home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / dev / lang / struct / exampleprograms / indenter.doc next >
Text File  |  1994-01-31  |  3KB  |  77 lines

  1.                         Struct Indenter 1.1
  2.                           by Roland Acton
  3.  
  4.   This program is designed to make life easier for Struct
  5. programmers. It indents source code to make the program flow through
  6. branches and loops more obvious.
  7.   Set up the Struct compiler as described in the documentation, then
  8. compile and link the Indenter program. Place the object code in your
  9. C: directory as IndentStr. Now you can use the Indenter from the CLI
  10. by typing:
  11.  
  12. IndentStr <source-file> <destination-file>
  13.  
  14.   The command line parsing code really isn't very good - unlike
  15. other programs, you can't use spaces in the filenames, not even if
  16. you surround them by quotes.
  17.   The Indenter will properly indent the code in the source-file and
  18. write it out to the destination-file. The source-file will not be
  19. affected.
  20.   There's a constant called INDENTAMOUNT which is defined near the
  21. beginning of the program. This sets how many columns the Indenter
  22. will shift a block of code by, if it decides to. It is originally
  23. set to 2, but can be changed if you have a different preference.
  24.  
  25. HOW IT WORKS
  26. ------------
  27.   The basic idea behind this program is easy to understand. We want
  28. to pull in a line of code from the source file, strip off any
  29. existing indentation (since this program may well have been used on
  30. the file before), indent it by a certain amount, and then write the
  31. line out. The "certain amount" is initially nothing, and shouldn't
  32. change when the program reads in a "standard" statement like A=A+B,
  33. but statements like For or Next will obviously change it.
  34.   Consider this block of code, taken from the Indenter program
  35. itself:
  36.  
  37.     libcall destfilehandle=open(destfilename,1006)
  38.     if destfilehandle>0
  39.       parsecommandline=1
  40.     else
  41.       libcall close(srcfilehandle)
  42.       print addresskludge
  43.       print destfilename
  44.       addresskludge=addresskludge+20
  45.       print addresskludge
  46.       parsecommandline=0
  47.     end if
  48.  
  49.   If we number the columns on our computer screen starting from 1,
  50. the If, Else, and End If are in column 5. Everything between them
  51. is in column 7. It's clear that this code is properly indented.
  52. But how did the program decide where to put what?
  53.   Notice what happened as we hit the If statement. From the Lib Call
  54. command above it, we can see that we were moving happily along,
  55. outputting everything at column 5. But then, AFTER the If, we
  56. started putting things in column 7. Notice the symmetry with the End
  57. If - we were outputting everything in column 7, and just BEFORE the
  58. End if we started to put things in column 5.
  59.   If we have an internal variable, call it INDENT, that controls the
  60. current amount of indentation, what we should do becomes clear. An
  61. If statement, or anything like it, should change the variable after
  62. the line is output. An End If-type statement should change the
  63. variable before the line is output.
  64.   This is the Indenter's keyword table:
  65.  
  66.   bytedata (keywords) "IF",0,"FOR",0,"WHILE",0,"REPEAT",0,"LOOP",0
  67.   bytedata "ZEROLOOP",0,"ASM",0
  68.   bytedata "ELSE",0
  69.   bytedata "ENDIF",0,"NEXT",0,"WEND",0,"UNTIL",0,"ENDLOOP",0
  70.   bytedata "ZEND",0,"ENDASM",0
  71.  
  72.   Everything before the Else is an If-type statement, and everything
  73. after it is an End If-type statement. The Else statement itself
  74. falls into BOTH classes. When it's encountered, INDENT is
  75. decremented, the Else is output, and INDENT goes back to whatever it
  76. was before.
  77.