-/* Win32 services routines */ \r
- \r
-/* Author: Nick Gammon */ \r
- \r
-#ifdef WIN32\r
- \r
-#include "copyrite.h"\r
-#include "config.h"\r
- \r
-#include <windows.h> /* for find first */\r
- \r
-#include <stdlib.h>\r
-#include <process.h>\r
-#include <direct.h>\r
- \r
-#include "conf.h"\r
-#include "mushdb.h"\r
-#include "match.h"\r
-#include "externs.h"\r
-#include "mymalloc.h"\r
-#include "log.h"\r
-#include "confmagic.h"\r
- \r
-/* This is bad, but only for WIN32, which is bad anyway... */ \r
-#define EMBEDDED_MKINDX\r
-\rstatic char buff[1024];
-\r\rBOOL \r ConcatenateFiles(const char *path, const char *outputfile) \r
+/* Win32 services routines */
+
+/* Author: Nick Gammon */
+
+#ifdef WIN32
+
+#include "copyrite.h"
+#include "config.h"
+
+#include <windows.h> /* for find first */
+
+#include <stdlib.h>
+#include <process.h>
+#include <direct.h>
+
+#include "conf.h"
+#include "mushdb.h"
+#include "match.h"
+#include "externs.h"
+#include "mymalloc.h"
+#include "log.h"
+#include "confmagic.h"
+
+extern char confname[BUFFER_LEN]; /* From bsd.c */
+
+/* This is bad, but only for WIN32, which is bad anyway... */
+#define EMBEDDED_MKINDX
+static char buff[1024];
+BOOL ConcatenateFiles(const char *path, const char *outputfile)
{
- \rHANDLE filscan;
- \rWIN32_FIND_DATA fildata;
- \rBOOL filflag;
- \rDWORD status;
- \rFILE * fo = NULL;
- \rFILE * f = NULL;
- \rsize_t bytes_in, bytes_out;
- \rlong total_bytes = 0;
- \rint total_files = 0;
- \rchar directory[MAX_PATH];
- \rchar fullname[MAX_PATH];
- \r\rchar *p;
- \r\r
- /* If outputfile is an empty string, forget it. */ \r
+ HANDLE filscan;
+ WIN32_FIND_DATA fildata;
+ BOOL filflag;
+ DWORD status;
+ FILE * fo = NULL;
+ FILE * f = NULL;
+ size_t bytes_in, bytes_out;
+ long total_bytes = 0;
+ int total_files = 0;
+ char directory[MAX_PATH];
+ char fullname[MAX_PATH];
+ char *p;
+
+ /* If outputfile is an empty string, forget it. */
if (!outputfile || !*outputfile)
- \rreturn FALSE;
- \r\r
-/* extract the directory from the path name */ \r
- \rstrcpy(directory, path);
- \rp = strrchr(directory, '\\');
- \rif (p)
- \rp[1] = 0;
- \r
+ return FALSE;
+
+/* extract the directory from the path name */
+ strcpy(directory, path);
+ p = strrchr(directory, '\\');
+ if (p)
+ p[1] = 0;
+
else {
- \rp = strrchr(directory, '/');
- \rif (p)
- \rp[1] = 0;
- \r}
- \r\r
-/* Open output file */ \r
- \rfo = fopen(outputfile, "wb");
- \r\rif (!fo) {
- \rdo_rawlog(LT_ERR, T("Unable to open file: %s"), outputfile);
- \rreturn FALSE;
- \r}
- \rdo_rawlog(LT_ERR, T("Creating file: %s"), outputfile);
- \r\r
-/* Find first file matching the wildcard */ \r
- \rfilscan = FindFirstFile(path, &fildata);
- \rif (filscan == INVALID_HANDLE_VALUE) {
- \rstatus = GetLastError();
- \r\rfclose(fo);
- \r\rdo_rawlog(LT_ERR, "**** No files matching: \"%s\" found.", path);
- \r\rif (status == ERROR_NO_MORE_FILES)
- \rreturn TRUE;
- \r
+ p = strrchr(directory, '/');
+ if (p)
+ p[1] = 0;
+ }
+
+/* Open output file */
+ fo = fopen(outputfile, "wb");
+ if (!fo) {
+ do_rawlog(LT_ERR, T("Unable to open file: %s"), outputfile);
+ return FALSE;
+ }
+ do_rawlog(LT_ERR, T("Creating file: %s"), outputfile);
+
+/* Find first file matching the wildcard */
+ filscan = FindFirstFile(path, &fildata);
+ if (filscan == INVALID_HANDLE_VALUE) {
+ status = GetLastError();
+ fclose(fo);
+ do_rawlog(LT_ERR, "**** No files matching: \"%s\" found.", path);
+ if (status == ERROR_NO_MORE_FILES)
+ return TRUE;
+
else
- \rreturn FALSE;
- \r}
- \r
-/*\r
- Now enter the concatenation loop.\r
- */ \r
- \r
+ return FALSE;
+ }
+
+/*
+ Now enter the concatenation loop.
+ */
+
do {
- \rif (!(fildata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
- \r\rdo_rawlog(LT_ERR, "%s: %s, %ld %s", \rT(" Copying file"),
- \rfildata.cFileName, \rfildata.nFileSizeLow,
- \rfildata.nFileSizeLow == 1 ? T("byte") : T("bytes"));
- \r\rstrcpy(fullname, directory);
- \rstrcat(fullname, fildata.cFileName);
- \r\r
-/* Open the input file */ \r
- \rf = fopen(fullname, "rb");
- \r\rif (!f)
- \rdo_rawlog(LT_ERR, T(" ** Unable to open file: %s"), fullname);
- \r
+ if (!(fildata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
+ do_rawlog(LT_ERR, "%s: %s, %ld %s", T(" Copying file"),
+ fildata.cFileName, fildata.nFileSizeLow,
+ fildata.nFileSizeLow == 1 ? T("byte") : T("bytes"));
+ strcpy(fullname, directory);
+ strcat(fullname, fildata.cFileName);
+
+/* Open the input file */
+ f = fopen(fullname, "rb");
+ if (!f)
+ do_rawlog(LT_ERR, T(" ** Unable to open file: %s"), fullname);
+
else {
- \r\rtotal_files++;
- \r\r
- /* do the copy loop */ \r
- \rwhile (!feof(f)) {
- \rbytes_in = fread(buff, 1, sizeof(buff), f);
- \rif (bytes_in <= 0)
- \rbreak;
- \r\rbytes_out = fwrite(buff, 1, bytes_in, fo);
- \rtotal_bytes += bytes_out;
- \rif (bytes_in != bytes_out) {
- \rdo_rawlog(LT_ERR, T("Unable to write to file: %s"), outputfile);
- \rfclose(f);
- \rbreak;
- \r}
- \r} /* end of copy loop */
- \r\r\rfclose(f);
- \r} /* end of being able to open file */
- \r\r}
- \r
- /* end of not being a directory */ \r
- /* get next file matching the wildcard */ \r
+ total_files++;
+
+ /* do the copy loop */
+ while (!feof(f)) {
+ bytes_in = fread(buff, 1, sizeof(buff), f);
+ if (bytes_in <= 0)
+ break;
+ bytes_out = fwrite(buff, 1, bytes_in, fo);
+ total_bytes += bytes_out;
+ if (bytes_in != bytes_out) {
+ do_rawlog(LT_ERR, T("Unable to write to file: %s"), outputfile);
+ fclose(f);
+ break;
+ }
+ } /* end of copy loop */
+ fclose(f);
+ } /* end of being able to open file */
+ }
+
+ /* end of not being a directory */
+ /* get next file matching the wildcard */
filflag = FindNextFile(filscan, &fildata);
- \r} while (filflag);
- \r\rstatus = GetLastError();
- \r\rFindClose(filscan);
- \r\rfclose(fo);
- \r\rdo_rawlog(LT_ERR, T("Copied %i %s, %ld %s"), \rtotal_files,
- \rtotal_files == 1 ? T("file") : T("files"), \rtotal_bytes,
+ } while (filflag);
+ status = GetLastError();
+ FindClose(filscan);
+ fclose(fo);
+ do_rawlog(LT_ERR, T("Copied %i %s, %ld %s"), total_files,
+ total_files == 1 ? T("file") : T("files"), total_bytes,
total_bytes == 1 ? T("byte") : T("bytes"));
- \r\rif (status == ERROR_NO_MORE_FILES)
- \rreturn TRUE;
- \r
+ if (status == ERROR_NO_MORE_FILES)
+ return TRUE;
+
else
- \rreturn FALSE;
-\r\r}
-\r\rint \r
-CheckDatabase(const char *path, FILETIME * modified, long *filesize) \r
+ return FALSE;
+}
+int
+CheckDatabase(const char *path, FILETIME * modified, long *filesize)
{
- \rHANDLE filscan;
- \rWIN32_FIND_DATA fildata;
- \rSYSTEMTIME st;
- \rstatic char *months[] =
- { \r">!<", \r"Jan", "Feb", "Mar", "Apr", "May", "Jun", \r"Jul", "Aug", "Sep",
- "Oct", "Nov", "Dec" \r
+ HANDLE filscan;
+ WIN32_FIND_DATA fildata;
+ SYSTEMTIME st;
+ static char *months[] =
+ { ">!<", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
+ "Oct", "Nov", "Dec"
};
- \rFILE * f;
- \rsize_t bytes;
- \r\rfilscan = FindFirstFile(path, &fildata);
- \rif (filscan == INVALID_HANDLE_VALUE) {
- \rdo_rawlog(LT_ERR, "File \"%s\" not found.", path);
- \rreturn FALSE;
- \r}
- \r*modified = fildata.ftLastWriteTime;
- \r*filesize = fildata.nFileSizeLow;
- \r\rFindClose(filscan);
- \r\rFileTimeToSystemTime(&fildata.ftLastWriteTime, &st);
- \r\rif (st.wMonth < 1 || st.wMonth > 12)
- \rst.wMonth = 0;
- \r\rdo_rawlog(LT_ERR, \rT \r
+ FILE * f;
+ size_t bytes;
+ filscan = FindFirstFile(path, &fildata);
+ if (filscan == INVALID_HANDLE_VALUE) {
+ do_rawlog(LT_ERR, "File \"%s\" not found.", path);
+ return FALSE;
+ }
+ *modified = fildata.ftLastWriteTime;
+ *filesize = fildata.nFileSizeLow;
+ FindClose(filscan);
+ FileTimeToSystemTime(&fildata.ftLastWriteTime, &st);
+ if (st.wMonth < 1 || st.wMonth > 12)
+ st.wMonth = 0;
+ do_rawlog(LT_ERR, T
("File \"%s\" found, size %ld %s, modified on %02d %s %04d %02d:%02d:%02d"),
- \rpath, fildata.nFileSizeLow,
- \rfildata.nFileSizeLow == 1 ? T("byte") : T("bytes"), st.wDay,
- \rmonths[st.wMonth], st.wYear, st.wHour, st.wMinute, st.wSecond);
- \r\rif (fildata.nFileSizeHigh == 0 && fildata.nFileSizeLow < 80) {
- \rdo_rawlog(LT_ERR, T("File is too small to be a MUSH database."));
- \rreturn FALSE;
- \r}
- \r
-/* check file for validity */ \r
- \rf = fopen(path, "rb");
- \r\rif (!f) {
- \rdo_rawlog(LT_ERR, T("Unable to open file %s"), path);
- \rreturn FALSE;
- \r}
- \rif (fseek(f, -80, SEEK_END) != 0) {
- \rdo_rawlog(LT_ERR, T("Unable to check file %s"), path);
- \rfclose(f);
- \rreturn FALSE;
- \r}
- \rbytes = fread(buff, 1, 80, f);
- \r\rfclose(f);
- \r\rif (bytes != 80) {
- \rdo_rawlog(LT_ERR, T("Unable to read last part of file %s"), path);
- \rreturn FALSE;
- \r}
- \rif (strstr(buff, "***END OF DUMP***") == 0) {
- \rdo_rawlog(LT_ERR, T("Database not terminated correctly, file %s"), path);
- \rreturn FALSE;
- \r}
- \rreturn TRUE;
-\r\r} /* end of CheckDatabase */
-\r\rvoid \r
-Win32MUSH_setup(void) \r
+ path, fildata.nFileSizeLow,
+ fildata.nFileSizeLow == 1 ? T("byte") : T("bytes"), st.wDay,
+ months[st.wMonth], st.wYear, st.wHour, st.wMinute, st.wSecond);
+ if (fildata.nFileSizeHigh == 0 && fildata.nFileSizeLow < 80) {
+ do_rawlog(LT_ERR, T("File is too small to be a MUSH database."));
+ return FALSE;
+ }
+
+/* check file for validity */
+ f = fopen(path, "rb");
+ if (!f) {
+ do_rawlog(LT_ERR, T("Unable to open file %s"), path);
+ return FALSE;
+ }
+ if (fseek(f, -80, SEEK_END) != 0) {
+ do_rawlog(LT_ERR, T("Unable to check file %s"), path);
+ fclose(f);
+ return FALSE;
+ }
+ bytes = fread(buff, 1, 80, f);
+ fclose(f);
+ if (bytes != 80) {
+ do_rawlog(LT_ERR, T("Unable to read last part of file %s"), path);
+ return FALSE;
+ }
+ if (strstr(buff, "***END OF DUMP***") == 0) {
+ do_rawlog(LT_ERR, T("Database not terminated correctly, file %s"), path);
+ return FALSE;
+ }
+ return TRUE;
+} /* end of CheckDatabase */
+void
+Win32MUSH_setup(void)
{
- \r\rint indb_OK, outdb_OK, panicdb_OK;
- \r\rFILETIME indb_time, outdb_time, panicdb_time;
- \r\rlong indb_size, outdb_size, panicdb_size;
- \r\r
-#ifndef _DEBUG\r
- \r\rchar FileName[256];
- \rif (GetModuleFileName(NULL, FileName, 256) != 0) {
- \rif (!strcasecmp(rindex(FileName, '\\') + 1, "pennmush.exe")) {
- \rif (CopyFile("pennmush.exe", "pennmush_run.exe", FALSE)) {
- \rdo_rawlog(LT_ERR, "Successfully copied executable, starting copy.");
- \rexecl("pennmush_run.exe", "pennmush_run.exe", "/run", NULL);
- \r}
- \r}
- \r}
- \r\r
-#endif /* \r */
- \rConcatenateFiles("txt\\hlp\\*.hlp", "txt\\help.txt");
- \rConcatenateFiles("txt\\nws\\*.nws", "txt\\news.txt");
- \rConcatenateFiles("txt\\evt\\*.evt", "txt\\events.txt");
- \rConcatenateFiles("txt\\rul\\*.rul", "txt\\rules.txt");
- \rConcatenateFiles("txt\\idx\\*.idx", "txt\\index.txt");
- \r\rindb_OK = CheckDatabase(options.input_db, &indb_time, &indb_size);
- \routdb_OK = CheckDatabase(options.output_db, &outdb_time, &outdb_size);
- \rpanicdb_OK = CheckDatabase(options.crash_db, &panicdb_time, &panicdb_size);
- \r\rif (indb_OK) { /* Look at outdb */
- \rif (outdb_OK) { /* Look at panicdb */
- \rif (panicdb_OK) { /* outdb or panicdb or indb */
- \rif (CompareFileTime(&panicdb_time, &outdb_time) > 0) { /* panicdb or indb */
- \r\rif (CompareFileTime(&panicdb_time, &indb_time) > 0) { /* panicdb */
- \r\rConcatenateFiles(options.crash_db, options.input_db);
- \r} else { /* indb */
- \r}
- \r} else { /* outdb or indb */
- \rif (CompareFileTime(&outdb_time, &indb_time) > 0) { /* outdb */
- \r\rConcatenateFiles(options.output_db, options.input_db);
- \r} else { /* indb */
- \r}
- \r}
- \r} else { /* outdb or indb */
- \rif (CompareFileTime(&outdb_time, &indb_time) > 0) { /* outdb */
- \r\rConcatenateFiles(options.output_db, options.input_db);
- \r} else { /* indb */
- \r}
- \r}
- \r} else { /* outdb not OK */
- \rif (panicdb_OK) { /* panicdb or indb */
- \rif (CompareFileTime(&panicdb_time, &indb_time) > 0) { /* panicdb */
- \r\rConcatenateFiles(options.crash_db, options.input_db);
- \r} else { /* indb */
- \r}
- \r} else { /* indb */
- \r}
- \r}
- \r} else { /* indb not OK */
- \rif (outdb_OK) { /* look at panicdb */
- \rif (panicdb_OK) { /* out or panic */
- \rif (CompareFileTime(&panicdb_time, &outdb_time) > 0) { /* panicdb */
- \r\rConcatenateFiles(options.crash_db, options.input_db);
- \r} else { /* outdb */
- \r\rConcatenateFiles(options.output_db, options.input_db);
- \r}
- \r} else { /* outdb */
- \rConcatenateFiles(options.output_db, options.input_db);
- \r}
- \r} else { /* outdb not OK */
- \rif (panicdb_OK) { /* panicdb */
- \rConcatenateFiles(options.crash_db, options.input_db);
- \r} else { /* NOTHING */
- \rreturn;
- \r}
- \r}
- \r}
- \r
-/* Final failsafe - input database SHOULD still be OK. */ \r
+ int indb_OK, outdb_OK, panicdb_OK;
+ FILETIME indb_time, outdb_time, panicdb_time;
+ long indb_size, outdb_size, panicdb_size;
+
+#ifndef _DEBUG
+ char FileName[256];
+ if (GetModuleFileName(NULL, FileName, 256) != 0) {
+ if (!strcasecmp(rindex(FileName, '\\') + 1, "pennmush.exe")) {
+ if (CopyFile("pennmush.exe", "pennmush_run.exe", FALSE)) {
+ do_rawlog(LT_ERR, "Successfully copied executable, starting copy.");
+#ifdef WIN32SERVICES
+ execl("pennmush_run.exe", "pennmush_run.exe", "/run", NULL);
+#else
+ execl("pennmush_run.exe", "pennmush_run.exe", confname, NULL);
+#endif
+ }
+ }
+ }
+
+#endif /* */
+ ConcatenateFiles("txt\\hlp\\*.hlp", "txt\\help.txt");
+ ConcatenateFiles("txt\\nws\\*.nws", "txt\\news.txt");
+ ConcatenateFiles("txt\\evt\\*.evt", "txt\\events.txt");
+ ConcatenateFiles("txt\\rul\\*.rul", "txt\\rules.txt");
+ ConcatenateFiles("txt\\idx\\*.idx", "txt\\index.txt");
+ indb_OK = CheckDatabase(options.input_db, &indb_time, &indb_size);
+ outdb_OK = CheckDatabase(options.output_db, &outdb_time, &outdb_size);
+ panicdb_OK = CheckDatabase(options.crash_db, &panicdb_time, &panicdb_size);
+ if (indb_OK) { /* Look at outdb */
+ if (outdb_OK) { /* Look at panicdb */
+ if (panicdb_OK) { /* outdb or panicdb or indb */
+ if (CompareFileTime(&panicdb_time, &outdb_time) > 0) { /* panicdb or indb */
+ if (CompareFileTime(&panicdb_time, &indb_time) > 0) { /* panicdb */
+ ConcatenateFiles(options.crash_db, options.input_db);
+ } else { /* indb */
+ }
+ } else { /* outdb or indb */
+ if (CompareFileTime(&outdb_time, &indb_time) > 0) { /* outdb */
+ ConcatenateFiles(options.output_db, options.input_db);
+ } else { /* indb */
+ }
+ }
+ } else { /* outdb or indb */
+ if (CompareFileTime(&outdb_time, &indb_time) > 0) { /* outdb */
+ ConcatenateFiles(options.output_db, options.input_db);
+ } else { /* indb */
+ }
+ }
+ } else { /* outdb not OK */
+ if (panicdb_OK) { /* panicdb or indb */
+ if (CompareFileTime(&panicdb_time, &indb_time) > 0) { /* panicdb */
+ ConcatenateFiles(options.crash_db, options.input_db);
+ } else { /* indb */
+ }
+ } else { /* indb */
+ }
+ }
+ } else { /* indb not OK */
+ if (outdb_OK) { /* look at panicdb */
+ if (panicdb_OK) { /* out or panic */
+ if (CompareFileTime(&panicdb_time, &outdb_time) > 0) { /* panicdb */
+ ConcatenateFiles(options.crash_db, options.input_db);
+ } else { /* outdb */
+ ConcatenateFiles(options.output_db, options.input_db);
+ }
+ } else { /* outdb */
+ ConcatenateFiles(options.output_db, options.input_db);
+ }
+ } else { /* outdb not OK */
+ if (panicdb_OK) { /* panicdb */
+ ConcatenateFiles(options.crash_db, options.input_db);
+ } else { /* NOTHING */
+ return;
+ }
+ }
+ }
+
+/* Final failsafe - input database SHOULD still be OK. */
do_rawlog(LT_ERR, T("Verifying selected database."));
- \rif (!CheckDatabase(options.input_db, &indb_time, &indb_size)) {
- \rdo_rawlog(LT_ERR, T("File corrupted during selection process."));
- \rexit(-1);
- \r} else {
- \rdo_rawlog(LT_ERR, T("Input database verified. Proceeding to analysis."));
- \r}
-\r}
+ if (!CheckDatabase(options.input_db, &indb_time, &indb_size)) {
+ do_rawlog(LT_ERR, T("File corrupted during selection process."));
+ exit(-1);
+ } else {
+ do_rawlog(LT_ERR, T("Input database verified. Proceeding to analysis."));
+ }
+}
+
-\r
-#endif /* WIN32 */\r
+#endif /* WIN32 */