Index: CMakeLists.txt =================================================================== --- CMakeLists.txt (Revision 68688) +++ CMakeLists.txt (Arbeitskopie) @@ -15,7 +15,7 @@ add_subdirectory(cabman) add_subdirectory(cdmake) -# add_subdirectory(hhpcomp) +add_subdirectory(hhpcomp) add_subdirectory(hpp) add_subdirectory(kbdtool) add_subdirectory(mkhive) Index: hhpcomp/chmc/chmc.c =================================================================== --- hhpcomp/chmc/chmc.c (Revision 68688) +++ hhpcomp/chmc/chmc.c (Arbeitskopie) @@ -25,7 +25,19 @@ #include #include #include + +#if defined(_WIN32) +#include +#include +#include +#ifndef __GNUC__ +typedef int (*__compar_fn_t)(const void *, const void *); +#endif + +#else #include +#endif + #include "err.h" @@ -277,7 +289,7 @@ else strcat(section->filename, "chmcUXXXXXX"); - section->fd = mkstemp(section->filename); + section->fd = mkstemps(section->filename,0); fprintf(stderr, "temp file: %s\n", section->filename); if (section->fd < 0) { chmcerr_set(errno, strerror(errno)); @@ -608,7 +620,7 @@ { memcpy(d, s, len); - return d + len; + return (char*)d + len; } static void *chmc_syscat_entry(Int16 code, void *d, void *s, Int16 len) @@ -691,7 +703,7 @@ val = 0; p = chmc_syscat_entry(SIEC_INFOCHKSUM, p, &val, sizeof(val)); - system->_size = p - sysp; + system->_size = (char*)p - (char*)sysp; chmc_add_meta(chm, "/#SYSTEM", 0, sysp, system->_size); return CHMC_NOERR; } @@ -973,7 +985,7 @@ { struct chmcLzxInfo *lzx_info = (struct chmcLzxInfo *)arg; struct chmcSect0 *sect0 = &lzx_info->chm->sect0; - ssize_t wx; + int wx; wx = write(lzx_info->section->fd, buf, n); sect0->file_len += wx; @@ -1062,12 +1074,12 @@ // read input if (node->buf) { - memcpy(buf + (n - todo), &node->buf[lzx_info->fd_offset], toread); + memcpy((char*)buf + (n - todo), &node->buf[lzx_info->fd_offset], toread); rx = toread; } else { - rx = read(lzx_info->fd, buf + (n - todo), toread); + rx = read(lzx_info->fd, (char*)buf + (n - todo), toread); if (rx <= 0) { chmc_error("read error\n"); lzx_info->error = 2; @@ -1149,7 +1161,7 @@ if (reset_table) { memcpy(reset_table, §ion->reset_table_header, _CHMC_LZXC_RESETTABLE_V1_LEN); - at = (void *)reset_table + _CHMC_LZXC_RESETTABLE_V1_LEN; + at = (UInt64 *)reset_table + _CHMC_LZXC_RESETTABLE_V1_LEN; i = 0; list_for_each(pos, §ion->mark_list) { @@ -1212,7 +1224,7 @@ struct chmcSect0 *sect0 = &chm->sect0; struct chmcTreeNode *node; struct list_head *pos; - ssize_t wx; + int wx; list_for_each(pos, &chm->entries_list) { node = list_entry( pos, struct chmcTreeNode, list ); @@ -1312,8 +1324,8 @@ p = (void *)&chunk->data[pmgl->data_len]; if (should_idx) { - idx = (void *)&chunk->data[CHMC_PMGL_DATA_LEN] - pmgl->index_len; - *idx = (void *)p - (void *)&chunk->data; + idx = (UInt16 *)&chunk->data[CHMC_PMGL_DATA_LEN] - pmgl->index_len; + *idx = (char *)p - (char *)&chunk->data; } p += chmc_encint(name_len, p); @@ -1558,8 +1570,8 @@ p = (void *)&chunk->data[pmgi->data_len]; if (should_idx) { - idx = (void *)&chunk->data[CHMC_PMGI_DATA_LEN] - pmgi->index_len; - *idx = (void *)p - (void *)&chunk->data; + idx = (UInt16 *)&chunk->data[CHMC_PMGI_DATA_LEN] - pmgi->index_len; + *idx = (char *)p - (char *)&chunk->data; } p += chmc_encint(name_len, p); @@ -1629,7 +1641,7 @@ struct stat statbuf; int in; off_t todo, toread; - ssize_t rx; + int rx; if (stat(filename, &statbuf) < 0) return errno; Index: hhpcomp/chmc/chmc.h =================================================================== --- hhpcomp/chmc/chmc.h (Revision 68688) +++ hhpcomp/chmc/chmc.h (Arbeitskopie) @@ -27,6 +27,10 @@ #include "chm.h" #include "list.h" +#ifndef PATH_MAX +#define PATH_MAX 260 +#endif + #define CHMC_DIR_UUID \ "\x10\xfd\x01\x7c\xaa\x7b\xd0\x11\x9e\x0c\x00\xa0\xc9\x22\xe6\xec" #define CHMC_STREAM_UUID \ @@ -256,6 +260,6 @@ void chmc_term(struct chmcFile *chm); int chmc_tree_done(struct chmcFile *chm); -#define chmc_dump(fmt, args...) fprintf(stderr, fmt , ##args) +#define chmc_dump(fmt, ...) fprintf(stderr, fmt , ## __VA_ARGS__) #endif /* CHMC_CHMC_H */ Index: hhpcomp/chmc/err.h =================================================================== --- hhpcomp/chmc/err.h (Revision 68688) +++ hhpcomp/chmc/err.h (Arbeitskopie) @@ -22,13 +22,13 @@ #define CHMC_ERR_H #include -#define chmcerr_printf(fmt,args...) fprintf (stderr, fmt , ##args) +#define chmcerr_printf(fmt, ...) fprintf (stderr, fmt , ## __VA_ARGS__) #include -#define BUG_ON(fmt, args...) \ +#define BUG_ON(fmt, ...) \ do { \ fprintf (stderr, "%s:%d: ", __FILE__, __LINE__); \ - fprintf (stderr, fmt , ##args); \ + fprintf (stderr, fmt , ## __VA_ARGS__); \ abort (); \ } while (0) @@ -45,28 +45,28 @@ int chmcerr_code(void); const char *chmcerr_message(void); -#define chmc_error(fmt, args...) fprintf (stdout, fmt , ##args) +#define chmc_error(fmt, ...) fprintf (stdout, fmt , ## __VA_ARGS__) -#define chmcerr_return_msg(fmt,args...) \ +#define chmcerr_return_msg(fmt,...) \ do { \ chmcerr_printf ( "%s: %d: ", __FILE__, __LINE__ ); \ chmcerr_printf ( "error %d: ", chmcerr_code () ); \ - chmcerr_printf ( fmt , ##args ); \ + chmcerr_printf ( fmt , ## __VA_ARGS__ ); \ chmcerr_printf ( ": %s\n", chmcerr_message () ); \ return chmcerr_code (); \ } while (0) -#define chmcerr_msg(fmt,args...) \ +#define chmcerr_msg(fmt,...) \ do { \ chmcerr_printf ("%s: %d: ", __FILE__, __LINE__); \ chmcerr_printf ("error %d: ", chmcerr_code ()); \ - chmcerr_printf (fmt , ##args ); \ + chmcerr_printf (fmt , ## __VA_ARGS__ ); \ chmcerr_printf (": %s\n", chmcerr_message ()); \ } while (0) -#define chmcerr_set_return(code,fmt,args...) \ +#define chmcerr_set_return(code,fmt,...) \ do { \ - chmcerr_set ( (code), (fmt), ##args ); \ + chmcerr_set ( (code), (fmt), ## __VA_ARGS__ ); \ return (code); \ } while (0) Index: hhpcomp/CMakeLists.txt =================================================================== --- hhpcomp/CMakeLists.txt (Revision 68688) +++ hhpcomp/CMakeLists.txt (Arbeitskopie) @@ -6,10 +6,11 @@ chmc/chmc.c chmc/err.c lzx_compress/lz_nonslide.c - lzx_compress/lzx_layer.c) + lzx_compress/lzx_layer.c + port/mkstemps.c) # used by lzx_compress add_definitions(-DNONSLIDE) add_executable(hhpcomp ${SOURCE}) -target_link_libraries(hhpcomp m) +target_link_libraries(hhpcomp) Index: hhpcomp/hhp_reader.cpp =================================================================== --- hhpcomp/hhp_reader.cpp (Revision 68688) +++ hhpcomp/hhp_reader.cpp (Arbeitskopie) @@ -23,6 +23,10 @@ #include +#if defined(_WIN32) +#include //for GetFullPathNameA +#endif + #include "hhp_reader.h" #include "utils.h" @@ -217,7 +221,19 @@ { for (list::iterator it = files->filenames.begin(); it != files->filenames.end(); ++it) { - unique_file_pathes.insert(replace_backslashes(realpath(it->c_str()))); + char* temp = NULL; + #if defined(_WIN32) + char temp2[MAX_PATH]; + if (GetFullPathNameA(it->c_str(), MAX_PATH, temp2, NULL)) { + temp = temp2; + } + #else + temp = realpath(it->c_str(), NULL); + #endif + if (temp == NULL) { + throw runtime_error("problem getting the realpath for " + *it + "!"); + } + unique_file_pathes.insert(replace_backslashes(temp)); } } Index: hhpcomp/hhpcomp.cpp =================================================================== --- hhpcomp/hhpcomp.cpp (Revision 68688) +++ hhpcomp/hhpcomp.cpp (Arbeitskopie) @@ -23,11 +23,16 @@ #include #include -#include #include "hhp_reader.h" #include "utils.h" +#if defined(_WIN32) + #include +#else + #include +#endif + extern "C" { #include "chmc/chmc.h" #include "chmc/err.h" @@ -48,7 +53,7 @@ exit(0); } - string absolute_name = replace_backslashes(realpath(argv[1])); + string absolute_name = replace_backslashes(real_path(argv[1])); int prefixlen = absolute_name.find_last_of('/'); clog << prefixlen << endl; chdir(absolute_name.substr(0, prefixlen).c_str()); // change to the project file's directory Index: hhpcomp/lzx_compress/lz_nonslide.c =================================================================== --- hhpcomp/lzx_compress/lz_nonslide.c (Revision 68688) +++ hhpcomp/lzx_compress/lz_nonslide.c (Arbeitskopie) @@ -19,14 +19,23 @@ /* * Document here */ + #include #include #include + #if defined(_WIN32) +#define WIN32_LEAN_AND_MEAN +#include +#include +#else #include -#ifdef DEBUG_PERF -#include -#include + #ifdef DEBUG_PERF + #include + #include + #endif #endif + + #include "lz_nonslide.h" #define MAX_MATCH 253 @@ -132,7 +141,7 @@ } #endif -__inline__ int lz_left_to_process(lz_info *lzi) +__inline int lz_left_to_process(lz_info *lzi) { return lzi->chars_in_buf - lzi->block_loc; } Index: hhpcomp/lzx_compress/lz_nonslide.h =================================================================== --- hhpcomp/lzx_compress/lz_nonslide.h (Revision 68688) +++ hhpcomp/lzx_compress/lz_nonslide.h (Arbeitskopie) @@ -15,6 +15,11 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + + #if defined(_WIN32) +typedef unsigned char u_char; +#endif + typedef struct lz_info lz_info; typedef int (*get_chars_t)(lz_info *lzi, int n, u_char *buf); typedef int (*output_match_t)(lz_info *lzi, int match_pos, int match_len); Index: hhpcomp/port/mkstemps.c =================================================================== --- hhpcomp/port/mkstemps.c (Revision 0) +++ hhpcomp/port/mkstemps.c (Arbeitskopie) @@ -0,0 +1,139 @@ +/* Copyright (C) 1991, 1992, 1996, 1998 Free Software Foundation, Inc. + This file is derived from mkstemp.c from the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_PROCESS_H +#include +#endif + +/* We need to provide a type for gcc_uint64_t. */ +#ifdef __GNUC__ +__extension__ typedef unsigned long long gcc_uint64_t; +#else +typedef unsigned long gcc_uint64_t; +#endif + +#ifndef TMP_MAX +#define TMP_MAX 16384 +#endif + +/* + +@deftypefn Replacement int mkstemps (char *@var{template}, int @var{suffix_len}) + +Generate a unique temporary file name from @var{template}. +@var{template} has the form: + +@example + @var{path}/ccXXXXXX@var{suffix} +@end example + +@var{suffix_len} tells us how long @var{suffix} is (it can be zero +length). The last six characters of @var{template} before @var{suffix} +must be @samp{XXXXXX}; they are replaced with a string that makes the +filename unique. Returns a file descriptor open on the file for +reading and writing. + +@end deftypefn + +*/ + +int +mkstemps ( + char *template, + int suffix_len) +{ + static const char letters[] + = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + static gcc_uint64_t value; +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv; +#endif + char *XXXXXX; + size_t len; + int count; + + len = strlen (template); + + if ((int) len < 6 + suffix_len + || strncmp (&template[len - 6 - suffix_len], "XXXXXX", 6)) + { + return -1; + } + + XXXXXX = &template[len - 6 - suffix_len]; + +#ifdef HAVE_GETTIMEOFDAY + /* Get some more or less random data. */ + gettimeofday (&tv, NULL); + value += ((gcc_uint64_t) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid (); +#else + value += getpid (); +#endif + + for (count = 0; count < TMP_MAX; ++count) + { + gcc_uint64_t v = value; + int fd; + + /* Fill in the random bits. */ + XXXXXX[0] = letters[v % 62]; + v /= 62; + XXXXXX[1] = letters[v % 62]; + v /= 62; + XXXXXX[2] = letters[v % 62]; + v /= 62; + XXXXXX[3] = letters[v % 62]; + v /= 62; + XXXXXX[4] = letters[v % 62]; + v /= 62; + XXXXXX[5] = letters[v % 62]; + +#ifdef VMS + fd = open (template, O_RDWR|O_CREAT|O_EXCL, 0600, "fop=tmd"); +#else + fd = open (template, O_RDWR|O_CREAT|O_EXCL, 0600); +#endif + if (fd >= 0) + /* The file does not exist. */ + return fd; + + /* This is a random value. It is only necessary that the next + TMP_MAX values generated by adding 7777 to VALUE are different + with (module 2^32). */ + value += 7777; + } + + /* We return the null string if we can't find a unique file name. */ + template[0] = '\0'; + return -1; +} Eigenschaftsänderungen: hhpcomp/port/mkstemps.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: hhpcomp/port =================================================================== --- hhpcomp/port (Revision 0) +++ hhpcomp/port (Arbeitskopie) Eigenschaftsänderungen: hhpcomp/port ___________________________________________________________________ Added: svn:ignore ## -0,0 +1,4 ## +GNUmakefile +*.user +*.ncb +*.suo Index: hhpcomp/port/mkstemps.c =================================================================== --- hhpcomp/port/mkstemps.c (Revision 0) +++ hhpcomp/port/mkstemps.c (Arbeitskopie) @@ -0,0 +1,139 @@ +/* Copyright (C) 1991, 1992, 1996, 1998 Free Software Foundation, Inc. + This file is derived from mkstemp.c from the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_PROCESS_H +#include +#endif + +/* We need to provide a type for gcc_uint64_t. */ +#ifdef __GNUC__ +__extension__ typedef unsigned long long gcc_uint64_t; +#else +typedef unsigned long gcc_uint64_t; +#endif + +#ifndef TMP_MAX +#define TMP_MAX 16384 +#endif + +/* + +@deftypefn Replacement int mkstemps (char *@var{template}, int @var{suffix_len}) + +Generate a unique temporary file name from @var{template}. +@var{template} has the form: + +@example + @var{path}/ccXXXXXX@var{suffix} +@end example + +@var{suffix_len} tells us how long @var{suffix} is (it can be zero +length). The last six characters of @var{template} before @var{suffix} +must be @samp{XXXXXX}; they are replaced with a string that makes the +filename unique. Returns a file descriptor open on the file for +reading and writing. + +@end deftypefn + +*/ + +int +mkstemps ( + char *template, + int suffix_len) +{ + static const char letters[] + = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + static gcc_uint64_t value; +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv; +#endif + char *XXXXXX; + size_t len; + int count; + + len = strlen (template); + + if ((int) len < 6 + suffix_len + || strncmp (&template[len - 6 - suffix_len], "XXXXXX", 6)) + { + return -1; + } + + XXXXXX = &template[len - 6 - suffix_len]; + +#ifdef HAVE_GETTIMEOFDAY + /* Get some more or less random data. */ + gettimeofday (&tv, NULL); + value += ((gcc_uint64_t) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid (); +#else + value += getpid (); +#endif + + for (count = 0; count < TMP_MAX; ++count) + { + gcc_uint64_t v = value; + int fd; + + /* Fill in the random bits. */ + XXXXXX[0] = letters[v % 62]; + v /= 62; + XXXXXX[1] = letters[v % 62]; + v /= 62; + XXXXXX[2] = letters[v % 62]; + v /= 62; + XXXXXX[3] = letters[v % 62]; + v /= 62; + XXXXXX[4] = letters[v % 62]; + v /= 62; + XXXXXX[5] = letters[v % 62]; + +#ifdef VMS + fd = open (template, O_RDWR|O_CREAT|O_EXCL, 0600, "fop=tmd"); +#else + fd = open (template, O_RDWR|O_CREAT|O_EXCL, 0600); +#endif + if (fd >= 0) + /* The file does not exist. */ + return fd; + + /* This is a random value. It is only necessary that the next + TMP_MAX values generated by adding 7777 to VALUE are different + with (module 2^32). */ + value += 7777; + } + + /* We return the null string if we can't find a unique file name. */ + template[0] = '\0'; + return -1; +} Eigenschaftsänderungen: hhpcomp/port/mkstemps.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: hhpcomp/utils.cpp =================================================================== --- hhpcomp/utils.cpp (Revision 68688) +++ hhpcomp/utils.cpp (Arbeitskopie) @@ -21,7 +21,11 @@ #include #include +#if defined(_WIN32) +#include //for GetFullPathNameA +#else #include +#endif #include using namespace std; @@ -33,13 +37,23 @@ return temp; } -string realpath(const char* path) +string real_path(const char* path) { - char* temp = realpath(path, NULL); + char* temp = NULL; + #if defined(_WIN32) + char temp2[MAX_PATH]; + if (GetFullPathNameA(path, MAX_PATH, temp2, NULL)) { + temp = temp2; + } + #else + temp = realpath(path, NULL); + #endif if (temp == NULL) throw runtime_error("realpath failed"); string result(temp); - free(temp); + #if !defined(_WIN32) + free(temp); + #endif return result; } Index: hhpcomp/utils.h =================================================================== --- hhpcomp/utils.h (Revision 68688) +++ hhpcomp/utils.h (Arbeitskopie) @@ -22,3 +22,5 @@ string realpath(const char* path); string replace_backslashes(string s); + +string real_path(const char* path);