X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=filter.c;h=c84b4823c745474f5ba92d59053f824cf946ca06;hp=04997cf29e84c01a7382339271754266028187e2;hb=607ac63646d7c31aa1792dcf1d9a60e498654376;hpb=4b4c68de8d7390f966e46d9402d5499d2e8ee227 diff --git a/filter.c b/filter.c index 04997cf2..c84b4823 100644 --- a/filter.c +++ b/filter.c @@ -29,12 +29,12 @@ INIT_FILTER_ERRLISTS; #define INBUF_SIZE 32 * 1024 -static struct filter_chain_info filter_chain_info_struct; -static struct filter_chain_info *fci = &filter_chain_info_struct; +static struct filter_chain filter_chain_struct; +static struct filter_chain *fc = &filter_chain_struct; struct gengetopt_args_info conf; -__printf_2_3 void para_log(int ll, char* fmt,...) +__printf_2_3 void para_log(int ll, const char* fmt,...) { va_list argp; @@ -55,11 +55,11 @@ static int init_active_filter_list(void) int i, filter_num; struct filter_node *fn; - INIT_LIST_HEAD(&fci->filters); + INIT_LIST_HEAD(&fc->filters); - fci->inbuf = inbuf; - fci->in_loaded = &loaded; - fci->eof = &eof; + fc->inbuf = inbuf; + fc->in_loaded = &loaded; + fc->eof = &eof; for (i = 0; i < conf.filter_given; i++) { char *fa = para_strdup(conf.filter_arg[i]); @@ -69,13 +69,13 @@ static int init_active_filter_list(void) free(fn); return filter_num; } - fn->fci = fci; + fn->fc = fc; INIT_LIST_HEAD(&fn->callbacks); fn->filter = &filters[filter_num]; PARA_DEBUG_LOG("adding %s to filter chain\n", fn->filter->name); - list_add_tail(&fn->node, &fci->filters); + list_add_tail(&fn->node, &fc->filters); } - if (list_empty(&fci->filters)) + if (list_empty(&fc->filters)) return -E_NO_FILTERS; return 1; } @@ -84,18 +84,18 @@ static void open_filters(void) { struct filter_node *fn; - list_for_each_entry(fn, &fci->filters, node) { + list_for_each_entry(fn, &fc->filters, node) { fn->filter->open(fn); PARA_INFO_LOG("opened %s filter\n", fn->filter->name); - fci->outbuf = fn->buf; - fci->out_loaded = &fn->loaded; + fc->outbuf = fn->buf; + fc->out_loaded = &fn->loaded; } } static int parse_config(int argc, char *argv[]) { static char *cf; /* config file */ - struct stat statbuf; + struct stat statbuf; int i; if (cmdline_parser(argc, argv, &conf)) @@ -105,7 +105,7 @@ static int parse_config(int argc, char *argv[]) cf = make_message("%s/.paraslash/filter.conf", home); free(home); } - if (!stat(cf, &statbuf)) { + if (!stat(cf, &statbuf)) { if (cmdline_parser_configfile(cf, &conf, 0, 0, 0)) return -E_FILTER_SYNTAX; } @@ -113,8 +113,10 @@ static int parse_config(int argc, char *argv[]) return 1; printf("available filters: "); for (i = 0; filters[i].name; i++) - printf("%s%s", i? " " : "", filters[i].name); - printf("\nTry para_filter -f:-h for help on \n"); + printf("%s%s%s", i? " " : "", filters[i].name, + filters[i].parse_config? "*": ""); + printf("\nFilters marked with \"*\" have further command line options. Try\n" + "\tpara_filter -f ' -h'\nfor more information.\n"); exit(EXIT_SUCCESS); } @@ -133,33 +135,33 @@ int main(int argc, char *argv[]) if (ret < 0) goto out; open_filters(); - ib = fci->inbuf; - ob = fci->outbuf; - il = fci->in_loaded; - ol = fci->out_loaded; + ib = fc->inbuf; + ob = fc->outbuf; + il = fc->in_loaded; + ol = fc->out_loaded; PARA_DEBUG_LOG("ib %p in, ob: %p\n", ib, ob); again: if (*il < INBUF_SIZE && !eof) { ret = read(STDIN_FILENO, ib + *il, INBUF_SIZE - *il); - PARA_DEBUG_LOG("read %d/%d\n", ret, INBUF_SIZE - *il); + PARA_DEBUG_LOG("read %d/%zd\n", ret, INBUF_SIZE - *il); if (ret < 0) goto out; if (!ret) eof = 1; *il += ret; } - ret = filter_io(fci); + ret = filter_io(fc); if (ret < 0) goto out; converted = ret; if (*ol) { ret = write(STDOUT_FILENO, ob, *ol); - PARA_DEBUG_LOG("wrote %d/%d\n", ret, *ol); + PARA_DEBUG_LOG("wrote %d/%zd\n", ret, *ol); if (ret <= 0) goto out; *ol -= ret; if (*ol) { - PARA_NOTICE_LOG("short write: %d bytes left\n", *ol); + PARA_NOTICE_LOG("short write: %zd bytes left\n", *ol); memmove(ob, ob + ret, *ol); } } @@ -169,6 +171,6 @@ again: out: if (ret < 0) PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret)); - close_filters(fci); + close_filters(fc); return ret; }