GnuCOBOL  2.0
A free COBOL compiler
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
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:

Macros

#define CB_NO_ARG   no_argument
 
#define _(s)   s
 
#define N_(s)   s
 

Functions

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

Variables

static const char short_options [] = "hirV"
 
static struct option long_options []
 

Macro Definition Documentation

#define _ (   s)    s

Referenced by ambiguous_error(), 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_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_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_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_comp_repeated(), check_pic_repeated(), check_picture_item(), check_relaxed_syntax(), check_repeated(), check_screen_attr(), check_valid_key(), cob_call(), cob_cancel(), cob_check_based(), 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_getopt_long_long(), cob_init(), cob_longjmp(), cob_parameter_check(), cob_resolve_error(), cob_resolve_func(), cob_resolve_internal(), cob_runtime_error(), cob_savenv(), 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_malloc(), cobc_main_realloc(), cobc_main_strdup(), cobc_malloc(), cobc_options_error_build(), cobc_options_error_nonfinal(), 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(), configuration_error(), decimal_alloc(), decimal_compute(), decimal_expand(), display_numeric(), emit_entry(), evaluate_test(), expr_reduce(), file_error(), finalize_file(), group_error(), if(), increment_depth(), 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_size(), output_stmt(), plex_action_directive(), ppcopy(), ppinput(), ppopen(), ppp_compare_vals(), ppp_define_add(), preprocess(), pretty_display_numeric(), print_error(), print_info(), print_runtime_env(), print_version(), process(), process_command_line(), process_filename(), process_translate(), read_literal(), redefinition_error(), redefinition_warning(), res_get_feature(), scan_define_options(), scan_floating_numeric(), scan_h(), scan_numeric(), scan_x(), search_set_keys(), setup_use_file(), terminator_error(), terminator_warning(), undefined_error(), unsupported_value(), valid_const_date_time_args(), validate_field_1(), validate_field_clauses(), validate_inspect(), validate_move(), var_print(), warning_destination(), and while().

#define CB_NO_ARG   no_argument
#define N_ (   s)    s

Function Documentation

static void cobcrun_print_usage ( char *  prog)
static

References _, and PACKAGE_NAME.

Referenced by process_command_line().

91 {
92  printf (_("Usage: %s PROGRAM [param ...]"), prog);
93  putchar ('\n');
94  printf (_(" or: %s options"), prog);
95  putchar ('\n');
96  putchar ('\n');
97  printf (_("COBOL driver program for %s modules"), PACKAGE_NAME);
98  putchar ('\n');
99  putchar ('\n');
100  puts (_("Options:"));
101  puts (_(" -h, -help Display this help and exit"));
102  puts (_(" -V, -version Display runtime version"));
103  puts (_(" -i, -info Display runtime information (build/environment)"));
104  puts (_(" -r, -runtime-env Display runtime information (build/environment)"));
105 }
static void cobcrun_print_version ( void  )
static

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

Referenced by process_command_line().

61 {
62  int year;
63  int day;
64  char buff[64];
65  char month[64];
66 
67  memset (buff, 0, sizeof(buff));
68  memset (month, 0, sizeof(month));
69  day = 0;
70  year = 0;
71  sscanf (__DATE__, "%s %d %d", month, &day, &year);
72  if (day && year) {
73  sprintf (buff, "%s %2.2d %4.4d %s", month, day, year, __TIME__);
74  } else {
75  sprintf (buff, "%s %s", __DATE__, __TIME__);
76  }
77  printf ("cobcrun (%s) %s.%d\n",
79  puts ("Copyright (C) 2004-2012 Roger While");
80  puts ("Copyright (C) 2012,2014 Simon Sobisch");
81  puts (_("This is free software; see the source for copying conditions. There is NO\n\
82 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."));
83  printf (_("Built %s"), buff);
84  putchar ('\n');
85  printf (_("Packaged %s"), COB_TAR_DATE);
86  putchar ('\n');
87 }
int main ( int  argc,
char **  argv 
)

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

167 {
168  int pcl_return;
169  cob_call_union unifunc;
170 
171 #ifdef HAVE_SETLOCALE
172  setlocale (LC_ALL, "");
173 #endif
174 
175  pcl_return = process_command_line (argc, argv);
176 
177  if (pcl_return != 99) {
178  return pcl_return;
179  }
180  if (strlen (argv[1]) > 31) {
181  fputs (_("PROGRAM name exceeds 31 characters"), stderr);
182  putc ('\n', stderr);
183  return 1;
184  }
185  cob_init (argc - 1, &argv[1]);
186  unifunc.funcvoid = cob_resolve (argv[1]);
187  if (unifunc.funcvoid == NULL) {
188  cob_call_error ();
189  }
190  cob_stop_run ( unifunc.funcint() );
191 }
static int process_command_line ( int  argc,
char *  argv[] 
)
static

References cob_getopt_long_long(), cobcrun_print_usage(), cobcrun_print_version(), print_info(), print_runtime_env(), print_version(), and short_options.

Referenced by main().

109 {
110  int c, idx;
111 
112  /* At least one option or module name needed */
113  if (argc <= 1) {
114  cobcrun_print_usage (argv[0]);
115  return 1;
116  }
117 
118 #ifdef _WIN32
119  /* Translate first command line argument from WIN to UNIX style */
120  if (strrchr(argv[1], '/') == argv[1]) {
121  argv[1][0] = '-';
122  }
123 #endif
124 
125  /* Process first command line argument only if not a module */
126  if (argv[1][0] != '-') {
127  return 99;
128  }
129 
130  c = cob_getopt_long_long (argc, argv, short_options,
131  long_options, &idx, 1);
132  if (c > 0) {
133  switch (c) {
134  case '?':
135  /* Unknown option or ambiguous */
136  return 1;
137 
138  case 'h':
139  /* --help */
140  cobcrun_print_usage (argv[0]);
141  return 0;
142 
143  case 'i':
144  /* --info */
145  print_info ();
146  return 0;
147 
148  case 'r':
149  /* --runtime-env */
151  return 0;
152 
153  case 'V':
154  /* --version */
156  putchar('\n');
157  print_version();
158  return 0;
159  }
160  }
161 
162  return 99;
163 }

Variable Documentation

struct option long_options[]
static
Initial value:
= {
{"help", CB_NO_ARG, NULL, 'h'},
{"info", CB_NO_ARG, NULL, 'i'},
{"runtime-env", CB_NO_ARG, NULL, 'r'},
{"version", CB_NO_ARG, NULL, 'V'},
{NULL, 0, NULL, 0}
}
const char short_options[] = "hirV"
static

Referenced by process_command_line().