GnuCOBOL  2.0
A free COBOL compiler
cobcrun.c File Reference
#include "config.h"
#include "defaults.h"
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include "libcob.h"
#include "tarstamp.h"
#include "libcob/cobgetopt.h"
#include <locale.h>
Include dependency graph for cobcrun.c:

Go to the source code of this file.

Macros

#define CB_NO_ARG   no_argument
 
#define CB_RQ_ARG   required_argument
 
#define CB_OP_ARG   optional_argument
 
#define _(s)   s
 
#define N_(s)   s
 

Functions

static void cobcrun_print_version (void)
 
static void cobcrun_print_usage (char *prog)
 
static int cobcrun_setenv (const char *environment)
 
static void process_command_line (int argc, char *argv[])
 
int main (int argc, char **argv)
 

Variables

static int arg_shift = 1
 
static const char short_options [] = "+hirc:V"
 
static const struct option long_options []
 

Macro Definition Documentation

#define _ (   s)    s

Definition at line 59 of file cobcrun.c.

Referenced by ambiguous_error(), begin_scope_of_program_name(), begin_statement(), build_evaluate(), cb_build_address(), cb_build_assignment_name(), cb_build_binary_op(), cb_build_cond(), cb_build_const_length(), cb_build_display_mnemonic(), cb_build_display_name(), cb_build_field_tree(), cb_build_identifier(), cb_build_intrinsic(), cb_build_locale_name(), cb_build_picture(), cb_build_replacing_characters(), cb_build_tallying_all(), cb_build_tallying_characters(), cb_build_tallying_leading(), cb_build_tallying_trailing(), cb_build_tallying_value(), cb_build_write_advancing_mnemonic(), cb_check_group_name(), cb_check_integer_value(), cb_check_numeric_edited_name(), cb_check_numeric_name(), cb_check_numeric_value(), cb_check_overlapping(), cb_concat_literals(), cb_config_entry(), cb_define_list_add(), cb_define_switch_name(), cb_emit_accept(), cb_emit_accept_mnemonic(), cb_emit_accept_name(), cb_emit_allocate(), cb_emit_call(), cb_emit_close(), cb_emit_corresponding(), cb_emit_delete(), cb_emit_delete_file(), cb_emit_display(), cb_emit_free(), cb_emit_goto(), cb_emit_initialize(), cb_emit_inspect(), cb_emit_move(), cb_emit_move_corresponding(), cb_emit_open(), cb_emit_read(), cb_emit_release(), cb_emit_rewrite(), cb_emit_set_attribute(), cb_emit_set_false(), cb_emit_set_to(), cb_emit_set_true(), cb_emit_sort_giving(), cb_emit_sort_init(), cb_emit_sort_using(), cb_emit_start(), cb_emit_write(), cb_error(), cb_error_x(), cb_expr_finish(), cb_field_size(), cb_get_int(), cb_get_level(), cb_get_long_long(), cb_get_u_long_long(), cb_list_intrinsics(), cb_list_mnemonics(), cb_list_reserved(), cb_list_system(), cb_load_conf(), cb_load_conf_file(), cb_name_1(), cb_plex_error(), cb_plex_warning(), cb_resolve_redefines(), cb_tree_category(), cb_tree_type(), cb_validate_88_item(), cb_validate_collating(), cb_validate_one(), cb_validate_program_body(), cb_validate_program_data(), cb_validate_program_environment(), cb_verify(), cb_warning(), cb_warning_x(), check_for_duplicate_prototype(), check_lit_length(), check_not_88_level(), check_not_both(), check_picture_item(), check_prototype_redefines_current_func(), check_prototype_seen(), check_relaxed_syntax(), check_valid_key(), cob_call(), cob_cancel(), cob_check_based(), cob_check_linkage(), cob_check_numeric(), cob_check_odo(), cob_check_ref_mod(), cob_check_subscript(), cob_check_version(), cob_command_line(), cob_exit_fileio(), cob_external_addr(), cob_fatal_error(), cob_gen_optim(), cob_get_sort_tempfile(), cob_init(), cob_load_config_file(), cob_longjmp(), cob_parameter_check(), cob_resolve_error(), cob_resolve_func(), cob_resolve_internal(), cob_runtime_error(), cob_savenv(), cob_screen_init(), cob_sys_check_file_exist(), cob_sys_create_file(), cob_sys_file_info(), cob_sys_getopt_long_long(), cob_sys_system(), cobc_abort(), cobc_abort_terminate(), cobc_add_str(), cobc_check_action(), cobc_check_string(), cobc_cmd_print(), cobc_deciph_funcs(), cobc_err_exit(), cobc_error_name(), cobc_free(), cobc_main_free(), cobc_main_malloc(), cobc_main_realloc(), cobc_main_strdup(), cobc_malloc(), cobc_options_error_build(), cobc_options_error_nonfinal(), cobc_parse_free(), cobc_parse_malloc(), cobc_parse_realloc(), cobc_parse_strdup(), cobc_plex_malloc(), cobc_plex_strdup(), cobc_print_info(), cobc_print_usage(), cobc_print_version(), cobc_print_warn(), cobc_realloc(), cobc_set_value(), cobc_stradd_dup(), cobc_strdup(), cobc_too_many_errors(), cobc_tree_cast_error(), cobc_var_print(), cobcrun_print_usage(), cobcrun_print_version(), codegen(), compute_size(), conf_runtime_error(), conf_runtime_error_value(), configuration_error(), configuration_warning(), decimal_alloc(), decimal_compute(), decimal_expand(), decrement_depth(), display_numeric(), emit_conflicting_clause_message(), emit_duplicate_clause_message(), emit_entry(), error_if_no_advancing_in_screen_display(), error_literal(), error_numeric_literal(), evaluate_test(), expr_reduce(), file_basename(), file_error(), finalize_file(), get_user_specified_reserved_word(), group_error(), increment_depth(), initialize_alias_for(), initialize_type(), invalid_value(), level_except_error(), level_redundant_error(), level_require_error(), lookup_reserved_word(), main(), make_intrinsic(), open_cbl_file(), output_attr(), output_base(), output_call_by_value_args(), output_cond(), output_data(), output_funcall(), output_initialize_one(), output_integer(), output_internal_function(), output_long_integer(), output_param(), output_search_whens(), output_size(), output_stmt(), plex_action_directive(), ppcopy(), ppinput(), pplex(), ppopen(), ppp_compare_vals(), ppp_define_add(), ppparse(), preprocess(), pretty_display_numeric(), print_error(), print_info(), print_runtime_env(), print_version(), process(), process_command_line(), process_filename(), process_library(), process_link(), process_run(), process_translate(), read_literal(), redefinition_error(), redefinition_warning(), res_get_feature(), scan_b(), scan_define_options(), scan_floating_numeric(), scan_h(), scan_numeric(), scan_o(), scan_x(), scan_z(), search_set_keys(), set_config_val(), set_up_use_file(), terminator_error(), terminator_warning(), undefined_error(), unsupported_value(), valid_const_date_time_args(), valid_format(), valid_screen_pos(), validate_field_1(), validate_field_clauses(), validate_inspect(), validate_move(), var_print(), warning_destination(), yylex(), and yyparse().

#define CB_NO_ARG   no_argument

Definition at line 41 of file cobcrun.c.

#define CB_OP_ARG   optional_argument

Definition at line 43 of file cobcrun.c.

#define CB_RQ_ARG   required_argument

Definition at line 42 of file cobcrun.c.

#define N_ (   s)    s

Definition at line 60 of file cobcrun.c.

Function Documentation

static void cobcrun_print_usage ( char *  prog)
static

Definition at line 98 of file cobcrun.c.

References _.

Referenced by main(), and process_command_line().

99 {
100  puts (_("COBOL driver program for GnuCOBOL modules"));
101  putchar ('\n');
102  printf (_("usage: %s [options] PROGRAM [param ...]"), prog);
103  putchar ('\n');
104  printf (_(" or: %s options"), prog);
105  putchar ('\n');
106  putchar ('\n');
107  puts (_("options:"));
108  puts (_(" -h, -help display this help and exit"));
109  puts (_(" -V, -version display cobcrun and runtime version and exit"));
110  puts (_(" -i, -info display runtime information (build/environment)"));
111  puts (_(" -c <file>, -config=<file> set runtime configuration from <file>"));
112  puts (_(" -r, -runtime-env display current runtime configuration\n"
113  " (value and origin for all settings)"));
114 }
#define _(s)
Definition: cobcrun.c:59

