home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 270.img / FORUM25C.ZIP / SUBS2.PAS < prev    next >
Pascal/Delphi Source File  |  1989-02-08  |  15KB  |  572 lines

  1. {$R-,S-,I-,D-,V-,B-,N-,L- }
  2. {$O+}
  3.  
  4. unit subs2;
  5.  
  6. { $define testingdevices}   (* Activate this define for test mode *)
  7.  
  8.  
  9. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  10.  
  11. interface
  12.  
  13. uses printer,
  14.      dos,
  15.      crt,
  16.      StrLib,
  17.      gentypes,
  18.      configrt,
  19.      gensubs,
  20.      subs1,
  21.      windows,
  22.      modem,
  23.      statret,
  24.      chatstuf,
  25.      flags;
  26.  
  27. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  28.  
  29. TYPE AllignTypes = (Left,Right,Middle);
  30.  
  31. Procedure beepbeep;
  32. Procedure summonbeep;
  33. Procedure abortttfile (er:integer);
  34. Procedure openttfile;
  35. Procedure writecon (k:char);
  36. Procedure toggleavail;
  37. Function charready:boolean;
  38. Function readchar:char;
  39. Function waitforchar:char;
  40. Procedure clearchain;
  41. Function charpressed (k:char):boolean;  { TRUE if K is in typeahead }
  42. Procedure addtochain (l:lstr);
  43. Procedure directoutchar (k:char);
  44. Procedure handleincoming;
  45. Procedure writechar (k:char);
  46.     { KEVIN: These aren't necessary, are they?? }
  47.       Function opendevice (VAR t:textrec):integer;
  48.       Function closedevice (VAR t:textrec):integer;
  49.       Function cleardevice (VAR t:textrec):integer;
  50.       Function ignorecommand (VAR t:textrec):integer;
  51.       Function directoutchars (VAR t:textrec):integer;
  52.       Function writechars (VAR t:textrec):integer;
  53.       Function directinchars (VAR t:textrec):integer;
  54.       Function readcharfunc (VAR t:textrec):integer;
  55.  
  56. Function getinputchar:char;
  57. Procedure getstr;
  58. Procedure writestr (s:anystr);
  59. Procedure cls;
  60. Procedure writehdr (q:anystr);
  61. Function issysop:boolean;
  62. Procedure reqlevel (l:integer);
  63. Procedure printfile (fn:lstr);
  64. Procedure printtexttopoint (VAR tf:text);
  65. Procedure skiptopoint (VAR tf:text);
  66. Function minstr (blocks:integer):sstr;
  67. Procedure parserange (numents:integer; VAR f,l:integer);
  68. Function menu (mname:mstr; mfn:sstr; choices:anystr):integer;
  69. Function checkpassword (VAR u:userrec):boolean;
  70. Function getpassword:boolean;
  71. Procedure getacflag (VAR ac:accesstype; VAR tex:mstr);
  72. Function Response(ChoiceList : String) : CHAR;
  73. Procedure Center(CenterString : String; ScreenWidth : BYTE);
  74. Procedure WaitReturn;
  75. Procedure TopOfBox(ScreenWidth : BYTE);
  76. Procedure BoxText(StringBox : String78; ScreenWidth : BYTE;
  77.                   AllignMent : AllignTypes);
  78. Procedure MiddleBar(ScreenWidth : BYTE);
  79. Procedure BottomOfBox(ScreenWidth : BYTE);
  80. Procedure BoxString(StringBox : String80; Size : BYTE);
  81. Function WidthScreen : BYTE;
  82.  
  83. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  84.  
  85. implementation
  86.  
  87. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  88.  
  89.  
  90. Procedure beepbeep;
  91. begin
  92.   nosound;
  93.   sound (200);
  94.   delay (10);
  95.   nosound
  96. end;
  97.  
  98. {=============================================================================}
  99.  
  100. Procedure summonbeep;
  101. VAR cnt:integer;
  102. begin
  103.   nosound;
  104.   cnt:=1330;
  105.   repeat
  106.     sound (cnt);
  107.     delay (10);
  108.     cnt:=cnt+200;
  109.   until cnt>4300;
  110.   nosound
  111. end;
  112.  
  113. {=============================================================================}
  114.  
  115. Procedure abortttfile (er:integer);
  116. VAR n:integer;
  117. begin
  118.   specialmsg ('<Texttrap error '+strr(er)+'>');
  119.   texttrap:=false;
  120.   textclose (ttfile);
  121.   n:=ioresult
  122. end;
  123.  
  124. {=============================================================================}
  125.  
  126. Procedure openttfile;
  127. VAR n:integer;
  128. begin
  129.   appendfile ('Texttrap',ttfile);
  130.   n:=ioresult;
  131.   if n=0 then
  132.     Begin
  133.       TextTrap := TRUE;
  134.       Writeln(TtFile,'-%- Forum-PC Text Trap File -%-');
  135.       Writeln(TtFile,'Date: ',DateStr(Now),'  ',TimeStr(Now),'');
  136.       Writeln(TtFile);
  137.     END
  138.   ELSE
  139.     abortttfile (n)
  140. end;
  141.  
  142. {=============================================================================}
  143.  
  144. Procedure writecon (k:char);
  145. VAR r:registers;
  146. begin
  147.   if k=^J
  148.     then write (usr,k)
  149.     else
  150.       begin
  151.         r.dl:=ord(k);
  152.         r.ah:=2;
  153.         intr($21,r)
  154.       end
  155. end;
  156.  
  157. {=============================================================================}
  158.  
  159. Procedure toggleavail;
  160. begin
  161.   if sysopavail=notavailable
  162.     then sysopavail:=available
  163.     else sysopavail:=succ(sysopavail)
  164. end;
  165.  
  166. {=============================================================================}
  167.  
  168. Function charready:boolean;
  169. VAR k:char;
  170. begin
  171.   if modeminlock then while numchars>0 do k:=getchar;
  172.   if hungupon or keyhit
  173.     then charready:=true
  174.     else if online
  175.       then charready:=(not modeminlock) and (numchars>0)
  176.       else charready:=false
  177. end;
  178.  
  179. {=============================================================================}
  180.  
  181. Function readchar:char;
  182.  
  183.   Procedure toggletempsysop;
  184.   begin
  185.     if tempsysop
  186.       then ulvl:=regularlevel
  187.       else
  188.         begin
  189.           regularlevel:=ulvl;
  190.           ulvl:=sysoplevel
  191.         end;
  192.     tempsysop:=not tempsysop
  193.   end;
  194.  
  195.   Procedure togviewstats;
  196.   begin
  197.     if splitmode
  198.       then unsplit
  199.       else
  200.         begin
  201.           splitscreen (7);
  202.           top;
  203.           clrscr;
  204.           write (usr,'File Level:     ',urec.udlevel,
  205.                  ^M^J'File Points:    ',urec.udpoints,
  206.                  ^M^J'XMODEM uploads: ',urec.uploads,
  207.                  ^M^J'XMODEM dnloads: ',urec.downloads);
  208.           window (40,1,80,5);
  209.           gotoxy (1,1);
  210.           write (usr,'Posts:      ',urec.nbu,
  211.                  ^M^J'Uploads:    ',urec.nup,
  212.                  ^M^J'Downloads:  ',urec.ndn,
  213.                  ^M^J'Total Time: ',urec.totaltime:0:0,
  214.                  ^M^J'Num. calls: ',urec.numon);
  215.           window (1,1,80,5);
  216.           bottom
  217.         end;
  218.   end;
  219.  
  220.   Procedure showhelp;
  221.   begin
  222.     if splitmode
  223.       then unsplit
  224.       else begin
  225.         splitscreen (10);
  226.         top;
  227.         clrscr;
  228.         write (usr,
  229. 'Chat with user: F1               Sysop commands: F2'^M^J,
  230. 'Sysop gets the system next: F7   Lock the timer: F8'^M^J,
  231. 'Lock out all modem input: F9     Lock all modem output: F10'^M^J,
  232. 'Chat availabily toggle: Alt-A    Grant temporary sysop powers: Alt-T'^M^J,
  233. 'Grant user more time: Alt-M      Take away user''s time: Alt-L'^M^J,
  234. 'Take away ALL time: Alt-K        Refresh the bottom line: Alt-B'^M^J,
  235. 'Toggle printer echo: Ctrl-PrtSc  Toggle text trap: Alt-E'^M^J,
  236. 'View user''s status: Alt-V');
  237.     end;
  238.   end;
  239.  
  240.   Procedure toggletexttrap;
  241.   VAR n:integer;
  242.   begin
  243.     if texttrap
  244.       then
  245.         begin
  246.           Writeln(TtFile,'=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=');
  247.           Writeln(TtFile);
  248.           textclose (ttfile);
  249.           n:=ioresult;
  250.           if n<>0 then abortttfile (n);
  251.           texttrap:=false
  252.         end
  253.       else openttfile
  254.   end;
  255.  
  256. VAR k:char;
  257.     ret:char;
  258.     dorefresh:boolean;
  259. begin
  260.   if keyhit
  261.     then
  262.       begin
  263.         k:=bioskey;
  264.         ret:=k;
  265.         if ord(k)>127 then begin
  266.           ret:=#0;
  267.           dorefresh:=ingetstr;
  268.           case ord(k)-128 of
  269.             availtogglechar:
  270.               begin
  271.                 toggleavail;
  272.                 chatmode:=false;
  273.                 dorefresh:=true
  274.               end;
  275.             sysopcomchar:
  276.               Begin
  277.                 k := #0;
  278.                 Command_proc;
  279.                 If NOT InChat THEN Write(^B^M^M^P,lastprompt);
  280.                 ChainStr := '';
  281.               End;
  282.             breakoutchar : halt(e_controlbreak);
  283.             lesstimechar : urec.timetoday:=urec.timetoday-1;
  284.             moretimechar : urec.timetoday:=urec.timetoday+1;
  285.             notimechar : settimeleft (-1);
  286.             Chatchar : Begin
  287.                          If Inchat THEN
  288.                             Begin
  289.                               InChat := FALSE;
  290.                               ChainStr := '';
  291.                               write(^B^M^M^P,lastprompt);
  292.                             End
  293.                          ELSE
  294.                            Begin
  295.                              InChat := TRUE;
  296.                              k := #0;
  297.                              Chat_proc;
  298.                            End;
  299.                        End;
  300.             sysnextchar  : sysnext:=not sysnext;
  301.             timelockchar : if timelock then timelock:=false else begin
  302.                            timelock:=true;
  303.                            lockedtime:=timeleft
  304.                          end;
  305.             inlockchar:modeminlock:=not modeminlock;
  306.             outlockchar:setoutlock (not modemoutlock);
  307.             tempsysopchar:toggletempsysop;
  308.             bottomchar:bottomline;
  309.             viewstatchar:togviewstats;
  310.             sysophelpchar:if dorefresh then showhelp;
  311.             texttrapchar:toggletexttrap;
  312.             printerechochar:printerecho:=not printerecho;
  313.             72:ret:=^E;
  314.             75:ret:=^S;
  315.             77:ret:=^D;
  316.             80:ret:=^X;
  317.             115:ret:=^A;
  318.             116:ret:=^F;
  319.             73:ret:=^R;
  320.             81:ret:=^C;
  321.             71:ret:=^Q;
  322.             79:ret:=^W;
  323.             83:ret:=^G;
  324.             82:ret:=^V;
  325.             117:ret:=^P;
  326.           end;
  327.           if dorefresh then bottomline
  328.         end
  329.       end
  330.     else
  331.       begin
  332.         k:=getchar;
  333.         if modeminlock
  334.           then ret:=#0
  335.           else ret:=k
  336.       end;
  337.   if ret='+' then write (' '^H);
  338.   readchar:=ret
  339. end;
  340.  
  341. {=============================================================================}
  342.  
  343. Function waitforchar:char;
  344. VAR t:integer;
  345.     k:char;
  346. begin
  347.   t:=timer+mintimeout;
  348.   if t>=1440 then t:=t-1440;
  349.   repeat
  350.     if timer=t then forcehangup:=true
  351.   until charready;
  352.   waitforchar:=readchar
  353. end;
  354.  
  355. {=============================================================================}
  356.  
  357. Procedure clearchain;
  358. begin
  359.   chainstr[0]:=#0
  360. end;
  361.  
  362. {=============================================================================}
  363.  
  364. Function charpressed (k:char):boolean;  { TRUE if K is in typeahead }
  365. begin
  366.   charpressed:=pos(k,chainstr)>0
  367. end;
  368.  
  369. {=============================================================================}
  370.  
  371. Procedure addtochain (l:lstr);
  372. begin
  373.   if length(chainstr)<>0 then chainstr:=chainstr+',';
  374.   chainstr:=chainstr+l
  375. end;
  376.  
  377. {=============================================================================}
  378.  
  379. Procedure directoutchar (k:char);
  380. VAR n:integer;
  381. begin
  382.   if inuse<>1
  383.     then writecon (k)
  384.     else begin
  385.       bottom;
  386.       writecon (k);
  387.       top
  388.     end;
  389.   if wherey>lasty then gotoxy (wherex,lasty);
  390.   if online and (not modemoutlock) and ((k<>#10) or uselinefeeds)
  391.     then sendchar(k);
  392.   if texttrap then begin
  393.     write (ttfile,k);
  394.     n:=ioresult;
  395.     if n<>0 then abortttfile (n)
  396.   end;
  397.   if printerecho then write (lst,k)
  398. end;
  399.  
  400. {=============================================================================}
  401.  
  402. Procedure handleincoming;
  403. VAR k:char;
  404. begin
  405.   k:=readchar;
  406.   case upcase(k) of
  407.     'X',^X,^K,^C,#27,' ':begin
  408.       writeln (direct);
  409.       break:=true;
  410.       linecount:=0;
  411.       xpressed:=(upcase(k)='X') or (k=^X);
  412.       if xpressed then clearchain
  413.     end;
  414.     ^S:k:=waitforchar;
  415.     else if length(chainstr)<255 then chainstr:=chainstr+k
  416.   end
  417. end;
  418.  
  419. {=============================================================================}
  420.  
  421. Procedure writechar (k:char);
  422.  
  423.   Procedure endofline;
  424.  
  425.     Procedure write13 (k:char);
  426.     VAR n:integer;
  427.     begin
  428.       for n:=1 to 13 do directoutchar (k)
  429.     end;
  430.  
  431.   VAR b:boolean;
  432.   begin
  433.     writeln (direct);
  434.     if timelock then settimeleft (lockedtime);
  435.     if curattrib=urec.statcolor then ansicolor (urec.regularcolor);
  436.     linecount:=linecount+1;
  437.     if (linecount>=urec.displaylen-1) and (not dontstop)
  438.           and (moreprompts in urec.config) then begin
  439.       linecount:=1;
  440.       write (direct,'More (Y/N/C)?');
  441.       repeat
  442.         k:=upcase(waitforchar)
  443.       until (k in [^M,' ','C','N','Y']) or hungupon;
  444.       write13 (^H);
  445.       write13 (' ');
  446.       write13 (^H);
  447.       if k='N' then break:=true else if k='C' then dontstop:=true
  448.     end
  449.   end;
  450.  
  451. begin
  452.   if hungupon then exit;
  453.   if k<=^Z then
  454.     case k of
  455.       ^J,#0:exit;
  456.       ^Q:k:=^H;
  457.       ^B:begin
  458.            clearbreak;
  459.            exit
  460.          end
  461.     end;
  462.   if break then exit;
  463.   if k<=^Z then begin
  464.     case k of
  465.       ^G : Begin
  466.              beepbeep;
  467.              SendChar(k);
  468.            End;
  469.       ^L : Begin
  470.              cls;
  471.              SendChar(k);
  472.            End;
  473.       ^N,^R:ansireset;
  474.       ^S:ansicolor (urec.statcolor);
  475.       ^P:ansicolor (urec.promptcolor);
  476.       ^U:ansicolor (urec.inputcolor);
  477.       ^H:directoutchar (k);
  478.       ^M:endofline
  479.     end;
  480.     exit
  481.   end;
  482.   if usecapsonly then k:=upcase(k);
  483.   directoutchar (k);
  484.   if (keyhit or ((not modemoutlock) and online and (numchars>0)))
  485.      and (not nobreak) then handleincoming
  486. end;
  487.  
  488. {=============================================================================}
  489.  
  490. Function getinputchar:char;
  491. VAR k:char;
  492. begin
  493.   if length(chainstr)=0 then begin
  494.     getinputchar:=waitforchar;
  495.     exit
  496.   end;
  497.   k:=chainstr[1];
  498.   delete (chainstr,1,1);
  499.   if (k=',') and (not nochain) then k:=#13;
  500.   getinputchar:=k
  501. end;
  502.  
  503. {=============================================================================}
  504.  
  505. {$I IOtxtFil.Sub}
  506. {$I IOStrings.Sub}
  507.  
  508. {=============================================================================}
  509.  
  510. Procedure cls;
  511. begin
  512.   bottom;
  513.   clrscr;
  514.   bottomline
  515. end;
  516.  
  517. {=============================================================================}
  518.  
  519. Procedure writehdr (q:anystr);
  520. VAR cnt:integer;
  521. begin
  522.   writeln (^B^M);
  523.   for cnt:=1 to (40-length(q)) div 2 do write (' ');
  524.   write (q,^M^M^B)
  525. end;
  526.  
  527. {=============================================================================}
  528.  
  529. Function issysop:boolean;
  530. begin
  531.   issysop:=(ulvl>=sysoplevel) or (cursection in urec.config)
  532. end;
  533.  
  534. {=============================================================================}
  535.  
  536. Procedure reqlevel (l:integer);
  537. begin
  538.   writeln (^B'Nice try, but level ',l,' is required.')
  539. end;
  540.  
  541. {=============================================================================}
  542.  
  543. {$I Prntfile.sub}
  544. {$I Ranges.sub}
  545. {$I Menu.sub}
  546. {$I Password.sub}
  547.  
  548. {=============================================================================}
  549.  
  550. Procedure getacflag (VAR ac:accesstype; VAR tex:mstr);
  551. begin
  552.   writestr ('[K]ick off, [B]y level, [L]et in:');
  553.   ac:=invalid;
  554.   if length(input)=0 then exit;
  555.   case upcase(input[1]) of
  556.     'B':ac:=bylevel;
  557.     'L':ac:=letin;
  558.     'K':ac:=keepout
  559.   end;
  560.   tex:=accessstr[ac]
  561. end;
  562.  
  563. {=============================================================================}
  564.  
  565. {$I Frmstf.pas}
  566.  
  567. begin
  568. end.
  569.  
  570.  
  571.  
  572.