summaryrefslogtreecommitdiff
path: root/support/dktools/Bmpp4App.cpp
blob: 822300d85152a4fb4b5104ed7de4cd6ddded3d00 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
/*
Copyright (C) 2018-2020, Dirk Krause
SPDX-License-Identifier: BSD-3-Clause
*/

/*
	WARNING: This file was generated by the dkct program (see
	http://dktools.sourceforge.net/ for details).
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: Bmpp4App.cpt
*/

/**	@file Bmpp4App.cpp The Bmpp4App module.
*/


#line 151 "Bmpp4App.cpt"

#include "wxbmpp.h"

#ifndef	DK4VERS_H_INCLUDED
#include "dk4vers.h"
#endif

#ifndef	DK4MEM_H_INCLUDED
#include "dk4mem.h"
#endif

#ifndef	DK4STRD_H_INCLUDED
#include "dk4strd.h"
#endif

#ifndef	DK4MPL_H_INCLUDED
#include "dk4mpl.h"
#endif

#ifndef	DK4PAPEA_H_INCLUDED
#include "dk4papea.h"
#endif

#ifndef	DK4GRCOA_H_INCLUDED
#include "dk4grcoa.h"
#endif

#ifndef	DK4STRX_H_INCLUDED
#include "dk4strx.h"
#endif





#line 185 "Bmpp4App.cpt"



