示例#1
0
static void
md_header(htsbuf_queue_t *hq, const char *prefix, const char *s)
{
  htsbuf_append_str(hq, prefix);
  htsbuf_append_str(hq, s);
  htsbuf_append(hq, "\n", 1);
}
示例#2
0
文件: doc_md.c 项目: 0p1pp1/tvheadend
/**
 * List of all classes with documentation
 */
static int
http_markdown_classes(http_connection_t *hc)
{
  idclass_t const **all, **all2;
  const idclass_t *ic;
  htsbuf_queue_t *hq = &hc->hc_reply;

  pthread_mutex_lock(&global_lock);
  all = idclass_find_all();
  if (all == NULL) {
    pthread_mutex_unlock(&global_lock);
    return HTTP_STATUS_NOT_FOUND;
  }
  for (all2 = all; *all2; all2++) {
    ic = *all2;
    if (ic->ic_caption) {
      htsbuf_append_str(hq, ic->ic_class);
      htsbuf_append(hq, "\n", 1);
    }
  }
  pthread_mutex_unlock(&global_lock);

  free(all);
  return 0;
}
示例#3
0
static void
md_style(htsbuf_queue_t *hq, const char *style, const char *s)
{
  size_t l = strlen(style);
  htsbuf_append(hq, style, l);
  htsbuf_append_str(hq, s);
  htsbuf_append(hq, style, l);
}
示例#4
0
文件: wizard.c 项目: ksooo/tvheadend
static const void *description_get(wizard_page_t *page, const char **doc)
{
  htsbuf_queue_t q;

  if (!page->desc) {
    htsbuf_queue_init(&q, 0);
    for (; *doc; doc++) {
      if (*doc[0] == '\xff') {
        htsbuf_append_str(&q, tvh_gettext_lang(config.language_ui, *doc + 1));
      } else {
        htsbuf_append_str(&q, *doc);
      }
    }
    page->desc = htsbuf_to_string(&q);
    htsbuf_queue_flush(&q);
  }
  return &page->desc;
}
示例#5
0
static void
md_text(htsbuf_queue_t *hq, const char *first, const char *next, const char *text)
{
  char *s, *t, *p;
  int col, nl;

  t = s = p = tvh_strdupa(text);
  col = nl = 0;
  while (*s) {
    if (++col > 74) {
      nl = md_nl(hq, nl);
      if (first) {
        htsbuf_append_str(hq, first);
        first = NULL;
      } else if (next) {
        htsbuf_append_str(hq, next);
      }
      if (p <= t)
        p = t + 74;
      htsbuf_append(hq, t, p - t);
      col = 0;
      t = s = p;
    } else if (*s <= ' ') {
      *s = ' ';
      p = ++s;
    } else {
      s++;
    }
  }
  if (t < s) {
    md_nl(hq, nl);
    if (first)
      htsbuf_append_str(hq, first);
    else if (next)
      htsbuf_append_str(hq, next);
    htsbuf_append(hq, t, s - t);
  }
}
示例#6
0
static int
md_props(htsbuf_queue_t *hq, htsmsg_t *m, const char *lang, int nl)
{
  htsmsg_t *l, *n, *e, *x;
  htsmsg_field_t *f, *f2;
  const char *s;
  int first = 1, b;

  l = htsmsg_get_list(m, "props");
  HTSMSG_FOREACH(f, l) {
    n = htsmsg_field_get_map(f);
    if (!n) continue;
    if (!htsmsg_get_bool(n, "noui", &b) && b) continue;
    s = htsmsg_get_str(n, "caption");
    if (!s) continue;
    if (first) {
      nl = md_nl(hq, nl);
      htsbuf_append_str(hq, "#### ");
      htsbuf_append_str(hq, tvh_gettext_lang(lang, N_("Items")));
      md_nl(hq, 1);
      md_nl(hq, 1);
      htsbuf_append_str(hq, tvh_gettext_lang(lang, N_("The items have the following functions:")));
      md_nl(hq, 1);
      first = 0;
    }
    nl = md_nl(hq, nl);
    md_style(hq, "**", s);
    if (!htsmsg_get_bool(n, "rdonly", &b) && b) {
      htsbuf_append(hq, " _", 2);
      htsbuf_append_str(hq, tvh_gettext_lang(lang, N_("(Read-only)")));
      htsbuf_append(hq, "_", 1);
    }
    md_nl(hq, 1);
    s = htsmsg_get_str(n, "description");
    if (s) {
      md_text(hq, ": ", "  ", s);
      md_nl(hq, 1);
    }
    s = htsmsg_get_str(n, "doc");
    if (s) {
      htsbuf_append_str(hq, s);
      md_nl(hq, 1);
    }
    if (!htsmsg_get_bool_or_default(n, "doc_nlist", 0)) {
      e = htsmsg_get_list(n, "enum");
      if (e) {
        HTSMSG_FOREACH(f2, e) {
          x = htsmsg_field_get_map(f2);
          if (x) {
            s = htsmsg_get_str(x, "val");
          } else {
            s = htsmsg_field_get_string(f2);
          }
          if (s) {
            md_nl(hq, 1);
            htsbuf_append(hq, "  * ", 4);
            md_style(hq, "**", s);
          }
        }
        md_nl(hq, 1);
      }
示例#7
0
文件: doc_md.c 项目: 0p1pp1/tvheadend
static int
http_markdown_class(http_connection_t *hc, const char *clazz)
{
  const idclass_t *ic;
  const char *lang = hc->hc_access->aa_lang_ui;
  htsbuf_queue_t *hq = &hc->hc_reply;
  htsmsg_t *m, *l, *n, *e, *x;
  htsmsg_field_t *f, *f2;
  const char *s, **doc;
  int nl = 0, first = 1;

  pthread_mutex_lock(&global_lock);
  ic = idclass_find(clazz);
  if (ic == NULL) {
    pthread_mutex_unlock(&global_lock);
    return HTTP_STATUS_NOT_FOUND;
  }
  doc = ic->ic_doc;
  m = idclass_serialize(ic, lang);
  pthread_mutex_unlock(&global_lock);
  s = htsmsg_get_str(m, "caption");
  if (s) {
    md_header(hq, "##", s);
    nl = md_nl(hq, 1);
  }
  if (doc) {
    for (; *doc; doc++) {
      if (*doc[0] == '\xff') {
        htsbuf_append_str(hq, tvh_gettext_lang(lang, *doc + 1));
      } else {
        htsbuf_append_str(hq, *doc);
      }
    }
  }
  l = htsmsg_get_list(m, "props");
  HTSMSG_FOREACH(f, l) {
    n = htsmsg_field_get_map(f);
    if (!n) continue;
    s = htsmsg_get_str(n, "caption");
    if (!s) continue;
    if (first) {
      nl = md_nl(hq, nl);
      htsbuf_append_str(hq, "####");
      htsbuf_append_str(hq, tvh_gettext_lang(lang, N_("Items")));
      md_nl(hq, 1);
      md_nl(hq, 1);
      htsbuf_append_str(hq, tvh_gettext_lang(lang, N_("The items have the following functions:")));
      md_nl(hq, 1);
      first = 0;
    }
    nl = md_nl(hq, nl);
    md_style(hq, "**", s);
    md_nl(hq, 1);
    s = htsmsg_get_str(n, "description");
    if (s) {
      md_text(hq, ": ", "  ", s);
      md_nl(hq, 1);
    }
    e = htsmsg_get_list(n, "enum");
    if (e) {
      HTSMSG_FOREACH(f2, e) {
        x = htsmsg_field_get_map(f2);
        if (x) {
          s = htsmsg_get_str(x, "val");
        } else {
          s = htsmsg_field_get_string(f2);
        }
        if (s) {
          md_nl(hq, 1);
          htsbuf_append(hq, "  * ", 4);
          md_style(hq, "**", s);
        }
      }
      md_nl(hq, 1);
    }