flags.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include <stdio.h>
  2. #include "markdown.h"
  3. struct flagnames {
  4. int flag;
  5. char *name;
  6. };
  7. static struct flagnames flagnames[] = {
  8. { MKD_NOLINKS, "!LINKS" },
  9. { MKD_NOIMAGE, "!IMAGE" },
  10. { MKD_NOPANTS, "!PANTS" },
  11. { MKD_NOHTML, "!HTML" },
  12. { MKD_TAGTEXT, "TAGTEXT" },
  13. { MKD_NO_EXT, "!EXT" },
  14. { MKD_CDATA, "CDATA" },
  15. { MKD_NOSUPERSCRIPT, "!SUPERSCRIPT" },
  16. { MKD_NORELAXED, "!RELAXED" },
  17. { MKD_NOTABLES, "!TABLES" },
  18. { MKD_NOSTRIKETHROUGH,"!STRIKETHROUGH" },
  19. { MKD_TOC, "TOC" },
  20. { MKD_1_COMPAT, "MKD_1_COMPAT" },
  21. { MKD_AUTOLINK, "AUTOLINK" },
  22. { MKD_SAFELINK, "SAFELINK" },
  23. { MKD_NOHEADER, "!HEADER" },
  24. { MKD_TABSTOP, "TABSTOP" },
  25. { MKD_NODIVQUOTE, "!DIVQUOTE" },
  26. { MKD_NOALPHALIST, "!ALPHALIST" },
  27. { MKD_EXTRA_FOOTNOTE, "FOOTNOTE" },
  28. { MKD_NOSTYLE, "!STYLE" },
  29. { MKD_DLDISCOUNT, "DLDISCOUNT" },
  30. { MKD_DLEXTRA, "DLEXTRA" },
  31. { MKD_FENCEDCODE, "FENCEDCODE" },
  32. { MKD_IDANCHOR, "IDANCHOR" },
  33. { MKD_GITHUBTAGS, "GITHUBTAGS" },
  34. { MKD_NORMAL_LISTITEM, "NORMAL_LISTITEM" },
  35. { MKD_URLENCODEDANCHOR, "URLENCODEDANCHOR" },
  36. { MKD_LATEX, "LATEX" },
  37. { MKD_EXPLICITLIST, "EXPLICITLIST" },
  38. };
  39. #define NR(x) (sizeof x/sizeof x[0])
  40. int
  41. mkd_flag_isset(mkd_flag_t *flags, int i)
  42. {
  43. return flags ? is_flag_set(flags, i) : 0;
  44. }
  45. void
  46. mkd_flags_are(FILE *f, mkd_flag_t* flags, int htmlplease)
  47. {
  48. int i;
  49. int not, set, even=1;
  50. char *name;
  51. if ( htmlplease )
  52. fprintf(f, "<table class=\"mkd_flags_are\">\n");
  53. for (i=0; i < NR(flagnames); i++) {
  54. set = mkd_flag_isset(flags, flagnames[i].flag);
  55. name = flagnames[i].name;
  56. if ( not = (*name == '!') ) {
  57. ++name;
  58. set = !set;
  59. }
  60. if ( htmlplease ) {
  61. if ( even ) fprintf(f, " <tr>");
  62. fprintf(f, "<td>");
  63. }
  64. else
  65. fputc(' ', f);
  66. if ( !set )
  67. fprintf(f, htmlplease ? "<s>" : "!");
  68. fprintf(f, "%s", name);
  69. if ( htmlplease ) {
  70. if ( !set )
  71. fprintf(f, "</s>");
  72. fprintf(f, "</td>");
  73. if ( !even ) fprintf(f, "</tr>\n");
  74. }
  75. even = !even;
  76. }
  77. if ( htmlplease ) {
  78. if ( even ) fprintf(f, "</tr>\n");
  79. fprintf(f, "</table>\n");
  80. }
  81. }
  82. void
  83. mkd_mmiot_flags(FILE *f, MMIOT *m, int htmlplease)
  84. {
  85. if ( m )
  86. mkd_flags_are(f, &(m->flags), htmlplease);
  87. }
  88. void
  89. mkd_init_flags(mkd_flag_t *p)
  90. {
  91. memset(p, 0, sizeof(*p));
  92. }
  93. mkd_flag_t *
  94. mkd_flags()
  95. {
  96. mkd_flag_t *p = malloc( sizeof(mkd_flag_t) );
  97. if ( p )
  98. mkd_init_flags(p);
  99. return p;
  100. }
  101. void
  102. mkd_free_flags(mkd_flag_t *rip)
  103. {
  104. if (rip) free(rip);
  105. }