home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
database
/
dbadv.zip
/
DBGUTIL.DOC
< prev
next >
Wrap
Text File
|
1986-02-25
|
10KB
|
302 lines
******************************************
* Documentation and Description* *
* of *
* DBGUTIL.PRG *
******************************************
*Utilit∙á likσ d'Uti∞ (tm⌐ Fo° ªá Gelle≥ *
*whicΦá i≤ donσ solel∙ iε dBAS┼ codσá a≤ *
*contrasteΣ witΦ thσ externa∞ naturσá oµ *
*d'Util. *
* *
*Thi≤áá prograφá contain≤á thσáá modula≥ *
*concept≤á showε iε thσ ADVANCE─ DBASEI╔ *
*USER╙ GUID┼ b∙ Adaφ Green« I⌠ i≤ baseΣ *
*largel∙ oε pp«á 8╢ -9░ anΣ reviseΣ witΦ *
*d'UTIL. *
* *
*Thσá prograφ ha≤ limiteΣ applicatioε iµ *
*yo⌡ arσ usinτ d'Util; however¼ witΦ thσ *
*comment≤ááá show≤ááá grea⌠áááá teachinτ *
*potential. *
* *
*Yo⌡ ma∙ usσ thσ prograφ a≤ is¼ o≥ speeΣ *
* *
*i⌠á u≡á witΦá somethinτá likσá DBSQUAS╚ *
*however¼á pleasσá remembe≥á tha⌠ i⌠á i≤ *
*submitteΣá onl∙ t∩ recommenΣá thσá booδ *
*and demonstrate the quality of content. *
*-> Don Saba
*-> SABALINE 24 hour BBS* 1200/300 baud
*-> (619)692-1961
*-> San Diego, CA.
***START OF Pretty PRG pp86-87 Advanced dBASE by Adam Greene
SET talk OFF
*
*set up the string macros
** -- DO string -- ****
***create the current character***
STORE "$(string,cpointer,1)" TO character
*
*move the character pointer
STORE "store 1 to cpointer" TO firstchar
STORE "store len(string) to cpointer" TO lastchar
STORE "store cpointer + 1 to cpointer" TO nextchar
*
*test for end of string
STORE "cpointer > len (trim(string))" TO endstring
*
*test for empty string
STORE "len(trim(string)) = 1 .and. string = ' ' " TO empty
*
*test for type of character
STORE "&character = ' '" TO isblank
STORE "&character $ '0123456789'" TO isnumber
STORE "&character >= 'A' .and. &character <= 'Z'" TO isupper
STORE "&character >= 'a' .and &character <= 'z' " TO islower
STORE "&character $ '.?!'" TO isendsent
*
*case conversion
STORE "chr(rank(&character)+32)" TO makelower
STORE "!(&character)" TO makeupper
STORE "store !($(string,1,1)) + $(string,2) to string" TO capfirst
*
*build a new string
STORE "store &character to newstring" TO startstr
STORE "store newstring + &character to newstring" TO addchar
***************************************************************
***************************************************************
***************************************************************
***************************************************************
*
* set up the variables which control indenting
STORE " " TO blanks
STORE 1 TO indent
STORE 3 TO indentamt
STORE 1 TO line
*
*set up the text data file to receive the program
USE text
DELETE ALL
PACK
*
* get the name of the program to be pretty printed
ACCEPT "What is the program's name? " TO program
*
*set up alternate file to contain the pretty version
SET ALTERNATE TO &program
SET ALTERNATE ON
*
*append the program into the text file
STORE program + ".PRG" TO program
APPEND FROM &program sdf
*
*process every line of the program
GOTO TOP
DO WHILE .not. eof
*
*if the current line isn 't empty, make it pretty
IF len(trim(text)) > 1 .OR. trim(text) <> " "
*
*remove any original indentation
STORE trim(text) TO string
** -- DO ltrim -- ****
*start at the first character of the string
&firstchar
* move past blank characters
DO WHILE &isblank
&nextchar
ENDDO WHILE &isblank
*get the restore of the string
STORE $(string,cpointer) TO newstring
** subroutine commented out for this module ? newstring
****************************************************************
****************************************************************
****************************************************************
STORE newstring TO string
*
* get the first word of the program, and capitalize it
&firstchar
** -- DO word -- ****
*look for the next non-blank character
STORE f TO inword
DO WHILE .not. inword .AND. .not. &endstring
*
IF .not. &isblank
* a non-blank character has been found, so start newstring
STORE t TO inword
&startstr
ENDIF .not. &isblank
*
&nextchar
ENDDO WHILE .not. inword .AND. .not. &endstring
*
* add the restore of the characters to newstring
DO WHILE inword .AND. .not. &endstring
*
IF .not. &isblank
&addchar
&nextchar
*stop when a blank character is reached
ELSE
STORE f TO inword
ENDIF .not. &isblank
*
ENDDO WHILE inword .AND. .not. &endstring
*
*clean up
RELEASE inword
****************************************************************
****************************************************************
****************************************************************
STORE!(newstring) TO newstring
*
DO CASE
*if the line is a comment, make it into lower case
CASE newstring = "*"
** -- DO lower -- ****
*start newstring
&firstchar
IF &isupper
STORE &makelower TO newstring
ELSE
&startstr
ENDIF &isupper
*convert each character until the end of the string is reached
&nextchar
DO WHILE .not. &endstring
*add each lower cas character to newstring
IF &isupper
STORE newstring +&makelower TO newstring
ELSE
&addchar
ENDIF &isupper
&nextchar
ENDDO WHILE .not. &endstring
****************************************************************
****************************************************************
****************************************************************
STORE newstring TO string
*
*if the line contains a quoted string
CASE '"' $ string
*find out where the quotes are
STORE @( '"' ,string) TO quote1
STORE @( '"' ,$(string,quote1 + 1)) + quote1 TO quote2
*if there are any characters after the second quote
IF len(trim(string)) > quote2
*store the capitalized part before the quote
*+ the quoted string + the capitalized part
*after the string back to the string
STORE !($(string,1,quote1 -1)) +;
$(string,quote1,quote2 - quote1 +1) +;
!($(string,quote2 +1)) TO string
ELSE
*store the capitalized part before the quote
*+ the quoted part back to the string
STORE !($(string,1,quote1-1)) +;
$(string,quote1,quote2 - quote1 + 1) TO string
ENDIF len(trim(string)) > quote2
*
*if it is a normal line just capitalize it
OTHERWISE
STORE !(string) TO string
ENDCASE
*
*print the line with indentation
DO CASE
*
*if the first word is do
CASE newstring = "DO"
*print the line
? str(line,3) + $(blanks,1,indent) + string
* get the next word
** -- DO word -- ****
*look for the next non-blank character
STORE f TO inword
DO WHILE .not. inword .AND. .not. &endstring
*
IF .not. &isblank
* a non-blank character has been found, so start newstring
STORE t TO inword
&startstr
ENDIF .not. &isblank
*
&nextchar
ENDDO WHILE .not. inword .AND. .not. &endstring
*
* add the restore of the characters to newstring
DO WHILE inword .AND. .not. &endstring
*
IF .not. &isblank
&addchar
&nextchar
*stop when a blank character is reached
ELSE
STORE f TO inword
ENDIF .not. &isblank
*
ENDDO WHILE inword .AND. .not. &endstring
*
*clean up
RELEASE inword
****************************************************************
****************************************************************
****************************************************************
* if the next string is while or case, indent the next line
IF !(newstring) = "WHILE" .OR. !(newstring) = "CASE"
STORE indent + indentamt TO indent
ENDIF !(newstring) = "WHILE" .OR. !(newstring) = "CASE"
*
* if the first word is endcase, enddo, or endif
CASE newstring = "ENDCASE" .OR. newstring = "ENDDO" .OR.;
newstring = "ENDIF"
* reduce the indentation and then print the line
STORE indent - indentamt TO indent
? str(line,3) + $(blanks,1,indent) + string
*
* if the first word is else
CASE newstring = "ELSE"
STORE indent - indentamt TO indent
* reduce the indentation and print the line
? str(line,3) + $(blanks,1,indent) + string
STORE indent + indentamt TO indent
*
* if the first word is if
CASE newstring = "IF"
*print the line and then indent the next line
? str(line,3) + $(blanks,1,indent) + string
STORE indent +indentamt TO indent
*
*if it is any otherwise type of line, just print it
OTHERWISE
? str(line,3) + $(blanks,1,indent) + string
ENDCASE
*
*if the line was empty jsut print the line number
ELSE
? str(line,3)
ENDIF len(trim(text)) > 1 .OR. trim(text) <> "
*
*move to the next line
STORE line +1 TO line
SKIP
*
ENDDO WHILE .not. eof
*
*clean up
USE
RELEASE blanks, indent, indentamt,line, program, string, newstring;
quote1,quote2
SET ALTERNATE OFF
SET talk ON
****************************************************************
****************************************************************
****************************************************************