possibly controversial commit: remove all windows sources, keeping only the windows cmake so that we can generate an sln to edit the code

This commit is contained in:
DarthArgus
2016-01-27 15:22:22 -06:00
parent 3dccead5d5
commit 48ba7961eb
201 changed files with 0 additions and 21403 deletions
@@ -1,334 +0,0 @@
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;
}
$
@@ -1,135 +0,0 @@
//===========================================================================
//
// 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)
{
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 ==
//===========================================================================
@@ -1,71 +0,0 @@
#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__
@@ -1,163 +0,0 @@
//===========================================================================
//
// 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)
{
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;
}
//===========================================================================
@@ -1,80 +0,0 @@
#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__
@@ -1,698 +0,0 @@
/* -*-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 <alloca.h>
#else /* not sparc */
#if defined (MSDOS) && !defined (__TURBOC__)
#include <malloc.h>
#else /* not MSDOS, or __TURBOC__ */
#if defined(_AIX)
#include <malloc.h>
#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;
}
@@ -1,62 +0,0 @@
// NOTE: this makes it more convinient for me to make the help screen fancier...
// blah... not that anybody cares...
printf("\
Usage:\n\
mIFF {-%c <filename>|--%s=<filename>}\n\
[{-%c <filename>|--%s=<filename>} | {-%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 <filename>,--%s=<filename>\n\
[required] specifies the input path for IFF source file.\n", SNAME_INPUT_FILE, LNAME_INPUT_FILE);
printf("\
-%c <filename>,--%s=<filename>\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 \"<drive letter>:\"\n\
#pragma directory \"<directory name>\"\n\
#pragma filename \"<filename>\"\n\
#pragma extension \"<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);
@@ -1,953 +0,0 @@
//===========================================================================
//
// 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 <string.h> // for memset()
#include <stdio.h> // FILE stuff
#include <direct.h> // for getcwd()
#include <stdlib.h> // for tolower()
#include <process.h> // 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[8]; // 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[512];
// switches to be sent to mIFF Compiler
char sourceBuffer[bufferSize];
char outFileName[512]; // 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[256];
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 = false;
SetupSharedFoundation::install (SetupSharedFoundationData);
SetupSharedCompression::install();
SetupSharedFile::install(false);
TreeFile::addSearchAbsolute(0);
TreeFile::addSearchPath (".", 0);
SetupSharedFoundation::callbackWithExceptionHandling(callbackFunction);
SetupSharedFoundation::remove();
SetupSharedThread::remove();
return static_cast<int> (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, &currentDir[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.$$$");
int sizeRead = inFileHandler->read(dest, maxBufferSize);
if (sizeRead >= maxBufferSize)
{
retVal = ERR_BUFFERTOOSMALL;
}
else
{
reinterpret_cast<char *>(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;
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++ -x c++ -pedantic -Wall -dD -H %s mIFF.$$$", sourceName);
}
else if (!useCCCP && !verboseMode)
{
sprintf(shellCommand, "cpp.exe -nostdinc -nostdinc++ -x c++ -pedantic -Wall -dD %s mIFF.$$$", sourceName);
}
else if (useCCCP && verboseMode)
{
sprintf(shellCommand, "cccp.exe -nostdinc -nostdinc++ -x c++ -pedantic -Wall -dD -H %s mIFF.$$$", sourceName);
}
else
sprintf(shellCommand, "cccp.exe -nostdinc -nostdinc++ -x c++ -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);
sizeRead = inFileName->read(buffer, maxBufferSize);
if (static_cast<unsigned>(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 ==
//===========================================================================
@@ -1,517 +0,0 @@
%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 <stdlib.h>
#include <string.h>
/*--------------------------------**
** 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();
}
<<EOF>> {
/* 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[256];
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);
}
File diff suppressed because it is too large Load Diff
@@ -1,42 +0,0 @@
#ifndef BASE_WIN32_ARCHIVE_H
#define BASE_WIN32_ARCHIVE_H
#ifdef EXTERNAL_DISTRO
namespace NAMESPACE
{
#endif
namespace Base
{
#ifdef PACK_BIG_ENDIAN
inline double byteSwap(double value) { byteReverse64(&value); return value; }
inline float byteSwap(float value) { byteReverse32(&value); return value; }
inline uint64 byteSwap(uint64 value) { byteReverse64(&value); return value; }
inline int64 byteSwap(int64 value) { byteReverse64(&value); return value; }
inline uint32 byteSwap(uint32 value) { byteReverse32(&value); return value; }
inline int32 byteSwap(int32 value) { byteReverse32(&value); return value; }
inline uint16 byteSwap(uint16 value) { byteReverse16(&value); return value; }
inline int16 byteSwap(int16 value) { byteReverse16(&value); return value; }
#else
inline double byteSwap(double value) { return value; }
inline float byteSwap(float value) { return value; }
inline uint64 byteSwap(uint64 value) { return value; }
inline int64 byteSwap(int64 value) { return value; }
inline uint32 byteSwap(uint32 value) { return value; }
inline int32 byteSwap(int32 value) { return value; }
inline uint16 byteSwap(uint16 value) { return value; }
inline int16 byteSwap(int16 value) { return value; }
#endif
};
#ifdef EXTERNAL_DISTRO
};
#endif
#endif
@@ -1,31 +0,0 @@
////////////////////////////////////////
// Platform.cpp
//
// Purpose:
// 1. Implementation of the global functionality declaired in Platform.h.
//
// Revisions:
// 07/10/2001 Created
//
#include "Platform.h"
#ifdef EXTERNAL_DISTRO
namespace NAMESPACE
{
#endif
namespace Base
{
CTimer::CTimer() :
mTimer(0)
{
}
};
#ifdef EXTERNAL_DISTRO
};
#endif
@@ -1,98 +0,0 @@
////////////////////////////////////////
// Platform.h
//
// Purpose:
// 1. Include relevent system headers that are platform specific.
// 2. Declair global platform specific functionality.
// 3. Include primative type definitions
//
// Global Functions:
// getTimer() : Return the current high resolution clock count.
// getTimerFrequency() : Return the frequency of the high resolution clock.
// sleep() : Voluntarily relinquish timeslice of the calling thread for a
// specified number of milliseconds.
//
// Revisions:
// 07/10/2001 Created
//
#ifndef BASE_WIN32_PLATFORM_H
#define BASE_WIN32_PLATFORM_H
#include <memory.h>
#include <winsock2.h>
#include <time.h>
#include <io.h>
#include <fcntl.h>
#include <direct.h>
#include <stdio.h>
#include <errno.h>
#include "Types.h"
#ifdef EXTERNAL_DISTRO
namespace NAMESPACE
{
#endif
namespace Base
{
uint64 getTimer(void);
uint64 getTimerFrequency(void);
inline uint64 getTimer(void)
{
uint64 result;
if (!QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER *>(&result)))
result = 0;
return result;
}
inline uint64 getTimerFrequency(void)
{
uint64 result;
if (!QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER *>(&result)))
result = 0;
return result;
}
inline void sleep(uint32 ms)
{
Sleep(ms);
}
class CTimer
{
public:
CTimer();
void Set(uint32 seconds);
void Signal();
bool Expired();
private:
uint32 mTimer;
};
inline void CTimer::Set(uint32 interval)
{
mTimer = (uint32)time(0) + interval;
}
inline void CTimer::Signal()
{
mTimer = 0;
}
inline bool CTimer::Expired()
{
return (mTimer <= (uint32)time(0));
}
};
#ifdef EXTERNAL_DISTRO
};
#endif
#endif BASE_WIN32_PLATFORM_H
@@ -1,42 +0,0 @@
////////////////////////////////////////
// Types.h
//
// Purpose:
// 1. Define integer types that are unambiguous with respect to size
//
// Revisions:
// 07/10/2001 Created
//
#ifndef BASE_WIN32_TYPES_H
#define BASE_WIN32_TYPES_H
#ifdef EXTERNAL_DISTRO
namespace NAMESPACE
{
#endif
namespace Base
{
#define INT32_MAX 0x7FFFFFFF
#define INT32_MIN 0x80000000
#define UINT32_MAX 0xFFFFFFFF
typedef signed char int8;
typedef unsigned char uint8;
typedef short int16;
typedef unsigned short uint16;
typedef int int32;
typedef unsigned uint32;
typedef __int64 int64;
typedef unsigned __int64 uint64;
};
#ifdef EXTERNAL_DISTRO
};
#endif
#endif // BASE_WIN32_TYPES_H
@@ -1,5 +0,0 @@
// CentralServerPrecompiledHeader.cpp
// copyright 2001 Verant Interactive
// Author: Justin Randall
#include "FirstCentralServer.h"
@@ -1,84 +0,0 @@
#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 <string>
#include <time.h>
//_____________________________________________________________________
/*
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.clear();
// 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;
}
//_____________________________________________________________________
@@ -1,42 +0,0 @@
#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 <string>
#include <time.h>
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;
}
@@ -1,70 +0,0 @@
#include "FirstCommodityServer.h"
#include "sharedFoundation/FirstSharedFoundation.h"
#include "sharedCompression/SetupSharedCompression.h"
#include "sharedDebug/SetupSharedDebug.h"
#include "sharedFile/TreeFile.h"
#include "sharedFile/SetupSharedFile.h"
#include "sharedFoundation/ConfigFile.h"
#include "sharedFoundation/ExitChain.h"
#include "sharedFoundation/Os.h"
#include "sharedFoundation/SetupSharedFoundation.h"
#include "sharedGame/CommoditiesAdvancedSearchAttribute.h"
#include "sharedGame/ConfigSharedGame.h"
#include "sharedNetwork/SetupSharedNetwork.h"
#include "sharedNetwork/NetworkHandler.h"
#include "sharedNetworkMessages/SetupSharedNetworkMessages.h"
#include "sharedThread/SetupSharedThread.h"
#include "sharedUtility/DataTableManager.h"
#include "CommodityServer.h"
#include "ConfigCommodityServer.h"
#include "LocalizationManager.h"
#include "UnicodeUtils.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);
ConfigSharedGame::install();
SetupSharedCompression::install();
SetupSharedFile::install(false);
SetupSharedNetworkMessages::install();
SetupSharedNetwork::SetupData networkSetupData;
SetupSharedNetwork::getDefaultServerSetupData(networkSetupData);
SetupSharedNetwork::install(networkSetupData);
NetworkHandler::install();
ConfigCommodityServer::install();
const bool displayBadStringIds = ConfigSharedGame::getDisplayBadStringIds ();
const bool debugStringIds = ConfigSharedGame::getDebugStringIds ();
Unicode::NarrowString defaultLocale(ConfigSharedGame::getDefaultLocale ());
Unicode::UnicodeNarrowStringVector localeVector;
localeVector.push_back(defaultLocale);
LocalizationManager::install (new TreeFile::TreeFileFactory, localeVector, debugStringIds, NULL, displayBadStringIds);
ExitChain::add(LocalizationManager::remove, "LocalizationManager::remove");
DataTableManager::install();
CommoditiesAdvancedSearchAttribute::install();
//-- run server
SetupSharedFoundation::callbackWithExceptionHandling(CommodityServer::run);
SetupSharedFoundation::remove();
return 0;
}
//-----------------------------------------------------------------------
@@ -1 +0,0 @@
#include "FirstConnectionServer.h"
@@ -1,58 +0,0 @@
#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 <time.h>
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;
}
@@ -1,16 +0,0 @@
// 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"
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
@@ -1,55 +0,0 @@
// ======================================================================
//
// 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;
}
// ======================================================================
@@ -1 +0,0 @@
#include "FirstLoginServer.h"
@@ -1,46 +0,0 @@
#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 <time.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;
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;
}
@@ -1,91 +0,0 @@
#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 <string>
// ======================================================================
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<uint32>(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;
}
@@ -1,8 +0,0 @@
// ======================================================================
//
// FirstPlanetServer.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "FirstPlanetServer.h"
@@ -1,67 +0,0 @@
#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 <cstdio>
//_____________________________________________________________________
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;
}
//_____________________________________________________________________
@@ -1,59 +0,0 @@
// 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;
}
//-----------------------------------------------------------------------
@@ -1,22 +0,0 @@
// ConsoleInput.cpp
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
// Author: Justin Randall
//-----------------------------------------------------------------------
#include "FirstTaskManager.h"
#include "Console.h"
#include <conio.h>
//-----------------------------------------------------------------------
const char Console::getNextChar()
{
char result = 0;
if(_kbhit())
result = static_cast<char>(_getche());
return result;
}
//-----------------------------------------------------------------------
@@ -1,33 +0,0 @@
#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);
}
};
@@ -1,153 +0,0 @@
#include "FirstTaskManager.h"
#include "sharedFoundation/FirstSharedFoundation.h"
#include "ProcessSpawner.h"
#include <map>
#include <string>
#include "TaskManager.h"
#include <stdio.h>
uint32 ProcessSpawner::prefix;
std::map<uint32, HANDLE> procById;
//-----------------------------------------------------------------------
bool tokenize (const std::string & str, std::vector<std::string> & 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<std::string> & parameters)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
char cmd[1024] = {"\0"};
std::string cmdLine;
cmdLine = processName.c_str();
cmdLine += " ";
std::vector<std::string>::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<char *>(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<uint32, HANDLE>(pi.dwProcessId, pi.hProcess));
return pi.dwProcessId;
}
//-----------------------------------------------------------------------
uint32 ProcessSpawner::execute(const std::string & cmd)
{
std::vector<std::string> 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<uint32, HANDLE>::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);
}
//-----------------------------------------------------------------------
@@ -1,147 +0,0 @@
// 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 <windows.h>
#include <tlhelp32.h>
//-----------------------------------------------------------------------
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<float>::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<float>(static_cast<float>(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(&currentTime[1], &fst, sizeof(int64));
int64 timeSlice = currentTime[1] - currentTime[0];
int64 activeSlice = activeTime[1] - activeTime[0];
procAvg = static_cast<double>(static_cast<double>(activeSlice) / timeSlice);
//REPORT_LOG(true, ("%f\n", procAvg));
currentScore = currentScore + static_cast<float>(procAvg * 0.5);
averageScore.insert(averageScore.end(), currentScore);
if(averageScore.size() > 100)
averageScore.erase(averageScore.begin());
}
//-----------------------------------------------------------------------
@@ -1,50 +0,0 @@
#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<uint32>(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;
}
//=====================================================================
@@ -1,60 +0,0 @@
// main.cpp
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
// Author: Justin Randall
//-----------------------------------------------------------------------
#include "FirstTransferServer.h"
#include "sharedFoundation/FirstSharedFoundation.h"
#include "sharedCompression/SetupSharedCompression.h"
#include "sharedDebug/SetupSharedDebug.h"
#include "sharedFile/SetupSharedFile.h"
#include "sharedFoundation/Os.h"
#include "sharedFoundation/SetupSharedFoundation.h"
#include "sharedNetwork/SetupSharedNetwork.h"
#include "sharedNetwork/NetworkHandler.h"
#include "sharedNetworkMessages/SetupSharedNetworkMessages.h"
#include "sharedThread/SetupSharedThread.h"
#include "TransferServer.h"
#include "ConfigTransferServer.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 = true;
SetupSharedFoundation::install (setupFoundationData);
SetupSharedCompression::install();
SetupSharedFile::install(false);
SetupSharedNetworkMessages::install();
SetupSharedNetwork::SetupData networkSetupData;
SetupSharedNetwork::getDefaultServerSetupData(networkSetupData);
SetupSharedNetwork::install(networkSetupData);
NetworkHandler::install();
//Os::setProgramName("TransferServer");
ConfigTransferServer::install();
//-- run server
SetupSharedFoundation::callbackWithExceptionHandling(TransferServer::run);
NetworkHandler::remove();
SetupSharedFoundation::remove();
SetupSharedThread::remove();
return 0;
}
//-----------------------------------------------------------------------
@@ -1,9 +0,0 @@
// ======================================================================
//
// FirstServerDatabase.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverDatabase/FirstServerDatabase.h"
@@ -1,10 +0,0 @@
// ======================================================================
//
// FirstServerGame.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
// ======================================================================
@@ -1,8 +0,0 @@
// ======================================================================
//
// FirstServerKeyShare.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverKeyShare/FirstServerKeyShare.h"
@@ -1,9 +0,0 @@
// FirstServerMetrics.cpp
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
// Author: Justin Randall
//-----------------------------------------------------------------------
#include "serverMetrics/FirstServerMetrics.h"
//-----------------------------------------------------------------------
@@ -1,3 +0,0 @@
#include "serverNetworkMessages/FirstServerNetworkMessages.h"
@@ -1,8 +0,0 @@
// ======================================================================
//
// FirstServerPathfinding.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverPathfinding/FirstServerPathfinding.h"
@@ -1,2 +0,0 @@
#include "serverScript/FirstServerScript.h"
@@ -1,2 +0,0 @@
#include "serverUtility/FirstServerUtility.h"
@@ -1 +0,0 @@
#include "FirstTemplateCompiler.h"
@@ -1,8 +0,0 @@
#include "sharedFoundationTypes/FoundationTypes.h"
#include "sharedDebug/FirstSharedDebug.h"
#include "sharedFoundation/FirstSharedFoundation.h"
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
@@ -1 +0,0 @@
#include "FirstTemplateDefinitionCompiler.h"
@@ -1,8 +0,0 @@
#include "sharedFoundationTypes/FoundationTypes.h"
#include "sharedDebug/FirstSharedDebug.h"
#include "sharedFoundation/FirstSharedFoundation.h"
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
@@ -1,8 +0,0 @@
// ======================================================================
//
// FirstSharedCollision.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedCollision/FirstSharedCollision.h"
@@ -1,8 +0,0 @@
// ======================================================================
//
// FirstCommandParser.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedCommandParser/FirstSharedCommandParser.h"
@@ -1,8 +0,0 @@
// ======================================================================
//
// FirstCompression.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedCompression/FirstSharedCompression.h"
@@ -1,9 +0,0 @@
// ======================================================================
//
// FirstServerDatabaseInterface.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedDatabaseInterface/FirstSharedDatabaseInterface.h"
@@ -1,19 +0,0 @@
/* SQLC_Defs.h
*
* This file includes common definitions needed by the other SQLClasses header files.
* (Don't include this file directly -- files that require it will include it.)
*
* Note that this file is specific to each OS, because what header files are
* needed varies in each OS. In particular, Unix versions don't want windows.h.
*
* ODBC versions: includes definitions of ODBC datatypes needed by the various
* SQLClasses
*/
#ifndef _SQLC_DEFS_H
#define _SQLC_DEFS_H
#include <windows.h>
#include <sqltypes.h>
#endif
@@ -1,670 +0,0 @@
// ======================================================================
//
// DebugHelp.cpp
// copyright 2000 Verant Interactive
//
// ======================================================================
#include "sharedDebug/FirstSharedDebug.h"
#include "sharedDebug/DebugHelp.h"
#include "sharedFoundation/WindowsWrapper.h"
#include <dbghelp.h>
#include <cstdio>
#include <cstring>
// ======================================================================
// ======================================================================
// This was done to keep the header file from having to include <windows.h> or <dbghelp.h>
namespace DebugHelpNamespace
{
static HINSTANCE library;
static HANDLE process;
struct CallbackData
{
const char *name;
bool loaded;
};
typedef DWORD (__stdcall *SymSetOptionsFP)(IN DWORD SymOptions);
typedef BOOL (__stdcall *SymInitializeFP)(IN HANDLE hProcess, IN PSTR UserSearchPath, IN BOOL fInvadeProcess);
typedef BOOL (__stdcall *SymCleanupFP)(IN HANDLE hProcess);
typedef BOOL (__stdcall *StackWalk64FP)(DWORD MachineType, HANDLE hProcess, HANDLE hThread, LPSTACKFRAME64 StackFrame, PVOID ContextRecord, PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine, PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress);
typedef BOOL (__stdcall *SymGetModuleInfo64FP)(IN HANDLE hProcess, IN DWORD64 dwAddr, OUT PIMAGEHLP_MODULE64 ModuleInfo);
typedef DWORD64 (__stdcall *SymLoadModule64FP)(IN HANDLE hProcess, IN HANDLE hFile, IN PSTR ImageName, IN PSTR ModuleName, IN DWORD64 BaseOfDll, IN DWORD SizeOfDll);
typedef BOOL (__stdcall *SymGetSymFromAddr64FP)(IN HANDLE hProcess, IN DWORD64 dwAddr, OUT PDWORD64 pdwDisplacement, OUT PIMAGEHLP_SYMBOL64 Symbol);
typedef BOOL (__stdcall *SymGetLineFromAddr64FP)(IN HANDLE hProcess, IN DWORD64 dwAddr, OUT PDWORD pdwDisplacement, OUT PIMAGEHLP_LINE64 Line);
typedef PVOID (__stdcall *SymFunctionTableAccess64FP)(HANDLE hProcess, DWORD64 AddrBase);
typedef DWORD64 (__stdcall *SymGetModuleBase64FP)(IN HANDLE hProcess, IN DWORD64 dwAddr);
typedef BOOL (__stdcall *SymEnumerateModules64FP)(HANDLE hProcess, PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback, PVOID UserContext);
typedef BOOL (__stdcall *EnumerateLoadedModules64FP)(IN HANDLE hProcess, IN PENUMLOADED_MODULES_CALLBACK64 EnumLoadedModulesCallback, IN PVOID UserContext);
typedef BOOL (__stdcall *MiniDumpWriteDumpFP)(HANDLE hProcess, DWORD ProcessId, HANDLE hFile, MINIDUMP_TYPE DumpType, PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
static SymSetOptionsFP symSetOptions;
static SymInitializeFP symInitialize;
static SymCleanupFP symCleanup;
static StackWalk64FP stackWalk64;
static SymGetModuleInfo64FP symGetModuleInfo64;
static SymLoadModule64FP symLoadModule64;
static SymGetSymFromAddr64FP symGetSymFromAddr64;
static SymGetLineFromAddr64FP symGetLineFromAddr64;
static SymFunctionTableAccess64FP symFunctionTableAccess64;
static SymGetModuleBase64FP symGetModuleBase64;
static SymEnumerateModules64FP symEnumerateModules64;
static EnumerateLoadedModules64FP enumerateLoadedModules64;
static MiniDumpWriteDumpFP miniDumpWriteDump;
static CRITICAL_SECTION criticalSection;
// ----------------------------------------------------------------------
//BOOL CALLBACK loadSymbolsForDllCallback(PTSTR ModuleName, DWORD64 ModuleBase, ULONG ModuleSize, PVOID UserContext);
// ----------------------------------------------------------------------
typedef unsigned long int ub4; /* unsigned 4-byte quantities */
typedef unsigned char ub1; /* unsigned 1-byte quantities */
#define hashsize(n) ((ub4)1<<(n))
#define hashmask(n) (hashsize(n)-1)
/*
--------------------------------------------------------------------
mix -- mix 3 32-bit values reversibly.
For every delta with one or two bits set, and the deltas of all three
high bits or all three low bits, whether the original value of a,b,c
is almost all zero or is uniformly distributed,
* If mix() is run forward or backward, at least 32 bits in a,b,c
have at least 1/4 probability of changing.
* If mix() is run forward, every bit of c will change between 1/3 and
2/3 of the time. (Well, 22/100 and 78/100 for some 2-bit deltas.)
mix() was built out of 36 single-cycle latency instructions in a
structure that could supported 2x parallelism, like so:
a -= b;
a -= c; x = (c>>13);
b -= c; a ^= x;
b -= a; x = (a<<8);
c -= a; b ^= x;
c -= b; x = (b>>13);
...
Unfortunately, superscalar Pentiums and Sparcs can't take advantage
of that parallelism. They've also turned some of those single-cycle
latency instructions into multi-cycle latency instructions. Still,
this is the fastest good hash I could find. There were about 2^^68
to choose from. I only looked at a billion or so.
--------------------------------------------------------------------
*/
#define mix(a,b,c) \
{ \
a -= b; a -= c; a ^= (c>>13); \
b -= c; b -= a; b ^= (a<<8); \
c -= a; c -= b; c ^= (b>>13); \
a -= b; a -= c; a ^= (c>>12); \
b -= c; b -= a; b ^= (a<<16); \
c -= a; c -= b; c ^= (b>>5); \
a -= b; a -= c; a ^= (c>>3); \
b -= c; b -= a; b ^= (a<<10); \
c -= a; c -= b; c ^= (b>>15); \
}
/*
--------------------------------------------------------------------
hash() -- hash a variable-length key into a 32-bit value
k : the key (the unaligned variable-length array of bytes)
len : the length of the key, counting by bytes
initval : can be any 4-byte value
Returns a 32-bit value. Every bit of the key affects every bit of
the return value. Every 1-bit and 2-bit delta achieves avalanche.
About 6*len+35 instructions.
The best hash table sizes are powers of 2. There is no need to do
mod a prime (mod is sooo slow!). If you need less than 32 bits,
use a bitmask. For example, if you need only 10 bits, do
h = (h & hashmask(10));
In which case, the hash table should have hashsize(10) elements.
If you are hashing n strings (ub1 **)k, do it like this:
for (i=0, h=0; i<n; ++i) h = hash( k[i], len[i], h);
By Bob Jenkins, 1996. [email protected]. You may use this
code any way you wish, private, educational, or commercial. It's free.
See http://burtleburtle.net/bob/hash/evahash.html
Use for hash table lookup, or anything where one collision in 2^^32 is
acceptable. Do NOT use for cryptographic purposes.
--------------------------------------------------------------------
*/
// k; /* the key */
// length; /* the length of the key */
// initval; /* the previous hash, or an arbitrary value */
#if 0
static ub4 hash(ub1 *k, const ub4 length, const ub4 initval)
{
ub4 a, b, c, len;
/* Set up the internal state */
len = length;
a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
c = initval; /* the previous hash value */
/*---------------------------------------- handle most of the key */
while (len >= 12)
{
a += (k[0] +((ub4)k[1]<<8) +((ub4)k[2]<<16) +((ub4)k[3]<<24));
b += (k[4] +((ub4)k[5]<<8) +((ub4)k[6]<<16) +((ub4)k[7]<<24));
c += (k[8] +((ub4)k[9]<<8) +((ub4)k[10]<<16)+((ub4)k[11]<<24));
mix(a,b,c);
k += 12; len -= 12;
}
/*------------------------------------- handle the last 11 bytes */
c += length;
switch(len) /* all the case statements fall through */
{
case 11: c+=((ub4)k[10]<<24);
case 10: c+=((ub4)k[9]<<16);
case 9 : c+=((ub4)k[8]<<8);
/* the first byte of c is reserved for the length */
case 8 : b+=((ub4)k[7]<<24);
case 7 : b+=((ub4)k[6]<<16);
case 6 : b+=((ub4)k[5]<<8);
case 5 : b+=k[4];
case 4 : a+=((ub4)k[3]<<24);
case 3 : a+=((ub4)k[2]<<16);
case 2 : a+=((ub4)k[1]<<8);
case 1 : a+=k[0];
/* case 0: nothing left to add */
}
mix(a,b,c);
/*-------------------------------------------- report the result */
return c;
}
#endif
// version optimized for 4 byte input.
static ub4 hash_DWORD(const DWORD in, const ub4 initval)
{
ub1 *const k = (ub1 *)&in;
ub4 a, b, c, len;
/* Set up the internal state */
len = 4;
a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
c = initval; /* the previous hash value */
/*------------------------------------- handle the last 11 bytes */
c += 4;
a+=((ub4)k[3]<<24);
a+=((ub4)k[2]<<16);
a+=((ub4)k[1]<<8);
a+=k[0];
mix(a,b,c);
/*-------------------------------------------- report the result */
return c;
}
// ----------------------------------------------------------------------
struct BaseAddressLookup
{
DWORD64 keyAddress; // key
DWORD64 baseAddress; // value
};
static BaseAddressLookup * s_baseAddressCache;
static inline unsigned _baseAddressCachePageBits() { return 8; }
static inline unsigned _baseAddressCacheBits() { return _baseAddressCachePageBits() + 12; }
static inline unsigned _baseAddressCacheSize() { return 1 << (_baseAddressCacheBits()); }
static inline unsigned _baseAddressCacheElements() { return _baseAddressCacheSize() / sizeof(*s_baseAddressCache); }
static inline unsigned _baseAddressCacheMask() { return _baseAddressCacheElements() - 1; }
static int s_baseAddressCacheMisses;
static int s_baseAddressCacheHits;
static int s_baseAddressElements;
static int s_baseAddressUsed;
/*
static void _baseAddressCacheAnalyze()
{
s_baseAddressElements=0;
s_baseAddressUsed=0;
unsigned i;
const unsigned count = _baseAddressCacheElements();
for (i=0;i<count;i++)
{
const BaseAddressLookup *lookup = s_baseAddressCache + i;
s_baseAddressElements++;
if (lookup->baseAddress)
{
s_baseAddressUsed++;
}
}
}
*/
static DWORD64 _baseAddressLookup(DWORD64 addr)
{
BaseAddressLookup *lookup;
unsigned long bits = _baseAddressCacheBits();
DWORD *addr32 = (DWORD *)&addr;
unsigned long hash32 = hash_DWORD(addr32[0], addr32[1]);
unsigned long hash = (hash32>>(32-bits)) ^ hash32;
unsigned long mask = _baseAddressCacheMask();
unsigned long index = hash & mask;
lookup = s_baseAddressCache + index;
if (lookup->keyAddress==addr)
{
s_baseAddressCacheHits++;
//DEBUG_FATAL(symGetModuleBase64(process, addr) != lookup->baseAddress, ("Cache failure.\n"));
return lookup->baseAddress;
}
else
{
s_baseAddressCacheMisses++;
DWORD64 baseAddress = symGetModuleBase64(process, addr);
lookup->keyAddress=addr;
lookup->baseAddress=baseAddress;
return baseAddress;
}
}
static DWORD64 __stdcall getModuleBase(HANDLE hProcess, DWORD64 dwAddr)
{
UNREF(hProcess);
DEBUG_FATAL(hProcess!=process, ("Wrong process handle for module base lookup.\n"));
return _baseAddressLookup(dwAddr);
}
// ----------------------------------------------------------------------
struct FunctionTableLookup
{
DWORD64 keyAddress; // key
PVOID functionTable; // value
};
static FunctionTableLookup * s_functionTableCache;
static inline unsigned _functionTableCachePageBits() { return 4; }
static inline unsigned _functionTableCacheBits() { return _functionTableCachePageBits() + 12; }
static inline unsigned _functionTableCacheSize() { return 1 << (_functionTableCacheBits()); }
static inline unsigned _functionTableCacheElements() { return _functionTableCacheSize() / sizeof(*s_functionTableCache); }
static inline unsigned _functionTableCacheMask() { return _functionTableCacheElements() - 1; }
static int s_functionTableCacheMisses;
static int s_functionTableCacheHits;
static PVOID _functionTableLookup(DWORD64 addr)
{
FunctionTableLookup *lookup;
unsigned long bits = _functionTableCacheBits();
DWORD *addr32 = (DWORD *)&addr;
unsigned long hash32 = hash_DWORD(addr32[0], addr32[1]);
unsigned long hash = (hash32>>(32-bits)) ^ hash32;
unsigned long mask = _functionTableCacheMask();
unsigned long index = hash & mask;
lookup = s_functionTableCache + index;
if (lookup->keyAddress==addr)
{
s_functionTableCacheHits++;
//DEBUG_FATAL(symFunctionTableAccess64(process, addr) != lookup->functionTable, ("Cache failure.\n"));
return lookup->functionTable;
}
else
{
s_functionTableCacheMisses++;
PVOID functionTable = symFunctionTableAccess64(process, addr);
lookup->keyAddress=addr;
lookup->functionTable=functionTable;
return functionTable;
}
}
static PVOID __stdcall functionTableAccess(HANDLE hProcess, DWORD64 dwAddr)
{
UNREF(hProcess);
DEBUG_FATAL(hProcess!=process, ("Wrong process handle for module base lookup.\n"));
return _functionTableLookup(DWORD(dwAddr));
}
// ----------------------------------------------------------------------
}
using namespace DebugHelpNamespace;
// ----------------------------------------------------------------------
BOOL CALLBACK loadSymbolsForDllCallback(PSTR ModuleName, DWORD64 ModuleBase, ULONG ModuleSize, PVOID UserContext)
{
if (!library)
return false;
CallbackData *callbackData = reinterpret_cast<CallbackData *>(UserContext);
// see if this is the right file module and if we can load its symbol information
if (_stricmp(ModuleName, callbackData->name) == 0 && symLoadModule64(process, NULL, ModuleName, 0, ModuleBase, ModuleSize) != 0)
{
callbackData->loaded = true;
return FALSE;
}
return TRUE;
}
// ======================================================================
void DebugHelp::install()
{
DEBUG_FATAL(library, ("DebugHelp already installed"));
library = LoadLibrary("dbghelp_6.3.17.0.dll");
if (library)
{
process = GetCurrentProcess();
#define GPA(a, b) a = reinterpret_cast<b##FP>(GetProcAddress(library, #b)); DEBUG_FATAL(!a, ("GetProcAddress failed for " #b))
GPA(symSetOptions, SymSetOptions);
GPA(symInitialize, SymInitialize);
GPA(symCleanup, SymCleanup);
GPA(stackWalk64, StackWalk64);
GPA(symGetModuleInfo64, SymGetModuleInfo64);
GPA(symLoadModule64, SymLoadModule64);
GPA(symGetSymFromAddr64, SymGetSymFromAddr64);
GPA(symGetLineFromAddr64, SymGetLineFromAddr64);
GPA(symFunctionTableAccess64, SymFunctionTableAccess64);
GPA(symGetModuleBase64, SymGetModuleBase64);
GPA(symEnumerateModules64, SymEnumerateModules64);
GPA(enumerateLoadedModules64, EnumerateLoadedModules64);
GPA(miniDumpWriteDump, MiniDumpWriteDump);
#undef GPA
IGNORE_RETURN(symSetOptions(SYMOPT_DEFERRED_LOADS | SYMOPT_UNDNAME | SYMOPT_LOAD_LINES));
// get the path to the executable
char executableDirectory[MAX_PATH * 2];
const DWORD result = GetModuleFileName(NULL, executableDirectory, sizeof(executableDirectory));
FATAL(result == 0, ("GetModuleFileName failed"));
char * const slash = strrchr(executableDirectory, '\\');
DEBUG_FATAL(!slash, ("Executable path does not contain a slash"));
*slash = '\0';
const BOOL result1 = symInitialize(process, executableDirectory, TRUE);
UNREF(result1);
DEBUG_FATAL(!result1, ("SymInitialize failed"));
// -----------------------------------------------------------------------
s_baseAddressCache = (BaseAddressLookup *)VirtualAlloc(0, _baseAddressCacheSize(), MEM_COMMIT, PAGE_READWRITE);
s_functionTableCache = (FunctionTableLookup *)VirtualAlloc(0, _functionTableCacheSize(), MEM_COMMIT, PAGE_READWRITE);
// -----------------------------------------------------------------------
}
// Initialize the critical section one time only.
InitializeCriticalSection(&criticalSection);
}
// ----------------------------------------------------------------------
void DebugHelp::remove()
{
if (s_baseAddressCache)
{
VirtualFree(s_baseAddressCache, 0, MEM_RELEASE);
s_baseAddressCache=0;
}
if (s_functionTableCache)
{
VirtualFree(s_functionTableCache, 0, MEM_RELEASE);
s_functionTableCache=0;
}
if (library)
{
IGNORE_RETURN(symCleanup(process));
IGNORE_RETURN(FreeLibrary(library));
library = NULL;
process = NULL;
symSetOptions = NULL;
symInitialize = NULL;
symCleanup = NULL;
stackWalk64 = NULL;
symGetModuleInfo64 = NULL;
symLoadModule64 = NULL;
symGetSymFromAddr64 = NULL;
symGetLineFromAddr64 = NULL;
symFunctionTableAccess64 = NULL;
symGetModuleBase64 = NULL;
symEnumerateModules64 = NULL;
enumerateLoadedModules64 = NULL;
}
// Release resources used by the critical section object.
DeleteCriticalSection(&criticalSection);
}
// ----------------------------------------------------------------------
bool DebugHelp::loadSymbolsForDll(const char *name)
{
if (!library)
return false;
CallbackData callbackData = { name, false };
enumerateLoadedModules64(process, (PENUMLOADED_MODULES_CALLBACK64)loadSymbolsForDllCallback, reinterpret_cast<void *>(&callbackData));
return callbackData.loaded;
}
// ----------------------------------------------------------------------
#pragma warning (disable: 4740 4748)
void DebugHelp::getCallStack(uint32 *callStack, int sizeOfCallStack)
{
{
for (int i = 0; i < sizeOfCallStack; ++i)
callStack[i] = 0;
}
if (!library)
return;
CONTEXT context;
Zero(context);
context.ContextFlags = CONTEXT_FULL;
// GetThreadContext returns invalid data when called from within the same thread
//if (!GetThreadContext(GetCurrentThread(), &context))
// return;
EnterCriticalSection(&criticalSection);
__asm
{
call GetEIP
GetEIP:
pop eax
mov context.Eip, eax
mov context.Esp, esp
mov context.Ebp, ebp
}
LeaveCriticalSection(&criticalSection);
STACKFRAME64 stackFrame;
Zero(stackFrame);
stackFrame.AddrPC.Mode = AddrModeFlat;
stackFrame.AddrPC.Offset = context.Eip;
stackFrame.AddrStack.Offset = context.Esp;
stackFrame.AddrStack.Mode = AddrModeFlat;
stackFrame.AddrFrame.Offset = context.Ebp;
stackFrame.AddrFrame.Mode = AddrModeFlat;
for (int i = 0; i < sizeOfCallStack; ++i, ++callStack)
{
if (stackWalk64(IMAGE_FILE_MACHINE_I386, process, process, &stackFrame, &context, NULL, functionTableAccess, getModuleBase, NULL))
{
const DWORD64 Offset = stackFrame.AddrPC.Offset;
*callStack = DWORD(Offset);
}
}
}
// ----------------------------------------------------------------------
void DebugHelp::reportCallStack(int const maxStackDepth)
{
// look up the call stack information
int const callStackOffset = 2;
int const callStackSize = callStackOffset + maxStackDepth;
uint32 * callStack = static_cast<uint32 *>(_alloca((callStackOffset + maxStackDepth) * sizeof(uint32)));
getCallStack(callStack, callStackOffset + maxStackDepth);
// look up the caller's file and line
if (callStack[callStackOffset])
{
char lib[4 * 1024] = { '\0' };
char file[4 * 1024] = { '\0' };
int line = 0;
for (int i = callStackOffset; i < callStackSize; ++i)
{
if (callStack[i])
{
if (lookupAddress(callStack[i], lib, file, sizeof(file), line))
REPORT_LOG(true, ("\t%s(%d) : caller %d\n", file, line, i-callStackOffset));
else
REPORT_LOG(true, ("\tunknown(0x%08X) : caller %d\n", static_cast<int>(callStack[i]), i-callStackOffset));
}
}
}
}
// ----------------------------------------------------------------------
bool DebugHelp::lookupAddress(uint32 address, char *libName, char *fileName, int fileNameLength, int &line)
{
UNREF(libName);
if (!library)
return false;
// make sure the image is loaded
IMAGEHLP_MODULE64 imageHelpModule;
Zero(imageHelpModule);
imageHelpModule.SizeOfStruct = sizeof(imageHelpModule);
if (!symGetModuleInfo64(process, address, &imageHelpModule))
return false;
// look up the symbol
const int MaxNameLength = 256;
char buffer[sizeof(IMAGEHLP_SYMBOL64) + MaxNameLength];
memset(buffer, 0, sizeof(buffer));
IMAGEHLP_SYMBOL64 *imageHelpSymbol = reinterpret_cast<IMAGEHLP_SYMBOL64*>(buffer);
imageHelpSymbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
imageHelpSymbol->Address = address;
imageHelpSymbol->MaxNameLength = MaxNameLength;
{
DWORD64 displacement = 0;
if (!symGetSymFromAddr64(process, address, &displacement, imageHelpSymbol))
{
return false;
}
}
// look up the source file name and line number
IMAGEHLP_LINE64 imageHelpLine;
Zero(imageHelpLine);
imageHelpLine.SizeOfStruct = sizeof(imageHelpLine);
{
DWORD displacement = 0;
if (!symGetLineFromAddr64(process, address, &displacement, &imageHelpLine))
{
return false;
}
}
// return the results
strncpy(fileName, imageHelpLine.FileName, static_cast<uint>(fileNameLength));
line = static_cast<int>(imageHelpLine.LineNumber);
return true;
}
// ----------------------------------------------------------------------
bool DebugHelp::writeMiniDump(char const *miniDumpFileName, PEXCEPTION_POINTERS exceptionPointers)
{
if (!miniDumpWriteDump)
return false;
char buffer[256];
if (!miniDumpFileName)
{
// get the program name
char programName[512];
DWORD result = GetModuleFileName(NULL, programName, sizeof(programName));
if (result == 0)
return false;
// get the file name without the path
const char *shortProgramName = strrchr(programName, '\\');
if (shortProgramName)
++shortProgramName;
else
shortProgramName = programName;
// lop off the extension
char *dot = const_cast<char *>(strchr(shortProgramName, '.'));
if (dot)
*dot = '\0';
// create a reasonable minidump filename
snprintf(buffer, sizeof(buffer), "%s_%d.mdmp", shortProgramName, static_cast<int>(GetCurrentProcessId()));
miniDumpFileName = buffer;
}
// create the file
HANDLE const file = CreateFile(miniDumpFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL);
if (file == INVALID_HANDLE_VALUE)
return false;
// create the exception information
MINIDUMP_EXCEPTION_INFORMATION exceptionInformationData;
MINIDUMP_EXCEPTION_INFORMATION *exceptionInformation = 0;
if (exceptionPointers)
{
exceptionInformationData.ThreadId = GetCurrentThreadId();
exceptionInformationData.ExceptionPointers = exceptionPointers;
exceptionInformationData.ClientPointers = true;
exceptionInformation = &exceptionInformationData;
}
// @todo make the minidump style modifiable
BOOL const result = miniDumpWriteDump(process, GetCurrentProcessId(), file, MiniDumpNormal, exceptionInformation, NULL, NULL);
// close the file
CloseHandle(file);
return result ? true : false;
}
// ======================================================================
@@ -1,35 +0,0 @@
// ======================================================================
//
// DebugHelp.h
// copyright 2000 Verant Interactive
//
// ======================================================================
#ifndef DEBUG_HELP_H
#define DEBUG_HELP_H
// ======================================================================
typedef unsigned long uint32;
// ======================================================================
class DebugHelp
{
public:
static void install();
static void remove();
static bool loadSymbolsForDll(const char *name);
static void getCallStack(uint32 *callStack, int sizeOfCallStack);
static void reportCallStack(int const maxStackDepth = 4);
static bool lookupAddress(uint32 address, char *libName, char *fileName, int fileNameLength, int &line);
static bool writeMiniDump(char const *miniDumpFileName=0, PEXCEPTION_POINTERS exceptionPointers=0);
};
// ======================================================================
#endif
@@ -1,321 +0,0 @@
// ======================================================================
//
// DebugMonitor.cpp
// copyright 1998 Bootprint Entertainment
// copyright 2001-2004 Sony Online Entertainment
//
// ======================================================================
#include "sharedDebug/FirstSharedDebug.h"
#include "sharedDebug/DebugMonitor.h"
#if PRODUCTION == 0
#include "sharedDebug/DebugFlags.h"
#include "sharedFoundation/ConfigFile.h"
// ======================================================================
namespace DebugMonitorNamespace
{
typedef void (*ChangedWindowCallback)(int x, int y, int width, int height);
typedef bool (*InstallFunction)(int x, int y, int width, int height);
typedef void (*RemoveFunction)();
typedef void (*ShowFunction)();
typedef void (*HideFunction)();
typedef void (*SetChangedWindowCallback)(ChangedWindowCallback);
typedef void (*SetBehindWindowFunction)(HWND window);
typedef void (*ClearScreenFunction)();
typedef void (*ClearToCursorFunction)();
typedef void (*GotoXYFunction)(int x, int y);
typedef void (*PrintFunction)(const char *string);
void changedWindowCallback(int x, int y, int width, int height);
HINSTANCE dll;
HKEY registryKey = HKEY_CLASSES_ROOT;
RemoveFunction removeFunction;
ShowFunction showFunction;
HideFunction hideFunction;
SetBehindWindowFunction setBehindWindowFunction;
ClearScreenFunction clearScreenFunction;
ClearToCursorFunction clearToCursorFunction;
GotoXYFunction gotoXYFunction;
PrintFunction printFunction;
bool noClear;
int GetRegistryValue(char const * name, int defaultValue)
{
int value;
DWORD type = 0;
DWORD size = sizeof(DWORD);
LONG result = RegQueryValueEx(registryKey, name, NULL, &type, reinterpret_cast<LPBYTE>(&value), &size);
if ((result != ERROR_SUCCESS || type != REG_DWORD) && (size != sizeof(int)))
value = defaultValue;
return value;
}
void SetRegistryValue(char const * name, int value)
{
RegSetValueEx(registryKey, name, NULL, REG_DWORD, reinterpret_cast<const LPBYTE>(&value), sizeof(int));
}
}
using namespace DebugMonitorNamespace;
// ======================================================================
// Install the debug monitor subsystem
//
// Remarks:
//
// This routine will first attempt to install the selected debug monitor.
void DebugMonitor::install()
{
dll = LoadLibrary("debugWindow.dll");
if (dll)
{
InstallFunction installFunction = reinterpret_cast<InstallFunction>(GetProcAddress(dll, "install"));
RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Sony Online Entertainment\\DebugWindow", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &registryKey, NULL);
int const x = ConfigFile::getKeyInt("SharedDebug", "debugWindowX", GetRegistryValue("x", 0));
int const y = ConfigFile::getKeyInt("SharedDebug", "debugWindowY", GetRegistryValue("y", 0));
int const width = ConfigFile::getKeyInt("SharedDebug", "debugWindowWidth", GetRegistryValue("width", 80));
int const height = ConfigFile::getKeyInt("SharedDebug", "debugWindowHeight", GetRegistryValue("height", 50));
if (installFunction && installFunction(x, y, width, height))
{
showFunction = reinterpret_cast<ShowFunction>(GetProcAddress(dll, "showWindow"));
hideFunction = reinterpret_cast<ShowFunction>(GetProcAddress(dll, "hideWindow"));
removeFunction = reinterpret_cast<RemoveFunction>(GetProcAddress(dll, "remove"));
setBehindWindowFunction = reinterpret_cast<SetBehindWindowFunction>(GetProcAddress(dll, "setBehindWindow"));
clearScreenFunction = reinterpret_cast<ClearScreenFunction>(GetProcAddress(dll, "clearScreen"));
clearToCursorFunction = reinterpret_cast<ClearToCursorFunction>(GetProcAddress(dll, "clearToCursor"));
gotoXYFunction = reinterpret_cast<GotoXYFunction>(GetProcAddress(dll, "gotoXY"));
printFunction = reinterpret_cast<PrintFunction>(GetProcAddress(dll, "print"));
SetChangedWindowCallback setChangedWindowCallback = reinterpret_cast<SetChangedWindowCallback>(GetProcAddress(dll, "setChangedWindowCallback"));
if (setChangedWindowCallback)
(*setChangedWindowCallback)(changedWindowCallback);
DebugFlags::registerFlag(noClear, "SharedDebug", "noDebugMonitorClear");
if (ConfigFile::getKeyBool("SharedDebug", "debugWindow", false))
show();
}
else
{
installFunction = NULL;
const BOOL result = FreeLibrary(dll);
dll = NULL;
UNREF(result);
DEBUG_FATAL(!result, ("FreeLibrary failed"));
}
}
}
// ----------------------------------------------------------------------
/**
* Remove the debug monitor subsystem.
*/
void DebugMonitor::remove()
{
if (removeFunction)
removeFunction();
removeFunction = NULL;
setBehindWindowFunction = NULL;
clearScreenFunction = NULL;
clearToCursorFunction = NULL;
gotoXYFunction = NULL;
printFunction = NULL;
if (dll)
{
const BOOL result = FreeLibrary(dll);
UNREF(result);
DEBUG_FATAL(!result, ("FreeLibrary failed"));
dll = NULL;
if (registryKey != HKEY_CLASSES_ROOT)
{
RegCloseKey(registryKey);
registryKey = HKEY_CLASSES_ROOT;
}
}
}
// ----------------------------------------------------------------------
void DebugMonitorNamespace::changedWindowCallback(int const x, int const y, int const width, int const height)
{
SetRegistryValue("x", x);
SetRegistryValue("y", y);
SetRegistryValue("width", width);
SetRegistryValue("height", height);
}
// ----------------------------------------------------------------------
void DebugMonitor::show()
{
if (showFunction)
(*showFunction)();
}
// ----------------------------------------------------------------------
void DebugMonitor::hide()
{
if (hideFunction)
(*hideFunction)();
}
// ----------------------------------------------------------------------
/**
* Set the debug window's z-order.
*/
void DebugMonitor::setBehindWindow(HWND window)
{
if (setBehindWindowFunction)
setBehindWindowFunction(window);
}
// ----------------------------------------------------------------------
/**
* Clear the debug monitor and home the cursor.
*
* If the mono monitor is not installed, this routine does nothing.
*
* This routine will clear the contents of the debug monitor, reset the screen
* offset to 0, and move the cursor to the upper left corner of the screen.
*
* @see DebugMonitor::home(), DebugMonitor::clearToCursor()
*/
void DebugMonitor::clearScreen()
{
if (noClear)
return;
if (clearScreenFunction)
clearScreenFunction();
}
// ----------------------------------------------------------------------
/**
* Clear the debug monitor to the current cursor position and home the cursor.
*
* If the debug monitor is not installed, this routine does nothing.
*
* This routine will clear the contents of the debug monitor only up to the
* cursor position. If the cursor is not very far down on the screen,
* this routine may be significantly more efficient clearing the screen.
*
* It will also move the cursor to the upper left corner of the screen.
*
* @see DebugMonitor::clearScreen(), DebugMonitor::home()
*/
void DebugMonitor::clearToCursor()
{
if (clearToCursorFunction)
clearToCursorFunction();
else
clearScreen();
}
// ======================================================================
// Move the cursor to the upper left hand corner of the mono monitor screen
//
// Remarks:
//
// If the debug monitor is not installed, this routine does nothing.
//
// All printing happens at the cursor position.
//
// This routine is identical to calling gotoXY(0,0);
//
// See Also:
//
// DebugMonitor::gotoXY()
void DebugMonitor::home()
{
gotoXY(0,0);
}
// ----------------------------------------------------------------------
/**
* Position the cursor on the debug monitor screen.
*
* If the debug monitor is not installed, this routine does nothing.
*
* All printing happens at the cursor position.
*
* @param x New X position for the cursor
* @param y New Y position for the cursor
*/
void DebugMonitor::gotoXY(int x, int y)
{
if (gotoXYFunction)
gotoXYFunction(x, y);
}
// ----------------------------------------------------------------------
/**
* Display a string on the debug monitor.
*
* If the debug monitor is not installed, this routine does nothing.
*
* Printing occurs from the cursor position.
*
* Newline characters '\n' will cause the cursor position to advance to the
* beginning of the next line. If the cursor is already on the last line of
* the screen, the screen will scroll up one line and the cursor will move to
* the beginning of the last line.
*
* The backspace character '\b' will cause the cursor to move one character
* backwards. If at the beginning of the line, the cursor will move to the
* end of the previous line. If already on the first line of the screen, the
* cursor position and screen contents will be unchanged.
*
* All other characters are placed directly into the text frame buffer.
* After each character, the cursor will be logically advanced one
* character forward. If the cursor was on the last column, it will advance
* to the next line. If the cursor was already on the last line, the screen
* will be scrolled up one line and the cursor will move to the beginning of
* the last line.
*
* @param string String to display on the debug monitor
*/
void DebugMonitor::print(const char *string)
{
if (printFunction)
printFunction(string);
}
// ----------------------------------------------------------------------
/**
* Ensure all changes to the DebugMonitor have taken effect by the time
* this function returns.
*
* Note: some platforms may do nothing here. The Win32 platform does not
* require flushing. The Linux platform does. Call it assuming
* that it is needed. It will be a no-op when not required.
*/
void DebugMonitor::flushOutput()
{
// Win32 debug monitors don't need to do anything here.
}
// ======================================================================
#endif
@@ -1,48 +0,0 @@
// ======================================================================
//
// DebugMonitor.h
//
// Portions copyright 1998 Bootprint Entertainment
// Portions copyright 2002-2004 Sony Online Entertainment
// All Rights Reserved.
//
// ======================================================================
#ifndef INCLUDED_DebugMonitor_H
#define INCLUDED_DebugMonitor_H
// ======================================================================
#include "sharedFoundation/Production.h"
// ======================================================================
#if PRODUCTION == 0
class DebugMonitor
{
public:
static void install();
static void remove();
static void setBehindWindow(HWND window);
static void show();
static void hide();
static void clearScreen();
static void clearToCursor();
static void home();
static void gotoXY(int x, int y);
static void print(const char *string);
static void flushOutput();
};
#endif
// ======================================================================
#endif
@@ -1,8 +0,0 @@
// ======================================================================
//
// FirstDebug.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "shareddebug/FirstSharedDebug.h"
@@ -1,105 +0,0 @@
//
// PerformanceTimer.cpp
// Copyright 2000-2004 Sony Online Entertainment
//
//-------------------------------------------------------------------
#include "shareddebug/FirstSharedDebug.h"
#include "shareddebug/PerformanceTimer.h"
//-------------------------------------------------------------------
#include <cstdio>
//-------------------------------------------------------------------
__int64 PerformanceTimer::ms_frequency;
//-------------------------------------------------------------------
void PerformanceTimer::install()
{
BOOL result = QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER *>(&ms_frequency));
FATAL(!result, ("PerformanceTimer::install QPF failed"));
}
//-------------------------------------------------------------------
PerformanceTimer::PerformanceTimer() :
m_startTime (0),
m_stopTime (0)
{
DEBUG_FATAL (ms_frequency == 0.f, ("PerformanceTimer not installed"));
}
//-------------------------------------------------------------------
PerformanceTimer::~PerformanceTimer()
{
}
//-------------------------------------------------------------------
void PerformanceTimer::start()
{
//-- get the current time
BOOL result = QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER *>(&m_startTime));
DEBUG_FATAL(!result, ("PerformanceTimer::start QPC failed"));
UNREF (result);
}
//-------------------------------------------------------------------
void PerformanceTimer::resume()
{
__int64 delta = m_stopTime - m_startTime;
start();
m_startTime -= delta;
}
//-------------------------------------------------------------------
void PerformanceTimer::stop ()
{
//-- get the current time
BOOL result = QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER *>(&m_stopTime));
DEBUG_FATAL(!result, ("PerformanceTimer::stop QPC failed"));
UNREF (result);
}
//-------------------------------------------------------------------
float PerformanceTimer::getElapsedTime() const
{
return static_cast<float> (m_stopTime - m_startTime) / static_cast<float> (ms_frequency);
}
// ----------------------------------------------------------------------
float PerformanceTimer::getSplitTime() const
{
__int64 currentTime;
BOOL result = QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER *>(&currentTime));
UNREF(result);
DEBUG_FATAL(!result, ("PerformanceTimer::getSplitTime QPC failed"));
return static_cast<float> (currentTime - m_startTime) / static_cast<float> (ms_frequency);
}
//-------------------------------------------------------------------
void PerformanceTimer::logElapsedTime(const char* string) const
{
UNREF (string);
#ifdef _DEBUG
static char buffer [1000];
sprintf (buffer, "%s : %1.5f seconds\n", string ? string : "null", getElapsedTime());
DEBUG_REPORT_LOG_PRINT (true, ("%s", buffer));
DEBUG_OUTPUT_CHANNEL("Foundation\\PerformanceTimer", ("%s", buffer));
#endif
}
//-------------------------------------------------------------------
@@ -1,49 +0,0 @@
//
// PerformanceTimer.h
// Copyright 2000-2004 Sony Online Entertainment
//
//-------------------------------------------------------------------
#ifndef INCLUDED_PerformanceTimer_H
#define INCLUDED_PerformanceTimer_H
//-------------------------------------------------------------------
class PerformanceTimer
{
public:
static void install();
public:
DLLEXPORT PerformanceTimer();
DLLEXPORT ~PerformanceTimer();
void DLLEXPORT start();
void DLLEXPORT resume();
void DLLEXPORT stop();
float DLLEXPORT getElapsedTime() const;
float getSplitTime() const; // Get the time since the timer was started without stopping the timer.
void logElapsedTime(const char* string) const;
private:
PerformanceTimer(PerformanceTimer const &);
PerformanceTimer & operator=(PerformanceTimer const &);
private:
static __int64 ms_frequency;
private:
__int64 m_startTime;
__int64 m_stopTime;
};
//-------------------------------------------------------------------
#endif
@@ -1,90 +0,0 @@
// ======================================================================
//
// ProfilerTimer.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "shareddebug/FirstSharedDebug.h"
#include "shareddebug/ProfilerTimer.h"
#include "shareddebug/DebugFlags.h"
#include "sharedFoundation/WindowsWrapper.h"
// ======================================================================
namespace ProfilerTimerNamespace
{
ProfilerTimer::Type ms_qpcFrequency;
float ms_floatQpcFrequency;
__int64 ms_rdtsc;
__int64 ms_qpc;
bool ms_useRdtsc;
}
using namespace ProfilerTimerNamespace;
// ======================================================================
static __int64 __declspec(naked) __stdcall readTimeStampCounter()
{
__asm
{
rdtsc;
ret;
}
}
// ======================================================================
void ProfilerTimer::install()
{
IGNORE_RETURN(QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER *>(&ms_qpc)));
ms_rdtsc = readTimeStampCounter();
IGNORE_RETURN(QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER *>(&ms_qpcFrequency)));
ms_floatQpcFrequency = static_cast<float>(ms_qpcFrequency);
DebugFlags::registerFlag(ms_useRdtsc, "SharedDebug/Profiler", "useRdtsc");
}
// ----------------------------------------------------------------------
void ProfilerTimer::getTime(Type &time)
{
if (ms_useRdtsc)
time = readTimeStampCounter();
else
IGNORE_RETURN(QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER *>(&time)));
}
// ----------------------------------------------------------------------
void ProfilerTimer::getCalibratedTime(Type &time, Type &frequency)
{
if (ms_useRdtsc)
{
__int64 qpc;
IGNORE_RETURN(QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER *>(&qpc)));
__int64 rdtsc = readTimeStampCounter();
float const t = static_cast<float>(qpc - ms_qpc) / ms_floatQpcFrequency;
frequency = static_cast<__int64>(static_cast<float>(rdtsc - ms_rdtsc) / t);
time = rdtsc;
ms_qpc = qpc;
ms_rdtsc = time;
}
else
{
IGNORE_RETURN(QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER *>(&time)));
frequency = ms_qpcFrequency;
}
}
void ProfilerTimer::getFrequency(Type &frequency)
{
frequency = ms_qpcFrequency;
}
// ======================================================================
@@ -1,29 +0,0 @@
// ======================================================================
//
// ProfilerTimer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ProfilerTimer_H
#define INCLUDED_ProfilerTimer_H
// ======================================================================
class ProfilerTimer
{
public:
typedef __int64 Type;
public:
static void install();
static void getTime(Type &time);
static void getCalibratedTime(Type &time, Type &frequency);
static void getFrequency(Type &frequency);
};
// ======================================================================
#endif
@@ -1,142 +0,0 @@
// ======================================================================
//
// VTune.cpp
// Copyright 2000-01, Sony Online Entertainment Inc.
// All Rights Reserved.
//
// ======================================================================
#include "sharedDebug/FirstSharedDebug.h"
#include "sharedDebug/VTune.h"
#if PRODUCTION == 0
#include "sharedDebug/DebugFlags.h"
#include <vtune/vtuneapi.h>
// ======================================================================
HMODULE VTune::ms_module;
VTune::PauseFunction VTune::ms_pauseFunction;
VTune::ResumeFunction VTune::ms_resumeFunction;
VTune::State VTune::ms_state;
bool VTune::ms_resumeNextFrame;
bool VTune::ms_pauseNextFrame;
bool VTune::ms_debugReport;
// ======================================================================
void VTune::install()
{
DEBUG_FATAL(ms_module, ("vtune already installed"));
ms_module = LoadLibrary("VTuneAPI");
if (!ms_module)
return;
ms_pauseFunction = reinterpret_cast<PauseFunction>(GetProcAddress(ms_module, "VTPause"));
ms_resumeFunction = reinterpret_cast<PauseFunction>(GetProcAddress(ms_module, "VTResume"));
ms_state = S_default;
#if PRODUCTION == 0
DebugFlags::registerFlag(ms_debugReport, "SharedDebug", "vtuneState", debugReport);
#endif
}
// ----------------------------------------------------------------------
void VTune::remove()
{
if (ms_module)
{
FreeLibrary(ms_module);
ms_pauseFunction = 0;
ms_resumeFunction = 0;
}
}
// ----------------------------------------------------------------------
void VTune::debugReport()
{
switch (ms_state)
{
case S_default:
REPORT_PRINT(true, ("Vtune state unknown\n"));
break;
case S_sampling:
REPORT_PRINT(true, ("Vtune is sampling\n"));
break;
case S_paused:
REPORT_PRINT(true, ("Vtune is NOT sampling\n"));
break;
default:
DEBUG_FATAL(true, ("bad case"));
}
}
// ----------------------------------------------------------------------
void VTune::resume()
{
if (ms_module && ms_resumeFunction)
{
MessageBeep(MB_OK);
(*ms_resumeFunction)();
ms_state = S_sampling;
}
}
// ----------------------------------------------------------------------
void VTune::pause()
{
if (ms_module && ms_pauseFunction)
{
(*ms_pauseFunction)();
MessageBeep(MB_ICONEXCLAMATION);
ms_state = S_paused;
}
}
// ----------------------------------------------------------------------
void VTune::pauseNextFrame()
{
ms_pauseNextFrame = true;
ms_resumeNextFrame = false;
}
// ----------------------------------------------------------------------
void VTune::resumeNextFrame()
{
ms_pauseNextFrame = false;
ms_resumeNextFrame = true;
}
// ----------------------------------------------------------------------
void VTune::beginFrame()
{
if (ms_pauseNextFrame)
{
pause();
ms_pauseNextFrame = false;
}
if (ms_resumeNextFrame)
{
resume();
ms_resumeNextFrame = false;
}
}
// ======================================================================
#endif // PRODUCTION == 0
@@ -1,65 +0,0 @@
// ======================================================================
//
// VTune.h
// Copyright 2000-01, Sony Online Entertainment Inc.
// All Rights Reserved.
//
// ======================================================================
#ifndef INCLUDED_VTune_H
#define INCLUDED_VTune_H
// ======================================================================
#include "sharedFoundation/Production.h"
// ======================================================================
#if PRODUCTION == 0
class VTune
{
public:
static void install();
static void resume();
static void pause();
static void resumeNextFrame();
static void pauseNextFrame();
static void beginFrame();
private:
static void remove();
static void debugReport();
private:
enum State
{
S_default,
S_sampling,
S_paused
};
typedef void (__cdecl *PauseFunction)(void);
typedef void (__cdecl *ResumeFunction)(void);
private:
static HMODULE ms_module;
static PauseFunction ms_pauseFunction;
static ResumeFunction ms_resumeFunction;
static State ms_state;
static bool ms_resumeNextFrame;
static bool ms_pauseNextFrame;
static bool ms_debugReport;
};
#endif // PRODUCTION == 0
// ======================================================================
#endif
@@ -1,8 +0,0 @@
// ======================================================================
//
// FirstFile.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedFile/FirstSharedFile.h"
@@ -1,195 +0,0 @@
// ======================================================================
//
// OsFile.cpp
// Copyright 2002, Sony Online Entertainment Inc.
// All Rights Reserved.
//
// ======================================================================
#include "sharedFile/FirstSharedFile.h"
#include "sharedFile/OsFile.h"
#ifdef _DEBUG
#include "sharedDebug/PerformanceTimer.h"
#endif
namespace OsFileNamespace
{
float ms_time;
}
using namespace OsFileNamespace;
// ======================================================================
void OsFile::install()
{
}
// ----------------------------------------------------------------------
float OsFile::getSpentTime()
{
float const result = ms_time;
ms_time = 0.0f;
return result;
}
// ----------------------------------------------------------------------
bool OsFile::exists(const char *fileName)
{
NOT_NULL(fileName);
DWORD attributes = GetFileAttributes(fileName);
#if _MSC_VER < 1300
const DWORD INVALID_FILE_ATTRIBUTES = 0xffffffff;
#endif
return (attributes != INVALID_FILE_ATTRIBUTES && (attributes & FILE_ATTRIBUTE_DIRECTORY) == 0);
}
// ----------------------------------------------------------------------
int OsFile::getFileSize(const char *fileName)
{
NOT_NULL(fileName);
#ifdef _DEBUG
PerformanceTimer t;
t.start();
#endif
HANDLE handle = CreateFile(fileName, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (handle == INVALID_HANDLE_VALUE)
return -1;
int const size = GetFileSize(handle, NULL);
CloseHandle(handle);
#ifdef _DEBUG
t.stop();
ms_time += t.getElapsedTime();
#endif
return size;
}
// ----------------------------------------------------------------------
OsFile *OsFile::open(const char *fileName, bool randomAccess)
{
#ifdef _DEBUG
PerformanceTimer t;
t.start();
#endif
// attempt to open the file
HANDLE handle = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | (randomAccess ? FILE_FLAG_RANDOM_ACCESS : 0), NULL);
// check to make sure the file opened sucessfully
if (handle == INVALID_HANDLE_VALUE)
return NULL;
#ifdef _DEBUG
t.stop();
ms_time += t.getElapsedTime();
#endif
return new OsFile(handle);
}
// ----------------------------------------------------------------------
OsFile::OsFile(HANDLE handle)
: m_handle(handle),
m_offset(0)
{
}
// ----------------------------------------------------------------------
OsFile::~OsFile()
{
#ifdef _DEBUG
PerformanceTimer t;
t.start();
#endif
CloseHandle(m_handle);
#ifdef _DEBUG
t.stop();
ms_time+= t.getElapsedTime();
#endif
}
// ----------------------------------------------------------------------
int OsFile::length() const
{
return GetFileSize(m_handle, NULL);
}
// ----------------------------------------------------------------------
void OsFile::seek(int newFilePosition)
{
#ifdef _DEBUG
PerformanceTimer t;
t.start();
#endif
if (m_offset != newFilePosition)
{
const DWORD result = SetFilePointer(m_handle, newFilePosition, NULL, FILE_BEGIN);
DEBUG_FATAL(static_cast<int>(result) != newFilePosition, ("SetFilePointer failed"));
UNREF(result);
m_offset = newFilePosition;
}
#ifdef _DEBUG
t.stop();
ms_time += t.getElapsedTime();
#endif
}
// ----------------------------------------------------------------------
int OsFile::read(void *destinationBuffer, int numberOfBytes)
{
#ifdef _DEBUG
PerformanceTimer t;
t.start();
#endif
DWORD amountReadDword;
BOOL result = ReadFile(m_handle, destinationBuffer, static_cast<uint>(numberOfBytes), &amountReadDword, NULL);
// miles crasher hack
#if 0
FATAL(!result, ("FileStreamerThread::processRead ReadFile failed to read '%d' bytes with error '%d'", static_cast<uint>(numberOfBytes), GetLastError()));
#else
if(!result)
{
if(GetLastError() == 998) // access violation - buffer coming from miles hosed
{
WARNING(true,("FileStreamerThread::processRead ReadFile failed to read '%d' bytes with error '%d'", static_cast<uint>(numberOfBytes), GetLastError()));
return 0;
}
else
{
FATAL(true, ("FileStreamerThread::processRead ReadFile failed to read '%d' bytes with error '%d'", static_cast<uint>(numberOfBytes), GetLastError()));
}
}
#endif
// end miles crasher hack
#ifdef _DEBUG
t.stop();
ms_time += t.getElapsedTime();
#endif
m_offset += static_cast<int>(amountReadDword);
return static_cast<int>(amountReadDword);
}
// ======================================================================
@@ -1,48 +0,0 @@
// ======================================================================
//
// OsFile.h
// Copyright 2002, Sony Online Entertainment Inc.
// All Rights Reserved.
//
// ======================================================================
#ifndef INCLUDED_OsFile_H
#define INCLUDED_OsFile_H
// ======================================================================
class OsFile
{
public:
static void install();
static float getSpentTime();
static bool exists(const char *fileName);
static int getFileSize(const char *fileName);
static OsFile *open(const char *fileName, bool randomAccess=false);
public:
~OsFile();
int length() const;
int tell() const;
void seek(int newFilePosition);
int read(void *destinationBuffer, int numberOfBytes);
private:
OsFile(HANDLE handle);
OsFile(const char *fileName);
private:
HANDLE m_handle;
int m_offset;
};
// ======================================================================
#endif
@@ -1,58 +0,0 @@
// ======================================================================
//
// ByteOrder.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedFoundation/FirstSharedFoundation.h"
#include "sharedFoundation/ByteOrder.h"
// ======================================================================
// I'm using the arguments, but the compiler can't tell that
#pragma warning(disable: 4100)
__declspec(naked) ulong ntohl(ulong netLong)
{
_asm
{
mov eax, [esp+4]
bswap eax
ret
}
} //lint !e533 !e715 // function should return a value, argument not referenced
__declspec(naked) ulong htonl(ulong hostLong)
{
_asm
{
mov eax, [esp+4]
bswap eax
ret
}
} //lint !e533 !e715 // function should return a value, argument not referenced
__declspec(naked) ushort ntohs(ushort netShort)
{
_asm
{
mov eax, [esp+4]
bswap eax
shr eax, 16
ret
}
} //lint !e533 !e715 // function should return a value, argument not referenced
__declspec(naked) ushort htons(ushort hostShort)
{
_asm
{
mov eax, [esp+4]
bswap eax
shr eax, 16
ret
}
} //lint !e533 !e715 // function should return a value, argument not referenced
// ======================================================================
@@ -1,22 +0,0 @@
// ======================================================================
//
// ByteOrder.h
// copyright 1998 Bootprint Entertainment
// copyright 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef BYTE_ORDER_H
#define BYTE_ORDER_H
// ======================================================================
ulong __cdecl ntohl(ulong netLong);
ushort __cdecl ntohs(ushort netShort);
ulong __cdecl htonl(ulong hostLong);
ushort __cdecl htons(ushort hostShort);
// ======================================================================
#endif
@@ -1,324 +0,0 @@
// ======================================================================
//
// ConfigSharedFoundation.cpp
// copyright 1998 Bootprint Entertainment
// copyright 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedFoundation/FirstSharedFoundation.h"
#include "sharedFoundation/ConfigSharedFoundation.h"
#include "sharedFoundation/ConfigFile.h"
#include "sharedFoundation/Production.h"
// ======================================================================
#define KEY_INT(a,b) (ms_ ## a = ConfigFile::getKeyInt("SharedFoundation", #a, b))
#define KEY_BOOL(a,b) (ms_ ## a = ConfigFile::getKeyBool("SharedFoundation", #a, b))
#define KEY_FLOAT(a,b) (ms_ ## a = ConfigFile::getKeyFloat("SharedFoundation", #a, b))
#define KEY_STRING(a,b) (ms_ ## a = ConfigFile::getKeyString("SharedFoundation", #a, b))
// ======================================================================
const int c_defaultFatalCallStackDepth = 32;
const int c_defaultWarningCallStackDepth = PRODUCTION ? -1 : 8;
// ======================================================================
namespace ConfigSharedFoundationNamespace
{
bool ms_noExceptionHandling;
bool ms_fpuExceptionPrecision;
bool ms_fpuExceptionUnderflow;
bool ms_fpuExceptionOverflow;
bool ms_fpuExceptionZeroDivide;
bool ms_fpuExceptionDenormal;
bool ms_fpuExceptionInvalid;
bool ms_demoMode;
real ms_frameRateLimit;
real ms_minFrameRate;
bool ms_useRemoteDebug;
int ms_defaultRemoteDebugPort;
bool ms_profilerExpandAllBranches;
bool ms_memoryManagerReportAllocations;
bool ms_memoryManagerReportOnOutOfMemory;
bool ms_useMemoryBlockManager;
bool ms_memoryBlockManagerDebugDumpOnRemove;
int ms_fatalCallStackDepth;
int ms_warningCallStackDepth;
bool ms_lookUpCallStackNames;
int ms_processPriority;
bool ms_verboseHardwareLogging;
bool ms_verboseWarnings;
bool ms_causeAccessViolation;
float ms_debugReportLongFrameTime;
}
using namespace ConfigSharedFoundationNamespace;
// ======================================================================
// Determine the Platform-specific configuration information
//
// Remarks:
//
// This routine inspects the ConfigFile class to set some variables for rapid access
// by the rest of the engine.
void ConfigSharedFoundation::install (const Defaults &defaults)
{
KEY_BOOL(noExceptionHandling, false);
KEY_BOOL(fpuExceptionPrecision, false);
KEY_BOOL(fpuExceptionUnderflow, false);
KEY_BOOL(fpuExceptionOverflow, false);
KEY_BOOL(fpuExceptionZeroDivide, false);
KEY_BOOL(fpuExceptionDenormal, false);
KEY_BOOL(fpuExceptionInvalid, false);
KEY_BOOL(demoMode, defaults.demoMode);
#if defined (WIN32) && PRODUCTION == 1
// In production builds, force our frame rate limit to be the application defined limit
ms_frameRateLimit = defaults.frameRateLimit;
#else
KEY_FLOAT(frameRateLimit, defaults.frameRateLimit);
#endif
KEY_FLOAT(minFrameRate, 1.0f);
KEY_BOOL(useRemoteDebug, false);
KEY_INT(defaultRemoteDebugPort, 4445);
KEY_BOOL(profilerExpandAllBranches, false);
KEY_BOOL(memoryManagerReportAllocations, true);
KEY_BOOL(memoryManagerReportOnOutOfMemory, true);
KEY_BOOL(useMemoryBlockManager, true);
KEY_BOOL(memoryBlockManagerDebugDumpOnRemove, false);
KEY_INT(fatalCallStackDepth, c_defaultFatalCallStackDepth);
KEY_INT(warningCallStackDepth, PRODUCTION ? -1 : c_defaultWarningCallStackDepth);
KEY_BOOL(lookUpCallStackNames, true);
KEY_INT(processPriority, 0);
KEY_BOOL(verboseHardwareLogging, false);
KEY_BOOL(verboseWarnings, defaults.verboseWarnings);
KEY_BOOL(causeAccessViolation, false);
KEY_FLOAT(debugReportLongFrameTime, 0.25f);
}
// ----------------------------------------------------------------------
/**
* Return whether to run with exception handling enabled.
*
* @return True to run without exception handling
*/
bool ConfigSharedFoundation::getNoExceptionHandling()
{
return ms_noExceptionHandling;
}
// ----------------------------------------------------------------------
bool ConfigSharedFoundation::getFpuExceptionPrecision()
{
return ms_fpuExceptionPrecision;
}
// ----------------------------------------------------------------------
bool ConfigSharedFoundation::getFpuExceptionUnderflow()
{
return ms_fpuExceptionUnderflow;
}
// ----------------------------------------------------------------------
bool ConfigSharedFoundation::getFpuExceptionOverflow()
{
return ms_fpuExceptionOverflow;
}
// ----------------------------------------------------------------------
bool ConfigSharedFoundation::getFpuExceptionZeroDivide()
{
return ms_fpuExceptionZeroDivide;
}
// ----------------------------------------------------------------------
bool ConfigSharedFoundation::getFpuExceptionDenormal()
{
return ms_fpuExceptionDenormal;
}
// ----------------------------------------------------------------------
bool ConfigSharedFoundation::getFpuExceptionInvalid()
{
return ms_fpuExceptionInvalid;
}
// ----------------------------------------------------------------------
bool ConfigSharedFoundation::getDemoMode()
{
return ms_demoMode;
}
// ----------------------------------------------------------------------
/**
* Return the frame rate limit value for the game.
*
* @return The initial frame rate limiter value
*/
real ConfigSharedFoundation::getFrameRateLimit()
{
return ms_frameRateLimit;
}
// ----------------------------------------------------------------------
/**
* Return the minimum frame rate value for the game. Frames that take longer
* will log a warning and be hard set to the given value.
*
* @return The initial min frame rate value
*/
real ConfigSharedFoundation::getMinFrameRate()
{
return ms_minFrameRate;
}
// ----------------------------------------------------------------------
int ConfigSharedFoundation::getDefaultRemoteDebugPort()
{
return ms_defaultRemoteDebugPort;
}
// ----------------------------------------------------------------------
bool ConfigSharedFoundation::getUseRemoteDebug()
{
return ms_useRemoteDebug;
}
// ----------------------------------------------------------------------
bool ConfigSharedFoundation::getProfilerExpandAllBranches()
{
return ms_profilerExpandAllBranches;
}
// ----------------------------------------------------------------------
bool ConfigSharedFoundation::getMemoryManagerReportAllocations()
{
return ms_memoryManagerReportAllocations;
}
// ----------------------------------------------------------------------
bool ConfigSharedFoundation::getMemoryManagerReportOnOutOfMemory()
{
return ms_memoryManagerReportOnOutOfMemory;
}
// ----------------------------------------------------------------------
bool ConfigSharedFoundation::getUseMemoryBlockManager()
{
return ms_useMemoryBlockManager;
}
// ----------------------------------------------------------------------
bool ConfigSharedFoundation::getMemoryBlockManagerDebugDumpOnRemove ()
{
return ms_memoryBlockManagerDebugDumpOnRemove;
}
// ----------------------------------------------------------------------
int ConfigSharedFoundation::getFatalCallStackDepth()
{
return ms_fatalCallStackDepth;
}
// ----------------------------------------------------------------------
int ConfigSharedFoundation::getWarningCallStackDepth()
{
return ms_warningCallStackDepth;
}
// ----------------------------------------------------------------------
bool ConfigSharedFoundation::getLookUpCallStackNames()
{
return ms_lookUpCallStackNames;
}
// ----------------------------------------------------------------------
int ConfigSharedFoundation::getProcessPriority()
{
return ms_processPriority;
}
// ----------------------------------------------------------------------
bool ConfigSharedFoundation::getVerboseHardwareLogging()
{
return ms_verboseHardwareLogging;
}
// ----------------------------------------------------------------------
bool ConfigSharedFoundation::getVerboseWarnings()
{
return ms_verboseWarnings;
}
// ----------------------------------------------------------------------
void ConfigSharedFoundation::setVerboseWarnings(bool const verboseWarnings)
{
ms_verboseWarnings = verboseWarnings;
}
// ----------------------------------------------------------------------
bool ConfigSharedFoundation::getCauseAccessViolation()
{
return ms_causeAccessViolation;
}
// ----------------------------------------------------------------------
float ConfigSharedFoundation::getDebugReportLongFrameTime()
{
return ms_debugReportLongFrameTime;
}
// ======================================================================
@@ -1,74 +0,0 @@
// ======================================================================
//
// ConfigSharedFoundation.h
// copyright 1998 Bootprint Entertainment
// copyright 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConfigSharedFoundation_H
#define INCLUDED_ConfigSharedFoundation_H
// ======================================================================
class ConfigSharedFoundation
{
public:
struct Defaults
{
int screenHeight;
int screenWidth;
bool windowed;
real frameRateLimit;
bool demoMode;
bool verboseWarnings;
};
public:
static void install(const Defaults &defaults);
static bool getNoExceptionHandling();
static bool getFpuExceptionPrecision();
static bool getFpuExceptionUnderflow();
static bool getFpuExceptionOverflow();
static bool getFpuExceptionZeroDivide();
static bool getFpuExceptionDenormal();
static bool getFpuExceptionInvalid();
static bool getDemoMode();
static real getFrameRateLimit();
static real getMinFrameRate();
static bool getUseRemoteDebug();
static int getDefaultRemoteDebugPort();
static bool getProfilerExpandAllBranches();
static bool getMemoryManagerReportAllocations();
static bool getMemoryManagerReportOnOutOfMemory();
static bool getUseMemoryBlockManager();
static bool getMemoryBlockManagerDebugDumpOnRemove();
static int getFatalCallStackDepth();
static int getWarningCallStackDepth();
static bool getLookUpCallStackNames();
static int getProcessPriority();
static DLLEXPORT bool getVerboseHardwareLogging();
static bool getVerboseWarnings();
static void setVerboseWarnings(bool verboseWarnings);
static bool getCauseAccessViolation();
static float getDebugReportLongFrameTime();
};
// ======================================================================
#endif
@@ -1,82 +0,0 @@
// ======================================================================
//
// FirstPlatform.h
// copyright 1998 Bootprint Entertainment
// copyright 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_FirstPlatform_H
#define INCLUDED_FirstPlatform_H
#ifdef WIN32
#include <WinNT.h>
#include <WinDef.h>
#endif
// ======================================================================
// C4127 conditional expression is constant
// C4291 no matching operator delete found; memory will not be freed if initialization throws an exception
// C4503 decorated name length exceeded, name was truncated
// C4514 unreferenced inline function has been removed
// C4702 unreachable code
// C4710 inline function not expanded
// C4786 identifier was truncated to 'number' characters in the debug
#pragma warning(disable: 4127 4291 4503 4514 4702 4710 4786)
// ======================================================================
// If we haven't defined this yet, then we're not compiling a DLL
#ifndef COMPILE_DLL
#define COMPILE_DLL 0
#endif
#if COMPILE_DLL
#define DLLEXPORT __declspec(dllimport)
#else
#define DLLEXPORT __declspec(dllexport)
#endif
// ======================================================================
template <class T>
inline int ComGetReferenceCount(T *t)
{
t->AddRef();
return t->Release();
}
// ======================================================================
// forward declare some windows stuff to avoid having to include <windows.h> here
struct HCURSOR__;
struct HICON__;
struct HINSTANCE__;
struct HWND__;
typedef void *HANDLE;
typedef HICON__ *HCURSOR;
typedef HICON__ *HICON;
typedef HINSTANCE__ *HINSTANCE;
typedef HWND__ *HWND;
// @todo codereorg still working on this
#include "sharedFoundation/WindowsWrapper.h"
// ======================================================================
// convienent fatal macros that check windows HRESULT codes
#define FATAL_HR(a,b) FATAL(FAILED(b), (a, HRESULT_CODE(b)))
#define DEBUG_FATAL_HR(a,b) DEBUG_FATAL(FAILED(b), (a, HRESULT_CODE(b)))
// ======================================================================
// include anything we need to replace missing functionality that other platforms provide
#include "sharedFoundation/PlatformGlue.h"
// ======================================================================
#endif
@@ -1,8 +0,0 @@
// ======================================================================
//
// FirstFoundation.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedFoundation/FirstSharedFoundation.h"
@@ -1,257 +0,0 @@
// ======================================================================
//
// FloatingPointUnit.cpp
// copyright 1999 Bootprint Entertainment
// copyright 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedFoundation/FirstSharedFoundation.h"
#include "sharedFoundation/FloatingPointUnit.h"
#include "sharedFoundation/ConfigSharedFoundation.h"
// ======================================================================
int FloatingPointUnit::updateNumber;
ushort FloatingPointUnit::status;
FloatingPointUnit::Precision FloatingPointUnit::precision;
FloatingPointUnit::Rounding FloatingPointUnit::rounding;
bool FloatingPointUnit::exceptionEnabled[E_max];
// ======================================================================
const WORD PRECISION_MASK = BINARY4(0000,0011,0000,0000);
const WORD PRECISION_24 = BINARY4(0000,0000,0000,0000);
const WORD PRECISION_53 = BINARY4(0000,0010,0000,0000);
const WORD PRECISION_64 = BINARY4(0000,0011,0000,0000);
const WORD ROUND_MASK = BINARY4(0000,1100,0000,0000);
const WORD ROUND_NEAREST = BINARY4(0000,0000,0000,0000);
const WORD ROUND_CHOP = BINARY4(0000,1100,0000,0000);
const WORD ROUND_DOWN = BINARY4(0000,0100,0000,0000);
const WORD ROUND_UP = BINARY4(0000,1000,0000,0000);
const WORD EXCEPTION_PRECISION = BINARY4(0000,0000,0010,0000);
const WORD EXCEPTION_UNDERFLOW = BINARY4(0000,0000,0001,0000);
const WORD EXCEPTION_OVERFLOW = BINARY4(0000,0000,0000,1000);
const WORD EXCEPTION_ZERO_DIVIDE = BINARY4(0000,0000,0000,0100);
const WORD EXCEPTION_DENORMAL = BINARY4(0000,0000,0000,0010);
const WORD EXCEPTION_INVALID = BINARY4(0000,0000,0000,0001);
const WORD EXCEPTION_ALL = BINARY4(0000,0000,0011,1111);
// ======================================================================
void FloatingPointUnit::install(void)
{
precision = P_24;
rounding = R_roundToNearestOrEven;
memset(exceptionEnabled, 0, sizeof(exceptionEnabled));
// preserve all other bits
status = getControlWord();
status &= ~(PRECISION_MASK | ROUND_MASK | EXCEPTION_ALL);
// set to single precision, rounding, and all exceptions masked
status |= PRECISION_24 | ROUND_NEAREST | EXCEPTION_ALL;
// check the config platform flags to see if we should enable some exceptions
if (ConfigSharedFoundation::getFpuExceptionPrecision())
{
exceptionEnabled[E_precision] = true;
status &= ~EXCEPTION_PRECISION;
}
if (ConfigSharedFoundation::getFpuExceptionUnderflow())
{
exceptionEnabled[E_underflow] = true;
status &= ~EXCEPTION_UNDERFLOW;
}
if (ConfigSharedFoundation::getFpuExceptionOverflow())
{
exceptionEnabled[E_overflow] = true;
status &= ~EXCEPTION_OVERFLOW;
}
if (ConfigSharedFoundation::getFpuExceptionZeroDivide())
{
exceptionEnabled[E_zeroDivide] = true;
status &= ~EXCEPTION_ZERO_DIVIDE;
}
if (ConfigSharedFoundation::getFpuExceptionDenormal())
{
exceptionEnabled[E_denormal] = true;
status &= ~EXCEPTION_DENORMAL;
}
if (ConfigSharedFoundation::getFpuExceptionInvalid())
{
exceptionEnabled[E_invalid] = true;
status &= ~EXCEPTION_INVALID;
}
setControlWord(status);
}
// ----------------------------------------------------------------------
void FloatingPointUnit::update(void)
{
WORD currentStatus = getControlWord();
if (currentStatus != status)
{
// DEBUG_REPORT_LOG_PRINT(true, ("FPU: update=%d, in mode=%04x, should be in mode=%04x\n", updateNumber, static_cast<int>(currentStatus), static_cast<int>(status)));
setControlWord(status);
}
++updateNumber;
}
// ----------------------------------------------------------------------
WORD FloatingPointUnit::getControlWord(void)
{
WORD controlWord = 0;
__asm fnstcw controlWord;
return controlWord;
}
// ----------------------------------------------------------------------
void FloatingPointUnit::setControlWord(WORD controlWord)
{
UNREF(controlWord);
__asm fldcw controlWord;
}
// ----------------------------------------------------------------------
void FloatingPointUnit::setPrecision(Precision newPrecision)
{
WORD bits = 0;
switch (precision)
{
case P_24:
bits = PRECISION_24;
break;
case P_53:
bits = PRECISION_53;
break;
case P_64:
bits = PRECISION_64;
break;
case P_max:
default:
DEBUG_FATAL(true, ("bad case"));
}
// record the current state
precision = newPrecision;
// set the proper bit pattern
status &= ~PRECISION_MASK;
status |= bits;
// slam it into the FPU
setControlWord(status);
}
// ----------------------------------------------------------------------
void FloatingPointUnit::setRounding(Rounding newRounding)
{
WORD bits = 0;
switch (newRounding)
{
case R_roundToNearestOrEven:
bits = ROUND_NEAREST;
break;
case R_chop:
bits = ROUND_CHOP;
break;
case R_roundDown:
bits = ROUND_DOWN;
break;
case R_roundUp:
bits = ROUND_UP;
break;
case R_max:
default:
DEBUG_FATAL(true, ("bad case"));
}
// record the current state
rounding = newRounding;
// set the proper bit pattern
status &= ~ROUND_MASK;
status |= bits;
// slam it into the FPU
setControlWord(status);
}
// ----------------------------------------------------------------------
void FloatingPointUnit::setExceptionEnabled(Exception exception, bool enabled)
{
WORD bits = 0;
switch (exception)
{
case E_precision:
bits = EXCEPTION_PRECISION;
break;
case E_underflow:
bits = EXCEPTION_UNDERFLOW;
break;
case E_overflow:
bits = EXCEPTION_OVERFLOW;
break;
case E_zeroDivide:
bits = EXCEPTION_ZERO_DIVIDE;
break;
case E_denormal:
bits = EXCEPTION_DENORMAL;
break;
case E_invalid:
bits = EXCEPTION_INVALID;
break;
case E_max:
default:
DEBUG_FATAL(true, ("bad case"));
}
// record the current state
exceptionEnabled[exception] = enabled;
// twiddle the bit appropriately. these bits masks, so set the bit to disable the exception, clear the bit to enable it.
if (enabled)
status &= ~bits;
else
status |= bits;
// slam it into the FPU
setControlWord(status);
}
// ======================================================================
@@ -1,104 +0,0 @@
// ======================================================================
//
// FloatingPointUnit.h
// jeff grills
//
// copyright 1999 Bootprint Entertainment
//
// ======================================================================
#ifndef FLOATING_POINT_UNIT_H
#define FLOATING_POINT_UNIT_H
// ======================================================================
class FloatingPointUnit
{
public:
typedef unsigned short WORD;
enum Precision
{
P_24,
P_53,
P_64,
P_max
};
enum Rounding
{
R_roundToNearestOrEven,
R_chop,
R_roundDown,
R_roundUp,
R_max
};
enum Exception
{
E_precision,
E_underflow,
E_overflow,
E_zeroDivide,
E_denormal,
E_invalid,
E_max
};
private:
static int updateNumber;
static WORD status;
static Precision precision;
static Rounding rounding;
static bool exceptionEnabled[E_max];
public:
static WORD getControlWord(void);
static void setControlWord(WORD controlWord);
public:
static void install(void);
static void update(void);
static void setPrecision(Precision newPrecision);
static void setRounding(Rounding newRounding);
static void setExceptionEnabled(Exception exception, bool enabled);
static Precision getPrecision(void);
static Rounding getRounding(void);
static bool getExceptionEnabled(Exception exception);
};
// ======================================================================
inline FloatingPointUnit::Precision FloatingPointUnit::getPrecision(void)
{
return precision;
}
// ----------------------------------------------------------------------
inline FloatingPointUnit::Rounding FloatingPointUnit::getRounding(void)
{
return rounding;
}
// ----------------------------------------------------------------------
inline bool FloatingPointUnit::getExceptionEnabled(Exception theException)
{
DEBUG_FATAL(static_cast<int>(theException) < 0 || static_cast<int>(theException) >= static_cast<int>(E_max), ("exception out of range")); //lint !e568 // non-negative quantity is never less than 0
return exceptionEnabled[theException];
}
// ======================================================================
#endif
File diff suppressed because it is too large Load Diff
@@ -1,152 +0,0 @@
// ======================================================================
//
// Os.h
//
// Portions copyright 1998 Bootprint Entertainment
// Portions copyright 2000-2002 Sony Online Entertainment
// All Rights Reserved
//
// ======================================================================
#ifndef INCLUDED_Os_H
#define INCLUDED_Os_H
// ======================================================================
#include <ctime>
// ======================================================================
class Os
{
public:
typedef bool (*IsGdiVisibleHookFunction)();
typedef void (*LostFocusHookFunction)();
typedef void (*AcquiredFocusHookFunction)();
typedef void (*QueueCharacterHookFunction)(int keyboard, int character);
typedef void (*SetSystemMouseCursorPositionHookFunction)(int x, int y);
typedef bool (*GetHardwareMouseCursorEnabled)();
typedef void (*GetOtherAdapterRectsHookFunction)(stdvector<RECT>::fwd &);
typedef void (*WindowPositionChangedHookFunction)();
typedef void (*DisplayModeChangedHookFunction)();
typedef void (*InputLanguageChangedHookFunction)();
typedef int (*IMEHookFunction)(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
typedef void (*QueueKeyDownHookFunction)(int keyboard, int character);
typedef uint ThreadId;
typedef DWORD OsPID_t;
enum Priority
{
P_high,
P_normal,
P_low
};
enum
{
MAX_PATH_LENGTH = 512
};
public:
static void install(HINSTANCE newInstance, const char *windowName, HICON normalIcon, HICON smallIcon);
static void install(HWND newWindow, bool processMessagePump);
static void install();
static bool isGameOver();
static DLLEXPORT bool isMainThread();
static bool wasFocusLost();
static void checkChildThreads();
static void setProcessPriority(Priority priority);
static bool update();
static void returnFromAbort();
static void abort();
static void enablePopupDebugMenu();
static void requestPopupDebugMenu();
static bool createDirectories (const char *dirname);
static bool writeFile(const char *fileName, const void *data, int length);
static HWND getWindow();
static bool engineOwnsWindow();
static int getNumberOfUpdates();
static char *getLastError();
static const char *getProgramName();
static const char *getShortProgramName();
static const char *getProgramStartupDirectory();
static void setIsGdiVisibleHookFunction(IsGdiVisibleHookFunction newGlIsGdiVisible);
static void setLostFocusHookFunction(LostFocusHookFunction lostFocusHookFunction);
static void setQueueCharacterHookFunction(QueueCharacterHookFunction queueCharacterHookFunction);
static void setSetSystemMouseCursorPositionHookFunction(SetSystemMouseCursorPositionHookFunction setSystemMouseCursorPositionHookFunction);
static void setSetSystemMouseCursorPositionHookFunction2(SetSystemMouseCursorPositionHookFunction setSystemMouseCursorPositionHookFunction);
static void setAcquiredFocusHookFunction(AcquiredFocusHookFunction acquiredFocusHookFunction);
static void setAcquiredFocusHookFunction2(AcquiredFocusHookFunction acquiredFocusHookFunction);
static void setGetHardwareMouseCursorEnabled(GetHardwareMouseCursorEnabled getHardwareMouseCursorEnabled);
static void setGetOtherAdapterRectsHookFunction(GetOtherAdapterRectsHookFunction getOtherAdapterRectsHookFunction);
static void setWindowPositionChangedHookFunction(WindowPositionChangedHookFunction windowPositionChangedHookFunction);
static void setDisplayModeChangedHookFunction(DisplayModeChangedHookFunction displayModeChangedHookFunction);
static void setInputLanguageChangedHookFunction(InputLanguageChangedHookFunction inputLanguageChangedHookFunction);
static void setIMEHookFunction(IMEHookFunction imeHookFunction);
static void setQueueKeyDownHookFunction(QueueKeyDownHookFunction queueKeyDownHookFunction);
static DLLEXPORT ThreadId getThreadId();
static void setThreadName(ThreadId threadID, const char* name);
static void sleep(int ms);
static time_t getRealSystemTime();
static void convertTimeToGMT(const time_t &time, tm &zulu);
static time_t convertGMTToTime(const tm &zulu);
static bool isMultiprocessor();
static int getProcessorCount();
static void buildRelativePath(const char *baseDirectory, const char *targetPathname, std::string &relativePath);
static bool getAbsolutePath(const char *relativePath, char *absolutePath, int absolutePathBufferSize);
static bool copyTextToClipboard(const char *text);
static bool getUserName(char *buffer, int &bufferSize);
static OsPID_t getProcessId();
static bool isFocused();
static bool launchBrowser(std::string const & website);
static bool isNumPadValue(unsigned char asciiChar);
static bool isNumPadChar(unsigned char asciiChar);
private:
Os();
Os(const Os &);
Os &operator =(const Os &);
private:
static void remove();
static void installCommon();
static LRESULT CALLBACK Os::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
private:
private:
static bool handleDebugMenu();
};
// ======================================================================
#endif
@@ -1,465 +0,0 @@
// ======================================================================
//
// PerThreadData.cpp
//
// Portions copyright 1998 Bootprint Entertainment
// Portions Copyright 2002 Sony Online Entertainment
// All Rights Reserved
//
// ======================================================================
#include "sharedFoundation/FirstSharedFoundation.h"
#include "sharedFoundation/PerThreadData.h"
#include "sharedSynchronization/RecursiveMutex.h"
#include "sharedSynchronization/Gate.h"
#include "sharedFoundation/Os.h"
#include <winbase.h>
#include <vector>
// ======================================================================
// ======================================================================
namespace PerThreadDataNamespace
{
struct Data
{
bool exitChainRunning;
bool exitChainFataling;
ExitChain::Entry *exitChainFirstEntry;
int debugPrintFlags;
Gate *fileStreamerReadGate;
HANDLE watchHandle;
};
typedef std::vector<Data *> DataAllocations;
// ------------------------------------------------------
static char buffer1[sizeof(RecursiveMutex)];
static char buffer2[sizeof(DataAllocations)];
static const DWORD BadSlot = 0xffffffff;
static DWORD slot = BadSlot;
static RecursiveMutex *criticalSection;
static DataAllocations *dataAllocations;
// ------------------------------------------------------
static void _threadRemove(Data *data);
static void _removeFromList(Data *data);
static void _watchThreads();
/*----------------------------------------------------------------------
* Get access to the per-thread-data.
*
* This routine will verify the per-thread-data subsystem has been installed and the
* threadInstall() function has been called for the current thread.
*
* @return A pointer to the per-thread-data.
*/
inline static Data *_getData(bool allowReturnNull=false)
{
UNREF(allowReturnNull);
if (slot == BadSlot)
{
DEBUG_FATAL(true && !allowReturnNull, ("not installed"));
return NULL;
}
Data * const data = reinterpret_cast<Data *>(TlsGetValue(slot));
DEBUG_FATAL(!data && !allowReturnNull, ("not installed for this thread"));
return data;
}
// ------------------------------------------------------
inline static void _closeData(Data *data)
{
if (data->fileStreamerReadGate)
{
delete data->fileStreamerReadGate;
data->fileStreamerReadGate=0;
}
if (data->watchHandle)
{
CloseHandle(data->watchHandle);
data->watchHandle=0;
}
}
// ------------------------------------------------------
inline static void _freeData(Data *data)
{
delete data;
}
// ------------------------------------------------------
}
using namespace PerThreadDataNamespace;
// ======================================================================
// ======================================================================
// Install the per-thread-data subsystem
//
// Remarks:
//
// This routine will install the per-thread-data subsystem that is required for several
// other subsystems in the engine. It should be called from the primary thread before
// any other threads have been created. It will also call threadInstall() for the
// primary thread.
//
// See Also:
//
// PerThreadData::remove()
void PerThreadData::install()
{
slot = TlsAlloc();
FATAL(slot == BadSlot, ("TlsAlloc failed"));
criticalSection = new(buffer1) RecursiveMutex;
dataAllocations = new(buffer2) DataAllocations;
dataAllocations->reserve(8);
threadInstall();
}
// ----------------------------------------------------------------------
/**
* Remove the per-thread-subsystem.
*
* This routine should be called by the primary thread after all other threads have
* terminated, and no other uses of per-thread-data will occur.
*
* @see PerThreadData::install()
*/
void PerThreadData::remove()
{
criticalSection->enter();
{
// remove this thread.
threadRemove();
// clean up after any threads which didn't clean up after themselves (like the miles sound system)
const DataAllocations::iterator iEnd = dataAllocations->end();
for (DataAllocations::iterator i = dataAllocations->begin(); i != iEnd; ++i)
{
_closeData(*i);
_freeData(*i);
}
dataAllocations->clear();
}
criticalSection->leave();
criticalSection->~RecursiveMutex();
dataAllocations->~vector();
memset(buffer1, 0, sizeof(buffer1));
memset(buffer2, 0, sizeof(buffer2));
const BOOL result = TlsFree(slot);
FATAL(!result, ("TlsFree failed"));
}
// ----------------------------------------------------------------------
/**
* Create the per-thread-data for a new thread.
*
* This routine should be called in a thread before the first usage of per-thread-data.
*
* If the client is calling this function on a thread that existed before the engine was
* installed, the client should set isNewThread to false. Setting isNewThread to false
* prevents the function from validating that the thread's TLS is NULL. For threads existing
* before the engine is installed, the TLS data for the thread is undefined.
*
* @param isNewThread [IN] true if the thread was created after the engine was installed, false otherwise
* @see PerThreadData::threadRemove()
*/
void PerThreadData::threadInstall(bool isNewThread)
{
UNREF(isNewThread);
DEBUG_FATAL(slot == BadSlot, ("not installed"));
// only check for already-set data if this is supposed to be a new thread
DEBUG_FATAL(isNewThread && TlsGetValue(slot), ("already installed for this thread"));
// create the data
Data * const data = new Data;
// initialize the data
memset(data, 0, sizeof(*data));
//create the event for file streaming reads
data->fileStreamerReadGate = new Gate(false);
// set the data into the thread slot
const BOOL result = TlsSetValue(slot, data);
UNREF(result);
DEBUG_FATAL(!result, ("TlsSetValue failed"));
criticalSection->enter();
{
_watchThreads();
dataAllocations->push_back(data);
// This is most likely a thread created by a 3rd party library such as Miles or Bink.
// Add a watch handle to it so we can clean it up.
if (!isNewThread)
{
const HANDLE processHandle = GetCurrentProcess();
DuplicateHandle(processHandle, GetCurrentThread(), processHandle, &data->watchHandle, 0, FALSE, DUPLICATE_SAME_ACCESS);
}
}
criticalSection->leave();
}
// ----------------------------------------------------------------------
void PerThreadDataNamespace::_removeFromList(Data *data)
{
const DataAllocations::iterator iEnd = dataAllocations->end();
const DataAllocations::iterator i = std::find(dataAllocations->begin(), iEnd, data);
if (i!=iEnd)
{
dataAllocations->erase(i);
}
}
// ----------------------------------------------------------------------
// Synchronization is left up to the user
// Unless this is called during shutdown, the critical section
// needs to be entered.
void PerThreadDataNamespace::_watchThreads()
{
DataAllocations::iterator tiDest = dataAllocations->begin();
DataAllocations::iterator tiSrc = tiDest;
DataAllocations::iterator tiEnd = dataAllocations->end();
while (tiSrc!=tiEnd)
{
Data *const data = *tiSrc;
const HANDLE h = data->watchHandle;
if (h!=0 && WaitForSingleObject(h, 0)==WAIT_OBJECT_0)
{
_closeData(data);
_freeData(data);
}
else
{
*tiDest++=data;
}
++tiSrc;
}
if (tiSrc!=tiDest)
{
const int newSize = tiDest - dataAllocations->begin();
dataAllocations->resize(newSize);
}
}
// ----------------------------------------------------------------------
void PerThreadDataNamespace::_threadRemove(Data *data)
{
//close the event used for file streaming reads
_closeData(data);
_removeFromList(data);
// free the memory
_freeData(data);
}
// ----------------------------------------------------------------------
/**
* Destroy the per-thread-data for a terminating thread.
*
* This routine should be called in a thread after the last usage of per-thread-data.
*
* @see PerThreadData::threadInstall()
*/
void PerThreadData::threadRemove()
{
DEBUG_FATAL(slot == BadSlot, ("not installed"));
DEBUG_FATAL(!TlsGetValue(slot), ("thread not installed"));
// find our thread record and free the memory
criticalSection->enter();
_threadRemove(_getData());
// wipe the data in the thread slot
const BOOL result = TlsSetValue(slot, NULL);
UNREF(result);
DEBUG_FATAL(!result, ("TlsSetValue failed"));
criticalSection->leave();
}
// ======================================================================
// ======================================================================
// Determine if the per-thread-data is available for this thread
//
// Return value:
//
// True if the per-thread-data is installed correctly, false otherwise
//
// Remarks:
//
// This routine is not intended for general use; it should only be used by the ExitChain class.
//
// -TRF- looks like Win98 does not zero out a new TLS slot for
// threads existing at the time of slot creation. Thus, if you build a
// plugin that only initializes the engine the first time it is
// used, and other threads already exist in the app, those threads
// will contain bogus non-null data in the TLS slot. If the plugin really
// wants to do lazy initialization of the engine, it will need
// to handle calling PerThreadData::threadInstall() for all existing threads
// (except the thread that initialized the engine, which already
// has its PerThreadData::threadInstall() called).
bool PerThreadData::isThreadInstalled()
{
return (_getData(true) != NULL);
}
// ----------------------------------------------------------------------
/**
* Get the exit chain running flag value.
*
* This routine is not intended for general use; it should only be used by the ExitChain class.
*
* @return True if the exit chain is running, false otherwise.
* @see ExitChain::isRunning()
*/
bool PerThreadData::getExitChainRunning()
{
return _getData()->exitChainRunning;
}
// ----------------------------------------------------------------------
/**
* Set the exit chain running flag value.
*
* This routine is not intended for general use; it should only be used by the ExitChain class.
*
* @param newValue New value for the exit chain running flag
*/
void PerThreadData::setExitChainRunning(bool newValue)
{
_getData()->exitChainRunning = newValue;
}
// ----------------------------------------------------------------------
/**
* Get the exit chain fataling flag value.
*
* This routine is not intended for general use; it should only be used by the ExitChain class.
*
* @return True if the exit chain is fataling, false otherwise.
* @see ExitChain::isFataling()
*/
bool PerThreadData::getExitChainFataling()
{
return _getData()->exitChainFataling;
}
// ----------------------------------------------------------------------
/**
* Set the exit chain fataling flag value.
*
* This routine is not intended for general use; it should only be used by the ExitChain class.
*
* @param newValue New value for the exit chain fataling flag
*/
void PerThreadData::setExitChainFataling(bool newValue)
{
_getData()->exitChainFataling = newValue;
}
// ----------------------------------------------------------------------
/**
* Get the first entry for the exit chain.
*
* This routine is not intended for general use; it should only be used by the ExitChain class.
* This routine may return NULL.
*
* @return Pointer to the first entry on the exit chain
* @see ExitChain::isFataling()
*/
ExitChain::Entry *PerThreadData::getExitChainFirstEntry()
{
return _getData()->exitChainFirstEntry;
}
// ----------------------------------------------------------------------
/**
* Set the exit chain fataling flag value.
*
* This routine is not intended for general use; it should only be used by the ExitChain class.
* The parameter to this routine may be NULL.
*
* @param newValue New value for the exit chain first entry
*/
void PerThreadData::setExitChainFirstEntry(ExitChain::Entry *newValue)
{
_getData()->exitChainFirstEntry = newValue;
}
// ----------------------------------------------------------------------
/**
* Get the debug print flags.
*
* This routine is not intended for general use; it should only be used by the DebugPrint functions.
*
* @return Current value of the debug print flags
*/
int PerThreadData::getDebugPrintFlags()
{
return _getData()->debugPrintFlags;
}
// ----------------------------------------------------------------------
/**
* Set the debug print flags value.
*
* This routine is not intended for general use; it should only be used by the DebugPrint functions.
*/
void PerThreadData::setDebugPrintFlags(int newValue)
{
_getData()->debugPrintFlags = newValue;
}
// ----------------------------------------------------------------------
Gate *PerThreadData::getFileStreamerReadGate()
{
return _getData()->fileStreamerReadGate;
}
// ======================================================================
@@ -1,57 +0,0 @@
// ======================================================================
//
// PerThreadData.h
//
// Portions copyright 1998 Bootprint Entertainment
// Portions Copyright 2002 Sony Online Entertainment
// All Rights Reserved
//
// ======================================================================
#ifndef INCLUDED_PerThreadData_H
#define INCLUDED_PerThreadData_H
// ======================================================================
class Gate;
#include "sharedFoundation/ExitChain.h"
// ======================================================================
// Provide thread local storage functionality.
//
// This class' purpose is to allow each thread to maintain some storage that is local and private to each thread.
// The system must be installed before use. Each thread that may use per-thread-data will also need to call the
// threadInstall() routine after creation and threadRemove() just before termination of the thread.
class PerThreadData
{
public:
static void install(void);
static void remove(void);
static void threadInstall(bool isNewThread = true);
static void threadRemove(void);
static bool isThreadInstalled(void);
static bool getExitChainRunning(void);
static void setExitChainRunning(bool newValue);
static bool getExitChainFataling(void);
static void setExitChainFataling(bool newValue);
static ExitChain::Entry *getExitChainFirstEntry(void);
static void setExitChainFirstEntry(ExitChain::Entry *newValue);
static int getDebugPrintFlags(void);
static void setDebugPrintFlags(int newValue);
static Gate *getFileStreamerReadGate(void);
};
// ======================================================================
#endif
@@ -1,124 +0,0 @@
// ======================================================================
//
// PlatformGlue.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedFoundation/FirstSharedFoundation.h"
#include "sharedFoundation/PlatformGlue.h"
#include <cstdio>
#include <cstdarg>
// ======================================================================
namespace
{
// ----------------------------------------------------------------------
class GmTimeSection
{
public:
GmTimeSection()
{
InitializeCriticalSection(&m_section);
}
~GmTimeSection()
{
DeleteCriticalSection(&m_section);
}
void enter()
{
EnterCriticalSection(&m_section);
}
void leave()
{
LeaveCriticalSection(&m_section);
}
private:
CRITICAL_SECTION m_section;
};
// ----------------------------------------------------------------------
static GmTimeSection s_gmTimeSection;
// ----------------------------------------------------------------------
}
// ======================================================================
// Tokenizing a string.
// Like strtok, except re-entrant.
char *strsep(char **string, const char *delim)
{
char *result = *string;
// handle no string specified, or the end of the string
if (result == 0)
return 0;
// skip leading delimiters
result = result + strspn(result, delim);
// handle trailing delimiters
if (*result == '\0')
return 0;
// look for the first delimiter
const int len = strcspn(result, delim);
if (result[len] == '\0')
{
// hit the end of the string
*string = 0;
}
else
{
// terminate the string and return the substring
result[len] = '\0';
*string = result + len + 1;
}
return result;
}
// ----------------------------------------------------------------------
int snprintf(char *buffer, size_t count, const char *format, ...)
{
va_list va;
va_start(va, format);
const int result = _vsnprintf(buffer, count, format, va);
va_end(va);
return result;
}
// ----------------------------------------------------------------------
struct tm *gmtime_r(const time_t *timep, struct tm *result)
{
s_gmTimeSection.enter();
tm *t = gmtime(timep);
*result = *t;
s_gmTimeSection.leave();
return result;
}
// ----------------------------------------------------------------------
int finite(double value)
{
return _finite(value);
}
// ======================================================================
@@ -1,32 +0,0 @@
// ======================================================================
//
// PlatformGlue.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_PlatformGlue_H
#define INCLUDED_PlatformGlue_H
// ======================================================================
#include <time.h>
// ======================================================================
char * strsep(char **string, const char *delim);
int snprintf(char *buffer, size_t count, const char *format, ...);
struct tm * gmtime_r(const time_t *timep, struct tm *result);
int finite(double value);
//Format specifier for non-portable printf
#define UINT64_FORMAT_SPECIFIER "%I64u"
#define INT64_FORMAT_SPECIFIER "%I64i"
//Constant definition macro for 64 bit values
#define UINT64_LITERAL(a) a ## ui64
#define INT64_LITERAL(a) a ## i64
// ======================================================================
#endif
@@ -1,310 +0,0 @@
//
// ProcessSpawner.cpp
//
//-------------------------------------------------------------------
#include "sharedFoundation/FirstSharedFoundation.h"
#include "sharedFoundation/ProcessSpawner.h"
#include "sharedFoundation/Os.h"
#include <minmax.h>
ProcessSpawner::ProcessSpawner()
{
m_asConsole=false;
hProcess=0;
hOutputRead=0;
hInputWrite=0;
currentLine=currentRead=readBuffer;
}
ProcessSpawner::~ProcessSpawner()
{
if (hProcess)
{
CloseHandle(hProcess);
hProcess=0;
}
if (hOutputRead)
{
CloseHandle(hOutputRead);
hOutputRead=0;
}
if (hInputWrite)
{
CloseHandle(hInputWrite);
hInputWrite=0;
}
}
bool ProcessSpawner::terminate(unsigned exitCode)
{
if (!hProcess)
{
return false;
}
return TerminateProcess(hProcess, exitCode)!=0;
}
bool ProcessSpawner::create(const char *commandLine, const char *startupFolder, bool asConsole)
{
if (hProcess)
{
return false;
}
if (!commandLine)
{
return false;
}
if (!startupFolder)
{
startupFolder=Os::getProgramStartupDirectory();
}
m_asConsole=asConsole;
STARTUPINFO sinfo;
memset(&sinfo, 0, sizeof(sinfo));
sinfo.cb=sizeof(sinfo);
HANDLE hOutputWrite=0;
HANDLE hErrorWrite=0;
HANDLE hInputRead=0;
if (asConsole)
{
SECURITY_ATTRIBUTES sa;
sa.nLength=sizeof(sa);
sa.lpSecurityDescriptor=0;
sa.bInheritHandle=true;
// -----------------------------------------------------
// Create the child output pipe.
HANDLE hOutputReadTmp;
CreatePipe(&hOutputReadTmp,&hOutputWrite,&sa,0);
// Create a duplicate of the output write handle for the std error
// write handle. This is necessary in case the child application
// closes one of its std output handles.
DuplicateHandle(
GetCurrentProcess(), hOutputWrite,
GetCurrentProcess(),&hErrorWrite,
0,
TRUE,DUPLICATE_SAME_ACCESS
);
// Create the child input pipe.
HANDLE hInputWriteTmp;
CreatePipe(&hInputRead,&hInputWriteTmp,&sa,0);
// Create new output read handle and the input write handles. Set
// the Properties to FALSE. Otherwise, the child inherits the
// properties and, as a result, non-closeable handles to the pipes
// are created.
DuplicateHandle(
GetCurrentProcess(), hOutputReadTmp,
GetCurrentProcess(), &hOutputRead, // Address of new handle.
0, FALSE, // Make it uninheritable.
DUPLICATE_SAME_ACCESS
);
DuplicateHandle(
GetCurrentProcess(), hInputWriteTmp,
GetCurrentProcess(), &hInputWrite, // Address of new handle.
0,FALSE, // Make it uninheritable.
DUPLICATE_SAME_ACCESS
);
// Close inheritable copies of the handles you do not want to be
// inherited.
CloseHandle(hOutputReadTmp); hOutputReadTmp=0;
CloseHandle(hInputWriteTmp); hInputWriteTmp=0;
sinfo.dwFlags|=(STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW);
sinfo.hStdError=hErrorWrite;
sinfo.hStdInput=hInputRead;
sinfo.hStdOutput=hOutputWrite;
sinfo.wShowWindow = SW_HIDE;
}
PROCESS_INFORMATION pinfo;
BOOL result = CreateProcess(
0,
(char *)commandLine,
0,
0,
TRUE,
CREATE_NEW_CONSOLE,
0,
startupFolder,
&sinfo,
&pinfo
);
if (asConsole)
{
// Close pipe handles (do not continue to modify the parent).
// You need to make sure that no handles to the write end of the
// output pipe are maintained in this process or else the pipe will
// not close when the child process exits and the ReadFile will hang.
CloseHandle(hOutputWrite); hOutputWrite=0;
CloseHandle(hErrorWrite); hErrorWrite=0;
CloseHandle(hInputRead); hInputRead=0;
}
if (result)
{
CloseHandle(pinfo.hThread);
hProcess=pinfo.hProcess;
return true;
}
else
{
// Failed to launch turf
hProcess=0;
return false;
}
}
bool ProcessSpawner::isFinished(unsigned waitTime)
{
if (!hProcess)
{
return true;
}
DWORD waitResult = WaitForSingleObject(hProcess, waitTime);
return waitResult==WAIT_OBJECT_0;
}
bool ProcessSpawner::getExitCode(unsigned &o_code)
{
if (!hProcess)
{
return false;
}
DWORD exitCode;
BOOL result = GetExitCodeProcess(hProcess, &exitCode);
if (result)
{
o_code=exitCode;
return true;
}
else
{
return false;
}
}
bool ProcessSpawner::_returnExistingLine(char *buffer, const int bufferSize)
{
const char *const bufferStop = buffer + bufferSize;
char *iter = currentLine;
while (iter!=currentRead)
{
if (buffer==bufferStop)
{
currentLine=iter;
return true;
}
if (*iter=='\n')
{
*buffer++=0;
_stepIter(iter);
currentLine=iter;
return true;
}
else
{
*buffer++=*iter;
_stepIter(iter);
}
}
return false;
}
bool ProcessSpawner::getOutputString(char *buffer, int bufferSize)
{
if (_returnExistingLine(buffer, bufferSize))
{
return true;
}
// ----------------------------------------------
if (!hOutputRead)
{
return false;
}
DWORD dwAvail = 0;
if (!::PeekNamedPipe(hOutputRead, NULL, 0, NULL, &dwAvail, NULL))
{
// ERROR
return false;
}
if (!dwAvail)
{
return false;
}
DWORD dwRead;
if (currentRead >= currentLine)
{
const unsigned bufferAvailable = sizeof(readBuffer) - (currentRead - readBuffer);
unsigned toRead = dwAvail;
if (toRead > bufferAvailable)
{
toRead=bufferAvailable;
}
dwRead=0;
if (!::ReadFile(hOutputRead, currentRead, min(bufferAvailable, dwAvail), &dwRead, NULL) || !dwRead)
{
return false;
}
dwAvail-=dwRead;
currentRead+=dwRead;
if (currentRead==readBuffer+sizeof(readBuffer))
{
currentRead=readBuffer;
}
}
if (dwAvail>0)
{
const unsigned bufferAvailable = currentLine - currentRead - 1;
if (bufferAvailable)
{
unsigned toRead = dwAvail;
if (toRead > bufferAvailable)
{
toRead=bufferAvailable;
}
dwRead=0;
if (!::ReadFile(hOutputRead, currentRead, min(bufferAvailable, dwAvail), &dwRead, NULL) || !dwRead)
{
return false;
}
currentRead+=dwRead;
DEBUG_FATAL(currentRead>=currentLine, (""));
}
}
return _returnExistingLine(buffer, bufferSize);
}
@@ -1,43 +0,0 @@
#ifndef INCLUDED_ProcessSpawner_H
#define INCLUDED_ProcessSpawner_H
class ProcessSpawner
{
public:
ProcessSpawner();
~ProcessSpawner();
bool create(const char *commandLine, const char *startupFolder=0, bool asConsole=true);
bool terminate(unsigned exitCode=0);
bool isFinished(unsigned waitTime=0);
bool getExitCode(unsigned &o_code);
bool getOutputString(char *buffer, int bufferSize);
protected:
bool _returnExistingLine(char *buffer, int bufferSize);
void _stepIter(char *&i)
{
if (i==readBuffer+sizeof(readBuffer)-1)
{
i=readBuffer;
}
else
{
i++;
}
}
HANDLE hProcess;
HANDLE hOutputRead, hInputWrite;
bool m_asConsole;
char *currentLine, *currentRead, readBuffer[4096];
};
#endif
@@ -1,918 +0,0 @@
// ======================================================================
//
// RegistryKey.cpp
// Todd Fiala
//
// copyright 1998 Bootprint Entertainment
//
// ======================================================================
#include "sharedFoundation/FirstSharedFoundation.h"
#include "sharedFoundation/RegistryKey.h"
#include "sharedFoundation/ExitChain.h"
#include "sharedFoundation/ConfigFile.h"
#if USE_REGISTRY_EXECUTION_STATISTICS
#include <cstdio>
#include <ctime>
#endif
// ======================================================================
// keyname for config file parameter containing relative registry path
// for the product
const char * const RegistryKey::PRODUCT_REGISTRY_PATH_KEYNAME = "ProductRegistryPath";
const char * const RegistryKey::DEFAULT_PRODUCT_REGISTRY_PATH = "Software\\Sony Online Entertainment\\Default";
#if USE_REGISTRY_EXECUTION_STATISTICS
const char * const RegistryKey::STATISTICS_KEYNAME = "Statistics";
const char * const RegistryKey::STAT_EXEC_STARTED_COUNT_VALUENAME = "StartedExecutions";
const char * const RegistryKey::STAT_EXEC_INCOMPLETE_COUNT_VALUENAME = "IncompleteExecutions";
const char * const RegistryKey::STAT_TIME_AVERAGE_VALUENAME = "AverageClockTime";
const char * const RegistryKey::STAT_TIME_MIN_VALUENAME = "MinimumClockTime";
const char * const RegistryKey::STAT_TIME_MAX_VALUENAME = "MaximumClockTime";
const char * const RegistryKey::STAT_TIME_START_VALUENAME = "StartClockTime";
#endif
bool RegistryKey::installed;
bool RegistryKey::setProductKeyPathFromConfig;
RegistryKey *RegistryKey::usersKey;
RegistryKey *RegistryKey::currentUserKey;
RegistryKey *RegistryKey::classRootKey;
RegistryKey *RegistryKey::localMachineKey;
RegistryKey *RegistryKey::productUserKey;
RegistryKey *RegistryKey::productMachineKey;
// ======================================================================
// construct a RegistryKey instance
//
// Remarks:
// This function does not create the underlying registry object. It
// solely attaches such a registry object with a RegistryKey class
// instance.
RegistryKey::RegistryKey(
HKEY newKeyHandle, // [IN] handle of existing registry key
bool newCloseKeyOnDestroy // [IN] true if RegCloseKey() should be called on key at destruction time
) :
keyHandle(newKeyHandle),
closeKeyOnDestroy(newCloseKeyOnDestroy)
{
// -qq- don't know which of these indicates an invalid handle, so check for both
DEBUG_FATAL(!newKeyHandle, ("null newKeyHandle arg"));
DEBUG_FATAL(newKeyHandle == INVALID_HANDLE_VALUE, ("newKeyHandle arg is an invalid handle"));
}
// ----------------------------------------------------------------------
/**
* destroy a RegistryKey instance.
*/
RegistryKey::~RegistryKey(void)
{
DEBUG_FATAL(!keyHandle, ("null keyHandle"));
if (closeKeyOnDestroy)
{
const LONG result = RegCloseKey(keyHandle);
UNREF(result);
DEBUG_FATAL(result != ERROR_SUCCESS, ("failed to close registry key, error = %ld\n", result));
}
keyHandle = 0;
}
// ----------------------------------------------------------------------
/**
* enumerate all child subkeys of the current key.
*
* @param context [IN] user-specified context variable passed to callback
* @param callback [IN] function to call for each subkey enumerated
* @see EnumerateKeyCallback, enumerateValues()
*/
void RegistryKey::enumerateSubkeys(void *context, EnumerateKeyCallback callback) const
{
const size_t MAX_NAME_LENGTH = 256;
LONG result;
FILETIME lastModifiedFileTime;
char subkeyName[MAX_NAME_LENGTH];
DWORD subkeyNameLength;
DWORD index;
DEBUG_FATAL(!callback, ("null callback arg\n"));
for (
index = 0, subkeyNameLength = MAX_NAME_LENGTH;
ERROR_SUCCESS == (result = RegEnumKeyEx(keyHandle, index, subkeyName, &subkeyNameLength, 0, 0, 0, &lastModifiedFileTime));
++index, subkeyNameLength = MAX_NAME_LENGTH
)
{
bool continueEnum = callback(context, subkeyName, &lastModifiedFileTime);
if (!continueEnum) break;
}
// ensure we finished enumeration cleanly
FATAL(
(result != ERROR_SUCCESS) && (result != ERROR_NO_MORE_ITEMS),
("failed to enumerate registry subkeys, error = %ld\n", result));
}
// ----------------------------------------------------------------------
/**
* open and return a subkey under this RegistryKey instance.
*
* The function will fail if the specified subkey does not exist.
*
* @param subkeyName [IN] registry path for subkey to open, relative to this RegistryKey instance
* @param accessFlags [IN] flags indicating access granted to the returned RegistryKey
* @return This function returns a RegistryKey instance for the specified
* subkey.
*/
RegistryKey *RegistryKey::openSubkey(const char *subkeyName, uint32 accessFlags) const
{
REGSAM samDesired = 0;
LONG result;
HKEY newKey = 0;
DEBUG_FATAL(!keyHandle, ("null keyHandle"));
DEBUG_FATAL(!subkeyName, ("null subkeyName arg"));
DEBUG_FATAL(!strlen(subkeyName), ("zero-length subkeyName arg"));
// configure security access desired
if (accessFlags & AF_READ)
samDesired |= KEY_READ;
if (accessFlags & AF_WRITE)
samDesired |= KEY_WRITE;
// open the key
result = RegOpenKeyEx(keyHandle, subkeyName, 0, samDesired, &newKey);
FATAL(result != ERROR_SUCCESS, ("failed to open registry subkey \"%s\", error = %ld\n", subkeyName, result));
// Create the RegistryKey object. Assume the key must be closed upon
// destruction.
return new RegistryKey(newKey, true);
}
// ----------------------------------------------------------------------
/**
* create and return a subkey under this RegistryKey instance.
*
* The function will succeed even if the specified subkey
* already exists.
*
* @return This function returns a RegistryKey instance for the specified
* subkey.
*/
RegistryKey *RegistryKey::createSubkey(const char *subkeyName, uint32 accessFlags) const
{
REGSAM samDesired = 0;
LONG result;
HKEY newKey = 0;
DWORD disposition;
DEBUG_FATAL(!keyHandle, ("null keyHandle"));
DEBUG_FATAL(!subkeyName, ("null subkeyName arg"));
DEBUG_FATAL(!strlen(subkeyName), ("zero-length subkeyName arg"));
// configure security access desired
if (accessFlags & AF_READ)
samDesired |= KEY_READ;
if (accessFlags & AF_WRITE)
samDesired |= KEY_WRITE;
// open the key
result = RegCreateKeyEx(
keyHandle,
subkeyName,
0, // reserved
const_cast<char *>(""), // class
REG_OPTION_NON_VOLATILE, // options
samDesired,
NULL, // security
&newKey,
&disposition);
FATAL(result != ERROR_SUCCESS, ("failed to create registry subkey \"%s\", error = %ld\n", subkeyName, result));
// Create the RegistryKey object. Assume the key must be closed upon
// destruction.
return new RegistryKey(newKey, true);
}
// ----------------------------------------------------------------------
/**
* delete a subkey relative to this RegistryKey instance.
*
* Under Windows NT, deleting a key that has subkeys is considered an
* error. Therefore, the client should ensure the target key for
* deletion does not have any subkeys. (Under Windows 9X, deletion of
* the target registry key will automatically delete all subkeys
* underneath the target key.)
*/
void RegistryKey::deleteSubkey(const char *subkeyName)
{
DEBUG_FATAL(!keyHandle, ("null keyHandle"));
DEBUG_FATAL(!subkeyName, ("null subkeyName arg"));
DEBUG_FATAL(!strlen(subkeyName), ("zero-length subkeyName arg"));
IGNORE_RETURN(RegDeleteKey(keyHandle, subkeyName));
}
// ----------------------------------------------------------------------
/**
* test for the existence of a subkey under this RegistryKey instance.
*
* @param subkeyName [IN] registry path for subkey to open, relative to this RegistryKey instance
*/
bool RegistryKey::subKeyExists(const char *subkeyName)
{
REGSAM samDesired = KEY_READ;
LONG result;
HKEY newKey = 0;
DEBUG_FATAL(!keyHandle, ("null keyHandle"));
DEBUG_FATAL(!subkeyName, ("null subkeyName arg"));
DEBUG_FATAL(!strlen(subkeyName), ("zero-length subkeyName arg"));
// open the key
result = RegOpenKeyEx(keyHandle, subkeyName, 0, samDesired, &newKey);
return (result == ERROR_SUCCESS);
}
// ----------------------------------------------------------------------
/**
* enumerate all values under the current key.
*
* @param context [IN] user-specified context variable passed to callback
* @param callback [IN] function to call for each value enumerated
* @see EnumerateValueCallback, enumerateSubkeys()
*/
void RegistryKey::enumerateValues(void *context, EnumerateValueCallback callback) const
{
const size_t MAX_NAME_LENGTH = 256;
LONG result;
char valueName[MAX_NAME_LENGTH];
DWORD valueNameLength;
DWORD index;
DWORD dataSize;
DWORD valueType;
DEBUG_FATAL(!callback, ("null callback arg\n"));
for (
index = 0, valueNameLength = MAX_NAME_LENGTH, dataSize = 0;
ERROR_SUCCESS == (result = RegEnumValue(keyHandle, index, valueName, &valueNameLength, 0, &valueType, 0, &dataSize));
++index, valueNameLength = MAX_NAME_LENGTH, dataSize = 0
)
{
bool continueEnum = callback(context, valueName, static_cast<uint32>(dataSize), valueType);
if (!continueEnum) break;
}
// ensure we finished enumeration cleanly
FATAL(
(result != ERROR_SUCCESS) && (result != ERROR_NO_MORE_ITEMS),
("failed to enumerate registry values, error = %ld\n", result));
}
// ----------------------------------------------------------------------
/**
* query if a value exists and how many bytes that value occupies.
*
* The client does can pass null for the valueSize and/or valueType
* parameter if that information is not desired. The value returned
* within the valueSize and valueType parameter is only valid
* if the doesExist parameter is set to true upon function return.
* The value of the valueType parameter is one of the Windows-defined
* REG_* constants provided for use with the Win32 Reg* registry
* API. Common values are REG_BINARY (binary data), REG_DWORD
* (unsigned integral type data) and REG_SZ (C-style zero-terminated
* strings). Consult the Win32 documentation for RegGetValueEx()
* for a description of all the type constants.
*
* @param valueName [IN] name of the value to query
* @param doesExist [OUT] true if value exists under this key, false otherwise
* @param valueSize [OUT] number of bytes occupied by value's data
* @param valueType [OUT] type flag for registry value (see REG_* in RegSetValueEx())
*/
void RegistryKey::getValueInfo(const char *valueName, bool *doesExist, uint32 *valueSize, DWORD *valueType) const
{
LONG result;
DWORD dwSize = 0;
DEBUG_FATAL(!keyHandle, ("null keyHandle"));
DEBUG_FATAL(!valueName, ("null valueName arg"));
DEBUG_FATAL(!doesExist, ("null doesExist arg"));
DEBUG_FATAL(!strlen(valueName), ("zero-length valueName arg"));
// get information on the value
result = RegQueryValueEx(keyHandle, valueName, 0, valueType, 0, &dwSize);
// assume a query failure indicates the value was not found
*doesExist = (result == ERROR_SUCCESS);
if (valueSize)
*valueSize = static_cast<uint32>(dwSize);
}
// ----------------------------------------------------------------------
/**
* set the data for this key's value.
*
* The value of the valueType parameter is one of the Windows-defined
* REG_* constants provided for use with the Win32 Reg* registry
* API. Common values are REG_BINARY (binary data), REG_DWORD
* (unsigned integral type data) and REG_SZ (C-style zero-terminated
* strings). Consult the Win32 documentation for RegGetValueEx()
* for a description of all the type constants.
*
* @param valueName [IN] name of value under which data will be stored
* @param dataPtr [IN] pointer to buffer containing value's data
* @param dataSize [IN] # bytes to store
* @param valueType [IN] type field for value (indicates nature of data stored with value)
*/
void RegistryKey::setValue(const char *valueName, const void *dataPtr, uint32 dataSize, DWORD valueType)
{
LONG result;
DEBUG_FATAL(!keyHandle, ("null keyHandle"));
DEBUG_FATAL(!valueName, ("null valueName arg"));
DEBUG_FATAL(!strlen(valueName), ("zero-length valueName arg"));
DEBUG_FATAL(!dataPtr, ("null dataPtr arg"));
// get information on the value
result = RegSetValueEx(keyHandle, valueName, 0, valueType, static_cast<CONST BYTE*>(dataPtr), static_cast<DWORD>(dataSize));
FATAL(result != ERROR_SUCCESS, ("failed to set registry value \"%s\", error = %ld\n", valueName, result));
}
// ----------------------------------------------------------------------
/**
* retrieve the data for the this key's value.
*
* The valueType and/or the valueDataSize parameter may be set
* to null if the client doesn't need this information.
* The value of the valueType parameter is one of the Windows-defined
* REG_* constants provided for use with the Win32 Reg* registry
* API. Common values are REG_BINARY (binary data), REG_DWORD
* (unsigned integral type data) and REG_SZ (C-style zero-terminated
* strings). Consult the Win32 documentation for RegGetValueEx()
* for a description of all the type constants.
*
* @param valueName [IN] the name of the value to retrieve
* @param dataPtr [OUT] the buffer where the value's data will be stored
* @param maxDataSize [IN] size of the data buffer in bytes
* @param valueDataSize [OUT] number of bytes retrieved from the named value
* @param valueType [OUT] type field for value's data (see REG_* codes in RegSetValueEx)
*/
void RegistryKey::getValue(const char *valueName, void *dataPtr, uint32 maxDataSize, uint32 *valueDataSize, DWORD *valueType) const
{
LONG result;
DWORD dwSize = maxDataSize;
DEBUG_FATAL(!keyHandle, ("null keyHandle"));
DEBUG_FATAL(!valueName, ("null valueName arg"));
DEBUG_FATAL(!strlen(valueName), ("zero-length valueName arg"));
// get information on the value
result = RegQueryValueEx(keyHandle, valueName, 0, valueType, static_cast<LPBYTE>(dataPtr), &dwSize);
FATAL(result != ERROR_SUCCESS, ("failed to read registry value \"%s\", error = %ld\n", valueName, result));
// assume a query failure indicates the value was not found
if (valueDataSize)
*valueDataSize = static_cast<uint32>(dwSize);
}
// ----------------------------------------------------------------------
/**
* retrieve a string from of this key's values, returning a default string
* if the value doesn't exist.
*
* The defaultValue arg is required, must be non-null.
*
* If the specified value exists but is not of type REG_SZ, the default
* string will be returned.
*
* This routine will DEBUG_FATAL on null args, even if optional is set.
* Optional only controls whether a FATAL occurs if there is an issue
* retrieving the value.
*
* @param valueName [IN] name of the string value to retrieve
* @param defaultValue [IN] string to return if registry key does not contain thev value
* @param dest [OUT] buffer for returned string
* @param destSize [IN] max number of bytes (including terminating null) that can be placed in dest
* @param optional [IN] if set, the function will return false if there is a problem retrieving the value. otherwise, a DEBUG_FATAL will occur
*/
bool RegistryKey::getStringValue(const char *valueName, const char *defaultValue, char *dest, DWORD destSize, bool optional)
{
DEBUG_FATAL(!defaultValue, ("null defaultValue arg"));
DEBUG_FATAL(!dest, ("null dest arg"));
bool doesExist;
DWORD valueType;
DWORD valueSize;
// clear out string
memset(dest, 0, static_cast<size_t>(destSize));
// get info on the value
getValueInfo (valueName, &doesExist, &valueSize, &valueType);
if (!doesExist || (valueType != REG_SZ))
strncpy(dest, defaultValue, destSize-1);
else
{
// value exists and is a string, retrieve it
getValue (valueName, dest, destSize, &valueSize);
if (!valueSize)
{
FATAL(!optional, ("failed to get registry data for key %s\n", valueName));
return false;
}
// terminate the string
dest [valueSize] = 0;
}
return true;
}
// ----------------------------------------------------------------------
/**
* delete a value from this registry key.
*/
void RegistryKey::deleteValue(const char *valueName)
{
LONG result;
DEBUG_FATAL(!keyHandle, ("null keyHandle"));
DEBUG_FATAL(!valueName, ("null valueName arg"));
DEBUG_FATAL(!strlen(valueName), ("zero-length valueName arg"));
result = RegDeleteValue(keyHandle, valueName);
FATAL(result != ERROR_SUCCESS, ("failed to delete registry value \"%s\", error = %ld\n", valueName, result));
}
#if USE_REGISTRY_EXECUTION_STATISTICS
// ----------------------------------------------------------------------
/**
* updates beginning-of-execution statistics using the values under a
* given key.
*
* Call this function at the beginning of execution of the code
* for which statistics are desired. At the end of execution,
* call updateShutdownKey() to finish generating statistics.
* This function should only be called once per execution,
* and should be followed by a call to updateShutdownKey().
* If the latter is not called, the next call to updateStartupKey()
* will assume the application terminated abnormally before
* proper shutdown could occur.
*/
void RegistryKey::updateStartupKey(RegistryKey *key)
{
bool valueExist;
uint32 valueSize;
DWORD valueType;
DWORD execStartedCount = 0;
clock_t startTime = clock();
DEBUG_FATAL(!key, ("null key arg\n"));
// handle improper shutdown of last run
key->getValueInfo(STAT_TIME_START_VALUENAME, &valueExist);
if (valueExist)
{
// appears the product did not run to completion on last run.
// increment the incomplete run counts
DWORD execIncompleteCount = 0;
key->getValueInfo(STAT_EXEC_INCOMPLETE_COUNT_VALUENAME, &valueExist);
if (valueExist)
{
key->getValue(STAT_EXEC_INCOMPLETE_COUNT_VALUENAME, &execIncompleteCount, sizeof(DWORD), &valueSize, &valueType);
DEBUG_FATAL((valueType != REG_DWORD) || (valueSize != sizeof(DWORD)), ("%s key not DWORD type as expected\n", STAT_EXEC_INCOMPLETE_COUNT_VALUENAME));
}
++execIncompleteCount;
key->setValue(STAT_EXEC_INCOMPLETE_COUNT_VALUENAME, &execIncompleteCount, sizeof(DWORD), REG_DWORD);
}
// get the start count
key->getValueInfo(STAT_EXEC_STARTED_COUNT_VALUENAME, &valueExist);
if (valueExist)
{
key->getValue(STAT_EXEC_STARTED_COUNT_VALUENAME, &execStartedCount, sizeof(DWORD), &valueSize, &valueType);
DEBUG_FATAL((valueType != REG_DWORD) || (valueSize != sizeof(DWORD)), ("%s key not DWORD type as expected\n", STAT_EXEC_STARTED_COUNT_VALUENAME));
}
++execStartedCount;
// save the data
key->setValue(STAT_EXEC_STARTED_COUNT_VALUENAME, &execStartedCount, sizeof(DWORD), REG_DWORD);
key->setValue(STAT_TIME_START_VALUENAME, &startTime, sizeof(clock_t));
}
#endif
#if USE_REGISTRY_EXECUTION_STATISTICS
// ----------------------------------------------------------------------
/**
* updates end-of-execution statistics using the values under a given key.
*
* This function should only be called after updateStartupKey()
* has been called on the same key. After this call returns,
* this function should not be called again until another
* call to updateStartupKey() is made.
*/
void RegistryKey::updateShutdownKey(RegistryKey *key)
{
bool valueExist;
uint32 valueSize;
DWORD valueType;
clock_t minTime;
clock_t maxTime;
clock_t averageTime = 0;
clock_t startTime;
clock_t stopTime = clock();
clock_t runTime;
DWORD startExecCount;
DWORD incompleteExecCount = 0;
DWORD completeExecCount;
real averageFraction;
DEBUG_FATAL(!key, ("null key arg\n"));
// find the number of complete execution runs of the product
key->getValue(STAT_EXEC_STARTED_COUNT_VALUENAME, &startExecCount, sizeof(DWORD), &valueSize, &valueType);
DEBUG_FATAL((valueSize != sizeof(DWORD)) || (valueType != REG_DWORD), ("invalid start count statistic registry value\n"));
key->getValueInfo(STAT_EXEC_INCOMPLETE_COUNT_VALUENAME, &valueExist);
if (valueExist)
{
key->getValue(STAT_EXEC_INCOMPLETE_COUNT_VALUENAME, &incompleteExecCount, sizeof(DWORD), &valueSize, &valueType);
DEBUG_FATAL((valueType != REG_DWORD) || (valueSize != sizeof(DWORD)), ("%s expected to be DWORD type, was %lu instead\n", STAT_EXEC_INCOMPLETE_COUNT_VALUENAME, valueType));
}
completeExecCount = startExecCount - incompleteExecCount;
// retrieve the start time
key->getValue(STAT_TIME_START_VALUENAME, &startTime, sizeof(clock_t), &valueSize, &valueType);
DEBUG_FATAL((valueSize != sizeof(clock_t)) || (valueType != REG_BINARY), ("invalid start time statistic registry value\n"));
// -qq- we don't handle clock wraparound
runTime = stopTime - startTime;
minTime = runTime;
maxTime = runTime;
// calculate average time
key->getValueInfo(STAT_TIME_AVERAGE_VALUENAME, &valueExist);
if (valueExist)
{
key->getValue(STAT_TIME_AVERAGE_VALUENAME, &averageTime, sizeof(clock_t), &valueSize, &valueType);
DEBUG_FATAL((valueSize != sizeof(clock_t)) || (valueType != REG_BINARY), ("invalid average exec time statistic registry value\n"));
}
averageFraction = CONST_REAL(1.0 / completeExecCount);
averageTime = static_cast<clock_t>(( CONST_REAL(averageTime) * (completeExecCount-1) + runTime) * averageFraction);
if (averageTime < 1)
averageTime = 1;
// check min exec time
key->getValueInfo(STAT_TIME_MIN_VALUENAME, &valueExist);
if (valueExist)
{
clock_t testValue;
key->getValue(STAT_TIME_MIN_VALUENAME, &testValue, sizeof(clock_t), &valueSize, &valueType);
DEBUG_FATAL((valueSize != sizeof(clock_t)) || (valueType != REG_BINARY), ("invalid min exec time statistic registry value\n"));
if (testValue < minTime)
minTime = testValue;
}
// check for max exec time
key->getValueInfo(STAT_TIME_MAX_VALUENAME, &valueExist);
if (valueExist)
{
clock_t testValue;
key->getValue(STAT_TIME_MAX_VALUENAME, &testValue, sizeof(clock_t), &valueSize, &valueType);
DEBUG_FATAL((valueSize != sizeof(clock_t)) || (valueType != REG_BINARY), ("invalid max exec time statistic registry value\n"));
if (testValue > maxTime)
maxTime = testValue;
}
// save the data
key->setValue(STAT_TIME_AVERAGE_VALUENAME, &averageTime, sizeof(clock_t));
key->setValue(STAT_TIME_MIN_VALUENAME, &minTime, sizeof(clock_t));
key->setValue(STAT_TIME_MAX_VALUENAME, &maxTime, sizeof(clock_t));
// delete the start time value
key->deleteValue(STAT_TIME_START_VALUENAME);
}
#endif
#if USE_REGISTRY_EXECUTION_STATISTICS
// ----------------------------------------------------------------------
/**
* An EnumValueCallback that prints each value name, type and size
*
* @param valueName name of value
* @param valueSize size of value in bytes
* @param valueTye type of value
*/
bool RegistryKey::enumValueInfoPrint(
void*, // unused user context
const char *valueName,
uint32 valueSize,
DWORD valueType
)
{
char *valueTypeStr;
char buffer[64];
switch (valueType)
{
case REG_BINARY:
valueTypeStr = "REG_BINARY";
break;
case REG_DWORD:
valueTypeStr = "REG_DWORD [little endian]";
break;
case REG_DWORD_BIG_ENDIAN:
valueTypeStr = "REG_DWORD_BIG_ENDIAN";
break;
case REG_EXPAND_SZ:
valueTypeStr = "REG_EXPAND_SZ";
break;
case REG_NONE:
valueTypeStr = "REG_NONE";
break;
case REG_SZ:
valueTypeStr = "REG_SZ";
break;
default:
valueTypeStr = buffer;
sprintf(buffer, "<TYPE %lu>", valueType);
break;
}
DEBUG_PRINT_LOG(true, (" Key: \"%s\", %s, %u bytes\n", valueName, valueTypeStr, valueSize));
// continue enumerating
return true;
}
#endif
#if USE_REGISTRY_EXECUTION_STATISTICS
// ----------------------------------------------------------------------
/**
* Update per-startup registry values.
*
* This routine is used primarily to test registry read/write
* functionality; however, it does provide statistics related
* to game usage. These include the following statistics on
* a per-game and per-machine basis:
* # times product was executed
* average real-time duration of execution
* minimum execution time
* maximum execution time
* # times product failed to execute to completion
* (i.e. updateRegistryShutdown() never executed---hard crash, stop debugging)
*/
void RegistryKey::updateStartupStatistics(void)
{
DEBUG_FATAL(!productUserKey, ("null productUserKey\n"));
DEBUG_FATAL(!productMachineKey, ("null productMachineKey\n"));
// create required keys
RegistryKey *userStatKey = productUserKey->createSubkey(STATISTICS_KEYNAME);
RegistryKey *machineStatKey = productMachineKey->createSubkey(STATISTICS_KEYNAME);
FATAL(!userStatKey, ("failed to create user statistics key"));
FATAL(!machineStatKey, ("failed to create machine statistics key"));
// handle machine stat key
#if 1
// print existing machine stat keys
DEBUG_PRINT_LOG(true, ("BEGIN machine stat key enumeration:\n"));
machineStatKey->enumerateValues(0, enumValueInfoPrint);
DEBUG_PRINT_LOG(true, ("END machine stat key enumeration:\n"));
#endif
updateStartupKey(machineStatKey);
// handle user stat key
#if 1
// print existing user stat keys
DEBUG_PRINT_LOG(true, ("BEGIN user stat key enumeration:\n"));
userStatKey->enumerateValues(0, enumValueInfoPrint);
DEBUG_PRINT_LOG(true, ("END user stat key enumeration:\n"));
#endif
updateStartupKey(userStatKey);
// cleanup
delete machineStatKey;
delete userStatKey;
}
#endif
#if USE_REGISTRY_EXECUTION_STATISTICS
// ----------------------------------------------------------------------
/**
* Update per-shutdown registry values.
*
* @see updateRegistryStartup()
*/
void RegistryKey::updateShutdownStatistics(void)
{
DEBUG_FATAL(!productUserKey, ("null productUserKey\n"));
DEBUG_FATAL(!productMachineKey, ("null productMachineKey\n"));
// create required keys
RegistryKey *userStatKey = productUserKey->createSubkey(STATISTICS_KEYNAME);
RegistryKey *machineStatKey = productMachineKey->createSubkey(STATISTICS_KEYNAME);
FATAL(!userStatKey, ("failed to create user statistics key"));
FATAL(!machineStatKey, ("failed to create machine statistics key"));
// handle machine stat key
updateShutdownKey(machineStatKey);
// handle user stat key
updateShutdownKey(userStatKey);
// cleanup
delete machineStatKey;
delete userStatKey;
}
#endif
// ----------------------------------------------------------------------
/**
* install the RegistryKey class.
*
* After installation, the following predefined keys are available:
*
* usersKey: HKEY_USERS
* currentUserKey: HKEY_CURRENT_USER
* classRootKey: HKEY_CLASSES_ROOT
* localMachineKey: HKEY_LOCAL_MACHINE
* productUserKey: HKEY_CURENT_USER\<product relative registry path>
* productMachineKey: HKEY_LOCAL_MACHINE\<product relative registry path>
*
* The client is free to create any other keys required.
*
* The product relative registry path is determined by the first of the
* following methods that succeed:
* 1. If the config file key "ProductRegistryPath" is set, that value is
* used for the relative path. If the product relative path is set
* in this manner, the client's attempt to change the product relative
* path via the setProductKey() function will silently fail.
* 2. If the productKeyRelativePath parameter is a non-null positive length
* string, that value is used as the product keys' relative path.
* 3. The default value DEFAULT_PRODUCT_REGISTRY_PATH ("Software\\Bootprint\\Default")
* is used.
*
* RegistryKey::remove() is added to the exit chain.
*
* Do not delete any of the predefined registry keys.
*
* @param productKeyRelativePath [IN] relative registry path for the product keys
* @see setProductKeyPath()
*/
void RegistryKey::install(const char *productKeyRelativePath)
{
UNREF(productKeyRelativePath);
char *useRegistryPath = 0;
DEBUG_FATAL(installed, ("attempted to install RegistryKey when already installed\n"));
installed = true;
// add to exit chain
ExitChain::add(remove, "RegistryKey::remove", 0, true);
// if no passed in value, use the default
setProductKeyPathFromConfig = false;
useRegistryPath = DuplicateString(DEFAULT_PRODUCT_REGISTRY_PATH);
// create the Windows-defined RegistryKeys (these keys don't get closed at object destruction time)
usersKey = new RegistryKey(HKEY_USERS, false); //lint !e1924 // Note -- C-style cast
currentUserKey = new RegistryKey(HKEY_CURRENT_USER, false); //lint !e1924 // Note -- C-style cast
classRootKey = new RegistryKey(HKEY_CLASSES_ROOT, false); //lint !e1924 // Note -- C-style cast
localMachineKey = new RegistryKey(HKEY_LOCAL_MACHINE, false); //lint !e1924 // Note -- C-style cast
// check for errors --- unnecessary if new cannot return NULL
FATAL(
!usersKey || !currentUserKey || !classRootKey || !localMachineKey,
("failed to create standard RegistryKey objects"));
// create/open the product user key
productUserKey = currentUserKey->createSubkey(useRegistryPath, AF_READ | AF_WRITE);
// create/open the product machine key
productMachineKey = localMachineKey->createSubkey(useRegistryPath, AF_READ);
delete [] useRegistryPath;
#if USE_REGISTRY_EXECUTION_STATISTICS
updateStartupStatistics();
#endif
}
// ----------------------------------------------------------------------
/**
* release all resources and state associated with the RegistryKey system.
*
* It is invalid to call any RegistryKey functions other than install()
* after calling remove().
*/
void RegistryKey::remove(void)
{
#if USE_REGISTRY_EXECUTION_STATISTICS
updateShutdownStatistics();
#endif
DEBUG_FATAL(!installed, ("attempted to remove RegistryKey when not installed\n"));
installed = false;
delete productMachineKey;
delete productUserKey;
delete localMachineKey;
delete classRootKey;
delete currentUserKey;
delete usersKey;
productMachineKey = 0;
productUserKey = 0;
localMachineKey = 0;
classRootKey = 0;
currentUserKey = 0;
usersKey = 0;
}
// ----------------------------------------------------------------------
/**
* reset the path to the product's machine and user keys.
*
* This routine will redefine the following keys:
* productUserKey: HKEY_CURENT_USER\<productKeyRelativePath>
* productMachineKey: HKEY_LOCAL_MACHINE\<productKeyRelativePath>
*
* If the product key relative paths were specified in the config
* file, this routine will essentially do nothing --- the client
* is not able to ovveride the config file settings.
*/
void RegistryKey::setProductKeyPath(const char *productKeyRelativePath)
{
DEBUG_FATAL(
!productKeyRelativePath || !productKeyRelativePath[0],
("invalid productKeyRelativePath arg\n"));
// don't allow client to overwrite if path set by config file
if (setProductKeyPathFromConfig)
{
DEBUG_REPORT_LOG_PRINT(true, ("attempted to set product registry key path to '%s' but config file setting will override\n", productKeyRelativePath));
return;
}
delete productUserKey;
delete productMachineKey;
productUserKey = currentUserKey->createSubkey(productKeyRelativePath, AF_READ | AF_WRITE);
productMachineKey = localMachineKey->createSubkey(productKeyRelativePath, AF_READ | AF_WRITE);
}
// ======================================================================
@@ -1,270 +0,0 @@
#ifndef REGISTRY_KEY_H
#define REGISTRY_KEY_H
// ======================================================================
//
// RegistryKey.h
// Todd Fiala
//
// copyright 1998 Bootprint Entertainment
//
// ======================================================================
// provide read and write access to the Windows Registry
//
// Remarks:
//
// Each RegistryKey can create or open a subkey relative to that
// key. This process produces another RegistryKey. RegistryKeys
// provide a mechanism to enumerate all the child subkeys and values
// associated with the key. In addition, clients may query for
// the presence, type and size of a specific value, get a specific
// value's data, and set a named value's data and type.
//
// The RegistryKey class provides the client with six RegistryKey
// objects as starting points into the registry. See documentation
// for install() for more info on these starting points.
//
// The client must install() the RegistryKey class before using it.
class RegistryKey
{
public:
// ----------------------------------------------------------------------
// flags used to indicate what type of access (e.g. read, write) should
// be granted when creating or opening a key.
//
// See Also:
//
// createSubkey(), openSubkey()
enum // AccessFlags
{
AF_READ = BINARY1(0001), // query values, enumerate subkeys
AF_WRITE = BINARY1(0010) // set values, create subkeys
};
// ----------------------------------------------------------------------
// callback prototype for subkey enumeration
//
// Return Value:
//
// A return value of true indicates the enumeration of subkeys should
// continue. A return value of false stops further enumeration of
// subkeys.
//
// Remarks:
//
// The context parameter is specified in the call to
// enumerateSubkeys(). One use for this could be to pass a class
// instance, with the callack defined as a static member function.
// The function can then cast the context to a pointer to class
// instance, allowing the static function to access per-instance
// data explicitly in place of an assumed this pointer.
//
// See Also:
//
// enumerateSubkeys()
typedef bool (*EnumerateKeyCallback)(
void *context, // [IN] user-specified context variable
const char *keyName, // [IN] name of the key being enumerated
const FILETIME *lastWriteTime // [IN] last time this key was modified
);
// ----------------------------------------------------------------------
// callback prototype for value enumeration
//
// Return Value:
//
// A return value of true indicates the enumeration of values should
// continue. A return value of false stops further enumeration of
// values .
//
// Remarks:
//
// The context parameter is specified in the call to
// enumerateValues(). One use for this could be to pass a class
// instance, with the callack defined as a static member function.
// The function can then cast the context to a pointer to class
// instance, allowing the static function to access per-instance
// data explicitly in place of an assumed this pointer.
//
// See Also:
//
// enumerateValues()
typedef bool (*EnumerateValueCallback)(
void *context, // [IN] user-specified context variable
const char *valueName, // [IN] name of the value being enumerated
uint32 valueSize, // [IN] number of bytes occupied by this value's data
DWORD valueType // [IN] type of value (one of REG_* as in RegSetValueEx documentation)
);
private:
static const char * const PRODUCT_REGISTRY_PATH_KEYNAME;
static const char * const DEFAULT_PRODUCT_REGISTRY_PATH;
#if USE_REGISTRY_EXECUTION_STATISTICS
static const char * const STATISTICS_KEYNAME;
static const char * const STAT_EXEC_STARTED_COUNT_VALUENAME;
static const char * const STAT_EXEC_INCOMPLETE_COUNT_VALUENAME;
static const char * const STAT_TIME_AVERAGE_VALUENAME;
static const char * const STAT_TIME_MIN_VALUENAME;
static const char * const STAT_TIME_MAX_VALUENAME;
static const char * const STAT_TIME_START_VALUENAME;
#endif
static bool installed;
static bool setProductKeyPathFromConfig;
// private instance member variables
HKEY keyHandle;
bool closeKeyOnDestroy;
private:
// public member variables
static RegistryKey *usersKey;
static RegistryKey *currentUserKey;
static RegistryKey *classRootKey;
static RegistryKey *localMachineKey;
static RegistryKey *productUserKey;
static RegistryKey *productMachineKey;
private:
// private member functions
static void remove(void);
RegistryKey(HKEY newKeyHandle, bool newCloseKeyOnDestroy);
#if USE_REGISTRY_EXECUTION_STATISTICS
static void updateStartupKey(RegistryKey *key);
static void updateShutdownKey(RegistryKey *key);
static bool enumValueInfoPrint(void *context, const char *valueName, uint32 valueSize, DWORD valueType);
static void updateStartupStatistics(void);
static void updateShutdownStatistics(void);
#endif
private:
// disable: default constructor, copy constructor, assignment operator
// NOTE: last two can be implemented, but must be specially handled
RegistryKey(void);
RegistryKey(const RegistryKey&);
RegistryKey &operator =(const RegistryKey&);
public:
// public member functions
static void install(const char *productKeyRelativePath = 0);
static void setProductKeyPath(const char *productKeyRelativePath);
// pre-defined RegistryKey retrieval
static RegistryKey *getUsersKey(void);
static RegistryKey *getCurrentUserKey(void);
static RegistryKey *getClassRootKey(void);
static RegistryKey *getLocalMachineKey(void);
static RegistryKey *getProductUserKey(void);
static RegistryKey *getProductMachineKey(void);
~RegistryKey(void);
// subkey interface
void enumerateSubkeys(void *context, EnumerateKeyCallback callback) const;
RegistryKey *openSubkey(const char *subkeyName, uint32 accessFlags = AF_READ) const;
RegistryKey *createSubkey(const char *subkeyName, uint32 accessFlags = AF_READ | AF_WRITE) const;
void deleteSubkey(const char *subkeyName);
bool subKeyExists(const char *subkeyName);
// value interface
void enumerateValues(void *context, EnumerateValueCallback callback) const;
void setValue(const char *valueName, const void *dataPtr, uint32 dataSize, DWORD valueType = REG_BINARY);
void deleteValue(const char *valueName);
void getValueInfo(const char *valueName, bool *doesExist, uint32 *valueSize = 0, DWORD *valueType = 0) const;
void getValue(const char *valueName, void *dataPtr, uint32 maxDataSize, uint32 *valueDataSize, DWORD *valueType = 0) const;
bool getStringValue(const char *valueName, const char *defaultValue, char *dest, DWORD destSize, bool optional = false);
};
// ======================================================================
// retrieve a key to the HKEY_USERS registry key with read access
inline RegistryKey *RegistryKey::getUsersKey(void)
{
DEBUG_FATAL(!installed, ("Attempted to use RegistryKey when not installed\n"));
return usersKey;
}
// ----------------------------------------------------------------------
/**
* retrieve a key to the HKEY_CURRENT_USER registry key with read/write
* access.
*/
inline RegistryKey *RegistryKey::getCurrentUserKey(void)
{
DEBUG_FATAL(!installed, ("Attempted to use RegistryKey when not installed\n"));
return currentUserKey;
}
// ----------------------------------------------------------------------
/**
* retrieve a key to the HKEY_CLASSES_ROOT registry key with read/write
* access.
*/
inline RegistryKey *RegistryKey::getClassRootKey(void)
{
DEBUG_FATAL(!installed, ("Attempted to use RegistryKey when not installed\n"));
return classRootKey;
}
// ----------------------------------------------------------------------
/**
* retrieve a key to the HKEY_LOCAL_MACHINE registry key with read/write
* access.
*/
inline RegistryKey *RegistryKey::getLocalMachineKey(void)
{
DEBUG_FATAL(!installed, ("Attempted to use RegistryKey when not installed\n"));
return localMachineKey;
}
// ----------------------------------------------------------------------
/**
* retrieve a key to the product's user key with read/write access.
*
* The product user key is the root key for storing user-specific
* product-related information. install() describes where this
* information exists in the registry.
*
* @see install(), getProductMachineKey()
*/
inline RegistryKey *RegistryKey::getProductUserKey(void)
{
DEBUG_FATAL(!installed, ("Attempted to use RegistryKey when not installed\n"));
return productUserKey;
}
// ----------------------------------------------------------------------
/**
* retrieve a key to the product's machine key with read/write access.
*
* The product machine key is the root key for storing machine-specific
* product-related information. install() describes where this
* information exists in the registry.
*
* @see install(), getProductUserKey()
*/
inline RegistryKey *RegistryKey::getProductMachineKey(void)
{
DEBUG_FATAL(!installed, ("Attempted to use RegistryKey when not installed\n"));
return productMachineKey;
}
// ======================================================================
#endif
@@ -1,410 +0,0 @@
// ======================================================================
//
// SetupSharedFoundation.cpp
// copyright 1998 Bootprint Entertainment
// copyright 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedFoundation/FirstSharedFoundation.h"
#include "sharedFoundation/SetupSharedFoundation.h"
#include "sharedDebug/DebugMonitor.h"
#include "sharedDebug/InstallTimer.h"
#include "sharedDebug/Profiler.h"
#include "sharedFoundation/ApplicationVersion.h"
#include "sharedFoundation/Clock.h"
#include "sharedFoundation/CommandLine.h"
#include "sharedFoundation/ConfigFile.h"
#include "sharedFoundation/ConfigSharedFoundation.h"
#include "sharedFoundation/CrashReportInformation.h"
#include "sharedFoundation/CrcLowerString.h"
#include "sharedFoundation/ExitChain.h"
#include "sharedFoundation/Os.h"
#include "sharedFoundation/Production.h"
#include "sharedFoundation/RegistryKey.h"
#include "sharedFoundation/StaticCallbackEntry.h"
#include "sharedFoundation/MemoryBlockManager.h"
#include "sharedFoundation/Watcher.h"
#include "sharedLog/TailFileLogObserver.h"
#include <eh.h>
#include <cstdio>
// ======================================================================
namespace FatalNamespace
{
extern char ms_buffer[32 * 1024];
}
namespace SetupSharedFoundationNamespace
{
LONG __stdcall MyUnhandledExceptionFilter(LPEXCEPTION_POINTERS exceptionPointers);
bool ms_writeMiniDumps;
}
using namespace SetupSharedFoundationNamespace;
// ======================================================================
LONG __stdcall SetupSharedFoundationNamespace::MyUnhandledExceptionFilter(LPEXCEPTION_POINTERS exceptionPointers)
{
// make the routine somewhat safe from re-entrance
static bool entered = false;
if (entered)
return EXCEPTION_CONTINUE_SEARCH;
entered = true;
// log some important information
static char buffer[128];
sprintf(buffer, "Exception %08x(%d)=code %08x=addr\n", exceptionPointers->ExceptionRecord->ExceptionCode, exceptionPointers->ExceptionRecord->ExceptionCode, exceptionPointers->ExceptionRecord->ExceptionAddress);
OutputDebugString(buffer);
// write the minidump if we're in here for the first time
static bool ms_alreadyWroteMiniDump = false;
if (ms_writeMiniDumps && !ms_alreadyWroteMiniDump)
{
ms_alreadyWroteMiniDump = true;
uint64 timestamp;
time_t now;
tm t;
IGNORE_RETURN(time(&now));
IGNORE_RETURN(gmtime_r(&now, &t));
timestamp = t.tm_year+1900; //lint !e732 !e737 !e776
timestamp *= 100;
timestamp += t.tm_mon+1; //lint !e737 !e776
timestamp *= 100;
timestamp += static_cast<unsigned int>(t.tm_mday);
timestamp *= 100;
timestamp += static_cast<unsigned int>(t.tm_hour);
timestamp *= 100;
timestamp += static_cast<unsigned int>(t.tm_min);
timestamp *= 100;
timestamp += static_cast<unsigned int>(t.tm_sec);
static char fileName[512];
sprintf(fileName, "%s-%s-%I64d.txt", Os::getShortProgramName(), ApplicationVersion::getInternalVersion(), timestamp);
HANDLE const file = CreateFile(fileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL);
if (file != INVALID_HANDLE_VALUE)
{
char text1[] = "automated crash dump from ";
DWORD bytesWritten;
WriteFile(file, text1, strlen(text1), &bytesWritten, NULL);
char const * text2 = Os::getShortProgramName();
WriteFile(file, text2, strlen(text2), &bytesWritten, NULL);
char text3[] = " ";
WriteFile(file, text3, strlen(text3), &bytesWritten, NULL);
char const * text4 = ApplicationVersion::getInternalVersion();
WriteFile(file, text4, strlen(text4), &bytesWritten, NULL);
char text5[] = "\n\n\n";
WriteFile(file, text5, strlen(text5), &bytesWritten, NULL);
if (exceptionPointers->ExceptionRecord->ExceptionCode == 0x80000003)
{
// write out the fatal buffer
char const * text6 = FatalNamespace::ms_buffer;
WriteFile(file, text6, strlen(text6), &bytesWritten, NULL);
}
else
{
char const * text6 = buffer;
WriteFile(file, text6, strlen(text6), &bytesWritten, NULL);
}
char text7[] = "\n\n";
WriteFile(file, text7, strlen(text7), &bytesWritten, NULL);
char const * text8 = "";
for (int i = 0; text8; ++i)
{
text8 = CrashReportInformation::getEntry(i);
if (text8)
{
int const text8Length = strlen(text8);
if (text8Length)
WriteFile(file, text8, text8Length, &bytesWritten, NULL);
}
}
CloseHandle(file);
}
sprintf(fileName, "%s-%s-%I64d.mdmp", Os::getShortProgramName(), ApplicationVersion::getInternalVersion(), timestamp);
OutputDebugString("Generating minidump ");
OutputDebugString(fileName);
OutputDebugString("\n");
DebugHelp::writeMiniDump(fileName, exceptionPointers);
sprintf(fileName, "%s-%s-%I64d.log", Os::getShortProgramName(), ApplicationVersion::getInternalVersion(), timestamp);
TailFileLogObserver::flushAllTailFileLogObservers(fileName);
}
// tell the Os not to abort so we can rethrow the exception
Os::returnFromAbort();
// Let the ExitChain do its job
Fatal("ExceptionHandler invoked");
// rethrow the exception so that the debugger can catch it
entered = false;
return EXCEPTION_CONTINUE_SEARCH; //lint !e527 // Unreachable
}
// ----------------------------------------------------------------------
static void setFatalVersionString()
{
char buffer[256];
sprintf(buffer, "%s: %s\n", Os::getShortProgramName(), ApplicationVersion::getInternalVersion());
FatalSetVersionString(buffer);
}
// ======================================================================
// Install the engine
//
// Remarks:
//
// The settings in the Data structure will determine which subsystems
// get initialized.
void SetupSharedFoundation::install(const Data &data)
{
InstallTimer const installTimer("SetupSharedFoundation::install");
DEBUG_REPORT_LOG(true, ("SetupSharedFoundation::install: version %s\n", ApplicationVersion::getInternalVersion()));
ms_writeMiniDumps = data.writeMiniDumps;
SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
// and get the command line stuff in quick so we can make decisions based on the command line settings
CommandLine::install();
// feed CommandLine with appropriate strings
if (data.commandLine)
CommandLine::absorbString(data.commandLine);
if (data.argc)
CommandLine::absorbStrings(const_cast<const char**>(data.argv+1), data.argc-1);
// load the config file
ConfigFile::install();
if (data.configFile)
IGNORE_RETURN(ConfigFile::loadFile(data.configFile));
// get the post command-line text for the ConfigFile (key-value pairs)
const char *configString = CommandLine::getPostCommandLineString();
if (configString)
{
IGNORE_RETURN(ConfigFile::loadFromCommandLine(configString));
}
// @todo codereorg should this be here?
MemoryManager::registerDebugFlags();
#if PRODUCTION == 0
Profiler::registerDebugFlags();
#endif
FatalInstall();
// @todo move these, it's part of sharedDebug. However, sharedDebug is installed before sharedFoundation, but these need the ConfigFile. ugh.
#if PRODUCTION == 0
DebugMonitor::install();
#endif
SetWarningStrictFatal(ConfigFile::getKeyBool("SharedDebug", "strict", false));
{
ConfigSharedFoundation::Defaults defaults;
defaults.frameRateLimit = data.frameRateLimit;
defaults.demoMode = data.demoMode;
defaults.verboseWarnings = data.verboseWarnings;
ConfigSharedFoundation::install(defaults);
if (ConfigSharedFoundation::getCauseAccessViolation())
static_cast<int*>(0)[0] = 0;
}
// @todo codereorg should this be here?
#ifdef _DEBUG
MemoryManager::setReportAllocations (ConfigSharedFoundation::getMemoryManagerReportAllocations ());
#endif
MemoryBlockManager::install (ConfigSharedFoundation::getMemoryBlockManagerDebugDumpOnRemove ());
ExitChain::install();
Report::install();
Clock::install(data.clockUsesSleep, data.clockUsesRecalibrationThread);
CrashReportInformation::install();
RegistryKey::install(data.productRegistryKey);
PersistentCrcString::install();
CrcLowerString::install();
WatchedByList::install();
if (data.createWindow)
{
DEBUG_FATAL(data.useWindowHandle, ("exactly one of createWindow and useWindowHandle must be true"));
Os::install(data.hInstance, data.windowName, data.windowNormalIcon, data.windowSmallIcon);
}
else
{
if (data.useWindowHandle)
Os::install(data.windowHandle, data.processMessagePump);
else
Os::install();
}
StaticCallbackEntry::install();
setFatalVersionString();
}
// ----------------------------------------------------------------------
// Call a function with appropriate exception handling
//
// Remarks:
//
// If exception handling has been disabled in the config file, this routine
// will call the callback without exception handling.
void SetupSharedFoundation::callbackWithExceptionHandling(
void (*callback)(void) // Routine to call with exception handling
)
{
callback();
}
// ----------------------------------------------------------------------
// Uninstall the engine
//
// Remarks:
//
// This routine will properly uninstall the engine componenets that were
// installed by SetupSharedFoundation::install().
void SetupSharedFoundation::remove(void)
{
ExitChain::quit();
if (!ConfigSharedFoundation::getDemoMode() && GetNumberOfWarnings())
REPORT(true, Report::RF_print | Report::RF_log | Report::RF_dialog, ("%d warnings logged", GetNumberOfWarnings()));
}
// ======================================================================
SetupSharedFoundation::Data::Data(Defaults defaults)
{
Zero(*this);
switch (defaults)
{
case D_console: setupConsoleDefaults(); break;
case D_game: setupGameDefaults(); break;
case D_mfc: setupMfcDefaults(); break;
default: DEBUG_FATAL(true, ("invalid enum value"));
}
}
// ----------------------------------------------------------------------
void SetupSharedFoundation::Data::setupGameDefaults()
{
createWindow = true;
windowName = NULL;
windowNormalIcon = NULL;
windowSmallIcon = NULL;
hInstance = NULL;
useWindowHandle = false;
processMessagePump = true;
windowHandle = NULL;
clockUsesSleep = false;
clockUsesRecalibrationThread = true;
writeMiniDumps = false;
commandLine = NULL;
argc = 0;
argv = NULL;
configFile = NULL;
productRegistryKey = NULL;
frameRateLimit = CONST_REAL(0);
lostFocusCallback = NULL;
demoMode = false;
verboseWarnings = false;
}
// ----------------------------------------------------------------------
void SetupSharedFoundation::Data::setupConsoleDefaults()
{
createWindow = false;
windowName = NULL;
windowNormalIcon = NULL;
windowSmallIcon = NULL;
hInstance = NULL;
useWindowHandle = false;
processMessagePump = true;
windowHandle = NULL;
clockUsesSleep = false;
clockUsesRecalibrationThread = false;
writeMiniDumps = false;
commandLine = NULL;
argc = NULL;
argv = NULL;
configFile = NULL;
productRegistryKey = NULL;
frameRateLimit = CONST_REAL(0);
lostFocusCallback = NULL;
demoMode = false;
verboseWarnings = false;
}
// ----------------------------------------------------------------------
void SetupSharedFoundation::Data::setupMfcDefaults()
{
createWindow = false;
windowName = NULL;
windowNormalIcon = NULL;
windowSmallIcon = NULL;
hInstance = NULL;
useWindowHandle = false;
processMessagePump = true;
windowHandle = NULL;
clockUsesSleep = false;
clockUsesRecalibrationThread = false;
writeMiniDumps = false;
commandLine = NULL;
argc = 0;
argv = NULL;
configFile = NULL;
productRegistryKey = NULL;
frameRateLimit = CONST_REAL(0);
demoMode = false;
verboseWarnings = false;
}
// ======================================================================
@@ -1,99 +0,0 @@
// ======================================================================
//
// SetupSharedFoundation.h
// copyright 1998 Bootprint Entertainment
// copyright 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_SetupSharedFoundation_H
#define INCLUDED_SetupSharedFoundation_H
// ======================================================================
class SetupSharedFoundation
{
public:
struct Data
{
typedef void (*LostFocusCallbackFuction)();
// window creation stuff
bool createWindow;
const char *windowName;
HICON windowNormalIcon;
HICON windowSmallIcon;
HINSTANCE hInstance;
// window use stuff
bool useWindowHandle;
bool processMessagePump;
HWND windowHandle;
bool writeMiniDumps;
bool clockUsesSleep;
bool clockUsesRecalibrationThread;
// pointer to command line
const char *commandLine;
int argc;
char **argv;
// name of the config file to lead
const char *configFile;
// registry stuff
const char *productRegistryKey;
real frameRateLimit;
bool demoMode;
bool verboseWarnings;
LostFocusCallbackFuction lostFocusCallback;
public:
enum Defaults
{
D_console,
D_game,
D_mfc
};
Data(Defaults defaults);
private:
Data();
void setupGameDefaults();
void setupConsoleDefaults();
void setupMfcDefaults();
};
public:
typedef void (*MainFunction)();
public:
static void install(const Data &data);
static void remove(void);
static void callbackWithExceptionHandling(MainFunction mainFunction);
private:
SetupSharedFoundation();
SetupSharedFoundation(const SetupSharedFoundation &);
SetupSharedFoundation &operator =(const SetupSharedFoundation &);
};
// ======================================================================
#endif
@@ -1,51 +0,0 @@
// ======================================================================
//
// WindowsWrapper.h
// copyright (c) 1998 Bootprint Entertainment
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_WindowsWrapper_H
#define INCLUDED_WindowsWrapper_H
// ======================================================================
// C4201 nonstandard extension used : nameless struct/union
#pragma warning(disable: 4201)
// make windows.h more strict in the types of handles
#ifndef STRICT
#define STRICT 1
#endif
// trim down the amount of stuff windows.h includes
#define NOGDICAPMASKS
#define NOVIRTUALKEYCODE
#define NOKEYSTATES
#define NORASTEROPS
#define NOATOM
#define NOCOLOR
#define NODRAWTEXT
#define NOMEMMGR
#define NOMETAFILE
#define NOMINMAX
#define NOOPENFILE
#define NOSERVICE
#define NOSOUND
#define NOCOMM
#define NOHELP
#define NOPROFILER
#define NODEFERWINDOWPOS
#define NOMCX
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <wtypes.h>
// reenable warnings disables for windows.h
#pragma warning(default: 4201)
// ======================================================================
#endif
@@ -1,33 +0,0 @@
// PRIVATE. Do not export this header file outside the package.
// ======================================================================
//
// FoundationTypesWin32.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_FoundationTypesWin32_H
#define INCLUDED_FoundationTypesWin32_H
// ======================================================================
// specify what platform we're running on.
#define PLATFORM_WIN32
// ======================================================================
// basic types that we assume to be around
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned long uint32;
typedef unsigned __int64 uint64;
typedef signed char int8;
typedef signed short int16;
typedef signed long int32;
typedef signed __int64 int64;
typedef int FILE_HANDLE;
// ======================================================================
#endif
@@ -1,8 +0,0 @@
// ======================================================================
//
// FirstFractal.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedFractal/FirstSharedFractal.h"
@@ -1,9 +0,0 @@
// ======================================================================
//
// FirstSharedGame.cpp
// Copyright 2002-2003 Sony Online Entertainment, Inc.
// All Rights Reserved.
//
// ======================================================================
#include "sharedGame/FirstSharedGame.h"
@@ -1,8 +0,0 @@
// ======================================================================
//
// FirstImage.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedImage/FirstSharedImage.h"
@@ -1,8 +0,0 @@
// ======================================================================
//
// FirstIoWin.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedIoWin/FirstSharedIoWin.h"
@@ -1,35 +0,0 @@
// ======================================================================
//
// StderrLogger.cpp
//
// Copyright 2003 Sony Online Entertainment
//
// ======================================================================
#include "sharedLog/FirstSharedLog.h"
#include "sharedLog/StderrLogger.h"
// ======================================================================
// Unimplemented for win32
// ======================================================================
void StderrLogger::install()
{
}
// ----------------------------------------------------------------------
void StderrLogger::remove()
{
}
// ----------------------------------------------------------------------
void StderrLogger::update()
{
}
// ======================================================================
@@ -1,8 +0,0 @@
// ======================================================================
//
// FirstMath.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedMath/FirstSharedMath.h"
@@ -1,430 +0,0 @@
// ======================================================================
//
// SseMath.cpp
// Copyright 2002 Sony Online Entertainment, Inc.
// All Rights Reserved.
//
// ======================================================================
#include "sharedMath/FirstSharedMath.h"
#include "sharedMath/SseMath.h"
#include "sharedMath/Transform.h"
#include "sharedMath/Vector.h"
// ======================================================================
#define SSE_ALIGN __declspec(align(16))
#define SSE_VARIABLE_COUNT 5
// ======================================================================
namespace
{
SSE_ALIGN float sseVariable[SSE_VARIABLE_COUNT][4];
}
// ======================================================================
/**
* Retrieve whether the hardware can do SSE math.
*
* @return true if SSE math processing is available; false otherwise.
*/
bool SseMath::canDoSseMath()
{
#if 0
return false;
#else
//-- First check the CPUID instruction. If it raises an exception,
// the CPUID instruction doesn't exist and SSE math support is not available.
bool cpuHasSse = false;
bool cpuHasSaveRestore = false;
uint32 featureBits;
#if 0
bool osSupportsSaveRestore = false;
bool osSimdExceptionSupport = false;
bool x87EmulationDisabled = false;
uint32 controlRegister4;
uint32 controlRegister0;
#endif
try
{
__asm {
//-- Get features bits.
mov eax, 1
cpuid
mov featureBits, edx
#if 0
//-- Get control registers.
mov ecx, CR4
mov controlRegister4, ecx
mov ecx, CR0
mov controlRegister0, ecx
#endif
}
cpuHasSse = ((featureBits & 0x02000000) != 0); //lint !e530 // featureBits not initialized - yes it is, in the asm
cpuHasSaveRestore = ((featureBits & 0x01000000) != 0);
#if 0
osSupportsSaveRestore = ((controlRegister4 & 0x00000200) != 0);
osSimdExceptionSupport = ((controlRegister4 & 0x00000400) != 0);
x87EmulationDisabled = ((controlRegister0 & 0x00000004) == 0);
#endif
}
catch (...)
{ //lint !e1775 // catch block does not catch any declared exceptions
}
#if 1
return cpuHasSse && cpuHasSaveRestore;
#else
return cpuHasSse && cpuHasSaveRestore && osSupportsSaveRestore && osSimdExceptionSupport && x87EmulationDisabled;
#endif
#endif
}
// ----------------------------------------------------------------------
Vector SseMath::rotateTranslateScale_l2p(const Transform &transform, const Vector &vector, float scale)
{
// NOTE: technically, my xmm register data contents comments are listing items in reverse order from how INTEL docs list them, left most val is really least significant value.
__asm {
//-- Keep track of ebx. Client is crashing if I trash this.
push ebx
//-- Load up matrix.
mov ebx, transform
movaps xmm0, [ebx + 0] // xmm0 = a1 a2 a3 a4
movaps xmm1, [ebx + 16] // xmm1 = b1 b2 b3 b4
movaps xmm2, [ebx + 32] // xmm2 = c1 c2 c3 c4
}
//-- Prepare source vector.
sseVariable[0][0] = vector.x;
sseVariable[0][1] = vector.y;
sseVariable[0][2] = vector.z;
sseVariable[0][3] = 1.0f;
__asm {
//-- Load up the source vector.
mov ebx, offset sseVariable
movaps xmm3, [ebx] // xmm3 = sx sy sz 1
//-- Copy source to workspaces.
movaps xmm4, xmm3 // xmm4 = sx sy sz 1
movaps xmm5, xmm3 // xmm5 = sx sy sz 1
}
//-- Prepare the scale vector.
__asm {
movss xmm6, scale // xmm6 = scale ? ? ?
shufps xmm6, xmm6, 0x00 // xmm6 = scale scale
movlhps xmm6, xmm6 // xmm6 = scale scale scale scale
//-- Do the transform multiplies.
mulps xmm3, xmm0 // xmm3 = a1*sx a2*sy a3*sz a4
mulps xmm4, xmm1 // xmm4 = b1*sx b2*sy b3*sz b4
mulps xmm5, xmm2 // xmm5 = c1*sx c2*sy c3*sz c4
//-- Do the scale multiplies.
mulps xmm3, xmm6 // xmm3 = a1*sx*scale a2*sy*scale a3*sz*scale a4*scale
mulps xmm4, xmm6 // xmm4 = b1*sx*scale b2*sy*scale b3*sz*scale b4*scale
mulps xmm5, xmm6 // xmm5 = c1*sx*scale c2*sy*scale c3*sz*scale c4*scale
//-- Save out data.
movaps [ebx + 32], xmm3
movaps [ebx + 48], xmm4
movaps [ebx + 64], xmm5
//-- Restore EBX
pop ebx
}
// @todo consider twizzling/detwizzling to be able to perform add in sse.
return Vector(
sseVariable[2][0] + sseVariable[2][1] + sseVariable[2][2] + sseVariable[2][3],
sseVariable[3][0] + sseVariable[3][1] + sseVariable[3][2] + sseVariable[3][3],
sseVariable[4][0] + sseVariable[4][1] + sseVariable[4][2] + sseVariable[4][3]);
} //lint !e715 // scale/transform not referenced - it's in the asm
// ----------------------------------------------------------------------
Vector SseMath::rotateScale_l2p(const Transform &transform, const Vector &vector, float scale)
{
#if 0
// @todo do the real thing.
return transform.rotate_l2p(vector) * scale;
#else
// NOTE: technically, my xmm register data contents comments are listing items in reverse order from how INTEL docs list them, left most val is really least significant value.
__asm {
//-- Keep track of ebx. Client is crashing if I trash this.
push ebx
//-- Load up matrix.
mov ebx, transform
movaps xmm0, [ebx + 0] // xmm0 = a1 a2 a3 a4
movaps xmm1, [ebx + 16] // xmm1 = b1 b2 b3 b4
movaps xmm2, [ebx + 32] // xmm2 = c1 c2 c3 c4
}
//-- Prepare source vector.
sseVariable[0][0] = vector.x;
sseVariable[0][1] = vector.y;
sseVariable[0][2] = vector.z;
sseVariable[0][3] = 0.0f;
__asm {
//-- Load up the source vector.
mov ebx, offset sseVariable
movaps xmm3, [ebx] // xmm3 = sx sy sz 1
//-- Copy source to workspaces.
movaps xmm4, xmm3 // xmm4 = sx sy sz 1
movaps xmm5, xmm3 // xmm5 = sx sy sz 1
}
//-- Prepare the scale vector.
__asm {
movss xmm6, scale // xmm6 = scale ? ? ?
shufps xmm6, xmm6, 0x00 // xmm6 = scale scale
movlhps xmm6, xmm6 // xmm6 = scale scale scale scale
//-- Do the transform multiplies.
mulps xmm3, xmm0 // xmm3 = a1*sx a2*sy a3*sz 0
mulps xmm4, xmm1 // xmm4 = b1*sx b2*sy b3*sz 0
mulps xmm5, xmm2 // xmm5 = c1*sx c2*sy c3*sz 0
//-- Do the scale multiplies.
mulps xmm3, xmm6 // xmm3 = a1*sx*scale a2*sy*scale a3*sz*scale 0
mulps xmm4, xmm6 // xmm4 = b1*sx*scale b2*sy*scale b3*sz*scale 0
mulps xmm5, xmm6 // xmm5 = c1*sx*scale c2*sy*scale c3*sz*scale 0
//-- Save out data.
movaps [ebx + 32], xmm3
movaps [ebx + 48], xmm4
movaps [ebx + 64], xmm5
//-- Restore EBX
pop ebx
}
// @todo consider twizzling/detwizzling to be able to perform add in sse.
return Vector(
sseVariable[2][0] + sseVariable[2][1] + sseVariable[2][2],
sseVariable[3][0] + sseVariable[3][1] + sseVariable[3][2],
sseVariable[4][0] + sseVariable[4][1] + sseVariable[4][2]);
#endif
} //lint !e715 // scale/transform not referenced - it's in the asm
// ----------------------------------------------------------------------
void SseMath::skinPositionNormal_l2p(const Transform &transform, const Vector &sourcePosition, const Vector &sourceNormal, float scale, Vector &destPosition, Vector &destNormal)
{
// NOTE: technically, my xmm register data contents comments are listing items in reverse order from how INTEL docs list them, left most val is really least significant value.
__asm {
//-- Keep track of ebx. Client is crashing if I trash this.
push ebx
//-- Load up matrix.
mov ebx, transform
movaps xmm0, [ebx + 0] // xmm0 = a1 a2 a3 a4
movaps xmm1, [ebx + 16] // xmm1 = b1 b2 b3 b4
movaps xmm2, [ebx + 32] // xmm2 = c1 c2 c3 c4
}
//-- Prepare source position.
sseVariable[0][0] = sourcePosition.x;
sseVariable[0][1] = sourcePosition.y;
sseVariable[0][2] = sourcePosition.z;
sseVariable[0][3] = 1.0f;
__asm {
//-- Load up the source vector.
mov ebx, offset sseVariable
movaps xmm3, [ebx] // xmm3 = sx sy sz 1
//-- Copy source to workspaces.
movaps xmm4, xmm3 // xmm4 = sx sy sz 1
movaps xmm5, xmm3 // xmm5 = sx sy sz 1
//-- Prepare the scale vector.
movss xmm6, scale // xmm6 = scale ? ? ?
shufps xmm6, xmm6, 0x00 // xmm6 = scale scale
movlhps xmm6, xmm6 // xmm6 = scale scale scale scale
//-- Do the transform multiplies.
mulps xmm3, xmm0 // xmm3 = a1*sx a2*sy a3*sz a4
mulps xmm4, xmm1 // xmm4 = b1*sx b2*sy b3*sz b4
mulps xmm5, xmm2 // xmm5 = c1*sx c2*sy c3*sz c4
//-- Do the scale multiplies.
mulps xmm3, xmm6 // xmm3 = a1*sx*scale a2*sy*scale a3*sz*scale a4*scale
mulps xmm4, xmm6 // xmm4 = b1*sx*scale b2*sy*scale b3*sz*scale b4*scale
mulps xmm5, xmm6 // xmm5 = c1*sx*scale c2*sy*scale c3*sz*scale c4*scale
//-- Save out data.
movaps [ebx + 32], xmm3
movaps [ebx + 48], xmm4
movaps [ebx + 64], xmm5
}
destPosition.x = sseVariable[2][0] + sseVariable[2][1] + sseVariable[2][2] + sseVariable[2][3];
destPosition.y = sseVariable[3][0] + sseVariable[3][1] + sseVariable[3][2] + sseVariable[3][3];
destPosition.z = sseVariable[4][0] + sseVariable[4][1] + sseVariable[4][2] + sseVariable[4][3];
//-- Prepare source normal.
sseVariable[0][0] = sourceNormal.x;
sseVariable[0][1] = sourceNormal.y;
sseVariable[0][2] = sourceNormal.z;
sseVariable[0][3] = 1.0f;
__asm {
//-- Load up the source vector.
movaps xmm3, [ebx] // xmm3 = sx sy sz 1
//-- Copy source to workspaces.
movaps xmm4, xmm3 // xmm4 = sx sy sz 1
movaps xmm5, xmm3 // xmm5 = sx sy sz 1
//-- Do the transform multiplies.
mulps xmm3, xmm0 // xmm3 = a1*sx a2*sy a3*sz a4
mulps xmm4, xmm1 // xmm4 = b1*sx b2*sy b3*sz b4
mulps xmm5, xmm2 // xmm5 = c1*sx c2*sy c3*sz c4
//-- Do the scale multiplies.
mulps xmm3, xmm6 // xmm3 = a1*sx*scale a2*sy*scale a3*sz*scale a4*scale
mulps xmm4, xmm6 // xmm4 = b1*sx*scale b2*sy*scale b3*sz*scale b4*scale
mulps xmm5, xmm6 // xmm5 = c1*sx*scale c2*sy*scale c3*sz*scale c4*scale
//-- Save out data.
movaps [ebx + 32], xmm3
movaps [ebx + 48], xmm4
movaps [ebx + 64], xmm5
//-- Restore EBX
pop ebx
}
destNormal.x = sseVariable[2][0] + sseVariable[2][1] + sseVariable[2][2];
destNormal.y = sseVariable[3][0] + sseVariable[3][1] + sseVariable[3][2];
destNormal.z = sseVariable[4][0] + sseVariable[4][1] + sseVariable[4][2];
} //lint !e715 // scale/transform not referenced - it's in the asm
// ----------------------------------------------------------------------
void SseMath::skinPositionNormalAdd_l2p(const Transform &transform, const Vector &sourcePosition, const Vector &sourceNormal, float scale, Vector &destPosition, Vector &destNormal)
{
// NOTE: technically, my xmm register data contents comments are listing items in reverse order from how INTEL docs list them, left most val is really least significant value.
__asm {
//-- Keep track of ebx. Client is crashing if I trash this.
push ebx
//-- Load up matrix.
mov ebx, transform
movaps xmm0, [ebx + 0] // xmm0 = a1 a2 a3 a4
movaps xmm1, [ebx + 16] // xmm1 = b1 b2 b3 b4
movaps xmm2, [ebx + 32] // xmm2 = c1 c2 c3 c4
}
//-- Prepare source position.
sseVariable[0][0] = sourcePosition.x;
sseVariable[0][1] = sourcePosition.y;
sseVariable[0][2] = sourcePosition.z;
sseVariable[0][3] = 1.0f;
__asm {
//-- Load up the source vector.
mov ebx, offset sseVariable
movaps xmm3, [ebx] // xmm3 = sx sy sz 1
//-- Copy source to workspaces.
movaps xmm4, xmm3 // xmm4 = sx sy sz 1
movaps xmm5, xmm3 // xmm5 = sx sy sz 1
//-- Prepare the scale vector.
movss xmm6, scale // xmm6 = scale ? ? ?
shufps xmm6, xmm6, 0x00 // xmm6 = scale scale
movlhps xmm6, xmm6 // xmm6 = scale scale scale scale
//-- Do the transform multiplies.
mulps xmm3, xmm0 // xmm3 = a1*sx a2*sy a3*sz a4
mulps xmm4, xmm1 // xmm4 = b1*sx b2*sy b3*sz b4
mulps xmm5, xmm2 // xmm5 = c1*sx c2*sy c3*sz c4
//-- Do the scale multiplies.
mulps xmm3, xmm6 // xmm3 = a1*sx*scale a2*sy*scale a3*sz*scale a4*scale
mulps xmm4, xmm6 // xmm4 = b1*sx*scale b2*sy*scale b3*sz*scale b4*scale
mulps xmm5, xmm6 // xmm5 = c1*sx*scale c2*sy*scale c3*sz*scale c4*scale
//-- Save out data.
movaps [ebx + 32], xmm3
movaps [ebx + 48], xmm4
movaps [ebx + 64], xmm5
}
destPosition.x += sseVariable[2][0] + sseVariable[2][1] + sseVariable[2][2] + sseVariable[2][3];
destPosition.y += sseVariable[3][0] + sseVariable[3][1] + sseVariable[3][2] + sseVariable[3][3];
destPosition.z += sseVariable[4][0] + sseVariable[4][1] + sseVariable[4][2] + sseVariable[4][3];
//-- Prepare source normal.
sseVariable[0][0] = sourceNormal.x;
sseVariable[0][1] = sourceNormal.y;
sseVariable[0][2] = sourceNormal.z;
sseVariable[0][3] = 1.0f;
__asm {
//-- Load up the source vector.
movaps xmm3, [ebx] // xmm3 = sx sy sz 1
//-- Copy source to workspaces.
movaps xmm4, xmm3 // xmm4 = sx sy sz 1
movaps xmm5, xmm3 // xmm5 = sx sy sz 1
//-- Do the transform multiplies.
mulps xmm3, xmm0 // xmm3 = a1*sx a2*sy a3*sz a4
mulps xmm4, xmm1 // xmm4 = b1*sx b2*sy b3*sz b4
mulps xmm5, xmm2 // xmm5 = c1*sx c2*sy c3*sz c4
//-- Do the scale multiplies.
mulps xmm3, xmm6 // xmm3 = a1*sx*scale a2*sy*scale a3*sz*scale a4*scale
mulps xmm4, xmm6 // xmm4 = b1*sx*scale b2*sy*scale b3*sz*scale b4*scale
mulps xmm5, xmm6 // xmm5 = c1*sx*scale c2*sy*scale c3*sz*scale c4*scale
//-- Save out data.
movaps [ebx + 32], xmm3
movaps [ebx + 48], xmm4
movaps [ebx + 64], xmm5
//-- Restore EBX
pop ebx
}
destNormal.x += sseVariable[2][0] + sseVariable[2][1] + sseVariable[2][2];
destNormal.y += sseVariable[3][0] + sseVariable[3][1] + sseVariable[3][2];
destNormal.z += sseVariable[4][0] + sseVariable[4][1] + sseVariable[4][2];
} //lint !e715 // scale/transform not referenced - it's in the asm
// ======================================================================
@@ -1,58 +0,0 @@
// ======================================================================
//
// SseMath.h
// Copyright 2002 Sony Online Entertainment, Inc.
// All Rights Reserved.
//
// ======================================================================
#ifndef INCLUDED_SseMath_H
#define INCLUDED_SseMath_H
// ======================================================================
class Transform;
class Vector;
// ======================================================================
#define MXCSR_FLUSH_TO_ZERO (1<<15)
#define MXCSR_PRECISION_MASK (1<<12)
#define MXCSR_UNDERFLOW_MASK (1<<11)
#define MXCSR_OVERFLOW_MASK (1<<10)
#define MXCSR_DIVIDE_BY_ZERO_MASK (1<< 9)
#define MXCSR_DENORMAL_MASK (1<< 8)
class SseMath
{
public:
static bool canDoSseMath();
static Vector rotateTranslateScale_l2p(const Transform &transform, const Vector &vector, float scale);
static Vector rotateScale_l2p(const Transform &transform, const Vector &vector, float scale);
static void skinPositionNormal_l2p(const Transform &transform, const Vector &position, const Vector &normal, float scale, Vector &destPosition, Vector &destNormal);
static void skinPositionNormalAdd_l2p(const Transform &transform, const Vector &position, const Vector &normal, float scale, Vector &destPosition, Vector &destNormal);
static void prefetch(void const * const sourceData, size_t const objectSize);
};
// ----------------------------------------------------------------------
inline void SseMath::prefetch(void const * const sourceData, size_t const objectSize)
{
#if defined(_MSC_VER)
_asm
{
mov esi, sourceData
prefetchnta objectSize[esi]
}
#else
// rls - add linux version here.
UNREF(sourceData);
UNREF(objectSize);
#endif
}
// ======================================================================
#endif
@@ -1,56 +0,0 @@
// ======================================================================
//
// OsMemory.cpp
//
// Copyright 2002 Sony Online Entertainment
//
// ======================================================================
#include "sharedMemoryManager/FirstSharedMemoryManager.h"
#include "sharedMemoryManager/OsMemory.h"
// ======================================================================
void OsMemory::install()
{
}
// ----------------------------------------------------------------------
void OsMemory::remove()
{
}
// ----------------------------------------------------------------------
void *OsMemory::reserve(size_t bytes)
{
return VirtualAlloc(0, bytes, MEM_RESERVE, PAGE_READWRITE);
}
// ----------------------------------------------------------------------
void *OsMemory::commit(void *addr, size_t bytes)
{
return VirtualAlloc(addr, bytes, MEM_COMMIT, PAGE_READWRITE);
}
// ----------------------------------------------------------------------
bool OsMemory::free(void *addr, size_t bytes)
{
UNREF(bytes);
return VirtualFree(addr, 0, MEM_RELEASE) ? true : false;
}
// ----------------------------------------------------------------------
bool OsMemory::protect(void *addr, size_t bytes, bool allowAccess)
{
DWORD old;
BOOL result = VirtualProtect(addr, bytes, allowAccess ? PAGE_READWRITE : PAGE_NOACCESS, &old);
return result ? true : false;
}
// ======================================================================
@@ -1,29 +0,0 @@
// ======================================================================
//
// OsMemory.h
//
// Copyright 2002 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_OsMemory_H
#define INCLUDED_OsMemory_H
// ======================================================================
class OsMemory
{
public:
static void install();
static void remove();
static void * reserve(size_t bytes);
static void * commit(void *addr, size_t bytes);
static bool free(void *addr, size_t bytes);
static bool protect(void *addr, size_t bytes, bool allowAccess);
};
// ======================================================================
#endif INCLUDED_OsMemory_H
@@ -1,211 +0,0 @@
// ======================================================================
//
// OsNewDel.cpp
//
// Copyright 2002 Sony Online Entertainment
//
// ======================================================================
#include "sharedMemoryManager/FirstSharedMemoryManager.h"
#include "sharedMemoryManager/OsNewDel.h"
// ======================================================================
// this is here because MSVC won't call MemoryManager::allocate() from asm directly
static void * __cdecl localAllocate(size_t size, uint32 owner, bool array, bool leakTest)
{
return MemoryManager::allocate(size, owner, array, leakTest);
}
// ----------------------------------------------------------------------
// We are using the arguments (except for file and line), but MSVC can't tell that.
#pragma warning(disable: 4100)
// ----------------------------------------------------------------------
__declspec(naked) void *operator new(size_t size, MemoryManagerNotALeak)
{
_asm
{
// setup local call stack
push ebp
mov ebp, esp
// MemoryManager::alloc(size, [return address], false, false)
push 0
push 0
mov eax, dword ptr [ebp+4]
push eax
mov eax, dword ptr [ebp+8]
push eax
call localAllocate
add esp, 12
mov esp, ebp
pop ebp
ret
}
}
// ----------------------------------------------------------------------
__declspec(naked) void *operator new(size_t size)
{
_asm
{
// setup local call stack
push ebp
mov ebp, esp
// MemoryManager::alloc(size, [return address], false, true)
push 1
push 0
mov eax, dword ptr [ebp+4]
push eax
mov eax, dword ptr [ebp+8]
push eax
call localAllocate
add esp, 12
mov esp, ebp
pop ebp
ret
}
}
// ----------------------------------------------------------------------
__declspec(naked) void *operator new[](size_t size)
{
_asm
{
// setup local call stack
push ebp
mov ebp, esp
// MemoryManager::alloc(size, [return address], true, true)
push 1
push 1
mov eax, dword ptr [ebp+4]
push eax
mov eax, dword ptr [ebp+8]
push eax
call localAllocate
add esp, 12
mov esp, ebp
pop ebp
ret
}
}
// ----------------------------------------------------------------------
__declspec(naked) void *operator new(size_t size, const char *file, int line)
{
_asm
{
// setup local call stack
push ebp
mov ebp, esp
// MemoryManager::alloc(size, [return address], false, true)
push 1
push 0
mov eax, dword ptr [ebp+4]
push eax
mov eax, dword ptr [ebp+8]
push eax
call localAllocate
add esp, 12
mov esp, ebp
pop ebp
ret
}
}
// ----------------------------------------------------------------------
__declspec(naked) void *operator new[](size_t size, const char *file, int line)
{
_asm
{
// setup local call stack
push ebp
mov ebp, esp
// MemoryManager::alloc(size, [return address], true, true)
push 1
push 1
mov eax, dword ptr [ebp+4]
push eax
mov eax, dword ptr [ebp+8]
push eax
call localAllocate
add esp, 12
mov esp, ebp
pop ebp
ret
}
}
// ----------------------------------------------------------------------
#pragma warning(default: 4100)
// ----------------------------------------------------------------------
void operator delete(void *pointer)
{
if (pointer)
MemoryManager::free(pointer, false);
}
// ----------------------------------------------------------------------
void operator delete[](void *pointer)
{
if (pointer)
MemoryManager::free(pointer, true);
}
// ----------------------------------------------------------------------
void operator delete(void *pointer, const char *file, int line)
{
UNREF(file);
UNREF(line);
if (pointer)
MemoryManager::free(pointer, false);
}
// ----------------------------------------------------------------------
void operator delete[](void *pointer, const char *file, int line)
{
UNREF(file);
UNREF(line);
if (pointer)
MemoryManager::free(pointer, true);
}
// ======================================================================
// WARNING!!!!!!!
//
// The init_seg pragma command is used to create certain static objects first, before other static objects are created.
// However, multiple static variables that use the same init_seg category(i.e. compiler) are not guaranteed to destroy in any
// particular order. It is completely random based on how all the linking of static objects occurs. Since this command is being
// used on our memory manager(to overwrite new/delete) - NO OTHER STATIC SHOULD EVER USE INIT_SEG(COMPILER)!!!! This static object
// *MUST* be the final static object that is destroyed.
//
#pragma warning(disable: 4074)
#pragma init_seg(compiler) // ^-Read warning above.-^
static MemoryManager memoryManager;
// ======================================================================
@@ -1,52 +0,0 @@
// ======================================================================
//
// OsNewDel.h
//
// Copyright 2002 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_OsNewDel_H
#define INCLUDED_OsNewDel_H
// ======================================================================
enum MemoryManagerNotALeak
{
MM_notALeak
};
void * __cdecl operator new(size_t size, MemoryManagerNotALeak);
void * __cdecl operator new(size_t size);
void * __cdecl operator new[](size_t size);
void * __cdecl operator new(size_t size, char const *file, int line);
void * __cdecl operator new[](size_t size, char const *file, int line);
void * __cdecl operator new(size_t size, void *placement);
void operator delete(void *pointer);
void operator delete[](void *pointer);
void operator delete(void *pointer, char const *file, int line);
void operator delete[](void *pointer, char const *file, int line);
void operator delete(void *pointer, void *placement);
#ifndef __PLACEMENT_NEW_INLINE
#define __PLACEMENT_NEW_INLINE
inline void *operator new(size_t size, void *placement)
{
static_cast<void>(size);
return placement;
}
inline void operator delete(void *pointer, void *placement)
{
static_cast<void>(pointer);
static_cast<void>(placement);
}
#endif // __PLACEMENT_NEW_INLINE
// ======================================================================
#endif INCLUDED_OsNewDel_H
@@ -1,8 +0,0 @@
// ======================================================================
//
// FirstMessageDispatch.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedMessageDispatch/FirstSharedMessageDispatch.h"

Some files were not shown because too many files have changed in this diff Show More