From efaaa4bb42dacdd23ca727fd3b7c283a868b5493 Mon Sep 17 00:00:00 2001 From: DarthArgus Date: Sat, 23 Jul 2016 18:00:40 -0700 Subject: [PATCH] readd some win32 files so that we can more easily run static analyzers that are windows only against the source --- .../application/Miff/src/win32/BISON.HAI | 334 ++++++ .../Miff/src/win32/InputFileHandler.cpp | 136 +++ .../Miff/src/win32/InputFileHandler.h | 71 ++ .../Miff/src/win32/OutputFileHandler.cpp | 164 +++ .../Miff/src/win32/OutputFileHandler.h | 80 ++ .../application/Miff/src/win32/bison.simple | 698 ++++++++++++ .../application/Miff/src/win32/mIFF.dox | 62 + .../application/Miff/src/win32/miff.cpp | 961 ++++++++++++++++ .../application/Miff/src/win32/parser.lex | 517 +++++++++ .../application/Miff/src/win32/parser.yac | 1004 +++++++++++++++++ .../src/win32/FirstCentralServer.cpp | 5 + .../CentralServer/src/win32/WinMain.cpp | 84 ++ .../ChatServer/src/win32/WinMain.cpp | 42 + .../src/win32/FirstConnectionServer.cpp | 1 + .../ConnectionServer/src/win32/WinMain.cpp | 58 + .../src/win32/LoggingServerApiWrapper.cpp | 16 + .../LogServer/src/win32/WinMain.cpp | 55 + .../src/win32/FirstLoginServer.cpp | 1 + .../LoginServer/src/win32/WinMain.cpp | 46 + .../MetricsServer/src/win32/WinMain.cpp | 91 ++ .../src/win32/FirstPlanetServer.cpp | 8 + .../PlanetServer/src/win32/WinMain.cpp | 67 ++ .../ServerConsole/src/win32/main.cpp | 59 + .../TaskManager/src/win32/ConsoleInput.cpp | 22 + .../src/win32/EnvironmentVariable.cpp | 33 + .../TaskManager/src/win32/ProcessSpawner.cpp | 153 +++ .../src/win32/TaskManagerSysInfo.cpp | 147 +++ .../TaskManager/src/win32/WinMain.cpp | 50 + 28 files changed, 4965 insertions(+) create mode 100644 engine/client/application/Miff/src/win32/BISON.HAI create mode 100644 engine/client/application/Miff/src/win32/InputFileHandler.cpp create mode 100644 engine/client/application/Miff/src/win32/InputFileHandler.h create mode 100644 engine/client/application/Miff/src/win32/OutputFileHandler.cpp create mode 100644 engine/client/application/Miff/src/win32/OutputFileHandler.h create mode 100644 engine/client/application/Miff/src/win32/bison.simple create mode 100644 engine/client/application/Miff/src/win32/mIFF.dox create mode 100644 engine/client/application/Miff/src/win32/miff.cpp create mode 100644 engine/client/application/Miff/src/win32/parser.lex create mode 100644 engine/client/application/Miff/src/win32/parser.yac create mode 100644 engine/server/application/CentralServer/src/win32/FirstCentralServer.cpp create mode 100644 engine/server/application/CentralServer/src/win32/WinMain.cpp create mode 100644 engine/server/application/ChatServer/src/win32/WinMain.cpp create mode 100644 engine/server/application/ConnectionServer/src/win32/FirstConnectionServer.cpp create mode 100644 engine/server/application/ConnectionServer/src/win32/WinMain.cpp create mode 100644 engine/server/application/LogServer/src/win32/LoggingServerApiWrapper.cpp create mode 100644 engine/server/application/LogServer/src/win32/WinMain.cpp create mode 100644 engine/server/application/LoginServer/src/win32/FirstLoginServer.cpp create mode 100644 engine/server/application/LoginServer/src/win32/WinMain.cpp create mode 100644 engine/server/application/MetricsServer/src/win32/WinMain.cpp create mode 100644 engine/server/application/PlanetServer/src/win32/FirstPlanetServer.cpp create mode 100644 engine/server/application/PlanetServer/src/win32/WinMain.cpp create mode 100644 engine/server/application/ServerConsole/src/win32/main.cpp create mode 100644 engine/server/application/TaskManager/src/win32/ConsoleInput.cpp create mode 100644 engine/server/application/TaskManager/src/win32/EnvironmentVariable.cpp create mode 100644 engine/server/application/TaskManager/src/win32/ProcessSpawner.cpp create mode 100644 engine/server/application/TaskManager/src/win32/TaskManagerSysInfo.cpp create mode 100644 engine/server/application/TaskManager/src/win32/WinMain.cpp diff --git a/engine/client/application/Miff/src/win32/BISON.HAI b/engine/client/application/Miff/src/win32/BISON.HAI new file mode 100644 index 00000000..999b5559 --- /dev/null +++ b/engine/client/application/Miff/src/win32/BISON.HAI @@ -0,0 +1,334 @@ + +extern int timeclock; + + +int yyerror; /* Yyerror and yycost are set by guards. */ +int yycost; /* If yyerror is set to a nonzero value by a */ + /* guard, the reduction with which the guard */ + /* is associated is not performed, and the */ + /* error recovery mechanism is invoked. */ + /* Yycost indicates the cost of performing */ + /* the reduction given the attributes of the */ + /* symbols. */ + + +/* YYMAXDEPTH indicates the size of the parser's state and value */ +/* stacks. */ + +#ifndef YYMAXDEPTH +#define YYMAXDEPTH 500 +#endif + +/* YYMAXRULES must be at least as large as the number of rules that */ +/* could be placed in the rule queue. That number could be determined */ +/* from the grammar and the size of the stack, but, as yet, it is not. */ + +#ifndef YYMAXRULES +#define YYMAXRULES 100 +#endif + +#ifndef YYMAXBACKUP +#define YYMAXBACKUP 100 +#endif + + +short yyss[YYMAXDEPTH]; /* the state stack */ +YYSTYPE yyvs[YYMAXDEPTH]; /* the semantic value stack */ +YYLTYPE yyls[YYMAXDEPTH]; /* the location stack */ +short yyrq[YYMAXRULES]; /* the rule queue */ +int yychar; /* the lookahead symbol */ + +YYSTYPE yylval; /* the semantic value of the */ + /* lookahead symbol */ + +YYSTYPE yytval; /* the semantic value for the state */ + /* at the top of the state stack. */ + +YYSTYPE yyval; /* the variable used to return */ + /* semantic values from the action */ + /* routines */ + +YYLTYPE yylloc; /* location data for the lookahead */ + /* symbol */ + +YYLTYPE yytloc; /* location data for the state at the */ + /* top of the state stack */ + + +int yynunlexed; +short yyunchar[YYMAXBACKUP]; +YYSTYPE yyunval[YYMAXBACKUP]; +YYLTYPE yyunloc[YYMAXBACKUP]; + +short *yygssp; /* a pointer to the top of the state */ + /* stack; only set during error */ + /* recovery. */ + +YYSTYPE *yygvsp; /* a pointer to the top of the value */ + /* stack; only set during error */ + /* recovery. */ + +YYLTYPE *yyglsp; /* a pointer to the top of the */ + /* location stack; only set during */ + /* error recovery. */ + + +/* Yyget is an interface between the parser and the lexical analyzer. */ +/* It is costly to provide such an interface, but it avoids requiring */ +/* the lexical analyzer to be able to back up the scan. */ + +yyget() +{ + if (yynunlexed > 0) + { + yynunlexed--; + yychar = yyunchar[yynunlexed]; + yylval = yyunval[yynunlexed]; + yylloc = yyunloc[yynunlexed]; + } + else if (yychar <= 0) + yychar = 0; + else + { + yychar = yylex(); + if (yychar < 0) + yychar = 0; + else yychar = YYTRANSLATE(yychar); + } +} + + + +yyunlex(chr, val, loc) +int chr; +YYSTYPE val; +YYLTYPE loc; +{ + yyunchar[yynunlexed] = chr; + yyunval[yynunlexed] = val; + yyunloc[yynunlexed] = loc; + yynunlexed++; +} + + + +yyrestore(first, last) +register short *first; +register short *last; +{ + register short *ssp; + register short *rp; + register int symbol; + register int state; + register int tvalsaved; + + ssp = yygssp; + yyunlex(yychar, yylval, yylloc); + + tvalsaved = 0; + while (first != last) + { + symbol = yystos[*ssp]; + if (symbol < YYNTBASE) + { + yyunlex(symbol, yytval, yytloc); + tvalsaved = 1; + ssp--; + } + + ssp--; + + if (first == yyrq) + first = yyrq + YYMAXRULES; + + first--; + + for (rp = yyrhs + yyprhs[*first]; symbol = *rp; rp++) + { + if (symbol < YYNTBASE) + state = yytable[yypact[*ssp] + symbol]; + else + { + state = yypgoto[symbol - YYNTBASE] + *ssp; + + if (state >= 0 && state <= YYLAST && yycheck[state] == *ssp) + state = yytable[state]; + else + state = yydefgoto[symbol - YYNTBASE]; + } + + *++ssp = state; + } + } + + if ( ! tvalsaved && ssp > yyss) + { + yyunlex(yystos[*ssp], yytval, yytloc); + ssp--; + } + + yygssp = ssp; +} + + + +int +yyparse() +{ + register int yystate; + register int yyn; + register short *yyssp; + register short *yyrq0; + register short *yyptr; + register YYSTYPE *yyvsp; + + int yylen; + YYLTYPE *yylsp; + short *yyrq1; + short *yyrq2; + + yystate = 0; + yyssp = yyss - 1; + yyvsp = yyvs - 1; + yylsp = yyls - 1; + yyrq0 = yyrq; + yyrq1 = yyrq0; + yyrq2 = yyrq0; + + yychar = yylex(); + if (yychar < 0) + yychar = 0; + else yychar = YYTRANSLATE(yychar); + +yynewstate: + + if (yyssp >= yyss + YYMAXDEPTH - 1) + { + yyabort("Parser Stack Overflow"); + YYABORT; + } + + *++yyssp = yystate; + +yyresume: + + yyn = yypact[yystate]; + if (yyn == YYFLAG) + goto yydefault; + + yyn += yychar; + if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar) + goto yydefault; + + yyn = yytable[yyn]; + if (yyn < 0) + { + yyn = -yyn; + goto yyreduce; + } + else if (yyn == 0) + goto yyerrlab; + + yystate = yyn; + + yyptr = yyrq2; + while (yyptr != yyrq1) + { + yyn = *yyptr++; + yylen = yyr2[yyn]; + yyvsp -= yylen; + yylsp -= yylen; + + yyguard(yyn, yyvsp, yylsp); + if (yyerror) + goto yysemerr; + + yyaction(yyn, yyvsp, yylsp); + *++yyvsp = yyval; + + yylsp++; + if (yylen == 0) + { + yylsp->timestamp = timeclock; + yylsp->first_line = yytloc.first_line; + yylsp->first_column = yytloc.first_column; + yylsp->last_line = (yylsp-1)->last_line; + yylsp->last_column = (yylsp-1)->last_column; + yylsp->text = 0; + } + else + { + yylsp->last_line = (yylsp+yylen-1)->last_line; + yylsp->last_column = (yylsp+yylen-1)->last_column; + } + + if (yyptr == yyrq + YYMAXRULES) + yyptr = yyrq; + } + + if (yystate == YYFINAL) + YYACCEPT; + + yyrq2 = yyptr; + yyrq1 = yyrq0; + + *++yyvsp = yytval; + *++yylsp = yytloc; + yytval = yylval; + yytloc = yylloc; + yyget(); + + goto yynewstate; + +yydefault: + + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + +yyreduce: + + *yyrq0++ = yyn; + + if (yyrq0 == yyrq + YYMAXRULES) + yyrq0 = yyrq; + + if (yyrq0 == yyrq2) + { + yyabort("Parser Rule Queue Overflow"); + YYABORT; + } + + yyssp -= yyr2[yyn]; + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTBASE] + *yyssp; + if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTBASE]; + + goto yynewstate; + +yysemerr: + *--yyptr = yyn; + yyrq2 = yyptr; + yyvsp += yyr2[yyn]; + +yyerrlab: + + yygssp = yyssp; + yygvsp = yyvsp; + yyglsp = yylsp; + yyrestore(yyrq0, yyrq2); + yyrecover(); + yystate = *yygssp; + yyssp = yygssp; + yyvsp = yygvsp; + yyrq0 = yyrq; + yyrq1 = yyrq0; + yyrq2 = yyrq0; + goto yyresume; +} + +$ diff --git a/engine/client/application/Miff/src/win32/InputFileHandler.cpp b/engine/client/application/Miff/src/win32/InputFileHandler.cpp new file mode 100644 index 00000000..b782e0cf --- /dev/null +++ b/engine/client/application/Miff/src/win32/InputFileHandler.cpp @@ -0,0 +1,136 @@ +//=========================================================================== +// +// FILENAME: InputFileHandler.cpp [C:\Projects\new\tools\src\miff\src\] +// COPYRIGHT: (C) 1999 BY Bootprint Entertainment +// +// DESCRIPTION: file handler for input files (standard flat text files) +// AUTHOR: Hideki Ikeda +// DATE: 1/13/99 4:53:31 PM +// +// HISTORY: 1/13/99 [HAI] - File created +// : +// +// FUNCTION: InputFileHandler() constructor +// : ~InputFileHandler() destructor +// : +// +//=========================================================================== + +//========================================================== include files == +#include "sharedFoundation/FirstSharedFoundation.h" +#include "InputFileHandler.h" + +#include "sharedFile/TreeFile.h" +//#include "sharedFile/Iff.h" + +//================================================= static vars assignment == + + + +//--------------------------------------------------------------------------- +// Constructor +// +// Remarks: +// +// +// See Also: +// +// +// Revisions and History: +// 1/13/99 [HAI] - created +// +InputFileHandler::InputFileHandler(const char *infilename) +{ + TreeFile::addSearchAbsolute(0); // search current working directory + + file = TreeFile::open(infilename, AbstractFile::PriorityData, true); + +} + + +//--------------------------------------------------------------------------- +// Destructor +// +// Remarks: +// +// +// See Also: +// +// +// Revisions and History: +// 1/13/99 [HAI] - created +// +InputFileHandler::~InputFileHandler(void) +{ + if(file) + delete file; +} + + +//--------------------------------------------------------------------------- +// reads a file stream into specified buffer of the size passed +// +// Return Value: +// actual size read (signed int) +// +// Remarks: +// +// +// See Also: +// Treefile::read() +// +// Revisions and History: +// 1/13/99 [HAI] - created +// +const int InputFileHandler::read( + void *sourceBuffer, // pointer to the buffer + int bufferSize // number of BYTES to be read + ) +{ + int retVal = -1; // assume fileHandle is NOT valid + + if (file) + retVal = file->read(sourceBuffer, bufferSize); + + return(retVal); +} + +//--------------------------------------------------------------------------- +// Deletes a file +// +// Return Value: +// whatever DeleteFile() returns +// if fileHandle != -1, it assumes that the fileHandle passed belonged to +// this filename, and therefore, it will attempt to close the file and +// set it to 0. +// +// Remarks: +// calls DeleteFile() found in windows.h +// InputFileHandler does NOT have any way to validate that the handle +// passed belongs to the filename that it wants to be deleted. So use +// it with caution +// +// See Also: +// windows.h +// +// Revisions and History: +// 1/13/99 [HAI] - created +// +int InputFileHandler::deleteFile( + const char *filename, + bool deleteHandleFlag + ) +{ + if (deleteHandleFlag && file) + { + delete file; + file = NULL; + } + return(DeleteFile(filename)); +} + + +//=========================================================================== +//============================================================ End-of-file == +//=========================================================================== + diff --git a/engine/client/application/Miff/src/win32/InputFileHandler.h b/engine/client/application/Miff/src/win32/InputFileHandler.h new file mode 100644 index 00000000..9e4734fe --- /dev/null +++ b/engine/client/application/Miff/src/win32/InputFileHandler.h @@ -0,0 +1,71 @@ +#ifndef __INPUTFILEHANDLER_H__ +#define __INPUTFILEHANDLER_H__ + +//=========================================================================== +// +// FILENAME: InputFileHandler.h [C:\Projects\new\tools\src\miff\src\] +// COPYRIGHT: (C) 1999 BY Bootprint Entertainment +// +// DESCRIPTION: file handler for input files (flat text files) +// AUTHOR: Hideki Ikeda +// DATE: 1/13/99 4:55:15 PM +// +// HISTORY: 1/13/99 [HAI] - File created +// : +// +//=========================================================================== + +//============================================================== #includes == + +//========================================================= class typedefs == + +//====================================================== class definitions == + +class AbstractFile; + +class InputFileHandler +{ +//------------------------------ +//--- public var & functions --- +//------------------------------ +public: // functions + InputFileHandler(const char *infilename); + ~InputFileHandler(void); + + const int read(void *sourceBuffer, int bufferSize); + int deleteFile(const char * filename, bool deleteHandleFlag = false); + +public: // vars + + + //------------------------------- + //--- member vars declaration --- + //------------------------------- +protected: // vars + AbstractFile *file; + +private: // vars + + //----------------------------------- + //--- member function declaration --- + //----------------------------------- +protected: // functions + +private: // functions + void close(void); // close the input file called by destructor + +}; + +//=========================================================================== +//========================================================= inline methods == +//=========================================================================== + + +//=========================================================================== +//============================================================ End-of-file == +//=========================================================================== +#else + #ifdef DEBUG + #pragma message("InputFileHandler.h included more then once!") + #endif +#endif // ifndef __H__ diff --git a/engine/client/application/Miff/src/win32/OutputFileHandler.cpp b/engine/client/application/Miff/src/win32/OutputFileHandler.cpp new file mode 100644 index 00000000..1c8ffe96 --- /dev/null +++ b/engine/client/application/Miff/src/win32/OutputFileHandler.cpp @@ -0,0 +1,164 @@ +//=========================================================================== +// +// FILENAME: OutputFileHandler.cpp +// COPYRIGHT: (C) 1999 BY Bootprint Entertainment +// +// DESCRIPTION: file handler for Output file (IFF file) +// AUTHOR: Hideki Ikeda +// DATE: 1/13/99 4:52:42 PM +// +//=========================================================================== + +#include "sharedFoundation/FirstSharedFoundation.h" +#include "OutputFileHandler.h" + +#include "sharedFile/Iff.h" + +//=========================================================================== +// Constructor + +OutputFileHandler::OutputFileHandler(const char *filename) +{ + outputIFF = new Iff(MAXIFFDATASIZE); + outFilename = NULL; + + setCurrentFilename(filename); +} + +void OutputFileHandler::setCurrentFilename(const char *filename) +{ + if (outFilename) + delete [] outFilename; + + outFilename = new char[strlen(filename)+1]; + strcpy(outFilename, filename); +} + +//--------------------------------------------------------------------------- +// Destructor + +OutputFileHandler::~OutputFileHandler(void) +{ + if (outputIFF && outFilename) + { + delete outputIFF; + delete [] outFilename; + } + + outputIFF = NULL; +} + + +//--------------------------------------------------------------------------- +// begins a new FORM in the IFF +// +// Return Value: +// bool - true == success +// +// See Also: +// Iff::insertForm() + +void OutputFileHandler::insertForm( + const char *tag + ) +{ + Tag formTag = convertStrToTag(tag); + outputIFF->insertForm(formTag); +} + +//--------------------------------------------------------------------------- +// begins a new CHUNK in the IFF +// +// See Also: +// Iff::insertChunk() + +void OutputFileHandler::insertChunk( + const char *tag + ) +{ + Tag chunkTag = convertStrToTag(tag); + outputIFF->insertChunk(chunkTag); +} + + +//--------------------------------------------------------------------------- +// converts string (4 bytes) form into Tag format +// +// Return Value: +// Tag +// +// Remarks: +// currently, this code is machine dependant code (non portable) and it assumes little endian +// +// See Also: +// Tag + +Tag OutputFileHandler::convertStrToTag( + const char *str + ) +{ + // prepare for hack-o-rama. It is byte order dependant, thus not portable ^_^ + Tag retVal = str[3] + (str[2] * 0x100) + (str[1] * 0x10000) + (str[0] * 0x1000000); + + return(retVal); +} + + +//--------------------------------------------------------------------------- +// adds new chunk data into the current chunk it is in +// +// See Also: +// Iff::insertChunkData() +// + +void OutputFileHandler::insertChunkData( + void *data, + int length + ) +{ + outputIFF->insertChunkData(data, length); +} + +//--------------------------------------------------------------------------- +// exits current FORM section we are in +// +// See Also: +// Iff::exitForm() + +void OutputFileHandler::exitForm(void) +{ + outputIFF->exitForm(); +} + +//--------------------------------------------------------------------------- +// exits current CHUNK we are in +// +// See Also: +// Iff::exitChunk() + +void OutputFileHandler::exitChunk(void) +{ + outputIFF->exitChunk(); +} + + +//--------------------------------------------------------------------------- +// Calls Iff:write() +// +// Return Value: +// +// True if the Iff was successfully written, otherwise false +// +// See Also: +// Iff::write() + +bool OutputFileHandler::writeBuffer(void) +{ + if (outputIFF && outFilename) + return outputIFF->write(outFilename, true); + + return false; +} + +//=========================================================================== + diff --git a/engine/client/application/Miff/src/win32/OutputFileHandler.h b/engine/client/application/Miff/src/win32/OutputFileHandler.h new file mode 100644 index 00000000..5f4eaf58 --- /dev/null +++ b/engine/client/application/Miff/src/win32/OutputFileHandler.h @@ -0,0 +1,80 @@ +#ifndef __OUTPUTFILEHANDLER_H__ +#define __OUTPUTFILEHANDLER_H__ + +//=========================================================================== +// +// FILENAME: OutputFileHandler.h [C:\Projects\new\tools\src\miff\src\] +// COPYRIGHT: (C) 1999 BY Bootprint Entertainment +// +// DESCRIPTION: file handler for output files (IFF file format) +// AUTHOR: Hideki Ikeda +// DATE: 1/13/99 4:55:56 PM +// +// HISTORY: 1/13/99 [HAI] - File created +// : +// +//=========================================================================== + +//============================================================== #includes == + +//========================================================= class typedefs == +#include "sharedFile/Iff.h" + +//====================================================== class definitions == +class OutputFileHandler +{ +//------------------------------ +//--- public var & functions --- +//------------------------------ +public: // functions + OutputFileHandler(const char *filename); + ~OutputFileHandler(void); + bool writeBuffer(void); + + void insertForm(const char *tagName); + void insertChunk(const char *tagName); + void insertChunkData(void *data, int length); + void exitForm(void); + void exitChunk(void); + + void setCurrentFilename(const char *fname); + +public: // vars + + + //------------------------------- + //--- member vars declaration --- + //------------------------------- +protected: // vars + Iff * outputIFF; + char *outFilename; + +enum{ + MAXIFFDATASIZE = 8192 // allocate 8K of memory for a starter + }; + +private: // vars + + //----------------------------------- + //--- member function declaration --- + //----------------------------------- +protected: // functions + +private: // functions + Tag convertStrToTag(const char *str); + +}; + +//=========================================================================== +//========================================================= inline methods == +//=========================================================================== + + +//=========================================================================== +//============================================================ End-of-file == +//=========================================================================== +#else + #ifdef DEBUG + #pragma message("OutputFileHandler.h included more then once!") + #endif +#endif // ifndef __H__ diff --git a/engine/client/application/Miff/src/win32/bison.simple b/engine/client/application/Miff/src/win32/bison.simple new file mode 100644 index 00000000..5f8f386e --- /dev/null +++ b/engine/client/application/Miff/src/win32/bison.simple @@ -0,0 +1,698 @@ +/* -*-C-*- Note some compilers choke on comments on `#line' lines. */ +#line 3 "bison.simple" + +/* Skeleton output parser for bison, + Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +/* As a special exception, when this file is copied by Bison into a + Bison output file, you may use that output file without restriction. + This special exception was added by the Free Software Foundation + in version 1.24 of Bison. */ + +#define MSDOS 1 + +#ifndef alloca +#ifdef __GNUC__ +#define alloca __builtin_alloca +#else /* not GNU C. */ +#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) +#include +#else /* not sparc */ +#if defined (MSDOS) && !defined (__TURBOC__) +#include +#else /* not MSDOS, or __TURBOC__ */ +#if defined(_AIX) +#include + #pragma alloca +#else /* not MSDOS, __TURBOC__, or _AIX */ +#ifdef __hpux +#ifdef __cplusplus +extern "C" { +void *alloca (unsigned int); +}; +#else /* not __cplusplus */ +void *alloca (); +#endif /* not __cplusplus */ +#endif /* __hpux */ +#endif /* not _AIX */ +#endif /* not MSDOS, or __TURBOC__ */ +#endif /* not sparc. */ +#endif /* not GNU C. */ +#endif /* alloca not defined. */ + +#ifdef MSDOS +#define alloca(n) malloc(n) +#endif + +/* This is the parser code that is written into each bison parser + when the %semantic_parser declaration is not specified in the grammar. + It was written by Richard Stallman by simplifying the hairy parser + used when %semantic_parser is specified. */ + +/* Note: there must be only one dollar sign in this file. + It is replaced by the list of actions, each action + as one case of the switch. */ + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY -2 +#define YYEOF 0 +#define YYACCEPT return(0) +#define YYABORT return(1) +#define YYERROR goto yyerrlab1 +/* Like YYERROR except do call yyerror. + This remains here temporarily to ease the + transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. */ +#define YYFAIL goto yyerrlab +#define YYRECOVERING() (!!yyerrstatus) +#define YYBACKUP(token, value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { yychar = (token), yylval = (value); \ + yychar1 = YYTRANSLATE (yychar); \ + YYPOPSTACK; \ + goto yybackup; \ + } \ + else \ + { yyerror ("syntax error: cannot back up"); YYERROR; } \ +while (0) + +#define YYTERROR 1 +#define YYERRCODE 256 + +#ifndef YYPURE +#define YYLEX yylex() +#endif + +#ifdef YYPURE +#ifdef YYLSP_NEEDED +#ifdef YYLEX_PARAM +#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM) +#else +#define YYLEX yylex(&yylval, &yylloc) +#endif +#else /* not YYLSP_NEEDED */ +#ifdef YYLEX_PARAM +#define YYLEX yylex(&yylval, YYLEX_PARAM) +#else +#define YYLEX yylex(&yylval) +#endif +#endif /* not YYLSP_NEEDED */ +#endif + +/* If nonreentrant, generate the variables here */ + +#ifndef YYPURE + +int yychar; /* the lookahead symbol */ +YYSTYPE yylval; /* the semantic value of the */ + /* lookahead symbol */ + +#ifdef YYLSP_NEEDED +YYLTYPE yylloc; /* location data for the lookahead */ + /* symbol */ +#endif + +int yynerrs; /* number of parse errors so far */ +#endif /* not YYPURE */ + +#if YYDEBUG != 0 +int yydebug = 1; /* nonzero means print parse trace */ +/* Since this is uninitialized, it does not stop multiple parsers + from coexisting. */ +#endif + +/* YYINITDEPTH indicates the initial size of the parser's stacks */ + +#ifndef YYINITDEPTH +#define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH is the maximum size the stacks can grow to + (effective only if the built-in stack extension method is used). */ + +#if YYMAXDEPTH == 0 +#undef YYMAXDEPTH +#endif + +#ifndef YYMAXDEPTH +#define YYMAXDEPTH 10000 +#endif + +/* Prevent warning if -Wstrict-prototypes. */ +#ifdef __GNUC__ +int yyparse (void); +#endif + +#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */ +#define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT) +#else /* not GNU C or C++ */ +#ifndef __cplusplus + +/* This is the most reliable way to avoid incompatibilities + in available built-in functions on various systems. */ +static void +__yy_memcpy (to, from, count) + char *to; + char *from; + int count; +{ + register char *f = from; + register char *t = to; + register int i = count; + + while (i-- > 0) + *t++ = *f++; +} + +#else /* __cplusplus */ + +/* This is the most reliable way to avoid incompatibilities + in available built-in functions on various systems. */ +static void +__yy_memcpy (char *to, char *from, int count) +{ + register char *f = from; + register char *t = to; + register int i = count; + + while (i-- > 0) + *t++ = *f++; +} + +#endif +#endif + +#line 196 "bison.simple" + +/* The user can define YYPARSE_PARAM as the name of an argument to be passed + into yyparse. The argument should have type void *. + It should actually point to an object. + Grammar actions can access the variable by casting it + to the proper pointer type. */ + +#ifdef YYPARSE_PARAM +#ifdef __cplusplus +#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM +#define YYPARSE_PARAM_DECL +#else /* not __cplusplus */ +#define YYPARSE_PARAM_ARG YYPARSE_PARAM +#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM; +#endif /* not __cplusplus */ +#else /* not YYPARSE_PARAM */ +#define YYPARSE_PARAM_ARG +#define YYPARSE_PARAM_DECL +#endif /* not YYPARSE_PARAM */ + +int +yyparse(YYPARSE_PARAM_ARG) + YYPARSE_PARAM_DECL +{ + register int yystate; + register int yyn; + register short *yyssp; + register YYSTYPE *yyvsp; + int yyerrstatus; /* number of tokens to shift before error messages enabled */ + int yychar1 = 0; /* lookahead token as an internal (translated) token number */ + + short yyssa[YYINITDEPTH]; /* the state stack */ + YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */ + + short *yyss = yyssa; /* refer to the stacks thru separate pointers */ + YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */ + +#ifdef YYLSP_NEEDED + YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */ + YYLTYPE *yyls = yylsa; + YYLTYPE *yylsp; + +#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--) +#else +#define YYPOPSTACK (yyvsp--, yyssp--) +#endif + + int yystacksize = YYINITDEPTH; + +#ifdef YYPURE + int yychar; + YYSTYPE yylval; + int yynerrs; +#ifdef YYLSP_NEEDED + YYLTYPE yylloc; +#endif +#endif + + YYSTYPE yyval; /* the variable used to return */ + /* semantic values from the action */ + /* routines */ + + int yylen; + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Starting parse\n"); +#endif + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + + yyssp = yyss - 1; + yyvsp = yyvs; +#ifdef YYLSP_NEEDED + yylsp = yyls; +#endif + +/* Push a new state, which is found in yystate . */ +/* In all cases, when you get here, the value and location stacks + have just been pushed. so pushing a state here evens the stacks. */ +yynewstate: + + *++yyssp = yystate; + + if (yyssp >= yyss + yystacksize - 1) + { + /* Give user a chance to reallocate the stack */ + /* Use copies of these so that the &'s don't force the real ones into memory. */ + YYSTYPE *yyvs1 = yyvs; + short *yyss1 = yyss; +#ifdef YYLSP_NEEDED + YYLTYPE *yyls1 = yyls; +#endif + + /* Get the current used size of the three stacks, in elements. */ + int size = yyssp - yyss + 1; + +#ifdef yyoverflow + /* Each stack pointer address is followed by the size of + the data in use in that stack, in bytes. */ +#ifdef YYLSP_NEEDED + /* This used to be a conditional around just the two extra args, + but that might be undefined if yyoverflow is a macro. */ + yyoverflow("parser stack overflow", + &yyss1, size * sizeof (*yyssp), + &yyvs1, size * sizeof (*yyvsp), + &yyls1, size * sizeof (*yylsp), + &yystacksize); +#else + yyoverflow("parser stack overflow", + &yyss1, size * sizeof (*yyssp), + &yyvs1, size * sizeof (*yyvsp), + &yystacksize); +#endif + + yyss = yyss1; yyvs = yyvs1; +#ifdef YYLSP_NEEDED + yyls = yyls1; +#endif +#else /* no yyoverflow */ + /* Extend the stack our own way. */ + if (yystacksize >= YYMAXDEPTH) + { + yyerror("parser stack overflow"); + return 2; + } + yystacksize *= 2; + if (yystacksize > YYMAXDEPTH) + yystacksize = YYMAXDEPTH; + yyss = (short *) alloca (yystacksize * sizeof (*yyssp)); + __yy_memcpy ((char *)yyss, (char *)yyss1, size * sizeof (*yyssp)); + yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp)); + __yy_memcpy ((char *)yyvs, (char *)yyvs1, size * sizeof (*yyvsp)); +#ifdef YYLSP_NEEDED + yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp)); + __yy_memcpy ((char *)yyls, (char *)yyls1, size * sizeof (*yylsp)); +#endif +#endif /* no yyoverflow */ + + yyssp = yyss + size - 1; + yyvsp = yyvs + size - 1; +#ifdef YYLSP_NEEDED + yylsp = yyls + size - 1; +#endif + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Stack size increased to %d\n", yystacksize); +#endif + + if (yyssp >= yyss + yystacksize - 1) + YYABORT; + } + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Entering state %d\n", yystate); +#endif + + goto yybackup; + yybackup: + +/* Do appropriate processing given the current state. */ +/* Read a lookahead token if we need one and don't already have one. */ +/* yyresume: */ + + /* First try to decide what to do without reference to lookahead token. */ + + yyn = yypact[yystate]; + if (yyn == YYFLAG) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* yychar is either YYEMPTY or YYEOF + or a valid token in external form. */ + + if (yychar == YYEMPTY) + { +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Reading a token: "); +#endif + yychar = YYLEX; + } + + /* Convert token to internal form (in yychar1) for indexing tables with */ + + if (yychar <= 0) /* This means end of input. */ + { + yychar1 = 0; + yychar = YYEOF; /* Don't call YYLEX any more */ + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Now at end of input.\n"); +#endif + } + else + { + yychar1 = YYTRANSLATE(yychar); + +#if YYDEBUG != 0 + if (yydebug) + { + fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]); + /* Give the individual parser a way to print the precise meaning + of a token, for further debugging info. */ +#ifdef YYPRINT + YYPRINT (stderr, yychar, yylval); +#endif + fprintf (stderr, ")\n"); + } +#endif + } + + yyn += yychar1; + if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1) + goto yydefault; + + yyn = yytable[yyn]; + + /* yyn is what to do for this token type in this state. + Negative => reduce, -yyn is rule number. + Positive => shift, yyn is new state. + New state is final state => don't bother to shift, + just return success. + 0, or most negative number => error. */ + + if (yyn < 0) + { + if (yyn == YYFLAG) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + else if (yyn == 0) + goto yyerrlab; + + if (yyn == YYFINAL) + YYACCEPT; + + /* Shift the lookahead token. */ + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]); +#endif + + /* Discard the token being shifted unless it is eof. */ + if (yychar != YYEOF) + yychar = YYEMPTY; + + *++yyvsp = yylval; +#ifdef YYLSP_NEEDED + *++yylsp = yylloc; +#endif + + /* count tokens shifted since error; after three, turn off error status. */ + if (yyerrstatus) yyerrstatus--; + + yystate = yyn; + goto yynewstate; + +/* Do the default action for the current state. */ +yydefault: + + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + +/* Do a reduction. yyn is the number of a rule to reduce with. */ +yyreduce: + yylen = yyr2[yyn]; + if (yylen > 0) + yyval = yyvsp[1-yylen]; /* implement default value of the action */ + +#if YYDEBUG != 0 + if (yydebug) + { + int i; + + fprintf (stderr, "Reducing via rule %d (line %d), ", + yyn, yyrline[yyn]); + + /* Print the symbols being reduced, and their result. */ + for (i = yyprhs[yyn]; yyrhs[i] > 0; i++) + fprintf (stderr, "%s ", yytname[yyrhs[i]]); + fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]); + } +#endif + +$ /* the action file gets copied in in place of this dollarsign */ +#line 498 "bison.simple" + + yyvsp -= yylen; + yyssp -= yylen; +#ifdef YYLSP_NEEDED + yylsp -= yylen; +#endif + +#if YYDEBUG != 0 + if (yydebug) + { + short *ssp1 = yyss - 1; + fprintf (stderr, "state stack now"); + while (ssp1 != yyssp) + fprintf (stderr, " %d", *++ssp1); + fprintf (stderr, "\n"); + } +#endif + + *++yyvsp = yyval; + +#ifdef YYLSP_NEEDED + yylsp++; + if (yylen == 0) + { + yylsp->first_line = yylloc.first_line; + yylsp->first_column = yylloc.first_column; + yylsp->last_line = (yylsp-1)->last_line; + yylsp->last_column = (yylsp-1)->last_column; + yylsp->text = 0; + } + else + { + yylsp->last_line = (yylsp+yylen-1)->last_line; + yylsp->last_column = (yylsp+yylen-1)->last_column; + } +#endif + + /* Now "shift" the result of the reduction. + Determine what state that goes to, + based on the state we popped back to + and the rule number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTBASE] + *yyssp; + if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTBASE]; + + goto yynewstate; + +yyerrlab: /* here on detecting error */ + + if (! yyerrstatus) + /* If not already recovering from an error, report this error. */ + { + ++yynerrs; + +#ifdef YYERROR_VERBOSE + yyn = yypact[yystate]; + + if (yyn > YYFLAG && yyn < YYLAST) + { + int size = 0; + char *msg; + int x, count; + + count = 0; + /* Start X at -yyn if nec to avoid negative indexes in yycheck. */ + for (x = (yyn < 0 ? -yyn : 0); + x < (sizeof(yytname) / sizeof(char *)); x++) + if (yycheck[x + yyn] == x) + size += strlen(yytname[x]) + 15, count++; + msg = (char *) malloc(size + 15); + if (msg != 0) + { + strcpy(msg, "parse error"); + + if (count < 5) + { + count = 0; + for (x = (yyn < 0 ? -yyn : 0); + x < (sizeof(yytname) / sizeof(char *)); x++) + if (yycheck[x + yyn] == x) + { + strcat(msg, count == 0 ? ", expecting `" : " or `"); + strcat(msg, yytname[x]); + strcat(msg, "'"); + count++; + } + } + yyerror(msg); + free(msg); + } + else + yyerror ("parse error; also virtual memory exceeded"); + } + else +#endif /* YYERROR_VERBOSE */ + yyerror("parse error"); + } + + goto yyerrlab1; +yyerrlab1: /* here on error raised explicitly by an action */ + + if (yyerrstatus == 3) + { + /* if just tried and failed to reuse lookahead token after an error, discard it. */ + + /* return failure if at end of input */ + if (yychar == YYEOF) + YYABORT; + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]); +#endif + + yychar = YYEMPTY; + } + + /* Else will try to reuse lookahead token + after shifting the error token. */ + + yyerrstatus = 3; /* Each real token shifted decrements this */ + + goto yyerrhandle; + +yyerrdefault: /* current state does not do anything special for the error token. */ + +#if 0 + /* This is wrong; only states that explicitly want error tokens + should shift them. */ + yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/ + if (yyn) goto yydefault; +#endif + +yyerrpop: /* pop the current state because it cannot handle the error token */ + + if (yyssp == yyss) YYABORT; + yyvsp--; + yystate = *--yyssp; +#ifdef YYLSP_NEEDED + yylsp--; +#endif + +#if YYDEBUG != 0 + if (yydebug) + { + short *ssp1 = yyss - 1; + fprintf (stderr, "Error: state stack now"); + while (ssp1 != yyssp) + fprintf (stderr, " %d", *++ssp1); + fprintf (stderr, "\n"); + } +#endif + +yyerrhandle: + + yyn = yypact[yystate]; + if (yyn == YYFLAG) + goto yyerrdefault; + + yyn += YYTERROR; + if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR) + goto yyerrdefault; + + yyn = yytable[yyn]; + if (yyn < 0) + { + if (yyn == YYFLAG) + goto yyerrpop; + yyn = -yyn; + goto yyreduce; + } + else if (yyn == 0) + goto yyerrpop; + + if (yyn == YYFINAL) + YYACCEPT; + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Shifting error token, "); +#endif + + *++yyvsp = yylval; +#ifdef YYLSP_NEEDED + *++yylsp = yylloc; +#endif + + yystate = yyn; + goto yynewstate; +} diff --git a/engine/client/application/Miff/src/win32/mIFF.dox b/engine/client/application/Miff/src/win32/mIFF.dox new file mode 100644 index 00000000..4c46d600 --- /dev/null +++ b/engine/client/application/Miff/src/win32/mIFF.dox @@ -0,0 +1,62 @@ +// NOTE: this makes it more convinient for me to make the help screen fancier... +// blah... not that anybody cares... + +printf("\ +Usage:\n\ + mIFF {-%c |--%s=}\n\ + [{-%c |--%s=} | {-%c|--%s}]\n\ + [{-%c|--%s}] [{-%c|--%s}] [{-%c|--%s}]\n\n", + SNAME_INPUT_FILE, LNAME_INPUT_FILE, + SNAME_OUTPUT_FILE, LNAME_OUTPUT_FILE, + SNAME_PRAGMA_TARGET, LNAME_PRAGMA_TARGET, + SNAME_CCCP, LNAME_CCCP, + SNAME_VERBOSE, LNAME_VERBOSE, + SNAME_DEBUG, LNAME_DEBUG); +printf("\ + mIFF {-%c|--%s}\n\n", SNAME_HELP, LNAME_HELP); + +printf("\ +Parameters:\n\ + -%c ,--%s=\n\ + [required] specifies the input path for IFF source file.\n", SNAME_INPUT_FILE, LNAME_INPUT_FILE); +printf("\ + -%c ,--%s=\n\ + [optional] specifies the pathname for the generated \n\ + IFF data file. Note that if neither this nor the following \n\ + option are specified, a default output filename of the source\n\ + file's base name with extension \".iff\" will be used.\n", SNAME_OUTPUT_FILE, LNAME_OUTPUT_FILE); +printf("\ + -%c,--%s\n\ + [optional] specifies the generated output filename should be \n\ + taken from the #pragma options within the source file. \n\ + Allowable #pragma options are: \n\ + #pragma drive \":\"\n\ + #pragma directory \"\"\n\ + #pragma filename \"\"\n\ + #pragma extension \"\"\n", SNAME_PRAGMA_TARGET, LNAME_PRAGMA_TARGET); +printf("\ + -%c,--%s\n\ + [optional] use CCCP rather than CPP.\n", SNAME_CCCP, LNAME_CCCP); +printf("\ + -%c,--%s\n\ + [optional] display more information during execution.\n", SNAME_VERBOSE, LNAME_VERBOSE); +printf("\ + -%c,--%s\n\ + [optional] enable debug mode (save intermediate files).\n", SNAME_DEBUG, LNAME_DEBUG); +printf("\ + -%c,--%s\n\ + [very optional] this help screen.\n", SNAME_HELP, LNAME_HELP); +printf("\ +Examples:\n\ + mIFF -%c foo.bar\n\ + this will generate an iff file foo.iff (default if no parm specified)\n\ + in the current working directory. Even if foo.bar contains #pragma, \n\ + it will create foo.iff because -%c was not specified.\n", SNAME_INPUT_FILE, SNAME_PRAGMA_TARGET); +printf("\ + mIFF -%c \"C:\\my project\\myData\\foo.iff\" --%s=foo.bar\n\ + notice that if you have space in your dirname, use \" to encapsulate \n\ + it.\n", SNAME_OUTPUT_FILE, LNAME_INPUT_FILE); +printf("\ + mIFF -%c foo.bar --%s\n\ + will generate output file specified by #pragma statements \n\ + within file foo.bar.\n", SNAME_INPUT_FILE, LNAME_PRAGMA_TARGET); diff --git a/engine/client/application/Miff/src/win32/miff.cpp b/engine/client/application/Miff/src/win32/miff.cpp new file mode 100644 index 00000000..89535216 --- /dev/null +++ b/engine/client/application/Miff/src/win32/miff.cpp @@ -0,0 +1,961 @@ +//=========================================================================== +// +// FILENAME: mIFF.cpp [C:\Projects\new\tools\src\miff\src\] +// COPYRIGHT: (C) 1999 BY Bootprint Entertainment +// +// DESCRIPTION: make IFF (Console version) +// AUTHOR: Hideki Ikeda +// DATE: 1/07/99 12:57:20 PM +// +// HISTORY: 1/07/99 [HAI] - File created +// : 1/07/99 [HAI] - v1.0 introductory version +// : 1/12/99 [HAI] - v1.1 switched from DOS to Engine library +// : - first attempt was to setup the main entry +// : point via ConsoleEntryPoint() via callback +// : 1/29/99 [HAI] - changed the parameter in MIFFMessage to allow +// : output even in non-verbose mode (for error +// : message purpose. +// : 05/07/99 [HAI]- added MIFFallocString() and MIFFfreeString() +// : to work with memory manager. they are allocated +// : in the lexical analyzer for IDENTIFIERS and STR_LIT +// : deleted after parser parses the rule. +// +// FUNCTION: main() +// : evaluateArgs() +// : help() +// : handleError() +// : preprocessSource() +// : MIFFMessage() +// : callbackFunction() +// +//=========================================================================== + +//========================================================== include files == +#include "sharedFoundation/FirstSharedFoundation.h" + +#include "sharedCompression/SetupSharedCompression.h" +#include "sharedDebug/SetupSharedDebug.h" +#include "sharedFile/SetupSharedFile.h" +#include "sharedFile/TreeFile.h" +#include "sharedFoundation/CommandLine.h" +#include "sharedFoundation/Crc.h" +#include "sharedFoundation/Os.h" +#include "sharedFoundation/SetupSharedFoundation.h" +#include "sharedMemoryManager/MemoryManager.h" +#include "sharedThread/SetupSharedThread.h" + +#include "InputFileHandler.h" +#include "OutputFileHandler.h" + +#include // for memset() +#include // FILE stuff +#include // for getcwd() +#include // for tolower() +#include // for system() + +//================================================= static vars assignment == +const int entryPointVersion = 1; // constantly check DataEntryPoint.h to see if this value has changed + +OutputFileHandler *outfileHandler = NULL; +const int bufferSize = 16 * 1024 * 1024; +const int maxStringSize = 256; +const char version[] = "1.3 September 18, 2000"; + +// vars set by pragmas or via command line +char drive[4]; // should be no more then 2 char "C:" +char directory[maxStringSize]; +char filename[maxStringSize]; +char extension[8]; // we'll truncate if the extension is more then 8 chars... +char inFileName[maxStringSize]; + +// switches to be sent to mIFF Compiler +char sourceBuffer[bufferSize]; +char outFileName[(maxStringSize * 2) + 8]; // x2 to combine filename, dir, and ext +bool usePragma = false; +bool useCCCP = false; +bool verboseMode = false; // default to non-verbose mode +bool debugMode = false; // set this on and the preprocessed source file (mIFF.$$$) won't be deleted + +static bool runningUnderNT; + +enum errorType { + ERR_FILENOTFOUND = -1, + ERR_ARGSTOOFEW = -2, + ERR_BUFFERTOOSMALL = -3, + ERR_UNKNOWNDIR = -4, + ERR_PREPROCESS = -5, + ERR_MULTIPLEINFILE = -6, + ERR_PARSER = -7, + ERR_ENGINE = -8, + + ERR_HELPREQUEST = -9, + ERR_OPTIONS = -10, + + ERR_WRITEERROR = -11, + + ERR_NONE = 0 + }; +char err_msg[512]; +errorType errorFlag = ERR_NONE; // assume no error (default) + + +// long and short name definitions for command line options + +static const char * const LNAME_HELP = "help"; +static const char * const LNAME_INPUT_FILE = "inputfile"; +static const char * const LNAME_OUTPUT_FILE = "outputfile"; +static const char * const LNAME_PRAGMA_TARGET = "pragmatarget"; +static const char * const LNAME_CCCP = "cccp"; +static const char * const LNAME_VERBOSE = "verbose"; +static const char * const LNAME_DEBUG = "debug"; + +static const char SNAME_HELP = 'h'; +static const char SNAME_INPUT_FILE = 'i'; +static const char SNAME_OUTPUT_FILE = 'o'; +static const char SNAME_PRAGMA_TARGET = 'p'; +static const char SNAME_CCCP = 'c'; +static const char SNAME_VERBOSE = 'v'; +static const char SNAME_DEBUG = 'd'; + +// following is the command line option spec tree needed for command line processing +static CommandLine::OptionSpec optionSpecArray[] = +{ + OP_BEGIN_SWITCH(OP_NODE_REQUIRED), + + // help + OP_SINGLE_SWITCH_NODE(SNAME_HELP, LNAME_HELP, OP_ARG_NONE, OP_MULTIPLE_DENIED), + + // real options + OP_BEGIN_SWITCH_NODE(OP_MULTIPLE_DENIED), + OP_BEGIN_LIST(), + // input filename required + OP_SINGLE_LIST_NODE(SNAME_INPUT_FILE, LNAME_INPUT_FILE, OP_ARG_REQUIRED, OP_MULTIPLE_DENIED, OP_NODE_REQUIRED), + + // optional, mutually exclusive output file specification options + // if none specified, generate derive output filename from input filename + OP_BEGIN_LIST_NODE(OP_MULTIPLE_DENIED, OP_NODE_OPTIONAL), + OP_BEGIN_SWITCH(OP_NODE_OPTIONAL), + // specify output filename on command line + OP_SINGLE_SWITCH_NODE(SNAME_OUTPUT_FILE, LNAME_OUTPUT_FILE, OP_ARG_REQUIRED, OP_MULTIPLE_DENIED), + + // use pragma target for output filename + OP_SINGLE_SWITCH_NODE(SNAME_PRAGMA_TARGET, LNAME_PRAGMA_TARGET, OP_ARG_NONE, OP_MULTIPLE_DENIED), + OP_END_SWITCH(), + OP_END_LIST_NODE(), + + // if specified, use cccp instead of cpp + OP_SINGLE_LIST_NODE(SNAME_CCCP, LNAME_CCCP, OP_ARG_NONE, OP_MULTIPLE_DENIED, OP_NODE_OPTIONAL), + + // if specified, be verbose + OP_SINGLE_LIST_NODE(SNAME_VERBOSE, LNAME_VERBOSE, OP_ARG_NONE, OP_MULTIPLE_DENIED, OP_NODE_OPTIONAL), + + // if specified, enter debug info + OP_SINGLE_LIST_NODE(SNAME_DEBUG, LNAME_DEBUG, OP_ARG_NONE, OP_MULTIPLE_DENIED, OP_NODE_OPTIONAL), + OP_END_LIST(), + OP_END_SWITCH_NODE(), + + OP_END_SWITCH() +}; +static const int optionSpecCount = sizeof(optionSpecArray) / sizeof(optionSpecArray[0]); + +//================================================= function prototypes == +int main(int argc, char *argv[]); +static errorType evaluateArgs(void); +static void help(void); +static void handleError(errorType error); +static int preprocessSource(char *sourceName); +static void callbackFunction(void); +static errorType loadInputToBuffer(void *destAddr, int maxBufferSize); + +// functions called by parser.yac and parser.lex +extern "C" void MIFFMessage(char *msg, int forceOut); +extern "C" void MIFFSetError(void); +extern "C" void MIFFSetIFFName(const char *newFileName); +extern "C" void MIFFinsertForm(const char *formName); +extern "C" void MIFFinsertChunk(const char *chunkName); +extern "C" void MIFFinsertChunkData(void * buffer, unsigned bufferSize); +extern "C" int MIFFloadRawData(char *fname, void * buffer, unsigned maxBufferSize); +extern "C" void MIFFexitChunk(void); +extern "C" void MIFFexitForm(void); +extern "C" unsigned long MIFFgetLabelHash(char *inputStream); + +// external functions found in parser.lex file +extern "C" void MIFFCompile(char *inputStream, char *inputFname); +extern "C" void MIFFCompileInit(char *inputStream, char *inputFname); + +//--------------------------------------------------------------------------- +// main entry point from console call +// +// Return Value: +// errorType - see enumeration; 0 if no errors +// +// Remarks: +// +// +// See Also: +// +// +// Revisions and History: +// 1/07/99 [HAI] - created +// +int main( int argc, // number of args in commandline + char * argv[] // list of pointers to strings + ) +{ + memset(sourceBuffer, 0, bufferSize); + + SetupSharedThread::install(); + SetupSharedDebug::install(4096); + + SetupSharedFoundation::Data SetupSharedFoundationData (SetupSharedFoundation::Data::D_console); + SetupSharedFoundationData.useWindowHandle = false; + SetupSharedFoundationData.argc = argc; + SetupSharedFoundationData.argv = argv; + SetupSharedFoundationData.demoMode = true; + SetupSharedFoundation::install (SetupSharedFoundationData); + + SetupSharedCompression::install(); + + SetupSharedFile::install(false); + + TreeFile::addSearchAbsolute(0); + TreeFile::addSearchPath (".", 0); + + SetupSharedFoundation::callbackWithExceptionHandling(callbackFunction); + SetupSharedFoundation::remove(); + + SetupSharedThread::remove(); + return static_cast (errorFlag); +} + +//--------------------------------------------------------------------------- +// callback function for Engine's console entry point +// +// Return Value: +// none +// +// Remarks: +// this is like a substitute of main() +// +// See Also: +// +// +// Revisions and History: +// 1/12/99 [HAI] - created +// +static void callbackFunction(void) +{ + outfileHandler = NULL; + +#ifdef WIN32 + + // check if we're running under NT + OSVERSIONINFO osInfo; + Zero(osInfo); + + osInfo.dwOSVersionInfoSize = sizeof(osInfo); + const BOOL getVersionResult = GetVersionEx(&osInfo); + if (getVersionResult) + runningUnderNT = (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT); + if (runningUnderNT) + DEBUG_REPORT_LOG(true, ("MIFF: running under Windows NT platform\n")); + else + DEBUG_REPORT_LOG(true, ("MIFF: running under non-NT Windows platform\n")); + +#endif + + errorFlag = evaluateArgs(); + if (ERR_NONE == errorFlag) + { + outfileHandler = new OutputFileHandler(outFileName); + MIFFCompile(sourceBuffer, inFileName); + } + else + handleError(errorFlag); + + if (outfileHandler) + { + // only write output IF there was no error + if (ERR_NONE == errorFlag) + { + if (!outfileHandler->writeBuffer()) + { + fprintf(stderr, "MIFF: failed to write output file \"%s\"\n", outFileName); + errorFlag = ERR_WRITEERROR; + } + } + delete outfileHandler; + } +} + +//--------------------------------------------------------------------------- +// Evaluates the command line and sets up the environment variables required for mIFF to function +// +// Return Value: +// errorType +// +// Remarks: +// argc's and argv's are substituted with CommandLine::functions() +// +// See Also: +// +// +// Revisions and History: +// 1/07/99 [HAI] - created +// +static errorType evaluateArgs(void) +{ + errorType retVal = ERR_NONE; + + // parse the commandline + const CommandLine::MatchCode mc = CommandLine::parseOptions(optionSpecArray, optionSpecCount); + if (mc != CommandLine::MC_MATCH) + { + // -TF- add call to retrieve command line error buffer for display (as soon as it is written!) + printf("WARNING: usage error detected, printing help.\n"); + help(); + return ERR_OPTIONS; + } + else if (CommandLine::getOccurrenceCount(SNAME_HELP)) + { + // user specified help + help(); + retVal = ERR_HELPREQUEST; + return(retVal); + } + + // at this point, we can assume a valid combination of options has been specified on the commandline + + + // setup input filename + strcpy(inFileName, CommandLine::getOptionString(SNAME_INPUT_FILE)); + + + // handle output filename spec + if (CommandLine::getOccurrenceCount(SNAME_OUTPUT_FILE)) + { + strcpy(outFileName, CommandLine::getOptionString(SNAME_OUTPUT_FILE)); + } + else if (CommandLine::getOccurrenceCount(SNAME_PRAGMA_TARGET)) + { + // use pragma target within iff source for output filename + usePragma = true; + } + else + { + // no output option specified on commandline, derive from input filename + char *terminator; + + // start with input file pathname + strcpy(outFileName, inFileName); + + // try to terminate at rightmost '.' + terminator = strrchr(outFileName, '.'); + if (terminator) + *terminator = 0; + + // append the default iff extension + strcat(outFileName, ".iff"); + } + + + // handle options (get them out of the way, as we use them later) + useCCCP = (CommandLine::getOccurrenceCount(SNAME_CCCP) != 0); + verboseMode = (CommandLine::getOccurrenceCount(SNAME_VERBOSE) != 0); + debugMode = (CommandLine::getOccurrenceCount(SNAME_DEBUG) != 0); + + + // preprocess the input file + if (0 == preprocessSource(inFileName)) + { + if (verboseMode) + { + sprintf(err_msg,"Now compiling %s...\n", inFileName); + MIFFMessage(err_msg, 0); + } + if (ERR_NONE == retVal) + retVal = loadInputToBuffer(sourceBuffer, bufferSize); + } + else + { + // preprocessSource returned an error... + retVal = ERR_PREPROCESS; + } + if (retVal != ERR_NONE) + return retVal; + + return retVal; + +#if 0 + + errorType retVal = ERR_NONE; // assume no error has been found + bool outPathUsed = false; // flag to monitor if -o flag was used, if so, we can ignore -d, -p, -e, -f + bool inFileEntered = false; + int argc = CommandLine::getPlainCount(); + + // get default values from DOS + char currentDir[maxStringSize]; + if (NULL == getcwd(currentDir, maxStringSize)) // get current working directory + { + retVal = ERR_UNKNOWNDIR; + return(retVal); + } + drive[0] = currentDir[0]; // drive letter + drive[1] = 0; // and null terminate it + strcpy(extension, "IFF"); // default to uppercase .IFF + strcpy(directory, ¤tDir[2]); // get everything after the Drive: including the first backslash + filename[0] = 0; + + // see specs.txt for requests + // scan for any argv's that has '-' in the argv[n][0]'s character + for (int index = 0; index < argc; index++) // note: if using argv[] rather then CommandLine::getPlainString() then start with 1 rather then 0 + { + if ('-' == CommandLine::getPlainString(index)[0]) + { + // we've found a parameter switch + switch (tolower(CommandLine::getPlainString(index)[1])) // assume non case sensitive switches + { + case 'i': // install via #pragma + { + usePragma = true; + break; + } + + case 'c': // use CCCP instead of CPP + useCCCP = true; + break; + + case 'v': // don't show any debug message + verboseMode = true; + break; + + case '$': + debugMode = true; + break; + + case 'o': // target output file name and path (complete path) + { + index++; // next param + outPathUsed = true; + strcpy(outFileName, CommandLine::getPlainString(index)); + break; + + } + + case 'd': // target drive letter (-p must be present) + { + if (!outPathUsed) + { + index++; // next param + strcpy(drive, CommandLine::getPlainString(index)); + } + else + index++; // skip the drive letter arg that SHOULD follow the -d option + break; + } + + case 'p': // target pathname + { + if (!outPathUsed) + { + index++; // next param + strcpy(directory, CommandLine::getPlainString(index)); + } + else + index++; // skip the pathname arg that follows the -p option + break; + } + + case 'f': // target filename + { + if (!outPathUsed) + { + index++; // next param + strcpy(filename, CommandLine::getPlainString(index)); + } + else + index++; // skip the filename arg that follows the -f + break; + } + + case 'e': // target extension + { + if (!outPathUsed) + { + index++; // next param + strcpy(extension, CommandLine::getPlainString(index)); + } + else + index++; // skip the extension arg that follows the -e + break; + } + + case 'h': // help! + case '?': + { + help(); + index = argc; // force to exit + retVal = ERR_HELPREQUEST; + return(retVal); // special case, ONLY time I call return() in the middle of the function (because I check for argc < 2 at the end of the code) + break; + } + + default: + { + sprintf(err_msg, "\nUnknown parameter %s, use -h to seek help...\n", CommandLine::getPlainString(index)); + MIFFMessage(err_msg, 1); + index = argc; // force to exit + break; + } + } + } + else + { + // we found an arg that doesn't start with '-' so let's assume it's a filename + if (!inFileEntered) + { + strcpy(inFileName, CommandLine::getPlainString(index)); + inFileEntered = true; + } + else + { + retVal = ERR_MULTIPLEINFILE; + index = argc; + } + + // now construct the DEFAULT filename for this file by scanning backwards to front and only extracting the filename (no extension, no path) + if (ERR_NONE == retVal) + { + char sourceName[maxStringSize]; + strcpy(sourceName, inFileName); // make a duplicate for us to play with + for (int strIndex = strlen(sourceName); strIndex > 0; strIndex--) + { + if ('.' == sourceName[strIndex]) + sourceName[strIndex] = 0; // put a stopper here... we are assuming that '.' indicates extension! I'm going to assume that the person is just testing me if s/he decides to use filename like "foo.bar.psych" which will truncate to "foo" + if ('\\' == sourceName[strIndex]) + break; // get out, for we've reached the path name... + } + + // ok, by here, strIndex should point to either beginning of the string, or where the first '\' was found scanning backwards + strcpy(filename, &sourceName[strIndex]); // ta-da-! + } + } + } + + if (inFileEntered) + { + if (0 == preprocessSource(inFileName)) + { + if (verboseMode) + { + // using err_msg as my temp buffer... + sprintf(err_msg,"Now compiling %s\n", inFileName); + MIFFMessage(err_msg, 0); + } + + if (ERR_NONE == retVal) + retVal = loadInputToBuffer(sourceBuffer, bufferSize); + } + else // preprocessSource returned an error... + { + retVal = ERR_PREPROCESS; + } + } + else // inFileEntered == false + { + MIFFMessage("Missing input filename in command line!", 1); + } + + // construct a outFileName[] based on drive[], directory[], filename[], and extension[] + if (!outPathUsed && (ERR_NONE == retVal)) + { + if (inFileName[0]) // make sure the user has entered a input filename + sprintf(outFileName,"%s:%s\\%s.%s", drive, directory, filename, extension); + } + + if (argc < 1) + retVal = ERR_ARGSTOOFEW; // we can do this because we know -h was not entered... + + return(retVal); + +#endif + +} + + +//--------------------------------------------------------------------------- +// reads the tmeporary files spit out by CCCP and stuffs the plain text into source buffer +// +// Return Value: +// errorType +// +// Remarks: +// +// +// See Also: +// +// +// Revisions and History: +// 1/14/99 [HAI] - created +// +static errorType loadInputToBuffer( + void * dest, // destination address of where you want the date to be read + int maxBufferSize // maximum destination data pool size + ) +{ + errorType retVal = ERR_NONE; + InputFileHandler *inFileHandler = new InputFileHandler("mIFF.$$$"); + if (inFileHandler) + { + int sizeRead = inFileHandler->read(dest, maxBufferSize); + if (sizeRead >= maxBufferSize) + { + retVal = ERR_BUFFERTOOSMALL; + } + else + { + reinterpret_cast(dest)[sizeRead] = 0; // so stupid... but if you don't zero-terminate at exact spot, YYInput may chokes because of extra grammer that may exist... + } + if (!debugMode) + inFileHandler->deleteFile("mIFF.$$$", true); // no need for temp file now... + + // we've successfully read the file, now close it... + delete inFileHandler; + } + else // inFileName is NULL + { + retVal = ERR_FILENOTFOUND; + } + + return(retVal); +} + +//--------------------------------------------------------------------------- +// help function called by main upon -h switch +// +// Return Value: +// none +// +// Remarks: +// #include's mIFF.dox +// make sure to update the version when modified. +// Notice that help() does NOT go thru MIFFMessage() because we want it to +// print out whether it's verbose mode or not... +// +// See Also: +// mIFF.dox +// +// Revisions and History: +// 1/07/99 [HAI] - created +// +static void help(void) +{ + printf("\nmIFF v%s (DOS version) - Bootprint Ent. (c) 1999\n", version); + printf("Hideki Ikeda\n"); +#include "mIFF.dox" +} + + +//--------------------------------------------------------------------------- +// upon exit from main(), if error has been found, it calls here to inform the user of the type of errors it has encounted. +// +// Return Value: +// none +// +// Remarks: +// use -q switch to suppress error messages - but in shell, return value can be used to determine the handling +// +// See Also: +// +// +// Revisions and History: +// 1/07/99 [HAI] - created +// +static void handleError(errorType error) +{ + if (ERR_NONE == error) + return; + + switch (error) + { + case ERR_NONE: + break; + + case ERR_FILENOTFOUND: + MIFFMessage("ERROR: INPUT File not found!\n", 1); + break; + + case ERR_ARGSTOOFEW: + MIFFMessage("ERROR: Not enough arguments. Use -h for help.\n", 1); + break; + + case ERR_BUFFERTOOSMALL: + MIFFMessage("ERROR: Internally allocated buffer for reading\nsource code is too small, increase buffer and re-compile\n", 1); + break; + + case ERR_UNKNOWNDIR: + MIFFMessage("ERROR: Directory unknown...\n", 1); + break; + + case ERR_PREPROCESS: + MIFFMessage("ERROR: Possible problems running the GNU C Preprocessor.\n", 1); + break; + + case ERR_MULTIPLEINFILE: + MIFFMessage("ERROR: There can only be ONE inputfile name.\nPerhaps you've forgotten the -o option flag\n", 1); + break; + + case ERR_ENGINE: + MIFFMessage("ERROR: Engine returned a non-zero value...\n", 1); + break; + + case ERR_PARSER: + MIFFMessage("ERROR: Parser error\n", 1); + break; + + case ERR_HELPREQUEST: + break; + + case ERR_OPTIONS: + MIFFMessage("ERROR: Failed to handle command line options\n", 1); + break; + + default: + MIFFMessage("ERROR: Unknown error, you suck!\n", 1); + break; + } +} + + +///////////////////////////////////////////////////////////////////////////// +// gotta write all these externs because you can't call C++ class based non-static +// functions from C... So we will use here as the bridge between the two +// languages + + +//--------------------------------------------------------------------------- +// Message output handler called by ALL external "C" functions +// +// Return Value: +// none +// +// Remarks: +// all the messages that are displayed are channeled thru this function. Note the -q quiet mode suppresses all messages. +// this is an extern "C" function +// +// See Also: +// yyerror() +// +// Revisions and History: +// 1/07/99 [] - created +// +extern "C" void MIFFMessage(char *message, // null terminated string to be displayed + int forceOutput) // if non-zero, it will print out even in quiet mode (for ERRORs) +{ + if (forceOutput) + fprintf(stdout, "%s\n", message); + else if (verboseMode) + fprintf(stdout, "%s\n", message); + OutputDebugString(message); + OutputDebugString("\n"); +} + +// Only call this via parser!!! +extern "C" void MIFFSetError(void) +{ + errorFlag = ERR_PARSER; +} + +//--------------------------------------------------------------------------- +// validation of the filename passed are legal. +// +// Return Value: +// bool usePragma - whether #pragma is ignored or not +// +// Remarks: +// if -i switch is used then #pragma's are expected +// this is an extern "C" function +// +// See Also: +// +// +// Revisions and History: +// 1/07/99 [ ] - created +// +extern "C" int validateTargetFilename( char *targetFileName, // pointer to where we can store the string filename + unsigned maxTargetBufSize // size of the filename string buffer + ) +{ + if (strlen(outFileName) > maxTargetBufSize) + MIFFMessage("Internal error, increase string buffer size in parser.yac and recompile!", 1); + + strcpy(targetFileName, outFileName); + + return(usePragma); +} + + +//--------------------------------------------------------------------------- +// function calls CCCP or CPP via shell to preprocess the source code for #include's and #define's via C-Compatible Compiler Preprocessor +// +// Return Value: +// shell return value (4DOS is very generous on returning different values, while DOS just returns 0 all the time) +// +// Remarks: +// use -c switch to use CCCP rather then CPP in your search path +// +// See Also: +// +// +// Revisions and History: +// 1/07/99 [ ] - created +// +static int preprocessSource(char *sourceName) +{ + char shellCommand[512]; + int retVal = 0; + + memset(shellCommand, 0, sizeof(shellCommand)); + +// if (!runningUnderNT) + { + + if (verboseMode) + MIFFMessage("Preprocessing... via CCCP", 0); + + // CCCP parameters: + // -nostdinc -nostdinc++ - do NOT search for standard include directory; without this, your + // puter would be just twiddling its thumb because CCCP can't find it... + // -pedantic - issue warnings (use pedantic-errors if you want it as errors) + // required by the ANSI C standard in certain cases such as comments that + // follow the #else/#endif + // -dD - output #defines (for the purpose of error msg I parse) + // -H - display the name of the header/included files (verbose mode) + // -P - originally, I had this... so it won't show the # line_num "filename" ??? + if (!useCCCP && verboseMode) + { + sprintf(shellCommand, "cpp.exe -nostdinc -nostdinc++ -pedantic -Wall -dD -H %s mIFF.$$$", sourceName); + } + else if (!useCCCP && !verboseMode) + { + sprintf(shellCommand, "cpp.exe -nostdinc -nostdinc++ -pedantic -Wall -dD %s mIFF.$$$", sourceName); + } + else if (useCCCP && verboseMode) + { + sprintf(shellCommand, "cccp.exe -nostdinc -nostdinc++ -pedantic -Wall -dD -H %s mIFF.$$$", sourceName); + } + else + sprintf(shellCommand, "cccp.exe -nostdinc -nostdinc++ -pedantic -Wall -dD %s mIFF.$$$", sourceName); + } +// else + { + // running under NT. Use the MSVC cl since it deals with long filenames on fat16/fat32 partitions correctly + // and ccp and cccp don't +// sprintf(shellCommand, "cl /nologo /W4 /EP %s > mIFF.$$$", sourceName); + } + + retVal = system(shellCommand); + if (2 == retVal) // actually, I think 4DOS reports 2 for cannot find file, but DOS returns a 0... + { + REPORT_LOG(true, ("failed to execute following shell command (%d):\n", retVal)); + REPORT_LOG(true, (" %s\n", shellCommand)); + MIFFMessage("\n\nERROR: Cannot find preprocessor (either CCCP.EXE, CPP.EXE or CL.EXE (under NT) in the search path...\n", 1); + MIFFMessage("Please make sure the preprocessor is in your search path!\n", 1); + } + return(retVal); +} + +extern "C" void MIFFSetIFFName(const char *newFileName) +{ + if (ERR_NONE != errorFlag) + return; + + if (outfileHandler) + outfileHandler->setCurrentFilename(newFileName); +} + +extern "C" void MIFFinsertForm(const char *formName) +{ + if (ERR_NONE != errorFlag) + return; + + if (outfileHandler) + outfileHandler->insertForm(formName); +} + +extern "C" void MIFFinsertChunk(const char *chunkName) +{ + if (ERR_NONE != errorFlag) + return; + + if (outfileHandler) + outfileHandler->insertChunk(chunkName); +} + +extern "C" void MIFFinsertChunkData(void * buffer, unsigned bufferSize) +{ + if (ERR_NONE != errorFlag) + return; + + if (outfileHandler) + outfileHandler->insertChunkData(buffer, bufferSize); +} + +extern "C" int MIFFloadRawData(char *fname, void * buffer, unsigned maxBufferSize) +{ + int sizeRead = -1; + + if (ERR_NONE != errorFlag) + return(sizeRead); // should be -1 + + InputFileHandler * inFileName = new InputFileHandler(fname); + if (inFileName) + { + sizeRead = inFileName->read(buffer, maxBufferSize); + if (static_cast(sizeRead) >= maxBufferSize) + { + handleError(ERR_BUFFERTOOSMALL); + sizeRead = -1; + } + delete inFileName; + } + + return(sizeRead); +} + +extern "C" void MIFFexitChunk(void) +{ + if (ERR_NONE != errorFlag) + return; + + if (outfileHandler) + outfileHandler->exitChunk(); +} +extern "C" void MIFFexitForm(void) +{ + if (ERR_NONE != errorFlag) + return; + + if (outfileHandler) + outfileHandler->exitForm(); +} + +extern "C" char * MIFFallocString(int sizeOfString) +{ + return(new char[sizeOfString]); +} + +extern "C" void MIFFfreeString(char * pointer) +{ + delete [] pointer; +} + +extern "C" unsigned long MIFFgetLabelHash(char * inputStream) +{ + return (unsigned long)Crc::calculate(inputStream); +} + +//=========================================================================== +//============================================================ End-of-file == +//=========================================================================== + diff --git a/engine/client/application/Miff/src/win32/parser.lex b/engine/client/application/Miff/src/win32/parser.lex new file mode 100644 index 00000000..b2996a07 --- /dev/null +++ b/engine/client/application/Miff/src/win32/parser.lex @@ -0,0 +1,517 @@ +%option full + +%{ +/*-----------------------------------------------------------------------------** +** FILE: parser.lex ** +** (c) 1998 - Bootprint GTInteractive ** +** ** +** DESCRIPTION: lexical analyzer for mIFF ** +** ** +** AUTHOR: Hideki Ikeda ** +** ** +** HISTORY: ** +** ** +** Notes: companion to parser.yac ** +**-----------------------------------------------------------------------------*/ +/* Disable compiler warnings (we want warning level 4) for anything that flex spits out */ +#pragma warning (disable: 4127) /* conditional expression is constant - ie. while(1) */ +#pragma warning (disable: 4131) /* usage of old-style declarator */ +#pragma warning (disable: 4098) /* void function returning a vlue - this is because yyterminate() is defined as return() */ +#pragma warning (disable: 4505) /* unreferenced local function has been removed (to be direct: yyunput()) */ + +/* include files */ +#include "parser.h" /* NOTE: make sure this matches what Bison/yacc spits out */ + +#include +#include + +/*--------------------------------** +** exteranl prototype declaration ** +**--------------------------------*/ +void MIFFMessage(char *message, int forceOutput); +void MIFFSetError(void); +char * MIFFallocString(int sizeOfString); +void MIFFfreeString(char * pointer); + +int yyparse(); + +/* prototype declaration */ +int MIFFYYInput(char *buf,int max_size); +void initParser(void); +void count(void); +void yyerror(char *err); +void open_brace(void); +void close_brace(void); +int count_brace(void); + +void printString(char *str); + +/* global vars that has to be pre-declared because it's referenced by the lexical analyzer */ +int initialCompile = 0; +int globalErrorFlag = 0; +char inFileName[512]; /* keep track of source file name for error message */ + +#undef YY_INPUT +#define YY_INPUT(buf,result,max_size) (result = MIFFYYInput(buf,max_size)) + +#define SPACE_COUNT_FOR_TAB (8) + +%} + +DIGIT [0-9] +HEXDIGIT [0-9a-fA-F] +LETTER [A-z_] +FLOATSYM (f|F|l|L) +INTSYM (u|U|l|L)* +EXP (e|E)(\+|-)? + +%% +"//"[^\n]*\n { + /* don't do count(); */ + } + +"#define"[^\n]*\n { + /* don't you love regular expression? [^\n]* everything but \n, and then end with \n */ + /* don't do count(); just like comments */ + /* return(DEFINE); <-- note: #define's are ignored in parser for they are handled via preprocessors CCCP */ + } + +\"([^\"]|(\\\"))*\" { + /* start with " then ( [^\"] | (\\\") )* which means either anything but " OR \" of multiple encounter, and then close with " */ + /* case for "string" literals */ + char *s; // allocate space for string and pass the string pointer rather then yytext + + count(); + s = MIFFallocString(strlen(yytext) + 1); + strcpy(s, yytext+1); /* strip off the double quotes */ + s[strlen(yytext+1)-1] = 0; /* strip off the ending double quotes */ + yylval.stype = s; + return(STR_LIT); + } + +"form" | +"FORM" { + count(); + return(FORM); + } + +"chunk" | +"CHUNK" { + count(); + return(CHUNK); + } + +"int32" { + count(); + return(INT32); + } +"int16" { + count(); + return(INT16); + } +"int8" { + count(); + return(INT8); + } +"uint32" { + count(); + return(UINT32); + } +"uint16" { + count(); + return(UINT16); + } +"uint8" { + count(); + return(UINT8); + } +"float" { + count(); + return(FLOAT); + } +"double" { + count(); + return(DOUBLE); + } +"string" | +"cstring" | +"CString" { + count(); + return(STRING); + } +"wstring" | +"WString" { + count(); + return(WSTRING); + } +"labelhash" { + count(); + return(LABELHASH); + } + +"sin" { + count(); + return(SIN); + } +"cos" { + count(); + return(COS); + } +"tan" { + count(); + return(TAN); + } +"asin" { + count(); + return(ASIN); + } +"acos" { + count(); + return(ACOS); + } +"atan" { + count(); + return(ATAN); + } + +"enum" { + count(); + return(ENUMSTRUCT); + } + +"includeIFF" | +"includeiff" { + count(); + return(INCLUDEIFF); + } +"include" { + count(); + return(INCLUDEBIN); + } +"#include" { + count(); + return(INCLUDESOURCE); + } +"#pragma" { + count(); + return(PRAGMA); + } +"drive" { + count(); + return(PRAGMA_DRIVE); + } +"directory" { + count(); + return(PRAGMA_DIR); + } +"filename" { + count(); + return(PRAGMA_FNAME); + } +"extension" { + count(); + return(PRAGMA_EXT); + } + +{LETTER}({LETTER}|{DIGIT})* { + /* label identifiers */ + char *s; // allocate space for string and pass the string pointer rather then yytext + + count(); + s = MIFFallocString(strlen(yytext) + 1); + strcpy(s, yytext); + yylval.stype = s; + return(IDENTIFIER); + } + +{DIGIT}*"."{DIGIT}+{FLOATSYM}? { + /* handle numericals (floats) */ + /* + * {DIGIT}*"."{DIGIT}+{FLOATSYM}? means zero or more digits . one or more digit and with/without f at the end + */ + count(); + /* make sure to store it to dtype, and use strtod to convert to double */ + yylval.dtype = strtod((char *) yytext, (char **) 0); + return(FLOAT_LIT); + } + +0[xX]{HEXDIGIT}+{INTSYM}? | +0{DIGIT}+{INTSYM}? | +{DIGIT}+{INTSYM}? { + /* handle numericals ( hex, ints) */ + /* + * 0[xX]{HEXDIGIT}+{INTSYM}? means start with 0, then X one or more digit and you can put int symbol if you want + * 0{DIGIT}+{INTSYM}? means start with 0, one ore more digit and w/or w/o int symbol + * {DIGIT}+{INTSYM}? means one or more digit and w/or w/o int symbol + */ + count(); + /* make sure to store it to ltype (long), and use strtod to convert to unsigned long */ + yylval.ltype = strtoul((char *) yytext, (char **) 0, 0); + return(LIT); + } + +'(\\.|[^\\'])+' { + /* handle 'x' - single character */ + count(); + yylval.chtype = yytext[1]; + return(CHAR_LIT); + } + +"#" { + /* #'s are used for informing the parser which file and line number it is processing (debug purpose) */ + count(); + return(POUND); + } + +">>" { + count(); + return(SHIFTRIGHT); + } +"<<" { + count(); + return(SHIFTLEFT); + } +"^^" { + count(); + return(RAISEDPOWER); + } + +"[" | +"]" | +"^" | +";" | +"," | +":" | +"=" | +"(" | +")" | +"." | +"&" | +"!" | +"~" | +"-" | +"+" | +"*" | +"/" | +"%" | +"<" | +">" | +"|" | +"?" { + /* valid operators */ + count(); + yylval.stype = yytext; + return(* yylval.stype); + } + +"{" { + count(); + open_brace(); + yylval.stype = yytext; + return(* yylval.stype); + } +"}" { + count(); + close_brace(); + yylval.stype = yytext; + return(* yylval.stype); + } + +[ \t\n\r]+ { + /* white spaces and newlines are ignored */ + count(); + } + +<> { + /* do a count on bracket matching... */ + if (0 == count_brace()) + { + if (!initialCompile && !globalErrorFlag) + MIFFMessage("mIFF successfully compiled!\n", 0); + } + + yyterminate(); /* tell yyparse() it's time to quit! DO NOT comment or delete this line! */ + } + +. { + /* anything that's not a rule from above goes here */ + count(); + yyerror((char *) yytext); + } +%% + +/*--------------------** +** C supporting codes ** +**--------------------*/ + +/*------------------** +** static variables ** +**------------------*/ +static char *MIFFInputStream; +int column = 0; +int line_num = 1; +int line_num2 = 1; +char error_line_buffer[4096]; +long brace_counter = 0; + + +/*---------------------------------------------------------------------** +** Initialize all the static variables before all calls to MIFFCompile ** +**---------------------------------------------------------------------*/ +void initParser(void) +{ + line_num = 1; + column = 0; + + brace_counter = 0; + error_line_buffer[0] = 0; + + globalErrorFlag = 0; + + memset(inFileName, 0, 512); /* make sure to change this size if the char array gets bigger... */ +} + +/*-------------------------------------------------** +** generate a dialog box to MFC to report an error ** +**-------------------------------------------------*/ +void yyerror(char *err) /* called by yyparse() */ +{ + char myString[256]; + + if (!initialCompile) + { + /* spit it out in MSDev error format */ + sprintf(myString, "\n%s(%d) : yyERROR : %s\n>>%s<<", inFileName, line_num, err, error_line_buffer); + MIFFMessage(myString, 1); + globalErrorFlag = 1; + MIFFSetError(); /* set global error flag for shell as well */ + yyterminate(); + } + +} + +/*-------------------------** +** our version of YY_INPUT ** +**-------------------------*/ +int MIFFYYInput(char *buf,int max_size) +{ + int len = strlen(MIFFInputStream); + int n = max_size < len ? max_size : len; + if (n > 0) + { + memcpy(buf,MIFFInputStream,n); + MIFFInputStream += n; + } + return(n); +} + +/*------------------------------------------------------------** +** line and column counter for error searching during compile ** +**------------------------------------------------------------*/ +void count() +{ + int i; + static char *elb = error_line_buffer; + for (i = 0; yytext[i] != '\0'; i++) + { + if (yytext[i] == '\n') + { + column = 0; + line_num++; + elb = error_line_buffer; + } + else + { + *elb++ = yytext[i]; + if (yytext[i] == '\t') + column += SPACE_COUNT_FOR_TAB - (column & (SPACE_COUNT_FOR_TAB - 1)); + else + column++; + } + *elb = 0; + } +} + +/*--------------------------------------------------------------** +** sets up current line number and filename the error came from ** +**--------------------------------------------------------------*/ +void setCurrentLineNumber(int lineNum, char * fileName, int mysteryNum) +{ + line_num = lineNum; + strcpy(inFileName, fileName); + line_num2 = mysteryNum; +} + +/*----------------------------------------------** +** MIFFCompile called by CMIFFView::OnCompile() ** +**----------------------------------------------*/ +void MIFFCompile(char *inputStream, char *inputFileName) +{ + MIFFInputStream = inputStream; + yyrestart(0); + initParser(); + initialCompile = 0; + strcpy(inFileName, inputFileName); + yyparse(); +} + +void MIFFCompileInit(char *inputStream, char *inputFileName) +{ + MIFFInputStream = inputStream; + yyrestart(0); + initParser(); + initialCompile = 1; + strcpy(inFileName, inputFileName); + yyparse(); +} + +/*---------------------------------------** +** matching of open/close brace checking ** +**---------------------------------------*/ +void open_brace(void) +{ + brace_counter++; +} + +void close_brace(void) +{ + brace_counter--; +} + +/* + * what: count_brace(): + * return: 0 == all braces matched + */ +int count_brace(void) +{ + if (0 == brace_counter) /* things are fine... */ + return(0); + + /* if this is called, we should have 0 brace counter if not, we have a mis-match*/ + if (brace_counter > 0) + { + /* a mismatch */ + yyerror("There are more OPEN brackets then closed"); + } + else if (brace_counter < 0) + { + yyerror("There are more CLOSED brackets then open"); + } + + return(-1); +} + +/*-----------------------------------------------------------------------** +** FLEX.SLK requires this prototype function so I'm forced to do this... ** +**-----------------------------------------------------------------------*/ +int yywrap() +{ + return(1); +} + +void printString(char *str) +{ + char ts[256]; + sprintf(ts, "%s - %s", str, yytext); + MIFFMessage(ts, 0); +} diff --git a/engine/client/application/Miff/src/win32/parser.yac b/engine/client/application/Miff/src/win32/parser.yac new file mode 100644 index 00000000..1bfec252 --- /dev/null +++ b/engine/client/application/Miff/src/win32/parser.yac @@ -0,0 +1,1004 @@ +%expect 1 +%{ +/*-----------------------------------------------------------------------------** +** FILE: parser.yac ** +** (c) 1998 - Bootprint GTInteractive ** +** ** +** DESCRIPTION: parser for mIFF ** +** ** +** AUTHOR: Hideki Ikeda ** +** HISTORY: ** +** ** +** Notes: companion to parser.lex ** +**-----------------------------------------------------------------------------*/ + +/*---------------** +** C declaration ** +**---------------*/ +#pragma warning (disable: 4005) /* macro redefinition - bision.simple redefines alloca() */ +#pragma warning (disable: 4127) /* conditional expression is constant - in bison.simple */ +#pragma warning (disable: 4131) /* uses old-style declarator - mostly in bison.simple */ +#pragma warning (disable: 4244) /* possible loss of data due to conversion from one type to another - bision.simple */ +#pragma warning (disable: 4701) /* local variable ('yyval' in first case) may be used without having been initialed */ +// #pragma warning (disable: 6311) /* compiler malloc.h: see previous definition of alloca() */ + +/* include files */ +#include /* for pow() and stuff */ +#include +#include /* for toupper() */ +#include /* for wide character (16bit) strings */ + +#include +#include + +/*----------------------------------------------------------------** +** debug options, turn these on to TEST ONLY! don't leave these ** +** switch on, it's annoying as hell in console mode! ** +** NOTE: if you turn YYERROR_VERBOSE on, you MUST have YYDEBUG! ** +** IMHO, it's better off using primitive printf() method to debug ** +**----------------------------------------------------------------*/ +#define YYERROR_VERBOSE 1 +#define YYDEBUG 1 + +#undef YYERROR_VERBOSE +#undef YYDEBUG + +/* external prototype declaration */ +extern void MIFFMessage(char *message); /* found in mIFF.CPP */ +extern char * MIFFallocString(int sizeOfString); +extern void MIFFfreeString(char * pointer); +extern int validateTargetFilename(char *fname, int fnameSize); /* found mIFF.CPP */ +extern void yyerror(char *); +extern int yylex(void); +extern void setCurrentLineNumber(int lineNum, char * fileName, int mysteryNum); +extern void MIFFSetIFFName(const char *newFileName); +extern void MIFFinsertForm(const char *formName); +extern void MIFFinsertChunk(const char *chunkName); +extern void MIFFinsertChunkData(void * buffer, unsigned bufferSize); +extern int MIFFloadRawData(char *fname, void * buffer, unsigned maxBufferSize); +extern void MIFFexitChunk(void); +extern void MIFFexitForm(void); +extern unsigned long MIFFgetLabelHash(char *inputStream); + +/* local prototype declaration */ +void initGlobalVars(void); +void checkArgs(void); +void checkPragmas(void); + +void includeBinary(char *fname); + +void write32(long i32); +void write16(short i16); +void write8(char i8); +void writeU32(unsigned long ui32); +void writeU16(unsigned short ui16); +void writeU8(unsigned char u8); +void writeDouble(double d); +void writeFloat(float f); +void writeString(char *s); +void writeString16(char *s); +void writeLabelHash(char *s); +void writeTag(char *tag); +void writeSize(unsigned long size); +void writeData(void *dataPtr, unsigned dataSize); + +void initSymTable(void); +long searchEnumSymbolTable(char *symString); +long getEnumValue(long index); +void addEnumSymbol(char *symString, long value); +void parseESCstring(char *str, char *targetBuffer, int sizeOfTarget); + +/*----------------------------------------------** +** Global vars used by all functions and parser ** +**----------------------------------------------*/ +char err_msg[256]; +int errorFlag; + +/*-----------------------------------------------------------------------------** +** NOTE: this symbol table is ONLY used to construct symbols for enum table!!! ** +**-----------------------------------------------------------------------------*/ +#define MAX_SYMBOLS (1024) /* total number of symbols it can grow to... */ +#define MAX_SYMCHARS (128) /* I label thee insane if you have more the 128 char for your variable! */ +struct structEnumSymTableType +{ + char symbol[MAX_SYMCHARS]; + long value; +}; + +struct structEnumSymTableType symbolEnumTable[MAX_SYMBOLS]; +unsigned currSymIndex = 0; +long lastValue = -1; +char id[MAX_SYMCHARS]; + +/* vars set by pragmas */ +#define MAX_BUFFER_SIZE (16 * 1024 * 1024) +#define MAX_STRING_SIZE (512) +char drive[8]; +char directory[MAX_STRING_SIZE/2]; +char filename[MAX_STRING_SIZE/2]; +char extension[8]; +char outFileName[MAX_STRING_SIZE]; +int usePragmas; + +/*------------------------------------------------------------------------** +** The IRONY of these so-called temp-data's that are GLOBAL is ** +** that they aren't temp if functions called within are also using it ** +** This really gives me the creeps and goosbumps! DOWN with GLOBAL VARS! ** +**------------------------------------------------------------------------*/ +int iTemp, jTemp; +char byteTemp; +short wordTemp; +char tempStr[MAX_STRING_SIZE]; + +%} + +/*--------------------** +** Bison declarations ** +**--------------------*/ +%union { + long ltype; + double dtype; + char *stype; + char chtype; + + int tokentype; +} + +/*------------------------------------------------** +** define tokens defined in lex file ** +** NOTE: all LITERALs are treated as signed long ** +** all FLOAT_LITERALs are treated as double ** +**------------------------------------------------*/ +%token CHAR_LIT +%token STR_LIT +%token IDENTIFIER +%token LIT +%token FLOAT_LIT + +/* all command tokens are type */ +%token INT32 +%token INT16 +%token INT8 +%token UINT32 +%token UINT16 +%token UINT8 +%token FLOAT +%token DOUBLE +%token STRING +%token WSTRING +%token LABELHASH + +%token FORM +%token CHUNK +%token PRAGMA +%token PRAGMA_DRIVE PRAGMA_DIR PRAGMA_FNAME PRAGMA_EXT +%token ENUMSTRUCT +%token INCLUDESOURCE +%token INCLUDEBIN +%token INCLUDEIFF +%token SIN +%token COS +%token TAN +%token ACOS +%token ASIN +%token ATAN +%token POUND +%token SHIFTRIGHT +%token SHIFTLEFT +%token RAISEDPOWER + +%% + +/*------------------------------------------------------------------------** +** Begin Grammar rules ** +** ** +** Note: if possible, always try to use left recurrsion rather then right ** +** to save stack depth... ** +**------------------------------------------------------------------------*/ +mIFFSource: + { + /* initialize some global varibles before we start */ + initGlobalVars(); + checkArgs(); + } + preprocessor + { + /* take care of any mIFF related preprocessors that we might encounter */ + checkPragmas(); + } + body + ; + +/*----------------------** +** Preprocessor handler ** +**----------------------*/ +preprocessor: { /* we don't really have to have preprocessor */} + | preprocessor pragma + | preprocessor debugInfo /* we have to have debugInfo or else pragma gets confused when it finds a # line */ + ; + +pragma: PRAGMA PRAGMA_DRIVE STR_LIT { + if (usePragmas) + { + strcpy(drive, $3); + if (strlen(drive) > 2) + { + sprintf(err_msg, "Drive [%s] is not a valid drive [must be in C: format]", drive); + yyerror(err_msg); + } + drive[1] = ':'; + drive[2] = 0; + } + MIFFfreeString($3); + } + | PRAGMA PRAGMA_DIR STR_LIT { + if (usePragmas) + { + strcpy(directory, $3); + if (directory[strlen(directory)] != '\\') + directory[strlen(directory)] = '\\'; + directory[strlen(directory) + 1] = 0; + } + MIFFfreeString($3); + } + | PRAGMA PRAGMA_FNAME STR_LIT { + if (usePragmas) + strcpy(filename, $3); + MIFFfreeString($3); + } + | PRAGMA PRAGMA_EXT STR_LIT { + if (usePragmas) + strcpy(extension, $3); + MIFFfreeString($3); + } + | PRAGMA IDENTIFIER STR_LIT { + sprintf(err_msg, "Unknown PRAGMA identifier [%s]", $2); + yyerror(err_msg); + MIFFfreeString($2); + MIFFfreeString($3); + } + ; + +/*-------------------------------------------------------** +** This is the #line pragmas in a format of: ** +** # lineNum "FileName" mysteryNumber ** +** We call setCurrentLineNumber so when an error occurs, ** +** it will be sync'd to correct filename and linenumber ** +**-------------------------------------------------------*/ +debugInfo: POUND LIT STR_LIT { setCurrentLineNumber($2, $3, 0); MIFFfreeString($3);} + | POUND LIT STR_LIT LIT { setCurrentLineNumber($2, $3, $4); MIFFfreeString($3);} + ; + +/*-----------------------** +** The main body section ** +**-----------------------*/ +body: /* body can be empty */ + | body form formbody + | body chunk chunkbody + | body enumSection + | body includesource { /* do nothing... should not exist if went thru the preprocessor */ } + | body includeIFF + | body debugInfo + ; + +/*------------------------** +** Enumeration definition ** +**------------------------*/ +enumSection: ENUMSTRUCT enumDeclare '{' enumBody '}' enumType ';' { /* enumSection */ } + ; + +enumDeclare: { /* could have no declaration */ lastValue = -1; } + | IDENTIFIER { /* enumDeclare: ID */ lastValue = -1; MIFFfreeString($1);} + ; + +enumBody: { /* enumBody: can be empty list */ } + | enumAssign { /* enumAssign */ } + | enumBody ',' enumAssign { /* enumAssign, enumBody */ } + ; + +enumAssign: IDENTIFIER '=' exprL { + addEnumSymbol($1, $3); + MIFFfreeString($1); + } + | IDENTIFIER { /* in this case, inc 1 from last count */ + addEnumSymbol($1, ++lastValue); + MIFFfreeString($1); + } + ; + +enumType: /* type declaration can be empty */ + | enumList + ; + +enumList: IDENTIFIER { /* enumList: just ID */ MIFFfreeString($1);} + | enumList ',' IDENTIFIER { /* enumList: ID, enumList */ MIFFfreeString($3);} + ; + +/*----------------------------** +** different types of include ** +**----------------------------*/ +includesource: INCLUDESOURCE STR_LIT { /* do nothing... because CCCP/preprocessor takes care of this*/ MIFFfreeString($2);} + ; + +includebin: INCLUDEBIN STR_LIT { includeBinary($2); MIFFfreeString($2);} + ; + +includeIFF: INCLUDEIFF STR_LIT { includeBinary($2); MIFFfreeString($2);} + ; + +/*------------------** +** the FORM section ** +**------------------*/ +form: FORM STR_LIT { + /* first make sure we have 4 char for FORM name */ + if (strlen($2) > 4) + { + sprintf(err_msg, "FORM name %s greater then 4 char", $2); + yyerror(err_msg); + } + else if (!errorFlag) + { + /* pack the string with ' ' (spaces) if less then 4 chars */ + strcpy(tempStr, $2); + if (strlen(tempStr) < 4) + { + /* pack the string */ + for (iTemp = strlen(tempStr);iTemp < 4; iTemp++) + { + tempStr[iTemp] = ' '; /* pack it with space */ + } + } + + /* let's make sure we don't have a smart ass who wants to do form "FORM" */ + if ((toupper(tempStr[0]) == 'F') && + (toupper(tempStr[1]) == 'O') && + (toupper(tempStr[2]) == 'R') && + (toupper(tempStr[3]) == 'M')) + { + yyerror("FORM name CANNOT BE 'FORM'... nice try bozo!"); + } + + /* FORM */ + MIFFinsertForm(tempStr); + } + MIFFfreeString($2); + } + ; + +formbody: '{' formelements '}' { if (!errorFlag) MIFFexitForm(); }; + +formelements: body { /* recursion of multiple depth in form is allowed */ } + | INCLUDEBIN STR_LIT { + yyerror("Found attempt to include binary file inside FORM\nBinary file inclusion ONLY allowed inside a CHUNK!\nError"); + MIFFfreeString($2); + } + ; + +/*-------------------** +** the CHUNK section ** +**-------------------*/ +chunk: CHUNK STR_LIT { + /* first make sure we have 4 char for CHUNK name */ + if (strlen($2) > 4) + { + sprintf(err_msg, "CHUNK name %s greater then 4 char", $2); + yyerror(err_msg); + } + else if (!errorFlag) + { + /* pack the string with ' ' (spaces) if less then 4 chars */ + strcpy(tempStr, $2); + if (strlen(tempStr) < 4) + { + /* pack the string */ + for (iTemp = strlen(tempStr);iTemp < 4; iTemp++) + { + tempStr[iTemp] = ' '; /* pack it with space */ + } + } + + /* let's make sure we don't have a smart ass who wants to do chunk "FORM" */ + if ((toupper(tempStr[0]) == 'F') && + (toupper(tempStr[1]) == 'O') && + (toupper(tempStr[2]) == 'R') && + (toupper(tempStr[3]) == 'M')) + { + yyerror("CHUNK name CANNOT BE 'FORM'... nice try bozo!"); + } + + MIFFinsertChunk(tempStr); + } + MIFFfreeString($2); + } + ; + +chunkbody: '{' chunkelements '}' { if (!errorFlag) MIFFexitChunk(); }; + +chunkelements: /* can be empty */ + | chunkelements memalloc + | chunkelements includebin + | chunkelements debugInfo + | chunkelements includeIFF { yyerror("Found attempt to include IFF (binary) file inside CHUNK\nIFF inclusion ONLY allowed outside a CHUNK!\nError"); } + ; + +memalloc: INT32 l32AllocExpr { } + | INT16 l16AllocExpr { } + | INT8 l8AllocExpr { } + | UINT32 lU32AllocExpr { } + | UINT16 lU16AllocExpr { } + | UINT8 lU8AllocExpr { } + | FLOAT fAllocExpr { } + | DOUBLE dAllocExpr { } + | LABELHASH STR_LIT { + writeLabelHash($2); + } + | STRING STR_LIT { writeString($2); + /* now, add a NULL termination for this string */ + byteTemp = 0; write8(byteTemp); + MIFFfreeString($2); + } + | WSTRING STR_LIT { writeString16($2); + /* now, add a NULL termination for this string */ + wordTemp = 0; write16(wordTemp); + MIFFfreeString($2); + } + ; + +l32AllocExpr: exprL { write32($1); } + | l32AllocExpr ',' exprL { write32($3); } + ; + +l16AllocExpr: exprL { write16((short) $1); } + | l16AllocExpr ',' exprL { write16((short) $3); } + ; + +l8AllocExpr: exprL { write8((char) $1); } + | l8AllocExpr ',' exprL { write8((char) $3); } + ; + +lU32AllocExpr: exprL { writeU32($1); } + | lU32AllocExpr ',' exprL { writeU32($3); } + ; + +lU16AllocExpr: exprL { writeU16((unsigned short) $1); } + | lU16AllocExpr ',' exprL { writeU16((unsigned short) $3); } + ; + +lU8AllocExpr: exprL { writeU8((unsigned char) $1); } + | lU8AllocExpr ',' exprL { writeU8((unsigned char) $3); } + ; + +fAllocExpr: exprD { writeFloat((float) $1); } + | fAllocExpr ',' exprD { writeFloat((float) $3); } + ; + +dAllocExpr: exprD { writeDouble($1); } + | dAllocExpr ',' exprD { writeDouble($3); } + ; + + +/*-------------------------** +** expression for integers ** +**-------------------------*/ +exprL: exprL '+' factorL { $$ = $1 + $3; } + | exprL '-' factorL { $$ = $1 - $3; } + | exprL SHIFTLEFT factorL { $$ = $1 << $3; } + | exprL SHIFTRIGHT factorL { $$ = $1 >> $3; } + | exprL '&' factorL { $$ = $1 & $3; } + | exprL '|' factorL { $$ = $1 | $3; } + | exprL '^' factorL { $$ = $1 ^ $3; } + | factorL { $$ = ($1); } + ; + +factorL: factorL '*' termL { $$ = $1 * $3; } + | factorL '/' termL { $$ = $1 / $3; } + | factorL '%' termL { $$ = $1 % $3; } + | termL { $$ = ($1); } + ; + +termL: LIT { $$ = $1; } + | '~' termL { $$ = ~$2; } /* bitwise NOT */ + | '-' termL { $$ = -$2; } /* Unary minus */ + | '+' termL { $$ = $2; } /* Unary plus */ + | '(' exprL ')' { $$ = ($2); } + | IDENTIFIER { /* assume it's enum symbol */ + $$ = (signed long) getEnumValue(searchEnumSymbolTable($1)); + MIFFfreeString($1); + } + ; + +/*-----------------------** +** expression for floats ** +**-----------------------*/ +exprD: exprD '+' factorD { $$ = $1 + $3; } + | exprD '-' factorD { $$ = $1 - $3; } + | exprD RAISEDPOWER factorD { $$ = pow($1, $3);} /* exponentiation */ + | factorD { $$ = ($1); } + ; + +factorD: factorD '*' termD { $$ = $1 * $3; } + | factorD '/' termD { $$ = $1 / $3; } + | termD { $$ = ($1); } + ; + +termD: FLOAT_LIT { $$ = $1; } + | LIT { $$ = (double) $1; } /* we should be able to handle values that are integer and treat it as float */ + | '-' termD { $$ = -$2; } /* Unary minus */ + | '+' termD { $$ = $2; } /* Unary plus */ + | '(' exprD ')' { $$ = ($2); } + | SIN '(' exprD ')' { $$ = sin( $3 ); } + | COS '(' exprD ')' { $$ = cos( $3 ); } + | TAN '(' exprD ')' { $$ = tan( $3 ); } + | ACOS '(' exprD ')' { $$ = acos( $3 ); } + | ASIN '(' exprD ')' { $$ = asin( $3 ); } + | ATAN '(' exprD ')' { $$ = atan( $3 ); } + | IDENTIFIER { /* assume it's enum symbol */ + $$ = (signed long) getEnumValue(searchEnumSymbolTable($1)); + MIFFfreeString($1); + } + ; + +%% + +/*-------------------------------------------** +** and now... the supporting C functions... ** +**-------------------------------------------*/ +void initGlobalVars(void) +{ + /* assign defaults */ + drive[0] = 0; + directory[0] = 0; + filename[0] = 0; + extension[0] = 0; + err_msg[0] = 0; + usePragmas = 1; /* default to #pragmas enabled because as a stand-alone .YAC, we have no knowledge of outFileName */ + + errorFlag = 0; + + initSymTable(); +} + +void checkPragmas(void) +{ + int indexOriginal, indexDest; + char _tempStr[512]; + + if (usePragmas) + { + /* check after pre processor if output target is still NULL */ + if (!drive[0] && !errorFlag) + { + yyerror("Drive pragma not defined"); + errorFlag = 1; + } + if (!directory[0] && !errorFlag) + { + yyerror("Directory pragma not defined"); + errorFlag = 1; + } + if (!filename[0] && !errorFlag) + { + yyerror("Filename pragma not defined"); + errorFlag = 1; + } + if (!extension[0] && !errorFlag) + { + yyerror("Extension pragma not defined"); + errorFlag = 1; + } + + if (!errorFlag) + { + /* create an output file */ + strcpy(_tempStr, directory); /* copy directory to _tempStr because we'll be messing with directory */ + for (indexOriginal = 0, indexDest = 0; indexOriginal < (int) strlen(_tempStr); indexOriginal++) + { + /* search for double-slashes and convert it to single slash */ + if ((_tempStr[indexOriginal] == '\\') && (_tempStr[indexOriginal+1] == '\\')) + { + directory[indexDest] = '\\'; + indexOriginal++; + } + else + directory[indexDest] = _tempStr[indexOriginal]; /* copy current position of _tempStr to directory */ + indexDest++; + directory[indexDest] = 0; /* force NULL termination */ + } + sprintf(outFileName, "%s%s%s%s", drive, directory, filename, extension); + } + } /* if usePragmas */ + + MIFFSetIFFName(outFileName); /* tell mIFF we want to use this filename instead of whatever it has! */ +} + +/*--------------------------------------------------------------------------------------** +** This function is called early in the process to find out if usePragma flag was set ** +** in the command line or not. If it was, mIFF already has the outfile and will stuff ** +** it into the outFileName data pool. Even if mIFF had an idea of what the output file ** +** name is, if usePragma flag returned said it is true, then #pragas in the mIFF source ** +** is used instead and overrides whatever file name it has returned. ** +** see usePragmas() for more details. ** +**--------------------------------------------------------------------------------------*/ +void checkArgs(void) +{ + /* request an external function (found in either mIFF.CPP or mIFFView.CPP) to see if pragmas and filename was set... */ + usePragmas = validateTargetFilename(outFileName, sizeof(outFileName)); +} + +/*----------------------------** +** Write to FILE functions... ** +**----------------------------*/ +void write32(long i32) +{ + MIFFinsertChunkData(&i32, sizeof(long)); +} + +void write16(short i16) +{ + MIFFinsertChunkData(&i16, sizeof(short)); +} + +void write8(char i8) +{ + MIFFinsertChunkData(&i8, sizeof(char)); +} + +void writeU32(unsigned long ui32) +{ + MIFFinsertChunkData(&ui32, sizeof(long)); +} + +void writeU16(unsigned short ui16) +{ + MIFFinsertChunkData(&ui16, sizeof(short)); +} + +void writeU8(unsigned char ui8) +{ + MIFFinsertChunkData(&ui8, sizeof(char)); +} + +void writeDouble(double d) +{ + MIFFinsertChunkData(&d, sizeof(double)); +} + +void writeFloat(float f) +{ + MIFFinsertChunkData(&f, sizeof(float)); +} + +void writeString(char *s) +{ + char tempS[MAX_STRING_SIZE]; + parseESCstring(s, tempS, MAX_STRING_SIZE); + + MIFFinsertChunkData(tempS, strlen(tempS)); +} + +void writeString16(char *s) +{ + char tempS[MAX_STRING_SIZE]; + int charCount = 0; + wchar_t wtempStr[512]; /* just to be on the safe side, allocating huge array... */ + + parseESCstring(s, tempS, MAX_STRING_SIZE); + + /* make sure string length is less then the allocated wchar size */ + if ((strlen(tempS) * sizeof(wchar_t)) > (512* sizeof(wchar_t))) + yyerror("wstring: 16bit string too long to handle in buffer!\n"); + else + { + /* call MultiByteString to WideCharString function */ + charCount = mbstowcs(wtempStr, tempS, strlen(tempS)); + writeData(wtempStr, charCount * sizeof(wchar_t)); + } +} + +void writeLabelHash(char *s) +{ + writeU32(MIFFgetLabelHash(s)); +} + +/* search from escape string such as \n and convert it to actual byte */ +void parseESCstring(char *str, char *targetBuffer, int sizeOfTarget) +{ + char *sPtr = str; + int strIndex = 0; + char numString[32]; /* hopefully, never go over 3 char i.e. \x0FF */ + int numIndex = 0; + int tempNum = 0; + int exitParser = 0; + int loopFlag = 0; + + /* memory hog but cute way to convert ascii hex to number */ + int hexTable[256]; + memset(hexTable, 0xFF, 256); + hexTable['0'] = 0x00; + hexTable['1'] = 0x01; + hexTable['2'] = 0x02; + hexTable['3'] = 0x03; + hexTable['4'] = 0x04; + hexTable['5'] = 0x05; + hexTable['6'] = 0x06; + hexTable['7'] = 0x07; + hexTable['8'] = 0x08; + hexTable['9'] = 0x09; + hexTable['A'] = 0x0A; hexTable['a'] = 0x0A; + hexTable['B'] = 0x0B; hexTable['b'] = 0x0B; + hexTable['C'] = 0x0C; hexTable['c'] = 0x0C; + hexTable['D'] = 0x0D; hexTable['d'] = 0x0D; + hexTable['E'] = 0x0E; hexTable['e'] = 0x0E; + hexTable['F'] = 0x0F; hexTable['f'] = 0x0F; + + memset(targetBuffer, 0, sizeOfTarget); + while ((*sPtr) && !exitParser) /* assume we can go until NULL termination */ + { + /* check for escape sequences */ + if (*sPtr == '\\') + { + sPtr++; /* check out next character */ + switch (tolower(*sPtr)) + { + case 'a': /* BELL */ + { + targetBuffer[strIndex++] = '\a'; + break; + } + + case 'b': /* BACKSPACE */ + { + targetBuffer[strIndex++] = '\b'; + break; + } + + case 'f': /* FORMFEED */ + { + targetBuffer[strIndex++] = '\a'; + break; + } + + case 'n': /* NEWLINE */ + { + targetBuffer[strIndex++] = '\n'; + break; + } + + case 'r': /* CARRIAGE RETURN */ + { + targetBuffer[strIndex++] = '\r'; + break; + } + + case 't': /* TAB */ + { + targetBuffer[strIndex++] = '\t'; + break; + } + + case 'v': /* VERTICAL TAB */ + { + targetBuffer[strIndex++] = '\v'; + break; + } + + case '\'': /* SINGLE QUOTE */ + { + targetBuffer[strIndex++] = '\''; + break; + } + + case '\"': /* DOUBLE QUOTE */ + { + targetBuffer[strIndex++] = '\"'; + break; + } + + case '\\': /* BACKSLASH */ + { + targetBuffer[strIndex++] = '\\'; + break; + } + + case '?': /* LITERAL QUESTION MARK */ + { + targetBuffer[strIndex++] = '\?'; + break; + } + + case '0': /* ASCII octal */ + case '1': /* ASCII octal */ + case '2': /* ASCII octal */ + case '3': /* ASCII octal */ + case '4': /* ASCII octal */ + case '5': /* ASCII octal */ + case '6': /* ASCII octal */ + case '7': /* ASCII octal */ + { + /* read until non-digit encountered - if octal value is greater then \377 (400 or more) it is bigger the 255! */ + numIndex = 0; + + while ((*sPtr >= '0') && (*sPtr <= '7') && (*sPtr)) + { + numString[numIndex++] = *sPtr; + sPtr++; + if (numIndex > 3) + { + sprintf(err_msg, "Escape sequence Octal numbers greater then\noctal o400 (256 decimal)! [more then 3 digits]", *sPtr); + yyerror(err_msg); + exitParser = 1; + } + } + + /* now we should have string of octal number in numString */ + if (!exitParser) + { + if (numIndex == 3) + tempNum = (hexTable[numString[0]] * 64) + (hexTable[numString[1]] * 8) + hexTable[numString[2]]; + else if (numIndex == 2) + tempNum = (hexTable[numString[0]] * 8) + hexTable[numString[1]]; + else + tempNum = hexTable[numString[0]]; + + if (tempNum > 255) + { + sprintf(err_msg, "Escape sequence Octal numbers greater then\noctal o400 (256 decimal)!", tempNum); + yyerror(err_msg); + exitParser = 1; + } + + if (!exitParser) + targetBuffer[strIndex++] = tempNum; + } + break; + } + + case 'x': /* ASCII hex */ + { + /* we have to make sure the hex value is less then 256! */ + numIndex = 0; + loopFlag = 1; + sPtr++; /* skip the 'x' */ + + while ((0xFF != hexTable[*sPtr]) && (*sPtr)) + { + numString[numIndex++] = *sPtr; + sPtr++; + if (numIndex > 3) + { + sprintf(err_msg, "Escape sequence HEX numbers greater then 0x100\n(256 decimal)! [more then 3 digits]", *sPtr); + yyerror(err_msg); + exitParser = 1; + } + } + + if (!exitParser) + { + if (numIndex == 3) + tempNum = (hexTable[numString[0]] * 0x100) + (hexTable[numString[1]] * 0x10) + hexTable[numString[2]]; + else if (numIndex == 2) + tempNum = (hexTable[numString[0]] * 0x10) + hexTable[numString[1]]; + else + tempNum = hexTable[numString[0]]; + } + + if (tempNum > 255) + { + sprintf(err_msg, "Escape sequence HEX numbers greater then 0x100\n(256 decimal)!", *sPtr); + yyerror(err_msg); + exitParser = 1; + } + + if (!exitParser) + targetBuffer[strIndex++] = tempNum; + + break; + } + + case '8': + case '9': + { + /* they tried to do octal mode, but 8 and 9 is not in the definition of octal */ + yyerror("Attempted to enter escape sequence with non-octal value"); + exitParser = 1; + break; + } + + default: + sprintf(err_msg, "Unknown ESCape sequence \\%c found in string.\n", *sPtr); + yyerror(err_msg); + exitParser = 1; + break; + } + } + else + targetBuffer[strIndex++] = *sPtr; + sPtr++; + } +} + + +void writeData(void *dataPtr, unsigned dataSize) +{ + MIFFinsertChunkData(dataPtr, dataSize); +} + + +/* NOTE: includeBinary modifies fsize for the caller to access for adjusting the chunk size */ +void includeBinary(char *fname) +{ + char buffer[MAX_BUFFER_SIZE+1]; + int fsize = 0; + + fsize = MIFFloadRawData(fname, buffer, MAX_BUFFER_SIZE); + MIFFinsertChunkData(buffer, fsize); +} + +/*--------------------------------------------------------------------------------** +** Following functions below are all used for constructing, adding, and searching ** +** the symbol table created by enum keyword. It is at this moment, set in a way ** +** that if two identical symbols are added to the list, it will use the first ** +** symbol added to the list and ignores the rest (because of forward search) ** +**--------------------------------------------------------------------------------*/ +void initSymTable(void) +{ + memset(symbolEnumTable, 0, sizeof(struct structEnumSymTableType) * MAX_SYMBOLS); + currSymIndex = 0; + lastValue = -1; +} + +/* Searches thru the symbol table and returns the index */ +long searchEnumSymbolTable(char *symString) +{ + long index = 0; + int found = 0; + while ((0 != symbolEnumTable[index].symbol[0]) && !found) + { + + if (0 == strcmp(symbolEnumTable[index].symbol, symString)) + { + found = 1; + break; + } + else + index++; + } + + if (!found) + { + index = -1; + sprintf(err_msg, "Undefined symbol %s", symString); + yyerror(err_msg); + } + + return(index); +} + +long getEnumValue(long index) +{ + if (index >= 0) + return(symbolEnumTable[index].value); + return(-1); +} + +void addEnumSymbol(char *symString, long value) +{ + if (MAX_SYMCHARS < strlen(symString)) + { + /* somebody insane decided to use variable longer then max size! */ + sprintf(err_msg, "%s is longer then %d characters! [value: %d]", symString, MAX_SYMCHARS, value); + yyerror(err_msg); + } + else + { + strcpy(symbolEnumTable[currSymIndex].symbol, symString); + symbolEnumTable[currSymIndex].value = value; + lastValue = value; + currSymIndex++; + if (MAX_SYMBOLS < currSymIndex) + { + sprintf(err_msg, "Symbol table reached maximum size of %d", MAX_SYMBOLS); + yyerror(err_msg); + } + } +} diff --git a/engine/server/application/CentralServer/src/win32/FirstCentralServer.cpp b/engine/server/application/CentralServer/src/win32/FirstCentralServer.cpp new file mode 100644 index 00000000..509e7da9 --- /dev/null +++ b/engine/server/application/CentralServer/src/win32/FirstCentralServer.cpp @@ -0,0 +1,5 @@ +// CentralServerPrecompiledHeader.cpp +// copyright 2001 Verant Interactive +// Author: Justin Randall + +#include "FirstCentralServer.h" diff --git a/engine/server/application/CentralServer/src/win32/WinMain.cpp b/engine/server/application/CentralServer/src/win32/WinMain.cpp new file mode 100644 index 00000000..6c760f37 --- /dev/null +++ b/engine/server/application/CentralServer/src/win32/WinMain.cpp @@ -0,0 +1,84 @@ +#include "FirstCentralServer.h" +#include "ConfigCentralServer.h" +#include "CentralServer.h" + +#include "sharedCompression/SetupSharedCompression.h" +#include "sharedDebug/SetupSharedDebug.h" +#include "sharedFile/SetupSharedFile.h" +#include "sharedFoundation/SetupSharedFoundation.h" +#include "sharedNetworkMessages/SetupSharedNetworkMessages.h" +#include "sharedRandom/SetupSharedRandom.h" +#include "sharedThread/SetupSharedThread.h" + +#include +#include + +//_____________________________________________________________________ +/* +int WINAPI WinMain( + HINSTANCE hInstance, // handle to current instance + HINSTANCE hPrevInstance, // handle to previous instance + LPSTR lpCmdLine, // pointer to command line + int nCmdShow // show state of window + ) + */ +int main(int argc, char ** argv) +{ //lint !e1065 //WinMain conflicts with clib + int i = 0; + +// UNREF(hPrevInstance); +// UNREF(nCmdShow); + + SetupSharedThread::install(); + SetupSharedDebug::install(1024); + + //-- setup foundation + SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game); + + // command line hack + std::string cmdLine; + for(i = 1; i < argc; ++i) + { + cmdLine += argv[i]; + if(i + 1 < argc) + { + cmdLine += " "; + } + } +// setupFoundationData.hInstance = hInstance; + setupFoundationData.commandLine = cmdLine.c_str(); + setupFoundationData.createWindow = false; + setupFoundationData.clockUsesSleep = true; + + SetupSharedFoundation::install (setupFoundationData); + + SetupSharedCompression::install(); + + SetupSharedFile::install(false); + + SetupSharedNetworkMessages::install(); + + ConfigCentralServer::install(); + + cmdLine = ""; + // now, the real command line + for(i = 0; i < argc; ++i) + { + cmdLine += argv[i]; + if(i + 1 < argc) + { + cmdLine += " "; + } + } + + CentralServer::getInstance().setCommandLine(cmdLine); + + //-- run game + SetupSharedFoundation::callbackWithExceptionHandling(CentralServer::run); + + SetupSharedFoundation::remove(); + + return 0; +} + +//_____________________________________________________________________ diff --git a/engine/server/application/ChatServer/src/win32/WinMain.cpp b/engine/server/application/ChatServer/src/win32/WinMain.cpp new file mode 100644 index 00000000..8d0ac8fc --- /dev/null +++ b/engine/server/application/ChatServer/src/win32/WinMain.cpp @@ -0,0 +1,42 @@ +#include "FirstChatServer.h" +#include "ConfigChatServer.h" +#include "ChatServer.h" +#include "sharedCompression/SetupSharedCompression.h" +#include "sharedDebug/SetupSharedDebug.h" +#include "sharedFoundation/SetupSharedFoundation.h" +#include "sharedNetworkMessages/SetupSharedNetworkMessages.h" +#include "sharedThread/SetupSharedThread.h" + +#include +#include + +int main( int argc, char ** argv ) +{ + SetupSharedThread::install(); + SetupSharedDebug::install(1024); + + //-- setup foundation + SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game); + + //setupFoundationData.hInstance = hInstance; + setupFoundationData.argc = argc; + setupFoundationData.argv = argv; + setupFoundationData.createWindow = false; + setupFoundationData.clockUsesSleep = true; + + SetupSharedFoundation::install (setupFoundationData); + + SetupSharedCompression::install(); + + SetupSharedNetworkMessages::install(); + + //-- setup game server + ConfigChatServer::install (); + + //-- run game + SetupSharedFoundation::callbackWithExceptionHandling(ChatServer::run); + + SetupSharedFoundation::remove(); + + return 0; +} diff --git a/engine/server/application/ConnectionServer/src/win32/FirstConnectionServer.cpp b/engine/server/application/ConnectionServer/src/win32/FirstConnectionServer.cpp new file mode 100644 index 00000000..137cad41 --- /dev/null +++ b/engine/server/application/ConnectionServer/src/win32/FirstConnectionServer.cpp @@ -0,0 +1 @@ +#include "FirstConnectionServer.h" diff --git a/engine/server/application/ConnectionServer/src/win32/WinMain.cpp b/engine/server/application/ConnectionServer/src/win32/WinMain.cpp new file mode 100644 index 00000000..236a8ebf --- /dev/null +++ b/engine/server/application/ConnectionServer/src/win32/WinMain.cpp @@ -0,0 +1,58 @@ +#include "FirstConnectionServer.h" +#include "ConfigConnectionServer.h" +#include "ConnectionServer.h" + +#include "sharedCompression/SetupSharedCompression.h" +#include "sharedDebug/SetupSharedDebug.h" +#include "sharedFile/SetupSharedFile.h" +#include "sharedFoundation/PerThreadData.h" +#include "sharedFoundation/SetupSharedFoundation.h" +#include "sharedNetworkMessages/SetupSharedNetworkMessages.h" +#include "sharedRandom/SetupSharedRandom.h" +#include "sharedThread/SetupSharedThread.h" + +#include + +int main(int argc, char ** argv) +{ + // command line hack + std::string cmdLine; + for(int i = 1; i < argc; ++i) + { + cmdLine += argv[i]; + if(i + 1 < argc) + { + cmdLine += " "; + } + } + + SetupSharedThread::install(); + SetupSharedDebug::install(1024); + +//-- setup foundation + SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game); + +// setupFoundationData.hInstance = hInstance; + setupFoundationData.commandLine = cmdLine.c_str(); + setupFoundationData.createWindow = false; + setupFoundationData.clockUsesSleep = true; + + SetupSharedFoundation::install (setupFoundationData); + SetupSharedFile::install(false); + SetupSharedCompression::install(); + + SetupSharedNetworkMessages::install(); + SetupSharedRandom::install(int(time(NULL))); + + //-- setup game server + ConfigConnectionServer::install (); + + ConnectionServer::install(); + //-- run game + SetupSharedFoundation::callbackWithExceptionHandling(ConnectionServer::run); + ConnectionServer::remove(); + ConfigConnectionServer::remove(); + SetupSharedFoundation::remove(); + PerThreadData::threadRemove(); + return 0; +} diff --git a/engine/server/application/LogServer/src/win32/LoggingServerApiWrapper.cpp b/engine/server/application/LogServer/src/win32/LoggingServerApiWrapper.cpp new file mode 100644 index 00000000..78b377f5 --- /dev/null +++ b/engine/server/application/LogServer/src/win32/LoggingServerApiWrapper.cpp @@ -0,0 +1,16 @@ +// LoggingServerApiWrapper.cpp +// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved. +// Author: Justin Randall + +// This is a wrapper cpp to workaround PCH and RSP's. While a DSP +// may exclude a single file from using precompiled headers, the +// dsp builder has no way (I know of) to honor this behavior. +//----------------------------------------------------------------------- + +#include "FirstLogServer.h" +//#include "LoggingServerApi.cpp" + +//----------------------------------------------------------------------- + +//----------------------------------------------------------------------- + diff --git a/engine/server/application/LogServer/src/win32/WinMain.cpp b/engine/server/application/LogServer/src/win32/WinMain.cpp new file mode 100644 index 00000000..21d829c4 --- /dev/null +++ b/engine/server/application/LogServer/src/win32/WinMain.cpp @@ -0,0 +1,55 @@ +// ====================================================================== +// +// WinMain.cpp +// +// Copyright 2002 Sony Online Entertainment +// +// ====================================================================== + +#include "FirstLogServer.h" +#include "sharedFoundation/FirstSharedFoundation.h" +#include "LogServer.h" + +#include "sharedCompression/SetupSharedCompression.h" +#include "sharedDebug/SetupSharedDebug.h" +#include "sharedFile/SetupSharedFile.h" +#include "sharedFoundation/SetupSharedFoundation.h" +#include "sharedNetworkMessages/SetupSharedNetworkMessages.h" +#include "sharedThread/SetupSharedThread.h" + +// ====================================================================== + +int main(int argc, char **argv) +{ + SetupSharedThread::install(); + SetupSharedDebug::install(1024); + + //-- setup foundation + SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game); + + setupFoundationData.argc = argc; + setupFoundationData.argv = argv; + setupFoundationData.createWindow = false; + setupFoundationData.clockUsesSleep = true; + + SetupSharedFoundation::install(setupFoundationData); + + SetupSharedCompression::install(); + + SetupSharedFile::install(false); + SetupSharedNetworkMessages::install(); + + //-- setup server + LogServer::install(); + + //-- run server + SetupSharedFoundation::callbackWithExceptionHandling(LogServer::run); + + LogServer::remove(); + SetupSharedFoundation::remove(); + SetupSharedThread::remove(); + + return 0; +} + +// ====================================================================== diff --git a/engine/server/application/LoginServer/src/win32/FirstLoginServer.cpp b/engine/server/application/LoginServer/src/win32/FirstLoginServer.cpp new file mode 100644 index 00000000..199562bb --- /dev/null +++ b/engine/server/application/LoginServer/src/win32/FirstLoginServer.cpp @@ -0,0 +1 @@ +#include "FirstLoginServer.h" diff --git a/engine/server/application/LoginServer/src/win32/WinMain.cpp b/engine/server/application/LoginServer/src/win32/WinMain.cpp new file mode 100644 index 00000000..f5c7056c --- /dev/null +++ b/engine/server/application/LoginServer/src/win32/WinMain.cpp @@ -0,0 +1,46 @@ +#include "FirstLoginServer.h" +#include "ConfigLoginServer.h" +#include "LoginServer.h" + +#include "sharedCompression/SetupSharedCompression.h" +#include "sharedDebug/SetupSharedDebug.h" +#include "sharedFile/SetupSharedFile.h" +#include "sharedFoundation/SetupSharedFoundation.h" +#include "sharedNetworkMessages/SetupSharedNetworkMessages.h" +#include "sharedRandom/SetupSharedRandom.h" +#include "sharedThread/SetupSharedThread.h" + +#include + +int main(int argc, char **argv) +{ + + SetupSharedThread::install(); + SetupSharedDebug::install(1024); + + //-- setup foundation + SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game); + + setupFoundationData.argc = argc; + setupFoundationData.argv = argv; + setupFoundationData.createWindow = false; + + SetupSharedFoundation::install (setupFoundationData); + SetupSharedNetworkMessages::install(); + + SetupSharedCompression::install(); + + SetupSharedFile::install(false); + + SetupSharedRandom::install(time(NULL)); + + //-- setup game server + ConfigLoginServer::install (); + + //-- run game + SetupSharedFoundation::callbackWithExceptionHandling(LoginServer::run); + + SetupSharedFoundation::remove(); + + return 0; +} diff --git a/engine/server/application/MetricsServer/src/win32/WinMain.cpp b/engine/server/application/MetricsServer/src/win32/WinMain.cpp new file mode 100644 index 00000000..5955efba --- /dev/null +++ b/engine/server/application/MetricsServer/src/win32/WinMain.cpp @@ -0,0 +1,91 @@ +#include "sharedFoundation/FirstSharedFoundation.h" + +#include "ConfigMetricsServer.h" +#include "MetricsServer.h" + +#include "sharedCompression/SetupSharedCompression.h" +#include "sharedDebug/SetupSharedDebug.h" +#include "sharedFile/SetupSharedFile.h" +#include "sharedFoundation/Os.h" +#include "sharedFoundation/SetupSharedFoundation.h" +#include "sharedNetwork/NetworkHandler.h" +#include "sharedNetwork/SetupSharedNetwork.h" +#include "sharedNetworkMessages/SetupSharedNetworkMessages.h" +#include "sharedRandom/SetupSharedRandom.h" +#include "sharedThread/SetupSharedThread.h" + +#include + +// ====================================================================== + +int main(int argc, char ** argv) +{ + SetupSharedThread::install(); + SetupSharedDebug::install(1024); + + //-- setup foundation + SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game); + + // command line hack + std::string cmdLine; + for(int i = 1; i < argc; ++i) + { + cmdLine += argv[i]; + if(i + 1 < argc) + { + cmdLine += " "; + } + } + + setupFoundationData.commandLine = cmdLine.c_str(); + setupFoundationData.createWindow = false; + setupFoundationData.clockUsesSleep = true; + + SetupSharedFoundation::install (setupFoundationData); + + { + //SetupSharedObject::Data data; + //SetupSharedObject::setupDefaultGameData(data); + //SetupSharedObject::install(data); + } + SetupSharedCompression::install(); + SetupSharedFile::install(true, 32); + + SetupSharedNetwork::SetupData networkSetupData; + SetupSharedNetwork::getDefaultServerSetupData(networkSetupData); + SetupSharedNetwork::install(networkSetupData); + + SetupSharedRandom::install(static_cast(time(NULL))); //lint !e1924 !e64 // NULL is a C-Style cast? + + //Os::setProgramName("MetricsServer"); + //setup the server + ConfigMetricsServer::install(); + + //set command line + cmdLine = setupFoundationData.commandLine; + size_t firstArg = cmdLine.find(" ", 0); + size_t lastSlash = 0; + size_t nextSlash = 0; + while(nextSlash < firstArg) + { + nextSlash = cmdLine.find("/", lastSlash); + if(nextSlash == cmdLine.npos || nextSlash >= firstArg) //lint !e1705 static class members may be accessed by the scoping operator (huh?) + break; + lastSlash = nextSlash + 1; + } + cmdLine = cmdLine.substr(lastSlash); + MetricsServer::setCommandLine(cmdLine); + + + //-- run game + NetworkHandler::install(); + MetricsServer::install(); + MetricsServer::run(); + MetricsServer::remove(); + NetworkHandler::remove(); + SetupSharedFoundation::remove(); + + return 0; +} + + diff --git a/engine/server/application/PlanetServer/src/win32/FirstPlanetServer.cpp b/engine/server/application/PlanetServer/src/win32/FirstPlanetServer.cpp new file mode 100644 index 00000000..97e05471 --- /dev/null +++ b/engine/server/application/PlanetServer/src/win32/FirstPlanetServer.cpp @@ -0,0 +1,8 @@ +// ====================================================================== +// +// FirstPlanetServer.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "FirstPlanetServer.h" diff --git a/engine/server/application/PlanetServer/src/win32/WinMain.cpp b/engine/server/application/PlanetServer/src/win32/WinMain.cpp new file mode 100644 index 00000000..f153fee1 --- /dev/null +++ b/engine/server/application/PlanetServer/src/win32/WinMain.cpp @@ -0,0 +1,67 @@ +#include "FirstPlanetServer.h" +#include "ConfigPlanetServer.h" +#include "PlanetServer.h" + +#include "sharedCompression/SetupSharedCompression.h" +#include "sharedDebug/SetupSharedDebug.h" +#include "sharedFile/SetupSharedFile.h" +#include "sharedFoundation/Os.h" +#include "sharedFoundation/SetupSharedFoundation.h" +#include "sharedLog/SetupSharedLog.h" +#include "sharedNetwork/SetupSharedNetwork.h" +#include "sharedNetworkMessages/SetupSharedNetworkMessages.h" +#include "sharedRandom/SetupSharedRandom.h" +#include "sharedThread/SetupSharedThread.h" +#include "sharedUtility/SetupSharedUtility.h" + +#include + +//_____________________________________________________________________ +int main(int argc, char ** argv) +{ + SetupSharedThread::install(); + SetupSharedDebug::install(1024); + + //-- setup foundation + SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game); + + setupFoundationData.argc = argc; + setupFoundationData.argv = argv; + setupFoundationData.createWindow = false; + setupFoundationData.clockUsesSleep = true; + + SetupSharedFoundation::install (setupFoundationData); + + SetupSharedCompression::install(); + SetupSharedFile::install(false); + + SetupSharedNetwork::SetupData networkSetupData; + SetupSharedNetwork::getDefaultServerSetupData(networkSetupData); + SetupSharedNetwork::install(networkSetupData); + + SetupSharedNetworkMessages::install(); + + SetupSharedRandom::install(int(time(NULL))); + + SetupSharedUtility::Data sharedUtilityData; + SetupSharedUtility::setupGameData (sharedUtilityData); + SetupSharedUtility::install (sharedUtilityData); + + //-- setup server + ConfigPlanetServer::install (); + + char tmp[92]; + sprintf(tmp, "PlanetServer:%d", Os::getProcessId()); + SetupSharedLog::install(tmp); + + //-- run server + SetupSharedFoundation::callbackWithExceptionHandling(PlanetServer::run); + + SetupSharedLog::remove(); + SetupSharedFoundation::remove(); + SetupSharedThread::remove(); + + return 0; +} + +//_____________________________________________________________________ diff --git a/engine/server/application/ServerConsole/src/win32/main.cpp b/engine/server/application/ServerConsole/src/win32/main.cpp new file mode 100644 index 00000000..3de57087 --- /dev/null +++ b/engine/server/application/ServerConsole/src/win32/main.cpp @@ -0,0 +1,59 @@ +// main.cpp +// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved. +// Author: Justin Randall + +//----------------------------------------------------------------------- + +#include "FirstServerConsole.h" + +#include "sharedFoundation/FirstSharedFoundation.h" +#include "sharedCompression/SetupSharedCompression.h" +#include "sharedDebug/SetupSharedDebug.h" +#include "sharedFile/SetupSharedFile.h" +#include "sharedFoundation/ConfigFile.h" +#include "sharedFoundation/SetupSharedFoundation.h" +#include "sharedNetwork/SetupSharedNetwork.h" +#include "sharedNetwork/NetworkHandler.h" +#include "sharedNetworkMessages/SetupSharedNetworkMessages.h" +#include "sharedThread/SetupSharedThread.h" +#include "ServerConsole.h" +#include "ConfigServerConsole.h" + +//----------------------------------------------------------------------- + +int main(int argc, char ** argv) +{ + SetupSharedThread::install(); + SetupSharedDebug::install(1024); + + //-- setup foundation + SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game); + + setupFoundationData.argc = argc; + setupFoundationData.argv = argv; + setupFoundationData.clockUsesSleep = true; + setupFoundationData.createWindow = false; + SetupSharedFoundation::install (setupFoundationData); + + SetupSharedCompression::install(); + SetupSharedNetworkMessages::install(); + + SetupSharedNetwork::SetupData networkSetupData; + SetupSharedNetwork::getDefaultClientSetupData(networkSetupData); + SetupSharedNetwork::install(networkSetupData); + NetworkHandler::install(); + + ConfigServerConsole::install(); + + //-- run server + SetupSharedFoundation::callbackWithExceptionHandling(ServerConsole::run); + + NetworkHandler::remove(); + SetupSharedFoundation::remove(); + SetupSharedThread::remove(); + + return 0; +} + +//----------------------------------------------------------------------- + diff --git a/engine/server/application/TaskManager/src/win32/ConsoleInput.cpp b/engine/server/application/TaskManager/src/win32/ConsoleInput.cpp new file mode 100644 index 00000000..dfd6c431 --- /dev/null +++ b/engine/server/application/TaskManager/src/win32/ConsoleInput.cpp @@ -0,0 +1,22 @@ +// ConsoleInput.cpp +// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved. +// Author: Justin Randall + +//----------------------------------------------------------------------- + +#include "FirstTaskManager.h" +#include "Console.h" +#include + +//----------------------------------------------------------------------- + +const char Console::getNextChar() +{ + char result = 0; + if(_kbhit()) + result = static_cast(_getche()); + return result; +} + +//----------------------------------------------------------------------- + diff --git a/engine/server/application/TaskManager/src/win32/EnvironmentVariable.cpp b/engine/server/application/TaskManager/src/win32/EnvironmentVariable.cpp new file mode 100644 index 00000000..017b221e --- /dev/null +++ b/engine/server/application/TaskManager/src/win32/EnvironmentVariable.cpp @@ -0,0 +1,33 @@ +#include "FirstTaskManager.h" + +namespace EnvironmentVariable +{ + bool addToEnvironmentVariable(const char* key, const char* value) + { + bool retval = false; + char oldValue[256]; + DWORD tmp = GetEnvironmentVariable(key, oldValue, sizeof(oldValue)); + if (tmp != 0) + { + std::string s(oldValue); + s += ";"; + s += value; + + //Bad things happen if the first character happens to be ; (ie from an empty environment string) + const char* newValue = s.c_str(); + if (newValue[0] == ';') + ++newValue; + + retval = (SetEnvironmentVariable(key, newValue) != 0); + } + else + { + retval = (SetEnvironmentVariable(key, value) != 0); + } + return retval; + } + bool setEnvironmentVariable(const char* key, const char* value) + { + return (SetEnvironmentVariable(key, value) != 0); + } +}; diff --git a/engine/server/application/TaskManager/src/win32/ProcessSpawner.cpp b/engine/server/application/TaskManager/src/win32/ProcessSpawner.cpp new file mode 100644 index 00000000..b544a301 --- /dev/null +++ b/engine/server/application/TaskManager/src/win32/ProcessSpawner.cpp @@ -0,0 +1,153 @@ +#include "FirstTaskManager.h" +#include "sharedFoundation/FirstSharedFoundation.h" +#include "ProcessSpawner.h" +#include +#include +#include "TaskManager.h" + +#include + +uint32 ProcessSpawner::prefix; +std::map procById; + +//----------------------------------------------------------------------- + +bool tokenize (const std::string & str, std::vector & result) +{ + size_t end_pos = 0; + size_t start_pos = 0; + + result.clear (); + + for (;;) + { + if (end_pos >= str.size ()) + break; + + start_pos = str.find_first_not_of (' ', end_pos); + + if (start_pos == str.npos) + break; + + //---------------------------------------------------------------------- + + if (str [start_pos] == '\"') + { + if (++start_pos >= str.size ()) + break; + end_pos = str.find_first_of ('\"', start_pos); + } + else + end_pos = str.find_first_of (' ', start_pos); + + //---------------------------------------------------------------------- + + if (start_pos == end_pos) + break; + + if (end_pos == str.npos) + { + result.push_back (str.substr (start_pos)); + break; + } + else + result.push_back (str.substr (start_pos, end_pos - start_pos)); + + ++start_pos; + } + + return true; +} + +uint32 ProcessSpawner::execute(const std::string & processName, const std::vector & parameters) +{ + STARTUPINFO si; + PROCESS_INFORMATION pi; + char cmd[1024] = {"\0"}; + std::string cmdLine; + + cmdLine = processName.c_str(); + cmdLine += " "; + std::vector::const_iterator i; + for(i = parameters.begin(); i != parameters.end(); ++i) + { + cmdLine += (*i).c_str(); + cmdLine += " "; + } + + _snprintf(cmd, 1024, "%s.exe", processName.c_str()); +// _snprintf(cmd, 1024, "%s", processName.c_str()); + memset(&si, 0, sizeof(si)); + memset(&pi, 0, sizeof(pi)); + + si.cb = sizeof(si); + + const int result = CreateProcess(cmd, const_cast(cmdLine.c_str()), NULL, NULL, false, 0, 0, 0, &si, &pi); + UNREF (result); + +#ifdef _DEBUG + if (!result) + { + DWORD iErr = GetLastError(); + char * errStr = strerror(iErr); + DEBUG_REPORT_LOG(true, ("ProcessSpawner: %s - %s\n", cmd, errStr)); + } +#endif + + procById.insert(std::pair(pi.dwProcessId, pi.hProcess)); + return pi.dwProcessId; +} + +//----------------------------------------------------------------------- + +uint32 ProcessSpawner::execute(const std::string & cmd) +{ + std::vector args; + size_t firstArg = cmd.find_first_of(" "); + std::string processName; + if(firstArg < cmd.size()) + { + std::string a = cmd.substr(firstArg + 1); + tokenize(a, args); + processName = cmd.substr(0, firstArg); + } + else + { + processName = cmd; + } + return execute(processName, args); +} + +//----------------------------------------------------------------------- + +bool ProcessSpawner::isProcessActive(uint32 pid) +{ + bool result = false; + std::map::const_iterator f = procById.find(pid); + if(f != procById.end()) + { + DWORD exitCode; + GetExitCodeProcess((*f).second, &exitCode); + result = (exitCode == STILL_ACTIVE); + } + return result; +} + +//----------------------------------------------------------------------- + +void ProcessSpawner::kill(uint32 pid) +{ + HANDLE p = OpenProcess(PROCESS_TERMINATE, false, (DWORD)pid); + if(p) + TerminateProcess(p, 0); +} + +//----------------------------------------------------------------------- + +void ProcessSpawner::forceCore(const unsigned long pid) +{ + ProcessSpawner::kill(pid); +} + +//----------------------------------------------------------------------- + diff --git a/engine/server/application/TaskManager/src/win32/TaskManagerSysInfo.cpp b/engine/server/application/TaskManager/src/win32/TaskManagerSysInfo.cpp new file mode 100644 index 00000000..feadf4f6 --- /dev/null +++ b/engine/server/application/TaskManager/src/win32/TaskManagerSysInfo.cpp @@ -0,0 +1,147 @@ +// TaskManagerSysInfo.cpp +// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved. +// Author: Justin Randall + +//----------------------------------------------------------------------- + +#include "FirstTaskManager.h" +#include "TaskManagerSysInfo.h" +#pragma warning ( disable : 4201) +#include +#include +//----------------------------------------------------------------------- + +TaskManagerSysInfo::TaskManagerSysInfo() : +averageScore() +{ + update(); +} + +//----------------------------------------------------------------------- + +TaskManagerSysInfo::TaskManagerSysInfo(const TaskManagerSysInfo &) +{ + +} + +//----------------------------------------------------------------------- + +TaskManagerSysInfo::~TaskManagerSysInfo() +{ +} + +//----------------------------------------------------------------------- + +TaskManagerSysInfo & TaskManagerSysInfo::operator = (const TaskManagerSysInfo & rhs) +{ + if(this != &rhs) + { + // make assignments if right hand side is not this instance + } + return *this; +} + +//----------------------------------------------------------------------- + +const float TaskManagerSysInfo::getScore() const +{ + std::list::const_iterator i; + float avg = 0.0f; + for(i = averageScore.begin(); i != averageScore.end(); ++i) + { + avg += (*i); + } + avg = avg / averageScore.size(); + return avg; +} + +//----------------------------------------------------------------------- + +void TaskManagerSysInfo::update() +{ + static int64 activeTime[2] = {0}; + static int64 currentTime[2] = {0}; + + float currentScore = 0.0f; + activeTime[0] = activeTime[1]; + currentTime[0] = currentTime[1]; + activeTime[1] = 0; + + HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0); + double procAvg = 0.0f; + + MEMORYSTATUS memStat; + GlobalMemoryStatus(&memStat); + + currentScore = static_cast(static_cast(memStat.dwMemoryLoad) * 0.005f); + if(hProcessSnap != INVALID_HANDLE_VALUE) + { + PROCESSENTRY32 pe32 = {0}; + pe32.dwSize = sizeof(PROCESSENTRY32); + if (Process32First(hProcessSnap, &pe32)) + { + do + { + HANDLE proc = OpenProcess(PROCESS_QUERY_INFORMATION, false, pe32.th32ProcessID); + // some stuf with the enumerated processes + FILETIME createTime = {0}; + FILETIME exitTime = {0}; + FILETIME kernelTime = {0}; + FILETIME userTime = {0}; + GetProcessTimes(proc, &createTime, &exitTime, &kernelTime, &userTime); + int64 totals; + + // SDK docs say: + // It is not recommended that you add and subtract values + // from the FILETIME structure to obtain relative times. Instead, you should + // Copy the resulting FILETIME structure to a ULARGE_INTEGER structure. + // Use normal 64-bit arithmetic on the ULARGE_INTEGER value. + int64 c; + int64 e; + int64 k; + int64 u; + memcpy(&c, &createTime, sizeof(int64)); + memcpy(&e, &exitTime, sizeof(int64)); + memcpy(&k, &kernelTime, sizeof(int64)); + memcpy(&u, &userTime, sizeof(int64)); + + totals = k + u; + + FILETIME fst; + SYSTEMTIME st; + GetSystemTime(&st); + SystemTimeToFileTime(&st, &fst); + + int64 runTime; + memcpy(&runTime, &fst, sizeof(int64)); + runTime = runTime - c; + + if(c || e || k || u) + { + activeTime[1] += k + e; + } + + } + while (Process32Next(hProcessSnap, &pe32)); + } + } + + FILETIME fst; + SYSTEMTIME st; + GetSystemTime(&st); + SystemTimeToFileTime(&st, &fst); + memcpy(¤tTime[1], &fst, sizeof(int64)); + int64 timeSlice = currentTime[1] - currentTime[0]; + int64 activeSlice = activeTime[1] - activeTime[0]; + procAvg = static_cast(static_cast(activeSlice) / timeSlice); + //REPORT_LOG(true, ("%f\n", procAvg)); + currentScore = currentScore + static_cast(procAvg * 0.5); + + averageScore.insert(averageScore.end(), currentScore); + + if(averageScore.size() > 100) + averageScore.erase(averageScore.begin()); +} + +//----------------------------------------------------------------------- + diff --git a/engine/server/application/TaskManager/src/win32/WinMain.cpp b/engine/server/application/TaskManager/src/win32/WinMain.cpp new file mode 100644 index 00000000..14a6ab39 --- /dev/null +++ b/engine/server/application/TaskManager/src/win32/WinMain.cpp @@ -0,0 +1,50 @@ +#include "FirstTaskManager.h" + +#include "sharedFoundation/FirstSharedFoundation.h" +#include "sharedCompression/SetupSharedCompression.h" +#include "sharedDebug/SetupSharedDebug.h" +#include "sharedFile/SetupSharedFile.h" +#include "sharedFoundation/ConfigFile.h" +#include "sharedFoundation/SetupSharedFoundation.h" +#include "sharedNetworkMessages/SetupSharedNetworkMessages.h" +#include "sharedRandom/SetupSharedRandom.h" +#include "sharedThread/SetupSharedThread.h" +#include "TaskManager.h" +#include "ConfigTaskManager.h" + +//===================================================================== + +int main(int argc, char **argv) +{ + SetupSharedThread::install(); + SetupSharedDebug::install(1024); + + //-- setup foundation + SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game); + + setupFoundationData.argc = argc; + setupFoundationData.argv = argv; + setupFoundationData.createWindow = false; + setupFoundationData.clockUsesSleep = true; + SetupSharedFoundation::install (setupFoundationData); + + SetupSharedCompression::install(); + SetupSharedFile::install(false); + SetupSharedNetworkMessages::install(); + SetupSharedRandom::install(static_cast(time(NULL))); //lint !e1924 !e64 // NULL is a C-Style cast? + + ConfigTaskManager::install(); + + TaskManager::install(); + + //-- run server + SetupSharedFoundation::callbackWithExceptionHandling(TaskManager::run); + + TaskManager::remove(); + SetupSharedFoundation::remove(); + SetupSharedThread::remove(); + + return 0; +} + +//=====================================================================