Source

LIME / lib / nvp2cpp.awk

Full commit
#!/usr/bin/awk -f
##################################################################
# AWK script to convert name=value pairs into a C header
#
#Copyright (C) 2008 NXP Semiconductors B.V.
#
#This file is part of LIME.
#
#LIME is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License version 2
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.
#
#LIME is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with LIME.  If not, see <http://www.gnu.org/licenses/>.
##################################################################

BEGIN { FS="=" }

/^#/ 	{ print "/*" substr($0,2),"*/"
	  next
}

$2 ~ /^[[:digit:]]+$/ || $2 ~ /^0[xX][[:xdigit:]]+$/ {
	  define($1,$2)
	  next
}

{ define($1,$2) }

func define(n,v) {
	  print "#ifndef",n
	  if (v!="") print "#define",n,v
	  else print "#undef",n
	  print "#endif"
}