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