home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / dbadv.zip / PRETTY.PRG < prev    next >
Text File  |  1986-02-25  |  4KB  |  135 lines

  1. SET talk OFF
  2. *
  3. *set up the string macros
  4. DO string
  5. *
  6. * set up the variables which control indenting
  7. STORE "                     " TO blanks
  8. STORE 1 TO indent
  9. STORE 3 TO indentamt
  10. STORE 1 TO line
  11. *
  12. *set up the text data file to receive the program
  13. USE text
  14. DELETE ALL
  15. PACK
  16. *
  17. * get the name of the program to be pretty printed
  18. ACCEPT "What is the program's name? " TO program
  19. *
  20. *set up alternate file to contain the pretty version
  21. SET ALTERNATE TO &program
  22. SET ALTERNATE ON
  23. *
  24. *append the program into the text file
  25. STORE program + ".PRG" TO program
  26. APPEND FROM &program sdf
  27. *
  28. *process every line of the program
  29. GOTO TOP
  30. DO WHILE .not. eof
  31.   *
  32.   *if the current line isn 't empty, make it pretty
  33.   IF len(trim(text)) > 1 .OR. trim(text) <> " " 
  34.     *
  35.     *remove any original indentation
  36.     STORE trim(text) TO string
  37.     DO ltrim
  38.     STORE newstring TO string
  39.     *
  40.     * get the first word of the program, and capitalize it
  41.     &firstchar
  42.     DO word
  43.     STORE!(newstring) TO newstring
  44.     *
  45.     DO CASE
  46.         *if the line is a comment, make it into lower case
  47.       CASE newstring = "*" 
  48.         DO lower
  49.         STORE newstring TO string
  50.         *
  51.         *if the line contains a quated string
  52.       CASE '"' $ string
  53.         *find out where the quotes are
  54.         STORE @( '"' ,string) TO quote1
  55.         STORE @( '"' ,$(string,quote1 + 1)) + quote1 TO quote2
  56.         *if there are any characters after the second quote
  57.         IF len(trim(string)) > quote2
  58.           *store the capitalized part before the quote
  59.           *+ the quoted string + the capitalized part
  60.           *after the string back to the string
  61.           STORE !($(string,1,quote1 -1)) +;
  62.           $(string,quote1,quote2 - quote1 +1) +;
  63.           !($(string,quote2 +1)) TO string
  64.         ELSE
  65.           *store the capitalized part before the quote
  66.           *+ the quoted part back to the string
  67.           STORE !($(string,1,quote1-1)) +;
  68.           $(string,quote1,quote2 - quote1 + 1) TO string
  69.         ENDIF len(trim(string)) > quote2 
  70.         *
  71.         *if it is a normal line just capitalize it
  72.       OTHERWISE
  73.         STORE !(string) TO string
  74.     ENDCASE 
  75.     *
  76.     *print the line with indentation
  77.     DO CASE
  78.         *
  79.         *if the first word is do
  80.       CASE newstring = "DO" 
  81.         *print the line
  82.         ? str(line,3) + $(blanks,1,indent) + string
  83.         * get the next word
  84.         DO word
  85.         * if the next string is while or case, indent the next line
  86.         IF !(newstring) = "WHILE" .OR. !(newstring) = "CASE" 
  87.           STORE indent + indentamt TO indent
  88.         ENDIF !(newstring) = "WHILE" .OR. !(newstring) = "CASE"  
  89.         *
  90.         * if the first word is endcase, enddo, or endif
  91.       CASE newstring = "ENDCASE" .OR. newstring = "ENDDO" .OR.;
  92.         newstring = "ENDIF" 
  93.         * reduce the indentation and then print the line
  94.         STORE indent - indentamt TO indent
  95.         ? str(line,3) + $(blanks,1,indent) + string
  96.         *
  97.         * if the first word is else
  98.       CASE newstring = "ELSE" 
  99.         STORE indent - indentamt TO indent
  100.         * reduce the indentation and print the line
  101.         ? str(line,3) + $(blanks,1,indent) + string
  102.         STORE indent + indentamt TO indent
  103.         *
  104.         * if the first word is if
  105.       CASE newstring = "IF" 
  106.         *print the line and then indent the next line
  107.         ? str(line,3) + $(blanks,1,indent) + string
  108.         STORE indent +indentamt TO indent
  109.         *
  110.         *if it is any otherwise type of line, just print it
  111.       OTHERWISE
  112.         ? str(line,3) + $(blanks,1,indent) + string
  113.     ENDCASE 
  114.     *
  115.     *if the line was empty jsut print the line number
  116.   ELSE
  117.     ? str(line,3)
  118.   ENDIF len(trim(text)) > 1 .OR. trim(text) <> " 
  119.   *
  120.   *move to the next line
  121.   STORE line +1 TO line
  122.   SKIP
  123.   *
  124. ENDDO WHILE .not. eof 
  125. *
  126. *clean up
  127. USE
  128. RELEASE blanks, indent, indentamt,line, program, string, newstring;
  129. quote1,quote2
  130. SET ALTERNATE OFF
  131. SET talk ON
  132. ****************************************************************
  133. ****************************************************************
  134. ****************************************************************
  135.