📄 cmpt.c
字号:
/* Replacements for routines missing on some systems. Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.This file is part of GNU Wget.GNU Wget is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 3 of the License, or(at your option) any later version.GNU Wget is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with Wget. If not, see <http://www.gnu.org/licenses/>.Additional permission under GNU GPL version 3 section 7If you modify this program, or any covered work, by linking orcombining it with the OpenSSL project's OpenSSL library (or amodified version of that library), containing parts covered by theterms of the OpenSSL or SSLeay licenses, the Free Software Foundationgrants you additional permission to convey the resulting work.Corresponding Source for a non-source form of such a combinationshall include the source code for the parts of OpenSSL used as wellas that of the covered work. */#include <config.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#ifdef HAVE_UNISTD_H# include <unistd.h>#endif#include <errno.h>#include "wget.h"/* Some systems lack certain functions normally taken for granted. For example, Windows doesn't have strptime, and some systems don't have a usable fnmatch. This file should contain fallback implementations of such missing functions. It should *not* define new Wget-specific interfaces -- those should be placed in utils.c or elsewhere. *//* strcasecmp and strncasecmp apparently originated with BSD 4.4. SUSv3 seems to be the only standard out there (that I can find) that requires their existence, so in theory there might be systems still in use that lack them. Note that these don't get defined under Windows because mswindows.h defines them to the equivalent Windows functions stricmp and strnicmp. */#ifndef HAVE_STRCASECMP/* From GNU libc. *//* Compare S1 and S2, ignoring case, returning less than, equal to or greater than zero if S1 is lexiographically less than, equal to or greater than S2. */intstrcasecmp (const char *s1, const char *s2){ register const unsigned char *p1 = (const unsigned char *) s1; register const unsigned char *p2 = (const unsigned char *) s2; unsigned char c1, c2; if (p1 == p2) return 0; do { c1 = TOLOWER (*p1++); c2 = TOLOWER (*p2++); if (c1 == '\0') break; } while (c1 == c2); return c1 - c2;}#endif /* not HAVE_STRCASECMP */#ifndef HAVE_STRNCASECMP/* From GNU libc. *//* Compare no more than N characters of S1 and S2, ignoring case, returning less than, equal to or greater than zero if S1 is lexicographically less than, equal to or greater than S2. */intstrncasecmp (const char *s1, const char *s2, size_t n){ register const unsigned char *p1 = (const unsigned char *) s1; register const unsigned char *p2 = (const unsigned char *) s2; unsigned char c1, c2; if (p1 == p2 || n == 0) return 0; do { c1 = TOLOWER (*p1++); c2 = TOLOWER (*p2++); if (c1 == '\0' || c1 != c2) return c1 - c2; } while (--n > 0); return c1 - c2;}#endif /* not HAVE_STRNCASECMP */#ifndef HAVE_MEMRCHR/* memrchr is a GNU extension. It is like the memchr function, except that it searches backwards from the end of the n bytes pointed to by s instead of forwards from the front. */void *memrchr (const void *s, int c, size_t n){ const char *b = s; const char *e = b + n; while (e > b) if (*--e == c) return (void *) e; return NULL;}#endif/* strptime is required by POSIX, but it is missing from Windows, which means we must keep a fallback implementation. It is reportedly missing or broken on many older Unix systems as well, so it's good to have around. */#ifndef HAVE_STRPTIME/* From GNU libc 2.1.3. *//* Ulrich, thanks for helping me out with this! --hniksic *//* strptime - Convert a string representation of time to a time value. Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. *//* XXX This version of the implementation is not really complete. Some of the fields cannot add information alone. But if seeing some of them in the same format (such as year, week and weekday) this is enough information for determining the date. */#ifndef __P# define __P(args) args#endif /* not __P */#if ! HAVE_LOCALTIME_R && ! defined localtime_r# ifdef _LIBC# define localtime_r __localtime_r# else/* Approximate localtime_r as best we can in its absence. */# define localtime_r my_localtime_rstatic struct tm *localtime_r __P ((const time_t *, struct tm *));static struct tm *localtime_r (t, tp) const time_t *t; struct tm *tp;{ struct tm *l = localtime (t); if (! l) return 0; *tp = *l; return tp;}# endif /* ! _LIBC */#endif /* ! HAVE_LOCALTIME_R && ! defined (localtime_r) */#define match_char(ch1, ch2) if (ch1 != ch2) return NULL#if defined __GNUC__ && __GNUC__ >= 2# define match_string(cs1, s2) \ ({ size_t len = strlen (cs1); \ int result = strncasecmp ((cs1), (s2), len) == 0; \ if (result) (s2) += len; \ result; })#else/* Oh come on. Get a reasonable compiler. */# define match_string(cs1, s2) \ (strncasecmp ((cs1), (s2), strlen (cs1)) ? 0 : ((s2) += strlen (cs1), 1))#endif/* We intentionally do not use isdigit() for testing because this will lead to problems with the wide character version. */#define get_number(from, to, n) \ do { \ int __n = n; \ val = 0; \ while (*rp == ' ') \ ++rp; \ if (*rp < '0' || *rp > '9') \ return NULL; \ do { \ val *= 10; \ val += *rp++ - '0'; \ } while (--__n > 0 && val * 10 <= to && *rp >= '0' && *rp <= '9'); \ if (val < from || val > to) \ return NULL; \ } while (0)#ifdef _NL_CURRENT/* Added check for __GNUC__ extensions here for Wget. --abbotti */# if defined __GNUC__ && __GNUC__ >= 2# define get_alt_number(from, to, n) \ ({ \ __label__ do_normal; \ if (*decided != raw) \ { \ const char *alts = _NL_CURRENT (LC_TIME, ALT_DIGITS); \ int __n = n; \ int any = 0; \ while (*rp == ' ') \ ++rp; \ val = 0; \ do { \ val *= 10; \ while (*alts != '\0') \ { \ size_t len = strlen (alts); \ if (strncasecmp (alts, rp, len) == 0) \ break; \ alts += len + 1; \ ++val; \ } \ if (*alts == '\0') \ { \ if (*decided == not && ! any) \ goto do_normal; \ /* If we haven't read anything it's an error. */ \ if (! any) \ return NULL; \ /* Correct the premature multiplication. */ \ val /= 10; \ break; \ } \ else \ *decided = loc; \ } while (--__n > 0 && val * 10 <= to); \ if (val < from || val > to) \ return NULL; \ } \ else \ { \ do_normal: \ get_number (from, to, n); \ } \ 0; \ })# else# define get_alt_number(from, to, n) \ do { if (*decided != raw) \ { \ const char *alts = _NL_CURRENT (LC_TIME, ALT_DIGITS); \ int __n = n; \ int any = 0; \ while (*rp == ' ') \ ++rp; \ val = 0; \ do { \ val *= 10; \ while (*alts != '\0') \ { \ size_t len = strlen (alts); \ if (strncasecmp (alts, rp, len) == 0) \ break; \ alts += len + 1; \ ++val; \ } \ if (*alts == '\0') \ { \ if (*decided == not && ! any) \ goto do_normal; \ /* If we haven't read anything it's an error. */ \ if (! any) \ return NULL; \ /* Correct the premature multiplication. */ \ val /= 10; \ break; \ } \ else \ *decided = loc; \ } while (--__n > 0 && val * 10 <= to); \ if (val < from || val > to) \ return NULL; \ } \ else \ { \ do_normal: \ get_number (from, to, n); \ } \ } while (0)# endif /* defined __GNUC__ && __GNUC__ >= 2 */#else# define get_alt_number(from, to, n) \ /* We don't have the alternate representation. */ \ get_number(from, to, n)#endif#define recursive(new_fmt) \ (*(new_fmt) != '\0' \ && (rp = strptime_internal (rp, (new_fmt), tm, decided)) != NULL)#ifdef _LIBC/* This is defined in locale/C-time.c in the GNU libc. */extern const struct locale_data _nl_C_LC_TIME;extern const unsigned short int __mon_yday[2][13];# define weekday_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (DAY_1)].string)# define ab_weekday_name \ (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABDAY_1)].string)# define month_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (MON_1)].string)# define ab_month_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABMON_1)].string)# define HERE_D_T_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (D_T_FMT)].string)# define HERE_D_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (D_FMT)].string)# define HERE_AM_STR (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (AM_STR)].string)# define HERE_PM_STR (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (PM_STR)].string)# define HERE_T_FMT_AMPM \ (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (T_FMT_AMPM)].string)# define HERE_T_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (T_FMT)].string)# define strncasecmp(s1, s2, n) __strncasecmp (s1, s2, n)#elsestatic char const weekday_name[][10] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };static char const ab_weekday_name[][4] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };static char const month_name[][10] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };static char const ab_month_name[][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };# define HERE_D_T_FMT "%a %b %e %H:%M:%S %Y"# define HERE_D_FMT "%m/%d/%y"# define HERE_AM_STR "AM"# define HERE_PM_STR "PM"# define HERE_T_FMT_AMPM "%I:%M:%S %p"# define HERE_T_FMT "%H:%M:%S"const unsigned short int __mon_yday[2][13];# ifndef NEED_MON_YDAY# define NEED_MON_YDAY
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -