Skip to content

Commit

Permalink
Reverted most changes. (Except ofcourse the bug)
Browse files Browse the repository at this point in the history
git-svn-id: https://codelite.svn.sourceforge.net/svnroot/codelite/trunk@1050 9da81c78-c036-0410-9e1f-a2b0375e4b5a
  • Loading branch information
srabbelier committed Feb 1, 2008
1 parent 01442c3 commit f4c7187
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 77 deletions.
21 changes: 10 additions & 11 deletions MakefileParser/MakefileImporter.project
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<Settings Type="Executable">
<Configuration Name="DebugUnicode" CompilerType="gnu g++" DebuggerType="GNU gdb debugger">
<General OutputFile="./MakefileImporter" IntermediateDirectory="./DebugUnicode" Command="./MakefileImporter" CommandArguments="" WorkingDirectory="./"/>
<Compiler Required="yes" Options="-g;$(shell wx-config --cxxflags --debug=yes --unicode=yes);-Wall">
<Compiler Required="yes" Options="-g;$(shell wx-config --cxxflags --debug=yes --unicode=yes)">
<IncludePath Value="."/>
<IncludePath Value="../../trunk/Interfaces"/>
<IncludePath Value="../../trunk/CodeLite"/>
Expand All @@ -55,23 +55,17 @@
<CustomBuild Enabled="no">
<CleanCommand></CleanCommand>
<BuildCommand></BuildCommand>
<WorkingDirectory></WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild></CustomPostBuild>
<CustomPreBuild>makefile_parser.cpp makefile_lexer.cpp
makefile_parser.cpp: makefile_parser.y
yacc -dl -t -v makefile_parser.y
mv y.tab.c makefile_parser.cpp
mv y.tab.h makefile_lexer.h
<CustomPreBuild>

makefile_lexer.cpp: makefile_parser.l
flex -L makefile_parser.l
mv lex.yy.c makefile_lexer.cpp
</CustomPreBuild>
</AdditionalRules>
</Configuration>
<Configuration Name="ReleaseUnicode" CompilerType="gnu g++" DebuggerType="GNU gdb debugger">
<General OutputFile="$(ConfigurationName)/MakefileImporter.so" IntermediateDirectory="./ReleaseUnicode" Command="" CommandArguments="" WorkingDirectory="./ReleaseUnicode"/>
<General OutputFile="./MakefileImporter" IntermediateDirectory="./ReleaseUnicode" Command="./MakefileImporter" CommandArguments="" WorkingDirectory="./"/>
<Compiler Required="yes" Options="$(shell wx-config --cxxflags --debug=no --unicode=yes); -O2">
<IncludePath Value="."/>
<IncludePath Value="../../trunk/Interfaces"/>
Expand All @@ -98,10 +92,13 @@ makefile_lexer.cpp: makefile_parser.l
<CustomBuild Enabled="no">
<CleanCommand></CleanCommand>
<BuildCommand></BuildCommand>
<WorkingDirectory></WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild></CustomPostBuild>
<CustomPreBuild></CustomPreBuild>
<CustomPreBuild>

</CustomPreBuild>
</AdditionalRules>
</Configuration>
<Configuration Name="WinDebugUnicode" CompilerType="gnu g++" DebuggerType="GNU gdb debugger">
Expand Down Expand Up @@ -135,6 +132,7 @@ makefile_lexer.cpp: makefile_parser.l
<CustomBuild Enabled="no">
<CleanCommand></CleanCommand>
<BuildCommand></BuildCommand>
<WorkingDirectory></WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild></CustomPostBuild>
Expand Down Expand Up @@ -180,6 +178,7 @@ makefile_lexer.cpp: makefile_parser.l
<CustomBuild Enabled="no">
<CleanCommand></CleanCommand>
<BuildCommand></BuildCommand>
<WorkingDirectory></WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild></CustomPostBuild>
Expand Down
9 changes: 5 additions & 4 deletions MakefileParser/VariableLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
#include <wx/log.h>
#include <wx/string.h>

extern void initLexer(const char *filename);

#define YYSTYPE std::string

extern void initLexer(const char *filename);
extern int yyparse();

typedef std::vector<std::string> Strings;
Expand All @@ -23,9 +22,11 @@ Strings TheUnmatched;
Strings TheError;
Tokens TheTokens;