/**	Localized wxChar texts.
*/
static wxChar const * const	wxbmpp_texts[] = {
/* 0 */
wxT("File"),

/* 1 */
wxT("Quit"),

/* 2 */
wxT("Exit the application"),

/* 3 */
wxT("Help"),

/* 4 */
wxT("About"),

/* 5 */
wxT("Show version information"),

/* 6 */
wxT("Contents"),

/* 7 */
wxT("Open table of contents"),

/* 8 */
wxT("Ready"),

/* 9 */
wxT("Copyright (c) "),

/* 10 */
wxT("About "),

/* 11 */
wxT("This program uses the following libraries:"),

/* 12 */
wxT("See:"),

/* 13 */
wxT("Make"),

/* 14 */
wxT("Avoid unnecessary conversions"),

/* 15 */
wxT("Color"),

/* 16 */
wxT("Produce colored output"),

/* 17 */
wxT("Output:"),

/* 18 */
wxT("PDF object"),

/* 19 */
wxT("PDF image"),

/* 20 */
wxT("PDF document"),

/* 21 */
wxT("EPS image"),

/* 22 */
wxT("PS  image"),

/* 23 */
wxT("PS  document"),

/* 24 */
wxT("Set output file type and intended purpose"),

/* 25 */
wxT("Interpolation"),

/* 26 */
wxT("Set image interpolation flag"),

/* 27 */
wxT("PS level:"),

/* 28 */
wxT("2"),

/* 29 */
wxT("3"),

/* 30 */
wxT("Choose the PS language level"),

/* 31 */
wxT("DSC"),

/* 32 */
wxT("Write DSC comments to PS output"),

/* 33 */
wxT("LZW"),

/* 34 */
wxT("Allow LZW compression in PS level 2 output"),

/* 35 */
wxT("JPEG DCT data"),

/* 36 */
wxT("Directly re-use DCT encoded data from JPEG files"),

/* 37 */
wxT("Paper size:"),

/* 38 */
wxT("Specify paper size"),

/* 39 */
wxT("Rotation"),

/* 40 */
wxT("Allow image rotation for better page fitting"),

/* 41 */
wxT("DCT interpolation"),

/* 42 */
wxT("Allow image interpolation for directly re-used DCT data from JPEG files"),

/* 43 */
wxT("Finishing:"),

/* 44 */
wxT("Single side"),

/* 45 */
wxT("Duplex"),

/* 46 */
wxT("Duplex+Tumble"),

/* 47 */
wxT("Choose single side printing or duplex printing like a book or calendar"),

/* 48 */
wxT("Analyze bit depth"),

/* 49 */
wxT("Attempt to reduce the number of bits per component"),

/* 50 */
wxT("Resolution:"),

/* 51 */
wxT("How to handle image resolution (use information from file, ignore or specify)"),

/* 52 */
wxT("from file"),

/* 53 */
wxT("ignore"),

/* 54 */
wxT("specify"),

/* 55 */
wxT("72.0"),

/* 56 */
wxT(""),

/* 57 */
wxT("Analyze color use"),

/* 58 */
wxT("Analyze use of colors, switch output to gray if no colors used"),

/* 59 */
wxT("Background:"),

/* 60 */
wxT("Choose a background color"),

/* 61 */
wxT("Enforce background"),

/* 62 */
wxT("Use specified background color even if the input file provides a background"),

/* 63 */
wxT("Analyze alpha"),

/* 64 */
wxT("Analyze alpha channel data"),

/* 65 */
wxT("Choose directory"),

/* 66 */
wxT("Choose directory containing the images to convert"),

/* 67 */
wxT("Conversion"),

/* 68 */
wxT("Run"),

/* 69 */
wxT("Run conversion"),

/* 70 */
wxT("No directory specified yet!"),

/* 71 */
wxT("Choose directory"),

/* 72 */
wxT("Extras"),

/* 73 */
wxT("Reset options"),

/* 74 */
wxT("Reset options - are you sure?"),

/* 75 */
wxT("Do you really want to reset all options to default values?"),

/* 76 */
wxT("Luma BT.601"),

/* 77 */
wxT("Luma short"),

/* 78 */
wxT("Luma BT.709"),

/* 79 */
wxT("fast"),

/* 80 */
wxT("faster"),

/* 81 */
wxT("average"),

/* 82 */
wxT("desaturation"),

/* 83 */
wxT("decomposition (min)"),

/* 84 */
wxT("decomposition (med)"),

/* 85 */
wxT("decomposition (max)"),

/* 86 */
wxT("red"),

/* 87 */
wxT("green"),

/* 88 */
wxT("blue"),

/* 89 */
wxT("RGB to gray:"),

/* 90 */
wxT("Choose method for RGB to gray conversions"),

/* 91 */
wxT("Success, application will exit."),

/* 92 */
wxT("Error, application will exit."),

/* 93 */
wxT("Reading image from file."),

/* 94 */
wxT("Generating output."),

/* 95 */
wxT("Writing output file."),

/* 96 */
wxT("Cancel"),

/* 97 */
wxT("Abort processing"),

/* 98 */
wxT("Conversion progress"),

/* 99 */
wxT("Not enough memory!\n"),

/* 100 */
wxT("No files found in directory!\n"),

/* 101 */
wxT("Finished."),

/* 102 */
wxT("Error"),

/* 103 */
wxT("Internal error (bug): No argv[0] argument found!"),

/* 104 */
wxT("Internal error (bug): Application group name not found!"),

/* 105 */
wxT("Illegal characters in language/options string!"),

/* 106 */
wxT("Failed to parse command line options!"),

/* 107 */
wxT("Too many paper sizes configured!"),

/* 108 */
wxT("Illegal character(s) in paper size names!"),

/* 109 */
wxT("Internal error (bug): Paper size without a name!"),

/* 110 */
wxT("Failed to obtain paper size information!"),

/* 111 */
wxT("Paper size not correctly configured!"),

/* 112 */
wxT("Not enough memory (RAM)!\n"),

/* 113 */
wxT(":\nERROR: Illegal character(s) in file name!\n"),

/* 114 */
wxT(":\nERROR: File name too long!\n"),

/* 115 */
wxT(":\nERROR: Empty directory\n"),

/* 116 */
wxT(":\nERROR: Not enough memory!\n"),

/* 117 */
wxT(":\nERROR: Failed to read image from file!\n"),

/* 118 */
wxT(":\nERROR: Failed to open graphics output!\n"),

/* 119 */
wxT(":\nERROR: Failed to select frame!\n"),

/* 120 */
wxT(":\nERROR: Failed to write graphics output to file!\n"),

/* 121 */
wxT("Aborted by user."),

/* 122 */
wxT("Reset all options to default values"),

NULL


#line 532 "Bmpp4App.cpt"
};



