FLTK logo

[master] 8f9728d - Fix -o and -h command line arg handling

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 8f9728d - Fix -o and -h command line arg handling "Matthias Melcher" Nov 28, 2022  
 
commit 8f9728d511f45c98bc505cdd4f0f8bdbc99dd1a2
Author:     Matthias Melcher <github@matthiasm.com>
AuthorDate: Tue Nov 29 00:04:47 2022 +0100
Commit:     Matthias Melcher <github@matthiasm.com>
CommitDate: Tue Nov 29 00:05:00 2022 +0100

    Fix -o and -h command line arg handling

 fluid/fluid.cxx | 24 ++++++++++++++++++------
 fluid/fluid.h   |  3 +++
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git fluid/fluid.cxx fluid/fluid.cxx
index 2dc3591..0ca92ea 100644
--- fluid/fluid.cxx
+++ fluid/fluid.cxx
@@ -163,6 +163,10 @@ int compile_strings = 0;        // fluic -cs
 /// Set, if Fluid runs in batch mode, and no user interface is activated.
 int batch_mode = 0;             // if set (-c, -u) don't open display
 
+/// command line arguments override settings in the projectfile
+Fd_String g_code_filename_arg;
+Fd_String g_header_filename_arg;
+
 /** \var int Project::header_file_set
  If set, commandline overrides header file name in .fl file.
  */
@@ -1904,23 +1908,21 @@ void update_sourceview_timer(void*)
  \return number of arguments used; if 0, the argument is not supported
  */
 static int arg(int argc, char** argv, int& i) {
-  if (argv[i][0]!='-')
+  if (argv[i][0] != '-')
     return 0;
   if (argv[i][1] == 'd' && !argv[i][2]) {G_debug=1; i++; return 1;}
   if (argv[i][1] == 'u' && !argv[i][2]) {update_file++; batch_mode++; i++; return 1;}
   if (argv[i][1] == 'c' && !argv[i][2]) {compile_file++; batch_mode++; i++; return 1;}
   if (argv[i][1] == 'c' && argv[i][2] == 's' && !argv[i][3]) {compile_file++; compile_strings++; batch_mode++; i++; return 1;}
   if (argv[i][1] == 'o' && !argv[i][2] && i+1 < argc) {
-    P.code_file_name = argv[i+1];
-    P.code_file_set  = 1;
+    g_code_filename_arg = argv[i+1];
     batch_mode++;
     i += 2;
     return 2;
   }
   if (argv[i][1] == 'h' && !argv[i][2]) {
-    if (i+1 < argc) {
-      P.header_file_name = argv[i+1];
-      P.header_file_set  = 1;
+    if ( (i+1 < argc) && (argv[i+1][0] != '-') ) {
+      g_header_filename_arg = argv[i+1];
       batch_mode++;
       i += 2;
       return 2;
@@ -2036,6 +2038,16 @@ int main(int argc,char **argv) {
   }
   undo_resume();
 
+  // command line args override code and header filenams from the project file
+  if (!g_code_filename_arg.empty()) {
+    P.code_file_set = 1;
+    P.code_file_name = g_code_filename_arg;
+  }
+  if (!g_header_filename_arg.empty()) {
+    P.header_file_set = 1;
+    P.header_file_name = g_header_filename_arg;
+  }
+
   if (update_file) {            // fluid -u
     write_file(c,0);
     if (!compile_file)
diff --git fluid/fluid.h fluid/fluid.h
index ac2f8fb..98ed188 100644
--- fluid/fluid.h
+++ fluid/fluid.h
@@ -118,6 +118,9 @@ public:
 
 extern Project P;
 
+extern Fd_String g_code_filename_arg;
+extern Fd_String g_header_filename_arg;
+
 // ---- public functions
 
 extern void set_filename(const char *c);
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.