OpenCOBOL 1.1pre-rel
cobcrun.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2009 Roger While
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2, or (at your option)
00007  * any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License 
00015  * along with this software; see the file COPYING.  If not, write to
00016  * the Free Software Foundation, 51 Franklin Street, Fifth Floor
00017  * Boston, MA 02110-1301 USA
00018  */
00019 
00020 #include        "config.h"
00021 #include        "defaults.h"
00022 
00023 #include        <stdio.h>
00024 #include        <string.h>
00025 #include        <libcob.h>
00026 #include        <tarstamp.h>
00027 
00028 static void
00029 print_version (void)
00030 {
00031         int     year;
00032         int     day;
00033         char    buff[64];
00034         char    month[64];
00035 
00036         memset (buff, 0, sizeof(buff));
00037         memset (month, 0, sizeof(month));
00038         day = 0;
00039         year = 0;
00040         sscanf (__DATE__, "%s %d %d", month, &day, &year);
00041         if (day && year) {
00042                 sprintf (buff, "%s %2.2d %4.4d %s", month, day, year, __TIME__);
00043         } else {
00044                 sprintf (buff, "%s %s", __DATE__, __TIME__);
00045         }
00046         printf ("cobcrun (%s) %s.%d\n",
00047                 PACKAGE_NAME, PACKAGE_VERSION, PATCH_LEVEL);
00048         puts ("Copyright (C) 2004-2009 Roger While");
00049         printf ("Built    %s\nPackaged %s\n", buff, octardate);
00050 }
00051 
00052 static void
00053 print_usage (void)
00054 {
00055         printf ("Usage: cobcrun PROGRAM [param ...]\n");
00056         printf ("or   : cobcrun --help (-h)\n");
00057         printf ("       Print this help\n");
00058         printf ("or   : cobcrun --version (-V)\n");
00059         printf ("       Print version information\n");
00060 }
00061 
00062 int
00063 main (int argc, char **argv)
00064 {
00065         union {
00066                 int     (*func)();
00067                 void    *func_void;
00068         } unifunc;
00069 
00070         if (argc <= 1) {
00071                 print_usage ();
00072                 return 1;
00073         }
00074         /* Quick check without getopt */
00075         if (!strncmp (argv[1], "--version", 10) ||
00076             !strncmp (argv[1], "-V", 4)) {
00077                 print_version ();
00078                 return 0;
00079         }
00080         if (!strncmp (argv[1], "--help", 10) ||
00081             !strncmp (argv[1], "-h", 4)) {
00082                 print_usage ();
00083                 return 0;
00084         }
00085         if (strlen (argv[1]) > 31) {
00086                 fprintf (stderr, "Invalid PROGRAM name\n");
00087                 return 1;
00088         }
00089         cob_init (argc - 1, &argv[1]);
00090         unifunc.func_void = cob_resolve (argv[1]);
00091         if (unifunc.func_void == NULL) {
00092                 cob_call_error ();
00093         }
00094         cob_stop_run ( unifunc.func() );
00095 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines