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

  1. {    ircle - Internet Relay Chat client    }
  2. {    File: IRCaux    }
  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 IRCaux;
  20. { utilities }
  21.  
  22. interface
  23. uses
  24.     TCPTypes, TCPStuff, TCPConnections, ApplBase, InputLine, MsgWindows, IRCGlobals;
  25.  
  26. var
  27.     Watch: CursHandle;
  28.  
  29. procedure ServerOK (status: OSErr);
  30. { Call this with the result of TCP functions }
  31.  
  32. procedure PutLine (var s: string);
  33. { Send a line to the server }
  34.  
  35. function IsChannel (var s: string): boolean;
  36. { is it a valid channel name? }
  37.  
  38. procedure NextArg (var from, arg: string);
  39. { get next arg out of 'from' into 'arg' }
  40.  
  41. procedure UpdateStatusLine;
  42. { Draw the IRC status line }
  43.  
  44. implementation
  45.  
  46. type
  47.     str8 = string[8];
  48.  
  49.  
  50. procedure ServerOK (status: OSErr);
  51.     var
  52.         n: integer;
  53.         s: Str255;
  54.     begin
  55.         n := 0;
  56.         case connectionEvent(status) of
  57.             C_SearchFailed: 
  58.                 begin
  59.                 status := -1;
  60.                 n := E_SFAILED;
  61.             end;
  62.             C_NameSearchFailed: 
  63.                 begin
  64.                 status := -1;
  65.                 n := E_NSFAILED;
  66.             end;
  67.             C_FailedToOpen: 
  68.                 begin
  69.                 status := -1;
  70.                 n := E_OFAILED;
  71.             end;
  72.             C_Closing: 
  73.                 begin
  74.                 status := -1;
  75.                 n := E_CLOSING;
  76.             end;
  77.             C_Closed: 
  78.                 begin
  79.                 status := -1;
  80.                 n := E_CLOSED;
  81.             end;
  82.             otherwise
  83.         end;
  84.         serverStatus := status;
  85.         if n <> 0 then begin
  86.             GetIndString(s, 256, n);
  87.             ParamText(s, '', '', '');
  88.             n := Alert(A_SSTAT, nil);
  89.         end;
  90.         UpdateStatusLine;
  91.     end;
  92.  
  93. procedure PutLine (var s: string);
  94.     var
  95.         i, n, oe: integer;
  96.         p: TCPConnectionPtr;
  97.     begin
  98.         n := length(s);
  99.         for i := 1 to n do
  100.             s[i] := ISOEncode^^[s[i]];
  101.         s[n + 1] := chr(10);
  102. {oe := TCPSend(p, @s^[1], ord(s[0]) + 2);}
  103.         GetConnectionTCPC(sSocket, p);
  104.         i := TCPSendAsync(p, @s[1], n + 1, @oe);
  105.         if i <> 0 then
  106.             serverStatus := i
  107.         else begin
  108.             repeat
  109.                 ApplRun
  110.             until oe <> inProgress;
  111.             serverStatus := oe;
  112.         end;
  113.     end;
  114.  
  115. function IsChannel (var s: string): boolean;
  116.     begin
  117.         IsChannel := (s[1] = '#'); { Strictly speaking, this is for 2.7 servers }
  118.     end;
  119.  
  120. procedure NextArg (var from, arg: string);
  121.     var
  122.         i: integer;
  123.     begin
  124.         i := pos(' ', from);
  125.         if i = 0 then begin
  126.             arg := from;
  127.             from := ''
  128.         end
  129.         else begin
  130.             arg := copy(from, 1, i - 1);
  131.             delete(from, 1, i);
  132.             if from[1] = ':' then
  133.                 delete(from, 1, 1);
  134.         end
  135.     end;
  136.  
  137. function two (n: integer): str8;
  138.     var
  139.         s: str8;
  140.     begin
  141.         s := stringof(n + 100 : 3);
  142.         two := copy(s, 2, 2)
  143.     end;
  144.  
  145. procedure UpdateStatusLine;
  146.     var
  147.         s: string[80];
  148.         s0: string[40];
  149.         s1, s2, s3: string[10];
  150.         d: DateTimeRec;
  151.     begin
  152.         case serverStatus of
  153.             S_OFFLINE: 
  154.                 s := '(Offline)';
  155.             S_LOOKUP: 
  156.                 s := '(Address lookup)';
  157.             S_OPENING: 
  158.                 s := '(opening)';
  159.             S_CONN: 
  160.                 s := CurrentServer;
  161.             otherwise
  162.                 s := stringof('Err(', serverStatus : 1, ')');
  163.         end;
  164.         s0 := CurrentTarget;
  165.         if s0 = '' then
  166.             s0 := '(nobody)';
  167.         s0 := concat(s0, '               ');
  168.         if logging then
  169.             s1 := 'Log'
  170.         else
  171.             s1 := '';
  172.         if flushing then
  173.             s2 := 'Flsh'
  174.         else
  175.             s2 := '';
  176.         if NFT > 0 then
  177.             s3 := stringof('FT(', NFT : 1, ')')
  178.         else
  179.             s3 := '';
  180.         GetTime(d);
  181.         s := stringof(CurrentNick : 10, ' talking to', copy(s0, 1, 12) : 13, s : 18, s1 : 4, s2 : 5, s3 : 8, '  ', two(d.hour), ':', two(d.minute), ':', two(d.second));
  182.         StatusLine(s);
  183.     end;
  184.  
  185.  
  186. end.