Monday, June 11, 2007

Turn pseudo-enums expressed as #defines into strings.

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 $1 | awk '/#define/{
print "\t\tcase " $2 ":";
print "\t\t\tfprintf(out_csv_fp,\"," $2 "\");";
print "\t\t\tbreak;";
}' > out.txt

Labels:

0 Comments:

Post a Comment

<< Home