The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-20-2009
gjbanton gjbanton is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 2
Sed question

Hi All,

Let's say I have a C file such as follows:

Code:
#include <stdio.h>

#if DEFINED 
#define EFG 1
int foo()
{
    return 0;
}

// comment here
/* comment here */
#elif _NOT_DEFINED
#define ABC 0
int boo()
{
    return 0;
}

#else
void zoo()
{
    // nothing here
}
#endif 

int main()
{
    return 0;
}
Using sed (or any other widely used scripting tool), I want to modify the C file to look something like this:

Code:
#include <stdio.h>

#if DEFINED 
#define EFG 1
int foo()
{
    return 0;
}

// comment here
/* comment here */
#endif 

int main()
{
    return 0;
}
Basically, I want to remove the code that falls under _NOT_DEFINED or else blocks (equivalent of #if 0 blocks). Any ideas?

Thanks in advance.
  #2 (permalink)  
Old 04-21-2009
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Why dont you use the C Processor utility i.e. cpp. Look at man cpp for more details.

Code:
/usr/bin/cpp -D DEFINED main.cpp
This would print out the contents of stdio.h as well.
  #3 (permalink)  
Old 04-21-2009
gjbanton gjbanton is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 2
Unfortunately this is not the option for me. Preprocessing option is not feasible due to cross-compilation and modular build, hence I have to resort to scripting.
Closed Thread

Bookmarks

Tags
block, delete, ifdef, sed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0