summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2015-03-09 20:37:45 +0000
committerAlbrecht Schlosser <albrechts.fltk@online.de>2015-03-09 20:37:45 +0000
commitc96c4c35b0c308c1da9796ca88762044851d3801 (patch)
treeae6eb8a6fee1f1f8ba582548fc9eb41e7271fe1f
parentc9ff10d8f9ad238cdc984dd820616f0335279cfb (diff)
Add 'fluid -u' command-line switch to upgrade fluid files in batch mode.
This option opens a fluid ('.fl') file and saves it overwriting the old file with the current syntax and library version number. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10611 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--documentation/src/fluid.dox29
-rw-r--r--fluid/Fl_Function_Type.cxx6
-rw-r--r--fluid/factory.cxx12
-rw-r--r--fluid/fluid.cxx58
4 files changed, 72 insertions, 33 deletions
diff --git a/documentation/src/fluid.dox b/documentation/src/fluid.dox
index 35417eba4..a552769a2 100644
--- a/documentation/src/fluid.dox
+++ b/documentation/src/fluid.dox
@@ -123,7 +123,8 @@ file from a <tt>.fl</tt> file. To do this type:
fluid -c filename.fl
\endcode
-This will read the <tt>filename.fl</tt> file and write
+This is the same as the menu 'File/Write Code...'.
+It will read the <tt>filename.fl</tt> file and write
<tt>filename.cxx</tt> and <tt>filename.h</tt>. Any leading
directory on <tt>filename.fl</tt> will be stripped, so they are
always written to the current directory. If there are any errors
@@ -146,6 +147,32 @@ files to be compiled:
fluid -c $<
\endcode
+If you use
+
+\code
+fluid -cs filename.fl
+\endcode
+
+FLUID will also write the "strings" for internationalization in file
+'filename.txt' (menu: 'File/Write Strings...').
+
+Finally there is another option which is useful for program developers
+who have many .fl files and want to upgrade them to the current FLUID
+version. FLUID will read the \p filename.fl file, save it, and exit
+immediately. This writes the file with current syntax and options and
+the current FLTK version in the header of the file. Use
+
+\code
+fluid -u filename.fl
+\endcode
+
+to 'upgrade' \p filename.fl . You may combine this with '-c' or '-cs'.
+
+\note All these commands overwrite existing files w/o warning. You should
+paticularly take care when running 'fluid -u' since this overwrites the
+original .fl source file.
+
+
\section fluid_tutorial A Short Tutorial
FLUID is an amazingly powerful little program. However, this
diff --git a/fluid/Fl_Function_Type.cxx b/fluid/Fl_Function_Type.cxx
index a6991a6f8..5ca6c192c 100644
--- a/fluid/Fl_Function_Type.cxx
+++ b/fluid/Fl_Function_Type.cxx
@@ -33,7 +33,7 @@ extern const char* i18n_file;
extern const char* i18n_set;
extern char i18n_program[];
-extern int compile_only;
+extern int batch_mode;
extern void redraw_browser();
extern void goto_source_dir();
@@ -920,9 +920,9 @@ void Fl_Data_Type::write_code1() {
}
}
// if we are in interactive mode, we pop up a warning dialog
- // giving the error: (compile_only && !write_sourceview)
+ // giving the error: (batch_mode && !write_sourceview) ???
if (message && !write_sourceview) {
- if (compile_only)
+ if (batch_mode)
fprintf(stderr, "FLUID ERROR: %s %s\n", message, fn);
else
fl_alert("%s\n%s\n", message, fn);
diff --git a/fluid/factory.cxx b/fluid/factory.cxx
index a3503abef..a39e6448e 100644
--- a/fluid/factory.cxx
+++ b/fluid/factory.cxx
@@ -167,7 +167,7 @@ static Fl_Round_Button_Type Fl_Round_Button_type;
////////////////////////////////////////////////////////////////
-extern int compile_only;
+extern int batch_mode;
#include <FL/Fl_Browser.H>
#include <FL/Fl_Check_Browser.H>
@@ -201,7 +201,7 @@ public:
Fl_Browser* b = new Fl_Browser(x,y,w,h);
// Fl_Browser::add calls fl_height(), which requires the X display open.
// Avoid this when compiling so it works w/o a display:
- if (!compile_only) {
+ if (!batch_mode) {
char buffer[20];
for (int i = 1; i <= 20; i++) {
sprintf(buffer,"Browser Line %d",i);
@@ -249,7 +249,7 @@ public:
Fl_Check_Browser* b = new Fl_Check_Browser(x,y,w,h);
// Fl_Check_Browser::add calls fl_height(), which requires the X display open.
// Avoid this when compiling so it works w/o a display:
- if (!compile_only) {
+ if (!batch_mode) {
char buffer[20];
for (int i = 1; i <= 20; i++) {
sprintf(buffer,"Browser Line %d",i);
@@ -285,7 +285,7 @@ public:
virtual const char *alt_type_name() {return "fltk::TreeBrowser";}
Fl_Widget *widget(int x,int y,int w,int h) {
Fl_Tree* b = new Fl_Tree(x,y,w,h);
- if (!compile_only) {
+ if (!batch_mode) {
b->add("/A1/B1/C1");
b->add("/A1/B1/C2");
b->add("/A1/B2/C1");
@@ -324,7 +324,7 @@ public:
Fl_File_Browser* b = new Fl_File_Browser(x,y,w,h);
// Fl_File_Browser::add calls fl_height(), which requires the X display open.
// Avoid this when compiling so it works w/o a display:
- if (!compile_only) {
+ if (!batch_mode) {
b->load(".");
}
return b;
@@ -640,7 +640,7 @@ public:
virtual const char *alt_type_name() {return "fltk::HelpView";}
Fl_Widget *widget(int x,int y,int w,int h) {
Fl_Help_View *myo = new Fl_Help_View(x,y,w,h);
- if (!compile_only) {
+ if (!batch_mode) {
myo->value("<HTML><BODY><H1>Fl_Help_View Widget</H1>"
"<P>This is a Fl_Help_View widget.</P></BODY></HTML>");
}
diff --git a/fluid/fluid.cxx b/fluid/fluid.cxx
index d0f1adc33..f6b1b43e0 100644
--- a/fluid/fluid.cxx
+++ b/fluid/fluid.cxx
@@ -634,8 +634,10 @@ void new_cb(Fl_Widget *, void *v) {
}
int exit_early = 0;
-int compile_only = 0;
-int compile_strings = 0;
+int update_file = 0; // fluid -u
+int compile_file = 0; // fluid -c
+int compile_strings = 0; // fluic -cs
+int batch_mode = 0; // if set (-c, -u) don't open display
int header_file_set = 0;
int code_file_set = 0;
const char* header_file_name = ".h";
@@ -668,12 +670,12 @@ void write_cb(Fl_Widget *, void *) {
} else {
strlcpy(hname, header_file_name, sizeof(hname));
}
- if (!compile_only) goto_source_dir();
+ if (!batch_mode) goto_source_dir();
int x = write_code(cname,hname);
- if (!compile_only) leave_source_dir();
+ if (!batch_mode) leave_source_dir();
strlcat(cname, " and ", sizeof(cname));
strlcat(cname, hname, sizeof(cname));
- if (compile_only) {
+ if (batch_mode) {
if (!x) {fprintf(stderr,"%s : %s\n",cname,strerror(errno)); exit(1);}
} else {
if (!x) {
@@ -693,10 +695,10 @@ void write_strings_cb(Fl_Widget *, void *) {
char sname[FL_PATH_MAX];
strlcpy(sname, fl_filename_name(filename), sizeof(sname));
fl_filename_setext(sname, sizeof(sname), exts[i18n_type]);
- if (!compile_only) goto_source_dir();
+ if (!batch_mode) goto_source_dir();
int x = write_strings(sname);
- if (!compile_only) leave_source_dir();
- if (compile_only) {
+ if (!batch_mode) leave_source_dir();
+ if (batch_mode) {
if (x) {fprintf(stderr,"%s : %s\n",sname,strerror(errno)); exit(1);}
} else {
if (x) {
@@ -1097,7 +1099,7 @@ Fl_Menu_Item Main_Menu[] = {
extern void fill_in_New_Menu();
void scheme_cb(Fl_Choice *, void *) {
- if (compile_only)
+ if (batch_mode)
return;
switch (scheme_choice->value()) {
@@ -1169,7 +1171,7 @@ void toggle_sourceview_b_cb(Fl_Button*, void *) {
}
void make_main_window() {
- if (!compile_only) {
+ if (!batch_mode) {
fluid_prefs.get("snap", snap, 1);
fluid_prefs.get("gridx", gridx, 5);
fluid_prefs.get("gridy", gridy, 5);
@@ -1200,7 +1202,7 @@ void make_main_window() {
main_window->end();
}
- if (!compile_only) {
+ if (!batch_mode) {
load_history();
make_settings_window();
make_global_settings_window();
@@ -1420,14 +1422,14 @@ static bool prepare_shell_command(const char * &command) { // common pre-shell
save_cb(0, 0);
}
if (shell_writecode_button->value()) {
- compile_only = 1;
+ batch_mode = 1;
write_cb(0, 0);
- compile_only = 0;
+ batch_mode = 0;
}
if (shell_writemsgs_button->value()) {
- compile_only = 1;
+ batch_mode = 1;
write_strings_cb(0, 0);
- compile_only = 0;
+ batch_mode = 0;
}
return true;
}
@@ -1510,7 +1512,7 @@ void set_filename(const char *c) {
if (filename) free((void *)filename);
filename = c ? strdup(c) : NULL;
- if (filename && !compile_only)
+ if (filename && !batch_mode)
update_history(filename);
set_modflag(modflag);
@@ -1647,7 +1649,7 @@ void set_modflag(int mf) {
// if the UI was modified in any way, update the Source View panel
if (sourceview_panel && sourceview_panel->visible() && sv_autorefresh->value())
{
- // we will only update ealiest 0.5 seconds after the last change, and only
+ // we will only update earliest 0.5 seconds after the last change, and only
// if no other change was made, so dragging a widget will not generate any
// CPU load
Fl::remove_timeout(update_sourceview_timer, 0);
@@ -1662,8 +1664,9 @@ void set_modflag(int mf) {
////////////////////////////////////////////////////////////////
static int arg(int argc, char** argv, int& i) {
- if (argv[i][1] == 'c' && !argv[i][2]) {compile_only = 1; i++; return 1;}
- if (argv[i][1] == 'c' && argv[i][2] == 's' && !argv[i][3]) {compile_only = 1; compile_strings = 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) {
code_file_name = argv[i+1];
code_file_set = 1;
@@ -1715,6 +1718,7 @@ int main(int argc,char **argv) {
if (!Fl::args(argc,argv,i,arg) || i < argc-1) {
static const char *msg =
"usage: %s <switches> name.fl\n"
+ " -u : update .fl file and exit (may be combined with '-c' or '-cs')\n"
" -c : write .cxx and .h and exit\n"
" -cs : write .cxx and .h and strings and exit\n"
" -o <name> : .cxx output filename, or extension if <name> starts with '.'\n"
@@ -1752,7 +1756,7 @@ int main(int argc,char **argv) {
if (c) set_filename(c);
- if (!compile_only) {
+ if (!batch_mode) {
#ifdef __APPLE__
fl_open_callback(apple_open_cb);
#endif // __APPLE__
@@ -1770,15 +1774,23 @@ int main(int argc,char **argv) {
}
undo_suspend();
if (c && !read_file(c,0)) {
- if (compile_only) {
+ if (batch_mode) {
fprintf(stderr,"%s : %s\n", c, strerror(errno));
exit(1);
}
fl_message("Can't read %s: %s", c, strerror(errno));
}
undo_resume();
- if (compile_only) {
- if (compile_strings) write_strings_cb(0,0);
+
+ if (update_file) { // fluid -u
+ write_file(c,0);
+ if (!compile_file)
+ exit(0);
+ }
+
+ if (compile_file) { // fluid -c[s]
+ if (compile_strings)
+ write_strings_cb(0,0);
write_cb(0,0);
exit(0);
}