Hi,
I want to just expand the macros in a set of c files from a filelist which are in different directories. I don't want the header files included in the c file to be expanded. I have a perl script which does
gcc -E <infile> -I <path to search for header files> -imacros <infile>
But in this case all the header files in the -I patch are expanded to get the preprocessed output which i don't want!!!
so how to specify the search path for the header files in the 'c' file but at the same time I don't want the header files to be expanded but just macros to be expanded?
Please let me know how to do this?
Please feel free to ask if you need any other info regd my question?
Thanks,
Senthil
Well, the problem is, compilation wouldn't work if those files weren't expanded. But it should be possible to filter the output of those files. I see lots of lines like
# 138 "/usr/include/stdint.h" 3 4
in the preprocessor output documenting where inclusions happen. Assuming all your includes are at the top, the last one of these pseudo-comments defines where the code begins. Just throw away all the output before the last '# 1 "something.h" 3' line.
#!/usr/bin/perl
# Call like ./filtere.pl file1.e file2.e ... and it will output file1.e.out, file2.e.out, ...
while($fname=shift)
{
open(IN,"<$fname") || die("Can't open input file");
open(OUT,">".$fname.".out") || die("Can't open output file");
while($line=<IN>)
{
if($line =~ /^#/)
{
truncate(OUT,0);
seek(OUT,0,SEEK_SET);
}
else { print OUT $line; }
}
close(OUT);
close(IN);
}