예제 #1
0
파일: iviewiir.c 프로젝트: shenki/iviewiir
int main(int argc, char **argv) {
    static bool show_series = false, show_all = false, use_cache = true;
    static int i_sid = 0;
    static char usage_str[] = "[SID[:PID]]";
    static struct opt_table opts[] = {
        OPT_WITH_ARG("--items-list|-i", opt_set_intval, NULL, &i_sid,
                "List episodes in a series. Requires a SID as a parameter."),
        OPT_WITHOUT_ARG("--series-list|-s", opt_set_bool, &show_series,
                "List the series available. The first element is the SID."),
        OPT_WITHOUT_ARG("--all|-a", opt_set_bool, &show_all,
                "List all items in all non-empty series."),
        OPT_WITHOUT_ARG("--force|-f", opt_set_invbool, &use_cache,
                "Force bypass the cached metadata."),
        OPT_WITHOUT_ARG("--help|-h", opt_usage_and_exit,
                usage_str, "Show this message."),
        OPT_ENDTABLE
    };
    opt_register_table(opts, NULL);
    if(!opt_parse(&argc, argv, opt_log_stderr)) {
        /* opt_parse will print an error to stderr. */
        exit(1);
    }
    if (!show_all && !show_series && !i_sid && (argc == 1)) {
        opt_usage_and_exit(usage_str);
    }

    struct iv_series *index;
    struct iv_config *config;
    int return_val = 0;
    cache_dir = xdg_user_dir_lookup_with_fallback("CACHE", "/tmp");
    if(NULL == (config = iviewiir_configure())) {
        fprintf(stderr, "Couldn't configure iviewiir, exiting\n");
        return 1;
    }
    int index_len = iviewiir_index(config, &index);
    if(0 >= index_len) {
        fprintf(stderr, "No items in index, exiting\n");
        return_val = 1;
        goto config_cleanup;
    }
    /* Check if they want everything listed */
    if(show_all) {
        list_all(config, index, index_len);
        return_val = 0;
        goto index_cleanup;
    }
    /* Check if they wanted a series list. */
    if(show_series) {
        int i;
        for(i=0; i<index_len; i++) {
            /* Heuristic to trim out empty series. */
            if((int)9e6 < index[i].id) {
                continue;
            }
            printf("%d - %s\n", index[i].id, index[i].title);
        }
        return_val = 0;
        goto index_cleanup;
    }
    /* Check if they want an episode list. */
    if(i_sid) {
        return_val = list_items(config, index, index_len, i_sid);
        goto index_cleanup;
    }
    /* If we've reached here and there are no arguments, print help message. */
    if (argc == 1) {
        opt_usage_and_exit(usage_str);
    }
    /* Otherwise, if they supplied a SID or SID:PID tuple, download the PID */
    int i = 1;
    while(i < argc) {
        if(NULL != strchr(argv[i], ':')) {
            // SID:PID
            const unsigned long sid = strtoul(strtok(argv[i], ":"), NULL, 10);
            const unsigned int pid = strtoul(strtok(NULL, ":"), NULL, 10);
            return_val += download_item(config, index, index_len, sid, pid);
        } else {
            // Check if it's a valid SID
            const unsigned int sid = strtoul(argv[i], NULL, 10);
            struct iv_episode *items;
            // Fetch episode lists for the SID
            debug("sid: %d\n", sid);
            int series_index;
            if(-1 == (series_index =
                        iv_find_series(sid, index, index_len, NULL))) {
                printf("No such series");
                return_val += 1;
                continue;
            }
            // Fetch items in series
            ssize_t items_len =
                iv_easy_series(config, &index[series_index], &items);
            if(1 > items_len) {
                printf("No items in series.\n");
                return_val += 1;
                continue;
            }
            for(i=0; i<items_len; i++) {
                return_val += download_item(config, index, index_len, sid,
                        items[i].id);
            }
            iv_destroy_series(items, items_len);
        }
        i++;
    }
index_cleanup:
    iv_destroy_index(index, index_len);
config_cleanup:
    iv_destroy_config(config);
    free(cache_dir);
    return return_val;
}
예제 #2
0
#include "charmodel.h"
#include "charmodel-helpers.h"
#include "utf8.h"
#include "colour.h"
#include "opt-helpers.h"

