Category : Dbase (Clipper, FoxBase, etc) Languages Source Code
Archive   : DGENIII.ZIP
Filename : DGPROC.PRG

 
Output of file : DGPROC.PRG contained in archive : DGENIII.ZIP
* Program..: dGENERATE
* Filename.: dg_proc.prg
* Author...: Tom Rettig
* Dates....: 3/28/84, 8/30/84, 12/29/84, 12/30/84, 12/31/84, 1/01/85,
* 1/03/85, 1/04/85, 1/05/85, 1/06/85, 1/11/85, 1/12/85,
* 1/13/85, 1/15/85, 1/25/85, 1/26/85, 1/27/85, 1/28/85,
* 1/29/85, 1/30/85, 2/01/85, 2/09/85, 2/10/85, 2/12/85,
* 2/13/85, 2/16/85, 2/17/85, 2/18/85, 2/19/85, 2/22/85,
* 2/23/85, 2/24/85, 2/25/85, 3/17/85, 4/01/85, 6/01/85,
* 6/26/85, 6/27/85, 7/01/85, 7/25/85, 7/27/85
* Notice...: Copyright 1985, Tom Rettig & Associates, All Rights Reserved.
* Version..: 1.0 (x30)
* Run under: dBASE III, any version greater than 1.1, or dBRUN.
* Notes....: To generate executable dBASE code from screen-forms
* and database files.
*
* Called from...: dg_main.prg
*
* Files requed: dg_main.prg --> Program entry and main menu
* dg.dbf --> Structure for database: dg.dbf
* Field Field Name Type Width
* 1 DG_TEXT Character 254
* ** Total ** 255
*
* Procedures are in alphabetical order:
* dg_main ::= entry/exit from dGENERATE and main menu
* 1 abort ::= aborts code generation and returns to main menu
* 2 alt_file ::= opens/closes alternate file and writes header/footer
* 3 config ::= initializes system values from parameters line
* 4 crea_new ::= creates a new screen-form for drawing
* 5 doer ::= executes a command file
* 6 editor ::= edits a screen-form or any text file
* 7 file_msg ::= displays source and target filenames
* 8 fileprmt ::= prompts for a filename and tests for existence
* 9 generate ::= reads a screen-form and causes code to be written
* 10 gen_entr ::= writes code for data entry/edit algorithm
* 11 gen_menu ::= writes code for menu algorithm
* 12 gen_rprt ::= writes code for report algorithm
* 13 helper ::= main help file
* 14 hlp_crea ::= help screen for crea_new
* 15 hlp_doer ::= help screen for doer
* 16 hlp_edit ::= help screen for edit
* 17 hlp_gene ::= help screen for generate
* 18 hlp_mgen ::= help screen for mem_gen
* 19 hlp_setu ::= help screen for setup
* 20 hlp_togl ::= toggles between pages in multi-page hlp_* screens
* 21 key_time ::= displays continuous time while waiting for keypress
* 22 line_inc ::= increments line counter and tests for new page
* 23 marquee ::= places this program's headings on screen
* 24 mem_gen ::= writes memvar statements from database file
* 25 pars_lit ::= parses literal strings for write
* 26 pars_var ::= parses variables for write
* { 27 setup ::= menu driven edit of the default parameters
* 28 set_if1 ::= setup options -|
* 29 set_if2 ::= setup options -|---(broken up for performance)
* 30 set_if3 ::= setup options -|
* 31 wait_msg ::= handles 'be patient' message, and sets up abort
* 32 write ::= writes code from parsed literals or variables
*
* Macro is used in the syntax of these commands:
* APPEND FROM, DIR, DO, ERASE, MODIFY COMMAND, RUN, USE
* SET ALTERNATE, SET COLOR, SET DELIMITERS


PROCEDURE abort
PARAMETERS dl_wrkfile
* Called from crea_new, generate, mem_gen
ON ESCAPE *
SET COLOR TO &dg_accent
SET BELL ON
@ 22,0 SAY " Aborting this procedure!!!" +;
" h "
?? CHR(7), CHR(7)
@ 23,0 SAY " One moment, please, while I clean up..." +;
" "
SET COLOR TO &dg_normal
SET BELL OFF
*
CLOSE ALTERNATE
IF FILE(dl_wrkfile)
ERASE &dl_wrkfile
ENDIF
*
CLOSE INDEXES
IF FILE("Dg_temp$.ndx")
ERASE Dg_temp$.ndx
ENDIF
*
* This is possible only from generate where 'dg_param' is reinitialized.
* (unless crea_new or mem_gen are told to use dg.dbf)
IF "DG.DBF" $ UPPER(DBF())
SET SAFETY OFF
ZAP
SET SAFETY ON
IF [] < dl_oldt
APPEND BLANK
REPLACE Dg_text WITH dl_oldt
DO config WITH dl_oldt
ENDIF
ENDIF
*
USE
*
IF FILE("Dg_temp$.dbf")
ERASE Dg_temp$.dbf
ENDIF
*
ON ESCAPE SUSPEND
RETURN TO MASTER
*
* EOP abort **********************************{***********************


{PROCEDURE alt_file
* Called from generate and mem_gen, not from crea_new
PARAMETERS dl_targetf, dl_part
*
IF dl_part = 1
* Open target file, and write its name and system date as a header.
@ 3,0 SAY []
SET ALTERNATE TO &dl_targetf
SET ALTERNATE ON
?? "* Program..: " + dl_targetf
? "* Author...: "
? "* Date.....: " + DTOC(DATE())
? "* Notice...: Copyright " + STR(YEAR(DATE()),4) +;
", , All Rights Reserved."
? "* Notes....: "
? "*"
?
ELSE
* Write footer and close the file.
?? "* EOF: " + dl_targetf
CLOSE ALTERNATE
ENDIF
*
RETURN
* EOP alt_file *******************************************************


PROCEDURE config
* Called from default, generate, setup
PARAMETERS dl_linef
*
* Characters used to denote SAYs and GETs in the screen-form.
dg_atget = SUBSTR(dl_linef,13,1)
dg_atsay = SUBSTR(dl_linef,15,1)
* Character used to denote a memvar initialization in the screeo~form.
dg_init = SUBSTR(dl_linef,17,1)
* Number of columns on the screen (1..254).
dg_eol = VAL(SUBSTR(dl_linef,19,3)) && end of line
* Number of lines (rows) on the screen (1..999).
dg_eos = VAL(SUBSTR(dl_linef,23,3)) && end of screen
* Logicals.
dg_isreltv = SUBSTR(dl_linef,27,1) = [T] && relative addressing in code
dg_isruler = SUBSTR(dl_linef,29,1) = [T] && ruler line in screen-form
dg_isdelim = SUBSTR(dl_linef,31,1) = [T] && set delimiters on
dg_isfill = SUBSTR(dl_linef,33,1) = [T] && fill screen-form with blanks
dg}7ishelp = SUBSTR(dl_linef,35,1) = [T] && help screens for each menu item
* Default file extensions.
dg_fmemout = SUBSTR(dl_linef,37,3) && output file for creating memvars
dg_fscrout = SUBSTR(dl_linef,41,3) && output file for code from screen-form
dg_fscr_in = SUBSTR(dl_linef,45,3) && screen-form file for drawing screens
* Characters in ruler.
dg_rule1 = SUBSTR(dl_linef,49,1) && appears in column zero only
dg_rule = SUBSTR(dl_linef,51,10) && repeats every ten columns after zero
* Delimiters.
dg_delim = SUBSTR(dl_linef,62,2) && characters used for delimiters
* Character used in this menu (ASCII value).
dg_char = VAL(SUBSTR(dl_linef,65,3)) && used in marquee of this program
* Word processor.
dg_wp = SUBSTR(dl_linef,69,8) && external editor for screen-forms
*
* Program constants.
dg_line = REPLICATE(CHR(dg_char),80) && marquee line in this program
dg_ruler = dg_rule1 + REPLICATE(dg_rule,INT((dg_eol-1)/10)) +;
LEFT(dg_rule,MOD(dg_eol-1,10)) && ruler line in screen-forms
dg_max = IIF(dg_eol < 100, 2, 3) && number of digits in @ coordinates
*
* Set the delimiters.
IF dg_isdelim .AND. dg_delim > [ ]
SET DELIMITERS TO [&dg_delim]
SET DELIMITERS ON
ELSE
SET DELIMITERS OFF
ENDIF
*
* Convert logicals to character.
dl_1 = IIF(dg_isreltv, "T", "F")
dl_2 = IIF(dg_isruler, "T", "F")
dl_3 = IIF(dg_isdelim, "T", "F")
dl_4 = IIF(dg_isfill , "T", "F")
dl_5 = IIF(dg_ishelp , "T", "F")
*
* Construct a new parameters line from individual memvars.
dl = [ ]
dg_param = [parameters: ]+dg_atget+dl+dg_atsay+dl+dg_init+dl+;
STR(dg_eol,3)+dl+STR(dg_eos,3)+dl+dl_1+dl+dl_2+dl+dl_3+dl+dl_4+dl+dl_5+dl+;
dg_fmemout+dl+dg_fscrout+dl+dg_fscr_in+dl+dg_rule1+dl+dg_rule+dl+;
dg_delim+dl+STR(dg_char,3)+dl+dg_wp
*
RETURN
* EOP config *********************************************************


PROCEDURE crea_new
* Called from menu
* To initialize a text file for drawing screens.
*
DO marquee WITH [ Creating a New Screen ]
*
IF dg_ishelp
DO helper WITH 1
ENDIF
*
* Prompt for name of target text file.
dl_targetf = [ ]
dl_defext = dg_fscr_in
dl_istargt = .T.
dl_isedit = .F.
DO fileprmt
IF dg_iserror
RETURN
ENDIF
*
* Prompt for name of source database file if any.
dl_sourcef = []
dl_names = [?]
SET COLOR TO &dg_accent
*
@ 11,13 SAY "Add field and memvar names from a database file? (Y/N)" ;
GET dl_names
IF dg_ishelp
@ 13,08 SAY "Memory variable names are generated from "+;
"this file's field names,"
@ 14,14 SAY "and both are placed in the screen-form for your use."
ENDIF
*
READ
@ 11,13
{@ 13,08
@ 14,14
SET COLOR TO &dg_normal
IF dl_names $ "Yy"
dl_defext = [dbf]
STORE .F. TO dl_istargt, dl_isedit
DO fileprmt
IF dg_iserror
RETURN
ENDIF
ENDIF
*
dl_abortf = dl_targetf
DO wait_msg WITH 1
DO file_msg WITH dl_sourcef, dl_targetf
* returns with color set to dg_accent.
*
* Open target file, and write.
SET CONSOLE OFF
SET ALTERNATE TO &dl_targetf
SET ALTERNATE ON
*
* Write the top (ruler) line.
IF dg_isruler
?? dg_ruler
ENDIF
*
* Write the screen body.
dl_i = 1
IF dg_isfill
DO WHILE dl_i <= dg_eos
? SPACE(dg_eol)
dl_i = dl_i+1
ENDDO
ELSE
DO WHILE dl_i <= dg_eos
?
dl_i = dl_i+1
ENDDO
ENDIF
*
* Add parameters, date, and definition table lines.
?
? "dgDEFINE -- Begin definitions in the first column. Example syntax follows:"
? " [ " + dg_init + ;
"] [PICTURE/FUNCTION