File: cli.c

package info (click to toggle)
udo 6.4.1-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,680 kB
  • sloc: ansic: 42,702; makefile: 81; cpp: 19
file content (892 lines) | stat: -rw-r--r-- 25,268 bytes parent folder | download | duplicates (6)
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
/*	############################################################
	# @(#) cli.c (Kommandozeilen-Version)
	# @(#)
	# @(#) Copyright (c) 1995-2001 by Dirk Hagedorn
	# @(#) Dirk Hagedorn (udo@dirk-hagedorn.de)
	#
	# This program is free software; you can redistribute it and/or
	# modify it under the terms of the GNU General Public License
	# as published by the Free Software Foundation; either version 2
	# of the License, or (at your option) any later version.
	# 
	# This program is distributed in the hope that it will be useful,
	# but WITHOUT ANY WARRANTY; without even the implied warranty of
	# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	# GNU General Public License for more details.
	# 
	# You should have received a copy of the GNU General Public License
	# along with this program; if not, write to the Free Software
	# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
	############################################################	*/
#ifndef ID_CLI_C
#define ID_CLI_C
const char *id_cli_c= "@(#) cli.c       21.08.1998";
#endif

#include	"import.h"
#include	<stdio.h>	
#include	<string.h>	
#include	<stdlib.h>
#include	"portab.h"
#include	"version.h"
#include	"constant.h"
#include	"udo_type.h"
#include	"file.h"
#include	"cfg.h"
#include	"msg.h"
#include	"udo.h"
#include        "udomem.h"

#ifdef __TOS__
	#ifdef USE_PCTOS
		#include <tos.h>
	#else
		#include	<mintbind.h>
	#endif
#endif

#include	"export.h"
#include	"gui.h"


/*	############################################################
	# Typen
	############################################################	*/
typedef enum
{
	DEUTSCH,
	ENGLISH
} t_lang;




/*	############################################################
	# Variablen
	############################################################	*/
LOCAL char		strPrgname[33];	/* der Name dieses Programms */
LOCAL t_lang	eLanguage;		/* Sprache */

LOCAL BOOLEAN	bHoldKey;
LOCAL BOOLEAN	bShowArgs;
LOCAL BOOLEAN   bShowHelp;
LOCAL BOOLEAN   bShowVersion;
LOCAL BOOLEAN	bShowIdent;
LOCAL int last_percent;

#define	PRGNAME		"udo"

/*	############################################################
	# lokale Prototypen
	############################################################	*/
LOCAL void show_ident ( void );
LOCAL void show_version ( void );
LOCAL void show_usage ( void );
LOCAL void show_use_help ( void );
LOCAL void show_help ( void );
LOCAL void show_unknown ( const char *s );
LOCAL void wait_on_keypress ( void );

LOCAL int getcliopt ( int *counter, const char *arg, const char *argnext, const BOOLEAN from_file );


/*	############################################################
	# Optionen
	############################################################	*/
typedef struct _cliopt
{
	char		longname[16];		/* lange Option								*/
	char		shortname[6];		/* kurze Option								*/
	char		type;				/* Typ: b=Boolean, c=char[]					*/
	BOOLEAN	needs2;					/* folgt der Option ein Parameter?			*/
	void			*var;			/* Variable, die geaendert wird				*/
	int			val;				/* Wert, der bei Benutzung zugewiesen wird	*/
}	CLIOPT;


