Skip to content

Commit

Permalink
pipe-tool: added command line parameter -resnames, which generates fi…
Browse files Browse the repository at this point in the history
…le MAHeaders.cpp with string name to resource mappings
  • Loading branch information
vedran- committed Apr 2, 2012
1 parent 2936239 commit 83d2c56
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
35 changes: 35 additions & 0 deletions tools/pipe-tool/Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ int main(int argc,char *argv[])
continue;
}

if (Token("resnames"))
{
Do_WriteResNames = 1;
continue;
}

if (Token("gcj="))
{
GetCmdString();
Expand Down Expand Up @@ -750,6 +756,7 @@ Build application (-B) options:\n\
\n\
Resource compiler (-R) options:\n\
-depend=file output dependencies in makefile syntax\n\
-resnames create MAHeaders.cpp with string to resource mappings\n\
\n\
Librarian (-L) options:\n\
-quiet don't display the component files\n\
Expand Down Expand Up @@ -1089,6 +1096,22 @@ void MainRes(char *input, char *output)
ExitApp(1);
}

if(Do_WriteResNames)
{
if ((ResNamesFile = fopen("MAHeaders.cpp","w") ) == NULL)
{
if (AsmMsg)
printf("Error : Problem creating 'MAHeaders.cpp' file\n");

fclose(CodeFile);
fclose(HeaderFile);
ExitApp(1);
}
fprintf( ResNamesFile, "#include <ma.h>\n\
#include \"MAHeaders.h\"\n\n\
int GetResourceID( const char *resourceName )\n{\n" );
}

if(Do_Export_Dependencies)
{
if ((DependFile = fopen(DependName,"w") ) == NULL)
Expand All @@ -1098,6 +1121,7 @@ void MainRes(char *input, char *output)

fclose(CodeFile);
fclose(HeaderFile);
if(Do_WriteResNames) fclose(ResNamesFile);
ExitApp(1);
}
fprintf(DependFile, "%s: \\\n", output);
Expand All @@ -1112,8 +1136,19 @@ void MainRes(char *input, char *output)
ResourceMain();
}

if (Do_WriteResNames && ResNamesFile)
{
fprintf(ResNamesFile, " return -1;\n}");
fclose(ResNamesFile);
printf("Created MAHeaders.cpp with string to resource mappings\n");
}

if (HeaderFile)
{
if (Do_WriteResNames)
fprintf( HeaderFile, "\nint GetResourceID( const char *resourceName );\n" );
fclose(HeaderFile);
}

if (CodeFile)
fclose(CodeFile);
Expand Down
2 changes: 2 additions & 0 deletions tools/pipe-tool/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,8 @@ decset(FILE *DependFile, NULL)
dec(FILE *InFile)
dec(FILE *CodeFile)
dec(FILE *HeaderFile)
decset(int Do_WriteResNames, 0)
dec(FILE *ResNamesFile)

dec(short DEBUG)
dec(short LIST)
Expand Down
14 changes: 10 additions & 4 deletions tools/pipe-tool/rescomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,12 @@ short ResourceCommands()

infoprintf("%d: index = %d ('%s')\n",IndexCount, IndexOffset, Name);

if (Pass == 2)
if (Name[0])
fprintf(HeaderFile,"#define idx_%s %d\n", Name, IndexCount);
if( Pass == 2 && Name[0] )
{
fprintf(HeaderFile,"#define idx_%s %d\n", Name, IndexCount);
if( Do_WriteResNames )
fprintf(ResNamesFile," if( strcmp( resName, \"idx_%s\" ) == 0 ) return idx_%s;\n", Name, Name);
}

IndexCount++;
return 1;
Expand Down Expand Up @@ -1520,8 +1523,11 @@ void FinalizeResource()
if (Pass == 2)
{
if (ResName[0])
{
fprintf(HeaderFile,"#define %s %d\n", ResName, CurrentResource);
else
if( Do_WriteResNames )
fprintf(ResNamesFile," if( strcmp( resourceName, \"%s\" ) == 0 ) return %s;\n", ResName, ResName);
} else
fprintf(HeaderFile,"//not defined %d\n", CurrentResource);
}

Expand Down

0 comments on commit 83d2c56

Please sign in to comment.