JSDOC/TokenReader.js
[gnome.introspection-doc-generator] / JSDOC / PackerRun.vala
1
2 /** 
3   the application
4   -- in theory this code  can be used as a library... but this is the standard command line version...
5   
6   
7   valac  --vapidir=/usr/share/vala/vapi 
8      --vapidir=/usr/share/vala/vapi 
9     --vapidir=/usr/share/vala-0.30/vapi 
10         --thread  -g  
11       JSDOC/Lang.vala JSDOC/TextStream.vala JSDOC/TokenReader.vala JSDOC/Token.vala JSDOC/TokenStream.vala JSDOC/Packer.vala 
12       JSDOC/Collapse.vala JSDOC/ScopeParser.vala JSDOC/Scope.vala JSDOC/Identifier.vala JSDOC/CompressWhite.vala 
13        JSDOC/PackerRun.vala --pkg glib-2.0 --pkg gee-1.0 --pkg gio-2.0 --pkg posix -o /tmp/jspack --target-glib=2.32  -X -lm
14
15   
16 */
17
18 namespace JSDOC
19 {
20         // --------------- <<<<<<< <MAIN HERE....
21         
22
23         class PackerRun : Application  
24         {
25                 public static string opt_target = "";
26                 public static string opt_debug_target = "";
27                 public static string opt_tmpdir = "";
28                 
29                 [CCode (array_length = false, array_null_terminated = true)]
30                 private static string[]? opt_files = null;
31                 [CCode (array_length = false, array_null_terminated = true)]
32                 private static string[]? opt_files_from = null;
33                 public static bool opt_debug = false;
34                 public static bool opt_keep_whitespace = false; 
35
36                 
37                 const OptionEntry[] options = {
38                 
39                         { "jsfile", 'f', 0, OptionArg.FILENAME_ARRAY, ref opt_files ,"add a file to compile", null },
40                         { "target", 't', 0, OptionArg.STRING, ref opt_target, "Target File to write (eg. roojs.js)", null },
41                         { "debug-target", 'T', 0, OptionArg.STRING, ref opt_debug_target, "Target File to write debug code (eg. roojs-debug.js)", null },
42                         { "tmpdir", 'm', 0, OptionArg.STRING, ref opt_tmpdir, "Temporary Directory to use", null },
43
44                         { "index-files", 'i', 0, OptionArg.FILENAME_ARRAY, ref opt_files_from ,"files that contain listing of files to compile", null },                 
45                         { "keep-whitespace", 'w', 0, OptionArg.NONE, ref opt_keep_whitespace, "Keep whitespace", null },
46                         { "debug", 0, 0, OptionArg.NONE, ref opt_debug, "Show debug messages", null },
47                         // fixme -- keepwhite.. cleanup 
48                         
49                         { null }
50                 };
51                 public static int main(string[] args) 
52                 {
53                         foreach(var a in args) {
54                                 print("ARG: %s\n", a);
55                         }
56                         
57                         var opt_context = new OptionContext ("JSDOC Packer");
58                         
59                                 try {
60                                         opt_context.set_help_enabled (true);
61                                         opt_context.add_main_entries (options, null);
62                                         if (!opt_context.parse ( ref args)) {
63                                                 print("options parse error");
64                                                 GLib.Process.exit(Posix.EXIT_FAILURE);
65                                         }
66
67                                 
68                                          
69                                 
70                                 } catch (OptionError e) {
71                                         stdout.printf ("error: %s\n", e.message);
72                                         stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s", 
73                                                                  args[0], opt_context.get_help(true,null));
74                                         GLib.Process.exit(Posix.EXIT_FAILURE);
75                                          
76                                 }
77                 
78                         new PackerRun(args);
79                         return 0;
80                 }
81
82
83         
84                 public PackerRun (string[] args)
85                 {
86                 
87                         Object(
88                             application_id: "org.roojs.jsdoc.packerrun",
89                                 flags: ApplicationFlags.HANDLES_COMMAND_LINE 
90                         );
91                                          
92                          
93                         
94                         // what's required...
95                         if (opt_debug) {
96                                 GLib.Log.set_handler(null, 
97                                         GLib.LogLevelFlags.LEVEL_DEBUG | GLib.LogLevelFlags.LEVEL_WARNING, 
98                                         (dom, lvl, msg) => {
99                                         print("%s: %s\n", dom, msg);
100                                 });
101                         }
102                         
103                         // now run the Packer...
104                         var p = new Packer(opt_target, opt_debug_target);
105                         p.keepWhite = opt_keep_whitespace;
106                         
107                         
108                         if (opt_files != null) {
109                          
110                                 foreach (string f in opt_files) {
111                                         GLib.debug("Adding File %s", f);
112                                         p.loadFile(f);
113                                 }
114                         } else {
115                                 GLib.debug("No files added");
116                         }
117                         p.pack();
118                 }        
119                 
120         }
121         
122 }