home *** CD-ROM | disk | FTP | other *** search
- 29-AUG-85 pFORMAT.PAS (v 2.02) 26-Aug-1985 page 1
-
-
- Author : Andy J. S. Decepida
-
- N.B. : This utility is declared public domain. Therefore it should
- not be used for commercial purposes. Users may freely distribute
- pFORMAT.PAS and p4mSetUp.PAS in source or executable form (unaltered or
- otherwise). Users who alter the source of pFORMAT.PAS and/or p4mSetUp.PAS
- are amiably requested to notify the author of any significant changes that
- would affect/optimize execution. The author also welcomes bug reports or
- suggestions.
-
- Messages may be sent to :
- Andy Decepida
- 416 Perth Avenue
- Toronto, Ontario
- CANADA M6P 3Y6
- (416) 762-0802 (voice/data --- no collect calls please)
-
- PC1171 on PCanada
- (416) 751-6337
- E-Mail
-
- Layout of this Document:
- ~~~~~~~~~~~~~~~~~~~~~~~
- General Functional Description
- Primary Features
- Case Alteration of Words
- RESERVED WORDS
- USER-DEFINED WORDS
- Handling of String Literals
- Handling of Comments
- Handling of Hexadecimal Literals
- Error Handling
- NonExistent Input File
- Extant Output File
- Input File designated as Output File as well
- Miscellaneous Features
- FileSpec Specifications Parsing
- Command Line Parameters
- Will Display File Date/Time & Size to assist in FileSpec confirmation
- Abortable by KeyPress during translation
- ReConfigurable at Compile Time
- ReConfigure the RESERVED WORD TABLE
- ReConfigure the MIXED-CASE handling
- A Sort of undocumented Turbo Pascal (v 30) feature?
- Limitations
- Inherently Slow
- Will NOT indent for you
- Usage
- Command Line Conventions
- Responding to the Option Prompts
- Terminologies / Jargon
-
-
- 1: General Functional Description
- ------------------------------
- pFormat will read an ASCII-text file, assumed to contain Pascal source,
- and generate a copy with changes in the case of both reserved and user-
- defined words according to options selected by the user.
-
- 1.1: Primary Features
- ----------------
- Input : Pascal source (in pFORMAT standard configuration, Turbo
- Pascal dialect)
- Output: a copy of the input with altered cases of reserved words and
- user-defined words.
-
- 1.1.1: Case Alteration of Words
- ------------------------
-
- 1.1.1.1: RESERVED WORDS
- --------------
- - User-Defined Translation
- - Primary Options are to translate RESERVED WORDS to:
- Upper-Case or Lower-Case or As-Is
- - Default is to translate RESERVED WORDS to Upper-Case.
- - When the default is overridden, the user is given the option
- to alter the translation as defined in the Primary Options above.
- Additionally, the user is prompted whether Extensions are to
- be translated to MIXED CASE (cf PROCEDURE makemixedcase in
- pFORMAT.PAS).
-
- 1.1.1.2: USER-DEFINED WORDS
- ------------------
- - User-Defined Translation
- - Primary Options are to translate USER-DEFINED WORDS to:
- Upper-Case or Lower-Case or As-Is
- - Default is to leave USER-DEFINED WORDS as-is.
-
- 1.1.2: Handling of String Literals
- ---------------------------
- String Literals are NOT translated at all (with the exception of
- HexaDecimal characters --- see below). They are, as with comments,
- left as-is, REGARDLESS of user selection/s for the treatment of
- RESERVED & USER-DEFINED WORDS.
-
- 1.1.3: Handling of Comments
- --------------------
- Comments are NOT translated at all (with the exception of
- HexaDecimal Literals --- see below). They are, as with string
- literals, left as-is, REGARDLESS of user selection/s for the
- treatment of RESERVED & USER-DEFINED WORDS.
-
- 1.1.4: Handling of Hexadecimal Literals
- --------------------------------
- - HexaDecimal Literals (specifically digits 'A'..'F') are
- unconditionally translated to Upper-Case ANYWHERE in the file. A
- HexaDecimal literal is recognized only by the <$> prefix.
-
- 1.2: Error Handling
- --------------
- pFORMAT has the standard error-handling features you would expect of
- text-based processors. These features, stated as the scenarios they are
- guarding against, are enumerated below.
-
- 1.2.1: NonExistent Input File
- ----------------------
- Severity : FATAL;
- Handling : The user is re-prompted for an extant file as input.
-
- 1.2.2: Extant Output File
- ------------------
- Severity : Depends on how dear the existing output file is to the
- user;
- Handling : The user is told of the situation and is asked whether
- he/she wants to proceed to write over the file or backout (NOT to
- write over the extant file). When this backout option is exercised,
- pFormat will prompt the user for a different FileSpec.
-
- 1.2.3: Input File designated as Output File as well
- --------------------------------------------
- Severity : VERY VERY FATAL;
- Handling : The user is told of the near-disaster and is reprompted
- for both an input and output file (ie., full recycling).
-
- 1.3: Miscellaneous Features
- ----------------------
- 1.3.1: FileSpec Specifications Parsing
- -------------------------------
- When supplying FileSpecs, the default Ext(ension) is <.PAS>. This
- means you don't have to key-in the Ext if the file has (or should
- have) the <.PAS> Ext.
- When specifying a filename without Ext, I have taken the cue from
- the Turbo Editor and made pFormat to expect a FileName suffixed by a
- lone period <.>. (e.g., to specify "FILE1" as the FileName, key in
- "FILE1."
-
- 1.3.2: Command Line Parameters
- -----------------------
- When Present =-> 1st Parm is the Input FileSpec
- =-> 2nd Parm is the Output FileSpec
-
- 1.3.3: Will Display File Date/Time & Size to assist in FileSpec confirmation
- ---------------------------------------------------------------------
-
- 1.3.4: Abortable by KeyPress during translation
- ----------------------------------------
- Before pFORMAT goes off to translate a file, it will prompt the
- user for a last option, that of being able to abort with a keypress
- during execution. If you elect this option, you can interrupt the
- translation in progress by pressing any key. At that point, pFORMAT
- will ask if you want to abort the translation or not ... much like
- the Turbo Compile command.
-
- 1.3.5: ReConfigurable at Compile Time
- ------------------------------
- pFORMAT.PAS is distributed in source form and is readily
- compilable with Turbo Pascal v 3.0. If you don't have release 3.xx,
- you may use the distributed executable image pFORMAT.COM or alter the
- v 3.0 specific code to compile under your version of Turbo Pascal.
- The ReConfiguration being hinted here concerns that of the array
- "Token" (which contains all the Turbo Pascal 3.0 RESERVED WORDS and,
- consequently, all token-patterns that will be translated as per user-
- choice for the RESERVED set of WORDS).
- I am supplying p4mSetUp.PAS as a companion utility to semi-
- automate this ReConfiguration. The readily ReConfigurable items
- (without altering the source of pFORMAT.PAS) are described below
- (such alterations would precede a re-compile of pFORMAT.PAS of
- course):
-
- 1.3.5.1: ReConfigure the RESERVED WORD TABLE
- -----------------------------------
- pFORMAT.PAS has 3 include files. The first is the declaration
- of the size of the array <token>. Then there is the initialization
- statements for the same array, and finally, the CASE (Pascal sense)
- body of the PROCEDURE doreserved.
- The array <token> is the driver array or RESERVED WORD TABLE.
- If you wish to expand, contract, or simply alter the actual WORDS
- that pFORMAT will recognize as RESERVED WORDS, you have to alter the
- second include file (distributed as TOKEN.INC). p4mSetUp.PAS will
- do this automatically for you after you alter the p4mSetUp.PAS input
- files called BASE.RES and EXTNS.RES (which contain the ISO-Pascal &
- Extensions respectively). These two files are plain ASCII-text
- files and can be altered by any text-editor or word-processor
- capable of handling plain text files. The advantages of using
- p4mSetUp are that you reduce keying errors and ensure synchronized
- include files.
-
- 1.3.5.2: ReConfigure the MIXED-CASE handling
- -----------------------------------
- As mentioned above (in the discussion of ReConfiguring the
- RESERVED WORD TABLE), the third include file (EXTNS.INC) contains
- the logic for translating extensions to MIXED-CASE.
- If you don't like the way the CASES are mixed in the standardly
- configured EXTNS.INC you can just edit that file. If you are
- dissatisfied with the scope/coverage this means you have to
- expand/contract the EXTNS.INC. You can then add the appropriate
- lines anywhere in EXTNS.INC or run p4mSetUp.PAS.
- If you the reconfiguration manually, you must keep the 3 include
- files in synch. p4mSetUp will do this for you automatically.
-
- 1.3.6: A Sort of undocumented Turbo Pascal (v 3.0) feature?
- ---------------------------------------------------
- This observation concerns Turbo Pascal v 3.0 only.
-
- Well it seems that pFORMAT, as compiled with Turbo Pascal 3.xx, will
- accept a filename <PRN> as an output file (since it is a logical
- device). The program (pFORMAT) will actually tell you it exists and
- even give you the strange file attributes of your printer (date, time,
- & size!). When you specify and confirm the PRN (that is, the printer)
- as a destination file, pFORMAT will actually route output to the
- printer. I have not provided for pagination if this happens since it
- will markedly slow the process down too significantly. There are
- several Pascal listers in the public domain anyway.
- If you use SideKick regularly, you know that the sequence ^K^P would
- cause either the marked block (or if none are marked, the entire file)
- in a NotePad file would print to LPT1:. Well, the above-mentioned
- piece-of-trivia also applies to SideKick AND the Turbo Editor.
-
- 1.4: Limitations
- -----------
-
- 1.4.1: Inherently Slow ...
- -------------------
- Since the I/O of pFORMAT is READLN/WRITELN and not
- BLOCKREAD/BLOCKWRITE, it is slow ... however, I can vouch that
- READ/WRITE (char by char) would be even more tedious. A more elegant
- version, which I will not release, uses READLN/WRITELN but has a
- different parser, tacks on 30% more time at execution.
-
- 1.4.2: Will NOT indent for you ...
- ---------------------------
- pFORMAT may be a misleading program ID, since it seems to claim
- that it will actually format Pascal source files (which usually
- includes what pFORMAT does plus indentation). Incorporating logic to
- indent source files is possible but NOT practical. It would slow down
- execution dramatically. I am working on an indenter but it will impose
- its own indentation style (which is another big question, who
- dictates?). There are several public domain indenters (and they are
- char-by-char oriented, ergo slow) available.
-
-
- 2: Usage
- -----
-
- 2.1: Command Line Conventions
- ------------------------
- The following assume normal scenarios, for exception handling/flow
- see Exception Handling above.
-
- Where you see FileName specify the 8-char DOS file-name
- Where you see extension you specify the 3 char extension (optional
- if these extensions are <.PAS> anyway.
-
- 1. Calling pFORMAT and specifying input and output at command line
- A> pformat <FileName><Ext> <FileName><Ext>
- The first FileName is the input file and the 2nd, the output file
-
- 2. Calling pFORMAT and specifying input only
- A> pformat <FileName><Ext>
- The FileName is the input file name and pformat will ask for the
- output file name.
-
- 3. Calling pFORMAT without specifying any parameters
- A> pformat
- pFORMAT will prompt you for the input file name & then the output
- filename.
-
- 2.2: Responding to the Option Prompts
- --------------------------------
- The Option Prompts are already bulletproof, a beep will sound if you
- have miskeyed a character input.
-
- 3: Terminologies / Jargon
- ----------------------
-
- RESERVED WORDS - includes the ISO-Pascal set and (in the standard
- pFormat configuration) Turbo Pascal-Extension set of "standard"
- identifiers, verbs, functions, procedures, etc.
-
- USER-DEFINED WORDS - the set of alpha-numeric identifiers, functions,
- procedures excluding RESERVED WORDS.
-
- CASE - concerns the visual configuration of a WORD (specifically,
- whether in upper-case or capital-letters, or lower-case).
-
- AS-IS - in pFORMAT context, this means no translation of a WORD found
- in the input file will be made in writing the WORD to the output file.
-
- MIXED-CASE - in pFORMAT context, means a special translation (via
- PROCEDURE makemixedcase) of a WORD is to be done. This (in the standard
- pFormat configuration) effectively highlights the Pascal-Extensions from
- those of the ISO-Pascal reserved words. An example is to translate the
- reserved word "lowvideo" to "LowVideo".
-
- STANDARD pFORMAT CONFIGURATION - pFORMAT as originally configured by
- the author and as distributed originally (for configuration information
- refer to p4mSetUp.PAS.
-
- WORD - the superset that consists of RESERVED WORDS and USER-DEFINED
- WORDS. A word is a string/sequence of alpha-numeric characters including
- the underscore-character <_>.
-
- HEXADECIMAL LITERALS - a string of characters prefixed by a dollar-
- sign <$> and restricted to the set of characters '0'..'9' and 'A'..'F'. In
- BNF,
- <hexadecimal literal> ::= <$> 0|1|2|3|4|5|6|7|8|9|a|A|b|B|c|C|d|D|e|E|f|F
-
- STRING LITERALS - a string of characters spanning the entire ASCII
- spectrum and delimited by a pair of apostrophe signs (e.g., '<string>')
-
- COMMENTS - a string of characters spanning the entire ASCII spectrum
- and delimited by a pair of either curly braces {} or the parenthesis-
- asterisk markers (* *)
-
- FileSpec - <FileName>.<Ext> this is an abbrev. of File Specification.
-
- FileName - 8 character maximum-length name of a file
-
- Ext - abbrev for Extension or the 3 character maximum-length
- qualification of a file's ID
-
- File - in pFormat context is strictly an ASCII-text file