1166124Srafan############################################################################## 2174993Srafan# Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. # 3166124Srafan# # 4166124Srafan# Permission is hereby granted, free of charge, to any person obtaining a # 5166124Srafan# copy of this software and associated documentation files (the "Software"), # 6166124Srafan# to deal in the Software without restriction, including without limitation # 7166124Srafan# the rights to use, copy, modify, merge, publish, distribute, distribute # 8166124Srafan# with modifications, sublicense, and/or sell copies of the Software, and to # 9166124Srafan# permit persons to whom the Software is furnished to do so, subject to the # 10166124Srafan# following conditions: # 11166124Srafan# # 12166124Srafan# The above copyright notice and this permission notice shall be included in # 13166124Srafan# all copies or substantial portions of the Software. # 14166124Srafan# # 15166124Srafan# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # 16166124Srafan# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # 17166124Srafan# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # 18166124Srafan# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # 19166124Srafan# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # 20166124Srafan# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # 21166124Srafan# DEALINGS IN THE SOFTWARE. # 22166124Srafan# # 23166124Srafan# Except as contained in this notice, the name(s) of the above copyright # 24166124Srafan# holders shall not be used in advertising or otherwise to promote the sale, # 25166124Srafan# use or other dealings in this Software without prior written # 26166124Srafan# authorization. # 27166124Srafan############################################################################## 28174993Srafan# $Id: MKcaptab.awk,v 1.20 2007/08/12 00:26:15 tom Exp $ 29174993Srafanfunction add_string(text) { 30174993Srafan if (text != "IGNORE") { 31174993Srafan offsets[num_strings] = offset; 32174993Srafan offset = offset + length(text) + 1; 33174993Srafan printf "%s\\0", text; 34174993Srafan } else { 35174993Srafan offsets[num_strings] = -1; 36174993Srafan } 37174993Srafan num_strings = num_strings + 1; 38174993Srafan if ((num_strings % 3) == 0) { 39174993Srafan printf "\\\n"; 40174993Srafan } 41174993Srafan return offsets[num_strings - 1]; 42174993Srafan} 43174993SrafanBEGIN { 44174993Srafan first = 1; 45174993Srafan num_aliases = 0; 46174993Srafan num_strings = 0; 47174993Srafan offset = 0; 48174993Srafan} 4950276Speter 50174993Srafan/^[^#]/ { 51174993Srafan if (first) { 52174993Srafan printf "/* generated by MKcaptab.awk %s(%d) */\n", tablename, bigstrings; 53174993Srafan print "" 54174993Srafan if (bigstrings) { 55174993Srafan printf "static struct alias *_nc_%s_table = 0;\n", tablename; 56174993Srafan print ""; 57174993Srafan printf "static const char %s_text[] = \"\\\n", tablename; 58174993Srafan } else { 59174993Srafan printf "static const struct alias _nc_%s_table[] =\n", tablename; 60174993Srafan printf "{\n"; 6150276Speter } 62174993Srafan first = 0; 63174993Srafan } 64174993Srafan if ($1 == tablename) { 65174993Srafan if ($3 == "IGNORE") { 66174993Srafan to = "(char *)NULL"; 67174993Srafan } else { 68174993Srafan to = "\"" $3 "\""; 6950276Speter } 70174993Srafan if (bigstrings) { 71174993Srafan c1 = add_string($2); 72174993Srafan c2 = add_string($3); 73174993Srafan c3 = add_string($4); 74174993Srafan aliases[num_aliases] = sprintf("\t{%5d, %5d, %5d},\t /* %s */", c1, c2, c3, $5); 75174993Srafan num_aliases = num_aliases + 1; 76174993Srafan } else { 77174993Srafan printf "\t{\"%s\", %s, \"%s\"},\t /* %s */\n", $2, to, $4, $5; 78174993Srafan } 79174993Srafan } 80174993Srafan } 81174993SrafanEND { 82174993Srafan if (bigstrings) { 83174993Srafan printf "\";\n\n"; 84174993Srafan printf "static const alias_table_data %s_data[] = {\n", tablename; 85174993Srafan for (n = 0; n < num_aliases; ++n) { 86174993Srafan printf "%s\n", aliases[n]; 87174993Srafan } 88174993Srafan printf "};\n\n"; 89174993Srafan } else { 90174993Srafan printf "\t{(char *)NULL, (char *)NULL, (char *)NULL}\n"; 91174993Srafan printf "};\n\n"; 92174993Srafan } 93174993Srafan } 94174993Srafan# vile:sw=4: 95