Macros expanded output of c files


 
Thread Tools Search this Thread
Top Forums Programming Macros expanded output of c files
# 1  
Old 09-15-2006
Java Macros expanded output of c files

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
# 2  
Old 09-15-2006
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
Code:
# 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.
Code:
#!/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);
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Wild char getting expanded in echo

Hi All, I am having a issue in a script. I am trying to execute a select * from a scirpt to a database and printing the the sql string. The * in the sqltring is printing all the files in the directory. How to handle it ? .. .. sql="select * from emp" execute ($sql) echo $sql Here my... (6 Replies)
Discussion started by: arunkumar_mca
6 Replies

2. UNIX for Beginners Questions & Answers

How the home alias (~) is it expanded?

echo $HOME return : /home/user1echo ~ return : /home/user1My_path=~/bin/"some dir1/some dir2" kate "$My_path/some_file"Kate open a file "~/~/bin/some dir1/some dir2/some_file" which does not exists. I was expecting kate to open : "~/bin/some dir1/some dir2/some_file" Any help is welcome. ... (8 Replies)
Discussion started by: jcdole
8 Replies

3. Solaris

zpool hasn't expanded

Hi Guys, I have a raidz zpool that consists of four disks. 2x2TB, 1x1TB and 1x0.75TB. Originally it was only 1x1TB, 3x0.75TB, and I had around 1.7TB of storage capacity. I've just switched out two of the 0.75TB disks for the 2x2TB ones. I did this one at a time and now the resilvering is... (2 Replies)
Discussion started by: rudigarude
2 Replies

4. Shell Programming and Scripting

Macros how-to?

Hi, all I just came to new system with RH, and it has alot of macros I was told to use, but I can't find how to open it for display or for edit, can you help me please, is it all about make/makefile? let say I have macro <trx> like this, that does a lot of things: >$ trx ... creating new... (1 Reply)
Discussion started by: trento17
1 Replies

5. Programming

help with atoi and macros in C

I have a PORT_NUM macro (10 digits long number) in a server file, if i do htons(PORT_NUM) i get warning: this decimal constant is unsigned only in ISO C90 warning: large integer implicitly truncated to unsigned type whats wrong with this? (2 Replies)
Discussion started by: omega666
2 Replies

6. Solaris

war file not expanded (tomcat solaris)

hi .. my example.war file is not expanded in the webapps folder.. could u guide me why the file is not expanded when i restart tomcat... (1 Reply)
Discussion started by: senkerth
1 Replies

7. Shell Programming and Scripting

List file with variables expanded

Hello, I have this problem. I have script file, e.g. #!/usr/bin/ksh echo $MY_DIR ls -lt $MY_DIR I want to list the script but with MY_DIR variable expanded. E.g. MY_DIR=/abc/xyz (in shell MY_DIR is set) So I want to list the script and see: #!/usr/bin/ksh echo /abc/xyz ls... (6 Replies)
Discussion started by: r1omen
6 Replies

8. UNIX for Advanced & Expert Users

Redirect contained in variable not expanded as expected

Hi all, I have a selection of files that contain several commands that write to a file and are started as background processes similar to below. command_to_run_simulator -simulator_arguments > log_file 2>&1 & command_to_run_simulator -simulator_arguments > log_file 2>&1 &... (2 Replies)
Discussion started by: noose
2 Replies

9. Linux

What are the meaning of these macros..

Masters, I am trying to learn the serial mouse driver for linux kernel. On the kernel source tree I find out these macros and I am unable to find out the meaning of these macros. Please anyone help me to understand these. These macros are defined in linux/serio.h... (2 Replies)
Discussion started by: iamjayanth
2 Replies

10. UNIX for Dummies Questions & Answers

troff macros

Hi, I'm going write a small handbook. The typesetting software I'm going to use is troff. There are -ms -me -mm macros for troff. Which one is the most suitable? Thanks! -Tony (2 Replies)
Discussion started by: tonyt
2 Replies
Login or Register to Ask a Question