mirror of
https://github.com/vishapoberon/vipak.git
synced 2026-04-05 20:42:26 +00:00
now processFurther procedure will get all the messages line by line. --
noch
This commit is contained in:
parent
4412d4803e
commit
e8d5186bd6
2 changed files with 102 additions and 41 deletions
86
IRC.Mod
86
IRC.Mod
|
|
@ -3,22 +3,26 @@ IMPORT Internet, Out, Files, Strings := ooc2Strings, sh := stringHelpers, types,
|
||||||
|
|
||||||
CONST
|
CONST
|
||||||
msgLen* = 512; (* message length not more than 512 characters *)
|
msgLen* = 512; (* message length not more than 512 characters *)
|
||||||
cmdPing* = "PING";
|
(* irc commands *)
|
||||||
cmdPong* = "PONG";
|
cmdPing* = "PING";
|
||||||
cmdMode* = "MODE";
|
cmdPong* = "PONG";
|
||||||
cmdJoin* = "JOIN";
|
cmdMode* = "MODE";
|
||||||
cmdUser* = "USER";
|
cmdJoin* = "JOIN";
|
||||||
cmdNick* = "NICK";
|
cmdUser* = "USER";
|
||||||
msgPRIVMSG* = "PRIVMSG";
|
cmdNick* = "NICK";
|
||||||
msgNOTICE* = "NOTICE";
|
msgPRIVMSG* = "PRIVMSG";
|
||||||
msgQUIT* = "QUIT";
|
msgNOTICE* = "NOTICE";
|
||||||
msgJOIN* = "JOIN";
|
msgQUIT* = "QUIT";
|
||||||
msgPART* = "PART";
|
msgJOIN* = "JOIN";
|
||||||
msg001 = "001";
|
msgPART* = "PART";
|
||||||
msg002 = "002";
|
(* irc replies rfc1459 from https://www.alien.net.au/irc/irc2numerics.html *)
|
||||||
msg003 = "003";
|
rplWelcome = "001";
|
||||||
msg004 = "004";
|
rplYourHost = "002";
|
||||||
msg005 = "005";
|
rplCreated = "003";
|
||||||
|
rplMyInfo = "004";
|
||||||
|
rplBounce = "005";
|
||||||
|
rplNameReply = "353";
|
||||||
|
rplEndOfNames = "366";
|
||||||
|
|
||||||
CR* = 0DX;
|
CR* = 0DX;
|
||||||
LF* = 0AX;
|
LF* = 0AX;
|
||||||
|
|
@ -136,20 +140,10 @@ BEGIN
|
||||||
END
|
END
|
||||||
END isPing;
|
END isPing;
|
||||||
|
|
||||||
PROCEDURE serverMsg(VAR line: ARRAY OF CHAR): BOOLEAN;
|
PROCEDURE isServerMsg(VAR line: ARRAY OF CHAR): BOOLEAN;
|
||||||
BEGIN
|
BEGIN
|
||||||
IF line[0] = ':' THEN RETURN TRUE ELSE RETURN FALSE END
|
IF line[0] = ':' THEN RETURN TRUE ELSE RETURN FALSE END
|
||||||
END serverMsg;
|
END isServerMsg;
|
||||||
|
|
||||||
PROCEDURE rplWelcome(VAR line : ARRAY OF CHAR): BOOLEAN;
|
|
||||||
VAR
|
|
||||||
found: BOOLEAN;
|
|
||||||
pos : INTEGER;
|
|
||||||
tmp: ARRAY 128 OF CHAR;
|
|
||||||
BEGIN
|
|
||||||
Strings.FindNext(msg001, line, 0, found, pos);
|
|
||||||
IF found THEN RETURN TRUE ELSE RETURN FALSE END
|
|
||||||
END rplWelcome;
|
|
||||||
|
|
||||||
PROCEDURE error(VAR line: ARRAY OF CHAR): BOOLEAN;
|
PROCEDURE error(VAR line: ARRAY OF CHAR): BOOLEAN;
|
||||||
VAR
|
VAR
|
||||||
|
|
@ -622,27 +616,41 @@ BEGIN
|
||||||
END;
|
END;
|
||||||
END;
|
END;
|
||||||
ELSE
|
ELSE
|
||||||
Out.String("unknown msg type: '"); Out.String(message); Out.String("' - ignoring!"); Out.Ln;
|
Out.String("unknown msg type: '"); Out.String(messagetype); Out.String("' - ignoring!"); Out.Ln;
|
||||||
END;
|
END;
|
||||||
END processFurther;
|
END processFurther;
|
||||||
|
|
||||||
PROCEDURE processResponse(VAR inst: instance; VAR line: ARRAY OF CHAR): BOOLEAN;
|
PROCEDURE processLineByLine(VAR inst: instance; VAR text: ARRAY OF CHAR);
|
||||||
|
VAR
|
||||||
|
i : INTEGER;
|
||||||
|
pstrs: sh.pstrings;
|
||||||
|
BEGIN
|
||||||
|
pstrs := sh.textToPstrings(text);
|
||||||
|
i := 0;
|
||||||
|
REPEAT
|
||||||
|
Out.Int(i, 0); Out.String(": '"); Out.String(pstrs^[i]^); Out.String("'"); Out.Ln;
|
||||||
|
processFurther(inst, pstrs^[i]^);
|
||||||
|
INC(i)
|
||||||
|
UNTIL i = LEN(pstrs^);
|
||||||
|
END processLineByLine;
|
||||||
|
|
||||||
|
PROCEDURE processResponse(VAR inst: instance; VAR text: ARRAY OF CHAR): BOOLEAN;
|
||||||
VAR
|
VAR
|
||||||
b : BOOLEAN;
|
b : BOOLEAN;
|
||||||
BEGIN
|
BEGIN
|
||||||
b := TRUE;
|
b := TRUE;
|
||||||
IF isPing(line) THEN
|
IF isPing(text) THEN
|
||||||
Pong(inst, line);
|
Pong(inst, text);
|
||||||
END;
|
END;
|
||||||
IF error(line) THEN
|
IF error(text) THEN
|
||||||
Disconnect(inst);
|
Disconnect(inst);
|
||||||
b := FALSE;
|
b := FALSE;
|
||||||
ELSE
|
ELSE
|
||||||
IF serverMsg(line) THEN (* string starts with ':' *)
|
IF isServerMsg(text) THEN (* string starts with ':' *)
|
||||||
IF rplWelcome(line) THEN (* string contains '001' *)
|
IF sh.contains1(text, rplWelcome) THEN (* string contains '001' *)
|
||||||
ModeAndJoin(inst);
|
ModeAndJoin(inst);
|
||||||
ELSE
|
ELSE
|
||||||
processFurther(inst, line);
|
processLineByLine(inst, text);
|
||||||
END;
|
END;
|
||||||
END;
|
END;
|
||||||
END;
|
END;
|
||||||
|
|
@ -652,11 +660,11 @@ END processResponse;
|
||||||
PROCEDURE Loop*(VAR inst: instance);
|
PROCEDURE Loop*(VAR inst: instance);
|
||||||
VAR
|
VAR
|
||||||
b, b2 : BOOLEAN;
|
b, b2 : BOOLEAN;
|
||||||
str : ARRAY msgLen OF CHAR;
|
txt : ARRAY msgLen OF CHAR;
|
||||||
BEGIN
|
BEGIN
|
||||||
REPEAT
|
REPEAT
|
||||||
b := Receive(inst, str);
|
b := Receive(inst, txt);
|
||||||
b2 := processResponse(inst, str);
|
b2 := processResponse(inst, txt);
|
||||||
UNTIL ~b OR ~b2;
|
UNTIL ~b OR ~b2;
|
||||||
END Loop;
|
END Loop;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
MODULE stringHelpers; (*noch 18.5.2017 / 18.5.2017*)
|
MODULE stringHelpers; (*noch 18.5.2017 / 18.5.2017*)
|
||||||
IMPORT Strings := ooc2Strings;
|
IMPORT Strings := ooc2Strings, Out;
|
||||||
|
|
||||||
CONST
|
CONST
|
||||||
CR* = 0DX;
|
CR* = 0DX;
|
||||||
LF* = 0AX;
|
LF* = 0AX;
|
||||||
|
|
||||||
(** feels whole array with zeroes, useful when one needs to get several strings which contain characters < ' ' and not necessarily end with 0X *)
|
TYPE
|
||||||
|
pstring* = POINTER TO ARRAY OF CHAR;
|
||||||
|
pstrings* = POINTER TO ARRAY OF pstring;
|
||||||
|
|
||||||
|
(** fills whole array with zeroes, useful when one needs to get several strings which contain characters < ' ' and not necessarily end with 0X *)
|
||||||
PROCEDURE zeroStr*(VAR str: ARRAY OF CHAR);
|
PROCEDURE zeroStr*(VAR str: ARRAY OF CHAR);
|
||||||
VAR
|
VAR
|
||||||
i, j : LONGINT;
|
i, j : LONGINT;
|
||||||
|
|
@ -121,5 +125,54 @@ UNTIL found OR (i = LEN(line) - patternLength - 1);
|
||||||
IF found THEN RETURN TRUE ELSE RETURN FALSE END
|
IF found THEN RETURN TRUE ELSE RETURN FALSE END
|
||||||
END contains;
|
END contains;
|
||||||
|
|
||||||
|
PROCEDURE contains1*(VAR line: ARRAY OF CHAR; pat : ARRAY OF CHAR): BOOLEAN;
|
||||||
|
VAR
|
||||||
|
found: BOOLEAN;
|
||||||
|
pos : INTEGER;
|
||||||
|
BEGIN
|
||||||
|
Strings.FindNext(pat, line, 0, found, pos);
|
||||||
|
IF found THEN RETURN TRUE ELSE RETURN FALSE END
|
||||||
|
END contains1;
|
||||||
|
|
||||||
|
PROCEDURE dumpText(VAR text: ARRAY OF CHAR);
|
||||||
|
VAR
|
||||||
|
i : INTEGER;
|
||||||
|
BEGIN
|
||||||
|
i := 0;
|
||||||
|
REPEAT
|
||||||
|
Out.Int(i, 3); Out.String(" | ord: "); Out.Int(ORD(text[i]), 15); Out.String(", char: '"); Out.Char(text[i]); Out.Char("'"); Out.Ln;
|
||||||
|
INC(i)
|
||||||
|
UNTIL i = LEN(text);
|
||||||
|
END dumpText;
|
||||||
|
|
||||||
|
PROCEDURE textToPstrings*(VAR text: ARRAY OF CHAR): pstrings;
|
||||||
|
VAR
|
||||||
|
i, j, lineNum, start, number: INTEGER;
|
||||||
|
pstrs: pstrings;
|
||||||
|
pstr: pstring;
|
||||||
|
BEGIN
|
||||||
|
i := 0;
|
||||||
|
j := 0;
|
||||||
|
REPEAT
|
||||||
|
IF text[i] = 0AX THEN INC(j) END;
|
||||||
|
INC(i);
|
||||||
|
UNTIL (i = LEN(text)) OR (text[i] = 0X); (* now in j we have count of lines *)
|
||||||
|
(* and in i we have position of the end of the text *)
|
||||||
|
NEW(pstrs, j); (*creating ptsrs array with that count *)
|
||||||
|
lineNum := 0; (* current line number, will inc until j*)
|
||||||
|
number := 0; (* character index in the text *)
|
||||||
|
REPEAT (* now we have to fill it line by line *)
|
||||||
|
WHILE (text[number] = 0AX) OR (text[number] = 0DX) DO INC(number) END;
|
||||||
|
start := number;
|
||||||
|
REPEAT
|
||||||
|
INC(number)
|
||||||
|
UNTIL (number = LEN(text) - 1) OR (text[number] = 0AX) OR (text[number] = 0DX) OR (text[number] = 0X); (* reached eol *)
|
||||||
|
NEW(pstr, number - start + 1);
|
||||||
|
Strings.Extract(text, start, number - start, pstr^);
|
||||||
|
pstrs^[lineNum] := pstr;
|
||||||
|
INC(lineNum);
|
||||||
|
UNTIL (lineNum = j) OR (number = i);
|
||||||
|
RETURN pstrs
|
||||||
|
END textToPstrings;
|
||||||
|
|
||||||
END stringHelpers.
|
END stringHelpers.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue