-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
1389 lines (1299 loc) · 42.3 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Command line parsing and main routines for Xdialog.
g++ -std=c++11 `fltk-config --cxxflags` main.cpp `fltk-config --ldflags` -o Xdialog
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef ENABLE_NLS
#include <locale.h>
#endif
#include<stdlib.h>
#include<errno.h>
#include<stdio.h>
#include <getopt.h>
#include <unistd.h>
#ifdef HAVE_GETOPT_LONG_ONLY
# include <getopt.h>
#else
# include "getopt.h"
#endif
#include "interface.h"
#include "support.h"
#include "callbacks.h"
#include "time.h"
/* A structure used to pass Xdialog parameters. */
Xdialog_data Xdialog;
/* (c)dialog compatibility flag */
gboolean dialog_compat = FALSE;
/* Usage displaying */
#define HELP_TEXT1 \
"Xdialog v VERSION by Thierry Godefroy <xdialog@free.fr> (v1.0 was\n\
written by Alfred at Cyberone Internet <alfred@cyberone.com.au>).\n\
Xdialog home page available at: http://xdialog.dyns.net/\n\
\n\
Usage: "
#define HELP_TEXT2 \
" [<common options>] [<transient options>] <box option> ...\n\
\n\
Common options:\n\
--wmclass <name>\n\
--rc-file <gtkrc filename>\n\
--backtitle <backtitle>\n\
--title <title>\n\
--allow-close | --no-close\n\
--screen-center | --under-mouse | --auto-placement\n\
--center | --right | --left | --fill\n\
--no-wrap | --wrap\n\
--cr-wrap | --no-cr-wrap\n\
--stderr | --stdout\n\
--separator <character> | --separate-output\n\
--buttons-style default|icon|text\n\
\n\
Transient options:\n\
--fixed-font\n\
--password (may be repeated 2 or 3 times before --2inputsbox or --3inputsbox)\n\
--password=1|2 (for --2inputsbox or --3inputsbox)\n\
--editable\n\
--time-stamp | --date-stamp\n\
--reverse\n\
--keep-colors\n\
--interval <timeout>\n\
--timeout <timeout> (in seconds)\n\
--no-tags\n\
--item-help (if used, the {...} parameters are needed in menus/lists widgets)\n\
--default-item <tag>\n\
--icon <xpm filename>\n\
--no-ok\n\
--no-cancel\n\
--no-buttons\n\
--default-no\n\
--wizard\n\
--help <help>\n\
--print <printer> (1)\n\
--check <label> [<status>]\n\
--ok-label <label>\n\
--cancel-label <label>\n\
--beep\n\
--beep-after\n\
--begin <Yorg> <Xorg>\n\
--ignore-eof\n\
--smooth\n\
\n\
Box options:\n\
--yesno <text> <height> <width>\n\
--msgbox <text> <height> <width>\n\
--infobox <text> <height> <width> [<timeout>]\n\
--gauge <text> <height> <width> [<percent>]\n\
--progress <text> <height> <width> [<maxdots> [[-]<msglen>]]\n\
--inputbox <text> <height> <width> [<init>]\n\
--2inputsbox <text> <height> <width> <label1> <init1> <label2> <init2>\n\
--3inputsbox <text> <height> <width> <label1> <init1> <label2> <init2> <label3> <init3>\n\
--combobox <text> <height> <width> <item1> ... <itemN>\n\
--rangebox <text> <height> <width> <min value> <max value> [<default value>]\n\
--2rangesbox <text> <height> <width> <label1> <min1> <max1> <def1> <label2> <min2> <max2> <def2>\n\
--3rangesbox <text> <height> <width> <label1> <min1> <max1> <def1> ... <label3> <min3> <max3> <def3>\n\
--spinbox <text> <height> <width> <min value> <max value> <default value> <label>\n\
--2spinsbox <text> <height> <width> <min1> <max1> <def1> <label1> <min2> <max2> <def2> <label2>\n\
--3spinsbox <text> <height> <width> <min1> <max1> <def1> <label1> ... <min3> <max3> <def3> <label3>\n\
--textbox <file> <height> <width>\n\
--editbox <file> <height> <width>\n\
--tailbox <file> <height> <width>\n\
--logbox <file> <height> <width>\n\
--menu <text> <height> <width> <menu height> <tag1> <item1> {<help1>}...\n\
--checklist <text> <height> <width> <list height> <tag1> <item1> <status1> {<help1>}...\n\
--radiolist <text> <height> <width> <list height> <tag1> <item1> <status1> {<help1>}...\n\
--buildlist <text> <height> <width> <list height> <tag1> <item1> <status1> {<help1>}...\n\
--treeview <text> <height> <width> <list height> <tag1> <item1> <status1> <item_depth1> {<help1>}...\n\
--fselect <file> <height> <width>\n\
--dselect <directory> <height> <width>\n\
--colorsel <text> <height> <width> [<red> <green> <blue>]\n\
--fontsel <font name> <height> <width>\n\
--calendar <text> <height> <width> [<day> <month> <year>]\n\
--timebox <text> <height> <width> [<hours> <minutes> <seconds>]\n\
\n\
Special options:\n\
--version (prints version number to stderr and exits).\n\
--print-version (same as above in a cdialog-compatible way).\n\
--print-maxsize (prints maximum menu size in characters and exits).\n\
\n\
Note that <height> and <width> are in characters and may be replaced by a single\n\
XSIZExYSIZE[+/-XORG+/-YORG] parameter (like the one passed in the -geometry option\n\
of X) which will represent the size of the Xdialog window in pixels. Specifying\n\
a size of 0 0 (or 0x0) will auto-size Xdialog, while a size of -1 -1 (or -1x-1)\n\
will maximize it.\n\
\n\
(1) This Xdialog binary compiled with: \"PRINTER_CMD\" \"PRINTER_CMD_OPTION\"<printer>\n\
as the print command. If <printer> is \"\" (an empty string), the \"PRINTER_CMD_OPTION\"\n\
option is not used.\n\n"
#ifdef USE_SCANF
#define HELP_TEXT3 \
"WARNING: This binary of Xdialog was compiled with the --with-scanf-calls configure\n\
option. The --infobox and --gauge widgets may therefore not work completely as\n\
expected (lack of refresh of the GTK+ menu while scanning the input stream).\n\
You may try to re-compile Xdialog without specifying this configure option (but\n\
then, your system C library may lack the necessary functions).\n\n"
#define HELP_MSG_SIZE 4600
#else
#define HELP_MSG_SIZE 4200
#endif
///////////
enum
GLogLevelFlags{
G_LOG_LEVEL_ERROR,
G_LOG_LEVEL_CRITICAL,
G_LOG_LEVEL_WARNING,
G_LOG_LEVEL_MESSAGE,
G_LOG_LEVEL_INFO,
G_LOG_LEVEL_DEBUG,
G_LOG_FLAG_RECURSION,
G_LOG_FLAG_FATAL
};
/* List of all recognized Xdialog options */
enum {
/* Box options */
B_YESNO,
B_MSGBOX,
B_INFOBOX,
B_GAUGE,
B_PROGRESS,
B_TAILBOX,
B_LOGBOX,
B_TEXTBOX,
B_EDITBOX,
B_INPUTBOX, /* Don't change the order of the 3 next options ! */
B_PASSWORDBOX,
B_2INPUTSBOX,
B_3INPUTSBOX,
B_COMBOBOX,
B_RANGEBOX, /* Don't change the order of the 2 next options ! */
B_2RANGESBOX,
B_3RANGESBOX,
B_SPINBOX, /* Don't change the order of the 2 next options ! */
B_2SPINSBOX,
B_3SPINSBOX,
B_MENUBOX,
B_CHECKLIST,
B_RADIOLIST,
B_BUILDLIST,
B_TREEVIEW,
B_FSELECT,
B_DSELECT,
B_COLORSEL,
B_FONTSEL,
B_CALENDAR,
B_TIMEBOX,
/* Common options */
C_TITLE,
C_BACKTITLE,
C_WMCLASS,
C_SCREENCENTER,
C_UNDERMOUSE,
C_AUTOPLACEMENT,
C_LEFT,
C_RIGHT,
C_CENTER,
C_FILL,
C_WRAP,
C_NOWRAP,
C_CRWRAP,
C_NOCRWRAP,
C_STDOUT,
C_STDERR,
C_NOCLOSE,
C_ALLOWCLOSE,
C_BUTTONSSTYLE,
C_RCFILE,
C_SEPARATOR,
C_SEPARATEOUTPUT,
/* Transient options */
T_FIXEDFONT,
T_PASSWORD,
T_EDITABLE,
T_TIMESTAMP,
T_DATESTAMP,
T_REVERSE,
T_KEEPCOLORS,
T_NOOK,
T_NOCANCEL,
T_NOBUTTONS,
T_NOTAGS,
T_ITEMHELP,
T_DEFAULTITEM,
T_HELP,
T_PRINT,
T_WIZARD,
T_DEFAULTNO,
T_OKLABEL,
T_CANCELLABEL,
T_ICON,
T_INTERVAL,
T_TIMEOUT,
T_CHECK,
T_BEEP,
T_BEEPAFTER,
T_BEGIN,
T_IGNOREEOF,
T_SMOOTH,
/* Special options */
S_PRINTMAXSIZE,
S_VERSION,
S_PRINTVERSION,
S_CLEAR
};
static void print_help_info(const char *name, const char *errmsg)
{
char msg[HELP_MSG_SIZE];
char cmd[32];
strcpy(cmd, strlen(name) < 32 ? name : XDIALOG);
strcpysafe(msg, HELP_TEXT1, HELP_MSG_SIZE);
strcatsafe(msg, cmd, HELP_MSG_SIZE);
strcatsafe(msg, HELP_TEXT2, HELP_MSG_SIZE);
#ifdef USE_SCANF
strcatsafe(msg, HELP_TEXT3, HELP_MSG_SIZE);
#endif
fprintf(stderr, "%s: %s !\n", cmd, errmsg);
fprintf(stderr, msg);
if (strlen(msg) == HELP_MSG_SIZE - 1)
fprintf(stderr, "\n\nHelp message truncated, please re-compile "\
"after increasing HELP_MSG_SIZE in main.c !\n");
strcpysafe(Xdialog.title, "Usage for ", MAX_TITLE_LENGTH);
strcatsafe(Xdialog.title, cmd, MAX_TITLE_LENGTH);
Xdialog.cancel_button = Xdialog.help = Xdialog.icon = Xdialog.check = false;
if (!Xdialog.print) {
Xdialog.print = true;
Xdialog.printer[0] = 0;
}
Xdialog.fixed_font = Xdialog.buttons = true;
Xdialog.backtitle[0] = 0;
Xdialog.buttons=true;
Xdialog.print=true;
Xdialog.set_origin = false;
Xdialog.xorg = Xdialog.yorg = 0;
Xdialog.size_in_pixels = true;
get_maxsize(&Xdialog.xsize, &Xdialog.ysize);
open_window();
Fl_Text_Display *textView = new Fl_Text_Display(5, 5, Xdialog.xsize - 10, Xdialog.ysize - 65, 0);
Fl_Text_Buffer *buffer = new Fl_Text_Buffer();
buffer->append(msg);
textView->buffer(buffer);
Fl_Button *btn_yes = new Fl_Button((Xdialog.xsize/2)-120, Xdialog.ysize - 25 - 5, 80, 25, 0);
Fl_Button *btn_no = new Fl_Button((Xdialog.xsize/2)+40, Xdialog.ysize - 25 - 5, 80, 25, 0);
btn_yes->label("OK");
btn_no->label("Print");
btn_yes->callback(click_yes);
btn_no->callback(click_print);
Xdialog.window->show();
Fl::run();
exit(255);
}
/* Returns TRUE when var_name environment variable exists and is set to "true"
* (case insensitive).
*/
static gboolean is_true(const char *var_name)
{
char *env_var;
if ((env_var = getenv(var_name)) == NULL)
return FALSE;
#ifdef HAVE_STRCASECMP
return (!strcasecmp(env_var, "true") || !strcmp(env_var, "1"));
#else
return (!strcmp(env_var, "true") || !strcmp(env_var, "True") ||
!strcmp(env_var, "TRUE") || !strcmp(env_var, "1"));
#endif
}
/* An equivalent to the g_log_default_handler() function of glib, with
* exclusive use of stderr (nothing is ever printed on stdout), and with a
* possibility to disable completely any message output, via the
* XDIALOG_NO_GMSGS environment variable.
*/
static void g_log_xdialog_handler(const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message, gpointer unused_data)
{
const gchar *recurse;
const gchar *fatal;
gchar type[10];
if (is_true("XDIALOG_NO_GMSGS"))
return;
recurse = (log_level & G_LOG_FLAG_RECURSION) != 0 ? "" : "(recursed) ";
fatal = (log_level & G_LOG_FLAG_FATAL) != 0 ? "\naborting..." : "";
if (!message)
message = "g_log_default_handler(): (NULL) message";
switch (log_level) {
case G_LOG_LEVEL_ERROR:
strcpy(type, "ERROR");
break;
case G_LOG_LEVEL_CRITICAL:
strcpy(type, "CRITICAL");
break;
case G_LOG_LEVEL_WARNING:
strcpy(type, "WARNING");
break;
case G_LOG_LEVEL_MESSAGE:
strcpy(type, "Message");
break;
case G_LOG_LEVEL_INFO:
strcpy(type, "INFO");
break;
case G_LOG_LEVEL_DEBUG:
strcpy(type, "DEBUG");
break;
default:
sprintf(type, "LOG 0x%2x", log_level);
}
if (log_domain) {
fprintf(stderr, "\n%s-", log_domain);
} else {
fprintf(stderr, "\n** ");
}
fprintf(stderr, "%s %s**: %s%s\n", type, recurse, message, fatal);
}
/* Xsize, Ysize, Xorg and Yorg parameters */
static void get_box_size(int argc, char *argv[], int *optind)
{
char *index, *index2 = NULL;
if (*optind > argc-1)
print_help_info(argv[0], "box size missing");
if ((index = strstr(argv[*optind], "x")) == NULL &&
argv[*optind + 1] == NULL)
print_help_info(argv[0], "bad size parameter");
/* Force auto-sizing when in dialog high compatibility mode
* and when XDIALOG_AUTO_SIZE is "true"
*/
if (dialog_compat) {
if (is_true(FORCE_AUTOSIZE)) {
Xdialog.ysize = Xdialog.xsize = 0;
*optind += (index == NULL ? 2 : 1);
return;
}
}
if (index == NULL) {
Xdialog.size_in_pixels = FALSE;
Xdialog.ysize = atoi(argv[(*optind)++]);
Xdialog.xsize = atoi(argv[(*optind)++]);
} else {
Xdialog.size_in_pixels = TRUE;
Xdialog.set_origin = FALSE;
Xdialog.xsize = atoi(argv[*optind]);
Xdialog.ysize = atoi(++index);
index = strstr(argv[*optind], "+");
index2 = strstr(argv[(*optind)++], "-");
if (index != NULL && index2 != NULL) {
if (index < index2) {
Xdialog.xorg = atoi(++index);
Xdialog.yorg = atoi(index2);
if (Xdialog.yorg == 0)
Xdialog.yorg = -1;
} else {
Xdialog.xorg = atoi(index2);
if (Xdialog.xorg == 0)
Xdialog.xorg = -1;
Xdialog.yorg = atoi(++index);
}
Xdialog.set_origin = TRUE;
} else if (index == NULL && index2 != NULL) {
Xdialog.xorg = atoi(index2++);
if (Xdialog.xorg == 0)
Xdialog.xorg = -1;
index2 = strstr(index2, "-");
if (index2 != NULL) {
Xdialog.yorg = atoi(index2);
if (Xdialog.yorg == 0)
Xdialog.yorg = -1;
Xdialog.set_origin = TRUE;
}
} else if (index != NULL && index2 == NULL) {
Xdialog.xorg = atoi(++index);
index = strstr(index, "+");
if (index != NULL) {
Xdialog.yorg = atoi(++index);
Xdialog.set_origin = TRUE;
}
}
}
/* If either of the two size parameters is negative, then
* use the maximum size for the box.
*/
if (Xdialog.xsize < 0 || Xdialog.ysize < 0) {
get_maxsize(&Xdialog.xsize, &Xdialog.ysize);
Xdialog.size_in_pixels = FALSE;
Xdialog.set_origin = TRUE;
Xdialog.xorg = Xdialog.yorg = 0;
}
}
static int get_list_size(int argc, char *argv[], int *optind, int parameters,
gboolean with_list_height)
{
int list_size, next_opt, i;
i = *optind;
if (with_list_height)
i++;
if (i >= argc)
print_help_info(argv[0], "missing list parameters");
if (with_list_height) {
Xdialog.list_height = atoi(argv[(*optind)++]);
if (Xdialog.list_height < 0)
print_help_info(argv[0], "negative list height");
}
next_opt = argc;
for (i = *optind; i < argc-1; i++)
if (strstr(argv[i], "--") == argv[i]) {
next_opt = i;
break;
}
list_size = (next_opt - *optind) / parameters;
if (list_size * parameters + *optind != next_opt)
print_help_info(argv[0],
"incorrect number of parameters in list");
if (list_size < 1)
print_help_info(argv[0], "missing list parameters");
return list_size;
}
static int param_number(int argc, char *argv[], int *optind)
{
int next_opt, i;
next_opt = argc;
for (i = *optind; i < argc-1; i++)
if (strstr(argv[i], "--") == argv[i]) {
next_opt = i;
break;
}
return (next_opt - *optind);
}
/* There is a problem with getopt_long_only that returns an optcode of 63 when
* it reaches an unknown option !
*/
#define GETOPT_BUG 1
/* Main routine */
int main(int argc, char *argv[])
{
int gtk_major_version = 3;
int gtk_minor_version = 3;
/////
gchar title_tmp[MAX_TITLE_LENGTH];
gchar backt_tmp[MAX_BACKTITLE_LENGTH];
gchar help_text[MAX_LABEL_LENGTH];
int option_index = 0, old_optind = 0;
#if GETOPT_BUG
int old_option_index = 0;
#endif
char *env_var;
int optcode, i;
gboolean win = FALSE;
gint timeout, percent, x, y;
gint list_size = 0;
gint min = 0, max = 0, deflt =0;
gint day = 0, month = 0, year = 0;
gint hours = 0, minutes = 0, seconds = 0;
gdouble colors[4];
gint beep_tmp, timeout_tmp;
gboolean icon_tmp, check_tmp;
gboolean cancel_tmp, yesno_tmp;
time_t curr_time;
struct tm *localdate;
static struct option long_options[] = {
/* Box options */
{"yesno", 1, 0, B_YESNO},
{"msgbox", 1, 0, B_MSGBOX},
{"infobox", 1, 0, B_INFOBOX},
{"gauge", 1, 0, B_GAUGE},
{"guage", 1, 0, B_GAUGE},
{"progress", 1, 0, B_PROGRESS},
{"tailboxbg", 1, 0, B_TAILBOX},
{"logbox", 1, 0, B_LOGBOX},
{"textbox", 1, 0, B_TEXTBOX},
{"editbox", 1, 0, B_EDITBOX},
{"inputbox", 1, 0, B_INPUTBOX},
{"passwordbox", 1, 0, B_PASSWORDBOX},
{"2inputsbox", 1, 0, B_2INPUTSBOX},
{"3inputsbox", 1, 0, B_3INPUTSBOX},
{"combobox", 1, 0, B_COMBOBOX},
{"rangebox", 1, 0, B_RANGEBOX},
{"2rangesbox", 1, 0, B_2RANGESBOX},
{"3rangesbox", 1, 0, B_3RANGESBOX},
{"spinbox", 1, 0, B_SPINBOX},
{"2spinsbox", 1, 0, B_2SPINSBOX},
{"3spinsbox", 1, 0, B_3SPINSBOX},
{"menu", 1, 0, B_MENUBOX},
{"checklist", 1, 0, B_CHECKLIST},
{"radiolist", 1, 0, B_RADIOLIST},
{"buildlist", 1, 0, B_BUILDLIST},
{"treeview", 1, 0, B_TREEVIEW},
{"fselect", 1, 0, B_FSELECT},
{"dselect", 1, 0, B_DSELECT},
{"colorsel", 1, 0, B_COLORSEL},
{"fontsel", 1, 0, B_FONTSEL},
{"calendar", 1, 0, B_CALENDAR},
{"timebox", 1, 0, B_TIMEBOX},
/* Common options */
{"title", 1, 0, C_TITLE},
{"backtitle", 1, 0, C_BACKTITLE},
{"wmclass", 1, 0, C_WMCLASS},
{"screen-center", 0, 0, C_SCREENCENTER},
{"under-mouse", 0, 0, C_UNDERMOUSE},
{"auto-placement", 0, 0, C_AUTOPLACEMENT},
{"left", 0, 0, C_LEFT},
{"right", 0, 0, C_RIGHT},
{"center", 0, 0, C_CENTER},
{"fill", 0, 0, C_FILL},
{"wrap", 0, 0, C_WRAP},
{"no-wrap", 0, 0, C_NOWRAP},
{"cr-wrap", 0, 0, C_CRWRAP},
{"no-cr-wrap", 0, 0, C_NOCRWRAP},
{"stdout", 0, 0, C_STDOUT},
{"stderr", 0, 0, C_STDERR},
{"no-close", 0, 0, C_NOCLOSE},
{"allow-close", 0, 0, C_ALLOWCLOSE},
{"buttons-style", 1, 0, C_BUTTONSSTYLE},
{"rc-file", 1, 0, C_RCFILE},
{"separator", 1, 0, C_SEPARATOR},
{"separate-output", 0, 0, C_SEPARATEOUTPUT},
/* Transient options */
{"fixed-font", 0, 0, T_FIXEDFONT},
{"password", 2, 0, T_PASSWORD},
{"editable", 0, 0, T_EDITABLE},
{"time-stamp", 0, 0, T_TIMESTAMP},
{"date-stamp", 0, 0, T_DATESTAMP},
{"reverse", 0, 0, T_REVERSE},
{"keep-colors", 0, 0, T_KEEPCOLORS},
{"no-ok", 0, 0, T_NOOK},
{"no-cancel", 0, 0, T_NOCANCEL},
{"no-buttons", 0, 0, T_NOBUTTONS},
{"no-tags", 0, 0, T_NOTAGS},
{"item-help", 0, 0, T_ITEMHELP},
{"default-item", 1, 0, T_DEFAULTITEM},
{"help", 1, 0, T_HELP},
{"print", 1, 0, T_PRINT},
{"wizard", 0, 0, T_WIZARD},
{"default-no", 0, 0, T_DEFAULTNO},
{"defaultno", 0, 0, T_DEFAULTNO},
{"ok-label", 1, 0, T_OKLABEL},
{"cancel-label", 1, 0, T_CANCELLABEL},
{"icon", 1, 0, T_ICON},
{"interval", 1, 0, T_INTERVAL},
{"timeout", 1, 0, T_TIMEOUT},
{"check", 1, 0, T_CHECK},
{"beep", 0, 0, T_BEEP},
{"beep-after", 0, 0, T_BEEPAFTER},
{"begin", 1, 0, T_BEGIN},
{"ignore-eof", 0, 0, T_IGNOREEOF},
{"smooth", 0, 0, T_SMOOTH},
/* Special options */
{"print-maxsize", 0, 0, S_PRINTMAXSIZE},
{"version", 0, 0, S_VERSION},
{"print-version", 0, 0, S_PRINTVERSION},
{"clear", 0, 0, S_CLEAR},
/* End of options marker */
{0, 0, 0, 0}
};
#ifdef ENABLE_NLS
#ifndef HAVE_SETLOCALE
#error setlocale() function unavailable, try: ./configure --disable-nls
#endif
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif
/* Check if the dialog high compatibility mode is requested */
dialog_compat = is_true(HIGH_DIALOG_COMPAT);
memset(&Xdialog, 0, sizeof(Xdialog_data)); /* Set all parameters to zero/NULL */
#if FALSE != 0 /* Just in case your compiler uses a different value for FALSE... */
Xdialog.editable = FALSE; /* Don't allow editable combobox */
Xdialog.time_stamp = FALSE; /* Don't time-stamp logbox messages */
Xdialog.date_stamp = FALSE; /* Don't date-stamp logbox messages */
Xdialog.reverse = FALSE; /* Don't reverse order in logbox */
Xdialog.keep_colors = FALSE; /* Don't keep colors in logbox */
Xdialog.fixed_font = FALSE; /* Don't use a fixed font as default */
Xdialog.icon = FALSE; /* No icon as default */
Xdialog.no_close = FALSE; /* Allow to close the box as default */
Xdialog.help = FALSE; /* No help button as default */
Xdialog.wizard = FALSE; /* No wizard buttons as default */
Xdialog.check = FALSE; /* No check button as default */
Xdialog.checked = FALSE; /* Check button unchecked as default */
Xdialog.default_no = FALSE; /* Default selected button is Yes/OK */
Xdialog.print = FALSE; /* No print button as default */
Xdialog.wrap = FALSE; /* Don't wrap back-title & text as default */
Xdialog.set_origin = FALSE; /* Don't set window origin */
Xdialog.cr_wrap = FALSE; /* Don't wrap at linefeeds by default */
Xdialog.ignore_eof = FALSE; /* Don't ignore EOF in infobox/gauge */
Xdialog.smooth = FALSE; /* Don't use smooth (slow) scrolling */
#endif
if (dialog_compat) {
Xdialog.justify = GTK_JUSTIFY_LEFT; /* Left justify messages as default */
} else {
Xdialog.justify = GTK_JUSTIFY_CENTER; /* Center messages as default */
Xdialog.cr_wrap = TRUE; /* Wrap at linefeeds by default */
}
Xdialog.output = stderr; /* Default output for Xdialog results */
Xdialog.placement = GTK_WIN_POS_CENTER; /* Center window on screen as default */
Xdialog.buttons_style = ICON_AND_TEXT; /* Default buttons style (icon+text) */
Xdialog.buttons = TRUE ; /* Display 2 buttons as default */
Xdialog.ok_button = TRUE; /* Display "OK" button as default */
Xdialog.cancel_button = TRUE; /* Display "Cancel" button as default */
Xdialog.yesno_button = FALSE; /* Normal "OK" and "Cancel" buttons */
Xdialog.tags = TRUE;
/* Display tags before items in lists */
#if 0 /* Not needed because of the memset: listed here as a reminder only... */
Xdialog.passwd = 0; /* Don't use passwd input as default */
Xdialog.interval = 0; /* Don't report periodically as default */
Xdialog.timeout = 0; /* Don't use a timeout */
Xdialog.tips = 0; /* Don't use tips for items in lists */
Xdialog.beep = 0; /* Don't beep */
Xdialog.backtitle[0] = 0; /* Defaults to no backtitle */
Xdialog.rc_file[0] = 0; /* Defaults to no rc-file */
Xdialog.default_item[0] = 0; /* No default item */
Xdialog.ok_label[0] = 0; /* No alternative for OK button label */
Xdialog.cancel_label[0] = 0; /* No alternative for CANCEL button label */
#endif
strcpy(Xdialog.title, XDIALOG); /* Default widget title */
strcpy(Xdialog.separator, "/"); /* Default results separator */
if (gtk_major_version < 1 ||
(gtk_major_version == 1 && gtk_minor_version < 2))
fprintf(stderr,
"%s: GTK+ version too old, please upgrade !\n", argv[0]);
//gtk_set_locale();
setlocale(LC_ALL, "");
/* Set custom log handler routines, so that GTK, GDK and GLIB never
* print anything on stdout, but always use stderr instead.
*/
/*g_log_set_handler("Gdk", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
| G_LOG_FLAG_RECURSION, g_log_xdialog_handler, NULL);
g_log_set_handler("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
| G_LOG_FLAG_RECURSION, g_log_xdialog_handler, NULL);
g_log_set_handler("Gtk", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
| G_LOG_FLAG_RECURSION, g_log_xdialog_handler, NULL);
g_log_set_handler(NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
| G_LOG_FLAG_RECURSION, g_log_xdialog_handler, NULL);
*/
// g_log_xdialog_handler("Gdk", G_LOG_LEVEL_MASK, NULL, NULL);
// g_log_xdialog_handler("GLib", G_LOG_LEVEL_MASK, NULL, NULL);
// g_log_xdialog_handler("Gtk", G_LOG_LEVEL_MASK, NULL, NULL);
// g_log_xdialog_handler(NULL, G_LOG_LEVEL_MASK, NULL, NULL);
/*if (!gtk_init_check(&argc, &argv)) {
fprintf(stderr,
"%s: Error initializing the GUI...\n"
"Do you run under X11 with GTK+ v1.2.0+ installed ?\n", argv[0]);
return 255;
}
*/
Fl::lock();
#if !defined(NO_FLTK_PATCH)
Fl::scheme("smooth");
// Fl::new_shortcut_logic=true;
fl_force_wrap_breaks=1;
#else
Fl::scheme("gtk+");
#endif
Fl::background(182, 198, 255);
Fl::get_system_colors();
FL_NORMAL_SIZE=12;
if (Fl::w()>1200) {
Fl::screen_scale(0, Fl::w()/1200.0);
}
opterr = 0;
while (TRUE) {
optcode = getopt_long_only(argc, argv, "", long_options, &option_index);
if (optcode == -1)
break;
#if GETOPT_BUG
/* Work around for a bug into getopt that returns optcode=63 for
* unrecognized options (the problem being that 63 is used for
* a valid option ==> crash !) !
*/
if (option_index == old_option_index && optcode == 63)
continue;
old_option_index = option_index;
#endif
old_optind = optind;
show_again:
win = FALSE;
switch (optcode) {
/* Box options */
case B_YESNO: /* a yesno box */
Xdialog.yesno_button = TRUE;
get_box_size(argc, argv, &optind);
create_msgbox(optarg, TRUE);
win = TRUE;
break;
case B_MSGBOX: /* a msgbox */
get_box_size(argc, argv, &optind);
create_msgbox(optarg, FALSE);
win = TRUE;
break;
case B_INFOBOX: /* an infobox */
get_box_size(argc, argv, &optind);
if (dialog_compat) {
if ((env_var = getenv(INFOBOX_TIMEOUT)) != NULL)
timeout = atoi(env_var);
else
timeout = 0;
if (timeout > 0)
create_infobox(optarg, timeout);
else
create_infobox(optarg,1000);
//create_msgbox(optarg, FALSE);
} else {
if (argv[optind] != NULL)
{
char *_timeout=new char[MAX_LABEL_LENGTH];
strcpysafe(_timeout,argv[optind++],MAX_LABEL_LENGTH);
sscanf(_timeout, "%d", &timeout);
//timeout = atoi(_timeout);
}
else
timeout = INFO_TIME;
create_infobox(optarg, timeout);
}
win = TRUE;
break;
case B_GAUGE: /* a gauge */
get_box_size(argc, argv, &optind);
if (argv[optind] == NULL)
percent = 0;
else
percent = atoi(argv[optind++]);
create_gauge(optarg, percent);
win = TRUE;
break;
case B_PROGRESS: /* a progress report box */
get_box_size(argc, argv, &optind);
if (argv[optind] == NULL) {
max = 0;
min = 0;
} else {
max = atoi(argv[optind++]);
if (argv[optind] == NULL)
min = 0;
else
min = atoi(argv[optind++]);
}
create_progress(optarg, min, max);
win = TRUE;
break;
case B_TAILBOX: /* a tail box */
get_box_size(argc, argv, &optind);
create_tailbox(optarg);
win = TRUE;
break;
case B_LOGBOX: /* a log box */
get_box_size(argc, argv, &optind);
create_logbox(optarg);
win = TRUE;
break;
case B_TEXTBOX: /* a text box */
case B_EDITBOX: /* an edit box */
get_box_size(argc, argv, &optind);
create_textbox(optarg, optcode == B_EDITBOX);
win = TRUE;
break;
case B_INPUTBOX: /* an inputbox */
case B_PASSWORDBOX: /* a passwordbox (cdialog compatible) */
case B_2INPUTSBOX: /* a 2inputsbox */
case B_3INPUTSBOX: /* a 3inputsbox */
if (optcode == B_PASSWORDBOX)
Xdialog.passwd = 1;
get_box_size(argc, argv, &optind);
if (optcode > B_PASSWORDBOX) {
list_size = get_list_size(argc, argv, &optind, 2, FALSE);
if (list_size != optcode - B_INPUTBOX)
print_help_info(argv[0],
"incorrect number of parameters");
}
create_inputbox(optarg, argv+optind,
optcode >= B_2INPUTSBOX ? optcode - B_2INPUTSBOX + 2 : 1);
if (optcode <= B_PASSWORDBOX)
optind += ((argv[optind] != NULL) ? 1 : 0);
else
optind += 2*list_size;
win = TRUE;
break;
case B_COMBOBOX: /* a combo box */
get_box_size(argc, argv, &optind);
list_size = get_list_size(argc, argv, &optind, 1, FALSE);
create_combobox(optarg, argv+optind, list_size);
optind += list_size;
win = TRUE;
break;
case B_RANGEBOX: /* a range box */
case B_2RANGESBOX: /* a 2ranges box */
case B_3RANGESBOX: /* a 3ranges box */
get_box_size(argc, argv, &optind);
if (optcode != B_RANGEBOX) {
list_size = get_list_size(argc, argv, &optind, 4, FALSE);
if (list_size != optcode - B_RANGEBOX + 1)
print_help_info(argv[0],
"incorrect number of parameters");
for (i = 0 ; i < list_size; i++) {
min = atoi(argv[optind+4*i+1]);
max = atoi(argv[optind+4*i+2]);
deflt = atoi(argv[optind+4*i+3]);
if (min >= max || deflt < min || deflt > max)
print_help_info(argv[0],
"bad range parameters");
}
} else {
if (argv[optind] == NULL || argv[optind+1] == NULL)
print_help_info(argv[0], "missing range parameter");
else {
min = atoi(argv[optind]);
max = atoi(argv[optind+1]);
}
if (argv[optind+2] == NULL)
deflt = min;
else
deflt = atoi(argv[optind+2]);
if (min >= max || deflt < min || deflt > max)
print_help_info(argv[0], "bad range parameters");
}
create_rangebox(optarg, argv+optind, optcode - B_RANGEBOX + 1);
if (optcode != B_RANGEBOX)
optind += 4*list_size;
else
optind += 2 + (argv[optind+2] != NULL ? 1 : 0);
win = TRUE;
break;
case B_SPINBOX: /* a spin box */
case B_2SPINSBOX: /* a 2spins box */
case B_3SPINSBOX: /* a 3spins box */
get_box_size(argc, argv, &optind);
list_size = get_list_size(argc, argv, &optind, 4, FALSE);
if (list_size != optcode - B_SPINBOX + 1)
print_help_info(argv[0], "incorrect number of parameters");
for (i = 0 ; i < list_size; i++) {
min = atoi(argv[optind+4*i]);
max = atoi(argv[optind+4*i+1]);
deflt = atoi(argv[optind+4*i+2]);
if (min >= max || deflt < min || deflt > max)
print_help_info(argv[0], "bad range parameters");
}
create_spinbox(optarg, argv+optind, optcode - B_SPINBOX + 1);
optind += 4*list_size;
win = TRUE;
break;
case B_MENUBOX: /* a menu box */
get_box_size(argc, argv, &optind);
list_size = get_list_size(argc, argv, &optind,
2 + Xdialog.tips, TRUE);
create_menubox(optarg, argv+optind, list_size);
optind += (2+Xdialog.tips)*list_size;
win = TRUE;
break;
case B_CHECKLIST: /* a check list */
case B_RADIOLIST: /* a radio list */
get_box_size(argc, argv, &optind);
list_size = get_list_size(argc, argv, &optind, 3+Xdialog.tips, TRUE);
create_itemlist(optarg,
optcode == B_CHECKLIST ? CHECKLIST : RADIOLIST,
argv+optind, list_size);
optind += (3+Xdialog.tips)*list_size;
win = TRUE;
break;
case B_BUILDLIST: /* a build list */
get_box_size(argc, argv, &optind);
list_size = get_list_size(argc, argv, &optind,
3 + Xdialog.tips, TRUE);
create_buildlist(optarg, argv+optind, list_size);
optind += (3+Xdialog.tips)*list_size;
win = TRUE;
break;
case B_TREEVIEW: /* a tree view */
get_box_size(argc, argv, &optind);
list_size = get_list_size(argc, argv, &optind,
4 + Xdialog.tips, TRUE);
create_treeview(optarg, argv+optind, list_size);
optind += (4+Xdialog.tips)*list_size;
win = TRUE;
break;
case B_FSELECT: /* file selector */
get_box_size(argc, argv, &optind);
create_filesel(optarg, FALSE);
return Xdialog.exit_code;
win = TRUE;
break;
case B_DSELECT: /* directory selector */
get_box_size(argc, argv, &optind);
create_filesel(optarg, TRUE);
return Xdialog.exit_code;
win = TRUE;
break;