Notes on the Use of BASCOM #2 COMMAND LINE INPUT (C) Copyright 1985 Merlin R. Null (818) 762-1429 To assembly language programmers or those familiar with compiled high level languages, getting an input filename or option directly from the CP/M command line is old stuff. For the first time user of BASCOM who has only had programming experience with the MBASIC interpreter it is another story. Many are not aware that it is very easy to implement in a compiled BASIC program. However, I know of no way to do it with the interpreter. The following short program is an example of how to get the command line tail into your program: 10 ' CTTEST.BAS Command tail test program by Merlin R. Null 7/6/85 20 CTLEN=PEEK(128) ' get the command tail length 30 FOR I=2 TO CTLEN ' read in command tail to CT$ 40 CT$=CT$+CHR$(PEEK(128+I)) 50 NEXT I 60 PRINT 70 PRINT"Command Line Length = ";CTLEN 80 PRINT"Command Line Tail reads: ";CT$ 90 END Cut a copy of CTTEST out of this document with your word processor and compile for use with BRUN.COM or as a stand alone program. Run CTTEST by entering: CTTEST FOO The output should read: Command Line Length = 4 Command Line Tail reads: FOO CTTEST first peeks at memory location 128 (80 hex), the start of the CP/M default buffer or DMA (Direct Memory Access) buffer. This byte contains the command tail length as a binary number. The variable CTLEN now contains the length of the command tail, including the space between the filename CTTEST and the command tail FOO. The next byte (129) contains the space entered to separate the command tail from the main command, CTTEST. The command tail starts at memory location 130. This is put into CT$ with peeks at the memory locations 130 thru the length found by peeking at location 128. You can then use CT$ for whatever you like in your program. It could be a filename or names to open for input or output, options for program operation or both. If you are going to input more than a single filename or option letter, you will need a command line parser to generate the filename string and the various flags used in your program. It might look something like the following: 190 ' Get filename and options 200 FOR I=1 TO LEN(CT$) 210 BYTE$=MID$(CT$,I,1) ' get a byte from command tail 220 IF OPTFLAG THEN 260 ' options started? 230 FILENAME$=FILENAME$+BYTE$ ' no, add byte to filename 240 IF BYTE$=" " THEN OPTFLAG=-1 ' flag start of options 250 IF NOT OPTFLAG THEN 330 ' no options yet, get next byte 260 IF BYTE$="N" THEN CONOFF=-1 ' No console output 270 IF BYTE$="P" THEN LNPRINT=-1 ' detect Print option 280 IF BYTE$="F" THEN FILE=-1 ' detect File option 290 IF BYTE$="L" THEN LNOPT=-1 ' Line number option 300 IF NUMFLAG THEN 330 ' already have a number? 310 ' this inputs a single number (0 thru 9) to the variable INDENT 320 IF ASC(BYTE$)>47 AND ASC(BYTE$)<58 THEN INDENT=ASC(BYTE$)-48:NUMFLAG=-1 330 NEXT I 340 IF FILENAME$="" THEN 1000 ' no filename, handle or exit 350 ' add extension if not given in command line tail 360 IF INSTR(FILENAME$,".")=0 THEN FILENAME$=FILENAME$+".DAT" No case conversion is required because CP/M will convert any command line tail to upper case. In the above example of a command line parser, only a space is required to start the detection of options. Extra spaces after the start of options are ignored. Thus, FOO F P N is equivalent to FOO FPN. Try running CTTEST in the interpreter to see the difference. You will find that it will always return a command tail length of 0, no matter what you enter at the CP/M command line. The interpreter uses the command tail to input filenames or buffer size and then zeros out the CP/M default buffer. This leaves you with nothing to read. If you were to enter MBASIC CTTEST FOO, neither CTTEST or FOO would be found in the buffer. 7-6-85 BASCOM AND MBASIC are trademarks of Microsoft