Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 1881 → Rev 1882

/programs/develop/libraries/menuetlibc/src/libc/dos/dir/Makefile
0,0 → 1,4
THIS_SRCS = findfirs.c findnext.c fnmerge.c fnsplit.c ftreewlk.c \
ftw.c getdisk.c setdisk.c srchpath.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/findfirs.c
0,0 → 1,12
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <dir.h>
#include <libc/dosio.h>
 
int findfirst(const char *pathname, struct ffblk *ffblk, int attrib)
{
return -1;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/findnext.c
0,0 → 1,12
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <dir.h>
#include <libc/dosio.h>
 
int findnext(struct ffblk *ffblk)
{
return -1;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/fnmerge.c
0,0 → 1,32
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dir.h>
#include <string.h>
 
void
fnmerge (char *path, const char *drive, const char *dir,
const char *name, const char *ext)
{
*path = '\0';
if (drive && *drive)
{
path[0] = drive[0];
path[1] = ':';
path[2] = 0;
}
if (dir && *dir)
{
char last_dir_char = dir[strlen(dir) - 1];
 
strcat(path, dir);
if (last_dir_char != '/' && last_dir_char != '\\')
strcat(path, strchr(dir, '\\') ? "\\" : "/");
}
if (name)
strcat(path, name);
if (ext && *ext)
{
if (*ext != '.')
strcat(path, ".");
strcat(path, ext);
}
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/fnsplit.c
0,0 → 1,120
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dir.h>
#include <ctype.h>
#include <string.h>
 
static char *
max_ptr(char *p1, char *p2)
{
if (p1 > p2)
return p1;
else
return p2;
}
 
int
fnsplit (const char *path, char *drive, char *dir,
char *name, char *ext)
{
int flags = 0, len;
const char *pp, *pe;
 
if (drive)
*drive = '\0';
if (dir)
*dir = '\0';
if (name)
*name = '\0';
if (ext)
*ext = '\0';
 
pp = path;
 
if ((isalpha(*pp) || strchr("[\\]^_`", *pp)) && (pp[1] == ':'))
{
flags |= DRIVE;
if (drive)
{
strncpy(drive, pp, 2);
drive[2] = '\0';
}
pp += 2;
}
 
pe = max_ptr(strrchr(pp, '\\'), strrchr(pp, '/'));
if (pe)
{
flags |= DIRECTORY;
pe++;
len = pe - pp;
if (dir)
{
strncpy(dir, pp, len);
dir[len] = '\0';
}
pp = pe;
}
else
pe = pp;
 
/* Special case: "c:/path/." or "c:/path/.."
These mean FILENAME, not EXTENSION. */
while (*pp == '.')
++pp;
if (pp > pe)
{
flags |= FILENAME;
if (name)
{
len = pp - pe;
strncpy(name, pe, len);
name[len] = '\0';
}
}
 
pe = strrchr(pp, '.');
if (pe)
{
flags |= EXTENSION;
if (ext)
strcpy(ext, pe);
}
else
pe = strchr( pp, '\0');
 
if (pp != pe)
{
flags |= FILENAME;
len = pe - pp;
if (name)
{
strncpy(name, pp, len);
name[len] = '\0';
}
}
 
if (strcspn(path, "*?[") < strlen(path))
flags |= WILDCARDS;
 
return flags;
}
 
#ifdef TEST
 
#include <stdio.h>
 
int
main(void)
{
char arg[81], drive[81], dir[81], fname[81], ext[81];
 
fputs("> ", stdout); fflush(stdout);
gets(arg);
 
printf("`%s' (%x): `%s' `%s' `%s' `%s'\n", arg,
fnsplit(arg, drive, dir, fname, ext), drive, dir, fname, ext);
 
return 0;
}
 
#endif
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/ftreewlk.c
0,0 → 1,171
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* Recursively descent the directory hierarchy rooted in DIR,
* calling FUNC for each object in the hierarchy. We cannot
* use ftw(), because it uses some non-ANSI functions which
* will pollute ANSI namespace, while we need this function
* in some ANSI functions (e.g., rename()). Thus, this function
* is closely modeled on ftw(), but uses DOS directory search
* functions and structures instead of opendir()/readdir()/stat().
*
* Copyright (c) 1995 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely as long as this copyright notice is
* left intact. There is no warranty on this software.
*
*/
 
#include <libc/stubs.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <dir.h>
 
#define FA_ALL (FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_LABEL|FA_DIREC|FA_ARCH)
 
int
__file_tree_walk(const char *dir,
int (*func)(const char *, const struct ffblk *))
{
struct ffblk ff;
unsigned char searchspec[FILENAME_MAX];
unsigned char found[FILENAME_MAX], *dir_end;
int e = errno;
 
if (dir == 0 || func == 0)
{
errno = EFAULT;
return -1;
}
 
if (*dir == '\0')
{
errno = ENOENT;
return -1;
}
 
/* Construct the search spec for findfirst(). Treat ``d:'' as ``d:.''. */
strcpy(searchspec, dir);
dir_end = searchspec + strlen(searchspec) - 1;
if (*dir_end == ':')
{
*++dir_end = '.';
*++dir_end = '\0';
}
else if (*dir_end == '/' || *dir_end == '\\')
*dir_end = '\0';
else
++dir_end;
strcpy(dir_end, "/*.*");
 
/* Prepare the buffer where the full pathname of the found files
will be placed. */
strcpy(found, dir);
dir_end = found + strlen(found) - 1;
if (*dir_end == ':')
{
*++dir_end = '.';
dir_end[1] = '\0';
}
if (*dir_end != '/' && *dir_end != '\\')
{
/* Try to preserve user's forward/backward slash style. */
*++dir_end = strchr(found, '\\') == 0 ? '/': '\\';
*++dir_end = '\0';
}
else
++dir_end;
 
if (findfirst(searchspec, &ff, FA_ALL))
return -1;
 
do
{
int func_result;
unsigned char *p = dir_end;
 
/* Skip `.' and `..' entries. */
if (ff.ff_name[0] == '.' &&
(ff.ff_name[1] == '\0' || ff.ff_name[1] == '.'))
continue;
 
/* Construct full pathname in FOUND[]. */
strcpy(dir_end, ff.ff_name);
 
/* Convert name of found file to lower-case. Cannot use
strlwr() because it's non-ANSI. Sigh... */
while (*p)
*p++ = tolower(*p);
 
/* Invoke FUNC() on this file. */
if ((func_result = (*func)(found, &ff)) != 0)
return func_result;
 
/* If this is a directory, walk its siblings. */
if (ff.ff_attrib & 0x10)
{
int subwalk_result;
 
if ((subwalk_result = __file_tree_walk(found, func)) != 0)
return subwalk_result;
}
} while (findnext(&ff) == 0);
 
if (errno == ENMFILE) /* normal case: tree exhausted */
{
errno = e; /* restore errno from previous syscall */
return 0;
}
 
return -1; /* error; errno set by findnext() */
}
 
#ifdef TEST
 
#include <stdlib.h>
 
int
ff_walker(const char *path, const struct ffblk *ff)
{
printf("%s:\t%lu\t", path, ff->ff_fsize);
if (ff->ff_attrib & 1)
printf("R");
if (ff->ff_attrib & 2)
printf("H");
if (ff->ff_attrib & 4)
printf("S");
if (ff->ff_attrib & 8)
printf("V");
if (ff->ff_attrib & 0x10)
printf("D");
if (ff->ff_attrib & 0x20)
printf("A");
printf("\n");
 
if (strcmp(ff->ff_name, "XXXXX") == 0)
return 8;
return 0;
}
 
int
main(int argc, char *argv[])
{
if (argc > 1)
{
char msg[80];
 
sprintf(msg, "file_tree_walk: %d",
file_tree_walk(argv[1], ff_walker));
if (errno)
perror(msg);
else
puts(msg);
}
else
printf("Usage: %s dir\n", argv[0]);
 
return 0;
}
 
#endif
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/ftw.c
0,0 → 1,220
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* ftw() for DJGPP.
*
* Recursively descent the directory hierarchy rooted in DIR,
* calling FUNC for each object in the hierarchy.
*
* Copyright (c) 1995 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely as long as this copyright notice is
* left intact. There is no warranty on this software.
*
*/
 
#include <libc/stubs.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <sys/stat.h>
#include <dirent.h>
#include <io.h>
#include <ftw.h>
 
static int
walk_dir(char *path, int (*func)(const char *, struct stat *, int))
{
DIR *dp;
struct dirent *de;
struct stat stbuf;
int flag;
int e = errno;
int pathlen = strlen(path);
 
if ((dp = opendir(path)) == 0)
return -1;
 
for (errno = 0; (de = readdir(dp)) != 0; errno = 0)
{
int func_result;
char lastc = de->d_name[de->d_namlen - 1];
 
/* Skip `.' and `..' entries. Checking the last char is enough,
because readdir will never return a filename which ends with
a dot. */
if (lastc == '.')
continue;
 
/* Append found name to directory path. */
if (pathlen + de->d_namlen + 1 > FILENAME_MAX)
{
(void)closedir(dp);
errno = ENAMETOOLONG;
return -1;
}
if (path[pathlen-1] == '/' || path[pathlen-1] == '\\')
pathlen--;
path[pathlen] = '/';
strcpy(path + pathlen + 1, de->d_name);
 
if (stat(path, &stbuf) < 0)
flag = FTW_NS;
else if (S_ISDIR(stbuf.st_mode))
flag = FTW_D;
else if (S_ISLABEL(stbuf.st_mode))
flag = FTW_VL;
else
flag = FTW_F;
 
/* Invoke FUNC() on this object. */
errno = e;
if ((func_result = (*func)(path, &stbuf, flag)) != 0)
{
(void)closedir(dp);
return func_result;
}
 
/* If this is a directory, walk its siblings. */
if (flag == FTW_D)
{
int subwalk_result;
 
errno = e;
if ((subwalk_result = walk_dir(path, func)) != 0)
{
(void)closedir(dp);
return subwalk_result;
}
}
 
/* Erase D_NAME[] from PATH. */
path[pathlen] = '\0';
}
 
(void)closedir(dp);
if (errno == 0) /* normal case: this subtree exhausted */
{
errno = e;/* restore errno from previous syscall */
return 0;
}
else
return -1; /* with whatever errno was set by readdir() */
}
 
int
ftw(const char *dir, int (*func)(const char *, struct stat *, int),
int ignored)
{
int flag;
unsigned char pathbuf[FILENAME_MAX];
int dirattr;
int len;
int e = errno;
 
ignored = ignored; /* pacify -Wall */
 
if (dir == 0 || func == 0)
{
errno = EFAULT;
return -1;
}
 
if (*dir == '\0')
{
errno = ENOENT;
return -1;
}
 
strcpy(pathbuf, dir);
len = strlen(pathbuf);
if (pathbuf[len-1] == ':')
{
pathbuf[len++] = '.';
pathbuf[len] = '\0';
}
 
/* Fail for non-directories. */
errno = 0;
dirattr = _chmod(pathbuf, 0, 0);
if (errno == ENOENT)
return -1;
else if ((dirattr & 0x10) != 0x10)
{
errno = ENOTDIR;
return -1;
}
else
{
int func_result;
struct stat stbuf;
 
if (stat(pathbuf, &stbuf) < 0)
flag = FTW_NS;
else
flag = FTW_D;
errno = e;
if ((func_result = (*func)(pathbuf, &stbuf, flag)) != 0)
return func_result;
return walk_dir(pathbuf, func);
}
}
 
#ifdef TEST
 
#include <stdlib.h>
 
int
ftw_walker(const char *path, struct stat *sb, int flag)
{
char *base;
 
printf("%s:\t%u\t", path, sb->st_size);
if (S_ISLABEL(sb->st_mode))
printf("V");
if (S_ISDIR(sb->st_mode))
printf("D");
if (S_ISCHR(sb->st_mode))
printf("C");
if (sb->st_mode & S_IRUSR)
printf("r");
if (sb->st_mode & S_IWUSR)
printf("w");
if (sb->st_mode & S_IXUSR)
printf("x");
 
if (flag == FTW_NS)
printf(" !!no_stat!!");
printf("\n");
 
base = strrchr(path, '/');
if (base == 0)
base = strrchr(path, '\\');
if (base == 0)
base = strrchr(path, ':');
if (strcmp(base == 0 ? path : base + 1, "xxxxx") == 0)
return 8;
return 0;
}
 
int
main(int argc, char *argv[])
{
if (argc > 1)
{
char msg[80];
 
sprintf(msg, "file_tree_walk: %d",
ftw(argv[1], ftw_walker, 0));
if (errno)
perror(msg);
else
puts(msg);
}
else
printf("Usage: %s dir\n", argv[0]);
 
return 0;
}
 
#endif
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/getdisk.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <dir.h>
 
int getdisk(void)
{
return 0;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/setdisk.c
0,0 → 1,7
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dir.h>
 
int setdisk(int _drive)
{
return -1;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/srchpath.c
0,0 → 1,92
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <limits.h>
#include <dir.h>
/* Search PATH for FILE.
If successful, store the full pathname in static buffer and return a
pointer to it.
If not sucessful, return NULL.
This is what the Borland searchpath() library function does.
*/
char *
searchpath(const char *file)
{
static char found[PATH_MAX];
static char *path;
 
memset(found, 0, sizeof(found));
/* Get the PATH and store it for reuse. */
if (path == 0)
{
char *p = getenv("PATH");
path = (char *)calloc(p ? strlen(p) + 3 : 2, sizeof(char));
if (path == (char *)0)
return (char *)0;
/* Prepend `.' to the PATH, so current directory
is always searched. */
path[0] = '.';
if (p)
{
register char *s;
path[1] = ';';
strcpy(path+2, p);
/* Convert to more plausible form. */
for (s = path; *s; ++s)
{
if (*s == '\\')
*s = '/';
if (isupper(*s))
*s = tolower(*s);
}
}
else
path[1] = 0;
}
if (strpbrk (file, "/\\:") != 0)
{
strcpy(found, file);
return found;
}
else
{
char *test_dir = path;
do {
char *dp;
dp = strchr(test_dir, ';');
if (dp == (char *)0)
dp = test_dir + strlen(test_dir);
if (dp == test_dir)
strcpy(found, file);
else
{
strncpy(found, test_dir, dp - test_dir);
found[dp - test_dir] = '/';
strcpy(found + (dp - test_dir) + 1, file);
}
 
if (__file_exists(found))
return found;
 
if (*dp == 0)
break;
test_dir = dp + 1;
} while (*test_dir != 0);
}
return NULL;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property