mirror of
https://github.com/reactos/reactos.git
synced 2025-07-24 13:53:41 +00:00
Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers into modules, and delete rossubsys.
This commit is contained in:
parent
b94e2d8ca0
commit
c2c66aff7d
24198 changed files with 0 additions and 37285 deletions
|
@ -0,0 +1,15 @@
|
|||
//
|
||||
// EnumDirs.h
|
||||
//
|
||||
|
||||
#ifndef __ENUMDIRS_H
|
||||
#define __ENUMDIRS_H
|
||||
|
||||
//#include "win.h"
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
typedef BOOL (*MYENUMDIRSPROC) ( PWIN32_FIND_DATA, long );
|
||||
BOOL EnumDirs ( const TCHAR* szDirectory, const TCHAR* szFileSpec, MYENUMDIRSPROC pProc, long lParam );
|
||||
|
||||
#endif//__ENUMDIRS_H
|
|
@ -0,0 +1,42 @@
|
|||
//
|
||||
// EnumDirs.cpp
|
||||
//
|
||||
|
||||
#include "EnumDirs.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(UNDER_CE) && !defined(assert)
|
||||
#define assert(x)
|
||||
#endif
|
||||
|
||||
BOOL EnumDirs ( const TCHAR* szDirectory_, const TCHAR* szFileSpec, MYENUMDIRSPROC pProc, long lParam )
|
||||
{
|
||||
assert ( szDirectory_ && szFileSpec && pProc );
|
||||
TCHAR szDirectory[MAX_PATH+1];
|
||||
TCHAR szSearchPath[MAX_PATH+1];
|
||||
TCHAR szTemp[MAX_PATH+1];
|
||||
_tcscpy ( szDirectory, szDirectory_ );
|
||||
if ( szDirectory[_tcslen(szDirectory)-1] != '\\' )
|
||||
_tcscat ( szDirectory, _T("\\") );
|
||||
_sntprintf ( szSearchPath, _MAX_PATH, _T("%s%s"), szDirectory, szFileSpec );
|
||||
WIN32_FIND_DATA wfd;
|
||||
HANDLE hfind = FindFirstFile ( szSearchPath, &wfd );
|
||||
if ( hfind == INVALID_HANDLE_VALUE )
|
||||
return TRUE;
|
||||
do
|
||||
{
|
||||
if ( !_tcscmp ( wfd.cFileName, _T(".") ) || !_tcscmp ( wfd.cFileName, _T("..") ) )
|
||||
continue;
|
||||
_sntprintf ( szTemp, _MAX_PATH, _T("%s%s"), szDirectory, wfd.cFileName );
|
||||
if ( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
|
||||
{
|
||||
if ( !pProc ( &wfd, lParam ) )
|
||||
{
|
||||
FindClose ( hfind );
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
} while ( FindNextFile ( hfind, &wfd ) );
|
||||
FindClose ( hfind );
|
||||
return TRUE;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
//
|
||||
// EnumFiles.h
|
||||
//
|
||||
|
||||
#ifndef ENUMFILES_H
|
||||
#define ENUMFILES_H
|
||||
|
||||
typedef BOOL (*MYENUMFILESPROC) ( PWIN32_FIND_DATA, const TCHAR*, long );
|
||||
BOOL EnumFilesInDirectory ( const TCHAR* szDirectory, const TCHAR* szFileSpec, MYENUMFILESPROC pProc, long lParam, BOOL bSubsToo, BOOL bSubsMustMatchFileSpec = FALSE );
|
||||
|
||||
#endif//ENUMFILES_H
|
|
@ -0,0 +1,92 @@
|
|||
//
|
||||
// EnumFilesImpl.h
|
||||
//
|
||||
|
||||
#include "EnumFiles.h"
|
||||
#include "FixLFN.h"
|
||||
#include "safestr.h"
|
||||
#ifndef UNDER_CE
|
||||
#include <direct.h>
|
||||
#endif//UNDER_CE
|
||||
#include <stdio.h>
|
||||
|
||||
BOOL EnumFilesInDirectory ( const TCHAR* szDirectory_, const TCHAR* szFileSpec, MYENUMFILESPROC pProc, long lParam, BOOL bSubsToo, BOOL bSubsMustMatchFileSpec )
|
||||
{
|
||||
TCHAR szDirectory[MAX_PATH+1];
|
||||
TCHAR szSearchPath[MAX_PATH+1];
|
||||
TCHAR szTemp[MAX_PATH+1];
|
||||
|
||||
if ( safestrlen(szDirectory_) > MAX_PATH || !szFileSpec || !pProc )
|
||||
return FALSE;
|
||||
if ( szDirectory_ )
|
||||
_tcscpy ( szDirectory, szDirectory_ );
|
||||
else
|
||||
#ifdef UNDER_CE
|
||||
_tcscpy ( szDirectory, _T("") );
|
||||
#else//UNDER_CE
|
||||
getcwd ( szDirectory, sizeof(szDirectory)-1 );
|
||||
#endif//UNDER_CE
|
||||
int dirlen = _tcslen(szDirectory);
|
||||
if ( dirlen > 0 && szDirectory[dirlen-1] != '\\' )
|
||||
_tcscat ( szDirectory, _T("\\") );
|
||||
|
||||
// first search for all files in directory that match szFileSpec...
|
||||
_sntprintf ( szSearchPath, sizeof(szSearchPath)-1, _T("%s%s"), szDirectory, szFileSpec );
|
||||
WIN32_FIND_DATA wfd;
|
||||
HANDLE hfind = FindFirstFile ( szSearchPath, &wfd );
|
||||
if ( hfind != INVALID_HANDLE_VALUE )
|
||||
{
|
||||
do
|
||||
{
|
||||
if ( !_tcscmp ( wfd.cFileName, _T(".") ) || !_tcscmp ( wfd.cFileName, _T("..") ) )
|
||||
continue;
|
||||
if ( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
|
||||
{
|
||||
if ( !bSubsMustMatchFileSpec )
|
||||
continue;
|
||||
_sntprintf ( szTemp, sizeof(szTemp)-1, _T("%s%s"), szDirectory, wfd.cFileName );
|
||||
if ( bSubsToo )
|
||||
{
|
||||
if ( !EnumFilesInDirectory ( szTemp, szFileSpec, pProc, lParam, bSubsToo, bSubsMustMatchFileSpec ) )
|
||||
{
|
||||
FindClose ( hfind );
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
_sntprintf ( szTemp, sizeof(szTemp)-1, _T("%s%s"), szDirectory, wfd.cFileName );
|
||||
FixLFN(szTemp,szTemp);
|
||||
if ( !pProc ( &wfd, szTemp, lParam ) )
|
||||
{
|
||||
FindClose ( hfind );
|
||||
return FALSE;
|
||||
}
|
||||
} while ( FindNextFile ( hfind, &wfd ) );
|
||||
FindClose ( hfind );
|
||||
}
|
||||
if ( !bSubsToo || bSubsMustMatchFileSpec )
|
||||
return TRUE;
|
||||
|
||||
// now search for all subdirectories...
|
||||
_sntprintf ( szSearchPath, sizeof(szSearchPath)-1, _T("%s*.*"), szDirectory );
|
||||
hfind = FindFirstFile ( szSearchPath, &wfd );
|
||||
if ( hfind != INVALID_HANDLE_VALUE )
|
||||
{
|
||||
do
|
||||
{
|
||||
if ( !_tcscmp ( wfd.cFileName, _T(".") ) || !_tcscmp ( wfd.cFileName, _T("..") ) )
|
||||
continue;
|
||||
if ( !(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
|
||||
continue;
|
||||
_sntprintf ( szTemp, sizeof(szTemp)-1, _T("%s%s"), szDirectory, wfd.cFileName );
|
||||
if ( FALSE == EnumFilesInDirectory ( szTemp, szFileSpec, pProc, lParam, bSubsToo, bSubsMustMatchFileSpec ) )
|
||||
{
|
||||
FindClose ( hfind );
|
||||
return FALSE;
|
||||
}
|
||||
} while ( FindNextFile ( hfind, &wfd ) );
|
||||
FindClose ( hfind );
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
129
modules/rosapps/applications/sysutils/utils/sdkparse/File.cpp
Normal file
129
modules/rosapps/applications/sysutils/utils/sdkparse/File.cpp
Normal file
|
@ -0,0 +1,129 @@
|
|||
// File.cpp
|
||||
// This file is (C) 2002-2003 Royce Mitchell III and released under the BSD license
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning ( disable : 4786 )
|
||||
#endif//_MSC_VER
|
||||
|
||||
#include "File.h"
|
||||
|
||||
bool File::open ( const char* filename, const char* mode )
|
||||
{
|
||||
close();
|
||||
_f = fopen ( filename, mode );
|
||||
return _f != 0;
|
||||
}
|
||||
|
||||
std::string File::getline ( bool strip_crlf /*= false*/ )
|
||||
{
|
||||
std::string s = "";
|
||||
char buf[256];
|
||||
for ( ;; )
|
||||
{
|
||||
*buf = 0;
|
||||
fgets ( buf, sizeof(buf)-1, _f );
|
||||
if ( !*buf )
|
||||
break;
|
||||
s += buf;
|
||||
if ( strchr ( "\r\n", buf[strlen(buf)-1] ) )
|
||||
break;
|
||||
}
|
||||
if ( strip_crlf )
|
||||
{
|
||||
char* p = strpbrk ( &s[0], "\r\n" );
|
||||
if ( p )
|
||||
{
|
||||
*p = '\0';
|
||||
s.resize ( p-&s[0] );
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// this function searches for the next end-of-line and puts all data it
|
||||
// finds until then in the 'line' parameter.
|
||||
//
|
||||
// call continuously until the function returns false ( no more data )
|
||||
bool File::next_line ( std::string& line, bool strip_crlf )
|
||||
{
|
||||
line = getline(strip_crlf);
|
||||
// indicate that we're done *if*:
|
||||
// 1) there's no more data, *and*
|
||||
// 2) we're at the end of the file
|
||||
return line.size()>0 || !eof();
|
||||
}
|
||||
|
||||
/*
|
||||
example usage:
|
||||
|
||||
bool mycallback ( const std::string& line, int line_number, long lparam )
|
||||
{
|
||||
std::cout << line << std::endl;
|
||||
return true; // continue enumeration
|
||||
}
|
||||
|
||||
File f ( "file.txt", "rb" ); // open file for binary read-only ( i.e. "rb" )
|
||||
f.enum_lines ( mycallback, 0, true );
|
||||
*/
|
||||
|
||||
bool File::enum_lines ( bool (*callback)(const std::string& line, int line_number, long lparam), long lparam, bool strip_crlf )
|
||||
{
|
||||
int line_number = 0;
|
||||
for ( ;; )
|
||||
{
|
||||
std::string s = getline(strip_crlf);
|
||||
line_number++;
|
||||
if ( !s.size() )
|
||||
{
|
||||
if ( eof() )
|
||||
return true;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
if ( !(*callback) ( s, line_number, lparam ) )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
size_t File::length()
|
||||
{
|
||||
#ifdef WIN32
|
||||
return _filelength ( _fileno(_f) );
|
||||
#elif defined(UNIX)
|
||||
struct stat file_stat;
|
||||
verify(fstat(fileno(_f), &file_stat) == 0);
|
||||
return file_stat.st_size;
|
||||
#endif
|
||||
}
|
||||
|
||||
void File::close()
|
||||
{
|
||||
if ( _f )
|
||||
{
|
||||
fclose(_f);
|
||||
_f = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*static*/ bool File::LoadIntoString ( std::string& s, const char* filename )
|
||||
{
|
||||
File in ( filename, "rb" );
|
||||
if ( !in.isopened() )
|
||||
return false;
|
||||
size_t len = in.length();
|
||||
s.resize ( len + 1 );
|
||||
if ( !in.read ( &s[0], len ) )
|
||||
return false;
|
||||
s[len] = '\0';
|
||||
s.resize ( len );
|
||||
return true;
|
||||
}
|
||||
|
||||
/*static*/ bool File::SaveFromString ( const char* filename, const std::string& s, bool binary )
|
||||
{
|
||||
File out ( filename, binary ? "wb" : "w" );
|
||||
if ( !out.isopened() )
|
||||
return false;
|
||||
out.write ( s.c_str(), s.size() );
|
||||
return true;
|
||||
}
|
111
modules/rosapps/applications/sysutils/utils/sdkparse/File.h
Normal file
111
modules/rosapps/applications/sysutils/utils/sdkparse/File.h
Normal file
|
@ -0,0 +1,111 @@
|
|||
// File.h
|
||||
// This file is (C) 2002-2003 Royce Mitchell III and released under the BSD license
|
||||
|
||||
#ifndef FILE_H
|
||||
#define FILE_H
|
||||
|
||||
#ifdef WIN32
|
||||
# include <io.h>
|
||||
#elif defined(UNIX)
|
||||
# include <sys/stat.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#include <string>
|
||||
|
||||
class File
|
||||
{
|
||||
public:
|
||||
File() : _f(0)
|
||||
{
|
||||
}
|
||||
|
||||
File ( const char* filename, const char* mode ) : _f(0)
|
||||
{
|
||||
open ( filename, mode );
|
||||
}
|
||||
|
||||
~File()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
bool open ( const char* filename, const char* mode );
|
||||
|
||||
bool seek ( long offset )
|
||||
{
|
||||
return !fseek ( _f, offset, SEEK_SET );
|
||||
}
|
||||
|
||||
int get()
|
||||
{
|
||||
return fgetc ( _f );
|
||||
}
|
||||
|
||||
bool put ( int c )
|
||||
{
|
||||
return fputc ( c, _f ) != EOF;
|
||||
}
|
||||
|
||||
std::string getline ( bool strip_crlf = false );
|
||||
|
||||
// this function searches for the next end-of-line and puts all data it
|
||||
// finds until then in the 'line' parameter.
|
||||
//
|
||||
// call continuously until the function returns false ( no more data )
|
||||
bool next_line ( std::string& line, bool strip_crlf );
|
||||
|
||||
/*
|
||||
example usage:
|
||||
|
||||
bool mycallback ( const std::string& line, int line_number, long lparam )
|
||||
{
|
||||
std::cout << line << std::endl;
|
||||
return true; // continue enumeration
|
||||
}
|
||||
|
||||
File f ( "file.txt", "rb" ); // open file for binary read-only ( i.e. "rb" )
|
||||
f.enum_lines ( mycallback, 0, true );
|
||||
*/
|
||||
|
||||
bool enum_lines ( bool (*callback)(const std::string& line, int line_number, long lparam), long lparam, bool strip_crlf );
|
||||
|
||||
bool read ( void* data, unsigned len )
|
||||
{
|
||||
return len == fread ( data, 1, len, _f );
|
||||
}
|
||||
|
||||
bool write ( const void* data, unsigned len )
|
||||
{
|
||||
return len == fwrite ( data, 1, len, _f );
|
||||
}
|
||||
|
||||
size_t length();
|
||||
|
||||
void close();
|
||||
|
||||
bool isopened()
|
||||
{
|
||||
return _f != 0;
|
||||
}
|
||||
|
||||
bool eof()
|
||||
{
|
||||
return feof(_f) ? true : false;
|
||||
}
|
||||
|
||||
FILE* operator * ()
|
||||
{
|
||||
return _f;
|
||||
}
|
||||
|
||||
static bool LoadIntoString ( std::string& s, const char* filename );
|
||||
static bool SaveFromString ( const char* filename, const std::string& s, bool binary );
|
||||
|
||||
private:
|
||||
File(const File&) {}
|
||||
const File& operator = ( const File& ) { return *this; }
|
||||
|
||||
FILE * _f;
|
||||
};
|
||||
|
||||
#endif//FILE_H
|
|
@ -0,0 +1,32 @@
|
|||
//
|
||||
// FixLFN.h
|
||||
//
|
||||
|
||||
#ifndef __FIXLFN_H
|
||||
#define __FIXLFN_H
|
||||
|
||||
#include <string.h>
|
||||
#include <tchar.h>
|
||||
#include <shellapi.h>
|
||||
|
||||
inline int FixLFN ( const TCHAR* pBadFileName, TCHAR* pGoodFileName )
|
||||
{
|
||||
SHFILEINFO sfi;
|
||||
TCHAR* p;
|
||||
|
||||
DWORD dwResult = SHGetFileInfo ( pBadFileName, 0, &sfi, sizeof(sfi), SHGFI_DISPLAYNAME );
|
||||
if ( dwResult )
|
||||
{
|
||||
if ( pGoodFileName != pBadFileName )
|
||||
_tcscpy ( pGoodFileName, pBadFileName );
|
||||
if ( (p = _tcsrchr ( pGoodFileName, '\\' )) )
|
||||
_tcscpy ( p+1, sfi.szDisplayName );
|
||||
else if ( (p = _tcsrchr ( pGoodFileName, '/' )) )
|
||||
_tcscpy ( p+1, sfi.szDisplayName );
|
||||
else
|
||||
_tcscpy ( pGoodFileName, sfi.szDisplayName );
|
||||
}
|
||||
return dwResult;
|
||||
}
|
||||
|
||||
#endif//__FIXLFN_H
|
|
@ -0,0 +1,26 @@
|
|||
// Header.h
|
||||
|
||||
#ifndef HEADER_H
|
||||
#define HEADER_H
|
||||
|
||||
#include "Symbol.h"
|
||||
|
||||
class Header
|
||||
{
|
||||
public:
|
||||
std::string filename;
|
||||
std::vector<std::string> includes, libc_includes, pragmas;
|
||||
std::vector<Symbol*> symbols;
|
||||
bool done, externc;
|
||||
|
||||
std::vector<std::string> ifs, ifspreproc;
|
||||
|
||||
Header ( const std::string& filename_ )
|
||||
: filename(filename_)
|
||||
{
|
||||
done = false;
|
||||
externc = false;
|
||||
}
|
||||
};
|
||||
|
||||
#endif//HEADER_H
|
|
@ -0,0 +1,18 @@
|
|||
// Symbol.h
|
||||
|
||||
#ifndef SYMBOL_H
|
||||
#define SYMBOL_H
|
||||
|
||||
#include "Type.h"
|
||||
|
||||
class Symbol
|
||||
{
|
||||
public:
|
||||
Type type;
|
||||
std::vector<std::string> names;
|
||||
std::vector<std::string> dependencies;
|
||||
std::vector<std::string> ifs;
|
||||
std::string definition;
|
||||
};
|
||||
|
||||
#endif//SYMBOL_H
|
22
modules/rosapps/applications/sysutils/utils/sdkparse/Type.h
Normal file
22
modules/rosapps/applications/sysutils/utils/sdkparse/Type.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Type.h
|
||||
|
||||
#ifndef TYPE_H
|
||||
#define TYPE_H
|
||||
|
||||
typedef enum
|
||||
{
|
||||
T_UNKNOWN = -1,
|
||||
T_IGNORED_STATEMENT,
|
||||
T_TIDENT,
|
||||
T_MACRO,
|
||||
T_DEFINE,
|
||||
T_VARIABLE,
|
||||
T_FUNCTION,
|
||||
T_FUNCTION_PTR,
|
||||
T_IF,
|
||||
T_WHILE,
|
||||
T_DO,
|
||||
T_STRUCT
|
||||
} Type;
|
||||
|
||||
#endif//TYPE_H
|
|
@ -0,0 +1,47 @@
|
|||
//
|
||||
// assert.h
|
||||
//
|
||||
|
||||
#ifndef __ASSERT_H
|
||||
#define __ASSERT_H
|
||||
|
||||
#ifndef _MFC_VER
|
||||
#ifdef _WIN32_WCE
|
||||
|
||||
#else//_WIN32_WCE
|
||||
#include <assert.h>
|
||||
#endif//_WIN32_WCE
|
||||
#endif
|
||||
|
||||
#ifndef ASSERT
|
||||
#ifdef _DEBUG
|
||||
#include <crtdbg.h>
|
||||
#include <stdio.h> // _snprintf
|
||||
//#ifndef WINVER
|
||||
#ifdef _CONSOLE
|
||||
#define ASSERT(x) if(!(x)){printf("ASSERT FAILURE: (%s) at %s:%i\n", #x, __FILE__, __LINE__); _CrtDbgBreak(); }
|
||||
#else//_CONSOLE/WINVER
|
||||
#define ASSERT(x) if(!(x)){char stmp_assert[1024+1]; _snprintf(stmp_assert,1024,"ASSERT FAILURE: (%s) at %s:%i\n",#x,__FILE__,__LINE__); ::MessageBox(NULL,stmp_assert,"Assertion Failure",MB_OK|MB_ICONSTOP); _CrtDbgBreak(); }
|
||||
#endif//_CONSOLE/WINVER
|
||||
#else//_DEBUG
|
||||
#define ASSERT(x)
|
||||
#endif//_DEBUG
|
||||
#endif//ASSERT
|
||||
|
||||
#undef VERIFY
|
||||
#ifdef _DEBUG
|
||||
#define VERIFY(x) ASSERT(x)
|
||||
#else//_DEBUG
|
||||
#define VERIFY(x) x
|
||||
#endif//_DEBUG
|
||||
|
||||
// code for ASSERTing in Release mode...
|
||||
#ifdef RELEASE_ASSERT
|
||||
#undef ASSERT
|
||||
#include <stdio.h>
|
||||
#define ASSERT(x) if ( !(x) ) { char s[1024+1]; _snprintf(s,1024,"ASSERTION FAILURE:\n%s\n\n%s: line %i", #x, __FILE__, __LINE__ ); ::MessageBox(NULL,s,"Assertion Failure",MB_OK|MB_ICONERROR); }
|
||||
#undef VERIFY
|
||||
#define VERIFY ASSERT
|
||||
#endif//RELEASE_ASSERT
|
||||
|
||||
#endif//__ASSERT_H
|
|
@ -0,0 +1,49 @@
|
|||
// binary2cstr.cpp
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning ( disable : 4786 )
|
||||
#endif//_MSC_VER
|
||||
|
||||
#include "binary2cstr.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
string binary2cstr ( const string& src )
|
||||
{
|
||||
string dst;
|
||||
for ( int i = 0; i < src.size(); i++ )
|
||||
{
|
||||
char c = src[i];
|
||||
switch ( c )
|
||||
{
|
||||
case '\n':
|
||||
dst += "\\n";
|
||||
break;
|
||||
case '\r':
|
||||
dst += "\\r";
|
||||
break;
|
||||
case '\t':
|
||||
dst += "\\t";
|
||||
break;
|
||||
case '\v':
|
||||
dst += "\\v";
|
||||
break;
|
||||
case '\"':
|
||||
dst += "\x22";
|
||||
break;
|
||||
default:
|
||||
if ( isprint ( c ) )
|
||||
dst += c;
|
||||
else
|
||||
{
|
||||
dst += "\\x";
|
||||
char tmp[16];
|
||||
_snprintf ( tmp, sizeof(tmp)-1, "%02X", (unsigned)(unsigned char)c );
|
||||
tmp[sizeof(tmp)-1] = '\0';
|
||||
dst += tmp;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
// binary2cstr.h
|
||||
|
||||
#ifndef BINARY2CSTR_H
|
||||
#define BINARY2CSTR_H
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string binary2cstr ( const std::string& src );
|
||||
|
||||
#endif//BINARY2CSTR_H
|
349
modules/rosapps/applications/sysutils/utils/sdkparse/input.lst
Normal file
349
modules/rosapps/applications/sysutils/utils/sdkparse/input.lst
Normal file
|
@ -0,0 +1,349 @@
|
|||
accctrl.h
|
||||
aclapi.h
|
||||
ascii.h
|
||||
base.h
|
||||
basetsd.h
|
||||
coff.h
|
||||
d3d.h
|
||||
d3dcaps.h
|
||||
d3dtypes.h
|
||||
ddentry.h
|
||||
ddraw.h
|
||||
debug.h
|
||||
defines.h
|
||||
devices.h
|
||||
epsapi.h
|
||||
errors.h
|
||||
excpt.h
|
||||
fmifs.h
|
||||
funcs.h
|
||||
getopt.h
|
||||
icmpapi.h
|
||||
ipexport.h
|
||||
iphlpapi.h
|
||||
ipifcons.h
|
||||
iprtrmib.h
|
||||
iptypes.h
|
||||
messages.h
|
||||
mmddk.h
|
||||
ndis.h
|
||||
ntddk.h
|
||||
ntos.h
|
||||
ntsecapi.h
|
||||
pe.h
|
||||
richedit.h
|
||||
roscfg.h
|
||||
roskrnl.h
|
||||
schemadef.h
|
||||
snmp.h
|
||||
sockets.h
|
||||
structs.h
|
||||
syssetup.h
|
||||
tchar.h
|
||||
tgetopt.h
|
||||
tmschema.h
|
||||
unicode.h
|
||||
uxtheme.h
|
||||
wdm.h
|
||||
wincrypt.h
|
||||
windows.h
|
||||
winsock2.h
|
||||
ws2spi.h
|
||||
wsahelp.h
|
||||
afd\shared.h
|
||||
csrss\csrss.h
|
||||
ddk\af_irda.h
|
||||
ddk\ccfuncs.h
|
||||
ddk\cctypes.h
|
||||
ddk\class2.h
|
||||
ddk\cmtypes.h
|
||||
ddk\d3dhal.h
|
||||
ddk\d3dnthal.h
|
||||
ddk\dbgfuncs.h
|
||||
ddk\ddrawi.h
|
||||
ddk\ddrawint.h
|
||||
ddk\defines.h
|
||||
ddk\exfuncs.h
|
||||
ddk\extypes.h
|
||||
ddk\fsfuncs.h
|
||||
ddk\fstypes.h
|
||||
ddk\halfuncs.h
|
||||
ddk\ioctrl.h
|
||||
ddk\iodef.h
|
||||
ddk\iofuncs.h
|
||||
ddk\iotypes.h
|
||||
ddk\kedef.h
|
||||
ddk\kefuncs.h
|
||||
ddk\ketypes.h
|
||||
ddk\ldrfuncs.h
|
||||
ddk\miniport.h
|
||||
ddk\mmfuncs.h
|
||||
ddk\mmtypes.h
|
||||
ddk\ntbootvid.h
|
||||
ddk\ntdd8042.h
|
||||
ddk\ntddbeep.h
|
||||
ddk\ntddblue.h
|
||||
ddk\ntddk.h
|
||||
ddk\ntddkbd.h
|
||||
ddk\ntddmou.h
|
||||
ddk\ntddscsi.h
|
||||
ddk\ntddser.h
|
||||
ddk\ntddvid.h
|
||||
ddk\ntdef.h
|
||||
ddk\ntifs.h
|
||||
ddk\obfuncs.h
|
||||
ddk\pnpfuncs.h
|
||||
ddk\pnptypes.h
|
||||
ddk\pofuncs.h
|
||||
ddk\potypes.h
|
||||
ddk\psfuncs.h
|
||||
ddk\pstypes.h
|
||||
ddk\scsi.h
|
||||
ddk\sefuncs.h
|
||||
ddk\setypes.h
|
||||
ddk\srb.h
|
||||
ddk\status.h
|
||||
ddk\structs.h
|
||||
ddk\types.h
|
||||
ddk\winddi.h
|
||||
ddk\i386\irql.h
|
||||
ddk\i386\pagesize.h
|
||||
dflat32\classdef.h
|
||||
dflat32\classes.h
|
||||
dflat32\commands.h
|
||||
dflat32\config.h
|
||||
dflat32\dflat.h
|
||||
dflat32\dflatmsg.h
|
||||
dflat32\dialbox.h
|
||||
dflat32\htree.h
|
||||
dflat32\keys.h
|
||||
dflat32\menu.h
|
||||
dflat32\rect.h
|
||||
dflat32\system.h
|
||||
dflat32\video.h
|
||||
fslib\vfatlib.h
|
||||
kernel32\cptable.h
|
||||
kernel32\error.h
|
||||
kernel32\heap.h
|
||||
kernel32\kernel32.h
|
||||
kernel32\lctable.h
|
||||
kernel32\nls.h
|
||||
kernel32\proc.h
|
||||
kernel32\process.h
|
||||
kernel32\thread.h
|
||||
kernel32\winnls.h
|
||||
libc\atexit.h
|
||||
libc\file.h
|
||||
libc\ieee.h
|
||||
lsass\lsass.h
|
||||
lsass\ntsecapi.h
|
||||
msvcrt\alloc.h
|
||||
msvcrt\assert.h
|
||||
msvcrt\conio.h
|
||||
msvcrt\crttypes.h
|
||||
msvcrt\ctype.h
|
||||
msvcrt\dir.h
|
||||
msvcrt\direct.h
|
||||
msvcrt\errno.h
|
||||
msvcrt\fcntl.h
|
||||
msvcrt\float.h
|
||||
msvcrt\io.h
|
||||
msvcrt\locale.h
|
||||
msvcrt\malloc.h
|
||||
msvcrt\math.h
|
||||
msvcrt\mbctype.h
|
||||
msvcrt\mbstring.h
|
||||
msvcrt\msvcrtdbg.h
|
||||
msvcrt\process.h
|
||||
msvcrt\search.h
|
||||
msvcrt\share.h
|
||||
msvcrt\signal.h
|
||||
msvcrt\stdarg.h
|
||||
msvcrt\stddef.h
|
||||
msvcrt\stdio.h
|
||||
msvcrt\stdlib.h
|
||||
msvcrt\string.h
|
||||
msvcrt\time.h
|
||||
msvcrt\wchar.h
|
||||
msvcrt\internal\atexit.h
|
||||
msvcrt\internal\console.h
|
||||
msvcrt\internal\file.h
|
||||
msvcrt\internal\ieee.h
|
||||
msvcrt\internal\rterror.h
|
||||
msvcrt\internal\stdio.h
|
||||
msvcrt\internal\tls.h
|
||||
msvcrt\sys\fcntl.h
|
||||
msvcrt\sys\file.h
|
||||
msvcrt\sys\locking.h
|
||||
msvcrt\sys\stat.h
|
||||
msvcrt\sys\time.h
|
||||
msvcrt\sys\timeb.h
|
||||
msvcrt\sys\types.h
|
||||
msvcrt\sys\unistd.h
|
||||
msvcrt\sys\utime.h
|
||||
napi\core.h
|
||||
napi\dbg.h
|
||||
napi\lpc.h
|
||||
napi\npipe.h
|
||||
napi\shared_data.h
|
||||
napi\teb.h
|
||||
napi\types.h
|
||||
napi\win32.h
|
||||
napi\i386\floatsave.h
|
||||
napi\i386\segment.h
|
||||
net\miniport.h
|
||||
net\ndis.h
|
||||
net\ndisoid.h
|
||||
net\netevent.h
|
||||
net\netpnp.h
|
||||
net\ntddndis.h
|
||||
net\ntddtdi.h
|
||||
net\tdi.h
|
||||
net\tdiinfo.h
|
||||
net\tdikrnl.h
|
||||
net\tdistat.h
|
||||
ntdll\base.h
|
||||
ntdll\csr.h
|
||||
ntdll\dbg.h
|
||||
ntdll\ldr.h
|
||||
ntdll\napi.h
|
||||
ntdll\ntdll.h
|
||||
ntdll\pagesize.h
|
||||
ntdll\rtl.h
|
||||
ntdll\trace.h
|
||||
ntos\bootvid.h
|
||||
ntos\cdrom.h
|
||||
ntos\console.h
|
||||
ntos\dbgfuncs.h
|
||||
ntos\disk.h
|
||||
ntos\except.h
|
||||
ntos\file.h
|
||||
ntos\fstypes.h
|
||||
ntos\gditypes.h
|
||||
ntos\halfuncs.h
|
||||
ntos\haltypes.h
|
||||
ntos\heap.h
|
||||
ntos\kdbgsyms.h
|
||||
ntos\kdfuncs.h
|
||||
ntos\kefuncs.h
|
||||
ntos\keyboard.h
|
||||
ntos\ldrtypes.h
|
||||
ntos\minmax.h
|
||||
ntos\mm.h
|
||||
ntos\ntdef.h
|
||||
ntos\obtypes.h
|
||||
ntos\port.h
|
||||
ntos\ps.h
|
||||
ntos\registry.h
|
||||
ntos\rtl.h
|
||||
ntos\rtltypes.h
|
||||
ntos\security.h
|
||||
ntos\service.h
|
||||
ntos\synch.h
|
||||
ntos\time.h
|
||||
ntos\tss.h
|
||||
ntos\types.h
|
||||
ntos\zw.h
|
||||
ntos\zwtypes.h
|
||||
ole32\basetyps.h
|
||||
ole32\guiddef.h
|
||||
ole32\objbase.h
|
||||
ole32\obj_base.h
|
||||
ole32\obj_cache.h
|
||||
ole32\obj_channel.h
|
||||
ole32\obj_clientserver.h
|
||||
ole32\obj_commdlgbrowser.h
|
||||
ole32\obj_connection.h
|
||||
ole32\obj_contextmenu.h
|
||||
ole32\obj_control.h
|
||||
ole32\obj_dataobject.h
|
||||
ole32\obj_dockingwindowframe.h
|
||||
ole32\obj_dragdrop.h
|
||||
ole32\obj_enumidlist.h
|
||||
ole32\obj_errorinfo.h
|
||||
ole32\obj_extracticon.h
|
||||
ole32\obj_inplace.h
|
||||
ole32\obj_marshal.h
|
||||
ole32\obj_misc.h
|
||||
ole32\obj_moniker.h
|
||||
ole32\obj_oleaut.h
|
||||
ole32\obj_olefont.h
|
||||
ole32\obj_oleobj.h
|
||||
ole32\obj_oleundo.h
|
||||
ole32\obj_oleview.h
|
||||
ole32\obj_picture.h
|
||||
ole32\obj_property.h
|
||||
ole32\obj_propertystorage.h
|
||||
ole32\obj_queryassociations.h
|
||||
ole32\obj_serviceprovider.h
|
||||
ole32\obj_shellbrowser.h
|
||||
ole32\obj_shellextinit.h
|
||||
ole32\obj_shellfolder.h
|
||||
ole32\obj_shelllink.h
|
||||
ole32\obj_shellview.h
|
||||
ole32\obj_storage.h
|
||||
ole32\obj_webbrowser.h
|
||||
ole32\ole32.h
|
||||
ole32\olectl.h
|
||||
ole32\rpc.h
|
||||
ole32\rpcdce.h
|
||||
ole32\rpcdcep.h
|
||||
ole32\unknwn.h
|
||||
ole32\winerror.h
|
||||
ole32\wtypes.h
|
||||
reactos\bugcodes.h
|
||||
reactos\buildno.h
|
||||
reactos\config.h
|
||||
reactos\errcodes.h
|
||||
reactos\resource.h
|
||||
reactos\version.h
|
||||
rosrtl\devmode.h
|
||||
rosrtl\logfont.h
|
||||
rosrtl\thread.h
|
||||
services\services.h
|
||||
user32\accel.h
|
||||
user32\callback.h
|
||||
user32\regcontrol.h
|
||||
user32\wininternal.h
|
||||
win32k\bitmaps.h
|
||||
win32k\brush.h
|
||||
win32k\cliprgn.h
|
||||
win32k\color.h
|
||||
win32k\coord.h
|
||||
win32k\cursoricon.h
|
||||
win32k\dc.h
|
||||
win32k\debug.h
|
||||
win32k\debug1.h
|
||||
win32k\driver.h
|
||||
win32k\fillshap.h
|
||||
win32k\float.h
|
||||
win32k\gdiobj.h
|
||||
win32k\icm.h
|
||||
win32k\kapi.h
|
||||
win32k\line.h
|
||||
win32k\math.h
|
||||
win32k\metafile.h
|
||||
win32k\misc.h
|
||||
win32k\ntddraw.h
|
||||
win32k\ntuser.h
|
||||
win32k\paint.h
|
||||
win32k\path.h
|
||||
win32k\pen.h
|
||||
win32k\print.h
|
||||
win32k\region.h
|
||||
win32k\text.h
|
||||
win32k\userobj.h
|
||||
win32k\win32k.h
|
||||
win32k\wingl.h
|
||||
wine\commctrl.h
|
||||
wine\config.h
|
||||
wine\debug.h
|
||||
wine\debugtools.h
|
||||
wine\port.h
|
||||
wine\prsht.h
|
||||
wine\test.h
|
||||
wine\unicode.h
|
||||
wine\vfw.h
|
||||
wine\windef16.h
|
||||
wine\wineros.h
|
||||
wine\winuser.h
|
|
@ -0,0 +1,138 @@
|
|||
// iskeyword.cpp
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning ( disable : 4786 )
|
||||
#endif//_MSC_VER
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "iskeyword.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
bool iskeyword ( const string& ident )
|
||||
{
|
||||
#define I(s) if ( ident == #s ) return true;
|
||||
switch ( ident[0] )
|
||||
{
|
||||
case '_':
|
||||
I(__cdecl);
|
||||
I(__declspec);
|
||||
I(__except);
|
||||
I(__fastcall);
|
||||
I(__finally);
|
||||
I(__inline);
|
||||
I(__int8);
|
||||
I(__int16);
|
||||
I(__int32);
|
||||
I(__int64);
|
||||
I(__leave);
|
||||
I(__stdcall);
|
||||
I(__try);
|
||||
break;
|
||||
case 'b':
|
||||
I(bool);
|
||||
I(break);
|
||||
break;
|
||||
case 'c':
|
||||
I(case);
|
||||
I(catch);
|
||||
I(char);
|
||||
I(class);
|
||||
I(const);
|
||||
I(const_cast);
|
||||
I(continue);
|
||||
break;
|
||||
case 'd':
|
||||
I(default);
|
||||
I(delete);
|
||||
I(dllexport);
|
||||
I(dllimport);
|
||||
I(do);
|
||||
I(double);
|
||||
I(dynamic_cast);
|
||||
break;
|
||||
case 'e':
|
||||
I(else);
|
||||
I(enum);
|
||||
I(explicit);
|
||||
I(extern);
|
||||
break;
|
||||
case 'f':
|
||||
I(false);
|
||||
I(float);
|
||||
I(for);
|
||||
I(friend);
|
||||
break;
|
||||
case 'g':
|
||||
I(goto);
|
||||
break;
|
||||
case 'i':
|
||||
I(if);
|
||||
I(inline);
|
||||
I(int);
|
||||
break;
|
||||
case 'l':
|
||||
I(long);
|
||||
break;
|
||||
case 'm':
|
||||
I(mutable);
|
||||
break;
|
||||
case 'n':
|
||||
I(naked);
|
||||
I(namespace);
|
||||
I(new);
|
||||
I(noreturn);
|
||||
break;
|
||||
case 'o':
|
||||
I(operator);
|
||||
break;
|
||||
case 'p':
|
||||
I(private);
|
||||
I(protected);
|
||||
I(public);
|
||||
break;
|
||||
case 'r':
|
||||
I(register);
|
||||
I(reinterpret_cast);
|
||||
I(return);
|
||||
break;
|
||||
case 's':
|
||||
I(short);
|
||||
I(signed);
|
||||
I(sizeof);
|
||||
I(static);
|
||||
I(static_cast);
|
||||
I(struct);
|
||||
I(switch);
|
||||
break;
|
||||
case 't':
|
||||
I(template);
|
||||
I(this);
|
||||
I(thread);
|
||||
I(throw);
|
||||
I(true);
|
||||
I(try);
|
||||
I(typedef);
|
||||
I(typeid);
|
||||
I(typename);
|
||||
break;
|
||||
case 'u':
|
||||
I(union);
|
||||
I(unsigned);
|
||||
I(using);
|
||||
I(uuid);
|
||||
I(__uuidof);
|
||||
break;
|
||||
case 'v':
|
||||
I(virtual);
|
||||
I(void);
|
||||
I(volatile);
|
||||
break;
|
||||
case 'w':
|
||||
I(wmain);
|
||||
I(while);
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
// iskeyword.h
|
||||
|
||||
#ifndef ISKEYWORD_H
|
||||
#define ISKEYWORD_H
|
||||
|
||||
bool iskeyword ( const std::string& ident );
|
||||
|
||||
#endif//ISKEYWORD_H
|
|
@ -0,0 +1,61 @@
|
|||
//
|
||||
// safestr.h
|
||||
//
|
||||
// safe versions of some string manipulation routines
|
||||
//
|
||||
|
||||
#ifndef __SAFESTR_H
|
||||
#define __SAFESTR_H
|
||||
|
||||
#include <tchar.h>
|
||||
|
||||
#ifndef tchar
|
||||
#define tchar TCHAR
|
||||
#endif//tchar
|
||||
|
||||
#include <string.h>
|
||||
#include "assert.h"
|
||||
|
||||
inline size_t safestrlen ( const tchar *string )
|
||||
{
|
||||
if ( !string )
|
||||
return 0;
|
||||
return _tcslen(string);
|
||||
}
|
||||
|
||||
inline tchar* safestrcpy ( tchar* strDest, const tchar* strSource )
|
||||
{
|
||||
ASSERT(strDest);
|
||||
if ( !strSource )
|
||||
*strDest = 0;
|
||||
else
|
||||
_tcscpy ( strDest, strSource );
|
||||
return strDest;
|
||||
}
|
||||
|
||||
inline tchar* safestrncpy ( tchar* strDest, const tchar* strSource, size_t count )
|
||||
{
|
||||
ASSERT(strDest);
|
||||
if ( !strSource )
|
||||
count = 0;
|
||||
else
|
||||
_tcsncpy ( strDest, strSource, count );
|
||||
strDest[count] = 0;
|
||||
return strDest;
|
||||
}
|
||||
|
||||
inline tchar* safestrlwr ( tchar* str )
|
||||
{
|
||||
if ( !str )
|
||||
return 0;
|
||||
return _tcslwr(str);
|
||||
}
|
||||
|
||||
inline tchar* safestrupr ( tchar* str )
|
||||
{
|
||||
if ( !str )
|
||||
return 0;
|
||||
return _tcsupr(str);
|
||||
}
|
||||
|
||||
#endif//__SAFESTR_H
|
|
@ -0,0 +1,988 @@
|
|||
// sdkparse.cpp
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning ( disable : 4786 )
|
||||
#endif//_MSC_VER
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <conio.h>
|
||||
|
||||
#include "EnumFilesImpl.h"
|
||||
|
||||
#include "assert.h"
|
||||
#include "File.h"
|
||||
#include "binary2cstr.h"
|
||||
#include "strip_comments.h"
|
||||
#include "tokenize.h"
|
||||
#include "skip_ws.h"
|
||||
#include "iskeyword.h"
|
||||
#include "Type.h"
|
||||
#include "Header.h"
|
||||
|
||||
#define TOKASSERT(x) \
|
||||
if(!(x))\
|
||||
{\
|
||||
printf("ASSERT FAILURE: (%s) at %s:%i\n", #x, __FILE__, __LINE__);\
|
||||
printf("WHILE PROCESSING: \n");\
|
||||
for ( int ajf83pfj = 0; ajf83pfj < tokens.size(); ajf83pfj++ )\
|
||||
printf("%s ", tokens[ajf83pfj].c_str() );\
|
||||
printf("\n");\
|
||||
_CrtDbgBreak();\
|
||||
}
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
vector<Header*> headers;
|
||||
|
||||
bool import_file ( const char* filename );
|
||||
char* findend ( char* p, bool& externc );
|
||||
Type identify ( const vector<string>& tokens, int off = 0 );
|
||||
Type process ( const string& element, vector<string>& names, bool& isTypedef, vector<string>& dependencies );
|
||||
void process_preprocessor ( const char* filename, Header& h, const string& element );
|
||||
void process_c ( Header& h, const string& element );
|
||||
int parse_type ( Type t, const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
||||
int parse_ignored_statement ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
||||
int parse_tident ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
||||
int parse_variable ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
||||
int parse_struct ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
||||
int parse_function ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
||||
int parse_function_ptr ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
||||
int parse_ifwhile ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
||||
int parse_do ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies );
|
||||
|
||||
const char* libc_includes[] =
|
||||
{
|
||||
"basestd.h",
|
||||
"except.h",
|
||||
"float.h",
|
||||
"limits.h",
|
||||
"stdarg.h",
|
||||
"stddef.h",
|
||||
"stdlib.h",
|
||||
"string.h",
|
||||
"types.h"
|
||||
};
|
||||
|
||||
bool is_libc_include ( const string& inc )
|
||||
{
|
||||
string s ( inc );
|
||||
strlwr ( &s[0] );
|
||||
for ( int i = 0; i < sizeof(libc_includes)/sizeof(libc_includes[0]); i++ )
|
||||
{
|
||||
if ( s == libc_includes[i] )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
BOOL FileEnumProc ( PWIN32_FIND_DATA pwfd, const char* filename, long lParam )
|
||||
{
|
||||
if ( !is_libc_include ( filename ) )
|
||||
import_file ( filename );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
//import_file ( "coff.h" );
|
||||
|
||||
File f ( "input.lst", "r" );
|
||||
if ( !f.isopened() )
|
||||
{
|
||||
printf ( "Couldn't open \"input.lst\" for input\nPress any key to exit\n" );
|
||||
(void)getch();
|
||||
return;
|
||||
}
|
||||
string filename;
|
||||
while ( f.next_line ( filename, true ) )
|
||||
import_file ( filename.c_str() );
|
||||
//printf ( "press any key to start\n" );
|
||||
//getch();
|
||||
/*#if 1
|
||||
import_file ( "../test.h" );
|
||||
#else
|
||||
EnumFilesInDirectory ( "c:/cvs/reactos/apps/utils/sdkparse/include", "*.h", FileEnumProc, 0, TRUE, FALSE );
|
||||
#endif*/
|
||||
printf ( "Done!\nPress any key to exit!\n" );
|
||||
(void)getch();
|
||||
}
|
||||
|
||||
bool import_file ( const char* filename )
|
||||
{
|
||||
int i;
|
||||
|
||||
for ( i = 0; i < headers.size(); i++ )
|
||||
{
|
||||
if ( headers[i]->filename == filename )
|
||||
return true;
|
||||
}
|
||||
|
||||
string s;
|
||||
if ( !File::LoadIntoString ( s, filename ) )
|
||||
{
|
||||
printf ( "Couldn't load \"%s\" for input.\n", filename );
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
printf ( "%s\n", filename );
|
||||
|
||||
// strip comments from the file...
|
||||
strip_comments ( s, true );
|
||||
|
||||
/*{
|
||||
string no_comments ( filename );
|
||||
no_comments += ".nocom.txt";
|
||||
File::SaveFromString ( no_comments.c_str(), s, false );
|
||||
}*/
|
||||
|
||||
Header* h = new Header ( filename );
|
||||
headers.push_back ( h );
|
||||
|
||||
char* p = &s[0];
|
||||
while ( p )
|
||||
{
|
||||
// skip whitespace
|
||||
p = skip_ws ( p );
|
||||
if ( !*p )
|
||||
break;
|
||||
// check for pre-processor command
|
||||
if ( *p == '#' )
|
||||
{
|
||||
char* end = strchr ( p, '\n' );
|
||||
while ( end && end[-1] == '\\' )
|
||||
end = strchr ( end+1, '\n' );
|
||||
if ( !end )
|
||||
end = p + strlen(p);
|
||||
string element ( p, end-p );
|
||||
|
||||
process_preprocessor ( filename, *h, element );
|
||||
|
||||
p = end;
|
||||
}
|
||||
else if ( *p == '}' && h->externc )
|
||||
{
|
||||
p++;
|
||||
p = skip_ws ( p );
|
||||
|
||||
if ( *p == ';' ) p++;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool externc = false;
|
||||
char* end = findend ( p, externc );
|
||||
ASSERT(end);
|
||||
if ( externc )
|
||||
h->externc = true;
|
||||
else
|
||||
{
|
||||
string element ( p, end-p );
|
||||
|
||||
process_c ( *h, element );
|
||||
}
|
||||
p = end;
|
||||
}
|
||||
}
|
||||
h->done = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
string get_hdrguardtext ( const char* filename )
|
||||
{
|
||||
string s ( filename );
|
||||
char* p = &s[0];
|
||||
char* p2;
|
||||
while ( (p2 = strchr(p, '\\')) )
|
||||
*p2 = '/';
|
||||
while ( (p2 = strchr(p,'/')) )
|
||||
p = p2 + 1;
|
||||
char* end = strchr ( p, '.' );
|
||||
ASSERT(end);
|
||||
while ( (p2 = strchr(end+1,'.')) )
|
||||
end = p2;
|
||||
string hdrguardtext ( p, end-p );
|
||||
strupr ( &hdrguardtext[0] );
|
||||
return hdrguardtext;
|
||||
}
|
||||
|
||||
void process_preprocessor ( const char* filename, Header& h, const string& element )
|
||||
{
|
||||
string hdrguardtext ( get_hdrguardtext ( filename ) );
|
||||
|
||||
const char* p = &element[0];
|
||||
ASSERT ( *p == '#' );
|
||||
p++;
|
||||
p = skip_ws ( p );
|
||||
const char* end = p;
|
||||
while ( iscsym(*end) )
|
||||
end++;
|
||||
string preproc ( p, end-p );
|
||||
p = end+1;
|
||||
p = skip_ws ( p );
|
||||
|
||||
const string dbg_filename = "napi/lpc.h DISABLE DISABLE DISABLE";
|
||||
|
||||
if ( preproc == "include" )
|
||||
{
|
||||
//if ( h.filename == "napi/lpc.h" )
|
||||
// _CrtDbgBreak();
|
||||
ASSERT ( *p == '<' || *p == '\"' );
|
||||
p++;
|
||||
p = skip_ws ( p );
|
||||
const char* end = strpbrk ( p, ">\"" );
|
||||
if ( !end )
|
||||
end = p + strlen(p);
|
||||
while ( end > p && isspace(end[-1]) )
|
||||
end--;
|
||||
string include_filename ( p, end-p );
|
||||
if ( is_libc_include ( include_filename ) )
|
||||
h.libc_includes.push_back ( include_filename );
|
||||
else
|
||||
{
|
||||
bool loaded = false;
|
||||
for ( int i = 0; i < headers.size() && !loaded; i++ )
|
||||
{
|
||||
if ( headers[i]->filename == include_filename )
|
||||
{
|
||||
if ( !headers[i]->done )
|
||||
{
|
||||
printf ( "circular dependency between '%s' and '%s'\n", filename, include_filename.c_str() );
|
||||
ASSERT ( 0 );
|
||||
}
|
||||
loaded = true;
|
||||
}
|
||||
}
|
||||
if ( !loaded )
|
||||
{
|
||||
printf ( "(diverting to '%s')\n", include_filename.c_str() );
|
||||
import_file ( include_filename.c_str() );
|
||||
printf ( "(now back to '%s')\n", filename );
|
||||
}
|
||||
h.includes.push_back ( include_filename );
|
||||
}
|
||||
}
|
||||
else if ( preproc == "define" )
|
||||
{
|
||||
size_t len = element.size();
|
||||
if ( strstr ( element.c_str(), hdrguardtext.c_str() )
|
||||
&& element[len-2] == '_'
|
||||
&& element[len-1] == 'H' )
|
||||
{
|
||||
// header include guard... ignore!
|
||||
return;
|
||||
}
|
||||
Symbol *s = new Symbol;
|
||||
s->type = T_DEFINE;
|
||||
|
||||
p += 6;
|
||||
p = skip_ws ( p );
|
||||
|
||||
const char* end = p;
|
||||
while ( iscsym(*end) )
|
||||
end++;
|
||||
|
||||
s->names.push_back ( string(p,end-p) );
|
||||
|
||||
s->definition = element;
|
||||
|
||||
h.symbols.push_back ( s );
|
||||
}
|
||||
else if ( preproc == "undef" )
|
||||
{
|
||||
// safely ignoreable for now, I think
|
||||
}
|
||||
else if ( preproc == "if" || preproc == "ifdef" || preproc == "ifndef" )
|
||||
{
|
||||
if ( dbg_filename == h.filename )
|
||||
printf ( "(%s) PRE-PUSH preproc stack = %lu\n", preproc.c_str(), h.ifs.size() );
|
||||
size_t len = element.size();
|
||||
// check for header include guard...
|
||||
if ( strstr ( element.c_str(), hdrguardtext.c_str() )
|
||||
&& element[len-2] == '_'
|
||||
&& element[len-1] == 'H' )
|
||||
h.ifs.push_back ( string("") );
|
||||
else
|
||||
h.ifs.push_back ( element );
|
||||
h.ifspreproc.push_back ( preproc );
|
||||
if ( dbg_filename == h.filename )
|
||||
printf ( "POST-PUSH preproc stack = %lu\n", h.ifs.size() );
|
||||
}
|
||||
else if ( preproc == "endif" )
|
||||
{
|
||||
if ( dbg_filename == h.filename )
|
||||
printf ( "(%s) PRE-POP preproc stack = %lu\n", preproc.c_str(), h.ifs.size() );
|
||||
ASSERT ( h.ifs.size() > 0 && h.ifs.size() == h.ifspreproc.size() );
|
||||
h.ifs.pop_back();
|
||||
h.ifspreproc.pop_back();
|
||||
if ( dbg_filename == h.filename )
|
||||
printf ( "POST-POP preproc stack = %lu\n", h.ifs.size() );
|
||||
}
|
||||
else if ( preproc == "elif" )
|
||||
{
|
||||
if ( dbg_filename == h.filename )
|
||||
printf ( "(%s) PRE-PUSHPOP preproc stack = %lu\n", preproc.c_str(), h.ifs.size() );
|
||||
string& oldpre = h.ifspreproc.back();
|
||||
string old = h.ifs.back();
|
||||
string condold;
|
||||
if ( oldpre == "ifdef" )
|
||||
condold = string("!defined(") + old + ")";
|
||||
else if ( oldpre == "ifndef" )
|
||||
condold = string("defined(") + old + ")";
|
||||
else if ( oldpre == "if" )
|
||||
condold = string("!(") + old + ")";
|
||||
else
|
||||
{
|
||||
printf ( "unrecognized preproc '%s'\n", oldpre.c_str() );
|
||||
ASSERT(0);
|
||||
return;
|
||||
}
|
||||
h.ifs.back() = string("(") + element + ") && " + condold;
|
||||
h.ifspreproc.back() = "if";
|
||||
if ( dbg_filename == h.filename )
|
||||
printf ( "POST-PUSHPOP preproc stack = %lu\n", h.ifs.size() );
|
||||
}
|
||||
else if ( preproc == "else" )
|
||||
{
|
||||
if ( dbg_filename == h.filename )
|
||||
printf ( "(%s) PRE-PUSHPOP preproc stack = %lu\n", preproc.c_str(), h.ifs.size() );
|
||||
string& oldpre = h.ifspreproc.back();
|
||||
ASSERT ( oldpre != "else" );
|
||||
if ( oldpre == "ifdef" )
|
||||
h.ifs.back() = "ifndef";
|
||||
else if ( oldpre == "ifndef" )
|
||||
h.ifs.back() = "ifdef";
|
||||
else if ( oldpre == "if" )
|
||||
h.ifs.back() = string("!(") + h.ifs.back() + ")";
|
||||
else
|
||||
{
|
||||
printf ( "unrecognized preproc '%s'\n", oldpre.c_str() );
|
||||
ASSERT(0);
|
||||
return;
|
||||
}
|
||||
oldpre = "else";
|
||||
if ( dbg_filename == h.filename )
|
||||
printf ( "POST-PUSHPOP preproc stack = %lu\n", h.ifs.size() );
|
||||
}
|
||||
else if ( preproc == "include_next" )
|
||||
{
|
||||
// we can safely ignore this command...
|
||||
}
|
||||
else if ( preproc == "pragma" )
|
||||
{
|
||||
h.pragmas.push_back ( element );
|
||||
}
|
||||
else if ( preproc == "error" )
|
||||
{
|
||||
// FIXME - how to handle these
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ( "process_preprocessor() choked on '%s'\n", preproc.c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
void process_c ( Header& h, const string& element )
|
||||
{
|
||||
//printf ( "\"%s\"\n\n", binary2cstr(element).c_str() );
|
||||
|
||||
bool isTypedef;
|
||||
|
||||
Symbol *s = new Symbol;
|
||||
s->definition = element;
|
||||
s->type = process ( element, s->names, isTypedef, s->dependencies );
|
||||
|
||||
for ( int i = 0; i < h.ifs.size(); i++ )
|
||||
{
|
||||
if ( h.ifs[i].size() )
|
||||
s->ifs.push_back ( h.ifs[i] );
|
||||
}
|
||||
|
||||
/*printf ( "names: " );
|
||||
if ( s->names.size() )
|
||||
{
|
||||
printf ( "%s", s->names[0].c_str() );
|
||||
for ( int i = 1; i < s->names.size(); i++ )
|
||||
printf ( ", %s", s->names[i].c_str() );
|
||||
}
|
||||
else
|
||||
printf ( "(none)" );
|
||||
printf ( "\n\n" );
|
||||
|
||||
printf ( "dependencies: " );
|
||||
if ( s->dependencies.size() )
|
||||
{
|
||||
printf ( "%s", s->dependencies[0].c_str() );
|
||||
for ( int i = 1; i < s->dependencies.size(); i++ )
|
||||
printf ( ", %s", s->dependencies[i].c_str() );
|
||||
}
|
||||
else
|
||||
printf ( "(none)" );
|
||||
printf ( "\n\n" );*/
|
||||
|
||||
h.symbols.push_back ( s );
|
||||
}
|
||||
|
||||
char* skipsemi ( char* p )
|
||||
{
|
||||
if ( *p != '{' ) // }
|
||||
{
|
||||
ASSERT(0);
|
||||
}
|
||||
p++;
|
||||
for ( ;; )
|
||||
{
|
||||
char* s = strchr ( p, '{' );
|
||||
char* e = strchr ( p, '}' );
|
||||
if ( !e )
|
||||
e = p + strlen(p);
|
||||
if ( !s || s > e )
|
||||
{
|
||||
// make sure we don't return pointer past null
|
||||
if ( *e )
|
||||
return e + 1;
|
||||
else
|
||||
return e;
|
||||
}
|
||||
p = skipsemi ( s );
|
||||
}
|
||||
}
|
||||
|
||||
char* findend ( char* p, bool& externc )
|
||||
{
|
||||
//if ( !strncmp ( p, "typedef struct _OSVERSIONINFOEXA : ", 35 ) )
|
||||
// _CrtDbgBreak();
|
||||
// special-case for 'extern "C"'
|
||||
if ( !strncmp ( p, "extern", 6 ) )
|
||||
{
|
||||
char* p2 = p + 6;
|
||||
p2 = skip_ws ( p2 );
|
||||
if ( !strncmp ( p2, "\"C\"", 3 ) )
|
||||
{
|
||||
p2 += 3;
|
||||
p2 = skip_ws ( p2 );
|
||||
if ( *p2 == '{' )
|
||||
{
|
||||
externc = true;
|
||||
return p2+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// special-case for 'typedef_tident'
|
||||
if ( !strncmp ( p, "typedef_tident", 14 ) )
|
||||
{
|
||||
char* end = strchr ( p, ')' );
|
||||
ASSERT(end);
|
||||
return end+1;
|
||||
}
|
||||
externc = false;
|
||||
bool isStruct = false;
|
||||
|
||||
char* end = strchr ( p, ';' );
|
||||
if ( !end )
|
||||
end = p + strlen(p);
|
||||
else
|
||||
end++;
|
||||
char* semi = strchr ( p, '{' );
|
||||
if ( !semi || semi > end )
|
||||
return end;
|
||||
end = skipsemi ( semi );
|
||||
|
||||
const char* structs[] = { "struct", "enum", "class", "union" };
|
||||
for ( int i = 0; i < sizeof(structs)/sizeof(structs[0]); i++ )
|
||||
{
|
||||
char* pStruct = strstr ( p, structs[i] );
|
||||
if ( pStruct
|
||||
&& pStruct < semi
|
||||
&& !__iscsym(pStruct[-1])
|
||||
&& !__iscsym(pStruct[strlen(structs[i])]) )
|
||||
{
|
||||
// make sure there's at most one identifier followed
|
||||
// by a {
|
||||
pStruct += strlen(structs[i]);
|
||||
pStruct = skip_ws ( pStruct );
|
||||
if ( __iscsymf(*pStruct) )
|
||||
{
|
||||
while ( __iscsym(*pStruct) )
|
||||
pStruct++;
|
||||
pStruct = skip_ws ( pStruct );
|
||||
}
|
||||
// special exception - C++ classes & stuff
|
||||
if ( *pStruct == ':' )
|
||||
{
|
||||
pStruct = skip_ws ( pStruct + 1 );
|
||||
ASSERT ( !strncmp(pStruct,"public",6) || !strncmp(pStruct,"protected",9) || !strncmp(pStruct,"private",7) );
|
||||
// skip access:
|
||||
while ( __iscsym(*pStruct) )
|
||||
pStruct++;
|
||||
pStruct = skip_ws ( pStruct );
|
||||
// skip base-class-name:
|
||||
ASSERT ( __iscsymf(*pStruct) );
|
||||
while ( __iscsym(*pStruct) )
|
||||
pStruct++;
|
||||
pStruct = skip_ws ( pStruct );
|
||||
}
|
||||
if ( *pStruct == '{' )
|
||||
isStruct = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( isStruct )
|
||||
{
|
||||
end = strchr ( end, ';' );
|
||||
if ( !end )
|
||||
end = p + strlen(p);
|
||||
else
|
||||
end++;
|
||||
}
|
||||
else
|
||||
{
|
||||
char* p2 = skip_ws ( end );
|
||||
if ( *p2 == ';' )
|
||||
end = p2 + 1;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
|
||||
int skip_declspec ( const vector<string>& tokens, int off )
|
||||
{
|
||||
if ( tokens[off] == "__declspec" )
|
||||
{
|
||||
off++;
|
||||
TOKASSERT ( tokens[off] == "(" );
|
||||
off++;
|
||||
int parens = 1;
|
||||
while ( parens )
|
||||
{
|
||||
if ( tokens[off] == "(" )
|
||||
parens++;
|
||||
else if ( tokens[off] == ")" )
|
||||
parens--;
|
||||
off++;
|
||||
}
|
||||
}
|
||||
return off;
|
||||
}
|
||||
|
||||
Type identify ( const vector<string>& tokens, int off )
|
||||
{
|
||||
off = skip_declspec ( tokens, off );
|
||||
/*if ( tokens.size() > off+4 )
|
||||
{
|
||||
if ( tokens[off+4] == "PCONTROLDISPATCHER" )
|
||||
_CrtDbgBreak();
|
||||
}*/
|
||||
/*if ( tokens.size() > off+1 )
|
||||
{
|
||||
if ( tokens[off+1] == "_OSVERSIONINFOEXA" )
|
||||
_CrtDbgBreak();
|
||||
}*/
|
||||
if ( tokens[off] == "__asm__" )
|
||||
return T_IGNORED_STATEMENT;
|
||||
else if ( tokens[off] == "return" )
|
||||
return T_IGNORED_STATEMENT;
|
||||
else if ( tokens[off] == "typedef_tident" )
|
||||
return T_TIDENT;
|
||||
else if ( tokens[off] == "if" )
|
||||
return T_IF;
|
||||
else if ( tokens[off] == "while" )
|
||||
return T_WHILE;
|
||||
else if ( tokens[off] == "do" )
|
||||
return T_DO;
|
||||
int openparens = 0;
|
||||
int closeparens = 0;
|
||||
int brackets = 0;
|
||||
for ( int i = off; i < tokens.size(); i++ )
|
||||
{
|
||||
if ( tokens[i] == "(" && !brackets )
|
||||
openparens++;
|
||||
else if ( tokens[i] == ")" && !brackets && openparens == 1 )
|
||||
closeparens++;
|
||||
else if ( tokens[i] == "{" )
|
||||
brackets++;
|
||||
else if ( (tokens[i] == "struct" || tokens[i] == "union") && !openparens )
|
||||
{
|
||||
for ( int j = i + 1; j < tokens.size(); j++ )
|
||||
{
|
||||
if ( tokens[j] == "{" )
|
||||
return T_STRUCT;
|
||||
else if ( tokens[j] == "(" || tokens[j] == ";" || tokens[j] == "*" )
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if ( tokens[i] == ";" )
|
||||
break;
|
||||
else if ( tokens[i] == "__attribute__" )
|
||||
break;
|
||||
}
|
||||
if ( openparens > 1 && closeparens )
|
||||
return T_FUNCTION_PTR;
|
||||
else if ( openparens >= 1 )
|
||||
return T_FUNCTION;
|
||||
return T_VARIABLE;
|
||||
}
|
||||
|
||||
Type process ( const string& element, vector<string>& names, bool& isTypedef, vector<string>& dependencies )
|
||||
{
|
||||
names.resize ( 0 );
|
||||
isTypedef = false;
|
||||
dependencies.resize ( 0 );
|
||||
|
||||
vector<string> tokens;
|
||||
|
||||
tokenize ( element, tokens );
|
||||
|
||||
// now let's do the classification...
|
||||
int i = 0;
|
||||
if ( tokens[i] == "typedef" )
|
||||
{
|
||||
isTypedef = true;
|
||||
i++;
|
||||
}
|
||||
|
||||
Type t = identify ( tokens, i );
|
||||
|
||||
parse_type ( t, tokens, i, names, dependencies );
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
int parse_type ( Type t, const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies )
|
||||
{
|
||||
switch ( t )
|
||||
{
|
||||
case T_IGNORED_STATEMENT:
|
||||
return parse_ignored_statement ( tokens, off, names, dependencies );
|
||||
case T_TIDENT:
|
||||
return parse_tident ( tokens, off, names, dependencies );
|
||||
case T_VARIABLE:
|
||||
return parse_variable ( tokens, off, names, dependencies );
|
||||
case T_STRUCT:
|
||||
return parse_struct ( tokens, off, names, dependencies );
|
||||
case T_FUNCTION:
|
||||
return parse_function ( tokens, off, names, dependencies );
|
||||
case T_FUNCTION_PTR:
|
||||
return parse_function_ptr ( tokens, off, names, dependencies );
|
||||
case T_IF:
|
||||
case T_WHILE:
|
||||
return parse_ifwhile ( tokens, off, names, dependencies );
|
||||
case T_DO:
|
||||
return parse_do ( tokens, off, names, dependencies );
|
||||
default:
|
||||
TOKASSERT(!"unidentified type in parse_type()");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void name ( const string& ident, vector<string>& names )
|
||||
{
|
||||
if ( !__iscsymf ( ident[0] ) )
|
||||
return;
|
||||
if ( iskeyword ( ident ) )
|
||||
return;
|
||||
for ( int i = 0; i < names.size(); i++ )
|
||||
{
|
||||
if ( names[i] == ident )
|
||||
return;
|
||||
}
|
||||
names.push_back ( ident );
|
||||
}
|
||||
|
||||
void depend ( const string& ident, vector<string>& dependencies )
|
||||
{
|
||||
if ( !__iscsymf ( ident[0] ) )
|
||||
return;
|
||||
if ( iskeyword ( ident ) )
|
||||
return;
|
||||
for ( int i = 0; i < dependencies.size(); i++ )
|
||||
{
|
||||
if ( dependencies[i] == ident )
|
||||
return;
|
||||
}
|
||||
dependencies.push_back ( ident );
|
||||
}
|
||||
|
||||
int parse_ignored_statement ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies )
|
||||
{
|
||||
off++;
|
||||
while ( tokens[off] != ";" )
|
||||
off++;
|
||||
ASSERT ( tokens[off] == ";" );
|
||||
return off + 1;
|
||||
}
|
||||
|
||||
int parse_tident ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies )
|
||||
{
|
||||
TOKASSERT ( tokens[off] == "typedef_tident" );
|
||||
TOKASSERT ( tokens[off+1] == "(" && tokens[off+3] == ")" );
|
||||
names.push_back ( tokens[off+2] );
|
||||
dependencies.push_back ( "typedef_tident" );
|
||||
return off + 4;
|
||||
}
|
||||
|
||||
int parse_variable ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies )
|
||||
{
|
||||
// NOTE - Test with bitfields, I think this code will actually handle them properly...
|
||||
if ( tokens[off] == ";" )
|
||||
return off + 1;
|
||||
depend ( tokens[off++], dependencies );
|
||||
int done = tokens.size();
|
||||
while ( off < tokens.size() && tokens[off] != ";" )
|
||||
name ( tokens[off++], names );
|
||||
TOKASSERT ( off < tokens.size() && tokens[off] == ";" );
|
||||
return off + 1;
|
||||
}
|
||||
|
||||
int parse_struct ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies )
|
||||
{
|
||||
int done = tokens.size();
|
||||
|
||||
//if ( tokens[off+1] == "_LARGE_INTEGER" )
|
||||
// _CrtDbgBreak();
|
||||
|
||||
while ( off < done && tokens[off] != "struct" && tokens[off] != "union" )
|
||||
depend ( tokens[off++], dependencies );
|
||||
|
||||
TOKASSERT ( tokens[off] == "struct" || tokens[off] == "union" );
|
||||
if ( tokens[off] != "struct" && tokens[off] != "union" )
|
||||
return off;
|
||||
off++;
|
||||
|
||||
if ( tokens[off] != "{" )
|
||||
name ( tokens[off++], names );
|
||||
|
||||
if ( tokens[off] == ":" )
|
||||
{
|
||||
off++;
|
||||
TOKASSERT ( tokens[off] == "public" || tokens[off] == "protected" || tokens[off] == "private" );
|
||||
off++;
|
||||
depend ( tokens[off++], dependencies );
|
||||
}
|
||||
|
||||
TOKASSERT ( tokens[off] == "{" );
|
||||
off++;
|
||||
|
||||
// skip through body of struct - noting any dependencies
|
||||
int indent = 1;
|
||||
//if ( off >= done ) _CrtDbgBreak();
|
||||
while ( off < done && tokens[off] != "}" )
|
||||
{
|
||||
vector<string> fauxnames;
|
||||
Type t = identify ( tokens, off );
|
||||
off = parse_type ( t, tokens, off, fauxnames, dependencies );
|
||||
//if ( off >= done ) _CrtDbgBreak();
|
||||
}
|
||||
|
||||
// process any trailing dependencies/names...
|
||||
while ( tokens[off] != ";" )
|
||||
{
|
||||
TOKASSERT ( off+1 < done );
|
||||
if ( tokens[off+1] == "," || tokens[off+1] == ";" )
|
||||
name ( tokens[off], names );
|
||||
else
|
||||
depend ( tokens[off], dependencies );
|
||||
off++;
|
||||
}
|
||||
|
||||
TOKASSERT ( tokens[off] == ";" );
|
||||
off++;
|
||||
|
||||
return off;
|
||||
}
|
||||
|
||||
int parse_param ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies )
|
||||
{
|
||||
if ( tokens[off] == ")" )
|
||||
return off;
|
||||
// special-case check for function pointer params
|
||||
int done = off;
|
||||
int parens = 1;
|
||||
bool fptr = false;
|
||||
for ( ;; )
|
||||
{
|
||||
if ( tokens[done] == "," && parens == 1 )
|
||||
break;
|
||||
if ( tokens[done] == ")" )
|
||||
{
|
||||
if ( parens == 1 )
|
||||
break;
|
||||
else
|
||||
parens--;
|
||||
}
|
||||
if ( tokens[done] == "(" )
|
||||
parens++;
|
||||
if ( tokens[done] == "*" && tokens[done-1] == "(" )
|
||||
fptr = true;
|
||||
done++;
|
||||
}
|
||||
if ( !fptr )
|
||||
done--;
|
||||
while ( off < done )
|
||||
depend ( tokens[off++], dependencies );
|
||||
if ( !fptr )
|
||||
name ( tokens[off++], names );
|
||||
return off;
|
||||
}
|
||||
|
||||
int parse_function ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies )
|
||||
{
|
||||
vector<string> fauxnames;
|
||||
|
||||
off = skip_declspec ( tokens, off );
|
||||
|
||||
while ( tokens[off+1] != "(" )
|
||||
depend ( tokens[off++], dependencies );
|
||||
name ( tokens[off++], names );
|
||||
|
||||
TOKASSERT ( tokens[off] == "(" );
|
||||
|
||||
while ( tokens[off] != ")" )
|
||||
{
|
||||
off++;
|
||||
off = parse_param ( tokens, off, fauxnames, dependencies );
|
||||
TOKASSERT ( tokens[off] == "," || tokens[off] == ")" );
|
||||
}
|
||||
|
||||
off++;
|
||||
|
||||
// check for "attributes"
|
||||
if ( tokens[off] == "__attribute__" )
|
||||
{
|
||||
off++;
|
||||
TOKASSERT ( tokens[off] == "(" );
|
||||
off++;
|
||||
int parens = 1;
|
||||
while ( parens )
|
||||
{
|
||||
if ( tokens[off] == "(" )
|
||||
parens++;
|
||||
else if ( tokens[off] == ")" )
|
||||
parens--;
|
||||
off++;
|
||||
}
|
||||
}
|
||||
|
||||
// is this just a function *declaration* ?
|
||||
if ( tokens[off] == ";" )
|
||||
return off;
|
||||
|
||||
// we have a function body...
|
||||
TOKASSERT ( tokens[off] == "{" );
|
||||
off++;
|
||||
|
||||
while ( tokens[off] != "}" )
|
||||
{
|
||||
Type t = identify ( tokens, off );
|
||||
if ( t == T_VARIABLE )
|
||||
off = parse_type ( t, tokens, off, fauxnames, dependencies );
|
||||
else
|
||||
{
|
||||
while ( tokens[off] != ";" )
|
||||
off++;
|
||||
TOKASSERT ( tokens[off] == ";" );
|
||||
off++;
|
||||
}
|
||||
}
|
||||
|
||||
TOKASSERT ( tokens[off] == "}" );
|
||||
off++;
|
||||
|
||||
return off;
|
||||
}
|
||||
|
||||
int parse_function_ptr ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies )
|
||||
{
|
||||
off = skip_declspec ( tokens, off );
|
||||
|
||||
while ( tokens[off] != "(" )
|
||||
depend ( tokens[off++], dependencies );
|
||||
|
||||
TOKASSERT ( tokens[off] == "(" );
|
||||
off++;
|
||||
|
||||
while ( tokens[off+1] != ")" )
|
||||
depend ( tokens[off++], dependencies );
|
||||
name ( tokens[off++], names );
|
||||
|
||||
TOKASSERT ( tokens[off] == ")" );
|
||||
|
||||
off++;
|
||||
|
||||
TOKASSERT ( tokens[off] == "(" );
|
||||
|
||||
while ( tokens[off] != ")" )
|
||||
{
|
||||
off++;
|
||||
vector<string> fauxnames;
|
||||
off = parse_param ( tokens, off, fauxnames, dependencies );
|
||||
TOKASSERT ( tokens[off] == "," || tokens[off] == ")" );
|
||||
}
|
||||
|
||||
off++;
|
||||
TOKASSERT ( tokens[off] == ";" );
|
||||
off++;
|
||||
return off;
|
||||
}
|
||||
|
||||
int parse_ifwhile ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies )
|
||||
{
|
||||
TOKASSERT ( tokens[off] == "if" || tokens[off] == "while" );
|
||||
off++;
|
||||
|
||||
TOKASSERT ( tokens[off] == "(" );
|
||||
off++;
|
||||
|
||||
TOKASSERT ( tokens[off] != ")" );
|
||||
while ( tokens[off] != ")" )
|
||||
off++;
|
||||
|
||||
if ( tokens[off] == "{" )
|
||||
{
|
||||
while ( tokens[off] != "}" )
|
||||
{
|
||||
Type t = identify ( tokens, off );
|
||||
off = parse_type ( t, tokens, off, names, dependencies );
|
||||
}
|
||||
off++;
|
||||
}
|
||||
return off;
|
||||
}
|
||||
|
||||
int parse_do ( const vector<string>& tokens, int off, vector<string>& names, vector<string>& dependencies )
|
||||
{
|
||||
TOKASSERT ( tokens[off] == "do" );
|
||||
off++;
|
||||
|
||||
if ( tokens[off] != "{" )
|
||||
{
|
||||
Type t = identify ( tokens, off );
|
||||
off = parse_type ( t, tokens, off, names, dependencies );
|
||||
}
|
||||
else
|
||||
{
|
||||
while ( tokens[off] != "}" )
|
||||
{
|
||||
Type t = identify ( tokens, off );
|
||||
off = parse_type ( t, tokens, off, names, dependencies );
|
||||
}
|
||||
}
|
||||
|
||||
TOKASSERT ( tokens[off] == "while" );
|
||||
off++;
|
||||
|
||||
TOKASSERT ( tokens[off] == "(" );
|
||||
while ( tokens[off] != ")" )
|
||||
off++;
|
||||
|
||||
TOKASSERT ( tokens[off] == ")" );
|
||||
off++;
|
||||
|
||||
TOKASSERT ( tokens[off] == ";" );
|
||||
off++;
|
||||
|
||||
return off;
|
||||
}
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
# Microsoft Developer Studio Project File - Name="sdkparse" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=sdkparse - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "sdkparse.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "sdkparse.mak" CFG="sdkparse - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "sdkparse - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "sdkparse - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "sdkparse - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
|
||||
!ELSEIF "$(CFG)" == "sdkparse - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "sdkparse - Win32 Release"
|
||||
# Name "sdkparse - Win32 Debug"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\assert.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\binary2cstr.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\EnumDirs.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\EnumDirsImpl.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\EnumFiles.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\EnumFilesImpl.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\File.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\File.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\FixLFN.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Header.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\iskeyword.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\iskeyword.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\safestr.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sdkparse.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\skip_ws.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\skip_ws.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strip_comments.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\strip_comments.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Symbol.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\tokenize.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Type.h
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
|
@ -0,0 +1,29 @@
|
|||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "sdkparse"=.\sdkparse.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
// skip_ws.cpp
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "skip_ws.h"
|
||||
|
||||
const char* ws = " \t\r\n\v";
|
||||
|
||||
char* skip_ws ( char* p )
|
||||
{
|
||||
return p + strspn ( p, ws );
|
||||
}
|
||||
|
||||
const char* skip_ws ( const char* p )
|
||||
{
|
||||
return p + strspn ( p, ws );
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
// skip_ws.h
|
||||
|
||||
#ifndef SKIP_WS_H
|
||||
#define SKIP_WS_H
|
||||
|
||||
char* skip_ws ( char* );
|
||||
|
||||
const char* skip_ws ( const char* );
|
||||
|
||||
#endif//SKIP_WS_H
|
|
@ -0,0 +1,43 @@
|
|||
// strip_comments.cpp
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning ( disable : 4786 )
|
||||
#endif//_MSC_VER
|
||||
|
||||
#include "strip_comments.h"
|
||||
|
||||
void strip_comments ( std::string& s, bool strip_lf )
|
||||
{
|
||||
char* src = &s[0];
|
||||
char* dst = src;
|
||||
while ( *src )
|
||||
{
|
||||
if ( src[0] == '/' && src[1] == '/' )
|
||||
{
|
||||
src += 2;
|
||||
while ( *src && *src != '\n' )
|
||||
src++;
|
||||
if ( *src )
|
||||
src++; // skip newline
|
||||
}
|
||||
else if ( src[0] == '/' && src[1] == '*' )
|
||||
{
|
||||
src += 2;
|
||||
char* newsrc = strstr ( src, "*/" );
|
||||
if ( !newsrc )
|
||||
break;
|
||||
src = newsrc;
|
||||
//while ( *src && ( src[0] != '*' || src[1] != '/' ) )
|
||||
// src++;
|
||||
if ( *src ) src++;
|
||||
if ( *src ) src++;
|
||||
}
|
||||
else if ( src[0] == '\r' && strip_lf )
|
||||
src++;
|
||||
else
|
||||
*dst++ = *src++;
|
||||
}
|
||||
*dst = '\0';
|
||||
|
||||
s.resize ( dst-&s[0] );
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
// strip_comments.h
|
||||
|
||||
#ifndef STRIP_COMMENTS_H
|
||||
#define STRIP_COMMENTS_H
|
||||
|
||||
#include <string>
|
||||
|
||||
void strip_comments ( std::string& s, bool strip_lf = false );
|
||||
|
||||
#endif//STRIP_COMMENTS_H
|
261
modules/rosapps/applications/sysutils/utils/sdkparse/test.h
Normal file
261
modules/rosapps/applications/sysutils/utils/sdkparse/test.h
Normal file
|
@ -0,0 +1,261 @@
|
|||
/*
|
||||
* test.h
|
||||
*
|
||||
* This file is a combination of a couple different headers
|
||||
* from ReactOS's include/ folder, and a little bit of custom
|
||||
* hacking as well for the purpose of testing sdkparse.
|
||||
*
|
||||
* THIS SOFTWARE IS NOT COPYRIGHTED
|
||||
*
|
||||
* This source code is offered for use in the public domain. You may
|
||||
* use, modify or distribute it freely.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful but
|
||||
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
|
||||
* DISCLAMED. This includes but is not limited to warranties of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __INTERNAL_PSAPI_H_INCLUDED__
|
||||
#define __INTERNAL_PSAPI_H_INCLUDED__
|
||||
|
||||
void *_lfind(const void* match, const void* start,unsigned int* array_size, unsigned int elem_size,int (*cf)(const void*,const void*));
|
||||
|
||||
static inline struct _TEB * NtCurrentTeb(void)
|
||||
{
|
||||
struct _TEB * pTeb;
|
||||
|
||||
/* FIXME: instead of hardcoded offsets, use offsetof() - if possible */
|
||||
__asm__ __volatile__
|
||||
(
|
||||
"movl %%fs:0x18, %0\n" /* fs:18h == Teb->Tib.Self */
|
||||
: "=r" (pTeb) /* can't have two memory operands */
|
||||
: /* no inputs */
|
||||
);
|
||||
|
||||
return pTeb;
|
||||
}
|
||||
|
||||
typedef struct tagFOO
|
||||
{
|
||||
INT lonibble : 4;
|
||||
INT hinibble : 4;
|
||||
} FOO, *PFOO, FAR *LPFOO;
|
||||
|
||||
/* INCLUDES */
|
||||
#define NTOS_MODE_USER
|
||||
#include <ntos.h>
|
||||
|
||||
/* OBJECTS */
|
||||
typedef struct
|
||||
{
|
||||
LPSTR LeftVolumeName;
|
||||
LPSTR RightVolumeName;
|
||||
ULONG DefaultVolume;
|
||||
ULONG Type;
|
||||
ULONG DeviceType;
|
||||
char Key[4];
|
||||
LPSTR PrototypeName;
|
||||
PVOID DeferredRoutine;
|
||||
PVOID ExclusionRoutine;
|
||||
PVOID DispatchRoutine;
|
||||
PVOID DevCapsRoutine;
|
||||
PVOID HwSetVolume;
|
||||
ULONG IoMethod;
|
||||
}SOUND_DEVICE_INIT;
|
||||
|
||||
/* TYPES */
|
||||
typedef NTSTATUS NTAPI (*PPROC_ENUM_ROUTINE)
|
||||
(
|
||||
IN PSYSTEM_PROCESSES CurrentProcess,
|
||||
IN OUT PVOID CallbackContext
|
||||
);
|
||||
|
||||
typedef NTSTATUS NTAPI (*PTHREAD_ENUM_ROUTINE)
|
||||
(
|
||||
IN PSYSTEM_THREADS CurrentThread,
|
||||
IN OUT PVOID CallbackContext
|
||||
);
|
||||
|
||||
typedef NTSTATUS NTAPI (*PSYSMOD_ENUM_ROUTINE)
|
||||
(
|
||||
IN PSYSTEM_MODULE_INFORMATION_ENTRY CurrentModule,
|
||||
IN OUT PVOID CallbackContext
|
||||
);
|
||||
|
||||
typedef NTSTATUS NTAPI (*PPROCMOD_ENUM_ROUTINE)
|
||||
(
|
||||
IN HANDLE ProcessHandle,
|
||||
IN PLDR_DATA_TABLE_ENTRY CurrentModule,
|
||||
IN OUT PVOID CallbackContext
|
||||
);
|
||||
|
||||
/* CONSTANTS */
|
||||
#define FAILED_WITH_STATUS DEFINE_DBG_MSG("%s() failed, status 0x%08X")
|
||||
|
||||
/* PROTOTYPES */
|
||||
/* Processes and threads */
|
||||
/* enumeration */
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PsaEnumerateProcessesAndThreads
|
||||
(
|
||||
IN PPROC_ENUM_ROUTINE ProcessCallback,
|
||||
IN OUT PVOID ProcessCallbackContext,
|
||||
IN PTHREAD_ENUM_ROUTINE ThreadCallback,
|
||||
IN OUT PVOID ThreadCallbackContext
|
||||
);
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PsaEnumerateProcesses
|
||||
(
|
||||
IN PPROC_ENUM_ROUTINE Callback,
|
||||
IN OUT PVOID CallbackContext
|
||||
);
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PsaEnumerateThreads
|
||||
(
|
||||
IN PTHREAD_ENUM_ROUTINE Callback,
|
||||
IN OUT PVOID CallbackContext
|
||||
);
|
||||
|
||||
/* capturing & walking */
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PsaCaptureProcessesAndThreads
|
||||
(
|
||||
OUT PSYSTEM_PROCESSES * ProcessesAndThreads
|
||||
);
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PsaWalkProcessesAndThreads
|
||||
(
|
||||
IN PSYSTEM_PROCESSES ProcessesAndThreads,
|
||||
IN PPROC_ENUM_ROUTINE ProcessCallback,
|
||||
IN OUT PVOID ProcessCallbackContext,
|
||||
IN PTHREAD_ENUM_ROUTINE ThreadCallback,
|
||||
IN OUT PVOID ThreadCallbackContext
|
||||
);
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PsaWalkProcesses
|
||||
(
|
||||
IN PSYSTEM_PROCESSES ProcessesAndThreads,
|
||||
IN PPROC_ENUM_ROUTINE Callback,
|
||||
IN OUT PVOID CallbackContext
|
||||
);
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PsaWalkThreads
|
||||
(
|
||||
IN PSYSTEM_PROCESSES ProcessesAndThreads,
|
||||
IN PTHREAD_ENUM_ROUTINE Callback,
|
||||
IN OUT PVOID CallbackContext
|
||||
);
|
||||
|
||||
PSYSTEM_PROCESSES
|
||||
FASTCALL
|
||||
PsaWalkFirstProcess
|
||||
(
|
||||
IN PSYSTEM_PROCESSES ProcessesAndThreads
|
||||
);
|
||||
|
||||
PSYSTEM_PROCESSES
|
||||
FASTCALL
|
||||
PsaWalkNextProcess
|
||||
(
|
||||
IN PSYSTEM_PROCESSES CurrentProcess
|
||||
);
|
||||
|
||||
PSYSTEM_THREADS
|
||||
FASTCALL
|
||||
PsaWalkFirstThread
|
||||
(
|
||||
IN PSYSTEM_PROCESSES CurrentProcess
|
||||
);
|
||||
|
||||
PSYSTEM_THREADS
|
||||
FASTCALL
|
||||
PsaWalkNextThread
|
||||
(
|
||||
IN PSYSTEM_THREADS CurrentThread
|
||||
);
|
||||
|
||||
/* System modules */
|
||||
/* enumeration */
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PsaEnumerateSystemModules
|
||||
(
|
||||
IN PSYSMOD_ENUM_ROUTINE Callback,
|
||||
IN OUT PVOID CallbackContext
|
||||
);
|
||||
|
||||
/* capturing & walking */
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PsaCaptureSystemModules
|
||||
(
|
||||
OUT PSYSTEM_MODULE_INFORMATION * SystemModules
|
||||
);
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PsaWalkSystemModules
|
||||
(
|
||||
IN PSYSTEM_MODULE_INFORMATION SystemModules,
|
||||
IN PSYSMOD_ENUM_ROUTINE Callback,
|
||||
IN OUT PVOID CallbackContext
|
||||
);
|
||||
|
||||
PSYSTEM_MODULE_INFORMATION_ENTRY
|
||||
FASTCALL
|
||||
PsaWalkFirstSystemModule
|
||||
(
|
||||
IN PSYSTEM_MODULE_INFORMATION SystemModules
|
||||
);
|
||||
|
||||
PSYSTEM_MODULE_INFORMATION_ENTRY
|
||||
FASTCALL
|
||||
PsaWalkNextSystemModule
|
||||
(
|
||||
IN PSYSTEM_MODULE_INFORMATION CurrentSystemModule
|
||||
);
|
||||
|
||||
/* Process modules */
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PsaEnumerateProcessModules
|
||||
(
|
||||
IN HANDLE ProcessHandle,
|
||||
IN PPROCMOD_ENUM_ROUTINE Callback,
|
||||
IN OUT PVOID CallbackContext
|
||||
);
|
||||
|
||||
/* Miscellaneous */
|
||||
VOID
|
||||
NTAPI
|
||||
PsaFreeCapture
|
||||
(
|
||||
IN PVOID Capture
|
||||
);
|
||||
|
||||
/* The user must define these functions. They are called by PSAPI to allocate
|
||||
memory. This allows PSAPI to be called from any environment */
|
||||
void *PsaiMalloc(SIZE_T size);
|
||||
void *PsaiRealloc(void *ptr, SIZE_T size);
|
||||
void PsaiFree(void *ptr);
|
||||
|
||||
/* MACROS */
|
||||
#define DEFINE_DBG_MSG(__str__) "PSAPI: " __str__ "\n"
|
||||
|
||||
#endif /* __INTERNAL_PSAPI_H_INCLUDED__ */
|
||||
|
||||
/* EOF */
|
|
@ -0,0 +1,312 @@
|
|||
// tokenize.cpp
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning ( disable : 4786 )
|
||||
#endif//_MSC_VER
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <conio.h>
|
||||
|
||||
#include "assert.h"
|
||||
#include "tokenize.h"
|
||||
#include "skip_ws.h"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
void tokenize ( const string& text, vector<string>& tokens )
|
||||
{
|
||||
tokens.resize ( 0 );
|
||||
string s ( text );
|
||||
char* p = &s[0];
|
||||
while ( *p )
|
||||
{
|
||||
// skip whitespace
|
||||
p = skip_ws ( p );
|
||||
// check for literal string
|
||||
if ( *p == '\"' )
|
||||
{
|
||||
// skip initial quote
|
||||
char* end = p + 1;
|
||||
for ( ;; )
|
||||
{
|
||||
if ( *end == '\\' )
|
||||
{
|
||||
end++;
|
||||
switch ( *end )
|
||||
{
|
||||
case 'x':
|
||||
case 'X':
|
||||
ASSERT(0); // come back to this....
|
||||
break;
|
||||
case '0':
|
||||
ASSERT(0);
|
||||
break;
|
||||
default:
|
||||
end++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if ( *end == '\"' )
|
||||
{
|
||||
end++;
|
||||
break;
|
||||
}
|
||||
else
|
||||
end++;
|
||||
}
|
||||
tokens.push_back ( string ( p, end-p ) );
|
||||
p = end;
|
||||
}
|
||||
else if ( __iscsymf(*p) )
|
||||
{
|
||||
char* end = p + 1;
|
||||
while ( __iscsym ( *end ) )
|
||||
end++;
|
||||
tokens.push_back ( string ( p, end-p ) );
|
||||
p = end;
|
||||
}
|
||||
else if ( isdigit(*p) || *p == '.' )
|
||||
{
|
||||
char* end = p;
|
||||
while ( isdigit(*end) )
|
||||
end++;
|
||||
bool f = false;
|
||||
if ( *end == '.' )
|
||||
{
|
||||
end++;
|
||||
while ( isdigit(*end) )
|
||||
end++;
|
||||
f = true;
|
||||
}
|
||||
if ( *end == 'f' || *end == 'F' )
|
||||
end++;
|
||||
else if ( !f && ( *end == 'l' || *end == 'L' ) )
|
||||
end++;
|
||||
tokens.push_back ( string ( p, end-p ) );
|
||||
p = end;
|
||||
}
|
||||
else switch ( *p )
|
||||
{
|
||||
case '.':
|
||||
tokens.push_back ( "." );
|
||||
p++;
|
||||
break;
|
||||
case ',':
|
||||
tokens.push_back ( "," );
|
||||
p++;
|
||||
break;
|
||||
case '(':
|
||||
tokens.push_back ( "(" );
|
||||
p++;
|
||||
break;
|
||||
case ')':
|
||||
tokens.push_back ( ")" );
|
||||
p++;
|
||||
break;
|
||||
case '{':
|
||||
tokens.push_back ( "{" );
|
||||
p++;
|
||||
break;
|
||||
case '}':
|
||||
tokens.push_back ( "}" );
|
||||
p++;
|
||||
break;
|
||||
case '[':
|
||||
tokens.push_back ( "[" );
|
||||
p++;
|
||||
break;
|
||||
case ']':
|
||||
tokens.push_back ( "]" );
|
||||
p++;
|
||||
break;
|
||||
case ';':
|
||||
tokens.push_back ( ";" );
|
||||
p++;
|
||||
break;
|
||||
case '\\':
|
||||
switch ( p[1] )
|
||||
{
|
||||
case '\n':
|
||||
tokens.push_back ( string ( p, 2 ) );
|
||||
p += 2;
|
||||
break;
|
||||
default:
|
||||
ASSERT(0); // shouldn't hit here, I think
|
||||
tokens.push_back ( "\\" );
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '|':
|
||||
switch ( p[1] )
|
||||
{
|
||||
case '|':
|
||||
tokens.push_back ( string ( p, 2 ) );
|
||||
p += 2;
|
||||
break;
|
||||
default:
|
||||
tokens.push_back ( "|" );
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '&':
|
||||
switch ( p[1] )
|
||||
{
|
||||
case '&':
|
||||
tokens.push_back ( string ( p, 2 ) );
|
||||
p += 2;
|
||||
break;
|
||||
default:
|
||||
tokens.push_back ( "&" );
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '<':
|
||||
switch ( p[1] )
|
||||
{
|
||||
case '<':
|
||||
if ( p[2] == '=' )
|
||||
tokens.push_back ( string ( p, 3 ) ), p += 3;
|
||||
else
|
||||
tokens.push_back ( string ( p, 2 ) ), p += 2;
|
||||
break;
|
||||
case '=':
|
||||
tokens.push_back ( string ( p, 2 ) );
|
||||
p += 2;
|
||||
break;
|
||||
default:
|
||||
tokens.push_back ( "<" );
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '>':
|
||||
switch ( p[1] )
|
||||
{
|
||||
case '>':
|
||||
if ( p[2] == '=' )
|
||||
tokens.push_back ( string ( p, 3 ) ), p += 3;
|
||||
else
|
||||
tokens.push_back ( string ( p, 2 ) ), p += 2;
|
||||
break;
|
||||
case '=':
|
||||
tokens.push_back ( string ( p, 2 ) );
|
||||
p += 2;
|
||||
break;
|
||||
default:
|
||||
tokens.push_back ( ">" );
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '!':
|
||||
switch ( p[1] )
|
||||
{
|
||||
case '=':
|
||||
tokens.push_back ( string ( p, 2 ) );
|
||||
p += 2;
|
||||
break;
|
||||
default:
|
||||
tokens.push_back ( "!" );
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '=':
|
||||
switch ( p[1] )
|
||||
{
|
||||
case '=':
|
||||
tokens.push_back ( string ( p, 2 ) );
|
||||
p += 2;
|
||||
break;
|
||||
default:
|
||||
tokens.push_back ( "=" );
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ':':
|
||||
switch ( p[1] )
|
||||
{
|
||||
case ':':
|
||||
tokens.push_back ( string ( p, 2 ) );
|
||||
p += 2;
|
||||
break;
|
||||
default:
|
||||
tokens.push_back ( ":" );
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '*':
|
||||
switch ( p[1] )
|
||||
{
|
||||
case '=':
|
||||
tokens.push_back ( string ( p, 2 ) );
|
||||
p += 2;
|
||||
break;
|
||||
default:
|
||||
tokens.push_back ( "*" );
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '/':
|
||||
switch ( p[1] )
|
||||
{
|
||||
case '=':
|
||||
tokens.push_back ( string ( p, 2 ) );
|
||||
p += 2;
|
||||
break;
|
||||
default:
|
||||
tokens.push_back ( "/" );
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '+':
|
||||
switch ( p[1] )
|
||||
{
|
||||
case '+':
|
||||
case '=':
|
||||
tokens.push_back ( string ( p, 2 ) );
|
||||
p += 2;
|
||||
break;
|
||||
default:
|
||||
tokens.push_back ( "+" );
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
switch ( p[1] )
|
||||
{
|
||||
case '-':
|
||||
case '=':
|
||||
tokens.push_back ( string ( p, 2 ) );
|
||||
p += 2;
|
||||
break;
|
||||
default:
|
||||
tokens.push_back ( "-" );
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '#':
|
||||
while ( *p && *p != '\n' )
|
||||
p++;
|
||||
break;
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
printf ( "choked on '%c' in tokenize() - press any key to continue\n", *p );
|
||||
getch();
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
// tokenize.h
|
||||
|
||||
#ifndef TOKENIZE_H
|
||||
#define TOKENIZE_H
|
||||
|
||||
void tokenize ( const std::string& text, std::vector<std::string>& tokens );
|
||||
|
||||
#endif//TOKENIZE_H
|
Loading…
Add table
Add a link
Reference in a new issue