home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / dbadvan.zip / DBGUTIL.DOC < prev    next >
Text File  |  1987-02-14  |  10KB  |  302 lines

  1. ******************************************
  2. *     Documentation and Description*     *
  3. *                  of                    *
  4. *              DBGUTIL.PRG               *
  5. ******************************************                                 
  6. *Utilit∙á likσ d'Uti∞ (tm⌐ Fo° ªá Gelle≥ *
  7. *whicΦá i≤ donσ solel∙ iε dBAS┼ codσá a≤ *
  8. *contrasteΣ witΦ thσ externa∞ naturσá oµ *
  9. *d'Util.                                 *
  10. *                                        * 
  11. *Thi≤áá prograφá contain≤á thσáá modula≥ *
  12. *concept≤á showε iε thσ ADVANCE─ DBASEI╔ *
  13. *USER╙ GUID┼ b∙ Adaφ Green«  I⌠ i≤ baseΣ *
  14. *largel∙ oε pp«á 8╢ -9░ anΣ reviseΣ witΦ *
  15. *d'UTIL.                                 *  
  16. *                                        * 
  17. *Thσá prograφ ha≤ limiteΣ applicatioε iµ *
  18. *yo⌡ arσ usinτ d'Util; however¼ witΦ thσ *
  19. *comment≤ááá show≤ááá grea⌠áááá teachinτ *
  20. *potential.                              *
  21. *                                        *  
  22. *Yo⌡ ma∙ usσ thσ prograφ a≤ is¼ o≥ speeΣ *
  23. *                                        *
  24. *i⌠á u≡á witΦá somethinτá likσá DBSQUAS╚ *
  25. *however¼á pleasσá remembe≥á tha⌠ i⌠á i≤ *
  26. *submitteΣá onl∙ t∩ recommenΣá thσá booδ *
  27. *and demonstrate the quality of content. *
  28.  
  29. *-> Don Saba
  30. *-> SABALINE 24 hour BBS* 1200/300 baud
  31. *-> (619)692-1961
  32. *-> San Diego, CA.
  33. ***START OF Pretty PRG pp86-87 Advanced dBASE by Adam Greene
  34. SET talk OFF
  35. *
  36. *set up the string macros
  37. ** -- DO string -- ****
  38.  
  39. ***create the current character***
  40. STORE "$(string,cpointer,1)" TO character
  41. *
  42. *move the character pointer
  43. STORE "store 1 to cpointer" TO firstchar
  44. STORE "store len(string) to cpointer" TO lastchar
  45. STORE "store cpointer + 1 to cpointer" TO nextchar
  46. *
  47. *test for end of string
  48. STORE "cpointer > len (trim(string))" TO endstring
  49. *
  50. *test for empty string
  51. STORE "len(trim(string)) = 1 .and. string = ' ' " TO empty
  52. *
  53. *test for type of character
  54. STORE "&character = ' '" TO isblank
  55. STORE "&character $ '0123456789'" TO isnumber
  56. STORE "&character >= 'A' .and. &character <= 'Z'" TO isupper
  57. STORE "&character >= 'a' .and  &character <= 'z' " TO islower
  58. STORE "&character $ '.?!'" TO isendsent
  59. *
  60. *case conversion
  61. STORE "chr(rank(&character)+32)" TO makelower
  62. STORE "!(&character)" TO makeupper
  63. STORE "store !($(string,1,1)) + $(string,2) to string" TO capfirst
  64. *
  65. *build a new string
  66. STORE "store &character to newstring" TO startstr
  67. STORE "store newstring + &character to newstring" TO addchar
  68. ***************************************************************
  69. ***************************************************************
  70. ***************************************************************
  71. ***************************************************************
  72. *
  73. * set up the variables which control indenting
  74. STORE "                     " TO blanks
  75. STORE 1 TO indent
  76. STORE 3 TO indentamt
  77. STORE 1 TO line
  78. *
  79. *set up the text data file to receive the program
  80. USE text
  81. DELETE ALL
  82. PACK
  83. *
  84. * get the name of the program to be pretty printed
  85. ACCEPT "What is the program's name? " TO program
  86. *
  87. *set up alternate file to contain the pretty version
  88. SET ALTERNATE TO &program
  89. SET ALTERNATE ON
  90. *
  91. *append the program into the text file
  92. STORE program + ".PRG" TO program
  93. APPEND FROM &program sdf
  94. *
  95. *process every line of the program
  96. GOTO TOP
  97. DO WHILE .not. eof
  98.   *
  99.   *if the current line isn 't empty, make it pretty
  100.   IF len(trim(text)) > 1 .OR. trim(text) <> " " 
  101.     *
  102.     *remove any original indentation
  103.     STORE trim(text) TO string
  104.     ** -- DO ltrim -- ****
  105.  
  106.     
  107.     *start at the first character of the string
  108.     &firstchar
  109.     * move past blank characters
  110.     DO WHILE &isblank
  111.       &nextchar
  112.     ENDDO WHILE &isblank 
  113.     *get the restore of the string
  114.     STORE $(string,cpointer) TO newstring
  115. ** subroutine commented out for this module    ? newstring
  116.     ****************************************************************
  117.     ****************************************************************
  118.     ****************************************************************
  119.     STORE newstring TO string
  120.     *
  121.     * get the first word of the program, and capitalize it
  122.     &firstchar
  123.     ** -- DO word -- ****
  124.  
  125.     *look for the next non-blank character
  126.     STORE f TO inword
  127.     DO WHILE .not. inword .AND. .not. &endstring
  128.       *
  129.       IF .not. &isblank
  130.         * a non-blank character has been found, so start newstring
  131.         STORE t TO inword
  132.         &startstr
  133.       ENDIF .not. &isblank 
  134.       *
  135.       &nextchar
  136.     ENDDO WHILE .not. inword .AND. .not. &endstring
  137.     *
  138.     * add the restore of the characters to newstring
  139.     DO WHILE inword .AND. .not. &endstring
  140.       *
  141.       IF .not. &isblank
  142.         &addchar
  143.         &nextchar
  144.         *stop when a blank character is reached
  145.       ELSE
  146.         STORE f TO inword
  147.       ENDIF .not. &isblank 
  148.       *
  149.     ENDDO WHILE inword .AND. .not. &endstring 
  150.     *
  151.     *clean up
  152.     RELEASE inword
  153.     ****************************************************************
  154.     ****************************************************************
  155.     ****************************************************************
  156.     STORE!(newstring) TO newstring
  157.     *
  158.     DO CASE
  159.         *if the line is a comment, make it into lower case
  160.       CASE newstring = "*" 
  161.         ** -- DO lower -- ****
  162.  
  163.         *start newstring
  164.         &firstchar
  165.         IF &isupper
  166.           STORE &makelower TO newstring
  167.         ELSE
  168.           &startstr
  169.         ENDIF &isupper 
  170.         *convert each character until the end of the string is reached
  171.         &nextchar
  172.         DO WHILE .not. &endstring
  173.           *add each lower cas character to newstring
  174.           IF &isupper
  175.             STORE newstring +&makelower TO newstring
  176.           ELSE
  177.             &addchar
  178.           ENDIF &isupper 
  179.           &nextchar
  180.         ENDDO WHILE .not. &endstring 
  181.         ****************************************************************
  182.         ****************************************************************
  183.         ****************************************************************
  184.         STORE newstring TO string
  185.         *
  186.         *if the line contains a quoted string
  187.       CASE '"' $ string
  188.         *find out where the quotes are
  189.         STORE @( '"' ,string) TO quote1
  190.         STORE @( '"' ,$(string,quote1 + 1)) + quote1 TO quote2
  191.         *if there are any characters after the second quote
  192.         IF len(trim(string)) > quote2
  193.           *store the capitalized part before the quote
  194.           *+ the quoted string + the capitalized part
  195.           *after the string back to the string
  196.           STORE !($(string,1,quote1 -1)) +;
  197.           $(string,quote1,quote2 - quote1 +1) +;
  198.           !($(string,quote2 +1)) TO string
  199.         ELSE
  200.           *store the capitalized part before the quote
  201.           *+ the quoted part back to the string
  202.           STORE !($(string,1,quote1-1)) +;
  203.           $(string,quote1,quote2 - quote1 + 1) TO string
  204.         ENDIF len(trim(string)) > quote2 
  205.         *
  206.         *if it is a normal line just capitalize it
  207.       OTHERWISE
  208.         STORE !(string) TO string
  209.     ENDCASE 
  210.     *
  211.     *print the line with indentation
  212.     DO CASE
  213.         *
  214.         *if the first word is do
  215.       CASE newstring = "DO" 
  216.         *print the line
  217.         ? str(line,3) + $(blanks,1,indent) + string
  218.         * get the next word
  219.         ** -- DO word -- ****
  220.  
  221.         *look for the next non-blank character
  222.         STORE f TO inword
  223.         DO WHILE .not. inword .AND. .not. &endstring
  224.           *
  225.           IF .not. &isblank
  226.             * a non-blank character has been found, so start newstring
  227.             STORE t TO inword
  228.             &startstr
  229.           ENDIF .not. &isblank 
  230.           *
  231.           &nextchar
  232.         ENDDO WHILE .not. inword .AND. .not. &endstring
  233.         *
  234.         * add the restore of the characters to newstring
  235.         DO WHILE inword .AND. .not. &endstring
  236.           *
  237.           IF .not. &isblank
  238.             &addchar
  239.             &nextchar
  240.             *stop when a blank character is reached
  241.           ELSE
  242.             STORE f TO inword
  243.           ENDIF .not. &isblank 
  244.           *
  245.         ENDDO WHILE inword .AND. .not. &endstring 
  246.         *
  247.         *clean up
  248.         RELEASE inword
  249.         ****************************************************************
  250.         ****************************************************************
  251.         ****************************************************************
  252.         * if the next string is while or case, indent the next line
  253.         IF !(newstring) = "WHILE" .OR. !(newstring) = "CASE" 
  254.           STORE indent + indentamt TO indent
  255.         ENDIF !(newstring) = "WHILE" .OR. !(newstring) = "CASE"  
  256.         *
  257.         * if the first word is endcase, enddo, or endif
  258.       CASE newstring = "ENDCASE" .OR. newstring = "ENDDO" .OR.;
  259.         newstring = "ENDIF" 
  260.         * reduce the indentation and then print the line
  261.         STORE indent - indentamt TO indent
  262.         ? str(line,3) + $(blanks,1,indent) + string
  263.         *
  264.         * if the first word is else
  265.       CASE newstring = "ELSE" 
  266.         STORE indent - indentamt TO indent
  267.         * reduce the indentation and print the line
  268.         ? str(line,3) + $(blanks,1,indent) + string
  269.         STORE indent + indentamt TO indent
  270.         *
  271.         * if the first word is if
  272.       CASE newstring = "IF" 
  273.         *print the line and then indent the next line
  274.         ? str(line,3) + $(blanks,1,indent) + string
  275.         STORE indent +indentamt TO indent
  276.         *
  277.         *if it is any otherwise type of line, just print it
  278.       OTHERWISE
  279.         ? str(line,3) + $(blanks,1,indent) + string
  280.     ENDCASE 
  281.     *
  282.     *if the line was empty jsut print the line number
  283.   ELSE
  284.     ? str(line,3)
  285.   ENDIF len(trim(text)) > 1 .OR. trim(text) <> " 
  286.   *
  287.   *move to the next line
  288.   STORE line +1 TO line
  289.   SKIP
  290.   *
  291. ENDDO WHILE .not. eof 
  292. *
  293. *clean up
  294. USE
  295. RELEASE blanks, indent, indentamt,line, program, string, newstring;
  296. quote1,quote2
  297. SET ALTERNATE OFF
  298. SET talk ON
  299. ****************************************************************
  300. ****************************************************************
  301. ****************************************************************
  302.