aboutsummaryrefslogtreecommitdiff
path: root/coreutils/date.c
diff options
context:
space:
mode:
author"Vladimir N. Oleynik" <dzo@simtreas.ru>2005-10-12 14:36:42 +0000
committer"Vladimir N. Oleynik" <dzo@simtreas.ru>2005-10-12 14:36:42 +0000
commit3ade65fc0451e898f3750a581c9a12abfe04b57e (patch)
treeb9d0ecc0753d2aecb4d63faead1a8787ecb0a079 /coreutils/date.c
parent3ebb89521831fbce738ab3dfbb9f841c3a561d37 (diff)
downloadbusybox-w32-3ade65fc0451e898f3750a581c9a12abfe04b57e.tar.gz
busybox-w32-3ade65fc0451e898f3750a581c9a12abfe04b57e.tar.bz2
busybox-w32-3ade65fc0451e898f3750a581c9a12abfe04b57e.zip
remove 1 CR, correct strange bb_opt_complementally, add #if 0 and XXX-comment: pleace examine this\!
Diffstat (limited to 'coreutils/date.c')
-rw-r--r--coreutils/date.c65
1 files changed, 33 insertions, 32 deletions
diff --git a/coreutils/date.c b/coreutils/date.c
index 5ee2c74e8..43130f914 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -84,35 +84,31 @@ static struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
84 84
85 /* Parse input and assign appropriately to tm_time */ 85 /* Parse input and assign appropriately to tm_time */
86 86
87 if (t = 87 if (t = *tm_time, sscanf(t_string, "%d:%d:%d", &t.tm_hour, &t.tm_min,
88 *tm_time, sscanf(t_string, "%d:%d:%d", &t.tm_hour, &t.tm_min,
89 &t.tm_sec) == 3) { 88 &t.tm_sec) == 3) {
90 /* no adjustments needed */ 89 /* no adjustments needed */
91 } else if (t = 90 } else if (t = *tm_time, sscanf(t_string, "%d:%d", &t.tm_hour,
92 *tm_time, sscanf(t_string, "%d:%d", &t.tm_hour,
93 &t.tm_min) == 2) { 91 &t.tm_min) == 2) {
94 /* no adjustments needed */ 92 /* no adjustments needed */
95 } else if (t = 93 } else if (t = *tm_time, sscanf(t_string, "%d.%d-%d:%d:%d", &t.tm_mon,
96 *tm_time, sscanf(t_string, "%d.%d-%d:%d:%d", &t.tm_mon, 94 &t.tm_mday, &t.tm_hour,
97 &t.tm_mday, &t.tm_hour, &t.tm_min, 95 &t.tm_min, &t.tm_sec) == 5) {
98 &t.tm_sec) == 5) {
99 /* Adjust dates from 1-12 to 0-11 */ 96 /* Adjust dates from 1-12 to 0-11 */
100 t.tm_mon -= 1; 97 t.tm_mon -= 1;
101 } else if (t = 98 } else if (t = *tm_time, sscanf(t_string, "%d.%d-%d:%d", &t.tm_mon,
102 *tm_time, sscanf(t_string, "%d.%d-%d:%d", &t.tm_mon, 99 &t.tm_mday,
103 &t.tm_mday, &t.tm_hour, &t.tm_min) == 4) { 100 &t.tm_hour, &t.tm_min) == 4) {
104 /* Adjust dates from 1-12 to 0-11 */ 101 /* Adjust dates from 1-12 to 0-11 */
105 t.tm_mon -= 1; 102 t.tm_mon -= 1;
106 } else if (t = 103 } else if (t = *tm_time, sscanf(t_string, "%d.%d.%d-%d:%d:%d", &t.tm_year,
107 *tm_time, sscanf(t_string, "%d.%d.%d-%d:%d:%d", &t.tm_year, 104 &t.tm_mon, &t.tm_mday,
108 &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, 105 &t.tm_hour, &t.tm_min,
109 &t.tm_sec) == 6) { 106 &t.tm_sec) == 6) {
110 t.tm_year -= 1900; /* Adjust years */ 107 t.tm_year -= 1900; /* Adjust years */
111 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */ 108 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
112 } else if (t = 109 } else if (t = *tm_time, sscanf(t_string, "%d.%d.%d-%d:%d", &t.tm_year,
113 *tm_time, sscanf(t_string, "%d.%d.%d-%d:%d", &t.tm_year, 110 &t.tm_mon, &t.tm_mday,
114 &t.tm_mon, &t.tm_mday, &t.tm_hour, 111 &t.tm_hour, &t.tm_min) == 5) {
115 &t.tm_min) == 5) {
116 t.tm_year -= 1900; /* Adjust years */ 112 t.tm_year -= 1900; /* Adjust years */
117 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */ 113 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
118 } else { 114 } else {
@@ -137,7 +133,9 @@ int date_main(int argc, char **argv)
137 char *date_fmt = NULL; 133 char *date_fmt = NULL;
138 int set_time; 134 int set_time;
139 int utc; 135 int utc;
136#if 0
140 int use_arg = 0; 137 int use_arg = 0;
138#endif
141 time_t tm; 139 time_t tm;
142 unsigned long opt; 140 unsigned long opt;
143 struct tm tm_time; 141 struct tm tm_time;
@@ -151,7 +149,7 @@ int date_main(int argc, char **argv)
151#else 149#else
152# define GETOPT_ISOFMT 150# define GETOPT_ISOFMT
153#endif 151#endif
154 bb_opt_complementally = "?d~ds:s~ds"; 152 bb_opt_complementally = "?d~s:s~d";
155 opt = bb_getopt_ulflags(argc, argv, "Rs:ud:r:" GETOPT_ISOFMT, 153 opt = bb_getopt_ulflags(argc, argv, "Rs:ud:r:" GETOPT_ISOFMT,
156 &date_str, &date_str, &filename 154 &date_str, &date_str, &filename
157#ifdef CONFIG_FEATURE_DATE_ISOFMT 155#ifdef CONFIG_FEATURE_DATE_ISOFMT
@@ -160,10 +158,12 @@ int date_main(int argc, char **argv)
160 ); 158 );
161 set_time = opt & DATE_OPT_SET; 159 set_time = opt & DATE_OPT_SET;
162 utc = opt & DATE_OPT_UTC; 160 utc = opt & DATE_OPT_UTC;
163 if ((utc) && (putenv("TZ=UTC0") != 0)) { 161 if (utc && putenv("TZ=UTC0") != 0) {
164 bb_error_msg_and_die(bb_msg_memory_exhausted); 162 bb_error_msg_and_die(bb_msg_memory_exhausted);
165 } 163 }
164#if 0
166 use_arg = opt & DATE_OPT_DATE; 165 use_arg = opt & DATE_OPT_DATE;
166#endif
167#ifdef CONFIG_FEATURE_DATE_ISOFMT 167#ifdef CONFIG_FEATURE_DATE_ISOFMT
168 if(opt & DATE_OPT_TIMESPEC) { 168 if(opt & DATE_OPT_TIMESPEC) {
169 if (!isofmt_arg) { 169 if (!isofmt_arg) {
@@ -171,17 +171,17 @@ int date_main(int argc, char **argv)
171 } else { 171 } else {
172 int ifmt_len = bb_strlen(isofmt_arg); 172 int ifmt_len = bb_strlen(isofmt_arg);
173 173
174 if ((ifmt_len <= 4) 174 if (ifmt_len <= 4
175 && (strncmp(isofmt_arg, "date", ifmt_len) == 0)) { 175 && strncmp(isofmt_arg, "date", ifmt_len) == 0) {
176 ifmt = 1; 176 ifmt = 1;
177 } else if ((ifmt_len <= 5) 177 } else if (ifmt_len <= 5
178 && (strncmp(isofmt_arg, "hours", ifmt_len) == 0)) { 178 && strncmp(isofmt_arg, "hours", ifmt_len) == 0) {
179 ifmt = 2; 179 ifmt = 2;
180 } else if ((ifmt_len <= 7) 180 } else if (ifmt_len <= 7
181 && (strncmp(isofmt_arg, "minutes", ifmt_len) == 0)) { 181 && strncmp(isofmt_arg, "minutes", ifmt_len) == 0) {
182 ifmt = 3; 182 ifmt = 3;
183 } else if ((ifmt_len <= 7) 183 } else if (ifmt_len <= 7
184 && (strncmp(isofmt_arg, "seconds", ifmt_len) == 0)) { 184 && strncmp(isofmt_arg, "seconds", ifmt_len) == 0) {
185 ifmt = 4; 185 ifmt = 4;
186 } 186 }
187 } 187 }
@@ -191,6 +191,7 @@ int date_main(int argc, char **argv)
191 } 191 }
192#endif 192#endif
193 193
194 /* XXX, date_fmt == NULL from this always */
194 if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) { 195 if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) {
195 date_fmt = &argv[optind][1]; /* Skip over the '+' */ 196 date_fmt = &argv[optind][1]; /* Skip over the '+' */
196 } else if (date_str == NULL) { 197 } else if (date_str == NULL) {
@@ -204,7 +205,7 @@ int date_main(int argc, char **argv)
204 if(filename) { 205 if(filename) {
205 struct stat statbuf; 206 struct stat statbuf;
206 if(stat(filename,&statbuf)) 207 if(stat(filename,&statbuf))
207 bb_perror_msg_and_die("File '%s' not found.\n",filename); 208 bb_perror_msg_and_die("File '%s' not found.", filename);
208 tm=statbuf.st_mtime; 209 tm=statbuf.st_mtime;
209 } else time(&tm); 210 } else time(&tm);
210 memcpy(&tm_time, localtime(&tm), sizeof(tm_time)); 211 memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
@@ -227,12 +228,12 @@ int date_main(int argc, char **argv)
227 if (tm < 0) { 228 if (tm < 0) {
228 bb_error_msg_and_die(bb_msg_invalid_date, date_str); 229 bb_error_msg_and_die(bb_msg_invalid_date, date_str);
229 } 230 }
230 if (utc && (putenv("TZ=UTC0") != 0)) { 231 if (utc && putenv("TZ=UTC0") != 0) {
231 bb_error_msg_and_die(bb_msg_memory_exhausted); 232 bb_error_msg_and_die(bb_msg_memory_exhausted);
232 } 233 }
233 234
234 /* if setting time, set it */ 235 /* if setting time, set it */
235 if (set_time && (stime(&tm) < 0)) { 236 if (set_time && stime(&tm) < 0) {
236 bb_perror_msg("cannot set date"); 237 bb_perror_msg("cannot set date");
237 } 238 }
238 } 239 }