[ros-diffs] [janderwald] 24975: - beginning of a def conversion utility

janderwald at svn.reactos.org janderwald at svn.reactos.org
Wed Nov 29 22:08:15 CET 2006


Author: janderwald
Date: Thu Nov 30 00:08:15 2006
New Revision: 24975

URL: http://svn.reactos.org/svn/reactos?rev=24975&view=rev
Log:
- beginning of a def conversion utility

Added:
    trunk/reactos/tools/fixdef/   (with props)
    trunk/reactos/tools/fixdef/fixdef.cpp   (with props)
    trunk/reactos/tools/fixdef/fixdef.mak   (with props)
Modified:
    trunk/reactos/tools/tools.mak

Propchange: trunk/reactos/tools/fixdef/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Nov 30 00:08:15 2006
@@ -1,0 +1,36 @@
+*.sys
+*.exe
+*.dll
+*.cpl
+*.a
+*.o
+*.d
+*.coff
+*.dsp
+*.dsw
+*.aps
+*.ncb
+*.opt
+*.sym
+*.plg
+*.bak
+*.zip
+*.iso
+*.img
+*.cab
+*.bat
+*.log
+*.patch
+*.diff
+makefile.auto
+config.rbuild
+obj-*
+output-*
+doxy-doc
+cd
+reactos
+ros
+*.s
+*.sln
+RosBE-Logs
+*.suo

Added: trunk/reactos/tools/fixdef/fixdef.cpp
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fixdef/fixdef.cpp?rev=24975&view=auto
==============================================================================
--- trunk/reactos/tools/fixdef/fixdef.cpp (added)
+++ trunk/reactos/tools/fixdef/fixdef.cpp Thu Nov 30 00:08:15 2006
@@ -1,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;
+}

Propchange: trunk/reactos/tools/fixdef/fixdef.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/reactos/tools/fixdef/fixdef.mak
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fixdef/fixdef.mak?rev=24975&view=auto
==============================================================================
--- trunk/reactos/tools/fixdef/fixdef.mak (added)
+++ trunk/reactos/tools/fixdef/fixdef.mak Thu Nov 30 00:08:15 2006
@@ -1,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

Propchange: trunk/reactos/tools/fixdef/fixdef.mak
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/reactos/tools/tools.mak
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/tools.mak?rev=24975&r1=24974&r2=24975&view=diff
==============================================================================
--- trunk/reactos/tools/tools.mak (original)
+++ trunk/reactos/tools/tools.mak Thu Nov 30 00:08:15 2006
@@ -59,4 +59,5 @@
 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




More information about the Ros-diffs mailing list