home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol195 / fluf11 / t.lbr / INITCMD.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-02-10  |  4.3 KB  |  106 lines

  1.      { Copyright (C) 1984 D.M. Fritz-Rohner                }
  2.  
  3. procedure ArgInit ( var narg : integer; var argv : argvec ) ;
  4.      {                                                     }
  5.      { Name: ArgInit - ARGument vector INITialization.     }
  6.      {                                                     }
  7.      { Version: 1.0/TURBO (tm)      Date: 1984 May 16      }
  8.      {                                                     }
  9.      { Purpose: Parse reduced command tail just enough to  }
  10.      { extract argument strings.  Note that argument       }
  11.      { counting conforms to Pascal's one origin indexing   }
  12.      { so that argument indices run from 1 to narg.        }
  13.      {                                                     }
  14.      { Notice that command tail length is limited because  }
  15.      { TURBO writes a jump vector over the command buffer  }
  16.      { beginning at offset 20H.  Therefore, only 31 bytes  }
  17.      { of the command tail are available in default line   }
  18.      { buffer.  See ALTCMD.PAS if the entire command line  }
  19.      { must be parsed.                                     }
  20.      {                                                     }
  21.      { Author: D.M. Fritz-Rohner                           }
  22.      {         Post Office Box 9080                        }
  23.      {         Akron, Ohio  44305                          }
  24.      {                                                     }
  25.  
  26. const     MAXLINE   = 31 ;
  27.  
  28. type      xstrptr   = ^xstr ;
  29.           xstr      = record
  30.                            len : char ;
  31.                            tail : array[1..MAXLINE] of char ;
  32.                       end ;
  33.  
  34. var       arg       : argstr ;     { intermediate variable }
  35.           cptr      : xstrptr ;    { command tail pointer  }
  36.           icl       : integer ;    { command tail index    }
  37.           ncl       : integer ;    { number command chars  }
  38.  
  39. begin
  40.  
  41.      cptr := ptr(128) ;       { command line tail }
  42.      ncl := ord(cptr^.len) ;
  43.      if (ncl > MAXLINE) then
  44.           ncl := MAXLINE ;
  45.  
  46.      narg := 0 ;
  47.      icl := 1 ;
  48.      while ((icl <= ncl) and (narg < MAXARG)) do begin
  49.           arg := '' ;
  50.  
  51.                               { gobble leading blanks }
  52.  
  53.           while ((icl <= ncl) and (cptr^.tail[icl] = BLANK)) do
  54.                icl := icl + 1 ;
  55.  
  56.                               { extract argument }
  57.  
  58.           while ((icl <= ncl) and (cptr^.tail[icl] <> BLANK)
  59.              and (length(arg) < MAXSTR)) do begin
  60.                arg := concat(arg,cptr^.tail[icl]) ;
  61.                icl := icl + 1
  62.           end ;
  63.  
  64.                               { skip argument tail if truncated }
  65.  
  66.           while ((icl <= ncl) and (cptr^.tail[icl] <> BLANK)) do
  67.                icl := icl + 1 ;
  68.  
  69.                               { update argument vector }
  70.  
  71.           if (length(arg) > 0) then begin
  72.                narg := narg + 1 ;
  73.                argv[narg] := arg
  74.           end
  75.      end
  76. end ;
  77.  
  78. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  79.  
  80. function GetArg (n : integer; var s : argstr; maxstr : integer) : boolean ;
  81.      {                                                     }
  82.      { Name: GetArg - GET and copy command line ARGument.  }
  83.      {                                                     }
  84.      { Version: 1.0/Turbo (tm)      Date: 1984 May 16      }
  85.      {                                                     }
  86.      { Purpose: Copy n-th argument from command line argu- }
  87.      { ment vector to string s. Note that maxstr is dummy. }
  88.      {                                                     }
  89.      { Author: D.M. Fritz-Rohner                           }
  90.      {         Post Office Box 9080                        }
  91.      {         Akron, Ohio  44305                          }
  92.      {                                                     }
  93.      { Reference: 'Software Tools in Pascal'               }
  94.      {         Brian W. Kernighan and P. J. Plauger        }
  95.      {         Addison-Wesley Publishing Company, 1981     }
  96.      {         pp. 350                                     }
  97.      {                                                     }
  98. begin
  99.      if (n > 0) and (n <= Narg) then begin
  100.           s := Argv[n] ;
  101.           GetArg := true
  102.      end
  103.      else
  104.           GetArg := false
  105. end ;
  106.