LOCAL const CLIOPT cliopt[]=
{
	{	"--asc",			"-a",		'b',	FALSE,	&desttype,			TOASC	},
	{	"--amg",			"",			'b',	FALSE,	&desttype,			TOAMG	},
	{	"--argv",			"",			'b',	FALSE,	&bShowArgs,			TRUE	},
	{	"--check",			"",			'b',	FALSE,	&bCheckMisc,		TRUE	},
	{	"--c",				"-c",		'b',	FALSE,	&desttype,			TOSRC	},
	{	"--drc",			"",			'b',	FALSE,	&desttype,			TODRC	},
	{	"--force-long",		"",			'b',	FALSE,	&bForceLong,		TRUE	},
	{	"--force-short",	"",			'b',	FALSE,	&bForceShort,		TRUE	},
	{	"--hold",			"-H",		'b',	FALSE,	&bHoldKey,			TRUE	},
	{	"--help",			"",			'b',	FALSE,	&bShowHelp,			TRUE	},
	{	"--helptag",		"-g",		'b',	FALSE,	&desttype,			TOHPH	},
	{	"--html",			"-h",		'b',	FALSE,	&desttype,			TOHTM	},
	{	"--htmlhelp",		"-hh",		'b',	FALSE,	&desttype,			TOMHH	},
	{	"--ident",			"",			'b',	FALSE,	&bShowIdent,		TRUE	},
	{	"--info",			"-i",		'b',	FALSE,	&desttype,			TOINF	},
	{	"--ipf",			"",			'b',	FALSE,	&desttype,			TOIPF	},
	{	"--linuxdoc",		"-x",		'b',	FALSE,	&desttype,			TOLDS	},
	{	"--lyx",			"",			'b',	FALSE,	&desttype,			TOLYX	},
	{	"--man",			"-m",		'b',	FALSE,	&desttype,			TOMAN	},
	{	"--map",			"",			'b',	FALSE,	&bUseIdMapFileC,	TRUE	},
	{	"--map-pas",		"",			'b',	FALSE,	&bUseIdMapFilePas,	TRUE	},
	{	"--map-vb",			"",			'b',	FALSE,	&bUseIdMapFileVB,	TRUE	},
	{	"--map-gfa",		"",			'b',	FALSE,	&bUseIdMapFileGFA,	TRUE	},
	{	"--no-hypfile",		"-y",		'b',	FALSE,	&bNoHypfile,		TRUE	},
	{	"--no-idxfile",		"-d",		'b',	FALSE,	&bNoIdxfile,		TRUE	},
	{	"--no-logfile",		"-l",		'b',	FALSE,	&bNoLogfile,		TRUE	},
	{	"--no-warnings",	"-W",		'b',	FALSE,	&bNoWarnings,		TRUE	},
	{	"--nroff",			"-n",		'b',	FALSE,	&desttype,			TONRO	},
	{	"--outfile",		"-o",		'c',	TRUE,	outfile.full,		0		},
	{	"--pascal",			"-P",		'b',	FALSE,	&desttype,			TOSRP	},
	{	"--pdflatex",		"-f",		'b',	FALSE,	&desttype,			TOPDL	},
	{	"--ps",				"",			'b',	FALSE,	&desttype,			TOKPS	},
	{	"--pchelp",			"-p",		'b',	FALSE,	&desttype,			TOPCH	},
	{	"--quiet",			"-q",		'b',	FALSE,	&bBeQuiet,			TRUE	},
	{	"--quickview",		"--aqv",	'b',	FALSE,	&desttype,			TOAQV	},
	{	"--rtf",			"-r",		'b',	FALSE,	&desttype,			TORTF	},
	{	"--stg",			"-s",		'b',	FALSE,	&desttype,			TOSTG	},
	{	"--save-upr",		"",			'b',	FALSE,	&bUseUPRfile,		TRUE	},
	{	"--test",			"",			'b',	FALSE,	&bTestmode,			TRUE	},
	{	"--tex",			"-t",		'b',	FALSE,	&desttype,			TOTEX	},
	{	"--txt",			"-a",		'b',	FALSE,	&desttype,			TOASC	},
	{	"--tree",			"",			'b',	FALSE,	&bUseTreefile,		TRUE	},
	{	"--udo",			"-u",		'b',	FALSE,	&desttype,			TOUDO	},
	{	"--verbose",		"",			'b',	FALSE,	&bVerbose,			TRUE	},
	{	"--version",		"",			'b',	FALSE,	&bShowVersion,		TRUE	},
	{	"--vision",			"-v",		'b',	FALSE,	&desttype,			TOTVH	},
	{	"--win",			"-w",		'b',	FALSE,	&desttype,			TOWIN	},
	{	"--win4",			"-4",		'b',	FALSE,	&desttype,			TOWH4	},

	/* Endekennung */
	{	"",					"",			'c',	FALSE,	NULL,				0		},
};


