Skip to content

Commit

Permalink
"
Browse files Browse the repository at this point in the history
git-svn-id: https://codelite.svn.sourceforge.net/svnroot/codelite/trunk@1043 9da81c78-c036-0410-9e1f-a2b0375e4b5a
  • Loading branch information
eranif committed Feb 1, 2008
1 parent bc1fb14 commit 94cb75f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 74 deletions.
19 changes: 12 additions & 7 deletions MakefileParser/MakefileImporter.project
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<File Name="makefile_lexer.h"/>
<File Name="makefile_parser.cpp"/>
</VirtualDirectory>
<Dependencies/>
<Settings Type="Executable">
<Configuration Name="DebugUnicode" CompilerType="gnu g++" DebuggerType="GNU gdb debugger">
<General OutputFile="./MakefileImporter" IntermediateDirectory="./DebugUnicode" Command="./MakefileImporter" CommandArguments="" WorkingDirectory="./"/>
Expand Down Expand Up @@ -56,12 +55,18 @@
<CustomBuild Enabled="no">
<CleanCommand></CleanCommand>
<BuildCommand></BuildCommand>
<WorkingDirectory></WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild></CustomPostBuild>
<CustomPreBuild>
<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

makefile_lexer.cpp: makefile_parser.l
flex -L makefile_parser.l
mv lex.yy.c makefile_lexer.cpp
</CustomPreBuild>
</AdditionalRules>
</Configuration>
Expand Down Expand Up @@ -93,11 +98,12 @@
<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 @@ -131,7 +137,6 @@
<CustomBuild Enabled="no">
<CleanCommand></CleanCommand>
<BuildCommand></BuildCommand>
<WorkingDirectory></WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild></CustomPostBuild>
Expand Down Expand Up @@ -177,12 +182,12 @@ makefile_lexer.cpp: makefile_parser.l
<CustomBuild Enabled="no">
<CleanCommand></CleanCommand>
<BuildCommand></BuildCommand>
<WorkingDirectory></WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild></CustomPostBuild>
<CustomPreBuild></CustomPreBuild>
</AdditionalRules>
</Configuration>
</Settings>
<Dependencies/>
</CodeLite_Project>
4 changes: 2 additions & 2 deletions MakefileParser/VariableLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Strings TheUnmatched;
Strings TheError;
Tokens TheTokens;

VariableLexer::VariableLexer(wxString path)
VariableLexer::VariableLexer(const char* path)
{
initLexer(path.mb_str());
initLexer(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(wxString path);
VariableLexer(const char* path);

const wxArrayString& getResult();
const wxArrayString& getUnmatched();
Expand Down
46 changes: 1 addition & 45 deletions MakefileParser/input
Original file line number Diff line number Diff line change
@@ -1,45 +1 @@
Lorem
Lorem ipsum ya
teset = bla
$(teset)
bla = jajaaaaja
rot hihi = okeedan
bok = rot
bla rot = lol
rot = vijf
blarot = hihi
rothihi = replaced
test = yoyo
name = eran
doeswork = fiex!
first = 1
bsecond = 2b
bthird = 3b
yarr = pirate
forwarding = gogogo
Lorem ipsum
Ik zou wel is willen weten wat bla nou is
test een twee $(bla) drie vier $(bok) vijf zes zeven acht
test $($(bok) $(bla$(bok))) twee drie
a = een
b = twee
c = drie
d = vier
eentweedrievier = bijna gelukt
een twee drie vier = gelukt
$($(a) $(b) $(c) $(d))
I say $(test) tataa
bla = sex
lol = haha
Hatste flats van te meen
hohum=$(bla)
$(yarr)
$(yarr shiver me timbers je $(weet wel toch ja nee ) hearties yoho)
the power of $(forwarding) is yet unknown
to most $(name) here.
Now see if $(doeswork) yes
^^--
$(first)
asecond $(bsecond)
athird $(bthird) cthird
first second third fourth fifth
Lorem
49 changes: 43 additions & 6 deletions MakefileParser/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,57 @@
#include "makefile_lexer.h"
#include "VariableLexer.h"
#include "stdio.h"
#include "errno.h"

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

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[])
{

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

VariableLexer lexer(path);
path = "input";

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

//release the input data
free(data);

wxArrayString result = lexer.getResult();
wxArrayString unmatched = lexer.getUnmatched();
wxArrayString error = lexer.getError();
Expand Down
14 changes: 3 additions & 11 deletions MakefileParser/makefile_parser.l
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,10 @@ word [0-9a-zA-Z_.\-+\*~:\\@&/|%\<\>,\'^ \t]+
%%


void initLexer(const char *fileName)
void initLexer(const char *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);
BEGIN INITIAL;
yy_scan_string(data);
}

int yywrap()
Expand Down
6 changes: 4 additions & 2 deletions MakefileParser/makefileimporter.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "precompiled_header.h"
#include "makefileimporter.h"
#include <wx/xrc/xmlres.h>
#include "workspace.h"
Expand Down Expand Up @@ -151,8 +152,9 @@ void MakefileImporter::ImportFromMakefile(const wxString &path)

wxFileName fileName = path;
LogMessage(fileName.GetPath() + wxT("\n"));

VariableLexer expander(path);

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

MakefileParser parser(expanded);
Expand Down

0 comments on commit 94cb75f

Please sign in to comment.