home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / dbase / computl2.arj / COMPALL2.PRG next >
Encoding:
Text File  |  1991-06-27  |  17.2 KB  |  653 lines

  1. *************************************************************************
  2. *      PROGRAM:            COMPALL2.PRG
  3. *   WRITTEN BY:            James Thomas
  4. * LAST CHANGED:            June 18, 1991 AT 10:29am
  5. *************************************************************************
  6. * This program creates source code to compile all .PRG
  7. * files in a directory
  8. *************************************************************************
  9.  
  10. * Set environment
  11.  
  12. SET TALK OFF
  13. SET STATUS OFF
  14. SET SAFETY OFF
  15. SET TITLE OFF
  16. SET SCOREBOARD OFF
  17. CLEAR ALL
  18. CLEAR
  19.  
  20. * Display program entry screen
  21.  
  22. CLEAR
  23. @ 0,0 TO 24,79 DOUBLE
  24. msg_txt = "COMPALL.PRG - dBase IV Source Code Compiling Program"
  25. @ 11,Cntr(msg_txt) SAY msg_txt COLOR W+
  26. msg_txt = "Charles County Government, Copyright (c) 1991"
  27. @ 13,Cntr(msg_txt) SAY msg_txt COLOR W+
  28. void = INKEY()
  29. void = INKEY(6)
  30. CLEAR
  31.  
  32. * Check for error conditions
  33.  
  34. IF Strstr("Runtime",VERSION())
  35.  
  36.     * Display error message
  37.  
  38.     ?? CHR(7)
  39.     @ 0,0 TO 24,79 DOUBLE
  40.     msg_txt = "COMPALL.PRG CANNOT Be Run From Runtime"
  41.     @ 11,Cntr(msg_txt) SAY msg_txt COLOR W+
  42.     msg_txt = "Re-run Program From dBase Dot Prompt"
  43.     @ 13,Cntr(msg_txt) SAY msg_txt COLOR W+
  44.     void = INKEY()
  45.     void = INKEY(6)
  46.     CLEAR
  47.  
  48.     * Reset environment and exit program
  49.  
  50.     SET TALK ON
  51.     SET STATUS ON
  52.     SET SAFETY ON
  53.     SET TITLE ON
  54.     SET SCOREBOARD ON
  55.     RETURN
  56. ENDIF
  57.  
  58. * Create database from extended structure file
  59.  
  60. DO Makedb
  61.  
  62. * Create database file containing program names
  63.  
  64. DO Create
  65.  
  66. * Build the source code program
  67.  
  68. DO Prg_bld
  69.  
  70. * Display messages, and define and activate a window before running
  71. * generated source code.
  72.  
  73. DO Text_box WITH "C O M P I L I N G   P R O G R A M S",6,2
  74. @ 17,Cntr("Directory--> " + SET("DIRECTORY")) SAY "Directory--> " + SET("DIRECTORY") COLOR W+
  75. DEFINE WINDOW WINTEMP FROM 8,9 TO 15,67 DOUBLE COLOR N/W,N/W
  76. ACTIVATE WINDOW WINTEMP
  77.  
  78. * Compile and run the generated program
  79.  
  80. COMPILE COMPRG$
  81. DO COMPRG$
  82.  
  83. * Restore enviroment & erase program file
  84.  
  85. DEACTIVATE WINDOW WINTEMP
  86. CLEAR
  87. RELEASE WINDOW WINTEMP
  88. RELEASE ALL
  89. ERASE COMPRG$.PRG
  90. ERASE COMPRG$.DBO
  91. ERASE CATALOG.CAT
  92. SET TALK ON
  93. SET STATUS ON
  94. SET SAFETY ON
  95. SET TITLE ON
  96. SET SCOREBOARD ON
  97.  
  98. RETURN
  99. * ============= Procedures =========== *
  100. PROCEDURE Create
  101.  
  102.     * Procedure to create program list
  103.  
  104.     * Clear screen and copy program files to text file using DOS command
  105.  
  106.     CLEAR
  107.     !DIR *.PRG > PRG$.TXT
  108.  
  109.     DO Text_box WITH "C R E A T I N G   P R O G R A M   L I S T",12,2
  110.  
  111.     * Iniailize variables
  112.  
  113.     PRIVATE fname, ext
  114.     STORE "" TO fname, ext
  115.  
  116.     * Append text from file
  117.  
  118.     APPEND FROM PRG$.TXT TYPE SDF
  119.  
  120.     * Erase temporary file
  121.  
  122.     ERASE PRG$.TXT
  123.  
  124.     * Delete unecessary lines
  125.  
  126.     DELETE FOR SUBSTR(ttext,10,3) # "PRG"
  127.     PACK
  128.     REPLACE ALL ttext WITH LEFT(ttext,12)
  129.     GO TOP
  130.  
  131.     * Delete spaces from file names, and insert the COMPILE command
  132.  
  133.     DO WHILE .NOT. EOF()
  134.         fname = LEFT(ttext,9)
  135.         ext   = SUBSTR(ttext,10,3)
  136.  
  137.         * If one of the files is this program "COMPALL.PRG" or the file created by this program "COMPRG$.PRG",
  138.         * do not compile
  139.  
  140.         IF TRIM(fname) # "COMPALL" .AND. TRIM(fname) # "COMPRG$"
  141.             REPLACE ttext WITH "COMPILE " + TRIM(fname) + "." + ext
  142.         ELSE
  143.             REPLACE ttext WITH "*COMPILE " + TRIM(fname) + "." + ext
  144.         ENDIF
  145.         SKIP
  146.     ENDDO
  147. RETURN
  148.  
  149. PROCEDURE Makedb
  150.  
  151.     * Procedure to create a database for use with the file
  152.  
  153.     DO Text_box WITH "C R E A T I N G   D A T A B A S E",12,2
  154.  
  155.     * Erase extended structure file if it exists before
  156.     * creating new structure file
  157.  
  158.     DO WHILE FILE("$TRUCFIL.DBF")
  159.         ERASE $TRUCFIL.DBF
  160.     ENDDO
  161.  
  162.     * Make new extended structure file
  163.  
  164.     void = Makestru("$TRUCFIL")
  165.  
  166.     * Append database information into $TRUCFIL.DBF
  167.  
  168.     USE $TRUCFIL
  169.     APPEND BLANK
  170.     REPLACE FIELD_NAME WITH "TTEXT"
  171.     REPLACE FIELD_TYPE WITH "C"
  172.     REPLACE FIELD_LEN  WITH 80
  173.     REPLACE FIELD_DEC  WITH  0
  174.     REPLACE FIELD_IDX  WITH "N"
  175.     USE
  176.  
  177.     * Create database for source code creation
  178.  
  179.     CREATE PRG$TEMP FROM $TRUCFIL.DBF
  180.  
  181.     * Erase extended structure file
  182.  
  183.     ERASE $TRUCFIL.DBF
  184.  
  185.     * Open created database
  186.  
  187.     USE PRG$TEMP.DBF NOSAVE EXCLUSIVE
  188. RETURN
  189.  
  190. PROCEDURE Prg_bld
  191.  
  192.     * Build program source code
  193.  
  194.     DO Text_box WITH "B U I L D I N G   S O U R C E   C O D E",12,2
  195.  
  196.     * Initialize variables
  197.  
  198.     PRIVATE a, line
  199.     STORE 1 TO a, line
  200.  
  201.     * Array to store source code
  202.  
  203.     DECLARE Program[300,1]
  204.  
  205.     * Initialize array
  206.  
  207.     DO WHILE a # 301
  208.         Program[a,1] = "VOID"
  209.         a = a + 1
  210.     ENDDO
  211.  
  212.     * Create program
  213.  
  214.     Program[ 1,1] = "********************************************************************************"
  215.     Program[ 2,1] = "*        Program:   COMPPRG$.PRG"
  216.     Program[ 3,1] = "*     Written By:   James Thomas, CCG Data Processing Dept. Copyright (c) 1991"
  217.     Program[ 4,1] = "* Code Generated:   " + Ddate(DATE()) + " AT " + TIME()
  218.     Program[ 5,1] = "********************************************************************************"
  219.     Program[ 6,1] = "* Generated code to compile all .PRG files in a directory"
  220.     Program[ 7,1] = "********************************************************************************"
  221.     Program[ 8,1] = ""
  222.     Program[ 9,1] = "* -- Initialization -- *"
  223.     Program[10,1] = ""
  224.     Program[11,1] = "CLEAR"
  225.     Program[12,1] = "SET TALK ON"
  226.     Program[13,1] = ""
  227.     Program[14,1] = "* -- Compile Programs -- *"
  228.     Program[15,1] = ""
  229.  
  230.     * Add source code from database
  231.  
  232.     * Initialize varible
  233.  
  234.     line = 16
  235.  
  236.     GO TOP
  237.     DO WHILE .NOT. EOF() .AND. LEN(TRIM(ttext)) # 0
  238.  
  239.         * Build display line
  240.  
  241.         Program[line,1] = [? "Compiling--> " + ]
  242.         comtmp = SUBSTR(TRIM(ttext),9,12)
  243.         Program[line,1] = Program[line,1] + ["&comtmp."]
  244.         line = line + 1
  245.  
  246.         * Build compile line
  247.  
  248.         Program[line,1] = TRIM(ttext)
  249.         SKIP
  250.         line = line + 1
  251.     ENDDO
  252.  
  253.     * Continue with source code listing
  254.  
  255.      Program[line,1] = ""
  256.     line = line + 1
  257.     Program[line,1] = "* -- Reset environment -- *"
  258.     line = line + 1
  259.     Program[line,1] = ""
  260.     line = line + 1
  261.     Program[line,1] = "SET TALK OFF"
  262.     line = line + 1
  263.     Program[line,1] = "CLEAR"
  264.     line = line + 1
  265.     Program[line,1] = ""
  266.     line = line + 1
  267.     Program[line,1] = "RETURN"
  268.     line = line + 1
  269.  
  270.     * Clear program file
  271.  
  272.     ZAP
  273.  
  274.     * Copy array data into program file
  275.  
  276.     APPEND FROM ARRAY Program FOR TRIM(ttext) # "VOID"
  277.  
  278.     * Copy database to program file, and erase database file
  279.  
  280.     COPY TO COMPRG$.PRG TYPE SDF
  281.     USE
  282.  
  283. RETURN
  284.  
  285. PROCEDURE Text_box
  286.  
  287.     *********************************************************************
  288.     * Text_box Program:   Draws a box around text on the line indicated *
  289.     *                     by the user.                                  *
  290.     *-------------------------------------------------------------------*
  291.     * Example Of Usage:    STORE "This is some Text" TO string         *
  292.     *                       STORE 12 TO line                *
  293.     *            STORE 1  TO type                *
  294.     *            DO Text_box WITH string,line,type           *
  295.     *                                                                   *
  296.     *    Type Options:    1 = Single Box                              *
  297.     *            2 = Double Box                              *
  298.     *                       3 = Panel Box                               *
  299.     *        Any other number = Single Box                              *
  300.     *********************************************************************
  301.  
  302.     * Establish Parameters
  303.  
  304.     PARAMETERS str,lno,typ
  305.  
  306.     CLEAR
  307.     * Declare variables
  308.  
  309.     PRIVATE msgline,lineno,bxtype
  310.  
  311.     * Store parameter to variable
  312.  
  313.     msgline = str
  314.     lineno  = lno
  315.     bxtype  = typ
  316.  
  317.     * If 1st parameter passed was not a string, convert to string
  318.  
  319.     IF TYPE("msgline") = "N"
  320.         msgline = LTRIM(STR(msgline))
  321.     ENDIF
  322.  
  323.     IF TYPE("msgline") = "D"
  324.         msgline = DTOC(msgline)
  325.     ENDIF
  326.  
  327.     * If 2nd parameter passed was not a number, convert to number
  328.  
  329.     IF TYPE("lineno") = "C"
  330.         lineno = VAL(lineno)
  331.     ENDIF
  332.  
  333.     * If 3rd parameter passed was not a number, convert to number
  334.  
  335.     IF TYPE("bxtype") = "C"
  336.         bxtype = VAL(bxtype)
  337.     ENDIF
  338.  
  339.     * If value is not character, return error message
  340.  
  341.     IF TYPE("msgline") # "C" .OR. TYPE("lineno") # "N" .OR. TYPE("bxtype") # "N"
  342.         ?? CHR(7) 
  343.         ?? "Invalid Value Passed To Text_box"
  344.         RETURN
  345.     ENDIF
  346.  
  347.     * If lenghth of text is greater than 80 (width of screen), return error message
  348.     IF LEN(msgline) > 74
  349.         ?? CHR(7) 
  350.         ?? "String Passed To Text_box Is Too Long"
  351.         RETURN
  352.     ENDIF
  353.  
  354.     * Draw Box and print text
  355.  
  356.     * Initialize variables
  357.  
  358.     PRIVATE up_lft,l_rght,bxapp
  359.  
  360.     STORE "" TO up_lft, l_rght, bxapp
  361.  
  362.     * Assign values to variables
  363.  
  364.     * Determine box type
  365.  
  366.     DO CASE
  367.         CASE bxtype = 2
  368.             STORE "DOUBLE" TO bxapp
  369.         CASE bxtype = 3
  370.             STORE "PANEL"  TO bxapp
  371.         OTHERWISE
  372.             STORE "" TO bxapp
  373.     ENDCASE
  374.  
  375.     * If the line number coordinate exceeds screen boundaries, reassign the cooridinate
  376.  
  377.     lineno = IIF(lineno<=0,1,lineno)
  378.  
  379.     IF SET("STATUS") = "ON"
  380.         lineno = IIF(lineno>=21,20,lineno)
  381.     ELSE
  382.         lineno = IIF(lineno>=24,23,lineno)
  383.     ENDIF
  384.  
  385.     * Row coordinate
  386.  
  387.     up_lft = LTRIM(STR(lineno-1))
  388.     l_rght = LTRIM(STR(lineno+1))
  389.  
  390.     * Column coordinate
  391.  
  392.     up_lft = up_lft + "," + LTRIM(STR(INT(Cntr(msgline))-2))
  393.     l_rght = l_rght + "," + LTRIM(STR(INT(Cntr(msgline))+(LEN(msgline)+1)))
  394.  
  395.     * Draw box and display text
  396.  
  397.     @ &up_lft. TO &l_rght. &bxapp.
  398.     @ lineno,Cntr(msgline) SAY msgline    COLOR W+
  399.  
  400. RETURN
  401.  
  402. * ============= Functions ============ *
  403.  
  404. *****************************************************************************************
  405. * PROGRAM NAME:            CNTR.PRG
  406. *                Centering Function
  407. * LAST CHANGED:            March 18, 1991 AT 10:55am
  408. *****************************************************************************************
  409. * This file contains functions to be used in dBase IV programs.
  410. *****************************************************************************************
  411.  
  412. *****************************************************************
  413. * Cntr Function:  Returns position to center text on the screen *
  414. *---------------------------------------------------------------*
  415. * Example Of Usage:    STORE "This is some Text" TO string     *
  416. *            @ 10,Cntr(string) SAY string            *
  417. *****************************************************************
  418.  
  419. FUNCTION Cntr
  420.  
  421.     * Establish Parameters
  422.  
  423.     PARAMETERS str
  424.  
  425.     * Declare variables
  426.  
  427.     PRIVATE msgline
  428.  
  429.     * Store parameter to variable
  430.  
  431.     msgline = str
  432.  
  433.     * If parameter passed was not a string, convert to string
  434.  
  435.     IF TYPE("msgline") = "N"
  436.         msgline = LTRIM(STR(msgline))
  437.     ENDIF
  438.  
  439.     * If value is not character, return error message
  440.  
  441.     IF TYPE("msgline") <> "C"
  442.         ?? CHR(7) 
  443.         ?? "Invalid Value Passed To Function Cntr"
  444.         RETURN 1
  445.     ENDIF
  446.  
  447.     * If lenghth of text is greater than 80 (width of screen), return 1 as starting position
  448.  
  449.     IF LEN(msgline) > 80
  450.         RETURN 1
  451.     ENDIF
  452.  
  453.     * Return Value of 40 minus half of the length of the string
  454.  
  455. RETURN 39-LEN(msgline)/2
  456.  
  457. *****************************************************************************************
  458. * PROGRAM NAME:            DDATE.PRG
  459. *                Date Function
  460. * LAST CHANGED:            March 18, 1991 AT 11:28am
  461. * WRITTEN BY:            James Thomas
  462. *****************************************************************************************
  463. * This file contains functions to be used in dBase IV programs.
  464. *****************************************************************************************
  465.  
  466. *******************************************************************
  467. * Ddate Function:  Returns Tuesday, October 9, 1990 from 10/09/90 *
  468. *-----------------------------------------------------------------*
  469. * Example Of Usage:    ?Ddate(DATE())                            *
  470. *        OR    @1,1 SAY Ddate({01/01/90})                *
  471. *******************************************************************
  472.  
  473. FUNCTION Ddate
  474.  
  475.     * Function to return the long display date from the system date.
  476.  
  477.     PARAMETERS dte
  478.  
  479.     * Establish variables
  480.  
  481.     PRIVATE d_date
  482.  
  483.     * Store parameter to variable
  484.  
  485.     d_date = dte
  486.  
  487.     * Test to see that a date was passed, if character convert to date.
  488.  
  489.     IF TYPE("d_date") = "C"
  490.         d_date = CTOD(d_date)
  491.     ENDIF
  492.  
  493.     * If value is not now a date, return error message
  494.  
  495.     IF TYPE("d_date") <> "D" .OR. d_date = {}
  496.         ?? CHR(7)
  497.         RETURN "Invalid Value Passed To Function Ddate"
  498.     ENDIF
  499.  
  500.     * Construct long form date to be returned.
  501.  
  502.     IF SUBSTR(DTOC(d_date),4,1) <> "0"
  503.  
  504.         RETURN CDOW(d_date) + ", " + CMONTH(d_date) + " " + SUBSTR(DTOC(d_date),4,2) + ", " + LTRIM(STR(YEAR(d_date)))
  505.     ENDIF
  506.         RETURN CDOW(d_date) + ", " + CMONTH(d_date) + " " + SUBSTR(DTOC(d_date),5,1) + ", " + LTRIM(STR(YEAR(d_date)))
  507.  
  508. *************************************************************************
  509. *      PROGRAM:            MAKESTRU.PRG
  510. *   WRITTEN BY:            Martin Leon AKA Hman (A-T BBS)
  511. * LAST CHANGED:            June 12, 1991 AT 8:02am
  512. *************************************************************************
  513. * This procedure creates a database structure.
  514. *************************************************************************
  515. FUNCTION Makestru
  516.  
  517.     * Establish paramters
  518.  
  519.     PARAMETER struname
  520.  
  521.     * Check to see that file does not already exist
  522.  
  523.     IF FILE(struname)
  524.         RETURN .F.
  525.     ENDIF
  526.  
  527.     * Create new catalog file
  528.  
  529.     newcat = "TMP" + LTRIM(STR(RAND(0)*100000,5)) + ".CAT"
  530.     DO WHILE FILE(newcat)
  531.         newcat = "TMP" + LTRIM(STR(RAND(0)*100000,5)) + ".CAT"
  532.     ENDDO
  533.  
  534.     KEYBOARD CHR(13)
  535.     SET CATALOG TO (newcat)
  536.     SET CATALOG TO
  537.     USE (newcat) NOSAVE
  538.     COPY STRUCTURE EXTENDED TO (struname)
  539.     USE(struname) EXCLUSIVE
  540.     ZAP
  541.     USE
  542.  
  543. RETURN .T.
  544.  
  545. *****************************************************************************************
  546. * PROGRAM NAME:            STRSTR.PRG
  547. *                String Searcing Function
  548. * LAST CHANGED:            May 8, 1991 AT 7:27am
  549. * WRITTEN BY:            James Thomas
  550. *****************************************************************************************
  551. * This file contains functions to be used in dBase IV programs.
  552. *****************************************************************************************
  553.  
  554. ***************************************************************************************
  555. * Strstr Function:    Searches for a substring within a string, and returns true or * 
  556. *            false.  Character Or Numeric Data Can Be Passed               *
  557. *            Recommened for searches of an array.
  558. *-------------------------------------------------------------------------------------*
  559. * Example Of Usage:    ?Strstr("ond","Monday") -> Returns .T.
  560. *
  561. *        OR    STORE "ond"    TO sub
  562. *            STORE "Monday"    TO str
  563. *            IF Strstr(sub,str)
  564. *                ? str
  565. *            ENDIF
  566. **************************************************************************************
  567.  
  568. FUNCTION Strstr
  569.  
  570.     ***********************************************************
  571.     * Establish Parameters                                    *
  572.     *---------------------------------------------------------*
  573.     * SUBSTR -  The substring to search for within the string *
  574.     * STRING -  The string to be searched for the substring   *
  575.     ***********************************************************
  576.  
  577.     PARAMETERS sub, str
  578.  
  579.     ***********************************************************
  580.     * Establish variables                                     *
  581.     *---------------------------------------------------------*
  582.     * sublen -  Used to store the length of the substring.    *
  583.     * strlen -  Used to store the length of the string.       *
  584.     * pend   -  Used to store the ending search position.     *
  585.     * pos    -  Used to store the current search postion.     *
  586.     ***********************************************************
  587.  
  588.     PRIVATE sublen, strlen, pend, pos, substr, string
  589.  
  590.     ***********************************************************
  591.     * Store parameters to variables                           *
  592.     ***********************************************************
  593.  
  594.     substr = sub
  595.     string = str
  596.  
  597.     ************************************************************
  598.     * If numeric expressions were passed, convert to character *
  599.     * expressions.                                             *
  600.     ************************************************************
  601.  
  602.     ************************
  603.     * Substring conversion *
  604.     ************************
  605.  
  606.     IF TYPE("substr") = "N"
  607.         substr = LTRIM(STR(substr))
  608.     ENDIF
  609.  
  610.     *********************
  611.     * String Conversion *
  612.     *********************
  613.  
  614.     IF TYPE("string") = "N"
  615.         string = LTRIM(STR(string))
  616.     ENDIF
  617.  
  618.     *********************************************************
  619.     * Return error message if either substring or string    *
  620.     * are non numeric.  Indicates invalid data type passed. *
  621.     *********************************************************
  622.  
  623.     IF TYPE("substr") <> "C" .OR. TYPE("string") <> "C"
  624.         ?? CHR(7)
  625.         ?? "Invalid Value Passed To Function Strstr"
  626.         RETURN .F.
  627.     ENDIF
  628.  
  629.     *****************
  630.     * Set variables *
  631.     *****************
  632.  
  633.     sublen = LEN(substr)        && Length of substring
  634.     strlen = LEN(string)        && Lenght of string
  635.     pend   = strlen - sublen    && Ending search position
  636.     pos   = 1            && Beginning Search Position
  637.     substr = TRIM(substr)        && Trim trailing spaces from substring
  638.  
  639.     **************************************************************
  640.     * Search Procedure, Infinite loop is executed. If substring  *
  641.     * is found, .T. is returned.  If substring is not found, and *
  642.     * the pos counter exceeds the pend counter, .F. is returned. *
  643.     **************************************************************
  644.  
  645.     DO WHILE pos <= (pend+1)
  646.         IF UPPER(SUBSTR(string,pos,sublen)) = UPPER(substr)    && Make comparison
  647.             RETURN .T.                    && Return True if substrings match
  648.         ENDIF
  649.         pos = pos + 1                        && Increment position counter
  650.     ENDDO
  651.  
  652. RETURN .F.                                && Return False if substring is not found
  653.