aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-07-14 18:39:08 +0000
committerEric Andersen <andersen@codepoet.org>2000-07-14 18:39:08 +0000
commitadd09fd558c8a336554fbf8b381ab0f8e180382a (patch)
tree2ccbcd48f335161c647be3f2c296cae06aceb671
parent17ad45aace3141d1b997208a43979495ead98f7c (diff)
downloadbusybox-w32-add09fd558c8a336554fbf8b381ab0f8e180382a.tar.gz
busybox-w32-add09fd558c8a336554fbf8b381ab0f8e180382a.tar.bz2
busybox-w32-add09fd558c8a336554fbf8b381ab0f8e180382a.zip
Getopt'ed by Marc Nijdam <marc_nijdam@hp.com>
-Erik
-rw-r--r--coreutils/date.c70
-rw-r--r--coreutils/echo.c25
-rw-r--r--date.c70
-rw-r--r--dmesg.c56
-rw-r--r--echo.c25
-rw-r--r--util-linux/dmesg.c56
6 files changed, 128 insertions, 174 deletions
diff --git a/coreutils/date.c b/coreutils/date.c
index bc6d13137..3ede1237c 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -159,7 +159,7 @@ int date_main(int argc, char **argv)
159 char *date_str = NULL; 159 char *date_str = NULL;
160 char *date_fmt = NULL; 160 char *date_fmt = NULL;
161 char *t_buff; 161 char *t_buff;
162 int i; 162 char c;
163 int set_time = 0; 163 int set_time = 0;
164 int rfc822 = 0; 164 int rfc822 = 0;
165 int utc = 0; 165 int utc = 0;
@@ -168,49 +168,39 @@ int date_main(int argc, char **argv)
168 struct tm tm_time; 168 struct tm tm_time;
169 169
170 /* Interpret command line args */ 170 /* Interpret command line args */
171 i = --argc; 171 while ((c = getopt(argc, argv, "Rs:ud:")) != EOF) {
172 argv++; 172 switch (c) {
173 while (i > 0 && **argv) { 173 case 'R':
174 if (**argv == '-') { 174 rfc822 = 1;
175 while (i > 0 && *++(*argv)) 175 break;
176 switch (**argv) { 176 case 's':
177 case 'R': 177 set_time = 1;
178 rfc822 = 1; 178 if ((date_str != NULL) || ((date_str = optarg) == NULL))
179 break;
180 case 's':
181 set_time = 1;
182 if (date_str != NULL)
183 usage(date_usage);
184 date_str = *argv;
185 break;
186 case 'u':
187 utc = 1;
188 if (putenv("TZ=UTC0") != 0)
189 fatalError(memory_exhausted);
190 break;
191 case 'd':
192 use_arg = 1;
193 if (date_str != NULL)
194 usage(date_usage);
195 date_str = *argv;
196 break;
197 case '-':
198 usage(date_usage);
199 }
200 } else {
201 if ((date_fmt == NULL) && (**argv == '+'))
202 date_fmt = *argv + 1; /* Skip over the '+' */
203 else if (date_str == NULL) {
204 set_time = 1;
205 date_str = *argv;
206 } else {
207 usage(date_usage); 179 usage(date_usage);
208 } 180 break;
181 case 'u':
182 utc = 1;
183 if (putenv("TZ=UTC0") != 0)
184 fatalError(memory_exhausted);
185 break;
186 case 'd':
187 use_arg = 1;
188 if ((date_str != NULL) || ((date_str = optarg) == NULL))
189 usage(date_usage);
190 break;
191 default:
192 usage(date_usage);
209 } 193 }
210 i--;
211 argv++;
212 } 194 }
213 195
196 if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+'))
197 date_fmt = &argv[optind][1]; /* Skip over the '+' */
198 else if (date_str == NULL) {
199 set_time = 1;
200 date_str = argv[optind];
201 } else {
202 usage(date_usage);
203 }
214 204
215 /* Now we have parsed all the information except the date format 205 /* Now we have parsed all the information except the date format
216 which depends on whether the clock is being set or read */ 206 which depends on whether the clock is being set or read */
diff --git a/coreutils/echo.c b/coreutils/echo.c
index 6e279d1c6..387ea3fef 100644
--- a/coreutils/echo.c
+++ b/coreutils/echo.c
@@ -45,23 +45,24 @@ echo_main(int argc, char** argv)
45 int nflag = 0; 45 int nflag = 0;
46 int eflag = 0; 46 int eflag = 0;
47 47
48 ap = argv; 48
49 if (argc) 49 while ((c = getopt(argc, argv, "neE")) != EOF) {
50 ap++; 50 switch (c) {
51 while ((p = *ap) != NULL && *p == '-') { 51 case 'n':
52 if (strcmp(p, "-n")==0) {
53 nflag = 1; 52 nflag = 1;
54 } else if (strcmp(p, "-e")==0) { 53 break;
54 case 'e':
55 eflag = 1; 55 eflag = 1;
56 } else if (strcmp(p, "-E")==0) { 56 break;
57 case 'E':
57 eflag = 0; 58 eflag = 0;
59 break;
60 default:
61 usage(uname_usage);
58 } 62 }
59 else if (strncmp(p, "--", 2)==0) {
60 usage( uname_usage);
61 }
62 else break;
63 ap++;
64 } 63 }
64
65 ap = &argv[optind];
65 while ((p = *ap++) != NULL) { 66 while ((p = *ap++) != NULL) {
66 while ((c = *p++) != '\0') { 67 while ((c = *p++) != '\0') {
67 if (c == '\\' && eflag) { 68 if (c == '\\' && eflag) {
diff --git a/date.c b/date.c
index bc6d13137..3ede1237c 100644
--- a/date.c
+++ b/date.c
@@ -159,7 +159,7 @@ int date_main(int argc, char **argv)
159 char *date_str = NULL; 159 char *date_str = NULL;
160 char *date_fmt = NULL; 160 char *date_fmt = NULL;
161 char *t_buff; 161 char *t_buff;
162 int i; 162 char c;
163 int set_time = 0; 163 int set_time = 0;
164 int rfc822 = 0; 164 int rfc822 = 0;
165 int utc = 0; 165 int utc = 0;
@@ -168,49 +168,39 @@ int date_main(int argc, char **argv)
168 struct tm tm_time; 168 struct tm tm_time;
169 169
170 /* Interpret command line args */ 170 /* Interpret command line args */
171 i = --argc; 171 while ((c = getopt(argc, argv, "Rs:ud:")) != EOF) {
172 argv++; 172 switch (c) {
173 while (i > 0 && **argv) { 173 case 'R':
174 if (**argv == '-') { 174 rfc822 = 1;
175 while (i > 0 && *++(*argv)) 175 break;
176 switch (**argv) { 176 case 's':
177 case 'R': 177 set_time = 1;
178 rfc822 = 1; 178 if ((date_str != NULL) || ((date_str = optarg) == NULL))
179 break;
180 case 's':
181 set_time = 1;
182 if (date_str != NULL)
183 usage(date_usage);
184 date_str = *argv;
185 break;
186 case 'u':
187 utc = 1;
188 if (putenv("TZ=UTC0") != 0)
189 fatalError(memory_exhausted);
190 break;
191 case 'd':
192 use_arg = 1;
193 if (date_str != NULL)
194 usage(date_usage);
195 date_str = *argv;
196 break;
197 case '-':
198 usage(date_usage);
199 }
200 } else {
201 if ((date_fmt == NULL) && (**argv == '+'))
202 date_fmt = *argv + 1; /* Skip over the '+' */
203 else if (date_str == NULL) {
204 set_time = 1;
205 date_str = *argv;
206 } else {
207 usage(date_usage); 179 usage(date_usage);
208 } 180 break;
181 case 'u':
182 utc = 1;
183 if (putenv("TZ=UTC0") != 0)
184 fatalError(memory_exhausted);
185 break;
186 case 'd':
187 use_arg = 1;
188 if ((date_str != NULL) || ((date_str = optarg) == NULL))
189 usage(date_usage);
190 break;
191 default:
192 usage(date_usage);
209 } 193 }
210 i--;
211 argv++;
212 } 194 }
213 195
196 if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+'))
197 date_fmt = &argv[optind][1]; /* Skip over the '+' */
198 else if (date_str == NULL) {
199 set_time = 1;
200 date_str = argv[optind];
201 } else {
202 usage(date_usage);
203 }
214 204
215 /* Now we have parsed all the information except the date format 205 /* Now we have parsed all the information except the date format
216 which depends on whether the clock is being set or read */ 206 which depends on whether the clock is being set or read */
diff --git a/dmesg.c b/dmesg.c
index df2bce713..961e532b0 100644
--- a/dmesg.c
+++ b/dmesg.c
@@ -44,50 +44,36 @@ static const char dmesg_usage[] = "dmesg [-c] [-n LEVEL] [-s SIZE]\n"
44 44
45int dmesg_main(int argc, char **argv) 45int dmesg_main(int argc, char **argv)
46{ 46{
47 char *buf; 47 char *buf, c;
48 int bufsize = 8196; 48 int bufsize = 8196;
49 int i; 49 int i;
50 int n; 50 int n;
51 int level = 0; 51 int level = 0;
52 int lastc; 52 int lastc;
53 int cmd = 3; 53 int cmd = 3;
54 int stopDoingThat;
55 54
56 argc--; 55 while ((c = getopt(argc, argv, "cn:s:")) != EOF) {
57 argv++; 56 switch (c) {
58 57 case 'c':
59 /* Parse any options */ 58 cmd = 4;
60 while (argc && **argv == '-') { 59 break;
61 stopDoingThat = FALSE; 60 case 'n':
62 while (stopDoingThat == FALSE && *++(*argv)) { 61 cmd = 8;
63 switch (**argv) { 62 if (optarg == NULL)
64 case 'c': 63 usage(dmesg_usage);
65 cmd = 4; 64 level = atoi(optarg);
66 break; 65 break;
67 case 'n': 66 case 's':
68 cmd = 8; 67 if (optarg == NULL)
69 if (--argc == 0) 68 usage(dmesg_usage);
70 goto end; 69 bufsize = atoi(optarg);
71 level = atoi(*(++argv)); 70 break;
72 if (--argc > 0) 71 default:
73 ++argv; 72 usage(dmesg_usage);
74 stopDoingThat = TRUE;
75 break;
76 case 's':
77 if (--argc == 0)
78 goto end;
79 bufsize = atoi(*(++argv));
80 if (--argc > 0)
81 ++argv;
82 stopDoingThat = TRUE;
83 break;
84 default:
85 goto end;
86 }
87 } 73 }
88 } 74 }
89 75
90 if (argc > 1) { 76 if (optind < argc) {
91 goto end; 77 goto end;
92 } 78 }
93 79
diff --git a/echo.c b/echo.c
index 6e279d1c6..387ea3fef 100644
--- a/echo.c
+++ b/echo.c
@@ -45,23 +45,24 @@ echo_main(int argc, char** argv)
45 int nflag = 0; 45 int nflag = 0;
46 int eflag = 0; 46 int eflag = 0;
47 47
48 ap = argv; 48
49 if (argc) 49 while ((c = getopt(argc, argv, "neE")) != EOF) {
50 ap++; 50 switch (c) {
51 while ((p = *ap) != NULL && *p == '-') { 51 case 'n':
52 if (strcmp(p, "-n")==0) {
53 nflag = 1; 52 nflag = 1;
54 } else if (strcmp(p, "-e")==0) { 53 break;
54 case 'e':
55 eflag = 1; 55 eflag = 1;
56 } else if (strcmp(p, "-E")==0) { 56 break;
57 case 'E':
57 eflag = 0; 58 eflag = 0;
59 break;
60 default:
61 usage(uname_usage);
58 } 62 }
59 else if (strncmp(p, "--", 2)==0) {
60 usage( uname_usage);
61 }
62 else break;
63 ap++;
64 } 63 }
64
65 ap = &argv[optind];
65 while ((p = *ap++) != NULL) { 66 while ((p = *ap++) != NULL) {
66 while ((c = *p++) != '\0') { 67 while ((c = *p++) != '\0') {
67 if (c == '\\' && eflag) { 68 if (c == '\\' && eflag) {
diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c
index df2bce713..961e532b0 100644
--- a/util-linux/dmesg.c
+++ b/util-linux/dmesg.c
@@ -44,50 +44,36 @@ static const char dmesg_usage[] = "dmesg [-c] [-n LEVEL] [-s SIZE]\n"
44 44
45int dmesg_main(int argc, char **argv) 45int dmesg_main(int argc, char **argv)
46{ 46{
47 char *buf; 47 char *buf, c;
48 int bufsize = 8196; 48 int bufsize = 8196;
49 int i; 49 int i;
50 int n; 50 int n;
51 int level = 0; 51 int level = 0;
52 int lastc; 52 int lastc;
53 int cmd = 3; 53 int cmd = 3;
54 int stopDoingThat;
55 54
56 argc--; 55 while ((c = getopt(argc, argv, "cn:s:")) != EOF) {
57 argv++; 56 switch (c) {
58 57 case 'c':
59 /* Parse any options */ 58 cmd = 4;
60 while (argc && **argv == '-') { 59 break;
61 stopDoingThat = FALSE; 60 case 'n':
62 while (stopDoingThat == FALSE && *++(*argv)) { 61 cmd = 8;
63 switch (**argv) { 62 if (optarg == NULL)
64 case 'c': 63 usage(dmesg_usage);
65 cmd = 4; 64 level = atoi(optarg);
66 break; 65 break;
67 case 'n': 66 case 's':
68 cmd = 8; 67 if (optarg == NULL)
69 if (--argc == 0) 68 usage(dmesg_usage);
70 goto end; 69 bufsize = atoi(optarg);
71 level = atoi(*(++argv)); 70 break;
72 if (--argc > 0) 71 default:
73 ++argv; 72 usage(dmesg_usage);
74 stopDoingThat = TRUE;
75 break;
76 case 's':
77 if (--argc == 0)
78 goto end;
79 bufsize = atoi(*(++argv));
80 if (--argc > 0)
81 ++argv;
82 stopDoingThat = TRUE;
83 break;
84 default:
85 goto end;
86 }
87 } 73 }
88 } 74 }
89 75
90 if (argc > 1) { 76 if (optind < argc) {
91 goto end; 77 goto end;
92 } 78 }
93 79