home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / rclesrc.10 / ircle sources / IRCIgnore.p < prev    next >
Encoding:
Text File  |  1992-09-05  |  4.5 KB  |  193 lines

  1. {    ircle - Internet Relay Chat client    }
  2. {    File: IRCIgnore    }
  3. {    Copyright ⌐ 1992 Olaf Titz (s_titz@iravcl.ira.uka.de)    }
  4.  
  5. {    This program is free software; you can redistribute it and/or modify    }
  6. {    it under the terms of the GNU General Public License as published by    }
  7. {    the Free Software Foundation; either version 2 of the License, or    }
  8. {    (at your option) any later version.    }
  9.  
  10. {    This program is distributed in the hope that it will be useful,    }
  11. {    but WITHOUT ANY WARRANTY; without even the implied warranty of    }
  12. {    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    }
  13. {    GNU General Public License for more details.    }
  14.  
  15. {    You should have received a copy of the GNU General Public License    }
  16. {    along with this program; if not, write to the Free Software    }
  17. {    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    }
  18.  
  19. unit IRCIgnore;
  20. { Deals with the /ignore command }
  21.  
  22. interface
  23. uses
  24.     TCPTypes, TCPStuff, TCPConnections, ApplBase, MsgWindows, {}
  25.     IRCGlobals, IRCAux, IRCChannels;
  26.  
  27. procedure InitIRCIgnore;
  28. { Startup }
  29.  
  30. procedure DoIgnore (var s: string);
  31. { handles the /ignore command }
  32. { format: /ignore nick!user@host = ignore nick,user,host}
  33. {    /ignore nick, /ignore user@host do as well}
  34. {     wildcards are ? and * }
  35. {    /ignore +nick!user@host = ignore and give him notice }
  36. {    /ignore = list all ignorations }
  37. {    /ignore -nick!user@host = remove a tag }
  38.  
  39. function IsIgnored (var s: string; p: boolean): boolean;
  40. { handles messages from s - returns true if ignored. p=message may be answered }
  41.  
  42. implementation
  43.  
  44. const
  45.     DELV = chr(4);    { mark for rude ignore }
  46.     DELS = chr(5);    { mark for silent ignore }
  47.  
  48. var
  49.     ign: CharsHandle;
  50.     maxign: integer;
  51.  
  52. procedure ListIgnores;
  53.     var
  54.         s: string;
  55.         i: integer;
  56.     begin
  57.         i := 0;
  58.         while i < maxign do begin
  59.             if ign^^[i] = DELV then
  60.                 s := 'Loudly Ignoring '
  61.             else
  62.                 s := 'Silently Ignoring ';
  63.             repeat
  64.                 i := succ(i);
  65.                 if i >= maxign then
  66.                     leave;
  67.                 if ord(ign^^[i]) < 32 then
  68.                     leave;
  69.                 s := concat(s, ign^^[i]);
  70.             until false;
  71.             LineMsg(s)
  72.         end
  73.     end;
  74.  
  75. procedure DoIgnore (var s: string);
  76.     var
  77.         tag: char;
  78.         i: integer;
  79.     begin
  80.         if s = '' then
  81.             ListIgnores
  82.         else if s[1] = '-' then begin
  83.             i := Munger(Handle(ign), 0, @s[2], length(s) - 1, Ptr(1), 0);
  84.             if i > 0 then
  85.                 i := Munger(Handle(ign), i - 1, nil, 1, Ptr(1), 0);
  86.             maxign := maxign - length(s);
  87.         end
  88.         else begin
  89.             if s[1] = '+' then
  90.                 s[1] := DELV
  91.             else
  92.                 insert(DELS, s, 1);
  93.             if pos('@', s) = 0 then
  94.                 s := concat(s, '!*@*')
  95.             else if pos('!', s) = 0 then
  96.                 s := concat(s[1], '*!', copy(s, 2, 255));
  97.             i := length(s);
  98.             if PtrAndHand(@s[1], Handle(ign), i) = 0 then
  99.                 maxign := maxign + i;
  100.         end;
  101.     end;
  102.  
  103. procedure IgnoreBack (var s: string);
  104.     var
  105.         t: string;
  106.         i: integer;
  107.     begin
  108.         if serverStatus = 0 then begin
  109.             t := s;
  110.             i := pos('!', t);
  111.             if i > 0 then
  112.                 t[0] := chr(i - 1);
  113.             t := concat('NOTICE ', t, ' You are being ignored');
  114.             PutLine(t);
  115.         end;
  116.     end;
  117.  
  118. function upc (c: char): char;
  119.     begin
  120.         if (c >= 'a') and (c <= 'z') then
  121.             upc := chr(ord(c) - 32)
  122.         else
  123.             upc := c
  124.     end;
  125.  
  126. function IsIgnored (var s: string; p: boolean): boolean;
  127.     var
  128.         back: boolean;
  129.         a: integer;
  130.     function matchFrom (i, j: integer): boolean;
  131.         begin
  132.             matchFrom := true;
  133.             repeat
  134.                 if (ign^^[i] < ' ') and (s[j] < ' ') then
  135.                     exit(matchFrom);    { completely matched }
  136.                 if ign^^[i] = '*' then begin
  137.                     i := succ(i);
  138.                     if (i >= maxign) or (ign^^[i] < ' ') then
  139.                         exit(matchFrom); { pattern ended in * : matched }
  140.                     repeat
  141.                         while upc(s[j]) <> upc(ign^^[i]) do begin
  142.                             j := succ(j);
  143.                             if s[j] < ' ' then begin
  144.                                 matchFrom := false; { pattern ended *x , no match for x }
  145.                                 exit(matchFrom);
  146.                             end;
  147.                         end; { pattern *x, , match for x }
  148.                         if matchFrom(i, j) then { check for matching rest }
  149.                             exit(matchFrom);
  150.                         j := succ(j)
  151.                     until s[j] < ' '; { backtrack }
  152.                     matchFrom := false;
  153.                     exit(matchFrom);
  154.                 end
  155.                 else if (ign^^[i] <> '?') then begin
  156.                     if (upc(ign^^[i]) <> upc(s[j])) then begin
  157.                         matchFrom := false;    { Mismatch }
  158.                         exit(matchFrom)
  159.                     end;
  160.                 end;
  161.                 i := succ(i);
  162.                 j := succ(j);
  163.             until false;
  164.         end;
  165.     begin
  166.         s[length(s) + 1] := chr(0);
  167.         a := 0;
  168.         while a < maxign do begin
  169.             back := (ign^^[a] = DELV);
  170.             a := succ(a);
  171.             if matchFrom(a, 1) then begin
  172.                 IsIgnored := true;
  173.                 if p and back then
  174.                     IgnoreBack(s);
  175.                 exit(IsIgnored)
  176.             end;
  177.             repeat
  178.                 a := succ(a);
  179.                 if a >= maxign then
  180.                     leave;
  181.             until ign^^[a] < ' ';
  182.         end;
  183.         IsIgnored := false;
  184.     end;
  185.  
  186.  
  187. procedure InitIRCIgnore;
  188.     begin
  189.         ign := CharsHandle(NewHandle(0));
  190.         maxign := 0;
  191.     end;
  192.  
  193. end.