Author: akhaldi Date: Wed Jan 13 16:08:08 2016 New Revision: 70587
URL: http://svn.reactos.org/svn/reactos?rev=70587&view=rev Log: [0.4.0] * Merge the cdmake work by Hermès in revisions 70552, 70553 and 70554.
Modified: branches/ros-branch-0_4_0/ (props changed) branches/ros-branch-0_4_0/reactos/ (props changed) branches/ros-branch-0_4_0/reactos/tools/cdmake/cdmake.c branches/ros-branch-0_4_0/reactos/tools/cdmake/dirhash.c branches/ros-branch-0_4_0/reactos/tools/cdmake/dirhash.h
Propchange: branches/ros-branch-0_4_0/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Wed Jan 13 16:08:08 2016 @@ -1 +1 @@ -/trunk:70000-70321,70323-70324,70328-70337,70339-70340,70347,70349,70354-70358,70360,70363,70369,70373,70375-70378,70381,70384-70385,70387-70389,70398,70400,70408,70424,70433-70437,70443,70445-70449,70464,70468,70470,70480,70497,70499-70501,70507-70510,70512-70513,70523,70527-70530,70557-70558,70576,70583 +/trunk:70000-70321,70323-70324,70328-70337,70339-70340,70347,70349,70354-70358,70360,70363,70369,70373,70375-70378,70381,70384-70385,70387-70389,70398,70400,70408,70424,70433-70437,70443,70445-70449,70464,70468,70470,70480,70497,70499-70501,70507-70510,70512-70513,70523,70527-70530,70552-70554,70557-70558,70576,70583
Propchange: branches/ros-branch-0_4_0/reactos/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Wed Jan 13 16:08:08 2016 @@ -20,4 +20,4 @@ /branches/usb-bringup:51335,51337,51341-51343,51348,51350,51353,51355,51365-51369,51372,51384-54388,54396-54398,54736-54737,54752-54754,54756-54760,54762,54764-54765,54767-54768,54772,54774-54777,54781,54787,54790-54792,54797-54798,54806,54808,54834-54838,54843,54850,54852,54856,54858-54859 /branches/usb-bringup-trunk:55019-55543,55548-55554,55556-55567 /branches/wlan-bringup:54809-54998 -/trunk/reactos:70000-70321,70323-70324,70328-70337,70339-70340,70347,70349,70354-70358,70360,70363,70369,70373,70375-70378,70381,70384-70385,70387-70389,70398,70400,70408,70424,70433-70437,70443,70445-70449,70464,70468,70470,70480,70497,70501,70507-70510,70523,70527-70530,70557-70558,70576,70583 +/trunk/reactos:70000-70321,70323-70324,70328-70337,70339-70340,70347,70349,70354-70358,70360,70363,70369,70373,70375-70378,70381,70384-70385,70387-70389,70398,70400,70408,70424,70433-70437,70443,70445-70449,70464,70468,70470,70480,70497,70501,70507-70510,70523,70527-70530,70552-70554,70557-70558,70576,70583
Modified: branches/ros-branch-0_4_0/reactos/tools/cdmake/cdmake.c URL: http://svn.reactos.org/svn/reactos/branches/ros-branch-0_4_0/reactos/tools/c... ============================================================================== --- branches/ros-branch-0_4_0/reactos/tools/cdmake/cdmake.c [iso-8859-1] (original) +++ branches/ros-branch-0_4_0/reactos/tools/cdmake/cdmake.c [iso-8859-1] Wed Jan 13 16:08:08 2016 @@ -619,7 +619,7 @@
#if defined(_WIN32) && !defined(strcasecmp) #define strcasecmp stricmp -#endif//_WIN32 +#endif // _WIN32
static BOOL cdname_exists(PDIR_RECORD d) { @@ -696,7 +696,7 @@ filename_counter = 1; while (cdname_exists(d)) { - // the file name must be least 8 char long + // the file name must be at least 8 chars long if (strlen(d->name_on_cd)<8) error_exit("'%s' is a duplicate file name, aborting...", filename);
@@ -704,7 +704,9 @@ error_exit("'%s' is a duplicate file name, aborting...", filename);
// max 255 times for equal short filename - if (filename_counter>255) error_exit("'%s' is a duplicate file name, aborting...", filename); + if (filename_counter>255) + error_exit("'%s' is a duplicate file name, aborting...", filename); + d->name_on_cd[8] = '~'; memset(&d->name_on_cd[9],0,5); sprintf(&d->name_on_cd[9],"%d",filename_counter); @@ -729,7 +731,7 @@ for the specified parent and returns a pointer to the new record. -----------------------------------------------------------------------------*/
-#if _WIN32 +#ifdef _WIN32
/* Win32 version */ PDIR_RECORD @@ -1167,7 +1169,7 @@ return new_d; }
-#if _WIN32 +#ifdef _WIN32 static BOOL get_cd_file_time(HANDLE handle, PDATE_AND_TIME cd_time_info) { @@ -1195,7 +1197,7 @@ scan_specified_files(PDIR_RECORD d, struct target_dir_entry *dir) { PDIR_RECORD new_d; -#if _WIN32 +#ifdef _WIN32 HANDLE open_file; LARGE_INTEGER file_size; #else @@ -1210,7 +1212,7 @@ { if (strcmp(file->target_name, DIRECTORY_TIMESTAMP) == 0) { -#if _WIN32 +#ifdef _WIN32 if ((open_file = CreateFileA(file->source_name, GENERIC_READ, FILE_SHARE_READ, @@ -1246,7 +1248,7 @@ } new_d = new_empty_dirrecord(d, FALSE); parse_filename_into_dirrecord(file->target_name, new_d, FALSE); -#if _WIN32 +#ifdef _WIN32 if ((open_file = CreateFileA(file->source_name, GENERIC_READ, FILE_SHARE_READ, @@ -1271,7 +1273,7 @@ #else if (stat(file->source_name, &stbuf) == -1) { - error_exit("Cannot find '%s' (target %s)\n", + error_exit("Cannot find '%s' (target '%s')\n", file->source_name, file->target_name); } @@ -2241,13 +2243,13 @@ } else { - char *trimmedline, *targetname, *srcname, *eq, *normdir; + char *trimmedline, *targetname, *normdir, *srcname, *eq; char lineread[1024];
FILE *f = fopen(source+1, "r"); if (!f) { - error_exit("Cannot open cd description %s\n", source+1); + error_exit("Cannot open CD-ROM file description %s\n", source+1); } while (fgets(lineread, sizeof(lineread), f)) { @@ -2268,17 +2270,17 @@ targetname = strtok(lineread, "="); srcname = strtok(NULL, "");
-#if _WIN32 +#ifdef _WIN32 if (_access(srcname, R_OK) == 0) - dir_hash_add_file(&specified_files, srcname, targetname); - else - error_exit("Cannot access file '%s' (target %s)\n", srcname, targetname); #else if (access(srcname, R_OK) == 0) - dir_hash_add_file(&specified_files, srcname, targetname); +#endif + { + if (!dir_hash_add_file(&specified_files, srcname, targetname)) + error_exit("Target '%s' (file '%s') is invalid\n", targetname, srcname); + } else - error_exit("Cannot access file '%s' (target %s)\n", srcname, targetname); -#endif + error_exit("Cannot access file '%s' (target '%s')\n", srcname, targetname); } } fclose(f);
Modified: branches/ros-branch-0_4_0/reactos/tools/cdmake/dirhash.c URL: http://svn.reactos.org/svn/reactos/branches/ros-branch-0_4_0/reactos/tools/c... ============================================================================== --- branches/ros-branch-0_4_0/reactos/tools/cdmake/dirhash.c [iso-8859-1] (original) +++ branches/ros-branch-0_4_0/reactos/tools/cdmake/dirhash.c [iso-8859-1] Wed Jan 13 16:08:08 2016 @@ -5,12 +5,17 @@ * PURPOSE: CD-ROM Premastering Utility - Directory names hashing * PROGRAMMERS: Art Yerkes */ + #include <string.h> #include <stdlib.h> #include <ctype.h> #include "config.h" #include "dirhash.h"
+#ifndef max +#define max(a, b) ((a) > (b) ? (a) : (b)) +#endif + /* This is the famous DJB hash */ static unsigned int djb_hash(const char *name) @@ -26,59 +31,33 @@ return val; }
-static const char * -chop_filename(const char *target) -{ - char *last_slash = strrchr(target, '/'); - if (!last_slash) - last_slash = strrchr(target, '\'); - if (last_slash) - return last_slash + 1; +static void +split_path(const char *path, char **dirname, char **filename /* OPTIONAL */) +{ + const char *result; + + /* Retrieve the file name */ + char *last_slash_1 = strrchr(path, '/'); + char *last_slash_2 = strrchr(path, '\'); + + if (last_slash_1 || last_slash_2) + result = max(last_slash_1, last_slash_2) + 1; else - return target; -} - -static void -chop_dirname(const char *name, char **dirname) -{ - char *last_slash = strrchr(name, '/'); - if (!last_slash) - last_slash = strrchr(name, '\'); - if (!last_slash) - { - *dirname = malloc(1); - **dirname = 0; - } - else - { - char *newdata = malloc(last_slash - name + 1); - memcpy(newdata, name, last_slash - name); - newdata[last_slash - name] = 0; - *dirname = newdata; - } -} - -static struct target_dir_entry * -get_entry_by_normname(struct target_dir_hash *dh, const char *norm) -{ - unsigned int hashcode; - struct target_dir_entry *de; - hashcode = djb_hash(norm); - de = dh->buckets[hashcode % NUM_DIR_HASH_BUCKETS]; - while (de && strcmp(de->normalized_name, norm)) - de = de->next_dir_hash_entry; - return de; -} - -static void -delete_entry(struct target_dir_hash *dh, struct target_dir_entry *de) -{ - struct target_dir_entry **ent; - ent = &dh->buckets[de->hashcode % NUM_DIR_HASH_BUCKETS]; - while (*ent && ((*ent) != de)) - ent = &(*ent)->next_dir_hash_entry; - if (*ent) - *ent = (*ent)->next_dir_hash_entry; + result = path; + + /* Duplicate the file name for the user if needed */ + if (filename) + *filename = strdup(result); + + /* Remove any trailing directory separators */ + while (result > path && (*(result-1) == '/' || *(result-1) == '\')) + result--; + + /* Retrieve and duplicate the directory */ + *dirname = malloc(result - path + 1); + if (result > path) + memcpy(*dirname, path, result - path); + (*dirname)[result - path] = '\0'; // NULL-terminate }
void normalize_dirname(char *filename) @@ -109,20 +88,39 @@ } } } - filename[tgt] = 0; - - while (tgt && (filename[--tgt] == DIR_SEPARATOR_CHAR)) - { - filename[tgt] = 0; - } + filename[tgt] = '\0'; // NULL-terminate +} + +static struct target_dir_entry * +get_entry_by_normname(struct target_dir_hash *dh, const char *norm) +{ + unsigned int hashcode; + struct target_dir_entry *de; + hashcode = djb_hash(norm); + de = dh->buckets[hashcode % NUM_DIR_HASH_BUCKETS]; + while (de && strcmp(de->normalized_name, norm)) + de = de->next_dir_hash_entry; + return de; +} + +static void +delete_entry(struct target_dir_hash *dh, struct target_dir_entry *de) +{ + struct target_dir_entry **ent; + ent = &dh->buckets[de->hashcode % NUM_DIR_HASH_BUCKETS]; + while (*ent && ((*ent) != de)) + ent = &(*ent)->next_dir_hash_entry; + if (*ent) + *ent = (*ent)->next_dir_hash_entry; }
struct target_dir_entry * dir_hash_create_dir(struct target_dir_hash *dh, const char *casename, const char *targetnorm) { struct target_dir_entry *de, *parent_de; + char *parentcase = NULL; + char *case_name = NULL; char *parentname = NULL; - char *parentcase = NULL; struct target_dir_entry **ent;
if (!dh->root.normalized_name) @@ -133,20 +131,36 @@ dh->buckets[dh->root.hashcode % NUM_DIR_HASH_BUCKETS] = &dh->root; }
+ /* Check whether the directory was already created and just return it if so */ de = get_entry_by_normname(dh, targetnorm); if (de) return de;
- chop_dirname(targetnorm, &parentname); - chop_dirname(casename, &parentcase); + /* + * If *case_name == '\0' after the following call to split_path(...), + * for example in the case where casename == "subdir/dir/", then just + * create the directories "subdir" and "dir" by a recursive call to + * dir_hash_create_dir(...) and return 'parent_de' instead (see after). + * We do not (and we never) create a no-name directory inside it. + */ + split_path(casename, &parentcase, &case_name); + split_path(targetnorm, &parentname, NULL); parent_de = dir_hash_create_dir(dh, parentcase, parentname); free(parentname); free(parentcase);
+ /* See the remark above */ + if (!*case_name) + { + free(case_name); + return parent_de; + } + + /* Now create the directory */ de = calloc(1, sizeof(*de)); de->parent = parent_de; de->normalized_name = strdup(targetnorm); - de->case_name = strdup(chop_filename(casename)); + de->case_name = case_name; de->hashcode = djb_hash(targetnorm);
de->next = parent_de->child; @@ -154,33 +168,43 @@
ent = &dh->buckets[de->hashcode % NUM_DIR_HASH_BUCKETS]; while (*ent) - { ent = &(*ent)->next_dir_hash_entry; - } *ent = de;
return de; }
-void dir_hash_add_file(struct target_dir_hash *dh, const char *source, const char *target) +struct target_file * +dir_hash_add_file(struct target_dir_hash *dh, const char *source, const char *target) { struct target_file *tf; struct target_dir_entry *de; - char *targetdir = NULL; + char *targetdir = NULL; + char *targetfile = NULL; char *targetnorm;
- chop_dirname(target, &targetdir); + /* First create the directory; check whether the file name is valid and bail out if not */ + split_path(target, &targetdir, &targetfile); + if (!*targetfile) + { + free(targetdir); + free(targetfile); + return NULL; + } targetnorm = strdup(targetdir); normalize_dirname(targetnorm); de = dir_hash_create_dir(dh, targetdir, targetnorm); free(targetnorm); free(targetdir);
+ /* Now add the file */ tf = calloc(1, sizeof(*tf)); tf->next = de->head; de->head = tf; tf->source_name = strdup(source); - tf->target_name = strdup(chop_filename(target)); + tf->target_name = targetfile; + + return tf; }
static void
Modified: branches/ros-branch-0_4_0/reactos/tools/cdmake/dirhash.h URL: http://svn.reactos.org/svn/reactos/branches/ros-branch-0_4_0/reactos/tools/c... ============================================================================== --- branches/ros-branch-0_4_0/reactos/tools/cdmake/dirhash.h [iso-8859-1] (original) +++ branches/ros-branch-0_4_0/reactos/tools/cdmake/dirhash.h [iso-8859-1] Wed Jan 13 16:08:08 2016 @@ -5,6 +5,7 @@ * PURPOSE: CD-ROM Premastering Utility - Directory names hashing * PROGRAMMERS: Art Yerkes */ + #ifndef _DIRHASH_H_ #define _DIRHASH_H_
@@ -37,9 +38,13 @@ };
void normalize_dirname(char *filename); -void dir_hash_add_file(struct target_dir_hash *dh, const char *source, const char *target); + struct target_dir_entry * dir_hash_create_dir(struct target_dir_hash *dh, const char *casename, const char *targetnorm); + +struct target_file * +dir_hash_add_file(struct target_dir_hash *dh, const char *source, const char *target); + void dir_hash_destroy(struct target_dir_hash *dh);
#endif // _DIRHASH_H_