OpenCOBOL 1.1pre-rel
Defines | Typedefs | Enumerations | Functions | Variables
cobc.c File Reference
#include "config.h"
#include "defaults.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <setjmp.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
#include <sys/stat.h>
#include <signal.h>
#include <getopt.h>
#include <locale.h>
#include <tarstamp.h>
#include "cobc.h"
#include "tree.h"
#include <libcob/exception.def>
#include "flag.def"
#include "warning.def"
Include dependency graph for cobc.c:

Go to the source code of this file.

Defines

#define COB_EXCEPTION(code, tag, name, critical)   {name, 0x##code, 0},
#define CB_FLAG(var, name, doc)   int var = 0;
#define CB_WARNDEF(var, name, wall, doc)   int var = 0;
#define PATHSEPS   ":"
#define COB_NUM_CSYNS   sizeof(cob_csyns) / sizeof(char *)
#define CB_FLAG(var, name, doc)
#define CB_WARNDEF(var, name, wall, doc)
#define CB_WARNDEF(var, name, wall, doc)
#define CB_FLAG(var, name, doc)
#define CB_WARNDEF(var, name, wall, doc)   var = 0;
#define CB_WARNDEF(var, name, wall, doc)   if (wall) var = 1;
#define CB_WARNDEF(var, name, wall, doc)   var = 1;

Typedefs

typedef void(* cob_sighandler_t )(int)

Enumerations

enum  cb_compile_level {
  CB_LEVEL_PREPROCESS = 1, CB_LEVEL_TRANSLATE, CB_LEVEL_COMPILE, CB_LEVEL_ASSEMBLE,
  CB_LEVEL_MODULE, CB_LEVEL_LIBRARY, CB_LEVEL_EXECUTABLE
}

Functions

void cobc_abort (const char *filename, const int linenum)
void cobc_tree_cast_error (cb_tree x, const char *filen, const int linenum, const int tagnum)
void * cobc_malloc (const size_t size)
void * cobc_realloc (void *prevptr, const size_t size)
struct cb_text_listcb_text_list_add (struct cb_text_list *list, const char *text)
size_t cobc_check_valid_name (char *name)
int main (int argc, char *argv[])

Variables

int cb_source_format = CB_FORMAT_FIXED
int cb_display_sign = COB_DISPLAY_SIGN_ASCII
struct cb_exception cb_exception_table []
int cb_id = 1
int cb_attr_id = 1
int cb_literal_id = 1
int cb_field_id = 1
int cb_storage_id = 1
int cb_flag_main = 0
int errorcount = 0
int warningcount = 0
int alt_ebcdic = 0
int optimize_flag = 0
char * cb_source_file = NULL
char * cb_oc_build_stamp = NULL
char * source_name
char * demangle_name
int cb_source_line = 0
FILE * cb_storage_file
char * cb_storage_file_name
FILE * cb_listing_file = NULL
FILE * cb_depend_file = NULL
char * cb_depend_target = NULL
struct cb_text_listcb_depend_list = NULL
struct cb_text_listcb_include_list = NULL
struct cb_text_listcb_extension_list = NULL
int cb_saveargc
char ** cb_saveargv
const char * cob_config_dir

Define Documentation

#define CB_FLAG (   var,
  name,
  doc 
)    int var = 0;

Definition at line 97 of file cobc.c.

#define CB_FLAG (   var,
  name,
  doc 
)
Value:
if (strcmp (name, "static-call"))       \
                printf ("  -f%-19s %s\n", name, gettext (doc));

Definition at line 97 of file cobc.c.

#define CB_FLAG (   var,
  name,
  doc 
)
Value:
{"f"name, no_argument, &var, 1},        \
        {"fno-"name, no_argument, &var, 0},

Definition at line 97 of file cobc.c.

#define CB_WARNDEF (   var,
  name,
  wall,
  doc 
)    var = 1;

Definition at line 102 of file cobc.c.