/*	----------------------------------------------------------------------
	Programm-Ausgaben
	----------------------------------------------------------------------	*/
LOCAL const char	*Usage[]=
{	"Gebrauch: %s [-acdDghHilmnpPqrstvwWxy@] [-o outfile] file",
	"usage: %s [-acdDghHilmnpPqrstvwWxy@] [-o outfile] file"
};

LOCAL const char	*Use_Help[]=
{	"          Mehr Hilfe mit --help",
	"          use --help for more information"
};

LOCAL const char	*Prog_Help[]=
{
	"-a,    --asc           ins ASCII-Format konvertieren\n"
	"       --amg           ins AmigaGuide-Format konvertieren\n"
	"--aqv, --quickview     ins Apple-QuickView-Format konvertieren\n"
	"-c,    --c             C-Sourcecode erzeugen\n"
	"       --check         Ueberpruefungen aktivieren\n"
	"       --drc           ins David's-Readme-Compiler-Format konvertieren\n"
	"-d,    --noidxfile     kein Indexfile (.ux?) anlegen\n"
	"-D sym                 Symbol <sym> setzen\n"
	"       --force-long    immer lange Dateinamen erzeugen\n"
	"       --force-short   immer kurze Dateinamen erzeugen\n"
	"-f     --pdflatex      ins PDFLaTeX-Format konvertieren\n"
	"-g,    --helptag       ins HP-Helptag-SGML-Format konvertieren\n"
	"-h,    --html          ins HTML-Format konvertieren\n"
	"-hh,   --htmlhelp      ins HTML-Help-Format konvertieren\n"
	"-H,    --hold          am Ende auf Tastendruck warten\n"
	"-i,    --info          ins GNU-Texinfo-Format konvertieren\n"
	"       --ipf           ins OS/2-IPF-Format konvertieren\n"
	"       --lyx           ins LyX-Format konvertieren\n"
	"-l,    --nologfile     kein Logfile (.ul?) anlegen\n"
	"-m,    --man           in eine Manualpage konvertieren\n"
	"       --map           C-Headerfile mit WinHelp-Jump-IDs erzeugen\n"
	"       --map-pas       Pascal-Headerfile mit WinHelp-Jump-IDs erzeugen\n"
	"       --map-vb        VB-Headerfile mit WinHelp-Jump-IDs erzeugen\n"
	"       --map-gfa       GFA-Headerfile mit WinHelp-Jump-IDs erzeugen\n"
	"-n,    --nroff         ins nroff-Format konvertieren\n"
	"-o F,  --outfile F     Ausgaben in die Datei F schreiben\n"
	"-p,    --pchelp        ins Pure-C-Help-Quelltextformat konvertieren\n"
	"-P,    --pascal        Pascal-Sourcecode erzeugen\n"
	"       --ps            ins PostScript-Format konvertieren\n"
	"-q,    --quiet         Ausgaben auf stdout und stderr unterdruecken\n"
	"-r,    --rtf           ins Rich Text Format konvertieren\n"
	"       --save-upr      Projekt-Datei (.upr) ausgeben\n"
	"-s,    --stg           ins ST-Guide-Quelltextformat konvertieren\n"
	"       --test          Testmodus (kein Outfile erzeugen)\n"
	"-t,    --tex           ins LaTeX-Format konvertieren\n"
	"       --tree          Include-Baum (.ut?) ausgeben\n"
  "       --verbose       ausfuehrliche Konvertierungs-Infos anzeigen\n"
	"-u,    --udo           Dateien sammeln und in einer UDO-Datei sichern\n"
	"-v,    --vision        ins Turbo-Vision-Help-Format konvertieren\n"
	"-w,    --win           ins WinHelp-Quelltextformat konvertieren\n"
	"-w4,   --win4          ins WinHelp4-Quelltextformat konvertieren\n"
	"-W,    --no-warnings   Warnungen unterdruecken\n"
	"-x,    --linuxdoc      ins Linuxdoc-SGML-Format konvertieren\n"
	"-y,    --no-hypfile    kein Hyphenfile (.uh?) anlegen\n"
	"-@ F                   Optionen aus der Datei F lesen\n"
	"       --help          diese Informationen anzeigen und beenden\n"
  "       --version       Versionsinformationen anzeigen und beenden",




	"-a,    --asc           convert to ASCII\n"
	"       --amg           convert to AmigaGuide\n"
	"--aqv, --quickview     convert to Apple QuickView\n"
	"-c,    --c             generate C sourcecode\n"
	"       --check         activate checkings\n"
	"       --drc           convert to David's Readme Compiler format\n"
	"-d,    --no-idxfile    don't generate index file (.ux?)\n"
	"-D sym                 set symbol <sym>\n"
	"       --force-long    save always long filenames\n"
	"       --force-short   save always short filenames\n"
	"-f     --pdflatex      generate PDFLaTeX sourcecode\n"
	"-g,    --helptag       convert to HP Helptag SGML\n"
	"-h,    --html          convert to HTML\n"
	"-hh,   --htmlhelp      convert to HTML-Help\n"
	"-H,    --hold          press key when udo finishs\n"
	"-i,    --info          convert to GNU Texinfo\n"
	"       --ipf           convert to OS/2 IPF format\n"
	"       --lyx           convert to LyX\n"
	"-l,    --no-logfile    don't generate logfile (.ul?)\n"
	"-m,    --man           convert to a manualpage\n"
	"       --map           generate C header file with jump id's for WinHelp\n"
	"       --map-pas       generate Pascal header file with jump id's for WinHelp\n"
	"       --map-vb        generate VB header file with jump id's for WinHelp\n"
	"       --map-gfa       generate GFA header file with jump id's for WinHelp\n"
	"-n,    --nroff         convert to nroff\n"
	"-o F,  --outfile F     write to file F\n"
	"-p,    --pchelp        convert to Pure C Help\n"
	"-P,    --pascal        generate Pascal sourcecode\n"
	"       --ps            convert to PostScript\n"
	"-q,    --quiet         suppress output to stdout and stderr\n"
	"-r,    --rtf           convert to RTF\n"
	"       --save-upr      create project file (.upr)\n"
	"-s,    --stg           convert to ST-Guide\n"
	"       --test          use test mode (no outfile will be saved)\n"
	"-t,    --tex           convert to LaTeX\n"
	"       --tree          generate tree file (.ut?)\n"
	"-u,    --udo           collect all files and save in UDO format\n"
  "       --verbose       verbose mode\n"
	"-v,    --vision        convert to Turbo Vision Help\n"
	"-w,    --win           convert to WinHelp\n"
	"-w4,   --win4          convert to WinHelp4\n"
	"-W,    --no-warnings   suppress warnings\n"
	"-x,    --linuxdoc      convert to Linuxdoc SGML\n"
	"-y,    --no-hypfile    don't generate hyphen file (.uh?)\n"
	"-@ F                   read options from file F\n"
	"       --help          show this helppage and exit\n"
  "       --version       show version of UDO and exit\n"
};

