add documentation; add search over atomic number

This commit is contained in:
Peter McGoron 2021-08-13 15:39:55 -04:00
parent 47eed18958
commit 21f92ff9a2
1 changed files with 18 additions and 3 deletions

View File

@ -1,13 +1,23 @@
module Opts = struct
open Arg
type lasttype = NAME | SYMB
type lasttype = NAME | SYMB | NUMB
(** Positional arguments search based on the last type searched. *)
let ltype = ref NAME
(** Json file that generates the Sqlite3 database. *)
let jsonf = ref ""
(** Limit the amount of matches. *)
let maxmatch = ref 3
(** Lists to search. *)
let match_name : string list ref = ref []
let match_symb : string list ref = ref []
let match_numb : int list ref = ref []
let dbfile = ref "elements.sqlite3"
let add_name s =
@ -16,9 +26,13 @@ module Opts = struct
let add_symb s =
match_symb := s::!match_symb;
ltype := SYMB
let add_numb i =
match_numb := i::!match_numb;
ltype := NUMB
let add_def s = match !ltype with
| NAME -> add_name s
| SYMB -> add_symb s
| NUMB -> add_numb (int_of_string s)
let msg = "Periodic table search\n\
elements -gendb file [-dbfile outfile]\n\
@ -35,7 +49,8 @@ module Opts = struct
"-maxmatch", Set_int maxmatch, "Limit the amount of matches (def. 3)";
"-dbfile", String (setfile "-dbfile" dbfile), "Set the DB filename";
"-name", String add_name, "Search by name (default)";
"-symb", String add_symb, "Search by symbol"
"-symb", String add_symb, "Search by symbol";
"-num", Int add_numb, "Search by atomic number"
]
let exec() = parse spec add_def msg
@ -44,7 +59,7 @@ end
let () = Opts.exec()
let db = Sqlite3.db_open !Opts.dbfile
if !Opts.jsonf <> "" then
let _ = if !Opts.jsonf <> "" then
Makedb.makedb db (if !Opts.jsonf = "-" then
Yojson.Basic.from_channel stdin
else