Commit a065d5cc authored by Claes Sjofors's avatar Claes Sjofors

getopt replaced

parent cb926fc8
...@@ -33,8 +33,6 @@ ...@@ -33,8 +33,6 @@
#include "rt_errh_msg.h" #include "rt_errh_msg.h"
#include "rt_pwr_msg.h" #include "rt_pwr_msg.h"
extern int getopt();
static ini_sContext *createContext (int argc, char **argv); static ini_sContext *createContext (int argc, char **argv);
static int checkErrors (ini_sContext*); static int checkErrors (ini_sContext*);
static pwr_tStatus events (ini_sContext *cp); static pwr_tStatus events (ini_sContext *cp);
...@@ -261,25 +259,9 @@ checkErrors ( ...@@ -261,25 +259,9 @@ checkErrors (
static ini_sContext * static ini_sContext *
createContext (int argc, char **argv) createContext (int argc, char **argv)
{ {
int c; int i, j;
extern char *optarg;
extern int optind;
#if 1
extern int optind;
#endif
ini_sContext *cp; ini_sContext *cp;
pwr_tStatus sts; pwr_tStatus sts;
#if defined(OS_LYNX) || defined(OS_LINUX) || defined OS_MACOS || defined OS_FREEBSD
char *options = "a:b:c:d:efg:hin:p:q:rsu:vwA:H:V";
#else
char *options = "a:b:d:efhin:p:q:rvwA:H:V";
#endif
#if 0
extern int opterr;
opterr = 0;
#endif
optind = 0;
if ( argc > 1 && strcmp( argv[1], "--version") == 0) { if ( argc > 1 && strcmp( argv[1], "--version") == 0) {
system( "cat $pwr_exe/rt_version.dat"); system( "cat $pwr_exe/rt_version.dat");
...@@ -290,59 +272,118 @@ createContext (int argc, char **argv) ...@@ -290,59 +272,118 @@ createContext (int argc, char **argv)
exit(1); exit(1);
} }
while ((c = getopt(argc, argv, options)) != -1) { for ( i = 1; i < argc; i++) {
switch (c) { if ( argv[i][0] == '-') {
case 'a': int i_incr = 0;
cp->flags.b.applfile = 1; for ( j = 1;
strcpy(cp->applfile.name, optarg); argv[i][j] != 0 && argv[i][j] != ' ' && argv[i][j] != ' ';
break; j++) {
case 'c': switch ( argv[i][j]) {
strcpy(cp->console, optarg); case 'a':
break; if ( i + 1 >= argc ||
case 'd': !(argv[i][j+1] == ' ' || argv[i][j+1] != ' ')) {
strcpy(cp->dir, optarg); usage( argv[0]);
break; exit(0);
case 'e': }
cp->flags.b.ignoreError = 1; cp->flags.b.applfile = 1;
break; strcpy(cp->applfile.name, argv[i+1]);
case 'f': i++;
cp->flags.b.ignoreFatal = 1; i_incr = 1;
break; break;
case 'h': case 'c':
cp->flags.b.hostname = 1; if ( i + 1 >= argc ||
strcpy(cp->hostname, optarg); !(argv[i][j+1] == ' ' || argv[i][j+1] != ' ')) {
break; usage( argv[0]);
case 'i': exit(0);
cp->flags.b.interactive = 1; }
break; strcpy(cp->console, argv[i+1]);
case 'n': i++;
cp->flags.b.nodename = 1; i_incr = 1;
strcpy(cp->nodename, optarg); break;
break; case 'd':
case 'q': if ( i + 1 >= argc ||
cp->flags.b.busid = 1; !(argv[i][j+1] == ' ' || argv[i][j+1] != ' ')) {
cp->busid = atoi(optarg); usage( argv[0]);
break; exit(0);
case 'r': }
cp->flags.b.restart = 1; strcpy(cp->dir, argv[i+1]);
cp->flags.b.interactive = 1; i++;
break; i_incr = 1;
case 's': break;
cp->flags.b.stop = 1; case 'e':
break; cp->flags.b.ignoreError = 1;
case 'v': break;
cp->flags.b.verbose = 1; case 'f':
break; cp->flags.b.ignoreFatal = 1;
case 'w': break;
cp->flags.b.ignoreWarning = 1; case 'h':
break; if ( i + 1 >= argc ||
case 'A': !(argv[i][j+1] == ' ' || argv[i][j+1] != ' ')) {
cp->flags.b.aliasfile = 1; usage( argv[0]);
strcpy(cp->aliasfile.name, optarg); exit(0);
break; }
case '?': cp->flags.b.hostname = 1;
usage(argv[0]); strcpy(cp->hostname, argv[i+1]);
break; i++;
i_incr = 1;
break;
case 'i':
cp->flags.b.interactive = 1;
break;
case 'n':
if ( i + 1 >= argc ||
!(argv[i][j+1] == ' ' || argv[i][j+1] != ' ')) {
usage( argv[0]);
exit(0);
}
cp->flags.b.nodename = 1;
strcpy(cp->nodename, argv[i+1]);
i++;
i_incr = 1;
break;
case 'q':
if ( i + 1 >= argc ||
!(argv[i][j+1] == ' ' || argv[i][j+1] != ' ')) {
usage( argv[0]);
exit(0);
}
cp->flags.b.busid = 1;
cp->busid = atoi(argv[i+1]);
break;
case 'r':
cp->flags.b.restart = 1;
cp->flags.b.interactive = 1;
break;
case 's':
cp->flags.b.stop = 1;
break;
case 'v':
cp->flags.b.verbose = 1;
break;
case 'w':
cp->flags.b.ignoreWarning = 1;
break;
case 'A':
if ( i + 1 >= argc ||
!(argv[i][j+1] == ' ' || argv[i][j+1] != ' ')) {
usage( argv[0]);
exit(0);
}
cp->flags.b.aliasfile = 1;
strcpy(cp->aliasfile.name, argv[i+1]);
i++;
i_incr = 1;
break;
case '?':
usage(argv[0]);
break;
default:
usage(argv[0]);
exit(0);
}
if ( i_incr)
break;
}
} }
} }
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include <stdio.h> #include <stdio.h>
#if defined OS_LYNX #if defined OS_LYNX
# include <sys/wait.h> # include <sys/wait.h>
#elif defined OS_MACOS || defined OS_FREEBSD #elif defined OS_LINUX || defined OS_MACOS || defined OS_FREEBSD
# include <sys/wait.h> # include <sys/wait.h>
# include <fcntl.h> # include <fcntl.h>
# include <unistd.h> # include <unistd.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment