home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pctech / 1986_05 / inout.pas < prev    next >
Pascal/Delphi Source File  |  1986-03-03  |  3KB  |  113 lines

  1.  
  2. { Input and Output procedures follow.  Interface to standard I/O included. }
  3.  
  4. TYPE 
  5.      regpack = record    { used for Standard I/O DOS calls }
  6.                     ax,bx,cx,dx,bp,si,di,ds,es,flg : integer
  7.                end ;
  8.      ary = byte;
  9.      xpt = record
  10.                case integer of
  11.                      1: (ptx : ^ary) ;
  12.                      2: (qq,rr :integer)
  13.                   end;
  14.      maxstr = string[255];
  15. VAR
  16.  register : regpack;
  17.  xx : ary;
  18.  here : xpt;
  19.  b: byte;           
  20.  
  21. procedure putstdout(wr: byte);
  22.  
  23. {  Procedure to put the next byte of Standard Output out to
  24.    MS DOS 2.x Standard Output file. }
  25.  
  26.    begin
  27.      here.ptx := addr(xx);
  28.      xx  := wr;
  29.      register.ds := here.rr;
  30.      register.dx := here.qq;
  31.      register.cx := 1;
  32.      register.bx := 1;
  33.      register.ax := $4000;
  34.      intr($21,register);
  35.    end;
  36.  
  37. procedure getstdin(var ip: byte);
  38. {
  39.     Procedure to get next byte of input from DOS 2.0, 2.1
  40.     Standard Input file.  This filter uses only ascii characters
  41.     (maximum decimal value 127) so 255 was chosen as the
  42.     end-of-input flag.
  43. }
  44. begin
  45.      here.ptx := addr(xx);
  46.      register.ds := here.rr;
  47.      register.dx := here.qq;
  48.      register.cx := 1;
  49.      register.bx := 0;
  50.      register.ax := $3F00;
  51.      intr($21,register);
  52.      if register.ax = 0 then ip:= 255;
  53.      if register.ax <>0 then ip:= xx;
  54. end;
  55.  
  56. function getline(var lin: maxstr): boolean;
  57. {
  58.     Reads a line from the Standard Input file and loads it
  59.     into the string LIN.  The end of line identifier ENDSTR
  60.     is appended to each line.  Unprintable characters are
  61.     ignored.
  62. }
  63. begin
  64.     getline:=false;
  65.     lin:='';
  66.     repeat
  67.        getstdin(b);
  68.        case b of
  69.                32..125: if length(lin)<254 then lin:=lin+chr(b);
  70.                eof_num: exit;
  71.            end; {case}
  72.     until b=eoln1_num;
  73.     lin:=lin+ENDSTR;
  74.     getline:=true;
  75. end;
  76.  
  77. procedure putline(lin: maxstr);
  78. {
  79.    Feeds a line to Standard Output byte by byte, adding
  80.    <carrage return> <line feed> at the end.
  81. }
  82. var i: integer;
  83. begin
  84.      i:=1;
  85.      while lin[i]<>ENDSTR do
  86.        begin
  87.           putstdout( ord(lin[i]) );
  88.           i:=i+1;
  89.        end;
  90.      putstdout(eoln1_num);
  91.      putstdout(eoln2_num);
  92. end;
  93.  
  94. function getarg(var arg: maxstr) : boolean;
  95. {
  96.    Command line parameters are returned in string ARG.
  97.    Spaces within the Regular Expression pattern are
  98.    preserved, but the Turbo parameter functions ignore
  99.    leading and trailing spaces.
  100. }
  101. var i, arg_num: integer;
  102. begin
  103.   getarg:=false;  arg:='';  arg_num:=paramcount;
  104.   if arg_num=0 then exit
  105.       else
  106.         for i:=1 to arg_num do
  107.           begin                   
  108.             arg:=arg+paramstr(i); 
  109.             if (arg_num>1) and (i<arg_num) then arg:=arg+' ';
  110.           end;
  111.   getarg:=true;
  112. end;
  113.