home *** CD-ROM | disk | FTP | other *** search
/ synchro.net / synchro.net.tar / synchro.net / main / BBS / GEO.ZIP / COMMON.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-09-27  |  13.0 KB  |  633 lines

  1.  {ok, to run a WWIV 3.21d program under WWIV v4.00:
  2.  
  3.   take the source to the 3.21d .chn file, edit it, and remove procedure
  4.   return.  Then, make sure this (new) common.pas is in the same directory,
  5.   and compile the 3.21d .chn to a .com file.  Say the program is "dukedom".
  6.   you compile it to dukedom.com.  Now, make sure it is in your main WWIV
  7.   v4.00 directory, and add a new chain to the wwiv 4.00 database.  For the
  8.   filename, say "dukedom %1".
  9.  
  10.   For more advanced conversion, you should go through the source, and,
  11.   wherever you find something like "'gfiles\whatever.msg'", replace it with
  12.   either "gfilespath+'whatever.msg'", or "datapath+'whatever.msg'".  You
  13.   should use gfilespath if the file is an ascii file, and datapath if the
  14.   file is a data file.  Then, of course, you have to make sure that the
  15.   files are in the correct directory.
  16. }
  17.  
  18. {$G1}{$P1}
  19.  
  20. CONST strlen=160;
  21.  
  22. TYPE str=string[strlen];
  23.      userrec=record
  24.                name:string[25];
  25.                realname:string[14];
  26.                laston:string[10];
  27.                linelen:byte;
  28.                pagelen:byte;
  29.                sl:byte;
  30.                age:byte;
  31.                sex:char;
  32.                callsign:string[8];
  33.                gold:real;
  34.              end;
  35.       regs=record ax,bx,cx,dx,bp,si,di,ds,es,flags:integer; end;
  36.  
  37. var
  38.     sysopf:text[1024];
  39.     sysopffn:string[80];
  40.     gfilespath,datapath:string[80];
  41.     usernum:integer;
  42.     incom,okansi,cs,so,hangup:boolean;
  43.     timeon,timeleft:real;
  44.     thisuser:userrec;
  45.     rp:regs;
  46.  
  47.  
  48. function timer:real;
  49. var reg:record
  50.           ax,bx,cx,dx,bp,si,di,ds,es,flags:integer;
  51.         end;
  52.     h,m,s,t:real;
  53. begin
  54.   reg.ax:=44*256;
  55.   msdos(reg);
  56.   h:=(reg.cx div 256);
  57.   m:=(reg.cx mod 256);
  58.   s:=(reg.dx div 256);
  59.   t:=(reg.dx mod 256);
  60.   timer:=h*3600+m*60+s+t/100;
  61. end;
  62.  
  63. function nsl:real;
  64. begin
  65.   if timer<timeon then
  66.     timeon:=timeon-24.0*3600.0;
  67.   nsl:=timeleft-(timer-timeon);
  68. end;
  69.  
  70. function sysop1:boolean;
  71. begin
  72.   if (mem[0:1047] and 16)=0 then sysop1:=false else sysop1:=true;
  73. end;
  74.  
  75. function sysop:boolean;
  76. begin
  77.   sysop:=sysop1;
  78. end;
  79.  
  80. procedure sl1(i:str);
  81. begin
  82.   writeln(sysopf,i);
  83. end;
  84.  
  85. procedure sysoplog(i:str);
  86. begin
  87.   if (not so) or incom then
  88.     sl1('   '+i);
  89. end;
  90.  
  91. function tch(i:str):str;
  92. begin
  93.   if length(i)>2 then i:=copy(i,length(i)-1,2) else
  94.     if length(i)=1 then i:='0'+i;
  95.   tch:=i;
  96. end;
  97.  
  98. function time:str;
  99. var reg:record
  100.           ax,bx,cx,dx,bp,si,di,ds,es,flags:integer;
  101.         end;
  102.     h,m,s:string[4];
  103. begin
  104.   reg.ax:=$2c00; intr($21,reg);
  105.   str(reg.cx shr 8,h); str(reg.cx mod 256,m); str(reg.dx shr 8,s);
  106.   time:=tch(h)+':'+tch(m)+':'+tch(s);
  107. end;
  108.  
  109. function date:str;
  110. var reg:record
  111.           ax,bx,cx,dx,bp,si,di,ds,es,flags:integer;
  112.         end;
  113.     m,d,y:string[4];
  114. begin
  115.   reg.ax:=$2a00; msdos(reg); str(reg.cx,y); str(reg.dx mod 256,d);
  116.  str(reg.dx shr 8,m);
  117.   date:=tch(m)+'/'+tch(d)+'/'+tch(y);
  118. end;
  119.  
  120. function value(I:str):integer;
  121. var n,n1:integer;
  122. begin
  123.   val(i,n,n1);
  124.   if n1<>0 then begin
  125.     i:=copy(i,1,n1-1);
  126.     val(i,n,n1)
  127.   end;
  128.   value:=n;
  129.   if i='' then value:=0;
  130. end;
  131.  
  132. function cstr(i:integer):str;
  133. var c:str;
  134. begin
  135.   str(i,c); cstr:=c;
  136. end;
  137.  
  138. function nam:str;
  139. var s:str; i:integer; tf:boolean;
  140. begin
  141.   s:=thisuser.name;
  142.   tf:=true;
  143.   for i:=1 to length(s) do
  144.     if s[i]<'A' then
  145.       tf:=true
  146.     else begin
  147.       if (s[i]<='Z') and not tf then
  148.         s[i]:=chr(ord(s[i])+32);
  149.       tf:=false;
  150.     end;
  151.   nam:=s+' #'+cstr(usernum);
  152. end;
  153.  
  154. function leapyear(yr:integer):boolean;
  155. begin
  156.   leapyear:=(yr mod 4=0) and ((yr mod 100<>0) or (yr mod 400=0));
  157. end;
  158.  
  159. function days(mo,yr:integer):integer;
  160. var d:integer;
  161. begin
  162.   d:=value(copy('312831303130313130313031',1+(mo-1)*2,2));
  163.   if (mo=2) and leapyear(yr) then d:=d+1;
  164.   days:=d;
  165. end;
  166.  
  167. function daycount(mo,yr:integer):integer;
  168. var m,t:integer;
  169. begin
  170.   t:=0;
  171.   for m:=1 to (mo-1) do t:=t+days(m,yr);
  172.   daycount:=t;
  173. end;
  174.  
  175. function daynum(dt:str):integer;
  176. var d,m,y,t,c:integer;
  177. begin
  178.   t:=0;
  179.   m:=value(copy(dt,1,2));
  180.   d:=value(copy(dt,4,2));
  181.   y:=value(copy(dt,7,2))+1900;
  182.   for c:=1985 to y-1 do
  183.     if leapyear(c) then t:=t+366 else t:=t+365;
  184.   t:=t+daycount(m,y)+(d-1);
  185.   daynum:=t;
  186.   if y<1985 then daynum:=0;
  187. end;
  188.  
  189. function dat:str;
  190. var ap,x,y:str; i:integer;
  191. begin
  192.   case daynum(date) mod 7 of
  193.     0:x:='Tue';
  194.     1:x:='Wed';
  195.     2:x:='Thu';
  196.     3:x:='Fri';
  197.     4:x:='Sat';
  198.     5:x:='Sun';
  199.     6:x:='Mon';
  200.   end;
  201.   case value(copy(date,1,2)) of
  202.     1:y:='Jan';
  203.     2:y:='Feb';
  204.     3:y:='Mar';
  205.     4:y:='Apr';
  206.     5:y:='May';
  207.     6:y:='Jun';
  208.     7:y:='Jul';
  209.     8:y:='Aug';
  210.     9:y:='Sep';
  211.     10:y:='Oct';
  212.     11:y:='Nov';
  213.     12:y:='Dec';
  214.   end;
  215.   x:=x+' '+y+' '+copy(date,4,2)+', '+cstr(1900+value(copy(date,7,2)));
  216.   y:=time; i:=value(copy(y,1,2));
  217.   if i>11 then ap:='pm' else ap:='am';
  218.   if i>12 then i:=i-12;
  219.   if i=0 then i:=12;
  220.   dat:=cstr(i)+copy(y,3,3)+' '+ap+'  '+x;
  221. end;
  222.  
  223. procedure checkhangup;
  224. begin
  225. end;
  226.  
  227. procedure getkey(var c:char); forward;
  228.  
  229. procedure prompt(i:str); forward;
  230.  
  231.  
  232. procedure ansic(c:integer);
  233. var i:str;
  234. begin
  235.   if (c=1) or (c=0) then
  236.     c:=0
  237.   else
  238.     if (c=2) then
  239.       c:=7
  240.     else
  241.       c:=c-2;
  242.   i:=#3+chr(ord('0')+c);
  243.   prompt(i);
  244. end;
  245.  
  246. procedure sdc;
  247. var f:integer;
  248. begin
  249.   ansic(0);
  250. end;
  251.  
  252.  
  253. procedure pausescr;
  254. var i:integer; cc:char;
  255. begin
  256.   ansic(3); prompt('(-*-)'); ansic(0);
  257.   getkey(cc);
  258.   for i:=1 to 5 do
  259.     prompt(#8+' '+#8);
  260. end;
  261.  
  262. procedure prompt;
  263. var c:integer; cc:char;
  264. begin
  265.   if (not hangup) then
  266.     for c:=1 to length(i) do begin
  267.       if (i[c]=#10) then
  268.         ansic(0);
  269.       write(i[c]);
  270.     end;
  271. end;
  272.  
  273. procedure print(i:str);
  274. begin
  275.   prompt(i+chr(13)+chr(10))
  276. end;
  277.  
  278. procedure nl;
  279. begin
  280.   prompt(chr(13)+chr(10))
  281. end;
  282.  
  283. procedure prt(i:str);
  284. begin
  285.   ansic(4); prompt(i); ansic(0);
  286. end;
  287.  
  288. procedure ynq(i:str);
  289. begin
  290.   ansic(7); prompt(i);
  291. end;
  292.  
  293. procedure mpl(c:integer);
  294. var n:integer; i:str;
  295. begin
  296.   if okansi then begin
  297.     ansic(6);
  298.     i:='';
  299.     for n:=1 to c do i:=i+' ';
  300.     prompt(i);
  301.     prompt(#27+'['+cstr(c)+'D');
  302.   end;
  303. end;
  304.  
  305. procedure tleft;
  306. var x,y:integer;
  307. begin
  308.   if timer<timeon then timeon:=timeon-24.0*60*60;
  309.   if (nsl<0) then begin
  310.     nl;
  311.     print('Time expired.');
  312.     hangup:=true;
  313.   end;
  314.   checkhangup;
  315. end;
  316.  
  317.  
  318. function empty:boolean;
  319. begin
  320.   rp.ax:=$0b00;
  321.   msdos(rp);
  322.   if (rp.ax and $00ff)=$00 then
  323.     empty:=true
  324.   else
  325.     empty:=false;
  326. end;
  327.  
  328. function inkey:char;
  329. var ch:char;
  330. begin
  331.   if (empty) then
  332.     inkey:=#0
  333.   else begin
  334.     rp.ax:=$0800;
  335.     msdos(rp);
  336.     inkey:=chr(rp.ax and $00ff);
  337.   end;
  338. end;
  339.  
  340.  
  341. procedure getkey;
  342. begin
  343.     rp.ax:=$0800;
  344.     msdos(rp);
  345.     c:=chr(rp.ax and $00ff);
  346. end;
  347.  
  348. procedure cls;
  349. begin
  350.   write(chr(12));
  351. end;
  352.  
  353.  
  354. function yn:boolean;
  355. var c:char;
  356. begin
  357.   if not hangup then begin
  358.     ansic(3);
  359.     repeat
  360.       getkey(c);
  361.       c:=upcase(c);
  362.     until (c='Y') or (c='N') or (c=chr(13)) or hangup;
  363.     if c='Y' then begin print('Yes'); yn:=true; end else begin print('No'); yn:=false; end;
  364.     if hangup then yn:=false;
  365.   end;
  366. end;
  367.  
  368. procedure input1(var i:str; ml:integer; tf:boolean);
  369. var cp:integer;
  370.     c:char;
  371.     r:real;
  372. begin
  373.  checkhangup;
  374.  if not hangup then begin
  375.   r:=timer;
  376.   cp:=1;
  377.   repeat
  378.     getkey(c);
  379.     if c=#1 then r:=timer;
  380.     if not tf then c:=upcase(c);
  381.     if (c>=' ') and (c<chr(127)) then
  382.       if cp<=ml then begin
  383.       i[cp]:=c;
  384.       cp:=cp+1;
  385.       write(c);
  386.     end else else case ord(c) of
  387.       8:if cp>1 then begin
  388.                c:=chr(8);
  389.                write(#8#32#8);
  390.                cp:=cp-1;
  391.              end;
  392.       21,24:while cp<>1 do begin
  393.                cp:=cp-1;
  394.                write(#8#32#8);
  395.              end;
  396.     end;
  397.     if (timer-r)>300.0 then hangup:=true;
  398.   until (c=#13) or (c=#14) or hangup;
  399.   i[0]:=chr(cp-1);
  400.   nl;
  401.  end;
  402. end;
  403.  
  404. procedure input(var i:str; ml:integer);
  405. begin
  406.   input1(i,ml,false);
  407. end;
  408.  
  409.  
  410. procedure inputl(var i:str; ml:integer);
  411. begin
  412.   input1(i,ml,true);
  413. end;
  414.  
  415. procedure onek(var c:char; ch:str);
  416. begin
  417.   repeat
  418.     getkey(c);
  419.     c:=upcase(c);
  420.   until (pos(c,ch)>0) or hangup;
  421.   if hangup then c:=ch[1];
  422.   print(''+c);
  423. end;
  424.  
  425.  
  426.  procedure wkey(var abort,next:boolean);
  427.  var cc:char;
  428.  begin
  429.     while not (empty or hangup or abort) do begin
  430.       getkey(cc);
  431.       if (cc=' ') or (cc=chr(3)) or (cc=chr(24)) or (cc=chr(11)) then
  432.         abort:=true;
  433.       if (cc=chr(14)) then begin abort:=true; next:=true; end;
  434.       if (cc=chr(19)) or (cc='P') or (cc='p') then begin
  435.         getkey(cc);
  436.       end;
  437.     end;
  438.  end;
  439.  
  440. function ctim(rl:real):str;
  441. var h,m,s:str;
  442. begin
  443.   s:=tch(cstr(trunc(rl-int(rl/60.0)*60.0)));
  444.   m:=tch(cstr(trunc(int(rl/60.0)-int(rl/3600.0)*60.0)));
  445.   h:=cstr(trunc(rl/3600.0));
  446.   if length(h)=1 then h:='0'+h;
  447.   ctim:=h+':'+m+':'+s;
  448. end;
  449.  
  450. function tlef:str;
  451. begin
  452.   tlef:=ctim(nsl);
  453. end;
  454.  
  455. function cstrr(rl:real; base:integer):str;
  456. var c1,c2,c3:integer; i:str; r1,r2:real;
  457. begin
  458.  if rl<=0.0 then cstrr:='0' else begin
  459.   r1:=ln(rl)/ln(1.0*base);
  460.   r2:=exp(ln(1.0*base)*(trunc(r1)));
  461.   i:='';
  462.   while (r2>0.999) do begin
  463.     c1:=trunc(rl/r2);
  464.     i:=i+copy('0123456789ABCDEF',c1+1,1);
  465.     rl:=rl-c1*r2;
  466.     r2:=r2/(1.0*base);
  467.   end;
  468.   cstrr:=i;
  469.  end;
  470. end;
  471.  
  472.  
  473. procedure printa1(i:str; var abort,next:boolean);
  474. var c:integer;
  475. begin
  476.  checkhangup;
  477.  if not hangup then begin
  478.   abort:=false; next:=false; c:=1;
  479.   if not empty then wkey(abort,next);
  480.   while (not abort) and (c-1<length(i)) and (not hangup) do begin
  481.     checkhangup;
  482.     if i[c]=#3 then
  483.       if i[c+1] in [#0..#8] then
  484.         if okansi then
  485.           ansic(ord(i[c+1]));
  486.     if not empty then wkey(abort,next);
  487.     if i[c]=#3 then
  488.       c:=c+1
  489.     else
  490.       write(i[c]);
  491.     c:=c+1;
  492.   end;
  493.  end else abort:=true;
  494. end;
  495.  
  496. procedure printa(i:str; var abort,next:boolean);
  497. var s:str; p,op,rp,rop,nca:integer; crend:boolean;
  498. begin
  499.   abort:=false;
  500.   crend:=(i[length(i)]=#1) and (i[length(i)-1]<>#3);
  501.   if crend then i:=copy(i,1,length(i)-1);
  502.   wkey(abort,next);
  503.   if i='' then nl;
  504.   while (i<>'') and (not abort) and (not hangup) do begin
  505.     rp:=0; nca:=thisuser.linelen-wherex-1; p:=0;
  506.     while (rp<nca) and (p<length(i)) do begin
  507.       if i[p+1]=#8 then rp:=rp-1 else
  508.         if i[p+1]=#3 then
  509.           p:=p+1
  510.         else
  511.           if (i[p+1]<>#10) then rp:=rp+1;
  512.       p:=p+1;
  513.     end;
  514.     op:=p; rop:=rp;
  515.     if (rp>=nca) and (p<length(i)) then begin
  516.       while ((not (i[p] in [' ',#8,#10])) or (i[p-1]=#3)) and (p>1) do begin
  517.         rp:=rp-1; p:=p-1;
  518.       end;
  519.       if p=1 then
  520.         if not (i[1] in [' ',#8,#10]) then begin rp:=rp-1; p:=p-1; end;
  521.     end;
  522.     if abs(rop-rp)>=(thisuser.linelen div 2) then p:=op;
  523.     s:=copy(i,1,p); delete(i,1,p);
  524.     if (s[length(s)]=' ') then s[0]:=pred(s[0]);
  525.     printa1(s,abort,next);
  526.     if ((i='') and crend) or (i<>'') or abort then
  527.       nl
  528.     else
  529.       printa1(' ',abort,next);
  530.   end;
  531. end;
  532.  
  533. procedure printacr(i:str; var abort,next:boolean);
  534. begin
  535.  if not abort then
  536.   if i[length(i)]=#1 then
  537.     printa(i,abort,next)
  538.   else
  539.     printa(i+#1,abort,next);
  540. end;
  541.  
  542. procedure pfl(fn:str; var abort:boolean; cr:boolean);
  543. var fil:text;
  544.     i:str;
  545.     next:boolean;
  546. begin
  547.     if not hangup then begin
  548.       assign(fil,fn);
  549.       {$I-} reset(fil); {$I+}
  550.       if ioresult<>0 then print('File not found.') else begin
  551.         abort:=false;
  552.         while not eof(fil) and (not abort) and (not hangup) do begin
  553.           readln(fil,i);
  554.           if cr then
  555.             printacr(i,abort,next)
  556.           else
  557.             printa(i,abort,next);
  558.         end;
  559.         close(fil);
  560.       end;
  561.       nl;nl;
  562.     end;
  563. end;
  564.  
  565. procedure printfile(fn:str);
  566. var abort:boolean;
  567. begin
  568.   pfl(fn,abort,true);
  569. end;
  570.  
  571. procedure iport;
  572. var f:text;
  573.     i:str;
  574.     n:integer;
  575. begin
  576.   assign(f,paramstr(1));
  577.   {$I-} reset(f); {$I+}
  578.   if (ioresult=0) then begin
  579.     readln(f,usernum);
  580.     readln(f,thisuser.name);
  581.     readln(f,thisuser.realname);
  582.     readln(f,thisuser.callsign);
  583.     readln(f,thisuser.age);
  584.     readln(f,thisuser.sex);
  585.     readln(f,thisuser.gold);
  586.     readln(f,thisuser.laston);
  587.     readln(f,thisuser.linelen);
  588.     readln(f,thisuser.pagelen);
  589.     readln(f,thisuser.sl);
  590.     readln(f,n);
  591.     cs:=(n=1);
  592.     readln(f,n);
  593.     so:=(n=1);
  594.     readln(f,n);
  595.     okansi:=(n=1);
  596.     readln(f,n);
  597.     incom:=(n=1);
  598.     readln(f,timeleft);
  599.     readln(f,gfilespath);
  600.     readln(f,datapath);
  601.     readln(f,i);
  602.     close(f);
  603.     sysopffn:=gfilespath+i;
  604.     assign(sysopf,sysopffn);
  605.     {$I-} append(sysopf); {$I+}
  606.     if (ioresult<>0) then begin
  607.       rewrite(sysopf);
  608.     end;
  609.   end else begin
  610.     writeln('Parameter file not found.');
  611.     halt;
  612.   end;
  613.   hangup:=false;
  614.   timeon:=timer;
  615. end;
  616.  
  617. procedure return;
  618. begin
  619.   close(sysopf);
  620.   halt;
  621. end;
  622.  
  623. procedure topscr;
  624. var wx,wy:integer;
  625.     st:string[80];
  626. begin
  627.   fillchar(st,81,'-');
  628.   st[0]:=#80;
  629.   write(st);
  630.   write(nam,'  ',tlef,'    ');
  631. end;
  632.  
  633.