don't know.

This commit is contained in:
norayr 2017-05-22 22:59:58 +04:00
parent f2d06dd9a5
commit 0edfd99ca4
2 changed files with 98 additions and 88 deletions

133
IRC.Mod
View file

@ -47,7 +47,6 @@ CONST
cbPublicMessage* = PROCEDURE (VAR msg, msgtype, user, ident, rcpt, host: ARRAY OF CHAR);
cbPublicMessageWithMention* = PROCEDURE(VAR msg, msgtype, user, ident, rcpt, host: ARRAY OF CHAR); (* rcpt is usually the room in case of public messages *)
instance* = RECORD
owner*, user*, nick*, host*, port*: chn;
connection*: Internet.Socket;
@ -60,7 +59,8 @@ CONST
VAR
eol* : ARRAY 3 OF CHAR;
eol- : ARRAY 3 OF CHAR;
debug: BOOLEAN;
PROCEDURE setLogging*(VAR inst: instance; state: BOOLEAN);
BEGIN
@ -397,57 +397,6 @@ BEGIN
Strings.Delete(msg, 0, Strings.Length(nick) + 2);
END cutMentionFromMessage;
(* IntToStr routine taken from
https://github.com/romiras/Oberon-F-components/blob/master/Ott/Mod/IntStr.cp
and modified to work on 64bit system by dcwbrown,
in order to avoid using oocIntStr, which has many dependencies *)
PROCEDURE Reverse0 (VAR str : ARRAY OF CHAR; start, end : INTEGER);
(* Reverses order of characters in the interval [start..end]. *)
VAR
h : CHAR;
BEGIN
WHILE start < end DO
h := str[start]; str[start] := str[end]; str[end] := h;
INC(start); DEC(end)
END
END Reverse0;
PROCEDURE IntToStr*(int: LONGINT; VAR str: ARRAY OF CHAR);
(* Converts the value of `int' to string form and copies the possibly truncated
result to `str'. *)
VAR
b : ARRAY 21 OF CHAR;
s, e: INTEGER;
maxLength : SHORTINT; (* maximum number of digits representing a LONGINT value *)
BEGIN
IF SIZE(LONGINT) = 4 THEN maxLength := 11 END;
IF SIZE(LONGINT) = 8 THEN maxLength := 20 END;
(* build representation in string 'b' *)
IF int = MIN(LONGINT) THEN (* smallest LONGINT, -int is an overflow *)
IF SIZE(LONGINT) = 4 THEN
b := "-2147483648";
e := 11
ELSE (* SIZE(LONGINT) = 8 *)
b := "-9223372036854775808";
e := 20
END
ELSE
IF int < 0 THEN (* negative sign *)
b[0] := "-"; int := -int; s := 1
ELSE (* no sign *)
s := 0
END;
e := s; (* 's' holds starting position of string *)
REPEAT
b[e] := CHR(int MOD 10+ORD("0"));
int := int DIV 10;
INC(e)
UNTIL int = 0;
b[e] := 0X;
Reverse0(b, s, e-1);
END;
COPY(b, str) (* truncate output if necessary *)
END IntToStr;
PROCEDURE formTimeString(VAR str: ARRAY OF CHAR);
VAR
@ -456,12 +405,12 @@ VAR
BEGIN
time.Now(year, month, day, hour, minute, second);
IntToStr(year, syear);
IntToStr(month, smonth);
IntToStr(day, sday);
IntToStr(hour, shour);
IntToStr(minute, sminute);
IntToStr(second, ssecond);
sh.IntToStr(year, syear);
sh.IntToStr(month, smonth);
sh.IntToStr(day, sday);
sh.IntToStr(hour, shour);
sh.IntToStr(minute, sminute);
sh.IntToStr(second, ssecond);
COPY(syear, str);
Strings.Append("-", str);
@ -484,36 +433,38 @@ VAR
str: ARRAY msgLen OF CHAR;
tmp: ARRAY 16 OF CHAR;
BEGIN
sh.zeroStr(str);
Out.String("logging about: "); Out.String(username); Out.String(", "); Out.String(messagetype); Out.String(", "); Out.String(rcpt); Out.Ln;
i := 0; b := FALSE;
REPEAT
Out.String("is "); Out.String(inst.channelList^[i].channel); Out.String("="); Out.String(rcpt); Out.String("?"); Out.Ln;
IF inst.channelList^[i].channel = rcpt THEN b := TRUE END;
INC(i);
UNTIL (i = LEN(inst.channelList^)) OR b;
IF b THEN Out.String("yes!") ELSE Out.String("no!") END; Out.Ln;
IF b OR (messagetype = msgPART) THEN (* we don't know from which channel user quits so we only write to log about it when he parts. *)
DEC(i);
formTimeString(str);
Strings.Append(username, str);
IF messagetype = msgPRIVMSG THEN
tmp := ": ";
Strings.Append(tmp, str);
Strings.Append(message, str);
ELSIF messagetype = msgJOIN THEN
tmp := " joined ";
Strings.Append (tmp, str);
Strings.Append (rcpt, str);
ELSIF (messagetype = msgPART) THEN
tmp := " has quit";
Strings.Append(tmp, str);
IF inst.doLog THEN
sh.zeroStr(str);
Out.String("logging about: "); Out.String(username); Out.String(", "); Out.String(messagetype); Out.String(", "); Out.String(rcpt); Out.Ln;
i := 0; b := FALSE;
REPEAT
Out.String("is "); Out.String(inst.channelList^[i].channel); Out.String("="); Out.String(rcpt); Out.String("?"); Out.Ln;
IF inst.channelList^[i].channel = rcpt THEN b := TRUE END;
INC(i);
UNTIL (i = LEN(inst.channelList^)) OR b;
IF b THEN Out.String("yes!") ELSE Out.String("no!") END; Out.Ln;
IF b OR (messagetype = msgPART) THEN (* we don't know from which channel user quits so we only write to log about it when he parts. *)
DEC(i);
formTimeString(str);
Strings.Append(username, str);
IF messagetype = msgPRIVMSG THEN
tmp := ": ";
Strings.Append(tmp, str);
Strings.Append(message, str);
ELSIF messagetype = msgJOIN THEN
tmp := " joined ";
Strings.Append (tmp, str);
Strings.Append (rcpt, str);
ELSIF (messagetype = msgPART) THEN
tmp := " has quit";
Strings.Append(tmp, str);
END;
Out.String("writing to "); Out.String(rcpt); Out.String(" log: "); Out.String(str); Out.Ln;
Files.WriteString(inst.channelList^[i].rider, str);
Files.Set(inst.channelList^[i].rider, inst.channelList^[i].logfile, Files.Pos(inst.channelList^[i].rider)-1); Files.Write(inst.channelList^[i].rider, 0AX);
Files.Register(inst.channelList^[i].logfile);
END;
Out.String("writing to "); Out.String(rcpt); Out.String(" log: "); Out.String(str); Out.Ln;
Files.WriteString(inst.channelList^[i].rider, str);
Files.Set(inst.channelList^[i].rider, inst.channelList^[i].logfile, Files.Pos(inst.channelList^[i].rider)-1); Files.Write(inst.channelList^[i].rider, 0AX);
Files.Register(inst.channelList^[i].logfile);
END;
END; (* if do log *)
END log;
PROCEDURE finalize*(VAR inst: instance);
@ -692,6 +643,12 @@ BEGIN
UNTIL ~b OR ~b2;
END Loop;
PROCEDURE setDebug*(state: BOOLEAN);
BEGIN
debug := state
END setDebug;
BEGIN
eol[0] := LF; eol[1] := CR;
debug := FALSE;
END IRC.

View file

@ -187,4 +187,57 @@ BEGIN
RETURN pstrs
END textToPstrings;
(* IntToStr routine taken from
https://github.com/romiras/Oberon-F-components/blob/master/Ott/Mod/IntStr.cp
and modified to work on 64bit system by dcwbrown,
in order to avoid using oocIntStr, which has many dependencies *)
PROCEDURE Reverse0 (VAR str : ARRAY OF CHAR; start, end : INTEGER);
(* Reverses order of characters in the interval [start..end]. *)
VAR
h : CHAR;
BEGIN
WHILE start < end DO
h := str[start]; str[start] := str[end]; str[end] := h;
INC(start); DEC(end)
END
END Reverse0;
PROCEDURE IntToStr*(int: LONGINT; VAR str: ARRAY OF CHAR);
(* Converts the value of `int' to string form and copies the possibly truncated
result to `str'. *)
VAR
b : ARRAY 21 OF CHAR;
s, e: INTEGER;
maxLength : SHORTINT; (* maximum number of digits representing a LONGINT value *)
BEGIN
IF SIZE(LONGINT) = 4 THEN maxLength := 11 END;
IF SIZE(LONGINT) = 8 THEN maxLength := 20 END;
(* build representation in string 'b' *)
IF int = MIN(LONGINT) THEN (* smallest LONGINT, -int is an overflow *)
IF SIZE(LONGINT) = 4 THEN
b := "-2147483648";
e := 11
ELSE (* SIZE(LONGINT) = 8 *)
b := "-9223372036854775808";
e := 20
END
ELSE
IF int < 0 THEN (* negative sign *)
b[0] := "-"; int := -int; s := 1
ELSE (* no sign *)
s := 0
END;
e := s; (* 's' holds starting position of string *)
REPEAT
b[e] := CHR(int MOD 10+ORD("0"));
int := int DIV 10;
INC(e)
UNTIL int = 0;
b[e] := 0X;
Reverse0(b, s, e-1);
END;
COPY(b, str) (* truncate output if necessary *)
END IntToStr;
END stringHelpers.