LOCAL const char *No_Option[]=
{	"Unbekannte Option!",
	"unknown option!"
};


/*	############################################################
	#
	# Ausgaberoutinen (call back's)
	#
	############################################################	*/
/*	----------------------------------------------------------------------
	Ausgabe von Informationen auf die Standardausgabe, aber nur falls
	ein Outfile geoeffnet wurde, der Testmodus aktiv ist und UDO nicht
	ruhig gestellt wurde
	----------------------------------------------------------------------	*/
GLOBAL void show_status_info ( const char *s )
{
	if ( (bOutOpened || bTestmode) && !bBeQuiet )
	{	fprintf(stdout, "%s\n", s);
	}
}

GLOBAL void show_status_loginfo ( const char *s )
{
	BOOLEAN flag= FALSE;
	if ( (bOutOpened || bTestmode) && !bBeQuiet )
	{	fprintf(stdout, "%s\n", s);
		flag= TRUE;
	}

	if (!flag || !bNoLogfile)
	{	logln(s);
	}
}

GLOBAL void show_status_pass ( const char *s )
{
	if ( (bOutOpened || bTestmode) && !bBeQuiet )
	{	fprintf(stdout, "%s\n", s);
	}
}

GLOBAL void show_status_udo2udo ( const char *s )
{
	if ( (bOutOpened || bTestmode) && !bBeQuiet )
	{	fprintf(stdout, "Reading %s\n", s);
	}
}

