home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / WWIV310S.ZIP / DOS.PAS < prev    next >
Pascal/Delphi Source File  |  1986-04-01  |  42KB  |  1,436 lines

  1. program dos;
  2.  
  3. {$V-} {$C-}
  4. TYPE j=array[1..8] of string[14];
  5.  
  6. CONST strlen=160;
  7.       comnum=1;
  8.       maxbaud=1200;
  9.       maxusers=300;
  10.       dsaves : Integer = 0;
  11.       buffer_Max    = 5120;
  12.       comptyp:j=('IBM','APPLE','TRS-80','Z-80 CP/M','COMMODORE','ATARI',
  13.                  'DUMB TERMINAL','OTHER');
  14.  
  15. TYPE str=string[strlen];
  16.      restrictions=(rlogon,rchat,rvalidate,rbackspace,ramsg,rpostan,
  17.                    rpost,remail,rvoting,rmsg);
  18.      acrq='@'..'G';
  19.      newtyp=(rp,lt,rm);
  20.      deflts=(spcsr,onekey,wordwrap,pause);
  21.      anontyp=(no,yes,forced,dearabby);
  22.      ansttype=(postn,emailn,pana,sanm,cosysop,lcosysop);
  23.      opts=(alert,smw,nomail);
  24.      pnr=record name:string[40]; number:string[14]; hs:byte; end;
  25.      slr=record
  26.            ttime:byte;
  27.            mallowed:integer;
  28.            emails,posts:byte;
  29.            anst:set of ansttype;
  30.          end;
  31.      messages=record
  32.                 ltr:char;
  33.                 number:integer;
  34.                 ext:byte;
  35.               end;
  36.      smalrec=record
  37.                name:string[25];
  38.                number:integer;
  39.              end;
  40.      userrec=record
  41.                name:string[25];
  42.                realname:string[14];
  43.                deleted:boolean;
  44.                pw:string[8];
  45.                ph:string[12];
  46.                waiting:byte;
  47.                laston:string[10];
  48.                loggedon:integer;
  49.                msgpost:integer;
  50.                emailsent:integer;
  51.                feedback:integer;
  52.                linelen:byte;
  53.                pagelen:byte;
  54.                defaults:set of deflts;
  55.                ontoday:byte;
  56.                illegal:byte;
  57.                cursor:string[10];
  58.                sl:byte;
  59.                ac:set of restrictions;
  60.                ar:set of acrq;
  61.                qscan:array[1..19] of messages;
  62.                qscn:array[1..19] of boolean;
  63.                macro:array[1..2] of string[79];
  64.                comptype:byte;
  65.                option:set of opts;
  66.                vote:array[1..9] of byte;
  67.                sbn:byte;
  68.                dsl:byte;
  69.                uploads,downloads:integer;
  70.                uk,dk:integer;
  71.              end;
  72.       boardrec=record
  73.                  name:string[25];
  74.                  filename:string[12];
  75.                  sl:byte;
  76.                  maxmsgs:byte;
  77.                  pw:string[10];
  78.                  anonymous:anontyp;
  79.                  ar:acrq;
  80.                  key:char;
  81.                end;
  82.       msgstat=(validated,unvalidated,deleted);
  83.       messagerec=record
  84.                    title:string[30];
  85.                    messagestat:msgstat;
  86.                    message:messages;
  87.                    owner:integer;
  88.                    date:integer;
  89.                    mage:byte;
  90.                  end;
  91.       systatrec=record
  92.                   boardpw:string[8];
  93.                   sysoppw:string[8];
  94.                   hmsg:messages;
  95.                   users:integer;
  96.                   lastdate:string[8];
  97.                   callernum:integer;
  98.                   activetoday:integer;
  99.                   callstoday:integer;
  100.                   msgposttoday:integer;
  101.                   emailtoday:integer;
  102.                   fbacktoday:integer;
  103.                   uptoday:integer;
  104.                   closedsystem:boolean;
  105.                 end;
  106.       blk=array[1..255] of byte;
  107.       mailrec=record
  108.                 title:string[30];
  109.                 from,destin:integer;
  110.                 msg:messages;
  111.                 date:integer;
  112.                 mage:byte;
  113.               end;
  114.       gft=record
  115.             num:integer;
  116.             title:string[40];
  117.             filen:string[12];
  118.           end;
  119.       charfil=text;
  120.       smr=record
  121.             msg:str;
  122.             destin:integer;
  123.           end;
  124.       vdatar=record
  125.                question:string[79];
  126.                numa:integer;
  127.                answ:array[0..9] of record
  128.                       ans:string[25];
  129.                       numres:integer;
  130.                     end;
  131.              end;
  132.       regs=record ax,bx,cx,dx,bp,si,di,ds,es,flags:integer; end;
  133.       ulrec=record
  134.               name:string[25];
  135.               filename:string[12];
  136.               password:string[10];
  137.               dsl:byte;
  138.               maxfiles:integer;
  139.             end;
  140.       strptr=^strrec;
  141.       strrec=record
  142.                i:str;
  143.                next,last:strptr;
  144.              end;
  145.  
  146. var sf:file of smalrec;
  147.     uf:file of userrec;
  148.     bf:file of boardrec;
  149.     mf:file of messagerec;
  150.     mailfile:file of mailrec;
  151.     sysopf:charfil;
  152.     slf:file of slr;
  153.     seclev:array[0..255] of slr;
  154.     systatf:file of systatrec;
  155.     systat:systatrec;
  156.     sr:smalrec;
  157.     thisline,chatr,buf,spd,irt,lastname,ll,cursor,ix:str;
  158.     thisuser,user:userrec;
  159.     boards:array[1..19] of boardrec;
  160.     fw,extramsgs,mread,board,numboards,t,usernum:integer;
  161.     pap,lil,realsl,ftoday,ptoday,etoday:integer;
  162.     c,ID:char;
  163.     hungup,useron,next,chatcall,expert,doneday,echo,hangup,incom,outcom:boolean;
  164.     extratime,timeon:real;
  165.     macok,lan,enddayf,ch,quit:boolean;
  166.     buffer:Array[0..buffer_Max] of Char;
  167.     comport,base:Integer;
  168.     Async_Irq:Integer;
  169.     buffer_Head,buffer_tail,buffer_newtail:Integer;
  170.     smf:file of smr;
  171.     srl:array[0..maxusers] of smalrec;
  172.     vqu:array[1..9] of boolean;
  173.     ret:byte absolute cseg:$0080;
  174.     ldate:integer;
  175.     maxspd:integer;
  176.     cmd:char;
  177.     help:array[1..25000] of char;
  178.     helpi:array['0'..'^'] of integer;
  179.     helpl:char;
  180.     ihelp:boolean;
  181.     cf:text; cfo,okt:boolean;
  182.     elevel:byte;
  183.     topheap:^byte;
  184.     i1:str;
  185.     i:array[1..9] of string[79];
  186.     donedos,dld,d1,d2,done,abort:boolean;
  187.     c1,c2,c3:integer;
  188.     f,f1:file of byte;
  189.     x:byte;
  190.     cd:str;
  191.     s1,s2,s3:str;
  192.     all:boolean;
  193.     chksum:byte;
  194.     crc:integer;
  195.     ucrc,ymodem:boolean;
  196.     fat,dta:string[44];
  197.     ft:byte;
  198.     lastvar:byte;
  199.  
  200. label reent;
  201.  
  202. {$I COMMON.PAS}
  203.  
  204. function tcheck(s:real; i:integer):boolean;
  205. var r:real;
  206. begin
  207.   r:=timer;
  208.   if r<s then r:=r+86400.0;
  209.   if trunc(r-s)>i then tcheck:=false else tcheck:=true;
  210. end;
  211.  
  212. function tchk(s:real; i:real):boolean;
  213. var r:real;
  214. begin
  215.   r:=timer;
  216.   if r<s then r:=r+86400.0;
  217.   if (r-s)>i then tchk:=false else tchk:=true;
  218. end;
  219.  
  220. {$I DLP1.PAS}
  221.  
  222. function okfile(fn:str):boolean;
  223. begin
  224.   okfile:=(pos('.LST',FN)=0) and (pos('.DAT',fn)=0) and (pos('.   ',fn)=0)
  225.           and (pos('.FIL',fn)=0) and (pos('.TRM',fn)=0) and (pos('.LOG',fn)=0);
  226.   if (not so) and (pos('.TXT',fn)=0) and (pos('.MSG',fn)=0)and (pos('.???',FN)=0)
  227.     then okfile:=false;
  228. end;
  229.  
  230. procedure printfile(fn:str);
  231. var fil:text;
  232.     i:str;
  233.     abort,next:boolean;
  234. begin
  235.  if not hangup then begin
  236.   assign(fil,fn);
  237.   {$I-} reset(fil); {$I+}
  238.   if ioresult<>0 then print('File not found.') else begin
  239.     abort:=false;
  240.     while not eof(fil) and (not abort) and (not hangup) do begin
  241.       readln(fil,i);
  242.       if i[length(i)]<>#1 then i:=i+#1;
  243.       printa(i,abort,next);
  244.     end;
  245.     close(fil);
  246.   end;
  247.   nl;nl;
  248.  end;
  249. end;
  250.  
  251. procedure inli(var i:str);
  252. var cp,rp:integer; c:char; cv,cc:integer;
  253. begin
  254.   rp:=1; cp:=1;
  255.   i:='';
  256.   if ll<>'' then begin prompt(ll); i:=ll; ll:=''; cp:=length(i)+1; rp:=cp;end;
  257.   repeat
  258.     getkey(c); skey(c);
  259.     case ord(c) of
  260.       32..126:if (cp<strlen) and (rp<thisuser.linelen) then begin
  261.                 i[cp]:=c; cp:=cp+1; rp:=rp+1; outkey(c); thisline:=thisline+c;
  262.               end;
  263.             127,8:if cp>1 then begin c:=chr(8);
  264.                 if i[cp-1]=chr(8) then begin prompt(' '); rp:=rp+1; end else
  265.                  if i[cp-1]<>chr(10) then
  266.                    begin prompt(c+' '+c); rp:=rp-1; end;
  267.                 cp:=cp-1;
  268.               end;
  269.            24:begin
  270.                 cp:=1; for cv:=1 to rp-1 do prompt(chr(8)+' '+chr(8));
  271.                 rp:=1;
  272.               end;
  273.            23:if cp>1 then repeat
  274.                 prompt(chr(8)+' '+chr(8)); rp:=rp-1; cp:=cp-1;
  275.               until (cp=1) or (i[cp]=' ') or (i[cp]=chr(8));
  276.            14:if (not (rbackspace in thisuser.ac)) and (rp>1) and (cp<strlen) then begin
  277.                 prompt(chr(8)); i[cp]:=chr(8); cp:=cp+1; rp:=rp-1;
  278.               end;
  279.            10:if (not (rbackspace in thisuser.ac)) and (cp<strlen) then begin
  280.                 prompt(c); i[cp]:=c; cp:=cp+1;
  281.               end;
  282.             9:begin
  283.                 cv:=5-(cp mod 5); if (cp+cv<strlen) and (rp+cv<thisuser.linelen) then
  284.                   for cc:=1 to cv do begin
  285.                     rp:=rp+1; prompt(' ');
  286.                     i[cp]:=' '; cp:=cp+1;
  287.                   end;
  288.               end;
  289.   end;
  290.   until (c=chr(13)) or ((rp=thisuser.linelen) and (wordwrap in thisuser.defaults)) or hangup;
  291.   i[0]:=chr(cp-1);
  292.   if c<>chr(13) then begin
  293.     cv:=cp-1;
  294.     while (cv>0) and (i[cv]<>' ') and (i[cv]<>chr(8))do cv:=cv-1;
  295.     if (cv>(rp div 2)) and (cv<>cp-1) then begin
  296.       ll:=copy(i,cv+1,cp-cv); for cc:=cp-2 downto cv do prompt(chr(8));
  297.       for cc:=cp-2 downto cv do prompt(' ');
  298.       i[0]:=chr(cv-1);
  299.     end;
  300.   end;
  301.   nl;
  302.   if c=chr(13) then i:=i+chr(1);
  303. end;
  304.  
  305. procedure ul;
  306. var dok,abort:boolean; i:str;
  307. f:file;
  308. begin
  309.   writeln; writeln; ft:=255;
  310.   prompt('Send file: ');
  311.   input(i,12);
  312.   i:='dloads\'+i;
  313.   assign(f,i);
  314.   {$I-} reset(f); {$I+}
  315.   if ioresult=0 then begin
  316.     close(f);
  317.     send1(i,dok,abort);
  318.   end else print('File not found.');
  319.   incom:=false;
  320.   hangup:=false;
  321.   outcom:=false;
  322.   writeln;
  323. end;
  324.  
  325. procedure dl;
  326. var dok:boolean; i:str; f:file;
  327. begin
  328.   writeln; writeln; ft:=255;
  329.   prompt('Receive file: ');
  330.   input(i,12);
  331.   i:='dloads\'+i;
  332.   assign(f,i);
  333.   {$I-} reset(f); {$I+}
  334.   if ioresult<>0 then begin
  335.     {$I-} rewrite(f); {$I+}
  336.     if ioresult=0 then begin
  337.       close(f);
  338.       dok:=true;
  339.     end else begin
  340.       dok:=false;
  341.       print('Illegal filename.');
  342.     end;
  343.   end else begin
  344.     close(f);
  345.     print(#7+'File already exists.');
  346.     prompt('Overwrite? ');
  347.     dok:=yn;
  348.   end;
  349.   if dok then
  350.     receive1(i,dok);
  351.   hangup:=false;
  352.   incom:=false;
  353.   outcom:=true;
  354. end;
  355.  
  356. procedure term;
  357. var c:char; done,bac,eco:boolean;
  358.     hs:byte;
  359.     ns:array[1..9] of pnr;
  360.     fil:file of pnr;
  361.     lnd,i:integer;
  362.     maxs:byte;
  363.  
  364.   procedure pc(s:str);
  365.   var i:integer;
  366.   begin
  367.     s:=s+chr(13);
  368.     for i:=1 to length(s) do o1(s[i]);
  369.   end;
  370.  
  371.   procedure cs(hs:byte);
  372.   begin
  373.     writeln;
  374.     case hs of
  375.       0:begin
  376.           set_baud(300);
  377.           writeln('--- 300 BAUD ---');
  378.         end;
  379.       1:begin
  380.           set_baud(1200);
  381.           writeln('=== 1200 BAUD ===');
  382.         end;
  383.       2:begin
  384.           set_baud(2400);
  385.           writeln('=-= 2400 BAUD =-=');
  386.         end;
  387.     end;
  388.     writeln;
  389.   end;
  390.  
  391.   procedure tab(x:integer);
  392.   begin
  393.     while wherex<x do write(' ');
  394.   end;
  395.  
  396.   procedure dial;
  397.   var i:integer; done:boolean; c:char; s:str;
  398.   begin
  399.     done:=false;
  400.     repeat
  401.       writeln;
  402.       write('Dial: 1-9,M,Q,? : ');
  403.       repeat
  404.         read(kbd,c); c:=upcase(c);
  405.       until c in ['1'..'9','M','Q','?'];
  406.       writeln(c); writeln;
  407.       if c='Q' then begin done:=true; writeln; writeln('Back in term mode.'); writeln; end;
  408.       if c='?' then begin
  409.         clrscr;
  410.         writeln('N NAME                                      NUMBER         SPD');
  411.         writeln('- ----------------------------------------  -------------  ----');
  412.         for i:=1 to 9 do begin
  413.           write(i,' ',ns[i].name); tab(44); write(ns[i].number); tab(60);
  414.           case ns[i].hs of
  415.             0:writeln(' 300');
  416.             1:writeln('1200');
  417.             2:writeln('2400');
  418.           end;
  419.         end;
  420.       end;
  421.       if c='M' then begin
  422.         write('Which (1-9) ? ');
  423.         repeat
  424.           read(kbd,c);
  425.         until c in ['1'..'9',#13];
  426.         if c in ['1'..'9'] then begin
  427.           i:=value(c);
  428.           clrscr;
  429.           writeln('Number: ',i);
  430.           writeln;
  431.           writeln('Old Name: ',ns[i].name);
  432.           write('New Name: '); inputl(s,40);
  433.           if s<>'' then ns[i].name:=s;
  434.           writeln;
  435.           writeln('Old Number: ',ns[i].number);
  436.           write('New Number: '); input(s,14);
  437.           if s<>'' then ns[i].number:=s;
  438.           writeln;
  439.           write('Old Speed: ');
  440.           case ns[i].hs of
  441.             0:writeln(' 300');
  442.             1:writeln('1200');
  443.             2:writeln('2400');
  444.           end;
  445.           writeln;
  446.           writeln('0 =  300');
  447.           if maxs>0 then writeln('1 = 1200');
  448.           if maxs>1 then writeln('2 = 2400');
  449.           write('New speed? '); read(kbd,c); if (c<'0') or (c>'2') then c:=#0;
  450.           writeln(c); writeln;
  451.           if (value(''+c)<=maxs) and (c<>#0)  then ns[i].hs:=value(''+c);
  452.           reset(fil); seek(fil,i-1); write(fil,ns[i]); close(fil);
  453.           c:=' ';
  454.         end;
  455.       end;
  456.       if c in ['1'..'9'] then begin
  457.         done:=true;
  458.         i:=value(c);
  459.         clrscr; lnd:=i;
  460.         hs:=ns[i].hs; cs(hs);
  461.         writeln('Dialing: ',ns[i].name);
  462.         writeln('At     : ',ns[i].number);
  463.         writeln;
  464.         pc('ATDT'+ns[i].number);
  465.       end;
  466.     until done;
  467.   end;
  468.  
  469.   function cd:boolean;
  470.   begin
  471.     cd:=((port[base+6] and 128)<>0)
  472.   end;
  473.  
  474.   procedure hang;
  475.   var rl:real;
  476.   begin
  477.     dump;
  478.     term_ready(false); rl:=timer;
  479.     while cd and (abs(timer-rl)<1.5) do;
  480.     term_ready(true);
  481.   end;
  482.  
  483.   procedure redial;
  484.   var c:char; done:boolean; try:integer; rl,rl1:real; int:integer; i,i1:str;
  485.   begin
  486.     clrscr; try:=0;
  487.     hs:=ns[lnd].hs; cs(hs); rl:=timer;
  488.     pc('ATM0Q0V0E0S7=16');
  489.     writeln('Re-Dialing: ',ns[lnd].name);
  490.     writeln('At        : ',ns[lnd].number);
  491.     writeln('Try       : 0');
  492.     writeln('Time      : 00:00');
  493.     writeln; writeln('Hit <ESC> to abort'); done:=false;
  494.     delay(500); dump;
  495.     repeat
  496.       pc('ATDT'+ns[lnd].number);
  497.       try:=try+1;
  498.       gotoxy(13,6); writeln(try);
  499.       rl1:=timer; if rl1<rl then rl:=rl+24.0*3600.0;
  500.       int:=trunc(rl1-rl);
  501.       i:=cstr(int div 60);
  502.       if length(i)=1 then i:='0'+i;
  503.       i1:=cstr(int mod 60);
  504.       if length(i1)=1 then i1:='0'+i1;
  505.       i:=i+':'+i1;
  506.       gotoxy(13,7); writeln(i); dump;
  507.       while (not done) and (not commpressed) do begin
  508.         if keypressed then begin
  509.           read(kbd,c); if c=#27 then begin done:=true; o1('A'); end;
  510.         end;
  511.       end;
  512.       delay(100);
  513.       if cd then done:=true else dump;
  514.     until done;
  515.     if cd then for try:=1 to 6 do begin
  516.       sound(1200); delay(200); nosound; delay(100);
  517.     end else begin
  518.       delay(500); pc('ATM1Q0V1E1S7=30');
  519.     end;
  520.     gotoxy(1,14); writeln; writeln('Back in term mode...');
  521.   end;
  522.  
  523.   procedure help;
  524.   var x,y,c:integer;
  525.   begin
  526.     x:=wherex; y:=wherey;
  527.     for c:=1 to 10 do begin
  528.       gotoxy(42,c); write(#$b3);
  529.     end;
  530.     gotoxy(42,11); write(#$c0);
  531.     while wherex<>1 do write(#$c4);
  532.     window(43,1,80,10); clrscr;
  533.     window(45,1,80,10); gotoxy(1,1);
  534.     writeln('Alt-B = backspacing toggle');
  535.     writeln('Alt-C = clear screen');
  536.     writeln('Alt-D = dial number');
  537.     writeln('Alt-E = echo toggle');
  538.     writeln('Alt-H = hang up phone');
  539.     writeln('Alt-Q = redial last number');
  540.     writeln('Alt-S = speed toggle');
  541.     writeln('Alt-X = exit');
  542.     writeln('PgUp  = send file from dloads');
  543.     write('PgDn  = receive file into dloads');
  544.     window(1,1,80,25); gotoxy(x,y);
  545.   end;
  546.  
  547. begin
  548.   clrscr; lnd:=0; eco:=false;
  549.   if maxspd=300 then maxs:=0;
  550.   if maxspd=1200 then maxs:=1;
  551.   if maxspd=2400 then maxs:=2;
  552.   assign(fil,'gfiles\numbers.trm');
  553.   reset(fil);
  554.   for i:=1 to 9 do read(fil,ns[i]);
  555.   close(fil);
  556.   writeln('Press [HOME] for help');
  557.   writeln;
  558.   hs:=maxs; cs(hs); bac:=false;
  559.   done:=false; mem[$40:$17]:=mem[$40:$17] or $40;
  560.   pc('ATQ0V1E1S2=43M1S11=50');
  561.   repeat
  562.     if commpressed then begin
  563.       c:=cinkey; if c=chr(12) then clrscr else
  564.         if c=chr(8) then begin
  565.           bs; if bac then begin write(' '); bs; end
  566.         end else if c<>chr(0) then write(c);
  567.       end;
  568.     if keypressed then begin
  569.       read(kbd,c);
  570.       if c=chr(27) then
  571.         if keypressed then begin
  572.           read(kbd,c); case ord(c) of
  573.             48:begin bac:=not bac; writeln; writeln;
  574.                  if bac then writeln('-Destructive-') else writeln('=Non-Destructive=');
  575.                  writeln; writeln;
  576.                end;
  577.             45:done:=true;
  578.             31:begin hs:=hs+1; if hs>maxs then hs:=0; cs(hs); end;
  579.             32:dial;
  580.             16:if (lnd>0) and (lnd<10) then redial;
  581.             35:hang;
  582.             73:ul;
  583.             81:dl;
  584.             71:help;
  585.             46:clrscr;
  586.             18:begin eco:=not eco; writeln; writeln;
  587.                  if eco then writeln('-= ECHO ON =-') else writeln('=- ECHO OFF -=');
  588.                  writeln; writeln;
  589.                end;
  590.           end;
  591.       end else else begin o1(c); if eco then write(c); end;
  592.     end;
  593.   until done;
  594.   hang; delay(1000); pc('ATS0=0Q0V0E0M0S2=1S7=30'); delay(100); dump;
  595.   mem[$40:$17]:=mem[$40:$17] and not $40;
  596. end;
  597.  
  598. procedure voteprint;
  599. var vdata:file of vdatar; vd:vdatar; vn:integer; t:text; i1,i2:integer; u:userrec;
  600.     x:array[1..maxusers] of array[1..9] of integer;
  601.     s1,s2:str;
  602.  
  603. begin
  604.   assign(t,'gfiles\votes.txt');
  605.   rewrite(t);
  606.   writeln(t); writeln(t,'Votes as of '+dat);
  607.   reset(uf);
  608.   print('Beginning output to file "VOTES.TXT"');
  609.   i1:=1;
  610.   while (i1<filesize(uf)) do begin
  611.     seek(uf,i1); read(uf,u);
  612.     for i2:=1 to 9 do
  613.       x[i1][i2]:=u.vote[i2];
  614.     i1:=i1+1;
  615.   end;
  616.   close(uf);
  617.   assign(vdata,'gfiles\voting.dat');
  618.   reset(vdata);
  619.   for vn:=1 to 9 do begin
  620.     seek(vdata,vn-1); read(vdata,vd);
  621.     if vd.numa<>0 then begin
  622.       writeln(t); writeln(t,vd.question);
  623.       print(vd.question);
  624.       for i1:=1 to vd.numa do begin
  625.         writeln(t,'   '+vd.answ[i1].ans);
  626.         for i2:=1 to systat.users do begin
  627.           if x[srl[i2].number][vn]=i1 then begin
  628.             writeln(t,'      '+srl[i2].name+' #'+cstr(srl[i2].number));
  629.           end;
  630.         end;
  631.       end;
  632.     end;
  633.   end;
  634.   close(t);
  635.   print('Output complete.');
  636. end;
  637.  
  638. procedure return;
  639. var f:file;
  640. begin
  641.   assign(f,'bbs.com');
  642.   print('Returning to BBS...');
  643.   remove_port;
  644.   if hangup then term_ready(false);
  645.   execute(f);
  646. end;
  647.  
  648.  
  649. procedure parse(i1:str);
  650. var c,lp,cp:integer;
  651. begin
  652.   for c:=1 to 9 do i[c]:='';
  653.   c:=1; lp:=1; cp:=1;
  654.   if length(i1)=1 then i[1]:=i1;
  655.   while cp<length(i1) do begin
  656.     cp:=cp+1;
  657.     if (i1[cp]=' ') or (cp=length(i1)) then begin
  658.       if cp=length(i1) then cp:=cp+1;
  659.       i[c]:=copy(i1,lp,(cp-lp));
  660.       lp:=cp+1;
  661.       c:=c+1;
  662.     end;
  663.   end;
  664. end;
  665.  
  666. function align(fn:str):str;
  667. var f,e,t:str; c,c1:integer;
  668. begin
  669.   c:=pos('.',fn);
  670.   if c=0 then begin
  671.     f:=fn; e:='   ';
  672.   end else begin
  673.     f:=copy(fn,1,c-1); e:=copy(fn,c+1,3);
  674.   end;
  675.   while length(f)<8 do f:=f+' ';
  676.   while length(e)<3 do e:=e+' ';
  677.   c:=pos('*',f); if c<>0 then for c1:=c to 8 do f[c1]:='?';
  678.   c:=pos('*',e); if c<>0 then for c1:=c to 3 do e[c1]:='?';
  679.   align:=f+'.'+e;
  680. end;
  681.  
  682. function vdir(var d:str):boolean;
  683. var x:boolean;
  684. begin
  685.   if d[length(d)]='\' then d:=copy(d,1,length(d)-1);
  686.   if (d='DLOADS') or (d='GFILES') then x:=true else x:=false;
  687.   if (d='.') and so then x:=true;
  688.   vdir:=x;
  689. end;
  690.  
  691. procedure fix(var fn:str);
  692. var i,i1:str; c1,c2:integer; ok:boolean;
  693. begin
  694.   if vdir(fn) then fn:=fn+'\';
  695.   c1:=pos('\',fn); ok:=true;
  696.   if c1<>0 then begin
  697.     i:=copy(fn,1,c1-1);
  698.     fn:=copy(fn,c1+1,15);
  699.     if not vdir(i) then ok:=false;
  700.   end else i:='';
  701.   if i='' then i:=cd;
  702.   if fn='' then fn:='*.*';
  703.   fn:=i+'\'+align(fn);
  704.   if (pos('.MSG',fn)=0) and (pos('.TXT',fn)=0) and (pos('?',fn)=0) and (not so) then ok:=false;
  705.   if not ok then fn:='';
  706.   if not okfile(fn) then fn:='';
  707. end;
  708.  
  709. function fit(f1,f2:str):boolean;
  710. var tf:boolean; c:integer;
  711. begin
  712.   tf:=true;
  713.   for c:=1 to 12 do
  714.     if (f1[c]<>f2[c]) and (f1[c]<>'?') then tf:=false;
  715.   fit:=tf;
  716. end;
  717.  
  718. overlay procedure tedit;
  719. var cur,nex,las,b4:strptr;
  720.     top,bottom,used:strptr;
  721.     tline,curline,c1,c2:integer;
  722.     fil:text;
  723.     abort,next,done,allread:boolean;
  724.     i1,i2:str;
  725.  
  726.   function newptr(var x:strptr):boolean;
  727.   begin
  728.     if used<>nil then begin
  729.       x:=used;
  730.       used:=used^.next;
  731.       newptr:=true;
  732.     end else begin
  733.       if (maxavail<0) or (maxavail>100) then begin
  734.         new(x);
  735.         newptr:=true;
  736.       end else newptr:=false;
  737.     end;
  738.   end;
  739.  
  740.   procedure oldptr(var x:strptr);
  741.   begin
  742.     x^.next:=used;
  743.     used:=x;
  744.   end;
  745.  
  746.   procedure pline(cl:integer; var cp:strptr; var abort:boolean);
  747.   var next:boolean; i:str;
  748.   begin
  749.     if not abort then begin
  750.       if cp=nil then i:='      [END]' else begin
  751.         i:=cstr(cl);
  752.         while length(i)<4 do i:=' '+i;
  753.         i:=i+': '+cp^.i;
  754.       end;
  755.       printacr(i,abort,next);
  756.     end;
  757.   end;
  758.  
  759.   procedure pl;
  760.   var abort:boolean;
  761.   begin
  762.     abort:=false;
  763.     pline(curline,cur,abort);
  764.   end;
  765.  
  766. begin
  767.   nl; allread:=true;
  768.   used:=nil;
  769.   top:=nil;
  770.   bottom:=nil;
  771.   fix(i[2]);
  772.   if (pos('.MSG',i[2])=0) and (pos('.TXT',i[2])=0) then i[2]:='';
  773.   if i[2]='' then print('Illegal filename.') else begin
  774.     assign(fil,i[2]); abort:=false;
  775.     {$I-} reset(fil); {$I+}
  776.     tline:=0;
  777.     new(cur);
  778.     cur^.last:=nil;
  779.     cur^.i:='';
  780.     if ioresult<>0 then begin
  781.       {$I-} rewrite(fil); {$I+}
  782.       if ioresult<>0 then begin
  783.         print('Illegal filename.');
  784.         abort:=true;
  785.       end else begin
  786.         close(fil); erase(fil);
  787.         print('New file.');
  788.         tline:=0;
  789.         cur:=nil; top:=cur; bottom:=cur;
  790.       end;
  791.     end else begin
  792.       abort:=not newptr(nex);
  793.       top:=nex;
  794.       print('Loading...');
  795.       while (not eof(fil)) and (not abort) do begin
  796.         tline:=tline+1;
  797.         cur^.next:=nex;
  798.         nex^.last:=cur;
  799.         cur:=nex;
  800.         readln(fil,i1);
  801.         cur^.i:=i1;
  802.         abort:=not newptr(nex);
  803.       end;
  804.       close(fil);
  805.       cur^.next:=nil;
  806.       if tline=0 then begin cur:=nil; top:=nil; end;
  807.       bottom:=cur;
  808.       if abort then begin print('Not all of file read.'); allread:=false; end;
  809.       abort:=false;
  810.     end;
  811.     if not abort then begin
  812.       print('Total lines: '+cstr(tline));
  813.       cur:=top;
  814.       if top<>nil then top^.last:=nil;
  815.       curline:=1;
  816.       done:=false;
  817.       pl;
  818.       repeat
  819.         prompt(':');
  820.         input(i1,10);
  821.         if i1='' then i1:='+';
  822.         if value(i1)>0 then begin
  823.           c1:=value(i1);
  824.           if (c1>0) and (c1<=tline) then begin
  825.             while c1<>curline do
  826.               if c1<curline then begin
  827.                 if cur=nil then begin
  828.                   cur:=bottom;
  829.                   curline:=tline;
  830.                 end else begin
  831.                   curline:=curline-1;
  832.                   cur:=cur^.last;
  833.                 end;
  834.               end else begin
  835.                 curline:=curline+1;
  836.                 cur:=cur^.next;
  837.               end;
  838.             pl;
  839.           end;
  840.         end else case i1[1] of
  841.           '+':if cur<>nil then begin
  842.                 c1:=value(copy(i1,2,9));
  843.                 if c1=0 then c1:=1;
  844.                 while (cur<>nil) and (c1>0) do begin
  845.                   cur:=cur^.next;
  846.                   curline:=curline+1;
  847.                   c1:=c1-1;
  848.                 end;
  849.                 pl;
  850.               end;
  851.           '?':begin
  852.                 print('P:rint line      L:ist');
  853.                 print('-:back line      +:forward line');
  854.                 print('T:op             B:ottom');
  855.                 print('I:nsert lines    D:elete line');
  856.                 print('R:eplace line    C:lear workspace');
  857.                 print('Q:uit            S:ave');
  858.               end;
  859.           '-':begin
  860.                 c1:=value(copy(i1,2,9));
  861.                 if c1=0 then c1:=1;
  862.                 if cur=nil then begin
  863.                   cur:=bottom;
  864.                   curline:=tline;
  865.                   c1:=c1-1;
  866.                 end;
  867.                 if cur<>nil then
  868.                   if cur^.last<>nil then begin
  869.                     while (cur^.last<>nil) and (c1>0) do begin
  870.                       cur:=cur^.last;
  871.                       curline:=curline-1;
  872.                       c1:=c1-1;
  873.                     end;
  874.                     pl;
  875.                   end;
  876.               end;
  877.           'C':begin
  878.                 prompt('Clear workspace? ');
  879.                 if yn then begin
  880.                   tline:=0; curline:=1;
  881.                   cur:=nil; top:=nil; bottom:=nil;
  882.                   release(topheap);
  883.                 end;
  884.               end;
  885.           'P':pl;
  886.           'D':begin
  887.                 c1:=value(copy(i1,2,9));
  888.                 if c1=0 then c1:=1;
  889.                 while (cur<>nil) and (c1>0) do begin
  890.                   las:=cur^.last;
  891.                   nex:=cur^.next;
  892.                   if las<>nil then las^.next:=nex;
  893.                   if nex<>nil then nex^.last:=las;
  894.                   oldptr(cur);
  895.                   if bottom=cur then bottom:=las;
  896.                   if top=cur then top:=nex;
  897.                   cur:=nex;
  898.                   tline:=tline-1;
  899.                   c1:=c1-1;
  900.                 end;
  901.                 pl;
  902.               end;
  903.           'R':if cur<>nil then begin
  904.                 pl;
  905.                 i2:=cstr(curline); while length(i2)<>4 do i2:=' '+i2;
  906.                 i2:=i2+': '; prompt(i2);
  907.                 inli(i1);
  908.                 cur^.i:=i1;
  909.               end;
  910.           'I':begin
  911.                 abort:=false; ll:='';
  912.                 print('Enter "." on a seperate line to exit insert mode.');
  913.                 i1:=''; thisuser.linelen:=thisuser.linelen-6;
  914.                 while (not abort) and (i1<>'.') and (i1<>'.'+#1) do begin
  915.                   i2:=cstr(curline); while length(i2)<>4 do i2:=' '+i2;
  916.                   i2:=i2+': '; prompt(i2);
  917.                   inli(i1);
  918.                   if (i1<>'.') and (i1<>'.'+#1) then begin
  919.                     abort:=not newptr(nex);
  920.                     if not abort then begin
  921.                       nex^.i:=i1;
  922.                       if (top=cur) then
  923.                         if cur=nil then begin
  924.                           nex^.last:=nil;
  925.                           nex^.next:=nil;
  926.                           top:=nex;
  927.                           bottom:=nex;
  928.                         end else begin
  929.                           nex^.next:=cur;
  930.                           cur^.last:=nex;
  931.                           top:=nex;
  932.                         end
  933.                       else begin
  934.                         if cur=nil then begin
  935.                           bottom^.next:=nex;
  936.                           nex^.last:=bottom;
  937.                           nex^.next:=nil;
  938.                           bottom:=nex;
  939.                         end else begin
  940.                           las:=cur^.last;
  941.                           nex^.last:=las;
  942.                           nex^.next:=cur;
  943.                           cur^.last:=nex;
  944.                           las^.next:=nex;
  945.                         end;
  946.                       end;
  947.                       curline:=curline+1;
  948.                       tline:=tline+1;
  949.                     end else print('No room left.');
  950.                   end;
  951.                 end;
  952.                 thisuser.linelen:=thisuser.linelen+6;
  953.               end;
  954.           'T':begin
  955.                 cur:=top;
  956.                 curline:=1;
  957.                 pl;
  958.               end;
  959.           'B':begin
  960.                 cur:=nil;
  961.                 curline:=tline+1;
  962.                 pl;
  963.               end;
  964.           'L':begin
  965.                 abort:=false;
  966.                 nex:=cur;
  967.                 c1:=curline;
  968.                 while (not abort) and (nex<>nil) do begin
  969.                   pline(c1,nex,abort);
  970.                   nex:=nex^.next;
  971.                   c1:=c1+1;
  972.                 end;
  973.               end;
  974.           'Q':done:=true;
  975.           'S':begin
  976.                 if not allread then begin
  977.                   prompt('Not all of file read.  Save anyway? ');
  978.                   allread:=yn;
  979.                 end;
  980.                 if allread then begin
  981.                   done:=true;
  982.                   writeln('Saving...');
  983.                   rewrite(fil);
  984.                   cur:=top;
  985.                   while cur<>nil do begin
  986.                     writeln(fil,cur^.i);
  987.                     cur:=cur^.next;
  988.                   end;
  989.                   close(fil);
  990.                 end;
  991.               end;
  992.         end;
  993.       until done;
  994.     end;
  995.   end;
  996.   release(topheap);
  997. end;
  998.  
  999. overlay procedure gfileedit;
  1000. var b,b1:gft; f:file of gft; i:str; t,c:integer; ok,exit:boolean;
  1001.     gftit:array[1..150] of record tit:string[80]; arn:integer; gfile:boolean;end;
  1002.     nums,lgftn,numgft:integer;
  1003.     gfs:array[0..100] of record tit:string[80]; arn:integer; end;
  1004.     c1,c2,c3,c4:integer; s1,s2,s3,s4:str; ch:char;
  1005.  
  1006.   procedure gettit(n:integer);
  1007.   var r:integer; b:gft;
  1008.   begin
  1009.     numgft:=0;
  1010.     r:=n+1;
  1011.     if r<=t then begin
  1012.       seek(f,r); read(f,b);
  1013.       while (r<=t) and (b.filen[1]<>#1) do begin
  1014.         begin
  1015.           numgft:=numgft+1;
  1016.           gftit[numgft].tit:=b.title;
  1017.           gftit[numgft].arn:=r;
  1018.           gftit[numgft].gfile:=true;
  1019.         end;
  1020.         r:=r+1;
  1021.         if (r<=t) then begin seek(f,r); read(f,b);end;
  1022.       end;
  1023.     end;
  1024.   end;
  1025.  
  1026.   procedure getsec;
  1027.   var r:integer; b:gft;
  1028.   begin
  1029.     nums:=0;
  1030.     gfs[0].tit:='[ Main Section ]';
  1031.     gfs[0].arn:=0;
  1032.     for r:=1 to t do begin
  1033.       seek(f,r); read(f,b);
  1034.       if b.filen[1]=#1 then begin
  1035.         nums:=nums+1;
  1036.         gfs[nums].tit:='[ '+b.title+' ]';
  1037.         gfs[nums].arn:=r;
  1038.       end;
  1039.     end;
  1040.     gfs[nums+1].arn:=t+1;
  1041.   end;
  1042.  
  1043.   procedure listsec;
  1044.   var r:integer; i:str; abort,next:boolean;
  1045.   begin
  1046.     r:=0; abort:=false; nl; nl;
  1047.     while (r<=nums) and (not abort) do begin
  1048.       i:=cstr(r)+': '+gfs[r].tit;
  1049.       r:=r+1;
  1050.       printacr(i,abort,next);
  1051.     end;
  1052.   end;
  1053.  
  1054.   procedure lgft;
  1055.   var abort,next:boolean; c:integer; b:gft;
  1056.   begin
  1057.     nl; nl;
  1058.     if numgft=0 then print('No G-files.') else begin
  1059.       abort:=false; next:=false; c:=1;
  1060.       while (c<=numgft) and (not abort) do begin
  1061.         seek(f,gftit[c].arn); read(f,b);
  1062.         i:=cstr(c)+': '; if length(i)=3 then i:=' '+i;
  1063.         i:=i+b.filen;
  1064.         while length(i)<18 do i:=i+' ';
  1065.         i:=i+cstr(b.num);
  1066.         while length(i)<24 do i:=i+' ';
  1067.         i:=i+b.title;
  1068.         printacr(i,abort,next);
  1069.         c:=c+1;
  1070.       end;
  1071.     end;
  1072.   end;
  1073.  
  1074. begin
  1075.   nl;assign(f,'gfiles\gfiles.dat'); {$I-} reset(f); {$I+}
  1076.   if ioresult<>0 then begin
  1077.     rewrite(f); b.num:=0; write(f,b);
  1078.   end;
  1079.   seek(f,0); read(f,b); t:=b.num; exit:=false;
  1080.     repeat
  1081.       nl; nl;prompt('Gfile Edit: Q,I,D,S,? : ');
  1082.       onek(ch,'QIDS?'); getsec;
  1083.       case ch of
  1084.         'Q':exit:=true;
  1085.         '?':begin
  1086.               print('Q:uit from gfile edit   ?:this list');
  1087.               print('I:nsert G-file          D:delete G-file');
  1088.               print('S:ection modification');
  1089.             end;
  1090.         'S':begin
  1091.               prompt('I:nsert, D:elete, Q:uit ? '); onek(ch,'QID');
  1092.               case ch of
  1093.                 'I':begin
  1094.                       listsec;
  1095.                       prompt('Before which section (1-'+cstr(nums+1)+') : '); input(s1,2);
  1096.                       c1:=value(s1);
  1097.                       if (c1>0) and (c1<=(nums+1)) then begin
  1098.                         if c1<=nums then
  1099.                           c1:=gfs[c1].arn
  1100.                         else
  1101.                           c1:=t+1;
  1102.                         prompt('Section title? '); inputl(b.title,40);
  1103.                         prompt('SL requirement? '); input(s1,3);
  1104.                         b.num:=value(s1); b.filen:=#1#0#0#0#0#0;
  1105.                         for c3:=t downto c1 do begin
  1106.                           seek(f,c3); read(f,b1); seek(f,c3+1); write(f,b1);
  1107.                         end;
  1108.                         seek(f,c1); write(f,b); t:=t+1;
  1109.                         b.num:=t; seek(f,0); write(f,b);
  1110.                       end else print('Illegal section number.');
  1111.                     end;
  1112.                 'D':begin
  1113.                       listsec;
  1114.                       prompt('Delete which section (1-'+cstr(nums)+') : '); input(s1,2);
  1115.                       c1:=value(s1);
  1116.                       if ((c1>0) and (c1<=nums)) then begin
  1117.                         c2:=gfs[c1].arn;
  1118.                         if c1=nums then c3:=t+1 else c3:=gfs[c1+1].arn;
  1119.                         c1:=(c3-c2);
  1120.                         for c4:=c3 to t do begin
  1121.                           seek(f,c4); read(f,b); seek(f,c4-c1); write(f,b);
  1122.                         end;
  1123.                         seek(f,0); t:=t-c1; b.num:=t; write(f,b);
  1124.                       end;
  1125.                     end;
  1126.               end;
  1127.             end;
  1128.         'D':begin
  1129.               listsec;
  1130.               prompt('Which section (0-'+cstr(nums)+') : '); input(s1,2);
  1131.               c1:=value(s1);
  1132.               if (s1='0') or ((c1>0) and (c1<=nums)) then begin
  1133.                 gettit(gfs[c1].arn);
  1134.                 lgft;
  1135.                 prompt('Delete which (1-'+cstr(numgft)+') :');
  1136.                 input(s1,3);
  1137.                 c1:=value(s1);
  1138.                 if (c1>0) and (c1<=(numgft)) then begin
  1139.                   c1:=gftit[c1].arn;
  1140.                   for c2:=c1+1 to t do begin
  1141.                     seek(f,c2); read(f,b); seek(f,c2-1); write(f,b);
  1142.                   end;
  1143.                   seek(f,0); read(f,b); b.num:=b.num-1;
  1144.                   seek(f,0); write(f,b); t:=t-1;
  1145.                 end;
  1146.               end;
  1147.             end;
  1148.         'I':begin
  1149.               listsec;
  1150.               prompt('Which section (0-'+cstr(nums)+') : '); input(s1,2);
  1151.               c1:=value(s1);
  1152.               if (s1='0') or ((c1>0) and (c1<=nums)) then begin
  1153.                 gettit(gfs[c1].arn);
  1154.                 lgft; c4:=c1;
  1155.                 prompt('Insert before which (1-'+cstr(numgft+1)+') :');
  1156.                 input(s1,3);
  1157.                 c1:=value(s1);
  1158.                 if (c1>0) and (c1<=(numgft+1)) then begin
  1159.                   if c1<=numgft then
  1160.                     c2:=gftit[c1].arn
  1161.                   else
  1162.                     c2:=gfs[c4+1].arn;
  1163.                   prompt('Enter filename of new G-file : ');
  1164.                   input(b.filen,12); if (pos('.TXT',b.filen)=0) and
  1165.                   (pos('.MSG',b.filen)=0) then b.filen:='';
  1166.                   assign(f1,'gfiles\'+b.filen); {$I-} reset(f1); {$I+}
  1167.                   ok:=false; if ioresult=0 then begin close(f1); ok:=true; end;
  1168.                   if b.filen='' then ok:=false;
  1169.                   if ok then begin
  1170.                     nl; prompt('Enter title : '); inputl(b.title,40);
  1171.                     prompt('Enter SL : ');
  1172.                     input(i,3); b.num:=value(i);
  1173.                     for c3:=t downto c2 do begin
  1174.                       seek(f,c3); read(f,b1); seek(f,c3+1); write(f,b1);
  1175.                     end;
  1176.                     seek(f,c2); write(f,b); t:=t+1;
  1177.                     seek(f,0); read(f,b); b.num:=b.num+1; seek(f,0); write(f,b);
  1178.                   end else print('Illegal filename.');
  1179.                 end;
  1180.               end;
  1181.             end;
  1182.       end;
  1183.     until exit or hangup;
  1184.   close(f);
  1185.   nl;nl;
  1186. end;
  1187.  
  1188.  
  1189. function ffile(x:str):str;
  1190. var r:regs; x1:str;
  1191. begin
  1192.   x:=align(x); x1:=copy(x,1,8)+copy(x,10,3);
  1193.   fat:= #255#0#0#0#0#0#0#0+x1+#0#0#0#0+'                     ';
  1194.   dta := #0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0+
  1195.                #0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0;
  1196.   r.ds := seg(dta);
  1197.   r.dx := ofs(dta)+1;
  1198.   r.ax := $1a00;
  1199.   msdos(r);
  1200.   r.ds := seg(fat);
  1201.   r.dx := ofs(fat)+1;
  1202.   r.ax := $1100;
  1203.   msdos(r);
  1204.   if r.ax=$1100 then x1:=copy(dta,9,8)+'.'+copy(dta,17,3) else x1:='';
  1205.   ffile:=x1;
  1206. end;
  1207.  
  1208. function nfile:str;
  1209. var x1:str; r:regs;
  1210. begin
  1211.   r.ax:=$1200;
  1212.   r.ds := seg(fat);
  1213.   r.dx := ofs(fat)+1;
  1214.   msdos(r);
  1215.   if r.ax=$1200 then x1:=copy(dta,9,8)+'.'+copy(dta,17,3) else x1:='';
  1216.   nfile:=x1;
  1217. end;
  1218.  
  1219. procedure dir(cd,x:str; all:boolean);
  1220. var
  1221.   abort,next:boolean;
  1222.   x1:str;
  1223. begin
  1224.   if cd<>'.' then chdir(cd);
  1225.   x1:=ffile(x);
  1226.   nl; abort:=false;
  1227.   while (x1<>'') and not abort do begin
  1228.     if ((copy(x1,10,3)='MSG') or (copy(x1,10,3)='TXT') or all) and okfile(x1) then
  1229.       printacr(x1,abort,next);
  1230.     x1:=nfile;
  1231.   end;
  1232.   if cd<>'.' then chdir('..');
  1233. end;
  1234.  
  1235. procedure copyfile(srcname,destname:str);
  1236.     var
  1237.       srcbuffer, destbuffer: array[1..16384] of byte;
  1238.       srcstatus, deststatus: record recoff, maxbuf: integer; end;
  1239.       eof_src: boolean;
  1240.       bite: byte;
  1241.       src, dest: file;
  1242.  
  1243.   procedure read_in(var b: byte);
  1244.     begin
  1245.       with srcstatus do begin
  1246.         recoff:=recoff+1;
  1247.         if recoff > maxbuf then begin
  1248.           blockread(src,srcbuffer,16384,maxbuf);
  1249.           recoff:=1;
  1250.         end;
  1251.         b:=srcbuffer[recoff];
  1252.         if maxbuf=0 then eof_src:=true;
  1253.       end;
  1254.     end;
  1255.  
  1256.   procedure write_out(var b:byte);
  1257.     begin
  1258.       with deststatus do begin
  1259.         recoff:=recoff+1;
  1260.         if recoff>16384 then begin
  1261.           blockwrite(dest,destbuffer,16384,maxbuf);
  1262.           recoff:=1;
  1263.         end;
  1264.         destbuffer[recoff]:=b;
  1265.       end;
  1266.     end;
  1267.  
  1268.   begin
  1269.     assign(src,srcname); reset(src,1);
  1270.     srcstatus.recoff:=16384; srcstatus.maxbuf:=16384;
  1271.     assign(dest,destname); rewrite(dest,1);
  1272.     deststatus.recoff := 0; eof_src := false;
  1273.     nl; print('Copying...');
  1274.     while not eof_src do begin
  1275.       read_in(bite);
  1276.       write_out(bite);
  1277.     end;
  1278.     if deststatus.recoff>0 then
  1279.       BlockWrite(Dest,DestBuffer,deststatus.recoff-1,deststatus.maxbuf);
  1280.     close(src); close(dest);
  1281.   end;
  1282.  
  1283.  
  1284. procedure ren;
  1285. begin
  1286.   fix(i[2]); fix(i[3]); abort:=false; nl;
  1287.   if (i[2]='') or (i[3]='') then begin abort:=true; print('Illegal filename.'); end;
  1288.   if not abort then begin
  1289.     assign(f,i[2]); {$I-} reset(f); {$I+}
  1290.     if ioresult=0 then begin
  1291.       close(f); assign(f,i[3]); {$I-} reset(f); {$I+}
  1292.       if ioresult<>0 then begin
  1293.         {$I-} rewrite(f); {$I+}
  1294.         if ioresult=0 then begin
  1295.           close(f); erase(f); assign(f,i[2]); rename(f,i[3]);
  1296.           print('Renamed.');
  1297.         end else print('Illegal filename.');
  1298.       end else begin close(f); print('Filename already in use.'); end;
  1299.     end else print('File not found.');
  1300.   end;
  1301. end;
  1302.  
  1303. procedure delfil;
  1304. begin
  1305.   nl;
  1306.   fix(i[2]);
  1307.   if (not so) and (pos('.TXT',i[2])=0) then begin
  1308.     i[2]:='';
  1309.   end;
  1310.   if i[2]<>'' then begin
  1311.     assign(f,i[2]);
  1312.     {$I-} erase(f); {$I+}
  1313.     if ioresult=0 then print('Deleted.') else print('File not found.');
  1314.   end else print('Illegal filename.');
  1315. end;
  1316.  
  1317. procedure copyf;
  1318. begin
  1319.   fix(i[2]); fix(i[3]); nl;
  1320.   if (pos('????????.???',i[3])<>0) then begin
  1321.     s1:=copy(i[3],1,pos('\',i[3])-1);
  1322.     s2:=copy(i[2],pos('\',i[2])+1,12);
  1323.     i[3]:=s1+'\'+s2;
  1324.   end;
  1325.   if (i[2]='') or (i[3]='') then print('Illegal filename.') else begin
  1326.     assign(f,i[2]); assign(f1,i[3]);
  1327.     {$I-} reset(f); {$I+}
  1328.     if ioresult<>0 then print('File not found.') else begin
  1329.       close(f);
  1330.       {$I-} reset(f1); {$I+}
  1331.       if ioresult=0 then begin
  1332.         print('File already exists.');
  1333.         close(f1);
  1334.       end else begin
  1335.         {$I-} rewrite(f1); {$I+}
  1336.         if ioresult<>0 then begin close(f); print('Illegal filename.'); end else begin
  1337.           close(f1);
  1338.           copyfile(i[2],i[3]);
  1339.         end;
  1340.       end;
  1341.     end;
  1342.   end;
  1343. end;
  1344.  
  1345. procedure dirf;
  1346. begin
  1347.   all:=false;
  1348.   if not (vdir(i[2]) or (i[2]='')) and so then all:=true;
  1349.   fix(i[2]);
  1350.   c1:=pos('\',i[2]);
  1351.   s1:=copy(i[2],1,c1-1);
  1352.   s2:=copy(i[2],c1+1,12);
  1353.   if s1='' then s1:=cd;
  1354.   nl; dir(s1,s2,all);
  1355. end;
  1356.  
  1357. procedure typef;
  1358. begin
  1359.   nl;
  1360.   fix(i[2]);
  1361.   if i[2]<>'' then printfile(i[2]) else print('Illegal filename.');
  1362. end;
  1363.  
  1364. procedure loadhelp;
  1365. var f:file; ch1:char; a,b,c:integer;
  1366. begin
  1367.   assign(f,'gfiles\help.msg');
  1368.   for ch1:='0' to '^' do helpi[ch1]:=0;
  1369.   {$I-} reset(f,1); {$I+}
  1370.   if ioresult=0 then begin
  1371.     blockread(f,help[1],25000,a);
  1372.     close(f);
  1373.     b:=1;
  1374.     while (b<a) do begin
  1375.       if help[b]='|' then begin
  1376.         ch1:=help[b+1];
  1377.         if ch1 in ['0'..'^'] then begin
  1378.           c:=b;
  1379.           while (help[c]<>#10) and (abs(c-b)<80) do c:=c+1;
  1380.           c:=c+1;
  1381.           if c<a then helpi[ch1]:=c;
  1382.         end;
  1383.       end;
  1384.       b:=b+1;
  1385.     end;
  1386.     help[a+1]:='|';
  1387.     print('Help file loaded.');
  1388.   end else print('No help file present.');
  1389.   nl;
  1390. end;
  1391.  
  1392.  
  1393. procedure dosfc;
  1394. begin
  1395.   nl; prompt(cd+': ');
  1396.   input(i1,35); parse(i1);
  1397.   if i[1]='?' then begin
  1398.     nl; nl; printfile('gfiles\dosmnu.msg');
  1399.   end;
  1400.   if i[1]='EDIT' then tedit;
  1401.   if i[1]='VOTEPRINT' then voteprint;
  1402.   if i[1]='LOADHELP' then loadhelp;
  1403.   if i[1]='GFILE' then gfileedit;
  1404.   if i[1]='QUIT' then donedos:=true;
  1405.   if i[1]='DEL' then delfil;
  1406.   if i[1]='TYPE' then typef;
  1407.   if i[1]='REN' then ren;
  1408.   if i[1]='DIR' then dirf;
  1409.   if i[1]='CD' then if vdir(i[2]) then cd:=i[2];
  1410.   if i[1]='COPY' then copyf;
  1411. end;
  1412.  
  1413. begin
  1414.   iport; cd:='GFILES';
  1415.   topheap:=ptr(seg(lastvar),ofs(lastvar));
  1416.   release(topheap);
  1417.   case upcase(cmd) of
  1418.     'D':begin
  1419.           donedos:=false;
  1420.           print('Now in Mini-DOS.  "?" for help');
  1421.           print('Only .TXT or .MSG files can be accessed.'); nl; nl;
  1422.           while (not hangup) and (not donedos) do
  1423.             dosfc;
  1424.         end;
  1425.     'T':term;
  1426.     'G':gfileedit;
  1427.     'E':begin
  1428.           prompt('Filename: ');
  1429.           input(i[2],12);
  1430.           tedit;
  1431.         end;
  1432.   end;
  1433.   return;
  1434. end.
  1435.  
  1436.