diff --git a/kicadsch.opam b/kicadsch.opam new file mode 100644 index 0000000..acbba1d --- /dev/null +++ b/kicadsch.opam @@ -0,0 +1,21 @@ +opam-version: "1.2" +maintainer: "Jean-Noel Avila " +author: "Jean-Noel Avila " +homepage: "https://jnavila.github.io/plotkicadsch/" +bug-reports: "https://github.com/jnavila/plotkicadsch/issues" +license: "ISC" +dev-repo: "https://github.com/jnavila/plotkicadsch.git" +doc: "" +build: [ + [ "jbuilder" "subst" ] {pinned} + [ "jbuilder" "build" "-p" name "-j" jobs ] +] +build-test: [["jbuilder" "runtest" "-p" name "-j" jobs]] +depends: [ + "jbuilder" {build} + "oUnit" {test} + "pcre" + "tyxml" {>= "4.0.0"} + "base64" +] +available: [ ocaml-version >= "4.03" ] diff --git a/kicadsch/src/jbuild b/kicadsch/src/jbuild new file mode 100644 index 0000000..d425d0f --- /dev/null +++ b/kicadsch/src/jbuild @@ -0,0 +1,16 @@ +(jbuild_version 1) + +(library + ((name kicadsch) + (public_name kicadsch) + (synopsis "Library to plotting KiCAD schematics") + (libraries + ( + pcre + tyxml + base64 + str + ) + ) + (flags (:standard -w -3 -safe-string)) + )) diff --git a/src/kicadSch_sigs.ml b/kicadsch/src/kicadSch_sigs.ml similarity index 100% rename from src/kicadSch_sigs.ml rename to kicadsch/src/kicadSch_sigs.ml diff --git a/src/kicadlib.ml b/kicadsch/src/kicadlib.ml similarity index 100% rename from src/kicadlib.ml rename to kicadsch/src/kicadlib.ml diff --git a/src/kicadsch.ml b/kicadsch/src/kicadsch.ml similarity index 99% rename from src/kicadsch.ml rename to kicadsch/src/kicadsch.ml index 42d1e9f..3329a56 100644 --- a/src/kicadsch.ml +++ b/kicadsch/src/kicadsch.ml @@ -1,4 +1,6 @@ open KicadSch_sigs +module SvgPainter = SvgPainter +module Sigs=KicadSch_sigs module MakeSchPainter (P: Painter): (SchPainter with type painterContext := P.t) = struct module CPainter = Kicadlib.MakePainter(P) @@ -57,7 +59,7 @@ struct | "I"| "Input" -> InputPort | "B"| "BiDi" -> BiDiPort | "~" -> NoPort - | _ as s -> ignore (Lwt_io.eprintf "unknown port type %s\n" s); NoPort + | _ as s -> ignore (Printf.printf "unknown port type %s\n" s); NoPort let justify_of_string s = match String.get s 0 with @@ -254,7 +256,7 @@ struct (Printf.printf "cannot plot component with missing definitions !"; comp, canevas) else comp,canevas) - | _ -> (ignore(Lwt_io.eprintf "ignored %s\n" line); + | _ -> (ignore(Printf.printf "ignored %s\n" line); comp, canevas) let parse_wire_wire = diff --git a/src/schparse.ml b/kicadsch/src/schparse.ml similarity index 100% rename from src/schparse.ml rename to kicadsch/src/schparse.ml diff --git a/src/svgPainter.ml b/kicadsch/src/svgPainter.ml similarity index 100% rename from src/svgPainter.ml rename to kicadsch/src/svgPainter.ml diff --git a/kicadsch/test/jbuild b/kicadsch/test/jbuild new file mode 100644 index 0000000..82b913c --- /dev/null +++ b/kicadsch/test/jbuild @@ -0,0 +1,17 @@ + +(executable + ((name test) + (libraries + ( + oUnit + kicadsch + ) + ) + (flags (:standard -w -27 )) + + )) + +(alias + ((name runtest) + (deps (test.exe)) + (action (run ${<})))) diff --git a/test/stubPainter.ml b/kicadsch/test/stubPainter.ml similarity index 92% rename from test/stubPainter.ml rename to kicadsch/test/stubPainter.ml index 62dcd43..106176e 100644 --- a/test/stubPainter.ml +++ b/kicadsch/test/stubPainter.ml @@ -1,4 +1,4 @@ -open KicadSch_sigs +open Kicadsch.Sigs type t = string list @@ -46,7 +46,7 @@ let paint_image co s b c = c let get_context () = [] -let result: string list ref = ref [] +let set_canevas_size _ _ c = + c -let write oc c = - result := c; Lwt.return_unit +let write c = c diff --git a/test/test.ml b/kicadsch/test/test.ml similarity index 76% rename from test/test.ml rename to kicadsch/test/test.ml index d50ea63..d851b55 100644 --- a/test/test.ml +++ b/kicadsch/test/test.ml @@ -1,9 +1,7 @@ open OUnit -open Lwt.Infix module MUT = Kicadsch.MakeSchPainter(StubPainter) -let toto = Lwt_io.open_file Lwt_io.Output "/tmp/toto" let init () = MUT.initial_context () @@ -11,8 +9,7 @@ let test_printable_F_line () = let line = "F 0 \"Y1\" V 10004 3631 50 0000 L CNN" in let u = MUT.parse_line "$Comp" (init ()) in let v = MUT.parse_line line u in - Lwt_main.run (toto >>= fun t -> MUT.output_context v t); - match !StubPainter.result with + match StubPainter.write (MUT.output_context v) with | [] -> failwith "Field should have been printed" | [v] -> assert true | u::v::w -> failwith "Only one line should be printed" @@ -22,8 +19,7 @@ let test_notprintable_F_line () = let u = MUT.parse_line "$Comp" (init ()) in let u' = MUT.parse_line line u in let v = MUT.parse_line "$EndComp" u' in - Lwt_main.run (toto >>= fun t -> MUT.output_context v t); - match !StubPainter.result with + match StubPainter.write (MUT.output_context v) with | [] -> () | _ -> failwith "Field should not have been printed" @@ -31,8 +27,7 @@ let match_wire_line () = let line = " 5500 1700 5500 2200" in let u = MUT.parse_line "Wire Wire Line" (init ()) in let v = MUT.parse_line line u in - Lwt_main.run (toto >>= fun t -> MUT.output_context v t); - match !StubPainter.result with + match StubPainter.write (MUT.output_context v) with | [v] -> () | _ -> failwith "Wire line should have matched" diff --git a/plotkicadsch.opam b/plotkicadsch.opam index ccb8f8b..ad33f19 100644 --- a/plotkicadsch.opam +++ b/plotkicadsch.opam @@ -10,14 +10,9 @@ build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] depends: [ - "ocamlfind" {build} "jbuilder" {build} - "pcre" - "tyxml" {>= "4.0.0"} - "lwt" - "base64" - "sha" - "git" - "git-unix" + "lwt" + "sha" + "git" + "git-unix" ] -available: [ ocaml-version >= "4.03" ] diff --git a/src/git-imgdiff b/plotkicadsch/src/git-imgdiff similarity index 100% rename from src/git-imgdiff rename to plotkicadsch/src/git-imgdiff diff --git a/src/jbuild b/plotkicadsch/src/jbuild similarity index 75% rename from src/jbuild rename to plotkicadsch/src/jbuild index c6bf7d7..42c3c67 100644 --- a/src/jbuild +++ b/plotkicadsch/src/jbuild @@ -7,20 +7,18 @@ (package plotkicadsch) (libraries ( + kicadsch git-unix lwt lwt.unix sha - pcre - tyxml - base64 str ) ) - (flags (:standard -w -3 -safe-string)) )) (install - ((section bin) + ((package plotkicadsch) + (section bin) (files (git-imgdiff)) )) diff --git a/src/plotgitsch.ml b/plotkicadsch/src/plotgitsch.ml similarity index 97% rename from src/plotgitsch.ml rename to plotkicadsch/src/plotgitsch.ml index eb895a9..695bd3b 100644 --- a/src/plotgitsch.ml +++ b/plotkicadsch/src/plotgitsch.ml @@ -2,7 +2,7 @@ open Lwt.Infix open Git_unix module Search = Git.Search.Make(FS) -module SvgSchPainter = Kicadsch.MakeSchPainter(SvgPainter) +module SvgSchPainter = Kicadsch.MakeSchPainter(Kicadsch.SvgPainter) open SvgSchPainter module type Simple_FS = sig @@ -97,7 +97,7 @@ let process_file initctx svg_name content = initctx >>= fun init -> content >|= Str.split (Str.regexp "\n") >>= fun lines -> Lwt_stream.fold parse_line (Lwt_stream.of_list lines) init >>= fun endcontext -> - Lwt_io.with_file ~mode:Lwt_io.Output svg_name (fun o -> Lwt_io.write o (SvgPainter.write @@ output_context endcontext)) + Lwt_io.with_file ~mode:Lwt_io.Output svg_name (fun o -> Lwt_io.write o (Kicadsch.SvgPainter.write @@ output_context endcontext)) let rev_parse r = let open Lwt_process in diff --git a/src/plotkicadsch.ml b/plotkicadsch/src/plotkicadsch.ml similarity index 94% rename from src/plotkicadsch.ml rename to plotkicadsch/src/plotkicadsch.ml index e8e720f..2ccfd57 100644 --- a/src/plotkicadsch.ml +++ b/plotkicadsch/src/plotkicadsch.ml @@ -1,4 +1,5 @@ -module SvgSchPainter = Kicadsch.MakeSchPainter(SvgPainter) +open Kicadsch +module SvgSchPainter = MakeSchPainter(SvgPainter) open Lwt open SvgSchPainter