GLOBAL void show_status_node ( const char *s )
{
	if ( (bOutOpened || bTestmode) && !bBeQuiet )
	{	fprintf(stdout, "%s", s);
	}
}

GLOBAL void show_status_file_1 ( const char *s )
{
	/* Dummy-Routine */
	UNUSED(s);
}

GLOBAL void show_status_file_2 ( const char *s )
{
	if ( (bOutOpened || bTestmode) && !bBeQuiet )
	{	fprintf(stdout, "(%s) ", s);
	}
}

GLOBAL void show_status_percent ( unsigned long Pass1Lines, unsigned long Pass2Lines )
{
	int percent;
	
	percent= 0;
	if (Pass1Lines>0)
	{	percent= (int) ((100*Pass2Lines)/Pass1Lines);
	}
	
	if ( (bOutOpened || bTestmode) && !bBeQuiet && percent != last_percent)
	{	if (bVerbose)
		{	fprintf(stdout, "\n%3d%% ", percent);
		}
		else
		{	fprintf(stdout, "%3d%%\010\010\010\010", percent);
		}
		fflush(stdout);
		last_percent = percent;
	}
}

GLOBAL void show_status_errors ( const char *s )
{
	if ( (bOutOpened || bTestmode) && !bBeQuiet )
	{
		fprintf(stdout, "%s\n", s);
	}
}


GLOBAL void show_logln_message ( const char *s )
{
	/* Dummy-Routine */
	UNUSED(s);
}


/*	######################################################################
	#
	# Dummyfunktionen (call back's)
	#
	######################################################################	*/
GLOBAL void warning_err_logfile ( void )
{	error_open_logfile(sLogfull);
}

GLOBAL void warning_err_treefile ( void )
{	error_open_treefile(sTreefull);
}

GLOBAL void warning_err_uprfile ( void )
{	error_open_uprfile(sUPRfull);
}

GLOBAL void warning_err_hypfile ( void )
{	error_open_hypfile(sHypfull);
}

GLOBAL void warning_err_idxfile ( void )
{	error_open_idxfile(sIdxfull);
}

GLOBAL void warning_err_destination ( void )
{	/* Dummy-Funktion */
}

GLOBAL void multitasking_interrupt ( void )
{	/* Dummy-Funktion */
}

GLOBAL void unregistered_copyright ( void )
{	/* Dummy-Funktion */
}

GLOBAL void cursor_working ( void )
{	/* Dummy-Funktion */
}

GLOBAL void cursor_active ( void )
{	/* Dummy-Funktion */
}

GLOBAL BOOLEAN break_action ( void )
{	return FALSE;
}


/*	######################################################################
	#
	# Programm-Informationen und Fehlermeldungen
	#
	######################################################################	*/


/*	----------------------------------------------------------------------
	show_version() zeigt die Versionsnummer dieses Programms
	----------------------------------------------------------------------	*/
LOCAL void show_version ( void )
{
	/* fprintf(stdout, "\n%s\n", strPrgname); v6.4.1[vj]: commented out (wished by Ulrich Kretschmer) */
	fprintf(stdout, "UDO Version %s.%s.%s for %s, %s %s\n",
				UDO_REL, UDO_SUBVER, UDO_PL, UDO_OS, compile_date, compile_time);
	fprintf(stdout, "%s\n", COPYRIGHT);
	sprintf(sInfMsg, "UDO is Open Source (see %s for further information).\n", UDO_URL);
	fprintf(stdout, sInfMsg);
}

