mirror of
https://github.com/fltk/fltk.git
synced 2025-12-13 07:34:40 +08:00
Remove platform specific code from test apps
Test programs that open files don't use platform specific code. They don't open files from macOS bundles. Support files must either be in the current working directory or given on the command line. On macOS this requires a full path when using bundles.
This commit is contained in:
@@ -165,38 +165,11 @@ int main(int argc, char **argv) {
|
||||
Fl_Double_Window window(720, 520, fname);
|
||||
browser = new Fl_Select_Browser(0, 0, window.w(), 350, 0);
|
||||
browser->type(FL_MULTI_BROWSER);
|
||||
//browser->type(FL_HOLD_BROWSER);
|
||||
//browser->color(42);
|
||||
browser->callback(b_cb);
|
||||
// browser->scrollbar_right();
|
||||
//browser->has_scrollbar(Fl_Browser::BOTH_ALWAYS);
|
||||
//browser->format_char('#');
|
||||
if (!browser->load(fname)) {
|
||||
int done = 0;
|
||||
#ifdef _MSC_VER
|
||||
// if 'browser' was started from the VisualC environment in Win32,
|
||||
// the current directory is set to the environment itself,
|
||||
// so we need to correct the browser file path
|
||||
if ( i == argc )
|
||||
{
|
||||
fname = "../test/browser.cxx";
|
||||
done = browser->load(fname);
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
char buf[2048];
|
||||
strcpy(buf, argv[0]);
|
||||
char *slash = strrchr(buf, '/');
|
||||
if (slash) {
|
||||
strcpy(slash, "/../../../browser.cxx");
|
||||
}
|
||||
done = browser->load(buf);
|
||||
#endif
|
||||
if ( !done )
|
||||
{
|
||||
fl_message("Can't load %s, %s\n", fname, strerror(errno));
|
||||
fl_message("Can't load '%s'\n%s\n", fname, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
browser->position(0);
|
||||
|
||||
field = new Fl_Int_Input(55, 350, window.w()-55, 25, "Line #:");
|
||||
|
||||
@@ -47,29 +47,20 @@ static Fl_Value_Slider *rs, *gs, *bs;
|
||||
static char dbname[FL_PATH_MAX];
|
||||
|
||||
static void create_form_cl(void);
|
||||
static int load_browser(char *);
|
||||
static int load_browser(const char *);
|
||||
|
||||
typedef struct { int r, g, b; } RGBdb;
|
||||
|
||||
static RGBdb rgbdb[MAX_RGB];
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Fl::args(argc, argv);
|
||||
int main(int argc, char *argv[]) {
|
||||
int i;
|
||||
if (!Fl::args(argc, argv, i)) Fl::fatal(Fl::help);
|
||||
const char *dbname = (i < argc) ? argv[i] : "rgb.txt";
|
||||
|
||||
create_form_cl();
|
||||
|
||||
#ifdef __APPLE__
|
||||
// Bundled apps do not set the current directory
|
||||
strcpy(dbname, argv[0]);
|
||||
char *slash = strrchr(dbname, '/');
|
||||
if (slash)
|
||||
strcpy(slash, "/../Resources/rgb.txt");
|
||||
#else
|
||||
strcpy(dbname, "rgb.txt");
|
||||
#endif
|
||||
|
||||
if (load_browser(dbname))
|
||||
dbobj->label(dbname);
|
||||
else
|
||||
@@ -139,7 +130,7 @@ static int read_entry(FILE * fp, int *r, int *g, int *b, char *name)
|
||||
}
|
||||
|
||||
|
||||
static int load_browser(char *fname)
|
||||
static int load_browser(const char *fname)
|
||||
{
|
||||
FILE *fp;
|
||||
RGBdb *db = rgbdb, *dbs = db + MAX_RGB;
|
||||
@@ -147,7 +138,7 @@ static int load_browser(char *fname)
|
||||
char name[256], buf[300];
|
||||
|
||||
if (!(fp = fl_fopen(fname, "r"))) {
|
||||
fl_alert("%s\n%s\n%s","Load", fname, "Can't open");
|
||||
fl_alert("Load:\nCan't open '%s'", fname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
@main:Fluid\n(UI design tool):fluid valuators.fl
|
||||
|
||||
@main:Cool\nDemos...:@e
|
||||
@e:X Color\nBrowser:colbrowser
|
||||
@e:X Color\nBrowser:colbrowser rgb.txt
|
||||
@e:Mandelbrot:mandelbrot
|
||||
@e:Fractals:fractals
|
||||
@e:Puzzle:glpuzzle
|
||||
|
||||
@@ -36,27 +36,11 @@ main(int argc, // I - Number of command-line arguments
|
||||
char *argv[]) // I - Command-line arguments
|
||||
{
|
||||
Fl_Help_Dialog *help = new Fl_Help_Dialog;
|
||||
char htmlname[FL_PATH_MAX];
|
||||
#ifdef __APPLE__
|
||||
int i = 1;
|
||||
while (i < argc && Fl::arg(argc, argv, i)) i++;
|
||||
if (i < argc) {
|
||||
strcpy(htmlname, argv[i]);
|
||||
} else {
|
||||
// bundled apps do not set the current directory
|
||||
strcpy(htmlname, argv[0]);
|
||||
char *slash = strrchr(htmlname, '/');
|
||||
if (slash) strcpy(slash, "/../Resources/help_dialog.html");
|
||||
}
|
||||
#else
|
||||
if (argc > 1) {
|
||||
strcpy(htmlname, argv[1]);
|
||||
} else {
|
||||
strcpy(htmlname, "help_dialog.html");
|
||||
}
|
||||
#endif
|
||||
int i;
|
||||
if (!Fl::args(argc, argv, i)) Fl::fatal(Fl::help);
|
||||
const char *fname = (i < argc) ? argv[i] : "help_dialog.html";
|
||||
|
||||
help->load(htmlname); // TODO: add error check (when load() returns int instead of void)
|
||||
help->load(fname); // TODO: add error check (when load() returns int instead of void)
|
||||
|
||||
help->show(1, argv);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user