/**	Non-localized wxChar texts.
*/
static wxChar const * const	wxbmpp_nl_wx[] = {
/* 0 */
wxT("wxbmpp"),

/* 1 */
wxT("1.0.0"),

/* 2 */
wxT("Dirk Krause"),

/* 3 */
wxT("DKrause"),

/* 4 */
wxT("aaaaa"),

/* 5 */
wxT(""),

/* 6 */
wxT(""),

/* 7 */
wxT(" "),

/* 8 */
wxT("\n"),

/* 9 */
wxT("DK tools, wxWidgets, libpng, libjpeg, libtiff, zlib."),

/* 10 */
wxT("http://sourceforge.net/p/dktools/wiki/Home/"),

/* 11 */
wxT("http://www.wxwidgets.org"),

/* 12 */
wxT("http://www.libpng.org/pub/png/libpng.html"),

/* 13 */
wxT("http://www.ijg.org"),

/* 14 */
wxT("http://www.remotesensing.org/libtiff"),

/* 15 */
wxT("http://www.zlib.net"),

/* 16 */
wxT("Error"),

/* 17 */
wxT("Not enough memory (RAM)!"),

NULL


#line 592 "Bmpp4App.cpt"
};



/**	Non-localized dkChar texts.
*/
static dkChar const * const	wxbmpp_nl_dk[] = {
/* 0 */
dkT("dktools"),

/* 1 */
dkT("wxbmpp4.str"),

/* 2 */
dkT("wxbmpp.chm"),

/* 3 */
dkT("wxbmpp.htb"),

/* 4 */
dkT("dummy.txt"),

NULL


#line 621 "Bmpp4App.cpt"
};



/**	Empty dummy text for help text and license file for application.
*/
static dkChar const *	dummy_text[] = {
NULL


#line 630 "Bmpp4App.cpt"
};


static dkChar const	versno_dk[] = { DKT_VERSION_DK };


/**	Implementation of the wxApp functionality.
*/

#if	wxCHECK_VERSION(3,0,0)
wxIMPLEMENT_APP(Bmpp4App);
#else
IMPLEMENT_APP(Bmpp4App)
#endif


bool
Bmpp4App::OnInit()
{
	Bmpp4Frame				*frame			= NULL;
	wxChar const * const	*localizedTexts	= NULL;
	wxPNGHandler			*phPng			= NULL;
	wxXPMHandler			*phXpm			= NULL;
	wxICOHandler			*phIco			= NULL;
	wxArchiveFSHandler		*phArchiveFS	= NULL;
	bool					 back			= false;

	

#line 658 "Bmpp4App.cpt"

	/* Initialize members.
	*/
	pAh = NULL;
	pHc = NULL;
	bRestoreGx = true;
	bRestoreMake = true;
	bRestoreLocation = true;
	bMakeMode = false;
	bAutorun = false;
	pPaperSizes = NULL;
	pasPaperSizes = NULL;
	pDirname = NULL;
	szPaperSizes = 0;
	dk4gra_conf_init(&graconf);

	/*	__CHANGE__ 009:	Initialize further members here.
	*/

	/* Set up helper object.
	*/
	pAh = new Dk4WxApplicationHelper();
	if (NULL == pAh) {
		ShowMemoryErrorMessage();
		goto finished;
	}
	if (!(pAh->Initialize(argv[0], wxbmpp_nl_wx[3], wxbmpp_nl_dk[0]))) {
		goto finished;
	}

	/* Add image and file system handlers for online help.
	*/
	phPng = new wxPNGHandler();
	if (NULL != phPng) {
		wxImage::AddHandler(phPng);
	}
	else {
		ShowMemoryErrorMessage();
		goto finished;
	}

	phXpm = new wxXPMHandler();
	if (NULL != phXpm) {
		wxImage::AddHandler(phXpm);
	}
	else {
		ShowMemoryErrorMessage();
		goto finished;
	}

	phIco = new wxICOHandler();
	if (NULL != phIco) {
		wxImage::AddHandler(phIco);
	}
	else {
		ShowMemoryErrorMessage();
		goto finished;
	}

	phArchiveFS = new wxArchiveFSHandler();
	if (NULL != phArchiveFS) {
		wxFileSystem::AddHandler(phArchiveFS);
	}
	else {
		ShowMemoryErrorMessage();
		goto finished;
	}

	/* Set up help controller.
	*/
	pHc = new Dk4WxHelpController();
	if (NULL == pHc) {
		ShowMemoryErrorMessage();
		goto finished;
	}
	if (!(pHc->Initialize(pAh, wxbmpp_nl_dk[2], wxbmpp_nl_dk[3]))) {
		goto finished;
	}

	/* Attempt to obtain localized texts in users preferred language.
	*/
	localizedTexts = pAh->GetStringTable(wxbmpp_nl_dk[1], wxbmpp_texts);
	if(!(localizedTexts)) {
		localizedTexts = wxbmpp_texts;
	}

	/*	Find list of paper sizes and process options.
	*/												

#line 746 "Bmpp4App.cpt"
	pasPaperSizes = new wxArrayString();
	if (NULL == pasPaperSizes) {					

#line 748 "Bmpp4App.cpt"
		ShowMemoryErrorMessage();
		goto finished;
	}												

#line 751 "Bmpp4App.cpt"
	if (!ProcessOptionsAndInitializeComponents(localizedTexts)) {
		

#line 753 "Bmpp4App.cpt"
		goto finished;
	}												

#line 755 "Bmpp4App.cpt"

	/* Create and show frame.
	*/
	frame = new Bmpp4Frame(
		Bmpp4Frame_MainWindow,
		pAh,
		pHc,
		localizedTexts,
		wxbmpp_nl_wx,
		wxbmpp_nl_dk,
		&graconf,
		pasPaperSizes,
		pDirname,
		szPaperSizes,
		bRestoreGx,
		bRestoreMake,
		bRestoreLocation,
		bMakeMode,
		bAutorun,
		pPaperSizes
	);
	if(!(frame)) {
		ShowMemoryErrorMessage();
		goto finished;
	}

	/*	Show frame, restore position and indicate success.
	*/
	frame->RestoreSettings();
	frame->CorrectGUI();
	frame->RestorePosition();
	frame->Show();
	back = true;

	/* Release resources if initialization failed.
	*/
	finished:
	if(!(back)) {
		if (NULL != pPaperSizes) {
			dk4mem_free(pPaperSizes);
			pPaperSizes = NULL;
		}
		if (NULL != pDirname) {				

#line 798 "Bmpp4App.cpt"
			dk4mem_free(pDirname);
			pDirname = NULL;
		}
		if (NULL != pasPaperSizes) {		

#line 802 "Bmpp4App.cpt"
			delete(pasPaperSizes);
			pasPaperSizes = NULL;			

#line 804 "Bmpp4App.cpt"
		}
		if (NULL != pHc) {
			pHc->Cleanup(); delete(pHc); pHc = NULL;
		}
		if (NULL != pAh) {
			pAh->Cleanup(); delete(pAh); pAh = NULL;
		}
	}
	

#line 813 "Bmpp4App.cpt"
	return back;
}



