home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 9
/
FreshFishVol9-CD2.bin
/
bbs
/
disk
/
mkisofs-1.00.7.lha
/
mkisofs
/
unix
/
filename.c
next >
Wrap
C/C++ Source or Header
|
1994-05-29
|
1KB
|
67 lines
/* filename.c: */
#include <stdlib.h>
#include <string.h>
#include "unixlib.h"
static int only_slashes (char *p_from, char *p_to)
{
char *cp;
for (cp=p_from; cp<=p_to; cp++)
if (*cp != '/')
return 0;
return 1;
}
/* remove files "." and ".." from a Unix filename: */
void remove_dot_files (char *buf)
{
char *cp;
if (cp = strchr (buf, ':'))
cp++;
else
cp = buf;
while (*cp) {
if (cp[0] == '.' && (cp[1] == 0 || cp[1] == '/')) {
if (cp[1] == 0)
cp[0] = 0;
else
memmove (cp, cp+2, strlen (cp+2) + 1);
} else if (cp[0] == '.' && cp[1] == '.' && (cp[2] == 0 || cp[2] == '/')) {
if (cp == buf || only_slashes (buf, cp-1)) {
cp[0] = '/';
if (cp[2] == 0)
cp[1] = 0;
else
memmove (cp+1, cp+3, strlen (cp+3) + 1);
cp++;
} else if (cp[-1] == ':') {
if (cp[2] == 0)
cp[0] = 0;
else
memmove (cp, cp+3, strlen (cp+3) + 1);
} else {
char *back = cp - 2;
while (back > buf && *back != '/' && *back != ':')
back--;
if (*back == '/' || *back == ':')
back++;
if (cp[2] == 0)
*back = 0;
else
memmove (back, cp+3, strlen (cp+3) + 1);
cp = back;
}
} else {
while (*cp != '/' && *cp != 0)
cp++;
if (*cp)
cp++;
}
}
}