GnuCOBOL  2.0
A free COBOL compiler
cobc.c
Go to the documentation of this file.
1 /*
2  Copyright (C) 2001-2016 Free Software Foundation, Inc.
3 
4  Authors:
5  Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Brian Tiffin
6 
7  This file is part of GnuCOBOL.
8 
9  The GnuCOBOL compiler is free software: you can redistribute it
10  and/or modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation, either version 3 of the
12  License, or (at your option) any later version.
13 
14  GnuCOBOL is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with GnuCOBOL. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "config.h"
24 #include "defaults.h"
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stddef.h>
29 #include <stdarg.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include <errno.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <time.h>
36 #ifdef HAVE_UNISTD_H
37 #include <unistd.h>
38 #endif
39 #ifdef HAVE_SIGNAL_H
40 #include <signal.h>
41 #endif
42 
43 #ifdef _WIN32
44 #define WIN32_LEAN_AND_MEAN
45 #include <windows.h>
46 #include <io.h>
47 #include <fcntl.h>
48 #endif
49 
50 #ifdef HAVE_LOCALE_H
51 #include <locale.h>
52 #endif
53 
54 #include "tarstamp.h"
55 
56 #include "cobc.h"
57 #include "tree.h"
58 
59 #include "lib/gettext.h"
60 
61 #include "libcob.h"
62 
63 #include "libcob/cobgetopt.h"
64 
65 struct strcache {
66  struct strcache *next;
67  void *val;
68 };
69 
70 /* Compile level */
71 #define CB_LEVEL_PREPROCESS 1
72 #define CB_LEVEL_TRANSLATE 2
73 #define CB_LEVEL_COMPILE 3
74 #define CB_LEVEL_ASSEMBLE 4
75 #define CB_LEVEL_MODULE 5
76 #define CB_LEVEL_LIBRARY 6
77 #define CB_LEVEL_EXECUTABLE 7
78 
79 /* Info display limits */
80 #define CB_IMSG_SIZE 24
81 #define CB_IVAL_SIZE (74 - CB_IMSG_SIZE - 4)
82 
83 #define COBC_ADD_STR(v,x,y,z) cobc_add_str (&v, &v##_size, x, y, z);
84 #define COBC_INV_PAR _("Invalid %s parameter")
85 
86 /* C version info */
87 #ifdef __VERSION__
88 #define OC_C_VERSION_PRF ""
89 #define OC_C_VERSION CB_XSTRINGIFY(__VERSION__)
90 #elif defined(__xlc__)
91 #define OC_C_VERSION_PRF "(IBM) "
92 #define OC_C_VERSION CB_XSTRINGIFY(__xlc__)
93 #elif defined(_MSC_VER)
94 #define OC_C_VERSION_PRF "(Microsoft) "
95 #define OC_C_VERSION CB_XSTRINGIFY(_MSC_VER)
96 #elif defined(__BORLANDC__)
97 #define OC_C_VERSION_PRF "(Borland) "
98 #define OC_C_VERSION CB_XSTRINGIFY(__BORLANDC__)
99 #elif defined(__WATCOMC__)
100 #define OC_C_VERSION_PRF "(Watcom) "
101 #define OC_C_VERSION CB_XSTRINGIFY(__WATCOMC__)
102 #elif defined(__INTEL_COMPILER)
103 #define OC_C_VERSION_PRF "(Intel) "
104 #define OC_C_VERSION CB_XSTRINGIFY(__INTEL_COMPILER)
105 #else
106 #define OC_C_VERSION_PRF ""
107 #define OC_C_VERSION "unknown"
108 #endif
109 
110 #define CB_TEXT_LIST_ADD(y,z) y = cb_text_list_add (y, z)
111 #define CB_TEXT_LIST_CHK(y,z) y = cb_text_list_chk (y, z)
112 
113 #ifdef _MSC_VER
114 #define CB_COPT_1 " /O1"
115 #define CB_COPT_2 " /O2"
116 #define CB_COPT_S " /Os"
117 #elif defined(__BORLANDC__)
118 #define CB_COPT_1 " -O"
119 #define CB_COPT_2 " -O2"
120 #define CB_COPT_S " -O1"
121 #elif defined(__hpux) && !defined(__GNUC__)
122 #define CB_COPT_1 " -O"
123 #define CB_COPT_2 " +O2"
124 #define CB_COPT_S " +O2 +Osize"
125 #elif defined(__WATCOMC__)
126 #define CB_COPT_1 " -ot"
127 #define CB_COPT_2 " -ox"
128 #define CB_COPT_S " -os"
129 #elif defined(__SUNPRO_C)
130 #define CB_COPT_1 " -xO1"
131 #define CB_COPT_2 " -xO2"
132 #define CB_COPT_S " -xO1 -xspace"
133 #elif defined(__xlc__)
134 #define CB_COPT_1 " -O"
135 #define CB_COPT_2 " -O2"
136 #define CB_COPT_S " -O"
137 #else
138 #define CB_COPT_1 " -O"
139 #define CB_COPT_2 " -O2"
140 #define CB_COPT_S " -Os"
141 #endif
142 
143 /* Global variables */
144 
145 const char *cb_source_file = NULL;
147 const char *demangle_name = NULL;
154 char **cb_saveargv = NULL;
155 const char *cob_config_dir = NULL;
158 #if 0 /* RXWRXW - source format */
159 char *source_name = NULL;
160 #endif
161 
162 int cb_source_format = CB_FORMAT_FIXED; /* Default format */
163 int cb_id = 0;
164 int cb_attr_id = 0;
166 int cb_field_id = 0;
168 int cb_flag_main = 0;
172 
173 int errorcount = 0;
174 int warningcount = 0;
175 int exit_option = 0;
176 int warningopt = 0;
179 int cb_saveargc = 0;
180 unsigned int cobc_gen_listing = 0;
181 
183 
184 #undef COB_EXCEPTION
185 #define COB_EXCEPTION(code,tag,name,critical) {name, 0x##code, 0},
187  {NULL, 0, 0}, /* CB_EC_ZERO */
188 #include "libcob/exception.def"
189  {NULL, 0, 0} /* CB_EC_MAX */
190 };
191 #undef COB_EXCEPTION
192 
193 #undef CB_FLAG
194 #undef CB_FLAG_RQ
195 #undef CB_FLAG_NQ
196 #define CB_FLAG(var,pdok,name,doc) int var = 0;
197 #define CB_FLAG_RQ(var,pdok,name,def,opt,doc) int var = def;
198 #define CB_FLAG_NQ(pdok,name,opt,doc)
199 #include "flag.def"
200 #undef CB_FLAG
201 #undef CB_FLAG_RQ
202 #undef CB_FLAG_NQ
203 
204 #undef CB_WARNDEF
205 #undef CB_NOWARNDEF
206 #define CB_WARNDEF(var,name,doc) int var = 0;
207 #define CB_NOWARNDEF(var,name,doc) int var = 0;
208 #include "warning.def"
209 #undef CB_WARNDEF
210 #undef CB_NOWARNDEF
211 
212 /* Local variables */
213 
214 #if defined(HAVE_SIGNAL_H) && defined(HAVE_SIG_ATOMIC_T)
215 static volatile sig_atomic_t sig_is_handled = 0;
216 #endif
217 
219 
223 
224 static const char *cobc_cc; /* C compiler */
225 static char *cobc_cflags; /* C compiler flags */
226 static char *cobc_libs; /* -l... */
227 static char *cobc_lib_paths; /* -L... */
228 static char *cobc_include; /* -I... */
229 static char *cobc_ldflags; /* -Q / COB_LDFLAGS */
230 
231 static size_t cobc_cflags_size;
232 static size_t cobc_libs_size;
233 static size_t cobc_lib_paths_size;
234 static size_t cobc_include_size;
235 static size_t cobc_ldflags_size;
236 
237 static size_t cobc_cc_len;
238 static size_t cobc_cflags_len;
239 static size_t cobc_libs_len;
240 static size_t cobc_lib_paths_len;
241 static size_t cobc_include_len;
242 static size_t cobc_ldflags_len;
243 static size_t cobc_export_dyn_len;
244 static size_t cobc_shared_opt_len;
245 static size_t cobc_pic_flags_len;
246 
247 static char *save_temps_dir;
248 static struct strcache *base_string;
249 
250 static char *cobc_list_dir;
251 static char *cobc_list_file;
252 
253 static char *output_name;
254 static char *cobc_buffer;
255 static char *cobc_objects_buffer;
256 static char *output_name_buff;
257 static char *basename_buffer;
258 
259 static size_t cobc_objects_len;
260 static size_t basename_len;
261 static size_t cobc_buffer_size;
262 
263 static struct filename *file_list;
264 
265 static unsigned int cb_compile_level = 0;
266 
267 static int iargs;
268 
269 static size_t wants_nonfinal = 0;
270 static size_t cobc_flag_module = 0;
271 static size_t cobc_flag_library = 0;
272 static size_t cobc_flag_run = 0;
273 static size_t save_temps = 0;
274 static size_t save_all_src = 0;
275 static size_t save_c_src = 0;
276 static size_t verbose_output = 0;
277 static size_t cob_optimize = 0;
278 
279 #ifdef _MSC_VER
280 #if defined(_MSC_VER) && COB_USE_VC2005_OR_GREATER
281 static const char *manicmd;
282 #endif
283 static const char *manilink;
284 static size_t manilink_len;
285 #define PATTERN_DELIM '|'
286 #endif
287 
288 static size_t strip_output = 0;
289 static size_t gflag_set = 0;
290 static size_t aflag_set = 0;
291 
292 static const char *const cob_csyns[] = {
293 #ifndef COB_EBCDIC_MACHINE
294  "NULL",
295  "P_cancel",
296  "P_initialize",
297  "P_ret_initialize",
298  "P_switch",
299 #endif
300 #ifdef COB_EBCDIC_MACHINE
301  "_float128",
302 #endif
303  "_Bool",
304  "_Complex",
305  "_Imaginary",
306 #ifndef COB_EBCDIC_MACHINE
307  "_float128",
308 #endif
309  "alignof",
310  "asm",
311  "auto",
312  "bool",
313  "break",
314  "case",
315  "catch",
316  "char",
317  "class",
318  "const",
319  "const_cast",
320  "continue",
321  "default",
322  "delete",
323  "do",
324  "double",
325  "dynamic_cast",
326  "else",
327  "enum",
328  "exit_program",
329  "explicit",
330  "extern",
331  "false",
332  "float",
333  "for",
334  "frame_pointer",
335  "frame_stack",
336  "friend",
337  "goto",
338  "if",
339  "inline",
340  "int",
341  "long",
342  "mutable",
343  "namespace",
344  "new",
345  "offsetof",
346  "operator",
347  "private",
348  "protected",
349  "public",
350  "register",
351  "reinterpret_cast",
352  "restrict",
353  "return",
354  "short",
355  "signed",
356  "sizeof",
357  "static",
358  "static_cast",
359  "struct",
360  "switch",
361  "template",
362  "this",
363  "throw",
364  "true",
365  "try",
366  "typedef",
367  "typeid",
368  "typename",
369  "typeof",
370  "union",
371  "unsigned",
372  "using",
373  "virtual",
374  "void",
375  "volatile",
376 #ifndef COB_EBCDIC_MACHINE
377  "wchar_t"
378 #else
379  "wchar_t",
380  "NULL",
381  "P_cancel",
382  "P_initialize",
383  "P_ret_initialize",
384  "P_switch"
385 #endif
386 };
387 
388 #define COB_NUM_CSYNS sizeof(cob_csyns) / sizeof(char *)
389 
390 static const char short_options[] = "hVivECScbmxjdFOPgwo:I:L:l:D:K:k:";
391 
392 #define CB_NO_ARG no_argument
393 #define CB_RQ_ARG required_argument
394 #define CB_OP_ARG optional_argument
395 
396 static const struct option long_options[] = {
397  {"help", CB_NO_ARG, NULL, 'h'},
398  {"version", CB_NO_ARG, NULL, 'V'},
399  {"verbose", CB_NO_ARG, NULL, 'v'},
400  {"info", CB_NO_ARG, NULL, 'i'},
401  {"list-reserved", CB_NO_ARG, NULL, '5'},
402  {"list-intrinsics", CB_NO_ARG, NULL, '6'},
403  {"list-mnemonics", CB_NO_ARG, NULL, '7'},
404  {"list-system", CB_NO_ARG, NULL, '8'},
405  {"O2", CB_NO_ARG, NULL, '9'},
406  {"Os", CB_NO_ARG, NULL, 's'},
407  {"save-temps", CB_OP_ARG, NULL, '_'},
408  {"std", CB_RQ_ARG, NULL, '$'},
409  {"conf", CB_RQ_ARG, NULL, '&'},
410  {"cb_conf", CB_RQ_ARG, NULL, '%'},
411  {"debug", CB_NO_ARG, NULL, 'd'},
412  {"ext", CB_RQ_ARG, NULL, 'e'},
415  {"static", CB_NO_ARG, &cb_flag_static_call, 1},
416  {"dynamic", CB_NO_ARG, &cb_flag_static_call, 0},
417  {"Q", CB_RQ_ARG, NULL, 'Q'},
418  {"A", CB_RQ_ARG, NULL, 'A'},
419  {"P", CB_OP_ARG, NULL, 'P'},
420  {"Xref", CB_NO_ARG, NULL, 'X'},
421  {"Wall", CB_NO_ARG, NULL, 'W'},
422  {"W", CB_NO_ARG, NULL, 'Z'},
423 
424 #undef CB_FLAG
425 #undef CB_FLAG_RQ
426 #undef CB_FLAG_NQ
427 #define CB_FLAG(var,pdok,name,doc) \
428  {"f"name, CB_NO_ARG, &var, 1}, \
429  {"fno-"name, CB_NO_ARG, &var, 0},
430 #define CB_FLAG_RQ(var,pdok,name,def,opt,doc) \
431  {"f"name, CB_RQ_ARG, NULL, opt},
432 #define CB_FLAG_NQ(pdok,name,opt,doc) \
433  {"f"name, CB_RQ_ARG, NULL, opt},
434 #include "flag.def"
435 #undef CB_FLAG
436 #undef CB_FLAG_RQ
437 #undef CB_FLAG_NQ
438 
439 #undef CB_WARNDEF
440 #undef CB_NOWARNDEF
441 #define CB_WARNDEF(var,name,doc) \
442  {"W"name, CB_NO_ARG, &var, 1}, \
443  {"Wno-"name, CB_NO_ARG, &var, 0},
444 #define CB_NOWARNDEF(var,name,doc) \
445  {"W"name, CB_NO_ARG, &var, 1}, \
446  {"Wno-"name, CB_NO_ARG, &var, 0},
447 #include "warning.def"
448 #undef CB_WARNDEF
449 #undef CB_NOWARNDEF
450 
451  {NULL, 0, NULL, 0}
452 };
453 
454 #undef CB_ARG_NO
455 #undef CB_ARG_RQ
456 #undef CB_ARG_NQ
457 #undef CB_ARG_OP
458 
459 /* Prototype */
461 
462 /* cobc functions */
463 
464 static void
466 {
467  struct cobc_mem_struct *reps;
468  struct cobc_mem_struct *repsl;
469 
470  if (save_temps_dir) {
473  }
474  if (cobc_list_dir) {
477  }
478  if (cobc_list_file) {
481  }
482  for (reps = cobc_plexmem_base; reps; ) {
483  repsl = reps;
484  reps = reps->next;
485  cobc_free (repsl);
486  }
487  cobc_plexmem_base = NULL;
488  for (reps = cobc_parsemem_base; reps; ) {
489  repsl = reps;
490  reps = reps->next;
491  cobc_free (repsl);
492  }
493  cobc_parsemem_base = NULL;
494  for (reps = cobc_mainmem_base; reps; ) {
495  repsl = reps;
496  reps = reps->next;
497  cobc_free (repsl);
498  }
499  cobc_mainmem_base = NULL;
500 }
501 
502 static const char *
503 cobc_enum_explain (const enum cb_tag tag)
504 {
505  switch (tag) {
506  case CB_TAG_CONST:
507  return "CONSTANT";
508  case CB_TAG_INTEGER:
509  return "INTEGER";
510  case CB_TAG_STRING:
511  return "STRING";
513  return "ALPHABET";
514  case CB_TAG_CLASS_NAME:
515  return "CLASS";
516  case CB_TAG_LOCALE_NAME:
517  return "LOCALE";
518  case CB_TAG_SYSTEM_NAME:
519  return "SYSTEM";
520  case CB_TAG_LITERAL:
521  return "LITERAL";
522  case CB_TAG_DECIMAL:
523  return "DECIMAL";
524  case CB_TAG_FIELD:
525  return "FIELD";
526  case CB_TAG_FILE:
527  return "FILE";
528  case CB_TAG_REPORT:
529  return "REPORT";
530  case CB_TAG_REFERENCE:
531  return "REFERENCE";
532  case CB_TAG_BINARY_OP:
533  return "BINARY OP";
534  case CB_TAG_FUNCALL:
535  return "FUNCTION CALL";
536  case CB_TAG_CAST:
537  return "CAST";
538  case CB_TAG_INTRINSIC:
539  return "INTRINSIC";
540  case CB_TAG_LABEL:
541  return "LABEL";
542  case CB_TAG_ASSIGN:
543  return "ASSIGN";
544  case CB_TAG_INITIALIZE:
545  return "INITIALIZE";
546  case CB_TAG_SEARCH:
547  return "SEARCH";
548  case CB_TAG_CALL:
549  return "CALL";
550  case CB_TAG_GOTO:
551  return "GO TO";
552  case CB_TAG_IF:
553  return "IF";
554  case CB_TAG_PERFORM:
555  return "PERFORM";
556  case CB_TAG_STATEMENT:
557  return "STATEMENT";
558  case CB_TAG_CONTINUE:
559  return "CONTINUE";
560  case CB_TAG_CANCEL:
561  return "CANCEL";
562  case CB_TAG_ALTER:
563  return "ALTER";
564  case CB_TAG_SET_ATTR:
565  return "SET ATTRIBUTE";
567  return "PERFORM";
568  case CB_TAG_PICTURE:
569  return "PICTURE";
570  case CB_TAG_LIST:
571  return "LIST";
572  case CB_TAG_DIRECT:
573  return "DIRECT";
574  case CB_TAG_DEBUG:
575  return "DEBUG";
576  case CB_TAG_DEBUG_CALL:
577  return "DEBUG CALL";
578  default:
579  break;
580  }
581  return "UNKNOWN";
582 }
583 
584 /* Global functions */
585 
586 void
587 cobc_abort_pr (const char *fmt, ...)
588 {
589  va_list ap;
590 
591  va_start (ap, fmt);
592  vfprintf (stderr, fmt, ap);
593  va_end (ap);
594  putc ('\n', stderr);
595  fflush (stderr);
596 }
597 
598 void
600 {
601  cobc_abort_pr (_("Too many errors - Aborting compilation"));
603 }
604 
605 void
606 cobc_abort (const char *filename, const int linenum)
607 {
608  cobc_abort_pr (_("%s:%d Internal compiler error"), filename, linenum);
610 }
611 
612 void
613 cobc_dumb_abort (const char *filename, const int linenum)
614 {
615  cobc_abort (filename, linenum);
616 }
617 
618 void
619 cobc_tree_cast_error (const cb_tree x, const char *filename, const int linenum,
620  const enum cb_tag tagnum)
621 {
622  cobc_abort_pr (_("%s:%d Invalid cast from '%s' type %s to type %s"),
623  filename, linenum,
624  x ? cb_name (x) : "NULL",
625  x ? cobc_enum_explain (CB_TREE_TAG(x)) : "None",
626  cobc_enum_explain (tagnum));
628 }
629 
630 #if !defined(__GNUC__) && defined(COB_TREE_DEBUG)
631 cb_tree
632 cobc_tree_cast_check (const cb_tree x, const char *file,
633  const int line, const enum cb_tag tag)
634 {
635  if (!x || x == cb_error_node || CB_TREE_TAG (x) != tag) {
636  cobc_tree_cast_error (x, file, line, tag);
637  }
638  return x;
639 }
640 #endif
641 
642 void *
643 cobc_malloc (const size_t size)
644 {
645  void *mptr;
646 
647  mptr = calloc ((size_t)1, size);
648  if (unlikely(!mptr)) {
649  cobc_abort_pr (_("Cannot allocate %d bytes of memory - Aborting"),
650  (int)size);
652  }
653  return mptr;
654 }
655 
656 void
657 cobc_free(void * mptr)
658 {
659 #ifdef COB_TREE_DEBUG
660  if (unlikely(!mptr)) {
661  cobc_abort_pr (_("Call to %s with NULL pointer"), "cobc_free");
663  }
664 #endif
665  free(mptr);
666 }
667 
668 void *
669 cobc_strdup (const char *dupstr)
670 {
671  void *p;
672  size_t n;
673 
674 #ifdef COB_TREE_DEBUG
675  if (unlikely(!dupstr)) {
676  cobc_abort_pr (_("Call to %s with NULL pointer"), "cobc_strdup");
678  }
679 #endif
680  n = strlen (dupstr);
681  p = cobc_malloc (n + 1);
682  memcpy (p, dupstr, n);
683  return p;
684 }
685 
686 void *
687 cobc_realloc (void *prevptr, const size_t size)
688 {
689  void *mptr;
690 
691  mptr = realloc (prevptr, size);
692  if (unlikely(!mptr)) {
693  cobc_abort_pr (_("Cannot reallocate %d bytes of memory - Aborting"),
694  (int)size);
696  }
697  return mptr;
698 }
699 
700 /* Memory allocate/strdup/reallocate/free for complete execution */
701 void *
702 cobc_main_malloc (const size_t size)
703 {
704  struct cobc_mem_struct *m;
705 
706  m = calloc ((size_t)1, sizeof(struct cobc_mem_struct) + size);
707  if (unlikely(!m)) {
708  cobc_abort_pr (_("Cannot allocate %d bytes of memory - Aborting"),
709  (int)size);
711  }
712  m->next = cobc_mainmem_base;
713  m->memptr = (char *)m + sizeof(struct cobc_mem_struct);
714  m->memlen = size;
715  cobc_mainmem_base = m;
716  return m->memptr;
717 }
718 
719 void *
720 cobc_main_strdup (const char *dupstr)
721 {
722  void *p;
723  size_t n;
724 
725 #ifdef COB_TREE_DEBUG
726  if (unlikely(!dupstr)) {
727  cobc_abort_pr (_("Call to %s with NULL pointer"), "cobc_main_strdup");
729  }
730 #endif
731  n = strlen (dupstr);
732  p = cobc_main_malloc (n + 1);
733  memcpy (p, dupstr, n);
734  return p;
735 }
736 
737 void *
738 cobc_main_realloc (void *prevptr, const size_t size)
739 {
740  struct cobc_mem_struct *m;
741  struct cobc_mem_struct *curr;
742  struct cobc_mem_struct *prev;
743 
744  m = calloc ((size_t)1, sizeof(struct cobc_mem_struct) + size);
745  if (unlikely(!m)) {
746  cobc_abort_pr (_("Cannot allocate %d bytes of memory - Aborting"),
747  (int)size);
749  }
750  m->memptr = (char *)m + sizeof(struct cobc_mem_struct);
751  m->memlen = size;
752 
753  prev = NULL;
754  for (curr = cobc_mainmem_base; curr; curr = curr->next) {
755  if (curr->memptr == prevptr) {
756  break;
757  }
758  prev = curr;
759  }
760  if (unlikely(!curr)) {
761  cobc_abort_pr (_("Attempt to reallocate non-allocated memory - Aborting"));
763  }
764  m->next = curr->next;
765  if (prev) {
766  prev->next = m;
767  } else {
768  /* At mainmem_base */
769  cobc_mainmem_base = m;
770  }
771  memcpy (m->memptr, curr->memptr, curr->memlen);
772  cobc_free (curr);
773 
774  return m->memptr;
775 }
776 
777 void
778 cobc_main_free (void *prevptr)
779 {
780  struct cobc_mem_struct *curr;
781  struct cobc_mem_struct *prev;
782 
783  prev = NULL;
784  for (curr = cobc_mainmem_base; curr; curr = curr->next) {
785  if (curr->memptr == prevptr) {
786  break;
787  }
788  prev = curr;
789  }
790  if (unlikely(!curr)) {
791 #ifdef COB_TREE_DEBUG
792  cobc_abort_pr (_("Call to %s with invalid pointer, as it is missing in list"), "cobc_main_free");
794 #else
795  return;
796 #endif
797  }
798  if (prev) {
799  prev->next = curr->next;
800  } else {
801  /* At mainmem_base */
802  cobc_mainmem_base = curr->next;
803  }
804  cobc_free (curr);
805 }
806 
807 /* Memory allocate/strdup/reallocate/free for parser */
808 void *
809 cobc_parse_malloc (const size_t size)
810 {
811  struct cobc_mem_struct *m;
812 
813  m = calloc ((size_t)1, sizeof(struct cobc_mem_struct) + size);
814  if (unlikely(!m)) {
815  cobc_abort_pr (_("Cannot allocate %d bytes of memory - Aborting"),
816  (int)size);
818  }
820  m->memptr = (char *)m + sizeof(struct cobc_mem_struct);
821  m->memlen = size;
822  cobc_parsemem_base = m;
823  return m->memptr;
824 }
825 
826 void *
827 cobc_parse_strdup (const char *dupstr)
828 {
829  void *p;
830  size_t n;
831 
832 #ifdef COB_TREE_DEBUG
833  if (unlikely(!dupstr)) {
834  cobc_abort_pr (_("Call to %s with NULL pointer"), "cobc_parse_strdup");
836  }
837 #endif
838  n = strlen (dupstr);
839  p = cobc_parse_malloc (n + 1);
840  memcpy (p, dupstr, n);
841  return p;
842 }
843 
844 void *
845 cobc_parse_realloc (void *prevptr, const size_t size)
846 {
847  struct cobc_mem_struct *m;
848  struct cobc_mem_struct *curr;
849  struct cobc_mem_struct *prev;
850 
851  m = calloc ((size_t)1, sizeof(struct cobc_mem_struct) + size);
852  if (unlikely(!m)) {
853  cobc_abort_pr (_("Cannot allocate %d bytes of memory - Aborting"),
854  (int)size);
856  }
857  m->memptr = (char *)m + sizeof(struct cobc_mem_struct);
858  m->memlen = size;
859 
860  prev = NULL;
861  for (curr = cobc_parsemem_base; curr; curr = curr->next) {
862  if (curr->memptr == prevptr) {
863  break;
864  }
865  prev = curr;
866  }
867  if (unlikely(!curr)) {
868  cobc_abort_pr (_("Attempt to reallocate non-allocated memory - Aborting"));
870  }
871  m->next = curr->next;
872  if (prev) {
873  prev->next = m;
874  } else {
875  /* At parsemem_base */
876  cobc_parsemem_base = m;
877  }
878  memcpy (m->memptr, curr->memptr, curr->memlen);
879  cobc_free (curr);
880 
881  return m->memptr;
882 }
883 
884 void
885 cobc_parse_free (void *prevptr)
886 {
887  struct cobc_mem_struct *curr;
888  struct cobc_mem_struct *prev;
889 
890  prev = NULL;
891  for (curr = cobc_parsemem_base; curr; curr = curr->next) {
892  if (curr->memptr == prevptr) {
893  break;
894  }
895  prev = curr;
896  }
897  if (unlikely(!curr)) {
898 #ifdef COB_TREE_DEBUG
899  cobc_abort_pr (_("Call to %s with invalid pointer, as it is missing in list"), "cobc_parse_free");
901 #else
902  return;
903 #endif
904  }
905  if (prev) {
906  prev->next = curr->next;
907  } else {
908  /* At parsemem_base */
909  cobc_parsemem_base = curr->next;
910  }
911  cobc_free (curr);
912 }
913 
914 /* Memory allocate/strdup/reallocate/free for preprocessor */
915 void *
916 cobc_plex_malloc (const size_t size)
917 {
918  struct cobc_mem_struct *m;
919 
920  m = calloc ((size_t)1, sizeof(struct cobc_mem_struct) + size);
921  if (unlikely(!m)) {
922  cobc_abort_pr (_("Cannot allocate %d bytes of memory - Aborting"),
923  (int)size);
925  }
926  m->memptr = (char *)m + sizeof(struct cobc_mem_struct);
927  m->next = cobc_plexmem_base;
928  cobc_plexmem_base = m;
929  return m->memptr;
930 }
931 
932 void *
933 cobc_plex_strdup (const char *dupstr)
934 {
935  void *p;
936  size_t n;
937 
938 #ifdef COB_TREE_DEBUG
939  if (unlikely(!dupstr)) {
940  cobc_abort_pr (_("Call to %s with NULL pointer"), "cobc_plex_strdup");
942  }
943 #endif
944  n = strlen (dupstr);
945  p = cobc_plex_malloc (n + 1);
946  memcpy (p, dupstr, n);
947  return p;
948 }
949 
950 void *
951 cobc_check_string (const char *dupstr)
952 {
953  struct strcache *s;
954 
955 #ifdef COB_TREE_DEBUG
956  if (unlikely(!dupstr)) {
957  cobc_abort_pr (_("Call to %s with NULL pointer"), "cobc_check_string");
959  }
960 #endif
961  for (s = base_string; s; s = s->next) {
962  if (!strcmp (dupstr, (const char *)s->val)) {
963  return s->val;
964  }
965  }
966  s = cobc_main_malloc (sizeof(struct strcache));
967  s->next = base_string;
968  s->val = cobc_main_strdup (dupstr);
969  base_string = s;
970  return s->val;
971 }
972 
973 static struct cb_text_list *
974 cb_text_list_add (struct cb_text_list *list, const char *text)
975 {
976  struct cb_text_list *p;
977 
978  p = cobc_main_malloc (sizeof (struct cb_text_list));
979  p->text = cobc_main_strdup (text);
980  if (!list) {
981  p->last = p;
982  return p;
983  }
984  list->last->next = p;
985  list->last = p;
986  return list;
987 }
988 
989 static struct cb_text_list *
990 cb_text_list_chk (struct cb_text_list *list, const char *text)
991 {
992  struct cb_text_list *p;
993 
994  for (p = list; p; p = p->next) {
995  if (!strcmp (text, p->text)) {
996  return list;
997  }
998  }
999  return cb_text_list_add (list, text);
1000 }
1001 
1002 static unsigned int
1003 cobc_set_value (struct cb_define_struct *p, const char *value)
1004 {
1005  const char *s;
1006  size_t size;
1007  unsigned int dot_seen;
1008  unsigned int sign_seen;
1009 
1010  if (!value) {
1011  p->deftype = PLEX_DEF_NONE;
1012  p->value = NULL;
1013  p->sign = 0;
1014  p->int_part = 0;
1015  p->dec_part = 0;
1016  return 0;
1017  }
1018 
1019  /* Quoted value */
1020  if (*value == '"' || *value == '\'') {
1021  size = strlen (value) - 1U;
1022  if (value[0] != value[size]) {
1023  p->value = NULL;
1024  p->deftype = PLEX_DEF_NONE;
1025  return 1;
1026  }
1027  p->value = cobc_main_strdup (value);
1028 
1029  p->deftype = PLEX_DEF_LIT;
1030  p->sign = 0;
1031  p->int_part = 0;
1032  p->dec_part = 0;
1033  return 0;
1034  }
1035 
1036  /* Non-quoted value - Check if possible numeric */
1037  dot_seen = 0;
1038  sign_seen = 0;
1039  size = 0;
1040  s = value;
1041  if (*s == '+' || *s == '-') {
1042  sign_seen = 1;
1043  size++;
1044  s++;
1045  }
1046  for (; *s; ++s) {
1047  if (*s == '.') {
1048  if (dot_seen) {
1049  break;
1050  }
1051  dot_seen = 1;
1052  size++;
1053  continue;
1054  }
1055  if (*s > '9' || *s < '0') {
1056  break;
1057  }
1058  size++;
1059  }
1060 
1061  if (*s || size <= (dot_seen + sign_seen)) {
1062  /* Not numeric */
1063 #if 0 /* RXWRXW - Lit warn */
1064  cobc_abort_pr (_("Warning - Assuming literal for unquoted '%s'"),
1065  value);
1066 #endif
1067  size = strlen (value);
1068  p->value = cobc_main_malloc (size + 4U);
1069  sprintf (p->value, "'%s'", value);
1070  p->deftype = PLEX_DEF_LIT;
1071  p->sign = 0;
1072  p->int_part = 0;
1073  p->dec_part = 0;
1074  return 0;
1075  }
1076 
1077  p->value = cobc_main_strdup (value);
1078  p->deftype = PLEX_DEF_NUM;
1079  p->sign = 0;
1080  p->int_part = 0;
1081  p->dec_part = 0;
1082  return 0;
1083 }
1084 
1085 static int
1086 cobc_bcompare (const void *p1, const void *p2)
1087 {
1088  const void **tptr;
1089 
1090  tptr = (const void **)p2;
1091  return strcmp (p1, *tptr);
1092 }
1093 
1094 static void
1095 cobc_error_name (const char *name, const unsigned int source,
1096  const unsigned int reason)
1097 {
1098  const char *s;
1099 
1100  s = "";
1101  switch (reason) {
1102  case 1:
1103  s = _(" - Length is < 1 or > 31");
1104  break;
1105  case 2:
1106  s = _(" - Name cannot begin with space or underscore");
1107  break;
1108  case 3:
1109  s = _(" - Name cannot begin with 'cob_' or 'COB_'");
1110  break;
1111  case 4:
1112  s = _(" - Name duplicates a 'C' keyword");
1113  break;
1114  case 5:
1115  s = _(" - Name cannot contain a directory separator");
1116  break;
1117  default:
1118  break;
1119  }
1120  switch (source) {
1121  case 0:
1122  /* basename */
1123  cobc_abort_pr (_("Invalid file base name '%s'%s"),
1124  name, s);
1125  break;
1126  case 1:
1127  /* ENTRY */
1128  cb_error (_("Invalid ENTRY '%s'%s"), name, s);
1129  break;
1130  case 2:
1131  /* PROGRAM-ID */
1132  cb_error (_("Invalid PROGRAM-ID '%s'%s"), name, s);
1133  break;
1134  default:
1135  cobc_abort_pr (_("Unknown name error '%s'%s"),
1136  name, s);
1137  break;
1138  }
1139 }
1140 
1141 size_t
1142 cobc_check_valid_name (const char *name, const unsigned int prechk)
1143 {
1144  const char *p;
1145  size_t len;
1146 
1147  for (p = name, len = 0; *p; p++, len++) {
1148  if (*p == '/' || *p == '\\') {
1149  cobc_error_name (name, prechk, 5U);
1150  return 1;
1151  }
1152  }
1153  if (len < 1) {
1154  cobc_error_name (name, prechk, 1U);
1155  return 1;
1156  }
1157  if (!cb_relaxed_syntax_check && len > 31) {
1158  cobc_error_name (name, prechk, 1U);
1159  return 1;
1160  }
1161  if (*name == '_' || *name == ' ') {
1162  cobc_error_name (name, prechk, 2U);
1163  return 1;
1164  }
1165  if (prechk && len > 3 &&
1166  (!memcmp (name, "cob_", (size_t)4) ||
1167  !memcmp (name, "COB_", (size_t)4))) {
1168  cobc_error_name (name, prechk, 3U);
1169  return 1;
1170  }
1171  if (bsearch (name, cob_csyns, COB_NUM_CSYNS,
1172  sizeof (char *), cobc_bcompare)) {
1173  cobc_error_name (name, prechk, 4U);
1174  return 1;
1175  }
1176  return 0;
1177 }
1178 
1179 /* Local functions */
1180 
1181 static void
1182 cobc_chk_buff_size (const size_t bufflen)
1183 {
1184  if (bufflen >= cobc_buffer_size) {
1185  cobc_buffer_size = bufflen + 32;
1187  }
1188 }
1189 
1190 static int
1191 cobc_deciph_optarg (const char *p, const int allow_quote)
1192 {
1193  const unsigned char *s;
1194  size_t len;
1195  size_t i;
1196  int n;
1197 
1198  len = strlen (p);
1199  if (!len) {
1200  return -1;
1201  }
1202  s = (const unsigned char *)p;
1203  if (allow_quote) {
1204  if (*s == '"' || *s == '\'') {
1205  if (len != 3 || *(s + 2) != *s) {
1206  return -1;
1207  }
1208  return (int)(*(s + 1));
1209  }
1210  if (*s < '0' || *s > '9') {
1211  if (len != 1) {
1212  return -1;
1213  }
1214  return (int)*s;
1215  }
1216  }
1217  n = 0;
1218  for (i = 0; i < len; ++i) {
1219  if (s[i] < '0' || s[i] > '9') {
1220  return -1;
1221  }
1222  n *= 10;
1223  n += (s[i] & 0x0F);
1224  }
1225  return n;
1226 }
1227 
1228 DECLNORET static void COB_A_NORETURN
1229 cobc_err_exit (const char *fmt, ...)
1230 {
1231  va_list ap;
1232 
1233  fputs ("cobc: ", stderr);
1234  fputs (_("Error: "), stderr);
1235  va_start (ap, fmt);
1236  vfprintf (stderr, fmt, ap);
1237  va_end (ap);
1238  putc ('\n', stderr);
1239  fflush (stderr);
1240  cobc_free_mem ();
1241  exit (1);
1242 }
1243 
1244 static struct cb_define_struct *
1245 cb_define_list_add (struct cb_define_struct *list, const char *text)
1246 {
1247  struct cb_define_struct *p;
1248  struct cb_define_struct *l;
1249  char *s;
1250  char *x;
1251 
1252  x = cobc_strdup (text);
1253  s = strtok (x, "=");
1254 
1255  /* Check duplicate */
1256  for (l = list; l; l = l->next) {
1257  if (!strcasecmp (s, l->name)) {
1258  cobc_abort_pr (_("Duplicate define '%s' - Ignoring"), s);
1259  cobc_free (x);
1260  return list;
1261  }
1262  }
1263 
1264  p = cobc_main_malloc (sizeof (struct cb_define_struct));
1265  p->next = NULL;
1266  p->name = cobc_check_string (s);
1267  p->deftype = PLEX_DEF_NONE;
1268  s = strtok (NULL, "");
1269  if (cobc_set_value (p, s)) {
1270  cobc_free (x);
1271  return NULL;
1272  }
1273 
1274  cobc_free (x);
1275 
1276  if (!list) {
1277  p->last = p;
1278  return p;
1279  }
1280  list->last->next = p;
1281  list->last = p;
1282  return list;
1283 }
1284 
1285 static char *
1286 cobc_stradd_dup (const char *str1, const char *str2)
1287 {
1288  char *p;
1289  size_t m, n;
1290 
1291 #ifdef COB_TREE_DEBUG
1292  if (unlikely(!str1 || !str2)) {
1293  cobc_abort_pr (_("Call to %s with NULL pointer"), "cobc_stradd_dup");
1295  }
1296 #endif
1297  m = strlen (str1);
1298  n = strlen (str2);
1299  p = cobc_main_malloc (m + n + 1);
1300  memcpy (p, str1, m);
1301  memcpy (p + m, str2, n);
1302  return p;
1303 }
1304 
1305 static char *
1306 cobc_getenv (const char *env)
1307 {
1308  char *p;
1309 
1310  p = getenv (env);
1311  if (!p || *p == 0 || *p == ' ') {
1312  return NULL;
1313  }
1314  return cobc_main_strdup (p);
1315 }
1316 
1317 static void
1318 cobc_add_str (char **var, size_t *cursize, const char *s1, const char *s2,
1319  const char *s3)
1320 {
1321  size_t calcsize;
1322 
1323  if (!s1) {
1324  return;
1325  }
1326 
1327  calcsize = strlen (*var);
1328  calcsize += strlen (s1);
1329  if (s2) {
1330  calcsize += strlen (s2);
1331  }
1332  if (s3) {
1333  calcsize += strlen (s3);
1334  }
1335  if (calcsize >= 131072) {
1336  /* Arbitrary limit */
1337  cobc_err_exit (_("Parameter buffer size exceeded"));
1338  }
1339  if (calcsize >= *cursize) {
1340  while (*cursize <= calcsize) {
1341  *cursize *= 2;
1342  }
1343  *var = cobc_main_realloc (*var, *cursize);
1344  }
1345  strcat (*var, s1);
1346  if (s2) {
1347  strcat (*var, s2);
1348  }
1349  if (s3) {
1350  strcat (*var, s3);
1351  }
1352 }
1353 
1354 static void
1356 {
1357  if (!name || access (name, F_OK)) {
1358  return;
1359  }
1360  if (!save_temps) {
1361  (void)unlink (name);
1362  return;
1363  }
1364  if (save_temps_dir) {
1365  char temp_buff[COB_MEDIUM_BUFF];
1366 
1367  snprintf (temp_buff, (size_t)COB_MEDIUM_MAX,
1368  "%s%s%s", save_temps_dir, SLASH_STR, name);
1369  temp_buff[COB_MEDIUM_MAX] = 0;
1370  /* Remove possible target file - ignore return */
1371  (void)unlink (temp_buff);
1372  if (rename (name, temp_buff)) {
1373  cobc_abort_pr (_("Warning - Could not move temporary file to %s"),
1374  temp_buff);
1375  }
1376  }
1377 }
1378 
1379 static void
1380 cobc_clean_up (const int status)
1381 {
1382  struct filename *fn;
1383  struct local_filename *lf;
1384  cob_u32_t i;
1385 
1386  if (cb_listing_file) {
1387  fclose (cb_listing_file);
1389  }
1390  if (cb_storage_file) {
1391  fclose (cb_storage_file);
1393  }
1394  if (ppin) {
1395  fclose (ppin);
1396  ppin = NULL;
1397  }
1398 
1399  if (ppout) {
1400  fclose (ppout);
1401  ppout = NULL;
1402  }
1403  if (yyin) {
1404  fclose (yyin);
1405  yyin = NULL;
1406  }
1407 
1408  if (yyout) {
1409  fclose (yyout);
1410  yyout = NULL;
1411  }
1412 
1413  for (fn = file_list; fn; fn = fn->next) {
1414  for (lf = fn->localfile; lf; lf = lf->next) {
1415  if (unlikely(lf->local_fp)) {
1416  fclose (lf->local_fp);
1417  lf->local_fp = NULL;
1418  }
1419  }
1420  if (fn->need_assemble &&
1421  (status || cb_compile_level > CB_LEVEL_ASSEMBLE ||
1423  cobc_check_action (fn->object);
1424  }
1425  if (save_all_src) {
1426  continue;
1427  }
1428  if (fn->need_preprocess &&
1429  (status || cb_compile_level > CB_LEVEL_PREPROCESS ||
1432  }
1433  if (save_c_src) {
1434  continue;
1435  }
1436  if (fn->need_translate &&
1437  (status || cb_compile_level > CB_LEVEL_TRANSLATE ||
1441  if (fn->localfile) {
1442  for (lf = fn->localfile; lf; lf = lf->next) {
1444  }
1445  } else if (fn->translate) {
1446  /* If we get syntax errors, we do not
1447  know the number of local include files */
1448  snprintf (cobc_buffer, cobc_buffer_size,
1449  "%s.l.h", fn->translate);
1451  for (i = 0; i < 30U; ++i) {
1452  if (i) {
1453  snprintf (cobc_buffer, cobc_buffer_size,
1454  "%s.l%u.h", fn->translate, i);
1456  }
1457  if (!access (cobc_buffer, F_OK)) {
1458  unlink (cobc_buffer);
1459  } else if (i) {
1460  break;
1461  }
1462  }
1463  }
1464  }
1465  }
1466  cobc_free_mem ();
1467  file_list = NULL;
1468 }
1469 
1470 DECLNORET static void COB_A_NORETURN
1471 cobc_terminate (const char *str)
1472 {
1473  int save_errno;
1474 
1475  save_errno = errno;
1476  fprintf (stderr, "cobc: ");
1477  fflush (stderr);
1478  errno = save_errno;
1479  perror (str);
1480  fflush (stderr);
1481  cobc_clean_up (1);
1482  exit (1);
1483 }
1484 
1485 DECLNORET static void COB_A_NORETURN
1487 {
1488  if (cb_source_file) {
1489  cobc_abort_pr (_("Aborting compile of %s at line %d"),
1491  }
1492  cobc_clean_up (99);
1493  exit (99);
1494 }
1495 
1496 #ifdef HAVE_SIGNAL_H
1497 DECLNORET static void COB_A_NORETURN
1498 cobc_sig_handler (int sig)
1499 {
1500 #if defined(HAVE_SIGACTION) && !defined(SA_RESETHAND)
1501  struct sigaction sa;
1502 #endif
1503 
1504 #ifdef HAVE_SIG_ATOMIC_T
1505  if (sig_is_handled) {
1506 #ifdef HAVE_RAISE
1507  raise (sig);
1508 #else
1509  kill (cob_sys_getpid (), sig);
1510 #endif
1511  exit (sig);
1512  }
1513  sig_is_handled = 1;
1514 #endif
1515 
1516 #ifdef HAVE_SIGACTION
1517 #ifndef SA_RESETHAND
1518  memset (&sa, 0, sizeof(sa));
1519  sa.sa_handler = SIG_DFL;
1520  (void)sigemptyset (&sa.sa_mask);
1521  (void)sigaction (sig, &sa, NULL);
1522 #endif
1523 #else
1524  (void)signal (sig, SIG_DFL);
1525 #endif
1526 
1527  save_temps = 0;
1528  cobc_clean_up (1);
1529 #ifdef HAVE_RAISE
1530  raise (sig);
1531 #else
1532  kill (cob_sys_getpid (), sig);
1533 #endif
1534  exit (sig);
1535 }
1536 #endif
1537 
1538 /* Command line */
1539 
1540 static void
1542 {
1543  printf ("cobc (%s) %s.%d\n",
1545  puts ("Copyright (C) 2001-2016 Free Software Foundation, Inc.");
1546  printf (_("Written by %s\n"), "Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch");
1547  puts (_("This is free software; see the source for copying conditions. There is NO\n"
1548  "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."));
1549  printf (_("Built %s"), cb_oc_build_stamp);
1550  putchar ('\n');
1551  printf (_("Packaged %s"), COB_TAR_DATE);
1552  putchar ('\n');
1553  printf (_("C version %s%s"), OC_C_VERSION_PRF, OC_C_VERSION);
1554  putchar ('\n');
1555 }
1556 
1557 static void
1558 cobc_cmd_print (const char *cmd)
1559 {
1560  char *p;
1561  char *token;
1562  size_t n;
1563  size_t toklen;
1564 
1565  fputs (_("Executing:"), stderr);
1566  /* Check if it fits in 80 characters */
1567  if (strlen (cmd) < 64) {
1568  fprintf (stderr, "\t%s\n", (char *)cmd);
1569  fflush (stderr);
1570  return;
1571  }
1572  putc ('\t', stderr);
1573  p = cobc_strdup (cmd);
1574  n = 0;
1575  token = strtok (p, " ");
1576  for (; token; token = strtok (NULL, " ")) {
1577  toklen = strlen (token) + 1;
1578  if ((n + toklen) > 63) {
1579  fprintf(stderr, "\n\t\t");
1580  n = 0;
1581  }
1582  fprintf (stderr, "%s%s", (n ? " " : ""), token);
1583  n += toklen;
1584  }
1585  cobc_free (p);
1586  putc ('\n', stderr);
1587  fflush (stderr);
1588 }
1589 
1590 static void
1591 cobc_var_print (const char *msg, const char *val, const unsigned int env)
1592 {
1593  char *p;
1594  char *token;
1595  size_t n;
1596  int lablen;
1597  size_t toklen;
1598 
1599  if (!env) {
1600  printf ("%-*.*s : ", CB_IMSG_SIZE, CB_IMSG_SIZE, msg);
1601  } else {
1602  printf (" %s: ", _("env"));
1603  lablen = CB_IMSG_SIZE - 2 - (int)strlen(_("env")) - 2;
1604  printf ("%-*.*s : ", lablen, lablen, msg);
1605  }
1606  if (strlen(val) <= CB_IVAL_SIZE) {
1607  printf("%s\n", val);
1608  return;
1609  }
1610  p = cobc_strdup (val);
1611  n = 0;
1612  token = strtok (p, " ");
1613  for (; token; token = strtok (NULL, " ")) {
1614  toklen = (int)strlen (token) + 1;
1615  if ((n + toklen) > CB_IVAL_SIZE) {
1616  if (n) {
1617  printf ("\n%*.*s", CB_IMSG_SIZE + 3,
1618  CB_IMSG_SIZE + 3, " ");
1619  }
1620  n = 0;
1621  }
1622  printf ("%s%s", (n ? " " : ""), token);
1623  n += toklen;
1624  }
1625  putchar ('\n');
1626  cobc_free (p);
1627 }
1628 
1629 static void
1631 {
1632  char buff[16];
1633  char *s;
1634 
1635  cobc_print_version ();
1636  putchar ('\n');
1637  puts (_("build information"));
1638  cobc_var_print (_("build environment"), COB_BLD_BUILD, 0);
1639  cobc_var_print ("CC", COB_BLD_CC, 0);
1640  cobc_var_print ("CPPFLAGS", COB_BLD_CPPFLAGS, 0);
1641  cobc_var_print ("CFLAGS", COB_BLD_CFLAGS, 0);
1642  cobc_var_print ("LD", COB_BLD_LD, 0);
1643  cobc_var_print ("LDFLAGS", COB_BLD_LDFLAGS, 0);
1644  putchar ('\n');
1645  puts (_("GnuCOBOL information"));
1646  cobc_var_print ("COB_CC", COB_CC, 0);
1647  if ((s = getenv ("COB_CC")) != NULL) {
1648  cobc_var_print ("COB_CC", s, 1);
1649  }
1650  cobc_var_print ("COB_CFLAGS", COB_CFLAGS, 0);
1651  if ((s = getenv ("COB_CFLAGS")) != NULL) {
1652  cobc_var_print ("COB_CFLAGS", s, 1);
1653  }
1654  cobc_var_print ("COB_LDFLAGS", COB_LDFLAGS, 0);
1655  if ((s = getenv ("COB_LDFLAGS")) != NULL) {
1656  cobc_var_print ("COB_LDFLAGS", s, 1);
1657  }
1658  cobc_var_print ("COB_LIBS", COB_LIBS, 0);
1659  if ((s = getenv ("COB_LIBS")) != NULL) {
1660  cobc_var_print ("COB_LIBS", s, 1);
1661  }
1662  cobc_var_print ("COB_CONFIG_DIR", COB_CONFIG_DIR, 0);
1663  if ((s = getenv ("COB_CONFIG_DIR")) != NULL) {
1664  cobc_var_print ("COB_CONFIG_DIR", s, 1);
1665  }
1666  cobc_var_print ("COB_COPY_DIR", COB_COPY_DIR, 0);
1667  if ((s = getenv ("COB_COPY_DIR")) != NULL) {
1668  cobc_var_print ("COB_COPY_DIR", s, 1);
1669  }
1670  if ((s = getenv ("COBCPY")) != NULL) {
1671  cobc_var_print ("COBCPY", s, 1);
1672  }
1673  if (cb_msg_style == CB_MSG_STYLE_MSC) {
1674  cobc_var_print ("COB_MSG_FORMAT", "MSC", 0);
1675  } else {
1676  cobc_var_print ("COB_MSG_FORMAT", "GCC", 0);
1677  }
1678  if ((s = getenv ("COB_MSG_FORMAT")) != NULL) {
1679  cobc_var_print ("COB_MSG_FORMAT", s, 1);
1680  }
1681 #if 0 /* Simon: only relevant for libcob */
1682  if ((s = getenv ("COB_LIBRARY_PATH")) != NULL) {
1683  cobc_var_print ("COB_LIBRARY_PATH", s, 1);
1684  }
1685 #endif
1686  cobc_var_print ("COB_MODULE_EXT", COB_MODULE_EXT, 0);
1687  cobc_var_print ("COB_EXEEXT", COB_EXEEXT, 0);
1688 
1689 #if 0 /* Simon: only relevant for libcob */
1690 #if defined(USE_LIBDL) || defined(_WIN32)
1691  cobc_var_print (_("Dynamic loading"), _("System"), 0);
1692 #else
1693  cobc_var_print (_("Dynamic loading"), _("Libtool"), 0);
1694 #endif
1695 
1696 #ifdef COB_PARAM_CHECK
1697  cobc_var_print ("\"CBL_\" param check", _("Enabled"), 0);
1698 #else
1699  cobc_var_print ("\"CBL_\" param check", _("Disabled"), 0);
1700 #endif
1701 #endif
1702 
1703  if (sizeof (void *) > 4U) {
1704  cobc_var_print ("64bit-mode", _("yes"), 0);
1705  } else {
1706  cobc_var_print ("64bit-mode", _("no"), 0);
1707  }
1708 
1709 #ifdef COB_LI_IS_LL
1710  cobc_var_print ("BINARY-C-LONG", _("8 bytes"), 0);
1711 #else
1712  cobc_var_print ("BINARY-C-LONG", _("4 bytes"), 0);
1713 #endif
1714 
1715  cobc_var_print (_("Extended screen I/O"), WITH_CURSES, 0);
1716 
1717  snprintf (buff, sizeof(buff), "%d", WITH_VARSEQ);
1718  cobc_var_print (_("Variable format"), buff, 0);
1719  if ((s = getenv ("COB_VARSEQ_FORMAT")) != NULL) {
1720  cobc_var_print ("COB_VARSEQ_FORMAT", s, 1);
1721  }
1722 
1723 #ifdef WITH_SEQRA_EXTFH
1724  cobc_var_print (_("Sequential handler"), _("External"), 0);
1725 #else
1726  cobc_var_print (_("Sequential handler"), _("Internal"), 0);
1727 #endif
1728 
1729 #if defined (WITH_INDEX_EXTFH)
1730  cobc_var_print (_("ISAM handler"), _("External"), 0);
1731 #elif defined (WITH_DB)
1732  cobc_var_print (_("ISAM handler"), "BDB", 0);
1733 #elif defined (WITH_CISAM)
1734  cobc_var_print (_("ISAM handler"), "C-ISAM", 0);
1735 #elif defined (WITH_DISAM)
1736  cobc_var_print (_("ISAM handler"), "D-ISAM", 0);
1737 #elif defined (WITH_VBISAM)
1738  cobc_var_print (_("ISAM handler"), "VBISAM", 0);
1739 #else
1740  cobc_var_print (_("ISAM handler"), _("Not available"), 0);
1741 #endif
1742 
1743 #ifdef WITH_INDEX_EXTFH
1744 #endif
1745 #ifdef WITH_DB
1746 #endif
1747 #ifdef WITH_CISAM
1748 #endif
1749 #ifdef WITH_DISAM
1750 #endif
1751 #ifdef WITH_VBISAM
1752 #endif
1753 }
1754 
1755 static void
1756 cobc_print_warn (const char *name, const char *doc, const int wall)
1757 {
1758  printf (" -W%-19s %s", name, doc);
1759  if (!wall) {
1760  fputs ("\n\t\t\t", stdout);
1761  fputs (_("- NOT set with -Wall"), stdout);
1762  }
1763  putchar ('\n');
1764 }
1765 
1766 static void
1767 cobc_print_flag (const char *name, const char *doc,
1768  const int pdok, const int exten)
1769 {
1770  const char *bptr;
1771  char buff[32];
1772 
1773  if (!pdok) {
1774  return;
1775  }
1776  if (!exten) {
1777  bptr = name;
1778  } else {
1779  snprintf (buff, sizeof(buff), "%s=<value>", name);
1780  bptr = buff;
1781  }
1782  printf (" -f%-19s %s\n", bptr, doc);
1783 }
1784 
1785 static void
1786 cobc_print_usage (char * prog)
1787 {
1788  puts (_("GnuCOBOL compiler for most COBOL dialects with lots of extensions"));
1789  putchar ('\n');
1790  printf (_("usage: %s [options]... file..."), prog);
1791  putchar ('\n');
1792  putchar ('\n');
1793  puts (_("options:"));
1794  puts (_(" -h, -help display this help and exit"));
1795  puts (_(" -V, -version display compiler version and exit"));
1796  puts (_(" -i, -info display compiler information (build/environment)"));
1797  puts (_(" -v, -verbose display the commands invoked by the compiler"));
1798  puts (_(" -vv display compiler version and the commands\n" \
1799  " invoked by the compiler"));
1800  puts (_(" -x build an executable program"));
1801  puts (_(" -m build a dynamically loadable module (default)"));
1802  puts (_(" -j run job, after build"));
1803  puts (_(" -std=<dialect> warnings/features for a specific dialect\n"
1804  " <dialect> can be one of:\n"
1805  " cobol2014, cobol2002, cobol85, default,\n"
1806  " ibm, mvs, bs2000, mf, acu;\n"
1807  " see configuration files in directory config"));
1808  puts (_(" -F, -free use free source format"));
1809  puts (_(" -free use free source format"));
1810  puts (_(" -fixed use fixed source format (default)"));
1811  puts (_(" -O, -O2, -Os enable optimization"));
1812  puts (_(" -g enable C compiler debug / stack check / trace"));
1813  puts (_(" -d, -debug enable all run-time error checking"));
1814  puts (_(" -o <file> place the output into <file>"));
1815  puts (_(" -b combine all input files into a single\n"
1816  " dynamically loadable module"));
1817  puts (_(" -E preprocess only; do not compile or link"));
1818  puts (_(" -C translation only; convert COBOL to C"));
1819  puts (_(" -S compile only; output assembly file"));
1820  puts (_(" -c compile and assemble, but do not link"));
1821  puts (_(" -P(=<dir or file>) generate preprocessed program listing (.lst)"));
1822  puts (_(" -Xref generate cross reference through 'cobxref'\n"
1823  " (V. Coen's 'cobxref' must be in path)"));
1824  puts (_(" -I <directory> add <directory> to copy/include search path"));
1825  puts (_(" -L <directory> add <directory> to library search path"));
1826  puts (_(" -l <lib> link the library <lib>"));
1827  puts (_(" -A <options> add <options> to the C compile phase"));
1828  puts (_(" -Q <options> add <options> to the C link phase"));
1829  puts (_(" -D <define> define <define> for COBOL compilation"));
1830  puts (_(" -K <entry> generate CALL to <entry> as static"));
1831  puts (_(" -conf=<file> user defined dialect configuration - See -std="));
1832  puts (_(" -cb_conf=<tag:value> override configuration entry"));
1833  puts (_(" -list-reserved display reserved words"));
1834  puts (_(" -list-intrinsics display intrinsic functions"));
1835  puts (_(" -list-mnemonics display mnemonic names"));
1836  puts (_(" -list-system display system routines"));
1837  puts (_(" -save-temps(=<dir>) save intermediate files\n"
1838  " - default: current directory"));
1839  puts (_(" -ext <extension> add default file extension"));
1840 
1841  putchar ('\n');
1842 
1843  puts (_(" -W enable ALL warnings"));
1844  puts (_(" -Wall enable all warnings except as noted below"));
1845  puts (_(" -Wno-<feature> disable warning enabled by -W or -Wall"));
1846 #undef CB_WARNDEF
1847 #undef CB_NOWARNDEF
1848 #define CB_WARNDEF(var,name,doc) \
1849  cobc_print_warn (name, doc, 1);
1850 #define CB_NOWARNDEF(var,name,doc) \
1851  cobc_print_warn (name, doc, 0);
1852 #include "warning.def"
1853 #undef CB_WARNDEF
1854 #undef CB_NOWARNDEF
1855 
1856  putchar ('\n');
1857 
1858 #undef CB_FLAG
1859 #undef CB_FLAG_RQ
1860 #undef CB_FLAG_NQ
1861 #define CB_FLAG(var,pdok,name,doc) \
1862  cobc_print_flag (name, doc, pdok, 0);
1863 #define CB_FLAG_RQ(var,pdok,name,def,opt,doc) \
1864  cobc_print_flag (name, doc, pdok, 1);
1865 #define CB_FLAG_NQ(pdok,name,opt,doc) \
1866  cobc_print_flag (name, doc, pdok, 1);
1867 #include "flag.def"
1868 #undef CB_FLAG
1869 #undef CB_FLAG_RQ
1870 #undef CB_FLAG_NQ
1871 
1872  putchar ('\n');
1873 }
1874 
1875 static void
1877 {
1878  cobc_err_exit (_("Only one of options 'E', 'S', 'C', 'c' may be specified"));
1879 }
1880 
1881 static void
1883 {
1884  cobc_err_exit (_("Only one of options 'm', 'x', 'b' may be specified"));
1885 }
1886 
1887 static void
1888 cobc_deciph_funcs (const char *opt)
1889 {
1890  char *p;
1891  char *q;
1892 
1893  if (!strcasecmp (opt, "ALL")) {
1895  return;
1896  }
1897 
1898  p = cobc_strdup (opt);
1899  q = strtok (p, ",");
1900  while (q) {
1901  if (!lookup_intrinsic (q, 0, 1)) {
1902  cobc_err_exit (_("'%s' is not an intrinsic function"), q);
1903  }
1904  CB_TEXT_LIST_ADD (cb_intrinsic_list, q);
1905  q = strtok (NULL, ",");
1906  }
1907  cobc_free (p);
1908 }
1909 
1910 static int
1911 process_command_line (const int argc, char **argv)
1912 {
1913  struct cb_define_struct *p;
1914  size_t osize;
1915  int c;
1916  int idx;
1917  int n;
1918  int list_reserved = 0;
1919 #ifdef _WIN32
1920  int argnum;
1921 #endif
1922  enum cob_exception_id i;
1923  struct stat st;
1924  char ext[COB_MINI_BUFF];
1925 
1926  int conf_ret = 0;
1927  int sub_ret;
1928 
1929 #ifdef _WIN32
1930  /* Translate command line arguments from WIN to UNIX style */
1931  argnum = 1;
1932  while (++argnum <= argc) {
1933  if (strrchr(argv[argnum - 1], '/') == argv[argnum - 1]) {
1934  argv[argnum - 1][0] = '-';
1935  }
1936  }
1937 #endif
1938 
1939  /* First run of getopt: handle std/conf and all listing options
1940  We need to postpone single configuration flags as we need
1941  a full configuration to be loaded before */
1942  cob_optind = 1;
1943  while ((c = cob_getopt_long_long (argc, argv, short_options,
1944  long_options, &idx, 1)) >= 0) {
1945  switch (c) {
1946 
1947  case '?':
1948  /* Unknown option or ambiguous */
1949  cobc_free_mem ();
1950  exit (1);
1951 
1952  case 'h':
1953  /* --help */
1954  cobc_print_usage (argv[0]);
1955  cobc_free_mem ();
1956  exit (0);
1957 
1958  case 'V':
1959  /* --version */
1960  cobc_print_version ();
1961  exit (0);
1962 
1963  case 'i':
1964  /* --info */
1965  cobc_print_info ();
1966  exit_option = 1;
1967  break;
1968 
1969  case '5':
1970  /* --list-reserved */
1971  /*
1972  This must be postponed until after the configuration
1973  is loaded.
1974  */
1975  list_reserved = 1;
1976  break;
1977 
1978  case '6':
1979  /* --list-intrinsics */
1980  cb_list_intrinsics ();
1981  exit_option = 1;
1982  break;
1983 
1984  case '7':
1985  /* --list-mnemonics */
1986  cb_list_mnemonics ();
1987  exit_option = 1;
1988  break;
1989 
1990  case '8':
1991  /* --list-system */
1992  cb_list_system ();
1993  exit_option = 1;
1994  break;
1995 
1996  case 'v':
1997  /* --verbose : Verbose reporting */
1998  /* VERY special case as we set different level by mutliple calls */
1999  /* Output version information when running very verbose */
2000  if (++verbose_output == 2) {
2001  cobc_print_version ();
2002  }
2003  break;
2004 
2005  case '$':
2006  /* -std=<xx> : Specify dialect */
2007  if (!exit_option) {
2008  snprintf (ext, (size_t)COB_MINI_MAX, "%s.conf", cob_optarg);
2009  if (cb_load_std (ext) != 0) {
2010  cobc_err_exit (_("Invalid option -std=%s"),
2011  cob_optarg);
2012  }
2013  }
2014  break;
2015 
2016  case '&':
2017  /* -conf=<xx> : Specify dialect configuration file */
2018  if (!exit_option) {
2019  if (strlen (cob_optarg) > COB_SMALL_MAX) {
2020  cobc_err_exit (COBC_INV_PAR, "-conf");
2021  }
2022  sub_ret = cb_load_conf (cob_optarg, 0);
2023  if (sub_ret != 0) conf_ret = sub_ret;
2024  }
2025  break;
2026 
2027  default:
2028  /* as we postpone most options simply skip everything other here */
2029  break;
2030  }
2031  }
2032 
2033  /* Exit if list options were specified */
2034  if (exit_option) {
2035  cobc_free_mem ();
2036  exit (0);
2037  }
2038 
2039  /* Load default configuration file if necessary */
2040  if (cb_config_name == NULL) {
2041  if (verbose_output) {
2042  fputs (_("Loading standard configuration file 'default.conf'"), stderr);
2043  fputc ('\n', stderr);
2044  }
2045  sub_ret = cb_load_std ("default.conf");
2046  if (sub_ret != 0) conf_ret = sub_ret;
2047  }
2048 
2049  /* Exit for configuration errors resulting from -std/-conf/default.conf */
2050  if (conf_ret != 0) {
2051  cobc_free_mem ();
2052  exit (1);
2053  }
2054 
2055  /* Set relaxed syntax configuration options if requested */
2056  if (cb_flag_relaxed_syntax) {
2057  cb_relaxed_syntax_check = 1;
2058  cb_larger_redefines_ok = 1;
2059  cb_relax_level_hierarchy = 1;
2060  cb_top_level_occurs_clause = CB_OK;
2061  }
2062 
2063  cob_optind = 1;
2064  while ((c = cob_getopt_long_long (argc, argv, short_options,
2065  long_options, &idx, 1)) >= 0) {
2066  switch (c) {
2067  case 0:
2068  /* Defined flag */
2069  break;
2070 
2071  case 'h':
2072  /* --help */
2073  case 'V':
2074  /* --version */
2075  case 'i':
2076  /* --info */
2077  case '5':
2078  /* --list-reserved */
2079  case '6':
2080  /* --list-intrinsics */
2081  case '7':
2082  /* --list-mnemonics */
2083  case '8':
2084  /* --list-system */
2085  /* These options were all processed in the first getopt-run */
2086  break;
2087 
2088  case 'E':
2089  /* -E : Preprocess */
2090  if (wants_nonfinal) {
2092  }
2093  wants_nonfinal = 1;
2095  break;
2096 
2097  case 'C':
2098  /* -C : Generate C code */
2099  if (wants_nonfinal) {
2101  }
2102  save_c_src = 1;
2103  wants_nonfinal = 1;
2105  break;
2106 
2107  case 'S':
2108  /* -S : Generate assembler code */
2109  if (wants_nonfinal) {
2111  }
2112  wants_nonfinal = 1;
2114  break;
2115 
2116  case 'c':
2117  /* -c : Generate C object code */
2118  if (wants_nonfinal) {
2120  }
2121  wants_nonfinal = 1;
2123  break;
2124 
2125  case 'b':
2126  /* -b : Generate combined library module */
2129  }
2130  cobc_flag_library = 1;
2131  no_physical_cancel = 1;
2132  cb_flag_implicit_init = 1;
2133  break;
2134 
2135  case 'm':
2136  /* -m : Generate loadable module (default) */
2139  }
2140  cobc_flag_module = 1;
2141  break;
2142 
2143  case 'x':
2144  /* -x : Generate executable */
2147  }
2148  cobc_flag_main = 1;
2149  cb_flag_main = 1;
2150  no_physical_cancel = 1;
2151  break;
2152 
2153  case 'j':
2154  /* -j : Run job; compile, link and go, either by ./ or cobcrun */
2155  cobc_flag_run = 1;
2156  break;
2157 
2158  case 'F':
2159  /* -F : short option for -free */
2161  break;
2162 
2163  case 'v':
2164  /* --verbose : Verbose reporting */
2165  /* This option was processed in the first getopt-run */
2166  break;
2167 
2168  case 'o':
2169  /* -o : Output file */
2170  osize = strlen (cob_optarg);
2171  if (osize > COB_SMALL_MAX) {
2172  cobc_err_exit (_("Invalid output file name"));
2173  }
2175  /* Allocate buffer plus extension reserve */
2176  output_name_buff = cobc_main_malloc (osize + 32U);
2177  break;
2178 
2179  case 'O':
2180  /* -O : Optimize */
2181  cob_optimize = 1;
2183  break;
2184 
2185  case '9':
2186  /* -O2 : Optimize */
2187  cob_optimize = 1;
2188  strip_output = 1;
2190  break;
2191 
2192  case 's':
2193  /* -Os : Optimize */
2194  cob_optimize = 1;
2195  strip_output = 1;
2197  break;
2198 
2199  case 'g':
2200  /* -g : Generate C debug code */
2201  save_all_src = 1;
2202  gflag_set = 1;
2203  cb_flag_stack_check = 1;
2204  cb_flag_source_location = 1;
2205 #ifndef _MSC_VER
2206  COBC_ADD_STR (cobc_cflags, " -g", NULL, NULL);
2207 #endif
2208  break;
2209 
2210  case '$':
2211  /* -std=<xx> : Specify dialect */
2212  case '&':
2213  /* -conf=<xx> : Specify dialect configuration file */
2214  /* These options were all processed in the first getopt-run */
2215  break;
2216 
2217  case '%':
2218  /* -cb_conf=<xx:yy> : Override configuration entry */
2219  if (strlen (cob_optarg) > COB_SMALL_MAX) {
2220  cobc_err_exit (COBC_INV_PAR , "-cb_conf");
2221  }
2222  sub_ret = cb_config_entry (cob_optarg, NULL, 0);
2223  if (sub_ret != 0) conf_ret = sub_ret;
2224  break;
2225 
2226  case 'd':
2227  /* -debug : Turn on OC debugging */
2228  cb_flag_source_location = 1;
2229  cb_flag_trace = 1;
2230  cb_flag_stack_check = 1;
2231  cobc_wants_debug = 1;
2232  break;
2233 
2234  case '_':
2235  /* --save-temps : Save intermediary files */
2236  save_temps = 1;
2237  if (cob_optarg) {
2238  if (stat (cob_optarg, &st) != 0 ||
2239  !(S_ISDIR (st.st_mode))) {
2240  cobc_abort_pr (_("Warning - '%s' is not a directory, defaulting to current directory"),
2241  cob_optarg);
2242  } else {
2244  }
2245  }
2246  break;
2247 
2248  case 'P':
2249  /* -P : Generate listing */
2250  if (cob_optarg) {
2251  if (!stat (cob_optarg, &st) && S_ISDIR (st.st_mode)) {
2253  } else {
2255  }
2256  }
2257  if (!cobc_gen_listing) {
2258  cobc_gen_listing = 1;
2259  }
2260  break;
2261 
2262  case 'X':
2263  /* -Xref : Generate listing through 'cobxref' */
2264  cobc_gen_listing = 2;
2265  break;
2266 
2267  case 'D':
2268  /* -D xx(=yy) : Define variables */
2269  if (strlen (cob_optarg) > 64U) {
2270  cobc_err_exit (COBC_INV_PAR, "-D");
2271  }
2272  if (!strcasecmp (cob_optarg, "ebug")) {
2273  cobc_abort_pr (_("Warning - assuming '%s' is a DEFINE - did you intend to use -debug?"),
2274  cob_optarg);
2275  }
2276  p = cb_define_list_add (cb_define_list, cob_optarg);
2277  if (!p) {
2278  cobc_err_exit (COBC_INV_PAR, "-D");
2279  }
2280  cb_define_list = p;
2281  break;
2282 
2283  case 'I':
2284  /* -I <xx> : Include/copy directory */
2285  if (strlen (cob_optarg) > COB_SMALL_MAX) {
2286  cobc_err_exit (COBC_INV_PAR, "-I");
2287  }
2288  if (stat (cob_optarg, &st) != 0 ||
2289  !(S_ISDIR (st.st_mode))) {
2290  break;
2291  }
2292 #ifdef _MSC_VER
2293  COBC_ADD_STR (cobc_include, " /I \"", cob_optarg, "\"");
2294 #elif defined (__WATCOMC__)
2295  COBC_ADD_STR (cobc_include, " -i\"", cob_optarg, "\"");
2296 #else
2297  COBC_ADD_STR (cobc_include, " -I\"", cob_optarg, "\"");
2298 #endif
2299  CB_TEXT_LIST_ADD (cb_include_list, cob_optarg);
2300  break;
2301 
2302  case 'L':
2303  /* -L <xx> : Directory for library search */
2304  if (strlen (cob_optarg) > COB_SMALL_MAX) {
2305  cobc_err_exit (COBC_INV_PAR, "-L");
2306  }
2307  if (stat (cob_optarg, &st) != 0 ||
2308  !(S_ISDIR (st.st_mode))) {
2309  break;
2310  }
2311 #ifdef _MSC_VER
2312  COBC_ADD_STR (cobc_lib_paths, " /LIBPATH:\"", cob_optarg, "\"");
2313 #else
2314  COBC_ADD_STR (cobc_lib_paths, " -L\"", cob_optarg, "\"");
2315 #endif
2316  break;
2317 
2318  case 'l':
2319  /* -l <xx> : Add library to link phase */
2320  if (strlen (cob_optarg) > COB_SMALL_MAX) {
2321  cobc_err_exit (COBC_INV_PAR, "-l");
2322  }
2323 #ifdef _MSC_VER
2324  COBC_ADD_STR (cobc_libs, " \"", cob_optarg, ".lib\"");
2325 #else
2326  COBC_ADD_STR (cobc_libs, " -l\"", cob_optarg, "\"");
2327 #endif
2328  break;
2329 
2330  case 'e':
2331  /* -e <xx> : Add an extension suffix */
2332  if (strlen (cob_optarg) > 15U) {
2333  cobc_err_exit (COBC_INV_PAR, "--ext");
2334  }
2335  snprintf (ext, (size_t)COB_MINI_MAX, ".%s", cob_optarg);
2336  CB_TEXT_LIST_ADD (cb_extension_list, ext);
2337  break;
2338 
2339  case 'K':
2340  /* -K <xx> : Define literal CALL to xx as static */
2341  if (strlen (cob_optarg) > 32U) {
2342  cobc_err_exit (COBC_INV_PAR, "-K");
2343  }
2344  CB_TEXT_LIST_ADD (cb_static_call_list, cob_optarg);
2345  break;
2346 
2347  case 'k':
2348  /* -k <xx> : Check for exit after CALL to xx */
2349  /* This is to cater for legacy German DIN standard */
2350  /* Check after CALL if an exit program required */
2351  /* Not in --help as subject to change and highly specific */
2352  if (strlen (cob_optarg) > 32U) {
2353  cobc_err_exit (COBC_INV_PAR, "-k");
2354  }
2355  CB_TEXT_LIST_ADD (cb_early_exit_list, cob_optarg);
2356  break;
2357 
2358  case 1:
2359  /* -fstack-size=<xx> : Specify stack (perform) size */
2360  n = cobc_deciph_optarg (cob_optarg, 0);
2361  if (n < 16 || n > 512) {
2362  cobc_err_exit (COBC_INV_PAR, "-fstack-size");
2363  }
2364  cb_stack_size = n;
2365  break;
2366 
2367  case 2:
2368  /* -fif-cutoff=<xx> : Specify IF cutoff level */
2369  n = cobc_deciph_optarg (cob_optarg, 0);
2370  if (n < 1 || n > 512) {
2371  cobc_err_exit (COBC_INV_PAR, "-fif-cutoff");
2372  }
2373  cb_if_cutoff = n;
2374  break;
2375 
2376  case 3:
2377  /* -fsign=<ASCII/EBCDIC> : Specify display sign */
2378  if (!strcasecmp (cob_optarg, "EBCDIC")) {
2379  cb_ebcdic_sign = 1;
2380  } else if (!strcasecmp (cob_optarg, "ASCII")) {
2381  cb_ebcdic_sign = 0;
2382  } else {
2383  cobc_err_exit (COBC_INV_PAR, "-fsign");
2384  }
2385  break;
2386 
2387  case 4:
2388  /* -ffold-copy=<UPPER/LOWER> : COPY fold case */
2389  if (!strcasecmp (cob_optarg, "UPPER")) {
2390  cb_fold_copy = COB_FOLD_UPPER;
2391  } else if (!strcasecmp (cob_optarg, "LOWER")) {
2392  cb_fold_copy = COB_FOLD_LOWER;
2393  } else {
2394  cobc_err_exit (COBC_INV_PAR, "-ffold-copy");
2395  }
2396  break;
2397 
2398  case 5:
2399  /* -ffold-call=<UPPER/LOWER> : CALL/PROG-ID fold case */
2400  if (!strcasecmp (cob_optarg, "UPPER")) {
2401  cb_fold_call = COB_FOLD_UPPER;
2402  } else if (!strcasecmp (cob_optarg, "LOWER")) {
2403  cb_fold_call = COB_FOLD_LOWER;
2404  } else {
2405  cobc_err_exit (COBC_INV_PAR, "-ffold-call");
2406  }
2407  break;
2408 
2409  case 6:
2410  /* -fdefaultbyte=<xx> : Default initialization byte */
2411  n = cobc_deciph_optarg (cob_optarg, 1);
2412  if (n < 0 || n > 255) {
2413  cobc_err_exit (COBC_INV_PAR, "-fdefaultbyte");
2414  }
2415  cb_default_byte = n;
2416  break;
2417 
2418  case 10:
2419  /* -fintrinsics=<xx> : Intrinsic name or ALL */
2421  break;
2422 
2423  case 'A':
2424  /* -A <xx> : Add options to C compile phase */
2426  aflag_set = 1;
2427  break;
2428 
2429  case 'Q':
2430  /* -Q <xx> : Add options to C link phase */
2432  break;
2433 
2434  case 'w':
2435  /* -w(xx) : Turn off warnings */
2436 #undef CB_WARNDEF
2437 #undef CB_NOWARNDEF
2438 #define CB_WARNDEF(var,name,doc) var = 0;
2439 #define CB_NOWARNDEF(var,name,doc) var = 0;
2440 #include "warning.def"
2441 #undef CB_WARNDEF
2442 #undef CB_NOWARNDEF
2443  break;
2444 
2445  case 'W':
2446  /* -W : Turn on warnings */
2447  warningopt = 1;
2448 #undef CB_WARNDEF
2449 #undef CB_NOWARNDEF
2450 #define CB_WARNDEF(var,name,doc) var = 1;
2451 #define CB_NOWARNDEF(var,name,doc)
2452 #include "warning.def"
2453 #undef CB_WARNDEF
2454 #undef CB_NOWARNDEF
2455  break;
2456 
2457  case 'Z':
2458  /* -W : Turn on all warnings */
2459  warningopt = 1;
2460 #undef CB_WARNDEF
2461 #undef CB_NOWARNDEF
2462 #define CB_WARNDEF(var,name,doc) var = 1;
2463 #define CB_NOWARNDEF(var,name,doc) var = 1;
2464 #include "warning.def"
2465 #undef CB_WARNDEF
2466 #undef CB_NOWARNDEF
2467  break;
2468 
2469  default:
2470  cobc_err_exit (_("Invalid option detected"));
2471  }
2472  }
2473 
2474  /* Exit for configuration errors resulting from -cb_conf */
2475  if (conf_ret != 0) {
2476  cobc_free_mem ();
2477  exit (1);
2478  }
2479 
2480  if (list_reserved) {
2481  cb_list_reserved ();
2482  cobc_free_mem ();
2483  exit (0);
2484  }
2485 
2486  /* debug: Turn on all exception conditions */
2487  if (cobc_wants_debug) {
2488  for (i = (enum cob_exception_id)1; i < COB_EC_MAX; ++i) {
2489  CB_EXCEPTION_ENABLE (i) = 1;
2490  }
2491  if (verbose_output > 1) {
2492  fputs (_("All runtime checks are enabled"), stderr);
2493  fputc ('\n', stderr);
2494  }
2495  }
2496 
2497  /* If C debug, do not strip output */
2498  if (gflag_set) {
2499  strip_output = 0;
2500  }
2501 
2502  if (cb_flag_traceall) {
2503  cb_flag_trace = 1;
2504  cb_flag_source_location = 1;
2505  }
2506 
2507  return cob_optind;
2508 }
2509 
2510 /* Reverse the list of programs */
2511 static struct cb_program *
2513 {
2514  struct cb_program *next;
2515  struct cb_program *last;
2516 
2517  last = NULL;
2518  for (; p; p = next) {
2519  next = p->next_program;
2520  p->next_program = last;
2521  last = p;
2522  }
2523  return last;
2524 }
2525 
2526 static void
2527 process_env_copy_path (const char *p)
2528 {
2529  char *value;
2530  char *token;
2531  struct stat st;
2532 
2533  if (p == NULL || !*p || *p == ' ') {
2534  return;
2535  }
2536 
2537  /* Clone value for destructive strtok */
2538  value = cobc_strdup (p);
2539 
2540  /* Tokenize for path sep. */
2541  token = strtok (value, PATHSEP_STR);
2542  while (token) {
2543  if (!stat (token, &st) && (S_ISDIR (st.st_mode))) {
2544  CB_TEXT_LIST_CHK (cb_include_list, token);
2545  }
2546  token = strtok (NULL, PATHSEP_STR);
2547  }
2548 
2549  cobc_free (value);
2550  return;
2551 }
2552 
2553 #if defined (_MSC_VER) || defined(__OS400__) || defined(__WATCOMC__) || defined(__BORLANDC__)
2554 static void
2555 file_stripext (char *buff)
2556 {
2557  char *endp;
2558 
2559  endp = buff + strlen (buff) - 1U;
2560  while (endp > buff) {
2561  if (*endp == '/' || *endp == '\\') {
2562  break;
2563  }
2564  if (*endp == '.') {
2565  *endp = 0;
2566  }
2567  --endp;
2568  }
2569 }
2570 #endif
2571 
2572 static char *
2574 {
2575  const char *p;
2576  const char *startp;
2577  const char *endp;
2578  size_t len;
2579 
2580  if (!filename) {
2581  cobc_abort_pr (_("Call to '%s' with invalid parameter '%s'"),
2582  "file_basename", "filename");
2583  COBC_ABORT ();
2584  }
2585 
2586  /* Remove directory name */
2587  startp = NULL;
2588  for (p = filename; *p; p++) {
2589  if (*p == '/' || *p == '\\') {
2590  startp = p;
2591  }
2592  }
2593  if (startp) {
2594  startp++;
2595  } else {
2596  startp = filename;
2597  }
2598 
2599  /* Remove extension */
2600  endp = strrchr (filename, '.');
2601  if (endp > startp) {
2602  len = endp - startp;
2603  } else {
2604  len = strlen (startp);
2605  }
2606 
2607  if (len >= basename_len) {
2608  basename_len = len + 16;
2610  }
2611  /* Copy base name */
2612  memcpy (basename_buffer, startp, len);
2613  basename_buffer[len] = 0;
2614  return basename_buffer;
2615 }
2616 
2617 static const char *
2619 {
2620  const char *p;
2621 
2622  p = strrchr (filename, '.');
2623  if (p) {
2624  return p + 1;
2625  }
2626  return "";
2627 }
2628 
2629 static struct filename *
2631 {
2632  const char *extension;
2633  struct filename *fn;
2634  struct filename *ffn;
2635  char *fbasename;
2636  char *listptr;
2637  size_t fsize;
2638  int file_is_stdin;
2639 
2640  if (strcmp(filename, COB_DASH) == 0) {
2641  if (cobc_seen_stdin == 0) {
2642  cobc_seen_stdin = 1;
2643  file_is_stdin = 1;
2644  filename = COB_DASH_NAME;
2645  } else {
2646  cobc_abort_pr (_("Only one stdin input allowed"));
2647  return NULL;
2648  }
2649  } else {
2650  file_is_stdin = 0;
2651  }
2652 
2653  fsize = strlen (filename);
2654  if (fsize > COB_NORMAL_MAX) {
2655  cobc_abort_pr (_("Invalid file name parameter"));
2656  return NULL;
2657  }
2658 
2659 #ifdef __OS400__
2660  if (strchr (filename, '.') != NULL) {
2661 #endif
2662 
2663  if (!file_is_stdin && access (filename, R_OK) != 0) {
2664  cobc_terminate (filename);
2665  }
2666 
2667 #ifdef __OS400__
2668  }
2669 #endif
2670 
2671  fbasename = file_basename (filename);
2672  extension = file_extension (filename);
2673  if (strcmp(extension, "lib") && strcmp(extension, "a") &&
2674  strcmp(extension, COB_OBJECT_EXT)) {
2675  if (cobc_check_valid_name (fbasename, 0)) {
2676  return NULL;
2677  }
2678  }
2679  fn = cobc_main_malloc (sizeof (struct filename));
2680  fn->need_preprocess = 1;
2681  fn->need_translate = 1;
2682  fn->need_assemble = 1;
2684  fn->next = NULL;
2685 
2686  if (!file_list) {
2687  file_list = fn;
2688  } else {
2689  for (ffn = file_list; ffn->next; ffn = ffn->next)
2690  ;
2691  ffn->next = fn;
2692  }
2693 
2694  fn->demangle_source = cb_encode_program_id (fbasename);
2695 
2696  /* Check input file type */
2697  if (strcmp (extension, "i") == 0) {
2698  /* Already preprocessed */
2699  fn->need_preprocess = 0;
2700  } else if (strcmp (extension, "c") == 0 ||
2701  strcmp (extension, "s") == 0) {
2702  /* Already compiled */
2703  fn->need_preprocess = 0;
2704  fn->need_translate = 0;
2705  }
2706  else if (
2707 #if defined(__OS400__)
2708  extension[0] == 0
2709 #else
2710  strcmp (extension, COB_OBJECT_EXT) == 0
2711 #if defined(_WIN32)
2712  || strcmp(extension, "lib") == 0
2713 #endif
2714 #if !defined(_WIN32) || defined(__MINGW32__) || defined(__MINGW64__)
2715  || strcmp(extension, "a") == 0
2716  || strcmp(extension, "so") == 0
2717  || strcmp(extension, "dylib") == 0
2718  || strcmp(extension, "sl") == 0
2719 #endif
2720 #endif
2721  ) {
2722  /* Already assembled */
2723  fn->need_preprocess = 0;
2724  fn->need_translate = 0;
2725  fn->need_assemble = 0;
2726  }
2727 
2728  /* Set source filename */
2729  fn->source = cobc_main_strdup (filename);
2730 
2731  /* Set preprocess filename */
2732  if (!fn->need_preprocess) {
2733  fn->preprocess = cobc_main_strdup (fn->source);
2736  } else if (save_all_src || save_temps ||
2738  fn->preprocess = cobc_stradd_dup (fbasename, ".i");
2739  } else {
2741  cob_temp_name ((char *)fn->preprocess, ".cob");
2742  }
2743 
2744  /* Set translate filename */
2745  if (!fn->need_translate) {
2746  fn->translate = cobc_main_strdup (fn->source);
2747  } else if (output_name && cb_compile_level == CB_LEVEL_TRANSLATE) {
2749  } else if (save_all_src || save_temps || save_c_src ||
2751  fn->translate = cobc_stradd_dup (fbasename, ".c");
2752  } else {
2754  cob_temp_name ((char *)fn->translate, ".c");
2755  }
2756  fn->translate_len = strlen (fn->translate);
2757 
2758  /* Set storage filename */
2759  if (fn->need_translate) {
2760  fn->trstorage = cobc_stradd_dup (fn->translate, ".h");
2761  }
2762 
2763  /* Set object filename */
2764  if (!fn->need_assemble) {
2765  fn->object = cobc_main_strdup (fn->source);
2766  } else if (output_name && cb_compile_level == CB_LEVEL_ASSEMBLE) {
2768  } else if (save_temps || cb_compile_level == CB_LEVEL_ASSEMBLE) {
2769  fn->object = cobc_stradd_dup(fbasename, "." COB_OBJECT_EXT);
2770  } else {
2772  cob_temp_name ((char *)fn->object, "." COB_OBJECT_EXT);
2773  }
2774  fn->object_len = strlen (fn->object);
2775  cobc_objects_len += fn->object_len + 8U;
2776 
2777  /* Set listing filename */
2778  if (cobc_gen_listing == 1) {
2779  if (cobc_list_file) {
2781  } else if (cobc_list_dir) {
2782  fsize = strlen (cobc_list_dir) + strlen (fbasename) + 8U;
2783  listptr = cobc_main_malloc (fsize);
2784  snprintf (listptr, fsize, "%s%c%s.lst",
2785  cobc_list_dir, SLASH_CHAR, fbasename);
2786  fn->listing_file = listptr;
2787  } else {
2788  fn->listing_file = cobc_stradd_dup (fbasename, ".lst");
2789  }
2790  } else if (cobc_gen_listing > 1) {
2791  fn->listing_file = cobc_stradd_dup (fbasename, ".xrf");
2792  }
2793 
2795  return fn;
2796 }
2797 
2798 #ifdef _MSC_VER
2799 /*
2800  * search_pattern can contain one or more search strings separated by '|'
2801  * search_patterns must have a final '|'
2802  */
2803 static int
2804 line_contains (char* line_start, char* line_end, char* search_patterns) {
2805  int pattern_end, pattern_start, pattern_length, full_length;
2806  char* line_pos;
2807 
2808  if (search_patterns == NULL) return 0;
2809 
2810  pattern_start = 0;
2811  full_length = (int)strlen (search_patterns) - 1;
2812  for (pattern_end = 0; pattern_end < (int)strlen(search_patterns); pattern_end++) {
2813  if (search_patterns[pattern_end] == PATTERN_DELIM) {
2814  pattern_length = pattern_end - pattern_start;
2815  for (line_pos = line_start; line_pos + pattern_length <= line_end; line_pos++) {
2816  /* Find matching substring */
2817  if (memcmp (line_pos, search_patterns + pattern_start, pattern_length) == 0) {
2818  /* Exit if all patterns found, skip to next pattern otherwise */
2819  if (pattern_start + pattern_length == full_length) {
2820  return 1;
2821  } else {
2822  break;
2823  }
2824  }
2825  }
2826  pattern_start = pattern_end + 1;
2827  }
2828  }
2829 
2830  return 0;
2831 }
2832 #endif
2833 
2834 /** -j run job after build */
2835 static int
2836 process_run (const char *name) {
2837  int ret;
2838 
2840  fputs (_("Nothing for -j to run"), stderr);
2841  fflush (stderr);
2842  return 0;
2843  }
2844 
2847  snprintf (cobc_buffer, cobc_buffer_size, "cobcrun %s",
2848  file_basename(name));
2849  } else { /* executable */
2850  snprintf (cobc_buffer, cobc_buffer_size, ".%c%s",
2851  SLASH_CHAR, name);
2852  }
2854  if (verbose_output) {
2856  }
2857  ret = system (cobc_buffer);
2858  if (verbose_output) {
2859  fputs (_("Return status:"), stderr);
2860  fprintf (stderr, "\t%d\n", ret);
2861  fflush (stderr);
2862  }
2863  return ret;
2864 }
2865 
2866 #ifdef __OS400__
2867 static int
2868 process (char *cmd)
2869 {
2870  char *buffptr;
2871  char *name = NULL;
2872  char *objname = NULL;
2873  char *cobjname = NULL;
2874  char *token;
2875  char *incl[100];
2876  char *defs[100];
2877  char *objs[100];
2878  char *libs[100];
2879  char *optc[100];
2880  char *optl[100];
2881  int nincl = 0;
2882  int ndefs = 0;
2883  int nobjs = 0;
2884  int nlibs = 0;
2885  int noptc = 0;
2886  int noptl = 0;
2887  int dbg = 0;
2888  int comp_only = 0;
2889  int shared = 0;
2890  int optimize = 0;
2891  int i;
2892  int len;
2893  int ret;
2894 
2895  if (verbose_output) {
2896  cobc_cmd_print (cmd);
2897  }
2898  if (gflag_set) {
2899  dbg = 1;
2900  }
2901  token = strtok (cmd, " ");
2902  if (token != NULL) {
2903  /* Skip C compiler */
2904  token = strtok (NULL, " ");
2905  }
2906  for (; token; token = strtok (NULL, " ")) {
2907  if (*token != '-') {
2908  len = strlen (token);
2909  if (*token == '"') {
2910  len -= 2;
2911  ++token;
2912  token[len] = 0;
2913  }
2914  if (token[len-2] == '.' && token[len-1] == 'c') {
2915  /* C source */
2916  name = token;
2917  continue;
2918  }
2919  /* Assuming module */
2920  objs[nobjs++] = token;
2921  continue;
2922  }
2923  ++token;
2924  switch (*token) {
2925  case 'c':
2926  comp_only = 1;
2927  break;
2928  case 'I':
2929  ++token;
2930  if (*token == 0) {
2931  token = strtok (NULL, " ");
2932  }
2933  if (*token == '"') {
2934  ++token;
2935  token[strlen(token) - 1] = 0;
2936  }
2937  incl[nincl++] = token;
2938  break;
2939  case 'D':
2940  ++token;
2941  if (*token == 0) {
2942  token = strtok (NULL, " ");
2943  }
2944  if (*token == '"') {
2945  ++token;
2946  token[strlen(token) - 1] = 0;
2947  }
2948  defs[ndefs++] = token;
2949  break;
2950  case 'A':
2951  ++token;
2952  optc[noptc++] = token;
2953  break;
2954  case 'Q':
2955  ++token;
2956  optl[noptl++] = token;
2957  break;
2958  case 'o':
2959  ++token;
2960  if (*token == 0) {
2961  token = strtok (NULL, " ");
2962  }
2963  if (*token == '"') {
2964  ++token;
2965  token[strlen(token) - 1] = 0;
2966  }
2967  objname = token;
2968  break;
2969  case 'l':
2970  ++token;
2971  if (*token == 0) {
2972  token = strtok (NULL, " ");
2973  }
2974  libs[nlibs++] = token;
2975  break;
2976  case 'G':
2977  shared = 1;
2978  break;
2979  case 'g':
2980  dbg = 1;
2981  break;
2982  case 'O':
2983  optimize = 1;
2984  break;
2985  default:
2986  cobc_abort_pr (_("Unknown option ignored:\t%s"),
2987  token - 1);
2988  }
2989  }
2990 
2991  buffptr = cobc_malloc (COB_LARGE_BUFF);
2992  if (name != NULL) {
2993  /* Requires compilation */
2994  if (objname == NULL) {
2995  cobjname = file_basename (name);
2996  } else {
2997  cobjname = objname;
2998  }
2999  sprintf(buffptr, "CRTCMOD MODULE(%s) SRCSTMF('%s') ",
3000  cobjname, name);
3001  if (nincl > 0) {
3002  strcat (buffptr, "INCDIR(");
3003  for (i = 0; i < nincl; ++i) {
3004  if (i != 0) {
3005  strcat (buffptr, " ");
3006  }
3007  strcat (buffptr, "'");
3008  strcat (buffptr, incl[i]);
3009  strcat (buffptr, "' ");
3010  }
3011  strcat (buffptr, ") ");
3012  }
3013  if (ndefs > 0) {
3014  strcat (buffptr, "DEFINE(");
3015  for (i = 0; i < ndefs; ++i) {
3016  if (i != 0) {
3017  strcat (buffptr, " ");
3018  }
3019  strcat (buffptr, "'");
3020  strcat (buffptr, defs[i]);
3021  strcat (buffptr, "' ");
3022  }
3023  strcat (buffptr, ") ");
3024  }
3025  strcat (buffptr, "SYSIFCOPT(*IFSIO)");
3026  for (i = 0; i < noptc; ++i) {
3027  strcat (buffptr, " ");
3028  strcat (buffptr, optc[i]);
3029  }
3030  if (optimize) {
3031  strcat (buffptr, " OPTIMIZE(40)");
3032  }
3033  if (dbg) {
3034  strcat (buffptr, " DBGVIEW(*ALL)");
3035  }
3036  if (cobc_gen_listing) {
3037  strcat (buffptr, " OUTPUT(*PRINT)");
3038  }
3039  if (verbose_output) {
3040  cobc_cmd_print (buffptr);
3041  }
3042  ret = system (buffptr);
3043  if (verbose_output) {
3044  fputs (_("Return status:"), stderr);
3045  fprintf (stderr, "\t%d\n", ret);
3046  fflush (stderr);
3047  }
3048  if (comp_only || ret != 0) {
3049  cobc_free (buffptr);
3050  return ret;
3051  }
3052  }
3053  if (objname == NULL) {
3054  if (name != NULL) {
3055  objname = cobjname;
3056  } else if (nobjs > 0) {
3057  objname = objs[0];
3058  } else {
3059  objname = (char *)"AOUT";
3060  }
3061  }
3062  if (shared) {
3063  sprintf(buffptr, "CRTSRVPGM SRVPGM(%s) MODULE(", objname);
3064  } else {
3065  sprintf(buffptr, "CRTPGM PGM(%s) MODULE(", objname);
3066  }
3067  if (name != NULL) {
3068  strcat (buffptr, cobjname);
3069  }
3070  for (i = 0; i < nobjs; ++i) {
3071  if (i != 0 || name != NULL) {
3072  strcat (buffptr, " ");
3073  }
3074  strcat (buffptr, objs[i]);
3075  }
3076  strcat (buffptr, ")");
3077  if (nlibs > 0) {
3078  strcat (buffptr, " BNDSRVPGM(");
3079  for (i = 0; i < nlibs; ++i) {
3080  if (i != 0) {
3081  strcat (buffptr, " ");
3082  }
3083  strcat (buffptr, libs[i]);
3084  }
3085  strcat (buffptr, ")");
3086  }
3087  for (i = 0; i < noptl; ++i) {
3088  strcat (buffptr, " ");
3089  strcat (buffptr, optl[i]);
3090  }
3091  if (shared) {
3092  strcat (buffptr, " EXPORT(*ALL)");
3093  }
3094  if (verbose_output) {
3095  cobc_cmd_print (buffptr);
3096  }
3097  ret = system (buffptr);
3098  if (verbose_output) {
3099  fputs (_("Return status:"), stderr);
3100  fprintf (stderr, "\t%d\n", ret);
3101  fflush (stderr);
3102  }
3103  cobc_free (buffptr);
3104 
3105  if ((ret == 0) && cobc_flag_run) {
3106  ret = process_run (name);
3107  }
3108  return ret;
3109 }
3110 
3111 #elif defined(_MSC_VER)
3112 static int
3113 process (const char *cmd)
3114 {
3115  int ret;
3116 
3117  if (verbose_output) {
3118  cobc_cmd_print (cmd);
3119  }
3120  ret = system (cmd);
3121  if (verbose_output) {
3122  fputs (_ ("Return status:"), stderr);
3123  fprintf (stderr, "\t%d\n", ret);
3124  fflush (stderr);
3125  }
3126  return !!ret;
3127 }
3128 
3129 static int
3130 process_filtered (const char *cmd, struct filename *fn)
3131 {
3132  FILE* pipe;
3133  char* read_buffer;
3134  char *line_start, *line_end;
3135  char* search_pattern, *search_pattern2 = NULL;
3136  char* output_name_temp;
3137  int i;
3138 
3139  /* Open pipe to catch output of cl.exe */
3140  pipe = _popen(cmd, "r");
3141 
3142  if (!pipe) {
3143  return !!-1; /* checkme */
3144  }
3145 
3146  /* building search_patterns */
3147  if (output_name) {
3148  output_name_temp = file_basename(output_name);
3149  } else {
3150  /* demangle_source is encoded and cannot be used
3151  -> set to file.something and strip at point
3152  */
3153  output_name_temp = cobc_strdup (fn->source);
3154  file_stripext(output_name_temp);
3155  }
3156 
3157  /* check for last path seperator as we only need the file name */
3158  for (i = fn->translate_len; i > 0; i--) {
3159  if (fn->translate[i - 1] == '\\' || fn->translate[i - 1] == '/') break;
3160  }
3161 
3162  search_pattern = (char*)cobc_malloc((fn->translate_len - i + 2) + 1);
3163  sprintf(search_pattern, "%s\n%c", fn->translate + i, PATTERN_DELIM);
3165  search_pattern2 = (char*)cobc_malloc (2 * (strlen (output_name_temp) + 5) + 1);
3166  sprintf (search_pattern2, "%s.lib%c%s.exp%c", file_basename(output_name_temp), PATTERN_DELIM,
3167  file_basename(output_name_temp), PATTERN_DELIM);
3168  }
3169 
3170  /* prepare buffer and read from pipe */
3171  read_buffer = (char*) cobc_malloc(COB_FILE_BUFF);
3172  line_start = fgets(read_buffer, COB_FILE_BUFF - 1, pipe);
3173 
3174  while (line_start != NULL) {
3175  /* read one line from buffer, returning line end position */
3176  line_end = line_start + strlen(line_start);
3177 
3178  /* if non of the patterns was found, print line */
3179  if (line_start == line_end
3180  || (!line_contains(line_start, line_end, search_pattern)
3181  && !line_contains(line_start, line_end, search_pattern2)))
3182  {
3183  fprintf(stdout, "%*s", (int)(line_end - line_start + 2), line_start);
3184  }
3185  line_start = fgets(read_buffer, COB_FILE_BUFF - 1, pipe);
3186  }
3187  fflush (stdout);
3188 
3189  cobc_free (read_buffer);
3190  cobc_free (search_pattern);
3191  cobc_free (search_pattern2);
3192 
3193  if (!output_name) cobc_free (output_name_temp);
3194 
3195  /* close pipe and get return code of cl.exe */
3196  return !!_pclose (pipe);
3197 }
3198 
3199 #else
3200 static int
3201 process (const char *cmd)
3202 {
3203  char *p;
3204  char *buffptr;
3205  size_t clen;
3206  int ret;
3207 
3208  if (likely(strchr (cmd, '$') == NULL)) {
3209  buffptr = (char *)cmd;
3210  } else {
3211  clen = strlen (cmd) + 64U;
3212  clen = clen + 6U;
3213  buffptr = (char *)cobc_malloc (clen);
3214  p = buffptr;
3215  /* Quote '$' */
3216  for (; *cmd; ++cmd) {
3217  if (*cmd == '$') {
3218  p += sprintf (p, "\\$");
3219  } else {
3220  *p++ = *cmd;
3221  }
3222  }
3223  *p = 0;
3224  }
3225 
3226  if (verbose_output) {
3227  cobc_cmd_print (buffptr);
3228  }
3229 
3230  ret = system (buffptr);
3231 
3232  if (unlikely(buffptr != cmd)) {
3233  cobc_free (buffptr);
3234  }
3235 
3236 #ifdef WIFSIGNALED
3237  if (WIFSIGNALED(ret)) {
3238 #ifdef SIGINT
3239  if (WTERMSIG(ret) == SIGINT) {
3240  cobc_sig_handler (SIGINT);
3241  }
3242 #endif
3243 #ifdef SIGQUIT
3244  if (WTERMSIG(ret) == SIGQUIT) {
3245  cobc_sig_handler (SIGQUIT);
3246  }
3247 #endif
3248  }
3249 #endif
3250  if (verbose_output) {
3251  fputs (_("Return status:"), stderr);
3252  fprintf (stderr, "\t%d\n", ret);
3253  fflush (stderr);
3254  }
3255  return !!ret;
3256 }
3257 #endif
3258 
3259 /* Preprocess source */
3260 
3261 static int
3262 preprocess (struct filename *fn)
3263 {
3264  struct cobc_mem_struct *m;
3265  struct cobc_mem_struct *ml;
3266  const char *sourcename;
3267  int save_source_format;
3268  int save_fold_copy;
3269  int save_fold_call;
3270  int ret;
3271 
3272  errorcount = 0;
3273 
3274  ppout = fopen (fn->preprocess, "w");
3275  if (!ppout) {
3276  cobc_terminate (fn->preprocess);
3277  }
3278 
3279  if (fn->file_is_stdin) {
3280  sourcename = COB_DASH;
3281  } else {
3282  sourcename = fn->source;
3283  }
3284  if (ppopen (sourcename, NULL) != 0) {
3285  fclose (ppout);
3286  ppout = NULL;
3287  if (fn->preprocess) {
3288  (void)unlink (fn->preprocess);
3289  }
3290  cobc_free_mem ();
3291  exit (1);
3292  }
3293 
3294  if (verbose_output) {
3295  fputs (_("Preprocessing:"), stderr);
3296  fprintf (stderr, "\t%s -> %s\n",
3297  sourcename, fn->preprocess);
3298  fflush (stderr);
3299  }
3300 
3301  if (cobc_gen_listing && !cobc_list_file) {
3302  cb_listing_file = fopen (fn->listing_file, "w");
3303  if (!cb_listing_file) {
3305  }
3306  }
3307 
3308  /* Reset pplex/ppparse variables */
3309  plex_clear_vars ();
3310  ppparse_clear_vars (cb_define_list);
3311 
3312  /* Save default flags in case program directives change them */
3313  save_source_format = cb_source_format;
3314  save_fold_copy = cb_fold_copy;
3315  save_fold_call = cb_fold_call;
3316 
3317  /* Preprocess */
3318  ppparse ();
3319 
3320  /* Restore default flags */
3321  cb_source_format = save_source_format;
3322  cb_fold_copy = save_fold_copy;
3323  cb_fold_call = save_fold_call;
3324 
3325  if (ppin) {
3326  fclose (ppin);
3327  ppin = NULL;
3328  }
3329 
3330  if (ppout) {
3331  if (unlikely(fclose(ppout) != 0)) {
3333  }
3334  ppout = NULL;
3335  }
3336 
3337  /* Release flex buffers - After file close */
3338  plex_call_destroy ();
3339 
3340  for (m = cobc_plexmem_base; m; ) {
3341  ml = m;
3342  m = m->next;
3343  cobc_free (ml);
3344  }
3345  cobc_plexmem_base = NULL;
3346 
3347  if (cobc_gen_listing && !cobc_list_file) {
3348  if (unlikely(fclose (cb_listing_file) != 0)) {
3350  }
3351  if (cobc_gen_listing > 1) {
3352  snprintf (cobc_buffer, cobc_buffer_size,
3353  "cobxref %s -R", fn->listing_file);
3355  if (verbose_output) {
3357  }
3358  ret = system (cobc_buffer);
3359  if (verbose_output) {
3360  fputs (_("Return status:"), stderr);
3361  fprintf (stderr, "\t%d\n", ret);
3362  fflush (stderr);
3363  }
3364  if (ret) {
3365  fputs (_("'cobxref' execution unsuccessful"),
3366  stderr);
3367  putc ('\n', stderr);
3368 #ifdef _WIN32
3369  fprintf (stderr, _("Check that 'cobxref' is in %s"),
3370  "%%PATH%%");
3371 #else
3372  fprintf (stderr, _("Check that 'cobxref' is in %s"),
3373  "$PATH");
3374 #endif
3375  putc ('\n', stderr);
3376  fputs (_("No listing produced"),
3377  stderr);
3378  putc ('\n', stderr);
3379  fflush (stderr);
3380  }
3381  unlink (fn->listing_file);
3382  }
3384  }
3385 
3386  if (verbose_output) {
3387  fputs (_("Return status:"), stderr);
3388  fprintf (stderr, "\t%d\n", errorcount);
3389  fflush (stderr);
3390  }
3391  return !!errorcount;
3392 }
3393 
3394 /* Create single-element C source */
3395 
3396 static int
3398 {
3399  struct cb_program *p;
3400  struct cb_program *q;
3401  struct cb_program *r;
3402  struct nested_list *nlp;
3403  struct handler_struct *hstr1;
3404  struct handler_struct *hstr2;
3405  struct local_filename *lf;
3406  int ret;
3407  int i;
3408 
3409  /* Initialize */
3410  cb_source_file = NULL;
3411  cb_source_line = 0;
3412  errorcount = 0;
3413 
3414  /* Open the input file */
3415  yyin = fopen (fn->preprocess, "r");
3416  if (!yyin) {
3417  cobc_terminate (fn->preprocess);
3418  }
3419 
3420  if (verbose_output) {
3421  fputs (_("Parsing:"), stderr);
3422  fprintf (stderr, "\t%s (%s)\n", fn->preprocess, fn->source);
3423  fflush (stderr);
3424  }
3425 
3427  cb_init_constants ();
3428 
3429  /* Parse */
3430  ret = yyparse ();
3431 
3432  fclose (yyin);
3433  yyin = NULL;
3434 
3435  /* Release flex buffers - After file close */
3436  ylex_call_destroy ();
3437 
3438  if (verbose_output) {
3439  fputs (_("Return status:"), stderr);
3440  fprintf (stderr, "\t%d\n", ret);
3441  fflush (stderr);
3442  }
3443 
3444  if (ret || cb_flag_syntax_only) {
3445  return !!ret;
3446  }
3448  return 0;
3449  }
3450 
3451  /* Set up USE GLOBAL handlers */
3452  p = current_program;
3453  for (q = p; q; q = q->next_program) {
3455  if (q->nested_level) {
3456  for (r = q->next_program; r; r = r->next_program) {
3457  if (r->nested_level >= q->nested_level) {
3458  continue;
3459  }
3460  for (i = COB_OPEN_INPUT; i <= COB_OPEN_EXTEND; ++i) {
3461  hstr1 = &q->global_handler[i];
3462  hstr2 = &r->global_handler[i];
3463  if (!hstr1->handler_label &&
3464  hstr2->handler_label &&
3465  hstr2->handler_label->flag_global) {
3466  hstr1->handler_label = hstr2->handler_label;
3467  hstr1->handler_prog = r;
3468  }
3469  }
3470  if (!r->nested_level) {
3471  break;
3472  }
3473  }
3474  }
3475  }
3476 
3477  if (verbose_output) {
3478  fputs (_("Translating:"), stderr);
3479  fprintf (stderr, "\t%s -> %s (%s)\n",
3480  fn->preprocess, fn->translate, fn->source);
3481  fflush (stderr);
3482  }
3483 
3484  /* Open the output file */
3485  yyout = fopen (fn->translate, "w");
3486  if (!yyout) {
3487  cobc_terminate (fn->translate);
3488  }
3489 
3490  /* Open the common storage file */
3492  cb_storage_file = fopen (cb_storage_file_name, "w");
3493  if (!cb_storage_file) {
3495  }
3496 
3498 
3499  /* Set up local storage files */
3500  lf = NULL;
3501  ret = 1;
3502  for (q = p; q; q = q->next_program, ret++) {
3503  lf = cobc_main_malloc (sizeof(struct local_filename));
3504  lf->local_name = cobc_main_malloc (fn->translate_len + 12U);
3505  if (q == p && !q->next_program) {
3506  sprintf (lf->local_name, "%s.l.h", fn->translate);
3507  } else {
3508  sprintf (lf->local_name, "%s.l%d.h", fn->translate, ret);
3509  }
3510  lf->local_fp = fopen (lf->local_name, "w");
3511  if (!lf->local_fp) {
3512  cobc_terminate (lf->local_name);
3513  }
3514  q->local_include = lf;
3515  lf->next = fn->localfile;
3516  fn->localfile = lf;
3517  }
3518 
3519  /* Entries for COMMON programs */
3520  for (q = p; q; q = q->next_program) {
3521  i = q->nested_level;
3522  for (nlp = q->common_prog_list; nlp; nlp = nlp->next) {
3523  for (r = q->next_program; r; r = r->next_program) {
3524  if (r->nested_level <= i) {
3525  break;
3526  }
3528  }
3529  }
3530  }
3531 
3532  errorcount = 0;
3533  /* Translate to C */
3534  codegen (p, 0);
3535 
3536  /* Close files */
3537  if(unlikely(fclose (cb_storage_file) != 0)) {
3539  }
3541  if(unlikely(fclose (yyout) != 0)) {
3542  cobc_terminate (fn->translate);
3543  }
3544  yyout = NULL;
3545  for (q = p; q; q = q->next_program) {
3546  if (unlikely(!q->local_include->local_fp)) {
3547  continue;
3548  }
3549  if (unlikely(fclose (q->local_include->local_fp) != 0)) {
3551  }
3552  q->local_include->local_fp = NULL;
3553  }
3554  return !!errorcount;
3555 }
3556 
3557 /* Create single-element assembly source */
3558 
3559 static int
3561 {
3562  char *name;
3563  size_t bufflen;
3564  size_t size;
3565 
3566  if (output_name) {
3567  name = output_name;
3568  } else {
3569  name = file_basename (fn->source);
3570 #ifndef _MSC_VER
3571  strcat (name, ".s");
3572 #endif
3573  }
3574  size = strlen (name);
3575 #ifdef _MSC_VER
3576  size *= 2U;
3577 #endif
3578 
3579  bufflen = cobc_cc_len + cobc_cflags_len
3580  + size + fn->translate_len
3581  + cobc_include_len + 64U;
3582 
3583  cobc_chk_buff_size (bufflen);
3584 
3585 #ifdef _MSC_VER
3586  sprintf (cobc_buffer, gflag_set ?
3587  "%s /c %s %s /Od /MDd /Zi /FR /c /Fa\"%s\" /Fo\"%s\" \"%s\"" :
3588  "%s /c %s %s /MD /c /Fa\"%s\" /Fo\"%s\" \"%s\"",
3590  name, fn->translate);
3591  if (verbose_output) {
3592  return process (cobc_buffer);
3593  } else {
3594  return process_filtered (cobc_buffer, fn);
3595  }
3596 #elif defined(__WATCOMC__)
3597  sprintf (cobc_buffer, "%s -fe=\"%s\" -s %s %s %s", cobc_cc, name,
3599  return process (cobc_buffer);
3600 #else
3601  sprintf (cobc_buffer, "%s -S -o \"%s\" %s %s %s", cobc_cc, name,
3603  return process(cobc_buffer);
3604 #endif
3605 
3606 }
3607 
3608 /* Create single-element assembled object */
3609 
3610 static int
3612 {
3613 #ifndef _MSC_VER
3614  int ret;
3615 #endif
3616  size_t bufflen;
3617 #ifdef __OS400__
3618  char *name;
3619 #endif
3620 
3621  bufflen = cobc_cc_len + cobc_cflags_len + fn->object_len
3623  + cobc_pic_flags_len + 64U;
3624 
3625  cobc_chk_buff_size (bufflen);
3626 
3627 #ifdef _MSC_VER
3628  sprintf (cobc_buffer, gflag_set ?
3629  "%s /c %s %s /Od /MDd /Zi /FR /Fo\"%s\" \"%s\"" :
3630  "%s /c %s %s /MD /Fo\"%s\" \"%s\"",
3632  fn->object, fn->translate);
3633  if (verbose_output) {
3634  return process (cobc_buffer);
3635  } else {
3636  return process_filtered (cobc_buffer, fn);
3637  }
3638 #elif defined(__OS400__)
3639  name = (char *) fn->translate;
3640  if (name[0] != '/') {
3641  char *p;
3642 
3644  getcwd (p, COB_LARGE_BUFF);
3645  strcat (p, "/");
3646  strcat (p, name);
3647  name = p;
3648  }
3649  file_stripext ((char *) fn->object);
3650  sprintf (cobc_buffer, "%s -c %s %s -o %s %s",
3652  fn->object, name);
3653  ret = process (cobc_buffer);
3654  if ((ret == 0) && cobc_flag_run) {
3655  ret = process_run (name);
3656  }
3657  return ret;
3658 #elif defined(__WATCOMC__)
3661  sprintf (cobc_buffer, "%s -c %s %s %s -fe=\"%s\" \"%s\"",
3663  COB_PIC_FLAGS, fn->object, fn->translate);
3664  } else {
3665  sprintf (cobc_buffer, "%s -c %s %s -fe=\"%s\" \"%s\"",
3667  fn->object, fn->translate);
3668  }
3669  ret = process (cobc_buffer);
3670  if ((ret == 0) && cobc_flag_run) {
3671  ret = process_run (fn->object);
3672  }
3673  return ret;
3674 #else
3678  sprintf (cobc_buffer, "%s -c %s %s %s -o \"%s\" \"%s\"",
3680  COB_PIC_FLAGS, fn->object, fn->translate);
3681  } else {
3682  // Only for CB_LEVEL_EXECUTABLE
3683  sprintf (cobc_buffer, "%s -c %s %s -o \"%s\" \"%s\"",
3685  fn->object, fn->translate);
3686  }
3687  ret = process (cobc_buffer);
3688  return ret;
3689 #endif
3690 
3691 }
3692 
3693 /* Create single-element loadable object without intermediate stages */
3694 
3695 static int
3697 {
3698  char *name;
3699 #ifdef _MSC_VER
3700  char *exename;
3701 #endif
3702  size_t bufflen;
3703  size_t size;
3704  int ret;
3705 
3706  if (output_name) {
3707  name = output_name_buff;
3708  strcpy (name, output_name);
3709 #if defined(_MSC_VER) || defined(__OS400__) || defined(__WATCOMC__) || defined(__BORLANDC__)
3710  file_stripext (name);
3711 #else
3712  if (strchr (output_name, '.') == NULL) {
3713  strcat (name, ".");
3714  strcat (name, COB_MODULE_EXT);
3715  }
3716 #endif
3717  } else {
3718  name = file_basename (fn->source);
3719 #if !defined(_MSC_VER) && !defined(__OS400__) && !defined(__WATCOMC__) && !defined(__BORLANDC__)
3720  strcat (name, ".");
3721  strcat (name, COB_MODULE_EXT);
3722 #endif
3723  }
3724 #ifdef _MSC_VER
3725  exename = cobc_stradd_dup (name, ".dll");
3726 #endif
3727 
3728  size = strlen (name);
3729 #ifdef _MSC_VER
3730  size *= 2U;
3731 #endif
3732 
3733  bufflen = cobc_cc_len + cobc_cflags_len
3735  + size + fn->translate_len
3737 #ifdef _MSC_VER
3738  + manilink_len
3739 #endif
3741 
3742  cobc_chk_buff_size (bufflen);
3743 
3744 #ifdef _MSC_VER
3745  sprintf (cobc_buffer, gflag_set ?
3746  "%s %s %s /Od /MDd /LDd /Zi /FR /Fe\"%s\" /Fo\"%s\" \"%s\" %s %s %s %s" :
3747  "%s %s %s /MD /LD /Fe\"%s\" /Fo\"%s\" \"%s\" %s %s %s %s",
3748  cobc_cc, cobc_cflags, cobc_include, exename, name,
3749  fn->translate,
3750  manilink, cobc_ldflags, cobc_libs, cobc_lib_paths);
3751  if (verbose_output) {
3752  ret = process (cobc_buffer);
3753  } else {
3754  ret = process_filtered (cobc_buffer, fn);
3755  }
3756 #if defined(_MSC_VER) && COB_USE_VC2005_OR_GREATER
3757  /* Embedding manifest */
3758  if (ret == 0) {
3759  sprintf (cobc_buffer,
3760  "%s /manifest \"%s.manifest\" /outputresource:\"%s\";#2",
3761  manicmd, exename, exename);
3762  ret = process (cobc_buffer);
3763  sprintf (cobc_buffer, "%s.manifest", exename);
3765  }
3766 #endif
3767  sprintf (cobc_buffer, "%s.exp", name);
3769  sprintf (cobc_buffer, "%s.lib", name);
3770  if (strstr(fn->source, cobc_buffer) == NULL) cobc_check_action (cobc_buffer);
3771  sprintf (cobc_buffer, "%s.%s", name, COB_OBJECT_EXT);
3772  if (strstr(fn->source, cobc_buffer) == NULL) cobc_check_action (cobc_buffer);
3773 #else /* _MSC_VER */
3774 #ifdef __OS400__
3775  if (fn->translate[0] != '/') {
3776  char *p;
3777 
3779  getcwd (p, COB_LARGE_BUFF);
3780  strcat (p, "/");
3781  strcat (p, fn->translate);
3782  fn->translate = p;
3783  fn->translate_len = strlen (p);
3784  }
3785 #endif
3786 #ifdef __WATCOMC__
3787  sprintf (cobc_buffer, "%s %s %s %s %s %s -fe=\"%s\" \"%s\" %s %s %s",
3791 #else
3792  sprintf (cobc_buffer, "%s %s %s %s %s %s -o \"%s\" \"%s\" %s %s %s",
3796 #endif
3797  ret = process (cobc_buffer);
3798 #ifdef COB_STRIP_CMD
3799  if (strip_output && ret == 0) {
3800  sprintf (cobc_buffer, "%s \"%s\"", COB_STRIP_CMD, name);
3801  ret = process (cobc_buffer);
3802  }
3803 #endif
3804 #endif /* _MSC_VER */
3805  if ((ret == 0) && cobc_flag_run) {
3806  ret = process_run (name);
3807  }
3808  return ret;
3809 }
3810 
3811 /* Create single-element loadable object */
3812 
3813 static int
3815 {
3816  char *name;
3817 #ifdef _MSC_VER
3818  char *exename;
3819 #endif
3820  size_t bufflen;
3821  size_t size;
3822  int ret;
3823 
3824  if (output_name) {
3825  name = output_name_buff;
3826  strcpy (name, output_name);
3827 #if defined(_MSC_VER) || defined(__OS400__) || defined(__WATCOMC__) || defined(__BORLANDC__)
3828  file_stripext (name);
3829 #else
3830  if (strchr (output_name, '.') == NULL) {
3831  strcat (name, ".");
3832  strcat (name, COB_MODULE_EXT);
3833  }
3834 #endif
3835  } else {
3836  name = file_basename (fn->source);
3837 #if !defined(_MSC_VER) && !defined(__OS400__) && !defined(__WATCOMC__) &&! defined(__BORLANDC__)
3838  strcat (name, ".");
3839  strcat (name, COB_MODULE_EXT);
3840 #endif
3841  }
3842 #ifdef _MSC_VER
3843  exename = cobc_stradd_dup (name, ".dll");
3844 #endif
3845 
3846  size = strlen (name);
3847  bufflen = cobc_cc_len + cobc_ldflags_len
3849  + size + fn->object_len + cobc_libs_len
3850 #ifdef _MSC_VER
3851  + manilink_len
3852 #endif
3854 
3855  cobc_chk_buff_size (bufflen);
3856 
3857 #ifdef _MSC_VER
3858  sprintf (cobc_buffer, gflag_set ?
3859  "%s /Od /MDd /LDd /Zi /FR /Fe\"%s\" \"%s\" %s %s %s %s" :
3860  "%s /MD /LD /Fe\"%s\" \"%s\" %s %s %s %s",
3861  cobc_cc, exename, fn->object,
3862  manilink, cobc_ldflags, cobc_libs, cobc_lib_paths);
3863  if (verbose_output) {
3864  ret = process (cobc_buffer);
3865  } else {
3866  ret = process_filtered (cobc_buffer, fn);
3867  }
3868 #if defined(_MSC_VER) && COB_USE_VC2005_OR_GREATER
3869  /* Embedding manifest */
3870  if (ret == 0) {
3871  sprintf (cobc_buffer,
3872  "%s /manifest \"%s.manifest\" /outputresource:\"%s\";#2",
3873  manicmd, exename, exename);
3874  ret = process (cobc_buffer);
3875  sprintf (cobc_buffer, "%s.manifest", exename);
3877  }
3878 #endif
3879  sprintf (cobc_buffer, "%s.exp", name);
3881  sprintf (cobc_buffer, "%s.lib", name);
3882  if (strstr(fn->source, cobc_buffer) == NULL) cobc_check_action (cobc_buffer);
3883  sprintf (cobc_buffer, "%s.obj", name);
3884  if (strstr(fn->source, cobc_buffer) == NULL) cobc_check_action (cobc_buffer);
3885 #else /* _MSC_VER */
3886 #ifdef __WATCOMC__
3887  sprintf (cobc_buffer, "%s %s %s %s -fe=\"%s\" \"%s\" %s %s %s",
3890 #else
3891  sprintf (cobc_buffer, "%s %s %s %s -o \"%s\" \"%s\" %s %s %s",
3894 #endif
3895  ret = process (cobc_buffer);
3896 #ifdef COB_STRIP_CMD
3897  if (strip_output && ret == 0) {
3898  sprintf (cobc_buffer, "%s %s", COB_STRIP_CMD, name);
3899  ret = process (cobc_buffer);
3900  }
3901 #endif
3902 #endif /* _MSC_VER */
3903  /* cobcrun job? */
3904  if ((ret == 0) && cobc_flag_run) {
3905  ret = process_run (name);
3906  }
3907  return ret;
3908 }
3909 
3910 /* Create multi-element loadable object */
3911 
3912 static int
3914 {
3915  struct filename *f;
3916  char *name;
3917 #ifdef _MSC_VER
3918  char *exename;
3919 #endif
3920  size_t bufflen;
3921  size_t size;
3922  int ret;
3923 
3924  if (!l) {
3925  cobc_abort_pr (_("Call to '%s' with invalid parameter '%s'"),
3926  "process_library", "l");
3927  COBC_ABORT ();
3928  }
3929 
3930  for (f = l; f; f = f->next) {
3931  strcat (cobc_objects_buffer, "\"");
3932  strcat (cobc_objects_buffer, f->object);
3933  strcat (cobc_objects_buffer, "\" ");
3934  }
3935 
3936  if (output_name) {
3937  name = output_name_buff;
3938  strcpy (name, output_name);
3939 #if defined(_MSC_VER) || defined(__OS400__) || defined(__WATCOMC__) || defined(__BORLANDC__)
3940  file_stripext (name);
3941 #else
3942  if (strchr (output_name, '.') == NULL) {
3943  strcat (name, ".");
3944  strcat (name, COB_MODULE_EXT);
3945  }
3946 #endif
3947  } else {
3948  name = file_basename (l->source);
3949 #if !defined(_MSC_VER) && !defined(__OS400__) && !defined(__WATCOMC__) && !defined(__BORLANDC__)
3950  strcat (name, ".");
3951  strcat (name, COB_MODULE_EXT);
3952 #endif
3953  }
3954 #ifdef _MSC_VER
3955  exename = cobc_stradd_dup (name, ".dll");
3956 #endif
3957 
3958  size = strlen (name);
3959  bufflen = cobc_cc_len + cobc_ldflags_len
3961  + size + cobc_objects_len + cobc_libs_len
3962 #ifdef _MSC_VER
3963  + manilink_len
3964 #endif
3966 
3967  cobc_chk_buff_size (bufflen);
3968 
3969 #ifdef _MSC_VER
3970  sprintf (cobc_buffer, gflag_set ?
3971  "%s /Od /MDd /LDd /Zi /FR /Fe\"%s\" %s %s %s %s %s" :
3972  "%s /MD /LD /Fe\"%s\" %s %s %s %s %s",
3973  cobc_cc, exename, cobc_objects_buffer,
3974  manilink, cobc_ldflags, cobc_libs, cobc_lib_paths);
3975  if (verbose_output) {
3976  ret = process (cobc_buffer);
3977  } else {
3978  ret = process_filtered (cobc_buffer, l);
3979  }
3980 #if defined(_MSC_VER) && COB_USE_VC2005_OR_GREATER
3981  /* Embedding manifest */
3982  if (ret == 0) {
3983  sprintf (cobc_buffer,
3984  "%s /manifest \"%s.manifest\" /outputresource:\"%s\";#2",
3985  manicmd, exename, exename);
3986  ret = process (cobc_buffer);
3987  sprintf (cobc_buffer, "%s.manifest", exename);
3989  }
3990 #endif
3991  sprintf (cobc_buffer, "%s.exp", name);
3993  sprintf (cobc_buffer, "%s.lib", name);
3994 
3995  for (f = l; f; f = f->next) {
3996  if (strstr (f->source, cobc_buffer) != NULL) {
3997  break;
3998  }
3999  }
4000  if (!f) cobc_check_action (cobc_buffer);
4001 #else /* _MSC_VER */
4002 #ifdef __WATCOMC__
4003  sprintf (cobc_buffer, "%s %s %s %s -fe=\"%s\" %s %s %s %s",
4007 #else
4008  sprintf (cobc_buffer, "%s %s %s %s -o \"%s\" %s %s %s %s",
4012 #endif
4013  ret = process (cobc_buffer);
4014 #ifdef COB_STRIP_CMD
4015  if (strip_output && ret == 0) {
4016  sprintf (cobc_buffer, "%s \"%s\"", COB_STRIP_CMD, name);
4017  ret = process (cobc_buffer);
4018  }
4019 #endif
4020 #endif /* _MSC_VER */
4021  /* cobcrun job? */
4022  if ((ret == 0) && cobc_flag_run) {
4023  ret = process_run (name);
4024  }
4025  return ret;
4026 }
4027 
4028 /* Create executable */
4029 
4030 static int
4032 {
4033  struct filename *f;
4034  const char *name;
4035 #ifdef _MSC_VER
4036  const char *exename;
4037 #endif
4038  size_t bufflen;
4039  size_t size;
4040  int ret;
4041 
4042  if (!l) {
4043  cobc_abort_pr (_("Call to '%s' with invalid parameter '%s'"),
4044  "process_link", "l");
4045  COBC_ABORT ();
4046  }
4047 
4048  for (f = l; f; f = f->next) {
4049 #ifdef __OS400__
4050  file_stripext ((char *) f->object);
4051  strcat (cobc_objects_buffer, f->object);
4052  strcat (cobc_objects_buffer, " ");
4053 #else
4054  strcat (cobc_objects_buffer, "\"");
4055  strcat (cobc_objects_buffer, f->object);
4056  strcat (cobc_objects_buffer, "\" ");
4057 #endif
4058  }
4059 
4060  if (output_name) {
4061 #if defined(_MSC_VER) || defined(__OS400__) || defined(__WATCOMC__) || defined(__BORLANDC__)
4062  name = cobc_main_strdup (output_name);
4063  file_stripext ((char *)name);
4064 #else
4065  name = output_name;
4066 #endif
4067  } else {
4068  if (l->file_is_stdin) {
4069  name = COB_DASH_OUT;
4070  } else {
4071  name = file_basename (l->source);
4072  }
4073  }
4074 #ifdef _MSC_VER
4075  exename = cobc_stradd_dup (name, ".exe");
4076 #endif
4077 
4078  size = strlen (name);
4079  bufflen = cobc_cc_len + cobc_ldflags_len
4080  + cobc_export_dyn_len + size
4082 #ifdef _MSC_VER
4083  + manilink_len
4084 #endif
4085  + cobc_lib_paths_len + 64U;
4086 
4087  cobc_chk_buff_size (bufflen);
4088 
4089 #ifdef _MSC_VER
4090  sprintf (cobc_buffer, gflag_set ?
4091  "%s /Od /MDd /Zi /FR /Fe\"%s\" %s %s %s %s %s" :
4092  "%s /MD /Fe\"%s\" %s %s %s %s %s",
4093  cobc_cc, exename, cobc_objects_buffer,
4094  manilink, cobc_ldflags, cobc_libs, cobc_lib_paths);
4095  if (verbose_output) {
4096  ret = process (cobc_buffer);
4097  } else {
4098  ret = process_filtered (cobc_buffer, l);
4099  }
4100 #if defined(_MSC_VER) && COB_USE_VC2005_OR_GREATER
4101  /* Embedding manifest */
4102  if (ret == 0) {
4103  sprintf (cobc_buffer,
4104  "%s /manifest \"%s.manifest\" /outputresource:\"%s\";#1",
4105  manicmd, exename, exename);
4106  ret = process (cobc_buffer);
4107  sprintf (cobc_buffer, "%s.manifest", exename);
4109  }
4110 #endif
4111 #else /* _MSC_VER */
4112 #ifdef __WATCOMC__
4113  sprintf (cobc_buffer, "%s %s -fe=\"%s\" %s %s %s %s",
4116 #else
4117  sprintf (cobc_buffer, "%s %s -o \"%s\" %s %s %s %s",
4120 #endif
4121 
4122  ret = process (cobc_buffer);
4123 
4124 #ifdef __hpux
4125  if (ret == 0) {
4126  sprintf (cobc_buffer, "chatr -s +s enable \"%s%s\" 1>/dev/null 2>&1",
4127  name, COB_EXEEXT);
4128  process (cobc_buffer);
4129  }
4130 #endif
4131 
4132 #ifdef COB_STRIP_CMD
4133  if (strip_output && ret == 0) {
4134  sprintf (cobc_buffer, "%s \"%s%s\"",
4135  COB_STRIP_CMD, name, COB_EXEEXT);
4136  ret = process (cobc_buffer);
4137  }
4138 #endif
4139 
4140 #endif /* _MSC_VER */
4141 
4142  /* run job? */
4143  if ((ret == 0) && cobc_flag_run) {
4144  ret = process_run (name);
4145  }
4146  return ret;
4147 }
4148 
4149 /* Main function */
4150 extern int yydebug;
4151 int
4152 main (int argc, char **argv)
4153 {
4154  struct filename *fn;
4155  char *p;
4156  struct cobc_mem_struct *mptr;
4157  struct cobc_mem_struct *mptrt;
4158  unsigned int iparams;
4159  unsigned int local_level;
4160  int status;
4161  int year;
4162  int day;
4163  int i;
4164  char month[32];
4165 
4166 #if defined(HAVE_SIGNAL_H) && defined(HAVE_SIGACTION)
4167  struct sigaction sa;
4168  struct sigaction osa;
4169 #endif
4170 #ifdef ENABLE_NLS
4171  struct stat localest;
4172  const char* localedir;
4173 #endif
4174 
4175  yydebug = 0;
4176  file_list = NULL;
4178  ppin = NULL;
4179  ppout = NULL;
4180  yyin = NULL;
4181  yyout = NULL;
4182 
4183 #ifdef HAVE_SIGNAL_H
4184 
4185 #ifdef HAVE_SIGACTION
4186  memset (&sa, 0, sizeof(sa));
4187  sa.sa_handler = cobc_sig_handler;
4188 #ifdef SA_RESETHAND
4189  sa.sa_flags = SA_RESETHAND;
4190 #else
4191  sa.sa_flags = 0;
4192 #endif
4193 #ifdef SA_NOCLDSTOP
4194  sa.sa_flags |= SA_NOCLDSTOP;
4195 #endif
4196 #ifdef SIGINT
4197  (void)sigaction (SIGINT, NULL, &osa);
4198  if (osa.sa_handler != SIG_IGN) {
4199  (void)sigemptyset (&sa.sa_mask);
4200  (void)sigaction (SIGINT, &sa, NULL);
4201  }
4202 #endif
4203 #ifdef SIGHUP
4204  (void)sigaction (SIGHUP, NULL, &osa);
4205  if (osa.sa_handler != SIG_IGN) {
4206  (void)sigemptyset (&sa.sa_mask);
4207  (void)sigaction (SIGHUP, &sa, NULL);
4208  }
4209 #endif
4210 #ifdef SIGQUIT
4211  (void)sigaction (SIGQUIT, NULL, &osa);
4212  if (osa.sa_handler != SIG_IGN) {
4213  (void)sigemptyset (&sa.sa_mask);
4214  (void)sigaction (SIGQUIT, &sa, NULL);
4215  }
4216 #endif
4217 #ifdef SIGTERM
4218  (void)sigaction (SIGTERM, NULL, &osa);
4219  if (osa.sa_handler != SIG_IGN) {
4220  (void)sigemptyset (&sa.sa_mask);
4221  (void)sigaction (SIGTERM, &sa, NULL);
4222  }
4223 #endif
4224 #ifdef SIGPIPE
4225  (void)sigaction (SIGPIPE, NULL, &osa);
4226  if (osa.sa_handler != SIG_IGN) {
4227  (void)sigemptyset (&sa.sa_mask);
4228  (void)sigaction (SIGPIPE, &sa, NULL);
4229  }
4230 #endif
4231 #ifdef SIGSEGV
4232  /* Take direct control of segementation violation */
4233  (void)sigemptyset (&sa.sa_mask);
4234  (void)sigaction (SIGSEGV, &sa, NULL);
4235 #endif
4236 
4237 #else
4238 
4239 #ifdef SIGINT
4240  if (signal (SIGINT, SIG_IGN) != SIG_IGN) {
4241  (void)signal (SIGINT, cobc_sig_handler);
4242  }
4243 #endif
4244 #ifdef SIGHUP
4245  if (signal (SIGHUP, SIG_IGN) != SIG_IGN) {
4246  (void)signal (SIGHUP, cobc_sig_handler);
4247  }
4248 #endif
4249 #ifdef SIGQUIT
4250  if (signal (SIGQUIT, SIG_IGN) != SIG_IGN) {
4251  (void)signal (SIGQUIT, cobc_sig_handler);
4252  }
4253 #endif
4254 #ifdef SIGTERM
4255  if (signal (SIGTERM, SIG_IGN) != SIG_IGN) {
4256  (void)signal (SIGTERM, cobc_sig_handler);
4257  }
4258 #endif
4259 #ifdef SIGPIPE
4260  if (signal (SIGPIPE, SIG_IGN) != SIG_IGN) {
4261  (void)signal (SIGPIPE, cobc_sig_handler);
4262  }
4263 #endif
4264  /* Take direct control of segmentation violation */
4265 #ifdef SIGSEGV
4266  (void)signal (SIGSEGV, cobc_sig_handler);
4267 #endif
4268 #endif
4269 
4270 #endif
4271 
4272  cb_saveargc = argc;
4273  cb_saveargv = argv;
4274 
4275  /* General buffers */
4279  basename_len = COB_MINI_MAX - 16;
4280 
4282  cobc_lib_paths = cobc_main_malloc ((size_t)COB_SMALL_BUFF);
4283  cobc_cflags = cobc_main_malloc ((size_t)COB_MINI_BUFF);
4284  cobc_ldflags = cobc_main_malloc ((size_t)COB_MINI_BUFF);
4285  cobc_include = cobc_main_malloc ((size_t)COB_MINI_BUFF);
4286 
4292 
4293  cb_source_file = NULL;
4294  save_temps_dir = NULL;
4295  base_string = NULL;
4296  cobc_objects_len = 0;
4297  cb_id = 1;
4298  cb_attr_id = 1;
4299  cb_literal_id = 1;
4300  cb_field_id = 1;
4301 #ifdef COB_EBCDIC_MACHINE
4302  cb_ebcdic_sign = 1;
4303 #else
4304  cb_ebcdic_sign = 0;
4305 #endif
4306 
4307 #ifdef _WIN32
4308  /* Allows running tests under Win */
4309  p = getenv ("COB_UNIX_LF");
4310  if (p && (*p == 'Y' || *p == 'y' || *p == '1')) {
4311  (void)_setmode (_fileno (stdin), _O_BINARY);
4312  (void)_setmode (_fileno (stdout), _O_BINARY);
4313  (void)_setmode (_fileno (stderr), _O_BINARY);
4314  }
4315 #endif
4316 
4317 #ifdef HAVE_SETLOCALE
4318  setlocale (LC_ALL, "");
4319  setlocale (LC_NUMERIC, "C");
4320 #endif
4321 
4322 #ifdef ENABLE_NLS
4323  localedir = getenv("LOCALEDIR");
4324  if (localedir != NULL
4325  && !stat (localedir, &localest)
4326  && (S_ISDIR (localest.st_mode))) {
4327  bindtextdomain (PACKAGE, localedir);
4328  } else {
4330  }
4331  textdomain (PACKAGE);
4332 #endif
4333 
4334  /* Initialize variables */
4335 
4336  /* Set up build time stamp */
4337  memset (month, 0, sizeof(month));
4338  day = 0;
4339  year = 0;
4340  status = sscanf (__DATE__, "%s %d %d", month, &day, &year);
4341  if (status == 3) {
4342  snprintf (cobc_buffer, (size_t)COB_MINI_MAX,
4343  "%s %2.2d %4.4d %s", month, day, year, __TIME__);
4344  } else {
4345  snprintf (cobc_buffer, (size_t)COB_MINI_MAX,
4346  "%s %s", __DATE__, __TIME__);
4347  }
4349 
4350  output_name = NULL;
4351 
4352  cobc_cc = cobc_getenv ("COB_CC");
4353  if (cobc_cc == NULL) {
4354  cobc_cc = COB_CC;
4355  }
4356 
4357  cob_config_dir = cobc_getenv ("COB_CONFIG_DIR");
4358  if (cob_config_dir == NULL) {
4360  }
4361 
4362  p = cobc_getenv ("COB_CFLAGS");
4363  if (p) {
4365  } else {
4367  }
4368 
4369  p = cobc_getenv ("COB_LDFLAGS");
4370  if (p) {
4372  } else {
4374  }
4375 
4376  p = cobc_getenv ("COB_LIBS");
4377  if (p) {
4379  } else {
4381  }
4382 
4383  p = cobc_getenv ("COB_LDADD");
4384  if (p) {
4385  COBC_ADD_STR (cobc_libs, " ", p, NULL);
4386  }
4387 
4388  p = cobc_getenv ("COB_LIB_PATHS");
4389  if (p) {
4391  } else {
4393  }
4394 
4395  /* Different styles for warning/error messages */
4396  p = cobc_getenv ("COB_MSG_FORMAT");
4397 #if defined (_MSC_VER)
4398  if (p && strcasecmp(p, "GCC") == 0) {
4400  } else {
4402  }
4403 #else
4404  if (p && strcasecmp(p, "MSC") == 0) {
4406  } else {
4408  }
4409 #endif
4410 
4411  /* Set default computed goto usage if appropriate */
4412 #if defined(__GNUC__) && !defined(__clang__)
4413  cb_flag_computed_goto = 1;
4414 #elif defined(__SUNPRO_C) && __SUNPRO_C >= 0x570
4415  cb_flag_computed_goto = 1;
4416 #elif defined(__xlc__) && defined(__IBMC__) && __IBMC__ >= 700
4417  cb_flag_computed_goto = 1;
4418  COBC_ADD_STR (cobc_cflags, " -qlanglvl=extended",
4419  NULL, NULL);
4420 #endif
4421 
4422  /* Compiler special options */
4423 
4424 #ifdef __WATCOMC__
4425  /* -s = no overflow checks, otherwise need to code/link a CHK routine */
4426  COBC_ADD_STR (cobc_cflags, " -s -wcd=118", NULL, NULL);
4427 #endif
4428 
4429 #ifdef __INTEL_COMPILER
4430  COBC_ADD_STR (cobc_cflags, " -vec-report0 -opt-report 0",
4431  NULL, NULL);
4432 #elif defined(__GNUC__)
4433 #if 0 /* RXWRXW - gcse */
4434  COBC_ADD_STR (cobc_cflags, " -Wno-unused -fsigned-char -fno-gcse",
4435  NULL, NULL);
4436 #else
4437  COBC_ADD_STR (cobc_cflags, " -Wno-unused -fsigned-char",
4438  NULL, NULL);
4439 #endif
4440  /* --param max-goto-duplication-insns=100000 */
4441 #ifdef HAVE_PSIGN_OPT
4442  COBC_ADD_STR (cobc_cflags, " -Wno-pointer-sign", NULL, NULL);
4443 #endif
4444 
4445 #elif defined(__xlc__)
4446  COBC_ADD_STR (cobc_cflags, " -qro -qroconst",
4447  NULL, NULL);
4448 #endif
4449 
4450  /* Enable default I/O exceptions */
4452 
4453  /* Compiler initialization I */
4454 #ifndef HAVE_DESIGNATED_INITS
4455  cobc_init_reserved ();
4456 #endif
4457 
4458  /* Process command line arguments */
4459  iargs = process_command_line (argc, argv);
4460 
4461  /* Check the filename */
4462  if (iargs == argc) {
4463  cobc_err_exit (_("No input files"));
4464  }
4465 
4466  /* Windows stuff reliant upon verbose option */
4467 #ifdef _MSC_VER
4468  if (!verbose_output) {
4469  COBC_ADD_STR (cobc_cflags, " /nologo", NULL, NULL);
4470  }
4471 #if defined(_MSC_VER) && COB_USE_VC2005_OR_GREATER
4472  if (!verbose_output) {
4473  manicmd = "mt /nologo";
4474  manilink = "/link /nologo /manifest";
4475  } else {
4476  manicmd = "mt";
4477  manilink = "/link /manifest";
4478  }
4479 #else
4480  if (!verbose_output) {
4481  manilink = "/link /nologo";
4482  } else {
4483  manilink = "/link";
4484  }
4485 #endif
4486  manilink_len = strlen (manilink);
4487 #endif
4488 
4489 #ifdef __WATCOMC__
4490  if (!verbose_output) {
4491  COBC_ADD_STR (cobc_cflags, " -q", NULL, NULL);
4492  }
4493 #endif
4494 
4495 #if 0 /* gcc opts */
4496 
4497 #if defined(__GNUC__) && !defined (__INTEL_COMPILER)
4498  if (!gflag_set && !cobc_wants_debug && !aflag_set) {
4499  COBC_ADD_STR (cobc_cflags, " -fomit-frame-pointer",
4500  " -fno-asynchronous-unwind-tables",
4501  " -U_FORTIFY_SOURCE");
4502 #if 0 /* RXWRXW - Default opt */
4503  if (!cob_optimize) {
4505  }
4506 #endif
4507 #ifdef HAVE_UNWIND_OPT
4508 #endif
4509  }
4510 #endif
4511 
4512 #endif
4513 
4514  /* Append default extensions */
4515  CB_TEXT_LIST_ADD (cb_extension_list, ".CPY");
4516  CB_TEXT_LIST_ADD (cb_extension_list, ".CBL");
4517  CB_TEXT_LIST_ADD (cb_extension_list, ".COB");
4518  CB_TEXT_LIST_ADD (cb_extension_list, ".cpy");
4519  CB_TEXT_LIST_ADD (cb_extension_list, ".cbl");
4520  CB_TEXT_LIST_ADD (cb_extension_list, ".cob");
4521  CB_TEXT_LIST_ADD (cb_extension_list, "");
4522 
4523  /* Process COB_COPY_DIR and COBCPY environment variables */
4524  process_env_copy_path (getenv ("COB_COPY_DIR"));
4525  process_env_copy_path (getenv ("COBCPY"));
4526 
4527  /* Add default COB_COPY_DIR directory */
4528  CB_TEXT_LIST_CHK (cb_include_list, COB_COPY_DIR);
4529 
4530  /* Defaults are set here */
4531  if (!cb_flag_syntax_only) {
4532  if (!wants_nonfinal) {
4533  if (cobc_flag_main) {
4535  } else if (cobc_flag_module) {
4537  } else if (cobc_flag_library) {
4539  } else if (cb_compile_level == 0) {
4541  cobc_flag_module = 1;
4542  }
4543  }
4546  cobc_flag_module = 1;
4547  }
4548  } else {
4550  cobc_flag_main = 0;
4551  cobc_flag_module = 0;
4552  cobc_flag_library = 0;
4553  }
4554 
4556  (argc - iargs) > 1) {
4557  cobc_err_exit (_("%s option invalid in this combination"), "-o");
4558  }
4559 
4560  if (cb_flag_notrunc) {
4561  cb_binary_truncate = 0;
4562  cb_pretty_display = 0;
4563  }
4564 
4565  /* Compiler initialization II */
4566 #ifndef HAVE_DESIGNATED_INITS
4567  cobc_init_scanner ();
4568  cobc_init_typeck ();
4569 #endif
4570 
4571  /* If -P=file specified, all lists go to this file */
4572  if (cobc_list_file) {
4573  cb_listing_file = fopen (cobc_list_file, "w");
4574  if (!cb_listing_file) {
4576  }
4577  }
4578 
4579  if (verbose_output) {
4580  fputs (_("Command line:"), stderr);
4581  putc ('\t', stderr);
4582  for (i = 0; i < argc; ++i) {
4583  fprintf (stderr, "%s ", argv[i]);
4584  }
4585  putc ('\n', stderr);
4586  fflush (stderr);
4587  }
4588 
4589  cobc_cc_len = strlen (cobc_cc);
4590  cobc_cflags_len = strlen (cobc_cflags);
4591  cobc_libs_len = strlen (cobc_libs);
4593  cobc_include_len = strlen (cobc_include);
4594  cobc_ldflags_len = strlen (cobc_ldflags);
4597  cobc_pic_flags_len = strlen (COB_PIC_FLAGS);
4598 
4599  /* Process input files */
4600  status = 0;
4601  iparams = 0;
4602  local_level = 0;
4603 
4604  while (iargs < argc) {
4605  /* Set up file parameters */
4606  fn = process_filename (argv[iargs++]);
4607  if (!fn) {
4608  cobc_clean_up (1);
4609  return 1;
4610  }
4611  cb_id = 1;
4612  cb_attr_id = 1;
4613  cb_literal_id = 1;
4614  cb_field_id = 1;
4616  memset (optimize_defs, 0, sizeof(optimize_defs));
4617  iparams++;
4618  if (iparams > 1 && cb_compile_level == CB_LEVEL_EXECUTABLE) {
4619  local_level = cb_compile_level;
4621  cobc_flag_main = 0;
4622  }
4623 
4625  fn->need_preprocess) {
4626  /* Preprocess */
4627  fn->has_error = preprocess (fn);
4628  status |= fn->has_error;
4629  }
4630  if (cobc_list_file) {
4631  putc ('\n', cb_listing_file);
4632  }
4633 
4634  if (cb_compile_level < CB_LEVEL_TRANSLATE || fn->has_error) {
4635  continue;
4636  }
4637  if (fn->need_translate) {
4638  /* Parse / Translate (to C code) */
4639  fn->has_error = process_translate (fn);
4640  status |= fn->has_error;
4641  /* Free parse memory */
4642  for (mptr = cobc_parsemem_base; mptr; ) {
4643  mptrt = mptr;
4644  mptr = mptr->next;
4645  cobc_free (mptrt);
4646  }
4647  cobc_parsemem_base = NULL;
4648  }
4650  cb_flag_syntax_only || fn->has_error) {
4651  continue;
4652  }
4654  /* Compile to assembler code */
4655  fn->has_error = process_compile (fn);
4656  status |= fn->has_error;
4657  continue;
4658  }
4659 
4661  /* Build module direct */
4662  fn->has_error = process_module_direct (fn);
4663  status |= fn->has_error;
4664  } else {
4665  /* Compile to object code */
4667  fn->need_assemble) {
4668  fn->has_error = process_assemble (fn);
4669  status |= fn->has_error;
4670  }
4671  if (fn->has_error) {
4672  continue;
4673  }
4674 
4675  /* Build module */
4677  fn->has_error = process_module (fn);
4678  status |= fn->has_error;
4679  }
4680  }
4681  }
4682 
4683  if (cobc_list_file) {
4684  fclose (cb_listing_file);
4686  }
4687 
4688  /* Clear rest of preprocess stuff */
4689  plex_clear_all ();
4690 
4691  /* Clear rest of parser stuff */
4692  ylex_clear_all ();
4693 
4694  if (local_level == CB_LEVEL_EXECUTABLE) {
4696  }
4697 
4699  status || cb_flag_syntax_only) {
4700  /* Finished */
4701  cobc_clean_up (status);
4702  return status;
4703  }
4704 
4705  /* Allocate objects buffer */
4707 
4708  if (file_list) {
4709  /* Link */
4711  /* Multi-program module */
4712  status = process_library (file_list);
4713  } else {
4714  /* Executable */
4715  status = process_link (file_list);
4716  }
4717  }
4718 
4719  /* We have completed */
4720  cobc_clean_up (status);
4721 
4722  return status;
4723 }
static const char * cobc_enum_explain(const enum cb_tag tag)
Definition: cobc.c:503
struct cb_label * handler_label
Definition: tree.h:805
struct cb_text_list * next
Definition: cobc.h:160
static size_t save_all_src
Definition: cobc.c:274
#define CB_LEVEL_LIBRARY
Definition: cobc.c:76
const char * cob_config_dir
Definition: cobc.c:155
Definition: cobc.c:65
int warningcount
Definition: cobc.c:174
void ylex_call_destroy(void)
Definition: scanner.c:4757
static char * save_temps_dir
Definition: cobc.c:247
void * cobc_main_malloc(const size_t size)
Definition: cobc.c:702
#define CB_TEXT_LIST_CHK(y, z)
Definition: cobc.c:111
static size_t cobc_include_size
Definition: cobc.c:234
void cobc_abort_pr(const char *fmt,...)
Definition: cobc.c:587
static size_t cobc_objects_len
Definition: cobc.c:259
void * cobc_realloc(void *prevptr, const size_t size)
Definition: cobc.c:687
static char * cobc_stradd_dup(const char *str1, const char *str2)
Definition: cobc.c:1286
static size_t cobc_ldflags_size
Definition: cobc.c:235
#define cob_u32_t
Definition: common.h:31
static struct strcache * base_string
Definition: cobc.c:248
int cob_getopt_long_long(const int argc, char *const *argv, const char *optstring, const struct option *longopts, int *longind, const int long_only)
Definition: cobgetopt.c:321
void plex_call_destroy(void)
Definition: pplex.c:4583
const char * cb_source_file
Definition: cobc.c:145
struct cb_text_list * cb_extension_list
Definition: cobc.c:151
#define CB_COPT_1
Definition: cobc.c:138
struct cb_text_list * cb_intrinsic_list
Definition: cobc.c:150
static size_t cobc_cflags_len
Definition: cobc.c:238
struct cb_text_list * cb_include_list
Definition: cobc.c:149
static char * cobc_include
Definition: cobc.c:228
void * cobc_parse_malloc(const size_t size)
Definition: cobc.c:809
FILE * cb_storage_file
Definition: cobc.c:156
static int cobc_deciph_optarg(const char *p, const int allow_quote)
Definition: cobc.c:1191
const char * text
Definition: cobc.h:162
int int_part
Definition: cobc.h:183
int cobc_seen_stdin
Definition: cobc.c:171
void codegen(struct cb_program *prog, const int nested)
Definition: codegen.c:7448
static size_t gflag_set
Definition: cobc.c:289
#define COB_LDFLAGS
Definition: defaults.h:4
unsigned int flag_global
Definition: tree.h:782
#define SLASH_STR
Definition: common.h:506
Definition: tree.h:88
static struct cobc_mem_struct * cobc_plexmem_base
Definition: cobc.c:222
static void cobc_free_mem(void)
Definition: cobc.c:465
struct cb_define_struct * next
Definition: cobc.h:177
int cb_flag_main
Definition: cobc.c:168
cb_tree global_file_list
Definition: tree.h:1282
#define WITH_VARSEQ
Definition: config.h:370
static char * cobc_libs
Definition: cobc.c:226
void * memptr
Definition: cobc.h:232
unsigned int need_assemble
Definition: cobc.h:209
#define PLEX_DEF_NONE
Definition: cobc.h:97
int warningopt
Definition: cobc.c:176
int cb_id
Definition: cobc.c:163
#define COBC_ADD_STR(v, x, y, z)
Definition: cobc.c:83
static size_t basename_len
Definition: cobc.c:260
void cobc_free(void *mptr)
Definition: cobc.c:657
static char * cobc_objects_buffer
Definition: cobc.c:255
int cb_load_conf(const char *, const int)
Definition: config.c:476
void cb_list_intrinsics(void)
Definition: reserved.c:3052
static int process_link(struct filename *l)
Definition: cobc.c:4031
char * cb_name(cb_tree x)
Definition: tree.c:735
static void cobc_var_print(const char *msg, const char *val, const unsigned int env)
Definition: cobc.c:1591
const char * cb_storage_file_name
Definition: cobc.c:148
const char * listing_file
Definition: cobc.h:203
static DECLNORET void COB_A_NORETURN cobc_terminate(const char *str)
Definition: cobc.c:1471
#define CB_LEVEL_ASSEMBLE
Definition: cobc.c:74
int dec_part
Definition: cobc.h:184
const char * preprocess
Definition: cobc.h:198
int nested_level
Definition: tree.h:1295
void * cobc_plex_strdup(const char *dupstr)
Definition: cobc.c:933
#define COB_NUM_CSYNS
Definition: cobc.c:388
void * cobc_parse_realloc(void *prevptr, const size_t size)
Definition: cobc.c:845
struct cb_intrinsic_table * lookup_intrinsic(const char *name, const int checkres, const int checkimpl)
Definition: reserved.c:2976
static int process_run(const char *name)
-j run job after build
Definition: cobc.c:2836
#define COB_BLD_CPPFLAGS
Definition: defaults.h:12
static size_t cobc_lib_paths_size
Definition: cobc.c:233
void ppparse_clear_vars(const struct cb_define_struct *)
Definition: ppparse.c:490
void cb_list_mnemonics(void)
Definition: reserved.c:3101
#define COB_SMALL_BUFF
Definition: common.h:540
static void process_env_copy_path(const char *p)
Definition: cobc.c:2527
FILE * cb_listing_file
Definition: cobc.c:157
struct nested_list * next
Definition: tree.h:1234
#define COB_MINI_BUFF
Definition: common.h:539
#define CB_TEXT_LIST_ADD(y, z)
Definition: cobc.c:110
static size_t cobc_cflags_size
Definition: cobc.c:231
#define COB_MEDIUM_BUFF
Definition: common.h:543
int cb_source_format
Definition: cobc.c:162
#define bindtextdomain(Domainname, Dirname)
Definition: gettext.h:86
static size_t cobc_cc_len
Definition: cobc.c:237
struct local_filename * local_include
Definition: tree.h:1248
static char * cobc_list_file
Definition: cobc.c:251
void cobc_main_free(void *prevptr)
Definition: cobc.c:778
static size_t wants_nonfinal
Definition: cobc.c:269
int main(int argc, char **argv)
Definition: cobc.c:4152
static struct cobc_mem_struct * cobc_mainmem_base
Definition: cobc.c:220
void plex_clear_all(void)
Definition: pplex.c:4570
#define CB_OP_ARG
Definition: cobc.c:394
struct strcache * next
Definition: cobc.c:66
void * cobc_check_string(const char *dupstr)
Definition: cobc.c:951
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax extension
Definition: flag.def:102
static DECLNORET void COB_A_NORETURN cobc_err_exit(const char *fmt,...)
Definition: cobc.c:1229
#define CB_COPT_S
Definition: cobc.c:140
#define COB_SMALL_MAX
Definition: common.h:546
#define COB_MODULE_EXT
Definition: defaults.h:9
void cobc_abort(const char *filename, const int linenum)
Definition: cobc.c:606
void * cobc_parse_strdup(const char *dupstr)
Definition: cobc.c:827
int cob_optind
Definition: cobgetopt.c:92
static struct cb_text_list * cb_text_list_add(struct cb_text_list *list, const char *text)
Definition: cobc.c:974
struct cb_exception cb_exception_table[]
Definition: cobc.c:186
void ylex_clear_all(void)
Definition: scanner.c:4736
const char * demangle_source
Definition: cobc.h:202
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional file
Definition: flag.def:129
#define COB_LARGE_BUFF
Definition: common.h:544
char * cb_oc_build_stamp
Definition: cobc.c:146
#define COB_PIC_FLAGS
Definition: config.h:32
static int process_module(struct filename *fn)
Definition: cobc.c:3814
unsigned int need_translate
Definition: cobc.h:208
#define COB_BLD_LDFLAGS
Definition: defaults.h:15
#define CB_COPT_2
Definition: cobc.c:139
#define COB_BLD_CC
Definition: defaults.h:11
static struct filename * file_list
Definition: cobc.c:263
static char * cobc_ldflags
Definition: cobc.c:229
void * cobc_main_realloc(void *prevptr, const size_t size)
Definition: cobc.c:738
#define OC_C_VERSION
Definition: cobc.c:107
int no_physical_cancel
Definition: cobc.c:177
static char * cobc_buffer
Definition: cobc.c:254
Definition: cobc.h:135
static int process_module_direct(struct filename *fn)
Definition: cobc.c:3696
unsigned int cobc_gen_listing
Definition: cobc.c:180
#define CB_LEVEL_TRANSLATE
Definition: cobc.c:72
static void cobc_error_name(const char *name, const unsigned int source, const unsigned int reason)
Definition: cobc.c:1095
#define textdomain(Domainname)
Definition: gettext.h:84
static char * cobc_list_dir
Definition: cobc.c:250
char * name
Definition: cobc.h:179
static int cobc_bcompare(const void *p1, const void *p2)
Definition: cobc.c:1086
#define yyout
Definition: pplex.c:20
static int process_compile(struct filename *fn)
Definition: cobc.c:3560
static size_t cobc_include_len
Definition: cobc.c:241
static int process(const char *cmd)
Definition: cobc.c:3201
static size_t cobc_flag_module
Definition: cobc.c:270
static struct cb_define_struct * cb_define_list_add(struct cb_define_struct *list, const char *text)
Definition: cobc.c:1245
#define CB_NO_ARG
Definition: cobc.c:392
const char * trstorage
Definition: cobc.h:200
static void cobc_deciph_funcs(const char *opt)
Definition: cobc.c:1888
static int iargs
Definition: cobc.c:267
static const struct option long_options[]
Definition: cobc.c:396
struct local_filename * localfile
Definition: cobc.h:204
int cobc_wants_debug
Definition: cobc.c:169
struct cb_program * nested_prog
Definition: tree.h:1235
FILE * ppin
Definition: pplex.c:367
strict implicit external value
Definition: warning.def:54
struct cb_text_list * cb_early_exit_list
Definition: cobc.c:153
static const char * file_extension(const char *filename)
Definition: cobc.c:2618
static size_t cobc_libs_size
Definition: cobc.c:232
int cb_flag_functions_all
Definition: cobc.c:170
const char * source
Definition: cobc.h:197
#define CB_LEVEL_EXECUTABLE
Definition: cobc.c:77
int exit_option
Definition: cobc.c:175
void cobc_parse_free(void *prevptr)
Definition: cobc.c:885
#define PACKAGE_NAME
Definition: config.h:300
#define _(s)
Definition: cobcrun.c:59
#define COB_OPEN_EXTEND
Definition: common.h:787
#define COB_FILE_BUFF
Definition: common.h:542
size_t object_len
Definition: cobc.h:206
static const char * cobc_cc
Definition: cobc.c:224
#define COB_OPEN_INPUT
Definition: common.h:784
#define COB_DASH
Definition: cobc.h:121
#define OC_C_VERSION_PRF
Definition: cobc.c:106
#define unlikely(x)
Definition: common.h:437
unsigned int deftype
Definition: cobc.h:181
#define F_OK
Definition: cobc.h:46
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define CB_TREE_TAG(x)
Definition: tree.h:441
void cobc_init_scanner(void)
Definition: scanner.c:4922
#define PLEX_DEF_NUM
Definition: cobc.h:99
static size_t verbose_output
Definition: cobc.c:276
#define COBC_ABORT()
Definition: cobc.h:61
#define CB_RQ_ARG
Definition: cobc.c:393
#define PATHSEP_STR
Definition: common.h:501
size_t translate_len
Definition: cobc.h:205
void plex_clear_vars(void)
Definition: pplex.c:4559
#define CB_MSG_STYLE_MSC
Definition: cobc.h:436
struct cb_program * next_program
Definition: tree.h:1242
#define CB_LEVEL_COMPILE
Definition: cobc.c:73
static char * file_basename(const char *filename)
Definition: cobc.c:2573
struct cb_text_list * last
Definition: cobc.h:161
static char * cobc_lib_paths
Definition: cobc.c:227
#define SLASH_CHAR
Definition: common.h:505
int ppparse(void)
Definition: ppparse.c:1656
#define COB_A_NORETURN
Definition: common.h:366
static int preprocess(struct filename *fn)
Definition: cobc.c:3262
int ppopen(const char *, struct cb_replace_list *)
Definition: pplex.c:4420
#define COB_DASH_NAME
Definition: cobc.h:122
struct cb_define_struct * last
Definition: cobc.h:178
#define COB_NORMAL_MAX
Definition: common.h:547
struct cb_program * handler_prog
Definition: tree.h:806
void cb_insert_common_prog(struct cb_program *prog, struct cb_program *comprog)
Definition: tree.c:1479
FILE * ppout
Definition: pplex.c:367
static size_t cobc_libs_len
Definition: cobc.c:239
char ** cb_saveargv
Definition: cobc.c:154
void cb_list_reserved(void)
Definition: reserved.c:2989
static int process_translate(struct filename *fn)
Definition: cobc.c:3397
int cb_saveargc
Definition: cobc.c:179
size_t memlen
Definition: cobc.h:233
static int process_command_line(const int argc, char **argv)
Definition: cobc.c:1911
void cb_list_system(void)
Definition: typeck.c:833
#define PLEX_DEF_LIT
Definition: cobc.h:98
size_t cb_msg_style
Definition: error.c:43
static void cobc_options_error_build(void)
Definition: cobc.c:1882
#define WITH_CURSES
Definition: config.h:355
cb_tree entry_list
Definition: tree.h:1251
#define CB_FORMAT_FIXED
Definition: cobc.h:65
void * cobc_main_strdup(const char *dupstr)
Definition: cobc.c:720
static void cobc_check_action(const char *name)
Definition: cobc.c:1355
static void cobc_print_info(void)
Definition: cobc.c:1630
cb_tree cb_error_node
Definition: tree.c:140
char * value
Definition: cobc.h:180
#define COB_FOLD_LOWER
Definition: common.h:587
static char * cobc_getenv(const char *env)
Definition: cobc.c:1306
static struct cb_text_list * cb_text_list_chk(struct cb_text_list *list, const char *text)
Definition: cobc.c:990
#define COB_TAR_DATE
Definition: tarstamp.h:1
void * cobc_strdup(const char *dupstr)
Definition: cobc.c:669
static size_t cob_optimize
Definition: cobc.c:277
static size_t save_c_src
Definition: cobc.c:275
int cb_field_id
Definition: cobc.c:166
static char * output_name
Definition: cobc.c:253
static void cobc_options_error_nonfinal(void)
Definition: cobc.c:1876
void cb_error(const char *,...) COB_A_FORMAT12
Definition: error.c:98
static void cobc_cmd_print(const char *cmd)
Definition: cobc.c:1558
static struct cb_program * program_list_reverse(struct cb_program *p)
Definition: cobc.c:2512
int has_error
Definition: cobc.h:210
char * cb_encode_program_id(const char *)
Definition: typeck.c:1132
int file_is_stdin
Definition: cobc.h:211
if fold fold static computed alternate extra correct stack on syntax debugging line
Definition: flag.def:90
static struct cb_define_struct * cb_define_list
Definition: cobc.c:218
struct cb_program * current_program
Definition: parser.c:168
#define COB_LIBS
Definition: defaults.h:5
struct nested_list * common_prog_list
Definition: tree.h:1250
#define COB_LARGE_MAX
Definition: common.h:550
static struct filename * process_filename(const char *filename)
Definition: cobc.c:2630
#define COB_BLD_LD
Definition: defaults.h:14
static size_t cobc_flag_run
Definition: cobc.c:272
int cb_literal_id
Definition: cobc.c:165
struct handler_struct global_handler[5]
Definition: tree.h:1283
struct filename * next
Definition: cobc.h:196
void cb_init_constants(void)
Definition: tree.c:1259
void cob_incr_temp_iteration(void)
Definition: common.c:3266
#define CB_EXCEPTION_ENABLE(id)
Definition: cobc.h:243
int cb_load_std(const char *)
Definition: config.c:147
#define CB_LEVEL_PREPROCESS
Definition: cobc.c:71
cob_exception_id
Definition: common.h:710
#define COB_CONFIG_DIR
Definition: defaults.h:6
#define yyin
Definition: pplex.c:16
const char * demangle_name
Definition: cobc.c:147
static char * cobc_cflags
Definition: cobc.c:225
#define DECLNORET
Definition: common.h:376
void * val
Definition: cobc.c:67
static size_t strip_output
Definition: cobc.c:288
static void cobc_print_flag(const char *name, const char *doc, const int pdok, const int exten)
Definition: cobc.c:1767
int cb_attr_id
Definition: cobc.c:164
void * cobc_plex_malloc(const size_t size)
Definition: cobc.c:916
#define COB_DASH_OUT
Definition: cobc.h:123
void * cobc_malloc(const size_t size)
Definition: cobc.c:643
#define CB_FORMAT_FREE
Definition: cobc.h:66
static DECLNORET void COB_A_NORETURN cobc_abort_terminate(void)
Definition: cobc.c:1486
int cb_source_line
Definition: cobc.c:178
#define COB_BLD_CFLAGS
Definition: defaults.h:13
cb_tag
Definition: tree.h:61
#define COB_BLD_BUILD
Definition: defaults.h:16
#define COB_EXEEXT
Definition: config.h:8
static size_t save_temps
Definition: cobc.c:273
static size_t cobc_export_dyn_len
Definition: cobc.c:243
static int process_assemble(struct filename *fn)
Definition: cobc.c:3611
#define COB_CFLAGS
Definition: defaults.h:3
cob_u32_t optimize_defs[COB_OPTIM_MAX]
Definition: cobc.c:182
#define PACKAGE_VERSION
Definition: config.h:312
#define CB_LEVEL_MODULE
Definition: cobc.c:75
#define R_OK
Definition: cobc.h:58
static const char *const cob_csyns[]
Definition: cobc.c:292
static void cobc_print_version(void)
Definition: cobc.c:1541
size_t cobc_check_valid_name(const char *name, const unsigned int prechk)
Definition: cobc.c:1142
unsigned int need_preprocess
Definition: cobc.h:207
Definition: cobc.h:195
struct local_filename * next
Definition: cobc.h:189
#define COB_FOLD_UPPER
Definition: common.h:586
cb_tree cb_list_reverse(cb_tree l)
Definition: tree.c:1327
static const char short_options[]
Definition: cobc.c:390
static unsigned int cobc_set_value(struct cb_define_struct *p, const char *value)
Definition: cobc.c:1003
static char * basename_buffer
Definition: cobc.c:257
const char * translate
Definition: cobc.h:199
static size_t cobc_lib_paths_len
Definition: cobc.c:240
#define PACKAGE
Definition: config.h:294
static size_t cobc_shared_opt_len
Definition: cobc.c:244
#define COB_FILE_MAX
Definition: common.h:548
static void cobc_add_str(char **var, size_t *cursize, const char *s1, const char *s2, const char *s3)
Definition: cobc.c:1318
void cobc_dumb_abort(const char *filename, const int linenum)
Definition: cobc.c:613
void cobc_too_many_errors(void)
Definition: cobc.c:599
#define COB_EXPORT_DYN
Definition: config.h:14
#define COB_STRIP_CMD
Definition: config.h:41
#define CB_MSG_STYLE_GCC
Definition: cobc.h:435
const char * object
Definition: cobc.h:201
#define LOCALEDIR
Definition: defaults.h:17
int cobc_flag_main
Definition: cobc.c:167
static char * output_name_buff
Definition: cobc.c:256
static int process_library(struct filename *l)
Definition: cobc.c:3913
FILE * local_fp
Definition: cobc.h:191
#define COBC_INV_PAR
Definition: cobc.c:84
static struct cobc_mem_struct * cobc_parsemem_base
Definition: cobc.c:221
void cobc_init_typeck(void)
Definition: typeck.c:8747
#define PATCH_LEVEL
Definition: config.h:315
static void cobc_clean_up(const int status)
Definition: cobc.c:1380
int cob_sys_getpid(void)
Definition: common.c:3818
static size_t cobc_buffer_size
Definition: cobc.c:261
#define CB_IMSG_SIZE
Definition: cobc.c:80
static void cobc_print_usage(char *prog)
Definition: cobc.c:1786
static void cobc_print_warn(const char *name, const char *doc, const int wall)
Definition: cobc.c:1756
#define COB_SHARED_OPT
Definition: config.h:35
#define COB_MEDIUM_MAX
Definition: common.h:549
#define likely(x)
Definition: common.h:436
char * local_name
Definition: cobc.h:190
int cb_config_entry(char *, const char *, const int)
Definition: config.c:153
static unsigned int cb_compile_level
Definition: cobc.c:265
static size_t cobc_flag_library
Definition: cobc.c:271
#define COB_CC
Definition: defaults.h:2
#define COB_OBJECT_EXT
Definition: defaults.h:10
#define yyparse
Definition: ppparse.c:63
struct cb_text_list * cb_static_call_list
Definition: cobc.c:152
char * cob_optarg
Definition: cobgetopt.c:77
void cobc_tree_cast_error(const cb_tree x, const char *filename, const int linenum, const enum cb_tag tagnum)
Definition: cobc.c:619
#define CB_IVAL_SIZE
Definition: cobc.c:81
int errorcount
Definition: cobc.c:173
static size_t aflag_set
Definition: cobc.c:290
#define COB_COPY_DIR
Definition: defaults.h:7
void cobc_init_reserved(void)
Definition: reserved.c:3133
#define COB_MINI_MAX
Definition: common.h:545
static size_t cobc_ldflags_len
Definition: cobc.c:242
void cob_temp_name(char *filename, const char *ext)
Definition: common.c:3253
static void cobc_chk_buff_size(const size_t bufflen)
Definition: cobc.c:1182
struct cobc_mem_struct * next
Definition: cobc.h:231
int yydebug
static size_t cobc_pic_flags_len
Definition: cobc.c:245