home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / basic / bascmnot.lbr / BASCOM2.NQT / BASCOM2.NOT
Encoding:
Text File  |  1986-07-14  |  4.1 KB  |  100 lines

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