From 419b1c5759f9323d49fb93d6e8699feed084c7b4 Mon Sep 17 00:00:00 2001 From: Casper Hornstrup Date: Sun, 25 May 2003 11:33:58 +0000 Subject: [PATCH] 2003-05-25 Casper S. Hornstrup * Makefile: Don't install system.hiv. Install fonts and nls directory. * tools/rcopy.c (copy_file, copy_directory, is_directory): New functions. svn path=/trunk/; revision=4752 --- reactos/ChangeLog | 5 + reactos/Makefile | 33 ++---- reactos/tools/rcopy.c | 248 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 244 insertions(+), 42 deletions(-) diff --git a/reactos/ChangeLog b/reactos/ChangeLog index 4699b02ad37..22682221ba2 100644 --- a/reactos/ChangeLog +++ b/reactos/ChangeLog @@ -1,3 +1,8 @@ +2003-05-25 Casper S. Hornstrup + + * Makefile: Don't install system.hiv. Install fonts and nls directory. + * tools/rcopy.c (copy_file, copy_directory, is_directory): New functions. + 2003-05-17 Casper S. Hornstrup * ntoskrnl/io/irp.c (IofCallDriver): Don't reference FileObject. diff --git a/reactos/Makefile b/reactos/Makefile index 0ce2e3fa0ff..b823918ff45 100644 --- a/reactos/Makefile +++ b/reactos/Makefile @@ -748,19 +748,8 @@ install_before: $(RLINE) bootdata/hivesft.inf $(INSTALL_DIR)/hivesft.inf $(RLINE) bootdata/hivesys.inf $(INSTALL_DIR)/hivesys.inf $(RLINE) bootdata/txtsetup.sif $(INSTALL_DIR)/txtsetup.sif - $(CP) system.hiv $(INSTALL_DIR)/system.hiv - $(CP) media/fonts/helb____.ttf $(INSTALL_DIR)/helb____.ttf - $(CP) media/fonts/timr____.ttf $(INSTALL_DIR)/timr____.ttf - $(CP) media/fonts/Vera.ttf $(INSTALL_DIR)/Vera.ttf - $(CP) media/fonts/VeraBd.ttf $(INSTALL_DIR)/VeraBd.ttf - $(CP) media/fonts/VeraBI.ttf $(INSTALL_DIR)/VeraBI.ttf - $(CP) media/fonts/VeraIt.ttf $(INSTALL_DIR)/VeraIt.ttf - $(CP) media/fonts/VeraMoBd.ttf $(INSTALL_DIR)/VeraMoBd.ttf - $(CP) media/fonts/VeraMoBI.ttf $(INSTALL_DIR)/VeraMoBI.ttf - $(CP) media/fonts/VeraMoIt.ttf $(INSTALL_DIR)/VeraMoIt.ttf - $(CP) media/fonts/VeraMono.ttf $(INSTALL_DIR)/VeraMono.ttf - $(CP) media/fonts/VeraSe.ttf $(INSTALL_DIR)/VeraSe.ttf - $(CP) media/fonts/VeraSeBd.ttf $(INSTALL_DIR)/VeraSeBd.ttf + $(CP) media/fonts $(INSTALL_DIR) + $(CP) media/nls $(INSTALL_DIR) else # BOOTCD_INSTALL @@ -778,19 +767,11 @@ install_before: $(CP) bootc.lst $(INSTALL_DIR)/bootc.lst $(CP) boot.bat $(INSTALL_DIR)/boot.bat $(CP) aboot.bat $(INSTALL_DIR)/aboot.bat - $(CP) system.hiv $(INSTALL_DIR)/system32/config/system.hiv - $(CP) media/fonts/helb____.ttf $(INSTALL_DIR)/media/fonts/helb____.ttf - $(CP) media/fonts/timr____.ttf $(INSTALL_DIR)/media/fonts/timr____.ttf - $(CP) media/fonts/Vera.ttf $(INSTALL_DIR)/media/fonts/Vera.ttf - $(CP) media/fonts/VeraBd.ttf $(INSTALL_DIR)/media/fonts/VeraBd.ttf - $(CP) media/fonts/VeraBI.ttf $(INSTALL_DIR)/media/fonts/VeraBI.ttf - $(CP) media/fonts/VeraIt.ttf $(INSTALL_DIR)/media/fonts/VeraIt.ttf - $(CP) media/fonts/VeraMoBd.ttf $(INSTALL_DIR)/media/fonts/VeraMoBd.ttf - $(CP) media/fonts/VeraMoBI.ttf $(INSTALL_DIR)/media/fonts/VeraMoBI.ttf - $(CP) media/fonts/VeraMoIt.ttf $(INSTALL_DIR)/media/fonts/VeraMoIt.ttf - $(CP) media/fonts/VeraMono.ttf $(INSTALL_DIR)/media/fonts/VeraMono.ttf - $(CP) media/fonts/VeraSe.ttf $(INSTALL_DIR)/media/fonts/VeraSe.ttf - $(CP) media/fonts/VeraSeBd.ttf $(INSTALL_DIR)/media/fonts/VeraSeBd.ttf + $(CP) media/fonts $(INSTALL_DIR)/media/fonts + $(CP) media/nls $(INSTALL_DIR)/system32 + $(CP) media/nls/c_1252.nls $(INSTALL_DIR)/system32/ansi.nls + $(CP) media/nls/c_437.nls $(INSTALL_DIR)/system32/oem.nls + $(CP) media/nls/l_intl.nls $(INSTALL_DIR)/system32/casemap.nls endif # BOOTCD_INSTALL diff --git a/reactos/tools/rcopy.c b/reactos/tools/rcopy.c index a285ff37786..77fbe57ebe9 100644 --- a/reactos/tools/rcopy.c +++ b/reactos/tools/rcopy.c @@ -1,6 +1,26 @@ #include #include #include +#include +#ifdef WIN32 +#include +#include +#else +#include +#include +#include +#include +#endif +#ifndef WIN32 +#ifndef MAX_PATH +#define MAX_PATH 260 +#endif +#define DIR_SEPARATOR_CHAR '/' +#define DIR_SEPARATOR_STRING "/" +#else +#define DIR_SEPARATOR_CHAR '\\' +#define DIR_SEPARATOR_STRING "\\" +#endif char* convert_path(char* origpath) { @@ -32,25 +52,15 @@ char* convert_path(char* origpath) #define TRANSFER_SIZE (65536) -int main(int argc, char* argv[]) +static void +copy_file(char* path1, char* path2) { - char* path1; - char* path2; FILE* in; FILE* out; char* buf; int n_in; int n_out; - - if (argc != 3) - { - fprintf(stderr, "Too many arguments\n"); - exit(1); - } - - path1 = convert_path(argv[1]); - path2 = convert_path(argv[2]); - + in = fopen(path1, "rb"); if (in == NULL) { @@ -58,8 +68,6 @@ int main(int argc, char* argv[]) exit(1); } - - out = fopen(path2, "wb"); if (out == NULL) { @@ -69,7 +77,6 @@ int main(int argc, char* argv[]) } buf = malloc(TRANSFER_SIZE); - while (!feof(in)) { n_in = fread(buf, 1, TRANSFER_SIZE, in); @@ -83,5 +90,214 @@ int main(int argc, char* argv[]) exit(1); } } +} + +#ifdef WIN32 + +static void +copy_directory (char *path1, char *path2) +{ + struct _finddata_t f; + int findhandle; + char buf[MAX_PATH]; + char tobuf[MAX_PATH]; + + strcpy(buf, path1); + if (path1[strlen(path1) - 1] != DIR_SEPARATOR_CHAR) + strcat(buf, DIR_SEPARATOR_STRING); + strcat(buf, "*.*"); + findhandle =_findfirst(buf, &f); + if (findhandle != 0) + { + do + { + if ((f.attrib & _A_SUBDIR) == 0 && f.name[0] != '.') + { + // Check for an absolute path + if (path1[0] == DIR_SEPARATOR_CHAR) + { + strcpy(buf, path1); + strcat(buf, DIR_SEPARATOR_STRING); + strcat(buf, f.name); + } + else + { + getcwd(buf, sizeof(buf)); + strcat(buf, DIR_SEPARATOR_STRING); + strcat(buf, path1); + if (path1[strlen(path1) - 1] != DIR_SEPARATOR_CHAR) + strcat(buf, DIR_SEPARATOR_STRING); + strcat(buf, f.name); + } + + //printf("copying file %s\n", buf); + if (path2[strlen(path2) - 1] == DIR_SEPARATOR_CHAR) + { + strcpy(tobuf, path2); + strcat(tobuf, f.name); + } + else + { + strcpy(tobuf, path2); + strcat(tobuf, DIR_SEPARATOR_STRING); + strcat(tobuf, f.name); + } + copy_file(buf, tobuf); + } + else + { + //printf("skipping directory '%s'\n", f.name); + } + } + while (_findnext(findhandle, &f) == 0); + + _findclose(findhandle); + } +} + +#else + +/* Linux version */ +static void +copy_directory (char *path1, char *path2) +{ + DIR *dirp; + struct dirent *entry; + char *old_end_source; + struct stat stbuf; + char buf[MAX_PATH]; + char tobuf[MAX_PATH]; + char err[400]; + + dirp = opendir(path1); + + if (dirp != NULL) + { + while ((entry = readdir (dirp)) != NULL) + { + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) + continue; // skip self and parent + + if (entry->d_type == DT_REG) // normal file + { + // Check for an absolute path + if (path1[0] == DIR_SEPARATOR_CHAR) + { + strcpy(buf, path1); + strcat(buf, DIR_SEPARATOR_STRING); + strcat(buf, entry->d_name); + } + else + { + getcwd(buf, sizeof(buf)); + strcat(buf, DIR_SEPARATOR_STRING); + strcat(buf, path1); + if (path1[strlen(path1) - 1] != DIR_SEPARATOR_CHAR) + strcat(buf, DIR_SEPARATOR_STRING); + strcat(buf, entry->d_name); + } + if (stat(buf, &stbuf) == -1) + { + sprintf(err, "Can't access '%s' (%s)\n", buf, strerror(errno)); + perror(err); + exit(1); + return; + } + + //printf("copying file '%s'\n", entry->d_name); + if (path2[strlen(path2) - 1] == DIR_SEPARATOR_CHAR) + { + strcpy(tobuf, path2); + strcat(tobuf, entry->d_name); + } + else + { + strcpy(tobuf, path2); + strcat(tobuf, DIR_SEPARATOR_STRING); + strcat(tobuf, entry->d_name); + } + copy_file(buf, tobuf); + } + else + { + //printf("skipping directory '%s'\n", entry->d_name); + } + } + closedir (dirp); + } + else + { + sprintf(err, "Can't open %s\n", path1); + perror(err); + exit(1); + return; + } +} + +#endif + +static int +is_directory(char *path) +{ + struct stat stbuf; + char buf[MAX_PATH]; + char err[400]; + + // Check for an absolute path + if (path[0] == DIR_SEPARATOR_CHAR) + { + strcpy(buf, path); + } + else + { + getcwd(buf, sizeof(buf)); + strcat(buf, DIR_SEPARATOR_STRING); + strcat(buf, path); + } + if (stat(buf, &stbuf) == -1) + { + /* Assume a destination file */ + return 0; + } + if (S_ISDIR(stbuf.st_mode)) + return 1; + else + return 0; +} + +int main(int argc, char* argv[]) +{ + char* path1; + char* path2; + int dir1; + int dir2; + + if (argc != 3) + { + fprintf(stderr, "Wrong argument count\n"); + exit(1); + } + + path1 = convert_path(argv[1]); + path2 = convert_path(argv[2]); + + dir1 = is_directory(path1); + dir2 = is_directory(path2); + + if ((dir1 && !dir2) || (!dir1 && dir2)) + { + perror("None or both paramters must be a directory\n"); + exit(1); + } + + if (dir1) + { + copy_directory(path1, path2); + } + else + { + copy_file(path1, path2); + } + exit(0); }