home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / comm / twft099b.zip / TWLINE.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-26  |  4KB  |  138 lines

  1. Unit TWLine;
  2. {
  3. Copyright (C) 1993 by David Myers.  All rights reserved.  Personal
  4. copying and use of this code permitted.  This source cannot be
  5. sold or distributed for more than the cost of media.
  6. }
  7. interface
  8. uses Crt,FlyCom,FParser,TwBuffer,TWAnsi;
  9.  
  10. Procedure Alarm;
  11.  
  12. Procedure GetaLine(Var T : integer; Var Seps, SS : string;
  13.                    Sterm : string; Var P : parsetype; Var Loop : boolean);
  14. implementation
  15.  
  16. FUNCTION isins(c : char;var s : string) : boolean;
  17.  
  18. { determines if a character c is in string s}
  19.  
  20. var
  21.   t : boolean;
  22.   i : integer;
  23. BEGIN
  24.   t := FALSE;
  25.   i := 1;
  26.   while ((t = FALSE) and (i <= length(s))) do BEGIN
  27.     if (c = s[i]) then
  28.       t := TRUE;
  29.     inc(i);
  30.   END;
  31.   isins := t;
  32. END;
  33.  
  34. Procedure Alarm;
  35. BEGIN
  36.   Sound(440); Delay(100);Nosound; Delay(200);
  37.   Sound(660); Delay(100);Nosound; Delay(200);
  38.   Sound(440); Delay(100);Nosound; Delay(200);
  39.   Sound(440); Delay(100);Nosound; Delay(200);
  40.   Sound(660); Delay(100);Nosound; Delay(200);
  41.   Sound(440); Delay(100);Nosound; Delay(200);
  42.   Sound(440); Delay(100);Nosound; Delay(200);
  43.   Sound(660); Delay(100);Nosound; Delay(200);
  44.   Sound(440); Delay(100);Nosound; Delay(200);
  45. END;
  46.  
  47. Procedure GetaLine(Var T : integer; Var Seps, SS : string;
  48.                    Sterm : string; Var P : parsetype; Var Loop : boolean);
  49. { this procedure gets a line of serial input from the modem and
  50.   parses it.  If tokens are greater than zero, it returns the string
  51.   as well as its parsed version.  Loop is used to supply a termination
  52.   signal to the calling program.
  53.  
  54.   VARIABLES:
  55.  
  56.   INPUT:
  57.  
  58.   Sterm - a list of characters used to terminate strings (other than
  59.           a newline (CHR(10)) character
  60.   Seps  - a list of characters that separate a string into tokens.
  61.           Typically, this is a string consisting of a space, a tab,
  62.           a newline and a return.
  63.   Loop  - a boolean variable equal to TRUE.
  64.  
  65.   OUTPUT
  66.  
  67.   T - the number of tokens in the parsed string
  68.  
  69.   SS - the whole input string
  70.  
  71.   P - ParseType, a record as follows:
  72.  
  73.   P.count : an integer equal to the # of tokens in the record
  74.   P.s[20] : 20 strings, which contain the tokens of SS in the
  75.              order P.s[0] to P.s[count-1]
  76.  
  77.   Loop - If ALT-Q is typed while GetALine is running, string
  78.   processing is terminated and Loop is returned with the value
  79.   FALSE.
  80.  
  81.   }
  82. Var
  83.   count : integer;
  84.   charin : char;
  85.  
  86. BEGIN
  87.   T := 0;
  88.   count := 0;
  89.   WHILE (Loop and (T < 1)) DO
  90.     BEGIN
  91.       If Async_Receive(CharIn) then
  92.         BEGIN
  93.           If BufferisOpen then
  94.             AddToBuffer(CharIn);
  95.           If (CharIn = #27) and AnsiOn then
  96.             Async_Ansi
  97.           Else begin
  98.           { using 2nd buffer for CIM captures now. This buffer doesn't
  99.            see Ansi, we trap it in the above sequence. }
  100.           If Buffer2isOpen then
  101.             Addto2Buffer(Charin);
  102.           Write(CharIn);
  103.           end;
  104.           If CharIn = #12 then
  105.             ClrScr;
  106.           If Ord(CharIn) > 31 THEN
  107.             BEGIN
  108.               Inc(count);
  109.               SS[count] := CharIn;
  110.               SS[0] := chr(count);
  111.             END;
  112.           If (CharIn = #10) or (isins(Charin,Sterm)) or (SS[0] > chr(79)) then
  113.             BEGIN
  114.               T := Parse_Str(Seps,SS,P);
  115.               If (T > 0) THEN BEGIN
  116.                 count := 0;
  117.                 SS[0] := chr(count);
  118.               END;
  119.             END;
  120.           CharIn := #0;
  121.         END
  122.       ELSE BEGIN
  123.         If KeyPressed then
  124.           BEGIN
  125.             CharIn := ReadKey;
  126.             IF (CharIn = #0) THEN
  127.               BEGIN
  128.                Charin := ReadKey;
  129.                If (Charin = #16) THEN { ALT-Q exits }
  130.                  Loop := FALSE;
  131.               END
  132.             ELSE Async_Send(CharIn); {keep this a free-flowing terminal}
  133.           END;
  134.       END;
  135.     END;
  136. END;
  137. END.
  138.