extern const char *id_abo_c;
extern const char *id_cfg_c;
extern const char *id_chr_c;
extern const char *id_env_c;
extern const char *id_fsplit_c;
extern const char *id_img_c;
extern const char *id_msg_c;
extern const char *id_str_c;
extern const char *id_sty_c;
extern const char *id_tab_c;
extern const char *id_toc_c;
extern const char *id_tp_c;
extern const char *id_udo_c;

extern const char *id_img_html_h;
extern const char *id_img_win_h;
extern const char *id_img_stg_h;
extern const char *id_charset_h;

#ifndef __HPUX_ROMAN8__
extern const char *id_hp82iso_h;
#endif

#if !defined(__MACOS__) && !defined(__MACOSX__)
extern const char *id_mac2iso_h;
#endif

#if !defined(__TOS__)
extern const char *id_tos2iso_h;
#endif

/*	----------------------------------------------------------------------
	show_ident() listet die Identstrings
	----------------------------------------------------------------------	*/
LOCAL void show_ident ( void )
{
	show_version();
	fprintf(stdout, "\n");
	fprintf(stdout, "%s\n", id_abo_c+5);
	fprintf(stdout, "%s\n", id_cfg_c+5);
	fprintf(stdout, "%s\n", id_chr_c+5);
	fprintf(stdout, "%s\n", id_cli_c+5);
	fprintf(stdout, "%s\n", id_env_c+5);
	fprintf(stdout, "%s\n", id_fsplit_c+5);
	fprintf(stdout, "%s\n", id_img_c+5);
	fprintf(stdout, "%s\n", id_msg_c+5);
	fprintf(stdout, "%s\n", id_str_c+5);
	fprintf(stdout, "%s\n", id_sty_c+5);
	fprintf(stdout, "%s\n", id_toc_c+5);
	fprintf(stdout, "%s\n", id_tab_c+5);
	fprintf(stdout, "%s\n", id_tp_c+5);
	fprintf(stdout, "%s\n", id_udo_c+5);

	fprintf(stdout, "\n");

	fprintf(stdout, "%s\n", id_charset_h+5);
	fprintf(stdout, "%s\n", id_img_html_h+5);
	fprintf(stdout, "%s\n", id_img_win_h+5);
	fprintf(stdout, "%s\n", id_img_stg_h+5);

#ifndef __HPUX_ROMAN8__
	fprintf(stdout, "%s\n", id_hp82iso_h+5);
#endif

#if !defined(__MACOS__) && !defined(__MACOSX__)
	fprintf(stdout, "%s\n", id_mac2iso_h+5);
#endif

#if !defined(__TOS__)
	fprintf(stdout, "%s\n", id_tos2iso_h+5);
#endif

}	/* show_ident */


/*	----------------------------------------------------------------------
	show_usage() gibt Auskunft ueber den Gebrauch dieses Programm
	----------------------------------------------------------------------	*/
LOCAL void show_usage ( void )
{	char s[256];
	sprintf(s, Usage[eLanguage], strPrgname);
	fprintf(stdout, "%s\n", s);
}

/*	----------------------------------------------------------------------
	show_use_help() gibt einen Hinweis auf "--help" aus
	----------------------------------------------------------------------	*/
LOCAL void show_use_help ( void )
{	fprintf(stdout, "%s\n", Use_Help[eLanguage]);
}

/*	----------------------------------------------------------------------
	show_help() gibt einen Hilfstext zu diesem Programm aus
	----------------------------------------------------------------------	*/
LOCAL void show_help ( void )
{	show_version();
	show_usage();
	fprintf(stdout, "\n%s\n", Prog_Help[eLanguage]);
}


LOCAL void show_unknown ( const char *s )
{
	fprintf(stdout, "%s: %s %s\n", strPrgname, No_Option[eLanguage], s);
}


/*	######################################################################
	# Auf Tastendruck warten, falls Option gesetzt wurde
	######################################################################	*/
LOCAL void wait_on_keypress ( void )
{
	char input[256];
	
	if (bHoldKey)
	{	if (eLanguage==DEUTSCH)
		{	fprintf(stdout, "\n<RETURN> druecken...\n");
		}
		else
		{	fprintf(stdout, "\nPress <RETURN>...\n");
		}
		fgets(input, 256, stdin);
	}

}	/* wait_on_keypress */



