{
struct filename *fn;
char *p;
int status = 1;
int year;
int day;
char month[32];
char buff[COB_SMALL_BUFF];
#ifdef HAVE_SIGNAL_H
if ((intsig = signal (SIGINT, cobc_sig_handler)) == SIG_IGN) {
(void)signal (SIGINT, SIG_IGN);
}
#ifdef SIGHUP
if ((hupsig = signal (SIGHUP, cobc_sig_handler)) == SIG_IGN) {
(void)signal (SIGHUP, SIG_IGN);
}
#endif
#ifdef SIGQUIT
if ((qutsig = signal (SIGQUIT, cobc_sig_handler)) == SIG_IGN) {
(void)signal (SIGQUIT, SIG_IGN);
}
#endif
#endif
cb_saveargc = argc;
cb_saveargv = argv;
#ifdef HAVE_SETLOCALE
setlocale (LC_ALL, "");
#endif
#ifdef ENABLE_NLS
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif
#ifndef _WIN32
cob_process_id = getpid ();
#endif
memset (buff, 0, sizeof(buff));
memset (month, 0, sizeof(month));
day = 0;
year = 0;
sscanf (__DATE__, "%s %d %d", month, &day, &year);
if (day && year) {
sprintf (buff, "%s %2.2d %4.4d %s", month, day, year, __TIME__);
} else {
sprintf (buff, "%s %s", __DATE__, __TIME__);
}
cb_oc_build_stamp = cobc_malloc (strlen (buff) + 1);
strcpy (cb_oc_build_stamp, buff);
output_name = NULL;
if ((p = getenv ("TMPDIR")) != NULL) {
cob_tmpdir = p;
} else if ((p = getenv ("TMP")) != NULL) {
cob_tmpdir = p;
sprintf (buff, "TMPDIR=%s", p);
p = strdup (buff);
putenv (p);
} else {
cob_tmpdir = "/tmp";
putenv ((char *)"TMPDIR=/tmp");
}
cob_cc = getenv ("COB_CC");
if (cob_cc == NULL) {
cob_cc = COB_CC;
}
cobc_init_var (cob_cflags, "COB_CFLAGS", COB_CFLAGS);
cobc_init_var (cob_libs, "COB_LIBS", COB_LIBS);
cob_ldflags = getenv ("COB_LDFLAGS");
if (cob_ldflags == NULL) {
cob_ldflags = COB_LDFLAGS;
}
cob_config_dir = getenv ("COB_CONFIG_DIR");
if (cob_config_dir == NULL) {
cob_config_dir = COB_CONFIG_DIR;
}
cob_copy_dir = getenv ("COB_COPY_DIR");
if (cob_copy_dir == NULL) {
cob_copy_dir = COB_COPY_DIR;
}
memset (cob_define_flags, 0, sizeof (cob_define_flags));
p = getenv ("COB_LDADD");
if (p) {
strcat (cob_libs, " ");
strcat (cob_libs, p);
}
p = getenv ("COB_EBCDIC");
if (p && (*p == 'F' || *p == 'f')) {
alt_ebcdic = 1;
}
iargs = process_command_line (argc, argv);
if (iargs == argc) {
fprintf (stderr, "cobc: No input files\n");
exit (1);
}
process_env_copy_path ();
cb_include_list = cb_text_list_add (cb_include_list, cob_copy_dir);
file_list = NULL;
if (setjmp (cob_jmpbuf) != 0) {
fprintf (stderr, "Aborting compile of %s at line %d\n",
cb_source_file, cb_source_line);
fflush (stderr);
if (yyout) {
fflush (yyout);
}
if (cb_storage_file) {
fflush (cb_storage_file);
}
status = 1;
cobc_clean_up (status);
return status;
}
if (!cb_flag_syntax_only) {
if (!wants_nonfinal) {
if (cb_flag_main) {
cb_compile_level = CB_LEVEL_EXECUTABLE;
}
if (cb_flag_module) {
cb_compile_level = CB_LEVEL_MODULE;
}
if (cb_flag_library) {
cb_compile_level = CB_LEVEL_LIBRARY;
}
}
if (cb_compile_level == 0 && !wants_nonfinal) {
cb_compile_level = CB_LEVEL_MODULE;
cb_flag_module = 1;
}
if (wants_nonfinal && cb_compile_level != CB_LEVEL_PREPROCESS &&
!cb_flag_main && !cb_flag_module && !cb_flag_library) {
cb_flag_module = 1;
}
} else {
cb_compile_level = CB_LEVEL_TRANSLATE;
}
if (output_name && cb_compile_level < CB_LEVEL_LIBRARY &&
(argc - iargs) > 1) {
fprintf (stderr, "cobc: -o option invalid in this combination\n");
exit (1);
}
if (cb_flag_sign_ascii && cb_flag_sign_ebcdic) {
fprintf (stderr, "Only one of -fsign-ascii or -fsign-ebcdic may be specified\n");
exit (1);
}
if (cb_flag_sign_ascii) {
cb_display_sign = COB_DISPLAY_SIGN_ASCII;
}
if (cb_flag_sign_ebcdic) {
cb_display_sign = COB_DISPLAY_SIGN_EBCDIC;
}
if (cb_flag_notrunc) {
cb_binary_truncate = 0;
cb_pretty_display = 0;
}
while (iargs < argc) {
fn = process_filename (argv[iargs++]);
if (!fn) {
status = 1;
cobc_clean_up (status);
return status;
}
if (cb_compile_level >= CB_LEVEL_PREPROCESS && fn->need_preprocess) {
if (preprocess (fn) != 0) {
cobc_clean_up (status);
return status;
}
}
}
for (fn = file_list; fn; fn = fn->next) {
cb_id = 1;
cb_attr_id = 1;
cb_literal_id = 1;
cb_field_id = 1;
cb_storage_id = 1;
iparams++;
demangle_name = fn->demangle_source;
if (iparams > 1 && cb_compile_level == CB_LEVEL_EXECUTABLE &&
!cb_flag_syntax_only) {
local_level = cb_compile_level;
cb_flag_main = 0;
cb_compile_level = CB_LEVEL_ASSEMBLE;
}
if (cb_compile_level >= CB_LEVEL_TRANSLATE && fn->need_translate) {
if (process_translate (fn) != 0) {
cobc_clean_up (status);
return status;
}
}
if (cb_flag_syntax_only) {
continue;
}
if (cb_compile_level == CB_LEVEL_COMPILE) {
if (process_compile (fn) != 0) {
cobc_clean_up (status);
return status;
}
}
if (cb_compile_level == CB_LEVEL_MODULE && fn->need_assemble) {
if (process_module_direct (fn) != 0) {
cobc_clean_up (status);
return status;
}
} else {
if (cb_compile_level >= CB_LEVEL_ASSEMBLE && fn->need_assemble) {
if (process_assemble (fn) != 0) {
cobc_clean_up (status);
return status;
}
}
if (cb_compile_level == CB_LEVEL_MODULE) {
if (process_module (fn) != 0) {
cobc_clean_up (status);
return status;
}
}
}
}
if (!cb_flag_syntax_only) {
if (local_level == CB_LEVEL_EXECUTABLE) {
cb_compile_level = CB_LEVEL_EXECUTABLE;
cb_flag_main = 1;
}
if (cb_compile_level == CB_LEVEL_LIBRARY) {
if (process_library (file_list) != 0) {
cobc_clean_up (status);
return status;
}
} else if (cb_compile_level == CB_LEVEL_EXECUTABLE) {
if (process_link (file_list) != 0) {
cobc_clean_up (status);
return status;
}
}
}
status = 0;
cobc_clean_up (status);
return status;
}