diff options
author | Matt Kraai <kraai@debian.org> | 2001-07-30 14:43:20 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2001-07-30 14:43:20 +0000 |
commit | 13cb8427736298c80055ecd6a9abbef45849b527 (patch) | |
tree | 35356ff4337b3aaa7ba0cc94aff024939cc06562 | |
parent | 547e10208224a60c513f3d127ea1d0e2a4e23f19 (diff) | |
download | busybox-w32-13cb8427736298c80055ecd6a9abbef45849b527.tar.gz busybox-w32-13cb8427736298c80055ecd6a9abbef45849b527.tar.bz2 busybox-w32-13cb8427736298c80055ecd6a9abbef45849b527.zip |
Rework option handling to save space.
-rw-r--r-- | rdate.c | 30 | ||||
-rw-r--r-- | util-linux/rdate.c | 30 |
2 files changed, 22 insertions, 38 deletions
@@ -48,10 +48,10 @@ static time_t askremotedate(const char *host) | |||
48 | h = xgethostbyname(host); /* get the IP addr */ | 48 | h = xgethostbyname(host); /* get the IP addr */ |
49 | 49 | ||
50 | if ((tserv = getservbyname("time", "tcp")) == NULL) /* find port # */ | 50 | if ((tserv = getservbyname("time", "tcp")) == NULL) /* find port # */ |
51 | perror_msg_and_die("%s", "time"); | 51 | perror_msg_and_die("time"); |
52 | 52 | ||
53 | if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) /* get net connection */ | 53 | if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) /* get net connection */ |
54 | perror_msg_and_die("%s", "socket"); | 54 | perror_msg_and_die("socket"); |
55 | 55 | ||
56 | memcpy(&s_in.sin_addr, h->h_addr, sizeof(s_in.sin_addr)); | 56 | memcpy(&s_in.sin_addr, h->h_addr, sizeof(s_in.sin_addr)); |
57 | s_in.sin_port= tserv->s_port; | 57 | s_in.sin_port= tserv->s_port; |
@@ -80,33 +80,25 @@ int rdate_main(int argc, char **argv) | |||
80 | { | 80 | { |
81 | time_t remote_time; | 81 | time_t remote_time; |
82 | int opt; | 82 | int opt; |
83 | int setdate = 0; | 83 | int setdate = 1; |
84 | int printdate= 0; | 84 | int printdate = 1; |
85 | 85 | ||
86 | /* Interpret command line args */ | 86 | /* Interpret command line args */ |
87 | /* do special-case option parsing */ | 87 | while ((opt = getopt(argc, argv, "sp")) > 0) { |
88 | if (argv[1] && (strcmp(argv[1], "--help") == 0)) | ||
89 | show_usage(); | ||
90 | |||
91 | /* do normal option parsing */ | ||
92 | while ((opt = getopt(argc, argv, "Hsp")) > 0) { | ||
93 | switch (opt) { | 88 | switch (opt) { |
94 | default: | ||
95 | case 'H': | ||
96 | show_usage(); | ||
97 | break; | ||
98 | case 's': | 89 | case 's': |
99 | setdate++; | 90 | printdate = 0; |
91 | setdate = 1; | ||
100 | break; | 92 | break; |
101 | case 'p': | 93 | case 'p': |
102 | printdate++; | 94 | printdate = 1; |
95 | setdate = 0; | ||
103 | break; | 96 | break; |
97 | default: | ||
98 | show_usage(); | ||
104 | } | 99 | } |
105 | } | 100 | } |
106 | 101 | ||
107 | /* the default action is to set the date */ | ||
108 | if (printdate==0 && setdate==0) setdate++; | ||
109 | |||
110 | if (optind == argc) | 102 | if (optind == argc) |
111 | show_usage(); | 103 | show_usage(); |
112 | 104 | ||
diff --git a/util-linux/rdate.c b/util-linux/rdate.c index 8deb35d14..50be4de8c 100644 --- a/util-linux/rdate.c +++ b/util-linux/rdate.c | |||
@@ -48,10 +48,10 @@ static time_t askremotedate(const char *host) | |||
48 | h = xgethostbyname(host); /* get the IP addr */ | 48 | h = xgethostbyname(host); /* get the IP addr */ |
49 | 49 | ||
50 | if ((tserv = getservbyname("time", "tcp")) == NULL) /* find port # */ | 50 | if ((tserv = getservbyname("time", "tcp")) == NULL) /* find port # */ |
51 | perror_msg_and_die("%s", "time"); | 51 | perror_msg_and_die("time"); |
52 | 52 | ||
53 | if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) /* get net connection */ | 53 | if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) /* get net connection */ |
54 | perror_msg_and_die("%s", "socket"); | 54 | perror_msg_and_die("socket"); |
55 | 55 | ||
56 | memcpy(&s_in.sin_addr, h->h_addr, sizeof(s_in.sin_addr)); | 56 | memcpy(&s_in.sin_addr, h->h_addr, sizeof(s_in.sin_addr)); |
57 | s_in.sin_port= tserv->s_port; | 57 | s_in.sin_port= tserv->s_port; |
@@ -80,33 +80,25 @@ int rdate_main(int argc, char **argv) | |||
80 | { | 80 | { |
81 | time_t remote_time; | 81 | time_t remote_time; |
82 | int opt; | 82 | int opt; |
83 | int setdate = 0; | 83 | int setdate = 1; |
84 | int printdate= 0; | 84 | int printdate = 1; |
85 | 85 | ||
86 | /* Interpret command line args */ | 86 | /* Interpret command line args */ |
87 | /* do special-case option parsing */ | 87 | while ((opt = getopt(argc, argv, "sp")) > 0) { |
88 | if (argv[1] && (strcmp(argv[1], "--help") == 0)) | ||
89 | show_usage(); | ||
90 | |||
91 | /* do normal option parsing */ | ||
92 | while ((opt = getopt(argc, argv, "Hsp")) > 0) { | ||
93 | switch (opt) { | 88 | switch (opt) { |
94 | default: | ||
95 | case 'H': | ||
96 | show_usage(); | ||
97 | break; | ||
98 | case 's': | 89 | case 's': |
99 | setdate++; | 90 | printdate = 0; |
91 | setdate = 1; | ||
100 | break; | 92 | break; |
101 | case 'p': | 93 | case 'p': |
102 | printdate++; | 94 | printdate = 1; |
95 | setdate = 0; | ||
103 | break; | 96 | break; |
97 | default: | ||
98 | show_usage(); | ||
104 | } | 99 | } |
105 | } | 100 | } |
106 | 101 | ||
107 | /* the default action is to set the date */ | ||
108 | if (printdate==0 && setdate==0) setdate++; | ||
109 | |||
110 | if (optind == argc) | 102 | if (optind == argc) |
111 | show_usage(); | 103 | show_usage(); |
112 | 104 | ||