/*	######################################################################
	# Optionen ermitteln, nun auch per "-@ F" aus einer Datei
	######################################################################	*/

#define	MAX_FILE_ARGV	256

LOCAL BOOLEAN read_cliopt_file ( const char *name )
{
	char *fargv[MAX_FILE_ARGV+1], *ptr, *mp;
	FILE *file;
	char opt[256];
	size_t sl;
	int counter= -1;
	int i;
	
	file= fopen(name, "r");
	if (!file)
	{	return FALSE;
	}

	while ( fgets(opt, 256, file) )
	{
		sl= strlen(opt);
		while ( sl>0 && opt[sl-1]<' ' )
		{	opt[sl-1]= EOS;
			sl--;
		}
		ptr= opt;
		while ( *ptr!=EOS && (*ptr==' ' || *ptr=='\t') )
		{	ptr++;
		}
		sl= strlen(ptr);
		if (sl>0)
		{	if ( counter+1<MAX_FILE_ARGV )
			{	mp= (char *) um_malloc ( sl * sizeof(char) + 1 );
				if (mp)
				{	counter++;
					fargv[counter]= mp;
					strcpy(fargv[counter], ptr);
				}
			}
		}
	}
	
	fclose(file);

	i= 0;
	while(i<=counter)
	{	getcliopt(&i, fargv[i], (i+1<=counter) ? fargv[i+1] : NULL, TRUE);
		i++;
	}
	
	for (i=counter; i>=0; i--)
	{	if (fargv[i]!=NULL)
		{	um_free(fargv[i]);
			fargv[i]= NULL;
		}
	}
	
	return TRUE;

}	/* read_cliopt_file */



LOCAL BOOLEAN getcliopt ( int *counter, const char *arg, const char *argnext, const BOOLEAN from_file )
{
	register int i;
	BOOLEAN found= FALSE;
	
	i= 0;

	while ( cliopt[i].longname[0]!=EOS )
	{
		if	(	strcmp(arg, cliopt[i].longname)==0 ||
				(	cliopt[i].shortname[0]!=EOS &&
					strcmp(arg, cliopt[i].shortname)==0
				)
			)
		{
			found= TRUE;

			if ( cliopt[i].var!=NULL )			
			{	switch ( cliopt[i].type )
				{
					case 'b':	/* BOOLEAN */
						*(BOOLEAN *) cliopt[i].var= cliopt[i].val;
						break;
					case 'c':	/* char */
						*(char *) cliopt[i].var= 0;
						if ( cliopt[i].needs2 )
						{	if ( argnext!=NULL )
							{ 	*counter = *counter + 1;
								strcpy( (char *) cliopt[i].var, argnext);
							}
						}
						else
						{	strcpy( (char *) cliopt[i].var, "");
						}
						break;
				}
			}
		}

		i++;
	}	

	if (!found)
	{
		if ( arg[0]!='-' )
		{	strcpy(infile.full, arg);
			found= TRUE;
		}
		else
		{
			if (strcmp(arg, "-@")==0 && !from_file)
			{	if (argnext!=NULL)
				{	*counter= *counter + 1;
					found= read_cliopt_file(argnext);
				}
				else
				{	/* <???> Fehlermeldung */
					found= FALSE;
				}
			}	else
			if (strcmp(arg, "-D")==0)
			{	if (argnext!=NULL)
				{	*counter= *counter + 1;
					add_udosymbol(argnext);
					found= TRUE;
				}
				else
				{	/* <???> Fehlermeldung */
					found= FALSE;
				}
			}
			else
			{	show_unknown(arg);
			}
		}
	}
	
	return found;

}	/* getcliopt */



/*	######################################################################
	# Hauptroutine
	######################################################################	*/
