filepanel: Fix -Wformat-security and remove unused options.

Change-Id: Iedf3bb500de15a29188c30940b5fd64dcaf043f5
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3319
Reviewed-by: Niels Sascha Reedijk <niels.reedijk@gmail.com>
This commit is contained in:
Murai Takashi 2020-10-15 06:30:22 +09:00 committed by Niels Sascha Reedijk
parent e5feb3a7ae
commit 08f2b4d50a

View File

@ -37,7 +37,7 @@ class FilePanelApp : public BApplication
{ {
public: public:
FilePanelApp(); FilePanelApp();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
virtual void RefsReceived(BMessage *message); virtual void RefsReceived(BMessage *message);
}; };
@ -49,7 +49,7 @@ FilePanelApp::FilePanelApp()
} }
void void
FilePanelApp::MessageReceived(BMessage *message) FilePanelApp::MessageReceived(BMessage *message)
{ {
entry_ref e; entry_ref e;
@ -77,7 +77,7 @@ FilePanelApp::MessageReceived(BMessage *message)
} }
void void
FilePanelApp::RefsReceived(BMessage *message) FilePanelApp::RefsReceived(BMessage *message)
{ {
entry_ref e; entry_ref e;
@ -97,37 +97,30 @@ FilePanelApp::RefsReceived(BMessage *message)
int int
usage(char *pname, int error) usage(char *pname, int error)
{ {
fprintf(stderr, B_TRANSLATE("display a load/save file panel\n")); fprintf(stderr, "%s", B_TRANSLATE("display a load/save file panel\n"));
fprintf(stderr, B_TRANSLATE("usage: %s [--help] [--directory folder] " fprintf(stderr, B_TRANSLATE("usage: %s [--help] [--directory folder] "
"[--load|--save] [--title ttl] [--single] [--modal] [--allow pattern] " "[--load|--save] [--title ttl] [--single] [--modal]\n"), pname);
"[--forbid pattern]\n"), pname);
fprintf(stderr, B_TRANSLATE("usage: %s [-h] [-d folder] " fprintf(stderr, B_TRANSLATE("usage: %s [-h] [-d folder] "
"[-l|-s] [-t ttl] [-1] [-m] [-a pattern] " "[-l|-s] [-t ttl] [-1] [-m]"), pname);
"[-f pattern]\n"), pname); fprintf(stderr, "%s", B_TRANSLATE("options:\n"));
fprintf(stderr, B_TRANSLATE("options:\n")); fprintf(stderr, "%s", B_TRANSLATE("short\tlong\tdescription\n"));
fprintf(stderr, B_TRANSLATE("short\tlong\tdescription\n")); fprintf(stderr, "%s", B_TRANSLATE("-h\t--help\tdisplay usage\n"));
fprintf(stderr, B_TRANSLATE("-h\t--help\tdisplay usage\n")); fprintf(stderr, "%s", B_TRANSLATE("-d\t--directory\topen at <folder>\n"));
fprintf(stderr, B_TRANSLATE("-d\t--directory\topen at <folder>\n")); fprintf(stderr, "%s",
fprintf(stderr, B_TRANSLATE("-l\t--load\tuse a load FilePanel " B_TRANSLATE("-l\t--load\tuse a load FilePanel (default)\n"));
"(default)\n")); fprintf(stderr, "%s", B_TRANSLATE("-s\t--save\tuse a save FilePanel\n"));
fprintf(stderr, B_TRANSLATE("-s\t--save\tuse a save FilePanel\n")); fprintf(stderr, "%s",
fprintf(stderr, B_TRANSLATE("-n\t--name\tset the default name for " B_TRANSLATE("-n\t--name\tset the default name for saving\n"));
"saving\n")); fprintf(stderr, "%s",
fprintf(stderr, B_TRANSLATE("-k\t--kind\tkind of entries that can be " B_TRANSLATE("-k\t--kind\tkind of entries that can be "
"opened (flavour): any combination of f, d, s (file (default), " "opened (flavour): any combination of f, d, s (file (default), "
"directory, symlink)\n")); "directory, symlink)\n"));
fprintf(stderr, B_TRANSLATE("-t\t--title\tset the FilePanel window " fprintf(stderr, "%s",
"title\n")); B_TRANSLATE("-t\t--title\tset the FilePanel window title\n"));
fprintf(stderr, B_TRANSLATE("-1\t--single\tallow only 1 file to be " fprintf(stderr, "%s",
"selected\n")); B_TRANSLATE("-1\t--single\tallow only 1 file to be selected\n"));
fprintf(stderr, B_TRANSLATE("-m\t--modal\tmakes the FilePanel modal\n")); fprintf(stderr, "%s",
#ifndef USE_FNMATCH B_TRANSLATE("-m\t--modal\tmakes the FilePanel modal\n"));
fprintf(stderr, B_TRANSLATE("-a\t--allow\tunimplemented\n"));
fprintf(stderr, B_TRANSLATE("-f\t--forbid\tunimplemented\n"));
#else
fprintf(stderr, B_TRANSLATE("-a\t--allow\tunimplemented\n"));
fprintf(stderr, B_TRANSLATE("-f\t--forbid\tunimplemented\n"));
#endif
return error; return error;
} }
@ -145,7 +138,7 @@ main(int argc, char **argv)
const char *defaultName = NULL; const char *defaultName = NULL;
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (strncmp(argv[i], "--", 2) && ((*(argv[i]) == '-' && if (strncmp(argv[i], "--", 2) && ((*(argv[i]) == '-' &&
strlen(argv[i]) != 2) || *(argv[i]) != '-')) { strlen(argv[i]) != 2) || *(argv[i]) != '-')) {
fprintf(stderr, B_TRANSLATE("%s not a valid option\n"), argv[i]); fprintf(stderr, B_TRANSLATE("%s not a valid option\n"), argv[i]);
return usage(argv[0], 2); return usage(argv[0], 2);
@ -190,20 +183,6 @@ main(int argc, char **argv)
allowMultiSelect = false; allowMultiSelect = false;
} else if (!strcmp(argv[i], "--modal") || !strcmp(argv[i], "-m")) { } else if (!strcmp(argv[i], "--modal") || !strcmp(argv[i], "-m")) {
makeModal = true; makeModal = true;
} else if (!strcmp(argv[i], "--allow") || !strcmp(argv[i], "-a")) {
if (++i >= argc) {
fprintf(stderr, B_TRANSLATE("%s: this option requires a "
"parameter\n"), argv[i-1]);
return usage(argv[0], 2);
}
fprintf(stderr, B_TRANSLATE("%s: UNIMPLEMENTED\n"), argv[i-1]);
} else if (!strcmp(argv[i], "--forbid") || !strcmp(argv[i], "-f")) {
if (++i >= argc) {
fprintf(stderr, B_TRANSLATE("%s: this option requires a "
"parameter\n"), argv[i-1]);
return usage(argv[0], 2);
}
fprintf(stderr, B_TRANSLATE("%s: UNIMPLEMENTED\n"), argv[i-1]);
} else { } else {
fprintf(stderr, B_TRANSLATE("%s not a valid option\n"), argv[i]); fprintf(stderr, B_TRANSLATE("%s not a valid option\n"), argv[i]);
return usage(argv[0], 2); return usage(argv[0], 2);
@ -211,9 +190,9 @@ main(int argc, char **argv)
} }
new FilePanelApp; new FilePanelApp;
entry_ref panelDir; entry_ref panelDir;
// THIS LINE makes main() return always 0 no matter which value on return of // THIS LINE makes main() return always 0 no matter which value on return of
// exit() ??? // exit() ???
BFilePanel *fPanel = new BFilePanel(fpMode, NULL, NULL, nodeFlavour, BFilePanel *fPanel = new BFilePanel(fpMode, NULL, NULL, nodeFlavour,
allowMultiSelect, NULL, NULL, makeModal); allowMultiSelect, NULL, NULL, makeModal);
/**/ /**/
if (openAt) if (openAt)
@ -222,7 +201,7 @@ main(int argc, char **argv)
fPanel->Window()->SetTitle(windowTitle); fPanel->Window()->SetTitle(windowTitle);
if (fpMode == B_SAVE_PANEL && defaultName) if (fpMode == B_SAVE_PANEL && defaultName)
fPanel->SetSaveText(defaultName); fPanel->SetSaveText(defaultName);
fPanel->Show(); fPanel->Show();
/**/ /**/
be_app->Run(); be_app->Run();