Example #1
0
int
main(int argc, char *argv[]) {
    command_t program;
    command_init(&program, "clib-search", CLIB_VERSION);
    program.usage = "[options] [query ...]";
    command_parse(&program, argc, argv);

    for (int i = 0; i < program.argc; i++) case_lower(program.argv[i]);

    char *html = wiki_html_cache();
    if (NULL == html) {
        command_free(&program);
        fprintf(stderr, "Failed to fetch wiki HTML\n");
        return 1;
    }

    list_t *pkgs = wiki_registry_parse(html);
    free(html);

    list_node_t *node;
    list_iterator_t *it = list_iterator_new(pkgs, LIST_HEAD);
    printf("\n");
    while ((node = list_iterator_next(it))) {
        wiki_package_t *pkg = (wiki_package_t *) node->val;
        if (matches(program.argc, program.argv, pkg)) {
            cc_fprintf(CC_FG_DARK_CYAN, stdout, "  %s\n", pkg->repo);
            printf("  url: ");
            cc_fprintf(CC_FG_DARK_GRAY, stdout, "%s\n", pkg->href);
            printf("  desc: ");
            cc_fprintf(CC_FG_DARK_GRAY, stdout, "%s\n", pkg->description);
            printf("\n");
        }
        wiki_package_free(pkg);
    }
    list_iterator_destroy(it);
    list_destroy(pkgs);
    command_free(&program);
    return 0;
}
int
main(int argc, char **argv) {
  filter.executables = true;
  filter.utilities = true;

  command_t program;
  command_init(&program, "clib-search", CLIB_SEARCH_VERSION);
  program.usage = "[options] [query ...]";
  command_option(&program, "-a", "--author <author>", "filter by author", author);
  command_option(&program, "-e", "--executables", "filter by executables", executables);
  command_option(&program, "-u", "--utilities", "filter by utilities", utilities);
  command_parse(&program, argc, argv);

  char *html = wiki_html_cache();
  if (NULL == html) {
    fprintf(stderr, "Failed to fetch wiki HTML\n");
    return 1;
  }

  list_t *pkgs = wiki_registry_parse(html);

  list_node_t *node;
  list_iterator_t *it = list_iterator_new(pkgs, LIST_HEAD);
  while ((node = list_iterator_next(it))) {
    package_t *pkg = (package_t *) node->val;
    if (matches(program.argc, program.argv, pkg)) {
      printf("  \033[36m%s\033[m\n", pkg->repo);
      printf("  url: \033[90m%s\033[m\n", pkg->href);
      printf("  desc: \033[90m%s\033[m\n", pkg->description);
      printf("\n");
    }
  }
  list_iterator_destroy(it);
  list_destroy(pkgs);
  command_free(&program);

  return 0;
}