1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "cdi.h"
#include "error.h"
static char *Progname;
extern int CDI_Debug;
static void
version(void)
{
fputs("createtable version 1.00 (11 Nov 2001)\n\n", stderr);
}
static void
usage(void)
{
fputs("usage : createtable [-options] ifile ofile\n"
"with:\n"
" -debug debugging mode\n"
" -version display version number\n",
stderr);
}
int
main(int argc, char *argv[])
{
int c;
char *cstring;
char *ifile = NULL, *ofile = NULL;
int debug = 0;
Progname = argv[0];
while (--argc && (*++argv)[0] == '-')
{
c = *++argv[0];
cstring = argv[0];
size_t len = strlen(cstring);
switch (c)
{
case 'd':
if (!strncmp(cstring, "debug", len)) { debug = 1; }
break;
case 'h':
if (!strncmp(cstring, "help", len))
{
usage();
return EXIT_SUCCESS;
}
break;
case 'v':
if (!strncmp(cstring, "version", len))
{
version();
return EXIT_SUCCESS;
}
break;
default:
usage();
fprintf(stderr, "illegal option %s\n", cstring);
return EXIT_FAILURE;
}
}
if (argc)
{
ifile = argv[0];
argc--;
}
if (argc)
{
ofile = (++argv)[0];
argc--;
}
if (ifile == NULL || ofile == NULL)
{
usage();
fprintf(stderr, "missing filenames\n");
return EXIT_FAILURE;
}
if (debug)
{
fprintf(stderr, "\n");
if (ifile) fprintf(stderr, " < %s \n", ifile);
if (ofile) fprintf(stderr, " > %s\n\n", ofile);
}
/*
if ( debug ) cdiDebug(debug);
*/
int tableID = tableRead(ifile);
if (CDI_Debug) Message("write parameter table %d to %s", tableID, ofile);
FILE *ptfp = (ofile[0] == '-' && ofile[1] == '\0') ? stdout : fopen(ofile, "w");
if (tableID != CDI_UNDEFID) tableFWriteC(ptfp, tableID);
return EXIT_SUCCESS;
}
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
|