From fa95cca1b4f03457d8a69ae497ad9d770dcebf95 Mon Sep 17 00:00:00 2001 From: malc Date: Sun, 18 Jan 2015 17:32:49 +0300 Subject: [PATCH] Refactoring Move some code to utils. --- config.ml | 19 +++++++++++++++++++ main.ml | 61 ------------------------------------------------------------- utils.ml | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 61 deletions(-) diff --git a/config.ml b/config.ml index f7b57bb..5a3e34d 100644 --- a/config.ml +++ b/config.ml @@ -2029,3 +2029,22 @@ let gc fdi fdo = ("error while saving configuration: " ^ exntos exn) ); ;; + +let logcurrently = function + | Idle -> dolog "Idle" + | Loading (l, gen) -> + dolog "Loading %d gen=%d curgen=%d" l.pageno gen state.gen + | Tiling (l, pageopaque, colorspace, angle, gen, col, row, tilew, tileh) -> + dolog + "Tiling %d[%d,%d] page=%s cs=%s angle" + l.pageno col row (~> pageopaque) + (CSTE.to_string colorspace) + ; + dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)" + angle gen conf.angle state.gen + tilew tileh + conf.tilew conf.tileh + ; + | Outlining _ -> + dolog "outlining" +;; diff --git a/main.ml b/main.ml index e4a5331..c4f6477 100644 --- a/main.ml +++ b/main.ml @@ -446,13 +446,6 @@ let showlinktype under = showtext ' ' s ;; -let addchar s c = - let b = Buffer.create (String.length s + 1) in - Buffer.add_string b s; - Buffer.add_char b c; - Buffer.contents b; -;; - let intentry_with_suffix text key = let c = if key >= 32 && key < 127 @@ -488,8 +481,6 @@ let readcmd fd = Bytes.to_string s ;; -let btod b = if b then 1 else 0;; - let wcmd fmt = let b = Buffer.create 16 in Buffer.add_string b "llll"; @@ -1577,30 +1568,6 @@ let gctiles () = loop 0 ;; -let logcurrently = function - | Idle -> dolog "Idle" - | Loading (l, gen) -> - dolog "Loading %d gen=%d curgen=%d" l.pageno gen state.gen - | Tiling (l, pageopaque, colorspace, angle, gen, col, row, tilew, tileh) -> - dolog - "Tiling %d[%d,%d] page=%s cs=%s angle" - l.pageno col row (~> pageopaque) - (CSTE.to_string colorspace) - ; - dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)" - angle gen conf.angle state.gen - tilew tileh - conf.tilew conf.tileh - ; - | Outlining _ -> - dolog "outlining" -;; - -let splitatspace = - let r = Str.regexp " " in - fun s -> Str.bounded_split r s 2; -;; - let onpagerect pageno f = let b = match conf.columns with @@ -2343,12 +2310,6 @@ let downbirdseye incr (conf, leftx, pageno, hooverpageno, anchor) = state.text <- E.s; ;; -let boundastep h step = - if step < 0 - then bound step ~-h 0 - else bound step 0 h -;; - let optentry mode _ key = let btos b = if b then "on" else "off" in if key >= 32 && key < 127 @@ -2556,28 +2517,6 @@ class virtual lvsourcebase = object method getminfo : (int * int) array = E.a end;; -let withoutlastutf8 s = - let len = String.length s in - if len = 0 - then s - else - let rec find pos = - if pos = 0 - then pos - else - let b = Char.code s.[pos] in - if b land 0b11000000 = 0b11000000 - then pos - else find (pos-1) - in - let first = - if Char.code s.[len-1] land 0x80 = 0 - then len-1 - else find (len-1) - in - String.sub s 0 first; -;; - let textentrykeyboard key _mask ((c, text, opthist, onkey, ondone, cancelonempty), onleave) = let key = diff --git a/utils.ml b/utils.ml index e3bcabd..416564e 100644 --- a/utils.ml +++ b/utils.ml @@ -171,3 +171,45 @@ let filelines path = ;; let unit () = ();; + +let addchar s c = + let b = Buffer.create (String.length s + 1) in + Buffer.add_string b s; + Buffer.add_char b c; + Buffer.contents b; +;; + +let btod b = if b then 1 else 0;; + +let splitatspace = + let r = Str.regexp " " in + fun s -> Str.bounded_split r s 2; +;; + +let boundastep h step = + if step < 0 + then bound step ~-h 0 + else bound step 0 h +;; + +let withoutlastutf8 s = + let len = String.length s in + if len = 0 + then s + else + let rec find pos = + if pos = 0 + then pos + else + let b = Char.code s.[pos] in + if b land 0b11000000 = 0b11000000 + then pos + else find (pos-1) + in + let first = + if Char.code s.[len-1] land 0x80 = 0 + then len-1 + else find (len-1) + in + String.sub s 0 first; +;; -- 2.11.4.GIT