Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
09-21-2007, 09:45 PM
|
#1
|
|
LQ Newbie
Registered: Jan 2006
Location: Australia
Distribution: Fedora Core 4 and Cygwin
Posts: 14
Rep:
|
Need to extract name of C variable from C declaration.
Hi everyone,
I only want the name of the declared variable. Everything else is not important to me:
char x[50]; //ANS:x
int y; //ANS:y
char z; //ANS:z
int (*f)(double); //ANS:y
union un u; //ANS:u
struct x y; //ANS:y
struct w w[25]; //ANS:w
struct z z; //ANS:z
double c; //ANS:c
Can somebody give me some shell or C code or Perl which extracts the name of a C variable from an arbitrary input? The above are only examples.
Thanks.
|
|
|
|
09-22-2007, 07:19 AM
|
#2
|
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530
Rep: 
|
What is the input? C source code file? or an binary executable file?
|
|
|
|
09-22-2007, 11:21 AM
|
#3
|
|
Senior Member
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 3,958
|
Shouldn't the answer to your fourth entry (the function pointer) be "f," not "y?"
If you're parsing source code, awk is an easy language to use to do the parsing.
But, if you want to get a little more sophisticated, look at yacc to generate a C program to parse it all out for you, or, if you're masochistic, look at the parser in the g++ source code tree.
|
|
|
|
09-22-2007, 12:46 PM
|
#4
|
|
HCL Maintainer
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450
Rep:
|
Quote:
Originally Posted by PTrenholme
But, if you want to get a little more sophisticated, look at yacc to generate a C program to parse it all out for you, or, if you're masochistic, look at the parser in the g++ source code tree.
|
You might also take a look at ctags or something else that does the brunt of the work for you.
|
|
|
|
| Thread Tools |
Search 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
HTML code is Off
|
|
|
All times are GMT -5. The time now is 08:02 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|