summaryrefslogtreecommitdiff
path: root/vmsify.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2006-11-18 20:53:44 +0000
committerPaul Smith <psmith@gnu.org>2006-11-18 20:53:44 +0000
commite4da30858037b431880263676e8f90b1f8412a38 (patch)
tree2605109d089f52e373bd976391dca85774ae3b21 /vmsify.c
parent7595f38f62afa7ac3451018d865fb251e3ce91c3 (diff)
downloadgunmake-e4da30858037b431880263676e8f90b1f8412a38.tar.gz
Fix from Eli for incorrect value of $(MAKE) on Cygwin.
A few changes from char* to void* where appropriate, and removing of unnecessary casts. Much more work on const-ifying the codebase. This round involves some code changes to make it correct. NOTE!! There will almost certainly be problems on the non-POSIX ports that will need to be addressed after the const changes are finished: they will need to be const-ified properly and there may need to be some changes to allocate memory, etc. as well. The next (last?) big push for this, still to come, is const-ifying the filenames in struct file, struct dep, etc. This will allow us to store file names in the string cache and finally resolve Savannah bug #15182 (make uses too much memory), among other advantages.
Diffstat (limited to 'vmsify.c')
-rw-r--r--vmsify.c305
1 files changed, 155 insertions, 150 deletions
diff --git a/vmsify.c b/vmsify.c
index d9f7df4..7ab4481 100644
--- a/vmsify.c
+++ b/vmsify.c
@@ -63,9 +63,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */
*/
static int
-copyto (char **to, char **from, char upto, int as_dir)
+copyto (char **to, const char **from, char upto, int as_dir)
{
- char *s;
+ const char *s;
s = strrchr (*from, '.');
@@ -111,7 +111,7 @@ copyto (char **to, char **from, char upto, int as_dir)
*/
static char *
-trnlog (char *name)
+trnlog (const char *name)
{
int stat;
static char reslt[1024];
@@ -205,11 +205,12 @@ enum namestate { N_START, N_DEVICE, N_OPEN, N_DOT, N_CLOSED, N_DONE };
25 filenames with ':' are left unchanged
26 filenames with a single pair of '[' ']' are left unchanged
- the input string is not written to
+ The input string is not written to. The result is also const because
+ it's a static buffer; we don't want to change it.
*/
-char *
-vmsify (char *name, int type)
+const char *
+vmsify (const char *name, int type)
{
/* max 255 device
max 39 directory
@@ -221,9 +222,9 @@ vmsify (char *name, int type)
enum namestate nstate;
static char vmsname[MAXPATHLEN+1];
- char *fptr;
+ const char *fptr;
+ const char *t;
char *vptr;
- char *s,*s1;
int as_dir;
int count;
@@ -234,69 +235,57 @@ vmsify (char *name, int type)
nstate = N_START;
/* case 25a */
+ t = strpbrk (name, "$:");
- s = strpbrk (name, "$:");
- if (s != 0)
+ if (t != 0)
{
- char *s1;
- char *s2;
+ const char *s1;
+ const char *s2;
if (type == 1)
- {
- s1 = strchr (s+1, '[');
- s2 = strchr (s+1, ']');
- }
+ {
+ s1 = strchr (t+1, '[');
+ s2 = strchr (t+1, ']');
+ }
- if (*s == '$')
- {
- if (strchr (name, '/') == 0)
- {
- if ((type == 1) && (s1 != 0) && (s2 == 0))
- {
- strcpy (vmsname, name);
- strcat (vmsname, "]");
- return vmsname;
- }
- else
- return name;
- }
- }
+ if (*t == '$')
+ {
+ if (strchr (name, '/') == 0)
+ {
+ strcpy (vmsname, name);
+ if ((type == 1) && (s1 != 0) && (s2 == 0))
+ strcat (vmsname, "]");
+ return vmsname;
+ }
+ }
else
- {
- if ((type == 1) && (s1 != 0) && (s2 == 0))
- {
- strcpy (vmsname, name);
- strcat (vmsname, "]");
- return vmsname;
- }
- else
- return name;
- }
+ {
+ strcpy (vmsname, name);
+ if ((type == 1) && (s1 != 0) && (s2 == 0))
+ strcat (vmsname, "]");
+ return vmsname;
+ }
}
/* case 26 */
+ t = strchr (name, '[');
- s = strchr (name, '[');
-
- if (s != 0)
+ if (t != 0)
{
- s1 = strchr (s+1, '[');
+ const char *s;
+ const char *s1 = strchr (t+1, '[');
if (s1 == 0)
{
- if ((type == 1)
- && (strchr (s+1, ']') == 0))
- {
- strcpy (vmsname, name);
- strcat (vmsname, "]");
- return vmsname;
- }
- else
- return name; /* single [, keep unchanged */
+ strcpy (vmsname, name);
+ if ((type == 1) && (strchr (t+1, ']') == 0))
+ strcat (vmsname, "]");
+ return vmsname;
}
s1--;
if (*s1 != ']')
{
- return name; /* not ][, keep unchanged */
+ strcpy (vmsname, name);
+ return vmsname; /* not ][, keep unchanged */
}
/* we have ][ */
@@ -305,7 +294,6 @@ vmsify (char *name, int type)
/* s -> starting char
s1 -> ending ']' */
-
do
{
strncpy (vptr, s, s1-s); /* copy up to but not including ']' */
@@ -329,19 +317,13 @@ vmsify (char *name, int type)
fptr = s;
}
-
else /* no [ in name */
-
{
-
- int state;
+ int state = 0;
int rooted = 1; /* flag if logical is rooted, else insert [000000] */
- state = 0;
-
do
{
-
switch (state)
{
case 0: /* start of loop */
@@ -370,7 +352,8 @@ vmsify (char *name, int type)
break;
case 2: /* no '/' at start */
- s = strchr (fptr, '/');
+ {
+ const char *s = strchr (fptr, '/');
if (s == 0) /* no '/' (16) */
{
if (type == 1)
@@ -401,8 +384,13 @@ vmsify (char *name, int type)
}
}
break;
+ }
case 3: /* '//' at start */
+ {
+ const char *s;
+ const char *s1;
+ char *vp;
while (*fptr == '/') /* collapse all '/' */
fptr++;
if (*fptr == 0) /* just // */
@@ -412,12 +400,14 @@ vmsify (char *name, int type)
s1 = getcwd(cwdbuf, MAXPATHLEN);
if (s1 == 0)
{
- return ""; /* FIXME, err getcwd */
+ vmsname[0] = '\0';
+ return vmsname; /* FIXME, err getcwd */
}
s = strchr (s1, ':');
if (s == 0)
{
- return ""; /* FIXME, err no device */
+ vmsname[0] = '\0';
+ return vmsname; /* FIXME, err no device */
}
strncpy (vptr, s1, s-s1+1);
vptr += s-s1+1;
@@ -444,28 +434,27 @@ vmsify (char *name, int type)
}
*vptr = 0;
/* check logical for [000000] insertion */
- s1 = trnlog (s);
- if (*s1 != 0)
+ vp = trnlog (s);
+ if (*vp != '\0')
{ /* found translation */
- char *s2;
for (;;) /* loop over all nested logicals */
{
- s2 = s1 + strlen (s1) - 1;
- if (*s2 == ':') /* translation ends in ':' */
+ char *vp2 = vp + strlen (vp) - 1;
+ if (*vp2 == ':') /* translation ends in ':' */
{
- s2 = trnlog (s1);
- free (s1);
- if (*s2 == 0)
+ vp2 = trnlog (vp);
+ free (vp);
+ if (*vp2 == 0)
{
rooted = 0;
break;
}
- s1 = s2;
+ vp = vp2;
continue; /* next iteration */
}
- if (*s2 == ']') /* translation ends in ']' */
+ if (*vp2 == ']') /* translation ends in ']' */
{
- if (*(s2-1) == '.') /* ends in '.]' */
+ if (*(vp2-1) == '.') /* ends in '.]' */
{
if (strncmp (fptr, "000000", 6) != 0)
rooted = 0;
@@ -473,15 +462,15 @@ vmsify (char *name, int type)
else
{
strcpy (vmsname, s1);
- s = strchr (vmsname, ']');
- *s = '.';
+ vp = strchr (vmsname, ']');
+ *vp = '.';
nstate = N_DOT;
- vptr = s;
+ vptr = vp;
}
}
break;
}
- free (s1);
+ free (vp);
}
else
rooted = 0;
@@ -496,15 +485,15 @@ vmsify (char *name, int type)
if (rooted == 0)
{
+ nstate = N_DOT;
strcpy (vptr, "[000000.");
vptr += 8;
- s1 = vptr-1;
- nstate = N_DOT;
+ vp = vptr-1;
}
else
- s1 = 0;
+ vp = 0;
- /* s1-> '.' after 000000 or NULL */
+ /* vp-> '.' after 000000 or NULL */
s = strchr (fptr, '/');
if (s == 0)
@@ -531,18 +520,18 @@ vmsify (char *name, int type)
}
else
if ((nstate == N_DOT)
- && (s1 != 0)
+ && (vp != 0)
&& (*(s+1) == 0))
{
if (type == 2)
{
- *s1 = ']';
+ *vp = ']';
nstate = N_CLOSED;
}
}
state = 9;
break;
-
+ }
case 4: /* single '/' at start (9..15) */
if (*fptr == 0)
state = 5;
@@ -564,7 +553,9 @@ vmsify (char *name, int type)
state = 8;
break;
- case 6: /* chars following '/' at start 10..15 */
+ case 6: /* chars following '/' at start 10..15 */
+ {
+ const char *s;
*vptr++ = '[';
nstate = N_OPEN;
s = strchr (fptr, '/');
@@ -595,24 +586,25 @@ vmsify (char *name, int type)
state = 9;
}
break;
+ }
case 7: /* add '.dir' and exit */
if ((nstate == N_OPEN)
|| (nstate == N_DOT))
{
- s = vptr-1;
- while (s > vmsname)
+ char *vp = vptr-1;
+ while (vp > vmsname)
{
- if (*s == ']')
+ if (*vp == ']')
{
break;
}
- if (*s == '.')
+ if (*vp == '.')
{
- *s = ']';
+ *vp = ']';
break;
}
- s--;
+ vp--;
}
}
strcpy (vptr, ".dir");
@@ -625,7 +617,9 @@ vmsify (char *name, int type)
state = -1;
break;
- case 9: /* 17..21, fptr -> 1st '/' + 1 */
+ case 9: /* 17..21, fptr -> 1st '/' + 1 */
+ {
+ const char *s;
if (*fptr == 0)
{
if (type == 2)
@@ -687,6 +681,7 @@ vmsify (char *name, int type)
&& ((*(fptr+2) == '/')
|| (*(fptr+2) == 0)) )
{
+ char *vp;
fptr += 2;
if (*fptr == '/')
{
@@ -699,29 +694,29 @@ vmsify (char *name, int type)
else if (*fptr == 0)
type = 1;
vptr--; /* vptr -> '.' or ']' */
- s1 = vptr;
+ vp = vptr;
for (;;)
{
- s1--;
- if (*s1 == '.') /* one back */
+ vp--;
+ if (*vp == '.') /* one back */
{
- vptr = s1;
+ vptr = vp;
nstate = N_OPEN;
break;
}
- if (*s1 == '[') /* top level reached */
+ if (*vp == '[') /* top level reached */
{
if (*fptr == 0)
{
- strcpy (s1, "[000000]");
- vptr = s1 + 8;
+ strcpy (vp, "[000000]");
+ vptr = vp + 8;
nstate = N_CLOSED;
s = 0;
break;
}
else
{
- vptr = s1+1;
+ vptr = vp+1;
nstate = N_OPEN;
break;
}
@@ -756,6 +751,7 @@ vmsify (char *name, int type)
}
}
break;
+ }
case 10: /* 1,2 first is '.' */
if (*fptr == '.')
@@ -773,7 +769,8 @@ vmsify (char *name, int type)
{
if (*fptr != '/') /* got ..xxx */
{
- return name;
+ strcpy (vmsname, name);
+ return vmsname;
}
do /* got ../ */
{
@@ -791,42 +788,44 @@ vmsify (char *name, int type)
while (*fptr == '/');
}
{ /* got '..' or '../' */
+ char *vp;
char cwdbuf[MAXPATHLEN+1];
- s1 = getcwd(cwdbuf, MAXPATHLEN);
- if (s1 == 0)
+ vp = getcwd(cwdbuf, MAXPATHLEN);
+ if (vp == 0)
{
- return ""; /* FIXME, err getcwd */
+ vmsname[0] = '\0';
+ return vmsname; /* FIXME, err getcwd */
}
- strcpy (vptr, s1);
- s = strchr (vptr, ']');
- if (s != 0)
+ strcpy (vptr, vp);
+ vp = strchr (vptr, ']');
+ if (vp != 0)
{
nstate = N_OPEN;
- while (s > vptr)
+ while (vp > vptr)
{
- s--;
- if (*s == '[')
+ vp--;
+ if (*vp == '[')
{
- s++;
- strcpy (s, "000000]");
+ vp++;
+ strcpy (vp, "000000]");
state = -1;
break;
}
- else if (*s == '.')
+ else if (*vp == '.')
{
if (--count == 0)
{
if (*fptr == 0) /* had '..' or '../' */
{
- *s++ = ']';
+ *vp++ = ']';
state = -1;
}
else /* had '../xxx' */
{
state = 9;
}
- *s = 0;
+ *vp = '\0';
break;
}
}
@@ -841,40 +840,43 @@ vmsify (char *name, int type)
{
if (*fptr != '/')
{
- return name;
+ strcpy (vmsname, name);
+ return vmsname;
}
while (*fptr == '/')
fptr++;
}
{
+ char *vp;
char cwdbuf[MAXPATHLEN+1];
- s1 = getcwd(cwdbuf, MAXPATHLEN);
- if (s1 == 0)
- {
- return ""; /*FIXME, err getcwd */
- }
- strcpy (vptr, s1);
- if (*fptr == 0)
+ vp = getcwd(cwdbuf, MAXPATHLEN);
+ if (vp == 0)
{
- state = -1;
- break;
- }
- else
- {
- s = strchr (vptr, ']');
- if (s == 0)
- {
- state = -1;
- break;
- }
- *s = 0;
- nstate = N_OPEN;
- vptr += strlen (vptr);
- state = 9;
+ vmsname[0] = '\0';
+ return vmsname; /*FIXME, err getcwd */
}
- }
+ strcpy (vptr, vp);
+ }
+ if (*fptr == 0)
+ {
+ state = -1;
+ break;
+ }
+ else
+ {
+ char *vp = strchr (vptr, ']');
+ if (vp == 0)
+ {
+ state = -1;
+ break;
+ }
+ *vp = '\0';
+ nstate = N_OPEN;
+ vptr += strlen (vptr);
+ state = 9;
+ }
break;
}
@@ -903,14 +905,18 @@ vmsify (char *name, int type)
dev:[dir1.dir2] //dev/dir1/dir2/
*/
-char *
-unixify (char *name)
+const char *
+unixify (const char *name)
{
static char piece[512];
- char *s, *p;
+ const char *s;
+ char *p;
if (strchr (name, '/') != 0) /* already in unix style */
- return name;
+ {
+ strcpy (piece, name);
+ return piece;
+ }
p = piece;
*p = 0;
@@ -921,12 +927,11 @@ unixify (char *name)
if (s != 0)
{
- *s = 0;
+ int l = s - name;
*p++ = '/';
*p++ = '/';
- strcpy (p, name);
- p += strlen (p);
- *s = ':';
+ strncpy (p, name, l);
+ p += l;
}
/* directory part */