Skip to content

Commit

Permalink
FLUID: moving project class into subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasWM committed Nov 13, 2024
1 parent e3a1eb5 commit 022d4ee
Show file tree
Hide file tree
Showing 28 changed files with 622 additions and 376 deletions.
8 changes: 8 additions & 0 deletions fluid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ set(TARGETS fluid)

set(CPPFILES
application/application.cxx
application/args.cxx
application/history.cxx
application/settings.cxx
project/project.cxx
CodeEditor.cxx
StyleParse.cxx
Fd_Snap_Action.cxx
Expand Down Expand Up @@ -60,6 +64,10 @@ set(CPPFILES

set(HEADERFILES
application/application.h
application/args.h
application/history.h
application/settings.h
project/project.h
CodeEditor.h
Fd_Snap_Action.h
Fl_Function_Type.h
Expand Down
1 change: 1 addition & 0 deletions fluid/ExternalCodeEditor_UNIX.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "fluid.h"
#include "application/application.h"
#include "project/project.h"

#include <FL/Fl.H> /* Fl_Timeout_Handler.. */
#include <FL/fl_ask.H> /* fl_alert() */
Expand Down
1 change: 1 addition & 0 deletions fluid/ExternalCodeEditor_WIN32.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "ExternalCodeEditor_WIN32.h"
#include "fluid.h"
#include "application/application.h"
#include "project/project.h"

#include <stdio.h> // snprintf()
#include <stdlib.h>
Expand Down
2 changes: 1 addition & 1 deletion fluid/Fl_Menu_Type.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//

#include "Fl_Menu_Type.h"

#include "project/project.h"
#include "fluid.h"
#include "Fl_Window_Type.h"
#include "file.h"
Expand Down
1 change: 1 addition & 0 deletions fluid/Fl_Type.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
#include "Fl_Type.h"

#include "fluid.h"
#include "project/project.h"
#include "Fd_Snap_Action.h"
#include "Fl_Function_Type.h"
#include "Fl_Widget_Type.h"
Expand Down
1 change: 1 addition & 0 deletions fluid/Fl_Widget_Type.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Fl_Widget_Type.h"

#include "fluid.h"
#include "project/project.h"
#include "Fl_Window_Type.h"
#include "Fl_Group_Type.h"
#include "Fl_Menu_Type.h"
Expand Down
1 change: 1 addition & 0 deletions fluid/Fl_Window_Type.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "Fl_Window_Type.h"

#include "application/application.h"
#include "project/project.h"
#include "Fl_Group_Type.h"
#include "Fl_Grid_Type.h"
#include "fluid.h"
Expand Down
2 changes: 1 addition & 1 deletion fluid/application/application.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


#include "application/application.h"

#include "project/project.h"
#include "fluid.h"
#include "widget_browser.h"

Expand Down
9 changes: 6 additions & 3 deletions fluid/application/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#define FLUID_APPLICATION_APPLICATION_H

#include "fluid.h"
#include "application/args.h"
#include "application/history.h"
#include "application/settings.h"

#include <string>

Expand All @@ -26,11 +29,11 @@ namespace fluid {
class Application {
public:
/// Command line arguments.
App_Args args;
application::Args args { *this };
/// Application settings.
App_Settings settings;
application::Settings settings;
/// Application history.
App_History history;
application::History history;
/// Set if the application is not in interactive mode.
bool batch_mode { false };
/// current directory path at application launch
Expand Down
129 changes: 129 additions & 0 deletions fluid/application/args.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
//
// Application Args Class for Fast Light User Interface Designer (FLUID).
//
// Copyright 1998-2024 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// https://www.fltk.org/COPYING.php
//
// Please see the following page on how to report bugs and issues:
//
// https://www.fltk.org/bugs.php
//

#include "application/args.h"
#include "application/application.h"

using namespace fluid;

application::Args::Args(Application &theApp)
: app(theApp) {}

/**
Handle one command line argument.
If an argument is not recognized, it is not supported and the function
returns 0. If the argument is supported, the function returns the number
of arguments used. The argument is then removed from the list.
\param[in] argc number of arguments in the list
\param[in] argv pointer to an array of arguments
\param[inout] i current argument index
\return number of arguments used; if 0, the argument is not supported
*/
int application::Args::arg(int argc, char** argv, int& i) {
if (argv[i][0] != '-')
return 0;
if (argv[i][1] == 'd' && !argv[i][2]) {
debug = true;
i++; return 1;
}
if (argv[i][1] == 'u' && !argv[i][2]) {
update = true;
app.batch_mode = true;
i++; return 1;
}
if (argv[i][1] == 'c' && !argv[i][2]) {
Fluid.args.compile = true;
Fluid.batch_mode = true;
i++; return 1;
}
if (argv[i][1] == 'c' && argv[i][2] == 's' && !argv[i][3]) {
Fluid.args.compile = true;
Fluid.args.strings = true;
Fluid.batch_mode = true;
i++; return 1;
}
if (argv[i][1] == 'o' && !argv[i][2] && i+1 < argc) {
Fluid.args.code_filename = argv[i+1];
Fluid.batch_mode = true;
i += 2; return 2;
}
#ifndef NDEBUG
if ((i+1 < argc) && (strcmp(argv[i], "--autodoc") == 0)) {
Fluid.args.autodoc_path = argv[i+1];
i += 2; return 2;
}
#endif
if (argv[i][1] == 'h' && !argv[i][2]) {
if ( (i+1 < argc) && (argv[i+1][0] != '-') ) {
Fluid.args.header_filename = argv[i+1];
Fluid.batch_mode = true;
i += 2;
return 2;
} else {
// a lone "-h" without a filename will output the help string
return 0;
}
}
return 0;
}

int application::Args::arg_callback(int argc, char** argv, int& i) {
return Fluid.args.arg(argc, argv, i);
}

/**
* Parses the command line arguments and sets the appropriate flags in the
* fluid::App_Args object. If an unsupported argument is found, or if the
* number of arguments is incorrect, prints an error message and returns false.
* Otherwise, returns true.
*
* \param[in] argc Number of arguments in the list.
* \param[in] argv Pointer to an array of arguments.
* \return -1 if there was an error in the command line
* or the index of the .fl project file
*/
int application::Args::read(int argc, char **argv) {
Fl::args_to_utf8(argc, argv); // for MSYS2/MinGW
int i = 1;
if ( (Fl::args(argc, argv, i, arg_callback) == 0) // unsupported argument found
|| (Fluid.batch_mode && (i != argc-1)) // .fl filename missing
|| (!Fluid.batch_mode && (i < argc-1)) // more than one filename found
|| (argv[i] && (argv[i][0] == '-'))) { // unknown option
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"
" -h <name> : .h output filename, or extension if <name> starts with '.'\n"
" -d : enable internal debugging\n";
const char *app_name = NULL;
if ( (argc > 0) && argv[0] && argv[0][0] )
app_name = fl_filename_name(argv[0]);
if ( !app_name || !app_name[0])
app_name = "fluid";
#ifdef _MSC_VER
fl_message(msg, app_name);
#else
fprintf(stderr, msg, app_name);
#endif
return -1;
}
return i;
}

60 changes: 60 additions & 0 deletions fluid/application/args.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// Application Args Class for Fast Light User Interface Designer (FLUID).
//
// Copyright 1998-2024 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// https://www.fltk.org/COPYING.php
//
// Please see the following page on how to report bugs and issues:
//
// https://www.fltk.org/bugs.php
//

#ifndef FLUID_APPLICATION_ARGS_H
#define FLUID_APPLICATION_ARGS_H

#include "../src/Fl_String.H"

namespace fluid {

class Application;

namespace application {

class Args {
private:
Application &app;
public:
/// Argsconstructor
Args(Application &theApp);
/// Read command line args.
int read(int argc, char **argv);
/// Read one command line argument
int arg(int argc, char** argv, int& i);
/// FLTK callback to ead one command line argument
static int arg_callback(int argc, char** argv, int& i);
/// `-o filename`: override the generate code file extension or name
Fl_String code_filename { };
/// `-h filename`: override the generate header file extension or name
Fl_String header_filename { };
/// `--autodoc path`: if set, generate images for automatic documentation in this directory
Fl_String autodoc_path { };
/// `-u`: update the project file
bool update { false };
/// `-c`: compile the project file into source code
bool compile { false };
/// `-cs`: compile the project file into source code and write i18n strings file
bool strings { false };
/// `-d`: debug mode (used by external code editor)
bool debug { false };
};

} // namespace application

} // namespace fluid

#endif // FLUID_APPLICATION_ARGS_H
Loading

0 comments on commit 022d4ee

Please sign in to comment.