From 3d412a87e0d4d92e5f0180071c3067b462f757e1 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Tue, 22 May 2001 08:30:26 +0000
Subject: [PATCH] -o output_filename

---
 Box/Main.cpp            |  4 ++--
 Common/Context.h        |  6 ++++--
 Common/GetOptions.cpp   | 11 ++++++++++-
 Common/Options.cpp      |  3 ++-
 Fltk/Callbacks.cpp      |  6 +++---
 Fltk/Main.cpp           |  6 +++---
 Graphics/CreateFile.cpp |  4 ++--
 Motif/Main.cpp          |  6 +++---
 Parser/OpenFile.cpp     | 10 +++++-----
 9 files changed, 34 insertions(+), 22 deletions(-)

diff --git a/Box/Main.cpp b/Box/Main.cpp
index 31f2592d50..4f9bacbb32 100644
--- a/Box/Main.cpp
+++ b/Box/Main.cpp
@@ -1,4 +1,4 @@
-// $Id: Main.cpp,v 1.3 2001-04-08 20:36:49 geuzaine Exp $
+// $Id: Main.cpp,v 1.4 2001-05-22 08:30:26 geuzaine Exp $
 
 #include <signal.h>
 
@@ -87,7 +87,7 @@ int main(int argc, char *argv[]){
     }
     if(CTX.batch > 0){
       mai3d(THEM, CTX.batch);
-      Print_Mesh(THEM,NULL,CTX.mesh.format);
+      Print_Mesh(THEM,CTX.output_filename,CTX.mesh.format);
     }
     exit(1);
   }    
diff --git a/Common/Context.h b/Common/Context.h
index 213669b516..b033ce1ac4 100644
--- a/Common/Context.h
+++ b/Common/Context.h
@@ -27,15 +27,17 @@ public :
 
   // general options
   char filename[NAME_STR_L];  // the name of the currently opened file
-  char basefilename[NAME_STR_L]; // the same without the extension
+  char base_filename[NAME_STR_L]; // the same without the extension
+  char *output_filename;      // output file specified with command line option '-o'
   char *default_filename;     // the name of the default file
   char *tmp_filename;         // the name of the temp file
   char *session_filename, sessionrc_filename[NAME_STR_L];
                               // the name of the sessionrc configuration file
   char *options_filename, optionsrc_filename[NAME_STR_L]; 
                               // the name of the optionrc configuration file
-  int session_save, options_save; // save session/option file on exit
   char *error_filename;       // the name of the error file
+
+  int session_save, options_save; // save session/option file on exit
   char *display;              // forced display host:0.0 under X11 
   int  terminal;              // show we print to the terminal console?
   char *editor;               // text editor command (with included '%s')
