home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ctformat.zip / CTFORMAT.DOC < prev    next >
Text File  |  1993-11-03  |  16KB  |  440 lines

  1. CTFORMAT 1.04  --  Code/Text Formatter -- Written by Scott T Jones       
  2. ------------------------------------------------------------------
  3.  
  4. CTFORMAT.EXE is a 32-bit filter that dynamically performs 3 kinds of
  5. formatting:  C/C++ source files, Assembler source files using the macros
  6. defined by SALUT, SAT, or STRUC, and text files which use Alt-255 for
  7. WYSIWYG text formatting.  To use it, enter:
  8.  
  9.     CTFORMAT [?|A|C|T|N][B][V[R]] [ind[,opc[,opr[,rem]]]]
  10.  
  11. where ?  = display this information
  12.       A = use Assembler formatting rules
  13.       C = use C-Language formatting rules
  14.       T = use WYSIWYG Text formatting rules
  15.       N = perform No formatting, tab insertion/removal only
  16.       B = replace tabs with Blanks
  17.    V[R] = perform Vertical alignment [Removal]
  18.     ind = structure indent or text width
  19.     opc = opcode indent or continuation indent
  20.     opr = operand indent
  21.     rem = remark indent
  22.  
  23. If none of A, C, or T is specified, CTFORMAT will decide what type of
  24. formatting is required by examining the lines as it processes them.  If
  25. it finds a semicolon (;) as the first non-blank on a line, it will
  26. perform Assembler formatting.  If it finds the C remark indicator (/*)
  27. as the first non-blanks on the line, it will perform C formatting.
  28. Finally, if it finds an Alternate Blank character (Alt-255 or FFh) as
  29. the last character on a line, it will perform WYSIWYG text formatting.
  30. The position of the Alternate Blank is used as the width of the file.
  31. Once the format type is specified or found, the Type Identification
  32. algorithm is no longer executed.
  33.  
  34. WARNING:  Since CTFORMAT is a filter, no checking is performed to ensure
  35. that the input and output files are different.  The CTF.CMD command file
  36. takes care of this problem for you when using CTFORMAT from the command
  37. line, as does the CTF.S command file when using CTFORMAT within the
  38. Slick editor.
  39.  
  40. Assembler Formatting: 
  41. ---------------------
  42.  
  43. Assembler formatting places the OPCODE, OPERAND, and REMARK fields of
  44. each line in specified columns.  Lines that begin with a semicolon (;)
  45. in column one are left unmodified to allow the use of block comments.
  46. Remarks are never placed left of the current tab position used by code,
  47. if there is room on the line.
  48.  
  49. The COMMENT directive can be used for multi-line comments only if
  50. COMMENT is the first string of non-blank characters on the line.  All
  51. lines, including the ones containing COMMENT and the ending character,
  52. are left unmodified.
  53.  
  54. If the OPCODE field is one of the following names, in any mixture of
  55. cases, it is indented in a fashion similar to my SALUT/2 processor of
  56. the MASM/2 package.  These include all of the SALUT, SAT, and STRUC
  57. macros and the conditional pseudo-ops of the form IFxx used by MASM
  58. itself.
  59.  
  60.         $IF             $DO             .WHILE          .FOR
  61.         $ELSE           $STRTDO         .ENDWHILE       .NEXT
  62.         $ENDIF          $LEAVE                          .LEAVE
  63.                         $ENDDO          WHILE
  64.         .IF                             ENDWHILE        .SELECT
  65.         .THEN           $SEARCH                         .WHEN
  66.         .ELSEIF         $STRTSRCH       .REPEAT         .OTHERWISE
  67.         .ELSE           $EXITIF         .UNTIL          .ENDSELECT
  68.         .ENDIF          $ORELSE         .LOOP
  69.                         $ENDLOOP
  70.         IFxx            $ENDSRCH        REPEAT
  71.         ELSEIF                          UNTIL
  72.         ELSE
  73.         ENDIF
  74.  
  75. The default structure indent is 4.  The opcode-tab and remark-tab
  76. parameters refer to the number of columns the formatter should tab over
  77. from the start of the line to the OPCODE and REMARK fields.  The
  78. operand-tab is the number of columns the formatter should tab over from
  79. the OPCODE field to the OPERAND field.  NOTE:  The actual opcode-tab for
  80. a given line is the opcode-tab plus the structure indentation.  If any
  81. field cannot be placed in its appropriate column, it is placed as close
  82. to that column as possible after at least one separating blank.  The
  83. default values for opcode-tab, operand-tab, and remark-tab are 8, 8, and
  84. 40, respectively.  WARNING:  Numbers which push fields beyond column 256
  85. cause unpredictable results.
  86.  
  87. These parameters can be changed in the middle of a file using the line:
  88.  
  89.         ;CTFORMAT,[ind[,opc[,opr[,rem]]]]
  90.  
  91. Note, that if this is the first line of the file, it can also be used to
  92. identify the file as an Assembler file.  For compatibility with its
  93. predecessor, CTFORMAT can be replaced by STJFMT in any command.  All of
  94. the default values apply when using this statement.
  95.  
  96. To disable or enable formatting for any reason, ;CTFORMAT,D or
  97. ;CTFORMAT,E can be used, respectively.
  98.  
  99. Characters can be added to a file for vertical alignment using
  100. ;CTFORMAT,V.  This will place a 0xF9 at the beginning of each group of
  101. blanks used for structure indentation.  The 0xF9 character was chosen
  102. because it looks good, it prints without putting printers into graphics
  103. modes, and it is easily removed without disrupting code.  Removal of
  104. these characters can be accomplished using ;CTFORMAT,VR.
  105.  
  106. C Formatting: 
  107. -------------
  108.  
  109. The C formatter is guaranteed to properly format C programs which use
  110. braces in the coding of all structures, even if only a single statement
  111. is coded.  This forces an explicit end of structure to be coded to
  112. improve the clarity of the code.  If this is not done, proper formatting
  113. may not be possible due to the extensive parsing that is required,
  114. although it will be attempted.  By using these conventions, C programs
  115. can be written in a format that is familiar to users of any of the
  116. Structured Assembler macros without violating any of the syntactic rules
  117. of C.
  118.  
  119. Continuations are identified by open parentheses or brackets in
  120. statements.  If a line is continued, following lines will be indented
  121. either the number of spaces indicated by opc or the number of spaces
  122. necessary to line up with the first non-blank character following the
  123. first left parenthesis or left bracket in the first continued line of
  124. this statement.
  125.  
  126.         //CTFORMAT,
  127.         main ()
  128.         parameter-declarations;
  129.         {
  130.             declarations;
  131.  
  132.             type tag {
  133.                 declaration-list;
  134.             } declarator;
  135.  
  136.             type tag
  137.             {
  138.                 declaration-list;
  139.             } declarator;
  140.  
  141.             statements;
  142.  
  143.             sub( parm1,
  144.                  parm2,
  145.                  parm3);
  146.  
  147.             subroutine(
  148.                     parm1,
  149.                     parm2,
  150.                     parm3);
  151.  
  152.             subroutine( parm1
  153.                     parm2,
  154.                     parm3);
  155.  
  156.             if (x) {
  157.                 statements;
  158.             } else if (x) {
  159.                 statements;
  160.             } else {
  161.                 statements;
  162.             }
  163.  
  164.             if (x) {
  165.                 statements;
  166.             } else {
  167.                 statements;
  168.             }
  169.  
  170.             if (x) {
  171.                 statements;
  172.             }
  173.             else {
  174.                 statements;
  175.             }
  176.  
  177.             if (x)
  178.             {
  179.                 statements;
  180.             }
  181.             else
  182.             {
  183.                 statements;
  184.             }
  185.  
  186.             if (x)
  187.             {
  188.                 statements;
  189.             } else
  190.             {
  191.                 statements;
  192.             }
  193.  
  194.             do {
  195.                 statements;
  196.             } while (x);
  197.  
  198.             for (x;y;z) {
  199.                 statements;
  200.             }
  201.  
  202.             while (x) {
  203.                 statements;
  204.             }
  205.  
  206.             switch (x) {
  207.             case x:
  208.                 statements;
  209.             case y:
  210.                 statements;
  211.             default:
  212.                 statements;
  213.             }
  214.  
  215.             if(x){
  216.                 statements;
  217.             }
  218.  
  219.             for(x;y;z){
  220.                 statements;
  221.             }
  222.  
  223.             while(x){
  224.                 statements;
  225.             }
  226.  
  227.             switch(x){
  228.             case(x):
  229.                 statements;
  230.             case(y):
  231.                 statements;
  232.             default:
  233.                 statements;
  234.             }
  235.  
  236.             if ( x
  237.                  && y ) {
  238.                 statement;
  239.             }
  240.  
  241.             for ( x;
  242.                   y;
  243.                   z )
  244.             {
  245.                 statements;
  246.             }
  247.  
  248.             while ( x
  249.                     && y ) {
  250.                 statements;
  251.             }
  252.  
  253.             if ( x )
  254.                 statement;
  255.  
  256.             if ( x ) statement;
  257.  
  258.             if ( x ) statement;
  259.             else statement;
  260.  
  261.             if ( x )
  262.                 statement;
  263.             else statement;
  264.  
  265.             if ( x ) statement;
  266.             else
  267.                 statement;
  268.  
  269.             if ( x )
  270.                 statement;
  271.             else
  272.                 statement;
  273.  
  274.             do statement while ( x );
  275.  
  276.             while ( x )
  277.                 statement;
  278.  
  279.             while ( x ) statement;
  280.  
  281.             for ( x; y; z )
  282.                 statement;
  283.  
  284.             for ( x; y; z ) statement;
  285.  
  286.         }
  287.  
  288.         subroutine(parm1,parm2,parm3)
  289.         parameter-declarations;
  290.         {
  291.             declarations;
  292.             statements;
  293.         }
  294.  
  295. The structure and remark indent parameters can be changed in the middle
  296. of a file using either of the following lines:
  297.  
  298.         /*CTFORMAT,[ind][,[opc][,,rem]]*/
  299.         //CTFORMAT,[ind][,[opc][,,rem]]
  300.  
  301. Note, that if this is the first line of the file, it can also be used to
  302. identify the file as a C file.  The default structure indent is 4, the
  303. default continuation indent is 8, and the default remark indent is 40.
  304.  
  305. Comments and remarks are handled just like they are for Assembler
  306. formatting.  Lines that begin with a /* or // in column one are left
  307. unmodified to allow the use of block comments.  Remarks are never placed
  308. left of the current tab position used by code, if there is room on the
  309. line.  Multi-line comments can be used if /* is coded in column one of
  310. the first line.  All lines up to and including the line containing the
  311. first */ will be treated as full-line comments and will remain
  312. unmodified.
  313.  
  314. To disable or enable formatting for any reason, /*CTFORMAT,D*/ or
  315. /*CTFORMAT,E*/ can be used, respectively.  You may want to use this
  316. around complex data definitions, which are usually indented according to
  317. the tastes of the user or the individual requirements of the structure.
  318. To disable only the formatting and indentation of #xxx statements, use
  319. /*CTFORMAT,#*/.
  320.  
  321. Characters can be added to a file for vertical alignment using
  322. /*CTFORMAT,V*/.  This will place a 0xF9 at the beginning of each group
  323. of blanks used for structure indentation.  The 0xF9 character was chosen
  324. because it looks good, it prints without putting printers into graphics
  325. modes, and it is easily removed without disrupting code.  Removal of
  326. these characters can be accomplished using /*CTFORMAT,VR*/
  327.  
  328. For compatibility with its predecessor, CTFORMAT can be replaced by
  329. STJFMT in any command.
  330.  
  331. Keyword Generation: 
  332. -------------------
  333.  
  334. The CTCODGEN filter has been provided to convert existing C source files
  335. into the form preferred by CTFORMAT.  The command used to perform this
  336. conversion is:
  337.  
  338.         CTCODGEN <inputfile | CTFORMAT >outputfile
  339.  
  340. WARNING:  Since this is a filter, no checking is done to ensure that the
  341. input and output files are different.
  342.  
  343. WYSIWYG Text Formatting: 
  344. ------------------------
  345.  
  346. WYSIWYG is short for What You See Is What You Get.  This style of Text
  347. formatting allows you to see exactly what will be printed at all times.
  348. It does not require unique script and print files, both of which are
  349. often hard to read.  It does this by making use of the Alternate Blank
  350. (Alt-255 or FFh).  This character looks like a blank to everything
  351. except the formatter.  If you happen to lose track of them at any time,
  352. the global change feature of most editors can be used to change it to
  353. some unique character for easy editing, then change it back when you are
  354. done.  However, after using them for a while, you develop your own style
  355. and know where they are.
  356.  
  357. The formatter flows words, or strings of non-blank characters, into
  358. paragraphs.  Words in these paragraphs are separated by exactly one
  359. blank, unless they end with a period, question mark, exclamation point,
  360. or colon.  In that case, two blanks are used.  The Alternate Blank can
  361. be used to eliminate double blanks after initials in a name by making
  362. the whole name a string of non-blank characters.  This results in a
  363. single word that looks like two or more words on the display and the
  364. printer.
  365.  
  366. The indentation used by a paragraph is determined by the indentation of
  367. its first two lines.  To be included in the same paragraph, successive
  368. lines must be aligned with the second line.  Any further change of
  369. indentation indicates the beginning of a new paragraph.  Null lines and
  370. lines that have the Alternate Blank character (Alt-255) as either the
  371. first or last non-blank character are left untouched to allow the use of
  372. figures.  These lines also indicate the end of any paragraph which may
  373. have been in progress.
  374.  
  375. Remember that the Alternate Blank can also be used to define the width
  376. of the lines used in the paragraphs by its position on the line used to
  377. identify Text formatting.  It designates the first column NOT used for
  378. flowing.  The default width is 72 columns, the value specified if an
  379. Alternate Blank were placed in the last tab position within the normal
  380. screen width of 80 colums.  This document was produced using the
  381. CTFORMAT filter and can be used as an example of the placement of
  382. Alternate Blanks.
  383.  
  384. Tab Insertion/Removal: 
  385. ----------------------
  386.  
  387. If the N option is selected when CTFORMAT is invoked, No formatting will
  388. be performed.  Instead, CTFORMAT becomes a tool for tab insertion and
  389. removal.  If the B sub-option is selected, tabs will be removed, else
  390. tabs will be inserted.
  391.  
  392. Using CTFORMAT with Editors: 
  393. ---------------------------- 
  394.  
  395. CTFORMAT can be used with a variety of programmable editors, such as EPM
  396. or SLICK.  By defining an editor macro, your file can be written to
  397. disk, passed through the CTFORMAT filter, and reloaded into your edit
  398. session.
  399.  
  400. A Slick command file, CTF.S, has been included to define the ctf_format
  401. command.  This will save the current buffer in a temporary file, format
  402. it, and reload it.  The changes will not be saved unless you save them.
  403. To properly use this command, it should be loaded into Slick and bound
  404. to some key.  I use Alt-I to indicate Indenting.
  405.  
  406. Only defaults will be used for code formatting unless a CTFORMAT
  407. statement is found in the file.  For WYSIWYG Text formatting, the
  408. position of the first Alternate Blank is required to define the width of
  409. the text.
  410.  
  411. You will quickly discover that this is not a major restriction, since
  412. most Assembler and C/C++ files begin with a comment which describes the
  413. program.  Most text files begin with some sort of title which can easily
  414. contain the critical Alternate Blank.  If this is a problem, have your
  415. editor macro specify the format type and parameters.  If this is done,
  416. the type identification algorithm is never executed.
  417.  
  418. The CTF.CMD File: 
  419. -----------------
  420.  
  421. To protect users from the occasional errors that occur when using
  422. filters, the CTF.CMD file has been included.  Its format is:
  423.  
  424.     CTF [?|filespec] [A|C|T|N][B][V[R]] [ind[,opc[,opr[,rem]]]] 
  425.  
  426. This file copies the specified file to CTFORMAT.BAK, then invokes the
  427. filter from CTFORMAT.BAK to the specified file, eliminating the
  428. possibility that you will accidentally delete your source file.
  429.  
  430. Package Contents: 
  431. -----------------
  432.  
  433. The CTFORMAT PACKAGE consists the following files in CTFORMAT.ZIP, which
  434. was packed using PKZIP.  PKUNZIP should be used to unpack the files.
  435.  
  436.         CTFORMAT   EXE    CTFORMAT filter for OS/2 2.0+
  437.         CTFORMAT   DOC    This documentation file
  438.         CTF        CMD    Command file for OS/2 2.0+
  439.         CTF        S      Command definition for the Slick editor
  440.