Tech Space

Experiencing Tech as a Professional Techie

Turn pseudo-enums expressed as #defines into strings.

Posted on | June 10, 2007 | View Comments

I have an include file that has 50+ #defines with constants (0,1,2,3,…,etc). I have a dump program to dump the data structure that these #defines are used in into a .csv file. I used this little script to dump case statements out for the #defines, with readable strings instead of arbitrary constant values.

cat | awk '/#define/{
print "\t\tcase " ":";
print "\t\t\tfprintf(out_csv_fp,\"," "\");";
print "\t\t\tbreak;";
}' > out.txt
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • StumbleUpon
  • Tumblr
  • TwitThis
  • FriendFeed
  • Netvibes
  • Ping.fm
  • Posterous
  • Technorati
  • Tipd
  • Twitter
  • Yahoo! Buzz

Comments

blog comments powered by Disqus