home *** CD-ROM | disk | FTP | other *** search
/ synchro.net / synchro.net.tar / synchro.net / main / BBS / MARVEL.ZIP / COMMON.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  2003-05-07  |  12.3 KB  |  629 lines

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