VariableLexer::VariableLexer(const char* path)
VariableLexer::VariableLexer(const wxString& path)
{
initLexer(path);
const wxCharBuffer pathBuffer = path.ToAscii();
const char *cstr_path = pathBuffer.data();
initLexer(cstr_path);
yyparse();

for(IStrings it = TheOutput.begin(); it != TheOutput.end(); it++)
Expand Down
2 changes: 1 addition & 1 deletion MakefileParser/VariableLexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class WXDLLIMPEXP_LE_SDK VariableLexer
{
public:
VariableLexer(const char* path);
VariableLexer(const wxString& path);

const wxArrayString& getResult();
const wxArrayString& getUnmatched();
Expand Down
54 changes: 7 additions & 47 deletions MakefileParser/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,20 @@
#include "makefile_lexer.h"
#include "VariableLexer.h"
#include "stdio.h"
#include "errno.h"

typedef std::map<wxString, wxString> Tokens;
typedef Tokens::iterator ITokens;

extern void initLexer(const char *filename);
extern int yyparse();

char *loadFile(const char *fileName)
{
FILE *fp;
long len;
char *buf = NULL;

fp = fopen(fileName, "rb");
if (!fp) {
printf("failed to open file 'test.h': %s\n", strerror(errno));
return NULL;
}

//read the whole file
fseek(fp, 0, SEEK_END); //go to end
len = ftell(fp); //get position at end (length)
fseek(fp, 0, SEEK_SET); //go to begining
buf = (char *)malloc(len+1); //malloc buffer

//read into buffer
long bytes = fread(buf, sizeof(char), len, fp);
printf("read: %ld\n", bytes);
if (bytes != len) {
fclose(fp);
printf("failed to read from file 'test.h': %s\n", strerror(errno));
return NULL;
}

buf[len] = 0; // make it null terminated string
fclose(fp);
return buf;
}

int main(int argv, char* argc[])
{
char* path(NULL);

wxString path;
if(argv>1)
path = argc[1];
path = _U(argc[1]);
else
path = "input";

char *data = loadFile(path);
VariableLexer lexer(data);

//release the input data
free(data);
/*
path = wxT("input");

VariableLexer lexer(path);
wxArrayString result = lexer.getResult();
wxArrayString unmatched = lexer.getUnmatched();
wxArrayString error = lexer.getError();
Expand Down Expand Up @@ -87,6 +47,6 @@ int main(int argv, char* argc[])
}

fprintf(of, "=============== DONE =============\n");
fclose(of);*/
fclose(of);
return 0;
}
22 changes: 13 additions & 9 deletions MakefileParser/makefile_lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,12 +669,6 @@ YY_RULE_SETUP
return WORD;
}
YY_BREAK
case YY_STATE_EOF(INITIAL):
{
//reset lexer
yyterminate();
}
YY_BREAK
case 10:
YY_RULE_SETUP
{
Expand All @@ -685,6 +679,8 @@ case 11:
YY_RULE_SETUP
ECHO;
YY_BREAK
case YY_STATE_EOF(INITIAL):
yyterminate();

case YY_END_OF_BUFFER:
{
Expand Down Expand Up @@ -1571,10 +1567,18 @@ int main()



void initLexer(const char *data)
void initLexer(const char *fileName)
{
BEGIN INITIAL;
yy_scan_string(data);
FILE *file = fopen(fileName, "r");
if(!file)
{
printf("failed loading file 'test.h'\n");
exit(-1);
}

//set the file to be our buffer
YY_BUFFER_STATE buffState = yy_create_buffer(file, YY_BUF_SIZE);
yy_switch_to_buffer(buffState);
}

int yywrap()
Expand Down
14 changes: 11 additions & 3 deletions MakefileParser/makefile_parser.l
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,18 @@ word [0-9a-zA-Z_.\-+\*~:\\@&/|%\<\>,\'^ \t]+
%%


void initLexer(const char *data)
void initLexer(const char *filename)
{
BEGIN INITIAL;
yy_scan_string(data);
FILE *file = fopen(fileName, "r");
if(!file)
{
printf("failed loading file 'test.h'\n");
exit(-1);
}

//set the file to be our buffer
YY_BUFFER_STATE buffState = yy_create_buffer(file, YY_BUF_SIZE);
yy_switch_to_buffer(buffState);
}

int yywrap()
Expand Down
3 changes: 1 addition & 2 deletions MakefileParser/makefileimporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ void MakefileImporter::ImportFromMakefile(const wxString &path)
wxFileName fileName = path;
LogMessage(fileName.GetPath() + wxT("\n"));

const wxCharBuffer _path = _C(path);
VariableLexer expander(_path.data());
VariableLexer expander(path.data());
wxArrayString expanded = expander.getResult();

MakefileParser parser(expanded);
Expand Down

0 comments on commit f4c7187

Please sign in to comment.