* Makefile.in: add miscfuncs.cc
* miscfuncs.cc: new, miscellaneous functions * winsup.h: define table-driven tolower/toupper * environ.cc: use them * fhandler_console.cc: ditto * fhandler_termios: ditto * path.cc: ditto (strncasematch, strcasematch, strcasestr): move to miscfuncs.cc
This commit is contained in:
parent
cc55c579a3
commit
2556e737ec
|
@ -1,3 +1,14 @@
|
||||||
|
2000-10-18 DJ Delorie <dj@redhat.com>
|
||||||
|
|
||||||
|
* Makefile.in: add miscfuncs.cc
|
||||||
|
* miscfuncs.cc: new, miscellaneous functions
|
||||||
|
* winsup.h: define table-driven tolower/toupper
|
||||||
|
* environ.cc: use them
|
||||||
|
* fhandler_console.cc: ditto
|
||||||
|
* fhandler_termios: ditto
|
||||||
|
* path.cc: ditto
|
||||||
|
(strncasematch, strcasematch, strcasestr): move to miscfuncs.cc
|
||||||
|
|
||||||
Wed Oct 18 20:50:27 2000 Christopher Faylor <cgf@cygnus.com>
|
Wed Oct 18 20:50:27 2000 Christopher Faylor <cgf@cygnus.com>
|
||||||
|
|
||||||
* sigproc.h (sigthread): Eliminate locking for now since per thread
|
* sigproc.h (sigthread): Eliminate locking for now since per thread
|
||||||
|
|
|
@ -118,7 +118,8 @@ DLL_OFILES:=assert.o cygheap.o dcrt0.o debug.o delqueue.o dir.o dlfcn.o \
|
||||||
fhandler_floppy.o fhandler_mem.o \
|
fhandler_floppy.o fhandler_mem.o \
|
||||||
fhandler_random.o fhandler_raw.o fhandler_serial.o fhandler_tape.o \
|
fhandler_random.o fhandler_raw.o fhandler_serial.o fhandler_tape.o \
|
||||||
fhandler_termios.o fhandler_tty.o fhandler_windows.o fhandler_zero.o \
|
fhandler_termios.o fhandler_tty.o fhandler_windows.o fhandler_zero.o \
|
||||||
fork.o glob.o grp.o heap.o init.o ioctl.o localtime.o malloc.o mmap.o \
|
fork.o glob.o grp.o heap.o init.o ioctl.o localtime.o malloc.o \
|
||||||
|
miscfuncs.o mmap.o \
|
||||||
net.o ntea.o passwd.o path.o pinfo.o pipe.o poll.o pthread.o regexp.o \
|
net.o ntea.o passwd.o path.o pinfo.o pipe.o poll.o pthread.o regexp.o \
|
||||||
regerror.o regsub.o registry.o resource.o scandir.o security.o select.o \
|
regerror.o regsub.o registry.o resource.o scandir.o security.o select.o \
|
||||||
shared.o signal.o sigproc.o smallprint.o spawn.o strace.o strsep.o \
|
shared.o signal.o sigproc.o smallprint.o spawn.o strace.o strsep.o \
|
||||||
|
|
|
@ -354,7 +354,7 @@ ucenv (char *p, char *eq)
|
||||||
we only do it for the first process in a session group. */
|
we only do it for the first process in a session group. */
|
||||||
for (; p < eq; p++)
|
for (; p < eq; p++)
|
||||||
if (islower (*p))
|
if (islower (*p))
|
||||||
*p = toupper (*p);
|
*p = cyg_toupper (*p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse CYGWIN options */
|
/* Parse CYGWIN options */
|
||||||
|
@ -538,8 +538,8 @@ environ_init (char **envp, int envc)
|
||||||
{
|
{
|
||||||
for (int i = 0; conv_envvars[i].name != NULL; i++)
|
for (int i = 0; conv_envvars[i].name != NULL; i++)
|
||||||
{
|
{
|
||||||
conv_start_chars[tolower(conv_envvars[i].name[0])] = 1;
|
conv_start_chars[cyg_tolower(conv_envvars[i].name[0])] = 1;
|
||||||
conv_start_chars[toupper(conv_envvars[i].name[0])] = 1;
|
conv_start_chars[cyg_toupper(conv_envvars[i].name[0])] = 1;
|
||||||
}
|
}
|
||||||
initted = 1;
|
initted = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,7 +228,7 @@ fhandler_console::read (void *pv, size_t buflen)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tmp[0] = '\033';
|
tmp[0] = '\033';
|
||||||
tmp[1] = tolower (tmp[1]);
|
tmp[1] = cyg_tolower (tmp[1]);
|
||||||
toadd = tmp;
|
toadd = tmp;
|
||||||
nread++;
|
nread++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,7 +283,7 @@ fhandler_termios::line_edit (const char *rptr, int nread, int always_accept)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tc->ti.c_iflag & IUCLC && isupper (c))
|
if (tc->ti.c_iflag & IUCLC && isupper (c))
|
||||||
c = tolower (c);
|
c = cyg_tolower (c);
|
||||||
|
|
||||||
if (tc->ti.c_lflag & ECHO)
|
if (tc->ti.c_lflag & ECHO)
|
||||||
doecho (&c, 1);
|
doecho (&c, 1);
|
||||||
|
|
|
@ -0,0 +1,114 @@
|
||||||
|
/* miscfuncs.cc: misc funcs that don't belong anywhere else
|
||||||
|
|
||||||
|
Copyright 1996, 1997, 1998, 1999, 2000 Red Hat, Inc.
|
||||||
|
|
||||||
|
This file is part of Cygwin.
|
||||||
|
|
||||||
|
This software is a copyrighted work licensed under the terms of the
|
||||||
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
||||||
|
details. */
|
||||||
|
|
||||||
|
#include "winsup.h"
|
||||||
|
|
||||||
|
/********************** String Helper Functions ************************/
|
||||||
|
|
||||||
|
char case_folded_lower[] = {
|
||||||
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||||
|
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
||||||
|
32, '!', '"', '#', '$', '%', '&', 39, '(', ')', '*', '+', ',', '-', '.', '/',
|
||||||
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
|
||||||
|
'@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
||||||
|
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', 92, ']', '^', '_',
|
||||||
|
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
||||||
|
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 127,
|
||||||
|
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
|
||||||
|
144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
|
||||||
|
160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
|
||||||
|
176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
|
||||||
|
192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
|
||||||
|
208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
|
||||||
|
224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
|
||||||
|
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
|
||||||
|
};
|
||||||
|
|
||||||
|
char case_folded_upper[] = {
|
||||||
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||||
|
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
||||||
|
32, '!', '"', '#', '$', '%', '&', 39, '(', ')', '*', '+', ',', '-', '.', '/',
|
||||||
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
|
||||||
|
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
||||||
|
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', 92, ']', '^', '_',
|
||||||
|
'`', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
||||||
|
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '{', '|', '}', '~', 127,
|
||||||
|
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
|
||||||
|
144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
|
||||||
|
160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
|
||||||
|
176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
|
||||||
|
192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
|
||||||
|
208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
|
||||||
|
224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
|
||||||
|
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
|
||||||
|
};
|
||||||
|
|
||||||
|
#define ch_case_eq(ch1, ch2) (cyg_tolower(ch1) == cyg_tolower(ch2))
|
||||||
|
|
||||||
|
/* Return TRUE if two strings match up to length n */
|
||||||
|
extern "C" int __stdcall
|
||||||
|
strncasematch (const char *s1, const char *s2, size_t n)
|
||||||
|
{
|
||||||
|
if (s1 == s2)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
n++;
|
||||||
|
while (--n && *s1)
|
||||||
|
{
|
||||||
|
if (!ch_case_eq (*s1, *s2))
|
||||||
|
return 0;
|
||||||
|
s1++; s2++;
|
||||||
|
}
|
||||||
|
return !n || *s2 == '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return TRUE if two strings match */
|
||||||
|
extern "C" int __stdcall
|
||||||
|
strcasematch (const char *s1, const char *s2)
|
||||||
|
{
|
||||||
|
if (s1 == s2)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
while (*s1)
|
||||||
|
{
|
||||||
|
if (!ch_case_eq (*s1, *s2))
|
||||||
|
return 0;
|
||||||
|
s1++; s2++;
|
||||||
|
}
|
||||||
|
return *s2 == '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" char * __stdcall
|
||||||
|
strcasestr (const char *searchee, const char *lookfor)
|
||||||
|
{
|
||||||
|
if (*searchee == 0)
|
||||||
|
{
|
||||||
|
if (*lookfor)
|
||||||
|
return NULL;
|
||||||
|
return (char *) searchee;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (*searchee)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
if (lookfor[i] == 0)
|
||||||
|
return (char *) searchee;
|
||||||
|
|
||||||
|
if (!ch_case_eq (lookfor[i], searchee[i]))
|
||||||
|
break;
|
||||||
|
lookfor++;
|
||||||
|
}
|
||||||
|
searchee++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
|
@ -93,7 +93,7 @@ struct symlink_info
|
||||||
cwdstuff cygcwd; /* The current working directory. */
|
cwdstuff cygcwd; /* The current working directory. */
|
||||||
|
|
||||||
#define path_prefix_p(p1, p2, l1) \
|
#define path_prefix_p(p1, p2, l1) \
|
||||||
((tolower(*(p1))==tolower(*(p2))) && \
|
((cyg_tolower(*(p1))==cyg_tolower(*(p2))) && \
|
||||||
path_prefix_p_(p1, p2, l1))
|
path_prefix_p_(p1, p2, l1))
|
||||||
|
|
||||||
#define SYMLINKATTR(x) \
|
#define SYMLINKATTR(x) \
|
||||||
|
@ -450,7 +450,7 @@ get_raw_device_number (const char *uxname, const char *w32path, int &unit)
|
||||||
else if (isdrive (w32path + 4))
|
else if (isdrive (w32path + 4))
|
||||||
{
|
{
|
||||||
devn = FH_FLOPPY;
|
devn = FH_FLOPPY;
|
||||||
unit = tolower (w32path[4]) - 'a';
|
unit = cyg_tolower (w32path[4]) - 'a';
|
||||||
}
|
}
|
||||||
else if (strncasematch (w32path, "\\\\.\\physicaldrive", 17))
|
else if (strncasematch (w32path, "\\\\.\\physicaldrive", 17))
|
||||||
{
|
{
|
||||||
|
@ -1151,7 +1151,7 @@ mount_info::cygdrive_posix_path (const char *src, char *dst, int trailing_slash_
|
||||||
/* Now finish the path off with the drive letter to be used.
|
/* Now finish the path off with the drive letter to be used.
|
||||||
The cygdrive prefix always ends with a trailing slash so
|
The cygdrive prefix always ends with a trailing slash so
|
||||||
the drive letter is added after the path. */
|
the drive letter is added after the path. */
|
||||||
dst[len++] = tolower (src[0]);
|
dst[len++] = cyg_tolower (src[0]);
|
||||||
if (!src[2] || (SLASH_P (src[2]) && !src[3]))
|
if (!src[2] || (SLASH_P (src[2]) && !src[3]))
|
||||||
dst[len++] = '\000';
|
dst[len++] = '\000';
|
||||||
else
|
else
|
||||||
|
@ -2395,7 +2395,7 @@ hash_path_name (unsigned long hash, const char *name)
|
||||||
char *nn, *newname = (char *) alloca (strlen (name) + 2);
|
char *nn, *newname = (char *) alloca (strlen (name) + 2);
|
||||||
nn = strncpy (newname, name, 2);
|
nn = strncpy (newname, name, 2);
|
||||||
if (isupper (*nn))
|
if (isupper (*nn))
|
||||||
*newname = tolower (*nn);
|
*newname = cyg_tolower (*nn);
|
||||||
*(nn += 2) = '\0';
|
*(nn += 2) = '\0';
|
||||||
name += 2;
|
name += 2;
|
||||||
if (*name != '\\')
|
if (*name != '\\')
|
||||||
|
@ -2427,7 +2427,7 @@ hashit:
|
||||||
\a\b\. but allow a single \ if that's all there is. */
|
\a\b\. but allow a single \ if that's all there is. */
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
int ch = tolower(*name);
|
int ch = cyg_tolower(*name);
|
||||||
hash += ch + (ch << 17);
|
hash += ch + (ch << 17);
|
||||||
hash ^= hash >> 2;
|
hash ^= hash >> 2;
|
||||||
}
|
}
|
||||||
|
@ -2762,100 +2762,6 @@ cygwin_split_path (const char *path, char *dir, char *file)
|
||||||
file[end - last_slash - 1] = 0;
|
file[end - last_slash - 1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************** String Helper Functions ************************/
|
|
||||||
|
|
||||||
static char case_folded[] = {
|
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
||||||
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
|
||||||
32, '!', '"', '#', '$', '%', '&', 39, '(', ')', '*', '+', ',', '-', '.', '/',
|
|
||||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
|
|
||||||
'@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
|
||||||
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', 92, ']', '^', '_',
|
|
||||||
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
|
||||||
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 127,
|
|
||||||
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
|
|
||||||
144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
|
|
||||||
160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
|
|
||||||
176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
|
|
||||||
192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
|
|
||||||
208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
|
|
||||||
224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
|
|
||||||
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
|
|
||||||
};
|
|
||||||
|
|
||||||
#define CHXOR ('a' ^ 'A')
|
|
||||||
#define old_ch_case_eq(ch1, ch2) \
|
|
||||||
({ \
|
|
||||||
unsigned char x; \
|
|
||||||
!((x = ((unsigned char)ch1 ^ (unsigned char)ch2)) && \
|
|
||||||
(x != CHXOR || !isalpha (ch1))); \
|
|
||||||
})
|
|
||||||
|
|
||||||
// This is about 10% faster than the above logic, on average
|
|
||||||
#define ch_case_eq(ch1, ch2) (case_folded[(unsigned char)(ch1)] \
|
|
||||||
== case_folded[(unsigned char)(ch2)])
|
|
||||||
|
|
||||||
/* Return TRUE if two strings match up to length n */
|
|
||||||
extern "C" int __stdcall
|
|
||||||
strncasematch (const char *s1, const char *s2, size_t n)
|
|
||||||
{
|
|
||||||
if (s1 == s2)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
n++;
|
|
||||||
while (--n && *s1)
|
|
||||||
{
|
|
||||||
if (!ch_case_eq (*s1, *s2))
|
|
||||||
return 0;
|
|
||||||
s1++; s2++;
|
|
||||||
}
|
|
||||||
return !n || *s2 == '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return TRUE if two strings match */
|
|
||||||
extern "C" int __stdcall
|
|
||||||
strcasematch (const char *s1, const char *s2)
|
|
||||||
{
|
|
||||||
if (s1 == s2)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
while (*s1)
|
|
||||||
{
|
|
||||||
if (!ch_case_eq (*s1, *s2))
|
|
||||||
return 0;
|
|
||||||
s1++; s2++;
|
|
||||||
}
|
|
||||||
return *s2 == '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" char * __stdcall
|
|
||||||
strcasestr (const char *searchee, const char *lookfor)
|
|
||||||
{
|
|
||||||
if (*searchee == 0)
|
|
||||||
{
|
|
||||||
if (*lookfor)
|
|
||||||
return NULL;
|
|
||||||
return (char *) searchee;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (*searchee)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
if (lookfor[i] == 0)
|
|
||||||
return (char *) searchee;
|
|
||||||
|
|
||||||
if (!ch_case_eq (lookfor[i], searchee[i]))
|
|
||||||
break;
|
|
||||||
lookfor++;
|
|
||||||
}
|
|
||||||
searchee++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int __stdcall
|
int __stdcall
|
||||||
check_null_empty_path (const char *name)
|
check_null_empty_path (const char *name)
|
||||||
{
|
{
|
||||||
|
@ -2869,6 +2775,8 @@ check_null_empty_path (const char *name)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
/* Return the hash value for the current win32 value.
|
/* Return the hash value for the current win32 value.
|
||||||
This is used when constructing inodes. */
|
This is used when constructing inodes. */
|
||||||
DWORD
|
DWORD
|
||||||
|
|
|
@ -53,6 +53,11 @@ __asm__ __volatile__(
|
||||||
return __res;
|
return __res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern char case_folded_lower[];
|
||||||
|
#define cyg_tolower(c) (case_folded_lower[(unsigned char)(c)])
|
||||||
|
extern char case_folded_upper[];
|
||||||
|
#define cyg_toupper(c) (case_folded_upper[(unsigned char)(c)])
|
||||||
|
|
||||||
#define cfree newlib_cfree_dont_use
|
#define cfree newlib_cfree_dont_use
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
#define WIN32_LEAN_AND_MEAN 1
|
||||||
|
|
Loading…
Reference in New Issue