home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol085 / xsub.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1984-04-29  |  5.2 KB  |  209 lines

  1. PROGRAM SUBMIT_DEMO;
  2. {
  3.   * PROGRAM TITLE:        Submittable Demo
  4.  
  5.   * WRITTEN BY:            Raymond E. Penley
  6.  
  7.   * DATE WRITTEN:        May 14, 1982
  8.  
  9.   * SUMMARY:
  10.     Execution of external command programs e.g. PIP,
  11.     STAT, DIR via a submit program entirely generated
  12.     within the users program.
  13. }
  14.  
  15. type
  16.   string0   = string 0;
  17.   string128 = string 128;
  18.   string255 = string 255;
  19.   xsub        = array [1..10] of string128;{ for submit processing }
  20.  
  21. var
  22.   asub         : xsub;
  23.   cmdchar    : char;
  24.   terminated : boolean;
  25.  
  26. procedure setlength ( var source: string0; leng: integer ); external;
  27.  
  28. function length ( source: string255 ): integer;    external;
  29.  
  30. procedure submit ( asub : xsub );
  31. {
  32.   * processes the strings in the array asub into a file of commands
  33.     that will be processed by the CP/M console command processor (CCP).
  34.   * constructs the file in reverse order.
  35.   * all records are exactly 1 sector/128 bytes long.
  36.   * requires:
  37.     - last command string in asub[] must be a null string.
  38.     - asub : array [1..xx] of string128
  39.     - external procedure length()
  40. }
  41. const    max    = 128;        { one record length / one sector }
  42. type    string128 = string 128;
  43.     line    = string128;
  44. var    count    : integer;
  45.     fsub      : file of line;
  46.     idx    : integer;
  47.  
  48.     procedure put_sub ( inbuffer : line );
  49.     { write records <strings> to our own submit file        }
  50.     { record format:                        }
  51.     { |length byte|command line|null byte|padding to 128 bytes| }
  52.     var    tbuffer : line;
  53.     begin
  54.       tbuffer := ' ';                { set up.     }
  55.       tbuffer[1] := chr ( length(inbuffer) );    { length byte }
  56.       append(tbuffer,inbuffer);            { command line }
  57.       repeat append(tbuffer,chr(0))            { pad to length }
  58.       until length(tbuffer)=max;
  59.       write ( fsub, tbuffer )
  60.     end{put_sub};
  61.  
  62. begin { submit }
  63.   { OPEN file '$$$.SUB' for WRITE assign fsub }
  64.     rewrite ( '$$$.SUB', fsub );
  65.   { see how many commands to process }
  66.   count := 0;
  67.   repeat count := count + 1
  68.   until length(asub[count])=0;
  69.   count := count - 1;
  70.   { must force Pascal/Z to dump an even # of 128 byte buffers. ugh! }
  71.   if odd(count) then count := count + 1;
  72.   { write commands to file in reverse order }
  73.   for idx:=count downto 1 do
  74.     put_sub ( asub[idx] )
  75. end{submit};
  76.  
  77.  
  78. procedure build_sub ( cmdchar: char );
  79. {
  80.   * builds the submit commands in the array asub
  81.     asub : array [1..xx] of string128;
  82.   * requires:
  83.     external procedure setlength()
  84. }
  85. const    drives    = 'WHICH DRIVE ( A-P ) ? ';
  86. type    string128 = string 128;
  87.     line    = string128;
  88. var    ch    : char;
  89.     Cmd    : line;
  90.     dest    : char;
  91.     filename: string 14;
  92.     idx    : integer;
  93.     source    : char;
  94.  
  95. begin { build_sub }
  96.   for idx:=1 to 10 do        { set asub[] to all nulls }
  97.     setlength ( asub[idx],0 );
  98.  
  99.   case cmdchar of
  100.     '3':{files/directory}{ command = DIR A: }
  101.     begin
  102.       write ( drives );
  103.       readln ( ch );
  104.       Cmd := 'DIR A:';
  105.       Cmd[5] := ch
  106.     end;
  107.     '4':{status/stat}{ command = STAT A:*.* }
  108.     begin
  109.       write ( drives );
  110.       readln ( ch );
  111.       Cmd := 'STAT A:*.*';
  112.       Cmd[6] := ch
  113.     end;
  114.     '5':{Move/Copy/PIP}{ command = PIP B:=A:filename[v]        }
  115.                { command = PIP A:filename=filename[v]    }
  116.     { simplistic copy operation:        }
  117.     { additional valid PIP commands    can be added }
  118.     {    PIP PRN:=myletter[NT8]        }
  119.     {    PIP CON:=b:sample.pas        }
  120.     {    PIP a:newname=b:oldname        }
  121.     begin
  122.       write ( 'ENTER FILE NAME TO BE COPIED - ' );
  123.       readln ( filename );
  124.       write ( 'WHERE WILL I FIND THIS FILE? - ' );
  125.       readln ( source );
  126.       write ( 'WHERE AM I TO PUT THE  FILE? - ' );
  127.       readln ( dest );
  128.       if dest=source then begin
  129.         Cmd := 'PIP A:';
  130.         Cmd[5] := dest;
  131.         append(Cmd,filename);
  132.         append(Cmd,'=');
  133.         append(Cmd,filename)
  134.       end
  135.       else begin
  136.         Cmd := 'PIP B:=A:';
  137.         Cmd[5] := dest;
  138.         Cmd[8] := source;
  139.         append(Cmd,filename)
  140.       end;
  141.       append(Cmd,'[v]' );    { verify option }
  142.     end
  143.   end{case};
  144.  
  145.   { construct the array of submit commands }
  146.   idx := 0;
  147.   idx := idx + 1;
  148.   asub[idx] := Cmd;        { command string }
  149.   if cmdchar<>'5' then begin
  150.      idx := idx + 1;
  151.      asub[idx] := 'PAUSE';    { pauses for any console input }
  152.   end;
  153.   idx := idx + 1;
  154.   asub[idx] := 'XSUB';        { file we want to chain back to }
  155.  
  156.   { write the submitable file }
  157.   submit ( asub )
  158. end{ build_sub };
  159.  
  160.  
  161. procedure do_menu;
  162. var    valid : boolean;
  163. begin        {$C+}{ allow console termination via ctrl-C here }
  164.   repeat
  165.     valid := true;
  166.     writeln;
  167.     writeln ( ' ':12, '(1)  ADD NEW RECORDS' );
  168.     writeln ( ' ':12, '(2)  CHANGE A RECORD' );
  169.     writeln ( ' ':12, '(3)  DIRECTORY' );
  170.     writeln ( ' ':12, '(4)  DISK STATUS' );
  171.     writeln ( ' ':12, '(5)  COPY FILES' );
  172.     writeln ( ' ':12, '(6)  TERMINATE PROGRAM' );
  173.     writeln;
  174.     write ( 'ENTER SELECTION: ' );
  175.     readln ( cmdchar );
  176.     if not ( cmdchar in ['1'..'6'] ) then begin
  177.        writeln ( 'SORRY INVALID SELECTION. TRY AGAIN' );
  178.        valid := false
  179.     end
  180.   until valid
  181. end{do_menu};    {$C-}{ disable ctrl-C keypress checking again }
  182.  
  183.  
  184. procedure do_add;
  185. begin
  186. end;
  187.  
  188. procedure do_change;
  189. begin
  190. end;
  191.  
  192.  
  193. begin { main program }
  194.   terminated := false;
  195.   while not terminated do begin
  196.      do_menu;
  197.      case cmdchar of
  198.     '1':    do_add;
  199.     '2':    do_change;
  200.     '3','4','5':
  201.         begin
  202.           build_sub ( cmdchar );
  203.           terminated := true
  204.         end;
  205.     '6':    terminated := true
  206.      end{case}
  207.   end{while}
  208. end{SUBMIT_DEMO}.
  209.