| Suppressing a Newline |
One interesting feature of the INPUT routine is its ability to print a prompt string and wait for input on the same line. This is accomplished using DOS's DEBUG utility to strip the carriage return/line feed from the prompt string. There are some who think this is somehow 'un-DOS'. Personally, I fail to see the distinction and often make use of DEBUG scripts to do things that cannot otherwise be done in DOS.INPUT.BAT calls a second procedure named NOLINE.BAT, shown below, to get the job done. In its simplist form, the procedure could be made part of INPUT, but I have made it a separate routine because it has many other uses.
The procedure constructs a simple control script in the fifth line, which is later deleted to keep from cluttering the disk with a tiny procedure. Creating secondary routines at run time also insures that they are always available, though it slows processing a little. The first few lines provide default inputs that are used if one or no command line inputs are provided to make the procedure more general purpose.
|
:: NOLINE.BAT - A procedure to remove the CR/LF from the last line of a file. |
Normally, the routine would be called with just one input argument, the name of the file containing the desired prompt string. However, if no prompt string is given, a question mark is provided instead as the default.A second default, the console device (CON), for output is also assumed. But, an alternate device, such as PRN or a file, can be supplied instead. This is very useful in sending control strings to a printer without a newline, thus providing better control of the printer's output.
For those who really want to know, the DEBUG script constructs a tiny bit of assembly code (three bytes, 83 E9 02) that subtracts two from the contents of the CX register, loads the prompt string just above this code (L103), runs the three byte program (P), names an output device (N%2), writes the shortened file contents to the named device (W103) and then quits DEBUG (Q).