home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / bbs / pics16.ark / PICS2H1.INC < prev    next >
Encoding:
Text File  |  1987-06-11  |  11.0 KB  |  313 lines

  1. {PICS2H1.INC  Pascal Integrated Communications System }
  2. { 6/11/87  vers 1.6 Copyright 1987 by Les Archambault}
  3.  
  4. overlay procedure process_macro;
  5.   var
  6.     done,continue: boolean;
  7.     ed_macro: StrStd;
  8.     ch:char;
  9.     i:integer;
  10.   begin
  11.     done := FALSE;
  12.     repeat
  13.       writeln(USR);
  14.       st:=prompt('Macro command <D><E><S><Q><?> ',80, 'ES?');
  15.       if length(st)=1 then ch:=st[1]
  16.       else ch:='?';
  17.       case ch of
  18.         'D': writeln(USR, macro);
  19.         'E': begin
  20.                continue:=true;
  21.                Assign(macro_file,'MACRO.LST');
  22.                {$I-} Reset(macro_file); {$I+}
  23.                if ioresult=0 then
  24.                  begin
  25.                    writeln(usr);
  26.                    write(usr,'The MACRO.LST file exists and must be edited');
  27.                    writeln(usr,' with a text editor.');
  28.                    continue:=ask('do you want to edit the in-memory macro');
  29.                    close(macro_file);
  30.                  end;
  31.                if continue then
  32.                  begin
  33.                    ed_macro := macro;
  34.                    GetStr(ed_macro, ch, 79, 'ES');
  35.                    writeln(USR);
  36.                    macro := ed_macro;
  37.                    setsect(HomDrv,HomUsr);
  38.                    Write_Config_File;
  39.                  end;
  40.              end;
  41.         'S': begin
  42.                done:=true;
  43.                Assign(macro_file,'MACRO.LST');
  44.                {$I-} Reset(macro_file); {$I+}
  45.                if ioresult=0 then
  46.                  begin
  47.                    if ask('Do you want to execute the MACRO.LST file') then
  48.                      begin
  49.                        macro_file_exists:=true;
  50.                        writeln('Starting macro execution.');
  51.                        macro_in_progress:=true;
  52.                      end
  53.                    else close(macro_file);
  54.                  end
  55.                else close(macro_file);
  56.                if (not macro_file_exists) and (length(macro)>0) then
  57.                  begin
  58.                    writeln('Starting macro execution.');
  59.                    macro_in_progress:=true;
  60.                    next_inpstr:=macro;
  61.                    repeat
  62.                      i:=pos('^M',next_inpstr);
  63.                      if i>0 then
  64.                        begin
  65.                          delete(next_inpstr,i,2);
  66.                          insert(chr(13),next_inpstr,i);
  67.                        end;
  68.                    until i=0;
  69.                    cmd_queue:=next_inpstr;
  70.                    next_inpstr:='';
  71.                    mult_cmds:=true;
  72.                  end;
  73.              end;
  74.         'Q': done := TRUE
  75.       else writeln(USR, '<D>isplay, <E>dit, <S>tart, <Q>uit');
  76.       end;
  77.     until (done) or (not online);
  78.   end;
  79.  
  80. overlay procedure sys_dir;
  81. { Create system directory file }
  82.   var
  83.     TmpDrv, TmpUsr, KepDrv, KepUsr: integer;
  84.     this: SectPtr;
  85.     this_lbr,this_arc: fileptr;
  86.     t: tad_array;
  87.     DestName:Filename;
  88.     KepReq: Str10;
  89.     str: StrTAD;
  90.     dir_file: text;
  91.     include_lbr,include_arc:boolean;
  92.  
  93.   Procedure Header;
  94.   var
  95.     this: SysmPtr;
  96.     rec:integer;
  97.   begin
  98.     this := SysmBase;
  99.     while (this <> nil) and (this^.key <> 'G') do
  100.       this := this^.next;
  101.     if this^.key = 'G'
  102.       then
  103.         begin
  104.           setsect(HomDrv,HomUsr);
  105.           rec:=succ(this^.loc);
  106.           repeat
  107.               setsect(HomDrv,HomUsr);
  108.               seek(sysm_file,rec);
  109.               read(sysm_file,sysm_rec);
  110.               rec:=succ(rec);
  111.               setsect(TmpDrv,TmpUsr);
  112.               if sysm_rec[1]<>':' then writeln(Dir_file, sysm_rec);
  113.           until EOF(sysm_file) or (sysm_rec[1]=':');
  114.           setsect(TmpDrv,TmpUsr);
  115.           writeln(dir_file);
  116.         end;
  117.   end;
  118.  
  119.   procedure center(str: StrStd);
  120.   { Center string on print line }
  121.     begin
  122.       writeln(dir_file, ' ':((user_rec.columns - length(str)) div 2), str);
  123.       writeln(dir_file)
  124.     end;
  125.  
  126.   procedure write_dir;
  127.   { Write directory to file }
  128.     const
  129.       col_width = 19;
  130.     var
  131.       i, j, k, entries, rows, size, col_limit: integer;
  132.       this: FilePtr;
  133.       nodes: array[1..4] of FilePtr;
  134.       str: Str10;
  135.     begin
  136.       col_limit := max(1, user_rec.columns div col_width);
  137.       writeln(dir_file);
  138.       if in_library then entries:=libentries
  139.       else
  140.       if in_arc then entries:=arcentries
  141.       else
  142.       entries:=direntries;
  143.       if entries <> 0
  144.         then
  145.           begin
  146.             if in_library then this:=libbase
  147.             else
  148.             if in_arc then this:=arcbase
  149.             else
  150.             this:=dirbase;
  151.             if in_library then
  152.             writeln(dir_file,' ** Library: ',libreq,' Files: ',entries,
  153.             '  Space Used  ',libspace,'K')
  154.             else
  155.             if in_arc then
  156.             writeln(dir_file,' * Arc File: ',arcreq,' Files: ',entries,
  157.             '  Space Used  ',arcspace,'K')
  158.             else
  159.             writeln(dir_file, '   File area: ', SectReq, '   Files: ', entries,
  160.               '   Space used: ', DirSpace, 'k');
  161.             rows := entries div col_limit;
  162.             if 0 <> entries mod col_limit
  163.               then rows := succ(rows);
  164.             nodes[1] := this;
  165.             for i := 2 to col_limit do
  166.               begin
  167.                 for j := 1 to rows do
  168.                   this := this^.next;
  169.                 nodes[i] := this
  170.               end;
  171.             i := 1;
  172.             while not (brk or (i > rows)) do
  173.               begin
  174.                 for j := 1 to col_limit do
  175.                   begin
  176.                     this := nodes[j];
  177.                     if (i + rows * pred(j)) <= entries
  178.                       then
  179.                         begin
  180.                           size := this^.fsize shr 3;
  181.                           if (this^.fsize mod 8) <> 0
  182.                             then size := succ(size);
  183.                           str := intstr(size, 4) + 'k ';
  184.                           if size>0 then
  185.                           write(dir_file, this^.fname, str)
  186.                           else write(dir_file,'                 ');
  187.                           if j < col_limit
  188.                             then write(dir_file, fence, ' ')
  189.                             else writeln(dir_file)
  190.                         end
  191.                       else writeln(dir_file);
  192.                     nodes[j] := nodes[j]^.next   { Go to next on list }
  193.                   end;
  194.                 i := succ(i)
  195.               end
  196.           end;
  197.       if j <> col_limit
  198.         then writeln(dir_file)
  199.     end;
  200.  
  201.   begin { sys_dir }
  202.     writeln(usr);
  203.     write(usr,'Select File Section where SYSTEM.DIR will be written:');
  204.     DestName:=Get_Section_name(' ');
  205.     writeln(usr);
  206.     include_lbr:= ask('Include Library breakdown');
  207.     include_arc:= ask('Include Arc breakdown');
  208.     if ch<>ETX then
  209.       begin
  210.         writeln(usr);
  211.         write(USR, 'Building system directory...Please wait...');
  212.         KepDrv := SetDrv;
  213.         KepUsr := SetUsr;
  214.         KepReq := SectReq;
  215.         FindSect(DestName, TmpDrv, TmpUsr, OK);
  216.         if not OK then
  217.           begin
  218.             TmpDrv := HomDrv;
  219.             TmpUsr := HomUsr
  220.           end;
  221.         SetSect(TmpDrv, TmpUsr);
  222.         Assign(dir_file, 'SYSTEM.DIR');
  223.         {$I-} Rewrite(dir_file) {$I+};
  224.         OK := (IOresult = 0);
  225.         if OK then
  226.           begin
  227.             header;
  228.             center('Complete System Directory Listing');
  229.             center('as of');
  230.             GetTAD(t);
  231.             setsect(homdrv,homusr);
  232.             str := FormTAD(t);
  233.             setsect(tmpdrv,tmpusr);
  234.             center(str);
  235.             this := SectBase;
  236.             while (this <> nil) and (not brk) and (online) do
  237.               begin
  238.                 if this^.SectAccs <= val_acc then
  239.                   begin
  240.                     SectReq := this^.SectName;
  241.                     SetDrv  := this^.SectDrive;
  242.                     SetUsr  := this^.SectUser;
  243.                     SetSect(HomDrv, HomUsr);
  244.                     ReadDir(DirEntries, DirSpace, DirBase);
  245.                     SetSect(TmpDrv, TmpUsr);
  246.                     write_dir;
  247.                     if include_lbr then
  248.                       begin
  249.                         this_lbr:=dirbase;
  250.                         while this_lbr<>Nil do
  251.                           begin
  252.                             if copy(this_lbr^.fname,10,3)='LBR' then
  253.                               begin
  254.                                 libreq:=this_lbr^.fname;
  255.                                 while pos(' ',libreq)>0 do
  256.                                  delete(libreq,pos(' ',libreq),1);
  257.                                 setsect(homdrv,homusr);
  258.                                 LibReadDir(libentries,libspace,libbase);
  259.                                 setsect(tmpdrv,tmpusr);
  260.                                 write_dir;
  261.                                 if in_library then
  262.                                   begin
  263.                                      in_library:=false;
  264.                                      setsect(setdrv,setusr);
  265.                                      close(libr_file);
  266.                                      setsect(tmpdrv,tmpusr);
  267.                                    end;
  268.                               end;
  269.                             this_lbr:=this_lbr^.next;
  270.                           end;
  271.                       end; {include lbr}
  272.  
  273.                     if include_arc then
  274.                       begin
  275.                         this_arc:=dirbase;
  276.                         while this_arc<>Nil do
  277.                           begin
  278.                             if copy(this_arc^.fname,10,3)='ARC' then
  279.                               begin
  280.                                 arcreq:=this_arc^.fname;
  281.                                 while pos(' ',arcreq)>0 do
  282.                                  delete(arcreq,pos(' ',arcreq),1);
  283.                                 setsect(homdrv,homusr);
  284.                                 ArcReadDir(Arcentries,Arcspace,Arcbase);
  285.                                 setsect(tmpdrv,tmpusr);
  286.                                 write_dir;
  287.                                 if in_arc then
  288.                                   begin
  289.                                      in_arc:=false;
  290.                                      setsect(setdrv,setusr);
  291.                                      close(arc_file);
  292.                                      setsect(tmpdrv,tmpusr);
  293.                                    end;
  294.                               end;
  295.                             this_arc:=this_arc^.next;
  296.                           end;
  297.                       end; {include arc}
  298.                   end;     {section<access}
  299.                   this := this^.next
  300.               end; {this<>nil}
  301.             Close(dir_file);
  302.             SetSect(Homdrv, HomUsr);
  303.             SectReq := KepReq;
  304.             SetDrv := KepDrv;
  305.             SetUsr := KepUsr;
  306.             ReadDir(DirEntries, DirSpace, DirBase)
  307.           end;   {file opened ok}
  308.         writeln(USR);
  309.       end;
  310.   end;
  311.  
  312. {end of PICS2H1.INC }
  313.