Skip to content

Commit

Permalink
FLUID: fixing command line argument handling
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasWM committed Nov 13, 2024
1 parent 96f9ec6 commit 723dff4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions fluid/fluid.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2109,11 +2109,12 @@ int FLUID::App_Args::arg(int argc, char** argv, int& i) {
*
* \param[in] argc Number of arguments in the list.
* \param[in] argv Pointer to an array of arguments.
* \return True if the arguments are valid, false otherwise.
* \return -1 if there was an error in the command line
* or the index of the .fl project file
*/
bool FLUID::App_Args::read(int argc, char **argv) {
int FLUID::App_Args::read(int argc, char **argv) {
Fl::args_to_utf8(argc, argv); // for MSYS2/MinGW
int i = 0;
int i = 1;
if ( (Fl::args(argc, argv, i, arg) == 0) // unsupported argument found
|| (Fluid.batch_mode && (i != argc-1)) // .fl filename missing
|| (!Fluid.batch_mode && (i < argc-1)) // more than one filename found
Expand All @@ -2136,9 +2137,9 @@ bool FLUID::App_Args::read(int argc, char **argv) {
#else
fprintf(stderr, msg, app_name);
#endif
return false;
return -1;
}
return true;
return i;
}

// ---- Main program entry point
Expand Down Expand Up @@ -2185,19 +2186,19 @@ static void sigint(SIGARG) {
stderr and stdout?
*/
int main(int argc,char **argv) {
int i = 1;

setlocale(LC_ALL, ""); // enable multi-language errors in file chooser
setlocale(LC_NUMERIC, "C"); // make sure numeric values are written correctly
Fluid.launch_path = end_with_slash(fl_getcwd()); // store the current path at launch

if (Fluid.args.read(argc, argv)==false) {
int project_index = Fluid.args.read(argc, argv);
if (project_index == -1) {
return 1;
}

const char *c = NULL;
if (Fluid.args.autodoc_path.empty())
c = argv[i];
c = argv[project_index];

fl_register_images();

Expand Down
2 changes: 1 addition & 1 deletion fluid/fluid.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class Project {
class App_Args {
public:
/// Read command line args.
bool read(int argc, char **argv);
int read(int argc, char **argv);
/// Read one command line argument
static int arg(int argc, char** argv, int& i);
/// `-o filename`: override the generate code file extension or name
Expand Down

0 comments on commit 723dff4

Please sign in to comment.