summaryrefslogtreecommitdiff
path: root/examples/howto-parse-args.cxx
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2023-11-20 20:12:02 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2023-11-29 16:29:54 +0100
commit727bd94560ca9056cdbe40fe2e7923ed008b6eac (patch)
treef0d202b6c72415751445bfd91f29dd96fe3f59d2 /examples/howto-parse-args.cxx
parenta0e4a3fd5d028694e9fa74d2de55eb4f3c3f14b0 (diff)
Add commandline conversion for Windows (no-op on other platforms)
- add Fl::args_to_utf8() to convert commandline arguments to UTF-8 This new function closes the gap that previously only Visual Studio applications converted their commandlines to UTF-8. Tested with MinGW, MSYS2/MinGW-w64, and Visual Studio (2019).
Diffstat (limited to 'examples/howto-parse-args.cxx')
-rw-r--r--examples/howto-parse-args.cxx27
1 files changed, 22 insertions, 5 deletions
diff --git a/examples/howto-parse-args.cxx b/examples/howto-parse-args.cxx
index 393344128..ef756d09b 100644
--- a/examples/howto-parse-args.cxx
+++ b/examples/howto-parse-args.cxx
@@ -11,7 +11,16 @@
// usual *nix idiom of "option=value", and provides no validation nor
// conversion of the parameter string into ints or floats.
//
-// Copyright 1998-2020 by Bill Spitzak and others.
+// Example 1:
+//
+// ./howto-parse-args -ti "FLTK is great" -o "FLTK is a great GUI tool"
+//
+// Example 2: translated to Japanese and simplified Chinese, respectively,
+// by a well known internet translation service.
+//
+// ./howto-parse-args -ti "FLTKは素晴らしいです" -o "FLTK 是一个很棒的 GUI 工具"
+//
+// Copyright 1998-2023 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
@@ -42,13 +51,14 @@ char *optionString = 0;
* returns 1 if argv[i] matches on its own,
* returns 0 if argv[i] does not match.
*/
-int arg(int argc, char **argv, int &i)
-{
+int arg(int argc, char **argv, int &i) {
+
if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
helpFlag = 1;
i += 1;
return 1;
}
+
if (strcmp("-o", argv[i]) == 0 || strcmp("--option", argv[i]) == 0) {
if (i < argc-1 && argv[i+1] != 0) {
optionString = argv[i+1];
@@ -59,8 +69,13 @@ int arg(int argc, char **argv, int &i)
return 0;
}
-int main(int argc, char** argv)
-{
+int main(int argc, char** argv) {
+
+ // Convert commandline arguments in 'argv' to UTF-8 on Windows.
+ // This is a no-op on all other platforms (see documentation).
+
+ Fl::args_to_utf8(argc, argv);
+
int i = 1;
if (Fl::args(argc, argv, i, arg) < argc)
// note the concatenated strings to give a single format string!
@@ -84,6 +99,8 @@ int main(int argc, char** argv)
textBox->label(optionString);
else
textBox->label("re-run with [-o|--option] text");
+
+ mainWin->resizable(mainWin);
mainWin->show(argc, argv);
return Fl::run();
}