mktags.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* block-level tags for passing html blocks through the blender
  2. */
  3. #include <stdio.h>
  4. #define __WITHOUT_AMALLOC 1
  5. #include "config.h"
  6. #include "cstring.h"
  7. #include "tags.h"
  8. STRING(struct kw) blocktags;
  9. /* define a html block tag
  10. */
  11. static void
  12. define_one_tag(char *id, int selfclose)
  13. {
  14. struct kw *p = &EXPAND(blocktags);
  15. p->id = id;
  16. p->size = strlen(id);
  17. p->selfclose = selfclose;
  18. }
  19. /* case insensitive string sort (for qsort() and bsearch() of block tags)
  20. */
  21. static int
  22. casort(struct kw *a, struct kw *b)
  23. {
  24. if ( a->size != b->size )
  25. return a->size - b->size;
  26. return strncasecmp(a->id, b->id, b->size);
  27. }
  28. /* stupid cast to make gcc shut up about the function types being
  29. * passed into qsort() and bsearch()
  30. */
  31. typedef int (*stfu)(const void*,const void*);
  32. /* load in the standard collection of html tags that markdown supports
  33. */
  34. int
  35. main()
  36. {
  37. int i;
  38. #define KW(x) define_one_tag(x, 0)
  39. #define SC(x) define_one_tag(x, 1)
  40. KW("STYLE");
  41. KW("SCRIPT");
  42. KW("ADDRESS");
  43. KW("BDO");
  44. KW("BLOCKQUOTE");
  45. KW("CENTER");
  46. KW("DFN");
  47. KW("DIV");
  48. KW("OBJECT");
  49. KW("H1");
  50. KW("H2");
  51. KW("H3");
  52. KW("H4");
  53. KW("H5");
  54. KW("H6");
  55. KW("LISTING");
  56. KW("NOBR");
  57. KW("FORM");
  58. KW("UL");
  59. KW("P");
  60. KW("OL");
  61. KW("DL");
  62. KW("PLAINTEXT");
  63. KW("PRE");
  64. KW("TABLE");
  65. KW("WBR");
  66. KW("XMP");
  67. SC("HR");
  68. KW("IFRAME");
  69. KW("MAP");
  70. qsort(T(blocktags), S(blocktags), sizeof(struct kw), (stfu)casort);
  71. printf("static struct kw blocktags[] = {\n");
  72. for (i=0; i < S(blocktags); i++)
  73. printf(" { \"%s\", %d, %d },\n", T(blocktags)[i].id, T(blocktags)[i].size, T(blocktags)[i].selfclose );
  74. printf("};\n\n");
  75. printf("#define NR_blocktags %d\n", S(blocktags));
  76. exit(0);
  77. }