15796c8dcSSimon Schubert#!/bin/sh 25796c8dcSSimon Schubert 35796c8dcSSimon Schubert# Convert text files to compilable C arrays. 45796c8dcSSimon Schubert# 5*ef5ccd6cSJohn Marino# Copyright (C) 2007-2013 Free Software Foundation, Inc. 65796c8dcSSimon Schubert# 75796c8dcSSimon Schubert# This file is part of GDB. 85796c8dcSSimon Schubert# 95796c8dcSSimon Schubert# This program is free software; you can redistribute it and/or modify 105796c8dcSSimon Schubert# it under the terms of the GNU General Public License as published by 115796c8dcSSimon Schubert# the Free Software Foundation; either version 3 of the License, or 125796c8dcSSimon Schubert# (at your option) any later version. 135796c8dcSSimon Schubert# 145796c8dcSSimon Schubert# This program is distributed in the hope that it will be useful, 155796c8dcSSimon Schubert# but WITHOUT ANY WARRANTY; without even the implied warranty of 165796c8dcSSimon Schubert# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 175796c8dcSSimon Schubert# GNU General Public License for more details. 185796c8dcSSimon Schubert# 195796c8dcSSimon Schubert# You should have received a copy of the GNU General Public License 205796c8dcSSimon Schubert# along with this program. If not, see <http://www.gnu.org/licenses/>. 215796c8dcSSimon Schubert 225796c8dcSSimon Schubertoutput=$1 235796c8dcSSimon Schubertshift 245796c8dcSSimon Schubert 255796c8dcSSimon Schubertif test -z "$output" || test -z "$1"; then 265796c8dcSSimon Schubert echo "Usage: $0 OUTPUTFILE INPUTFILE..." 275796c8dcSSimon Schubert exit 1 285796c8dcSSimon Schubertfi 295796c8dcSSimon Schubert 305796c8dcSSimon Schubertif test -e "$output"; then 315796c8dcSSimon Schubert echo "Output file \"$output\" already exists; refusing to overwrite." 325796c8dcSSimon Schubert exit 1 335796c8dcSSimon Schubertfi 345796c8dcSSimon Schubert 355796c8dcSSimon Schubertfor input; do 365796c8dcSSimon Schubert arrayname=xml_feature_`echo $input | sed 's,.*/,,; s/[-.]/_/g'` 375796c8dcSSimon Schubert 385796c8dcSSimon Schubert ${AWK:-awk} 'BEGIN { n = 0 395796c8dcSSimon Schubert print "static const char '$arrayname'[] = {" 405796c8dcSSimon Schubert for (i = 0; i < 255; i++) 415796c8dcSSimon Schubert _ord_[sprintf("%c", i)] = i 425796c8dcSSimon Schubert } { 435796c8dcSSimon Schubert split($0, line, ""); 445796c8dcSSimon Schubert printf " " 455796c8dcSSimon Schubert for (i = 1; i <= length($0); i++) { 465796c8dcSSimon Schubert c = line[i] 475796c8dcSSimon Schubert if (c == "'\''") { 485796c8dcSSimon Schubert printf "'\''\\'\'''\'', " 495796c8dcSSimon Schubert } else if (c == "\\") { 505796c8dcSSimon Schubert printf "'\''\\\\'\'', " 515796c8dcSSimon Schubert } else if (_ord_[c] >= 32 && _ord_[c] < 127) { 525796c8dcSSimon Schubert printf "'\''%s'\'', ", c 535796c8dcSSimon Schubert } else { 545796c8dcSSimon Schubert printf "'\''\\%03o'\'', ", _ord_[c] 555796c8dcSSimon Schubert } 565796c8dcSSimon Schubert if (i % 10 == 0) 575796c8dcSSimon Schubert printf "\n " 585796c8dcSSimon Schubert } 595796c8dcSSimon Schubert printf "'\''\\n'\'', \n" 605796c8dcSSimon Schubert } END { 615796c8dcSSimon Schubert print " 0 };" 625796c8dcSSimon Schubert }' < $input >> $output 635796c8dcSSimon Schubertdone 645796c8dcSSimon Schubert 655796c8dcSSimon Schubertecho >> $output 665796c8dcSSimon Schubertecho "const char *const xml_builtin[][2] = {" >> $output 675796c8dcSSimon Schubert 685796c8dcSSimon Schubertfor input; do 695796c8dcSSimon Schubert basename=`echo $input | sed 's,.*/,,'` 705796c8dcSSimon Schubert arrayname=xml_feature_`echo $input | sed 's,.*/,,; s/[-.]/_/g'` 715796c8dcSSimon Schubert echo " { \"$basename\", $arrayname }," >> $output 725796c8dcSSimon Schubertdone 735796c8dcSSimon Schubert 745796c8dcSSimon Schubertecho " { 0, 0 }" >> $output 755796c8dcSSimon Schubertecho "};" >> $output 76