xml2c.c 960 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * xml2c.c
  3. */
  4. #include "private.h"
  5. #include <stdio.h>
  6. #include <stdarg.h>
  7. static int indent = 0;
  8. /*--------------------------------------------------------- */
  9. const char *xml2c_enum(int value, const char *array[])
  10. {
  11. return array[value];
  12. }
  13. char *xml2c_esc(const char *str)
  14. {
  15. /* char *tmp, *d, *s;
  16. if (!str)
  17. return NULL;
  18. tmp = malloc(strlen(str) * 2);
  19. s = str;
  20. d = tmp;
  21. while (*s) {
  22. switch(*s) {
  23. case '\"':
  24. case '\\':
  25. *d = '\\';
  26. d++;
  27. *d = *s;
  28. break;
  29. case '%':
  30. *d = '\\';
  31. d++;
  32. *d = *s;
  33. break;
  34. default:
  35. *d = *s;
  36. break;
  37. }
  38. d++;
  39. }
  40. */
  41. return lub_string_encode(str, "\\\"");
  42. }
  43. /*--------------------------------------------------------- */
  44. /*int lub_dump_printf(const char *fmt, ...)
  45. {
  46. va_list args;
  47. int len;
  48. va_start(args, fmt);
  49. fprintf(stderr, "%*s", indent, "");
  50. len = vfprintf(stderr, fmt, args);
  51. va_end(args);
  52. return len;
  53. }
  54. */
  55. /*--------------------------------------------------------- */