mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 08:25:03 +00:00
- beginning of a def conversion utility
svn path=/trunk/; revision=24975
This commit is contained in:
parent
358a8ed849
commit
93c26f0ab5
3 changed files with 274 additions and 1 deletions
226
reactos/tools/fixdef/fixdef.cpp
Normal file
226
reactos/tools/fixdef/fixdef.cpp
Normal file
|
@ -0,0 +1,226 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <tchar.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define _FINDDATA_T_DEFINED
|
||||
#include <io.h>
|
||||
#include <time.h>
|
||||
|
||||
typedef std::basic_string<TCHAR> string;
|
||||
typedef std::basic_istringstream<TCHAR> istringstream;
|
||||
|
||||
#ifdef UNICODE
|
||||
|
||||
using std::wcout;
|
||||
using std::wcerr;
|
||||
using std::endl;
|
||||
|
||||
#define cout wcout
|
||||
#define cerr wcerr
|
||||
|
||||
#else
|
||||
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
#endif
|
||||
|
||||
using std::vector;
|
||||
using std::endl;
|
||||
|
||||
|
||||
bool scan_dir(string current_dir, vector<string> & def_files)
|
||||
{
|
||||
vector<string> vect;
|
||||
string val = current_dir;
|
||||
val.insert (val.length(), _T("\\*"));
|
||||
|
||||
struct _tfinddatai64_t c_file;
|
||||
intptr_t hFile = _tfindfirsti64(val.c_str(), &c_file);
|
||||
|
||||
if (hFile == -1L)
|
||||
{
|
||||
cerr << "scan_dir failed" << val << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
do
|
||||
{
|
||||
TCHAR * pos;
|
||||
if ((pos = _tcsstr(c_file.name, _T(".def"))))
|
||||
{
|
||||
string modulename = c_file.name;
|
||||
if (modulename.find (_T(".spec.def")) != string::npos)
|
||||
{
|
||||
///
|
||||
/// ignore spec files
|
||||
///
|
||||
continue;
|
||||
}
|
||||
string fname = current_dir;
|
||||
fname.insert (fname.length (), _T("\\"));
|
||||
fname.insert (fname.length (), modulename);
|
||||
cout << "adding file to scan list: "<< fname << endl;
|
||||
def_files.push_back(fname);
|
||||
}
|
||||
if (c_file.attrib & _A_SUBDIR)
|
||||
{
|
||||
if (!_tcscmp(c_file.name, _T(".svn")))
|
||||
{
|
||||
///
|
||||
/// ignore .svn directories
|
||||
///
|
||||
continue;
|
||||
}
|
||||
if (c_file.name[0] != _T('.'))
|
||||
{
|
||||
string path = current_dir;
|
||||
path.insert (path.length(), _T("\\"));
|
||||
path.insert (path.length(), c_file.name);
|
||||
vect.push_back (path);
|
||||
}
|
||||
}
|
||||
|
||||
}while(_tfindnexti64(hFile, &c_file) == 0);
|
||||
|
||||
_findclose(hFile);
|
||||
hFile = -1L;
|
||||
|
||||
while(!vect.empty ())
|
||||
{
|
||||
current_dir = vect.front ();
|
||||
vect.erase (vect.begin());
|
||||
val = current_dir;
|
||||
val.insert (val.length(), _T("\\*"));
|
||||
hFile = _tfindfirsti64(val.c_str(), &c_file);
|
||||
if (hFile != -1L)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hFile == -1L)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
}while(1);
|
||||
|
||||
return !def_files.empty ();
|
||||
}
|
||||
|
||||
bool readFile(string filename, vector<string> & file)
|
||||
{
|
||||
FILE * fd = _tfopen(filename.c_str(), _T("rt"));
|
||||
if (!fd)
|
||||
{
|
||||
cerr << "Error: failed to open file " << filename << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
TCHAR szBuffer[256];
|
||||
memset(szBuffer, 0x0, sizeof(szBuffer));
|
||||
|
||||
if(_fgetts(szBuffer, sizeof(szBuffer) / sizeof(char), fd))
|
||||
{
|
||||
string line = szBuffer;
|
||||
file.push_back (line);
|
||||
}
|
||||
}while(!feof(fd));
|
||||
|
||||
fclose(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool convertFile(string filename, vector<string> & file)
|
||||
{
|
||||
bool modified = false;
|
||||
|
||||
for(size_t i = 0; i < file.size(); i++)
|
||||
{
|
||||
string & line = file[i];
|
||||
if (line[0] == _T(';'))
|
||||
{
|
||||
///
|
||||
/// line is a comment ignore
|
||||
///
|
||||
continue;
|
||||
}
|
||||
if (line.find(_T("@")) == string::npos)
|
||||
{
|
||||
// file has no @
|
||||
continue;
|
||||
}
|
||||
|
||||
///
|
||||
/// TODO implement algorithm
|
||||
///
|
||||
|
||||
//cout << ">" << line;
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
bool writeFile(string filename, vector<string> & file)
|
||||
{
|
||||
FILE * fd = _tfopen(filename.c_str(), _T("wt"));
|
||||
if (!fd)
|
||||
{
|
||||
cerr << "Error: failed to open file " << filename << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < file.size (); i++)
|
||||
{
|
||||
string & line = file[i];
|
||||
_fputts(line.c_str (), fd);
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int _tmain(int argc, TCHAR ** argv)
|
||||
{
|
||||
string current_dir;
|
||||
vector<string> def_files;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
cout << "Usage: " << argv[0] << "path to source" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!scan_dir(argv[1], def_files) || def_files.size() == 0)
|
||||
{
|
||||
cout << "Error: found no def files or invalid directory" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < def_files.size(); i++)
|
||||
{
|
||||
vector<string> file;
|
||||
file.clear ();
|
||||
if (readFile(def_files[i], file))
|
||||
{
|
||||
if (convertFile(def_files[i], file))
|
||||
{
|
||||
writeFile(def_files[i], file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
46
reactos/tools/fixdef/fixdef.mak
Normal file
46
reactos/tools/fixdef/fixdef.mak
Normal file
|
@ -0,0 +1,46 @@
|
|||
FIXDEF_BASE = $(TOOLS_BASE)$(SEP)fixdef
|
||||
FIXDEF_BASE_ = $(FIXDEF_BASE)$(SEP)
|
||||
FIXDEF_INT = $(INTERMEDIATE_)$(FIXDEF_BASE)
|
||||
FIXDEF_INT_ = $(FIXDEF_INT)$(SEP)
|
||||
FIXDEF_OUT = $(OUTPUT_)$(FIXDEF_BASE)
|
||||
FIXDEF_OUT_ = $(FIXDEF_OUT)$(SEP)
|
||||
|
||||
$(FIXDEF_INT): | $(TOOLS_INT)
|
||||
$(ECHO_MKDIR)
|
||||
${mkdir} $@
|
||||
|
||||
ifneq ($(INTERMEDIATE),$(OUTPUT))
|
||||
$(FIXDEF_OUT): | $(TOOLS_OUT)
|
||||
$(ECHO_MKDIR)
|
||||
${mkdir} $@
|
||||
endif
|
||||
|
||||
FIXDEF_TARGET = \
|
||||
$(EXEPREFIX)$(FIXDEF_OUT_)FIXDEF$(EXEPOSTFIX)
|
||||
|
||||
FIXDEF_SOURCES = $(addprefix $(FIXDEF_BASE_), \
|
||||
fixdef.cpp \
|
||||
)
|
||||
|
||||
FIXDEF_OBJECTS = \
|
||||
$(addprefix $(INTERMEDIATE_), $(FIXDEF_SOURCES:.cpp=.o))
|
||||
|
||||
FIXDEF_HOST_CFLAGS = $(TOOLS_CFLAGS) -D__USE_W32API -Iinclude -Iinclude/reactos -Iinclude/psdk
|
||||
|
||||
FIXDEF_HOST_LFLAGS = $(TOOLS_LFLAGS) -lntdll
|
||||
|
||||
.PHONY: FIXDEF
|
||||
FIXDEF: $(FIXDEF_TARGET)
|
||||
|
||||
$(FIXDEF_TARGET): $(FIXDEF_OBJECTS) | $(FIXDEF_OUT)
|
||||
$(ECHO_LD)
|
||||
${host_gpp} $(FIXDEF_OBJECTS) $(FIXDEF_HOST_LFLAGS) -o $@
|
||||
|
||||
$(FIXDEF_INT_)fixdef.o: $(FIXDEF_BASE_)fixdef.cpp | $(FIXDEF_INT)
|
||||
$(ECHO_CC)
|
||||
${host_gpp} $(FIXDEF_HOST_CFLAGS) -c $< -o $@
|
||||
|
||||
.PHONY: FIXDEF_clean
|
||||
FIXDEF_clean:
|
||||
-@$(rm) $(FIXDEF_TARGET) $(FIXDEF_OBJECTS) 2>$(NUL)
|
||||
clean: FIXDEF_clean
|
|
@ -59,4 +59,5 @@ include tools/wmc/wmc.mak
|
|||
include tools/wpp/wpp.mak
|
||||
include tools/wrc/wrc.mak
|
||||
include tools/sysreg/sysreg.mak
|
||||
include tools/dbgprint/dbgprint.mak
|
||||
include tools/dbgprint/dbgprint.mak
|
||||
include tools/fixdef/fixdef.mak
|
Loading…
Reference in a new issue