aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2001-03-17 01:29:14 +0000
committerChristopher Faylor <me@cgf.cx>2001-03-17 01:29:14 +0000
commitb65c6896c82307106f1f9dca2f197e4d21911f17 (patch)
tree1ebc5706d0a4724412f25eaf83a7404d9f7a0fa8
parent5ccbf4b6998788d90b317b2c27f93efc2eca1516 (diff)
downloadnewlib-b65c6896c82307106f1f9dca2f197e4d21911f17.zip
newlib-b65c6896c82307106f1f9dca2f197e4d21911f17.tar.gz
newlib-b65c6896c82307106f1f9dca2f197e4d21911f17.tar.bz2
* path.cc: Translate scan states from defines to enums.
(suffix_scan): Rename state to nextstate for clarity. (lnk_match): Change to allow multiple states to indicate that a .lnk has been matched. (suffix_scan::has): Eliminate a goto. Handle .lnk as a special case, since a .lnk may also need to be tacked on the end of a .lnk. (suffix_scan::next): Don't increment next state. Set it specifically. Recognize new .lnk states.
-rw-r--r--winsup/cygwin/ChangeLog11
-rw-r--r--winsup/cygwin/path.cc46
2 files changed, 39 insertions, 18 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index a42758e..fbaeb19 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,14 @@
+Fri Mar 16 20:25:40 2001 Christopher Faylor <cgf@cygnus.com>
+
+ * path.cc: Translate scan states from defines to enums.
+ (suffix_scan): Rename state to nextstate for clarity.
+ (lnk_match): Change to allow multiple states to indicate that a .lnk
+ has been matched.
+ (suffix_scan::has): Eliminate a goto. Handle .lnk as a special case,
+ since a .lnk may also need to be tacked on the end of a .lnk.
+ (suffix_scan::next): Don't increment next state. Set it specifically.
+ Recognize new .lnk states.
+
aturday Mar 17 01:19 2001 Robert Collins rbtcollins@hotmail.com
* cygwin.din: Export the new functions.
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 3a84b09..c964a50 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -2394,23 +2394,28 @@ check_sysfile (const char *path, DWORD fileattr, HANDLE h,
return res;
}
-#define SCAN_BEG 0
-#define SCAN_LNK 1
-#define SCAN_TERM1 2
-#define SCAN_JUSTCHECK 3
+enum
+{
+ SCAN_BEG,
+ SCAN_LNK,
+ SCAN_HASLNK,
+ SCAN_JUSTCHECK,
+ SCAN_DONE,
+ SCAN_CHECKEDLNK,
+ SCAN_APPENDLNK,
+};
class suffix_scan
{
char *ext_here;
const suffix_info *suffixes;
- int state;
- int lnk_state;
+ int nextstate;
int nullterm;
public:
const char *path;
char *has (const char *, const suffix_info *, char **);
int next ();
- int lnk_match () {return lnk_state;}
+ int lnk_match () {return nextstate >= SCAN_CHECKEDLNK;}
};
char *
@@ -2419,8 +2424,7 @@ suffix_scan::has (const char *in_path, const suffix_info *in_suffixes, char **ex
path = in_path;
suffixes = in_suffixes;
nullterm = 0;
- state = SCAN_BEG;
- lnk_state = 0;
+ nextstate = SCAN_BEG;
ext_here = *ext_where = strrchr (in_path, '.');
if (ext_here)
{
@@ -2430,15 +2434,15 @@ suffix_scan::has (const char *in_path, const suffix_info *in_suffixes, char **ex
for (const suffix_info *ex = in_suffixes; ex->name != NULL; ex++)
if (strcasematch (ext_here, ex->name))
{
- state = SCAN_JUSTCHECK;
- suffixes = NULL; /* Has an extension so don't scan for one. */
+ nextstate = SCAN_JUSTCHECK;
+ 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"))
{
- lnk_state = 1;
+ nextstate = SCAN_HASLNK;
suffixes = NULL;
}
}
@@ -2464,17 +2468,23 @@ suffix_scan::next ()
return 1;
}
suffixes = NULL;
- state++;
}
- switch (state++)
+ switch (nextstate)
{
+ case SCAN_BEG:
+ nextstate = SCAN_LNK;
+ return 1;
+ case SCAN_HASLNK:
+ nextstate = SCAN_APPENDLNK; /* Skip SCAN_BEG */
+ return 1;
case SCAN_LNK:
- lnk_state = 1;
+ case SCAN_APPENDLNK:
strcpy (ext_here, ".lnk");
- /* fall through */
- case SCAN_BEG:
+ nextstate = SCAN_CHECKEDLNK;
+ return 1;
case SCAN_JUSTCHECK:
+ nextstate = SCAN_DONE;
return 1;
default:
if (nullterm && ext_here)
@@ -2559,7 +2569,7 @@ symlink_info::check (const char *path, const suffix_info *suffixes)
if (suffix.lnk_match ())
{
fileattr = (DWORD)-1;
- continue;
+ continue; /* in case we're going to tack *another* .lnk on this filename. */
}
goto file_not_symlink;
}