6 module Cxx
= Gen.Make
(Gen_cxx
)
7 module Caml
= Gen.Make
(Gen_caml
)
8 module Xml_gen
= Gen.Make
(Gen_xml
)
9 module Java
= Gen.Make
(Gen_java
)
10 module CSharp
= Gen.Make
(Gen_csharp
)
12 let generate = ref Cxx.process
13 let name = ref "sqlgg"
17 match (String.lowercase s
) with
18 | "cxx" | "c++" | "cpp" -> Cxx.process
19 | "caml" | "ocaml" | "ml" -> Caml.process
20 | "xml" -> Xml_gen.process
21 | "java" -> Java.process
22 | "csharp" | "c#" | "cs" -> CSharp.process
23 | _
-> failwith
(sprintf
"Unknown output language: %s" s
)
25 let set_name s
= name := s
26 let set_params_mode s
=
28 match String.lowercase s
with
29 | "named" -> Some
Gen.Named
30 | "unnamed" -> Some
Gen.Unnamed
34 let run ch
= ch
>> Main.get_statements
>> !generate !name in
37 | filename
-> Main.with_channel filename
run
40 let s1 = sprintf
"SQL Guided (code) Generator ver. %s\n" Config.version
in
41 let s2 = sprintf
"Usage: %s <options> <file.sql>\n" (Filename.basename
Sys.executable_name
) in
42 let s3 = "Options are:" in
45 let show_version () = print_endline
Config.version
50 "-version", Arg.Unit
show_version, " Show version";
51 "-gen", Arg.String
set_out, "cxx|caml|java|xml|csharp Set output language";
52 "-name", Arg.String
set_name, "<identifier> Set output module name";
53 "-params", Arg.String
set_params_mode, "named|unnamed|input Output query parameters substitution";
54 "-", Arg.Unit
(fun () -> work "-"), " Read sql from stdin";
55 "-test", Arg.Unit
Test.run, " Run unit tests";
58 Arg.parse
(Arg.align
args) work usage_msg
60 let _ = Printexc.print
main ()