3 * reactos/iface/dll/defedf.c
5 * ReactOS Operating System
7 * Convert a *.def file for a PE image into an *.edf file,
8 * to build the PE image with a clean exports table.
10 * Written by EA (19990703)
18 # define MAX_PATH PATH_MAX
20 # define MAX_PATH _MAX_PATH
25 #define INPUT_BUFFER_SIZE 1024
29 static const char * SUFFIX_DEF = ".def";
30 static const char * SUFFIX_EDF = ".edf";
34 Usage ( const char * ImageName )
38 "Usage: %s def_file [edf_file]\n",
47 const char * Prototype,
51 char NewName [MAX_PATH];
54 if (!Prototype) return NULL;
55 strcpy( NewName, Prototype );
60 if (strcmp(SuffixStart,Suffix))
62 strcat(NewName, Suffix);
64 return strdup(NewName);
76 char NewName [MAX_PATH];
79 strcpy( NewName, NameDef );
80 Dot = strrchr( NewName, '.');
81 if (0 == strcmp(Dot, SUFFIX_DEF))
85 return AddSuffix( NewName, SUFFIX_EDF );
87 return AddSuffix( NameEdf, SUFFIX_EDF );
100 // LineSymbolFastcall,
116 r = strrchr( InputBuffer, '\n' );
119 printf("ParseInput(%s)\n",InputBuffer);
121 if (0 == strlen(InputBuffer))
124 printf("LineEmpty\n");
129 * Skip blanks and tabs.
134 && (*InputBuffer == ' ')
135 && (*InputBuffer == '\t')
140 printf("1st=\"%c\" (%d)\n", *InputBuffer, (int) *InputBuffer );
145 strcpy( InputBuffer, r );
147 printf("LineComment\n");
151 r = strchr( InputBuffer, '=' );
154 printf( "Fatal error: can not process DEF files with aliases!\n");
157 r = strchr( InputBuffer, '@' );
160 strcpy( CleanName, InputBuffer );
161 r = strchr( CleanName, '@' );
164 printf("LineSymbol: \"%s\"=\"%s\"\n",InputBuffer,CleanName);
168 /* can not recognize it; copy it verbatim */
170 printf("LineComment\n");
178 const char * ImageName,
185 char InputBuffer [INPUT_BUFFER_SIZE];
192 fDef = fopen( Def, "r" );
197 "%s: could not open \"%s\"\n",
203 fEdf = fopen( Edf, "w" );
208 "%s: could not create \"%s\"\n",
214 while ( fgets( InputBuffer, sizeof InputBuffer, fDef ) )
216 char CleanName [MAX_PATH];
218 switch (ParseInput(InputBuffer,CleanName))
221 fprintf(fEdf,"%s\n",InputBuffer);
225 fprintf(fEdf,"EXPORTS\n");
229 fprintf(fEdf,"IMPORTS\n");
274 if ((argc != 2) && (argc != 3))
276 return Usage(argv[0]);
286 "%s: can not build the def_file name\n",
291 NameEdf = MakeEdfName(
299 "%s: can not build the edf_file name\n",