home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / beehive / program / zsm.arc / ARX.DOC next >
Encoding:
Text File  |  1991-08-11  |  4.8 KB  |  132 lines

  1.     ARX.O, RARX.O, PARX.O, QARX.O - C runtime startup modules
  2.  
  3.     These do various things: most of them parse the command line into
  4. separate args, all of them load the stack pointer to the top of free memory,
  5. and set up argc & argv for procedure main. They then call main, and on
  6. return exit to the system (or in the case of PARX.O execute the next program
  7. in the pipe). In addition, they all define an external label exit which can
  8. be jumped to in order to terminate the program with extreme prejudice. The
  9. difference between them is how clever they are. In order of increasing
  10. intelligence we have:
  11.  
  12.     QARX.O    (Q for quick): ignores the command line args - does no
  13.         argc/argv setup at all.
  14.  
  15.     ARX.O    parse the command line into arguments, argv is set up from
  16.         these, however the program name is not available as argv[0].
  17.         argc is set as needed.
  18.  
  19.     RARX.O    (R for redirection): parse the command line, but if it finds
  20.         arguments with a leading < > or >> these don't reach argv,
  21.         instead they are used to do redirection of standard input
  22.         & output just like UNIX does it, to give an example,
  23.         A>PROG
  24.         normally PROG would take standard input from the keyboard,
  25.         and send standard output to the screen, however if it
  26.         were invoked as follows:
  27.         A>PROG <FILE1 >FILE2
  28.         standard input would read from FILE1, and FILE2 would be
  29.         created to hold the standard output, in addition
  30.         A>PROG >>FILE3
  31.         will send output to FILE3, but if the file exists it is
  32.         opened for append rather than being created anew.
  33.  
  34.     PARX.O    (P for pipe): does all that RARX.O does, it also will look for
  35.         | chars in the command line, and do pipes like UNIX does, so
  36.  
  37.         PROG | PROG1 | PROG2
  38.  
  39.         will work. A few words of warning are in order here: because
  40.         the Z80 is not the worlds biggest CPU, I haven't figured out
  41.         a way to do multi-tasking (but I'm working on it (?!?!)). As
  42.         a result of this, each program in the pipe must finish before
  43.         the next one can start, requiring that all the information
  44.         passing from one to the next be stored on disk: so if you do a
  45.  
  46.         CAT *.Z | ...
  47.  
  48.         you may find yourself in a lot of trouble when CAT runs out of
  49.         room to save all the stuff that was in *.Z. It goes without
  50.         saying that all programs in the pipe EXCEPT THE LAST must have
  51.         been linked with PARX, and the last needs either PARX or RARX:
  52.         the reason being that in the first example, PROG1 would be
  53.         invoked with a command line looking like:
  54.  
  55.         PROG1 <TEMPFILE | PROG2
  56.  
  57.     Note that none of these routines which do set up arguments will set
  58. up the program name as argv[0] as is conventional under UNIX, instead argv[0]
  59. is set to the null string, i.e. a pointer to a zero byte.
  60.  
  61.  
  62.     For those who have not worked with UNIX this (hopefully) will give
  63. a consise overview of exactly what argc and argv are:
  64.  
  65. A>PROGRAM ARG1 ARG2
  66.  
  67. argv (word) ---->   argv[0] - argv[1] - argv[2]   argc is 3 - 3 arguments
  68. [argument           |     |       |      [argument count max]
  69.  vector]           |     |       v
  70.                |     |       second arg string
  71.                |     v
  72.                |     first arg string
  73.                v
  74.                normally program name, not available under CP/M
  75.  
  76.  
  77. The way I set these up is to use the command line tail saved by CP/M
  78. at location 0x80 - as an example:
  79.  
  80. A>PROGRAM ARG1 ARG2
  81.  
  82. would leave
  83.  
  84. 0080:  0A 20 41 52 47 31 20 41-52 47 32 00 00 00 00 00   . ARG1 ARG2.....
  85.  
  86. in memory. After ARX has done its stuff, the following will be elsewhere
  87. in memory:
  88.  
  89.    high in memory
  90. argv[3]        NULL pointer (i.e. zero word)
  91. argv[2]        0x87 - address of ARG2 string (terminated by zero byte)
  92. argv[1]        0x82 - address of ARG1 string
  93. argv[0]        pointer to a zero byte (not the NULL pointer)
  94.    lower in memory
  95.  
  96. and on the stack will be found:
  97.  
  98. start of stack (high in memory)
  99.  
  100. argv        address of argv[0] whereever it is in memory
  101. argc        3 in this case - three valid arguments
  102. return address    return as created by the call to main
  103.  
  104. end of stack (lower in memory)
  105.  
  106. Usually spaces (and some other chars) can be a problem to get into command
  107. line arguments, so the following 'escape' sequences are recognised - using
  108. backslash '\' as the lead in character:
  109.  
  110. '\ '    backslash space - gets converted to a space, allow spaces to
  111.         get into arguments, usually spaces are used to separate
  112.         arguments
  113.  
  114. '\t'    backslash 't' - gets converted to a tab
  115.  
  116. '\n'    backslash 'n' - gets converted to a linefeed (newline)
  117.  
  118. '\r'    backslash 'r' - gets converted to a carriage return
  119.  
  120. '\b'    backslash 'b' - gets converted to a backspace
  121.  
  122. '\f'    backslash 'f' - gets converted to a formfeed
  123.  
  124. '\\'    backslash backslash - gets converted to a single backslash
  125.  
  126. '\e'    backslash 'e' - gets converted to an escape (may not be
  127.         implemented yet)
  128.  
  129.  
  130. ;;;;;;
  131.  
  132.