caltime_scan.c (1078B)
1 #include <tai/caltime.h> 2 3 unsigned int caltime_scan(char *s, struct caltime *ct) 4 { 5 char *t = s; 6 unsigned long z; 7 unsigned long c; 8 int sign; 9 10 t += caldate_scan(t,&ct->date); 11 12 while ((*t == ' ') || (*t == '\t') || (*t == 'T')) ++t; 13 z = 0; while ((c = (unsigned char) (*t - '0')) <= 9) { z = z * 10 + c; ++t; } 14 ct->hour = z; 15 16 if (*t++ != ':') return 0; 17 z = 0; while ((c = (unsigned char) (*t - '0')) <= 9) { z = z * 10 + c; ++t; } 18 ct->minute = z; 19 20 if (*t != ':') 21 ct->second = 0; 22 else { 23 ++t; 24 z = 0; while ((c = (unsigned char) (*t - '0')) <= 9) { z = z * 10 + c; ++t; } 25 ct->second = z; 26 } 27 28 while ((*t == ' ') || (*t == '\t')) ++t; 29 if (*t == '+') sign = 1; else if (*t == '-') sign = -1; else return 0; 30 ++t; 31 c = (unsigned char) (*t++ - '0'); if (c > 9) return 0; z = c; 32 c = (unsigned char) (*t++ - '0'); if (c > 9) return 0; z = z * 10 + c; 33 c = (unsigned char) (*t++ - '0'); if (c > 9) return 0; z = z * 6 + c; 34 c = (unsigned char) (*t++ - '0'); if (c > 9) return 0; z = z * 10 + c; 35 ct->offset = z * sign; 36 37 return t - s; 38 }