#define CB_WARNDEF (   var,
  name,
  wall,
  doc 
)
Value:
printf ("  -W%-19s %s", name, gettext (doc)); \
        if (!wall) { \
                puts (_(" (NOT set with -Wall)")); \
        } else { \
                printf ("\n"); \
        }

Definition at line 102 of file cobc.c.

#define CB_WARNDEF (   var,
  name,
  wall,
  doc 
)    var = 0;

Definition at line 102 of file cobc.c.

#define CB_WARNDEF (   var,
  name,
  wall,
  doc 
)
Value:
{"W"name, no_argument, &var, 1},        \
        {"Wno-"name, no_argument, &var, 0},

Definition at line 102 of file cobc.c.

#define CB_WARNDEF (   var,
  name,
  wall,
  doc 
)    int var = 0;

Definition at line 102 of file cobc.c.

#define CB_WARNDEF (   var,
  name,
  wall,
  doc 
)    if (wall) var = 1;

Definition at line 102 of file cobc.c.

#define COB_EXCEPTION (   code,
  tag,
  name,
  critical 
)    {name, 0x##code, 0},

Definition at line 88 of file cobc.c.

#define COB_NUM_CSYNS   sizeof(cob_csyns) / sizeof(char *)

Definition at line 201 of file cobc.c.

#define PATHSEPS   ":"

Definition at line 109 of file cobc.c.


Typedef Documentation

typedef void(* cob_sighandler_t)(int)

Definition at line 249 of file cobc.c.


Enumeration Type Documentation

Enumerator:
CB_LEVEL_PREPROCESS 
CB_LEVEL_TRANSLATE 
CB_LEVEL_COMPILE 
CB_LEVEL_ASSEMBLE 
CB_LEVEL_MODULE 
CB_LEVEL_LIBRARY 
CB_LEVEL_EXECUTABLE 

Definition at line 65 of file cobc.c.


Function Documentation

struct cb_text_list* cb_text_list_add ( struct cb_text_list list,
const char *  text 
) [read]

Definition at line 355 of file cobc.c.

{
        struct cb_text_list *p;
        struct cb_text_list *l;

        p = cobc_malloc (sizeof (struct cb_text_list));
        p->text = strdup (text);
        p->next = NULL;
        if (!list) {
                return p;
        } else {
                for (l = list; l->next; l = l->next) { ; }
                l->next = p;
                return list;
        }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cobc_abort ( const char *  filename,
const int  linenum 
)

Definition at line 310 of file cobc.c.

{
        fprintf (stderr, "%s:%d: Internal compiler error\n", filename, linenum);
        (void)longjmp (cob_jmpbuf, 1);
}
size_t cobc_check_valid_name ( char *  name)

Definition at line 373 of file cobc.c.

{
        size_t  n;

        for (n = 0; n < COB_NUM_CSYNS; ++n) {
                if (!strcmp (name, cob_csyns[n])) {
                        return 1;
                }
        }
        return 0;
}

Here is the caller graph for this function:

void* cobc_malloc ( const size_t  size)

Definition at line 327 of file cobc.c.

{
        void *mptr;

        mptr = calloc (1, size);
        if (!mptr) {
                fprintf (stderr, "Cannot allocate %d bytes of memory - Aborting\n", (int)size);
                fflush (stderr);
                (void)longjmp (cob_jmpbuf, 1);
        }
        return mptr;
}

Here is the caller graph for this function:

void* cobc_realloc ( void *  prevptr,
const size_t  size 
)

Definition at line 341 of file cobc.c.

{
        void *mptr;

        mptr = realloc (prevptr, size);
        if (!mptr) {
                fprintf (stderr, "Cannot reallocate %d bytes of memory - Aborting\n", (int)size);
                fflush (stderr);
                (void)longjmp (cob_jmpbuf, 1);
        }
        return mptr;
}
void cobc_tree_cast_error ( cb_tree  x,
const char *  filen,
const int  linenum,
const int  tagnum 
)

Definition at line 317 of file cobc.c.

{
        fprintf (stderr, "%s:%d: Invalid type cast from '%s'\n",
                filen, linenum, x ? cb_name (x) : "null");
        fprintf (stderr, "Tag 1 %d Tag 2 %d\n", x ? CB_TREE_TAG(x) : 0,
                tagnum);
        (void)longjmp (cob_jmpbuf, 1);
}

Here is the call graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 1686 of file cobc.c.

{
        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

        /* Initialize global variables */
        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;
        }

        /* Process command line arguments */
        iargs = process_command_line (argc, argv);

        /* Check the filename */
        if (iargs == argc) {
                fprintf (stderr, "cobc: No input files\n");
                exit (1);
        }

        /* processes COBCPY environment variable */
        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;
        }

        /* Defaults are set here */
        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;
                }
                /* Preprocess */
                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;
                }
                /* Translate */
                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;
                }

                /* Compile */
                if (cb_compile_level == CB_LEVEL_COMPILE) {
                        if (process_compile (fn) != 0) {
                                cobc_clean_up (status);
                                return status;
                        }
                }

                /* Build module */
                if (cb_compile_level == CB_LEVEL_MODULE && fn->need_assemble) {
                        if (process_module_direct (fn) != 0) {
                                cobc_clean_up (status);
                                return status;
                        }
                } else {
                        /* Assemble */
                        if (cb_compile_level >= CB_LEVEL_ASSEMBLE && fn->need_assemble) {
                                if (process_assemble (fn) != 0) {
                                        cobc_clean_up (status);
                                        return status;
                                }
                        }

                        /* Build module */
                        if (cb_compile_level == CB_LEVEL_MODULE) {
                                if (process_module (fn) != 0) {
                                        cobc_clean_up (status);
                                        return status;
                                }
                        }
                }
        }

        if (!cb_flag_syntax_only) {
                /* Link */
                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;
                        }
                }
        }

        /* We have successfully completed */
        status = 0;
        cobc_clean_up (status);

        return status;
}

