mirror of https://github.com/nealey/irc-bot
Fixed buf in Client.handle_input
F it, I'll just use regular expressions (Str.split). They're easier to code, the code looks cleaner, and it fixes a buf with a case I hadn't considered.
This commit is contained in:
parent
1617dbca19
commit
1b517745bb
|
@ -3,6 +3,9 @@ OCAMLPACKS[] =
|
||||||
equeue
|
equeue
|
||||||
pcre
|
pcre
|
||||||
str
|
str
|
||||||
|
NATIVE_ENABLED = true
|
||||||
|
BYTE_ENABLED = true
|
||||||
|
OCAMLCFLAGS += -g
|
||||||
|
|
||||||
.DEFAULT: ircd
|
.DEFAULT: ircd
|
||||||
|
|
||||||
|
@ -11,9 +14,11 @@ OCamlProgram(ircd, ircd irc command client channel)
|
||||||
section
|
section
|
||||||
OCAMLPACKS[] +=
|
OCAMLPACKS[] +=
|
||||||
oUnit
|
oUnit
|
||||||
|
NATIVE_ENABLED = false
|
||||||
|
|
||||||
tests.cmx:
|
tests.cmx:
|
||||||
tests.cmi:
|
tests.cmi:
|
||||||
|
tests.cmo:
|
||||||
tests$(EXT_OBJ):
|
tests$(EXT_OBJ):
|
||||||
|
|
||||||
OCamlProgram(tests, tests chat ircd irc command client channel)
|
OCamlProgram(tests, tests chat ircd irc command client channel)
|
||||||
|
|
33
client.ml
33
client.ml
|
@ -73,26 +73,23 @@ let handle_command_login cli cmd =
|
||||||
"NOTICE"
|
"NOTICE"
|
||||||
[nick]))
|
[nick]))
|
||||||
|
|
||||||
let rec handle_input cli =
|
let crlf = Str.regexp "\r?\n"
|
||||||
match cli.ibuf with
|
|
||||||
| "" ->
|
let handle_input cli =
|
||||||
|
let buf = Str.string_before cli.ibuf !(cli.ibuf_len) in
|
||||||
|
let lines = Str.split crlf buf in
|
||||||
|
let rec loop l =
|
||||||
|
match l with
|
||||||
|
| [] ->
|
||||||
()
|
()
|
||||||
| ibuf ->
|
| [leftover] ->
|
||||||
let p =
|
String.blit leftover 0 cli.ibuf 0 (String.length leftover)
|
||||||
let nlp = String.index ibuf '\n' in
|
| line :: tl ->
|
||||||
if ((String.get ibuf (nlp - 1)) = '\r') then
|
let parsed = Command.from_string line in
|
||||||
(nlp - 1)
|
|
||||||
else
|
|
||||||
nlp
|
|
||||||
in
|
|
||||||
let s = String.sub ibuf 0 p in
|
|
||||||
if p >= !(cli.ibuf_len) then
|
|
||||||
raise Not_found;
|
|
||||||
cli.ibuf_len := !(cli.ibuf_len) - (p + 1);
|
|
||||||
String.blit ibuf (p + 1) ibuf 0 !(cli.ibuf_len);
|
|
||||||
let parsed = Command.from_string s in
|
|
||||||
cli.handle_command cli parsed;
|
cli.handle_command cli parsed;
|
||||||
handle_input cli
|
loop tl
|
||||||
|
in
|
||||||
|
loop lines
|
||||||
|
|
||||||
let handle_event ues esys e =
|
let handle_event ues esys e =
|
||||||
match e with
|
match e with
|
||||||
|
|
Loading…
Reference in New Issue