#define UNCLASSIFIED "*unclassified*"

static int opt_ignore_start = 0;
static int opt_min_length = 0;
static char *opt_filename = NULL;
static char *opt_test_dir = NULL;


static struct opt_table options[] = {
  OPT_WITH_ARG("-m|--min-length=<n>", opt_set_intval, opt_show_intval, &opt_min_length,
      "ignore texts shorter than this"),
  OPT_WITH_ARG("-i|--ignore-start", opt_set_intval, opt_show_intval,
      &opt_ignore_start, "don't classify this many first characters per block"),
  OPT_WITH_ARG("-f|--filename=<file>", opt_set_charp, opt_show_charp,
      &opt_filename, "load/save net here"),
  OPT_WITH_ARG("-t|--test-dir=<dir>", opt_set_charp, opt_show_charp,
      &opt_test_dir, "emit scores for files in this directory"),

  OPT_WITHOUT_ARG("-h|--help", opt_usage_and_exit,
      "-f NET TEXTFILE [TEXTFILE...] \n"
      "Print classification probabilities of documents",
      "Print this message."),

  OPT_ENDTABLE
};
예제 #3
0
#define us_to_clk(x) ((x)*1000/8)
#define clk_to_us(x) ((x)*8/1000)

char *g_file_name;
char *g_ifc_name;
int g_search_val;
unsigned long long g_pr_start, g_pr_end;
int g_bucket = 1;
bool g_dump;
bool g_hm;
int g_n_skip;
bool g_msg = true;

static struct opt_table opts[] = {
	OPT_WITH_ARG("-i|--interface <ifname>", opt_set_charp, NULL,
		     &g_ifc_name, "live capture on interface <ifname>"),
	OPT_WITH_ARG("-r|--read <file>", opt_set_charp, NULL,
		     &g_file_name, "read packets from pcap <file>"),
	OPT_WITH_ARG("-n|--bucket <val>", opt_set_intval, NULL,
		     &g_bucket, "aggragate <val> results for distribution"),
	OPT_WITH_ARG("-f|--find <val>", opt_set_intval, NULL,
		     &g_search_val, "find samples with delay <val> clocks"),
	OPT_WITH_ARG("-b|--begin <val>", opt_set_ulonglongval_si, NULL,
		     &g_pr_start, "print pairs from no <val>"),
	OPT_WITH_ARG("-e|--end <val>", opt_set_ulonglongval_si, NULL,
		     &g_pr_end, "print pairs to no <val>"),
	OPT_WITHOUT_ARG("-D|--dist", opt_set_bool,
			&g_dump, "dump distributions"),
	OPT_WITHOUT_ARG("-H|--heatmap", opt_set_bool,
			&g_hm, "dump heat map"),
	OPT_WITH_ARG("-s|--skip <s>", opt_set_intval, NULL,
예제 #4
0
	if (allocated)
		free(*argv);

	*argv = a;
	allocated = true;
	/* Re-set before parsing. */
	optind = 0;

	return opt_parse(argc, *argv, save_err_output);
}

struct opt_table short_table[] = {
	/* Short opts, different args. */
	OPT_WITHOUT_ARG("-a", test_noarg, "a", "Description of a"),
	OPT_WITH_ARG("-b", test_arg, show_arg, "b", "Description of b"),
	OPT_ENDTABLE
};

struct opt_table long_table[] = {
	/* Long opts, different args. */
	OPT_WITHOUT_ARG("--ddd", test_noarg, "ddd", "Description of ddd"),
	OPT_WITH_ARG("--eee <filename>", test_arg, show_arg, "eee", ""),
	OPT_ENDTABLE
};

struct opt_table long_and_short_table[] = {
	/* Short and long, different args. */
	OPT_WITHOUT_ARG("--ggg|-g", test_noarg, "ggg", "Description of ggg"),
	OPT_WITH_ARG("-h|--hhh", test_arg, NULL, "hhh", "Description of hhh"),
	OPT_ENDTABLE