1/* Copyright (C) 1999-2001, 2003, 2005 Free Software Foundation, Inc. 2 This file is part of the GNU LIBICONV Library. 3 4 The GNU LIBICONV Library is free software; you can redistribute it 5 and/or modify it under the terms of the GNU Library General Public 6 License as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 The GNU LIBICONV Library is distributed in the hope that it will be 10 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Library General Public License for more details. 13 14 You should have received a copy of the GNU Library General Public 15 License along with the GNU LIBICONV Library; see the file COPYING.LIB. 16 If not, write to the Free Software Foundation, Inc., 51 Franklin Street, 17 Fifth Floor, Boston, MA 02110-1301, USA. */ 18 19/* Creates the aliases.gperf table. */ 20 21#include <stdio.h> 22#include <stdlib.h> 23 24static void emit_encoding (FILE* out1, FILE* out2, const char* const* names, size_t n, const char* c_name) 25{ 26 fprintf(out2,"grep 'sizeof(\""); 27 /* Output *names in upper case. */ 28 { 29 const char* s = *names; 30 for (; *s; s++) { 31 unsigned char c = * (unsigned char *) s; 32 if (c >= 0x80) 33 exit(1); 34 if (c >= 'a' && c <= 'z') 35 c -= 'a'-'A'; 36 putc(c, out2); 37 } 38 } 39 fprintf(out2,"\")' tmp.h | sed -e 's|^.*\\(stringpool_str[0-9]*\\).*$| (int)(long)\\&((struct stringpool_t *)0)->\\1,|'\n"); 40 for (; n > 0; names++, n--) { 41 /* Output *names in upper case. */ 42 const char* s = *names; 43 for (; *s; s++) { 44 unsigned char c = * (unsigned char *) s; 45 if (c >= 0x80) 46 exit(1); 47 if (c >= 'a' && c <= 'z') 48 c -= 'a'-'A'; 49 putc(c, out1); 50 } 51 fprintf(out1,", ei_%s\n", c_name); 52 } 53} 54 55int main () 56{ 57 FILE* stdout2; 58 59 printf("struct alias { int name; unsigned int encoding_index; };\n"); 60 printf("%%struct-type\n"); 61 printf("%%language=ANSI-C\n"); 62 printf("%%define hash-function-name aliases_hash\n"); 63 printf("%%define lookup-function-name aliases_lookup\n"); 64 printf("%%7bit\n"); 65 printf("%%readonly-tables\n"); 66 printf("%%global-table\n"); 67 printf("%%define word-array-name aliases\n"); 68 printf("%%pic\n"); 69 printf("%%%%\n"); 70 71#define DEFENCODING(xxx_names,xxx,xxx_ifuncs1,xxx_ifuncs2,xxx_ofuncs1,xxx_ofuncs2) \ 72 { \ 73 static const char* const names[] = BRACIFY xxx_names; \ 74 emit_encoding(stdout,stdout2,names,sizeof(names)/sizeof(names[0]),#xxx); \ 75 } 76#define BRACIFY(...) { __VA_ARGS__ } 77 78 stdout2 = fdopen(3, "w"); 79 if (stdout2 == NULL) 80 exit(1); 81#include "encodings.def" 82 if (fclose(stdout2)) 83 exit(1); 84 85 stdout2 = fdopen(4, "w"); 86 if (stdout2 == NULL) 87 exit(1); 88#include "encodings_local.def" 89 if (fclose(stdout2)) 90 exit(1); 91 92#undef BRACIFY 93#undef DEFENCODING 94 95 if (ferror(stdout) || fclose(stdout)) 96 exit(1); 97 exit(0); 98} 99