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:
Neale Pickett 2008-02-29 17:16:00 -07:00
parent 1617dbca19
commit 1b517745bb
2 changed files with 22 additions and 20 deletions

View File

@ -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)

View File

@ -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
| ibuf -> let lines = Str.split crlf buf in
let p = let rec loop l =
let nlp = String.index ibuf '\n' in match l with
if ((String.get ibuf (nlp - 1)) = '\r') then | [] ->
(nlp - 1) ()
else | [leftover] ->
nlp String.blit leftover 0 cli.ibuf 0 (String.length leftover)
in | line :: tl ->
let s = String.sub ibuf 0 p in let parsed = Command.from_string line in
if p >= !(cli.ibuf_len) then cli.handle_command cli parsed;
raise Not_found; loop tl
cli.ibuf_len := !(cli.ibuf_len) - (p + 1); in
String.blit ibuf (p + 1) ibuf 0 !(cli.ibuf_len); loop lines
let parsed = Command.from_string s in
cli.handle_command cli parsed;
handle_input cli
let handle_event ues esys e = let handle_event ues esys e =
match e with match e with