cleared out errant tabs

This commit is contained in:
Jean-Francois Dockes
2020-05-30 15:54:49 +02:00
parent 796db76fc6
commit 560041cab9
167 changed files with 18868 additions and 18868 deletions
+116 -116
View File
@@ -59,122 +59,122 @@ int fnmatch (const char *pattern, const char *string, int flags)
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;
not = (*p == '!' || *p == '^');
if (not)
++p;
c = *p++;
for (;;)
{
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;
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 (FOLD_FN_CHAR (c) != FOLD_FN_CHAR (*n))
return FNM_NOMATCH;
}
{
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;
not = (*p == '!' || *p == '^');
if (not)
++p;
c = *p++;
for (;;)
{
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;
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 (FOLD_FN_CHAR (c) != FOLD_FN_CHAR (*n))
return FNM_NOMATCH;
}
++n;
}
+8 -8
View File
@@ -11,23 +11,23 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details. */
#ifndef _FNMATCH_H
#ifndef _FNMATCH_H
#define _FNMATCH_H 1
#define _FNMATCH_H 1
/* Bits set in the FLAGS argument to `fnmatch'. */
#undef FNM_PATHNAME
#define FNM_PATHNAME (1 << 0)/* No wildcard can ever match `/'. */
#define FNM_PATHNAME (1 << 0)/* No wildcard can ever match `/'. */
#undef FNM_NOESCAPE
#define FNM_NOESCAPE (1 << 1)/* Backslashes don't quote special chars. */
#define FNM_NOESCAPE (1 << 1)/* Backslashes don't quote special chars. */
#undef FNM_PERIOD
#define FNM_PERIOD (1 << 2)/* Leading `.' is matched only explicitly. */
#define FNM_PERIOD (1 << 2)/* Leading `.' is matched only explicitly. */
#undef __FNM_FLAGS
#define __FNM_FLAGS (FNM_PATHNAME|FNM_NOESCAPE|FNM_PERIOD)
#define __FNM_FLAGS (FNM_PATHNAME|FNM_NOESCAPE|FNM_PERIOD)
/* Value returned by `fnmatch' if STRING does not match PATTERN. */
#undef FNM_NOMATCH
#define FNM_NOMATCH 1
#define FNM_NOMATCH 1
/* Match STRING against the filename pattern PATTERN,
returning zero if it matches, FNM_NOMATCH if not. */
@@ -40,5 +40,5 @@ extern int fnmatch (const char *pattern, const char *str, int flags);
#endif
#endif /* fnmatch.h */
#endif /* fnmatch.h */
+11 -11
View File
@@ -51,17 +51,17 @@ int main(int argc, char *argv[])
argc--; argv++;
int imode = 0;
while (argc > 0 && **argv == '-') {
(*argv)++;
if (!(**argv))
Usage();
while (**argv)
switch (*(*argv)++) {
case 'm': op_flags |= OPT_m; if (argc < 2) Usage();
if ((sscanf(*(++argv), "%d", &imode)) != 1)
Usage();
argc--; goto b1;
default: Usage(); break;
}
(*argv)++;
if (!(**argv))
Usage();
while (**argv)
switch (*(*argv)++) {
case 'm': op_flags |= OPT_m; if (argc < 2) Usage();
if ((sscanf(*(++argv), "%d", &imode)) != 1)
Usage();
argc--; goto b1;
default: Usage(); break;
}
b1: argc--; argv++;
}
+237 -237
View File
@@ -10,244 +10,244 @@ const char * strp_monthnames[] =
{ "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" };
bool strp_atoi(const char * & s, int & result, int low, int high, int offset)
{
bool worked = false;
char * end;
unsigned long num = strtoul(s, &end, 10);
if (num >= (unsigned long)low && num <= (unsigned long)high)
{
result = (int)(num + offset);
s = end;
worked = true;
}
return worked;
bool worked = false;
char * end;
unsigned long num = strtoul(s, &end, 10);
if (num >= (unsigned long)low && num <= (unsigned long)high)
{
result = (int)(num + offset);
s = end;
worked = true;
}
return worked;
}
char * strptime(const char *s, const char *format, struct tm *tm)
{
bool working = true;
while (working && *format && *s)
{
switch (*format)
{
case '%':
{
++format;
switch (*format)
{
case 'a':
case 'A': // weekday name
tm->tm_wday = -1;
working = false;
for (int i = 0; i < 7; ++i)
{
size_t len = strlen(strp_weekdays[i]);
if (!strnicmp(strp_weekdays[i], s, len))
{
tm->tm_wday = i;
s += len;
working = true;
break;
}
else if (!strnicmp(strp_weekdays[i], s, 3))
{
tm->tm_wday = i;
s += 3;
working = true;
break;
}
}
break;
case 'b':
case 'B':
case 'h': // month name
tm->tm_mon = -1;
working = false;
for (int i = 0; i < 12; ++i)
{
size_t len = strlen(strp_monthnames[i]);
if (!strnicmp(strp_monthnames[i], s, len))
{
tm->tm_mon = i;
s += len;
working = true;
break;
}
else if (!strnicmp(strp_monthnames[i], s, 3))
{
tm->tm_mon = i;
s += 3;
working = true;
break;
}
}
break;
case 'd':
case 'e': // day of month number
working = strp_atoi(s, tm->tm_mday, 1, 31, 0);
break;
case 'D': // %m/%d/%y
{
const char * s_save = s;
working = strp_atoi(s, tm->tm_mon, 1, 12, -1);
if (working && *s == '/')
{
++s;
working = strp_atoi(s, tm->tm_mday, 1, 31, 0);
if (working && *s == '/')
{
++s;
working = strp_atoi(s, tm->tm_year, 0, 99, 0);
if (working && tm->tm_year < 69)
tm->tm_year += 100;
}
}
if (!working)
s = s_save;
}
break;
case 'H': // hour
working = strp_atoi(s, tm->tm_hour, 0, 23, 0);
break;
case 'I': // hour 12-hour clock
working = strp_atoi(s, tm->tm_hour, 1, 12, 0);
break;
case 'j': // day number of year
working = strp_atoi(s, tm->tm_yday, 1, 366, -1);
break;
case 'm': // month number
working = strp_atoi(s, tm->tm_mon, 1, 12, -1);
break;
case 'M': // minute
working = strp_atoi(s, tm->tm_min, 0, 59, 0);
break;
case 'n': // arbitrary whitespace
case 't':
while (isspace((int)*s))
++s;
break;
case 'p': // am / pm
if (!strnicmp(s, "am", 2))
{ // the hour will be 1 -> 12 maps to 12 am, 1 am .. 11 am, 12 noon 12 pm .. 11 pm
if (tm->tm_hour == 12) // 12 am == 00 hours
tm->tm_hour = 0;
}
else if (!strnicmp(s, "pm", 2))
{
if (tm->tm_hour < 12) // 12 pm == 12 hours
tm->tm_hour += 12; // 1 pm -> 13 hours, 11 pm -> 23 hours
}
else
working = false;
break;
case 'r': // 12 hour clock %I:%M:%S %p
{
const char * s_save = s;
working = strp_atoi(s, tm->tm_hour, 1, 12, 0);
if (working && *s == ':')
{
++s;
working = strp_atoi(s, tm->tm_min, 0, 59, 0);
if (working && *s == ':')
{
++s;
working = strp_atoi(s, tm->tm_sec, 0, 60, 0);
if (working && isspace((int)*s))
{
++s;
while (isspace((int)*s))
++s;
if (!strnicmp(s, "am", 2))
{ // the hour will be 1 -> 12 maps to 12 am, 1 am .. 11 am, 12 noon 12 pm .. 11 pm
if (tm->tm_hour == 12) // 12 am == 00 hours
tm->tm_hour = 0;
}
else if (!strnicmp(s, "pm", 2))
{
if (tm->tm_hour < 12) // 12 pm == 12 hours
tm->tm_hour += 12; // 1 pm -> 13 hours, 11 pm -> 23 hours
}
else
working = false;
}
}
}
if (!working)
s = s_save;
}
break;
case 'R': // %H:%M
{
const char * s_save = s;
working = strp_atoi(s, tm->tm_hour, 0, 23, 0);
if (working && *s == ':')
{
++s;
working = strp_atoi(s, tm->tm_min, 0, 59, 0);
}
if (!working)
s = s_save;
}
break;
case 'S': // seconds
working = strp_atoi(s, tm->tm_sec, 0, 60, 0);
break;
case 'T': // %H:%M:%S
{
const char * s_save = s;
working = strp_atoi(s, tm->tm_hour, 0, 23, 0);
if (working && *s == ':')
{
++s;
working = strp_atoi(s, tm->tm_min, 0, 59, 0);
if (working && *s == ':')
{
++s;
working = strp_atoi(s, tm->tm_sec, 0, 60, 0);
}
}
if (!working)
s = s_save;
}
break;
case 'w': // weekday number 0->6 sunday->saturday
working = strp_atoi(s, tm->tm_wday, 0, 6, 0);
break;
case 'Y': // year
working = strp_atoi(s, tm->tm_year, 1900, 65535, -1900);
break;
case 'y': // 2-digit year
working = strp_atoi(s, tm->tm_year, 0, 99, 0);
if (working && tm->tm_year < 69)
tm->tm_year += 100;
break;
case '%': // escaped
if (*s != '%')
working = false;
++s;
break;
default:
working = false;
}
}
break;
case ' ':
case '\t':
case '\r':
case '\n':
case '\f':
case '\v':
// zero or more whitespaces:
while (isspace((int)*s))
++s;
break;
default:
// match character
if (*s != *format)
working = false;
else
++s;
break;
}
++format;
}
return (working ? (char *)s : 0);
bool working = true;
while (working && *format && *s)
{
switch (*format)
{
case '%':
{
++format;
switch (*format)
{
case 'a':
case 'A': // weekday name
tm->tm_wday = -1;
working = false;
for (int i = 0; i < 7; ++i)
{
size_t len = strlen(strp_weekdays[i]);
if (!strnicmp(strp_weekdays[i], s, len))
{
tm->tm_wday = i;
s += len;
working = true;
break;
}
else if (!strnicmp(strp_weekdays[i], s, 3))
{
tm->tm_wday = i;
s += 3;
working = true;
break;
}
}
break;
case 'b':
case 'B':
case 'h': // month name
tm->tm_mon = -1;
working = false;
for (int i = 0; i < 12; ++i)
{
size_t len = strlen(strp_monthnames[i]);
if (!strnicmp(strp_monthnames[i], s, len))
{
tm->tm_mon = i;
s += len;
working = true;
break;
}
else if (!strnicmp(strp_monthnames[i], s, 3))
{
tm->tm_mon = i;
s += 3;
working = true;
break;
}
}
break;
case 'd':
case 'e': // day of month number
working = strp_atoi(s, tm->tm_mday, 1, 31, 0);
break;
case 'D': // %m/%d/%y
{
const char * s_save = s;
working = strp_atoi(s, tm->tm_mon, 1, 12, -1);
if (working && *s == '/')
{
++s;
working = strp_atoi(s, tm->tm_mday, 1, 31, 0);
if (working && *s == '/')
{
++s;
working = strp_atoi(s, tm->tm_year, 0, 99, 0);
if (working && tm->tm_year < 69)
tm->tm_year += 100;
}
}
if (!working)
s = s_save;
}
break;
case 'H': // hour
working = strp_atoi(s, tm->tm_hour, 0, 23, 0);
break;
case 'I': // hour 12-hour clock
working = strp_atoi(s, tm->tm_hour, 1, 12, 0);
break;
case 'j': // day number of year
working = strp_atoi(s, tm->tm_yday, 1, 366, -1);
break;
case 'm': // month number
working = strp_atoi(s, tm->tm_mon, 1, 12, -1);
break;
case 'M': // minute
working = strp_atoi(s, tm->tm_min, 0, 59, 0);
break;
case 'n': // arbitrary whitespace
case 't':
while (isspace((int)*s))
++s;
break;
case 'p': // am / pm
if (!strnicmp(s, "am", 2))
{ // the hour will be 1 -> 12 maps to 12 am, 1 am .. 11 am, 12 noon 12 pm .. 11 pm
if (tm->tm_hour == 12) // 12 am == 00 hours
tm->tm_hour = 0;
}
else if (!strnicmp(s, "pm", 2))
{
if (tm->tm_hour < 12) // 12 pm == 12 hours
tm->tm_hour += 12; // 1 pm -> 13 hours, 11 pm -> 23 hours
}
else
working = false;
break;
case 'r': // 12 hour clock %I:%M:%S %p
{
const char * s_save = s;
working = strp_atoi(s, tm->tm_hour, 1, 12, 0);
if (working && *s == ':')
{
++s;
working = strp_atoi(s, tm->tm_min, 0, 59, 0);
if (working && *s == ':')
{
++s;
working = strp_atoi(s, tm->tm_sec, 0, 60, 0);
if (working && isspace((int)*s))
{
++s;
while (isspace((int)*s))
++s;
if (!strnicmp(s, "am", 2))
{ // the hour will be 1 -> 12 maps to 12 am, 1 am .. 11 am, 12 noon 12 pm .. 11 pm
if (tm->tm_hour == 12) // 12 am == 00 hours
tm->tm_hour = 0;
}
else if (!strnicmp(s, "pm", 2))
{
if (tm->tm_hour < 12) // 12 pm == 12 hours
tm->tm_hour += 12; // 1 pm -> 13 hours, 11 pm -> 23 hours
}
else
working = false;
}
}
}
if (!working)
s = s_save;
}
break;
case 'R': // %H:%M
{
const char * s_save = s;
working = strp_atoi(s, tm->tm_hour, 0, 23, 0);
if (working && *s == ':')
{
++s;
working = strp_atoi(s, tm->tm_min, 0, 59, 0);
}
if (!working)
s = s_save;
}
break;
case 'S': // seconds
working = strp_atoi(s, tm->tm_sec, 0, 60, 0);
break;
case 'T': // %H:%M:%S
{
const char * s_save = s;
working = strp_atoi(s, tm->tm_hour, 0, 23, 0);
if (working && *s == ':')
{
++s;
working = strp_atoi(s, tm->tm_min, 0, 59, 0);
if (working && *s == ':')
{
++s;
working = strp_atoi(s, tm->tm_sec, 0, 60, 0);
}
}
if (!working)
s = s_save;
}
break;
case 'w': // weekday number 0->6 sunday->saturday
working = strp_atoi(s, tm->tm_wday, 0, 6, 0);
break;
case 'Y': // year
working = strp_atoi(s, tm->tm_year, 1900, 65535, -1900);
break;
case 'y': // 2-digit year
working = strp_atoi(s, tm->tm_year, 0, 99, 0);
if (working && tm->tm_year < 69)
tm->tm_year += 100;
break;
case '%': // escaped
if (*s != '%')
working = false;
++s;
break;
default:
working = false;
}
}
break;
case ' ':
case '\t':
case '\r':
case '\n':
case '\f':
case '\v':
// zero or more whitespaces:
while (isspace((int)*s))
++s;
break;
default:
// match character
if (*s != *format)
working = false;
else
++s;
break;
}
++format;
}
return (working ? (char *)s : 0);
}