2405 lines
64 KiB
C
2405 lines
64 KiB
C
/*
|
|
* Copyright (C) 1999 - 2004 Glen Colbert, David Essex, Bernard Giroud,
|
|
* Rildo Pragana.
|
|
* Copyright (C) 1993, 1991 Rildo Pragana.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
* any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this software; see the file COPYING. If not, write to
|
|
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
* Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
|
|
/*
|
|
|
|
This portion of the compiler processes the
|
|
compiler options files, compiler environment
|
|
variables, and processes the command line for
|
|
flags and options used to determine the
|
|
compiler behavior.
|
|
|
|
This file was formated using indent -gnu -blp
|
|
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
#include <unistd.h>
|
|
#include <getopt.h>
|
|
#include <sys/time.h>
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include "htconfig.h"
|
|
#include "htcoboly.h"
|
|
#include "htversion.h"
|
|
#include "hthelp.h"
|
|
#include "htglobals.h"
|
|
#include "mwindows.h"
|
|
|
|
#if defined(__MINGW32__)
|
|
/* #include <windows.h> */
|
|
#include <process.h>
|
|
#else
|
|
#include <sys/wait.h>
|
|
#endif
|
|
|
|
/* #define DEBUG_COBPP_PP 1 */
|
|
|
|
#ifdef DEBUG_COBPP_PP
|
|
|
|
char errppbuf[1024*8];
|
|
|
|
void debug_pp_rtn (const char *s1, const char *s2, const char *s3, int w1, int cw);
|
|
|
|
#define DEBUG_PPRTN_STR1(msg1) debug_pp_rtn (msg1, NULL, NULL, 0, 1);
|
|
#define DEBUG_PPRTN_STR3(msg1, msg2) debug_pp_rtn (msg1, msg2, NULL, 0, 3);
|
|
#define DEBUG_PPRTN_STR7(msg1, i1) debug_pp_rtn (msg1, NULL, NULL, i1, 7);
|
|
#define DEBUG_PPRTN_STR15(msg1, msg2, msg3) debug_pp_rtn (msg1, msg2, msg3, 0, 15);
|
|
#define DEBUG_PPRTN_STR21(msg1, msg2, i1) debug_pp_rtn (msg1, msg2, NULL, i1, 21);
|
|
#define DEBUG_PPRTN_STR105(msg1, msg2, msg3, i1) debug_pp_rtn (msg1, msg2, msg3, i1, 105);
|
|
|
|
#else
|
|
|
|
#define DEBUG_PPRTN_STR1(msg1)
|
|
#define DEBUG_PPRTN_STR3(msg1, msg2)
|
|
#define DEBUG_PPRTN_STR7(msg1, i1)
|
|
#define DEBUG_PPRTN_STR15(msg1, msg2, msg3)
|
|
#define DEBUG_PPRTN_STR21(msg1, msg2, i1)
|
|
#define DEBUG_PPRTN_STR105(msg1, msg2, msg3, i1)
|
|
|
|
#endif
|
|
|
|
extern int module_flag;
|
|
|
|
int main_flag = 0; /* Specify main entry point action */
|
|
int main_entry_flag = 0; /* Main entry point detected */
|
|
char main_entry_buf[MAXNAMEBUF] = ""; /* main entry point name */
|
|
|
|
/* command line options */
|
|
static char option_list[] = { HTG_CMDOPTION_LIST };
|
|
|
|
struct cobopt_option
|
|
{
|
|
char *opt;
|
|
int sel;
|
|
};
|
|
|
|
struct cobopt_option option[] =
|
|
{
|
|
/*{ "COPYEXT", HTG_RESOPT_COPYEXT },*/
|
|
/*{ "COPYLBR", HTG_RESOPT_COPYLBR },*/
|
|
{ "COPYLIST", HTG_RESOPT_COPYLIST },
|
|
{ "NOCOPYLIST", HTG_RESOPT_NOCOPYLIST },
|
|
{ "LIST", HTG_RESOPT_LIST },
|
|
{ "NOLIST", HTG_RESOPT_NOLIST },
|
|
{ "LD_PATH:", HTG_RESOPT_LD_PATH },
|
|
/*{ "LD_LIBS:", HTG_RESOPT_LD_LIBS },*/
|
|
{ "XREF", HTG_RESOPT_XREF },
|
|
{ "NOXREF", HTG_RESOPT_NOXREF },
|
|
{ "PGM_SUFFIXES:", HTG_RESOPT_PGM_SUFFIXES },
|
|
{ "LD_FLAGS:", HTG_RESOPT_LD_FLAGS },
|
|
{ "LD_IO_LIBS:", HTG_RESOPT_LD_IO_LIBS },
|
|
{ "LD_TERM_LIBS:", HTG_RESOPT_LD_TERM_LIBS },
|
|
{ "LD_DCALL_LIBS:", HTG_RESOPT_LD_DCALL_LIBS },
|
|
{ "LD_HT1_LIBS:", HTG_RESOPT_LD_HT1_LIBS },
|
|
/*{ "LD_HT2_LIBS:", HTG_RESOPT_LD_HT2_LIBS },*/
|
|
{ "LD_EXTRA_LIBS:", HTG_RESOPT_LD_EXTRA_LIBS },
|
|
{ "LD_READLINE_LIBS:", HTG_RESOPT_LD_READLINE_LIBS },
|
|
{ "PGM_FORMAT_FREE", HTG_RESOPT_PGM_FORMAT_FREE },
|
|
{ "PGM_FORMAT_FIXED", HTG_RESOPT_PGM_FORMAT_FIXED },
|
|
{ "COPYBOOK_PATH:", HTG_RESOPT_INCLUDE_PATH },
|
|
{ "COPYBOOK_SUFFIXES:", HTG_RESOPT_COPYBOOK_SUFFIXES },
|
|
{ "CCX_CMD:", HTG_RESOPT_CCX_CMD },
|
|
{ "ASX_CMD:", HTG_RESOPT_ASX_CMD },
|
|
{ "ARX_CMD:", HTG_RESOPT_ARX_CMD },
|
|
{ "RANLIBX_CMD:", HTG_RESOPT_RANLIBX_CMD },
|
|
{ "LD_MATH_LIBS:", HTG_RESOPT_LD_MATH_LIBS },
|
|
{ "PGMLIST_SUFFIX:", HTG_RESOPT_PGMLIST_SUFFIX },
|
|
{ "DEBUG_LINES", HTG_RESOPT_DEBUG_LINES },
|
|
{ "NODEBUG_LINES", HTG_RESOPT_NODEBUG_LINES },
|
|
{ "COMPILE_DEFAULT:", HTG_RESOPT_COMPILE_DEFAULT },
|
|
{ "SHLIB_NAME_DEFAULT:", HTG_RESOPT_SHLIB_NAME_DEFAULT },
|
|
{ "PGM_ENTRY_POINT_AUTO", HTG_RESOPT_PGM_ENTRY_POINT_AUTO },
|
|
{ "PGM_ENTRY_POINT_FIRST", HTG_RESOPT_PGM_ENTRY_POINT_FIRST },
|
|
{ "PGM_ENTRY_POINT_NONE", HTG_RESOPT_PGM_ENTRY_POINT_NONE },
|
|
{ NULL, 0 }
|
|
};
|
|
|
|
/* *********************************************************************
|
|
* * Define flags and storage for global *
|
|
* * compiler options *
|
|
* *********************************************************************/
|
|
|
|
int wrncnt = 0;
|
|
int errcnt = 0;
|
|
unsigned int source_lineno = 0;
|
|
unsigned int source_colno = 0;
|
|
char *source_filename = NULL;
|
|
char *include_filename = NULL;
|
|
char input_filename[PATHMAX];
|
|
char working_filename[PATHMAX];
|
|
char output_filename[PATHMAX];
|
|
char list_filename[PATHMAX];
|
|
char sys_buf[300];
|
|
|
|
int HTG_RETURN_CODE = 0;
|
|
int HTG_temporary_error_code = 0;
|
|
int HTG_temporary_severity = 0;
|
|
short HTG_compile_level_flag = 0;
|
|
short HTG_compile_level_default = 0;
|
|
short HTG_assemble_flag = 0;
|
|
short HTG_full_compile_flag = 0;
|
|
short HTG_make_object_flag = 0;
|
|
short HTG_list_flag = 0;
|
|
short HTG_xref_flag = 0;
|
|
/* short HTG_sym_flag = 0; */
|
|
short HTG_debug_lines_flag = 0;
|
|
short HTG_offset_flag = 0;
|
|
short HTG_verbose = 0;
|
|
short HTG_verbose_verbose = 0;
|
|
short HTG_all_calls_dynamic = 0;
|
|
short HTG_retain_symbols = 0;
|
|
short HTG_dynamic_flag = 0;
|
|
short HTG_shlib_soname_flag = 0;
|
|
short HTG_libcob = 0;
|
|
|
|
char HTG_COPYDIR[PATHMAX1 + 2] = "";
|
|
char HTG_TMPDIR[PATHMAX];
|
|
char HTG_CCX_CMD[PATHMAX];
|
|
char HTG_ASX_CMD[PATHMAX];
|
|
char HTG_ARX_CMD[PATHMAX];
|
|
char HTG_RANLIBX_CMD[PATHMAX];
|
|
|
|
/* char HTG_ASMLST[PATHMAX]; */
|
|
char HTG_OBJECT[PATHMAX];
|
|
char HTG_EXECUTABLE[PATHMAX];
|
|
char HTG_LIBNAME[PATHMAX];
|
|
char HTG_LD_OPTIONS[120] = "";
|
|
char HTG_LD_PATHS[120] = "";
|
|
/* char HTG_LD_ARGS[120] = ""; */
|
|
char HTG_LD_ARGS[PATHMAX2] = "";
|
|
char HTG_LD_RESOPT_ARGS[PATHMAX2] = "";
|
|
char HTG_LD_CMDLINE_ARGS[PATHMAX2] = "";
|
|
char HTG_LD_DCALL_ARGS[120] = "";
|
|
char HTG_LD_TERM_ARGS[120] = "";
|
|
char HTG_LD_IO_ARGS[120] = "";
|
|
char HTG_LD_HT1_ARGS[120] = "";
|
|
/* char HTG_LD_HT2_ARGS[120] = ""; */
|
|
char HTG_LD_EXTRA_ARGS[120] = "";
|
|
char HTG_LD_MATH_ARGS[120] = "";
|
|
char HTG_LD_READLINE_ARGS[120] = "";
|
|
char HTG_LD_DYNAMIC[10] = "";
|
|
|
|
char HTG_PCAL_RESOPT_ARGS[PATHMAX] = "";
|
|
char HTG_SHLIB_NAME_DEFAULT[120] = "";
|
|
|
|
char HTG_LD_FLAGS[256] = "";
|
|
|
|
char file_path[PATHMAX];
|
|
char file_base[PATHMAX];
|
|
char file_ext[PATHMAX];
|
|
char ofile[PATHMAX];
|
|
char COBFLAGS[64];
|
|
char file_pgmlist_suffix[PATHMAX] = ".lis";
|
|
char lib_prefix[PATHMAX] = "tcob";
|
|
int HTG_grp_desc_len = FLD_DESC_SIZE0;
|
|
int HTG_fld_desc_len = FLD_DESC_SIZE1;
|
|
|
|
char COBDIR[PATHMAX];
|
|
char COBOPT[PATHMAX];
|
|
char PWD[PATHMAX];
|
|
|
|
#if defined(__MINGW32__ )
|
|
char COBINSTDIR[PATHMAX];
|
|
#endif
|
|
|
|
char cmdstr[PATHMAX + PATHMAX1 + 1];
|
|
|
|
char HTG_codeFormat;
|
|
char cobpp_flag_E;
|
|
char cobpp_tabs[10];
|
|
int HTG_tab2space;
|
|
char *cobpp_fpath;
|
|
char HTG_process_level;
|
|
|
|
char HTG_FNAME_SUFFIX[PATHMAX3] = "";
|
|
char fpath[PATHMAX1 + 2] = "";
|
|
char fsuffix[PATHMAX] = "";
|
|
|
|
FILE *yyin;
|
|
FILE *o_src;
|
|
FILE *o_lst;
|
|
|
|
extern FILE *pp_yyin;
|
|
extern FILE *pp_yyout;
|
|
extern FILE *pp_yylist;
|
|
extern char *pp_filename;
|
|
|
|
extern int pp_yyparse(void);
|
|
|
|
/* Internal function declarations */
|
|
int check_option (char *, char *);
|
|
static void init_env (char *buf, const char *env, const char *def);
|
|
void process_verbose_options (int ac, char *av[]);
|
|
void process_bind_options (char *arglist);
|
|
void initialize_setup (void);
|
|
void append_include_path(char *ap);
|
|
void setup_filenames(void);
|
|
void print_compiler_banner(void);
|
|
void print_copybooks_path(void);
|
|
void setup_ld_paths(void);
|
|
void print_listing_file(void);
|
|
int process_pp(void);
|
|
int process_compile (void);
|
|
void process_select_verify(char compile_level);
|
|
int find_source_file(void);
|
|
void copytrip (char *sout, char *sin);
|
|
void get_compile_level_default(void);
|
|
void pass_options_ld (char *s);
|
|
|
|
char OPTFILE[PATHMAX];
|
|
char argtmp[PATHMAX];
|
|
char *prg_name;
|
|
char pgm_suffixes[PATHMAX] = HTG_PGM_SUFFIXES;
|
|
|
|
int HTG_prg_uses_fileio = 0;
|
|
int HTG_prg_uses_term = 0;
|
|
int HTG_prg_uses_dcall = 0;
|
|
|
|
int HTG_norun = 0;
|
|
|
|
extern int stabs_on_sw;
|
|
extern int read_compiler_options(void);
|
|
|
|
int process_command_line (int argc, char *argv[])
|
|
{
|
|
int sw, idx=0;
|
|
|
|
|
|
/* **********************************************
|
|
* * Parse the command line, determining what *
|
|
* * features have been selected *
|
|
* **********************************************/
|
|
/* opterr = 0; */
|
|
while ((sw = getopt (argc, argv, option_list)) != EOF) {
|
|
/* printf("switch: %c\n", sw); */
|
|
switch (sw) {
|
|
|
|
case HTG_CMDOPT_NIL:
|
|
break;
|
|
case HTG_CMDOPT_DEBUG_LINES:
|
|
HTG_debug_lines_flag = 1;
|
|
break;
|
|
case HTG_CMDOPT_BIND_MODE:
|
|
process_bind_options(optarg);
|
|
break;
|
|
case HTG_CMDOPT_OUTPUT_NAME:
|
|
strcpy (ofile, optarg);
|
|
break;
|
|
case HTG_CMDOPT_INCLUDE_PATH:
|
|
if (idx == 0) {
|
|
strcpy (HTG_COPYDIR, "");
|
|
idx = 1;
|
|
}
|
|
append_include_path(optarg);
|
|
break;
|
|
case HTG_CMDOPT_DEBUG:
|
|
stabs_on_sw = 1;
|
|
strcat (HTG_LD_OPTIONS, "-g ");
|
|
break;
|
|
case HTG_CMDOPT_LISTING:
|
|
HTG_list_flag = TRUE;
|
|
break;
|
|
/* Set entry module to call from main */
|
|
/*
|
|
auto (1) - Use the first encountered 'STOP RUN' statement,
|
|
and if found, generate a program entry point.
|
|
first(2) - Use the first encountered 'PROGRAM-ID' statement,
|
|
and if found, generate a program entry point.
|
|
none (0) - Do not generate any program entry point.
|
|
(3) - Specific program entry point defined using
|
|
the '-e' CMD line option.
|
|
*/
|
|
/* Specify main entry point name */
|
|
case HTG_CMDOPT_ENTRY_NAME:
|
|
main_flag = 3;
|
|
strncpy(main_entry_buf, optarg, MAXNAMEBUF);
|
|
break;
|
|
/* Specify the main entry point action */
|
|
case HTG_CMDOPT_MAIN_ENTRY:
|
|
if (main_flag != 3) {
|
|
if (strcasecmp(optarg, "NONE") == 0) {
|
|
main_flag = 0;
|
|
}
|
|
else {
|
|
if (strcasecmp(optarg, "AUTO") == 0) {
|
|
main_flag = 1;
|
|
}
|
|
else {
|
|
if (strcasecmp(optarg, "FIRST") == 0) {
|
|
main_flag = 2;
|
|
}
|
|
else {
|
|
fprintf (stdout, "Invalid entry point action option '%s' ... ignoring\n", optarg);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
/* case HTG_CMDOPT_MODULE: */
|
|
case HTG_CMDOPT_LIB_SHARED:
|
|
process_select_verify (HTG_CMDOPT_LIB_SHARED);
|
|
module_flag = TRUE;
|
|
strcat (HTG_LD_OPTIONS, "-shared ");
|
|
main_entry_flag = FALSE;
|
|
main_flag = FALSE;
|
|
HTG_compile_level_flag = HTG_COMPILE_LEVEL_PCAM;
|
|
/* strcpy (HTG_LIBNAME, optarg); */
|
|
break;
|
|
case HTG_CMDOPT_LIB_STATIC:
|
|
process_select_verify (HTG_CMDOPT_LIB_STATIC);
|
|
module_flag = TRUE;
|
|
HTG_compile_level_flag = HTG_COMPILE_LEVEL_PCAS;
|
|
break;
|
|
case HTG_CMDOPT_EXECUTABLE:
|
|
process_select_verify (HTG_CMDOPT_EXECUTABLE);
|
|
/* HTG_full_compile_flag = TRUE; */
|
|
HTG_compile_level_flag = HTG_COMPILE_LEVEL_PCAL;
|
|
break;
|
|
case HTG_CMDOPT_SOURCE_OPEN:
|
|
HTG_codeFormat = 'x';
|
|
break;
|
|
case HTG_CMDOPT_SOURCE_FIXED:
|
|
HTG_codeFormat = 'f';
|
|
break;
|
|
case HTG_CMDOPT_PREPROCESSOR:
|
|
process_select_verify (HTG_CMDOPT_PREPROCESSOR);
|
|
HTG_compile_level_flag = HTG_COMPILE_LEVEL_P;
|
|
cobpp_flag_E = '1';
|
|
break;
|
|
case HTG_CMDOPT_COMPILE:
|
|
process_select_verify (HTG_CMDOPT_COMPILE);
|
|
HTG_compile_level_flag = HTG_COMPILE_LEVEL_PC;
|
|
HTG_assemble_flag = TRUE;
|
|
break;
|
|
case HTG_CMDOPT_TAB_NUMBER:
|
|
strncpy (cobpp_tabs, optarg, 10);
|
|
cobpp_tabs[9] = '\0';
|
|
sscanf(cobpp_tabs, "%d", &HTG_tab2space);
|
|
break;
|
|
#if 0
|
|
case 't':
|
|
cobpp_flag_t = '1';
|
|
break;
|
|
#endif
|
|
case HTG_CMDOPT_ASSEMBLE:
|
|
process_select_verify (HTG_CMDOPT_ASSEMBLE);
|
|
HTG_make_object_flag = TRUE;
|
|
HTG_compile_level_flag = HTG_COMPILE_LEVEL_PCA;
|
|
break;
|
|
|
|
/* HTG_CMDOPT_INCLUDE_LIB 'l' */
|
|
case HTG_CMDOPT_INCLUDE_LIB:
|
|
strcat (HTG_LD_CMDLINE_ARGS, "-l");
|
|
strcat (HTG_LD_CMDLINE_ARGS, optarg);
|
|
strcat (HTG_LD_CMDLINE_ARGS, " ");
|
|
break;
|
|
|
|
/* HTG_CMDOPT_LIB_PATH 'L' */
|
|
case HTG_CMDOPT_LIB_PATH:
|
|
// strcat (HTG_LD_CMDLINE_ARGS, "-L");
|
|
// strcat (HTG_LD_CMDLINE_ARGS, optarg);
|
|
// strcat (HTG_LD_CMDLINE_ARGS, " ");
|
|
strcat (HTG_LD_PATHS, " ");
|
|
strcat (HTG_LD_PATHS, "-L");
|
|
strcat (HTG_LD_PATHS, optarg);
|
|
strcat (HTG_LD_PATHS, " ");
|
|
break;
|
|
|
|
/* HTG_CMDOPT_PASS_OPTIONS 'W' */
|
|
case HTG_CMDOPT_PASS_OPTIONS:
|
|
if (optarg != NULL) {
|
|
if (*optarg != 'l' ) {
|
|
fprintf (stderr, "Invalid sub-option \'%c\' selected ... ignoring", *optarg);
|
|
}
|
|
else {
|
|
pass_options_ld (optarg);
|
|
}
|
|
}
|
|
break;
|
|
|
|
case HTG_CMDOPT_VERY_VERBOSE:
|
|
/* HTG_verbose_verbose = TRUE; */
|
|
/* HTG_verbose = TRUE; */
|
|
break;
|
|
case HTG_CMDOPT_VERBOSE:
|
|
/* HTG_verbose = TRUE; */
|
|
break;
|
|
|
|
case HTG_CMDOPT_TESTMODE:
|
|
HTG_retain_symbols = TRUE;
|
|
break;
|
|
|
|
case HTG_CMDOPT_NORUN:
|
|
HTG_norun = TRUE;
|
|
HTG_verbose = TRUE;
|
|
break;
|
|
case HTG_CMDOPT_CALLS_DYNAMIC:
|
|
HTG_all_calls_dynamic = TRUE;
|
|
break;
|
|
case HTG_CMDOPT_LIBCOB:
|
|
HTG_libcob = TRUE;
|
|
strcpy(lib_prefix, "cob");
|
|
printf("Lib cob option on (%s)!!\n", lib_prefix);
|
|
HTG_grp_desc_len = CFLD_DESC_SIZE0;
|
|
HTG_fld_desc_len = CFLD_DESC_SIZE1;
|
|
break;
|
|
case HTG_CMDOPT_VERSION:
|
|
fprintf (stdout, "%s - %s\n", HTG_PGM_NAME, TCOB_PGM_VERSION);
|
|
fprintf (stdout, "%s", HTG_COPYWR);
|
|
exit (0);
|
|
break;
|
|
case HTG_CMDOPT_HELP:
|
|
default:
|
|
fprintf (stdout, "Usage: %s [options] file\n%s", argv[0], HTG_OPTIONS);
|
|
exit (0);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (HTG_compile_level_flag == HTG_COMPILE_LEVEL) {
|
|
if (HTG_compile_level_default == HTG_COMPILE_LEVEL) {
|
|
HTG_compile_level_flag = HTG_COMPILE_LEVEL_PCAL;
|
|
}
|
|
else {
|
|
HTG_compile_level_flag = HTG_compile_level_default;
|
|
}
|
|
}
|
|
|
|
/* fprintf (stderr, "debug: process_command_line 9: HTG_compile_level_flag=%d, HTG_compile_level_default=%d;\n", HTG_compile_level_flag, HTG_compile_level_default); */
|
|
|
|
return optind;
|
|
}
|
|
|
|
/* **********************************************
|
|
* * Clean up working files as needed. *
|
|
* **********************************************/
|
|
void do_file_cleanup ()
|
|
{
|
|
if (HTG_retain_symbols != TRUE) {
|
|
switch (HTG_compile_level_flag) {
|
|
|
|
case HTG_COMPILE_LEVEL_P:
|
|
break;
|
|
|
|
case HTG_COMPILE_LEVEL_PC:
|
|
remove (working_filename);
|
|
break;
|
|
|
|
case HTG_COMPILE_LEVEL_PCA:
|
|
remove (working_filename);
|
|
remove (output_filename);
|
|
break;
|
|
|
|
case HTG_COMPILE_LEVEL_PCAL:
|
|
case HTG_COMPILE_LEVEL_PCAS:
|
|
case HTG_COMPILE_LEVEL_PCAM:
|
|
remove (working_filename);
|
|
remove (output_filename);
|
|
remove (HTG_OBJECT);
|
|
break;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
/* **********************************************
|
|
* * Execute assembler to generate object file *
|
|
* **********************************************/
|
|
int process_assemble (void)
|
|
{
|
|
int rc=0;
|
|
|
|
if (stabs_on_sw == 1) {
|
|
/* Note: The '--gstabs' will not work properly
|
|
* It will generate stabs in the assembler and override the TC ones.
|
|
* sprintf (sys_buf, "%s -D --gstabs -o %s %s", HTG_ASX_CMD, HTG_OBJECT, output_filename);
|
|
*/
|
|
sprintf (sys_buf, "%s -D -o %s %s", HTG_ASX_CMD, HTG_OBJECT, output_filename);
|
|
}
|
|
else {
|
|
sprintf (sys_buf, "%s -o %s %s", HTG_ASX_CMD, HTG_OBJECT, output_filename);
|
|
}
|
|
|
|
if (HTG_verbose == TRUE)
|
|
printf ("%s\n", sys_buf);
|
|
|
|
if (HTG_verbose_verbose == TRUE)
|
|
printf ("Compiler assembly phase ... ");
|
|
|
|
if (HTG_norun == 0)
|
|
rc = system (sys_buf);
|
|
|
|
if (HTG_verbose_verbose == TRUE )
|
|
printf ("return code = %2d\n", rc);
|
|
|
|
if (rc > 0)
|
|
return (8);
|
|
|
|
return rc;
|
|
}
|
|
|
|
|
|
/* **************************************************
|
|
* * Execute link edit to generate executable file *
|
|
* **************************************************/
|
|
int process_ld (void)
|
|
{
|
|
int rc=0;
|
|
|
|
sprintf (sys_buf, "%s ", HTG_CCX_CMD);
|
|
if (strlen(HTG_LD_OPTIONS) > 0)
|
|
strcat(sys_buf, HTG_LD_OPTIONS);
|
|
|
|
strcat(sys_buf, "-o ");
|
|
strcat(sys_buf, HTG_EXECUTABLE);
|
|
strcat(sys_buf, " ");
|
|
strcat(sys_buf, HTG_OBJECT);
|
|
strcat(sys_buf, " ");
|
|
|
|
if (strlen(HTG_LD_DYNAMIC) > 0) {
|
|
strcat(sys_buf, HTG_LD_DYNAMIC);
|
|
// printf("HTG_LD_DYNAMIC=%s\n",HTG_LD_DYNAMIC);
|
|
strcat(sys_buf, " ");
|
|
}
|
|
|
|
if (strlen(HTG_LD_FLAGS) > 0) {
|
|
strcat(sys_buf, HTG_LD_FLAGS);
|
|
// printf("HTG_LD_FLAGS=%s\n",HTG_LD_FLAGS);
|
|
strcat(sys_buf, " ");
|
|
}
|
|
|
|
|
|
if (strlen(HTG_LD_CMDLINE_ARGS) > 0)
|
|
{
|
|
strcat(sys_buf, HTG_LD_CMDLINE_ARGS);
|
|
// printf("HTG_LD_CMDLINE_ARGS=%s\n",HTG_LD_CMDLINE_ARGS);
|
|
}
|
|
|
|
|
|
if (strlen(HTG_LD_RESOPT_ARGS) > 0) {
|
|
strcat(sys_buf, HTG_LD_RESOPT_ARGS);
|
|
// printf("HTG_LD_RESOPT_ARGS=%s\n",HTG_LD_RESOPT_ARGS);
|
|
strcat(sys_buf, " ");
|
|
}
|
|
|
|
|
|
if (HTG_verbose == TRUE)
|
|
printf ("%s\n", sys_buf);
|
|
|
|
if (HTG_verbose_verbose == TRUE)
|
|
printf ("linking %s ... ", HTG_EXECUTABLE);
|
|
|
|
if (HTG_norun == 0)
|
|
rc = system (sys_buf);
|
|
|
|
if (HTG_verbose_verbose == TRUE)
|
|
printf ("return code = %2d\n", rc);
|
|
|
|
if (rc > 0)
|
|
return (12);
|
|
|
|
return rc;
|
|
}
|
|
|
|
/* **************************************************
|
|
* * Execute link edit to generate shared library *
|
|
* **************************************************/
|
|
int process_shlib_ld (void)
|
|
{
|
|
int rc=0;
|
|
|
|
sprintf (sys_buf, "%s ", HTG_CCX_CMD);
|
|
if (strlen(HTG_LD_OPTIONS) > 0)
|
|
strcat(sys_buf, HTG_LD_OPTIONS);
|
|
/*
|
|
${CCX} -shared -Wl,--out-implib,${lib_name1}.dll.a -o ${SHARED_LIB1} $(OBJD1) ${LIBS}
|
|
${CCX} -shared -Wl,--out-implib,${lib_name2}.dll.a,--output-def,${lib_name2}.def -o ${SHARED_LIB2} $(OBJS2) ${LIBS}
|
|
${CCX} -shared -Wl,-soname,lib${lib_name1}.so.0 -o ${SHARED_LIB1} $(OBJD1) ${LIBS}
|
|
*/
|
|
if (HTG_shlib_soname_flag == 0) {
|
|
#ifndef WIN32
|
|
strcat(sys_buf, "-Wl,-soname,");
|
|
strcat(sys_buf, HTG_LIBNAME);
|
|
#else
|
|
strcat(sys_buf, "-Wl,--enable-auto-import,--out-implib,");
|
|
strcat(sys_buf, HTG_LIBNAME);
|
|
strcat(sys_buf, ".a,--output-def,");
|
|
strcat(sys_buf, file_base);
|
|
strcat(sys_buf, ".def");
|
|
#endif
|
|
}
|
|
|
|
strcat(sys_buf," -o ");
|
|
strcat(sys_buf, HTG_EXECUTABLE);
|
|
strcat(sys_buf, " ");
|
|
strcat(sys_buf, HTG_OBJECT);
|
|
strcat(sys_buf, " ");
|
|
strcat(sys_buf, HTG_LD_PATHS);
|
|
strcat(sys_buf, " ");
|
|
strcat(sys_buf, HTG_LD_HT1_ARGS);
|
|
strcat(sys_buf, " ");
|
|
/* strcat(HTG_LD_ARGS, HTG_LD_HT2_ARGS); */
|
|
/* strcat(sys_buf, " "); */
|
|
|
|
if (HTG_verbose == TRUE)
|
|
printf ("%s\n", sys_buf);
|
|
|
|
if (HTG_verbose_verbose == TRUE)
|
|
printf ("linking %s ... ", HTG_EXECUTABLE);
|
|
|
|
if (HTG_norun == 0)
|
|
rc = system (sys_buf);
|
|
|
|
if (HTG_verbose_verbose == TRUE)
|
|
printf ("return code = %2d\n", rc);
|
|
|
|
if (rc > 0)
|
|
return (12);
|
|
|
|
return rc;
|
|
}
|
|
|
|
/* **************************************************
|
|
* * Execute link edit to generate static library *
|
|
* **************************************************/
|
|
int process_lib_ld (void)
|
|
{
|
|
int rc=0;
|
|
|
|
sprintf (sys_buf, "%s cr %s %s ", HTG_ARX_CMD, HTG_EXECUTABLE, HTG_OBJECT);
|
|
|
|
if (HTG_verbose == TRUE)
|
|
printf ("%s\n", sys_buf);
|
|
|
|
if (HTG_verbose_verbose == TRUE)
|
|
printf ("creating archive %s ... ", HTG_EXECUTABLE);
|
|
|
|
if (HTG_norun == 0)
|
|
rc = system (sys_buf);
|
|
|
|
if (HTG_verbose_verbose == TRUE)
|
|
printf ("return code = %2d\n", rc);
|
|
|
|
if (rc > 0)
|
|
return (12);
|
|
|
|
sprintf (sys_buf, "%s %s ", HTG_RANLIBX_CMD, HTG_EXECUTABLE);
|
|
|
|
if (HTG_verbose == TRUE)
|
|
printf ("%s\n", sys_buf);
|
|
|
|
if (HTG_verbose_verbose == TRUE)
|
|
printf ("ranlib archive %s ... ", HTG_EXECUTABLE);
|
|
|
|
if (HTG_norun == 0)
|
|
rc = system (sys_buf);
|
|
|
|
if (HTG_verbose_verbose == TRUE)
|
|
printf ("return code = %2d\n", rc);
|
|
|
|
if (rc > 0)
|
|
return (12);
|
|
|
|
return rc;
|
|
}
|
|
|
|
/* **************************************************
|
|
* * Read $COBDIR/htcobolrc for compiler options *
|
|
* **************************************************/
|
|
int read_compiler_options (void)
|
|
{
|
|
FILE *cobopt;
|
|
char optbfr[PATHMAX2 + 1];
|
|
char optstr[PATHMAX2 + 1];
|
|
char optarg[PATHMAX2 + 1];
|
|
int i, j, len, r=0;
|
|
|
|
i = 0;
|
|
j = 0;
|
|
|
|
if ((cobopt = fopen (OPTFILE, "r")) == NULL) {
|
|
fprintf (stderr, "Cobol parameter file '%s' not found - using configure defaults\n", OPTFILE);
|
|
return (1);
|
|
}
|
|
|
|
if (HTG_verbose_verbose == TRUE) {
|
|
printf ("Processing compiler options file parameters\n");
|
|
}
|
|
|
|
i = 0;
|
|
j = 0;
|
|
optstr[0] = 0;
|
|
optarg[0] = 0;
|
|
fgets (optbfr, PATHMAX2, cobopt);
|
|
while (!feof (cobopt)) {
|
|
|
|
len = strlen (optbfr);
|
|
if (len > 1 && optbfr[0] != '#') {
|
|
|
|
while (optbfr[i] != ' ' && i < len) {
|
|
optstr[j] = optbfr[i];
|
|
i++;
|
|
j++;
|
|
optstr[j] = 0;
|
|
}
|
|
j = 0;
|
|
len = strlen (optbfr);
|
|
while (i < len) {
|
|
optarg[j] = optbfr[i];
|
|
i++;
|
|
j++;
|
|
optarg[j] = 0;
|
|
}
|
|
if (strlen (optarg) == 0) {
|
|
optstr[strlen (optstr) - 1] = 0;
|
|
}
|
|
else {
|
|
optarg[strlen (optarg) - 1] = 0;
|
|
}
|
|
#if 0
|
|
len = strlen (optstr);
|
|
if (len > 0 && optstr[0] != '#') {
|
|
check_option (optstr, optarg);
|
|
}
|
|
#endif
|
|
r += check_option (optstr, optarg);
|
|
|
|
}
|
|
i = 0;
|
|
j = 0;
|
|
optstr[0] = 0;
|
|
optarg[0] = 0;
|
|
fgets (optbfr, PATHMAX2, cobopt);
|
|
}
|
|
fclose (cobopt);
|
|
return r;
|
|
}
|
|
|
|
|
|
int check_option (char *option_in, char *arg)
|
|
{
|
|
|
|
int i, j, r=0;
|
|
|
|
for (i=0, j=0; option[i].opt != NULL; i++) {
|
|
if (strcmp (option[i].opt, option_in) == 0) {
|
|
j = option[i].sel;
|
|
break;
|
|
}
|
|
}
|
|
|
|
/* fprintf (stderr, "debug: check_option 0: i=%d, j=%d, option=%s;\n", i, j, option[i].opt); */
|
|
|
|
switch (j)
|
|
{
|
|
case HTG_RESOPT_LIST:
|
|
HTG_list_flag = TRUE;
|
|
break;
|
|
case HTG_RESOPT_NOLIST:
|
|
HTG_list_flag = FALSE;
|
|
break;
|
|
case HTG_RESOPT_LD_PATH:
|
|
copytrip (HTG_LD_PATHS, arg);
|
|
break;
|
|
#if 0
|
|
case HTG_RESOPT_LD_LIBS:
|
|
strcpy (HTG_LD_ARGS, arg+1);
|
|
break;
|
|
#endif
|
|
case HTG_RESOPT_XREF:
|
|
HTG_xref_flag = TRUE;
|
|
break;
|
|
case HTG_RESOPT_NOXREF:
|
|
HTG_xref_flag = FALSE;
|
|
break;
|
|
case HTG_RESOPT_PGM_SUFFIXES:
|
|
copytrip (pgm_suffixes, arg);
|
|
break;
|
|
case HTG_RESOPT_LD_FLAGS:
|
|
copytrip (HTG_LD_FLAGS, arg);
|
|
break;
|
|
case HTG_RESOPT_LD_IO_LIBS:
|
|
copytrip (HTG_LD_IO_ARGS, arg);
|
|
break;
|
|
case HTG_RESOPT_LD_TERM_LIBS:
|
|
copytrip (HTG_LD_TERM_ARGS, arg);
|
|
break;
|
|
case HTG_RESOPT_LD_DCALL_LIBS:
|
|
copytrip (HTG_LD_DCALL_ARGS, arg);
|
|
break;
|
|
case HTG_RESOPT_LD_HT1_LIBS:
|
|
copytrip (HTG_LD_HT1_ARGS, arg);
|
|
break;
|
|
#if 0
|
|
case HTG_RESOPT_LD_HT2_LIBS:
|
|
copytrip (HTG_LD_HT2_ARGS, arg);
|
|
break;
|
|
#endif
|
|
case HTG_RESOPT_LD_EXTRA_LIBS:
|
|
copytrip (HTG_LD_EXTRA_ARGS, arg);
|
|
break;
|
|
case HTG_RESOPT_LD_READLINE_LIBS:
|
|
copytrip (HTG_LD_READLINE_ARGS, arg);
|
|
break;
|
|
case HTG_RESOPT_PGM_FORMAT_FIXED:
|
|
HTG_codeFormat = 'f';
|
|
break;
|
|
case HTG_RESOPT_PGM_FORMAT_FREE:
|
|
HTG_codeFormat = 'x';
|
|
break;
|
|
case HTG_RESOPT_INCLUDE_PATH:
|
|
/* append_include_path(arg+1); */
|
|
copytrip (HTG_COPYDIR, arg);
|
|
break;
|
|
|
|
#if 0
|
|
case HTG_RESOPT_COPYBOOK_SUFFIXES:
|
|
fprintf (stderr, "debug: check_option 1: HTG_RESOPT_COPYBOOK_SUFFIXES=%d;\n", HTG_CMDOPT_COPYBOOK_SUFFIXES);
|
|
break;
|
|
#endif
|
|
|
|
case HTG_RESOPT_CCX_CMD:
|
|
copytrip (HTG_CCX_CMD, arg);
|
|
break;
|
|
case HTG_RESOPT_ASX_CMD:
|
|
copytrip (HTG_ASX_CMD, arg);
|
|
break;
|
|
|
|
case HTG_RESOPT_ARX_CMD:
|
|
copytrip (HTG_ARX_CMD, arg);
|
|
break;
|
|
|
|
case HTG_RESOPT_RANLIBX_CMD:
|
|
copytrip (HTG_RANLIBX_CMD, arg);
|
|
break;
|
|
|
|
case HTG_RESOPT_LD_MATH_LIBS:
|
|
copytrip (HTG_LD_MATH_ARGS, arg);
|
|
break;
|
|
|
|
case HTG_RESOPT_PGMLIST_SUFFIX:
|
|
copytrip (file_pgmlist_suffix, arg);
|
|
break;
|
|
|
|
case HTG_RESOPT_DEBUG_LINES:
|
|
HTG_debug_lines_flag = 1;
|
|
break;
|
|
|
|
case HTG_RESOPT_NODEBUG_LINES:
|
|
HTG_debug_lines_flag = 0;
|
|
break;
|
|
|
|
case HTG_RESOPT_COMPILE_DEFAULT:
|
|
copytrip (HTG_PCAL_RESOPT_ARGS, arg);
|
|
get_compile_level_default();
|
|
break;
|
|
|
|
case HTG_RESOPT_SHLIB_NAME_DEFAULT:
|
|
copytrip (HTG_SHLIB_NAME_DEFAULT, arg);
|
|
break;
|
|
|
|
case HTG_RESOPT_PGM_ENTRY_POINT_AUTO:
|
|
main_flag = 1;
|
|
break;
|
|
|
|
case HTG_RESOPT_PGM_ENTRY_POINT_FIRST:
|
|
main_flag = 2;
|
|
break;
|
|
|
|
case HTG_RESOPT_PGM_ENTRY_POINT_NONE:
|
|
main_flag = FALSE;
|
|
break;
|
|
|
|
default:
|
|
fprintf (stderr, "%s: *** WARNING - Unknown resource file option '%s'. Ignoring.\n", prg_name, option_in);
|
|
r = 4;
|
|
}
|
|
|
|
return r;
|
|
}
|
|
|
|
void copytrip (char *sout, char *sin)
|
|
{
|
|
char *pt1, *pt2;
|
|
int len, i;
|
|
|
|
pt1=NULL;
|
|
pt2=NULL;
|
|
|
|
/* fprintf (stderr, "debug: copytrip 0: sin=%s;\n", sin); */
|
|
|
|
len = strlen(sin);
|
|
for (i=0; i<len; i++) {
|
|
if (sin[i] != ' ') {
|
|
if (pt1 == NULL) {
|
|
pt1 = sin + i;
|
|
pt2 = sin + i;
|
|
}
|
|
else {
|
|
pt2 = sin + i;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (pt1 != NULL) {
|
|
if ((i = pt2 - pt1) >= 0) {
|
|
// if(*pt1 == '$') { // walter garrote: get the environment variable
|
|
// pt1 = getenv(pt1 + 1);
|
|
// i = strlen(pt1);
|
|
// }
|
|
strncpy(sout, pt1, i+1);
|
|
sout[i+1] = '\0';
|
|
}
|
|
}
|
|
//printf("saiu %s %s\n", sin, sout);
|
|
/* fprintf (stderr, "debug: copytrip 9: sin=%s, sout=%s;\n", sin, sout); */
|
|
|
|
}
|
|
|
|
void get_compile_level_default(void)
|
|
{
|
|
int i;
|
|
char *pt;
|
|
struct opt_sel opts_sel[6] = {
|
|
{ HTG_COMPILE_LEVEL_STR_P, HTG_COMPILE_LEVEL_P },
|
|
{ HTG_COMPILE_LEVEL_STR_PC, HTG_COMPILE_LEVEL_PC },
|
|
{ HTG_COMPILE_LEVEL_STR_PCA, HTG_COMPILE_LEVEL_PCA },
|
|
{ HTG_COMPILE_LEVEL_STR_PCAM, HTG_COMPILE_LEVEL_PCAM },
|
|
{ HTG_COMPILE_LEVEL_STR_PCAS, HTG_COMPILE_LEVEL_PCAS },
|
|
{ HTG_COMPILE_LEVEL_STR_PCAL, HTG_COMPILE_LEVEL_PCAL }
|
|
};
|
|
|
|
/* fprintf (stderr, "debug: get_compile_level_default 0: arg=%s;\n", HTG_PCAL_RESOPT_ARGS); */
|
|
|
|
for (i=5; i>=0; i--) {
|
|
pt = opts_sel[i].opt;
|
|
if (strcmp (pt, HTG_PCAL_RESOPT_ARGS) == 0) {
|
|
HTG_compile_level_default = opts_sel[i].iopt;
|
|
i=-1;
|
|
}
|
|
/* fprintf (stderr, "debug: get_compile_level_default 7: pt=%s, arg=%s;\n", pt, HTG_PCAL_RESOPT_ARGS); */
|
|
}
|
|
|
|
if (HTG_compile_level_default == 0) {
|
|
fprintf (stderr, "%s: *** WARNING - Invalid resource file option for COMPILE_DEFAULT selected '%s'. Ignoring.\n", prg_name, HTG_PCAL_RESOPT_ARGS);
|
|
}
|
|
|
|
|
|
/* fprintf (stderr, "debug: get_compile_level_default 9: HTG_compile_level_default=%d;\n", HTG_compile_level_default); */
|
|
|
|
}
|
|
|
|
int find_source_file(void)
|
|
{
|
|
int rc = 1;
|
|
char del[2] = LT_PATHSEP_STR, *pt, fpath[PATHMAX2];
|
|
struct stat sbuf;
|
|
|
|
|
|
/* Check using full path file name */
|
|
if (strlen (file_ext) != 0) {
|
|
sprintf(input_filename, "%s%s%s", file_path, file_base, file_ext);
|
|
if (stat(input_filename, &sbuf) == 0) {
|
|
rc = 0;
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
strcpy(fpath, pgm_suffixes);
|
|
pt = strtok(fpath, del);
|
|
while (pt != NULL) {
|
|
sprintf(input_filename, "%s%s%s", file_path, file_base, pt);
|
|
if (HTG_verbose_verbose == TRUE ) {
|
|
printf("Checking for source filename (fullpath) =%s\n", input_filename);
|
|
}
|
|
if (stat(input_filename, &sbuf) == 0) {
|
|
if (HTG_verbose_verbose == TRUE ) {
|
|
printf("Found source filename (fullpath) =%s\n", input_filename);
|
|
}
|
|
strcpy (file_ext, pt);
|
|
rc = 0;
|
|
pt = NULL;
|
|
}
|
|
else {
|
|
pt = strtok(NULL, del);
|
|
}
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
static void
|
|
init_env (char *buf, const char *env, const char *def)
|
|
{
|
|
char *s = getenv (env);
|
|
if (s)
|
|
strcpy (buf, s);
|
|
else
|
|
strcpy (buf, def);
|
|
}
|
|
|
|
int pexec (char *cmdstr)
|
|
{
|
|
|
|
int rc=0, i, pid, argcexe;
|
|
char *argvexe[256], *tmpt;
|
|
|
|
argcexe = 0;
|
|
tmpt = strtok(cmdstr, " ");
|
|
while (tmpt != NULL) {
|
|
argvexe[argcexe] = malloc(strlen(tmpt)+1);
|
|
strcpy(argvexe[argcexe], tmpt);
|
|
/* fprintf(stderr, "htglobals debug: argvexe[%d]:%s:\n", argcexe, argvexe[argcexe]); */
|
|
argcexe++;
|
|
tmpt = strtok(NULL, " ");
|
|
}
|
|
argvexe[argcexe] = NULL;
|
|
|
|
#ifndef __MINGW32__
|
|
|
|
switch (pid = fork())
|
|
{
|
|
case -1:
|
|
fprintf(stderr, "fork failed... aborting\n");
|
|
exit(1);
|
|
break;
|
|
|
|
case 0:
|
|
execv(argvexe[0], argvexe);
|
|
/* fprintf(stderr, "Cannot spawn \"%s\" execv failed\n", argvexe[0]); */
|
|
fprintf(stderr, "error: Failed to spawn pre-processor \"%s\"\n", argvexe[0]);
|
|
exit(12);
|
|
break;
|
|
}
|
|
|
|
/* waitpid(pid, &rc, 0); */
|
|
wait(&rc);
|
|
/* fprintf(stderr, "debug: htglobals: exec \'%s\' return status=%d\n", argvexe[0], rc); */
|
|
#else
|
|
|
|
// pid = spawnv (1, argvexe[0], argvexe);
|
|
pid = spawnl (1, argvexe[0], argvexe[0]);
|
|
pid = cwait (&rc, pid, WAIT_CHILD);
|
|
|
|
#endif
|
|
|
|
for (i = 0; i < argcexe; i++) {
|
|
free(argvexe[i]);
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
void process_bind_options (char *arglist)
|
|
{
|
|
if (strcmp (arglist, "static") == 0) {
|
|
HTG_dynamic_flag = 1;
|
|
strcpy (HTG_LD_DYNAMIC, "-static");
|
|
strcat (HTG_LD_DYNAMIC, " ");
|
|
}
|
|
else {
|
|
if (strcmp (arglist, "dynamic") == 0) {
|
|
strcpy (HTG_LD_DYNAMIC, "-dynamic");
|
|
strcat (HTG_LD_DYNAMIC, " ");
|
|
HTG_dynamic_flag = 2;
|
|
}
|
|
else {
|
|
fprintf (stderr, "Unknown bind option %s specified, (static,dynamic) ignoring\n", arglist);
|
|
}
|
|
}
|
|
}
|
|
|
|
void process_verbose_options (int ac, char *av[])
|
|
{
|
|
int i;
|
|
char *pt, op;
|
|
|
|
for (i=1; i<ac; i++) {
|
|
/* fprintf (stderr, "htglobals debug 1: process_verbose_options: av[%d]=%s;\n", i, av[i]); */
|
|
pt = av[i];
|
|
if (*pt == '-') {
|
|
op = *(pt + 1);
|
|
/* fprintf (stderr, "htglobals debug 2: process_verbose_options: op=%c\n", op); */
|
|
switch (op) {
|
|
case HTG_CMDOPT_VERY_VERBOSE:
|
|
HTG_verbose_verbose = TRUE;
|
|
HTG_verbose = TRUE;
|
|
break;
|
|
case HTG_CMDOPT_VERBOSE:
|
|
HTG_verbose = TRUE;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
/* fprintf (stderr, "htglobals debug 3: process_verbose_options: HTG_verbose=%d, HTG_verbose_verbose=%d;\n", */
|
|
/* HTG_verbose, HTG_verbose_verbose); */
|
|
}
|
|
|
|
void initialize_setup (void)
|
|
{
|
|
int i;
|
|
|
|
HTG_codeFormat = 'x';
|
|
cobpp_flag_E = '0';
|
|
strcpy(cobpp_tabs, "8");
|
|
HTG_tab2space = 8;
|
|
cobpp_fpath = NULL;
|
|
|
|
#if defined(__MINGW32__ ) || defined(__CYGWIN__)
|
|
strcpy (HTG_CCX_CMD, "gcc.exe");
|
|
strcpy (HTG_ASX_CMD, "as.exe");
|
|
strcpy (HTG_ARX_CMD, "ar.exe");
|
|
strcpy (HTG_RANLIBX_CMD, "ranlib.exe");
|
|
#else
|
|
strcpy (HTG_CCX_CMD, "gcc");
|
|
strcpy (HTG_ASX_CMD, "as");
|
|
strcpy (HTG_ARX_CMD, "ar");
|
|
strcpy (HTG_RANLIBX_CMD, "ranlib");
|
|
#endif
|
|
|
|
/* ***********************************************
|
|
* * Hard load all of the default compiler *
|
|
* * behaviors before checking for options. *
|
|
* ***********************************************/
|
|
HTG_list_flag = FALSE;
|
|
HTG_xref_flag = FALSE;
|
|
HTG_offset_flag = FALSE;
|
|
HTG_assemble_flag = FALSE;
|
|
HTG_full_compile_flag = FALSE;
|
|
HTG_verbose = FALSE;
|
|
HTG_verbose_verbose = FALSE;
|
|
HTG_retain_symbols = FALSE;
|
|
HTG_dynamic_flag = 0;
|
|
HTG_shlib_soname_flag = 0;
|
|
|
|
HTG_RETURN_CODE = 0;
|
|
HTG_temporary_error_code = 256;
|
|
HTG_temporary_severity = 12;
|
|
|
|
stabs_on_sw = 0;
|
|
|
|
/* ***********************************************
|
|
* * Clear out all of the name spaces just to *
|
|
* * be sure that core garbage dosen't get us. *
|
|
* * This only happens once, so there shouldn't *
|
|
* * be any real performance issues. *
|
|
* ***********************************************/
|
|
for (i = 0; i < PATHMAX; i++) {
|
|
input_filename[i] = 0;
|
|
output_filename[i] = 0;
|
|
ofile[i] = 0;
|
|
list_filename[i] = 0;
|
|
file_path[i] = 0;
|
|
file_base[i] = 0;
|
|
file_ext[i] = 0;
|
|
HTG_TMPDIR[i] = 0;
|
|
COBDIR[i] = 0;
|
|
COBOPT[i] = 0;
|
|
PWD[i] = 0;
|
|
}
|
|
|
|
strcpy(HTG_COPYDIR, "");
|
|
|
|
/* **********************************************
|
|
* * Extract relevent environment variables *
|
|
* **********************************************/
|
|
init_env (COBFLAGS, "COBFLAGS", "");
|
|
init_env (HTG_TMPDIR, "TMPDIR", TMPDIR_DEFAULT_STR);
|
|
|
|
if (HTG_TMPDIR[strlen (HTG_TMPDIR) - 1] != LT_DIRSEP_CHAR)
|
|
{
|
|
strcat (HTG_TMPDIR, LT_DIRSEP_STR);
|
|
}
|
|
|
|
#ifndef __MINGW32__
|
|
init_env (COBDIR, HTG_COBDIR, COBDIR_DEFAULT);
|
|
#else
|
|
init_env (COBDIR, HTG_COBDIR, COBINSTDIR);
|
|
#endif
|
|
|
|
/* fprintf (stderr, "debug 10: initialize_setup: COBDIR=%s;\n", COBDIR); */
|
|
|
|
strcpy (OPTFILE, COBDIR);
|
|
strcat (OPTFILE, LT_DIRSEP_STR);
|
|
strcat (OPTFILE, OPTFILE_DEFAULT);
|
|
|
|
/* fprintf (stderr, "debug: initialize_setup 15: OPTFILE=%s;\n", OPTFILE); */
|
|
|
|
init_env (PWD, "PWD", COBDIR_DEFAULT);
|
|
|
|
HTG_LD_OPTIONS[0] = 0;
|
|
HTG_LD_DYNAMIC[0] = 0;
|
|
|
|
}
|
|
|
|
void setup_filenames(void)
|
|
{
|
|
int i, j, x, rc=0;
|
|
char *tp, HTG_WORK[100];
|
|
|
|
/* *******************************************
|
|
* * Isolate the base name of the file from *
|
|
* * the path. *
|
|
* *******************************************/
|
|
i = strlen (file_path);
|
|
while (i > 0 && file_path[i] != LT_DIRSEP_CHAR)
|
|
{
|
|
i--;
|
|
}
|
|
if (i > 0)
|
|
{
|
|
i++;
|
|
}
|
|
j = 0;
|
|
x = strlen (file_path);
|
|
while (i < x && i < PATHMAX)
|
|
{
|
|
file_base[j++] = file_path[i];
|
|
file_path[i++] = 0;
|
|
}
|
|
file_base[i] = 0;
|
|
|
|
/* *******************************************
|
|
* * We have basename, now look for suffix *
|
|
* *******************************************/
|
|
|
|
while (i > 0 && file_base[i] != SUFFIX_SEP_CHAR) {
|
|
i--;
|
|
}
|
|
|
|
if (file_base[i - 1] == SUFFIX_SEP_CHAR)
|
|
i++;
|
|
|
|
j = 0;
|
|
x = strlen (file_base);
|
|
|
|
while (i < x && i < PATHMAX) {
|
|
file_ext[j++] = file_base[i];
|
|
file_base[i++] = 0;
|
|
}
|
|
|
|
file_ext[i] = 0;
|
|
if (strlen (file_base) <= 0) {
|
|
strcpy (file_base, file_ext);
|
|
file_ext[0] = 0;
|
|
}
|
|
|
|
if (HTG_verbose_verbose == TRUE)
|
|
printf ("GEC=> path: (%s) base (%s) ext: (%s)\n", file_path, file_base, file_ext);
|
|
|
|
/* ***************************************************
|
|
* * Fumble around for file extension *
|
|
* * Force an extension to prevent overwriting exe *
|
|
* ***************************************************/
|
|
if (find_source_file() != 0) {
|
|
rc=8;
|
|
fprintf (stderr, "%s: Could not find input file for '%s%s%s' using search suffixes '%s'. Abort.\n",
|
|
prg_name, file_path, file_base, file_ext, pgm_suffixes);
|
|
exit(rc);
|
|
}
|
|
|
|
strcpy (working_filename, file_base);
|
|
strcat (working_filename, HTG_FILE_PPOUT_SUFFIX);
|
|
|
|
strcpy (list_filename, file_base);
|
|
strcat (list_filename, file_pgmlist_suffix);
|
|
|
|
strcpy (output_filename, file_base);
|
|
strcat (output_filename, HTG_FILE_GAS_SUFFIX);
|
|
|
|
strcpy (HTG_OBJECT, file_base);
|
|
strcat (HTG_OBJECT, HTG_FILE_OBJECT_SUFFIX);
|
|
|
|
switch (HTG_compile_level_flag)
|
|
{
|
|
|
|
case HTG_COMPILE_LEVEL_PCAS:
|
|
if (strlen (ofile) > 0) {
|
|
strcpy (HTG_EXECUTABLE, ofile);
|
|
}
|
|
else {
|
|
strcpy(HTG_EXECUTABLE, file_base);
|
|
strcat(HTG_EXECUTABLE, HTG_FILE_LIB_SUFFIX);
|
|
}
|
|
break;
|
|
|
|
case HTG_COMPILE_LEVEL_PCAM:
|
|
strcpy (HTG_WORK, HTG_SHLIB_NAME_DEFAULT);
|
|
strtok(HTG_WORK, SHLIB_SEP_STR);
|
|
tp = strtok(NULL, SHLIB_SEP_STR);
|
|
if (tp == NULL){
|
|
strcpy(HTG_LIBNAME, file_base);
|
|
tp = HTG_WORK;
|
|
tp++;
|
|
strcat(HTG_LIBNAME, tp);
|
|
}else{
|
|
strcpy(HTG_LIBNAME, HTG_WORK);
|
|
strcat(HTG_LIBNAME, file_base);
|
|
strcat(HTG_LIBNAME, tp);
|
|
}
|
|
if (strlen (ofile) > 0) {
|
|
strcpy (HTG_EXECUTABLE, ofile);
|
|
}
|
|
else {
|
|
strcpy(HTG_EXECUTABLE, HTG_LIBNAME);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
if (strlen (ofile) > 0) {
|
|
strcpy (HTG_EXECUTABLE, ofile);
|
|
}
|
|
else {
|
|
strcpy(HTG_EXECUTABLE, file_base);
|
|
}
|
|
break;
|
|
}
|
|
|
|
/* printf ("debug: htglobals (775): file_base=%s, output_filename=%s\n", file_base, output_filename); */
|
|
/* printf ("debug: htglobals (777): file_base=%s, HTG_SHLIB_NAME_DEFAULT=%s, HTG_LIBNAME=%s\n", file_base, HTG_SHLIB_NAME_DEFAULT, HTG_LIBNAME); */
|
|
}
|
|
|
|
void print_compiler_banner(void)
|
|
{
|
|
|
|
/* **********************************************
|
|
* * Print compiler banner *
|
|
* **********************************************/
|
|
|
|
if (HTG_verbose_verbose == TRUE ) {
|
|
fprintf (stdout, "%s - %s\n", HTG_PGM_NAME, TCOB_PGM_VERSION);
|
|
fprintf (stdout, "%s", HTG_COPYWR);
|
|
}
|
|
}
|
|
|
|
void print_copybooks_path(void)
|
|
{
|
|
if (HTG_verbose_verbose == TRUE ) {
|
|
printf ("Processing '%s'\n", input_filename);
|
|
printf ("Full include (copybooks) search path '%s'\n", HTG_COPYDIR);
|
|
printf ("Output file '%s'\n", output_filename);
|
|
}
|
|
}
|
|
|
|
void setup_ld_paths(void)
|
|
{
|
|
int i, cmdline_ld_math_args=0,
|
|
cmdline_ld_ht1_args=0, /*cmdline_ld_ht2_args=0,*/
|
|
cmdline_ld_io_args=0, cmdline_ld_term_args=0,
|
|
cmdline_ld_readline_args=0, cmdline_ld_dcall=0;
|
|
|
|
char *pt=NULL;
|
|
char tmp_ld_args[PATHMAX2];
|
|
|
|
strncpy(tmp_ld_args, HTG_LD_CMDLINE_ARGS, PATHMAX2 - 1);
|
|
tmp_ld_args[PATHMAX2 - 1] = '\0';
|
|
/*
|
|
i = strlen(HTG_LD_ARGS);
|
|
fprintf (stderr, "debug: setup_ld_paths 0: HTG_prg_uses_term=%d, HTG_LD_ARGS=%s, i=%d;\n",
|
|
HTG_prg_uses_term, HTG_LD_ARGS, i);
|
|
*/
|
|
i = 0;
|
|
pt = strtok(tmp_ld_args, " ");
|
|
while (pt != NULL) {
|
|
if (cmdline_ld_ht1_args == 0) {
|
|
if ((i=strcmp(HTG_LD_HT1_ARGS, pt)) == 0) {
|
|
cmdline_ld_ht1_args = 1;
|
|
}
|
|
}
|
|
#if 0
|
|
if (cmdline_ld_ht2_args == 0) {
|
|
if ((i=strcmp(HTG_LD_HT2_ARGS, pt)) == 0) {
|
|
cmdline_ld_ht2_args = 1;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
if (cmdline_ld_math_args == 0) {
|
|
if ((i=strcmp(HTG_LD_MATH_ARGS, pt)) == 0) {
|
|
cmdline_ld_math_args = 1;
|
|
}
|
|
}
|
|
|
|
if (cmdline_ld_readline_args == 0) {
|
|
if ((i=strcmp(HTG_LD_READLINE_ARGS, pt)) == 0) {
|
|
cmdline_ld_readline_args = 1;
|
|
}
|
|
}
|
|
|
|
if (cmdline_ld_dcall == 0) {
|
|
if ((i=strcmp(HTG_LD_DCALL_ARGS, pt)) == 0) {
|
|
cmdline_ld_dcall = 1;
|
|
}
|
|
}
|
|
|
|
if (cmdline_ld_io_args == 0) {
|
|
if ((i=strcmp(HTG_LD_IO_ARGS, pt)) == 0) {
|
|
cmdline_ld_io_args = 1;
|
|
}
|
|
}
|
|
|
|
if (cmdline_ld_term_args == 0) {
|
|
if ((i=strcmp(HTG_LD_TERM_ARGS, pt)) == 0) {
|
|
cmdline_ld_term_args= 1;
|
|
}
|
|
}
|
|
|
|
pt = strtok(NULL, " ");
|
|
}
|
|
|
|
if (cmdline_ld_ht1_args == 0) {
|
|
strcat(HTG_LD_ARGS, " ");
|
|
strcat(HTG_LD_ARGS, HTG_LD_HT1_ARGS);
|
|
}
|
|
|
|
/* gcc -g -o dyntest dyntest.o -rdynamic -L. -lhtcobol -lhtcobol2 -lm -ldl */
|
|
if (HTG_prg_uses_dcall == 1) {
|
|
#ifndef __MINGW32__
|
|
strcpy (HTG_LD_DYNAMIC, "-rdynamic");
|
|
strcat (HTG_LD_DYNAMIC, " ");
|
|
#endif
|
|
#if 0
|
|
if (cmdline_ld_ht2_args == 0) {
|
|
strcat(HTG_LD_ARGS, " ");
|
|
strcat(HTG_LD_ARGS, HTG_LD_HT2_ARGS);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
#ifdef WANT_READLINE
|
|
if (cmdline_ld_readline_args == 0) {
|
|
strcat(HTG_LD_ARGS, " ");
|
|
strcat(HTG_LD_ARGS, HTG_LD_READLINE_ARGS);
|
|
}
|
|
#endif
|
|
|
|
if ((i=strlen(HTG_LD_EXTRA_ARGS)) > 0) {
|
|
strcat(HTG_LD_ARGS, " ");
|
|
strcat(HTG_LD_ARGS, HTG_LD_EXTRA_ARGS);
|
|
}
|
|
|
|
/* fprintf (stderr, "debug: setup_ld_paths 1: HTG_prg_uses_term=%d, HTG_LD_ARGS=%s, i=%d;\n", */
|
|
/* HTG_prg_uses_term, HTG_LD_ARGS, i); */
|
|
|
|
if ((HTG_prg_uses_fileio != 0) && (cmdline_ld_io_args == 0) ) {
|
|
strcat(HTG_LD_ARGS, " ");
|
|
strcat(HTG_LD_ARGS, HTG_LD_IO_ARGS);
|
|
}
|
|
|
|
if ((HTG_prg_uses_term != 0) && (cmdline_ld_term_args == 0) ) {
|
|
strcat(HTG_LD_ARGS, " ");
|
|
strcat(HTG_LD_ARGS, HTG_LD_TERM_ARGS);
|
|
}
|
|
|
|
if (cmdline_ld_math_args == 0) {
|
|
strcat(HTG_LD_ARGS, " ");
|
|
strcat(HTG_LD_ARGS, HTG_LD_MATH_ARGS);
|
|
}
|
|
|
|
#ifdef WANT_ALL_DYNAMIC_LIBS
|
|
|
|
if (cmdline_ld_dcall == 0) {
|
|
strcat(HTG_LD_ARGS, " ");
|
|
strcat(HTG_LD_ARGS, HTG_LD_DCALL_ARGS);
|
|
}
|
|
|
|
#else
|
|
|
|
if ((HTG_prg_uses_dcall != 0) || (HTG_dynamic_flag == 2) ) {
|
|
if (cmdline_ld_dcall == 0) {
|
|
strcat(HTG_LD_ARGS, " ");
|
|
strcat(HTG_LD_ARGS, HTG_LD_DCALL_ARGS);
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|
|
if (strlen (HTG_LD_PATHS) > 0) {
|
|
strcpy (HTG_LD_RESOPT_ARGS, HTG_LD_PATHS);
|
|
strcat(HTG_LD_ARGS, " ");
|
|
}
|
|
strcat (HTG_LD_RESOPT_ARGS, HTG_LD_ARGS);
|
|
|
|
/* fprintf (stderr, "debug: setup_ld_paths 9: HTG_LD_ARGS=%s, HTG_prg_uses_dcall=%d, HTG_prg_uses_term=%d, HTG_prg_uses_fileio=%d, i=%d;\n", */
|
|
/* HTG_LD_ARGS, HTG_prg_uses_dcall, HTG_prg_uses_term, HTG_prg_uses_fileio, i); */
|
|
|
|
}
|
|
|
|
/* If resource file not avaiable, use configure defaults */
|
|
void setup_ld_paths_defaults(void)
|
|
{
|
|
int i, cmdline_ld_math_args=0,
|
|
cmdline_ld_ht1_args=0,/* cmdline_ld_ht2_args=0,*/
|
|
cmdline_ld_io_args=0, cmdline_ld_term_args=0,
|
|
cmdline_ld_readline_args=0,
|
|
cmdline_ld_dcall=0;
|
|
|
|
char *pt=NULL;
|
|
char tmp_ld_args[PATHMAX2];
|
|
|
|
strncpy(tmp_ld_args, HTG_LD_CMDLINE_ARGS, PATHMAX2 - 1);
|
|
tmp_ld_args[PATHMAX2 - 1] = '\0';
|
|
/* i = strlen(HTG_LD_ARGS); */
|
|
/* fprintf (stderr, "debug: setup_ld_paths 0: HTG_prg_uses_term=%d, HTG_LD_ARGS=%s, i=%d;\n", */
|
|
/* HTG_prg_uses_term, HTG_LD_ARGS, i); */
|
|
|
|
i = 0;
|
|
pt = strtok(tmp_ld_args, " ");
|
|
while (pt != NULL) {
|
|
if (cmdline_ld_ht1_args == 0) {
|
|
if ((i=strcmp(HTG_LD_ARGS_HT1, pt)) == 0) {
|
|
cmdline_ld_ht1_args = 1;
|
|
}
|
|
}
|
|
#if 0
|
|
if (cmdline_ld_ht2_args == 0) {
|
|
if ((i=strcmp(HTG_LD_ARGS_HT2, pt)) == 0) {
|
|
cmdline_ld_ht2_args = 1;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
if (cmdline_ld_math_args == 0) {
|
|
if ((i=strcmp(HTG_LD_MATH_ARGS, pt)) == 0) {
|
|
cmdline_ld_math_args = 1;
|
|
}
|
|
}
|
|
|
|
if (cmdline_ld_readline_args == 0) {
|
|
if ((i=strcmp(HTG_LD_ARGS_READLINE, pt)) == 0) {
|
|
cmdline_ld_readline_args = 1;
|
|
}
|
|
}
|
|
|
|
if (cmdline_ld_dcall == 0) {
|
|
if ((i=strcmp(HTG_LD_ARGS_DL, pt)) == 0) {
|
|
cmdline_ld_dcall = 1;
|
|
}
|
|
}
|
|
|
|
if (cmdline_ld_io_args == 0) {
|
|
if ((i=strcmp(HTG_LD_ARGS_DB, pt)) == 0) {
|
|
cmdline_ld_io_args = 1;
|
|
}
|
|
}
|
|
|
|
if (cmdline_ld_term_args == 0) {
|
|
if ((i=strcmp(HTG_LD_ARGS_CURSES, pt)) == 0) {
|
|
cmdline_ld_term_args= 1;
|
|
}
|
|
}
|
|
|
|
pt = strtok(NULL, " ");
|
|
}
|
|
|
|
if (cmdline_ld_ht1_args == 0) {
|
|
strcat(HTG_LD_ARGS, " ");
|
|
strcat(HTG_LD_ARGS, HTG_LD_ARGS_HT1);
|
|
}
|
|
|
|
/* gcc -g -o dyntest dyntest.o -rdynamic -L. -lhtcobol -lhtcobol2 -lm -ldl */
|
|
if (HTG_prg_uses_dcall == 1) {
|
|
strcpy (HTG_LD_DYNAMIC, "-rdynamic");
|
|
strcat (HTG_LD_DYNAMIC, " ");
|
|
#if 0
|
|
if (cmdline_ld_ht2_args == 0) {
|
|
strcat(HTG_LD_ARGS, " ");
|
|
strcat(HTG_LD_ARGS, HTG_LD_ARGS_HT2);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
#ifdef WANT_READLINE
|
|
if (cmdline_ld_readline_args == 0) {
|
|
strcat(HTG_LD_ARGS, " ");
|
|
strcat(HTG_LD_ARGS, HTG_LD_ARGS_READLINE);
|
|
}
|
|
#endif
|
|
|
|
|
|
if ((HTG_prg_uses_fileio != 0) && (cmdline_ld_io_args == 0) ) {
|
|
strcat(HTG_LD_ARGS, " ");
|
|
strcat(HTG_LD_ARGS, HTG_LD_ARGS_DB);
|
|
}
|
|
|
|
if ((HTG_prg_uses_term != 0) && (cmdline_ld_term_args == 0) ) {
|
|
strcat(HTG_LD_ARGS, " ");
|
|
strcat(HTG_LD_ARGS, HTG_LD_ARGS_CURSES);
|
|
}
|
|
|
|
if (cmdline_ld_math_args == 0) {
|
|
strcat(HTG_LD_ARGS, " ");
|
|
strcat(HTG_LD_ARGS, HTG_LD_MATH_ARGS);
|
|
}
|
|
|
|
#ifdef WANT_ALL_DYNAMIC_LIBS
|
|
|
|
if (cmdline_ld_dcall == 0) {
|
|
strcat(HTG_LD_ARGS, " ");
|
|
strcat(HTG_LD_ARGS, HTG_LD_ARGS_MATH);
|
|
}
|
|
|
|
#else
|
|
|
|
if ((HTG_prg_uses_dcall != 0) || (HTG_dynamic_flag == 2) ) {
|
|
if (cmdline_ld_dcall == 0) {
|
|
strcat(HTG_LD_ARGS, " ");
|
|
strcat(HTG_LD_ARGS, HTG_LD_ARGS_DL);
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
if (strlen (HTG_LD_PATHS) > 0) {
|
|
strcpy (HTG_LD_RESOPT_ARGS, HTG_LD_PATHS);
|
|
strcat(HTG_LD_ARGS, " ");
|
|
}
|
|
else {
|
|
strcpy (HTG_LD_RESOPT_ARGS, HTG_LD_PATHS_DEFAULT);
|
|
strcat(HTG_LD_ARGS, " ");
|
|
}
|
|
strcat (HTG_LD_RESOPT_ARGS, HTG_LD_ARGS);
|
|
|
|
/* fprintf (stderr, "debug: setup_ld_paths 9: HTG_LD_ARGS=%s, HTG_prg_uses_dcall=%d, HTG_prg_uses_term=%d, HTG_prg_uses_fileio=%d, i=%d;\n", */
|
|
/* HTG_LD_ARGS, HTG_prg_uses_dcall, HTG_prg_uses_term, HTG_prg_uses_fileio, i); */
|
|
|
|
strcpy (HTG_CCX_CMD, TCOB_CCX_CMD);
|
|
strcpy (HTG_ASX_CMD, TCOB_ASX_CMD);
|
|
|
|
}
|
|
|
|
|
|
void print_listing_file(void)
|
|
{
|
|
if ((o_src = fopen (output_filename, "w")) == NULL)
|
|
{
|
|
fprintf (stderr, "Output file '%s' could not be opened for writing ... aborting\n", output_filename);
|
|
exit (12);
|
|
}
|
|
|
|
/* o_src = stderr; */
|
|
if (HTG_list_flag)
|
|
{
|
|
if (HTG_verbose_verbose == TRUE )
|
|
{
|
|
printf ("Listing file '%s'\n", list_filename);
|
|
}
|
|
if ((o_lst = fopen (list_filename, "a")) == NULL)
|
|
{
|
|
fprintf (stderr, "* WARNING * Listings file %s could not be opened for writing ...\n", list_filename);
|
|
HTG_list_flag = FALSE;
|
|
HTG_RETURN_CODE = 4;
|
|
}
|
|
else
|
|
{
|
|
fprintf (o_lst, "\n\nError(s) listing:\n\n");
|
|
}
|
|
}
|
|
}
|
|
|
|
int process_pp (void)
|
|
{
|
|
int rc=0;
|
|
|
|
// fprintf (stderr, "htglobals debug 5: process_pp: HTG_verbose=%d, HTG_verbose_verbose=%d\n",
|
|
// HTG_verbose, HTG_verbose_verbose);
|
|
if (HTG_verbose_verbose == TRUE)
|
|
printf("Pre-processing '%s'\n", input_filename);
|
|
|
|
/* Open input file */
|
|
pp_filename = strdup (input_filename);
|
|
pp_yyin = fopen(input_filename, "r");
|
|
if ( pp_yyin == NULL ) {
|
|
fprintf(stderr, "Error opening input file: %s\n", input_filename);
|
|
rc = 3;
|
|
return rc;
|
|
}
|
|
|
|
/* Open output file */
|
|
if (cobpp_flag_E == '0') {
|
|
pp_yyout = fopen(working_filename, "w");
|
|
// fprintf(stderr,"Pre-processing output file '%s'\n",working_filename);
|
|
if ( pp_yyout == NULL ) {
|
|
fprintf(stderr, "Error opening output file: %s\n", working_filename);
|
|
fclose(pp_yyin);
|
|
rc = 9;
|
|
return rc;
|
|
}
|
|
}
|
|
else {
|
|
if (strlen (ofile) > 0) {
|
|
strcpy (working_filename, ofile);
|
|
pp_yyout = fopen(working_filename, "w");
|
|
if (pp_yyout == NULL) {
|
|
fprintf(stderr, "Error opening output file: %s\n", working_filename);
|
|
fclose(pp_yyin);
|
|
rc = 9;
|
|
return rc;
|
|
}
|
|
}
|
|
else {
|
|
pp_yyout = stdout;
|
|
}
|
|
}
|
|
|
|
/* Open listing file */
|
|
if (HTG_list_flag == TRUE) {
|
|
pp_yylist = fopen(list_filename, "w");
|
|
if ( pp_yylist == NULL ) {
|
|
fprintf(stderr, "Error opening listing file: %s\n", list_filename );
|
|
fclose(pp_yyin);
|
|
if (pp_yyout != stdout) {
|
|
fclose(pp_yyout);
|
|
}
|
|
rc = 11;
|
|
return rc;
|
|
}
|
|
}
|
|
|
|
// fprintf(stderr,"will pre-process....\n");
|
|
pp_setup_scanner_state();
|
|
|
|
rc = pp_yyparse();
|
|
|
|
/* fprintf(stderr, "process_pp debug: pre-processor return status=%d\n", rc); */
|
|
|
|
if ((pp_yyin != NULL) && (pp_yyin != stdin)) {
|
|
fclose(pp_yyin);
|
|
pp_yyin = NULL;
|
|
}
|
|
|
|
if ((pp_yyout != NULL) && (pp_yyout != stdout)) {
|
|
fclose(pp_yyout);
|
|
pp_yyout = NULL;
|
|
}
|
|
|
|
if (pp_yylist != NULL) {
|
|
fclose(pp_yylist);
|
|
pp_yylist = NULL;
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
int process_compile (void)
|
|
{
|
|
int rc=0;
|
|
|
|
if (HTG_norun != 0)
|
|
return rc;
|
|
|
|
if ((yyin = fopen (working_filename, "r")) == NULL) {
|
|
printf ("Input file '%s' not found or not readable\n", working_filename);
|
|
/* exit (12); */
|
|
rc = 12;
|
|
return rc;
|
|
}
|
|
|
|
/* print_compiler_banner(); */
|
|
|
|
print_copybooks_path();
|
|
|
|
print_listing_file();
|
|
|
|
if (rc > 4) {
|
|
return rc;
|
|
}
|
|
|
|
if (HTG_verbose_verbose == TRUE )
|
|
printf("Processing '%s'\n", input_filename);
|
|
|
|
install_reserved();
|
|
|
|
if (HTG_verbose_verbose == TRUE )
|
|
printf("Begining compile process ...\n");
|
|
|
|
/* yydebug=1; */
|
|
yyparse();
|
|
rc = HTG_RETURN_CODE;
|
|
/* dcs(); */ /* this is to test the copy statement replacements */
|
|
|
|
if (HTG_verbose_verbose == TRUE ) {
|
|
#if 0
|
|
printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
|
|
printf("+ +\n");
|
|
printf("+ COMPILER SUMMARY +\n");
|
|
printf("+ +\n");
|
|
printf("+ Lines compiled : %4d +\n",source_lineno);
|
|
printf("+ Number of warnings : %4d +\n",wrncnt);
|
|
printf("+ Number of errors found: %4d +\n",errcnt);
|
|
printf("+ +\n");
|
|
printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
|
|
printf("Writing listing tables...");
|
|
#endif
|
|
|
|
printf("Compiler summary:\n");
|
|
printf("Lines compiled : %4d\n",source_lineno);
|
|
printf("Number of warnings : %4d\n",wrncnt);
|
|
printf("Number of errors found: %4d\n",errcnt);
|
|
printf("Writing listing tables ... \n");
|
|
}
|
|
|
|
/*dump_symbols();*/
|
|
|
|
#if 0
|
|
if (HTG_verbose_verbose == TRUE ) {
|
|
printf("(done)\nUsed stack words: %d\n",stack_offset/2);
|
|
}
|
|
#endif
|
|
|
|
if (HTG_list_flag) {
|
|
fflush(o_lst);
|
|
fclose(o_lst);
|
|
}
|
|
fflush(o_src);
|
|
fclose(o_src);
|
|
fclose(yyin);
|
|
|
|
if (source_lineno < 1) {
|
|
rc = 16;
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
|
|
void process_select_verify (char compile_level)
|
|
{
|
|
char compile_level_0;
|
|
|
|
if (HTG_compile_level_flag != HTG_COMPILE_LEVEL) {
|
|
switch (HTG_compile_level_flag) {
|
|
|
|
case HTG_COMPILE_LEVEL_P:
|
|
compile_level_0 = 'E';
|
|
break;
|
|
|
|
case HTG_COMPILE_LEVEL_PC:
|
|
compile_level_0 = 'S';
|
|
break;
|
|
|
|
case HTG_COMPILE_LEVEL_PCA:
|
|
compile_level_0 = 'c';
|
|
break;
|
|
|
|
case HTG_COMPILE_LEVEL_PCAL:
|
|
case HTG_COMPILE_LEVEL_PCAX:
|
|
compile_level_0 = 'x';
|
|
break;
|
|
|
|
case HTG_COMPILE_LEVEL_PCAS:
|
|
compile_level_0 = 'a';
|
|
break;
|
|
|
|
case HTG_COMPILE_LEVEL_PCAM:
|
|
compile_level_0 = 'm';
|
|
break;
|
|
|
|
}
|
|
fprintf (stderr, "%s: *** Multiple and/or conflicting command line options, '%c' and '%c', selected. Abort.\n", prg_name, compile_level_0, compile_level);
|
|
exit (16);
|
|
}
|
|
}
|
|
|
|
void pass_options_ld (char *s)
|
|
{
|
|
char *tp = NULL;
|
|
|
|
strcat(HTG_LD_OPTIONS, "-W");
|
|
strcat(HTG_LD_OPTIONS, s);
|
|
strcat(HTG_LD_OPTIONS, " ");
|
|
|
|
tp = strstr(s, SHLIB_SONAME_STR);
|
|
if (tp != NULL) {
|
|
HTG_shlib_soname_flag = TRUE;
|
|
}
|
|
/* fprintf (stderr, "debug: pass_options: HTG_CMDOPT_PASS_OPTIONS=%s:\n", s); */
|
|
}
|
|
|
|
int find_copybook_file (char *fname, char *lname)
|
|
{
|
|
int r = 1, len;//, sw = 0;
|
|
char *pt,
|
|
tpath[PATHMAX1],
|
|
fname1[PATHMAX],
|
|
lname1[PATHMAX1];
|
|
|
|
//printf("find_copybook_file entrou fname %s lname %s\n", fname, lname);
|
|
if (lname == NULL) {
|
|
if ((*fname == CHR_SQUOTE) || (*fname == CHR_DQUOTE)) {
|
|
//sw = STATE_FLIT_LNONE;
|
|
strcpy(fname1, fname+1);
|
|
len = strlen(fname1);
|
|
fname1[len - 1] = CHR_EOS;
|
|
r = find_filename_literal(fname1, HTG_COPYDIR);
|
|
|
|
}
|
|
else {
|
|
//sw = STATE_FNAME_LNONE;
|
|
strcpy(fname1, fname);
|
|
strcpy(HTG_FNAME_SUFFIX, STR_SEARCH_SUFFIXES);
|
|
r = find_filename_text(fname1, HTG_COPYDIR, HTG_FNAME_SUFFIX);
|
|
}
|
|
}
|
|
else {
|
|
if ((*lname == CHR_SQUOTE) || (*lname == CHR_DQUOTE)) {
|
|
strcpy(lname1, lname+1);
|
|
len = strlen(lname1);
|
|
lname1[len - 1] = CHR_EOS;
|
|
strcpy(tpath, lname1);
|
|
len = strlen(tpath);
|
|
if (len > 0) {
|
|
if (tpath[len - 1] != CHR_COLEN) {
|
|
strcat(tpath, STR_COLEN);
|
|
}
|
|
}
|
|
if ((*fname == CHR_SQUOTE) || (*fname == CHR_DQUOTE)) {
|
|
//sw = STATE_FLIT_LLIT;
|
|
strcpy(fname1, fname+1);
|
|
len = strlen(fname1);
|
|
fname1[len - 1] = CHR_EOS;
|
|
r = find_filename_literal(fname1, tpath);
|
|
}
|
|
else {
|
|
//sw = STATE_FNAME_LLIT;
|
|
strcpy(fname1, fname);
|
|
strcpy(HTG_FNAME_SUFFIX, STR_SEARCH_SUFFIXES);
|
|
r = find_filename_text(fname1, tpath, HTG_FNAME_SUFFIX);
|
|
}
|
|
}
|
|
else {
|
|
if ((*fname == CHR_SQUOTE) || (*fname == CHR_DQUOTE)) {
|
|
//sw = STATE_FLIT_LNAME;
|
|
strcpy(fname1, fname+1);
|
|
len = strlen(fname1);
|
|
fname1[len - 1] = CHR_EOS;
|
|
strcpy(lname1, lname);
|
|
pt = find_env_variable(lname1);
|
|
if (pt != NULL) {
|
|
strcpy(tpath, pt);
|
|
}
|
|
else {
|
|
strcpy(tpath, "");
|
|
}
|
|
len = strlen(tpath);
|
|
if (len > 0) {
|
|
if (tpath[len - 1] != CHR_COLEN) {
|
|
strcat(tpath, STR_COLEN);
|
|
}
|
|
}
|
|
r = find_filename_literal(fname1, tpath);
|
|
}
|
|
else {
|
|
//sw = STATE_FNAME_LNAME;
|
|
strcpy(fname1, fname);
|
|
strcpy(lname1, lname);
|
|
strcpy(HTG_FNAME_SUFFIX, STR_SEARCH_SUFFIXES);
|
|
pt = find_env_variable(lname1);
|
|
if (pt != NULL) {
|
|
strcpy(tpath, pt);
|
|
}
|
|
else {
|
|
strcpy(tpath, "");
|
|
}
|
|
len = strlen(tpath);
|
|
if (len > 0) {
|
|
if (tpath[len - 1] != CHR_COLEN) {
|
|
strcat(tpath, STR_COLEN);
|
|
}
|
|
}
|
|
r = find_filename_text(fname1, tpath, HTG_FNAME_SUFFIX);
|
|
}
|
|
}
|
|
}
|
|
// printf("vou retornar daqui\n");
|
|
return r;
|
|
}
|
|
|
|
int find_filename_literal (char *fname, char *fp)
|
|
{
|
|
int r = 1, len, sw1=0;
|
|
char *pt1;
|
|
struct stat sbuf;
|
|
|
|
//printf("find_filename_literal entrou fname %s fp %s tamanho %i \n", fname, fp, strlen(fp));
|
|
//printf("fpath antes %s tamanho %i\n", fpath, strlen(fpath));
|
|
strcpy(fpath, fp);
|
|
//printf("fpath depois %s tamanho %i\n", fpath, strlen(fpath));
|
|
|
|
len = strlen(fpath);
|
|
if (len == 0) {
|
|
sprintf(include_full_filename, "%s", fname);
|
|
if (stat(include_full_filename, &sbuf) == 0) {
|
|
if (S_ISREG(sbuf.st_mode) &&
|
|
((S_IRUSR & sbuf.st_mode) || (S_IRGRP & sbuf.st_mode) || (S_IROTH & sbuf.st_mode))) {
|
|
r = 0;
|
|
if(HTG_verbose == TRUE) {
|
|
printf("found copybook name \'%s\'\n", include_full_filename);
|
|
}
|
|
}
|
|
else {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("copybook file \'%s\' not readable\n", include_full_filename);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("copybook file \'%s\' not found\n", include_full_filename);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
/* If filename is an absolute path ignore library path */
|
|
if (*fname == CHR_SLASH) {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("warning: ignoring other search path(s) in absolute path copybook name \'%s\'\n", fname);
|
|
}
|
|
sprintf(include_full_filename, "%s", fname);
|
|
if (stat(include_full_filename, &sbuf) == 0) {
|
|
if (S_ISREG(sbuf.st_mode) &&
|
|
((S_IRUSR & sbuf.st_mode) || (S_IRGRP & sbuf.st_mode) || (S_IROTH & sbuf.st_mode))) {
|
|
r = 0;
|
|
if(HTG_verbose == TRUE) {
|
|
printf("found copybook name \'%s\'\n", include_full_filename);
|
|
}
|
|
}
|
|
else {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("copybook file \'%s\' not readable\n", include_full_filename);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("copybook file \'%s\' not found\n", include_full_filename);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
sw1 = 0;
|
|
strcpy(fpath, fp);
|
|
pt1 = find_token(fpath, STR_COLEN, 0);
|
|
if (pt1 == NULL) {
|
|
pt1 = fpath;
|
|
}
|
|
while (sw1 == 0) {
|
|
sprintf(include_full_filename, "%s", pt1);
|
|
if (stat(include_full_filename, &sbuf) == 0) {
|
|
if (S_ISDIR(sbuf.st_mode) &&
|
|
((S_IRUSR & sbuf.st_mode) || (S_IRGRP & sbuf.st_mode) || (S_IROTH & sbuf.st_mode))) {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("searching directory path \'%s\'\n", include_full_filename);
|
|
}
|
|
sprintf(include_full_filename, "%s/%s", pt1, fname);
|
|
if (stat(include_full_filename, &sbuf) == 0) {
|
|
if (S_ISREG(sbuf.st_mode) &&
|
|
((S_IRUSR & sbuf.st_mode) || (S_IRGRP & sbuf.st_mode) || (S_IROTH & sbuf.st_mode))) {
|
|
r = 0;
|
|
if(HTG_verbose == TRUE) {
|
|
printf("found copybook name \'%s\'\n", include_full_filename);
|
|
}
|
|
sw1 = 1;
|
|
}
|
|
else {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("copybook file \'%s\' not readable\n", include_full_filename);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("copybook file \'%s\' not found\n", include_full_filename);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("directory path \'%s\' not readable\n", include_full_filename);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("directory path \'%s\' not found\n", include_full_filename);
|
|
}
|
|
}
|
|
pt1 = find_token(pt1, STR_COLEN, 1);
|
|
if (pt1 == NULL) {
|
|
sw1 = 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//printf("saindo literal %i\n",r);
|
|
return r;
|
|
}
|
|
|
|
int find_filename_text (char *fname, char *fp, char *fs)
|
|
{
|
|
int r = 1, len, sw1, sw2;
|
|
char *pt1, *pt2;
|
|
struct stat sbuf;
|
|
|
|
//printf("find_filename_text entrou fname %s fp %s fs %s\n", fname, fp, fs);
|
|
strcpy(fpath, fp);
|
|
strcpy(fsuffix, fs);
|
|
|
|
len = strlen(fpath);
|
|
if (len == 0) {
|
|
sw1 = 0;
|
|
pt1 = find_token(fsuffix, STR_COLEN, 0);
|
|
if (pt1 == NULL) {
|
|
pt1 = fsuffix;
|
|
}
|
|
while (sw1 == 0) {
|
|
sprintf(include_full_filename, "%s%s", fname, pt1);
|
|
if (stat(include_full_filename, &sbuf) == 0) {
|
|
if (S_ISREG(sbuf.st_mode) &&
|
|
((S_IRUSR & sbuf.st_mode) || (S_IRGRP & sbuf.st_mode) || (S_IROTH & sbuf.st_mode))) {
|
|
r = 0;
|
|
if(HTG_verbose == TRUE) {
|
|
printf("found copybook name \'%s\'\n", include_full_filename);
|
|
}
|
|
sw1 = 1;
|
|
}
|
|
else {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("copybook file \'%s\' not readable\n", include_full_filename);
|
|
}
|
|
}
|
|
sw1 = 1;
|
|
}
|
|
else {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("copybook file \'%s\' not found\n", include_full_filename);
|
|
}
|
|
}
|
|
pt1 = find_token(pt1, STR_COLEN, 1);
|
|
if (pt1 == NULL) {
|
|
sw1 = 1;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
sw1 = 0;
|
|
sw2 = 0;
|
|
strcpy(fpath, fp);
|
|
strcpy(fsuffix, fs);
|
|
|
|
/* FIXME: This shit must include the current directory on the search, despite of the
|
|
the directories present of htcobolrc under COPYBOOK_PATH key */
|
|
pt1 = find_token(fpath, STR_COLEN, 0);
|
|
if (pt1 == NULL) {
|
|
pt1 = fpath;
|
|
}
|
|
while (sw1 == 0) {
|
|
sprintf(include_full_filename, "%s", pt1);
|
|
if (stat(include_full_filename, &sbuf) == 0) {
|
|
if (S_ISDIR(sbuf.st_mode) &&
|
|
((S_IRUSR & sbuf.st_mode) || (S_IRGRP & sbuf.st_mode) || (S_IROTH & sbuf.st_mode))) {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("searching directory path \'%s\'\n", include_full_filename);
|
|
}
|
|
strcpy(fsuffix, fs);
|
|
sw2 = 0;
|
|
pt2 = find_token(fsuffix, STR_COLEN, 0);
|
|
while (sw2 == 0) {
|
|
sprintf(include_full_filename, "%s/%s%s", pt1, fname, pt2);
|
|
if (stat(include_full_filename, &sbuf) == 0) {
|
|
if (S_ISREG(sbuf.st_mode) &&
|
|
((S_IRUSR & sbuf.st_mode) || (S_IRGRP & sbuf.st_mode) || (S_IROTH & sbuf.st_mode))) {
|
|
r = 0;
|
|
if(HTG_verbose == TRUE) {
|
|
printf("found copybook name \'%s\'\n", include_full_filename);
|
|
}
|
|
sw1 = 1;
|
|
sw2 = 1;
|
|
}
|
|
else {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("copybook file \'%s\' not readable\n", include_full_filename);
|
|
}
|
|
}
|
|
sw2 = 1;
|
|
}
|
|
else {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("copybook file \'%s\' not found\n", include_full_filename);
|
|
}
|
|
}
|
|
pt2 = find_token(pt2, STR_COLEN, 1);
|
|
if (pt2 == NULL) {
|
|
sw2 = 1;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("directory path \'%s\' not readable\n", include_full_filename);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("directory path \'%s\' not found\n", include_full_filename);
|
|
}
|
|
}
|
|
pt1 = find_token(pt1, STR_COLEN, 1);
|
|
if (pt1 == NULL) {
|
|
sw1 = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
return r;
|
|
}
|
|
|
|
char *find_env_variable (char *ev)
|
|
{
|
|
char *pt, ev1[PATHMAX];
|
|
int i, len;
|
|
|
|
len = strlen(ev);
|
|
for (i=0; i<len; i++) {
|
|
if (*(ev+i) == STR_DASH) {
|
|
*(ev1+i) = STR_UNDERSCORE;
|
|
}
|
|
else {
|
|
*(ev1+i) = *(ev+i);
|
|
}
|
|
}
|
|
*(ev1+len) = CHR_EOS;
|
|
|
|
pt = getenv(ev1);
|
|
if (pt != NULL) {
|
|
if(HTG_verbose == TRUE) {
|
|
printf("envoromental variable \'%s\' found, setting search path(s) to \'%s\'\n", ev1, pt);
|
|
}
|
|
return pt;
|
|
}
|
|
|
|
if(HTG_verbose == TRUE) {
|
|
printf("warning: envoromental variable \'%s\' not found\n", ev1);
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
char *find_token(char *p, const char *d, int sw)
|
|
{
|
|
int i, len;
|
|
|
|
DEBUG_PPRTN_STR105("find_token trace(1): p=%s; d=%s, sw=%d\n", p, d, sw)
|
|
|
|
if (sw == 0) {
|
|
|
|
len = strlen(p);
|
|
*(p+len+1) = CHR_EOS;
|
|
for (i=0; i<len; i++) {
|
|
if (*(p+i) == *d) {
|
|
*(p+i) = CHR_EOS;
|
|
|
|
DEBUG_PPRTN_STR105("find_token trace(2): p=%s; d=%s, sw=%d\n", p, d, sw)
|
|
|
|
return p;
|
|
}
|
|
}
|
|
|
|
DEBUG_PPRTN_STR21("find_token trace(3): p=NULL; d=%s, sw=%d\n", d, sw)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
else {
|
|
|
|
len = strlen(p);
|
|
p = p + len + 1;
|
|
if (*p != CHR_EOS) {
|
|
len = strlen(p);
|
|
for (i=0; i<len; i++) {
|
|
if (*(p+i) == *d) {
|
|
*(p+i) = CHR_EOS;
|
|
|
|
DEBUG_PPRTN_STR105("find_token trace(4): p=%s; d=%s, sw=%d\n", p, d, sw)
|
|
|
|
return p;
|
|
}
|
|
}
|
|
}
|
|
|
|
DEBUG_PPRTN_STR21("find_token trace(5): p=NULL; d=%s, sw=%d\n", d, sw)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void append_include_path(char *ap)
|
|
{
|
|
int len1, len2, len3, rc=0;
|
|
|
|
len1 = strlen(HTG_COPYDIR);
|
|
len2 = strlen(ap);
|
|
len3 = len1 + len2;
|
|
|
|
if (len1 == 0) {
|
|
if (len2 < (PATHMAX1 + 1)) {
|
|
strcpy (HTG_COPYDIR, ap);
|
|
strcat (HTG_COPYDIR, STR_COLEN);
|
|
}
|
|
else {
|
|
rc = 16;
|
|
}
|
|
}
|
|
else {
|
|
if (len3 < PATHMAX1) {
|
|
strcat (HTG_COPYDIR, ap);
|
|
strcat (HTG_COPYDIR, STR_COLEN);
|
|
}
|
|
else {
|
|
rc = 16;
|
|
}
|
|
}
|
|
|
|
if(HTG_verbose == TRUE) {
|
|
fprintf (stdout, "Appending '%s' to include (copybooks) search path\n", ap);
|
|
}
|
|
|
|
if (rc != 0) {
|
|
fprintf (stderr, "%s: *** Buffer overflow error while appending '%s' to include (copybooks) search path. Abort.\n", prg_name, ap);
|
|
exit(rc);
|
|
}
|
|
|
|
}
|