diff --git a/Common/GetOptions.cpp b/Common/GetOptions.cpp
index e41129b0c6..9450992f4c 100644
--- a/Common/GetOptions.cpp
+++ b/Common/GetOptions.cpp
@@ -1,4 +1,4 @@
-// $Id: GetOptions.cpp,v 1.21 2001-05-21 08:56:35 geuzaine Exp $
+// $Id: GetOptions.cpp,v 1.22 2001-05-22 08:30:26 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "GmshUI.h"
@@ -33,6 +33,7 @@ void Print_Usage(char *name){
   Msg(DIRECT, "  -0                    parse input files, output flattened geometry, and exit");
   Msg(DIRECT, "Mesh options:");
   Msg(DIRECT, "  -1, -2, -3            perform batch 1D, 2D and 3D mesh generation");
+  Msg(DIRECT, "  -o file               specify output file name");
   Msg(DIRECT, "  -format msh|unv|gref  set output mesh format (default: msh)");
   Msg(DIRECT, "  -algo iso|aniso       select 2D mesh algorithm (default: iso)");
   Msg(DIRECT, "  -smooth int           set mesh smoothing (default: 0)");
@@ -121,6 +122,14 @@ void Get_Options (int argc, char *argv[], int *nbfiles) {
       else if(!strcmp(argv[i]+1, "3")){ 
         CTX.batch = 3; i++;
       }
+      else if(!strcmp(argv[i]+1, "o")){ 
+        i++;
+        if(argv[i] != NULL) CTX.output_filename = argv[i++];
+        else {    
+          fprintf(stderr, ERROR_STR "Missing file name\n");
+          exit(1);
+        }
+      }
       else if(!strcmp(argv[i]+1, "bgm")){ 
         i++;
         if(argv[i] != NULL) TheBgmFileName = argv[i++];
diff --git a/Common/Options.cpp b/Common/Options.cpp
index 2c04b8a413..13381fcffb 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -1,4 +1,4 @@
-// $Id: Options.cpp,v 1.21 2001-05-21 13:19:05 geuzaine Exp $
+// $Id: Options.cpp,v 1.22 2001-05-22 08:30:26 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "GmshUI.h"
@@ -73,6 +73,7 @@ void Init_Options(int num){
 
   // The following defaults cannot be set by the user 
   CTX.batch = 0 ;
+  CTX.output_filename = NULL ;
   CTX.expose = 0 ;
   CTX.stream = TO_SCREEN ;
   CTX.gl_fontheight = 12;
diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp
index 4157bee84c..b9e82fa82d 100644
--- a/Fltk/Callbacks.cpp
+++ b/Fltk/Callbacks.cpp
@@ -1,4 +1,4 @@
-// $Id: Callbacks.cpp,v 1.56 2001-05-20 19:24:53 geuzaine Exp $
+// $Id: Callbacks.cpp,v 1.57 2001-05-22 08:30:26 geuzaine Exp $
 
 #include <sys/types.h>
 #include <signal.h>
@@ -1093,7 +1093,7 @@ void geometry_physical_add_volume_cb (CALLBACK_ARGS){
 // Dynamic Mesh Menus
 
 void mesh_save_cb(CALLBACK_ARGS) {
-  Print_Mesh(&M, NULL, CTX.mesh.format);
+  Print_Mesh(&M, CTX.output_filename, CTX.mesh.format);
 }
 void mesh_define_cb(CALLBACK_ARGS){
   WID->set_context(menu_mesh_define, 0);
@@ -1319,7 +1319,7 @@ void getdp_cb(CALLBACK_ARGS){
   static int first=1;
   if(first){
     first = 0;
-    strcpy(file,CTX.basefilename);
+    strcpy(file,CTX.base_filename);
     strcat(file,".pro");
     WID->getdp_input[0]->value(file);
   }
diff --git a/Fltk/Main.cpp b/Fltk/Main.cpp
index 3e360ef2f8..1947f019b3 100644
--- a/Fltk/Main.cpp
+++ b/Fltk/Main.cpp
@@ -1,4 +1,4 @@
-// $Id: Main.cpp,v 1.25 2001-05-21 13:01:13 geuzaine Exp $
+// $Id: Main.cpp,v 1.26 2001-05-22 08:30:26 geuzaine Exp $
 
 #include <signal.h>
 
@@ -87,10 +87,10 @@ int main(int argc, char *argv[]){
       }
       if(CTX.batch > 0){
         mai3d(THEM, CTX.batch);
-        Print_Mesh(THEM,NULL,CTX.mesh.format);
+        Print_Mesh(THEM, CTX.output_filename, CTX.mesh.format);
       }
       else
-        Print_Geo(THEM, NULL);
+        Print_Geo(THEM, CTX.output_filename);
       exit(1);
     }    
   }
diff --git a/Graphics/CreateFile.cpp b/Graphics/CreateFile.cpp
index 4a0efade28..d40e815e32 100644
--- a/Graphics/CreateFile.cpp
+++ b/Graphics/CreateFile.cpp
@@ -1,4 +1,4 @@
-// $Id: CreateFile.cpp,v 1.17 2001-04-08 20:36:49 geuzaine Exp $
+// $Id: CreateFile.cpp,v 1.18 2001-05-22 08:30:26 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "GmshUI.h"
@@ -204,7 +204,7 @@ void CreateOutputFile (char *name, int format) {
       res = GL2PS_OVERFLOW ;
       while(res == GL2PS_OVERFLOW){
 	size3d += 2048*2048 ;
-	gl2psBeginPage(CTX.basefilename, "Gmsh", 
+	gl2psBeginPage(CTX.base_filename, "Gmsh", 
 		       (CTX.print.eps_quality == 1 ? GL2PS_SIMPLE_SORT : GL2PS_BSP_SORT),
 		       GL2PS_SIMPLE_LINE_OFFSET | GL2PS_DRAW_BACKGROUND,
 		       GL_RGBA, 0, NULL, size3d, fp);
diff --git a/Motif/Main.cpp b/Motif/Main.cpp
index 3ec5335b9c..8c99e0b1f2 100644
--- a/Motif/Main.cpp
+++ b/Motif/Main.cpp
@@ -1,4 +1,4 @@
-// $Id: Main.cpp,v 1.10 2001-02-20 18:32:58 geuzaine Exp $
+// $Id: Main.cpp,v 1.11 2001-05-22 08:30:26 geuzaine Exp $
 
 #include <signal.h>
 
@@ -95,10 +95,10 @@ int main(int argc, char *argv[]){
       }
       if(CTX.batch > 0){
         mai3d(THEM, CTX.batch);
-        Print_Mesh(THEM,NULL,CTX.mesh.format);
+        Print_Mesh(THEM,CTX.output_filename,CTX.mesh.format);
       }
       else
-        Print_Geo(THEM, NULL);
+        Print_Geo(THEM,CTX.output_filename);
       exit(1);
     }    
   }
diff --git a/Parser/OpenFile.cpp b/Parser/OpenFile.cpp
index 312ac06282..055a82d611 100644
--- a/Parser/OpenFile.cpp
+++ b/Parser/OpenFile.cpp
@@ -1,4 +1,4 @@
-// $Id: OpenFile.cpp,v 1.15 2001-05-20 19:24:53 geuzaine Exp $
+// $Id: OpenFile.cpp,v 1.16 2001-05-22 08:30:26 geuzaine Exp $
 #include "Gmsh.h"
 #include "Const.h"
 #include "Context.h"
@@ -98,7 +98,7 @@ void OpenProblem(char *name){
   Init_Mesh(&M, 1);
 
   strncpy(CTX.filename,name,NAME_STR_L);
-  strncpy(CTX.basefilename,name,NAME_STR_L);
+  strncpy(CTX.base_filename,name,NAME_STR_L);
 
   strcpy(ext,name+(strlen(name)-4));
   if(!strcmp(ext,".geo") || !strcmp(ext,".GEO") ||
@@ -106,19 +106,19 @@ void OpenProblem(char *name){
      !strcmp(ext,".stl") || !strcmp(ext,".STL") ||
      !strcmp(ext,".sms") || !strcmp(ext,".SMS") ||
      !strcmp(ext,".pos") || !strcmp(ext,".POS")){
-    CTX.basefilename[strlen(name)-4] = '\0';
+    CTX.base_filename[strlen(name)-4] = '\0';
   }
   else{
     strcat(CTX.filename,".geo");
   }
 
-  strncpy(THEM->name, CTX.basefilename,NAME_STR_L);
+  strncpy(THEM->name, CTX.base_filename,NAME_STR_L);
 
   if(!CTX.batch){
 #if _XMOTIF
     XtVaSetValues(WID.G.shell,
                   XmNtitle, CTX.filename,
-                  XmNiconName, CTX.basefilename,
+                  XmNiconName, CTX.base_filename,
                   NULL);
 #elif _FLTK
     WID->set_title(CTX.filename);
-- 
GitLab