From cef76b7a933583c1ec749a4f814932c4601cb84d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Wed, 7 Jan 2015 19:26:49 +0000 Subject: [PATCH] [TOOLS]: Slap some sense in the indentation of some files. Next time: PLEASE CHECK YOUR F*CKING EDITOR's TABS AND SET THEM TO 4 SPACES BEFORE DOING ANYTHING ELSE!!!! (and not to 8 spaces and then use 4 space indentation and complete with tabs). svn path=/trunk/; revision=65998 --- reactos/tools/cabman/cabinet.cxx | 2 +- reactos/tools/cabman/cabinet.h | 9 +- reactos/tools/cabman/cabman.h | 3 +- reactos/tools/cabman/dff.txt | 2 +- reactos/tools/cabman/dfp.h | 18 +- reactos/tools/cabman/main.cxx | 2 +- reactos/tools/cabman/makefile.win32 | 27 - reactos/tools/cabman/mszip.h | 3 +- reactos/tools/cabman/raw.h | 3 +- reactos/tools/cdmake/cdmake.c | 20 +- reactos/tools/cdmake/dirhash.h | 2 +- reactos/tools/create_nls/Readme | 8 +- reactos/tools/create_nls/create_nls.c | 874 ++++++++--------- reactos/tools/log2lines/CMakeLists.txt | 4 +- reactos/tools/log2lines/cache.c | 14 +- reactos/tools/log2lines/cmd.c | 10 +- reactos/tools/log2lines/config.h | 4 +- reactos/tools/log2lines/list.c | 8 +- reactos/tools/log2lines/options.c | 8 +- reactos/tools/log2lines/revision.h | 2 +- reactos/tools/log2lines/stat.c | 2 +- reactos/tools/mkhive/binhive.c | 34 +- reactos/tools/mkhive/binhive.h | 4 +- reactos/tools/mkhive/cmi.c | 891 +++++++++--------- reactos/tools/mkhive/cmi.h | 46 +- reactos/tools/mkhive/mkhive.c | 148 +-- reactos/tools/mkhive/reginf.c | 662 ++++++------- reactos/tools/mkhive/registry.c | 798 ++++++++-------- reactos/tools/mkhive/registry.h | 6 +- reactos/tools/mkhive/rtl.c | 190 ++-- reactos/tools/mkshelllink/mkshelllink.c | 8 +- reactos/tools/ms2ps/ms2ps.cpp | 325 +++---- reactos/tools/nandflash/main.c | 6 +- reactos/tools/ofw_interface/calls.ofw | 30 +- reactos/tools/ofw_interface/ofw_interface.cpp | 262 ++--- reactos/tools/pipetools/piperead.cpp | 346 ++++--- reactos/tools/pipetools/pipespy.cpp | 308 +++--- reactos/tools/pipetools/pipetunnel.cpp | 364 +++---- reactos/tools/stubgen.c | 244 ++--- reactos/tools/utf16le/utf16le.cpp | 496 +++++----- 40 files changed, 3082 insertions(+), 3111 deletions(-) delete mode 100644 reactos/tools/cabman/makefile.win32 diff --git a/reactos/tools/cabman/cabinet.cxx b/reactos/tools/cabman/cabinet.cxx index 0f23b07be43..0c52e247300 100644 --- a/reactos/tools/cabman/cabinet.cxx +++ b/reactos/tools/cabman/cabinet.cxx @@ -1676,7 +1676,7 @@ ULONG CCabinet::WriteFileToScratchStorage(PCFFILE_NODE FileNode) CurrentFolderNode->UncompOffset += TotalBytesLeft; FileNode->File.FileControlID = (USHORT)(NextFolderNumber - 1); CurrentFolderNode->Commit = true; - PrevCabinetNumber = CurrentDiskNumber; + PrevCabinetNumber = CurrentDiskNumber; Size = sizeof(CFFILE) + (ULONG)strlen(GetFileName(FileNode->FileName)) + 1; CABHeader.FileTableOffset += Size; diff --git a/reactos/tools/cabman/cabinet.h b/reactos/tools/cabman/cabinet.h index 105fcfebba2..4794d5e78f1 100644 --- a/reactos/tools/cabman/cabinet.h +++ b/reactos/tools/cabman/cabinet.h @@ -255,7 +255,8 @@ typedef struct _CAB_SEARCH /* Codecs */ -class CCABCodec { +class CCABCodec +{ public: /* Default constructor */ CCABCodec() {}; @@ -291,7 +292,8 @@ public: #ifndef CAB_READ_ONLY -class CCFDATAStorage { +class CCFDATAStorage +{ public: /* Default constructor */ CCFDATAStorage(); @@ -312,7 +314,8 @@ private: #endif /* CAB_READ_ONLY */ -class CCabinet { +class CCabinet +{ public: /* Default constructor */ CCabinet(); diff --git a/reactos/tools/cabman/cabman.h b/reactos/tools/cabman/cabman.h index b23376acfec..a4160275a71 100644 --- a/reactos/tools/cabman/cabman.h +++ b/reactos/tools/cabman/cabman.h @@ -18,7 +18,8 @@ /* Classes */ -class CCABManager : public CDFParser { +class CCABManager : public CDFParser +{ public: CCABManager(); virtual ~CCABManager(); diff --git a/reactos/tools/cabman/dff.txt b/reactos/tools/cabman/dff.txt index a400e0a652e..776c0431bc8 100644 --- a/reactos/tools/cabman/dff.txt +++ b/reactos/tools/cabman/dff.txt @@ -21,7 +21,7 @@ Syntax Description Standard variable Description ------------------------------------------------------------------------------- Cabinet=ON|OFF Turns cabinet mode on or off (* -- currently always on) -CabinetFileCountThreshold=count Threshold count of files per cabinet (*) +CabinetFileCountThreshold=count Threshold count of files per cabinet (*) CabinetNamen=filename Cabinet file name for cabinet number n CabinetNameTemplate=template Cabinet file name template * is replaced by cabinet number diff --git a/reactos/tools/cabman/dfp.h b/reactos/tools/cabman/dfp.h index 77ffb44dd0a..bfea30f81bd 100644 --- a/reactos/tools/cabman/dfp.h +++ b/reactos/tools/cabman/dfp.h @@ -9,19 +9,22 @@ #include "cabinet.h" -typedef struct _CABINET_NAME { +typedef struct _CABINET_NAME +{ struct _CABINET_NAME *Next; ULONG DiskNumber; char Name[128]; } CABINET_NAME, *PCABINET_NAME; -typedef struct _DISK_NUMBER { +typedef struct _DISK_NUMBER +{ struct _DISK_NUMBER *Next; ULONG DiskNumber; ULONG Number; } DISK_NUMBER, *PDISK_NUMBER; -typedef enum { +typedef enum +{ TokenUnknown, TokenInteger, TokenIdentifier, @@ -35,7 +38,8 @@ typedef enum { } DFP_TOKEN; -typedef enum { +typedef enum +{ stCabinetName, stCabinetNameTemplate, stDiskLabel, @@ -45,7 +49,8 @@ typedef enum { } SETTYPE; -typedef enum { +typedef enum +{ ntDisk, ntCabinet, ntFolder, @@ -54,7 +59,8 @@ typedef enum { /* Classes */ -class CDFParser : public CCabinet { +class CDFParser : public CCabinet +{ public: CDFParser(); virtual ~CDFParser(); diff --git a/reactos/tools/cabman/main.cxx b/reactos/tools/cabman/main.cxx index bfa43c4c8e0..2aa9aebed60 100644 --- a/reactos/tools/cabman/main.cxx +++ b/reactos/tools/cabman/main.cxx @@ -346,7 +346,7 @@ bool CCABManager::ParseCmdline(int argc, char* argv[]) SetFileRelativePath(&argv[i][2]); break; - + case 'V': Verbose = true; break; diff --git a/reactos/tools/cabman/makefile.win32 b/reactos/tools/cabman/makefile.win32 deleted file mode 100644 index c7af1d70705..00000000000 --- a/reactos/tools/cabman/makefile.win32 +++ /dev/null @@ -1,27 +0,0 @@ -PATH_TO_TOP = ../.. - -TARGET_TYPE = program - -TARGET_APPTYPE = console - -TARGET_NAME = cabman -#TARGET_NAME = test - -TARGET_CPPAPP = yes - -TARGET_OBJECTS = cabinet.o mszip.o raw.o main.o dfp.o - -TARGET_SDKLIBS = zlib.a - -TARGET_CFLAGS = -I$(PATH_TO_TOP)/lib/zlib -Werror -Wall - -TARGET_CPPFLAGS = $(TARGET_CFLAGS) - -TARGET_GCCLIBS = stdc++ - -TARGET_NORC = yes - -include $(PATH_TO_TOP)/rules.mak - -include $(TOOLS_PATH)/helper.mk - diff --git a/reactos/tools/cabman/mszip.h b/reactos/tools/cabman/mszip.h index da5c59f0a8e..5b43d8170e5 100644 --- a/reactos/tools/cabman/mszip.h +++ b/reactos/tools/cabman/mszip.h @@ -15,7 +15,8 @@ /* Classes */ -class CMSZipCodec : public CCABCodec { +class CMSZipCodec : public CCABCodec +{ public: /* Default constructor */ CMSZipCodec(); diff --git a/reactos/tools/cabman/raw.h b/reactos/tools/cabman/raw.h index 0b79efb7cd9..dfbc2ae2eb2 100644 --- a/reactos/tools/cabman/raw.h +++ b/reactos/tools/cabman/raw.h @@ -12,7 +12,8 @@ /* Classes */ -class CRawCodec : public CCABCodec { +class CRawCodec : public CCABCodec +{ public: /* Default constructor */ CRawCodec(); diff --git a/reactos/tools/cdmake/cdmake.c b/reactos/tools/cdmake/cdmake.c index 056cd4ca2e0..0a8f299c931 100644 --- a/reactos/tools/cdmake/cdmake.c +++ b/reactos/tools/cdmake/cdmake.c @@ -66,13 +66,13 @@ typedef int BOOL; // file system parameters -#define MAX_LEVEL 8 -#define MAX_NAME_LENGTH 64 -#define MAX_CDNAME_LENGTH 8 -#define MAX_EXTENSION_LENGTH 10 -#define MAX_CDEXTENSION_LENGTH 3 -#define SECTOR_SIZE 2048 -#define BUFFER_SIZE (8 * SECTOR_SIZE) +#define MAX_LEVEL 8 +#define MAX_NAME_LENGTH 64 +#define MAX_CDNAME_LENGTH 8 +#define MAX_EXTENSION_LENGTH 10 +#define MAX_CDEXTENSION_LENGTH 3 +#define SECTOR_SIZE 2048 +#define BUFFER_SIZE (8 * SECTOR_SIZE) const BYTE HIDDEN_FLAG = 1; const BYTE DIRECTORY_FLAG = 2; @@ -395,8 +395,8 @@ This function writes a directory record to the CD_ROM image. static void write_directory_record(PDIR_RECORD d, - DIR_RECORD_TYPE DirType, - BOOL joliet) + DIR_RECORD_TYPE DirType, + BOOL joliet) { unsigned identifier_size; unsigned record_size; @@ -1253,7 +1253,7 @@ static void get_time_string(char *str) struct tm *current; time_t timestamp = time(NULL); current = gmtime(×tamp); - sprintf(str, "%04d%02d%02d%02d%02d%02d00", + sprintf(str, "%04d%02d%02d%02d%02d%02d00", current->tm_year + 1900, current->tm_mon, current->tm_mday, diff --git a/reactos/tools/cdmake/dirhash.h b/reactos/tools/cdmake/dirhash.h index 874f6315ccc..1e91030ff7c 100644 --- a/reactos/tools/cdmake/dirhash.h +++ b/reactos/tools/cdmake/dirhash.h @@ -35,4 +35,4 @@ dir_hash_create_dir(struct target_dir_hash *dh, const char *casename, const char struct target_dir_entry *dir_hash_next_dir(struct target_dir_hash *dh, struct target_dir_traversal *t); void dir_hash_destroy(struct target_dir_hash *dh); -#endif//_REACTOS_TOOLS_CDMAKE_DIRHASH_H_ +#endif //_REACTOS_TOOLS_CDMAKE_DIRHASH_H_ diff --git a/reactos/tools/create_nls/Readme b/reactos/tools/create_nls/Readme index e72804b6b74..8bd2abedb6e 100644 --- a/reactos/tools/create_nls/Readme +++ b/reactos/tools/create_nls/Readme @@ -12,10 +12,10 @@ site into the unicode.org subdirectory and create_nls will build the .nls files. Makefile targets: - 'make': builds create_nls tool. - 'make clean': deletes all executable and object files - 'make nls': generates binary .nls files. - 'make clean_nls': deletes binary .nls files. + 'make': builds create_nls tool. + 'make clean': deletes all executable and object files + 'make nls': generates binary .nls files. + 'make clean_nls': deletes binary .nls files. Since the binary .nls files are part of the ReactOS source tree it is not necessary to build these files yourself. Therefore create_nls is not diff --git a/reactos/tools/create_nls/create_nls.c b/reactos/tools/create_nls/create_nls.c index 4e21ce31b0f..63a8ac23488 100644 --- a/reactos/tools/create_nls/create_nls.c +++ b/reactos/tools/create_nls/create_nls.c @@ -64,32 +64,32 @@ static void patch_aliases(void *u2cp, CPINFOEXA *cpi) BYTE *c; if(cpi->MaxCharSize == 2) { - wc = (WCHAR *)u2cp; - for(i = 0; i < 65536; i++) { - for(j = 0; j < sizeof(u2cp_alias)/sizeof(u2cp_alias[0]); j++) { - alias = u2cp_alias[j].alias; - while(*alias) { - if(*alias == i && wc[i] == *(WCHAR *)cpi->DefaultChar) { - wc[i] = u2cp_alias[j].cp_char; - } - alias++; - } - } - } + wc = (WCHAR *)u2cp; + for(i = 0; i < 65536; i++) { + for(j = 0; j < sizeof(u2cp_alias)/sizeof(u2cp_alias[0]); j++) { + alias = u2cp_alias[j].alias; + while(*alias) { + if(*alias == i && wc[i] == *(WCHAR *)cpi->DefaultChar) { + wc[i] = u2cp_alias[j].cp_char; + } + alias++; + } + } + } } else { - c = (BYTE *)u2cp; - for(i = 0; i < 65536; i++) { - for(j = 0; j < sizeof(u2cp_alias)/sizeof(u2cp_alias[0]); j++) { - alias = u2cp_alias[j].alias; - while(*alias) { - if(*alias == i && c[i] == cpi->DefaultChar[0] && u2cp_alias[j].cp_char < 256) { - c[i] = (BYTE)u2cp_alias[j].cp_char; - } - alias++; - } - } - } + c = (BYTE *)u2cp; + for(i = 0; i < 65536; i++) { + for(j = 0; j < sizeof(u2cp_alias)/sizeof(u2cp_alias[0]); j++) { + alias = u2cp_alias[j].alias; + while(*alias) { + if(*alias == i && c[i] == cpi->DefaultChar[0] && u2cp_alias[j].cp_char < 256) { + c[i] = (BYTE)u2cp_alias[j].cp_char; + } + alias++; + } + } + } } } @@ -103,33 +103,33 @@ static BOOL write_unicode2cp_table(FILE *out, CPINFOEXA *cpi, WCHAR *table) u2cp = malloc(cpi->MaxCharSize * 65536); if(!u2cp) { - printf("Not enough memory for Unicode to Codepage table\n"); - return FALSE; + printf("Not enough memory for Unicode to Codepage table\n"); + return FALSE; } if(cpi->MaxCharSize == 2) { - wc = (WCHAR *)u2cp; - for(i = 0; i < 65536; i++) - wc[i] = *(WCHAR *)cpi->DefaultChar; + wc = (WCHAR *)u2cp; + for(i = 0; i < 65536; i++) + wc[i] = *(WCHAR *)cpi->DefaultChar; - for(i = 0; i < 65536; i++) - if (table[i] != '?') - wc[table[i]] = (WCHAR)i; + for(i = 0; i < 65536; i++) + if (table[i] != '?') + wc[table[i]] = (WCHAR)i; } else { - c = (CHAR *)u2cp; - for(i = 0; i < 65536; i++) - c[i] = cpi->DefaultChar[0]; + c = (CHAR *)u2cp; + for(i = 0; i < 65536; i++) + c[i] = cpi->DefaultChar[0]; - for(i = 0; i < 256; i++) - if (table[i] != '?') - c[table[i]] = (CHAR)i; + for(i = 0; i < 256; i++) + if (table[i] != '?') + c[table[i]] = (CHAR)i; } patch_aliases(u2cp, cpi); if(fwrite(u2cp, 1, cpi->MaxCharSize * 65536, out) != cpi->MaxCharSize * 65536) - ret = FALSE; + ret = FALSE; free(u2cp); @@ -147,25 +147,25 @@ static BOOL write_lb_ranges(FILE *out, CPINFOEXA *cpi, WCHAR *table) offset = 0; for(i = 0; i < MAX_LEADBYTES; i += 2) { - for(range = cpi->LeadByte[i]; range != 0 && range <= cpi->LeadByte[i + 1]; range++) { - offset += 256; - offsets[range] = offset; - } + for(range = cpi->LeadByte[i]; range != 0 && range <= cpi->LeadByte[i + 1]; range++) { + offset += 256; + offsets[range] = offset; + } } if(fwrite(offsets, 1, sizeof(offsets), out) != sizeof(offsets)) - return FALSE; + return FALSE; for(i = 0; i < MAX_LEADBYTES; i += 2) { - for(range = cpi->LeadByte[i]; range != 0 && range <= cpi->LeadByte[i + 1]; range++) { - /*printf("Writing sub table for LeadByte %02X\n", range);*/ - for(j = MAKEWORD(0, range); j <= MAKEWORD(0xFF, range); j++) { - sub_table[j - MAKEWORD(0, range)] = table[j]; - } + for(range = cpi->LeadByte[i]; range != 0 && range <= cpi->LeadByte[i + 1]; range++) { + /*printf("Writing sub table for LeadByte %02X\n", range);*/ + for(j = MAKEWORD(0, range); j <= MAKEWORD(0xFF, range); j++) { + sub_table[j - MAKEWORD(0, range)] = table[j]; + } - if(fwrite(sub_table, 1, sizeof(sub_table), out) != sizeof(sub_table)) - return FALSE; - } + if(fwrite(sub_table, 1, sizeof(sub_table), out) != sizeof(sub_table)) + return FALSE; + } } return TRUE; @@ -180,8 +180,8 @@ static BOOL create_nls_file(char *name, CPINFOEXA *cpi, WCHAR *table, WCHAR *oem printf("Creating NLS table \"%s\"\n", name); if(!(out = fopen(name, "wb"))) { - printf("Could not create file \"%s\"\n", name); - return FALSE; + printf("Could not create file \"%s\"\n", name); + return FALSE; } memset(&nls, 0, sizeof(nls)); @@ -196,19 +196,19 @@ static BOOL create_nls_file(char *name, CPINFOEXA *cpi, WCHAR *table, WCHAR *oem memcpy(nls.LeadByte, cpi->LeadByte, MAX_LEADBYTES); if(fwrite(&nls, 1, sizeof(nls), out) != sizeof(nls)) { - fclose(out); - printf("Could not write to file \"%s\"\n", name); - return FALSE; + fclose(out); + printf("Could not write to file \"%s\"\n", name); + return FALSE; } number_of_lb_ranges = 0; number_of_lb_subtables = 0; for(i = 0; i < MAX_LEADBYTES; i += 2) { - if(cpi->LeadByte[i] != 0 && cpi->LeadByte[i + 1] > cpi->LeadByte[i]) { - number_of_lb_ranges++; - number_of_lb_subtables += cpi->LeadByte[i + 1] - cpi->LeadByte[i] + 1; - } + if(cpi->LeadByte[i] != 0 && cpi->LeadByte[i + 1] > cpi->LeadByte[i]) { + number_of_lb_ranges++; + number_of_lb_subtables += cpi->LeadByte[i + 1] - cpi->LeadByte[i] + 1; + } } /*printf("Number of LeadByte ranges %d\n", number_of_lb_ranges);*/ @@ -225,22 +225,22 @@ static BOOL create_nls_file(char *name, CPINFOEXA *cpi, WCHAR *table, WCHAR *oem */ wValue = (256 * sizeof(WORD) + /* 1 */ - sizeof(WORD) + /* 2 */ - ((oemtable !=NULL) ? (256 * sizeof(WORD)) : 0) + /* 3 */ - sizeof(WORD) + /* 4 */ - ((number_of_lb_subtables != 0) ? 256 * sizeof(WORD) : 0) + /* 5 */ - number_of_lb_subtables * 256 * sizeof(WORD) + /* 6 */ - sizeof(WORD) /* 7 */ - ) / sizeof(WORD); + sizeof(WORD) + /* 2 */ + ((oemtable !=NULL) ? (256 * sizeof(WORD)) : 0) + /* 3 */ + sizeof(WORD) + /* 4 */ + ((number_of_lb_subtables != 0) ? 256 * sizeof(WORD) : 0) + /* 5 */ + number_of_lb_subtables * 256 * sizeof(WORD) + /* 6 */ + sizeof(WORD) /* 7 */ + ) / sizeof(WORD); /* offset of Unicode to CP table in words */ fwrite(&wValue, 1, sizeof(wValue), out); /* primary CP to Unicode table */ if(fwrite(table, 1, 256 * sizeof(WCHAR), out) != 256 * sizeof(WCHAR)) { - fclose(out); - printf("Could not write to file \"%s\"\n", name); - return FALSE; + fclose(out); + printf("Could not write to file \"%s\"\n", name); + return FALSE; } /* optional OEM glyph table size in words */ @@ -249,11 +249,11 @@ static BOOL create_nls_file(char *name, CPINFOEXA *cpi, WCHAR *table, WCHAR *oem /* optional OEM to Unicode table */ if (oemtable) { - if(fwrite(oemtable, 1, 256 * sizeof(WCHAR), out) != 256 * sizeof(WCHAR)) { - fclose(out); - printf("Could not write to file \"%s\"\n", name); - return FALSE; - } + if(fwrite(oemtable, 1, 256 * sizeof(WCHAR), out) != 256 * sizeof(WCHAR)) { + fclose(out); + printf("Could not write to file \"%s\"\n", name); + return FALSE; + } } /* Number of DBCS LeadByte ranges */ @@ -261,11 +261,11 @@ static BOOL create_nls_file(char *name, CPINFOEXA *cpi, WCHAR *table, WCHAR *oem /* offsets of lead byte sub tables and lead byte sub tables */ if(number_of_lb_ranges > 0) { - if(!write_lb_ranges(out, cpi, table)) { - fclose(out); - printf("Could not write to file \"%s\"\n", name); - return FALSE; - } + if(!write_lb_ranges(out, cpi, table)) { + fclose(out); + printf("Could not write to file \"%s\"\n", name); + return FALSE; + } } /* Unknown flag */ @@ -273,9 +273,9 @@ static BOOL create_nls_file(char *name, CPINFOEXA *cpi, WCHAR *table, WCHAR *oem fwrite(&wValue, 1, sizeof(wValue), out); if(!write_unicode2cp_table(out, cpi, table)) { - fclose(out); - printf("Could not write to file \"%s\"\n", name); - return FALSE; + fclose(out); + printf("Could not write to file \"%s\"\n", name); + return FALSE; } fclose(out); @@ -310,20 +310,20 @@ static WCHAR *Load_CP2Unicode_Table(char *table_name, UINT cp, CPINFOEXA *cpi) table = (WCHAR *)malloc(sizeof(WCHAR) * 65536); if(!table) { - printf("Not enough memory for Codepage to Unicode table\n"); - return NULL; + printf("Not enough memory for Codepage to Unicode table\n"); + return NULL; } for(n = 0; n < 256; n++) - table[n] = (WCHAR)n; + table[n] = (WCHAR)n; for(n = 256; n < 65536; n++) - table[n] = cpi->UnicodeDefaultChar; + table[n] = cpi->UnicodeDefaultChar; file = fopen(table_name, "r"); if(file == NULL) { - free(table); - return NULL; + free(table); + return NULL; } line = 0; @@ -331,67 +331,67 @@ static WCHAR *Load_CP2Unicode_Table(char *table_name, UINT cp, CPINFOEXA *cpi) lb_range_started = 0; while(fgets(buf, sizeof(buf), file)) { - line++; - p = buf; - while(isspace(*p)) p++; + line++; + p = buf; + while(isspace(*p)) p++; - if(!*p || p[0] == '#') - continue; + if(!*p || p[0] == '#') + continue; - n = strtol(p, &p, 0); - if(n > 0xFFFF) { - printf("Line %d: Entry 0x%06lX: File \"%s\" corrupted\n", line, n, table_name); - continue; - } + n = strtol(p, &p, 0); + if(n > 0xFFFF) { + printf("Line %d: Entry 0x%06lX: File \"%s\" corrupted\n", line, n, table_name); + continue; + } - if(n > 0xFF && cpi->MaxCharSize != 2) { - /*printf("Line %d: Entry 0x%04lX: Switching to DBCS\n", line, n);*/ - cpi->MaxCharSize = 2; - } + if(n > 0xFF && cpi->MaxCharSize != 2) { + /*printf("Line %d: Entry 0x%04lX: Switching to DBCS\n", line, n);*/ + cpi->MaxCharSize = 2; + } - while(isspace(*p)) p++; + while(isspace(*p)) p++; - if(!*p || p[0] == '#') { - /*printf("Line %d: Entry 0x%02lX has no Unicode value\n", line, n);*/ - } - else { - value = strtol(p, &p, 0); - if(value > 0xFFFF) { - printf("Line %d: Entry 0x%06lX unicode value: File \"%s\" corrupted\n", line, n, table_name); - } - table[n] = (WCHAR)value; - } + if(!*p || p[0] == '#') { + /*printf("Line %d: Entry 0x%02lX has no Unicode value\n", line, n);*/ + } + else { + value = strtol(p, &p, 0); + if(value > 0xFFFF) { + printf("Line %d: Entry 0x%06lX unicode value: File \"%s\" corrupted\n", line, n, table_name); + } + table[n] = (WCHAR)value; + } - /* wait for comment */ - while(*p && *p != '#') p++; + /* wait for comment */ + while(*p && *p != '#') p++; - if(*p == '#' && strstr(p, "DBCS LEAD BYTE")) { - /*printf("Line %d, entry 0x%02lX DBCS LEAD BYTE\n", line, n);*/ - if(n > 0xFF) { - printf("Line %d: Entry 0x%04lX: Error: DBCS lead byte overflowed\n", line, n); - continue; - } + if(*p == '#' && strstr(p, "DBCS LEAD BYTE")) { + /*printf("Line %d, entry 0x%02lX DBCS LEAD BYTE\n", line, n);*/ + if(n > 0xFF) { + printf("Line %d: Entry 0x%04lX: Error: DBCS lead byte overflowed\n", line, n); + continue; + } - table[n] = (WCHAR)0; + table[n] = (WCHAR)0; - if(lb_range_started) { - cpi->LeadByte[(lb_ranges - 1) * 2 + 1] = (BYTE)n; - } - else { - /*printf("Line %d: Starting new DBCS lead byte range, entry 0x%02lX\n", line, n);*/ - if(lb_ranges < MAX_LEADBYTES/2) { - lb_ranges++; - lb_range_started = 1; - cpi->LeadByte[(lb_ranges - 1) * 2] = (BYTE)n; - } - else - printf("Line %d: Error: could not start new lead byte range\n", line); - } - } - else { - if(lb_range_started) - lb_range_started = 0; - } + if(lb_range_started) { + cpi->LeadByte[(lb_ranges - 1) * 2 + 1] = (BYTE)n; + } + else { + /*printf("Line %d: Starting new DBCS lead byte range, entry 0x%02lX\n", line, n);*/ + if(lb_ranges < MAX_LEADBYTES/2) { + lb_ranges++; + lb_range_started = 1; + cpi->LeadByte[(lb_ranges - 1) * 2] = (BYTE)n; + } + else + printf("Line %d: Error: could not start new lead byte range\n", line); + } + } + else { + if(lb_range_started) + lb_range_started = 0; + } } fclose(file); @@ -412,63 +412,63 @@ static WCHAR *Load_OEM2Unicode_Table(char *table_name, WCHAR *def_table, UINT cp table = (WCHAR *)malloc(sizeof(WCHAR) * 65536); if(!table) { - printf("Not enough memory for Codepage to Unicode table\n"); - return NULL; + printf("Not enough memory for Codepage to Unicode table\n"); + return NULL; } memcpy(table, def_table, 65536 * sizeof(WCHAR)); file = fopen(table_name, "r"); if(file == NULL) { - free(table); - return NULL; + free(table); + return NULL; } while(fgets(buf, sizeof(buf), file)) { - line++; - p = buf; - while(isspace(*p)) p++; + line++; + p = buf; + while(isspace(*p)) p++; - if(!*p || p[0] == '#') - continue; + if(!*p || p[0] == '#') + continue; - value = strtol(p, &p, 16); - if(value > 0xFFFF) { - printf("Line %d: Entry 0x%06lX: File \"%s\" corrupted\n", line, value, table_name); - continue; - } + value = strtol(p, &p, 16); + if(value > 0xFFFF) { + printf("Line %d: Entry 0x%06lX: File \"%s\" corrupted\n", line, value, table_name); + continue; + } - while(isspace(*p)) p++; + while(isspace(*p)) p++; - if(!*p || p[0] == '#') { - /*printf("Line %d: Entry 0x%02lX has no Unicode value\n", line, n);*/ - continue; - } - else { - n = strtol(p, &p, 16); - if(n > 0xFFFF) { - printf("Line %d: Entry 0x%06lX unicode value: File \"%s\" corrupted\n", line, value, table_name); - continue; - } - } + if(!*p || p[0] == '#') { + /*printf("Line %d: Entry 0x%02lX has no Unicode value\n", line, n);*/ + continue; + } + else { + n = strtol(p, &p, 16); + if(n > 0xFFFF) { + printf("Line %d: Entry 0x%06lX unicode value: File \"%s\" corrupted\n", line, value, table_name); + continue; + } + } - if (cpi->CodePage == 864) { - while(isspace(*p)) p++; + if (cpi->CodePage == 864) { + while(isspace(*p)) p++; - if(!*p || p[0] == '#' || p[0] == '-') { - /*printf("Line %d: Entry 0x%02lX has no Unicode value\n", line, n);*/ - continue; - } - else { - n = strtol(p, &p, 16); - if(n > 0xFFFF) { - printf("Line %d: Entry 0x%06lX oem value: File \"%s\" corrupted\n", line, value, table_name); - } - continue; - } - } + if(!*p || p[0] == '#' || p[0] == '-') { + /*printf("Line %d: Entry 0x%02lX has no Unicode value\n", line, n);*/ + continue; + } + else { + n = strtol(p, &p, 16); + if(n > 0xFFFF) { + printf("Line %d: Entry 0x%06lX oem value: File \"%s\" corrupted\n", line, value, table_name); + } + continue; + } + } - table[n] = (WCHAR)value; + table[n] = (WCHAR)value; } fclose(file); @@ -484,124 +484,124 @@ int write_nls_files() CPINFOEXA cpi; int i; struct code_page { - UINT cp; - BOOL oem; - char *table_filename; - char *comment; + UINT cp; + BOOL oem; + char *table_filename; + char *comment; } pages[] = { - {37, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/EBCDIC/CP037.TXT", "IBM EBCDIC US Canada"}, - {424, FALSE, LIBDIR"MAPPINGS/VENDORS/MISC/CP424.TXT", "IBM EBCDIC Hebrew"}, - {437, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP437.TXT", "OEM United States"}, - {500, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/EBCDIC/CP500.TXT", "IBM EBCDIC International"}, - /*{708, FALSE, "", "Arabic ASMO"},*/ - /*{720, FALSE, "", "Arabic Transparent ASMO"},*/ - {737, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP737.TXT", "OEM Greek 437G"}, - {775, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP775.TXT", "OEM Baltic"}, - {850, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP850.TXT", "OEM Multilingual Latin 1"}, - {852, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP852.TXT", "OEM Slovak Latin 2"}, - {855, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP855.TXT", "OEM Cyrillic" }, - {856, TRUE, LIBDIR"MAPPINGS/VENDORS/MISC/CP856.TXT", "Hebrew PC"}, - {857, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP857.TXT", "OEM Turkish"}, - {860, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP860.TXT", "OEM Portuguese"}, - {861, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP861.TXT", "OEM Icelandic"}, - {862, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP862.TXT", "OEM Hebrew"}, - {863, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP863.TXT", "OEM Canadian French"}, - {864, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP864.TXT", "OEM Arabic"}, - {865, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP865.TXT", "OEM Nordic"}, - {866, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP866.TXT", "OEM Russian"}, - {869, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP869.TXT", "OEM Greek"}, - /*{870, FALSE, "", "IBM EBCDIC Multilingual/ROECE (Latin 2)"},*/ - {874, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP874.TXT", "ANSI/OEM Thai"}, - {875, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/EBCDIC/CP875.TXT", "IBM EBCDIC Greek"}, - {878, FALSE, LIBDIR"MAPPINGS/VENDORS/MISC/KOI8-R.TXT", "Russian KOI8"}, - {932, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP932.TXT", "ANSI/OEM Japanese Shift-JIS"}, - {936, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP936.TXT", "ANSI/OEM Simplified Chinese GBK"}, - {949, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP949.TXT", "ANSI/OEM Korean Unified Hangul"}, - {950, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP950.TXT", "ANSI/OEM Traditional Chinese Big5"}, - {1006, FALSE, LIBDIR"MAPPINGS/VENDORS/MISC/CP1006.TXT", "IBM Arabic"}, - {1026, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/EBCDIC/CP1026.TXT", "IBM EBCDIC Latin 5 Turkish"}, - {1250, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1250.TXT", "ANSI Eastern Europe"}, - {1251, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1251.TXT", "ANSI Cyrillic"}, - {1252, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT", "ANSI Latin 1"}, - {1253, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1253.TXT", "ANSI Greek"}, - {1254, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1254.TXT", "ANSI Turkish"}, - {1255, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1255.TXT", "ANSI Hebrew"}, - {1256, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1256.TXT", "ANSI Arabic"}, - {1257, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1257.TXT", "ANSI Baltic"}, - {1258, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1258.TXT", "ANSI/OEM Viet Nam"}, - {10000, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/MAC/ROMAN.TXT", "Mac Roman"}, - {10006, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/MAC/GREEK.TXT", "Mac Greek"}, - {10007, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/MAC/CYRILLIC.TXT", "Mac Cyrillic"}, - {10029, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/MAC/LATIN2.TXT", "Mac Latin 2"}, - {10079, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/MAC/ICELAND.TXT", "Mac Icelandic"}, - {10081, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/MAC/TURKISH.TXT", "Mac Turkish"}, - /*{20000, FALSE, "", "CNS Taiwan"},*/ - /*{20001, FALSE, "", "TCA Taiwan"},*/ - /*{20002, FALSE, "", "Eten Taiwan"},*/ - /*{20003, FALSE, "", "IBM5550 Taiwan"},*/ - /*{20004, FALSE, "", "TeleText Taiwan"},*/ - /*{20005, FALSE, "", "Wang Taiwan"},*/ - /*{20105, FALSE, "", "IA5 IRV International Alphabet No.5"},*/ - /*{20106, FALSE, "", "IA5 German"},*/ - /*{20107, FALSE, "", "IA5 Swedish"},*/ - /*{20108, FALSE, "", "IA5 Norwegian"},*/ - /*{20127, FALSE, "", "US ASCII"}, */ - /*{20261, FALSE, "", "T.61"},*/ - /*{20269, FALSE, "", "ISO 6937 NonSpacing Accent"},*/ - /*{20273, FALSE, "", "IBM EBCDIC Germany"},*/ - /*{20277, FALSE, "", "IBM EBCDIC Denmark/Norway"},*/ - /*{20278, FALSE, "", "IBM EBCDIC Finland/Sweden"},*/ - /*{20280, FALSE, "", "IBM EBCDIC Italy"},*/ - /*{20284, FALSE, "", "IBM EBCDIC Latin America/Spain"},*/ - /*{20285, FALSE, "", "IBM EBCDIC United Kingdom"},*/ - /*{20290, FALSE, "", "IBM EBCDIC Japanese Katakana Extended"},*/ - /*{20297, FALSE, "", "IBM EBCDIC France"},*/ - /*{20420, FALSE, "", "IBM EBCDIC Arabic"},*/ - /*{20423, FALSE, "IBM869.TXT", "IBM EBCDIC Greek"},*/ - /*{20424, FALSE, "", "IBM EBCDIC Hebrew"},*/ - /*{20833, FALSE, "", "IBM EBCDIC Korean Extended"},*/ - /*{20838, FALSE, "", "IBM EBCDIC Thai"},*/ - {20871, FALSE, "ReactOS/IBMCP861.TXT", "IBM EBCDIC Icelandic"}, - /*{20880, FALSE, "", "IBM EBCDIC Cyrillic (Russian)"},*/ - {20866, FALSE, LIBDIR"MAPPINGS/VENDORS/MISC/KOI8-R.TXT", "Russian KOI8"}, - /*{20905, FALSE, "", "IBM EBCDIC Turkish"},*/ - /*{21025, FALSE, "", "IBM EBCDIC Cyrillic (Serbian, Bulgarian)"},*/ - /*{21027, FALSE, "", "Ext Alpha Lowercase"},*/ - {28591, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-1.TXT", "ISO 8859-1 Latin 1"}, - {28592, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-2.TXT", "ISO 8859-2 Eastern Europe"}, - {28593, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-3.TXT", "ISO 8859-3 Turkish"}, - {28594, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-4.TXT", "ISO 8859-4 Baltic"}, - {28595, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-5.TXT", "ISO 8859-5 Cyrillic"}, - {28596, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-6.TXT", "ISO 8859-6 Arabic"}, - {28597, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-7.TXT", "ISO 8859-7 Greek"}, - {28598, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-8.TXT", "ISO 8859-8 Hebrew"}, - {28599, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-9.TXT", "ISO 8859-9 Latin 5"} + {37, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/EBCDIC/CP037.TXT", "IBM EBCDIC US Canada"}, + {424, FALSE, LIBDIR"MAPPINGS/VENDORS/MISC/CP424.TXT", "IBM EBCDIC Hebrew"}, + {437, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP437.TXT", "OEM United States"}, + {500, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/EBCDIC/CP500.TXT", "IBM EBCDIC International"}, + /*{708, FALSE, "", "Arabic ASMO"},*/ + /*{720, FALSE, "", "Arabic Transparent ASMO"},*/ + {737, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP737.TXT", "OEM Greek 437G"}, + {775, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP775.TXT", "OEM Baltic"}, + {850, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP850.TXT", "OEM Multilingual Latin 1"}, + {852, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP852.TXT", "OEM Slovak Latin 2"}, + {855, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP855.TXT", "OEM Cyrillic" }, + {856, TRUE, LIBDIR"MAPPINGS/VENDORS/MISC/CP856.TXT", "Hebrew PC"}, + {857, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP857.TXT", "OEM Turkish"}, + {860, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP860.TXT", "OEM Portuguese"}, + {861, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP861.TXT", "OEM Icelandic"}, + {862, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP862.TXT", "OEM Hebrew"}, + {863, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP863.TXT", "OEM Canadian French"}, + {864, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP864.TXT", "OEM Arabic"}, + {865, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP865.TXT", "OEM Nordic"}, + {866, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP866.TXT", "OEM Russian"}, + {869, TRUE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP869.TXT", "OEM Greek"}, + /*{870, FALSE, "", "IBM EBCDIC Multilingual/ROECE (Latin 2)"},*/ + {874, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/PC/CP874.TXT", "ANSI/OEM Thai"}, + {875, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/EBCDIC/CP875.TXT", "IBM EBCDIC Greek"}, + {878, FALSE, LIBDIR"MAPPINGS/VENDORS/MISC/KOI8-R.TXT", "Russian KOI8"}, + {932, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP932.TXT", "ANSI/OEM Japanese Shift-JIS"}, + {936, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP936.TXT", "ANSI/OEM Simplified Chinese GBK"}, + {949, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP949.TXT", "ANSI/OEM Korean Unified Hangul"}, + {950, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP950.TXT", "ANSI/OEM Traditional Chinese Big5"}, + {1006, FALSE, LIBDIR"MAPPINGS/VENDORS/MISC/CP1006.TXT", "IBM Arabic"}, + {1026, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/EBCDIC/CP1026.TXT", "IBM EBCDIC Latin 5 Turkish"}, + {1250, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1250.TXT", "ANSI Eastern Europe"}, + {1251, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1251.TXT", "ANSI Cyrillic"}, + {1252, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT", "ANSI Latin 1"}, + {1253, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1253.TXT", "ANSI Greek"}, + {1254, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1254.TXT", "ANSI Turkish"}, + {1255, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1255.TXT", "ANSI Hebrew"}, + {1256, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1256.TXT", "ANSI Arabic"}, + {1257, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1257.TXT", "ANSI Baltic"}, + {1258, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1258.TXT", "ANSI/OEM Viet Nam"}, + {10000, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/MAC/ROMAN.TXT", "Mac Roman"}, + {10006, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/MAC/GREEK.TXT", "Mac Greek"}, + {10007, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/MAC/CYRILLIC.TXT", "Mac Cyrillic"}, + {10029, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/MAC/LATIN2.TXT", "Mac Latin 2"}, + {10079, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/MAC/ICELAND.TXT", "Mac Icelandic"}, + {10081, FALSE, LIBDIR"MAPPINGS/VENDORS/MICSFT/MAC/TURKISH.TXT", "Mac Turkish"}, + /*{20000, FALSE, "", "CNS Taiwan"},*/ + /*{20001, FALSE, "", "TCA Taiwan"},*/ + /*{20002, FALSE, "", "Eten Taiwan"},*/ + /*{20003, FALSE, "", "IBM5550 Taiwan"},*/ + /*{20004, FALSE, "", "TeleText Taiwan"},*/ + /*{20005, FALSE, "", "Wang Taiwan"},*/ + /*{20105, FALSE, "", "IA5 IRV International Alphabet No.5"},*/ + /*{20106, FALSE, "", "IA5 German"},*/ + /*{20107, FALSE, "", "IA5 Swedish"},*/ + /*{20108, FALSE, "", "IA5 Norwegian"},*/ + /*{20127, FALSE, "", "US ASCII"}, */ + /*{20261, FALSE, "", "T.61"},*/ + /*{20269, FALSE, "", "ISO 6937 NonSpacing Accent"},*/ + /*{20273, FALSE, "", "IBM EBCDIC Germany"},*/ + /*{20277, FALSE, "", "IBM EBCDIC Denmark/Norway"},*/ + /*{20278, FALSE, "", "IBM EBCDIC Finland/Sweden"},*/ + /*{20280, FALSE, "", "IBM EBCDIC Italy"},*/ + /*{20284, FALSE, "", "IBM EBCDIC Latin America/Spain"},*/ + /*{20285, FALSE, "", "IBM EBCDIC United Kingdom"},*/ + /*{20290, FALSE, "", "IBM EBCDIC Japanese Katakana Extended"},*/ + /*{20297, FALSE, "", "IBM EBCDIC France"},*/ + /*{20420, FALSE, "", "IBM EBCDIC Arabic"},*/ + /*{20423, FALSE, "IBM869.TXT", "IBM EBCDIC Greek"},*/ + /*{20424, FALSE, "", "IBM EBCDIC Hebrew"},*/ + /*{20833, FALSE, "", "IBM EBCDIC Korean Extended"},*/ + /*{20838, FALSE, "", "IBM EBCDIC Thai"},*/ + {20871, FALSE, "ReactOS/IBMCP861.TXT", "IBM EBCDIC Icelandic"}, + /*{20880, FALSE, "", "IBM EBCDIC Cyrillic (Russian)"},*/ + {20866, FALSE, LIBDIR"MAPPINGS/VENDORS/MISC/KOI8-R.TXT", "Russian KOI8"}, + /*{20905, FALSE, "", "IBM EBCDIC Turkish"},*/ + /*{21025, FALSE, "", "IBM EBCDIC Cyrillic (Serbian, Bulgarian)"},*/ + /*{21027, FALSE, "", "Ext Alpha Lowercase"},*/ + {28591, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-1.TXT", "ISO 8859-1 Latin 1"}, + {28592, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-2.TXT", "ISO 8859-2 Eastern Europe"}, + {28593, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-3.TXT", "ISO 8859-3 Turkish"}, + {28594, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-4.TXT", "ISO 8859-4 Baltic"}, + {28595, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-5.TXT", "ISO 8859-5 Cyrillic"}, + {28596, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-6.TXT", "ISO 8859-6 Arabic"}, + {28597, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-7.TXT", "ISO 8859-7 Greek"}, + {28598, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-8.TXT", "ISO 8859-8 Hebrew"}, + {28599, FALSE, LIBDIR"MAPPINGS/ISO8859/8859-9.TXT", "ISO 8859-9 Latin 5"} }; for(i = 0; i < sizeof(pages)/sizeof(pages[0]); i++) { - table = Load_CP2Unicode_Table(pages[i].table_filename, pages[i].cp, &cpi); - if(!table) { - printf("Could not load \"%s\" (%s)\n", pages[i].table_filename, pages[i].comment); - continue; - } + table = Load_CP2Unicode_Table(pages[i].table_filename, pages[i].cp, &cpi); + if(!table) { + printf("Could not load \"%s\" (%s)\n", pages[i].table_filename, pages[i].comment); + continue; + } - if (pages[i].oem) { - oemtable = Load_OEM2Unicode_Table(LIBDIR"MAPPINGS/VENDORS/MISC/IBMGRAPH.TXT", table, pages[i].cp, &cpi); - if(!oemtable) { - printf("Could not load \"%s\" (%s)\n", LIBDIR"MAPPINGS/VENDORS/MISC/IBMGRAPH.TXT", "IBM OEM glyph table"); - continue; - } - } + if (pages[i].oem) { + oemtable = Load_OEM2Unicode_Table(LIBDIR"MAPPINGS/VENDORS/MISC/IBMGRAPH.TXT", table, pages[i].cp, &cpi); + if(!oemtable) { + printf("Could not load \"%s\" (%s)\n", LIBDIR"MAPPINGS/VENDORS/MISC/IBMGRAPH.TXT", "IBM OEM glyph table"); + continue; + } + } - sprintf(nls_filename, "%s/c_%03d.nls", NLSDIR, cpi.CodePage); - if(!create_nls_file(nls_filename, &cpi, table, pages[i].oem ? oemtable : NULL)) { - printf("Could not write \"%s\" (%s)\n", nls_filename, pages[i].comment); - } + sprintf(nls_filename, "%s/c_%03d.nls", NLSDIR, cpi.CodePage); + if(!create_nls_file(nls_filename, &cpi, table, pages[i].oem ? oemtable : NULL)) { + printf("Could not write \"%s\" (%s)\n", nls_filename, pages[i].comment); + } - if (pages[i].oem) - free(oemtable); + if (pages[i].oem) + free(oemtable); - free(table); + free(table); } return 0; @@ -634,29 +634,29 @@ static void test_packed_table(WCHAR *table) len = lstrlenW(test_str); for(i = 0; i < len + 1; i++) { - /*off = table[HIBYTE(test_str[i])]; + /*off = table[HIBYTE(test_str[i])]; - sub_table = table + off; - off = sub_table[LOBYTE(test_str[i]) >> 4]; + sub_table = table + off; + off = sub_table[LOBYTE(test_str[i]) >> 4]; - sub_table = table + off; - off = LOBYTE(test_str[i]) & 0x0F; + sub_table = table + off; + off = LOBYTE(test_str[i]) & 0x0F; - diff = sub_table[off]; + diff = sub_table[off]; - test_str[i] += diff;*/ - test_str[i] += table[table[table[HIBYTE(test_str[i])] + (LOBYTE(test_str[i]) >> 4)] + (LOBYTE(test_str[i]) & 0x0F)]; + test_str[i] += diff;*/ + test_str[i] += table[table[table[HIBYTE(test_str[i])] + (LOBYTE(test_str[i]) >> 4)] + (LOBYTE(test_str[i]) & 0x0F)]; } /* { - FILE *file; - static int n = 0; - char name[20]; + FILE *file; + static int n = 0; + char name[20]; - sprintf(name, "text%02d.dat", n++); - file = fopen(name, "wb"); - fwrite(test_str, len * sizeof(WCHAR), 1, file); - fclose(file); + sprintf(name, "text%02d.dat", n++); + file = fopen(name, "wb"); + fwrite(test_str, len * sizeof(WCHAR), 1, file); + fclose(file); }*/ } @@ -670,136 +670,136 @@ static BOOL CreateCaseDiff(char *table_name) to_upper_org = (WORD *)calloc(65536, sizeof(WORD)); if(!to_upper_org) { - printf("Not enough memory for to upper table\n"); - return FALSE; + printf("Not enough memory for to upper table\n"); + return FALSE; } to_lower_org = (WORD *)calloc(65536, sizeof(WORD)); if(!to_lower_org) { - printf("Not enough memory for to lower table\n"); - return FALSE; + printf("Not enough memory for to lower table\n"); + return FALSE; } file = fopen(table_name, "r"); if(file == NULL) { - printf("Could not open file \"%s\"\n", table_name); - return FALSE; + printf("Could not open file \"%s\"\n", table_name); + return FALSE; } line = 0; while(fgets(buf, sizeof(buf), file)) { - line++; - p = buf; - while(*p && isspace(*p)) p++; + line++; + p = buf; + while(*p && isspace(*p)) p++; - if(!*p) - continue; + if(!*p) + continue; - /* 0. Code value */ - code = (WORD)strtol(p, &p, 16); + /* 0. Code value */ + code = (WORD)strtol(p, &p, 16); - //if(code != 0x9A0 && code != 0xBA0) - //continue; + //if(code != 0x9A0 && code != 0xBA0) + //continue; - while(*p && *p != ';') p++; - if(!*p) - continue; - p++; + while(*p && *p != ';') p++; + if(!*p) + continue; + p++; - /* 1. Character name */ - while(*p && *p != ';') p++; - if(!*p) - continue; - p++; + /* 1. Character name */ + while(*p && *p != ';') p++; + if(!*p) + continue; + p++; - /* 2. General Category */ - while(*p && *p != ';') p++; - if(!*p) - continue; - p++; + /* 2. General Category */ + while(*p && *p != ';') p++; + if(!*p) + continue; + p++; - /* 3. Canonical Combining Classes */ - while(*p && *p != ';') p++; - if(!*p) - continue; - p++; + /* 3. Canonical Combining Classes */ + while(*p && *p != ';') p++; + if(!*p) + continue; + p++; - /* 4. Bidirectional Category */ - while(*p && *p != ';') p++; - if(!*p) - continue; - p++; + /* 4. Bidirectional Category */ + while(*p && *p != ';') p++; + if(!*p) + continue; + p++; - /* 5. Character Decomposition Mapping */ - while(*p && *p != ';') p++; - if(!*p) - continue; - p++; + /* 5. Character Decomposition Mapping */ + while(*p && *p != ';') p++; + if(!*p) + continue; + p++; - /* 6. Decimal digit value */ - while(*p && *p != ';') p++; - if(!*p) - continue; - p++; + /* 6. Decimal digit value */ + while(*p && *p != ';') p++; + if(!*p) + continue; + p++; - /* 7. Digit value */ - while(*p && *p != ';') p++; - if(!*p) - continue; - p++; + /* 7. Digit value */ + while(*p && *p != ';') p++; + if(!*p) + continue; + p++; - /* 8. Numeric value */ - while(*p && *p != ';') p++; - if(!*p) - continue; - p++; + /* 8. Numeric value */ + while(*p && *p != ';') p++; + if(!*p) + continue; + p++; - /* 9. Mirrored */ - while(*p && *p != ';') p++; - if(!*p) - continue; - p++; + /* 9. Mirrored */ + while(*p && *p != ';') p++; + if(!*p) + continue; + p++; - /* 10. Unicode 1.0 Name */ - while(*p && *p != ';') p++; - if(!*p) - continue; - p++; + /* 10. Unicode 1.0 Name */ + while(*p && *p != ';') p++; + if(!*p) + continue; + p++; - /* 11. 10646 comment field */ - while(*p && *p != ';') p++; - if(!*p) - continue; - p++; + /* 11. 10646 comment field */ + while(*p && *p != ';') p++; + if(!*p) + continue; + p++; - /* 12. Uppercase Mapping */ - while(*p && isspace(*p)) p++; - if(!*p) continue; - if(*p != ';') { - case_mapping = (WORD)strtol(p, &p, 16); - to_upper_org[code] = case_mapping - code; - while(*p && *p != ';') p++; - } - else - p++; + /* 12. Uppercase Mapping */ + while(*p && isspace(*p)) p++; + if(!*p) continue; + if(*p != ';') { + case_mapping = (WORD)strtol(p, &p, 16); + to_upper_org[code] = case_mapping - code; + while(*p && *p != ';') p++; + } + else + p++; - /* 13. Lowercase Mapping */ - while(*p && isspace(*p)) p++; - if(!*p) continue; - if(*p != ';') { - case_mapping = (WORD)strtol(p, &p, 16); - to_lower_org[code] = case_mapping - code; - while(*p && *p != ';') p++; - } - else - p++; + /* 13. Lowercase Mapping */ + while(*p && isspace(*p)) p++; + if(!*p) continue; + if(*p != ';') { + case_mapping = (WORD)strtol(p, &p, 16); + to_lower_org[code] = case_mapping - code; + while(*p && *p != ';') p++; + } + else + p++; - /* 14. Titlecase Mapping */ - while(*p && *p != ';') p++; - if(!*p) - continue; - p++; + /* 14. Titlecase Mapping */ + while(*p && *p != ';') p++; + if(!*p) + continue; + p++; } fclose(file); @@ -813,8 +813,8 @@ static int find_diff(WORD diff) int i; for(i = 0; i < number_of_diffs; i++) { - if(diffs[i] == diff) - return i; + if(diffs[i] == diff) + return i; } return -1; @@ -826,14 +826,14 @@ static WORD find_subtable_with_diffs(WORD *table, WORD *subtable) WORD index; for(index = 0; index < number_of_subtables_with_diffs; index++) { - if(memcmp(subtables_with_diffs[index], subtable, 16 * sizeof(WORD)) == 0) { - return index; - } + if(memcmp(subtables_with_diffs[index], subtable, 16 * sizeof(WORD)) == 0) { + return index; + } } if(number_of_subtables_with_diffs >= 4096) { - printf("Could not add new subtable with diffs, storage is full\n"); - return 0; + printf("Could not add new subtable with diffs, storage is full\n"); + return 0; } subtables_with_diffs[number_of_subtables_with_diffs] = subtable; @@ -847,14 +847,14 @@ static WORD find_subtable_with_offsets(WORD *subtable) WORD index; for(index = 0; index < number_of_subtables_with_offsets; index++) { - if(memcmp(&subtables_with_offsets[index * 16], subtable, 16 * sizeof(WORD)) == 0) { - return index; - } + if(memcmp(&subtables_with_offsets[index * 16], subtable, 16 * sizeof(WORD)) == 0) { + return index; + } } if(number_of_subtables_with_offsets >= 4096) { - printf("Could not add new subtable with offsets, storage is full\n"); - return 0; + printf("Could not add new subtable with offsets, storage is full\n"); + return 0; } memcpy(&subtables_with_offsets[number_of_subtables_with_offsets * 16], subtable, 16 * sizeof(WORD)); @@ -878,14 +878,14 @@ static WORD *pack_table(WORD *table, WORD *packed_size_in_words) number_of_subtables_with_offsets = 0; for(high = 0; high < 256; high++) { - for(low4 = 0; low4 < 256; low4 += 16) { - index = find_subtable_with_diffs(table, &table[MAKEWORD(low4, high)]); + for(low4 = 0; low4 < 256; low4 += 16) { + index = find_subtable_with_diffs(table, &table[MAKEWORD(low4, high)]); - temp_subtable[low4 >> 4] = index; - } + temp_subtable[low4 >> 4] = index; + } - index = find_subtable_with_offsets(temp_subtable); - main_index[high] = index; + index = find_subtable_with_offsets(temp_subtable); + main_index[high] = index; } *packed_size_in_words = 0x100 + number_of_subtables_with_offsets * 16 + number_of_subtables_with_diffs * 16; @@ -893,25 +893,25 @@ static WORD *pack_table(WORD *table, WORD *packed_size_in_words) /* fill main index according to the subtables_with_offsets */ for(high = 0; high < 256; high++) { - packed_table[high] = 0x100 + main_index[high] * 16; + packed_table[high] = 0x100 + main_index[high] * 16; } //memcpy(sub_table, subtables_with_offsets, number_of_subtables_with_offsets * 16); /* fill subtable index according to the subtables_with_diffs */ for(index = 0; index < number_of_subtables_with_offsets; index++) { - subtable_dst = packed_table + 0x100 + index * 16; - subtable_src = &subtables_with_offsets[index * 16]; + subtable_dst = packed_table + 0x100 + index * 16; + subtable_src = &subtables_with_offsets[index * 16]; - for(low4 = 0; low4 < 16; low4++) { - subtable_dst[low4] = 0x100 + number_of_subtables_with_offsets * 16 + subtable_src[low4] * 16; - } + for(low4 = 0; low4 < 16; low4++) { + subtable_dst[low4] = 0x100 + number_of_subtables_with_offsets * 16 + subtable_src[low4] * 16; + } } for(index = 0; index < number_of_subtables_with_diffs; index++) { - subtable_dst = packed_table + 0x100 + number_of_subtables_with_offsets * 16 + index * 16; - memcpy(subtable_dst, subtables_with_diffs[index], 16 * sizeof(WORD)); + subtable_dst = packed_table + 0x100 + number_of_subtables_with_offsets * 16 + index * 16; + memcpy(subtable_dst, subtables_with_diffs[index], 16 * sizeof(WORD)); } @@ -928,7 +928,7 @@ int write_casemap_file(void) FILE *file; if(!CreateCaseDiff(LIBDIR"UnicodeData.txt")) - return -1; + return -1; file = fopen(NLSDIR"/l_intl.nls", "wb"); @@ -962,8 +962,8 @@ int write_casemap_file(void) int main() { - write_nls_files(); - write_casemap_file(); + write_nls_files(); + write_casemap_file(); - return 0; + return 0; } diff --git a/reactos/tools/log2lines/CMakeLists.txt b/reactos/tools/log2lines/CMakeLists.txt index 0eb9c39ccbf..18b56580e5f 100644 --- a/reactos/tools/log2lines/CMakeLists.txt +++ b/reactos/tools/log2lines/CMakeLists.txt @@ -10,8 +10,8 @@ list(APPEND SOURCE options.c revision.c stat.c - util.c) + util.c) include_directories(${REACTOS_SOURCE_DIR}/tools/rsym) add_executable(log2lines ${SOURCE}) -target_link_libraries(log2lines rsym_common) +target_link_libraries(log2lines rsym_common) diff --git a/reactos/tools/log2lines/cache.c b/reactos/tools/log2lines/cache.c index 31ad78bd0f7..c46bc40c1f4 100644 --- a/reactos/tools/log2lines/cache.c +++ b/reactos/tools/log2lines/cache.c @@ -69,9 +69,9 @@ unpack_iso(char *dir, char *iso) int cleanable(char *path) { - if (strcmp(basename(path),DEF_OPT_DIR) == 0) - return 1; - return 0; + if (strcmp(basename(path),DEF_OPT_DIR) == 0) + return 1; + return 0; } int @@ -144,10 +144,10 @@ check_directory(int force) cache_name = malloc(PATH_MAX); tmp_name = malloc(PATH_MAX); strcpy(cache_name, opt_dir); - if (cleanable(opt_dir)) - strcat(cache_name, ALT_PATH_STR CACHEFILE); - else - strcat(cache_name, PATH_STR CACHEFILE); + if (cleanable(opt_dir)) + strcat(cache_name, ALT_PATH_STR CACHEFILE); + else + strcat(cache_name, PATH_STR CACHEFILE); strcpy(tmp_name, cache_name); strcat(tmp_name, "~"); return 0; diff --git a/reactos/tools/log2lines/cmd.c b/reactos/tools/log2lines/cmd.c index 8fd80bd859b..5a817a3e182 100644 --- a/reactos/tools/log2lines/cmd.c +++ b/reactos/tools/log2lines/cmd.c @@ -160,7 +160,7 @@ handle_address_cmd(FILE *outFile, char *arg) if (( plm = entry_lookup(&cache, Image) )) { if (plm->RelBase != INVALID_BASE) - esclog(outFile, "Address: 0x%lx\n", plm->RelBase + Offset) + esclog(outFile, "Address: 0x%lx\n", plm->RelBase + Offset) else esclog(outFile, "Relocated base missing for '%s' ('mod' will update)\n", Image); } @@ -168,7 +168,7 @@ handle_address_cmd(FILE *outFile, char *arg) esclog(outFile, "Image '%s' not found\n", Image); } else - esclog(outFile, "usage: `a :\n"); + esclog(outFile, "usage: `a :\n"); } else esclog(outFile, "':' expected\n"); @@ -259,10 +259,10 @@ handle_escape_cmd(FILE *outFile, char *Line, char *path, char *LineOut) break; case 'R': changed = handle_switch_pstr(outFile, &opt_Revision, arg, NULL); - opt_Revision_check = 0; + opt_Revision_check = 0; if (opt_Revision) { - opt_Revision_check = 1; + opt_Revision_check = 1; if (strstr(opt_Revision, "check") == opt_Revision) { esclog(outFile, "-R is \"%s\" (%s)\n", opt_Revision, changed ? "changed":"unchanged"); @@ -302,7 +302,7 @@ handle_escape_cmd(FILE *outFile, char *Line, char *path, char *LineOut) { handle_switch(outFile, &opt_undo, "1", "-u Undo"); handle_switch(outFile, &opt_redo, "1", "-U Undo and reprocess"); - opt_Revision_check = 1; + opt_Revision_check = 1; } esclog(outFile, "-S Sources option is %d+%d,\"%s\"\n", opt_Source, opt_SrcPlus, opt_SourcesPath); esclog(outFile, "(Setting source tree not implemented)\n"); diff --git a/reactos/tools/log2lines/config.h b/reactos/tools/log2lines/config.h index d1c73898e94..5f3d3cb6e96 100644 --- a/reactos/tools/log2lines/config.h +++ b/reactos/tools/log2lines/config.h @@ -27,8 +27,8 @@ PATH_STR "reactos" PATH_STR "reactos > " DEV_NULL /* When we can't use a normal path, because it gets cleaned, - * fallback to name mangling: - */ + * fallback to name mangling: + */ #define ALT_PATH_STR "#" #define LINESIZE 1024 diff --git a/reactos/tools/log2lines/list.c b/reactos/tools/log2lines/list.c index 3fdd22b564d..3a6cfe7c6b0 100644 --- a/reactos/tools/log2lines/list.c +++ b/reactos/tools/log2lines/list.c @@ -43,7 +43,7 @@ entry_lookup(PLIST list, char *name) return NULL; } -PLIST_MEMBER +PLIST_MEMBER entry_delete(PLIST_MEMBER pentry) { if (!pentry) @@ -54,7 +54,7 @@ entry_delete(PLIST_MEMBER pentry) return NULL; } -PLIST_MEMBER +PLIST_MEMBER entry_insert(PLIST list, PLIST_MEMBER pentry) { if (!pentry) @@ -115,7 +115,7 @@ entry_remove(LIST *list, LIST_MEMBER *pentry) } #endif -PLIST_MEMBER +PLIST_MEMBER cache_entry_create(char *Line) { PLIST_MEMBER pentry; @@ -169,7 +169,7 @@ cache_entry_create(char *Line) } -PLIST_MEMBER +PLIST_MEMBER sources_entry_create(PLIST list, char *path, char *prefix) { PLIST_MEMBER pentry; diff --git a/reactos/tools/log2lines/options.c b/reactos/tools/log2lines/options.c index 7de58ff7f77..0bcbf068dc0 100644 --- a/reactos/tools/log2lines/options.c +++ b/reactos/tools/log2lines/options.c @@ -70,7 +70,7 @@ int optionInit(int argc, const char **argv) //The user introduced "log2lines.exe" or "log2lines.exe /?" //Let's help the user - if ((argc == 1) || + if ((argc == 1) || ((argc == 2) && (argv[1][0] == '/') && (argv[1][1] == '?'))) { opt_help++; @@ -169,8 +169,8 @@ int optionParse(int argc, const char **argv) free(opt_Revision); opt_Revision = malloc(LINESIZE); sscanf(optarg, "%s", opt_Revision); - if (strcmp(opt_Revision, "check") == 0) - opt_Revision_check ++; + if (strcmp(opt_Revision, "check") == 0) + opt_Revision_check ++; break; case 's': opt_stats++; @@ -186,7 +186,7 @@ int optionParse(int argc, const char **argv) /* need to retranslate for source info: */ opt_undo++; opt_redo++; - opt_Revision_check ++; + opt_Revision_check ++; } break; case 't': diff --git a/reactos/tools/log2lines/revision.h b/reactos/tools/log2lines/revision.h index 6da59ad03e3..54714259180 100644 --- a/reactos/tools/log2lines/revision.h +++ b/reactos/tools/log2lines/revision.h @@ -11,7 +11,7 @@ typedef struct revinfo_struct { - int rev; + int rev; int buildrev; int range; int opt_verbose; diff --git a/reactos/tools/log2lines/stat.c b/reactos/tools/log2lines/stat.c index 801f693bde2..8cd6e703cba 100644 --- a/reactos/tools/log2lines/stat.c +++ b/reactos/tools/log2lines/stat.c @@ -37,7 +37,7 @@ stat_print(FILE *outFile, PSUMM psumm) } } -void +void stat_clear(PSUMM psumm) { memset(psumm, 0, sizeof(SUMM)); diff --git a/reactos/tools/mkhive/binhive.c b/reactos/tools/mkhive/binhive.c index 0921160aa18..540d1708507 100644 --- a/reactos/tools/mkhive/binhive.c +++ b/reactos/tools/mkhive/binhive.c @@ -31,28 +31,28 @@ BOOL ExportBinaryHive( - IN PCSTR FileName, - IN PCMHIVE Hive) + IN PCSTR FileName, + IN PCMHIVE Hive) { - FILE *File; - BOOL ret; + FILE *File; + BOOL ret; - printf (" Creating binary hive: %s\n", FileName); + printf (" Creating binary hive: %s\n", FileName); - /* Create new hive file */ - File = fopen (FileName, "w+b"); - if (File == NULL) - { - printf(" Error creating/opening file\n"); - return FALSE; - } + /* Create new hive file */ + File = fopen (FileName, "w+b"); + if (File == NULL) + { + printf(" Error creating/opening file\n"); + return FALSE; + } - fseek (File, 0, SEEK_SET); + fseek (File, 0, SEEK_SET); - Hive->FileHandles[HFILE_TYPE_PRIMARY] = (HANDLE)File; - ret = HvWriteHive(&Hive->Hive); - fclose (File); - return ret; + Hive->FileHandles[HFILE_TYPE_PRIMARY] = (HANDLE)File; + ret = HvWriteHive(&Hive->Hive); + fclose (File); + return ret; } /* EOF */ diff --git a/reactos/tools/mkhive/binhive.h b/reactos/tools/mkhive/binhive.h index 43becbf9abd..f319427bd3a 100644 --- a/reactos/tools/mkhive/binhive.h +++ b/reactos/tools/mkhive/binhive.h @@ -27,7 +27,7 @@ BOOL ExportBinaryHive( - IN PCSTR FileName, - IN PCMHIVE Hive); + IN PCSTR FileName, + IN PCMHIVE Hive); /* EOF */ diff --git a/reactos/tools/mkhive/cmi.c b/reactos/tools/mkhive/cmi.c index 19ee8b932e8..a38261c6d4e 100644 --- a/reactos/tools/mkhive/cmi.c +++ b/reactos/tools/mkhive/cmi.c @@ -29,89 +29,89 @@ PVOID NTAPI CmpAllocate( - IN SIZE_T Size, - IN BOOLEAN Paged, + IN SIZE_T Size, + IN BOOLEAN Paged, IN ULONG Tag) { - return (PVOID) malloc((size_t)Size); + return (PVOID) malloc((size_t)Size); } VOID NTAPI CmpFree( - IN PVOID Ptr, + IN PVOID Ptr, IN ULONG Quota) { - free(Ptr); + free(Ptr); } static BOOLEAN NTAPI CmpFileRead( - IN PHHIVE RegistryHive, - IN ULONG FileType, - IN PULONG FileOffset, - OUT PVOID Buffer, - IN SIZE_T BufferLength) + IN PHHIVE RegistryHive, + IN ULONG FileType, + IN PULONG FileOffset, + OUT PVOID Buffer, + IN SIZE_T BufferLength) { - DPRINT1("CmpFileRead() unimplemented\n"); - return FALSE; + DPRINT1("CmpFileRead() unimplemented\n"); + return FALSE; } static BOOLEAN NTAPI CmpFileWrite( - IN PHHIVE RegistryHive, - IN ULONG FileType, - IN PULONG FileOffset, - IN PVOID Buffer, - IN SIZE_T BufferLength) + IN PHHIVE RegistryHive, + IN ULONG FileType, + IN PULONG FileOffset, + IN PVOID Buffer, + IN SIZE_T BufferLength) { - PCMHIVE CmHive = (PCMHIVE)RegistryHive; - FILE *File = CmHive->FileHandles[HFILE_TYPE_PRIMARY]; - if (0 != fseek (File, *FileOffset, SEEK_SET)) - return FALSE; - return BufferLength == fwrite (Buffer, 1, BufferLength, File); + PCMHIVE CmHive = (PCMHIVE)RegistryHive; + FILE *File = CmHive->FileHandles[HFILE_TYPE_PRIMARY]; + if (0 != fseek (File, *FileOffset, SEEK_SET)) + return FALSE; + return BufferLength == fwrite (Buffer, 1, BufferLength, File); } static BOOLEAN NTAPI CmpFileSetSize( - IN PHHIVE RegistryHive, - IN ULONG FileType, - IN ULONG FileSize, + IN PHHIVE RegistryHive, + IN ULONG FileType, + IN ULONG FileSize, IN ULONG OldFileSize) { - DPRINT1("CmpFileSetSize() unimplemented\n"); - return FALSE; + DPRINT1("CmpFileSetSize() unimplemented\n"); + return FALSE; } static BOOLEAN NTAPI CmpFileFlush( - IN PHHIVE RegistryHive, - IN ULONG FileType, + IN PHHIVE RegistryHive, + IN ULONG FileType, PLARGE_INTEGER FileOffset, ULONG Length) { - PCMHIVE CmHive = (PCMHIVE)RegistryHive; - FILE *File = CmHive->FileHandles[HFILE_TYPE_PRIMARY]; - return 0 == fflush (File); + PCMHIVE CmHive = (PCMHIVE)RegistryHive; + FILE *File = CmHive->FileHandles[HFILE_TYPE_PRIMARY]; + return 0 == fflush (File); } NTSTATUS CmiInitializeTempHive( - IN OUT PCMHIVE Hive) + IN OUT PCMHIVE Hive) { - NTSTATUS Status; + NTSTATUS Status; - RtlZeroMemory ( - Hive, - sizeof(CMHIVE)); + RtlZeroMemory ( + Hive, + sizeof(CMHIVE)); - DPRINT("Hive 0x%p\n", Hive); + DPRINT("Hive 0x%p\n", Hive); - Status = HvInitialize(&Hive->Hive, + Status = HvInitialize(&Hive->Hive, HINIT_CREATE, 0, 0, @@ -124,325 +124,322 @@ CmiInitializeTempHive( CmpFileFlush, 1, NULL); - if (!NT_SUCCESS(Status)) - { - return Status; - } + if (!NT_SUCCESS(Status)) + { + return Status; + } - if (!CmCreateRootNode (&Hive->Hive, L"")) - { - HvFree (&Hive->Hive); - return STATUS_INSUFFICIENT_RESOURCES; - } + if (!CmCreateRootNode (&Hive->Hive, L"")) + { + HvFree (&Hive->Hive); + return STATUS_INSUFFICIENT_RESOURCES; + } - Hive->Flags = HIVE_NO_FILE; + Hive->Flags = HIVE_NO_FILE; - /* Add the new hive to the hive list */ - InsertTailList ( - &CmiHiveListHead, - &Hive->HiveList); + /* Add the new hive to the hive list */ + InsertTailList(&CmiHiveListHead, + &Hive->HiveList); - VERIFY_REGISTRY_HIVE (Hive); + VERIFY_REGISTRY_HIVE (Hive); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } static NTSTATUS CmiAddKeyToHashTable( - IN PCMHIVE RegistryHive, - IN OUT PCM_KEY_FAST_INDEX HashCell, + IN PCMHIVE RegistryHive, + IN OUT PCM_KEY_FAST_INDEX HashCell, IN HCELL_INDEX HashCellIndex, - IN PCM_KEY_NODE NewKeyCell, - IN HCELL_INDEX NKBOffset) + IN PCM_KEY_NODE NewKeyCell, + IN HCELL_INDEX NKBOffset) { - ULONG i; - ULONG HashKey = 0; + ULONG i; + ULONG HashKey = 0; - if (NewKeyCell->Flags & KEY_COMP_NAME) - { - RtlCopyMemory( - &HashKey, - NewKeyCell->Name, - min(NewKeyCell->NameLength, sizeof(ULONG))); - } + if (NewKeyCell->Flags & KEY_COMP_NAME) + { + RtlCopyMemory( + &HashKey, + NewKeyCell->Name, + min(NewKeyCell->NameLength, sizeof(ULONG))); + } - for (i = 0; i < HashCell->Count; i++) - { - if (HashCell->List[i].HashKey > HashKey) - break; - } + for (i = 0; i < HashCell->Count; i++) + { + if (HashCell->List[i].HashKey > HashKey) + break; + } - if (i < HashCell->Count) - { - RtlMoveMemory(HashCell->List + i + 1, - HashCell->List + i, - (HashCell->Count - i) * - sizeof(HashCell->List[0])); - } + if (i < HashCell->Count) + { + RtlMoveMemory(HashCell->List + i + 1, + HashCell->List + i, + (HashCell->Count - i) * + sizeof(HashCell->List[0])); + } - HashCell->List[i].Cell = NKBOffset; - HashCell->List[i].HashKey = HashKey; + HashCell->List[i].Cell = NKBOffset; + HashCell->List[i].HashKey = HashKey; HashCell->Count++; - HvMarkCellDirty(&RegistryHive->Hive, HashCellIndex, FALSE); - return STATUS_SUCCESS; + HvMarkCellDirty(&RegistryHive->Hive, HashCellIndex, FALSE); + return STATUS_SUCCESS; } static NTSTATUS CmiAllocateHashTableCell ( - IN PCMHIVE RegistryHive, - OUT PCM_KEY_FAST_INDEX *HashBlock, - OUT HCELL_INDEX *HBOffset, - IN USHORT SubKeyCount, - IN HSTORAGE_TYPE Storage) + IN PCMHIVE RegistryHive, + OUT PCM_KEY_FAST_INDEX *HashBlock, + OUT HCELL_INDEX *HBOffset, + IN USHORT SubKeyCount, + IN HSTORAGE_TYPE Storage) { - PCM_KEY_FAST_INDEX NewHashBlock; - ULONG NewHashSize; - NTSTATUS Status; + PCM_KEY_FAST_INDEX NewHashBlock; + ULONG NewHashSize; + NTSTATUS Status; - Status = STATUS_SUCCESS; - *HashBlock = NULL; - NewHashSize = FIELD_OFFSET(CM_KEY_FAST_INDEX, List) + - (SubKeyCount * sizeof(CM_INDEX)); - *HBOffset = HvAllocateCell(&RegistryHive->Hive, NewHashSize, Storage, HCELL_NIL); + Status = STATUS_SUCCESS; + *HashBlock = NULL; + NewHashSize = FIELD_OFFSET(CM_KEY_FAST_INDEX, List) + + (SubKeyCount * sizeof(CM_INDEX)); + *HBOffset = HvAllocateCell(&RegistryHive->Hive, NewHashSize, Storage, HCELL_NIL); - if (*HBOffset == HCELL_NIL) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - } - else - { - NewHashBlock = (PCM_KEY_FAST_INDEX)HvGetCell (&RegistryHive->Hive, *HBOffset); - NewHashBlock->Signature = CM_KEY_FAST_LEAF; - NewHashBlock->Count = 0; - *HashBlock = NewHashBlock; - } + if (*HBOffset == HCELL_NIL) + { + Status = STATUS_INSUFFICIENT_RESOURCES; + } + else + { + NewHashBlock = (PCM_KEY_FAST_INDEX)HvGetCell (&RegistryHive->Hive, *HBOffset); + NewHashBlock->Signature = CM_KEY_FAST_LEAF; + NewHashBlock->Count = 0; + *HashBlock = NewHashBlock; + } - return Status; + return Status; } NTSTATUS CmiCreateSubKey( - IN PCMHIVE RegistryHive, - IN HCELL_INDEX ParentKeyCellOffset, - IN PCUNICODE_STRING SubKeyName, - IN ULONG CreateOptions, - OUT HCELL_INDEX* pNKBOffset) + IN PCMHIVE RegistryHive, + IN HCELL_INDEX ParentKeyCellOffset, + IN PCUNICODE_STRING SubKeyName, + IN ULONG CreateOptions, + OUT HCELL_INDEX* pNKBOffset) { - HCELL_INDEX NKBOffset; - PCM_KEY_NODE NewKeyCell; - ULONG NewBlockSize; - NTSTATUS Status; - USHORT NameLength; - PWSTR NamePtr; - BOOLEAN Packable; - HSTORAGE_TYPE Storage; - ULONG i; + HCELL_INDEX NKBOffset; + PCM_KEY_NODE NewKeyCell; + ULONG NewBlockSize; + NTSTATUS Status; + USHORT NameLength; + PWSTR NamePtr; + BOOLEAN Packable; + HSTORAGE_TYPE Storage; + ULONG i; - /* Skip leading backslash */ - if (SubKeyName->Buffer[0] == L'\\') - { - NamePtr = &SubKeyName->Buffer[1]; - NameLength = SubKeyName->Length - sizeof(WCHAR); - } - else - { - NamePtr = SubKeyName->Buffer; - NameLength = SubKeyName->Length; - } + /* Skip leading backslash */ + if (SubKeyName->Buffer[0] == L'\\') + { + NamePtr = &SubKeyName->Buffer[1]; + NameLength = SubKeyName->Length - sizeof(WCHAR); + } + else + { + NamePtr = SubKeyName->Buffer; + NameLength = SubKeyName->Length; + } - /* Check whether key name can be packed */ - Packable = TRUE; - for (i = 0; i < NameLength / sizeof(WCHAR); i++) - { - if (NamePtr[i] & 0xFF00) - { - Packable = FALSE; - break; - } - } + /* Check whether key name can be packed */ + Packable = TRUE; + for (i = 0; i < NameLength / sizeof(WCHAR); i++) + { + if (NamePtr[i] & 0xFF00) + { + Packable = FALSE; + break; + } + } - /* Adjust name size */ - if (Packable) - { - NameLength = NameLength / sizeof(WCHAR); - } + /* Adjust name size */ + if (Packable) + { + NameLength = NameLength / sizeof(WCHAR); + } - Status = STATUS_SUCCESS; + Status = STATUS_SUCCESS; - Storage = (CreateOptions & REG_OPTION_VOLATILE) ? Volatile : Stable; - NewBlockSize = FIELD_OFFSET(CM_KEY_NODE, Name) + NameLength; - NKBOffset = HvAllocateCell(&RegistryHive->Hive, NewBlockSize, Storage, HCELL_NIL); - if (NKBOffset == HCELL_NIL) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - } - else - { - NewKeyCell = (PCM_KEY_NODE)HvGetCell (&RegistryHive->Hive, NKBOffset); - NewKeyCell->Signature = CM_KEY_NODE_SIGNATURE; - if (CreateOptions & REG_OPTION_VOLATILE) - { - NewKeyCell->Flags = KEY_IS_VOLATILE; - } - else - { - NewKeyCell->Flags = 0; - } - KeQuerySystemTime(&NewKeyCell->LastWriteTime); - NewKeyCell->Parent = ParentKeyCellOffset; - NewKeyCell->SubKeyCounts[Stable] = 0; - NewKeyCell->SubKeyCounts[Volatile] = 0; - NewKeyCell->SubKeyLists[Stable] = HCELL_NIL; - NewKeyCell->SubKeyLists[Volatile] = HCELL_NIL; - NewKeyCell->ValueList.Count = 0; - NewKeyCell->ValueList.List = HCELL_NIL; - NewKeyCell->Security = HCELL_NIL; - NewKeyCell->Class = HCELL_NIL; + Storage = (CreateOptions & REG_OPTION_VOLATILE) ? Volatile : Stable; + NewBlockSize = FIELD_OFFSET(CM_KEY_NODE, Name) + NameLength; + NKBOffset = HvAllocateCell(&RegistryHive->Hive, NewBlockSize, Storage, HCELL_NIL); + if (NKBOffset == HCELL_NIL) + { + Status = STATUS_INSUFFICIENT_RESOURCES; + } + else + { + NewKeyCell = (PCM_KEY_NODE)HvGetCell (&RegistryHive->Hive, NKBOffset); + NewKeyCell->Signature = CM_KEY_NODE_SIGNATURE; + if (CreateOptions & REG_OPTION_VOLATILE) + { + NewKeyCell->Flags = KEY_IS_VOLATILE; + } + else + { + NewKeyCell->Flags = 0; + } + KeQuerySystemTime(&NewKeyCell->LastWriteTime); + NewKeyCell->Parent = ParentKeyCellOffset; + NewKeyCell->SubKeyCounts[Stable] = 0; + NewKeyCell->SubKeyCounts[Volatile] = 0; + NewKeyCell->SubKeyLists[Stable] = HCELL_NIL; + NewKeyCell->SubKeyLists[Volatile] = HCELL_NIL; + NewKeyCell->ValueList.Count = 0; + NewKeyCell->ValueList.List = HCELL_NIL; + NewKeyCell->Security = HCELL_NIL; + NewKeyCell->Class = HCELL_NIL; - /* Pack the key name */ - NewKeyCell->NameLength = NameLength; - if (Packable) - { - NewKeyCell->Flags |= KEY_COMP_NAME; - for (i = 0; i < NameLength; i++) - { - ((PCHAR)NewKeyCell->Name)[i] = (CHAR)(NamePtr[i] & 0x00FF); - } - } - else - { - RtlCopyMemory( - NewKeyCell->Name, - NamePtr, - NameLength); - } + /* Pack the key name */ + NewKeyCell->NameLength = NameLength; + if (Packable) + { + NewKeyCell->Flags |= KEY_COMP_NAME; + for (i = 0; i < NameLength; i++) + { + ((PCHAR)NewKeyCell->Name)[i] = (CHAR)(NamePtr[i] & 0x00FF); + } + } + else + { + RtlCopyMemory(NewKeyCell->Name, + NamePtr, + NameLength); + } - VERIFY_KEY_CELL(NewKeyCell); - } + VERIFY_KEY_CELL(NewKeyCell); + } - if (NT_SUCCESS(Status)) - { - *pNKBOffset = NKBOffset; - } - return Status; + if (NT_SUCCESS(Status)) + { + *pNKBOffset = NKBOffset; + } + return Status; } NTSTATUS CmiAddSubKey( - IN PCMHIVE RegistryHive, - IN HCELL_INDEX ParentKeyCellOffset, - IN PCUNICODE_STRING SubKeyName, - IN ULONG CreateOptions, - OUT PCM_KEY_NODE *pSubKeyCell, - OUT HCELL_INDEX *pBlockOffset) + IN PCMHIVE RegistryHive, + IN HCELL_INDEX ParentKeyCellOffset, + IN PCUNICODE_STRING SubKeyName, + IN ULONG CreateOptions, + OUT PCM_KEY_NODE *pSubKeyCell, + OUT HCELL_INDEX *pBlockOffset) { - PCM_KEY_NODE ParentKeyCell; - HCELL_INDEX NKBOffset; - NTSTATUS Status; + PCM_KEY_NODE ParentKeyCell; + HCELL_INDEX NKBOffset; + NTSTATUS Status; - ParentKeyCell = (PCM_KEY_NODE)HvGetCell(&RegistryHive->Hive, ParentKeyCellOffset); - if (!ParentKeyCell) - return STATUS_UNSUCCESSFUL; - VERIFY_KEY_CELL(ParentKeyCell); + ParentKeyCell = (PCM_KEY_NODE)HvGetCell(&RegistryHive->Hive, ParentKeyCellOffset); + if (!ParentKeyCell) + return STATUS_UNSUCCESSFUL; + VERIFY_KEY_CELL(ParentKeyCell); - /* Create the new key */ - Status = CmiCreateSubKey(RegistryHive, ParentKeyCellOffset, SubKeyName, CreateOptions, &NKBOffset); - if (!NT_SUCCESS(Status)) - { - return Status; - } + /* Create the new key */ + Status = CmiCreateSubKey(RegistryHive, ParentKeyCellOffset, SubKeyName, CreateOptions, &NKBOffset); + if (!NT_SUCCESS(Status)) + { + return Status; + } - if (!CmpAddSubKey(&RegistryHive->Hive, ParentKeyCellOffset, NKBOffset)) - { - /* FIXME: delete newly created cell */ - return STATUS_UNSUCCESSFUL; - } + if (!CmpAddSubKey(&RegistryHive->Hive, ParentKeyCellOffset, NKBOffset)) + { + /* FIXME: delete newly created cell */ + return STATUS_UNSUCCESSFUL; + } - KeQuerySystemTime(&ParentKeyCell->LastWriteTime); - HvMarkCellDirty(&RegistryHive->Hive, ParentKeyCellOffset, FALSE); + KeQuerySystemTime(&ParentKeyCell->LastWriteTime); + HvMarkCellDirty(&RegistryHive->Hive, ParentKeyCellOffset, FALSE); - *pBlockOffset = NKBOffset; - return STATUS_SUCCESS; + *pBlockOffset = NKBOffset; + return STATUS_SUCCESS; } static BOOLEAN CmiCompareHash( - IN PCUNICODE_STRING KeyName, - IN PCHAR HashString) + IN PCUNICODE_STRING KeyName, + IN PCHAR HashString) { - CHAR Buffer[4]; + CHAR Buffer[4]; - Buffer[0] = (KeyName->Length >= 2) ? (CHAR)KeyName->Buffer[0] : 0; - Buffer[1] = (KeyName->Length >= 4) ? (CHAR)KeyName->Buffer[1] : 0; - Buffer[2] = (KeyName->Length >= 6) ? (CHAR)KeyName->Buffer[2] : 0; - Buffer[3] = (KeyName->Length >= 8) ? (CHAR)KeyName->Buffer[3] : 0; + Buffer[0] = (KeyName->Length >= 2) ? (CHAR)KeyName->Buffer[0] : 0; + Buffer[1] = (KeyName->Length >= 4) ? (CHAR)KeyName->Buffer[1] : 0; + Buffer[2] = (KeyName->Length >= 6) ? (CHAR)KeyName->Buffer[2] : 0; + Buffer[3] = (KeyName->Length >= 8) ? (CHAR)KeyName->Buffer[3] : 0; - return (strncmp(Buffer, HashString, 4) == 0); + return (strncmp(Buffer, HashString, 4) == 0); } BOOLEAN CmiCompareHashI( - IN PCUNICODE_STRING KeyName, - IN PCHAR HashString) + IN PCUNICODE_STRING KeyName, + IN PCHAR HashString) { - CHAR Buffer[4]; + CHAR Buffer[4]; - Buffer[0] = (KeyName->Length >= 2) ? (CHAR)KeyName->Buffer[0] : 0; - Buffer[1] = (KeyName->Length >= 4) ? (CHAR)KeyName->Buffer[1] : 0; - Buffer[2] = (KeyName->Length >= 6) ? (CHAR)KeyName->Buffer[2] : 0; - Buffer[3] = (KeyName->Length >= 8) ? (CHAR)KeyName->Buffer[3] : 0; + Buffer[0] = (KeyName->Length >= 2) ? (CHAR)KeyName->Buffer[0] : 0; + Buffer[1] = (KeyName->Length >= 4) ? (CHAR)KeyName->Buffer[1] : 0; + Buffer[2] = (KeyName->Length >= 6) ? (CHAR)KeyName->Buffer[2] : 0; + Buffer[3] = (KeyName->Length >= 8) ? (CHAR)KeyName->Buffer[3] : 0; - return (strncasecmp(Buffer, HashString, 4) == 0); + return (strncasecmp(Buffer, HashString, 4) == 0); } NTSTATUS CmiScanForSubKey( - IN PCMHIVE RegistryHive, - IN HCELL_INDEX ParentKeyCellOffset, - IN PCUNICODE_STRING SubKeyName, - IN ULONG Attributes, - OUT PCM_KEY_NODE *pSubKeyCell, - OUT HCELL_INDEX *pBlockOffset) + IN PCMHIVE RegistryHive, + IN HCELL_INDEX ParentKeyCellOffset, + IN PCUNICODE_STRING SubKeyName, + IN ULONG Attributes, + OUT PCM_KEY_NODE *pSubKeyCell, + OUT HCELL_INDEX *pBlockOffset) { - PCM_KEY_NODE KeyCell; - PCM_KEY_FAST_INDEX HashBlock; - PCM_KEY_NODE CurSubKeyCell; - BOOLEAN CaseInsensitive; - ULONG Storage; - ULONG i; + PCM_KEY_NODE KeyCell; + PCM_KEY_FAST_INDEX HashBlock; + PCM_KEY_NODE CurSubKeyCell; + BOOLEAN CaseInsensitive; + ULONG Storage; + ULONG i; - KeyCell = (PCM_KEY_NODE)HvGetCell(&RegistryHive->Hive, ParentKeyCellOffset); - if (!KeyCell) - return STATUS_UNSUCCESSFUL; - VERIFY_KEY_CELL(KeyCell); + KeyCell = (PCM_KEY_NODE)HvGetCell(&RegistryHive->Hive, ParentKeyCellOffset); + if (!KeyCell) + return STATUS_UNSUCCESSFUL; + VERIFY_KEY_CELL(KeyCell); - ASSERT(RegistryHive); + ASSERT(RegistryHive); - *pSubKeyCell = NULL; + *pSubKeyCell = NULL; CaseInsensitive = (Attributes & OBJ_CASE_INSENSITIVE) != 0; - for (Storage = Stable; Storage < HTYPE_COUNT; Storage++) - { - if (KeyCell->SubKeyLists[Storage] == HCELL_NIL) - { - /* The key does not have any subkeys */ - continue; - } + for (Storage = Stable; Storage < HTYPE_COUNT; Storage++) + { + if (KeyCell->SubKeyLists[Storage] == HCELL_NIL) + { + /* The key does not have any subkeys */ + continue; + } - /* Get hash table */ - HashBlock = (PCM_KEY_FAST_INDEX)HvGetCell (&RegistryHive->Hive, KeyCell->SubKeyLists[Storage]); - if (!HashBlock || HashBlock->Signature != CM_KEY_FAST_LEAF) - return STATUS_UNSUCCESSFUL; + /* Get hash table */ + HashBlock = (PCM_KEY_FAST_INDEX)HvGetCell (&RegistryHive->Hive, KeyCell->SubKeyLists[Storage]); + if (!HashBlock || HashBlock->Signature != CM_KEY_FAST_LEAF) + return STATUS_UNSUCCESSFUL; - for (i = 0; i < KeyCell->SubKeyCounts[Storage]; i++) - { + for (i = 0; i < KeyCell->SubKeyCounts[Storage]; i++) + { if ((HashBlock->List[i].HashKey == 0) || (CmCompareHash(SubKeyName, (PCHAR)&HashBlock->List[i].HashKey, CaseInsensitive))) { - CurSubKeyCell = (PCM_KEY_NODE)HvGetCell ( - &RegistryHive->Hive, - HashBlock->List[i].Cell); + CurSubKeyCell = (PCM_KEY_NODE)HvGetCell(&RegistryHive->Hive, + HashBlock->List[i].Cell); if (CmCompareKeyName(CurSubKeyCell, SubKeyName, CaseInsensitive)) { @@ -451,222 +448,226 @@ CmiScanForSubKey( return STATUS_SUCCESS; } } - } - } + } + } - return STATUS_OBJECT_NAME_NOT_FOUND; + return STATUS_OBJECT_NAME_NOT_FOUND; } static USHORT CmiGetPackedNameLength( - IN PCUNICODE_STRING Name, - OUT PBOOLEAN pPackable) + IN PCUNICODE_STRING Name, + OUT PBOOLEAN pPackable) { - USHORT i; + USHORT i; - *pPackable = TRUE; + *pPackable = TRUE; - for (i = 0; i < Name->Length / sizeof(WCHAR); i++) - { - if (Name->Buffer[i] & 0xFF00) - { - *pPackable = FALSE; - return Name->Length; - } - } + for (i = 0; i < Name->Length / sizeof(WCHAR); i++) + { + if (Name->Buffer[i] & 0xFF00) + { + *pPackable = FALSE; + return Name->Length; + } + } - return (Name->Length / sizeof(WCHAR)); + return (Name->Length / sizeof(WCHAR)); } static NTSTATUS CmiAllocateValueCell( - IN PCMHIVE RegistryHive, - OUT PCM_KEY_VALUE *ValueCell, - OUT HCELL_INDEX *VBOffset, - IN PCUNICODE_STRING ValueName, - IN HSTORAGE_TYPE Storage) + IN PCMHIVE RegistryHive, + OUT PCM_KEY_VALUE *ValueCell, + OUT HCELL_INDEX *VBOffset, + IN PCUNICODE_STRING ValueName, + IN HSTORAGE_TYPE Storage) { - PCM_KEY_VALUE NewValueCell; - BOOLEAN Packable; - USHORT NameLength, i; - NTSTATUS Status; + PCM_KEY_VALUE NewValueCell; + BOOLEAN Packable; + USHORT NameLength, i; + NTSTATUS Status; - Status = STATUS_SUCCESS; + Status = STATUS_SUCCESS; - NameLength = CmiGetPackedNameLength(ValueName, &Packable); + NameLength = CmiGetPackedNameLength(ValueName, &Packable); - DPRINT("ValueName->Length %u NameLength %u\n", ValueName->Length, NameLength); + DPRINT("ValueName->Length %u NameLength %u\n", ValueName->Length, NameLength); - *VBOffset = HvAllocateCell(&RegistryHive->Hive, sizeof(CM_KEY_VALUE) + NameLength, Storage, HCELL_NIL); - if (*VBOffset == HCELL_NIL) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - } - else - { - NewValueCell = (PCM_KEY_VALUE)HvGetCell (&RegistryHive->Hive, *VBOffset); - NewValueCell->Signature = CM_KEY_VALUE_SIGNATURE; - NewValueCell->NameLength = (USHORT)NameLength; - if (Packable) - { - /* Pack the value name */ - for (i = 0; i < NameLength; i++) - ((PCHAR)NewValueCell->Name)[i] = (CHAR)ValueName->Buffer[i]; - NewValueCell->Flags |= VALUE_COMP_NAME; - } - else - { - /* Copy the value name */ - RtlCopyMemory( - NewValueCell->Name, - ValueName->Buffer, - NameLength); - NewValueCell->Flags = 0; - } - NewValueCell->Type = 0; - NewValueCell->DataLength = 0; - NewValueCell->Data = HCELL_NIL; - *ValueCell = NewValueCell; - } + *VBOffset = HvAllocateCell(&RegistryHive->Hive, sizeof(CM_KEY_VALUE) + NameLength, Storage, HCELL_NIL); + if (*VBOffset == HCELL_NIL) + { + Status = STATUS_INSUFFICIENT_RESOURCES; + } + else + { + NewValueCell = (PCM_KEY_VALUE)HvGetCell (&RegistryHive->Hive, *VBOffset); + NewValueCell->Signature = CM_KEY_VALUE_SIGNATURE; + NewValueCell->NameLength = (USHORT)NameLength; + if (Packable) + { + /* Pack the value name */ + for (i = 0; i < NameLength; i++) + { + ((PCHAR)NewValueCell->Name)[i] = (CHAR)ValueName->Buffer[i]; + } + NewValueCell->Flags |= VALUE_COMP_NAME; + } + else + { + /* Copy the value name */ + RtlCopyMemory(NewValueCell->Name, + ValueName->Buffer, + NameLength); + NewValueCell->Flags = 0; + } + NewValueCell->Type = 0; + NewValueCell->DataLength = 0; + NewValueCell->Data = HCELL_NIL; + *ValueCell = NewValueCell; + } - return Status; + return Status; } NTSTATUS CmiAddValueKey( - IN PCMHIVE RegistryHive, - IN HCELL_INDEX KeyCellOffset, - IN PCUNICODE_STRING ValueName, - OUT PCM_KEY_VALUE *pValueCell, - OUT HCELL_INDEX *pValueCellOffset) + IN PCMHIVE RegistryHive, + IN HCELL_INDEX KeyCellOffset, + IN PCUNICODE_STRING ValueName, + OUT PCM_KEY_VALUE *pValueCell, + OUT HCELL_INDEX *pValueCellOffset) { - PVALUE_LIST_CELL ValueListCell; - PCM_KEY_NODE KeyCell; - PCM_KEY_VALUE NewValueCell; - HCELL_INDEX ValueListCellOffset; - HCELL_INDEX NewValueCellOffset; - ULONG CellSize; - HSTORAGE_TYPE Storage; - NTSTATUS Status; + PVALUE_LIST_CELL ValueListCell; + PCM_KEY_NODE KeyCell; + PCM_KEY_VALUE NewValueCell; + HCELL_INDEX ValueListCellOffset; + HCELL_INDEX NewValueCellOffset; + ULONG CellSize; + HSTORAGE_TYPE Storage; + NTSTATUS Status; - KeyCell = HvGetCell(&RegistryHive->Hive, KeyCellOffset); - if (!KeyCell) - return STATUS_UNSUCCESSFUL; - Storage = (KeyCell->Flags & KEY_IS_VOLATILE) ? Volatile : Stable; - if (KeyCell->ValueList.List == HCELL_NIL) - { - /* Allocate some room for the value list */ - CellSize = sizeof(VALUE_LIST_CELL) + (3 * sizeof(HCELL_INDEX)); - ValueListCellOffset = HvAllocateCell(&RegistryHive->Hive, CellSize, Storage, HCELL_NIL); - if (ValueListCellOffset == HCELL_NIL) - return STATUS_INSUFFICIENT_RESOURCES; + KeyCell = HvGetCell(&RegistryHive->Hive, KeyCellOffset); + if (!KeyCell) + return STATUS_UNSUCCESSFUL; - ValueListCell = (PVALUE_LIST_CELL)HvGetCell(&RegistryHive->Hive, ValueListCellOffset); - if (!ValueListCell) - return STATUS_UNSUCCESSFUL; - KeyCell->ValueList.List = ValueListCellOffset; - HvMarkCellDirty(&RegistryHive->Hive, KeyCellOffset, FALSE); - } - else - { - ValueListCell = (PVALUE_LIST_CELL)HvGetCell(&RegistryHive->Hive, KeyCell->ValueList.List); - if (!ValueListCell) - return STATUS_UNSUCCESSFUL; - CellSize = ABS_VALUE(HvGetCellSize(&RegistryHive->Hive, ValueListCell)); + Storage = (KeyCell->Flags & KEY_IS_VOLATILE) ? Volatile : Stable; + if (KeyCell->ValueList.List == HCELL_NIL) + { + /* Allocate some room for the value list */ + CellSize = sizeof(VALUE_LIST_CELL) + (3 * sizeof(HCELL_INDEX)); + ValueListCellOffset = HvAllocateCell(&RegistryHive->Hive, CellSize, Storage, HCELL_NIL); + if (ValueListCellOffset == HCELL_NIL) + return STATUS_INSUFFICIENT_RESOURCES; - if (KeyCell->ValueList.Count >= CellSize / sizeof(HCELL_INDEX)) - { - CellSize *= 2; - ValueListCellOffset = HvReallocateCell(&RegistryHive->Hive, KeyCell->ValueList.List, CellSize); - if (ValueListCellOffset == HCELL_NIL) - return STATUS_INSUFFICIENT_RESOURCES; + ValueListCell = (PVALUE_LIST_CELL)HvGetCell(&RegistryHive->Hive, ValueListCellOffset); + if (!ValueListCell) + return STATUS_UNSUCCESSFUL; - ValueListCell = (PVALUE_LIST_CELL)HvGetCell(&RegistryHive->Hive, ValueListCellOffset); - if (!ValueListCell) - return STATUS_UNSUCCESSFUL; - KeyCell->ValueList.List = ValueListCellOffset; - HvMarkCellDirty(&RegistryHive->Hive, KeyCellOffset, FALSE); + KeyCell->ValueList.List = ValueListCellOffset; + HvMarkCellDirty(&RegistryHive->Hive, KeyCellOffset, FALSE); + } + else + { + ValueListCell = (PVALUE_LIST_CELL)HvGetCell(&RegistryHive->Hive, KeyCell->ValueList.List); + if (!ValueListCell) + return STATUS_UNSUCCESSFUL; + + CellSize = ABS_VALUE(HvGetCellSize(&RegistryHive->Hive, ValueListCell)); + + if (KeyCell->ValueList.Count >= CellSize / sizeof(HCELL_INDEX)) + { + CellSize *= 2; + ValueListCellOffset = HvReallocateCell(&RegistryHive->Hive, KeyCell->ValueList.List, CellSize); + if (ValueListCellOffset == HCELL_NIL) + return STATUS_INSUFFICIENT_RESOURCES; + + ValueListCell = (PVALUE_LIST_CELL)HvGetCell(&RegistryHive->Hive, ValueListCellOffset); + if (!ValueListCell) + return STATUS_UNSUCCESSFUL; + + KeyCell->ValueList.List = ValueListCellOffset; + HvMarkCellDirty(&RegistryHive->Hive, KeyCellOffset, FALSE); } - } + } - Status = CmiAllocateValueCell( - RegistryHive, - &NewValueCell, - &NewValueCellOffset, - ValueName, - Storage); - if (!NT_SUCCESS(Status)) - return Status; + Status = CmiAllocateValueCell(RegistryHive, + &NewValueCell, + &NewValueCellOffset, + ValueName, + Storage); + if (!NT_SUCCESS(Status)) + return Status; - ValueListCell->ValueOffset[KeyCell->ValueList.Count] = NewValueCellOffset; - KeyCell->ValueList.Count++; - if (NewValueCell->Flags & VALUE_COMP_NAME) - { - if (NewValueCell->NameLength*sizeof(WCHAR) > KeyCell->MaxValueNameLen) + ValueListCell->ValueOffset[KeyCell->ValueList.Count] = NewValueCellOffset; + KeyCell->ValueList.Count++; + if (NewValueCell->Flags & VALUE_COMP_NAME) + { + if (NewValueCell->NameLength*sizeof(WCHAR) > KeyCell->MaxValueNameLen) KeyCell->MaxValueNameLen = NewValueCell->NameLength*sizeof(WCHAR); - } - else - { - if (NewValueCell->NameLength > KeyCell->MaxValueNameLen) + } + else + { + if (NewValueCell->NameLength > KeyCell->MaxValueNameLen) KeyCell->MaxValueNameLen = NewValueCell->NameLength; - } + } - HvMarkCellDirty(&RegistryHive->Hive, KeyCellOffset, FALSE); - HvMarkCellDirty(&RegistryHive->Hive, KeyCell->ValueList.List, FALSE); - HvMarkCellDirty(&RegistryHive->Hive, NewValueCellOffset, FALSE); + HvMarkCellDirty(&RegistryHive->Hive, KeyCellOffset, FALSE); + HvMarkCellDirty(&RegistryHive->Hive, KeyCell->ValueList.List, FALSE); + HvMarkCellDirty(&RegistryHive->Hive, NewValueCellOffset, FALSE); - *pValueCell = NewValueCell; - *pValueCellOffset = NewValueCellOffset; + *pValueCell = NewValueCell; + *pValueCellOffset = NewValueCellOffset; - return STATUS_SUCCESS; + return STATUS_SUCCESS; } NTSTATUS CmiScanForValueKey( - IN PCMHIVE RegistryHive, - IN HCELL_INDEX KeyCellOffset, - IN PCUNICODE_STRING ValueName, - OUT PCM_KEY_VALUE *pValueCell, - OUT HCELL_INDEX *pValueCellOffset) + IN PCMHIVE RegistryHive, + IN HCELL_INDEX KeyCellOffset, + IN PCUNICODE_STRING ValueName, + OUT PCM_KEY_VALUE *pValueCell, + OUT HCELL_INDEX *pValueCellOffset) { - PCM_KEY_NODE KeyCell; - PVALUE_LIST_CELL ValueListCell; - PCM_KEY_VALUE CurValueCell; - ULONG i; + PCM_KEY_NODE KeyCell; + PVALUE_LIST_CELL ValueListCell; + PCM_KEY_VALUE CurValueCell; + ULONG i; - KeyCell = (PCM_KEY_NODE)HvGetCell(&RegistryHive->Hive, KeyCellOffset); - if (!KeyCell) - return STATUS_UNSUCCESSFUL; - *pValueCell = NULL; - *pValueCellOffset = HCELL_NIL; + KeyCell = (PCM_KEY_NODE)HvGetCell(&RegistryHive->Hive, KeyCellOffset); + if (!KeyCell) + return STATUS_UNSUCCESSFUL; - /* The key does not have any values */ - if (KeyCell->ValueList.List == HCELL_NIL) + *pValueCell = NULL; + *pValueCellOffset = HCELL_NIL; + + /* The key does not have any values */ + if (KeyCell->ValueList.List == HCELL_NIL) { - return STATUS_OBJECT_NAME_NOT_FOUND; + return STATUS_OBJECT_NAME_NOT_FOUND; } - ValueListCell = (PVALUE_LIST_CELL)HvGetCell(&RegistryHive->Hive, KeyCell->ValueList.List); + ValueListCell = (PVALUE_LIST_CELL)HvGetCell(&RegistryHive->Hive, KeyCell->ValueList.List); - VERIFY_VALUE_LIST_CELL(ValueListCell); + VERIFY_VALUE_LIST_CELL(ValueListCell); - for (i = 0; i < KeyCell->ValueList.Count; i++) - { - CurValueCell = (PCM_KEY_VALUE)HvGetCell( - &RegistryHive->Hive, - ValueListCell->ValueOffset[i]); + for (i = 0; i < KeyCell->ValueList.Count; i++) + { + CurValueCell = (PCM_KEY_VALUE)HvGetCell(&RegistryHive->Hive, + ValueListCell->ValueOffset[i]); - if (CmComparePackedNames(ValueName, + if (CmComparePackedNames(ValueName, (PUCHAR)CurValueCell->Name, CurValueCell->NameLength, (CurValueCell->Flags & VALUE_COMP_NAME) ? TRUE : FALSE, TRUE)) - { - *pValueCell = CurValueCell; - *pValueCellOffset = ValueListCell->ValueOffset[i]; - return STATUS_SUCCESS; - } - } + { + *pValueCell = CurValueCell; + *pValueCellOffset = ValueListCell->ValueOffset[i]; + return STATUS_SUCCESS; + } + } - return STATUS_OBJECT_NAME_NOT_FOUND; + return STATUS_OBJECT_NAME_NOT_FOUND; } diff --git a/reactos/tools/mkhive/cmi.h b/reactos/tools/mkhive/cmi.h index 025cb13ddd0..a61f65f58fa 100644 --- a/reactos/tools/mkhive/cmi.h +++ b/reactos/tools/mkhive/cmi.h @@ -28,38 +28,38 @@ NTSTATUS CmiInitializeTempHive( - IN OUT PCMHIVE Hive); + IN OUT PCMHIVE Hive); NTSTATUS CmiAddSubKey( - IN PCMHIVE RegistryHive, - IN HCELL_INDEX ParentKeyCellOffset, - IN PCUNICODE_STRING SubKeyName, - IN ULONG CreateOptions, - OUT PCM_KEY_NODE *pSubKeyCell, - OUT HCELL_INDEX *pBlockOffset); + IN PCMHIVE RegistryHive, + IN HCELL_INDEX ParentKeyCellOffset, + IN PCUNICODE_STRING SubKeyName, + IN ULONG CreateOptions, + OUT PCM_KEY_NODE *pSubKeyCell, + OUT HCELL_INDEX *pBlockOffset); NTSTATUS CmiScanForSubKey( - IN PCMHIVE RegistryHive, - IN HCELL_INDEX ParentKeyCellOffset, - IN PCUNICODE_STRING SubKeyName, - IN ULONG Attributes, - OUT PCM_KEY_NODE *pSubKeyCell, - OUT HCELL_INDEX *pBlockOffset); + IN PCMHIVE RegistryHive, + IN HCELL_INDEX ParentKeyCellOffset, + IN PCUNICODE_STRING SubKeyName, + IN ULONG Attributes, + OUT PCM_KEY_NODE *pSubKeyCell, + OUT HCELL_INDEX *pBlockOffset); NTSTATUS CmiAddValueKey( - IN PCMHIVE RegistryHive, - IN HCELL_INDEX KeyCellOffset, - IN PCUNICODE_STRING ValueName, - OUT PCM_KEY_VALUE *pValueCell, - OUT HCELL_INDEX *pValueCellOffset); + IN PCMHIVE RegistryHive, + IN HCELL_INDEX KeyCellOffset, + IN PCUNICODE_STRING ValueName, + OUT PCM_KEY_VALUE *pValueCell, + OUT HCELL_INDEX *pValueCellOffset); NTSTATUS CmiScanForValueKey( - IN PCMHIVE RegistryHive, - IN HCELL_INDEX KeyCellOffset, - IN PCUNICODE_STRING ValueName, - OUT PCM_KEY_VALUE *pValueCell, - OUT HCELL_INDEX *pValueCellOffset); + IN PCMHIVE RegistryHive, + IN HCELL_INDEX KeyCellOffset, + IN PCUNICODE_STRING ValueName, + OUT PCM_KEY_VALUE *pValueCell, + OUT HCELL_INDEX *pValueCellOffset); diff --git a/reactos/tools/mkhive/mkhive.c b/reactos/tools/mkhive/mkhive.c index 3d94e74bd67..3579df7429d 100644 --- a/reactos/tools/mkhive/mkhive.c +++ b/reactos/tools/mkhive/mkhive.c @@ -49,105 +49,105 @@ void usage (void) { - printf ("Usage: mkhive \n\n"); - printf (" dstdir - binary hive files are created in this directory\n"); - printf (" inffiles - inf files with full path\n"); + printf ("Usage: mkhive \n\n"); + printf (" dstdir - binary hive files are created in this directory\n"); + printf (" inffiles - inf files with full path\n"); } void convert_path(char *dst, char *src) { - int i; + int i; - i = 0; - while (src[i] != 0) - { + i = 0; + while (src[i] != 0) + { #ifdef _WIN32 - if (src[i] == '/') - { - dst[i] = '\\'; - } + if (src[i] == '/') + { + dst[i] = '\\'; + } #else - if (src[i] == '\\') - { - dst[i] = '/'; - } + if (src[i] == '\\') + { + dst[i] = '/'; + } #endif - else - { - dst[i] = src[i]; - } + else + { + dst[i] = src[i]; + } - i++; - } - dst[i] = 0; + i++; + } + dst[i] = 0; } int main (int argc, char *argv[]) { - char FileName[PATH_MAX]; - int i; + char FileName[PATH_MAX]; + int i; - if (argc < 3) - { - usage (); - return 1; - } + if (argc < 3) + { + usage (); + return 1; + } - printf ("Binary hive maker\n"); + printf ("Binary hive maker\n"); - RegInitializeRegistry (); + RegInitializeRegistry (); - for (i = 2; i < argc; i++) - { - convert_path (FileName, argv[i]); - ImportRegistryFile (FileName); - } + for (i = 2; i < argc; i++) + { + convert_path (FileName, argv[i]); + ImportRegistryFile (FileName); + } - convert_path (FileName, argv[1]); - strcat (FileName, DIR_SEPARATOR_STRING); - strcat (FileName, "default"); - if (!ExportBinaryHive (FileName, &DefaultHive)) - { - return 1; - } + convert_path (FileName, argv[1]); + strcat (FileName, DIR_SEPARATOR_STRING); + strcat (FileName, "default"); + if (!ExportBinaryHive (FileName, &DefaultHive)) + { + return 1; + } - convert_path (FileName, argv[1]); - strcat (FileName, DIR_SEPARATOR_STRING); - strcat (FileName, "sam"); - if (!ExportBinaryHive (FileName, &SamHive)) - { - return 1; - } + convert_path (FileName, argv[1]); + strcat (FileName, DIR_SEPARATOR_STRING); + strcat (FileName, "sam"); + if (!ExportBinaryHive (FileName, &SamHive)) + { + return 1; + } - convert_path (FileName, argv[1]); - strcat (FileName, DIR_SEPARATOR_STRING); - strcat (FileName, "security"); - if (!ExportBinaryHive (FileName, &SecurityHive)) - { - return 1; - } + convert_path (FileName, argv[1]); + strcat (FileName, DIR_SEPARATOR_STRING); + strcat (FileName, "security"); + if (!ExportBinaryHive (FileName, &SecurityHive)) + { + return 1; + } - convert_path (FileName, argv[1]); - strcat (FileName, DIR_SEPARATOR_STRING); - strcat (FileName, "software"); - if (!ExportBinaryHive (FileName, &SoftwareHive)) - { - return 1; - } + convert_path (FileName, argv[1]); + strcat (FileName, DIR_SEPARATOR_STRING); + strcat (FileName, "software"); + if (!ExportBinaryHive (FileName, &SoftwareHive)) + { + return 1; + } - convert_path (FileName, argv[1]); - strcat (FileName, DIR_SEPARATOR_STRING); - strcat (FileName, "system"); - if (!ExportBinaryHive (FileName, &SystemHive)) - { - return 1; - } + convert_path (FileName, argv[1]); + strcat (FileName, DIR_SEPARATOR_STRING); + strcat (FileName, "system"); + if (!ExportBinaryHive (FileName, &SystemHive)) + { + return 1; + } - RegShutdownRegistry (); + RegShutdownRegistry (); - printf (" Done.\n"); + printf (" Done.\n"); - return 0; + return 0; } /* EOF */ diff --git a/reactos/tools/mkhive/reginf.c b/reactos/tools/mkhive/reginf.c index 2b94fbc6ef8..8082f8b6cd7 100644 --- a/reactos/tools/mkhive/reginf.c +++ b/reactos/tools/mkhive/reginf.c @@ -67,33 +67,33 @@ static const WCHAR DelReg[] = {'D','e','l','R','e','g',0}; static BOOL GetRootKey (PWCHAR Name) { - if (!strcmpiW (Name, HKCR)) - { - strcpyW (Name, HKCRPath); - return TRUE; - } + if (!strcmpiW (Name, HKCR)) + { + strcpyW (Name, HKCRPath); + return TRUE; + } - if (!strcmpiW (Name, HKCU)) - { - strcpyW (Name, HKCUPath); - return TRUE; - } + if (!strcmpiW (Name, HKCU)) + { + strcpyW (Name, HKCUPath); + return TRUE; + } - if (!strcmpiW (Name, HKLM)) - { - strcpyW (Name, HKLMPath); - return TRUE; - } + if (!strcmpiW (Name, HKLM)) + { + strcpyW (Name, HKLMPath); + return TRUE; + } - if (!strcmpiW (Name, HKU)) - { - strcpyW (Name, HKUPath); - return TRUE; - } + if (!strcmpiW (Name, HKU)) + { + strcpyW (Name, HKUPath); + return TRUE; + } #if 0 - if (!strcmpiW (Name, HKR)) - return FALSE; + if (!strcmpiW (Name, HKR)) + return FALSE; #endif return FALSE; @@ -107,77 +107,77 @@ GetRootKey (PWCHAR Name) */ static VOID AppendMultiSzValue ( - IN HKEY KeyHandle, - IN PWCHAR ValueName, - IN PWCHAR Strings, - IN SIZE_T StringSize) + IN HKEY KeyHandle, + IN PWCHAR ValueName, + IN PWCHAR Strings, + IN SIZE_T StringSize) { - SIZE_T Size; - ULONG Type; - size_t Total; - PWCHAR Buffer; - PWCHAR p; - size_t len; - LONG Error; + SIZE_T Size; + ULONG Type; + size_t Total; + PWCHAR Buffer; + PWCHAR p; + size_t len; + LONG Error; - Error = RegQueryValueExW ( - KeyHandle, - ValueName, - NULL, - &Type, - NULL, - &Size); - if ((Error != ERROR_SUCCESS) || - (Type != REG_MULTI_SZ)) - return; + Error = RegQueryValueExW ( + KeyHandle, + ValueName, + NULL, + &Type, + NULL, + &Size); + if ((Error != ERROR_SUCCESS) || + (Type != REG_MULTI_SZ)) + return; - Buffer = malloc ((Size + StringSize) * sizeof(WCHAR)); - if (Buffer == NULL) - return; + Buffer = malloc ((Size + StringSize) * sizeof(WCHAR)); + if (Buffer == NULL) + return; - Error = RegQueryValueExW ( - KeyHandle, - ValueName, - NULL, - NULL, - (PUCHAR)Buffer, - &Size); - if (Error != ERROR_SUCCESS) - goto done; + Error = RegQueryValueExW ( + KeyHandle, + ValueName, + NULL, + NULL, + (PUCHAR)Buffer, + &Size); + if (Error != ERROR_SUCCESS) + goto done; - /* compare each string against all the existing ones */ - Total = Size; - while (*Strings != 0) - { - len = strlenW(Strings) + 1; + /* compare each string against all the existing ones */ + Total = Size; + while (*Strings != 0) + { + len = strlenW(Strings) + 1; - for (p = Buffer; *p != 0; p += strlenW(p) + 1) - if (!strcmpiW(p, Strings)) - break; + for (p = Buffer; *p != 0; p += strlenW(p) + 1) + if (!strcmpiW(p, Strings)) + break; - if (*p == 0) /* not found, need to append it */ - { - memcpy (p, Strings, len); - p[len] = 0; - Total += len; - } - Strings += len; - } + if (*p == 0) /* not found, need to append it */ + { + memcpy (p, Strings, len); + p[len] = 0; + Total += len; + } + Strings += len; + } - if (Total != Size) - { - DPRINT ("setting value %S to %S\n", ValueName, Buffer); - RegSetValueExW ( - KeyHandle, - ValueName, - 0, - REG_MULTI_SZ, - (PUCHAR)Buffer, - (ULONG)Total * sizeof(WCHAR)); - } + if (Total != Size) + { + DPRINT ("setting value %S to %S\n", ValueName, Buffer); + RegSetValueExW ( + KeyHandle, + ValueName, + 0, + REG_MULTI_SZ, + (PUCHAR)Buffer, + (ULONG)Total * sizeof(WCHAR)); + } done: - free (Buffer); + free (Buffer); } @@ -188,202 +188,202 @@ done: */ static BOOL do_reg_operation( - IN HKEY KeyHandle, - IN PWCHAR ValueName, - IN PINFCONTEXT Context, - IN ULONG Flags) + IN HKEY KeyHandle, + IN PWCHAR ValueName, + IN PINFCONTEXT Context, + IN ULONG Flags) { - WCHAR EmptyStr = (CHAR)0; - ULONG Type; - ULONG Size; - LONG Error; + WCHAR EmptyStr = (CHAR)0; + ULONG Type; + ULONG Size; + LONG Error; - if (Flags & FLG_ADDREG_DELVAL) /* deletion */ - { - if (ValueName) - { - RegDeleteValueW (KeyHandle, ValueName); - } - else - { - RegDeleteKeyW (KeyHandle, NULL); - } + if (Flags & FLG_ADDREG_DELVAL) /* deletion */ + { + if (ValueName) + { + RegDeleteValueW (KeyHandle, ValueName); + } + else + { + RegDeleteKeyW (KeyHandle, NULL); + } - return TRUE; - } + return TRUE; + } - if (Flags & FLG_ADDREG_KEYONLY) - return TRUE; + if (Flags & FLG_ADDREG_KEYONLY) + return TRUE; - if (Flags & (FLG_ADDREG_NOCLOBBER | FLG_ADDREG_OVERWRITEONLY)) - { - Error = RegQueryValueExW ( - KeyHandle, - ValueName, - NULL, - NULL, - NULL, - NULL); - if ((Error == ERROR_SUCCESS) && - (Flags & FLG_ADDREG_NOCLOBBER)) - return TRUE; + if (Flags & (FLG_ADDREG_NOCLOBBER | FLG_ADDREG_OVERWRITEONLY)) + { + Error = RegQueryValueExW ( + KeyHandle, + ValueName, + NULL, + NULL, + NULL, + NULL); + if ((Error == ERROR_SUCCESS) && + (Flags & FLG_ADDREG_NOCLOBBER)) + return TRUE; - if ((Error != ERROR_SUCCESS) && - (Flags & FLG_ADDREG_OVERWRITEONLY)) - return TRUE; - } + if ((Error != ERROR_SUCCESS) && + (Flags & FLG_ADDREG_OVERWRITEONLY)) + return TRUE; + } - switch (Flags & FLG_ADDREG_TYPE_MASK) - { - case FLG_ADDREG_TYPE_SZ: - Type = REG_SZ; - break; + switch (Flags & FLG_ADDREG_TYPE_MASK) + { + case FLG_ADDREG_TYPE_SZ: + Type = REG_SZ; + break; - case FLG_ADDREG_TYPE_MULTI_SZ: - Type = REG_MULTI_SZ; - break; + case FLG_ADDREG_TYPE_MULTI_SZ: + Type = REG_MULTI_SZ; + break; - case FLG_ADDREG_TYPE_EXPAND_SZ: - Type = REG_EXPAND_SZ; - break; + case FLG_ADDREG_TYPE_EXPAND_SZ: + Type = REG_EXPAND_SZ; + break; - case FLG_ADDREG_TYPE_BINARY: - Type = REG_BINARY; - break; + case FLG_ADDREG_TYPE_BINARY: + Type = REG_BINARY; + break; - case FLG_ADDREG_TYPE_DWORD: - Type = REG_DWORD; - break; + case FLG_ADDREG_TYPE_DWORD: + Type = REG_DWORD; + break; - case FLG_ADDREG_TYPE_NONE: - Type = REG_NONE; - break; + case FLG_ADDREG_TYPE_NONE: + Type = REG_NONE; + break; - default: - Type = Flags >> 16; - break; - } + default: + Type = Flags >> 16; + break; + } - if (!(Flags & FLG_ADDREG_BINVALUETYPE) || - (Type == REG_DWORD && InfHostGetFieldCount (Context) == 5)) - { - PWCHAR Str = NULL; + if (!(Flags & FLG_ADDREG_BINVALUETYPE) || + (Type == REG_DWORD && InfHostGetFieldCount (Context) == 5)) + { + PWCHAR Str = NULL; - if (Type == REG_MULTI_SZ) - { - if (InfHostGetMultiSzField (Context, 5, NULL, 0, &Size) != 0) - Size = 0; + if (Type == REG_MULTI_SZ) + { + if (InfHostGetMultiSzField (Context, 5, NULL, 0, &Size) != 0) + Size = 0; - if (Size) - { - Str = malloc (Size * sizeof(WCHAR)); - if (Str == NULL) - return FALSE; + if (Size) + { + Str = malloc (Size * sizeof(WCHAR)); + if (Str == NULL) + return FALSE; - InfHostGetMultiSzField (Context, 5, Str, (ULONG)Size, NULL); - } + InfHostGetMultiSzField (Context, 5, Str, (ULONG)Size, NULL); + } - if (Flags & FLG_ADDREG_APPEND) - { - if (Str == NULL) - return TRUE; + if (Flags & FLG_ADDREG_APPEND) + { + if (Str == NULL) + return TRUE; - AppendMultiSzValue ( - KeyHandle, - ValueName, - Str, - Size); + AppendMultiSzValue ( + KeyHandle, + ValueName, + Str, + Size); - free (Str); - return TRUE; - } - /* else fall through to normal string handling */ - } - else - { - if (InfHostGetStringField (Context, 5, NULL, 0, &Size) != 0) - Size = 0; + free (Str); + return TRUE; + } + /* else fall through to normal string handling */ + } + else + { + if (InfHostGetStringField (Context, 5, NULL, 0, &Size) != 0) + Size = 0; - if (Size) - { - Str = malloc (Size * sizeof(WCHAR)); - if (Str == NULL) - return FALSE; + if (Size) + { + Str = malloc (Size * sizeof(WCHAR)); + if (Str == NULL) + return FALSE; - InfHostGetStringField (Context, 5, Str, (ULONG)Size, NULL); - } - } + InfHostGetStringField (Context, 5, Str, (ULONG)Size, NULL); + } + } - if (Type == REG_DWORD) - { - ULONG dw = Str ? strtoulW (Str, NULL, 0) : 0; + if (Type == REG_DWORD) + { + ULONG dw = Str ? strtoulW (Str, NULL, 0) : 0; - DPRINT("setting dword %S to %x\n", ValueName, dw); + DPRINT("setting dword %S to %x\n", ValueName, dw); - RegSetValueExW ( - KeyHandle, - ValueName, - 0, - Type, - (const PUCHAR)&dw, - sizeof(ULONG)); - } - else - { - DPRINT("setting value %S to %S\n", ValueName, Str); + RegSetValueExW ( + KeyHandle, + ValueName, + 0, + Type, + (const PUCHAR)&dw, + sizeof(ULONG)); + } + else + { + DPRINT("setting value %S to %S\n", ValueName, Str); - if (Str) - { - RegSetValueExW ( - KeyHandle, - ValueName, - 0, - Type, - (PVOID)Str, - (ULONG)Size * sizeof(WCHAR)); - } - else - { - RegSetValueExW ( - KeyHandle, - ValueName, - 0, - Type, - (PVOID)&EmptyStr, - (ULONG)sizeof(WCHAR)); - } - } - free (Str); - } - else /* get the binary data */ - { - PUCHAR Data = NULL; + if (Str) + { + RegSetValueExW ( + KeyHandle, + ValueName, + 0, + Type, + (PVOID)Str, + (ULONG)Size * sizeof(WCHAR)); + } + else + { + RegSetValueExW ( + KeyHandle, + ValueName, + 0, + Type, + (PVOID)&EmptyStr, + (ULONG)sizeof(WCHAR)); + } + } + free (Str); + } + else /* get the binary data */ + { + PUCHAR Data = NULL; - if (InfHostGetBinaryField (Context, 5, NULL, 0, &Size) != 0) - Size = 0; + if (InfHostGetBinaryField (Context, 5, NULL, 0, &Size) != 0) + Size = 0; - if (Size) - { - Data = malloc (Size); - if (Data == NULL) - return FALSE; + if (Size) + { + Data = malloc (Size); + if (Data == NULL) + return FALSE; - DPRINT("setting binary data %S len %d\n", ValueName, Size); - InfHostGetBinaryField (Context, 5, Data, Size, NULL); - } + DPRINT("setting binary data %S len %d\n", ValueName, Size); + InfHostGetBinaryField (Context, 5, Data, Size, NULL); + } - RegSetValueExW ( - KeyHandle, - ValueName, - 0, - Type, - (PVOID)Data, - (ULONG)Size); + RegSetValueExW ( + KeyHandle, + ValueName, + 0, + Type, + (PVOID)Data, + (ULONG)Size); - free (Data); - } + free (Data); + } - return TRUE; + return TRUE; } /*********************************************************************** @@ -394,114 +394,114 @@ do_reg_operation( static BOOL registry_callback (HINF hInf, PWCHAR Section, BOOL Delete) { - WCHAR Buffer[MAX_INF_STRING_LENGTH]; - PWCHAR ValuePtr; - ULONG Flags; - size_t Length; + WCHAR Buffer[MAX_INF_STRING_LENGTH]; + PWCHAR ValuePtr; + ULONG Flags; + size_t Length; - PINFCONTEXT Context = NULL; - HKEY KeyHandle; - BOOL Ok; + PINFCONTEXT Context = NULL; + HKEY KeyHandle; + BOOL Ok; - Ok = InfHostFindFirstLine (hInf, Section, NULL, &Context) == 0; - if (!Ok) - return TRUE; /* Don't fail if the section isn't present */ + Ok = InfHostFindFirstLine (hInf, Section, NULL, &Context) == 0; + if (!Ok) + return TRUE; /* Don't fail if the section isn't present */ - for (;Ok; Ok = (InfHostFindNextLine (Context, Context) == 0)) - { - /* get root */ - if (InfHostGetStringField (Context, 1, Buffer, MAX_INF_STRING_LENGTH, NULL) != 0) - continue; - if (!GetRootKey (Buffer)) - continue; + for (;Ok; Ok = (InfHostFindNextLine (Context, Context) == 0)) + { + /* get root */ + if (InfHostGetStringField (Context, 1, Buffer, MAX_INF_STRING_LENGTH, NULL) != 0) + continue; + if (!GetRootKey (Buffer)) + continue; - /* get key */ - Length = strlenW (Buffer); - if (InfHostGetStringField (Context, 2, Buffer + Length, MAX_INF_STRING_LENGTH - (ULONG)Length, NULL) != 0) - *Buffer = 0; + /* get key */ + Length = strlenW (Buffer); + if (InfHostGetStringField (Context, 2, Buffer + Length, MAX_INF_STRING_LENGTH - (ULONG)Length, NULL) != 0) + *Buffer = 0; - DPRINT("KeyName: <%S>\n", Buffer); + DPRINT("KeyName: <%S>\n", Buffer); - if (Delete) - { - Flags = FLG_ADDREG_DELVAL; - } - else - { - /* get flags */ - if (InfHostGetIntField (Context, 4, (INT *)&Flags) != 0) - Flags = 0; - } + if (Delete) + { + Flags = FLG_ADDREG_DELVAL; + } + else + { + /* get flags */ + if (InfHostGetIntField (Context, 4, (INT *)&Flags) != 0) + Flags = 0; + } - DPRINT("Flags: 0x%x\n", Flags); + DPRINT("Flags: 0x%x\n", Flags); - if (Delete || (Flags & FLG_ADDREG_OVERWRITEONLY)) - { - if (RegOpenKeyW (NULL, Buffer, &KeyHandle) != ERROR_SUCCESS) - { - DPRINT("RegOpenKey(%S) failed\n", Buffer); - continue; /* ignore if it doesn't exist */ - } - } - else - { - if (RegCreateKeyW (NULL, Buffer, &KeyHandle) != ERROR_SUCCESS) - { - DPRINT("RegCreateKey(%S) failed\n", Buffer); - continue; - } - } + if (Delete || (Flags & FLG_ADDREG_OVERWRITEONLY)) + { + if (RegOpenKeyW (NULL, Buffer, &KeyHandle) != ERROR_SUCCESS) + { + DPRINT("RegOpenKey(%S) failed\n", Buffer); + continue; /* ignore if it doesn't exist */ + } + } + else + { + if (RegCreateKeyW (NULL, Buffer, &KeyHandle) != ERROR_SUCCESS) + { + DPRINT("RegCreateKey(%S) failed\n", Buffer); + continue; + } + } - /* get value name */ - if (InfHostGetStringField (Context, 3, Buffer, MAX_INF_STRING_LENGTH, NULL) == 0) - { - ValuePtr = Buffer; - } - else - { - ValuePtr = NULL; - } + /* get value name */ + if (InfHostGetStringField (Context, 3, Buffer, MAX_INF_STRING_LENGTH, NULL) == 0) + { + ValuePtr = Buffer; + } + else + { + ValuePtr = NULL; + } - /* and now do it */ - if (!do_reg_operation (KeyHandle, ValuePtr, Context, Flags)) - { - return FALSE; - } - } + /* and now do it */ + if (!do_reg_operation (KeyHandle, ValuePtr, Context, Flags)) + { + return FALSE; + } + } - InfHostFreeContext(Context); + InfHostFreeContext(Context); - return TRUE; + return TRUE; } BOOL ImportRegistryFile(PCHAR FileName) { - HINF hInf; - ULONG ErrorLine; + HINF hInf; + ULONG ErrorLine; - /* Load inf file from install media. */ - if (InfHostOpenFile(&hInf, FileName, 0, &ErrorLine) != 0) - { - DPRINT1 ("InfHostOpenFile(%s) failed\n", FileName); - return FALSE; - } + /* Load inf file from install media. */ + if (InfHostOpenFile(&hInf, FileName, 0, &ErrorLine) != 0) + { + DPRINT1 ("InfHostOpenFile(%s) failed\n", FileName); + return FALSE; + } - if (!registry_callback (hInf, (PWCHAR)DelReg, TRUE)) - { - DPRINT1 ("registry_callback() for DelReg failed\n"); - } + if (!registry_callback (hInf, (PWCHAR)DelReg, TRUE)) + { + DPRINT1 ("registry_callback() for DelReg failed\n"); + } - if (!registry_callback (hInf, (PWCHAR)AddReg, FALSE)) - { - DPRINT1 ("registry_callback() for AddReg failed\n"); - } + if (!registry_callback (hInf, (PWCHAR)AddReg, FALSE)) + { + DPRINT1 ("registry_callback() for AddReg failed\n"); + } - InfHostCloseFile (hInf); + InfHostCloseFile (hInf); - return TRUE; + return TRUE; } /* EOF */ diff --git a/reactos/tools/mkhive/registry.c b/reactos/tools/mkhive/registry.c index d54b5ac22b0..9afd25cea5e 100644 --- a/reactos/tools/mkhive/registry.c +++ b/reactos/tools/mkhive/registry.c @@ -25,9 +25,9 @@ /* * TODO: - * - Implement RegDeleteKeyW() - * - Implement RegEnumValue() - * - Implement RegQueryValueExW() + * - Implement RegDeleteKeyW() + * - Implement RegEnumValue() + * - Implement RegQueryValueExW() */ #include @@ -50,200 +50,198 @@ CMHIVE SystemHive; /* \Registry\Machine\SYSTEM */ static PMEMKEY CreateInMemoryStructure( - IN PCMHIVE RegistryHive, - IN HCELL_INDEX KeyCellOffset) + IN PCMHIVE RegistryHive, + IN HCELL_INDEX KeyCellOffset) { - PMEMKEY Key; + PMEMKEY Key; - Key = (PMEMKEY) malloc (sizeof(MEMKEY)); - if (!Key) - return NULL; + Key = (PMEMKEY) malloc (sizeof(MEMKEY)); + if (!Key) + return NULL; - Key->RegistryHive = RegistryHive; - Key->KeyCellOffset = KeyCellOffset; - return Key; + Key->RegistryHive = RegistryHive; + Key->KeyCellOffset = KeyCellOffset; + return Key; } LIST_ENTRY CmiReparsePointsHead; static LONG RegpOpenOrCreateKey( - IN HKEY hParentKey, - IN PCWSTR KeyName, - IN BOOL AllowCreation, - IN BOOL Volatile, - OUT PHKEY Key) + IN HKEY hParentKey, + IN PCWSTR KeyName, + IN BOOL AllowCreation, + IN BOOL Volatile, + OUT PHKEY Key) { - PWSTR LocalKeyName; - PWSTR End; - UNICODE_STRING KeyString; - NTSTATUS Status; - PREPARSE_POINT CurrentReparsePoint; - PMEMKEY CurrentKey; - PCMHIVE ParentRegistryHive; - HCELL_INDEX ParentCellOffset; - PLIST_ENTRY Ptr; - PCM_KEY_NODE SubKeyCell; - HCELL_INDEX BlockOffset; + PWSTR LocalKeyName; + PWSTR End; + UNICODE_STRING KeyString; + NTSTATUS Status; + PREPARSE_POINT CurrentReparsePoint; + PMEMKEY CurrentKey; + PCMHIVE ParentRegistryHive; + HCELL_INDEX ParentCellOffset; + PLIST_ENTRY Ptr; + PCM_KEY_NODE SubKeyCell; + HCELL_INDEX BlockOffset; - DPRINT("RegpCreateOpenKey('%S')\n", KeyName); + DPRINT("RegpCreateOpenKey('%S')\n", KeyName); - if (*KeyName == L'\\') - { - KeyName++; - ParentRegistryHive = RootKey->RegistryHive; - ParentCellOffset = RootKey->KeyCellOffset; - } - else if (hParentKey == NULL) - { - ParentRegistryHive = RootKey->RegistryHive; - ParentCellOffset = RootKey->KeyCellOffset; - } - else - { - ParentRegistryHive = HKEY_TO_MEMKEY(RootKey)->RegistryHive; - ParentCellOffset = HKEY_TO_MEMKEY(RootKey)->KeyCellOffset; - } + if (*KeyName == L'\\') + { + KeyName++; + ParentRegistryHive = RootKey->RegistryHive; + ParentCellOffset = RootKey->KeyCellOffset; + } + else if (hParentKey == NULL) + { + ParentRegistryHive = RootKey->RegistryHive; + ParentCellOffset = RootKey->KeyCellOffset; + } + else + { + ParentRegistryHive = HKEY_TO_MEMKEY(RootKey)->RegistryHive; + ParentCellOffset = HKEY_TO_MEMKEY(RootKey)->KeyCellOffset; + } - LocalKeyName = (PWSTR)KeyName; - for (;;) - { - End = (PWSTR)strchrW(LocalKeyName, '\\'); - if (End) - { - KeyString.Buffer = LocalKeyName; - KeyString.Length = KeyString.MaximumLength = - (USHORT)((ULONG_PTR)End - (ULONG_PTR)LocalKeyName); - } - else - { - RtlInitUnicodeString(&KeyString, LocalKeyName); - if (KeyString.Length == 0) - { - /* Trailing backslash char; we're done */ - break; - } - } + LocalKeyName = (PWSTR)KeyName; + for (;;) + { + End = (PWSTR)strchrW(LocalKeyName, '\\'); + if (End) + { + KeyString.Buffer = LocalKeyName; + KeyString.Length = KeyString.MaximumLength = + (USHORT)((ULONG_PTR)End - (ULONG_PTR)LocalKeyName); + } + else + { + RtlInitUnicodeString(&KeyString, LocalKeyName); + if (KeyString.Length == 0) + { + /* Trailing backslash char; we're done */ + break; + } + } - Status = CmiScanForSubKey( - ParentRegistryHive, - ParentCellOffset, - &KeyString, - OBJ_CASE_INSENSITIVE, - &SubKeyCell, - &BlockOffset); - if (NT_SUCCESS(Status)) - { - /* Search for a possible reparse point */ - Ptr = CmiReparsePointsHead.Flink; - while (Ptr != &CmiReparsePointsHead) - { - CurrentReparsePoint = CONTAINING_RECORD(Ptr, REPARSE_POINT, ListEntry); - if (CurrentReparsePoint->SourceHive == ParentRegistryHive && - CurrentReparsePoint->SourceKeyCellOffset == BlockOffset) - { - ParentRegistryHive = CurrentReparsePoint->DestinationHive; - BlockOffset = CurrentReparsePoint->DestinationKeyCellOffset; - break; - } - Ptr = Ptr->Flink; - } - } - else if (Status == STATUS_OBJECT_NAME_NOT_FOUND && AllowCreation) - { - Status = CmiAddSubKey( - ParentRegistryHive, - ParentCellOffset, - &KeyString, - Volatile ? REG_OPTION_VOLATILE : 0, - &SubKeyCell, - &BlockOffset); - } - if (!NT_SUCCESS(Status)) - return ERROR_UNSUCCESSFUL; + Status = CmiScanForSubKey(ParentRegistryHive, + ParentCellOffset, + &KeyString, + OBJ_CASE_INSENSITIVE, + &SubKeyCell, + &BlockOffset); + if (NT_SUCCESS(Status)) + { + /* Search for a possible reparse point */ + Ptr = CmiReparsePointsHead.Flink; + while (Ptr != &CmiReparsePointsHead) + { + CurrentReparsePoint = CONTAINING_RECORD(Ptr, REPARSE_POINT, ListEntry); + if (CurrentReparsePoint->SourceHive == ParentRegistryHive && + CurrentReparsePoint->SourceKeyCellOffset == BlockOffset) + { + ParentRegistryHive = CurrentReparsePoint->DestinationHive; + BlockOffset = CurrentReparsePoint->DestinationKeyCellOffset; + break; + } + Ptr = Ptr->Flink; + } + } + else if (Status == STATUS_OBJECT_NAME_NOT_FOUND && AllowCreation) + { + Status = CmiAddSubKey(ParentRegistryHive, + ParentCellOffset, + &KeyString, + Volatile ? REG_OPTION_VOLATILE : 0, + &SubKeyCell, + &BlockOffset); + } + if (!NT_SUCCESS(Status)) + return ERROR_UNSUCCESSFUL; nextsubkey: - ParentCellOffset = BlockOffset; - if (End) - LocalKeyName = End + 1; - else - break; - } + ParentCellOffset = BlockOffset; + if (End) + LocalKeyName = End + 1; + else + break; + } - CurrentKey = CreateInMemoryStructure(ParentRegistryHive, ParentCellOffset); - if (!CurrentKey) - return ERROR_OUTOFMEMORY; - *Key = MEMKEY_TO_HKEY(CurrentKey); + CurrentKey = CreateInMemoryStructure(ParentRegistryHive, ParentCellOffset); + if (!CurrentKey) + return ERROR_OUTOFMEMORY; + *Key = MEMKEY_TO_HKEY(CurrentKey); - return ERROR_SUCCESS; + return ERROR_SUCCESS; } LONG WINAPI RegCreateKeyW( - IN HKEY hKey, - IN LPCWSTR lpSubKey, - OUT PHKEY phkResult) + IN HKEY hKey, + IN LPCWSTR lpSubKey, + OUT PHKEY phkResult) { - return RegpOpenOrCreateKey(hKey, lpSubKey, TRUE, FALSE, phkResult); + return RegpOpenOrCreateKey(hKey, lpSubKey, TRUE, FALSE, phkResult); } static PWSTR MultiByteToWideChar( - IN PCSTR MultiByteString) + IN PCSTR MultiByteString) { - ANSI_STRING Source; - UNICODE_STRING Destination; - NTSTATUS Status; + ANSI_STRING Source; + UNICODE_STRING Destination; + NTSTATUS Status; - RtlInitAnsiString(&Source, MultiByteString); - Status = RtlAnsiStringToUnicodeString(&Destination, &Source, TRUE); - if (!NT_SUCCESS(Status)) - return NULL; - return Destination.Buffer; + RtlInitAnsiString(&Source, MultiByteString); + Status = RtlAnsiStringToUnicodeString(&Destination, &Source, TRUE); + if (!NT_SUCCESS(Status)) + return NULL; + return Destination.Buffer; } LONG WINAPI RegDeleteKeyW( - IN HKEY hKey, - IN LPCWSTR lpSubKey) + IN HKEY hKey, + IN LPCWSTR lpSubKey) { - DPRINT1("FIXME: implement RegDeleteKeyW!\n"); - return ERROR_SUCCESS; + DPRINT1("FIXME: implement RegDeleteKeyW!\n"); + return ERROR_SUCCESS; } LONG WINAPI RegDeleteKeyA( - IN HKEY hKey, - IN LPCSTR lpSubKey) + IN HKEY hKey, + IN LPCSTR lpSubKey) { - PWSTR lpSubKeyW = NULL; - LONG rc; + PWSTR lpSubKeyW = NULL; + LONG rc; - if (lpSubKey != NULL && strchr(lpSubKey, '\\') != NULL) - return ERROR_INVALID_PARAMETER; + if (lpSubKey != NULL && strchr(lpSubKey, '\\') != NULL) + return ERROR_INVALID_PARAMETER; - if (lpSubKey) - { - lpSubKeyW = MultiByteToWideChar(lpSubKey); - if (!lpSubKeyW) - return ERROR_OUTOFMEMORY; - } + if (lpSubKey) + { + lpSubKeyW = MultiByteToWideChar(lpSubKey); + if (!lpSubKeyW) + return ERROR_OUTOFMEMORY; + } - rc = RegDeleteKeyW(hKey, lpSubKeyW); + rc = RegDeleteKeyW(hKey, lpSubKeyW); - if (lpSubKey) - free(lpSubKeyW); + if (lpSubKey) + free(lpSubKeyW); - return rc; + return rc; } LONG WINAPI RegOpenKeyW( - IN HKEY hKey, - IN LPCWSTR lpSubKey, - OUT PHKEY phkResult) + IN HKEY hKey, + IN LPCWSTR lpSubKey, + OUT PHKEY phkResult) { - return RegpOpenOrCreateKey(hKey, lpSubKey, FALSE, FALSE, phkResult); + return RegpOpenOrCreateKey(hKey, lpSubKey, FALSE, FALSE, phkResult); } LONG WINAPI @@ -267,250 +265,248 @@ RegCreateKeyExW( LONG WINAPI RegOpenKeyA( - IN HKEY hKey, - IN LPCSTR lpSubKey, - OUT PHKEY phkResult) + IN HKEY hKey, + IN LPCSTR lpSubKey, + OUT PHKEY phkResult) { - PWSTR lpSubKeyW; - LONG rc; + PWSTR lpSubKeyW; + LONG rc; - lpSubKeyW = MultiByteToWideChar(lpSubKey); - if (!lpSubKeyW) - return ERROR_OUTOFMEMORY; + lpSubKeyW = MultiByteToWideChar(lpSubKey); + if (!lpSubKeyW) + return ERROR_OUTOFMEMORY; - rc = RegOpenKeyW(hKey, lpSubKeyW, phkResult); - free(lpSubKeyW); - return rc; + rc = RegOpenKeyW(hKey, lpSubKeyW, phkResult); + free(lpSubKeyW); + return rc; } static LONG RegpOpenOrCreateValue( - IN HKEY hKey, - IN LPCWSTR ValueName, - IN BOOL AllowCreation, - OUT PCM_KEY_VALUE *ValueCell, - OUT PHCELL_INDEX ValueCellOffset) + IN HKEY hKey, + IN LPCWSTR ValueName, + IN BOOL AllowCreation, + OUT PCM_KEY_VALUE *ValueCell, + OUT PHCELL_INDEX ValueCellOffset) { - PMEMKEY ParentKey; - UNICODE_STRING ValueString; - NTSTATUS Status; + PMEMKEY ParentKey; + UNICODE_STRING ValueString; + NTSTATUS Status; - ParentKey = HKEY_TO_MEMKEY(hKey); - RtlInitUnicodeString(&ValueString, ValueName); + ParentKey = HKEY_TO_MEMKEY(hKey); + RtlInitUnicodeString(&ValueString, ValueName); - Status = CmiScanForValueKey( - ParentKey->RegistryHive, - ParentKey->KeyCellOffset, - &ValueString, - ValueCell, - ValueCellOffset); - if (AllowCreation && Status == STATUS_OBJECT_NAME_NOT_FOUND) - { - Status = CmiAddValueKey( - ParentKey->RegistryHive, - ParentKey->KeyCellOffset, - &ValueString, - ValueCell, - ValueCellOffset); - } - if (!NT_SUCCESS(Status)) - return ERROR_UNSUCCESSFUL; - return ERROR_SUCCESS; + Status = CmiScanForValueKey(ParentKey->RegistryHive, + ParentKey->KeyCellOffset, + &ValueString, + ValueCell, + ValueCellOffset); + if (AllowCreation && Status == STATUS_OBJECT_NAME_NOT_FOUND) + { + Status = CmiAddValueKey(ParentKey->RegistryHive, + ParentKey->KeyCellOffset, + &ValueString, + ValueCell, + ValueCellOffset); + } + if (!NT_SUCCESS(Status)) + return ERROR_UNSUCCESSFUL; + return ERROR_SUCCESS; } LONG WINAPI RegSetValueExW( - IN HKEY hKey, - IN LPCWSTR lpValueName OPTIONAL, - IN ULONG Reserved, - IN ULONG dwType, - IN const UCHAR* lpData, - IN USHORT cbData) + IN HKEY hKey, + IN LPCWSTR lpValueName OPTIONAL, + IN ULONG Reserved, + IN ULONG dwType, + IN const UCHAR* lpData, + IN USHORT cbData) { - PMEMKEY Key, DestKey; - PHKEY phKey; - PCM_KEY_VALUE ValueCell; - HCELL_INDEX ValueCellOffset; - PVOID DataCell; - LONG DataCellSize; - NTSTATUS Status; + PMEMKEY Key, DestKey; + PHKEY phKey; + PCM_KEY_VALUE ValueCell; + HCELL_INDEX ValueCellOffset; + PVOID DataCell; + LONG DataCellSize; + NTSTATUS Status; - if (dwType == REG_LINK) - { - /* Special handling of registry links */ - if (cbData != sizeof(PVOID)) - return STATUS_INVALID_PARAMETER; - phKey = (PHKEY)lpData; - Key = HKEY_TO_MEMKEY(hKey); - DestKey = HKEY_TO_MEMKEY(*phKey); + if (dwType == REG_LINK) + { + /* Special handling of registry links */ + if (cbData != sizeof(PVOID)) + return STATUS_INVALID_PARAMETER; - /* Create the link in registry hive (if applicable) */ - if (Key->RegistryHive != DestKey->RegistryHive) - return STATUS_SUCCESS; - DPRINT1("Save link to registry\n"); - return STATUS_NOT_IMPLEMENTED; - } + phKey = (PHKEY)lpData; + Key = HKEY_TO_MEMKEY(hKey); + DestKey = HKEY_TO_MEMKEY(*phKey); - if ((cbData & REG_DATA_SIZE_MASK) != cbData) - return STATUS_UNSUCCESSFUL; + /* Create the link in registry hive (if applicable) */ + if (Key->RegistryHive != DestKey->RegistryHive) + return STATUS_SUCCESS; + DPRINT1("Save link to registry\n"); + return STATUS_NOT_IMPLEMENTED; + } - Key = HKEY_TO_MEMKEY(hKey); + if ((cbData & REG_DATA_SIZE_MASK) != cbData) + return STATUS_UNSUCCESSFUL; - Status = RegpOpenOrCreateValue(hKey, lpValueName, TRUE, &ValueCell, &ValueCellOffset); - if (!NT_SUCCESS(Status)) - return ERROR_UNSUCCESSFUL; + Key = HKEY_TO_MEMKEY(hKey); - /* Get size of the allocated cellule (if any) */ - if (!(ValueCell->DataLength & REG_DATA_IN_OFFSET) && - (ValueCell->DataLength & REG_DATA_SIZE_MASK) != 0) - { - DataCell = HvGetCell(&Key->RegistryHive->Hive, ValueCell->Data); - if (!DataCell) - return ERROR_UNSUCCESSFUL; - DataCellSize = -HvGetCellSize(&Key->RegistryHive->Hive, DataCell); - } - else - { - DataCell = NULL; - DataCellSize = 0; - } + Status = RegpOpenOrCreateValue(hKey, lpValueName, TRUE, &ValueCell, &ValueCellOffset); + if (!NT_SUCCESS(Status)) + return ERROR_UNSUCCESSFUL; - if (cbData <= sizeof(HCELL_INDEX)) - { - /* If data size <= sizeof(HCELL_INDEX) then store data in the data offset */ - DPRINT("ValueCell->DataLength %u\n", ValueCell->DataLength); - if (DataCell) - HvFreeCell(&Key->RegistryHive->Hive, ValueCell->Data); + /* Get size of the allocated cellule (if any) */ + if (!(ValueCell->DataLength & REG_DATA_IN_OFFSET) && + (ValueCell->DataLength & REG_DATA_SIZE_MASK) != 0) + { + DataCell = HvGetCell(&Key->RegistryHive->Hive, ValueCell->Data); + if (!DataCell) + return ERROR_UNSUCCESSFUL; - RtlCopyMemory(&ValueCell->Data, lpData, cbData); - ValueCell->DataLength = (ULONG)(cbData | REG_DATA_IN_OFFSET); - ValueCell->Type = dwType; - HvMarkCellDirty(&Key->RegistryHive->Hive, ValueCellOffset, FALSE); - } - else - { - if (cbData > (SIZE_T)DataCellSize) - { - /* New data size is larger than the current, destroy current - * data block and allocate a new one. */ - HCELL_INDEX NewOffset; + DataCellSize = -HvGetCellSize(&Key->RegistryHive->Hive, DataCell); + } + else + { + DataCell = NULL; + DataCellSize = 0; + } - DPRINT("ValueCell->DataLength %u\n", ValueCell->DataLength); + if (cbData <= sizeof(HCELL_INDEX)) + { + /* If data size <= sizeof(HCELL_INDEX) then store data in the data offset */ + DPRINT("ValueCell->DataLength %u\n", ValueCell->DataLength); + if (DataCell) + HvFreeCell(&Key->RegistryHive->Hive, ValueCell->Data); - NewOffset = HvAllocateCell(&Key->RegistryHive->Hive, cbData, Stable, HCELL_NIL); - if (NewOffset == HCELL_NIL) - { - DPRINT("HvAllocateCell() failed with status 0x%08x\n", Status); - return ERROR_UNSUCCESSFUL; - } + RtlCopyMemory(&ValueCell->Data, lpData, cbData); + ValueCell->DataLength = (ULONG)(cbData | REG_DATA_IN_OFFSET); + ValueCell->Type = dwType; + HvMarkCellDirty(&Key->RegistryHive->Hive, ValueCellOffset, FALSE); + } + else + { + if (cbData > (SIZE_T)DataCellSize) + { + /* New data size is larger than the current, destroy current + * data block and allocate a new one. */ + HCELL_INDEX NewOffset; - if (DataCell) - HvFreeCell(&Key->RegistryHive->Hive, ValueCell->Data); + DPRINT("ValueCell->DataLength %u\n", ValueCell->DataLength); - ValueCell->Data = NewOffset; - DataCell = (PVOID)HvGetCell(&Key->RegistryHive->Hive, NewOffset); - } + NewOffset = HvAllocateCell(&Key->RegistryHive->Hive, cbData, Stable, HCELL_NIL); + if (NewOffset == HCELL_NIL) + { + DPRINT("HvAllocateCell() failed with status 0x%08x\n", Status); + return ERROR_UNSUCCESSFUL; + } - /* Copy new contents to cellule */ - RtlCopyMemory(DataCell, lpData, cbData); - ValueCell->DataLength = (ULONG)(cbData & REG_DATA_SIZE_MASK); - ValueCell->Type = dwType; - HvMarkCellDirty(&Key->RegistryHive->Hive, ValueCell->Data, FALSE); - HvMarkCellDirty(&Key->RegistryHive->Hive, ValueCellOffset, FALSE); - } + if (DataCell) + HvFreeCell(&Key->RegistryHive->Hive, ValueCell->Data); - HvMarkCellDirty(&Key->RegistryHive->Hive, Key->KeyCellOffset, FALSE); + ValueCell->Data = NewOffset; + DataCell = (PVOID)HvGetCell(&Key->RegistryHive->Hive, NewOffset); + } - DPRINT("Return status 0x%08x\n", Status); - return Status; + /* Copy new contents to cellule */ + RtlCopyMemory(DataCell, lpData, cbData); + ValueCell->DataLength = (ULONG)(cbData & REG_DATA_SIZE_MASK); + ValueCell->Type = dwType; + HvMarkCellDirty(&Key->RegistryHive->Hive, ValueCell->Data, FALSE); + HvMarkCellDirty(&Key->RegistryHive->Hive, ValueCellOffset, FALSE); + } + + HvMarkCellDirty(&Key->RegistryHive->Hive, Key->KeyCellOffset, FALSE); + + DPRINT("Return status 0x%08x\n", Status); + return Status; } LONG WINAPI RegQueryValueExW( - IN HKEY hKey, - IN LPCWSTR lpValueName, - IN PULONG lpReserved, - OUT PULONG lpType, - OUT PUCHAR lpData, - OUT PSIZE_T lpcbData) + IN HKEY hKey, + IN LPCWSTR lpValueName, + IN PULONG lpReserved, + OUT PULONG lpType, + OUT PUCHAR lpData, + OUT PSIZE_T lpcbData) { - //ParentKey = HKEY_TO_MEMKEY(RootKey); - PCM_KEY_VALUE ValueCell; - HCELL_INDEX ValueCellOffset; - LONG rc; + //ParentKey = HKEY_TO_MEMKEY(RootKey); + PCM_KEY_VALUE ValueCell; + HCELL_INDEX ValueCellOffset; + LONG rc; - rc = RegpOpenOrCreateValue( - hKey, - lpValueName, - FALSE, - &ValueCell, - &ValueCellOffset); - if (rc != ERROR_SUCCESS) - return rc; + rc = RegpOpenOrCreateValue(hKey, + lpValueName, + FALSE, + &ValueCell, + &ValueCellOffset); + if (rc != ERROR_SUCCESS) + return rc; - DPRINT1("RegQueryValueExW(%S) not implemented\n", lpValueName); - /* ValueCell and ValueCellOffset are valid */ + DPRINT1("RegQueryValueExW(%S) not implemented\n", lpValueName); + /* ValueCell and ValueCellOffset are valid */ - return ERROR_UNSUCCESSFUL; + return ERROR_UNSUCCESSFUL; } LONG WINAPI RegDeleteValueW( - IN HKEY hKey, - IN LPCWSTR lpValueName OPTIONAL) + IN HKEY hKey, + IN LPCWSTR lpValueName OPTIONAL) { - DPRINT1("RegDeleteValueW() unimplemented\n"); - return ERROR_UNSUCCESSFUL; + DPRINT1("RegDeleteValueW() unimplemented\n"); + return ERROR_UNSUCCESSFUL; } static BOOL ConnectRegistry( - IN HKEY RootKey, - IN PCMHIVE HiveToConnect, - IN LPCWSTR Path) + IN HKEY RootKey, + IN PCMHIVE HiveToConnect, + IN LPCWSTR Path) { - NTSTATUS Status; - PREPARSE_POINT ReparsePoint; - PMEMKEY NewKey; - LONG rc; + NTSTATUS Status; + PREPARSE_POINT ReparsePoint; + PMEMKEY NewKey; + LONG rc; - ReparsePoint = (PREPARSE_POINT)malloc(sizeof(REPARSE_POINT)); - if (!ReparsePoint) - return FALSE; + ReparsePoint = (PREPARSE_POINT)malloc(sizeof(REPARSE_POINT)); + if (!ReparsePoint) + return FALSE; - Status = CmiInitializeTempHive(HiveToConnect); - if (!NT_SUCCESS(Status)) - { - DPRINT1("CmiInitializeTempHive() failed with status 0x%08x\n", Status); - free(ReparsePoint); - return FALSE; - } + Status = CmiInitializeTempHive(HiveToConnect); + if (!NT_SUCCESS(Status)) + { + DPRINT1("CmiInitializeTempHive() failed with status 0x%08x\n", Status); + free(ReparsePoint); + return FALSE; + } - /* Create key */ - rc = RegCreateKeyExW( - RootKey, - Path, - 0, - NULL, - REG_OPTION_VOLATILE, - 0, - NULL, - (PHKEY)&NewKey, - NULL); - if (rc != ERROR_SUCCESS) - { - free(ReparsePoint); - return FALSE; - } + /* Create key */ + rc = RegCreateKeyExW(RootKey, + Path, + 0, + NULL, + REG_OPTION_VOLATILE, + 0, + NULL, + (PHKEY)&NewKey, + NULL); + if (rc != ERROR_SUCCESS) + { + free(ReparsePoint); + return FALSE; + } - ReparsePoint->SourceHive = NewKey->RegistryHive; - ReparsePoint->SourceKeyCellOffset = NewKey->KeyCellOffset; - NewKey->RegistryHive = HiveToConnect; - NewKey->KeyCellOffset = HiveToConnect->Hive.BaseBlock->RootCell; - ReparsePoint->DestinationHive = NewKey->RegistryHive; - ReparsePoint->DestinationKeyCellOffset = NewKey->KeyCellOffset; - InsertTailList(&CmiReparsePointsHead, &ReparsePoint->ListEntry); - return TRUE; + ReparsePoint->SourceHive = NewKey->RegistryHive; + ReparsePoint->SourceKeyCellOffset = NewKey->KeyCellOffset; + NewKey->RegistryHive = HiveToConnect; + NewKey->KeyCellOffset = HiveToConnect->Hive.BaseBlock->RootCell; + ReparsePoint->DestinationHive = NewKey->RegistryHive; + ReparsePoint->DestinationKeyCellOffset = NewKey->KeyCellOffset; + InsertTailList(&CmiReparsePointsHead, &ReparsePoint->ListEntry); + return TRUE; } LIST_ENTRY CmiHiveListHead; @@ -518,88 +514,80 @@ LIST_ENTRY CmiHiveListHead; VOID RegInitializeRegistry(VOID) { - UNICODE_STRING RootKeyName = RTL_CONSTANT_STRING(L"\\"); - NTSTATUS Status; - PMEMKEY ControlSetKey, CurrentControlSetKey; - PREPARSE_POINT ReparsePoint; + UNICODE_STRING RootKeyName = RTL_CONSTANT_STRING(L"\\"); + NTSTATUS Status; + PMEMKEY ControlSetKey, CurrentControlSetKey; + PREPARSE_POINT ReparsePoint; - InitializeListHead(&CmiHiveListHead); - InitializeListHead(&CmiReparsePointsHead); + InitializeListHead(&CmiHiveListHead); + InitializeListHead(&CmiReparsePointsHead); - Status = CmiInitializeTempHive(&RootHive); - if (!NT_SUCCESS(Status)) - { - DPRINT1("CmiInitializeTempHive() failed with status 0x%08x\n", Status); - return; - } + Status = CmiInitializeTempHive(&RootHive); + if (!NT_SUCCESS(Status)) + { + DPRINT1("CmiInitializeTempHive() failed with status 0x%08x\n", Status); + return; + } - RootKey = CreateInMemoryStructure( - &RootHive, - RootHive.Hive.BaseBlock->RootCell); + RootKey = CreateInMemoryStructure(&RootHive, + RootHive.Hive.BaseBlock->RootCell); - /* Create DEFAULT key */ - ConnectRegistry( - NULL, - &DefaultHive, - L"Registry\\User\\.DEFAULT"); + /* Create DEFAULT key */ + ConnectRegistry(NULL, + &DefaultHive, + L"Registry\\User\\.DEFAULT"); - /* Create SAM key */ - ConnectRegistry( - NULL, - &SamHive, - L"Registry\\Machine\\SAM"); + /* Create SAM key */ + ConnectRegistry(NULL, + &SamHive, + L"Registry\\Machine\\SAM"); - /* Create SECURITY key */ - ConnectRegistry( - NULL, - &SecurityHive, - L"Registry\\Machine\\SECURITY"); + /* Create SECURITY key */ + ConnectRegistry(NULL, + &SecurityHive, + L"Registry\\Machine\\SECURITY"); - /* Create SOFTWARE key */ - ConnectRegistry( - NULL, - &SoftwareHive, - L"Registry\\Machine\\SOFTWARE"); + /* Create SOFTWARE key */ + ConnectRegistry(NULL, + &SoftwareHive, + L"Registry\\Machine\\SOFTWARE"); - /* Create SYSTEM key */ - ConnectRegistry( - NULL, - &SystemHive, - L"Registry\\Machine\\SYSTEM"); + /* Create SYSTEM key */ + ConnectRegistry(NULL, + &SystemHive, + L"Registry\\Machine\\SYSTEM"); - /* Create 'ControlSet001' key */ - RegCreateKeyW( - NULL, - L"Registry\\Machine\\SYSTEM\\ControlSet001", - (HKEY*)&ControlSetKey); + /* Create 'ControlSet001' key */ + RegCreateKeyW(NULL, + L"Registry\\Machine\\SYSTEM\\ControlSet001", + (HKEY*)&ControlSetKey); - /* Create 'CurrentControlSet' key */ - RegCreateKeyExW( - NULL, - L"Registry\\Machine\\SYSTEM\\CurrentControlSet", - 0, - NULL, - REG_OPTION_VOLATILE, - 0, - NULL, - (HKEY*)&CurrentControlSetKey, - NULL); + /* Create 'CurrentControlSet' key */ + RegCreateKeyExW(NULL, + L"Registry\\Machine\\SYSTEM\\CurrentControlSet", + 0, + NULL, + REG_OPTION_VOLATILE, + 0, + NULL, + (HKEY*)&CurrentControlSetKey, + NULL); - /* Connect 'CurrentControlSet' to 'ControlSet001' */ - ReparsePoint = (PREPARSE_POINT)malloc(sizeof(REPARSE_POINT)); - ReparsePoint->SourceHive = CurrentControlSetKey->RegistryHive; - ReparsePoint->SourceKeyCellOffset = CurrentControlSetKey->KeyCellOffset; - ReparsePoint->DestinationHive = ControlSetKey->RegistryHive; - ReparsePoint->DestinationKeyCellOffset = ControlSetKey->KeyCellOffset; - InsertTailList(&CmiReparsePointsHead, &ReparsePoint->ListEntry); + /* Connect 'CurrentControlSet' to 'ControlSet001' */ + ReparsePoint = (PREPARSE_POINT)malloc(sizeof(REPARSE_POINT)); + ReparsePoint->SourceHive = CurrentControlSetKey->RegistryHive; + ReparsePoint->SourceKeyCellOffset = CurrentControlSetKey->KeyCellOffset; + ReparsePoint->DestinationHive = ControlSetKey->RegistryHive; + ReparsePoint->DestinationKeyCellOffset = ControlSetKey->KeyCellOffset; + InsertTailList(&CmiReparsePointsHead, &ReparsePoint->ListEntry); } VOID RegShutdownRegistry(VOID) { - /* FIXME: clean up the complete hive */ + /* FIXME: clean up the complete hive */ - free(RootKey); + free(RootKey); } /* EOF */ diff --git a/reactos/tools/mkhive/registry.h b/reactos/tools/mkhive/registry.h index b37214d3c4b..d49d2a70a36 100644 --- a/reactos/tools/mkhive/registry.h +++ b/reactos/tools/mkhive/registry.h @@ -17,9 +17,9 @@ typedef struct _REPARSE_POINT typedef struct _MEMKEY { - /* Information on hard disk structure */ - HCELL_INDEX KeyCellOffset; - PCMHIVE RegistryHive; + /* Information on hard disk structure */ + HCELL_INDEX KeyCellOffset; + PCMHIVE RegistryHive; } MEMKEY, *PMEMKEY; #define HKEY_TO_MEMKEY(hKey) ((PMEMKEY)(hKey)) diff --git a/reactos/tools/mkhive/rtl.c b/reactos/tools/mkhive/rtl.c index 5c89336ca38..24b7410abd7 100644 --- a/reactos/tools/mkhive/rtl.c +++ b/reactos/tools/mkhive/rtl.c @@ -24,24 +24,24 @@ */ VOID NTAPI RtlInitAnsiString( - IN OUT PANSI_STRING DestinationString, - IN PCSTR SourceString) + IN OUT PANSI_STRING DestinationString, + IN PCSTR SourceString) { - SIZE_T DestSize; + SIZE_T DestSize; - if(SourceString) - { - DestSize = strlen(SourceString); - DestinationString->Length = (USHORT)DestSize; - DestinationString->MaximumLength = (USHORT)DestSize + sizeof(CHAR); - } - else - { - DestinationString->Length = 0; - DestinationString->MaximumLength = 0; - } + if(SourceString) + { + DestSize = strlen(SourceString); + DestinationString->Length = (USHORT)DestSize; + DestinationString->MaximumLength = (USHORT)DestSize + sizeof(CHAR); + } + else + { + DestinationString->Length = 0; + DestinationString->MaximumLength = 0; + } - DestinationString->Buffer = (PCHAR)SourceString; + DestinationString->Buffer = (PCHAR)SourceString; } /* @@ -52,129 +52,129 @@ RtlInitAnsiString( */ VOID NTAPI RtlInitUnicodeString( - IN OUT PUNICODE_STRING DestinationString, - IN PCWSTR SourceString) + IN OUT PUNICODE_STRING DestinationString, + IN PCWSTR SourceString) { - SIZE_T DestSize; + SIZE_T DestSize; - if(SourceString) - { - DestSize = strlenW(SourceString) * sizeof(WCHAR); - DestinationString->Length = (USHORT)DestSize; - DestinationString->MaximumLength = (USHORT)DestSize + sizeof(WCHAR); - } - else - { - DestinationString->Length = 0; - DestinationString->MaximumLength = 0; - } + if(SourceString) + { + DestSize = strlenW(SourceString) * sizeof(WCHAR); + DestinationString->Length = (USHORT)DestSize; + DestinationString->MaximumLength = (USHORT)DestSize + sizeof(WCHAR); + } + else + { + DestinationString->Length = 0; + DestinationString->MaximumLength = 0; + } - DestinationString->Buffer = (PWCHAR)SourceString; + DestinationString->Buffer = (PWCHAR)SourceString; } NTSTATUS NTAPI RtlAnsiStringToUnicodeString( - IN OUT PUNICODE_STRING UniDest, - IN PANSI_STRING AnsiSource, - IN BOOLEAN AllocateDestinationString) + IN OUT PUNICODE_STRING UniDest, + IN PANSI_STRING AnsiSource, + IN BOOLEAN AllocateDestinationString) { - ULONG Length; - PUCHAR WideString; - USHORT i; + ULONG Length; + PUCHAR WideString; + USHORT i; - Length = AnsiSource->Length * sizeof(WCHAR); - if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2; - UniDest->Length = (USHORT)Length; + Length = AnsiSource->Length * sizeof(WCHAR); + if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2; + UniDest->Length = (USHORT)Length; - if (AllocateDestinationString) - { - UniDest->MaximumLength = (USHORT)Length + sizeof(WCHAR); - UniDest->Buffer = (PWSTR) malloc(UniDest->MaximumLength); - if (!UniDest->Buffer) - return STATUS_NO_MEMORY; - } - else if (UniDest->Length >= UniDest->MaximumLength) - { - return STATUS_BUFFER_OVERFLOW; - } + if (AllocateDestinationString) + { + UniDest->MaximumLength = (USHORT)Length + sizeof(WCHAR); + UniDest->Buffer = (PWSTR) malloc(UniDest->MaximumLength); + if (!UniDest->Buffer) + return STATUS_NO_MEMORY; + } + else if (UniDest->Length >= UniDest->MaximumLength) + { + return STATUS_BUFFER_OVERFLOW; + } - WideString = (PUCHAR)UniDest->Buffer; - for (i = 0; i <= AnsiSource->Length; i++) - { - WideString[2 * i + 0] = AnsiSource->Buffer[i]; - WideString[2 * i + 1] = 0; - } - return STATUS_SUCCESS; + WideString = (PUCHAR)UniDest->Buffer; + for (i = 0; i <= AnsiSource->Length; i++) + { + WideString[2 * i + 0] = AnsiSource->Buffer[i]; + WideString[2 * i + 1] = 0; + } + return STATUS_SUCCESS; } LONG NTAPI RtlCompareUnicodeString( - IN PCUNICODE_STRING String1, - IN PCUNICODE_STRING String2, - IN BOOLEAN CaseInSensitive) + IN PCUNICODE_STRING String1, + IN PCUNICODE_STRING String2, + IN BOOLEAN CaseInSensitive) { - USHORT i; - WCHAR c1, c2; + USHORT i; + WCHAR c1, c2; - for (i = 0; i <= String1->Length / sizeof(WCHAR) && i <= String2->Length / sizeof(WCHAR); i++) - { - if (CaseInSensitive) - { - c1 = RtlUpcaseUnicodeChar(String1->Buffer[i]); - c2 = RtlUpcaseUnicodeChar(String2->Buffer[i]); - } - else - { - c1 = String1->Buffer[i]; - c2 = String2->Buffer[i]; - } + for (i = 0; i <= String1->Length / sizeof(WCHAR) && i <= String2->Length / sizeof(WCHAR); i++) + { + if (CaseInSensitive) + { + c1 = RtlUpcaseUnicodeChar(String1->Buffer[i]); + c2 = RtlUpcaseUnicodeChar(String2->Buffer[i]); + } + else + { + c1 = String1->Buffer[i]; + c2 = String2->Buffer[i]; + } - if (c1 < c2) - return -1; - else if (c1 > c2) - return 1; - } + if (c1 < c2) + return -1; + else if (c1 > c2) + return 1; + } - return 0; + return 0; } WCHAR NTAPI RtlUpcaseUnicodeChar( - IN WCHAR Source) + IN WCHAR Source) { - USHORT Offset; + USHORT Offset; - if (Source < 'a') - return Source; + if (Source < 'a') + return Source; - if (Source <= 'z') - return (Source - ('a' - 'A')); + if (Source <= 'z') + return (Source - ('a' - 'A')); - Offset = 0; + Offset = 0; - return Source + (SHORT)Offset; + return Source + (SHORT)Offset; } VOID NTAPI KeQuerySystemTime( - OUT PLARGE_INTEGER CurrentTime) + OUT PLARGE_INTEGER CurrentTime) { - CurrentTime->QuadPart = 0; + CurrentTime->QuadPart = 0; } PVOID NTAPI ExAllocatePool( - IN POOL_TYPE PoolType, - IN SIZE_T NumberOfBytes) + IN POOL_TYPE PoolType, + IN SIZE_T NumberOfBytes) { - return (PVOID) malloc(NumberOfBytes); + return (PVOID) malloc(NumberOfBytes); } VOID NTAPI ExFreePool( - IN PVOID p) + IN PVOID p) { - free(p); + free(p); } ULONG diff --git a/reactos/tools/mkshelllink/mkshelllink.c b/reactos/tools/mkshelllink/mkshelllink.c index 008dfc5bef9..cf88f450c02 100644 --- a/reactos/tools/mkshelllink/mkshelllink.c +++ b/reactos/tools/mkshelllink/mkshelllink.c @@ -92,10 +92,10 @@ typedef struct _LNK_LOCAL_VOLUME_INFO char VolumeLabel[0]; } LNK_LOCAL_VOLUME_INFO; -#define PT_GUID 0x1F -#define PT_DRIVE1 0x2F -#define PT_FOLDER 0x31 -#define PT_VALUE 0x32 +#define PT_GUID 0x1F +#define PT_DRIVE1 0x2F +#define PT_FOLDER 0x31 +#define PT_VALUE 0x32 typedef struct _ID_LIST_FILE { diff --git a/reactos/tools/ms2ps/ms2ps.cpp b/reactos/tools/ms2ps/ms2ps.cpp index 2a1ef3b53ff..b5a0475b070 100644 --- a/reactos/tools/ms2ps/ms2ps.cpp +++ b/reactos/tools/ms2ps/ms2ps.cpp @@ -57,14 +57,14 @@ char *c_operators[] = { int isident( int c ) { return (c != '{') && (c != '}') && (c != '(') && (c != ')') && - (c != '\'') && (c != '\"') && !isspace(c); + (c != '\'') && (c != '\"') && !isspace(c); } bool areinclass( string str, int (*isclass)(int) ) { int i; - for( i = 0; i < (int)str.size(); i++ ) - if( !isclass( str[i] ) ) return false; + for( i = 0; i < (int)str.size(); i++ ) + if( !isclass( str[i] ) ) return false; return true; } @@ -74,13 +74,13 @@ bool areident( string s ) { return areinclass( s, isident ); } bool isop( string tok ) { int i; for( i = 0; c_operators[i] && tok != c_operators[i]; i++ ); - if( c_operators[i] ) return true; else return false; + if( c_operators[i] ) return true; else return false; } enum fstate { EMPTY, INT, FRAC, EXP }; string generic_match( string tok, string la, - bool (*mf)( string ) ) { + bool (*mf)( string ) ) { if( tok.size() < 1 ) return ""; if( mf(tok) && !mf(la) ) return tok; else return ""; } @@ -95,16 +95,16 @@ string match_ident( string tok, string la ) { string match_quoted_const( string tok, string la, char q ) { if( ((tok.size() && tok[0] == q) || - ((tok.size() > 2) && tok[0] == 'L' && tok[1] == q)) && - (tok.rfind(q) == (tok.size() - 1)) ) { - if( (tok.rfind("\\") != (tok.size() - 2)) || - (tok.size() > 3 && tok.rfind("\\\\") == (tok.size() - 3)) ) - return tok; - else return ""; + ((tok.size() > 2) && tok[0] == 'L' && tok[1] == q)) && + (tok.rfind(q) == (tok.size() - 1)) ) { + if( (tok.rfind("\\") != (tok.size() - 2)) || + (tok.size() > 3 && tok.rfind("\\\\") == (tok.size() - 3)) ) + return tok; + else return ""; } else return ""; } - + sl_t snarf_tokens( string line ) { int i; sl_t out; @@ -113,57 +113,57 @@ sl_t snarf_tokens( string line ) { line += " "; for( i = 0; i < (int)line.size() - 1; i++ ) { - /*cout << "Char [" << line[i] << "] and [" << line[i+1] << "]" - << endl; */ + /*cout << "Char [" << line[i] << "] and [" << line[i+1] << "]" + << endl; */ - if( (!curtok.size() || - (curtok[0] != '\'' && curtok[0] != '\"')) && - (curtok.size() <= 2 || - curtok[0] != 'L' || - (curtok[1] != '\'' && curtok[1] != '\"')) && - isspace(line[i]) ) { - if( curtok.size() ) out.push_back( curtok ); - curtok = ""; - continue; - } + if( (!curtok.size() || + (curtok[0] != '\'' && curtok[0] != '\"')) && + (curtok.size() <= 2 || + curtok[0] != 'L' || + (curtok[1] != '\'' && curtok[1] != '\"')) && + isspace(line[i]) ) { + if( curtok.size() ) out.push_back( curtok ); + curtok = ""; + continue; + } - curtok.push_back( line[i] ); + curtok.push_back( line[i] ); - la = curtok + line[i+1]; + la = curtok + line[i+1]; - op = match_operator( curtok, la ); - - if( op != "" ) { - out.push_back( op MAYBE(+ "O") ); - curtok = ""; - continue; - } + op = match_operator( curtok, la ); - if( la != "L\"" && la != "L\'" ) { - ident = match_ident( curtok, la ); - - if( ident != "" ) { - out.push_back( ident MAYBE(+ "I") ); - curtok = ""; - continue; - } - } + if( op != "" ) { + out.push_back( op MAYBE(+ "O") ); + curtok = ""; + continue; + } - qconst = match_quoted_const( curtok, la, '\'' ); - - if( qconst != "" ) { - out.push_back( qconst MAYBE(+ "q") ); - curtok = ""; - continue; - } + if( la != "L\"" && la != "L\'" ) { + ident = match_ident( curtok, la ); - qconst = match_quoted_const( curtok, la, '\"' ); - - if( qconst != "" ) { - out.push_back( qconst MAYBE(+ "Q") ); - curtok = ""; - continue; - } + if( ident != "" ) { + out.push_back( ident MAYBE(+ "I") ); + curtok = ""; + continue; + } + } + + qconst = match_quoted_const( curtok, la, '\'' ); + + if( qconst != "" ) { + out.push_back( qconst MAYBE(+ "q") ); + curtok = ""; + continue; + } + + qconst = match_quoted_const( curtok, la, '\"' ); + + if( qconst != "" ) { + out.push_back( qconst MAYBE(+ "Q") ); + curtok = ""; + continue; + } } return out; @@ -175,29 +175,29 @@ istream &getline_no_comments( istream &is, string &line ) { int seen_slash = false; while( (ch = is.get()) != -1 ) { - if( seen_slash ) { - if( ch == '/' ) { - do { - ch = is.get(); - } while( ch != -1 && ch != '\n' && ch != '\r' ); - break; - } else if( ch == '*' ) { - ch = is.get(); /* Skip one char */ - do { - while( ch != '*' ) - ch = is.get(); - ch = is.get(); - } while( ch != '/' ); - buf += ' '; - } else { - buf += '/'; buf += (char)ch; - } - seen_slash = false; - } else { - if( ch == '/' ) seen_slash = true; - else if( ch == '\r' || ch == '\n' ) break; - else buf += (char)ch; - } + if( seen_slash ) { + if( ch == '/' ) { + do { + ch = is.get(); + } while( ch != -1 && ch != '\n' && ch != '\r' ); + break; + } else if( ch == '*' ) { + ch = is.get(); /* Skip one char */ + do { + while( ch != '*' ) + ch = is.get(); + ch = is.get(); + } while( ch != '/' ); + buf += ' '; + } else { + buf += '/'; buf += (char)ch; + } + seen_slash = false; + } else { + if( ch == '/' ) seen_slash = true; + else if( ch == '\r' || ch == '\n' ) break; + else buf += (char)ch; + } } line = buf; @@ -212,33 +212,34 @@ bool expand_input( sl_t &tok ) { out = getline_no_comments( cin, line ); while( line.size() && isspace( line[0] ) ) - line = line.substr( 1 ); + line = line.substr( 1 ); if( line[0] == '#' ) { - tok.push_back( line ); - while( line[line.size()-1] == '\\' ) { - getline_no_comments( cin, line ); - tok.push_back( line ); - tok.push_back( "\n" ); - } - tok.push_back( "\n" ); - } else { - new_tokens = snarf_tokens( line ); - tok.splice( tok.end(), new_tokens ); - tok.push_back( "\n" ); + tok.push_back( line ); + while( line[line.size()-1] == '\\' ) { + getline_no_comments( cin, line ); + tok.push_back( line ); + tok.push_back( "\n" ); } - + tok.push_back( "\n" ); + } else { + new_tokens = snarf_tokens( line ); + tok.splice( tok.end(), new_tokens ); + tok.push_back( "\n" ); + } + return out; } sl_it complete_block( sl_it i, - sl_it end, - string start_ch, string end_ch) { + sl_it end, + string start_ch, + string end_ch) { int bc = 1; - + for( i++; i != end && bc; i++ ) { - if( *i == start_ch ) bc++; - if( *i == end_ch ) bc--; + if( *i == start_ch ) bc++; + if( *i == end_ch ) bc--; } return i; @@ -255,21 +256,21 @@ string makename( string intro ) { void append_block( sl_t &t, sl_it b, sl_it e ) { while( b != e ) { - t.push_back( *b ); - b++; + t.push_back( *b ); + b++; } } void error( sl_t &container, sl_it it, string l ) { - int line = 0; - for( sl_it i = container.begin(); i != it; i++ ) - if( (*i)[0] == '#' ) { - sscanf( i->substr(1).c_str(), "%d", &line ); - cerr << "*standard-input*:" << line << ": " << l; - } + int line = 0; + for( sl_it i = container.begin(); i != it; i++ ) + if( (*i)[0] == '#' ) { + sscanf( i->substr(1).c_str(), "%d", &line ); + cerr << "*standard-input*:" << line << ": " << l; + } } -/* Goal: match and transform one __try { a } __except [ (foo) ] { b } +/* Goal: match and transform one __try { a } __except [ (foo) ] { b } * [ __finally { c } ] * * into @@ -288,51 +289,51 @@ void handle_try( sl_t &container, sl_it try_kw, sl_it end ) { sl_t pseh_clause, temp_tok; string finally_name, filter_name; sl_it try_block, try_block_end, except_kw, paren, end_paren, - except_block, except_block_end, todelete, - finally_kw, finally_block, finally_block_end, clause_end; + except_block, except_block_end, todelete, + finally_kw, finally_block, finally_block_end, clause_end; try_block = try_kw; try_block++; try_block_end = complete_block( try_block, end, "{", "}" ); - - if( try_block_end == end ) - error( container, try_block, "unclosed try block"); + + if( try_block_end == end ) + error( container, try_block, "unclosed try block"); except_kw = try_block_end; if( *except_kw == FINALLY_TOKEN ) { - finally_kw = except_kw; - except_kw = end; - paren = end; - end_paren = end; - except_block = end; - except_block_end = end; + finally_kw = except_kw; + except_kw = end; + paren = end; + end_paren = end; + except_block = end; + except_block_end = end; } else if( *except_kw == EXCEPT_TOKEN ) { - paren = except_kw; - paren++; - if( *paren == "(" ) { - end_paren = complete_block( paren, end, "(", ")" ); - except_block = end_paren; - } else { - except_block = paren; - paren = end; - end_paren = end; - } - except_block_end = complete_block( except_block, end, "{", "}" ); - finally_kw = except_block_end; + paren = except_kw; + paren++; + if( *paren == "(" ) { + end_paren = complete_block( paren, end, "(", ")" ); + except_block = end_paren; } else { - except_kw = paren = end_paren = except_block = except_block_end = - finally_kw = finally_block = finally_block_end = end; + except_block = paren; + paren = end; + end_paren = end; + } + except_block_end = complete_block( except_block, end, "{", "}" ); + finally_kw = except_block_end; + } else { + except_kw = paren = end_paren = except_block = except_block_end = + finally_kw = finally_block = finally_block_end = end; } if( finally_kw != end && *finally_kw != FINALLY_TOKEN ) { - finally_kw = end; - finally_block = end; - finally_block_end = end; + finally_kw = end; + finally_block = end; + finally_block_end = end; } else { - finally_block = finally_kw; - finally_block++; - finally_block_end = complete_block( finally_block, end, "{", "}" ); + finally_block = finally_kw; + finally_block++; + finally_block_end = complete_block( finally_block, end, "{", "}" ); } if( finally_block_end != end ) clause_end = finally_block_end; @@ -351,11 +352,11 @@ void handle_try( sl_t &container, sl_it try_kw, sl_it end ) { pseh_clause.push_back( "(" ); pseh_clause.push_back( finally_name ); pseh_clause.push_back( ")" ); - if( finally_kw != end ) - append_block( pseh_clause, finally_block, finally_block_end ); + if( finally_kw != end ) + append_block( pseh_clause, finally_block, finally_block_end ); else { - pseh_clause.push_back( "{" ); - pseh_clause.push_back( "}" ); + pseh_clause.push_back( "{" ); + pseh_clause.push_back( "}" ); } pseh_clause.push_back( "_SEH_FILTER" ); @@ -365,9 +366,9 @@ void handle_try( sl_t &container, sl_it try_kw, sl_it end ) { pseh_clause.push_back( "{" ); pseh_clause.push_back( "return" ); if( paren != end ) - append_block( pseh_clause, paren, end_paren ); + append_block( pseh_clause, paren, end_paren ); else - pseh_clause.push_back( "EXCEPTION_EXECUTE_HANDLER" ); + pseh_clause.push_back( "EXCEPTION_EXECUTE_HANDLER" ); pseh_clause.push_back( ";" ); pseh_clause.push_back( "}" ); @@ -381,23 +382,23 @@ void handle_try( sl_t &container, sl_it try_kw, sl_it end ) { pseh_clause.push_back( "_SEH_HANDLE" ); pseh_clause.push_back( "{" ); if( except_block != end ) - append_block( pseh_clause, except_block, except_block_end ); + append_block( pseh_clause, except_block, except_block_end ); pseh_clause.push_back( "}" ); pseh_clause.push_back( "_SEH_END" ); pseh_clause.push_back( ";" ); container.splice( try_kw, pseh_clause ); while( try_kw != clause_end ) { - todelete = try_kw; - try_kw++; - container.erase( todelete ); + todelete = try_kw; + try_kw++; + container.erase( todelete ); } } void print_tokens( sl_it begin, sl_it end ) { - for( sl_it i = begin; i != end; i++ ) - if( *i == "\n" ) cout << *i; - else cout << /*"[" <<*/ *i << /*"]" <<*/ " "; + for( sl_it i = begin; i != end; i++ ) + if( *i == "\n" ) cout << *i; + else cout << /*"[" <<*/ *i << /*"]" <<*/ " "; } int main( int argc, char **argv ) { @@ -406,24 +407,24 @@ int main( int argc, char **argv ) { int i; for( i = 1; i < argc; i++ ) { - if( string(argv[i]) == "-try" && i < argc - 1 ) { - i++; - TRY_TOKEN = argv[i]; - } else if( string(argv[i]) == "-except" && i < argc - 1 ) { - i++; - EXCEPT_TOKEN = argv[i]; - } else if( string(argv[i]) == "-finally" && i < argc - 1 ) { - i++; - FINALLY_TOKEN = argv[i]; - } + if( string(argv[i]) == "-try" && i < argc - 1 ) { + i++; + TRY_TOKEN = argv[i]; + } else if( string(argv[i]) == "-except" && i < argc - 1 ) { + i++; + EXCEPT_TOKEN = argv[i]; + } else if( string(argv[i]) == "-finally" && i < argc - 1 ) { + i++; + FINALLY_TOKEN = argv[i]; + } } /* XXX Uses much memory for large files */ while( expand_input(tok) ); while( (try_found = find( tok.begin(), tok.end(), TRY_TOKEN )) != - tok.end() ) { - handle_try( tok, try_found, tok.end() ); + tok.end() ) { + handle_try( tok, try_found, tok.end() ); } tok.push_front("#include \n"); diff --git a/reactos/tools/nandflash/main.c b/reactos/tools/nandflash/main.c index 012fc54b3db..bf2b5c9d086 100644 --- a/reactos/tools/nandflash/main.c +++ b/reactos/tools/nandflash/main.c @@ -69,7 +69,7 @@ WriteToFlash(IN INT NandImageFile, /* Offset to NAND Page convert */ StartPage = ImageStart / NAND_PAGE_SIZE; EndPage = ImageEnd / NAND_PAGE_SIZE; - + /* Jump to NAND offset */ if (NeedsOob) OobSize = NAND_OOB_SIZE; lseek(NandImageFile, StartPage * (NAND_PAGE_SIZE + OobSize), SEEK_SET); @@ -153,7 +153,7 @@ main(ULONG argc, char **argv) { INT NandImageFile, RamDiskFile; - + /* Flat NAND, no OOB */ if (argc == 2) NeedsOob = FALSE; @@ -177,7 +177,7 @@ main(ULONG argc, /* Write it */ WriteRamDisk(RamDiskFile); - + /* Close */ close(RamDiskFile); } diff --git a/reactos/tools/ofw_interface/calls.ofw b/reactos/tools/ofw_interface/calls.ofw index 00273f1a426..f4c0d5a1e2b 100644 --- a/reactos/tools/ofw_interface/calls.ofw +++ b/reactos/tools/ofw_interface/calls.ofw @@ -1,16 +1,16 @@ -# Function Args Returns Types +# Function Args Returns Types # Real OFW functions to proxy -finddevice 1 1 char* int -open 1 1 char* int -getprop 4 1 int char* char*:arg3 int int -nextprop 3 1 int char* char* int -getproplen 2 1 int char* int -write 3 1 int char*:arg2 int int -read 3 1 int char*:arg2 int int -exit 0 0 -child 1 1 int int -peer 1 1 int int -parent 1 1 int int -seek 3 1 int int int int -package-to-path 3 1 int char*:arg2 int int -claim 3 1 int int int int +finddevice 1 1 char* int +open 1 1 char* int +getprop 4 1 int char* char*:arg3 int int +nextprop 3 1 int char* char* int +getproplen 2 1 int char* int +write 3 1 int char*:arg2 int int +read 3 1 int char*:arg2 int int +exit 0 0 +child 1 1 int int +peer 1 1 int int +parent 1 1 int int +seek 3 1 int int int int +package-to-path 3 1 int char*:arg2 int int +claim 3 1 int int int int diff --git a/reactos/tools/ofw_interface/ofw_interface.cpp b/reactos/tools/ofw_interface/ofw_interface.cpp index 5946c7b3e08..bb64a427b67 100644 --- a/reactos/tools/ofw_interface/ofw_interface.cpp +++ b/reactos/tools/ofw_interface/ofw_interface.cpp @@ -18,35 +18,35 @@ public: class vartype { public: vartype( const std::string &typestr ) { - size_t amp = typestr.find('&'); - size_t col = typestr.find(':'); - if( amp != std::string::npos ) { - if( col > amp && col != std::string::npos ) - lit_value = typestr.substr(amp+1,col-amp+1); - else lit_value = typestr.substr(amp+1); - } - if( col != std::string::npos ) { - if( amp > col && amp != std::string::npos ) - len = typestr.substr(col+1,amp-col+1); - else len = typestr.substr(col+1); - } + size_t amp = typestr.find('&'); + size_t col = typestr.find(':'); + if( amp != std::string::npos ) { + if( col > amp && col != std::string::npos ) + lit_value = typestr.substr(amp+1,col-amp+1); + else lit_value = typestr.substr(amp+1); + } + if( col != std::string::npos ) { + if( amp > col && amp != std::string::npos ) + len = typestr.substr(col+1,amp-col+1); + else len = typestr.substr(col+1); + } - if( amp != std::string::npos && amp < col ) col = amp; - if( col == std::string::npos ) col = typestr.size(); - c_type = typestr.substr(0,col); + if( amp != std::string::npos && amp < col ) col = amp; + if( col == std::string::npos ) col = typestr.size(); + c_type = typestr.substr(0,col); } vartype( const vartype &other ) - : c_type(other.c_type), - len(other.len), - lit_value(other.lit_value) { + : c_type(other.c_type), + len(other.len), + lit_value(other.lit_value) { } vartype &operator = ( const vartype &other ) { - c_type = other.c_type; - len = other.len; - lit_value = other.lit_value; - return *this; + c_type = other.c_type; + len = other.len; + lit_value = other.lit_value; + return *this; } std::string c_type; @@ -57,7 +57,7 @@ public: std::string uppercase( const std::string &toucase ) { std::vector ucase_work(toucase.size()); for( size_t i = 0; i < toucase.size(); i++ ) { - ucase_work[i] = toupper(toucase[i]); + ucase_work[i] = toupper(toucase[i]); } return std::string(&ucase_work[0], toucase.size()); } @@ -65,9 +65,9 @@ std::string uppercase( const std::string &toucase ) { std::string clip_eol( std::string in, const std::string &eol_marks ) { size_t found; for( size_t i = 0; i < eol_marks.size(); i++ ) { - found = in.find( eol_marks[i] ); - if( found != std::string::npos ) - in = in.substr( 0, found ); + found = in.find( eol_marks[i] ); + if( found != std::string::npos ) + in = in.substr( 0, found ); } return in; } @@ -90,39 +90,39 @@ void populate_definition( ofw_wrappers &wrapper, const std::string &line ) { if( !name.size() ) return; if( (f = name.find('!')) != std::string::npos ) { - nametext = name.substr(f+1); - name = name.substr(0,f); + nametext = name.substr(f+1); + name = name.substr(0,f); } if( name[0] == '-' ) { - name = name.substr(1); - make_function = false; + name = name.substr(1); + make_function = false; } if( name[0] == '+' ) { - name = name.substr(1); - make_stub = false; + name = name.substr(1); + make_stub = false; } if( name[0] == '@' ) { - name = name.substr(1); - method_call = true; - make_function = false; + name = name.substr(1); + method_call = true; + make_function = false; } if( !nametext.size() ) nametext = name; for( i = 1; i < (int)name.size(); i++ ) - if( name[i] == '-' ) name[i] = '_'; + if( name[i] == '-' ) name[i] = '_'; if( nametext == "call-method" ) - wrapper.method_ctindex = wrapper.ctindex; + wrapper.method_ctindex = wrapper.ctindex; for( i = 0; i < args; i++ ) { iss >> argtype; - argtypes.push_back(vartype(argtype)); + argtypes.push_back(vartype(argtype)); } if( method_call ) { - userarg_start = 1; - args += 2; + userarg_start = 1; + args += 2; } iss >> rettype; @@ -132,76 +132,76 @@ void populate_definition( ofw_wrappers &wrapper, const std::string &line ) { total_stack = round_up(12 + local_offset, 16); function << "asm_ofw_" << name << ":\n" - << "\t/* Reserve stack space */\n" - << "\tsubi %r1,%r1," << total_stack << "\n" - << "\t/* Store r8, r9, lr */\n" - << "\tstw %r8," << (local_offset + 0) << "(%r1)\n" - << "\tstw %r9," << (local_offset + 4) << "(%r1)\n" - << "\tmflr %r8\n" - << "\tstw %r8," << (local_offset + 8) << "(%r1)\n" - << "\t/* Get read name */\n" - << "\tlis %r8," << name << "_ofw_name@ha\n" - << "\taddi %r9,%r8," << name << "_ofw_name@l\n" - << "\tstw %r9,0(%r1)\n" - << "\t/* " << args << " arguments and " << rets << " return */\n" - << "\tli %r9," << args << "\n" - << "\tstw %r9,4(%r1)\n" - << "\tli %r9," << rets << "\n" - << "\tstw %r9,8(%r1)\n"; + << "\t/* Reserve stack space */\n" + << "\tsubi %r1,%r1," << total_stack << "\n" + << "\t/* Store r8, r9, lr */\n" + << "\tstw %r8," << (local_offset + 0) << "(%r1)\n" + << "\tstw %r9," << (local_offset + 4) << "(%r1)\n" + << "\tmflr %r8\n" + << "\tstw %r8," << (local_offset + 8) << "(%r1)\n" + << "\t/* Get read name */\n" + << "\tlis %r8," << name << "_ofw_name@ha\n" + << "\taddi %r9,%r8," << name << "_ofw_name@l\n" + << "\tstw %r9,0(%r1)\n" + << "\t/* " << args << " arguments and " << rets << " return */\n" + << "\tli %r9," << args << "\n" + << "\tstw %r9,4(%r1)\n" + << "\tli %r9," << rets << "\n" + << "\tstw %r9,8(%r1)\n"; for( int i = 0; i < args; i++ ) - function << "\tstw %r" << (i+3) << "," << (4 * (i + 3)) << "(%r1)\n"; + function << "\tstw %r" << (i+3) << "," << (4 * (i + 3)) << "(%r1)\n"; function << "\t/* Load up the call address */\n" << "\tlis %r10,ofw_call_addr@ha\n" - << "\tlwz %r9,ofw_call_addr@l(%r10)\n" - << "\tmtlr %r9\n" - << "\t/* Set argument */\n" - << "\tmr %r3,%r1\n" - << "\t/* Fire */\n" - << "\tblrl\n" - << "\tlwz %r3," << (local_offset - 4) << "(%r1)\n" - << "\t/* Restore registers */\n" - << "\tlwz %r8," << (local_offset + 8) << "(%r1)\n" - << "\tmtlr %r8\n" - << "\tlwz %r9," << (local_offset + 4) << "(%r1)\n" - << "\tlwz %r8," << (local_offset + 0) << "(%r1)\n" - << "\t/* Return */\n" - << "\taddi %r1,%r1," << total_stack << "\n" - << "\tblr\n"; + << "\tlwz %r9,ofw_call_addr@l(%r10)\n" + << "\tmtlr %r9\n" + << "\t/* Set argument */\n" + << "\tmr %r3,%r1\n" + << "\t/* Fire */\n" + << "\tblrl\n" + << "\tlwz %r3," << (local_offset - 4) << "(%r1)\n" + << "\t/* Restore registers */\n" + << "\tlwz %r8," << (local_offset + 8) << "(%r1)\n" + << "\tmtlr %r8\n" + << "\tlwz %r9," << (local_offset + 4) << "(%r1)\n" + << "\tlwz %r8," << (local_offset + 0) << "(%r1)\n" + << "\t/* Return */\n" + << "\taddi %r1,%r1," << total_stack << "\n" + << "\tblr\n"; if( method_call ) { - argtypes.insert(argtypes.begin(),vartype("int")); - argtypes.insert(argtypes.begin(),vartype("char*")); + argtypes.insert(argtypes.begin(),vartype("int")); + argtypes.insert(argtypes.begin(),vartype("char*")); } le_stub << rettype << " ofw_" << name << "("; comma = false; for( i = userarg_start; i < args; i++ ) { - if( !argtypes[i].lit_value.size() ) { - if( !comma ) comma = true; else le_stub << ","; - le_stub << argtypes[i].c_type << " arg" << i; - } + if( !argtypes[i].lit_value.size() ) { + if( !comma ) comma = true; else le_stub << ","; + le_stub << argtypes[i].c_type << " arg" << i; + } } le_stub << ")"; of_call << le_stub.str() << ";\n"; le_stub << " {\n"; if( rettype != "void" ) - le_stub << "\t" << rettype << " ret;\n"; + le_stub << "\t" << rettype << " ret;\n"; if( method_call ) { - le_stub << "\tchar arg0[" - << round_up(nametext.size()+1,8) - << "] = \"" << nametext << "\";\n"; + le_stub << "\tchar arg0[" + << round_up(nametext.size()+1,8) + << "] = \"" << nametext << "\";\n"; } for( i = 0; i < args; i++ ) { - if( argtypes[i].lit_value.size() ) { - le_stub << "\t" << argtypes[i].c_type << " arg" << i << " = " - << argtypes[i].lit_value << ";\n"; - } + if( argtypes[i].lit_value.size() ) { + le_stub << "\t" << argtypes[i].c_type << " arg" << i << " = " + << argtypes[i].lit_value << ";\n"; + } } le_stub << "\t"; @@ -211,26 +211,26 @@ void populate_definition( ofw_wrappers &wrapper, const std::string &line ) { (method_call ? (wrapper.method_ctindex * 4) : (wrapper.ctindex * 4)); for( i = 0; i < 6; i++ ) { - if( i < args ) le_stub << ",(void *)arg" << i; - else le_stub << ",NULL"; + if( i < args ) le_stub << ",(void *)arg" << i; + else le_stub << ",NULL"; } le_stub << ");\n"; if( rettype != "void" ) - le_stub << "\treturn ret;\n"; + le_stub << "\treturn ret;\n"; le_stub << "}\n"; if( make_function ) wrapper.functions += function.str(); if( make_stub ) { - wrapper.le_stubs += le_stub.str(); - wrapper.of_call += of_call.str(); + wrapper.le_stubs += le_stub.str(); + wrapper.of_call += of_call.str(); } if( !method_call ) { - wrapper.names += name + "_ofw_name:\n\t.asciz \"" + nametext + "\"\n"; - wrapper.calltable += std::string("\t.long asm_ofw_") + name + "\n"; - wrapper.ctindex++; + wrapper.names += name + "_ofw_name:\n\t.asciz \"" + nametext + "\"\n"; + wrapper.calltable += std::string("\t.long asm_ofw_") + name + "\n"; + wrapper.ctindex++; } } @@ -246,70 +246,70 @@ int main( int argc, char **argv ) { wrappers.ctindex = 0; if( argc < 5 ) { - fprintf( stderr, "%s [interface.ofw] [ofw.s] [le_stub.c] [le_stub.h]\n", argv[0] ); - return 1; + fprintf( stderr, "%s [interface.ofw] [ofw.s] [le_stub.c] [le_stub.h]\n", argv[0] ); + return 1; } in.open( argv[1] ); if( !in ) { - fprintf( stderr, "can't open %s\n", argv[1] ); - status = 1; - goto error; + fprintf( stderr, "can't open %s\n", argv[1] ); + status = 1; + goto error; } out.open( argv[2] ); if( !out ) { - fprintf( stderr, "can't open %s\n", argv[2] ); - status = 1; - goto error; + fprintf( stderr, "can't open %s\n", argv[2] ); + status = 1; + goto error; } outcsource.open( argv[3] ); if( !outcsource ) { - fprintf( stderr, "can't open %s\n", argv[3] ); - status = 1; - goto error; + fprintf( stderr, "can't open %s\n", argv[3] ); + status = 1; + goto error; } outcheader.open( argv[4] ); if( !outcheader ) { - fprintf( stderr, "can't open %s\n", argv[4] ); - status = 1; - goto error; + fprintf( stderr, "can't open %s\n", argv[4] ); + status = 1; + goto error; } while( std::getline( in, line ) ) { - line = clip_eol( line, eol_marks ); - if( line.size() ) populate_definition( wrappers, line ); + line = clip_eol( line, eol_marks ); + if( line.size() ) populate_definition( wrappers, line ); } out << "/* AUTOMATICALLY GENERATED BY ofw_interface */\n" - << "\t.section .text\n" - << "\t.align 4\n" - << "\t.globl _start\n" - << "\t.globl ofw_functions\n" - << "\t.globl ofw_call_addr\n" - << "ofw_call_addr:\n" - << "\t.long 0\n" - << "\n/* Function Wrappers */\n\n" - << wrappers.functions - << "\n/* Function Names */\n\n" - << wrappers.names - << "\n/* Function Call Table for Freeldr */\n\n" + << "\t.section .text\n" << "\t.align 4\n" - << "ofw_functions:\n" - << wrappers.calltable - << "\n/* End */\n"; + << "\t.globl _start\n" + << "\t.globl ofw_functions\n" + << "\t.globl ofw_call_addr\n" + << "ofw_call_addr:\n" + << "\t.long 0\n" + << "\n/* Function Wrappers */\n\n" + << wrappers.functions + << "\n/* Function Names */\n\n" + << wrappers.names + << "\n/* Function Call Table for Freeldr */\n\n" + << "\t.align 4\n" + << "ofw_functions:\n" + << wrappers.calltable + << "\n/* End */\n"; outcsource << "/* AUTOMATICALLY GENERATED BY ofw_interface */\n" - << "#include \"of.h\"\n" - << wrappers.le_stubs; + << "#include \"of.h\"\n" + << wrappers.le_stubs; outcheader << "/* AUTOMATICALLY GENERATE BY ofw_interface */\n" - << "#ifndef _OFW_CALLS_H\n" - << "#define _OFW_CALLS_H\n" - << wrappers.of_call - << "#endif/*_OFW_CALLS_H*/\n"; + << "#ifndef _OFW_CALLS_H\n" + << "#define _OFW_CALLS_H\n" + << wrappers.of_call + << "#endif/*_OFW_CALLS_H*/\n"; error: return status; diff --git a/reactos/tools/pipetools/piperead.cpp b/reactos/tools/pipetools/piperead.cpp index 6359335dc0a..b3f37eabc89 100644 --- a/reactos/tools/pipetools/piperead.cpp +++ b/reactos/tools/pipetools/piperead.cpp @@ -2,235 +2,233 @@ // piperead.cpp // // Martin Fuchs, 30.11.2003 -// +// // Jan Roeloffzen, 26.1.2010 // Pipe client, based on msdn example - -#define WIN32_LEAN_AND_MEAN + +#define WIN32_LEAN_AND_MEAN #include #include #include -#define PIPEREAD_VERSION "0.3" -#define PIPEREAD_NOPIPE (-101) +#define PIPEREAD_VERSION "0.3" +#define PIPEREAD_NOPIPE (-101) // This definition currently missing in MinGW. -#ifndef FILE_FLAG_FIRST_PIPE_INSTANCE -#define FILE_FLAG_FIRST_PIPE_INSTANCE 0x00080000 +#ifndef FILE_FLAG_FIRST_PIPE_INSTANCE +#define FILE_FLAG_FIRST_PIPE_INSTANCE 0x00080000 #endif -#define BUFSIZE 1024 +#define BUFSIZE 1024 static void print_error(DWORD win32_error) { - fprintf(stderr, "WIN32 error %lu\n", win32_error); + fprintf(stderr, "WIN32 error %lu\n", win32_error); } static int pipeServer(char *path) { - HANDLE hPipe = CreateNamedPipe(path, PIPE_ACCESS_DUPLEX|FILE_FLAG_FIRST_PIPE_INSTANCE, PIPE_WAIT|PIPE_TYPE_BYTE, 1, 4096, 4096, 30000, NULL); + HANDLE hPipe = CreateNamedPipe(path, PIPE_ACCESS_DUPLEX|FILE_FLAG_FIRST_PIPE_INSTANCE, PIPE_WAIT|PIPE_TYPE_BYTE, 1, 4096, 4096, 30000, NULL); - if (hPipe == INVALID_HANDLE_VALUE) { - print_error(GetLastError()); - return 1; - } + if (hPipe == INVALID_HANDLE_VALUE) { + print_error(GetLastError()); + return 1; + } - for(;;) { - DWORD read; - BYTE buffer[BUFSIZE]; + for(;;) { + DWORD read; + BYTE buffer[BUFSIZE]; - if (!ReadFile(hPipe, buffer, sizeof(buffer), &read, NULL)) { - DWORD error = GetLastError(); + if (!ReadFile(hPipe, buffer, sizeof(buffer), &read, NULL)) { + DWORD error = GetLastError(); - if (error == ERROR_PIPE_LISTENING) { - Sleep(1000); - } else if (error == ERROR_BROKEN_PIPE) { - CloseHandle(hPipe); + if (error == ERROR_PIPE_LISTENING) { + Sleep(1000); + } else if (error == ERROR_BROKEN_PIPE) { + CloseHandle(hPipe); - hPipe = CreateNamedPipe(path, PIPE_ACCESS_DUPLEX|FILE_FLAG_FIRST_PIPE_INSTANCE, PIPE_WAIT|PIPE_TYPE_BYTE, 1, 4096, 4096, 30000, NULL); + hPipe = CreateNamedPipe(path, PIPE_ACCESS_DUPLEX|FILE_FLAG_FIRST_PIPE_INSTANCE, PIPE_WAIT|PIPE_TYPE_BYTE, 1, 4096, 4096, 30000, NULL); - if (hPipe == INVALID_HANDLE_VALUE) { - fprintf(stderr,"INVALID_HANDLE_VALUE\n"); - print_error(GetLastError()); - return 1; - } - } else { - fprintf(stderr,"error %lu\n",error); - print_error(error); - break; - } - } + if (hPipe == INVALID_HANDLE_VALUE) { + fprintf(stderr,"INVALID_HANDLE_VALUE\n"); + print_error(GetLastError()); + return 1; + } + } else { + fprintf(stderr,"error %lu\n",error); + print_error(error); + break; + } + } - if (read) - fwrite(buffer, read, 1, stdout); - } + if (read) + fwrite(buffer, read, 1, stdout); + } - if (!CloseHandle(hPipe)) - print_error(GetLastError()); + if (!CloseHandle(hPipe)) + print_error(GetLastError()); - return 0; + return 0; } static int pipeClient(char *path) { - HANDLE hPipe=INVALID_HANDLE_VALUE; - TCHAR chBuf[BUFSIZE]; - BOOL fSuccess = FALSE; - DWORD cbRead; - DWORD Err; - int res = 0; + HANDLE hPipe=INVALID_HANDLE_VALUE; + TCHAR chBuf[BUFSIZE]; + BOOL fSuccess = FALSE; + DWORD cbRead; + DWORD Err; + int res = 0; - setvbuf(stdout, NULL, _IONBF, 0); - while (1) { - hPipe = CreateFile( - path, // pipe name - GENERIC_READ, - 0, // no sharing - NULL, // default security attributes - OPEN_EXISTING, // opens existing pipe - 0, // default attributes - NULL); // no template file - - // Break if the pipe handle is valid. - if (hPipe != INVALID_HANDLE_VALUE) - break; - - // Exit if an error other than ERROR_PIPE_BUSY occurs. - Err = GetLastError(); - if (Err != ERROR_PIPE_BUSY) { - if (ERROR_FILE_NOT_FOUND == Err) - { - res = PIPEREAD_NOPIPE; - return res; - } - else - { - fprintf(stderr,"Could not open pipe %s. Error=%lu\n", path, Err ); - res = -1; - } - break; - } - - // All pipe instances are busy, so wait for 20 seconds. - if ( ! WaitNamedPipe(path, 20000)) { - fprintf(stderr,"Could not open pipe: 20 second wait timed out."); - res = -2; - break; - } - } - - if (!res) do { - fSuccess = ReadFile( - hPipe, // pipe handle - chBuf, // buffer to receive reply - BUFSIZE, // size of buffer - &cbRead, // number of bytes read - NULL); // not overlapped - - if ( ! fSuccess ) { - Err = GetLastError(); - if ( Err == ERROR_MORE_DATA ) { - fSuccess = TRUE; - } else { - fprintf(stderr, "ReadFile: Error %lu \n", Err ); - res = -9; - break; - } - } - - fwrite(chBuf,1,cbRead,stdout); - } while ( fSuccess); + setvbuf(stdout, NULL, _IONBF, 0); + while (1) { + hPipe = CreateFile(path, // pipe name + GENERIC_READ, + 0, // no sharing + NULL, // default security attributes + OPEN_EXISTING, // opens existing pipe + 0, // default attributes + NULL); // no template file - if ( ! fSuccess) { - fprintf(stderr, "ReadFile from pipe failed. Error=%lu\n", GetLastError() ); - } + // Break if the pipe handle is valid. + if (hPipe != INVALID_HANDLE_VALUE) + break; - if (hPipe != INVALID_HANDLE_VALUE) - CloseHandle(hPipe); + // Exit if an error other than ERROR_PIPE_BUSY occurs. + Err = GetLastError(); + if (Err != ERROR_PIPE_BUSY) { + if (ERROR_FILE_NOT_FOUND == Err) + { + res = PIPEREAD_NOPIPE; + return res; + } + else + { + fprintf(stderr,"Could not open pipe %s. Error=%lu\n", path, Err ); + res = -1; + } + break; + } + + // All pipe instances are busy, so wait for 20 seconds. + if ( ! WaitNamedPipe(path, 20000)) { + fprintf(stderr,"Could not open pipe: 20 second wait timed out."); + res = -2; + break; + } + } + + if (!res) do { + fSuccess = ReadFile(hPipe, // pipe handle + chBuf, // buffer to receive reply + BUFSIZE, // size of buffer + &cbRead, // number of bytes read + NULL); // not overlapped + + if ( ! fSuccess ) { + Err = GetLastError(); + if ( Err == ERROR_MORE_DATA ) { + fSuccess = TRUE; + } else { + fprintf(stderr, "ReadFile: Error %lu \n", Err ); + res = -9; + break; + } + } + + fwrite(chBuf,1,cbRead,stdout); + } while ( fSuccess); + + if ( ! fSuccess) { + fprintf(stderr, "ReadFile from pipe failed. Error=%lu\n", GetLastError() ); + } + + if (hPipe != INVALID_HANDLE_VALUE) + CloseHandle(hPipe); + + return res; - return res; - } static int fileClient(const char *path) { - int res = 0; - FILE *fin; - int c; + int res = 0; + FILE *fin; + int c; - setvbuf(stdout, NULL, _IONBF, 0); - if (!(fin = fopen(path, "r"))) { - fprintf(stderr,"Could not fopen %s (%s)\n", path, strerror(errno) ); - return -1; - } + setvbuf(stdout, NULL, _IONBF, 0); + if (!(fin = fopen(path, "r"))) { + fprintf(stderr,"Could not fopen %s (%s)\n", path, strerror(errno) ); + return -1; + } - while ((c = fgetc(fin)) != EOF) { - fputc(c, stdout); - } + while ((c = fgetc(fin)) != EOF) { + fputc(c, stdout); + } - fclose(fin); - return res; + fclose(fin); + return res; } void usage(void) { fprintf(stderr, "piperead " PIPEREAD_VERSION "\n\n"); - fprintf(stderr, "Usage: piperead [-c] \n"); - fprintf(stderr, "-c means Client mode\n"); - fprintf(stderr, "Example: piperead -c \\\\.\\pipe\\kdbg | log2lines -c\n\n"); + fprintf(stderr, "Usage: piperead [-c] \n"); + fprintf(stderr, "-c means Client mode\n"); + fprintf(stderr, "Example: piperead -c \\\\.\\pipe\\kdbg | log2lines -c\n\n"); } int main(int argc, char** argv) { - char path[MAX_PATH]; - const char* pipe_name; - const char* clientMode; - int res = 0; + char path[MAX_PATH]; + const char* pipe_name; + const char* clientMode; + int res = 0; - pipe_name = "com_1"; - clientMode = NULL; - switch (argc) { - case 3: - clientMode = *++argv; - if (strcmp(clientMode,"-c") != 0) { - fprintf(stderr,"Invalid option: %s\n", clientMode); - clientMode = NULL; - res = -6; - } - //fall through - case 2: - pipe_name = *++argv; - if (strcmp(pipe_name,"-h") == 0) { - res = -7; - } - break; - default: - res = -8; - break; - } - if (res) { - usage(); - return res; - } + pipe_name = "com_1"; + clientMode = NULL; + switch (argc) { + case 3: + clientMode = *++argv; + if (strcmp(clientMode,"-c") != 0) { + fprintf(stderr,"Invalid option: %s\n", clientMode); + clientMode = NULL; + res = -6; + } + //fall through + case 2: + pipe_name = *++argv; + if (strcmp(pipe_name,"-h") == 0) { + res = -7; + } + break; + default: + res = -8; + break; + } + if (res) { + usage(); + return res; + } - if ( pipe_name[0] == '\\' ) { - //assume caller specified full path - sprintf(path, "%s", pipe_name); - } else { - sprintf(path, "\\\\.\\pipe\\%s", pipe_name); - } + if ( pipe_name[0] == '\\' ) { + //assume caller specified full path + sprintf(path, "%s", pipe_name); + } else { + sprintf(path, "\\\\.\\pipe\\%s", pipe_name); + } - if ( clientMode ) { - res = pipeClient(path); - if (res == PIPEREAD_NOPIPE) { - res = fileClient(pipe_name); - } - } else { - res = pipeServer(path); - } + if ( clientMode ) { + res = pipeClient(path); + if (res == PIPEREAD_NOPIPE) { + res = fileClient(pipe_name); + } + } else { + res = pipeServer(path); + } - return res; + return res; } diff --git a/reactos/tools/pipetools/pipespy.cpp b/reactos/tools/pipetools/pipespy.cpp index 653c7f1def4..210e3943437 100644 --- a/reactos/tools/pipetools/pipespy.cpp +++ b/reactos/tools/pipetools/pipespy.cpp @@ -31,221 +31,221 @@ CRITICAL_SECTION g_OutputLock; void dumphex(const char *buf, int len, int pos) { - int i, j; - for(j = 0; j < len; j += 16) { - for(i = 0; i < 16; i++) { - if(i + j < len) - printf("%02x%c", (unsigned char)buf[i + j], j + i + 1 == pos ? '*' : ' '); - else - printf(" "); - } - for(i = 0; i < 16; i++) { - if(i + j < len) - printf("%c", buf[i + j] >= ' ' ? buf[i + j] : '.'); - else - printf(" "); - } - printf("\n"); - } + int i, j; + for(j = 0; j < len; j += 16) { + for(i = 0; i < 16; i++) { + if(i + j < len) + printf("%02x%c", (unsigned char)buf[i + j], j + i + 1 == pos ? '*' : ' '); + else + printf(" "); + } + for(i = 0; i < 16; i++) { + if(i + j < len) + printf("%c", buf[i + j] >= ' ' ? buf[i + j] : '.'); + else + printf(" "); + } + printf("\n"); + } } enum { - PIPEBUF_INITIAL_SIZE = 4096, - PIPEBUF_MAX_SIZE = 16384 + PIPEBUF_INITIAL_SIZE = 4096, + PIPEBUF_MAX_SIZE = 16384 }; typedef struct _READ_OVERLAPPED { - OVERLAPPED ReadOverlapped; - char* Buffer; - HANDLE Pipe, OtherPipe; - bool Server; - bool Connected; + OVERLAPPED ReadOverlapped; + char* Buffer; + HANDLE Pipe, OtherPipe; + bool Server; + bool Connected; } READ_OVERLAPPED; VOID WINAPI WritePipeCompletion(DWORD dwErrorCode, DWORD dwNumberOfBytesTransferred, LPOVERLAPPED lpOverlapped) { - if(dwErrorCode) { - EnterCriticalSection(&g_OutputLock); - printf(lpOverlapped->hEvent ? "Server> Error %u writing to client pipe\n" : "Client> Error %u writing to server pipe\n", dwErrorCode); - LeaveCriticalSection(&g_OutputLock); - } + if(dwErrorCode) { + EnterCriticalSection(&g_OutputLock); + printf(lpOverlapped->hEvent ? "Server> Error %u writing to client pipe\n" : "Client> Error %u writing to server pipe\n", dwErrorCode); + LeaveCriticalSection(&g_OutputLock); + } - free((void*)lpOverlapped); + free((void*)lpOverlapped); } VOID WINAPI ReadPipeCompletion(DWORD dwErrorCode, DWORD dwNumberOfBytesTransferred, LPOVERLAPPED lpOverlapped) { - READ_OVERLAPPED* ReadOverlapped = (READ_OVERLAPPED*)lpOverlapped; - LPOVERLAPPED WriteOverlapped; + READ_OVERLAPPED* ReadOverlapped = (READ_OVERLAPPED*)lpOverlapped; + LPOVERLAPPED WriteOverlapped; - EnterCriticalSection(&g_OutputLock); + EnterCriticalSection(&g_OutputLock); - if(dwErrorCode) { - printf(ReadOverlapped->Server ? "Server> Error %u reading from pipe\n" : "Client> Error %u reading from pipe\n", dwErrorCode); - ReadOverlapped->Connected = false; - } else { - SYSTEMTIME SystemTime; + if(dwErrorCode) { + printf(ReadOverlapped->Server ? "Server> Error %u reading from pipe\n" : "Client> Error %u reading from pipe\n", dwErrorCode); + ReadOverlapped->Connected = false; + } else { + SYSTEMTIME SystemTime; - GetLocalTime(&SystemTime); - printf(ReadOverlapped->Server ? "Server> [%02u:%02u:%02u.%03u] Received %u byte message:\n" : "Client> [%02u:%02u:%02u.%03u] Received %u byte message:\n", - SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond, SystemTime.wMilliseconds, dwNumberOfBytesTransferred); - dumphex(ReadOverlapped->Buffer, (int)dwNumberOfBytesTransferred, -1); - printf("\n"); - } + GetLocalTime(&SystemTime); + printf(ReadOverlapped->Server ? "Server> [%02u:%02u:%02u.%03u] Received %u byte message:\n" : "Client> [%02u:%02u:%02u.%03u] Received %u byte message:\n", + SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond, SystemTime.wMilliseconds, dwNumberOfBytesTransferred); + dumphex(ReadOverlapped->Buffer, (int)dwNumberOfBytesTransferred, -1); + printf("\n"); + } - LeaveCriticalSection(&g_OutputLock); + LeaveCriticalSection(&g_OutputLock); - WriteOverlapped = (LPOVERLAPPED)malloc(sizeof(OVERLAPPED)+dwNumberOfBytesTransferred); + WriteOverlapped = (LPOVERLAPPED)malloc(sizeof(OVERLAPPED)+dwNumberOfBytesTransferred); - if(!WriteOverlapped) - printf(ReadOverlapped->Server ? "Server> Out of memory\n" : "Client> Out of memory\n"); - else { - ZeroMemory(WriteOverlapped, sizeof(OVERLAPPED)); - WriteOverlapped->hEvent = (HANDLE)ReadOverlapped->Server; - memcpy(((char*)WriteOverlapped)+sizeof(OVERLAPPED), ReadOverlapped->Buffer, dwNumberOfBytesTransferred); - WriteFileEx(ReadOverlapped->OtherPipe, ((char*)WriteOverlapped)+sizeof(OVERLAPPED), dwNumberOfBytesTransferred, WriteOverlapped, - WritePipeCompletion); - } + if(!WriteOverlapped) + printf(ReadOverlapped->Server ? "Server> Out of memory\n" : "Client> Out of memory\n"); + else { + ZeroMemory(WriteOverlapped, sizeof(OVERLAPPED)); + WriteOverlapped->hEvent = (HANDLE)ReadOverlapped->Server; + memcpy(((char*)WriteOverlapped)+sizeof(OVERLAPPED), ReadOverlapped->Buffer, dwNumberOfBytesTransferred); + WriteFileEx(ReadOverlapped->OtherPipe, ((char*)WriteOverlapped)+sizeof(OVERLAPPED), dwNumberOfBytesTransferred, WriteOverlapped, + WritePipeCompletion); + } - if(!dwErrorCode) { - ZeroMemory(ReadOverlapped, sizeof(OVERLAPPED)); - ReadFileEx(ReadOverlapped->Pipe, ReadOverlapped->Buffer, PIPEBUF_INITIAL_SIZE, &ReadOverlapped->ReadOverlapped, ReadPipeCompletion); - } + if(!dwErrorCode) { + ZeroMemory(ReadOverlapped, sizeof(OVERLAPPED)); + ReadFileEx(ReadOverlapped->Pipe, ReadOverlapped->Buffer, PIPEBUF_INITIAL_SIZE, &ReadOverlapped->ReadOverlapped, ReadPipeCompletion); + } } void __cdecl pipeserver(void* param) { - READ_OVERLAPPED ReadOverlapped; + READ_OVERLAPPED ReadOverlapped; - ReadOverlapped.Pipe = (HANDLE)param, ReadOverlapped.OtherPipe = ReadOverlapped.Pipe == g_DebugServerPipe ? g_DebugClientPipe : g_DebugServerPipe; - ReadOverlapped.Server = ReadOverlapped.Pipe == g_DebugServerPipe; - ReadOverlapped.Buffer = (char*)malloc(PIPEBUF_INITIAL_SIZE); + ReadOverlapped.Pipe = (HANDLE)param, ReadOverlapped.OtherPipe = ReadOverlapped.Pipe == g_DebugServerPipe ? g_DebugClientPipe : g_DebugServerPipe; + ReadOverlapped.Server = ReadOverlapped.Pipe == g_DebugServerPipe; + ReadOverlapped.Buffer = (char*)malloc(PIPEBUF_INITIAL_SIZE); - for(;;) { - if(!ConnectNamedPipe(ReadOverlapped.Pipe, 0) && GetLastError() != ERROR_PIPE_CONNECTED) { - printf(ReadOverlapped.Server ? "Server> Error %u accepting pipe connection\n" : "Client> Error %u accepting pipe connection\n", - GetLastError()); - break; - } + for(;;) { + if(!ConnectNamedPipe(ReadOverlapped.Pipe, 0) && GetLastError() != ERROR_PIPE_CONNECTED) { + printf(ReadOverlapped.Server ? "Server> Error %u accepting pipe connection\n" : "Client> Error %u accepting pipe connection\n", + GetLastError()); + break; + } - ReadOverlapped.Connected = true; - printf(ReadOverlapped.Server ? "Server> Connected\n" : "Client> Connected\n"); + ReadOverlapped.Connected = true; + printf(ReadOverlapped.Server ? "Server> Connected\n" : "Client> Connected\n"); - ZeroMemory(&ReadOverlapped.ReadOverlapped, sizeof(OVERLAPPED)); - ReadFileEx(ReadOverlapped.Pipe, ReadOverlapped.Buffer, PIPEBUF_INITIAL_SIZE, &ReadOverlapped.ReadOverlapped, ReadPipeCompletion); + ZeroMemory(&ReadOverlapped.ReadOverlapped, sizeof(OVERLAPPED)); + ReadFileEx(ReadOverlapped.Pipe, ReadOverlapped.Buffer, PIPEBUF_INITIAL_SIZE, &ReadOverlapped.ReadOverlapped, ReadPipeCompletion); - do { - SleepEx(INFINITE, TRUE); - } while(ReadOverlapped.Connected) ; + do { + SleepEx(INFINITE, TRUE); + } while(ReadOverlapped.Connected) ; - DisconnectNamedPipe(ReadOverlapped.Pipe); - printf(ReadOverlapped.Server ? "Server> Disconnected\n" : "Client> Disconnected\n"); - } + DisconnectNamedPipe(ReadOverlapped.Pipe); + printf(ReadOverlapped.Server ? "Server> Disconnected\n" : "Client> Disconnected\n"); + } - printf(ReadOverlapped.Server ? "Server> Shutting down\n" : "Client> Shutting down\n"); + printf(ReadOverlapped.Server ? "Server> Shutting down\n" : "Client> Shutting down\n"); - free(ReadOverlapped.Buffer); - CloseHandle(ReadOverlapped.Pipe); - SleepEx(0, TRUE); + free(ReadOverlapped.Buffer); + CloseHandle(ReadOverlapped.Pipe); + SleepEx(0, TRUE); } int main(int ac, char **av) { - if(ac != 3) { - printf("syntax: pipespy serverpipe clientpipe\n"); - return 0; - } + if(ac != 3) { + printf("syntax: pipespy serverpipe clientpipe\n"); + return 0; + } - g_DebugServerPipe = CreateNamedPipe(av[1], PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, - 1, 4096, 4096, NMPWAIT_WAIT_FOREVER, 0); + g_DebugServerPipe = CreateNamedPipe(av[1], PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, + 1, 4096, 4096, NMPWAIT_WAIT_FOREVER, 0); - if(g_DebugServerPipe == INVALID_HANDLE_VALUE) { - printf("Error %u creating server pipe\n", GetLastError()); - return 0; - } + if(g_DebugServerPipe == INVALID_HANDLE_VALUE) { + printf("Error %u creating server pipe\n", GetLastError()); + return 0; + } - g_DebugClientPipe = CreateNamedPipe(av[2], PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, - 1, 4096, 4096, NMPWAIT_WAIT_FOREVER, 0); + g_DebugClientPipe = CreateNamedPipe(av[2], PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, + 1, 4096, 4096, NMPWAIT_WAIT_FOREVER, 0); - if(g_DebugClientPipe == INVALID_HANDLE_VALUE) { - printf("Error %u creating client pipe\n", GetLastError()); - CloseHandle(g_DebugServerPipe); - return 0; - } + if(g_DebugClientPipe == INVALID_HANDLE_VALUE) { + printf("Error %u creating client pipe\n", GetLastError()); + CloseHandle(g_DebugServerPipe); + return 0; + } - InitializeCriticalSection(&g_OutputLock); - _beginthread(pipeserver, 0, (void*)g_DebugServerPipe); - pipeserver((void*)g_DebugClientPipe); - DeleteCriticalSection(&g_OutputLock); - return 0; + InitializeCriticalSection(&g_OutputLock); + _beginthread(pipeserver, 0, (void*)g_DebugServerPipe); + pipeserver((void*)g_DebugClientPipe); + DeleteCriticalSection(&g_OutputLock); + return 0; } /* - while(!Error) { - SleepEx(0, TRUE); - BufferPos = 0; + while(!Error) { + SleepEx(0, TRUE); + BufferPos = 0; - if(BufferSize > PIPEBUF_MAX_SIZE) { - char* NewBuf = (char*)realloc(Buffer, PIPEBUF_MAX_SIZE); + if(BufferSize > PIPEBUF_MAX_SIZE) { + char* NewBuf = (char*)realloc(Buffer, PIPEBUF_MAX_SIZE); - if(NewBuf) { - Buffer = NewBuf; - BufferSize = PIPEBUF_MAX_SIZE; - } - } + if(NewBuf) { + Buffer = NewBuf; + BufferSize = PIPEBUF_MAX_SIZE; + } + } - for(;;) { - char* NewBuf; + for(;;) { + char* NewBuf; - if(ReadFile(Pipe, Buffer+BufferPos, BufferSize-BufferPos, &Read, 0)) { - BufferPos += Read; - Error = 0; - break; - } + if(ReadFile(Pipe, Buffer+BufferPos, BufferSize-BufferPos, &Read, 0)) { + BufferPos += Read; + Error = 0; + break; + } - Error = GetLastError(); + Error = GetLastError(); - printf("Error=%u read=%u\n", Error, Read); + printf("Error=%u read=%u\n", Error, Read); - if(Error != ERROR_MORE_DATA) { - printf(Server ? "Server> Error %u reading from pipe\n" : "Client> Error %u reading from pipe\n", GetLastError()); - break; - } + if(Error != ERROR_MORE_DATA) { + printf(Server ? "Server> Error %u reading from pipe\n" : "Client> Error %u reading from pipe\n", GetLastError()); + break; + } - NewBuf = (char*)realloc(Buffer, BufferSize << 1); + NewBuf = (char*)realloc(Buffer, BufferSize << 1); - if(!NewBuf) { - printf(Server ? "Server> Out of memory\n" : "Client> Out of memory\n"); - break; - } + if(!NewBuf) { + printf(Server ? "Server> Out of memory\n" : "Client> Out of memory\n"); + break; + } - BufferSize <<= 1; - BufferPos += Read; - Error = 0; - } + BufferSize <<= 1; + BufferPos += Read; + Error = 0; + } - if(Error) - break; + if(Error) + break; - WriteOverlapped = (LPOVERLAPPED)malloc(sizeof(OVERLAPPED)+BufferPos); + WriteOverlapped = (LPOVERLAPPED)malloc(sizeof(OVERLAPPED)+BufferPos); - if(!WriteOverlapped) - printf(Server ? "Server> Out of memory\n" : "Client> Out of memory\n"); - else { - ZeroMemory(WriteOverlapped, sizeof(OVERLAPPED)); - memcpy(((char*)WriteOverlapped)+sizeof(OVERLAPPED), Buffer, BufferPos); - WriteFileEx(OtherPipe, ((char*)WriteOverlapped)+sizeof(OVERLAPPED), BufferPos, WriteOverlapped, WritePipeCompletion); - } + if(!WriteOverlapped) + printf(Server ? "Server> Out of memory\n" : "Client> Out of memory\n"); + else { + ZeroMemory(WriteOverlapped, sizeof(OVERLAPPED)); + memcpy(((char*)WriteOverlapped)+sizeof(OVERLAPPED), Buffer, BufferPos); + WriteFileEx(OtherPipe, ((char*)WriteOverlapped)+sizeof(OVERLAPPED), BufferPos, WriteOverlapped, WritePipeCompletion); + } - EnterCriticalSection(&g_OutputLock); - printf(Server ? "Server> Received %u byte message:\n" : "Client> Received %u byte message:\n", BufferPos); - dumphex(Buffer, (int)BufferPos, -1); - printf("\n"); - LeaveCriticalSection(&g_OutputLock); - } + EnterCriticalSection(&g_OutputLock); + printf(Server ? "Server> Received %u byte message:\n" : "Client> Received %u byte message:\n", BufferPos); + dumphex(Buffer, (int)BufferPos, -1); + printf("\n"); + LeaveCriticalSection(&g_OutputLock); + } - DisconnectNamedPipe(Pipe); - printf(Server ? "Server> Disconnected\n" : "Client> Disconnected\n"); + DisconnectNamedPipe(Pipe); + printf(Server ? "Server> Disconnected\n" : "Client> Disconnected\n"); */ diff --git a/reactos/tools/pipetools/pipetunnel.cpp b/reactos/tools/pipetools/pipetunnel.cpp index 23643ff5776..0d68a7ee2b9 100644 --- a/reactos/tools/pipetools/pipetunnel.cpp +++ b/reactos/tools/pipetools/pipetunnel.cpp @@ -5,15 +5,15 @@ // // -// Invoke as: "pipetunnel [pipe_name]", -// for example: "pipetunnel com_2" +// Invoke as: "pipetunnel [pipe_name]", +// for example: "pipetunnel com_2" // // Then start up RectOS in VMWare, wait for the serial connect. // After that you can connect GDB using the command "target remote :9999". // -#define WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN #include #include @@ -27,14 +27,14 @@ // This definition currently missing in MinGW. -#ifndef FILE_FLAG_FIRST_PIPE_INSTANCE -#define FILE_FLAG_FIRST_PIPE_INSTANCE 0x00080000 +#ifndef FILE_FLAG_FIRST_PIPE_INSTANCE +#define FILE_FLAG_FIRST_PIPE_INSTANCE 0x00080000 #endif static void print_error(DWORD win32_error) { - fprintf(stderr, "WIN32 error %lu\n", win32_error); + fprintf(stderr, "WIN32 error %lu\n", win32_error); } @@ -43,45 +43,45 @@ static void print_error(DWORD win32_error) // critical section wrapper struct CritSect : public CRITICAL_SECTION { - CritSect() - { - InitializeCriticalSection(this); - } + CritSect() + { + InitializeCriticalSection(this); + } - ~CritSect() - { - DeleteCriticalSection(this); - } + ~CritSect() + { + DeleteCriticalSection(this); + } }; static void dbg_trace(char mode, const char* buffer, int l) { - static char s_mode = '\0'; - static CritSect crit_sect; + static char s_mode = '\0'; + static CritSect crit_sect; - EnterCriticalSection(&crit_sect); + EnterCriticalSection(&crit_sect); - if (l) { - for(const char*p=buffer; l--; ++p) { - if (mode != s_mode) { - putchar('\n'); - putchar(mode); - putchar(' '); + if (l) { + for(const char*p=buffer; l--; ++p) { + if (mode != s_mode) { + putchar('\n'); + putchar(mode); + putchar(' '); - s_mode = mode; - } + s_mode = mode; + } - if (*p=='\n' || !*p /*|| *p=='#'*/) { - /*if (*p == '#') - putchar(*p);*/ + if (*p=='\n' || !*p /*|| *p=='#'*/) { + /*if (*p == '#') + putchar(*p);*/ - s_mode = '\0'; - } else - putchar(*p); - } - } + s_mode = '\0'; + } else + putchar(*p); + } + } - LeaveCriticalSection(&crit_sect); + LeaveCriticalSection(&crit_sect); } #endif @@ -91,227 +91,227 @@ static SOCKET s_srv_socket = (SOCKET)-1; SOCKET open_tcp_connect() { - if (s_srv_socket == (SOCKET)-1) { - SOCKADDR_IN srv_addr = {0}; + if (s_srv_socket == (SOCKET)-1) { + SOCKADDR_IN srv_addr = {0}; - srv_addr.sin_family = AF_INET; - srv_addr.sin_addr.s_addr = htonl(INADDR_ANY); - srv_addr.sin_port = htons(9999); + srv_addr.sin_family = AF_INET; + srv_addr.sin_addr.s_addr = htonl(INADDR_ANY); + srv_addr.sin_port = htons(9999); - s_srv_socket = socket(PF_INET, SOCK_STREAM, 0); - if (s_srv_socket == (SOCKET)-1) { - perror("socket()"); - return 0; - } + s_srv_socket = socket(PF_INET, SOCK_STREAM, 0); + if (s_srv_socket == (SOCKET)-1) { + perror("socket()"); + return 0; + } - if (bind(s_srv_socket, (struct sockaddr*) &srv_addr, sizeof(srv_addr)) == -1) { - perror("bind()"); - return 0; - } + if (bind(s_srv_socket, (struct sockaddr*) &srv_addr, sizeof(srv_addr)) == -1) { + perror("bind()"); + return 0; + } - if (listen(s_srv_socket, 4) == -1) { - perror("listen()"); - return 0; - } - } + if (listen(s_srv_socket, 4) == -1) { + perror("listen()"); + return 0; + } + } - SOCKADDR_IN rem_addr; - int rem_len = sizeof(rem_addr); + SOCKADDR_IN rem_addr; + int rem_len = sizeof(rem_addr); - for(;;) { - SOCKET sock = accept(s_srv_socket, (struct sockaddr*)&rem_addr, &rem_len); + for(;;) { + SOCKET sock = accept(s_srv_socket, (struct sockaddr*)&rem_addr, &rem_len); - if (sock < 0) { - if (errno == EINTR) - continue; + if (sock < 0) { + if (errno == EINTR) + continue; - perror("accept()"); - return 0; - } + perror("accept()"); + return 0; + } - return sock; - } + return sock; + } } struct WriterThread { - WriterThread(SOCKET sock, HANDLE hPipe) - : _sock(sock), - _hPipe(hPipe) - { - DWORD tid; + WriterThread(SOCKET sock, HANDLE hPipe) + : _sock(sock), + _hPipe(hPipe) + { + DWORD tid; - HANDLE hThread = CreateThread(NULL, 0, WriterThreadRoutine, this, 0, &tid); + HANDLE hThread = CreateThread(NULL, 0, WriterThreadRoutine, this, 0, &tid); - if (hThread) { - SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST); + if (hThread) { + SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST); - CloseHandle(hThread); - } else - delete this; - } + CloseHandle(hThread); + } else + delete this; + } protected: - SOCKET _sock; - HANDLE _hPipe; + SOCKET _sock; + HANDLE _hPipe; - static DWORD WINAPI WriterThreadRoutine(LPVOID param) - { - WriterThread* pThis = (WriterThread*) param; + static DWORD WINAPI WriterThreadRoutine(LPVOID param) + { + WriterThread* pThis = (WriterThread*) param; - DWORD ret = pThis->Run(); + DWORD ret = pThis->Run(); - delete pThis; + delete pThis; - return ret; - } + return ret; + } - DWORD Run() - { - char buffer[1024]; + DWORD Run() + { + char buffer[1024]; - for(;;) { - int r = recv(_sock, buffer, sizeof(buffer), 0); + for(;;) { + int r = recv(_sock, buffer, sizeof(buffer), 0); - if (r == -1) { - perror("recv()"); - fprintf(stderr, "debugger connection broken\n"); - _sock = (SOCKET)-1; - return 1; - } + if (r == -1) { + perror("recv()"); + fprintf(stderr, "debugger connection broken\n"); + _sock = (SOCKET)-1; + return 1; + } - if (r) { - DWORD wrote; + if (r) { + DWORD wrote; - if (!WriteFile(_hPipe, buffer, r, &wrote, NULL)) - break; + if (!WriteFile(_hPipe, buffer, r, &wrote, NULL)) + break; #ifdef _DEBUG - dbg_trace('<', buffer, r); + dbg_trace('<', buffer, r); #endif - } - } + } + } - return 0; - } + return 0; + } }; LONG read_pipe(HANDLE hPipe, SOCKET sock) { - for(;;) { - DWORD read; - char buffer[1024]; + for(;;) { + DWORD read; + char buffer[1024]; - // wait for input data - WaitForSingleObject(hPipe, INFINITE); + // wait for input data + WaitForSingleObject(hPipe, INFINITE); - if (!ReadFile(hPipe, buffer, sizeof(buffer), &read, NULL)) { - DWORD error = GetLastError(); + if (!ReadFile(hPipe, buffer, sizeof(buffer), &read, NULL)) { + DWORD error = GetLastError(); - if (error == ERROR_PIPE_LISTENING) - Sleep(1000); - else - return error; - } + if (error == ERROR_PIPE_LISTENING) + Sleep(1000); + else + return error; + } - if (read) { + if (read) { #ifdef _DEBUG - dbg_trace('>', buffer, read); + dbg_trace('>', buffer, read); #endif - if (!send(sock, buffer, read, 0)) { - perror("send()"); - return GetLastError(); - } - } - } + if (!send(sock, buffer, read, 0)) { + perror("send()"); + return GetLastError(); + } + } + } } int main(int argc, char** argv) { - char path[MAX_PATH]; - const char* pipe_name; + char path[MAX_PATH]; + const char* pipe_name; - if (argc > 1) - pipe_name = *++argv; - else - pipe_name = "com_2"; + if (argc > 1) + pipe_name = *++argv; + else + pipe_name = "com_2"; - sprintf(path, "\\\\.\\pipe\\%s", pipe_name); + sprintf(path, "\\\\.\\pipe\\%s", pipe_name); - // initialize winsock - WSADATA wsa_data; + // initialize winsock + WSADATA wsa_data; - if (WSAStartup(MAKEWORD(2,2), &wsa_data)) { - fprintf(stderr, "WSAStartup() failed\n"); - return 0; - } + if (WSAStartup(MAKEWORD(2,2), &wsa_data)) { + fprintf(stderr, "WSAStartup() failed\n"); + return 0; + } - // increment priority to be faster than the cpu eating VMWare process - SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); - SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); + // increment priority to be faster than the cpu eating VMWare process + SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); - HANDLE hPipe = INVALID_HANDLE_VALUE; + HANDLE hPipe = INVALID_HANDLE_VALUE; - for(;;) { - DWORD read; + for(;;) { + DWORD read; - if (hPipe == INVALID_HANDLE_VALUE) { - hPipe = CreateNamedPipe(path, PIPE_ACCESS_DUPLEX|FILE_FLAG_FIRST_PIPE_INSTANCE|FILE_FLAG_OVERLAPPED, PIPE_WAIT|PIPE_TYPE_BYTE, 1, 4096, 4096, 30000, NULL); + if (hPipe == INVALID_HANDLE_VALUE) { + hPipe = CreateNamedPipe(path, PIPE_ACCESS_DUPLEX|FILE_FLAG_FIRST_PIPE_INSTANCE|FILE_FLAG_OVERLAPPED, PIPE_WAIT|PIPE_TYPE_BYTE, 1, 4096, 4096, 30000, NULL); - if (hPipe == INVALID_HANDLE_VALUE) { - print_error(GetLastError()); - return 1; - } - } + if (hPipe == INVALID_HANDLE_VALUE) { + print_error(GetLastError()); + return 1; + } + } - // wait for the client side of the pipe - while(!ReadFile(hPipe, NULL, 0, &read, NULL) && - GetLastError()==ERROR_PIPE_LISTENING) - Sleep(1000); + // wait for the client side of the pipe + while(!ReadFile(hPipe, NULL, 0, &read, NULL) && + GetLastError()==ERROR_PIPE_LISTENING) + Sleep(1000); - puts("\nnamed pipe connected, now waiting for TCP connection..."); + puts("\nnamed pipe connected, now waiting for TCP connection..."); - SOCKET sock = open_tcp_connect(); - if (sock == (SOCKET)-1) - break; + SOCKET sock = open_tcp_connect(); + if (sock == (SOCKET)-1) + break; - puts("TCP connection established."); + puts("TCP connection established."); - // launch writer thread - new WriterThread(sock, hPipe); + // launch writer thread + new WriterThread(sock, hPipe); - // launch reader loop - LONG error = read_pipe(hPipe, sock); + // launch reader loop + LONG error = read_pipe(hPipe, sock); - // close TCP connectiom - closesocket(sock); - sock = (SOCKET)-1; + // close TCP connectiom + closesocket(sock); + sock = (SOCKET)-1; - // close named pipe - CloseHandle(hPipe); - hPipe = INVALID_HANDLE_VALUE; + // close named pipe + CloseHandle(hPipe); + hPipe = INVALID_HANDLE_VALUE; - if (error == ERROR_BROKEN_PIPE) - puts("\nconnection closed."); // normal connection termination - else { - print_error(GetLastError()); - break; - } - } + if (error == ERROR_BROKEN_PIPE) + puts("\nconnection closed."); // normal connection termination + else { + print_error(GetLastError()); + break; + } + } - if (hPipe != INVALID_HANDLE_VALUE) - if (!CloseHandle(hPipe)) - print_error(GetLastError()); + if (hPipe != INVALID_HANDLE_VALUE) + if (!CloseHandle(hPipe)) + print_error(GetLastError()); - return 0; + return 0; } diff --git a/reactos/tools/stubgen.c b/reactos/tools/stubgen.c index 86bb8de9671..ad8c8f080f4 100644 --- a/reactos/tools/stubgen.c +++ b/reactos/tools/stubgen.c @@ -9,166 +9,166 @@ #endif typedef struct _stub { - char *name; - char *origin; - struct _stub *next; + char *name; + char *origin; + struct _stub *next; } stub; void usage( char *name ) { - fprintf( stderr, - "Usage: %s [-n nm] [-m make] libs...\n" - "nm -- The command used to run nm on reactos objects\n" - "make -- The command used to build reactos\n\n" - "libs are import libraries (.a files) typically from\n" - "dk/lib/nkm and dk/lib/w32\n", - name ); + fprintf( stderr, + "Usage: %s [-n nm] [-m make] libs...\n" + "nm -- The command used to run nm on reactos objects\n" + "make -- The command used to build reactos\n\n" + "libs are import libraries (.a files) typically from\n" + "dk/lib/nkm and dk/lib/w32\n", + name ); } int main( int argc, char **argv ) { - char line[1024]; - char *make = "make"; - char *nm = "nm"; - char *origin = "unknown.a"; - stub *functions = NULL, *new_f, *imports = NULL, *search; - FILE *make_f, *nm_f; - int i, libstart = argc; - FILE *out = fopen("tests/stubs.tst","w"); + char line[1024]; + char *make = "make"; + char *nm = "nm"; + char *origin = "unknown.a"; + stub *functions = NULL, *new_f, *imports = NULL, *search; + FILE *make_f, *nm_f; + int i, libstart = argc; + FILE *out = fopen("tests/stubs.tst","w"); - if( argc == 1 ) { - if( out ) fclose( out ); - usage(argv[0]); - return 1; - } + if( argc == 1 ) { + if( out ) fclose( out ); + usage(argv[0]); + return 1; + } - if( !out ) { - fprintf( stderr, "Could not write file tests/stubs.tst\n" ); - return 1; - } + if( !out ) { + fprintf( stderr, "Could not write file tests/stubs.tst\n" ); + return 1; + } - fprintf( out, "# Automatically generated by stubgen\n" ); + fprintf( out, "# Automatically generated by stubgen\n" ); - for( i = 1; i < argc; i++ ) { - if( !strcmp( argv[i], "-m" ) ) { - make = argv[i+1]; - i++; - } else if( !strcmp( argv[i], "-n" ) ) { - nm = argv[i+1]; - i++; - } else { libstart = i; break; } - } + for( i = 1; i < argc; i++ ) { + if( !strcmp( argv[i], "-m" ) ) { + make = argv[i+1]; + i++; + } else if( !strcmp( argv[i], "-n" ) ) { + nm = argv[i+1]; + i++; + } else { libstart = i; break; } + } - snprintf( line, sizeof(line), "%s test 2>&1", make ); - make_f = popen( line, "r" ); + snprintf( line, sizeof(line), "%s test 2>&1", make ); + make_f = popen( line, "r" ); - if( !make_f ) { - fclose( out ); - fprintf( stderr, "Could not run %s test\n", make ); - return 1; - } + if( !make_f ) { + fclose( out ); + fprintf( stderr, "Could not run %s test\n", make ); + return 1; + } - while( fgets( line, sizeof(line), make_f ) ) { - char *end_of_location; - char *begin_q, *end_q; + while( fgets( line, sizeof(line), make_f ) ) { + char *end_of_location; + char *begin_q, *end_q; - if( !strstr( line, "undefined reference to" ) ) continue; + if( !strstr( line, "undefined reference to" ) ) continue; - end_of_location = strrchr( line, ':' ); + end_of_location = strrchr( line, ':' ); - if( !end_of_location ) continue; + if( !end_of_location ) continue; - begin_q = strchr( end_of_location, '`' ); - end_q = strchr( end_of_location, '\'' ); + begin_q = strchr( end_of_location, '`' ); + end_q = strchr( end_of_location, '\'' ); - if( !begin_q || !end_q ) continue; + if( !begin_q || !end_q ) continue; - begin_q += 2; /* skip `_ */ + begin_q += 2; /* skip `_ */ - memmove( line, begin_q, end_q - begin_q ); - line[end_q - begin_q] = 0; + memmove( line, begin_q, end_q - begin_q ); + line[end_q - begin_q] = 0; - for( new_f = functions; new_f; new_f = new_f->next ) - if( !strcmp( new_f->name, line ) ) break; + for( new_f = functions; new_f; new_f = new_f->next ) + if( !strcmp( new_f->name, line ) ) break; - if( new_f ) continue; + if( new_f ) continue; - new_f = (stub *)malloc( sizeof(stub) ); - if( !new_f ) - { - fprintf( stderr, "Out of memory\n" ); - fclose( out ); - pclose( make_f ); - return 1; - } + new_f = (stub *)malloc( sizeof(stub) ); + if( !new_f ) + { + fprintf( stderr, "Out of memory\n" ); + fclose( out ); + pclose( make_f ); + return 1; + } - new_f->name = strdup( line ); - new_f->next = functions; - functions = new_f; - } + new_f->name = strdup( line ); + new_f->next = functions; + functions = new_f; + } - /* Scan libraries and collect available import sections */ - for( i = libstart; i < argc; i++ ) { - snprintf( line, sizeof(line), "%s %s", nm, argv[i] ); - nm_f = popen( line, "r" ); + /* Scan libraries and collect available import sections */ + for( i = libstart; i < argc; i++ ) { + snprintf( line, sizeof(line), "%s %s", nm, argv[i] ); + nm_f = popen( line, "r" ); - for( origin = argv[i]; *argv[i]; argv[i]++ ) - if( *argv[i] == '/' || *argv[i] == '\\' ) - origin = argv[i] + 1; + for( origin = argv[i]; *argv[i]; argv[i]++ ) + if( *argv[i] == '/' || *argv[i] == '\\' ) + origin = argv[i] + 1; - if( !nm_f ) { - fprintf( stderr, "Could not run %s\n", line ); - continue; - } + if( !nm_f ) { + fprintf( stderr, "Could not run %s\n", line ); + continue; + } - while( fgets( line, sizeof(line), nm_f ) ) { - char *import_sign, *eol; + while( fgets( line, sizeof(line), nm_f ) ) { + char *import_sign, *eol; - if( !(import_sign = strstr( line, " I " )) ) continue; + if( !(import_sign = strstr( line, " I " )) ) continue; - import_sign += 3; - while( *import_sign && isspace(*import_sign) ) import_sign++; + import_sign += 3; + while( *import_sign && isspace(*import_sign) ) import_sign++; - /* Strip ws after name */ - for( eol = import_sign; *eol && !isspace(*eol); eol++ ); + /* Strip ws after name */ + for( eol = import_sign; *eol && !isspace(*eol); eol++ ); - *eol = 0; + *eol = 0; - for( new_f = imports; new_f; new_f = new_f->next ) - if( !strcmp( new_f->name, import_sign ) ) break; + for( new_f = imports; new_f; new_f = new_f->next ) + if( !strcmp( new_f->name, import_sign ) ) break; - if( new_f ) continue; + if( new_f ) continue; - new_f = (stub *)malloc( sizeof(stub) ); - if( !new_f ) - { - fprintf( stderr, "Out of memory\n" ); - fclose( out ); - pclose( make_f ); - pclose( nm_f ); - return 1; - } + new_f = (stub *)malloc( sizeof(stub) ); + if( !new_f ) + { + fprintf( stderr, "Out of memory\n" ); + fclose( out ); + pclose( make_f ); + pclose( nm_f ); + return 1; + } - new_f->name = strdup( import_sign + 1 ); - new_f->origin = origin; - new_f->next = imports; - imports = new_f; - } + new_f->name = strdup( import_sign + 1 ); + new_f->origin = origin; + new_f->next = imports; + imports = new_f; + } - pclose( nm_f ); - } + pclose( nm_f ); + } - /* Now we have a list of unique functions and a list of imports, - lookup each function and output the entry from the import list. */ - for( new_f = functions; new_f; new_f = new_f->next ) { - for( search = imports; search; search = search->next ) { - if( !strcmp( new_f->name, search->name ) ) { - fprintf( out, "%s %s\n", search->origin, search->name ); - continue; - } - } - } + /* Now we have a list of unique functions and a list of imports, + lookup each function and output the entry from the import list. */ + for( new_f = functions; new_f; new_f = new_f->next ) { + for( search = imports; search; search = search->next ) { + if( !strcmp( new_f->name, search->name ) ) { + fprintf( out, "%s %s\n", search->origin, search->name ); + continue; + } + } + } - fclose( out ); - pclose( make_f ); - return 0; + fclose( out ); + pclose( make_f ); + return 0; } diff --git a/reactos/tools/utf16le/utf16le.cpp b/reactos/tools/utf16le/utf16le.cpp index 8f4fa29bc40..6418905f228 100644 --- a/reactos/tools/utf16le/utf16le.cpp +++ b/reactos/tools/utf16le/utf16le.cpp @@ -5,7 +5,7 @@ * i.e. on Linux gcc and not mingw-gcc (cross-compiler). * It's a converter from utf-8, utf-16 (LE/BE) and utf-32 (LE/BE) * to utf-16 LE and especially made for automatic conversions of - * INF-files from utf-8 to utf-16LE (so we can furthermore + * INF-files from utf-8 to utf-16LE (so we can furthermore * store the INF files in utf-8 for subversion. * * Author: Matthias Kupfer (mkupfer@reactos.org) @@ -20,271 +20,269 @@ using namespace std; class utf_converter { - public: - // detect can detect utf-8 and both utf-16 variants, but assume utf-32 only - // due to ambiguous BOM - enum enc_types { detect, utf8, utf16le, utf16be, utf32le, utf32be }; - enum err_types { none, iopen, oopen, eof, read, write, decode }; - protected: - err_types error; - enc_types encoding; - unsigned char buffer[4], fill, index; // need 4 char buffer for optional BOM handling - fstream inputfile,outputfile; - static const unsigned char utf8table[64]; - public: - utf_converter(string ifname, string ofname, enc_types enc = detect) : error(none), encoding(enc), fill(0), index(0) - { - enc_types tmp_enc; - inputfile.open(ifname.c_str(), ios::in | ios::binary); - if (!inputfile) - { - error = iopen; - return; - } - outputfile.open(ofname.c_str(), ios::out | ios::binary); - if (!outputfile) - { - error = oopen; - return; - } - tmp_enc = getBOM(); - if (enc != detect) - { - if (enc != tmp_enc) - cerr << "Warning: UTF-BOM doesn't match encoding setting, but given encoding forced" << endl; - } - else - encoding = tmp_enc; - } - err_types getError() - { - return error; - } - enc_types getBOM() - { - index = 0; - /* first byte can also detect with: - if ((buffer[0] & 0x11) || !buffer[0])) - valid values are 0xef, 0xff, 0xfe, 0x00 - */ - inputfile.read(reinterpret_cast(&buffer),4); - fill =inputfile.gcount(); - // stupid utf8 bom - if ((fill > 2) && - (buffer[0] == 0xef) && - (buffer[1] == 0xbb) && - (buffer[2] == 0xbf)) - { - index += 3; - fill -=3; +public: + // detect can detect utf-8 and both utf-16 variants, but assume utf-32 only + // due to ambiguous BOM + enum enc_types { detect, utf8, utf16le, utf16be, utf32le, utf32be }; + enum err_types { none, iopen, oopen, eof, read, write, decode }; +protected: + err_types error; + enc_types encoding; + unsigned char buffer[4], fill, index; // need 4 char buffer for optional BOM handling + fstream inputfile,outputfile; + static const unsigned char utf8table[64]; +public: + utf_converter(string ifname, string ofname, enc_types enc = detect) : error(none), encoding(enc), fill(0), index(0) + { + enc_types tmp_enc; + inputfile.open(ifname.c_str(), ios::in | ios::binary); + if (!inputfile) + { + error = iopen; + return; + } + outputfile.open(ofname.c_str(), ios::out | ios::binary); + if (!outputfile) + { + error = oopen; + return; + } + tmp_enc = getBOM(); + if (enc != detect) + { + if (enc != tmp_enc) + cerr << "Warning: UTF-BOM doesn't match encoding setting, but given encoding forced" << endl; + } + else + encoding = tmp_enc; + } + err_types getError() + { + return error; + } + enc_types getBOM() + { + index = 0; + /* first byte can also detect with: + if ((buffer[0] & 0x11) || !buffer[0])) + valid values are 0xef, 0xff, 0xfe, 0x00 + */ + inputfile.read(reinterpret_cast(&buffer),4); + fill =inputfile.gcount(); + // stupid utf8 bom + if ((fill > 2) && + (buffer[0] == 0xef) && + (buffer[1] == 0xbb) && + (buffer[2] == 0xbf)) + { + index += 3; + fill -=3; #ifdef DISPLAY_DETECTED_UNICODE - cerr << "UTF-8 BOM found" << endl; + cerr << "UTF-8 BOM found" << endl; #endif - return utf8; - } - if ((fill > 1) && - (buffer[0] == 0xfe) && - (buffer[1] == 0xff)) - { - index += 2; - fill -= 2; + return utf8; + } + if ((fill > 1) && + (buffer[0] == 0xfe) && + (buffer[1] == 0xff)) + { + index += 2; + fill -= 2; #ifdef DISPLAY_DETECTED_UNICODE - cerr << "UTF-16BE BOM found" << endl; + cerr << "UTF-16BE BOM found" << endl; #endif - return utf16be; - } - if ((fill > 1) && - (buffer[0] == 0xff) && - (buffer[1] == 0xfe)) - { - if ((fill == 4) && - (buffer[2] == 0x00) && - (buffer[3] == 0x00)) - { - cerr << "UTF Error: ambiguous BOM UTF-16 or UTF-32; assume UTF-32" << endl; - fill = 0; - index = 0; - return utf32le; - } - fill -= 2; - index += 2; + return utf16be; + } + if ((fill > 1) && + (buffer[0] == 0xff) && + (buffer[1] == 0xfe)) + { + if ((fill == 4) && + (buffer[2] == 0x00) && + (buffer[3] == 0x00)) + { + cerr << "UTF Error: ambiguous BOM UTF-16 or UTF-32; assume UTF-32" << endl; + fill = 0; + index = 0; + return utf32le; + } + fill -= 2; + index += 2; #ifdef DISPLAY_DETECTED_UNICODE - cerr << "UTF-16LE BOM found" << endl; + cerr << "UTF-16LE BOM found" << endl; #endif - return utf16le; - } - if ((fill == 4) && - (buffer[0] == 0x00) && - (buffer[1] == 0x00) && - (buffer[2] == 0xfe) && - (buffer[3] == 0xff)) - { - fill = 0; - index = 0; + return utf16le; + } + if ((fill == 4) && + (buffer[0] == 0x00) && + (buffer[1] == 0x00) && + (buffer[2] == 0xfe) && + (buffer[3] == 0xff)) + { + fill = 0; + index = 0; #ifdef DISPLAY_DETECTED_UNICODE - cerr << "UTF-32BE BOM found" << endl; + cerr << "UTF-32BE BOM found" << endl; #endif - return utf32be; - } - return utf8; // no valid bom so use utf8 as default - } - int getByte(unsigned char &c) - { - if (fill) - { - index %= 4; - --fill; - c = buffer[index++]; - return 1; - } else - { - inputfile.read(reinterpret_cast(&c),1); - return inputfile.gcount(); - } - } - int getWord(unsigned short &w) - { - unsigned char c[2]; - if (!getByte(c[0])) - return 0; - if (!getByte(c[1])) - return 1; - if (encoding == utf16le) - w = c[0] | (c[1] << 8); - else - w = c[1] | (c[0] << 8); - return 2; - } - int getDWord(wchar_t &d) - { - unsigned char c[4]; - for (int i=0;i<4;i++) - if (!getByte(c[i])) - return i; - if (encoding == utf32le) - d = c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24); - else - d = c[3] | (c[2] << 8) | (c[1] << 16) | (c[0] << 24); - return 4; - } - wchar_t get_wchar_t() - { - wchar_t ret = (wchar_t)-1; - switch (encoding) - { - case detect: // if still unknwon - encoding = utf8; // assume utf8 as default - case utf8: - unsigned char c, tmp; - if (!getByte(tmp)) - return ret; - // table for 64 bytes (all 11xxxxxx resp. >=192) - // resulting byte is determined: - // lower 3 bits: number of following bytes (max.8) 0=error - // upper 5 bits: data filled with 0 - if (tmp & 0x80) - { - if ((tmp & 0xc0) != 0xc0) - { - cerr << "UTF-8 Error: invalid data byte" << endl; - return ret; - } - unsigned char i = utf8table[tmp & 0x3f]; - ret = i >> 3; - i &= 7; - while (i--) - { - ret <<= 6; - if (!getByte(c)) - return wchar_t(-1); - ret |= c & 0x3f; - } - return ret; - } - else - return wchar_t(tmp); - case utf16le: - case utf16be: - unsigned short w,w2; - if (getWord(w) != 2) - return ret; - if ((w & 0xfc00) == 0xd800) // high surrogate first - { - if (getWord(w2) != 2) - return ret; - if ((w2 & 0xfc00) != 0xdc00) - { - cerr << "UTF-16 Error: invalid low surrogate" << endl; - return ret; - } - return (((w & 0x3ff) + 0x40) << 10) | (w2 & 0x3ff); - } - return w; - case utf32le: - case utf32be: - if (getDWord(ret) != 4) - return wchar_t (-1); - return ret; - } - return ret; - } - void convert2utf16le() - { - wchar_t c; - unsigned char buffer[2] = {0xff, 0xfe}; - outputfile.write(reinterpret_cast(&buffer),2); // write BOM - c = get_wchar_t(); - while (!inputfile.eof()) - { - buffer[0] = c & 0xff; - buffer[1] = (c >> 8) & 0xff; // create utf16-le char - outputfile.write(reinterpret_cast(&buffer),2); // write char - c = get_wchar_t(); - } - } - ~utf_converter() - { - if (inputfile) - inputfile.close(); - if (outputfile) - outputfile.close(); - } + return utf32be; + } + return utf8; // no valid bom so use utf8 as default + } + int getByte(unsigned char &c) + { + if (fill) + { + index %= 4; + --fill; + c = buffer[index++]; + return 1; + } else + { + inputfile.read(reinterpret_cast(&c),1); + return inputfile.gcount(); + } + } + int getWord(unsigned short &w) + { + unsigned char c[2]; + if (!getByte(c[0])) + return 0; + if (!getByte(c[1])) + return 1; + if (encoding == utf16le) + w = c[0] | (c[1] << 8); + else + w = c[1] | (c[0] << 8); + return 2; + } + int getDWord(wchar_t &d) + { + unsigned char c[4]; + for (int i=0;i<4;i++) + if (!getByte(c[i])) + return i; + if (encoding == utf32le) + d = c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24); + else + d = c[3] | (c[2] << 8) | (c[1] << 16) | (c[0] << 24); + return 4; + } + wchar_t get_wchar_t() + { + wchar_t ret = (wchar_t)-1; + switch (encoding) + { + case detect: // if still unknwon + encoding = utf8; // assume utf8 as default + case utf8: + unsigned char c, tmp; + if (!getByte(tmp)) + return ret; + // table for 64 bytes (all 11xxxxxx resp. >=192) + // resulting byte is determined: + // lower 3 bits: number of following bytes (max.8) 0=error + // upper 5 bits: data filled with 0 + if (tmp & 0x80) + { + if ((tmp & 0xc0) != 0xc0) + { + cerr << "UTF-8 Error: invalid data byte" << endl; + return ret; + } + unsigned char i = utf8table[tmp & 0x3f]; + ret = i >> 3; + i &= 7; + while (i--) + { + ret <<= 6; + if (!getByte(c)) + return wchar_t(-1); + ret |= c & 0x3f; + } + return ret; + } + else + return wchar_t(tmp); + case utf16le: + case utf16be: + unsigned short w,w2; + if (getWord(w) != 2) + return ret; + if ((w & 0xfc00) == 0xd800) // high surrogate first + { + if (getWord(w2) != 2) + return ret; + if ((w2 & 0xfc00) != 0xdc00) + { + cerr << "UTF-16 Error: invalid low surrogate" << endl; + return ret; + } + return (((w & 0x3ff) + 0x40) << 10) | (w2 & 0x3ff); + } + return w; + case utf32le: + case utf32be: + if (getDWord(ret) != 4) + return wchar_t (-1); + return ret; + } + return ret; + } + void convert2utf16le() + { + wchar_t c; + unsigned char buffer[2] = {0xff, 0xfe}; + outputfile.write(reinterpret_cast(&buffer),2); // write BOM + c = get_wchar_t(); + while (!inputfile.eof()) + { + buffer[0] = c & 0xff; + buffer[1] = (c >> 8) & 0xff; // create utf16-le char + outputfile.write(reinterpret_cast(&buffer),2); // write char + c = get_wchar_t(); + } + } + ~utf_converter() + { + if (inputfile) + inputfile.close(); + if (outputfile) + outputfile.close(); + } }; const unsigned char utf_converter::utf8table[64] = { 1, 9, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 97, 105, 113, 121, 129, 137, 145, 153, 161, 169, 177, 185, 193, 201, 209, 217, 225, 233, 241, 249, 2, 10, 18, 26, 34, 42, 50, 58, 66, 74, 82, 90, 98, 106, 114, 122, -3, 11, 19, 27, 35, 43, 51, 59, 4, 12, 20, 28, 5, 13, 6, 7 +3, 11, 19, 27, 35, 43, 51, 59, 4, 12, 20, 28, 5, 13, 6, 7 }; int main(int argc, char* argv[]) { - utf_converter::err_types err; - if (argc < 3) - { - cout << "usage: " << argv[0] << " inputfile outputfile" << endl; - return -1; - } - utf_converter conv(argv[1],argv[2]); - if ((err = conv.getError())!=utf_converter::none) - { - switch (err) - { - case utf_converter::iopen: - cerr << "Couldn't open input file." << endl; - break; - case utf_converter::oopen: - cerr << "Couldn't open output file." << endl; - break; - default: - cerr << "Unknown error." << endl; - } - return -1; - } else - conv.convert2utf16le(); - return 0; + utf_converter::err_types err; + if (argc < 3) + { + cout << "usage: " << argv[0] << " inputfile outputfile" << endl; + return -1; + } + utf_converter conv(argv[1],argv[2]); + if ((err = conv.getError())!=utf_converter::none) + { + switch (err) + { + case utf_converter::iopen: + cerr << "Couldn't open input file." << endl; + break; + case utf_converter::oopen: + cerr << "Couldn't open output file." << endl; + break; + default: + cerr << "Unknown error." << endl; + } + return -1; + } else + conv.convert2utf16le(); + return 0; } - -// vim:set ts=4 sw=4: