Commit a065d5cc authored by Claes Sjofors's avatar Claes Sjofors

getopt replaced

parent cb926fc8
......@@ -33,8 +33,6 @@
#include "rt_errh_msg.h"
#include "rt_pwr_msg.h"
extern int getopt();
static ini_sContext *createContext (int argc, char **argv);
static int checkErrors (ini_sContext*);
static pwr_tStatus events (ini_sContext *cp);
......@@ -261,25 +259,9 @@ checkErrors (
static ini_sContext *
createContext (int argc, char **argv)
{
int c;
extern char *optarg;
extern int optind;
#if 1
extern int optind;
#endif
int i, j;
ini_sContext *cp;
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) {
system( "cat $pwr_exe/rt_version.dat");
......@@ -290,17 +272,43 @@ createContext (int argc, char **argv)
exit(1);
}
while ((c = getopt(argc, argv, options)) != -1) {
switch (c) {
for ( i = 1; i < argc; i++) {
if ( argv[i][0] == '-') {
int i_incr = 0;
for ( j = 1;
argv[i][j] != 0 && argv[i][j] != ' ' && argv[i][j] != ' ';
j++) {
switch ( argv[i][j]) {
case 'a':
if ( i + 1 >= argc ||
!(argv[i][j+1] == ' ' || argv[i][j+1] != ' ')) {
usage( argv[0]);
exit(0);
}
cp->flags.b.applfile = 1;
strcpy(cp->applfile.name, optarg);
strcpy(cp->applfile.name, argv[i+1]);
i++;
i_incr = 1;
break;
case 'c':
strcpy(cp->console, optarg);
if ( i + 1 >= argc ||
!(argv[i][j+1] == ' ' || argv[i][j+1] != ' ')) {
usage( argv[0]);
exit(0);
}
strcpy(cp->console, argv[i+1]);
i++;
i_incr = 1;
break;
case 'd':
strcpy(cp->dir, optarg);
if ( i + 1 >= argc ||
!(argv[i][j+1] == ' ' || argv[i][j+1] != ' ')) {
usage( argv[0]);
exit(0);
}
strcpy(cp->dir, argv[i+1]);
i++;
i_incr = 1;
break;
case 'e':
cp->flags.b.ignoreError = 1;
......@@ -309,19 +317,38 @@ createContext (int argc, char **argv)
cp->flags.b.ignoreFatal = 1;
break;
case 'h':
if ( i + 1 >= argc ||
!(argv[i][j+1] == ' ' || argv[i][j+1] != ' ')) {
usage( argv[0]);
exit(0);
}
cp->flags.b.hostname = 1;
strcpy(cp->hostname, optarg);
strcpy(cp->hostname, argv[i+1]);
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, optarg);
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(optarg);
cp->busid = atoi(argv[i+1]);
break;
case 'r':
cp->flags.b.restart = 1;
......@@ -337,12 +364,26 @@ createContext (int argc, char **argv)
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, optarg);
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 @@
#include <stdio.h>
#if defined OS_LYNX
# 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 <fcntl.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