int
Bmpp4App::OnExit()
{
	int			 back = 0;

	

#line 824 "Bmpp4App.cpt"

	/*	__CHANGE__ 009:	Release resources allocated by further members.
	*/

	/* Release resources.
	*/
	if (NULL != pPaperSizes) {		

#line 831 "Bmpp4App.cpt"
		dk4mem_free(pPaperSizes);
	}
	if (NULL != pDirname) {			

#line 834 "Bmpp4App.cpt"
		dk4mem_free(pDirname);		

#line 835 "Bmpp4App.cpt"
	}
	if (NULL != pasPaperSizes) {	

#line 837 "Bmpp4App.cpt"
		delete(pasPaperSizes);
		pasPaperSizes = NULL;		

#line 839 "Bmpp4App.cpt"
	}
	if (NULL != pHc) {
		pHc->Cleanup(); delete(pHc); pHc = NULL;
	}
	if (NULL != pAh) {
		pAh->Cleanup(); delete(pAh); pAh = NULL;
	}

	/*	__CHANGE__ 010:	Set exit status code.
	*/
	

#line 850 "Bmpp4App.cpt"
	return back;
}



void
Bmpp4App::ShowMemoryErrorMessage(void)
{
	const wxChar	*s_title	= NULL;
	const wxChar	*s_text		= NULL;

	if (NULL != pAh) {
		s_title = pAh->GetBasicString(6);
		s_text  = pAh->GetBasicString(7);
	}
	if (NULL == s_title) {
		s_title = wxbmpp_nl_wx[16];
	}
	if (NULL == s_text) {
		s_text  = wxbmpp_nl_wx[17];
	}
	wxMessageBox(s_text, s_title, (wxOK | wxCENTRE | wxICON_ERROR));
}



bool
Bmpp4App::ProcessOptionsAndInitializeComponents(
	wxChar const * const	*localizedTexts
)
{
	dkChar				*margv[4];
	dk4_app_t			*app		=	NULL;
	dkChar				*argv0		=	NULL;
	dkChar		const	*pahargv0	=	NULL;
	dkChar		const	*grname		=	NULL;
	bool				 back		=	false;
	

#line 888 "Bmpp4App.cpt"
	pahargv0 = pAh->GetDkArgv0();
	if (NULL == pahargv0) {					

#line 890 "Bmpp4App.cpt"
		/* ERROR: No argv[0] */
		wxMessageBox(
			localizedTexts[103], localizedTexts[102],
			(wxOK | wxCENTRE | wxICON_ERROR)
		);
		goto finished;
	}										

#line 897 "Bmpp4App.cpt"
	argv0 = dk4str_dup(pahargv0, NULL);
	if (NULL == argv0) {					

#line 899 "Bmpp4App.cpt"
		/* ERROR: Memory */
		ShowMemoryErrorMessage();
		goto finished;
	}										

#line 903 "Bmpp4App.cpt"
	grname = pAh->GetDkGroupName();
	if (NULL == grname) {					

#line 905 "Bmpp4App.cpt"
		/* ERROR: No group name */
		wxMessageBox(
			localizedTexts[104], localizedTexts[102],
			(wxOK | wxCENTRE | wxICON_ERROR)
		);
		goto finished;
	}										

#line 912 "Bmpp4App.cpt"
	margv[0] = argv0;
	margv[1] = NULL;
	app = dk4app_open_silent(
		1, margv, NULL, 0, grname, versno_dk, wxbmpp_nl_dk[4],
		dummy_text, dummy_text
	);
	if (NULL == app) {						

#line 919 "Bmpp4App.cpt"
		/* ERROR: No app */
		ShowMemoryErrorMessage();
		goto finished;
	}										

#line 923 "Bmpp4App.cpt"
	back = ProcessOptions(app, localizedTexts);

	finished:
	if (NULL != app) {
		dk4app_close(app);
	}
	if (NULL != argv0) {
		dk4mem_free(argv0);
	}
	

#line 933 "Bmpp4App.cpt"
	return		back;
}



#if __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif

static const wxCmdLineEntryDesc wxbmpp_cmd_line_desc[] = {
  {
    wxCMD_LINE_OPTION,
    wxT_2("l"),
    wxT_2("language"),
    wxT_2("Choose output language"),
    wxCMD_LINE_VAL_STRING
  },
  {
    wxCMD_LINE_SWITCH,
    wxT_2("m"),
    wxT_2("make"),
    wxT_2("Run in make mode")
  },
  {
    wxCMD_LINE_PARAM,
    NULL,
    NULL,
    wxT_2("input file"),
    wxCMD_LINE_VAL_STRING,
    wxCMD_LINE_PARAM_OPTIONAL
  },
  { wxCMD_LINE_NONE }
};

#if __GNUC__
#pragma GCC diagnostic pop
#endif



bool
Bmpp4App::ProcessOptions(dk4_app_t *app, wxChar const * const *localizedTexts)
{
	dkChar								 cobu[DK4_MAX_PATH];
	wxChar								 buf[256];
	wxString							 sLanguage(wxT(""));
	dk4_paper_size_collection_t			*pscoll	=	NULL;
	dk4_paper_size_t			const	*paps	=	NULL;
	wxChar						const	*ptr	=	NULL;
	size_t								 i;
	int									 res	=	-1;
	bool								 back	=	false;
	

#line 987 "Bmpp4App.cpt"
	{
		wxCmdLineParser parser(wxbmpp_cmd_line_desc, argc, argv);
		{
			wxLogNull	log;
			res = parser.Parse(false);
		}
		if (0 == res) {
			back = true;
			if(parser.Found(wxT("l"), &sLanguage)) {
				bRestoreGx = false;
				bRestoreMake = false;
				bAutorun = true;
				wxCStrData	sLanguageData = sLanguage.c_str();
				ptr = (wxChar const *)sLanguageData;
				if (NULL != ptr) {
					if (pAh->StringToDk(cobu, DK4_MAX_PATH, ptr, NULL)) {
						(void)dk4gra_conf_setup(
							&graconf, cobu, 1, DK4_GRA_CONF_SCOPE_BMPP, app
						);
					}
					else {
						/* ERROR: Conversion to dkChar string failed */
						wxMessageBox(
							localizedTexts[105], localizedTexts[102],
							(wxOK | wxCENTRE | wxICON_ERROR)
						);
						back = false;
						goto finished;
					}
				}
				else {
					/* ERROR: No c_str (can not happen) */
					back = false;
					goto finished;
				}
			}
			if(parser.Found(wxT("m"))) {
				bMakeMode = true;
			}
			if(parser.GetParamCount() > 0) {
				wxString cmdfn = parser.GetParam(0);
				wxFileName fn(cmdfn);
				fn.Normalize(
					wxPATH_NORM_LONG | wxPATH_NORM_DOTS
					| wxPATH_NORM_TILDE | wxPATH_NORM_ABSOLUTE
				);
#if	0
				/*	2018-04-04	Change
					Whenever wxbmpp is called with -l option the program
					starts a conversion automatically, now for both
					directories and single files.
				*/
				if (!(fn.FileExists())) {
					bAutorun = false;
				}
#endif
				cmdfn = fn.GetFullPath();
				wxCStrData	fnstrdata = cmdfn.c_str();
				ptr = (wxChar const *)fnstrdata;
				if (NULL != ptr) {
					pDirname = dk4strx_dup(ptr, NULL);
					if (NULL != pDirname) {
						bRestoreLocation = false;
					}
					else {
						/* ERROR: Memory */
						ShowMemoryErrorMessage();
						back = false;
						goto finished;
					}
				}
			}
			else {
				bAutorun = false;
			}
		}
		else {
			/* ERROR: In command line options */
			wxMessageBox(
				localizedTexts[106], localizedTexts[102],
				(wxOK | wxCENTRE | wxICON_ERROR)
			);
			goto finished;
		}
	}
	pscoll = dk4app_get_paper_sizes(app);
	if (NULL != pscoll) {
		dk4papersize_coll_reset(pscoll);
		do {
			paps = dk4papersize_coll_next(pscoll);
			if (NULL != paps) {
				if (NULL != paps->name) {	

#line 1079 "Bmpp4App.cpt"
					if (
						pAh->StringToWx(
							buf, DK4_SIZEOF(buf,wxChar), paps->name, NULL
						)
					) {
						if (SIZE_MAX > szPaperSizes) {
							pasPaperSizes->Add(buf);
							szPaperSizes += 1;
						}
						else {
							/* ERROR: Too many paper sizes */
							wxMessageBox(
								localizedTexts[107], localizedTexts[102],
								(wxOK | wxCENTRE | wxICON_ERROR)
							);
							back = false;
						}
					}
					else {
						/* ERROR: Failed to convert to wx */
						wxMessageBox(
							localizedTexts[108], localizedTexts[102],
							(wxOK | wxCENTRE | wxICON_ERROR)
						);
						back = false;
					}
				}
				else {
					/* ERROR: Paper size with no name (bug) */
					wxMessageBox(
						localizedTexts[109], localizedTexts[102],
						(wxOK | wxCENTRE | wxICON_ERROR)
					);
				}
			}
		} while((NULL != paps) && (back));
		if ((0 < szPaperSizes) && (back)) {
			pPaperSizes = dk4mem_new(dk4_paper_size_t,szPaperSizes,NULL);
			for (i = 0; i < szPaperSizes; i++) {
				pPaperSizes[i].name = NULL;
				pPaperSizes[i].name = NULL;
				pPaperSizes[i].w = 595.0;
				pPaperSizes[i].h = 842.0;
				pPaperSizes[i].i = 56.0;
				pPaperSizes[i].o = 28.0;
				pPaperSizes[i].b = 14.0;
				pPaperSizes[i].t = 14.0;
			}
			if (NULL != pPaperSizes) {
				dk4papersize_coll_reset(pscoll);
				i = 0;
				do {
					paps = dk4papersize_coll_next(pscoll);
					if (NULL != paps) {
					DK4_MEMCPY(&(pPaperSizes[i]),paps,sizeof(dk4_paper_size_t));
					pPaperSizes[i].name = NULL;
					}
					i++;
				} while((NULL != paps) && (i < szPaperSizes));
			}
			else {
				/* ERROR: Memory */
				ShowMemoryErrorMessage();
				back = false;
			}
		}
		dk4papersize_coll_close(pscoll);
		

#line 1147 "Bmpp4App.cpt"
	}
	else {
		/* ERROR: Failed to obtain paper sizes collection */
		wxMessageBox(
			localizedTexts[110], localizedTexts[102],
			(wxOK | wxCENTRE | wxICON_ERROR)
		);
		back = false;
	}

	finished:
	

#line 1159 "Bmpp4App.cpt"
	return back;
}




/* vim: set ai sw=4 ts=4 : */