Here is the caller graph for this function:

static void cobcrun_print_version ( void  )
static

Definition at line 65 of file cobcrun.c.

References _, COB_MINI_BUFF, COB_MINI_MAX, COB_TAR_DATE, PACKAGE_NAME, PACKAGE_VERSION, and PATCH_LEVEL.

Referenced by process_command_line().

66 {
67  char cob_build_stamp[COB_MINI_BUFF];
68  char month[64];
69  int status, day, year;
70 
71  /* Set up build time stamp */
72  memset (cob_build_stamp, 0, (size_t)COB_MINI_BUFF);
73  memset (month, 0, sizeof(month));
74  day = 0;
75  year = 0;
76  status = sscanf (__DATE__, "%s %d %d", month, &day, &year);
77  if (status == 3) {
78  snprintf (cob_build_stamp, (size_t)COB_MINI_MAX,
79  "%s %2.2d %4.4d %s", month, day, year, __TIME__);
80  } else {
81  snprintf (cob_build_stamp, (size_t)COB_MINI_MAX,
82  "%s %s", __DATE__, __TIME__);
83  }
84 
85  printf ("cobcrun (%s) %s.%d\n",
87  puts ("Copyright (C) 2004-2012, 2014-2016 Free Software Foundation, Inc.");
88  printf (_("Written by %s\n"), "Roger While, Simon Sobisch");
89  puts (_("This is free software; see the source for copying conditions. There is NO\n"\
90  "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."));
91  printf (_("Built %s"), cob_build_stamp);
92  putchar ('\n');
93  printf (_("Packaged %s"), COB_TAR_DATE);
94  putchar ('\n');
95 }
#define COB_MINI_BUFF
Definition: common.h:539
#define PACKAGE_NAME
Definition: config.h:300
#define _(s)
Definition: cobcrun.c:59
#define COB_TAR_DATE
Definition: tarstamp.h:1
#define PACKAGE_VERSION
Definition: config.h:312
#define PATCH_LEVEL
Definition: config.h:315
#define COB_MINI_MAX
Definition: common.h:545

Here is the caller graph for this function:

static int cobcrun_setenv ( const char *  environment)
static

Definition at line 118 of file cobcrun.c.

References cob_fast_malloc(), and cob_optarg.

Referenced by process_command_line().

119 {
120 #if !HAVE_SETENV
121  int len;
122  char * p;
123 
124  len = strlen (environment) + strlen (cob_optarg) + 2U;
125  p = cob_fast_malloc (len);
126  sprintf (p, "%s=%s", environment, cob_optarg);
127  return putenv (p);
128 #else
129  return setenv(environment, cob_optarg, 1);
130 #endif
131 }
void * cob_fast_malloc(const size_t size)
Definition: common.c:1296
char * cob_optarg
Definition: cobgetopt.c:77

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 201 of file cobcrun.c.

References _, arg_shift, cob_call_error(), cob_init(), cob_resolve(), cob_stop_run(), cobcrun_print_usage(), cob_call_union::funcint, cob_call_union::funcvoid, NULL, and process_command_line().

202 {
203  cob_call_union unifunc;
204 
205 #ifdef HAVE_SETLOCALE
206  setlocale (LC_ALL, "");
207 #endif
208 
209  process_command_line (argc, argv);
210 
211  /* At least one option or module name needed */
212  if (argc <= arg_shift) {
213  cobcrun_print_usage (argv[0]);
214  exit (1);
215  }
216 
217  if (strlen (argv[arg_shift]) > 31) {
218  fputs (_("PROGRAM name exceeds 31 characters"), stderr);
219  putc ('\n', stderr);
220  return 1;
221  }
222  cob_init (argc - arg_shift, &argv[arg_shift]);
223  unifunc.funcvoid = cob_resolve (argv[arg_shift]);
224  if (unifunc.funcvoid == NULL) {
225  cob_call_error ();
226  }
227  cob_stop_run ( unifunc.funcint() );
228 }
static void cobcrun_print_usage(char *prog)
Definition: cobcrun.c:98
static int arg_shift
Definition: cobcrun.c:37
void * cob_resolve(const char *name)
Definition: call.c:908
void * funcvoid
Definition: common.h:1010
#define _(s)
Definition: cobcrun.c:59
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
void cob_init(const int argc, char **argv)
Definition: common.c:5390
int(* funcint)()
Definition: common.h:1009
void cob_call_error(void)
Definition: call.c:878
static void process_command_line(int argc, char *argv[])
Definition: cobcrun.c:134
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

static void process_command_line ( int  argc,
char *  argv[] 
)
static

Definition at line 134 of file cobcrun.c.

References _, arg_shift, cob_getopt_long_long(), cob_init(), cob_optarg, COB_SMALL_MAX, cobcrun_print_usage(), cobcrun_print_version(), cobcrun_setenv(), print_info(), print_runtime_env(), print_version(), and short_options.

Referenced by main().

135 {
136  int c, idx;
137 #ifdef _WIN32
138  int argnum;
139 
140  /* Translate command line arguments from WIN to UNIX style */
141  argnum = 1;
142  while (++argnum <= argc) {
143  if (strrchr(argv[argnum - 1], '/') == argv[argnum - 1]) {
144  argv[argnum - 1][0] = '-';
145  }
146  }
147 #endif
148 
149  /* c = -1 if idx > argc or argv[idx] has non-option */
150  while ((c = cob_getopt_long_long (argc, argv, short_options,
151  long_options, &idx, 1)) >= 0) {
152  switch (c) {
153  case '?':
154  /* Unknown option or ambiguous */
155  exit (1);
156 
157  case 'c':
158  case 'C':
159  /* --config=<file> */
160  if (strlen (cob_optarg) > COB_SMALL_MAX) {
161  fputs (_("invalid configuration file name"), stderr);
162  putc ('\n', stderr);
163  fflush (stderr);
164  exit (1);
165  }
166  arg_shift++;
167  cobcrun_setenv ("COB_RUNTIME_CONFIG");
168  /* shift argument again if two part argument was used */
169  if (c == 'c') {
170  arg_shift++;
171  }
172  break;
173 
174  case 'h':
175  /* --help */
176  cobcrun_print_usage (argv[0]);
177  exit (0);
178 
179  case 'i':
180  /* --info */
181  print_info ();
182  exit (0);
183 
184  case 'r':
185  /* --runtime-env */
186  cob_init (0, &argv[0]);
188  exit (0);
189 
190  case 'V':
191  /* --version */
193  putchar ('\n');
194  print_version();
195  exit (0);
196  }
197  }
198 }
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
static void cobcrun_print_usage(char *prog)
Definition: cobcrun.c:98
void print_version(void)
Definition: common.c:5119
static int arg_shift
Definition: cobcrun.c:37
void print_info(void)
Definition: common.c:5153
static int cobcrun_setenv(const char *environment)
Definition: cobcrun.c:118
#define COB_SMALL_MAX
Definition: common.h:546
#define _(s)
Definition: cobcrun.c:59
void cob_init(const int argc, char **argv)
Definition: common.c:5390
void print_runtime_env()
Definition: common.c:5234
static void cobcrun_print_version(void)
Definition: cobcrun.c:65
static const char short_options[]
Definition: cobcrun.c:39
static const struct option long_options[]
Definition: cobcrun.c:45
char * cob_optarg
Definition: cobgetopt.c:77

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

int arg_shift = 1
static

Definition at line 37 of file cobcrun.c.

Referenced by main(), and process_command_line().

const struct option long_options[]
static
Initial value:
= {
{"help", 0 , ((void*)0) , 'h'},
{"info", 0 , ((void*)0) , 'i'},
{"runtime-env", 0 , ((void*)0) , 'r'},
{"config", 1 , ((void*)0) , 'C'},
{"version", 0 , ((void*)0) , 'V'},
{ ((void*)0) , 0, ((void*)0) , 0}
}

Definition at line 45 of file cobcrun.c.

const char short_options[] = "+hirc:V"
static

Definition at line 39 of file cobcrun.c.

Referenced by process_command_line().