~cypheon/kicad2spice

bcfc133608fa55d020a630459e9ba2aa4dc8efc6 — Johann Rudloff 5 years ago 80e8dbf
Upgrade to ocaml>=4.08.0, replace batteries with extlib.
M bin/eeschema2netlist.ml => bin/eeschema2netlist.ml +2 -2
@@ 1,8 1,8 @@
open BatOptParse
open OptParse

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 out_filename_opt = Opt.value_option "FILE" (Some None) (Stdlib.Option.some) (fun _exn file -> "error: " ^ file) in
  let optparser = OptParser.make ~version:Eeschema.Version.version () in
  OptParser.add optparser
    ~help:"overwrite output file"

M eeschema2netlist.opam => eeschema2netlist.opam +2 -1
@@ 10,7 10,8 @@ depends: [
  "dune" {build}
  "menhir" {build}
  "alcotest" {build}
  "batteries" { >= "2.9" }
  "ocaml" { >= "4.08" }
  "extlib" { >= "1.7" }
  "ppx_deriving" { build & >= "4.3" }
  "ppx_compare" { build & >= "0.12" }
]

M lib/connectiongraph.ml => lib/connectiongraph.ml +6 -5
@@ 2,8 2,9 @@ open List

open Schematic

let default = BatOption.default
let reduce = BatList.reduce
let reduce f = function
  | x::xs -> List.fold_left f x xs
  | [] -> raise (Invalid_argument "reduce called on empty list")

let min_by compare a b = if (compare a b) < 0
  then a


@@ 87,7 88,7 @@ module Netlist = struct

  let driver_net_name nl net_name =
    let net_drivers = drivers nl net_name in
    snd @@ BatList.reduce (min_by driver_compare) net_drivers
    snd @@ reduce (min_by driver_compare) net_drivers

end



@@ 101,7 102,7 @@ let rec get_minpoint (netmap: (point2i, point2i) Hashtbl.t) (pt : point2i) =
  match Hashtbl.find_opt netmap pt with
  | Some minpoint -> (
      if minpoint = pt then pt
      else (assert ((Pervasives.compare minpoint pt) = -1); get_minpoint netmap minpoint)
      else (assert ((Stdlib.compare minpoint pt) = -1); get_minpoint netmap minpoint)
  )
  | None -> pt



@@ 124,7 125,7 @@ let make_netmap schematic : (point2i, point2i) Hashtbl.t =
    | Item.Comp c when c.part.power ->
        assert (length c.part.pins = 1);
        let pin = (nth (get_pins c) 0) in
        let net_point = default pin.pos (Hashtbl.find_opt named_nets pin.name) in
        let net_point = Stdlib.Option.value (Hashtbl.find_opt named_nets pin.name) ~default:pin.pos in
        let new_minpoint = min (get_minpoint minpoint_map net_point) (get_minpoint minpoint_map pin.pos) in
        Hashtbl.replace minpoint_map net_point new_minpoint;
        Hashtbl.replace minpoint_map pin.pos new_minpoint;

M lib/dune => lib/dune +1 -1
@@ 1,7 1,7 @@
(library
  (name eeschema)
  (public_name eeschema2netlist)
  (libraries batteries)
  (libraries extlib)
  (preprocess (pps ppx_deriving.show ppx_compare))
  )
(menhir

M lib/export_pspice.ml => lib/export_pspice.ml +3 -3
@@ 16,8 16,8 @@ let write_comp outch pin_cache comp =
  ignore pin_cache

let make_cache kf vf xs =
  let tbl = Hashtbl.create (BatEnum.count xs) in
  BatEnum.iter (fun x ->
  let tbl = Hashtbl.create (Enum.count xs) in
  Enum.iter (fun x ->
    Hashtbl.replace tbl (kf x) (vf x)
  ) xs;
  tbl


@@ 27,7 27,7 @@ let id x = x
let write_netlist outch schematic netlist =
  let net_names = make_cache id ( fun net_name ->
    Netlist.driver_net_name netlist net_name
  ) (BatHashtbl.keys netlist.Netlist.nets) in
  ) (ExtHashtbl.Hashtbl.keys netlist.Netlist.nets) in
  let pin_cache = Hashtbl.create 512 in
  Hashtbl.iter ( fun net_name subgraph -> iter (
    function

M lib/parser.ml => lib/parser.ml +3 -2
@@ 57,8 57,9 @@ 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 cache_lib sch_filename = match (Util.replace_suffix sch_filename ".sch" "-cache.lib") with
  | Some v -> v
  | None -> raise (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

M lib/util.ml => lib/util.ml +1 -1
@@ 1,4 1,4 @@
open BatString
open ExtString.String

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)