int main ( int argc, const char *argv[] )
{
	int		i;
	char	nam[32], *ptr;
	BOOLEAN cliok;

        /* One of the first things to do: init UDO memory management,
        else um_malloc can not be called. */
        init_um();

	/* ---Programmnamen ermitteln--- */
#ifdef __TOS__
	Pdomain(1);
	strcpy(strPrgname, PRGNAME);
#else
	((argv[0][0]!=0)) ?	strcpy(strPrgname, argv[0]) : strcpy(strPrgname, PRGNAME);
#endif

	/* globale Variablen initialisieren */
	init_vars();
	sprintf(nam, "UDO Version %s", UDO_REL);
#ifdef __WIN32__
	init_module_config("udo32.ini", nam, UDO_OS);
#else
	init_module_config("udo.ini", nam, UDO_OS);
#endif
	read_profile();

	outfile.file= stdout;
	infile.file= stdin;

	eLanguage= ENGLISH;				/* default ist Englisch */

	desttype= TOASC;
	bNoLogfile= FALSE;
	bNoHypfile= FALSE;
	bNoIdxfile= FALSE;
	bBeQuiet= FALSE;
	bVerbose= FALSE;
	bTestmode= FALSE;
	bUseTreefile= FALSE;
	bUseUPRfile= FALSE;
	bUseIdMapFileC= FALSE;
	bUseIdMapFilePas= FALSE;
	bUseIdMapFileVB= FALSE;
	bUseIdMapFileGFA= FALSE;
	bNoWarnings= FALSE;
	bForceLong= FALSE;
	bForceShort= FALSE;
	bCheckMisc= FALSE;
	bHoldKey = FALSE;
	bShowArgs = FALSE;
	bShowVersion = FALSE;
	bShowHelp = FALSE;
	bShowIdent = FALSE;
	last_percent = -1;

	outfile.full[0]= EOS;
	infile.full[0]= EOS;
	sLogfull[0]= EOS;

	no_stderr_output= FALSE;		/* r5pl9 */

	if ( (ptr=getenv("LANG"))!=NULL )
	{	if ( strstr(ptr, "german") )
		{	eLanguage=DEUTSCH;
		}
	}

	if ( (ptr=getenv("LC_ALL"))!=NULL )
	{	if ( strstr(ptr, "german") )
		{	eLanguage=DEUTSCH;
		}
	}

	if ( (ptr=getenv("LC_MESSAGES"))!=NULL )
	{	if ( strstr(ptr, "german") )
		{	eLanguage=DEUTSCH;
		}
	}


	/* Kommandozeile auswerten */
	i= 1;
	cliok= TRUE;

	while ( (cliok) && (i<argc) && (argv[i] != NULL) )
	{
		cliok= getcliopt(&i, argv[i], (i<argc) ? argv[i+1] : NULL, FALSE);
		i++;
	}	/*while*/


	/* r6pl6: Kommandos anzeigen */
	if (bShowArgs)
	{
		i= 1;
		while ( i<argc )
		{
			fprintf(stdout, "%2d: %s\n", i, argv[i]);
			i++;
		}	/*while*/
	} else if (bShowHelp)
	{
		show_help();
	} else if (bShowVersion)
	{
		show_version();
	} else if (bShowIdent)
	{
		show_ident();
	} else
	{
		if ( i==1 || infile.full[0]==EOS )
		{	/* Leere Kommandozeile uebergeben oder kein Infile*/
			show_version();
			show_usage();
			show_use_help();
		}
		else
		{
			fsplit(infile.full, infile.driv, infile.path, infile.name, infile.suff);

			if (outfile.full[0]!=EOS)
			{	fsplit(outfile.full, outfile.driv, outfile.path, outfile.name, outfile.suff);
				if ( strcmp(outfile.name, "!")==0 )
				{	dest_adjust();
				}
				else
				{	dest_special_adjust();
				}
			}
			else
			{	bNoLogfile= TRUE;
				bNoHypfile= TRUE;
			}

			if (desttype==TOUDO)
			{
				udo2udo(infile.full);
			}
			else
			{
				udo(infile.full);	/* <???> informativeren Exitcode ermitteln */
			}
		}
	}

	exit_um(); /* Call memory management to clean up memory allocated */

	wait_on_keypress();
	
	if (!cliok || bErrorDetected || get_error_counter() > 0)
	{	return 1;
	}

	return 0;

}	/* main */