APPLICATION NOTE #190 MODIFYING XYWRITE TEXT FILES DURING STARTUP Rev. 01 Although XyWrite enables you to automatically open a text file at the conclusion of its booting process, it does not ordinarily allow you to modify the file until its startup process has finished. This application note outlines a batch file method for both opening and modifying a text file as part of XyWrite's startup process. This process requires that XyWrite III Plus, version 3.54 or later, be used. THE XYWRITE STARTUP PROCESS XyWrite uses a program named STARTUP.INT to help you customize your XyWrite working environment. STARTUP.INT is a regular XyWrite program file, which can be modified following the procedures outlined in Chapter 6 of the XyWrite III Plus Reference Guide. The startup file can be used to load printer, keyboard, spelling, help, Save/Get, and dictionary files. It can be used to establish various XyWrite default settings (page length parameters, how the error beep sounds, etc.), and it can be used to run subsidiary programs. One option of the startup process is to automatically open a text file for editing. This option is not specified in STARTUP.INT itself. Instead, you specify it at the DOS prompt when you give the command to boot XyWrite: C:>editor filename The file you specify will be opened for editing when STARTUP.INT has finished running. But sometimes you might want to be able to manipulate the text file during the startup process. For instance, if you receive files via electronic mail, you might want to be able to boot XyWrite and automatically call and format the e-mail file so you can print it. This can be accomplished by using the batch file XYOPEN.BAT to boot XyWrite, and including a special XyWrite program called XYOPEN.PGM in your STARTUP.INT file. This program opens the text file and allows it to be modified while STARTUP.INT is still running. You may add customized formatting commands to XYOPEN.PGM. To edit a file during startup, enter the following command at the DOS prompt: C:>xyopen filename If you do not wish to edit a file during startup, you may boot XyWrite normally by typing the following command at the DOS prompt: C:>editor CONFIGURING YOUR SYSTEM TO USE XYOPEN.BAT AND XYOPEN.PGM There are two or three steps involved in configuring your system: (1) copying the two files to your XyWrite subdirectory or working disk; (2) adding a line to your startup file; and, in some cases, (3) making minor modifications to the two files. Copy XYOPEN.BAT and XYOPEN.PGM from the source disk into the same directory (or disk) as your XyWrite working files. Then use the following steps to modify your startup file: 1. Call your startup file to the screen as a program file by using the CAP command. Type: F5cap startup.int 2. With the cursor at the top of the file, add a blank line and move the cursor to this line. Press: Press: Cursor Up 3. Turn on programming mode. Press: Scroll Lock Result: An uppercase "S" appears in the upper right-hand corner of the screen. 4. Add the following line to your startup file. Press: F5 Result: A bold BC appears in the text area. Type: run xyopen.pgm 5. Turn off programming mode. Press: Scroll Lock 6. Store the file. Type: F5st If you boot XyWrite from drive C:, you are ready to use XYOPEN.PGM and XYOPEN.BAT. If you boot XyWrite from a drive other than drive C:, you must perform the following steps: 1. Call XYOPEN.BAT to the screen. Type: F5ca xyopen.bat 2. Change the sixth line so it refers to the root directory of the drive you boot from. For instance: Type: F5ci /c:/d:/ 3. Store the file. Type: F5st 4. Call XYOPEN.PGM to the screen. Type: F5ca xyopen.pgm 5. Change the three places which refer to drive C: to the drive letter you used in step 2. For instance: Type: F5ci /c:/d:/ 6. Store the file. Type: F5st PUTTING IT ALL TOGETHER When you want to boot XyWrite and have the startup process modify an open file, use the batch file you wrote instead of simply typing EDITOR. If you use XYOPEN to boot XyWrite, you must also specify a filename as a parameter. For instance: C:>xyopen bigbook Result: XYOPEN.BAT executes. After performing some error checking to make certain you have specified a valid file name, XYOPEN.BAT places the filename you specified in a variable called XYOPEN in the DOS environment. It then uses DOS redirection commands to place a record of your DOS environment in a small ASCII text file (called XYOPEN.SET) in the root directory of the specified drive. Finally, it boots XyWrite. XyWrite immediately starts to run your STARTUP.INT file, which includes a command to run XYOPEN.PGM. This subsidiary program checks to make certain that the ASCII text file created by the batch file exists. If it does not, XYOPEN.PGM concludes and control passes back to STARTUP.INT. This error checking means that the same STARTUP.INT file can used whether you boot XyWrite by using XYOPEN.BAT, or by simply typing EDITOR. If there is a XYOPEN.SET file, the program opens it and captures into a Save/Get the name of the file that you want to open. It deletes XYOPEN.SET, and opens the file you want. Control then passes back to STARTUP.INT, which is now able to modify the file. This method can be expanded in a variety of ways. For instance, you can build into STARTUP.INT some procedures for branching, based on the name of the file which has been opened. Also, the technique of setting a variable at the DOS level, and then reading it in XyWrite can be adapted to help make a number of other decisions--which printer file to load, for instance. You might prefer to add to XYOPEN.PGM, so that all file modification takes place under its control, rather than under the control of STARTUP.INT. Note #1 Description of XYOPEN.BAT Components. For your convenience, the contents of XYOPEN.BAT are listed and described below. For more information on writing batch files, refer to your DOS manual. echo off (Stops all subsequent commands from being "echoed" or displayed on the screen as they execute.) cls (Clears the screen.) if "%1"=="" goto nofile (Error checking: makes sure a file name has been specified; if not, the batch file branches to a label named "nofile.") if not exist %1 goto notfound (Error checking: makes sure the specified file name exists; if not, the batch file branches to a label named "notfound.") set xyopen=%1 (Establishes the DOS variable.) set > C:\xyopen.set (Redirects display of the DOS environment settings to a file.) editor (Boots XyWrite.) goto exit (Directs execution to a label named "exit." When you quit XyWrite, batch file execution resumes; this line tells the batch file what to do then.) :nofile (Label.) echo Format must be XYOPEN filename (Places reminder on screen.) goto exit (Directs execution to a label named "exit.") :notfound (Label.) echo File not found: %1 (Places reminder on screen.) :exit (Label.) Note #2 Contents of XYOPEN.PGM. XYOPEN.PGM is reproduced below. If you plan to recreate this program yourself, you must follow the rules for creating a XyWrite program file. For more information, refer to Chapter 5 of the XyWrite III Plus Reference Guide. BC exist c:\xyopen.setXC <>>><><>BC ca c:\xyopen.setXC BC se xyopen=XC DF ER DF <>BC abXC BC ernv c:\xyopen.setXC BC ca <>XC <> Note #3 XyWrite Versions Earlier than 3.54. You can change XYOPEN.PGM to make it work with versions 3.53 and earlier. Change <> to SV 1 and <> to <>. This will overwrite any Save/Get you normally have on Alt-1. ###