-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathcobc.c
2524 lines (2263 loc) · 56.2 KB
/
cobc.c
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
/*
* Copyright (C) 2001-2009 Keisuke Nishida
* Copyright (C) 2007-2009 Roger While
*
* 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, 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
#include "config.h"
#include "defaults.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <setjmp.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <time.h>
#include <sys/stat.h>
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
#ifdef _WIN32
#include <windows.h> /* for GetTempPath, GetTempFileName */
#endif
#ifdef HAVE_KPATHSEA_GETOPT_H
#include <kpathsea/getopt.h>
#else
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#else
#include "lib/getopt.h"
#endif
#endif
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#include <tarstamp.h>
#include "cobc.h"
#include "tree.h"
/* Compile level */
enum cb_compile_level {
CB_LEVEL_PREPROCESS = 1,
CB_LEVEL_TRANSLATE,
CB_LEVEL_COMPILE,
CB_LEVEL_ASSEMBLE,
CB_LEVEL_MODULE,
CB_LEVEL_LIBRARY,
CB_LEVEL_EXECUTABLE
};
#if defined(_MSC_VER)
#define PATHSEPS ";"
#else
#define PATHSEPS ":"
#endif
#ifdef _MSC_VER
#define CB_COPT_1 " /O1"
#define CB_COPT_2 " /O2"
#define CB_COPT_S " /Os"
#elif defined(__hpux) && !defined(__GNUC__)
#define CB_COPT_1 " -O"
#define CB_COPT_2 " +O2"
#define CB_COPT_S " +O2 +Osize"
#elif defined(__xlc__)
#define CB_COPT_1 " -O"
#define CB_COPT_2 " -O2"
#define CB_COPT_S " -O"
#else
#define CB_COPT_1 " -O"
#define CB_COPT_2 " -O2"
#define CB_COPT_S " -Os"
#endif
/*
* Global variables
*/
int cb_source_format = CB_FORMAT_FIXED;
int cb_source_format1 = 0;
#ifdef COB_EBCDIC_MACHINE
int cb_display_sign = COB_DISPLAY_SIGN_EBCDIC; /* 1 */
#else
int cb_display_sign = COB_DISPLAY_SIGN_ASCII; /* 0 */
#endif
#undef COB_EXCEPTION
#define COB_EXCEPTION(code,tag,name,critical) {name, 0x##code, 0},
struct cb_exception cb_exception_table[] = {
{NULL, 0, 0}, /* CB_EC_ZERO */
#include <libcob/exception.def>
{NULL, 0, 0} /* CB_EC_MAX */
};
#undef COB_EXCEPTION
#undef CB_FLAG
#define CB_FLAG(var,name,doc) int var = 0;
#include "flag.def"
#undef CB_FLAG
#undef CB_WARNDEF
#define CB_WARNDEF(var,name,wall,doc) int var = 0;
#include "warning.def"
#undef CB_WARNDEF
int cb_id = 1;
int cb_attr_id = 1;
int cb_literal_id = 1;
int cb_field_id = 1;
int cb_storage_id = 1;
int cb_flag_main = 0;
int external_flg = 0;
int errorcount = 0;
int warningcount = 0;
int alt_ebcdic = 0;
int optimize_flag = 0;
char *cb_source_file = NULL;
char *cb_oc_build_stamp = NULL;
char *source_name;
char *demangle_name;
int cb_source_line = 0;
FILE *cb_storage_file;
char *cb_storage_file_name;
FILE *cb_listing_file = NULL;
FILE *cb_depend_file = NULL;
char *cb_depend_target = NULL;
struct cb_text_list *cb_depend_list = NULL;
struct cb_text_list *cb_include_list = NULL;
struct cb_text_list *cb_extension_list = NULL;
struct cb_constant_list *cb_const_list = NULL;
int cb_saveargc;
char **cb_saveargv;
const char *cob_config_dir;
#ifdef _MSC_VER
#if _MSC_VER >= 1400
static const char *manicmd;
static const char *manilink;
#endif
#endif
/*
* Local variables
*/
static const char *const cob_csyns[] = {
"NULL",
"L_initextern",
"LRET_initextern",
#ifndef __GNUC__
"P_switch",
#endif
"alignof",
"asm",
"auto",
"break",
"case",
"char",
"const",
"continue",
"default",
"do",
"double",
"else",
"enum",
"exit_program",
"extern",
"float",
"for",
"frame_pointer",
"frame_stack",
"goto",
"if",
"inline",
"int",
"long",
"offsetof",
"register",
"restrict",
"return",
"short",
"signed",
"sizeof",
"static",
"struct",
"switch",
"typedef",
"typeof",
"union",
"unsigned",
"void",
"volatile",
"_Bool",
"_Complex",
"_Imaginary"
};
#define COB_NUM_CSYNS sizeof(cob_csyns) / sizeof(char *)
static enum cb_compile_level cb_compile_level = 0;
static enum cb_compile_level local_level = 0;
static size_t iparams = 0;
static int iargs;
static char *cobcpy = NULL;
static char *save_temps_dir = NULL;
static jmp_buf cob_jmpbuf;
static int wants_nonfinal = 0;
static int cb_flag_module = 0;
static int cb_flag_library = 0;
static int save_temps = 0;
static int save_csrc = 0;
static int verbose_output = 0;
static int cob_iteration = 0;
#ifndef _WIN32
static pid_t cob_process_id = 0;
#endif
static int strip_output = 0;
static int gflag_set = 0;
static char *output_name;
static const char *cob_tmpdir; /* /tmp */
static struct filename *file_list;
/* NOTE fcopts MUST have at least one leading space */
#if defined (__GNUC__) && (__GNUC__ >= 3)
static const char fcopts[] = " -finline-functions -fno-gcse -freorder-blocks ";
#elif defined(__xlc__)
static const char fcopts[] = " -Q -qro -qroconst ";
#else
static const char fcopts[] = " ";
#endif
#if defined (__GNUC__) && (__GNUC__ >= 3)
static const char gccpipe[] = "-pipe";
#else
static const char gccpipe[] = "\0";
#endif
#ifdef HAVE_SIGNAL_H
typedef void (*cob_sighandler_t) (int);
static cob_sighandler_t hupsig = NULL;
static cob_sighandler_t intsig = NULL;
static cob_sighandler_t qutsig = NULL;
#endif
static const char short_options[] = "hVvECScbmxOgwo:t:I:L:l:D:";
static const struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
/* getopt_long_only has a problem with eg. -xv - remove
{"verbose", no_argument, NULL, 'v'},
*/
{"list-reserved", no_argument, NULL, 'R'},
{"list-intrinsics", no_argument, NULL, '6'},
{"list-mnemonics", no_argument, NULL, 'q'},
{"save-temps", optional_argument, NULL, '_'},
{"std", required_argument, NULL, '$'},
{"conf", required_argument, NULL, '&'},
{"debug", no_argument, NULL, 'd'},
{"ext", required_argument, NULL, 'e'},
{"free", no_argument, &cb_source_format, CB_FORMAT_FREE},
{"free_1col_aster", no_argument, &cb_source_format, CB_FORMAT_FREE_1COL_ASTER},
{"fixed", no_argument, &cb_source_format, CB_FORMAT_FIXED},
{"static", no_argument, &cb_flag_static_call, 1},
{"dynamic", no_argument, &cb_flag_static_call, 0},
{"O2", no_argument, NULL, '2'},
{"Os", no_argument, NULL, 's'},
{"Q", required_argument, NULL, 'Q'},
{"B", required_argument, NULL, 'B'},
{"MT", required_argument, NULL, '%'},
{"MF", required_argument, NULL, '@'},
{"assign_external", no_argument, NULL, 'A'},
{"reference_check", no_argument, NULL, 'K'},
{"constant", optional_argument, NULL, '3'},
#undef CB_FLAG
#define CB_FLAG(var,name,doc) \
{"f"name, no_argument, &var, 1}, \
{"fno-"name, no_argument, &var, 0},
#include "flag.def"
#undef CB_FLAG
{"Wall", no_argument, NULL, 'W'},
{"W", no_argument, NULL, 'Z'},
#undef CB_WARNDEF
#define CB_WARNDEF(var,name,wall,doc) \
{"W"name, no_argument, &var, 1}, \
{"Wno-"name, no_argument, &var, 0},
#include "warning.def"
#undef CB_WARNDEF
{NULL, 0, NULL, 0}
};
static const char *cob_cc; /* gcc */
static char cob_cflags[COB_SMALL_BUFF]; /* -I... */
static char cob_libs[COB_MEDIUM_BUFF]; /* -L... -lcob */
static char cob_define_flags[COB_SMALL_BUFF]; /* -D... */
static char cob_ldflags[COB_SMALL_BUFF];
static const char *cob_copy_dir;
/* cobc functions */
/*
* Global functions
*/
void
cobc_abort (const char *filename, const int linenum)
{
fprintf (stderr, "%s:%d: Internal compiler error\n", filename, linenum);
(void)longjmp (cob_jmpbuf, 1);
}
void
cobc_tree_cast_error (cb_tree x, const char *filen, const int linenum, const int tagnum)
{
fprintf (stderr, "%s:%d: Invalid type cast from '%s'\n",
filen, linenum, x ? cb_name (x) : "null");
fprintf (stderr, "Tag 1 %d Tag 2 %d\n", x ? CB_TREE_TAG(x) : 0,
tagnum);
(void)longjmp (cob_jmpbuf, 1);
}
void *
cobc_malloc (const size_t size)
{
void *mptr;
mptr = calloc (1, size);
if (!mptr) {
fprintf (stderr, "Cannot allocate %d bytes of memory - Aborting\n", (int)size);
fflush (stderr);
(void)longjmp (cob_jmpbuf, 1);
}
return mptr;
}
void *
cobc_realloc (void *prevptr, const size_t size)
{
void *mptr;
mptr = realloc (prevptr, size);
if (!mptr) {
fprintf (stderr, "Cannot reallocate %d bytes of memory - Aborting\n", (int)size);
fflush (stderr);
(void)longjmp (cob_jmpbuf, 1);
}
return mptr;
}
struct cb_text_list *
cb_text_list_add (struct cb_text_list *list, const char *text)
{
struct cb_text_list *p;
struct cb_text_list *l;
p = cobc_malloc (sizeof (struct cb_text_list));
p->text = strdup (text);
p->next = NULL;
if (!list) {
return p;
} else {
for (l = list; l->next; l = l->next) { ; }
l->next = p;
return list;
}
}
#ifdef _WIN32
#define strndup(x,y) _strndup(x,y)
char *
_strndup (char *src, int size)
{
char *dup;
int srclen;
if (src == NULL) {
return NULL;
}
srclen = strlen (src);
if (size > srclen) {
size = srclen;
}
dup = malloc (size + 1);
if (dup == NULL) {
return NULL;
}
memset (dup, 0, size + 1);
memcpy (dup, src, size);
return dup;
}
#endif
void
cb_constant_list_add (char *buff)
{
struct cb_constant_list *p;
struct cb_constant_list *l;
char *s1, *s2;
p = cobc_malloc (sizeof (struct cb_constant_list));
s1 = strchr (buff, '\"');
s2 = strchr (buff, '(');
if ((s1 && s2) || buff == s1 || buff == s2) {
/* ERROR */
fprintf (stderr, "Invalid format constant option : %s \n", buff);
free (p);
return;
} else if (s1) {
if (strlen (s1) < 3 ||
s1 == strrchr (buff, '\"') ||
strlen (strchr (s1+1, '\"')) > 1) {
/* ERROR */
fprintf (stderr, "Invalid format constant option1 : %s \n", buff);
free (p->name);
free (p->alphavalue);
free (p);
return;
}
p->name = strndup (buff, s1-buff);
s1 = s1 + 1;
strcpy (strrchr (s1, '\"'), "");
p->alphavalue = strdup (s1);
p->type = CB_CONSTANT_TYPE_ALPANUM;
p->numvalue = -1;
} else if (s2) {
cb_warning (_("'%s' not implemented"), "CONSTANT NUMLIC LITERAL");
free (p);
return;
} else {
p->name = strdup (buff);
p->type = CB_CONSTANT_TYPE_NONE;
p->alphavalue = NULL;
p->numvalue = -1;
}
p->next = NULL;
if (!cb_const_list) {
cb_const_list = p;
} else {
for (l = cb_const_list; l->next; l = l->next);
l->next = p;
}
}
size_t
cobc_check_valid_name (char *name)
{
size_t n;
for (n = 0; n < COB_NUM_CSYNS; ++n) {
if (!strcmp (name, cob_csyns[n])) {
return 1;
}
}
return 0;
}
#ifdef I18N_UTF8
const unsigned char *
utf8_ext_pick (const unsigned char *p)
{
const unsigned char *rp = (unsigned char *)0;
for (; *p; p++) {
if (*p & 0x80) {
rp = p;
break;
}
}
return rp;
}
#else /*!I18N_UTF8*/
const unsigned char *
sjis_pick (const unsigned char *p)
{
const unsigned char *rp = (unsigned char*)0;
char sjis1 = 0;
for (; *p; p++) {
if (sjis1) {
if ((*p >= 0x40 && *p <= 0x7f) || (*p >= 0x80 && *p <= 0xfc)) {
rp = --p;
break;
}
sjis1 = 0;
} else if ((*p >= 0x81 && *p <= 0x9f) || (*p >= 0xe0 && *p <= 0xfc)) {
sjis1 = 1;
}
}
return rp;
}
#endif /*I18N_UTF8*/
#ifdef I18N_UTF8
size_t
utf8_strlen (const unsigned char *p)
{
const unsigned char *ub = p + strlen ((const char *)p);
size_t siz = 0;
while (p < ub) {
p += ((*p >>7) == 0x00)? 1:
((*p >>5) == 0x06)? 2:
((*p >>4) == 0x0e)? 3:
((*p >>3) == 0x1e)? 4:
((*p >>2) == 0x3e)? 5:
((*p >>1) == 0x7e)? 6: 1;
siz++;
}
return siz;
}
#else /*!I18N_UTF8*/
size_t
sjis_strlen (const unsigned char *p)
{
size_t siz = 0;
char sjis1 = 0;
for (; *p; p++) {
if (sjis1) {
if ((*p >= 0x40 && *p <= 0x7f) || (*p >= 0x80 && *p <= 0xfc)) {
--siz;
}
sjis1 = 0;
} else if ((*p >= 0x81 && *p <= 0x9f) || (*p >= 0xe0 && *p <= 0xfc)) {
sjis1 = 1;
}
siz++;
}
return siz;
}
#endif /*I18N_UTF8*/
#ifdef I18N_UTF8
int
utf8_casecmp (const char *s1, const char *s2)
{
size_t n1 = strlen (s1);
int rt = n1 - strlen (s2);
if (!rt) {
if (utf8_ext_pick ((unsigned char *)s1) == 0 ||
utf8_ext_pick ((unsigned char *)s2) == 0) {
rt = strcasecmp (s1, s2);
} else {
rt = memcmp (s1, s2, n1);
}
}
return rt;
}
#else /*!I18N_UTF8*/
int
sjis_casecmp (const char *s1, const char *s2)
{
size_t n1 = strlen (s1);
int rt = n1 - strlen (s2);
if (!rt) {
if (sjis_pick ((unsigned char*)s1) == 0 ||
sjis_pick ((unsigned char*)s2) == 0) {
rt = strcasecmp (s1, s2);
} else {
rt = memcmp (s1, s2, n1);
}
}
return rt;
}
#endif /*I18N_UTF8*/
#ifdef I18N_UTF8
int
utf8_national_length (const unsigned char *str, int len)
{
const unsigned char *p, *ub = &(str[len]);
int mb_len = 0;
int n, siz = 0;
for (p = str; p < ub; p++) {
if (0 != (n = COB_U8BYTE_1(*p))) {
if (n > 6) {
siz = -1;
break;
} else if (mb_len) {
siz = -2; /* byte_N expected */
break;
} else {
mb_len = n - 1;
}
if (n == 1) {
siz += 3; /* to be converted to Zenkaku */
} else {
siz += n;
}
} else if (COB_U8BYTE_N(*p)) {
if (0 >= mb_len) {
siz = -3; /* byte_1 expected */
break;
} else {
--mb_len;
if (0 == mb_len && siz >= 3 && (*(p-2) == 0xEF && *(p-1) == 0xBE && (*p == 0x9E || *p == 0x9F))) {
/* Dakuten to be merged */
siz -= 3;
}
}
} else {
siz = -4; /* unexpected char */
break;
}
}
if (siz >= 0 && mb_len != 0) {
siz = -5; /* immature end of multibytes sequence */
}
return siz;
}
#endif /*I18N_UTF8*/
#ifdef I18N_UTF8
void
utf8_spc_to_ascii (char *str)
{
unsigned char *p = (unsigned char *)str;
while (*p) {
if (*p == 0xE3 && *(p+1) == 0x80 && *(p+2) == 0x80) {
*p++ = ' ';
*p++ = ' ';
*p++ = ' ';
} else {
p++;
}
}
}
#else /*!I18N_UTF8*/
void
sjis_spc_to_ascii (char *str)
{
unsigned char *p = (unsigned char *)str;
while (*p) {
if (*p == 0x81 && *(p+1) == 0x40) {
*p++ = ' ';
*p++ = ' ';
} else {
p++;
}
}
}
#endif /*I18N_UTF8*/
/*
* Local functions
*/
static void
cobc_init_var (char *var, const char *env, const char *def)
{
char *p = getenv (env);
if (p) {
strcpy (var, p);
} else {
strcpy (var, def);
}
}
static void
cobc_check_action (const char *name)
{
struct stat st;
char buff[COB_SMALL_BUFF];
if (name && !stat (name, &st)) {
if (!save_temps) {
unlink (name);
} else if (save_temps_dir) {
memset (buff, 0, sizeof(buff));
sprintf (buff, "%s/%s", save_temps_dir, name);
(void)rename (name, buff);
}
}
}
static void
cobc_clean_up (int status)
{
struct filename *fn;
struct local_filename *lf;
int i;
char buff[COB_SMALL_BUFF];
if (cb_listing_file) {
fclose (cb_listing_file);
cb_listing_file = NULL;
}
for (fn = file_list; fn; fn = fn->next) {
if (fn->need_preprocess
&& (status || cb_compile_level > CB_LEVEL_PREPROCESS)) {
cobc_check_action (fn->preprocess);
}
if (!save_csrc && fn->need_translate
&& (status || cb_compile_level > CB_LEVEL_TRANSLATE)) {
cobc_check_action (fn->translate);
cobc_check_action (fn->trstorage);
if (fn->localfile) {
for (lf = fn->localfile; lf; lf = lf->next) {
cobc_check_action (lf->local_name);
}
} else if (fn->translate) {
/* If we get syntax errors, we do not
know the number of local include files */
memset (buff, 0, sizeof(buff));
for (i = 0; i < 30; i++) {
if (i) {
sprintf (buff, "%s.l%d.h",
fn->translate, i);
} else {
sprintf (buff, "%s.l.h",
fn->translate);
}
unlink (buff);
}
}
}
if (fn->need_assemble
&& (status || cb_compile_level > CB_LEVEL_ASSEMBLE)) {
cobc_check_action (fn->object);
}
}
}
static void
cobc_terminate (const char *str)
{
fprintf (stderr, "cobc: ");
fflush (stderr);
perror (str);
cobc_clean_up (1);
exit (1);
}
#ifdef HAVE_SIGNAL_H
static void
cobc_sig_handler (int sig)
{
save_temps = 0;
cobc_clean_up (1);
switch (sig) {
#ifdef SIGHUP
case SIGHUP:
if ((hupsig != SIG_IGN) && (hupsig != SIG_DFL)) {
(*hupsig) (SIGHUP);
}
break;
#endif
case SIGINT:
if ((intsig != SIG_IGN) && (intsig != SIG_DFL)) {
(*intsig) (SIGINT);
}
break;
#ifdef SIGQUIT
case SIGQUIT:
if ((qutsig != SIG_IGN) && (qutsig != SIG_DFL)) {
(*qutsig) (SIGQUIT);
}
break;
#endif
}
exit (sig);
}
#endif
/*
* Command line
*/
static void
cobc_print_version (void)
{
puts ("opensource COBOL 1.5.2J");
puts ("OSS Consortium's patched version of OpenCOBOL1.1(Feb.06 2009)");
#ifdef I18N_UTF8
puts ("[unicode/utf-8 support]");
#endif /*I18N_UTF8*/
puts ("----");
printf ("cobc (%s) %s.%d\n",
PACKAGE_NAME, PACKAGE_VERSION, PATCH_LEVEL);
puts ("Copyright (C) 2001-2009 Keisuke Nishida / Roger While");
printf ("Built %s\nPackaged %s\n", cb_oc_build_stamp, octardate);
}
static void
cobc_print_usage (void)
{
puts (_("Usage: cobc [options] file..."));
puts (_("Options:"));
puts (_(" --help Display this message"));
puts (_(" --version, -V Display compiler version"));
puts (_(" -v Display the commands invoked by the compiler"));
puts (_(" -x Build an executable program"));
puts (_(" -m Build a dynamically loadable module (default)"));
puts (_(" -std=<dialect> Warnings/features for a specific dialect :"));
puts (_(" cobol2002 Cobol 2002"));
puts (_(" cobol85 Cobol 85"));
puts (_(" ibm IBM Compatible"));
puts (_(" mvs MVS Compatible"));
puts (_(" bs2000 BS2000 Compatible"));
puts (_(" mf Micro Focus Compatible"));
puts (_(" default When not specified"));
puts (_(" See config/default.conf and config/*.conf"));
puts (_(" -free Use free source format"));
puts (_(" -free_1col_aster Use free(1col_aster) source format"));
puts (_(" -fixed Use fixed source format (default)"));
puts (_(" -O, -O2, -Os Enable optimization"));
puts (_(" -g Enable C compiler debug / stack check / trace"));
puts (_(" -debug Enable all run-time error checking"));
puts (_(" -o <file> Place the output into <file>"));
puts (_(" -b Combine all input files into a single"));
puts (_(" dynamically loadable module"));
puts (_(" -E Preprocess only; do not compile or link"));
puts (_(" -C Translation only; convert COBOL to C"));
puts (_(" -S Compile only; output assembly file"));
puts (_(" -c Compile and assemble, but do not link"));
puts (_(" -t <file> Generate and place a program listing into <file>"));
puts (_(" -I <directory> Add <directory> to copy/include search path"));
puts (_(" -L <directory> Add <directory> to library search path"));
puts (_(" -l <lib> Link the library <lib>"));
puts (_(" -B <options> Add <options> to the C compile phase"));
puts (_(" -Q <options> Add <options> to the C link phase"));
puts (_(" -D <define> Pass <define> to the C compiler"));
puts (_(" -conf=<file> User defined dialect configuration - See -std="));
puts (_(" --list-reserved Display reserved words"));
puts (_(" --list-intrinsics Display intrinsic functions"));
puts (_(" --list-mnemonics Display mnemonic names"));
puts (_(" -save-temps(=<dir>) Save intermediate files (default current directory)"));
puts (_(" -MT <target> Set target file used in dependency list"));
puts (_(" -MF <file> Place dependency list into <file>"));
puts (_(" -ext <extension> Add default file extension"));
puts (_(" -assign_external Set the file assign to external"));
puts (_(" -reference_check Set reference check in runtime"));
puts (_(" -constant(=<name\"value\">) define <name> to <value> for $IF statement"));
putchar ('\n');
puts (_(" -W Enable ALL warnings"));
puts (_(" -Wall Enable all warnings except as noted below"));
#undef CB_WARNDEF
#define CB_WARNDEF(var,name,wall,doc) \
printf (" -W%-19s %s", name, gettext (doc)); \
if (!wall) { \
puts (_(" (NOT set with -Wall)")); \
} else { \
printf ("\n"); \
}
#include "warning.def"
#undef CB_WARNDEF
putchar ('\n');
#undef CB_FLAG
#define CB_FLAG(var,name,doc) \
if (strcmp (name, "static-call")) \
printf (" -f%-19s %s\n", name, gettext (doc));
#include "flag.def"
#undef CB_FLAG
putchar ('\n');
}
static void
cobc_options_error (void)
{
fprintf (stderr, "Only one of options 'E', 'S', 'C' 'c' may be specified\n");
exit (1);
}
static int
process_command_line (const int argc, char *argv[])
{
int c, idx;
int argnum;
enum cob_exception_id i;
struct stat st;
char ext[COB_MINI_BUFF];
/* Enable default I/O exceptions */
CB_EXCEPTION_ENABLE (COB_EC_I_O) = 1;
/* Translate command line arguments from WIN to UNIX style */
argnum = 1;
while (++argnum <= argc) {
if (strrchr(argv[argnum - 1], '/') == argv[argnum - 1]) {
argv[argnum - 1][0] = '-';
}
}
while ((c = getopt_long_only (argc, argv, short_options, long_options, &idx)) >= 0) {
switch (c) {
case 0:
break;
case '?':
/* Unknown option or ambiguous */
exit (1);
case 'h':
/* --help */
cobc_print_usage ();
exit (0);
case 'V':
/* --version */
cobc_print_version ();
exit (0);
case 'R':
/* --list-reserved */
cb_list_reserved ();
exit (0);
case '6':
/* --list-intrinsics */
cb_list_intrinsics ();
exit (0);
case 'q':
/* --list-mnemonics */
cb_list_mnemonics ();
exit (0);
case 'K':
CB_EXCEPTION_ENABLE (COB_EC_BOUND_REF_MOD) = 1;
break;
case 'E':
/* -E : Preprocess */
if (wants_nonfinal) {
cobc_options_error ();
}
wants_nonfinal = 1;
cb_compile_level = CB_LEVEL_PREPROCESS;
break;
case 'C':
/* -C : Generate C code */
if (wants_nonfinal) {
cobc_options_error ();
}
wants_nonfinal = 1;
cb_compile_level = CB_LEVEL_TRANSLATE;
break;
case 'S':
/* -S : Generate assembler code */
if (wants_nonfinal) {
cobc_options_error ();
}
wants_nonfinal = 1;
cb_compile_level = CB_LEVEL_COMPILE;
break;
case 'c':