psdate.c (50479) | psdate.c (61957) |
---|---|
1/*- 2 * Copyright (C) 1996 3 * David L. Nugent. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#ifndef lint 28static const char rcsid[] = | 1/*- 2 * Copyright (C) 1996 3 * David L. Nugent. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#ifndef lint 28static const char rcsid[] = |
29 "$FreeBSD: head/usr.sbin/pw/psdate.c 50479 1999-08-28 01:35:59Z peter $"; | 29 "$FreeBSD: head/usr.sbin/pw/psdate.c 61957 2000-06-22 16:48:41Z ache $"; |
30#endif /* not lint */ 31 32#include <stdio.h> 33#include <stdlib.h> 34#include <string.h> 35#include <ctype.h> 36 37#include "psdate.h" 38 39 40static int 41a2i(char const ** str) 42{ 43 int i = 0; 44 char const *s = *str; 45 | 30#endif /* not lint */ 31 32#include <stdio.h> 33#include <stdlib.h> 34#include <string.h> 35#include <ctype.h> 36 37#include "psdate.h" 38 39 40static int 41a2i(char const ** str) 42{ 43 int i = 0; 44 char const *s = *str; 45 |
46 if (isdigit(*s)) { | 46 if (isdigit((unsigned char)*s)) { |
47 i = atoi(s); | 47 i = atoi(s); |
48 while (isdigit(*s)) | 48 while (isdigit((unsigned char)*s)) |
49 ++s; 50 *str = s; 51 } 52 return i; 53} 54 55static int 56numerics(char const * str) 57{ | 49 ++s; 50 *str = s; 51 } 52 return i; 53} 54 55static int 56numerics(char const * str) 57{ |
58 int rc = isdigit(*str); | 58 int rc = isdigit((unsigned char)*str); |
59 60 if (rc) | 59 60 if (rc) |
61 while (isdigit(*str) || *str == 'x') | 61 while (isdigit((unsigned char)*str) || *str == 'x') |
62 ++str; 63 return rc && !*str; 64} 65 66static int 67aindex(char const * arr[], char const ** str, int len) 68{ 69 int l, i; 70 char mystr[32]; 71 72 mystr[len] = '\0'; 73 l = strlen(strncpy(mystr, *str, len)); 74 for (i = 0; i < l; i++) | 62 ++str; 63 return rc && !*str; 64} 65 66static int 67aindex(char const * arr[], char const ** str, int len) 68{ 69 int l, i; 70 char mystr[32]; 71 72 mystr[len] = '\0'; 73 l = strlen(strncpy(mystr, *str, len)); 74 for (i = 0; i < l; i++) |
75 mystr[i] = (char) tolower(mystr[i]); | 75 mystr[i] = (char) tolower((unsigned char)mystr[i]); |
76 for (i = 0; arr[i] && strcmp(mystr, arr[i]) != 0; i++); 77 if (arr[i] == NULL) 78 i = -1; 79 else { /* Skip past it */ | 76 for (i = 0; arr[i] && strcmp(mystr, arr[i]) != 0; i++); 77 if (arr[i] == NULL) 78 i = -1; 79 else { /* Skip past it */ |
80 while (**str && isalpha(**str)) | 80 while (**str && isalpha((unsigned char)**str)) |
81 ++(*str); 82 /* And any following whitespace */ | 81 ++(*str); 82 /* And any following whitespace */ |
83 while (**str && (**str == ',' || isspace(**str))) | 83 while (**str && (**str == ',' || isspace((unsigned char)**str))) |
84 ++(*str); 85 } /* Return index */ 86 return i; 87} 88 89static int 90weekday(char const ** str) 91{ --- 46 unchanged lines hidden (view full) --- 138 *mon = i; 139 else if ((i = a2i(&str)) != 0) 140 *mon = i - 1; 141 } else 142 return; 143 144 while (*str && strchr(nchrs + 10, *str) != NULL) 145 ++str; | 84 ++(*str); 85 } /* Return index */ 86 return i; 87} 88 89static int 90weekday(char const ** str) 91{ --- 46 unchanged lines hidden (view full) --- 138 *mon = i; 139 else if ((i = a2i(&str)) != 0) 140 *mon = i - 1; 141 } else 142 return; 143 144 while (*str && strchr(nchrs + 10, *str) != NULL) 145 ++str; |
146 if (isdigit(*str)) { | 146 if (isdigit((unsigned char)*str)) { |
147 *year = atoi(str); 148 if (*year > 1900) 149 *year -= 1900; 150 else if (*year < 32) 151 *year += 100; 152 } 153} 154 --- 16 unchanged lines hidden (view full) --- 171 char *p; 172 int i; 173 long val; 174 struct tm *T; 175 176 if (dt == 0) 177 dt = time(NULL); 178 | 147 *year = atoi(str); 148 if (*year > 1900) 149 *year -= 1900; 150 else if (*year < 32) 151 *year += 100; 152 } 153} 154 --- 16 unchanged lines hidden (view full) --- 171 char *p; 172 int i; 173 long val; 174 struct tm *T; 175 176 if (dt == 0) 177 dt = time(NULL); 178 |
179 while (*str && isspace(*str)) | 179 while (*str && isspace((unsigned char)*str)) |
180 ++str; 181 182 if (numerics(str)) { 183 dt = strtol(str, &p, 0); 184 } else if (*str == '+' || *str == '-') { 185 val = strtol(str, &p, 0); 186 switch (*p) { 187 case 'h': --- 54 unchanged lines hidden (view full) --- 242 * See if we can break off any timezone 243 */ 244 while ((q = strrchr(tmp, ' ')) != NULL) { 245 if (strchr("(+-", q[1]) != NULL) 246 *q = '\0'; 247 else { 248 int j = 1; 249 | 180 ++str; 181 182 if (numerics(str)) { 183 dt = strtol(str, &p, 0); 184 } else if (*str == '+' || *str == '-') { 185 val = strtol(str, &p, 0); 186 switch (*p) { 187 case 'h': --- 54 unchanged lines hidden (view full) --- 242 * See if we can break off any timezone 243 */ 244 while ((q = strrchr(tmp, ' ')) != NULL) { 245 if (strchr("(+-", q[1]) != NULL) 246 *q = '\0'; 247 else { 248 int j = 1; 249 |
250 while (q[j] && isupper(q[j])) | 250 while (q[j] && isupper((unsigned char)q[j])) |
251 ++j; 252 if (q[j] == '\0') 253 *q = '\0'; 254 else 255 break; 256 } 257 } 258 --- 41 unchanged lines hidden --- | 251 ++j; 252 if (q[j] == '\0') 253 *q = '\0'; 254 else 255 break; 256 } 257 } 258 --- 41 unchanged lines hidden --- |