parse() parses the -s option now correctly
This commit is contained in:
parent
76400bfaaa
commit
00efa76eaa
19
websh.c
19
websh.c
@ -10,12 +10,16 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
static const char *pname;
|
static const char *pname;
|
||||||
|
|
||||||
|
static const char *word;
|
||||||
|
static const char *tag;
|
||||||
|
|
||||||
void usage(void)
|
void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: websh [-e] [-h] [-s WORD:TAG]\n");
|
fprintf(stderr, "Usage: websh [-e] [-h] [-s WORD:TAG]\n");
|
||||||
@ -29,6 +33,7 @@ void parse(int argc, char *argv[])
|
|||||||
int sFlag = 0;
|
int sFlag = 0;
|
||||||
|
|
||||||
int optInd = 0;
|
int optInd = 0;
|
||||||
|
char *sArg;
|
||||||
|
|
||||||
while ((optInd = getopt(argc, argv, "ehs:")) != -1) {
|
while ((optInd = getopt(argc, argv, "ehs:")) != -1) {
|
||||||
switch (optInd) {
|
switch (optInd) {
|
||||||
@ -51,7 +56,7 @@ void parse(int argc, char *argv[])
|
|||||||
usage();
|
usage();
|
||||||
} else {
|
} else {
|
||||||
sFlag = 1;
|
sFlag = 1;
|
||||||
char *sArg = optarg;
|
sArg = optarg;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
@ -62,6 +67,18 @@ void parse(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *token;
|
||||||
|
int i = 0;
|
||||||
|
while ((token = strsep(&sArg, ":"))) {
|
||||||
|
if (i == 2)
|
||||||
|
usage();
|
||||||
|
if (i == 0) {
|
||||||
|
word = token;
|
||||||
|
} else {
|
||||||
|
tag = token;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
pname = argv[0];
|
pname = argv[0];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user