Here is the call graph for this function:


Variable Documentation

int alt_ebcdic = 0

Definition at line 121 of file cobc.c.

int cb_attr_id = 1

Definition at line 113 of file cobc.c.

FILE* cb_depend_file = NULL

Definition at line 134 of file cobc.c.

struct cb_text_list* cb_depend_list = NULL

Definition at line 136 of file cobc.c.

char* cb_depend_target = NULL

Definition at line 135 of file cobc.c.

int cb_display_sign = COB_DISPLAY_SIGN_ASCII

Definition at line 84 of file cobc.c.

Definition at line 89 of file cobc.c.

Definition at line 138 of file cobc.c.

int cb_field_id = 1

Definition at line 115 of file cobc.c.

int cb_flag_main = 0

Definition at line 117 of file cobc.c.

int cb_id = 1

Definition at line 112 of file cobc.c.

struct cb_text_list* cb_include_list = NULL

Definition at line 137 of file cobc.c.

FILE* cb_listing_file = NULL

Definition at line 133 of file cobc.c.

int cb_literal_id = 1

Definition at line 114 of file cobc.c.

char* cb_oc_build_stamp = NULL

Definition at line 125 of file cobc.c.

Definition at line 140 of file cobc.c.

char** cb_saveargv

Definition at line 141 of file cobc.c.

char* cb_source_file = NULL

Definition at line 124 of file cobc.c.

int cb_source_format = CB_FORMAT_FIXED

Definition at line 79 of file cobc.c.

int cb_source_line = 0

Definition at line 128 of file cobc.c.

Definition at line 130 of file cobc.c.

Definition at line 131 of file cobc.c.

int cb_storage_id = 1

Definition at line 116 of file cobc.c.

const char* cob_config_dir

Definition at line 143 of file cobc.c.

Definition at line 127 of file cobc.c.

int errorcount = 0

Definition at line 119 of file cobc.c.

int optimize_flag = 0

Definition at line 122 of file cobc.c.

char* source_name

Definition at line 126 of file cobc.c.

int warningcount = 0

Definition at line 120 of file cobc.c.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines