Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for "output discrepancy if file already exists" (Issue #12) #14

Merged
merged 3 commits into from
Jun 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions make2graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <unistd.h>
#include <errno.h>
#include <getopt.h>
#include <assert.h>

/* version */
#define M2G_VERSION "1.5.0"
Expand Down Expand Up @@ -176,8 +177,10 @@ static char* targetLabel(GraphPtr g,const char* s)
}

/** read line character by character */
static char* readline(FILE* in)
static char* readline(FILE* in, size_t* level)
{
assert(level);
*level= 0UL;
int c;
char* p=NULL;
size_t len=0UL;
Expand All @@ -192,6 +195,10 @@ static char* readline(FILE* in)
{
p[len++]=c;
}
else
{
(*level)++;
}
}
p[len]=0;
return p;
Expand Down Expand Up @@ -231,11 +238,12 @@ static TargetPtr GraphGetTarget(GraphPtr graph,const char* name)
}

/** scan the makefile -nd output */
static void GraphScan(GraphPtr graph,TargetPtr root,FILE* in)
static void GraphScan(GraphPtr graph,TargetPtr root,FILE* in, size_t level)
{
char* line=NULL;
char* makefile_name=NULL;
while((line=readline(in))!=NULL)
size_t iLevel=0UL;
while((line=readline(in, &iLevel))!=NULL)
{
if(startsWith(line,"Considering target file"))
{
Expand All @@ -247,7 +255,8 @@ static void GraphScan(GraphPtr graph,TargetPtr root,FILE* in)
free(tName);
free(line);
//skip lines
while((line=readline(in))!=NULL)
size_t iLevelDump=0UL;
while((line=readline(in, &iLevelDump))!=NULL)
{
if(startsWith(line,"Finished prerequisites of target file "))
{
Expand All @@ -268,10 +277,15 @@ static void GraphScan(GraphPtr graph,TargetPtr root,FILE* in)

TargetPtr child=GraphGetTarget(graph,tName);

// fprintf(stderr, "a: %zu(%s)->%zu(%s)\n", level, root->name, iLevel, tName);
free(tName);

TargetAddChildren(root,child);
GraphScan(graph,child,in);
if(level+1 >= iLevel)
{
TargetAddChildren(root,child);
// fprintf(stderr, "b: %zu(%s)->%zu(%s)\n", level, root->name, iLevel, child->name);
GraphScan(graph,child,in,iLevel+1);
}

}
else if(startsWith(line,"Must remake target "))
Expand All @@ -286,7 +300,7 @@ static void GraphScan(GraphPtr graph,TargetPtr root,FILE* in)
TargetAddChildren(root,GraphGetTarget(graph,tName));
free(tName);
}
else if(startsWith(line,"Finished prerequisites of target file "))
else if(startsWith(line,"Finished prerequisites of target file ") && (level+1 >= iLevel))
{
char* tName=targetName(line);
if(strcmp(tName,root->name)!=0)
Expand Down Expand Up @@ -564,7 +578,7 @@ int main(int argc,char** argv)
app->root=GraphGetTarget(app,"<ROOT>");
if(optind==argc)
{
GraphScan(app,app->root,stdin);
GraphScan(app,app->root,stdin,0);
}
else if(optind+1==argc)
{
Expand All @@ -574,7 +588,7 @@ int main(int argc,char** argv)
fprintf(stderr,"Cannot open \"%s\" : \"%s\".\n",argv[optind],strerror(errno));
return EXIT_FAILURE;
}
GraphScan(app,app->root,in);
GraphScan(app,app->root,in,0);
fclose(in);
}
else
Expand Down