aboutsummaryrefslogtreecommitdiffstats
path: root/elements.ml
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2021-08-13 15:39:55 -0400
committerGravatar Peter McGoron 2021-08-13 15:39:55 -0400
commit21f92ff9a260bcde2200a44eb61a95be5e642547 (patch)
treef343f75af269381bd703dcab81d60b301aa31150 /elements.ml
parentchange 'cache' to 'searchtable' in database (diff)
add documentation; add search over atomic number
Diffstat (limited to '')
-rw-r--r--elements.ml21
1 files changed, 18 insertions, 3 deletions
diff --git a/elements.ml b/elements.ml
index a2877fb..846b0f0 100644
--- a/elements.ml
+++ b/elements.ml
@@ -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