summaryrefslogtreecommitdiffhomepage
path: root/echo.c
diff options
context:
space:
mode:
Diffstat (limited to 'echo.c')
-rw-r--r--echo.c25
1 files changed, 13 insertions, 12 deletions
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)
int nflag = 0;
int eflag = 0;
- ap = argv;
- if (argc)
- ap++;
- while ((p = *ap) != NULL && *p == '-') {
- if (strcmp(p, "-n")==0) {
+
+ while ((c = getopt(argc, argv, "neE")) != EOF) {
+ switch (c) {
+ case 'n':
nflag = 1;
- } else if (strcmp(p, "-e")==0) {
+ break;
+ case 'e':
eflag = 1;
- } else if (strcmp(p, "-E")==0) {
+ break;
+ case 'E':
eflag = 0;
+ break;
+ default:
+ usage(uname_usage);
}
- else if (strncmp(p, "--", 2)==0) {
- usage( uname_usage);
- }
- else break;
- ap++;
}
+
+ ap = &argv[optind];
while ((p = *ap++) != NULL) {
while ((c = *p++) != '\0') {
if (c == '\\' && eflag) {