Author: bfreisen Date: Tue Aug 11 20:19:58 2015 New Revision: 68693
URL: http://svn.reactos.org/svn/reactos?rev=68693&view=rev Log: [HHPCOMP] Re-enable and (hopefully) fix build. Patch by Michael Fritscher (CORE-10013) with some changes by me to make the program work again (on Linux)
Added: trunk/reactos/tools/hhpcomp/port/ (with props) trunk/reactos/tools/hhpcomp/port/mkstemps.c (with props) Modified: trunk/reactos/tools/CMakeLists.txt trunk/reactos/tools/hhpcomp/CMakeLists.txt trunk/reactos/tools/hhpcomp/chmc/chmc.c trunk/reactos/tools/hhpcomp/chmc/chmc.h trunk/reactos/tools/hhpcomp/chmc/err.h trunk/reactos/tools/hhpcomp/hhp_reader.cpp trunk/reactos/tools/hhpcomp/hhpcomp.cpp trunk/reactos/tools/hhpcomp/lzx_compress/lz_nonslide.c trunk/reactos/tools/hhpcomp/lzx_compress/lz_nonslide.h trunk/reactos/tools/hhpcomp/utils.cpp trunk/reactos/tools/hhpcomp/utils.h
Modified: trunk/reactos/tools/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/CMakeLists.txt?rev=68... ============================================================================== --- trunk/reactos/tools/CMakeLists.txt [iso-8859-1] (original) +++ trunk/reactos/tools/CMakeLists.txt [iso-8859-1] Tue Aug 11 20:19:58 2015 @@ -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)
Modified: trunk/reactos/tools/hhpcomp/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/hhpcomp/CMakeLists.tx... ============================================================================== --- trunk/reactos/tools/hhpcomp/CMakeLists.txt [iso-8859-1] (original) +++ trunk/reactos/tools/hhpcomp/CMakeLists.txt [iso-8859-1] Tue Aug 11 20:19:58 2015 @@ -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)
Modified: trunk/reactos/tools/hhpcomp/chmc/chmc.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/hhpcomp/chmc/chmc.c?r... ============================================================================== --- trunk/reactos/tools/hhpcomp/chmc/chmc.c [iso-8859-1] (original) +++ trunk/reactos/tools/hhpcomp/chmc/chmc.c [iso-8859-1] Tue Aug 11 20:19:58 2015 @@ -25,7 +25,19 @@ #include <errno.h> #include <string.h> #include <assert.h> + +#if defined(_WIN32) +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#ifndef __GNUC__ +typedef int (*__compar_fn_t)(const void *, const void *); +#endif + +#else #include <unistd.h> +#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 = (void *)((char *)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 = (void *)((char *)&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 = (void *)((char *)&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;
Modified: trunk/reactos/tools/hhpcomp/chmc/chmc.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/hhpcomp/chmc/chmc.h?r... ============================================================================== --- trunk/reactos/tools/hhpcomp/chmc/chmc.h [iso-8859-1] (original) +++ trunk/reactos/tools/hhpcomp/chmc/chmc.h [iso-8859-1] Tue Aug 11 20:19:58 2015 @@ -26,6 +26,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" @@ -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 */
Modified: trunk/reactos/tools/hhpcomp/chmc/err.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/hhpcomp/chmc/err.h?re... ============================================================================== --- trunk/reactos/tools/hhpcomp/chmc/err.h [iso-8859-1] (original) +++ trunk/reactos/tools/hhpcomp/chmc/err.h [iso-8859-1] Tue Aug 11 20:19:58 2015 @@ -22,13 +22,13 @@ #define CHMC_ERR_H
#include <stdio.h> -#define chmcerr_printf(fmt,args...) fprintf (stderr, fmt , ##args) +#define chmcerr_printf(fmt, ...) fprintf (stderr, fmt , ## __VA_ARGS__)
#include <stdlib.h> -#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)
Modified: trunk/reactos/tools/hhpcomp/hhp_reader.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/hhpcomp/hhp_reader.cp... ============================================================================== --- trunk/reactos/tools/hhpcomp/hhp_reader.cpp [iso-8859-1] (original) +++ trunk/reactos/tools/hhpcomp/hhp_reader.cpp [iso-8859-1] Tue Aug 11 20:19:58 2015 @@ -217,7 +217,7 @@ { for (list<string>::iterator it = files->filenames.begin(); it != files->filenames.end(); ++it) { - unique_file_pathes.insert(replace_backslashes(realpath(it->c_str()))); + unique_file_pathes.insert(replace_backslashes(real_path(it->c_str()))); } }
Modified: trunk/reactos/tools/hhpcomp/hhpcomp.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/hhpcomp/hhpcomp.cpp?r... ============================================================================== --- trunk/reactos/tools/hhpcomp/hhpcomp.cpp [iso-8859-1] (original) +++ trunk/reactos/tools/hhpcomp/hhpcomp.cpp [iso-8859-1] Tue Aug 11 20:19:58 2015 @@ -23,10 +23,15 @@ #include <stdexcept>
#include <sys/stat.h> -#include <unistd.h>
#include "hhp_reader.h" #include "utils.h" + +#if defined(_WIN32) + #include <direct.h> +#else + #include <unistd.h> +#endif
extern "C" { #include "chmc/chmc.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
Modified: trunk/reactos/tools/hhpcomp/lzx_compress/lz_nonslide.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/hhpcomp/lzx_compress/... ============================================================================== --- trunk/reactos/tools/hhpcomp/lzx_compress/lz_nonslide.c [iso-8859-1] (original) +++ trunk/reactos/tools/hhpcomp/lzx_compress/lz_nonslide.c [iso-8859-1] Tue Aug 11 20:19:58 2015 @@ -22,10 +22,16 @@ #include <stdio.h> #include <stdlib.h> #include <assert.h> -#include <strings.h> -#ifdef DEBUG_PERF -#include <sys/time.h> -#include <sys/resource.h> +#if defined(_WIN32) + #define WIN32_LEAN_AND_MEAN + #include <string.h> + #include <windows.h> +#else + #include <strings.h> + #ifdef DEBUG_PERF + #include <sys/time.h> + #include <sys/resource.h> + #endif #endif #include "lz_nonslide.h"
@@ -132,7 +138,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; }
Modified: trunk/reactos/tools/hhpcomp/lzx_compress/lz_nonslide.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/hhpcomp/lzx_compress/... ============================================================================== --- trunk/reactos/tools/hhpcomp/lzx_compress/lz_nonslide.h [iso-8859-1] (original) +++ trunk/reactos/tools/hhpcomp/lzx_compress/lz_nonslide.h [iso-8859-1] Tue Aug 11 20:19:58 2015 @@ -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);
Propchange: trunk/reactos/tools/hhpcomp/port/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Tue Aug 11 20:19:58 2015 @@ -0,0 +1,4 @@ +GNUmakefile +*.user +*.ncb +*.suo
Added: trunk/reactos/tools/hhpcomp/port/mkstemps.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/hhpcomp/port/mkstemps... ============================================================================== --- trunk/reactos/tools/hhpcomp/port/mkstemps.c (added) +++ trunk/reactos/tools/hhpcomp/port/mkstemps.c [iso-8859-1] Tue Aug 11 20:19:58 2015 @@ -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 <sys/types.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <stdio.h> +#include <fcntl.h> +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif +#ifdef HAVE_SYS_TIME_H +#include <sys/time.h> +#endif +#ifdef HAVE_PROCESS_H +#include <process.h> +#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; +}
Propchange: trunk/reactos/tools/hhpcomp/port/mkstemps.c ------------------------------------------------------------------------------ svn:eol-style = native
Modified: trunk/reactos/tools/hhpcomp/utils.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/hhpcomp/utils.cpp?rev... ============================================================================== --- trunk/reactos/tools/hhpcomp/utils.cpp [iso-8859-1] (original) +++ trunk/reactos/tools/hhpcomp/utils.cpp [iso-8859-1] Tue Aug 11 20:19:58 2015 @@ -21,7 +21,12 @@ #include <algorithm> #include <stdexcept>
-#include <unistd.h> +#if defined(_WIN32) + #include <windows.h> // for GetFullPathNameA +#else + #include <unistd.h> +#endif + #include <stdlib.h>
using namespace std; @@ -33,13 +38,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; }
Modified: trunk/reactos/tools/hhpcomp/utils.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/hhpcomp/utils.h?rev=6... ============================================================================== --- trunk/reactos/tools/hhpcomp/utils.h [iso-8859-1] (original) +++ trunk/reactos/tools/hhpcomp/utils.h [iso-8859-1] Tue Aug 11 20:19:58 2015 @@ -19,6 +19,6 @@
string to_upper(string s);
-string realpath(const char* path); +string real_path(const char* path);
string replace_backslashes(string s);