diff --git a/OMakefile b/OMakefile index 5e42126..1c822ea 100644 --- a/OMakefile +++ b/OMakefile @@ -3,6 +3,9 @@ OCAMLPACKS[] = equeue pcre str +NATIVE_ENABLED = true +BYTE_ENABLED = true +OCAMLCFLAGS += -g .DEFAULT: ircd @@ -11,9 +14,11 @@ OCamlProgram(ircd, ircd irc command client channel) section OCAMLPACKS[] += oUnit + NATIVE_ENABLED = false tests.cmx: tests.cmi: + tests.cmo: tests$(EXT_OBJ): OCamlProgram(tests, tests chat ircd irc command client channel) diff --git a/client.ml b/client.ml index 43eddf9..0ae08cb 100644 --- a/client.ml +++ b/client.ml @@ -73,26 +73,23 @@ let handle_command_login cli cmd = "NOTICE" [nick])) -let rec handle_input cli = - match cli.ibuf with - | "" -> - () - | ibuf -> - let p = - let nlp = String.index ibuf '\n' in - if ((String.get ibuf (nlp - 1)) = '\r') then - (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; - handle_input cli +let crlf = Str.regexp "\r?\n" + +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 + | [] -> + () + | [leftover] -> + String.blit leftover 0 cli.ibuf 0 (String.length leftover) + | line :: tl -> + let parsed = Command.from_string line in + cli.handle_command cli parsed; + loop tl + in + loop lines let handle_event ues esys e = match e with