* dir.cc (readdir): Use strcasematch for consistency.

* path.cc (symlink_info): Eliminate known_suffix.
(path_conv::check): Always copy ext_here to end of buffer, if found.
(suffix_scan): Eliminate ext_here, add suffixes_start.
(suffix_scan::has): Eliminate an argument.  Reorganize.  Always return pointer
to end of input path.
(suffix_scan::next): Take a second pass through the suffix list looking for
.lnk.
(symlink_info::check): Eliminate known_suffix usage.
This commit is contained in:
Christopher Faylor 2001-03-17 07:09:41 +00:00
parent 92f4bf9725
commit b63a3f55a7
3 changed files with 66 additions and 49 deletions

View File

@ -1,3 +1,15 @@
Sat Mar 17 02:05:38 2001 Christopher Faylor <cgf@cygnus.com>
* dir.cc (readdir): Use strcasematch for consistency.
* path.cc (symlink_info): Eliminate known_suffix.
(path_conv::check): Always copy ext_here to end of buffer, if found.
(suffix_scan): Eliminate ext_here, add suffixes_start.
(suffix_scan::has): Eliminate an argument. Reorganize. Always return
pointer to end of input path.
(suffix_scan::next): Take a second pass through the suffix list looking
for .lnk.
(symlink_info::check): Eliminate known_suffix usage.
Sat Mar 17 00:10:52 2001 Christopher Faylor <cgf@cygnus.com> Sat Mar 17 00:10:52 2001 Christopher Faylor <cgf@cygnus.com>
* syscalls.cc (stat_dev): Give devices full read/write by default. * syscalls.cc (stat_dev): Give devices full read/write by default.

View File

@ -181,7 +181,7 @@ readdir (DIR * dir)
{ {
char *c = dir->__d_dirent->d_name; char *c = dir->__d_dirent->d_name;
int len = strlen (c); int len = strlen (c);
if (!strcasecmp (c + len - 4, ".lnk")) if (strcasematch (c + len - 4, ".lnk"))
{ {
char fbuf[MAX_PATH + 1]; char fbuf[MAX_PATH + 1];
strcpy (fbuf, dir->__d_dirname); strcpy (fbuf, dir->__d_dirname);

View File

@ -85,14 +85,13 @@ static int path_prefix_p_ (const char *path1, const char *path2, int len1);
struct symlink_info struct symlink_info
{ {
char buf[3 + MAX_PATH * 3]; char buf[3 + MAX_PATH * 3];
char *known_suffix;
char *ext_here; char *ext_here;
char *contents; char *contents;
unsigned pflags; unsigned pflags;
DWORD fileattr; DWORD fileattr;
int is_symlink; int is_symlink;
int error; int error;
symlink_info (): known_suffix (NULL), contents (buf + MAX_PATH + 1) {} symlink_info (): contents (buf + MAX_PATH + 1) {}
int check (const char *path, const suffix_info *suffixes); int check (const char *path, const suffix_info *suffixes);
}; };
@ -370,9 +369,7 @@ path_conv::check (const char *src, unsigned opt,
} }
fillin: fillin:
if (sym.known_suffix) if (sym.ext_here && !(opt & PC_SYM_CONTENTS))
known_suffix = this->path + (sym.known_suffix - path_copy);
else if (sym.ext_here && !(opt & PC_SYM_CONTENTS))
{ {
known_suffix = strchr (this->path, '\0'); known_suffix = strchr (this->path, '\0');
strcpy (known_suffix, sym.ext_here); strcpy (known_suffix, sym.ext_here);
@ -2400,57 +2397,56 @@ enum
SCAN_LNK, SCAN_LNK,
SCAN_HASLNK, SCAN_HASLNK,
SCAN_JUSTCHECK, SCAN_JUSTCHECK,
SCAN_DONE,
SCAN_CHECKEDLNK,
SCAN_APPENDLNK, SCAN_APPENDLNK,
SCAN_EXTRALNK,
SCAN_DONE,
}; };
class suffix_scan class suffix_scan
{ {
char *ext_here; const suffix_info *suffixes, *suffixes_start;
const suffix_info *suffixes;
int nextstate; int nextstate;
int nullterm; char *eopath;
public: public:
const char *path; const char *path;
char *has (const char *, const suffix_info *, char **); char *has (const char *, const suffix_info *);
int next (); int next ();
int lnk_match () {return nextstate >= SCAN_CHECKEDLNK;} int lnk_match () {return nextstate >= SCAN_EXTRALNK;}
}; };
char * char *
suffix_scan::has (const char *in_path, const suffix_info *in_suffixes, char **ext_where) suffix_scan::has (const char *in_path, const suffix_info *in_suffixes)
{ {
path = in_path;
suffixes = in_suffixes;
nullterm = 0;
nextstate = SCAN_BEG; nextstate = SCAN_BEG;
ext_here = *ext_where = strrchr (in_path, '.'); suffixes = suffixes_start = in_suffixes;
if (ext_here)
char *ext_here = strrchr (in_path, '.');
if (!ext_here)
goto done;
if (suffixes)
{ {
if (suffixes) /* Check if the extension matches a known extension */
{ for (const suffix_info *ex = in_suffixes; ex->name != NULL; ex++)
/* Check if the extension matches a known extension */ if (strcasematch (ext_here, ex->name))
for (const suffix_info *ex = in_suffixes; ex->name != NULL; ex++) {
if (strcasematch (ext_here, ex->name)) nextstate = SCAN_JUSTCHECK;
{ suffixes = NULL; /* Has an extension so don't scan for one. */
nextstate = SCAN_JUSTCHECK; goto done;
suffixes = NULL; /* Has an extension so don't scan for one. */ }
return ext_here;
}
}
/* Didn't match. Use last resort -- .lnk. */
if (strcasematch (ext_here, ".lnk"))
{
nextstate = SCAN_HASLNK;
suffixes = NULL;
}
} }
/* Didn't find a matching suffix. */ /* Didn't match. Use last resort -- .lnk. */
ext_here = *ext_where = strchr (path, '\0'); if (strcasematch (ext_here, ".lnk"))
nullterm = 1; {
return NULL; nextstate = SCAN_HASLNK;
suffixes = NULL;
}
done:
path = in_path;
eopath = strchr (path, '\0');
return eopath;
} }
int int
@ -2463,7 +2459,9 @@ suffix_scan::next ()
suffixes++; suffixes++;
else else
{ {
strcpy (ext_here, suffixes->name); strcpy (eopath, suffixes->name);
if (nextstate == SCAN_EXTRALNK)
strcat (eopath, ".lnk");
suffixes++; suffixes++;
return 1; return 1;
} }
@ -2473,22 +2471,29 @@ suffix_scan::next ()
switch (nextstate) switch (nextstate)
{ {
case SCAN_BEG: case SCAN_BEG:
nextstate = SCAN_LNK; suffixes = suffixes_start;
if (suffixes)
nextstate = SCAN_EXTRALNK;
else
nextstate = SCAN_LNK;
return 1; return 1;
case SCAN_HASLNK: case SCAN_HASLNK:
nextstate = SCAN_APPENDLNK; /* Skip SCAN_BEG */ nextstate = SCAN_EXTRALNK; /* Skip SCAN_BEG */
return 1; return 1;
case SCAN_LNK: case SCAN_LNK:
case SCAN_APPENDLNK: case SCAN_EXTRALNK:
strcpy (ext_here, ".lnk"); strcpy (eopath, ".lnk");
nextstate = SCAN_CHECKEDLNK; nextstate = SCAN_DONE;
return 1; return 1;
case SCAN_JUSTCHECK: case SCAN_JUSTCHECK:
nextstate = SCAN_APPENDLNK;
return 1;
case SCAN_APPENDLNK:
strcat (eopath, ".lnk");
nextstate = SCAN_DONE; nextstate = SCAN_DONE;
return 1; return 1;
default: default:
if (nullterm && ext_here) *eopath = '\0';
*ext_here = '\0';
return 0; return 0;
} }
} }
@ -2518,7 +2523,7 @@ symlink_info::check (const char *path, const suffix_info *suffixes)
suffix_scan suffix; suffix_scan suffix;
is_symlink = TRUE; is_symlink = TRUE;
known_suffix = suffix.has (path, suffixes, &ext_here); ext_here = suffix.has (path, suffixes);
while (suffix.next ()) while (suffix.next ())
{ {