APPLICATION NOTE 197 HARD CODING COUNTERS HARD CODING COUNTERS XyWrite's automatic numbering feature makes it easy to place incrementing counters in a text file along with other formatting commands. These counters are ``soft coded'' in that their values change if you add or remove counters from a section of text. Some applications might require that these counters be ``hard coded,'' turned into real numbers, while retaining all other XyWrite formatting commands. This application note discusses a method you can use to do that. Hard Numbers Versus Soft Numbers Hard numbers are ones you actually type into your document. Soft numbers are ones you let XyWrite determine by using the Counter Command. The advantage to soft numbers is that XyWrite keeps track of and displays the correct value of each counter, even if you reorganize sections of text. If you used hard numbers, you would have to manually update them when you reorganize text. The disadvantage to soft numbers is that they have no fixed value until you actually print the file. This disadvantage becomes very large if you are preparing text files for transfer to a typesetting system or for conversion to a different word processor. Most typesetting systems and conversion software can handle basic page formatting (margins, indents, typeface selection, etc.), but can't handle formatting that depends on XyWrite's internal logic (counters, footnotes, etc.). Thus, you might have to choose: if you want to be able to convert page formatting commands, you have to give up soft numbers. But giving up soft numbers means a formidable editing task to make sure hard numbers stay in sequence. One way to change soft numbers into hard numbers is to use XyWrite's Type to File feature (TYF) with STRIP.PRN loaded. (Refer to the explanation of STRIP.PRN in the XyWrite III Plus Reference Guide for details.) But not only will the numbers be changed, all other formatting will be carried out. For example, if you have established a left margin of 5, there will be 5 units of space at the beginning of each line. An alternative is to use HARDCODE.PGM to change soft numbers into hard and preserve all other XyWrite formatting commands. Using HARDCODE.PGM HARDCODE.PGM, which was written by XYQUEST Technical Services, eliminates the inherent disadvantages of soft numbers and STRIP.PRN by giving you a way to change soft numbers into hard ones, while retaining all other formatting commands. The original file (with the counter commands) is left intact; the resulting file with the hard-coded counters can then be used by the typesetting system or conversion software to complete the translation. To use HARDCODE.PGM, make sure you have the text file to be hard coded on the screen. On the command line: Type: F5run hardcode.pgm The program immediately asks you whether or not you want to use label markers. Label markers are a means of tagging every place in the file where a soft number or a related counter command originally appeared. The markers display on the screen, but do not affect printing in XyWrite. (If you are sending the file to a typesetter, the label will be considered part of the text. Therefore, do not use label markers if you are planning to send the file elsewhere for printing.) The markers will not affect any further translation you do on the file. Type either Y or N to continue the program, or press Esc to exit. Depending on the length of your text file, the conversion process may take several minutes. The program displays the message, ``Working,'' on the Prompt line to indicate that the conversion is in progress. When the conversion to hard numbers is complete, the program displays the converted file on the screen and stores the original file to disk. Depending on the length of your text file, the program might ask you a few questions about certain places in the file. HARDCODE.PGM turns every 250 lines of your file into one long ``page''. (If your file exceeds 250 lines, the program finds each place it was forced to make a page break and asks you if that place should appear as a word space or hard return. Press either spacebar or to continue.) Make certain you store the converted file to disk also, using the filename of your choice. For example: Type: F5st filename.cnv You also must reload your printer file, since HARDCODE.PGM automatically unloads it in order to function properly. For example: Type: F5load 3hp-soft.prn Note #1 Scrolling to Disk May Affect Program Performance. When your file exhausts available memory, it scrolls to disk. In some versions of XyWrite, HARDCODE.PGM might not perform properly. To avoid this, maximize memory by unloading unneeded features and customization files before calling the text file to be hard coded. Choosing Markers Permanently If you use HARDCODE.PGM frequently and find that you always make the same decision to include or exclude the markers, you might prefer to make a minor change in the program itself so that the choice is made automatically. To do this, use the CA (Call) command to display HARDCODE.PGM on screen and read the notes at the beginning. The first paragraph explains how to choose markers permanently by copying a command triangle from the end of the paragraph to the beginning of the program file. For example, to always have markers, position the cursor directly on the command triangle at the end of line A, define it, and copy it to the beginning of the file: Press: F1 Press: right arrow Press: F1 Press: Ctrl Home Press: F7 Press: F3 Store the file. The next time you run it, it will skip directly to the section of the program that includes markers. Note #2 Selecting Other Marker Options. You can repeat the procedure described above as often as you like to choose markers or not depending on the situation. The program branches depending on which command triangle appears first in the program file. If the first triangle reads GLMARKERS, you will automatically get markers in the hard-coded file. If it reads GLNOMARKERS, you will automatically get no markers. If it reads GLDECIDE, you will be asked to decide if you want markers or not each time you run the program. Loading HARDCODE.PGM to a Key If you find that you use HARDCODE.PGM frequently, it might be convenient to have it automatically loaded to a key each time you use XyWrite. To do this, add a line to STARTUP.INT. For example, the following line in STARTUP.INT loads HARDCODE.PGM to Save/Get H: ldpm hardcode.pgm,h However, to ensure that this works properly, you must include the line in STARTUP.INT below any line that loads Save/Get keys. For example: ldsgt altkeys.sav ldpm hardcode.pgm,h How HARDCODE.PGM Works HARDCODE.PGM works by making three basic changes to the original file, using the TYF command, and then making more changes to the resulting file. First, it changes the open and close command brackets on the Counter, Define Counter, Reference, Counter, Footnote, and Set Footnote commands to a pair of unique strings. (The program also adds the markers at this stage, if selected.) Next it changes all remaining open and close command brackets to another string. Then it changes the first pair of unique strings back to regular open and close command brackets. It also specially codes hard returns to make sure they are preserved in the resulting file. Before using TYF, the program prepares and loads a dummy printer file. This dummy file makes certain that your regular printer file is removed from memory and is replaced with benign instructions. Once this printer file is in place, the TYF command is used to prepare another version of the file. TYF carries out all formatting instructions in the file, but HARDCODE.PGM has manipulated the file so the only formatting instructions are the Counter, Define Counter, Reference, Counter, Footnote, and Set Footnote commands. Thus, only they are carried out (hard coded). After TYF is complete, HARDCODE.PGM goes to work on the resulting file (automatically named FO.TMP by XyWrite; the original file is on disk in the same form and under the same name it had when HARDCODE.PGM was invoked). It changes all instances of the second pair of unique strings back to open and close command brackets, thus restoring the formatting commands it temporarily disabled while hard coding took place. Reserved Characters To function properly, HARDCODE.PGM needs to use several unique characters to mark various elements in your text file. We have tried to choose unusual characters unlikely to occur in normal text work, but conflicts might occur. If any of these reserved characters must appear in your text files, please call XYQUEST Technical Services for assistance in modifying HARDCODE.PGM: Character Use by HARDCODE.PGM  Open command, string 1  Close command, string 1 Open Command, String 2  Close command, string 2  Hard return ô Nonbreaking hyphen õ Tab ï Nonbreaking space ð Breaking space Page