📄 cmpt.c
字号:
if (*decided != raw) { const char *fmt = _NL_CURRENT (LC_TIME, ERA_D_T_FMT); if (*fmt == '\0') fmt = _NL_CURRENT (LC_TIME, D_T_FMT); if (!recursive (fmt)) { if (*decided == loc) return NULL; else rp = rp_backup; } else { if (strcmp (fmt, HERE_D_T_FMT)) *decided = loc; want_xday = 1; break; } *decided = raw; } /* The C locale has no era information, so use the normal representation. */ if (!recursive (HERE_D_T_FMT)) return NULL; want_xday = 1; break; case 'C': case 'y': case 'Y': /* Match name of base year in locale's alternate representation. */ /* XXX This is currently not implemented. It should use the value _NL_CURRENT (LC_TIME, ERA). */ break; case 'x': if (*decided != raw) { const char *fmt = _NL_CURRENT (LC_TIME, ERA_D_FMT); if (*fmt == '\0') fmt = _NL_CURRENT (LC_TIME, D_FMT); if (!recursive (fmt)) { if (*decided == loc) return NULL; else rp = rp_backup; } else { if (strcmp (fmt, HERE_D_FMT)) *decided = loc; break; } *decided = raw; } if (!recursive (HERE_D_FMT)) return NULL; break; case 'X': if (*decided != raw) { const char *fmt = _NL_CURRENT (LC_TIME, ERA_T_FMT); if (*fmt == '\0') fmt = _NL_CURRENT (LC_TIME, T_FMT); if (!recursive (fmt)) { if (*decided == loc) return NULL; else rp = rp_backup; } else { if (strcmp (fmt, HERE_T_FMT)) *decided = loc; break; } *decided = raw; } if (!recursive (HERE_T_FMT)) return NULL; break; default: return NULL; } break;#else /* We have no information about the era format. Just use the normal format. */ if (*fmt != 'c' && *fmt != 'C' && *fmt != 'y' && *fmt != 'Y' && *fmt != 'x' && *fmt != 'X') /* This is an illegal format. */ return NULL; goto start_over;#endif case 'O': switch (*fmt++) { case 'd': case 'e': /* Match day of month using alternate numeric symbols. */ get_alt_number (1, 31, 2); tm->tm_mday = val; have_mday = 1; want_xday = 1; break; case 'H': /* Match hour in 24-hour clock using alternate numeric symbols. */ get_alt_number (0, 23, 2); tm->tm_hour = val; have_I = 0; break; case 'I': /* Match hour in 12-hour clock using alternate numeric symbols. */ get_alt_number (1, 12, 2); tm->tm_hour = val - 1; have_I = 1; break; case 'm': /* Match month using alternate numeric symbols. */ get_alt_number (1, 12, 2); tm->tm_mon = val - 1; have_mon = 1; want_xday = 1; break; case 'M': /* Match minutes using alternate numeric symbols. */ get_alt_number (0, 59, 2); tm->tm_min = val; break; case 'S': /* Match seconds using alternate numeric symbols. */ get_alt_number (0, 61, 2); tm->tm_sec = val; break; case 'U': case 'V': case 'W': get_alt_number (0, 53, 2); /* XXX This cannot determine any field in TM without further information. */ break; case 'w': /* Match number of weekday using alternate numeric symbols. */ get_alt_number (0, 6, 1); tm->tm_wday = val; have_wday = 1; break; case 'y': /* Match year within century using alternate numeric symbols. */ get_alt_number (0, 99, 2); tm->tm_year = val >= 69 ? val : val + 100; want_xday = 1; break; default: return NULL; } break; default: return NULL; } } if (have_I && is_pm) tm->tm_hour += 12; if (century != -1) { if (want_century) tm->tm_year = tm->tm_year % 100 + (century - 19) * 100; else /* Only the century, but not the year. Strange, but so be it. */ tm->tm_year = (century - 19) * 100; } if (want_xday && !have_wday) { if ( !(have_mon && have_mday) && have_yday) { /* we don't have tm_mon and/or tm_mday, compute them */ int t_mon = 0; while (__mon_yday[__isleap(1900 + tm->tm_year)][t_mon] <= tm->tm_yday) t_mon++; if (!have_mon) tm->tm_mon = t_mon - 1; if (!have_mday) tm->tm_mday = tm->tm_yday - __mon_yday[__isleap(1900 + tm->tm_year)][t_mon - 1] + 1; } day_of_the_week (tm); } if (want_xday && !have_yday) day_of_the_year (tm); return (char *) rp;}char *strptime (buf, format, tm) const char *buf; const char *format; struct tm *tm;{ enum locale_status decided;#ifdef _NL_CURRENT decided = not;#else decided = raw;#endif return strptime_internal (buf, format, tm, &decided);}#endif /* not HAVE_STRPTIME */#ifdef NEED_MON_YDAY/* __mon_yday[][] is common to mktime and strptime implementations. --abbotti */const unsigned short int __mon_yday[2][13] = { /* Normal years. */ { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, /* Leap years. */ { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } };#endif#ifndef HAVE_MEMMOVEvoid *memmove (char *dest, const char *source, unsigned length){ char *d0 = dest; if (source < dest) /* Moving from low mem to hi mem; start at end. */ for (source += length, dest += length; length; --length) *--dest = *--source; else if (source != dest) { /* Moving from hi mem to low mem; start at beginning. */ for (; length; --length) *dest++ = *source++; } return (void *) d0;}#endif /* not HAVE_MEMMOVE *//* fnmatch is a POSIX function, but we include an implementation for the sake of systems that don't have it. Furthermore, according to anecdotal evidence, historical implementations of fnmatch are buggy and unreliable. So we use our version, except when compiling under systems where fnmatch is known to work (currently glibc.) */#ifndef SYSTEM_FNMATCH#define __FNM_FLAGS (FNM_PATHNAME | FNM_NOESCAPE | FNM_PERIOD)/* Match STRING against the filename pattern PATTERN, returning zero if it matches, FNM_NOMATCH if not. This implementation comes from an earlier version of GNU Bash. (It doesn't make sense to update it with a newer version because it adds a lot of features Wget doesn't use or care about.) */intfnmatch (const char *pattern, const char *string, int flags){ register const char *p = pattern, *n = string; register char c; if ((flags & ~__FNM_FLAGS) != 0) { errno = EINVAL; return (-1); } while ((c = *p++) != '\0') { switch (c) { case '?': if (*n == '\0') return (FNM_NOMATCH); else if ((flags & FNM_PATHNAME) && *n == '/') return (FNM_NOMATCH); else if ((flags & FNM_PERIOD) && *n == '.' && (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/'))) return (FNM_NOMATCH); break; case '\\': if (!(flags & FNM_NOESCAPE)) c = *p++; if (*n != c) return (FNM_NOMATCH); break; case '*': if ((flags & FNM_PERIOD) && *n == '.' && (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/'))) return (FNM_NOMATCH); for (c = *p++; c == '?' || c == '*'; c = *p++, ++n) if (((flags & FNM_PATHNAME) && *n == '/') || (c == '?' && *n == '\0')) return (FNM_NOMATCH); if (c == '\0') return (0); { char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c; for (--p; *n != '\0'; ++n) if ((c == '[' || *n == c1) && fnmatch (p, n, flags & ~FNM_PERIOD) == 0) return (0); return (FNM_NOMATCH); } case '[': { /* Nonzero if the sense of the character class is inverted. */ register int not; if (*n == '\0') return (FNM_NOMATCH); if ((flags & FNM_PERIOD) && *n == '.' && (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/'))) return (FNM_NOMATCH); /* Make sure there is a closing `]'. If there isn't, the `[' is just a character to be matched. */ { register const char *np; for (np = p; np && *np && *np != ']'; np++); if (np && !*np) { if (*n != '[') return (FNM_NOMATCH); goto next_char; } } not = (*p == '!' || *p == '^'); if (not) ++p; c = *p++; while (1) { register char cstart = c, cend = c; if (!(flags & FNM_NOESCAPE) && c == '\\') cstart = cend = *p++; if (c == '\0') /* [ (unterminated) loses. */ return (FNM_NOMATCH); c = *p++; if ((flags & FNM_PATHNAME) && c == '/') /* [/] can never match. */ return (FNM_NOMATCH); if (c == '-' && *p != ']') { cend = *p++; if (!(flags & FNM_NOESCAPE) && cend == '\\') cend = *p++; if (cend == '\0') return (FNM_NOMATCH); c = *p++; } if (*n >= cstart && *n <= cend) goto matched; if (c == ']') break; } if (!not) return (FNM_NOMATCH); next_char: break; matched: /* Skip the rest of the [...] that already matched. */ while (c != ']') { if (c == '\0') /* [... (unterminated) loses. */ return (FNM_NOMATCH); c = *p++; if (!(flags & FNM_NOESCAPE) && c == '\\') /* 1003.2d11 is unclear if this is right. %%% */ ++p; } if (not) return (FNM_NOMATCH); } break; default: if (c != *n) return (FNM_NOMATCH); } ++n; } if (*n == '\0') return (0); return (FNM_NOMATCH);}#endif /* not SYSTEM_FNMATCH */#ifndef HAVE_TIMEGM/* timegm is a GNU extension, but lately also available on *BSD systems and possibly elsewhere. *//* True if YEAR is a leap year. */#define ISLEAP(year) \ ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))/* Number of leap years in the range [y1, y2). */#define LEAPYEARS(y1, y2) \ ((y2-1)/4 - (y1-1)/4) - ((y2-1)/100 - (y1-1)/100) + ((y2-1)/400 - (y1-1)/400)/* Inverse of gmtime: converts struct tm to time_t, assuming the data in tm is UTC rather than local timezone. This implementation returns the number of seconds elapsed since midnight 1970-01-01, converted to time_t. */time_ttimegm (struct tm *t){ static const unsigned short int month_to_days[][13] = { { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }, /* normal */ { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 } /* leap */ }; const int year = 1900 + t->tm_year; unsigned long secs; /* until 2106-02-07 for 32-bit unsigned long */ int days; if (year < 1970) return (time_t) -1; days = 365 * (year - 1970); /* Take into account leap years between 1970 and YEAR, not counting YEAR itself. */ days += LEAPYEARS (1970, year); if (t->tm_mon < 0 || t->tm_mon >= 12) return (time_t) -1; days += month_to_days[ISLEAP (year)][t->tm_mon]; days += t->tm_mday - 1; secs = days * 86400 + t->tm_hour * 3600 + t->tm_min * 60 + t->tm_sec; return (time_t) secs;}#endif /* HAVE_TIMEGM */#ifdef NEED_STRTOLL/* strtoll is required by C99 and used by Wget only on systems with LFS. Unfortunately, some systems have LFS, but no strtoll or equivalent. These include HPUX 11.0 and Windows. We use #ifdef NEED_STRTOLL instead of #ifndef HAVE_STRTOLL because of the systems which have a suitable replacement (e.g. _strtoi64 on Windows), on which Wget's str_to_wgint is instructed to use that instead. */static inline intchar_value (char c, int base){ int value; if (c < '0') return -1; if ('0' <= c && c <= '9') value = c - '0'; else if ('a' <= c && c <= 'z') value = c - 'a' + 10; else if ('A' <= c && c <= 'Z') value = c - 'A' + 10; else return -1; if (value >= base) return -1; return value;}#define LL strtoll_return /* long long or __int64 *//* These constants assume 64-bit strtoll_return. *//* A roundabout way of writing 2**63-1 = 9223372036854775807 */#define STRTOLL_OVERFLOW (((LL) 1 << 62) - 1 + ((LL) 1 << 62))/* A roundabout way of writing -2**63 = -9223372036854775808 */#define STRTOLL_UNDERFLOW (-STRTOLL_OVERFLOW - 1)/* A strtoll replacement for systems that have LFS but don't supply strtoll. The headers typedef strtoll_return to long long or to __int64. */strtoll_returnstrtoll (const char *nptr, char **endptr, int base){ strtoll_return result = 0; int negative; if (base != 0 && (base < 2 || base > 36)) { errno = EINVAL; return 0; } while (*nptr == ' ' || *nptr == '\t') ++nptr; if (*nptr == '-') { negative = 1; ++nptr; } else if (*nptr == '+') { negative = 0; ++nptr; } else negative = 0; /* If base is 0, determine the real base based on the beginning on the number; octal numbers begin with "0", hexadecimal with "0x", and the others are considered octal. */ if (*nptr == '0') { if ((base == 0 || base == 16) && (*(nptr + 1) == 'x' || *(nptr + 1) == 'X')) { base = 16; nptr += 2; } else if (base == 0) base = 8; } else if (base == 0) base = 10; if (!negative) { /* Parse positive number, checking for overflow. */ int val; for (; (val = char_value (*nptr, base)) != -1; ++nptr) { strtoll_return newresult = base * result + val; if (newresult < result) { result = STRTOLL_OVERFLOW; errno = ERANGE; break; } result = newresult; } } else { /* Parse negative number, checking for underflow. */ int val; for (; (val = char_value (*nptr, base)) != -1; ++nptr) { strtoll_return newresult = base * result - val; if (newresult > result) { result = STRTOLL_UNDERFLOW; errno = ERANGE; break; } result = newresult; } } if (endptr) *endptr = (char *) nptr; return result;}#endif /* NEED_STRTOLL */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -