M bin/eeschema2netlist.ml => bin/eeschema2netlist.ml +31 -3
@@ 1,4 1,32 @@
-let compdef_filename = "data/minimal/minimal-cache.lib"
-let sch_filename = "data/minimal/minimal.sch"
+open BatOptParse
-let () = Eeschema.Parser.convert compdef_filename sch_filename "out2.cir"
+let main () =
+ let overwrite_opt = StdOpt.store_true () in
+ let out_filename_opt = Opt.value_option "FILE" (Some None) (BatOption.some) (fun _exn file -> "error: " ^ file) in
+ let optparser = OptParser.make ~version:Eeschema.Version.version () in
+ OptParser.add optparser
+ ~help:"overwrite output file"
+ ~short_name:'f'
+ ~long_name:"overwrite"
+ overwrite_opt;
+ OptParser.add optparser
+ ~help:"output filename"
+ ~short_name:'o'
+ ~long_name:"output"
+ out_filename_opt;
+ let args = OptParser.parse_argv optparser in
+ let overwrite = Opt.get overwrite_opt in
+ match args with
+ | [input_filename] ->
+ let compdef_filename = Eeschema.Parser.cache_lib input_filename in
+ let output_filename = match (Opt.get out_filename_opt) with
+ | Some o -> o
+ | None -> Eeschema.Util.replace_suffix_exn input_filename ".sch" ".cir" (Invalid_argument "no output filename given, and unable to determine one automatically")
+ in
+ if Sys.file_exists output_filename && not overwrite then failwith "output file exists (specify \"-f\" to overwrite)";
+ Printf.printf "f: %s\nc: %s\no: %s\n" input_filename compdef_filename output_filename;
+ Eeschema.Parser.convert compdef_filename input_filename output_filename
+ | [] -> failwith "input filename missing"
+ | _::extra::_ -> failwith ("unexpected extra argument: " ^ extra)
+
+let () = main ()
M eeschema2netlist.opam => eeschema2netlist.opam +1 -0
@@ 1,5 1,6 @@
opam-version: "2.0"
name: "eeschema2netlist"
+version: "0.1.0"
maintainer: "Johann Rudloff <johann@sinyax.net>"
authors: "Johann Rudloff <johann@sinyax.net>"
homepage: "https://git.sinyax.net/cypheon/eeschame2netlist"
M lib/parser.ml => lib/parser.ml +2 -0
@@ 57,6 57,8 @@ let resolve compdefs (version, items) =
items=List.map (resolve_item compdefs) items;
}
+let cache_lib sch_filename =
+ BatOption.get_exn (Util.replace_suffix sch_filename ".sch" "-cache.lib") (Invalid_argument ("can not find cache lib for file: " ^ sch_filename))
let convert compdef_filename sch_filename output_filename = match process Parse_lib.main Lex_lib.read format_compdeflist compdef_filename with
| Some compdefs -> begin
A lib/util.ml => lib/util.ml +10 -0
@@ 0,0 1,10 @@
+open BatString
+
+let replace_suffix str suffix_to_remove suffix_to_add = if ends_with str suffix_to_remove
+ then Some ((slice ~last:(-length suffix_to_remove) str) ^ suffix_to_add)
+ else None
+
+let replace_suffix_exn a b c err = match replace_suffix a b c with
+ | Some r -> r
+ | None -> raise err
+
A lib/version.ml => lib/version.ml +1 -0
@@ 0,0 1,1 @@
+let version = "0.1.0"