aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2002-08-23 05:58:38 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2002-08-23 05:58:38 +0000
commit03195fc16f400798fe27640ccb46ed39f4ee7f4a (patch)
tree0480b59d739463d96525fd9c125429294107e6f6
parenta199b1725344f211c79b880855e6895bdd6c7477 (diff)
downloadbusybox-w32-03195fc16f400798fe27640ccb46ed39f4ee7f4a.tar.gz
busybox-w32-03195fc16f400798fe27640ccb46ed39f4ee7f4a.tar.bz2
busybox-w32-03195fc16f400798fe27640ccb46ed39f4ee7f4a.zip
Run through indent, fix comments
-rw-r--r--coreutils/date.c238
1 files changed, 112 insertions, 126 deletions
diff --git a/coreutils/date.c b/coreutils/date.c
index a9188a1ce..d68c04a8d 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -48,19 +48,18 @@ static struct tm *date_conv_time(struct tm *tm_time, const char *t_string)
48{ 48{
49 int nr; 49 int nr;
50 50
51 nr = sscanf(t_string, "%2d%2d%2d%2d%d", 51 nr = sscanf(t_string, "%2d%2d%2d%2d%d", &(tm_time->tm_mon),
52 &(tm_time->tm_mon), 52 &(tm_time->tm_mday), &(tm_time->tm_hour), &(tm_time->tm_min),
53 &(tm_time->tm_mday), 53 &(tm_time->tm_year));
54 &(tm_time->tm_hour),
55 &(tm_time->tm_min), &(tm_time->tm_year));
56 54
57 if (nr < 4 || nr > 5) { 55 if (nr < 4 || nr > 5) {
58 error_msg_and_die(invalid_date, t_string); 56 error_msg_and_die(invalid_date, t_string);
59 } 57 }
60 58
61 /* correct for century - minor Y2K problem here? */ 59 /* correct for century - minor Y2K problem here? */
62 if (tm_time->tm_year >= 1900) 60 if (tm_time->tm_year >= 1900) {
63 tm_time->tm_year -= 1900; 61 tm_time->tm_year -= 1900;
62 }
64 /* adjust date */ 63 /* adjust date */
65 tm_time->tm_mon -= 1; 64 tm_time->tm_mon -= 1;
66 65
@@ -77,50 +76,39 @@ static struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
77 76
78 /* Parse input and assign appropriately to tm_time */ 77 /* Parse input and assign appropriately to tm_time */
79 78
80 if (t=*tm_time,sscanf(t_string, "%d:%d:%d", 79 if (t =
81 &t.tm_hour, &t.tm_min, &t.tm_sec) == 3) { 80 *tm_time, sscanf(t_string, "%d:%d:%d", &t.tm_hour, &t.tm_min,
82 /* no adjustments needed */ 81 &t.tm_sec) == 3) {
83 82 /* no adjustments needed */
84 } else if (t=*tm_time,sscanf(t_string, "%d:%d", 83 } else if (t =
85 &t.tm_hour, &t.tm_min) == 2) { 84 *tm_time, sscanf(t_string, "%d:%d", &t.tm_hour,
86 /* no adjustments needed */ 85 &t.tm_min) == 2) {
87 86 /* no adjustments needed */
88 87 } else if (t =
89 } else if (t=*tm_time,sscanf(t_string, "%d.%d-%d:%d:%d", 88 *tm_time, sscanf(t_string, "%d.%d-%d:%d:%d", &t.tm_mon,
90 &t.tm_mon, 89 &t.tm_mday, &t.tm_hour, &t.tm_min,
91 &t.tm_mday, 90 &t.tm_sec) == 5) {
92 &t.tm_hour, 91 /* Adjust dates from 1-12 to 0-11 */
93 &t.tm_min, &t.tm_sec) == 5) { 92 t.tm_mon -= 1;
94 93 } else if (t =
95 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */ 94 *tm_time, sscanf(t_string, "%d.%d-%d:%d", &t.tm_mon,
96 95 &t.tm_mday, &t.tm_hour, &t.tm_min) == 4) {
97 } else if (t=*tm_time,sscanf(t_string, "%d.%d-%d:%d", 96 /* Adjust dates from 1-12 to 0-11 */
98 &t.tm_mon, 97 t.tm_mon -= 1;
99 &t.tm_mday, 98 } else if (t =
100 &t.tm_hour, &t.tm_min) == 4) { 99 *tm_time, sscanf(t_string, "%d.%d.%d-%d:%d:%d", &t.tm_year,
101 100 &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min,
102 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */ 101 &t.tm_sec) == 6) {
103
104 } else if (t=*tm_time,sscanf(t_string, "%d.%d.%d-%d:%d:%d",
105 &t.tm_year,
106 &t.tm_mon,
107 &t.tm_mday,
108 &t.tm_hour,
109 &t.tm_min, &t.tm_sec) == 6) {
110
111 t.tm_year -= 1900; /* Adjust years */ 102 t.tm_year -= 1900; /* Adjust years */
112 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */ 103 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
113 104 } else if (t =
114 } else if (t=*tm_time,sscanf(t_string, "%d.%d.%d-%d:%d", 105 *tm_time, sscanf(t_string, "%d.%d.%d-%d:%d", &t.tm_year,
115 &t.tm_year, 106 &t.tm_mon, &t.tm_mday, &t.tm_hour,
116 &t.tm_mon, 107 &t.tm_min) == 5) {
117 &t.tm_mday,
118 &t.tm_hour, &t.tm_min) == 5) {
119 t.tm_year -= 1900; /* Adjust years */ 108 t.tm_year -= 1900; /* Adjust years */
120 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */ 109 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
121
122 } else { 110 } else {
123 error_msg_and_die(invalid_date, t_string); 111 error_msg_and_die(invalid_date, t_string);
124 } 112 }
125 *tm_time = t; 113 *tm_time = t;
126 return (tm_time); 114 return (tm_time);
@@ -142,70 +130,71 @@ int date_main(int argc, char **argv)
142 130
143#ifdef CONFIG_FEATURE_DATE_ISOFMT 131#ifdef CONFIG_FEATURE_DATE_ISOFMT
144 int ifmt = 0; 132 int ifmt = 0;
145#define GETOPT_ISOFMT "I::" 133
134# define GETOPT_ISOFMT "I::"
146#else 135#else
147#define GETOPT_ISOFMT 136# define GETOPT_ISOFMT
148#endif 137#endif
149 138
150 /* Interpret command line args */ 139 /* Interpret command line args */
151 while ((c = getopt(argc, argv, "Rs:ud:" GETOPT_ISOFMT )) != EOF) { 140 while ((c = getopt(argc, argv, "Rs:ud:" GETOPT_ISOFMT)) != EOF) {
152 switch (c) { 141 switch (c) {
153 case 'R': 142 case 'R':
154 rfc822 = 1; 143 rfc822 = 1;
155 break; 144 break;
156 case 's': 145 case 's':
157 set_time = 1; 146 set_time = 1;
158 if ((date_str != NULL) || ((date_str = optarg) == NULL)) { 147 if ((date_str != NULL) || ((date_str = optarg) == NULL)) {
159 show_usage(); 148 show_usage();
160 } 149 }
161 break; 150 break;
162 case 'u': 151 case 'u':
163 utc = 1; 152 utc = 1;
164 if (putenv("TZ=UTC0") != 0) 153 if (putenv("TZ=UTC0") != 0)
165 error_msg_and_die(memory_exhausted); 154 error_msg_and_die(memory_exhausted);
166 break; 155 break;
167 case 'd': 156 case 'd':
168 use_arg = 1; 157 use_arg = 1;
169 if ((date_str != NULL) || ((date_str = optarg) == NULL)) 158 if ((date_str != NULL) || ((date_str = optarg) == NULL))
170 show_usage(); 159 show_usage();
171 break; 160 break;
172#ifdef CONFIG_FEATURE_DATE_ISOFMT 161#ifdef CONFIG_FEATURE_DATE_ISOFMT
173 case 'I': 162 case 'I':
174 if ( !optarg ) 163 if (!optarg)
164 ifmt = 1;
165 else {
166 int ifmt_len = xstrlen(optarg);
167
168 if ((ifmt_len <= 4)
169 && (strncmp(optarg, "date", ifmt_len) == 0)) {
175 ifmt = 1; 170 ifmt = 1;
176 else { 171 } else if ((ifmt_len <= 5)
177 int ifmt_len = xstrlen ( optarg ); 172 && (strncmp(optarg, "hours", ifmt_len) == 0)) {
178 173 ifmt = 2;
179 if (( ifmt_len <= 4 ) && ( strncmp ( optarg, "date", ifmt_len ) == 0 )) 174 } else if ((ifmt_len <= 7)
180 ifmt = 1; 175 && (strncmp(optarg, "minutes", ifmt_len) == 0)) {
181 else if (( ifmt_len <= 5 ) && ( strncmp ( optarg, "hours", ifmt_len ) == 0 )) 176 ifmt = 3;
182 ifmt = 2; 177 } else if ((ifmt_len <= 7)
183 else if (( ifmt_len <= 7 ) && ( strncmp ( optarg, "minutes", ifmt_len ) == 0 )) 178 && (strncmp(optarg, "seconds", ifmt_len) == 0)) {
184 ifmt = 3; 179 ifmt = 4;
185 else if (( ifmt_len <= 7 ) && ( strncmp ( optarg, "seconds", ifmt_len ) == 0 )) 180 }
186 ifmt = 4; 181 }
187 } 182 if (ifmt) {
188 if ( ifmt ) 183 break; /* else show_usage(); */
189 break; // else show_usage(); 184 }
190#endif 185#endif
191 default: 186 default:
192 show_usage(); 187 show_usage();
193 } 188 }
194 } 189 }
195 190
196 191
197 if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) 192 if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) {
198 date_fmt = &argv[optind][1]; /* Skip over the '+' */ 193 date_fmt = &argv[optind][1]; /* Skip over the '+' */
199 else if (date_str == NULL) { 194 } else if (date_str == NULL) {
200 set_time = 1; 195 set_time = 1;
201 date_str = argv[optind]; 196 date_str = argv[optind];
202 }
203#if 0
204 else {
205 error_msg("date_str='%s' date_fmt='%s'\n", date_str, date_fmt);
206 show_usage();
207 } 197 }
208#endif
209 198
210 /* Now we have parsed all the information except the date format 199 /* Now we have parsed all the information except the date format
211 which depends on whether the clock is being set or read */ 200 which depends on whether the clock is being set or read */
@@ -230,18 +219,16 @@ int date_main(int argc, char **argv)
230 219
231 /* Correct any day of week and day of year etc. fields */ 220 /* Correct any day of week and day of year etc. fields */
232 tm = mktime(&tm_time); 221 tm = mktime(&tm_time);
233 if (tm < 0) 222 if (tm < 0) {
234 error_msg_and_die(invalid_date, date_str); 223 error_msg_and_die(invalid_date, date_str);
235 if ( utc ) { 224 }
236 if (putenv("TZ=UTC0") != 0) 225 if (utc && (putenv("TZ=UTC0") != 0)) {
237 error_msg_and_die(memory_exhausted); 226 error_msg_and_die(memory_exhausted);
238 } 227 }
239 228
240 /* if setting time, set it */ 229 /* if setting time, set it */
241 if (set_time) { 230 if (set_time && (stime(&tm) < 0)) {
242 if (stime(&tm) < 0) { 231 perror_msg("cannot set date");
243 perror_msg("cannot set date");
244 }
245 } 232 }
246 } 233 }
247 234
@@ -250,30 +237,29 @@ int date_main(int argc, char **argv)
250 /* Deal with format string */ 237 /* Deal with format string */
251 if (date_fmt == NULL) { 238 if (date_fmt == NULL) {
252#ifdef CONFIG_FEATURE_DATE_ISOFMT 239#ifdef CONFIG_FEATURE_DATE_ISOFMT
253 switch ( ifmt ) { 240 switch (ifmt) {
254 case 4: 241 case 4:
255 date_fmt = utc ? "%Y-%m-%dT%H:%M:%SZ" : "%Y-%m-%dT%H:%M:%S%z"; 242 date_fmt = utc ? "%Y-%m-%dT%H:%M:%SZ" : "%Y-%m-%dT%H:%M:%S%z";
256 break; 243 break;
257 case 3: 244 case 3:
258 date_fmt = utc ? "%Y-%m-%dT%H:%MZ" : "%Y-%m-%dT%H:%M%z"; 245 date_fmt = utc ? "%Y-%m-%dT%H:%MZ" : "%Y-%m-%dT%H:%M%z";
259 break; 246 break;
260 case 2: 247 case 2:
261 date_fmt = utc ? "%Y-%m-%dT%HZ" : "%Y-%m-%dT%H%z"; 248 date_fmt = utc ? "%Y-%m-%dT%HZ" : "%Y-%m-%dT%H%z";
262 break; 249 break;
263 case 1: 250 case 1:
264 date_fmt = "%Y-%m-%d"; 251 date_fmt = "%Y-%m-%d";
265 break; 252 break;
266 case 0: 253 case 0:
267 default: 254 default:
268#endif 255#endif
269 date_fmt = (rfc822 256 date_fmt =
270 ? (utc 257 (rfc822
271 ? "%a, %e %b %Y %H:%M:%S GMT" 258 ? (utc ? "%a, %e %b %Y %H:%M:%S GMT" :
272 : "%a, %e %b %Y %H:%M:%S %z") 259 "%a, %e %b %Y %H:%M:%S %z") : "%a %b %e %H:%M:%S %Z %Y");
273 : "%a %b %e %H:%M:%S %Z %Y"); 260
274
275#ifdef CONFIG_FEATURE_DATE_ISOFMT 261#ifdef CONFIG_FEATURE_DATE_ISOFMT
276 break; 262 break;
277 } 263 }
278#endif 264#endif
279 } else if (*date_fmt == '\0') { 265 } else if (*date_fmt == '\0') {