genaliases.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Copyright (C) 1999-2001, 2003, 2005, 2008 Free Software Foundation, Inc.
  2. This file is part of the GNU LIBICONV Library.
  3. The GNU LIBICONV Library is free software; you can redistribute it
  4. and/or modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. The GNU LIBICONV Library is distributed in the hope that it will be
  8. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU LIBICONV Library; see the file COPYING.LIB.
  13. If not, write to the Free Software Foundation, Inc., 51 Franklin Street,
  14. Fifth Floor, Boston, MA 02110-1301, USA. */
  15. /* Creates the aliases.gperf table. */
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. static void emit_alias (FILE* out1, const char* alias, const char* c_name)
  19. {
  20. /* Output alias in upper case. */
  21. const char* s = alias;
  22. for (; *s; s++) {
  23. unsigned char c = * (unsigned char *) s;
  24. if (c >= 0x80)
  25. exit(1);
  26. if (c >= 'a' && c <= 'z')
  27. c -= 'a'-'A';
  28. putc(c, out1);
  29. }
  30. fprintf(out1,", ei_%s\n", c_name);
  31. }
  32. static void emit_encoding (FILE* out1, FILE* out2, const char* const* names, size_t n, const char* c_name)
  33. {
  34. fprintf(out2,"grep 'sizeof(\"");
  35. /* Output *names in upper case. */
  36. {
  37. const char* s = *names;
  38. for (; *s; s++) {
  39. unsigned char c = * (unsigned char *) s;
  40. if (c >= 0x80)
  41. exit(1);
  42. if (c >= 'a' && c <= 'z')
  43. c -= 'a'-'A';
  44. putc(c, out2);
  45. }
  46. }
  47. fprintf(out2,"\")' tmp.h | sed -e 's|^.*\\(stringpool_str[0-9]*\\).*$| (int)(long)\\&((struct stringpool_t *)0)->\\1,|'\n");
  48. for (; n > 0; names++, n--)
  49. emit_alias(out1, *names, c_name);
  50. }