nrss-0.3.9/0000755034046500244610000000000010761115026013254 5ustar jjmillermkgroup-l-dnrss-0.3.9/args.c0000644034046500244610000000362510655656761014404 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include "nrss.h" void print_version() { printf("NRSS version %s\n", VERSION); } void print_help() { print_version(); printf("For configuration + key bindings, read \"man nrss\"\n\n"); printf("Usage: nrss [options]\n\n"); printf("Command line options:\n"); printf("\t-h\tThis help\n"); printf("\t-v\tVersion\n"); printf("\t-c 0-9\tNumber of columns\n"); printf("\t-o\tOffline\n"); printf("\nFile path options:\n"); printf("\t-D \tPath to config directory (~/.nrss)\n"); printf("\t-C \tPath to config file (~/.nrss/config)\n"); printf("\t-L \tPath to log file (~/.nrss/log)\n"); printf("\t-F \tPath to feed directory (~/.nrss/feeds/)\n"); printf("\nReport bugs to \n"); } void parse_args(int argc, char **argv) { int c = 0; while ((c = getopt(argc, argv, "hovc:D:C:L:F:")) != -1) { switch (c) { case 'h': print_help(); exit(0); break; case 'v': print_version(); exit(0); break; case 'c': if ((nc->defs[DEF_COLS] = atoi(optarg)) <= 0) nc->defs[DEF_COLS] = 1; nc->bits |= CFG_SETCOLS; break; case 'o': nc->bits |= CFG_OFFLINE; break; case 'D': nc->config_dir = xstrdup(optarg); break; case 'C': nc->config_file = xstrdup(optarg); break; case 'L': nc->log_file = xstrdup(optarg); break; case 'F': nc->feed_dir = optarg; break; } } } nrss-0.3.9/cache.c0000644034046500244610000000156510655656761014514 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include "nrss.h" char *get_cache_descr(int start, int len) { FILE *fp = NULL; char *line = NULL; if ((fp = fopen(nc->cache_file, "r")) != NULL) { line = xmalloc(len + 1); fseek(fp, start, SEEK_SET); fread(line, len, 1, fp); line[len] = 0; fclose(fp); } return line; } void desc_cache(char *descr, int *start, int *len) { FILE *fp = NULL; if(!descr) return; if ((fp = fopen(nc->cache_file, "a")) != NULL) { *start = ftell(fp); *len = strlen(descr); fprintf(fp, "%s", descr); fclose(fp); } } nrss-0.3.9/cnf/0000755034046500244610000000000010761115026014022 5ustar jjmillermkgroup-l-dnrss-0.3.9/cnf/cnf.c0000644034046500244610000001506010734623622014744 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #define _GNU_SOURCE #include #include #include #include #include #include "cnf.h" #ifdef BSD int getline(char **line, size_t * len, FILE * fp) { size_t mylen; char *buf; buf = fgetln(fp, &mylen); if (!mylen) return -1; if (!buf) return -1; if (buf[mylen - 1] == '\n') { buf[mylen - 1] = 0; *line = malloc(mylen); memcpy(*line, buf, mylen); *len = mylen; return mylen; } else { *line = malloc(mylen + 1); (*line)[mylen] = 0; memcpy(*line, buf, mylen); *len = mylen + 1; return mylen + 1; } } #endif static struct cnf_config_list *cfg_list; void fake_cnfdbg(char *format, ...) { } /*Return a class based on the identifying */ struct cnf_config_class *get_class(char ident, struct cnf_config *cfg) { int i = 0; for (i = 0; i < cfg->num_classes; i++) { if (cfg->classes[i].ident == ident) return &cfg->classes[i]; } return NULL; } void *get_data(char *format, char *line, struct cnf_config *cfg) { struct cnf_config_class *cls; mac_addr *data = NULL; int i = 0; int j = 0; void *tok = NULL; data = malloc(sizeof(void *) * strlen(format)); for (i = 0; format[i] != 0; i++) { cls = get_class(format[i], cfg); if (!cls) { cnfdbg("Unknown class in config meta\n"); break; } /*Skip over any whitespace */ while ((line[j]) && (line[j] != cls->delimiter)) j++; if (line[j]) tok = &line[++j]; else break; /*We can safely reference line[-1] because this * is a substring within the entire config line*/ for (j = j; line[j]; j++) { if ((line[j] == cls->delimiter)) { if (line[j - 1] != '\\') break; else memmove(&line[j - 1], &line[j], strlen(&line[j])); } } if (line[j]) line[j++] = 0; else break; if (is_numeric(cls)) data[i] = atoi(tok); else data[i] = (mac_addr) strdup((char *) tok); if ((cls->sanity) && (cls->sanity((void *) data[i]))) { cnfdbg("Invalid arg.\n"); break; } } if (format[i] == 0) return data; free(data); return NULL; } /*Uses the struct to determine whether two things are equal*/ int same_item(struct cnf_config_list *item, struct cnf_config_list *item2, struct cnf_config *cfg) { struct cnf_config_class *cls = NULL; int i = item->meta->ident_arg; if (!i) return 0; else i--; cls = get_class(item->meta->classes[i], cfg); if (((is_numeric(cls)) && (((int *) item->data)[i] == ((int *) item2->data)[i])) || ((!is_numeric(cls)) && (!strcmp (((char **) item->data)[i], ((char **) item2->data)[i])))) return 1; return 0; } /*Returns 0 if duplicate*/ int duplicate(struct cnf_config_list *item, struct cnf_config *cfg) { struct cnf_config_list *cur = cfg_list; while (cur != NULL) { if ((item->meta == cur->meta) && (same_item(cur, item, cfg))) return 0; cur = cur->next; } return 1; } void add_item(struct cnf_config_list *item) { struct cnf_config_list *cur = cfg_list; item->next = NULL; if (!cfg_list) { cfg_list = item; return; } while (cur->next) cur = cur->next; cur->next = item; } void free_item(struct cnf_config_list *item, char *format, struct cnf_config *cfg) { struct cnf_config_class *cls = NULL; int i = 0; for (i = 0; format[i] != 0; i++) { cls = get_class(format[i], cfg); if ((cls) && (!is_numeric(cls))) free(((char **) item->data)[i]); } free(item->data); free(item); } void cnf_free_list(struct cnf_config_list *item, struct cnf_config *cfg) { if (!item) return; cnf_free_list(item->next, cfg); free_item(item, item->meta->classes, cfg); } int cnf_parse_line(char *line, struct cnf_config *cfg) { struct cnf_config_list *item = NULL; int i = 0; char *args = NULL; /*Just avoid comments and empty lines */ if ((line[0] == '#') || (line[0] == '\n')) return 0; /*Strip the ending newline */ if (line[strlen(line) - 1] == '\n') line[strlen(line) - 1] = 0; /*Get the initial identifying token */ for (i = 0; line[i] != 0; i++) { if (line[i] == cfg->delimiter[0]) { line[i] = 0; args = &line[i + 1]; break; } } /*Now we handle the class */ for (i = 0; i < cfg->num_meta; i++) { if (!strcmp(line, cfg->metas[i].name)) { item = malloc(sizeof(struct cnf_config)); item->meta = &cfg->metas[i]; if (cfg->metas[i].classes[0] != '0') { item->data = get_data(cfg->metas[i].classes, args, cfg); if (!item->data) { free(item); item = NULL; } } break; } } /*Something went wrong if !item */ if (!item) return 1; /*Check duplicates */ if ((!duplicate(item, cfg)) || ((cfg->metas[i].done) && (cfg->metas[i].done(item->data)))) { free_item(item, cfg->metas[i].classes, cfg); return 1; } /*Excellent, add the item */ add_item(item); return 0; } char *get_next_line(char *fname) { static FILE *fp = NULL; char *line = NULL; size_t len = 0; if ((!fp) && ((fp = fopen(fname, "r")) <= 0)) return NULL; if (getline(&line, &len, fp) < 0) { free(line); fclose(fp); return NULL; } return line; } void cnf_parse(char *fname, struct cnf_config *cfg, struct cnf_config_list **cfgl) { char *line = NULL; int linect = 0; while ((line = get_next_line(fname))) { linect++; if (cnf_parse_line(line, cfg)) cnfdbg("[%s][%d] %s\n", fname, linect, "Parse Error"); free(line); } if (cfgl) *cfgl = cfg_list; else cnf_free_list(cfg_list, cfg); } nrss-0.3.9/cnf/cnf.h0000644034046500244610000000173210677142041014747 0ustar jjmillermkgroup-l-d#ifndef CNFH #define mac_addr __SIZE_TYPE__ #define CFG_CLASS_STR 1 #define CFG_CLASS_NUM 2 #define is_numeric(X) (X->type & CFG_CLASS_NUM) #ifndef CNFDBG #define cnfdbg(format, ...) fake_cnfdbg(format,##__VA_ARGS__) #endif #ifdef BSD #include int getline(char **line, size_t *len, FILE *fp); #endif struct cnf_config_class { char ident; char type; char delimiter; int (*sanity) (void *data); }; struct cnf_config_meta { char *name; char *classes; int ident_arg; int (*done) (void *data); }; struct cnf_config_list { struct cnf_config_meta *meta; void *data; struct cnf_config_list *next; }; struct cnf_config { char *delimiter; int num_meta; int num_classes; struct cnf_config_meta *metas; struct cnf_config_class *classes; }; int cnf_parse_line(char *line, struct cnf_config *cfg); void cnf_parse(char *fname, struct cnf_config *cfg, struct cnf_config_list **cfgl); void cnf_free_list(struct cnf_config_list *item, struct cnf_config *cfg); #endif nrss-0.3.9/cnf/Makefile0000644034046500244610000000010510641356604015464 0ustar jjmillermkgroup-l-dinclude ../config.mk OBJS = cnf.o all: ${OBJS} clean: @rm -f *.o nrss-0.3.9/commands.c0000644034046500244610000000670010761115000015214 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include "nrss.h" #define WGET_ESCAPES 3 static struct escape wget_escapes[WGET_ESCAPES] = { {"%u", NULL}, {"%p", NULL}, {"%a", "NRSS-1.0.0"} }; #define BROWSER_ESCAPES 1 static struct escape browser_escapes[BROWSER_ESCAPES] = { {"%u", NULL} }; char **make_args(char *format) { char **ret = NULL; int i = 0; int toks = 2; char *tok = NULL; char *save = NULL; int quote = 0; for (i = 0; format[i] != 0; i++) { if ((format[i] == ' ')&&(!quote)) toks++; else if (format[i] == '"') quote = !quote; } ret = xmalloc(sizeof(char *) * toks); tok = strtok_r(format, " ", &save); ret[0] = tok; for (i = 1; i < (toks - 1); i++) { if (save[0] == '\"') { save++; ret[i] = strtok_r(NULL, "\"", &save); } else ret[i] = strtok_r(NULL, " ", &save); } ret[i] = NULL; return ret; } pid_t wget(char *URL, char *fname) { char **args = NULL; char *escaped_string = NULL; pid_t pid = 0; wget_escapes[0].replacement = URL; wget_escapes[1].replacement = concat(nc->feed_dir, fname); escaped_string = escape_string(nc->wget_line, wget_escapes, WGET_ESCAPES); args = make_args(escaped_string); setpgid(getpid(), getpid()); if (!(pid = fork())) { setpgid(getpid(), getpid()); execve(args[0], args, NULL); exit(-1); } free(args); free(wget_escapes[1].replacement); wget_escapes[1].replacement = NULL; free(escaped_string); return pid; } void open_url(char *URL) { char **args = NULL; char *escaped_string = NULL; pid_t pid = 0; if (!nc->browser_line) { status_message("No browser defined."); return; } browser_escapes[0].replacement = URL; escaped_string = escape_string(nc->browser_line, browser_escapes, BROWSER_ESCAPES); args = make_args(escaped_string); setpgid(getpid(), getpid()); if (!(pid = fork())) { setpgid(getpid(), getpid()); close(STDERR_FILENO); execve(args[0], args, environ); exit(-1); } if (browser_wait()) { iface_mute(); tcsetpgrp(STDIN_FILENO, pid); waitpid(pid, NULL, 0); tcsetpgrp(STDIN_FILENO, getpid()); iface_unmute(); wnch(0); } free(args); free(escaped_string); } char *filter_string(char *str, char *cmd) { char **args = NULL; char *filtered_str = NULL; char *arg_str = xstrdup(cmd); int inpipe[2]; int outpipe[2]; pid_t pid = 0; pipe(inpipe); pipe(outpipe); args = make_args(arg_str); setpgid(getpid(), getpid()); if (!(pid = fork())) { dup2(inpipe[0], STDIN_FILENO); close(inpipe[1]); dup2(outpipe[1], STDOUT_FILENO); close(outpipe[0]); close(STDERR_FILENO); setpgid(getpid(), getpid()); execve(args[0], args, NULL); exit(-1); } close(inpipe[0]); close(outpipe[1]); write_string_to_fd(str, inpipe[1]); close(inpipe[1]); filtered_str = read_string_from_fd(outpipe[0]); close(outpipe[0]); free(args); free(arg_str); return filtered_str; } nrss-0.3.9/conf.c0000644034046500244610000000721210655656761014371 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include "nrss.h" #include "conf.h" int set_columns(void *data) { if ((unsigned long) data < 0) return 1; if (columns_set()) return 0; nc->defs[DEF_COLS] = ((int *) data)[0]; return 0; } int check_theme(void *data) { if (((unsigned long) data < 0) || (((unsigned long) data) > 7)) { return 1; } return 0; } int set_rate(void *data) { struct feed *cur = get_feed(((char **) data)[1]); int num = ((int *) data)[0]; if (cur) { if (num <= 0) cur->rate = 0; else cur->rate = num; return 0; } return 1; } int set_max(void *data) { struct feed *cur = get_feed(((char **) data)[1]); int num = ((int *) data)[0]; if (cur) { if (num <= 0) cur->keep = 0; else cur->keep = num; return 0; } return 1; } int set_show(void *data) { struct feed *cur = get_feed(((char **) data)[1]); int num = ((int *) data)[0]; if (cur) { if (num <= 0) cur->show = 0; else cur->show = num; return 0; } return 1; } int set_def(int def, int num) { if (num < 0) nc->defs[def] = 0; else nc->defs[def] = num; return 0; } int set_def_max(void *data) { return set_def(DEF_MAX, ((int *) data)[0]); } int set_def_rate(void *data) { return set_def(DEF_RATE, ((int *) data)[0]); } int set_def_show(void *data) { return set_def(DEF_SHOW, ((int *) data)[0]); } int set_theme(void *data) { if ((((int *) data)[0] >= 1) && (((int *) data)[0] <= 8)) { nc->themes[((int *) data)[0] - 1].fg = ((int *) data)[1]; nc->themes[((int *) data)[0] - 1].bg = ((int *) data)[2]; } return 0; } int set_browser_wait(void *data) { if (((int *) data)[0]) nc->bits |= CFG_BITS_BROWSER_WAIT; else nc->bits &= ~(CFG_BITS_BROWSER_WAIT); return 0; } void escape_filter(char *line) { char *sub = line; while ((sub = strstr(sub, "\\n")) != NULL) { if (sub != line) { if (sub[-1] != '\\') sub[0] = '\n'; else sub--; memmove(&sub[1], &sub[2], strlen(sub) - 1); } else { sub[0] = '\n'; memmove(&sub[1], &sub[2], strlen(sub) - 1); } sub++; } } int set_browser(void *data) { nc->browser_line = ((char **) data)[0]; return 0; } int set_wget(void *data) { nc->wget_line = ((char **) data)[0]; return 0; } int set_desc_filter(void *data) { nc->desc_filter_line = ((char **) data)[0]; return 0; } int set_story_filter(void *data) { nc->story_filter_line = ((char **) data)[0]; return 0; } int set_title_escape(void *data) { escape_filter(((char **) data)[0]); nc->title_string = ((char **) data)[0]; return 0; } int set_story_escape(void *data) { escape_filter(((char **) data)[0]); nc->story_string = ((char **) data)[0]; return 0; } int set_r_story_escape(void *data) { escape_filter(((char **) data)[0]); nc->r_story_string = ((char **) data)[0]; return 0; } int set_u_story_escape(void *data) { escape_filter(((char **) data)[0]); nc->u_story_string = ((char **) data)[0]; return 0; } int set_reader_escape(void *data) { escape_filter(((char **) data)[0]); nc->descr_string = ((char **) data)[0]; return 0; } nrss-0.3.9/conf.h0000644034046500244610000000211510644321162014351 0ustar jjmillermkgroup-l-d#ifndef CONFH #define CONFH /*Feeds.c*/ int add_feed(void *data); struct feed *get_feed(char *handle); /*Conf.c*/ int set_max(void *data); int set_show(void *data); int set_rate(void *data); int set_def_max(void *data); int set_def_show(void *data); int set_def_rate(void *data); int set_def(int def, int num); int set_theme(void *data); int set_theme_unread(void *data); int set_theme_new(void *data); int set_theme_title(void *data); int set_thm(int theme, int fg, int bg); int set_browser(void *data); int set_browser_wait(void *data); int set_wget(void *data); int set_desc_filter(void *data); int set_story_filter(void *data); int set_title_escape(void *data); int set_story_escape(void *data); int set_sel_title_escape(void *data); int set_sel_story_escape(void *data); int set_reader_escape(void *data); int set_r_story_escape(void *data); int set_u_story_escape(void *data); int set_sel_r_story_escape(void *data); int set_sel_u_story_escape(void *data); int set_columns(void *data); int check_theme(void *data); /*Keys.c*/ int set_key(void *data); int check_char(void *data); #endif nrss-0.3.9/config.mk0000644034046500244610000000153210761115000015043 0ustar jjmillermkgroup-l-dVERSION = 0.3.9 # Customize the following # Define where everything should be installed. ifndef PREFIX PREFIX = /usr/local endif ifndef MANPREFIX MANPREFIX = ${PREFIX}/share/man endif # Define your ncurses library, usu. ncurses, but # also can be ncursesw if built with unicode ifeq (${shell find /usr/include/* -name ncursesw},/usr/include/ncursesw) CURSDEF = NCURSESW CURSES = ncursesw PANEL = panelw else CURSDEF = NCURSES CURSES = ncurses PANEL = panel endif INCS = -I. -I/usr/include -I/usr/local/include LIBS = -L/usr/lib -L/usr/local/lib CFLAGS += -g -Wall -std=gnu99 ${INCS} -DVERSION=\"${VERSION}\" -D${CURSDEF} WGET = ${shell which wget} ifneq (${WGET},"wget not found") CFLAGS += -DWGET_PATH=\"${WGET}\" endif LIBS += -lexpat -l${CURSES} -l${PANEL} LDFLAGS += ${LIBS} CC = cc .c.o: @echo CC $< @${CC} -c ${CFLAGS} $< nrss-0.3.9/COPYING0000644034046500244610000004310310655656761014332 0ustar jjmillermkgroup-l-d GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. nrss-0.3.9/feeds.c0000644034046500244610000000157010655656761014533 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include "nrss.h" int add_feed(void *data) { struct feed *newfeed = NULL; newfeed = xmalloc(sizeof(struct feed)); memset(newfeed, 0, sizeof(struct feed)); newfeed->URL = ((char **) data)[0]; newfeed->handle = ((char **) data)[1]; newfeed->rate = nc->defs[DEF_RATE]; newfeed->show = nc->defs[DEF_SHOW]; newfeed->keep = nc->defs[DEF_MAX]; newfeed->time = 1; ladd_feed(&nc->feeds, newfeed); return 0; } struct feed *get_feed(char *handle) { foreach_feed(curfeed) { if (!strcmp(curfeed->handle, handle)) return curfeed; } return NULL; } nrss-0.3.9/filter.c0000644034046500244610000000227010655656761014730 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include "nrss.h" char *read_string_from_fd(int source) { char *str = NULL; char *tmp = NULL; char *buff = xmalloc(BUFFER + 1); int len = 0; while ((len = read(source, buff, BUFFER)) > 0) { buff[len] = 0; if (str) { tmp = concat(str, buff); free(str); str = tmp; } else str = strdup(buff); } free(buff); return str; } void write_string_to_fd(const char *str, int dest) { size_t len = 0; size_t index = 0; size_t bytes = 0; if (!str) return; len = strlen(str); while (index < len) { bytes = write(dest, &(str[index]), len - index); index += bytes; } } char *filter_description(char *str) { char *filtered_string = NULL; if (!nc->desc_filter_line) return NULL; filtered_string = filter_string(str, nc->desc_filter_line); return filtered_string; } nrss-0.3.9/header0000644034046500244610000000042010655656761014445 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ nrss-0.3.9/INSTALL0000644034046500244610000000022510655656761014326 0ustar jjmillermkgroup-l-dSimply type "make install" If you'd like to install in a place other than /usr/local, you can define PREFIX. For example: PREFIX=/usr make install nrss-0.3.9/interface.c0000644034046500244610000002330610655656761015406 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include "nrss.h" #include "interface.h" void status_message(char *format, ...) { char *buffer = NULL; va_list args; if (muted()) return; buffer = xmalloc(ni->width - 1); va_start(args, format); clear_status(); vsnprintf(buffer, ni->width - 2, format, args); mvwaddstr(ni->status, 1, 1, buffer); va_end(args); free(buffer); update_panels(); doupdate(); } void init_themes() { int i = 0; for (i = 1; i <= COLORS; i++) init_pair(i, nc->themes[i - 1].fg, nc->themes[i - 1].bg); } void clean_windows() { int i = 0; for (i = 0; i < ni->columns; i++) { del_panel(ni->plist[i]); delwin(ni->list[i]); } del_panel(ni->pstatus); delwin(ni->status); if (reader_open()) reader_off(); if (usage_open()) usage_off(); } void build_windows(int height, int width) { int i = 0; for (i = 0; i < ni->columns; i++) { ni->list[i] = newwin(height - 3, width / ni->columns, 0, (width / ni->columns) * i); ni->plist[i] = new_panel(ni->list[i]); } ni->status = newwin(3, width, height - 3, 0); ni->pstatus = new_panel(ni->status); halfdelay(5); ni->width = width; ni->height = height; if (reader_open()) reader(nc->descr_string); if (usage_open()) usage(); } void rfrsh() { int nheight, nwidth, i; getmaxyx(stdscr, nheight, nwidth); if ((ni->height != nheight) || (ni->width != nwidth)) { clean_windows(); build_windows(nheight, nwidth); } init_themes(); for (i = 0; i < ni->columns; i++) { wbkgdset(ni->list[i], ' ' | COLOR_PAIR(THEME_DEF)); wattron(ni->list[i], COLOR_PAIR(THEME_DEF)); wclear(ni->list[i]); } wattron(ni->status, COLOR_PAIR(THEME_DEF)); wclear(ni->status); wborder(ni->status, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE, ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER); clear_status(); keypad(ni->status, 1); update_panels(); doupdate(); } void interface_init() { initscr(); cbreak(); noecho(); start_color(); rfrsh(); } void check_scroll_down() { if (ni->selitem) { if ((ni->selfeed->line + ni->selitem->idx) > ni->offset + (ni->height - 5) * ni->columns) ni->offset = ni->selfeed->line + ni->selitem->idx - (ni->height - 5) * ni->columns; } else { if (ni->selfeed->line == 1) ni->offset = 0; else if (ni->selfeed->line > ni->offset + (ni->height - 5) * ni->columns) ni->offset = (ni->selfeed->line) - (ni->height - 5) * ni->columns; } } void check_scroll_up() { if (ni->selitem) { if (((ni->selfeed->line + ni->selitem->idx) <= ni->offset)) ni->offset = (ni->selfeed->line + ni->selitem->idx) - 1; else if (ni->selfeed->line + ni->selitem->idx > (ni->offset + ni->height - 5) * ni->columns) ni->offset = ni->selfeed->line + ni->selitem->idx - (ni->height - 5) * ni->columns + 1; } else { if (ni->selfeed->line <= ni->offset) ni->offset = ni->selfeed->line - 1; } } void mark_read(struct feed *fd, struct item *it) { if (nw(it)) { fd->nitems_new--; fd->nitems_unread--; } else if (unrd(it)) fd->nitems_unread--; icachebad(it); usetnw(fd, it); usetunrd(fd, it); } void mark_all_read() { foreach_feed(curfeed) { foreach_item(curfeed, curitem) mark_read(curfeed, curitem); } interface_draw(); } void new_reader() { if ((reader_open()) && (ni->selitem)) { reader_off(); ni->reader = NULL; reader(nc->descr_string); mark_read(ni->selfeed, ni->selitem); } } void handle_usage() { if (usage_open()) usage_off(); else usage(); } void next_feed() { if (ni->selfeed != nc->feeds->prev) { fcachebad(ni->selfeed); ni->selfeed = ni->selfeed->next; fcachebad(ni->selfeed); if(ni->selitem) { icachebad(ni->selitem); ni->selitem = NULL; } } } void prev_feed() { if (ni->selfeed != nc->feeds) { fcachebad(ni->selfeed); ni->selfeed = ni->selfeed->prev; fcachebad(ni->selfeed); if(ni->selitem) { icachebad(ni->selitem); ni->selitem = NULL; } } } void select_next_feed() { next_feed(); check_scroll_down(); interface_draw(); } void select_prev_feed() { prev_feed(); check_scroll_up(); interface_draw(); } void select_next_item() { if (ni->selitem) { icachebad(ni->selitem); if ((!ni->selitem->next) || (ni->selitem->next->idx > ni->selfeed->nitems_visible)) { next_feed(); } else { icachebad(ni->selitem->next); ni->selitem = ni->selitem->next; } } else if (ni->selfeed) { if (ni->selfeed->nitems_visible >= 1) { ni->selitem = ni->selfeed->items; icachebad(ni->selitem); } else if (ni->selfeed->next) select_next_feed(); } check_scroll_down(); interface_draw(); new_reader(); } void select_prev_item() { if (ni->selitem) { icachebad(ni->selitem); if (ni->selitem->idx == 1) ni->selitem = NULL; else { icachebad(ni->selitem->prev); ni->selitem = ni->selitem->prev; } } else if (ni->selfeed != nc->feeds) { prev_feed(); if (ni->selfeed->nitems_visible) { ni->selitem = ni->selfeed->items; for (int i = 0; i < ni->selfeed->nitems_visible - 1; i++) ni->selitem = ni->selitem->next; icachebad(ni->selitem); } } check_scroll_up(); interface_draw(); new_reader(); } void handle_goto() { if (ni->selitem) { open_url(ni->selitem->link); mark_read(ni->selfeed, ni->selitem); } else open_url(ni->selfeed->link); } void refresh_feed(struct feed *cfd) { if (!cfd->update_pid) { update(cfd); cfd->time = cfd->rate; } } void refresh_cur() { refresh_feed(ni->selfeed); } void refresh_all() { foreach_feed(curfeed) refresh_feed(curfeed); } void toggle_shrunk(struct feed *cur) { if (sh(cur)) { usetsh(cur); } else { setsh(cur); } enumerate(cur, cur->line); } void expand_feed(struct feed *cur) { if (ex(cur)) { usetex(cur); } else { setex(cur); } enumerate(cur, cur->line); } void shrink_all_feeds() { if (all_shrunk()) ni->bits &= ~(IFACE_ALL_SHRUNK); else ni->bits |= IFACE_ALL_SHRUNK; if (ni->selitem) icachebad(ni->selitem); foreach_feed(curfeed) fcachebad(curfeed); ni->selitem = NULL; enumerate(nc->feeds, nc->feeds->line); ni->offset = ni->selfeed->line - 1; interface_draw(); } void soft_shrink_all_feeds() { if(all_soft_shrunk()) { ni->bits &= ~(IFACE_ALL_SOFT_SHRUNK); foreach_feed(curfeed) { usetsh(curfeed); fcachebad(curfeed); } } else { ni->bits |= IFACE_ALL_SOFT_SHRUNK; foreach_feed(curfeed) { setsh(curfeed); fcachebad(curfeed); } } if(ni->selitem) icachebad(ni->selitem); ni->selitem = NULL; enumerate(nc->feeds, nc->feeds->line); ni->offset = ni->selfeed->line - 1; interface_draw(); } void handle_default() { if (ni->selitem) { if (reader_open()) { reader_off(); ni->reader = NULL; } else { mark_read(ni->selfeed, ni->selitem); reader(nc->descr_string); } } else toggle_shrunk(ni->selfeed); interface_draw(); } void handle_expand() { expand_feed(ni->selfeed); while ((ni->selitem) && (ni->selitem->idx > ni->selfeed->nitems_visible)) select_prev_item(); interface_draw(); } void interface(int columns) { unsigned int i = 0; unsigned int key = 0; ni = xmalloc(sizeof(struct niface)); memset(ni, 0, sizeof(struct niface)); ni->list = xmalloc(sizeof(WINDOW *) * columns); memset(ni->list, 0, sizeof(WINDOW *) * columns); ni->plist = xmalloc(sizeof(PANEL *) * columns); memset(ni->plist, 0, sizeof(WINDOW *) * columns); ni->columns = columns; ni->offset = 1; interface_init(); enumerate(nc->feeds, 1); ni->selfeed = nc->feeds; interface_draw(); tick_feeds(); if (!ni->selfeed) status_message("Add some feeds! (read 'man nrss')"); while (1) { key = wgetch(ni->status); if (key != -1) { if (key == 27) key = ALT(wgetch(ni->status)); for (i = 0; i < (ni->selfeed ? NUM_FBINDINGS : NUM_BINDINGS); i++) { if (nc->keys[i].bind == key) nc->keys[i].function(); } } if (signal_child()) chld_handler(); if (signal_alarm()) alrm_handler(); if (signal_wnch()) wnch_handler(); if (signal_pipe()) pipe_handler(); } } void interface_destroy() { clean_windows(); free(ni->list); free(ni->plist); free(ni); endwin(); } nrss-0.3.9/interface.h0000644034046500244610000000246210654665301015400 0ustar jjmillermkgroup-l-d#ifndef INTERFACEH #define INTERFACEH #define IFACE_ALL_SHRUNK 1 #define IFACE_READER 2 #define IFACE_ALL_SOFT_SHRUNK 4 struct niface { int height, width; WINDOW **list; WINDOW *status; WINDOW *reader; WINDOW *usage; PANEL **plist; PANEL *pstatus; PANEL *preader; PANEL *pusage; struct feed *selfeed; struct item *selitem; int bits; int columns; int offset; int max_offset; }; struct niface *ni; /*Interface.c*/ void interface_init(); void interface(int columns); void interface_destroy(); void rfrsh(); /*Interface.c Bindings*/ void select_next_item(); void select_prev_item(); void handle_goto(); void refresh_cur(); void shrink_all_feeds(); void soft_shrink_all_feeds(); void handle_default(); void handle_expand(); void select_next_feed(); void select_prev_feed(); void handle_usage(); void refresh_all(); void mark_all_read(); /*Reader.c*/ void reader(char *string); void reader_off(); int word_length(char *string); /*Usage.c*/ void usage(); void usage_off(); /*Interface_draw.c*/ void interface_draw(); void print_item(struct feed *curfeed, struct item *curitem, WINDOW *win, int y, int x); void print_title(struct feed *curfeed, WINDOW *win, int y, int x); void theme_print(WINDOW *win, int y, int x, int width, char *message, int mode); void enumerate(struct feed *first, int line); #endif nrss-0.3.9/interface_draw.c0000644034046500244610000002012310672272564016407 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include "nrss.h" #include "interface.h" #define NUM_TITLE_ESCAPES 7 static struct escape title_escapes[NUM_TITLE_ESCAPES] = { {"%u", NULL}, {"%i", NULL}, {"%n", NULL}, {"%d", NULL}, {"%r", NULL}, {"%h", NULL}, {"%t", NULL} }; #define NUM_STORY_ESCAPES 1 static struct escape story_escapes[NUM_STORY_ESCAPES] = { {"%s", NULL} }; #define NUM_TITLE_TERNS 2 static struct ternary title_terns[NUM_TITLE_TERNS] = { {'x', 0}, {'s', 0} }; #define NUM_STORY_TERNS 4 static struct ternary story_terns[NUM_STORY_TERNS] = { {'e', 0}, {'b', 0}, {'s', 0}, {'f', 0} }; #define BIT_BOLD 1 #define BIT_UNDERLINE 2 #define BIT_STANDOUT 4 #define BIT_REVERSE 8 #define BIT_DIM 16 #define toggle_att(att) \ if(on & BIT_##att) {\ wattroff(win, A_##att);\ on = on & ~(BIT_##att);\ }\ else {\ wattron(win, A_##att);\ on = on | BIT_##att;\ } #define MODE_NOWRAP 0 #define MODE_WRAP 1 void theme_print(WINDOW * win, int y, int x, int width, char *message, int mode) { int on = 0; int i = 0; int ct = 0; int print = 1; if (!message) return; wmove(win, y, x); for (i = 0; message[i] != 0; i++, x++) { if (((ct == 0) || (message[i] == ' ')) && (mode == MODE_WRAP)) { ct = word_length(&message[i + 1]); if (x + ct > ni->width - 2) { x = 0; y++; } } if ((x > width) || (message[i] == '\n')) { if (mode == MODE_WRAP) { y++; x = 0; } else print = 0; } if (message[i] == '\\') { i++; if (print) mvwaddch(win, y, x, message[i]); } else if (message[i] == '%') { i++; x--; if (message[i] == 0) break; if (message[i] == 'B') { toggle_att(BOLD); } else if (message[i] == 'U') { toggle_att(UNDERLINE) } else if (message[i] == 'S') { toggle_att(STANDOUT) } else if (message[i] == 'R') { toggle_att(REVERSE) } else if (message[i] == 'D') { toggle_att(DIM) } else if ((message[i] >= '1') && (message[i] <= '8')) wattron(win, COLOR_PAIR(message[i] - '0')); } #ifdef NCURSESW else if ((unsigned char) message[i] > 0x7F) { wchar_t dest[2]; int bytes = 0; i += mbtowc(dest, &message[i], 4) - 1; dest[1] = 0; bytes = wcswidth(dest, 1); if((x + bytes <= width)&&(print)) mvwaddwstr(win, y, x, dest); x += wcswidth(dest, 1) - 1; } #endif else if (print) mvwaddch(win, y, x, message[i]); } wclrtoeol(win); wattron(win, COLOR_PAIR(THEME_DEF)); } void print_title(struct feed *curfeed, WINDOW * win, int y, int x) { char *tern_string = NULL; char itemstr[5]; char nitemstr[5]; char ditemstr[5]; char ritemstr[5]; if (!fcached(curfeed)) { if (curfeed->cached_line) free(curfeed->cached_line); fcacheok(curfeed); snprintf(itemstr, 5, "%d", curfeed->nitems); snprintf(nitemstr, 5, "%d", curfeed->nitems_new); snprintf(ditemstr, 5, "%d", curfeed->nitems_unread); snprintf(ritemstr, 5, "%d", curfeed->nitems ? curfeed->nitems - curfeed->nitems_unread - 1 : 0); title_escapes[0].replacement = curfeed->URL; title_escapes[1].replacement = itemstr; title_escapes[2].replacement = nitemstr; title_escapes[3].replacement = ditemstr; title_escapes[4].replacement = ritemstr; title_escapes[5].replacement = curfeed->handle; title_escapes[6].replacement = curfeed->title; title_terns[0].status = ((!sh(curfeed)) && (!all_shrunk())); title_terns[1].status = (curfeed == ni->selfeed); tern_string = ternary_string(nc->title_string, title_terns, NUM_TITLE_TERNS); curfeed->cached_line = escape_string(tern_string, title_escapes, NUM_TITLE_ESCAPES); } theme_print(win, y, x, ni->width / ni->columns - 2, curfeed->cached_line, MODE_NOWRAP); free(tern_string); } char *get_item_string(struct item *cur) { if (nw(cur)) return nc->story_string; else if (unrd(cur)) return nc->u_story_string; else return nc->r_story_string; } void print_item(struct feed *curfeed, struct item *curitem, WINDOW * win, int y, int x) { char *tern_string = NULL; if (!icached(curitem)) { if (curitem->cached_line) free(curitem->cached_line); icacheok(curitem); story_escapes[0].replacement = curitem->title; story_terns[0].status = (curitem->idx == curfeed->nitems_visible); story_terns[1].status = (curitem->idx == 1); story_terns[2].status = (curitem == ni->selitem); story_terns[3].status = (curfeed == ni->selfeed); tern_string = ternary_string(get_item_string(curitem), story_terns, NUM_STORY_TERNS); curitem->cached_line = escape_string(tern_string, story_escapes, NUM_STORY_ESCAPES); } theme_print(win, y, x, ni->width / ni->columns - 2, curitem->cached_line, MODE_NOWRAP); free(tern_string); } void calc_visible(struct feed *cur) { if ((all_shrunk()) || (sh(cur))) cur->nitems_visible = 0; else if (ex(cur)) cur->nitems_visible = max(cur->nitems - 1, 0); else cur->nitems_visible = min(max(cur->nitems - 1, 0), cur->show); } void enumerate(struct feed *first, int line) { struct feed *cur = NULL; int idx = 1; for (cur = first; cur; cur = cur->next) { idx = 1; foreach_item(cur, curitem) curitem->idx = idx++; calc_visible(cur); cur->line = line; line += cur->nitems_visible + 2; } ni->max_offset = max(line - ((ni->height - 4) * ni->columns), 0); } void interface_draw() { int curwin = 0; int i = 1; if (muted()) return; ni->offset = min(ni->max_offset, ni->offset); foreach_feed(curfeed) { if (curfeed->line + curfeed->nitems_visible >= ni->offset) { if (curfeed->line > ni->offset) print_title(curfeed, ni->list[curwin], i++, 1); if (i > ni->height - 5) { if (curwin == (ni->columns - 1)) break; curwin++; i = 1; } foreach_visible_item(curfeed, curitem) { if (curfeed->line + curitem->idx > ni->offset) print_item(curfeed, curitem, ni->list[curwin], i++, 1); if (i > ni->height - 5) { if (curwin == (ni->columns - 1)) goto done; curwin++; i = 1; } } theme_print(ni->list[curwin], i++, 0, ni->width / ni->columns - 2, "", MODE_NOWRAP); if (i > ni->height - 5) { if (curwin == (ni->columns - 1)) break; curwin++; i = 1; } } } done: wclrtobot(ni->list[curwin]); for (i = curwin + 1; i < ni->columns; i++) wclear(ni->list[i]); for (i = 0; i < ni->columns; i++) wborder(ni->list[i], ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE, ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER); update_panels(); doupdate(); } nrss-0.3.9/keys.c0000644034046500244610000001550210655656761014420 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include "nrss.h" #include "conf.h" #define ret_key_const(_str) \ else if(!strcmp( #_str, tmp)) \ key = _str; int get_key(char *data) { char *tmp = data; int i = 0; int mod = 0; int key = 0; for (i = 0; i < 2; i++) { if (!strncmp(tmp, "C-", 2)) { mod |= 1; tmp += 2; } else if (!strncmp(tmp, "M-", 2)) { mod |= 2; tmp += 2; } } if (strlen(tmp) == 1) key = (int) tmp[0]; else if ((!strncmp(tmp, "KEY_F", 5)) && (tmp[5] >= '0') && (tmp[5] <= '9')) { int num = 0; if ((num = atoi(&tmp[5])) > 0) key = KEY_F0 + num; } else if (!strncmp(data, "KEY_RETURN", 11)) key = 10; ret_key_const(KEY_DOWN) /* down-arrow key */ ret_key_const(KEY_UP) /* up-arrow key */ ret_key_const(KEY_LEFT) /* left-arrow key */ ret_key_const(KEY_RIGHT) /* right-arrow key */ ret_key_const(KEY_HOME) /* home key */ ret_key_const(KEY_BACKSPACE) /* backspace key */ ret_key_const(KEY_DL) /* delete-line key */ ret_key_const(KEY_IL) /* insert-line key */ ret_key_const(KEY_DC) /* delete-character key */ ret_key_const(KEY_IC) /* insert-character key */ ret_key_const(KEY_EIC) /* sent by rmir or smir in insert mode */ ret_key_const(KEY_CLEAR) /* clear-screen or erase key */ ret_key_const(KEY_EOS) /* clear-to-end-of-screen key */ ret_key_const(KEY_EOL) /* clear-to-end-of-line key */ ret_key_const(KEY_SF) /* scroll-forward key */ ret_key_const(KEY_SR) /* scroll-backward key */ ret_key_const(KEY_NPAGE) /* next-page key */ ret_key_const(KEY_PPAGE) /* previous-page key */ ret_key_const(KEY_STAB) /* set-tab key */ ret_key_const(KEY_CTAB) /* clear-tab key */ ret_key_const(KEY_CATAB) /* clear-all-tabs key */ ret_key_const(KEY_ENTER) /* enter/send key */ ret_key_const(KEY_PRINT) /* print key */ ret_key_const(KEY_LL) /* lower-left key (home down) */ ret_key_const(KEY_A1) /* upper left of keypad */ ret_key_const(KEY_A3) /* upper right of keypad */ ret_key_const(KEY_B2) /* center of keypad */ ret_key_const(KEY_C1) /* lower left of keypad */ ret_key_const(KEY_C3) /* lower right of keypad */ ret_key_const(KEY_BTAB) /* back-tab key */ ret_key_const(KEY_BEG) /* begin key */ ret_key_const(KEY_CANCEL) /* cancel key */ ret_key_const(KEY_CLOSE) /* close key */ ret_key_const(KEY_COMMAND) /* command key */ ret_key_const(KEY_COPY) /* copy key */ ret_key_const(KEY_CREATE) /* create key */ ret_key_const(KEY_END) /* end key */ ret_key_const(KEY_EXIT) /* exit key */ ret_key_const(KEY_FIND) /* find key */ ret_key_const(KEY_HELP) /* help key */ ret_key_const(KEY_MARK) /* mark key */ ret_key_const(KEY_MESSAGE) /* message key */ ret_key_const(KEY_MOVE) /* move key */ ret_key_const(KEY_NEXT) /* next key */ ret_key_const(KEY_OPEN) /* open key */ ret_key_const(KEY_OPTIONS) /* options key */ ret_key_const(KEY_PREVIOUS) /* previous key */ ret_key_const(KEY_REDO) /* redo key */ ret_key_const(KEY_REFERENCE) /* reference key */ ret_key_const(KEY_REFRESH) /* refresh key */ ret_key_const(KEY_REPLACE) /* replace key */ ret_key_const(KEY_RESTART) /* restart key */ ret_key_const(KEY_RESUME) /* resume key */ ret_key_const(KEY_SAVE) /* save key */ ret_key_const(KEY_SBEG) /* shifted begin key */ ret_key_const(KEY_SCANCEL) /* shifted cancel key */ ret_key_const(KEY_SCOMMAND) /* shifted command key */ ret_key_const(KEY_SCOPY) /* shifted copy key */ ret_key_const(KEY_SCREATE) /* shifted create key */ ret_key_const(KEY_SDC) /* shifted delete-character key */ ret_key_const(KEY_SDL) /* shifted delete-line key */ ret_key_const(KEY_SELECT) /* select key */ ret_key_const(KEY_SEND) /* shifted end key */ ret_key_const(KEY_SEOL) /* shifted clear-to-end-of-line key */ ret_key_const(KEY_SEXIT) /* shifted exit key */ ret_key_const(KEY_SFIND) /* shifted find key */ ret_key_const(KEY_SHELP) /* shifted help key */ ret_key_const(KEY_SHOME) /* shifted home key */ ret_key_const(KEY_SIC) /* shifted insert-character key */ ret_key_const(KEY_SLEFT) /* shifted left-arrow key */ ret_key_const(KEY_SMESSAGE) /* shifted message key */ ret_key_const(KEY_SMOVE) /* shifted move key */ ret_key_const(KEY_SNEXT) /* shifted next key */ ret_key_const(KEY_SOPTIONS) /* shifted options key */ ret_key_const(KEY_SPREVIOUS) /* shifted previous key */ ret_key_const(KEY_SPRINT) /* shifted print key */ ret_key_const(KEY_SREDO) /* shifted redo key */ ret_key_const(KEY_SREPLACE) /* shifted replace key */ ret_key_const(KEY_SRIGHT) /* shifted right-arrow key */ ret_key_const(KEY_SRSUME) /* shifted resume key */ ret_key_const(KEY_SSAVE) /* shifted save key */ ret_key_const(KEY_SSUSPEND) /* shifted suspend key */ ret_key_const(KEY_SUNDO) /* shifted undo key */ ret_key_const(KEY_SUSPEND) /* suspend key */ ret_key_const(KEY_UNDO) /* undo key */ if (key == 0) return 0; if (mod & 1) key = CTRL(key); if (mod & 2) key = ALT(key); return key; } int check_char(void *data) { int len = strlen((char *) data); if ((len == 1) || (get_key((char *) data))) return 0; return 1; } void clear_bind(int key) { for (int i = 0; i < NUM_FBINDINGS; i++) { if (nc->keys[i].bind == key) { logit("Key bound to %s overridden.\n", nc->keys[i].descr); nc->keys[i].bind = 0; } } } int set_key(void *data) { for (int i = 0; i < NUM_FBINDINGS; i++) { if (!strcmp(((char **) data)[0], nc->keys[i].descr)) { int key = get_key(((char **) data)[1]); clear_bind(key); nc->keys[i].bind = key; nc->keys[i].printable = ((char **) data)[1]; return 0; } } logit("Unknown function \"%s\"\n", ((char **) data)[0]); return 1; } nrss-0.3.9/list.c0000644034046500244610000000401710702544733014403 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include "nrss.h" void ladd_item(struct item **head, struct item *newitem) { struct item *cur = NULL; if (*head == NULL) { *head = newitem; (*head)->next = NULL; (*head)->prev = newitem; } else if (!nw((*head))) { newitem->next = *head; newitem->prev = (*head)->prev; (*head)->prev = newitem; *head = newitem; } else { cur = *head; while ((cur->next) && (nw(cur->next))) cur = cur->next; if (!cur->next) (*head)->prev = newitem; else cur->next->prev = newitem; newitem->next = cur->next; newitem->prev = cur; cur->next = newitem; } } int lsearch(struct item *items, char *title) { if(!title) return 0; struct item *cur = NULL; if(!title) return 1; for (cur = items; cur; cur = cur->next) { if (!strcmp(title, cur->title)) return 0; } return 1; } void lfree_item(struct item *head) { if (head) { lfree_item(head->next); free(head->title); free(head->cached_line); free(head->link); free(head); } } void ladd_feed(struct feed **head, struct feed *newfeed) { struct feed *cur = NULL; if (*head == NULL) { *head = newfeed; (*head)->next = NULL; (*head)->prev = newfeed; } else { cur = (*head)->prev; (*head)->prev = newfeed; cur->next = newfeed; newfeed->prev = cur; newfeed->next = NULL; } } void lfree_feed(struct feed *head) { if (head) { lfree_feed(head->next); lfree_item(head->items); free(head->title); free(head->cached_line); free(head->link); free(head); } } nrss-0.3.9/log.c0000644034046500244610000000101010655656761014213 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include "nrss.h" void logit(char *format, ...) { FILE *fp = NULL; va_list ap; if ((fp = fopen(nc->log_file, "a")) > 0) { va_start(ap, format); vfprintf(fp, format, ap); va_end(ap); fclose(fp); } } nrss-0.3.9/macros.h0000644034046500244610000000527610654665301014732 0ustar jjmillermkgroup-l-d#ifndef MACROSH #define MACROSH #define foreach_feed(_cur) \ struct feed *_cur = NULL;\ for(_cur = nc->feeds; _cur; _cur = _cur->next) #define foreach_feed_from(_start, _cur)\ struct feed *_cur = NULL;\ for(_cur = _start; _cur; _cur = _cur->next) #define foreach_feed_from_rev(_start, _cur)\ struct feed *_cur = NULL;\ for(_cur = _start; _cur; _cur = _cur->prev) #define foreach_item(_data, _cur)\ struct item *_cur = _data->items;\ for(_cur = _data->items; _cur != NULL; _cur = _cur->next) #define foreach_visible_item(_data, _cur)\ struct item *_cur = _data->items;\ for(int _i = 0; (_i < _data->nitems_visible)&&(_cur); _i++, _cur = _cur->next) #define min(A, B) ((A < B) ? A : B) #define max(A, B) ((A > B) ? A : B) #define safeset(_x, _a) (_x = (_x ? _x : _a)) #define clear_status() mvwhline(ni->status, 1, 1, ' ', ni->width -2) #define nw(_cur) (_cur->bits & ITEM_NEW) #define setnw(_curf,_cur) _cur->bits |= ITEM_NEW; fcachebad(_curf) #define usetnw(_curf,_cur) _cur->bits &= ~(ITEM_NEW); fcachebad(_curf) #define unrd(_cur) (_cur->bits & ITEM_UNREAD) #define setunrd(_curf,_cur) _cur->bits |= ITEM_UNREAD; fcachebad(_curf) #define usetunrd(_curf,_cur) _cur->bits &= ~(ITEM_UNREAD); fcachebad(_curf) #define icached(_cur) (_cur->bits & ITEM_CACHED) #define icacheok(_cur) (_cur->bits |= ITEM_CACHED) #define icachebad(_cur) (_cur->bits &= ~(ITEM_CACHED)) #define sh(_cur) (_cur->bits & FEED_SHRUNK) #define setsh(_cur) _cur->bits |= FEED_SHRUNK; fcachebad(_cur) #define usetsh(_cur) _cur->bits &= ~(FEED_SHRUNK); fcachebad(_cur) #define ex(_cur) (_cur->bits & FEED_EXP) #define setex(_cur) cur->bits |= FEED_EXP; fcachebad(_cur) #define usetex(_cur) cur->bits &= ~(FEED_EXP); fcachebad(_cur) #define fcached(_cur) (_cur->bits & FEED_CACHED) #define fcacheok(_cur) (_cur->bits |= FEED_CACHED) #define fcachebad(_cur) (_cur->bits &= ~(FEED_CACHED)) #define all_shrunk() (ni->bits & IFACE_ALL_SHRUNK) #define all_soft_shrunk() (ni->bits & IFACE_ALL_SOFT_SHRUNK) #define browser_wait() (nc->bits & CFG_BITS_BROWSER_WAIT) #define offline_mode() (nc->bits & CFG_OFFLINE) #define iface_mute() (nc->bits |= CFG_MUTED) #define iface_unmute() (nc->bits &= ~(CFG_MUTED)) #define muted() (nc->bits & CFG_MUTED) #define signal_alarm() (nc->bits & CFG_ALRM) #define unset_alarm() (nc->bits &= ~(CFG_ALRM)) #define signal_wnch() (nc->bits & CFG_WNCH) #define unset_wnch() (nc->bits &= ~(CFG_WNCH)) #define signal_pipe() (nc->bits & CFG_PIPE) #define unset_pipe() (nc->bits &= ~(CFG_PIPE)) #define signal_child() (nc->children) #define unset_child() (nc->children--) #define set_child() (nc->children++) #define columns_set() (nc->bits & CFG_SETCOLS) #define reader_open() (ni->reader) #define usage_open() (ni->usage) #endif nrss-0.3.9/main.c0000644034046500244610000001100510671706036014350 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include "cnf/cnf.h" #include "conf.h" #include "nrss.h" #include "interface.h" static struct cnf_config_list *cfg_list = NULL; #define CLASSES 4 static struct cnf_config_class classes[CLASSES] = { {'s', CFG_CLASS_STR, '\"', NULL}, {'c', CFG_CLASS_STR, '\"', check_char}, {'i', CFG_CLASS_NUM, '\"', NULL}, {'t', CFG_CLASS_NUM, '\"', check_theme} }; #define METAS 20 static struct cnf_config_meta metas[METAS] = { {"add", "ss", 2, add_feed}, {"rate", "is", 2, set_rate}, {"show", "is", 2, set_show}, {"maxitems", "is", 2, set_max}, {"default_maxitems", "i", 0, set_def_max}, {"default_rate", "i", 0, set_def_rate}, {"default_show", "i", 0, set_def_show}, {"theme", "itt", 1, set_theme}, {"browser_wait", "i", 0, set_browser_wait}, {"browser", "s", 0, set_browser}, {"wget", "s", 0, set_wget}, {"description_filter", "s", 0, set_desc_filter}, {"title_filter", "s", 0, set_story_filter}, {"title_string", "s", 0, set_title_escape}, {"n_story_string", "s", 0, set_story_escape}, {"u_story_string", "s", 0, set_u_story_escape}, {"r_story_string", "s", 0, set_r_story_escape}, {"reader_string", "s", 0, set_reader_escape}, {"columns", "i", 0, set_columns}, {"key", "sc", 0, set_key} }; static struct cnf_config cfg = { " ", METAS, CLASSES, metas, classes }; void cleanup_paths() { free(nc->config_dir); free(nc->config_file); free(nc->log_file); free(nc->feed_dir); free(nc->cache_file); } void cleanup() { cleanup_paths(); lfree_feed(nc->feeds); cnf_free_list(cfg_list, &cfg); interface_destroy(); exit(0); } struct ncfg my_nc = { NULL, NULL, NULL, NULL, NULL, NULL, WGET, NULL, NULL, " %?s(>: ) %U%B%h%U %?x(-:+) [%2%n%1][%3%d%1]%B", " %?s(>: ) %B%2%s%1%B", " %?s(>: ) %2%s%1", " %?s(>: ) %3%s%1", "%B%t%B\n\n%d", 0, 0, {5, 30, 50, 1}, {{COLOR_WHITE, COLOR_BLACK}, {COLOR_BLUE, COLOR_BLACK}, {COLOR_GREEN, COLOR_BLACK}, {COLOR_RED, COLOR_BLACK}}, {{'q', cleanup, "quit", "q"}, {'h', handle_usage, "toggle-usage", "h"}}, {{KEY_DOWN, select_next_item, "next", "KEY_DOWN"}, {KEY_UP, select_prev_item, "prev", "KEY_UP"}, {KEY_NPAGE, select_next_feed, "next-feed", "KEY_NPAGE"}, {KEY_PPAGE, select_prev_feed, "prev-feed", "KEY_PPAGE"}, {'g', handle_goto, "goto", "g"}, {'r', refresh_cur, "refresh", "r"}, {'R', refresh_all, "refresh-all", "R"}, {' ', handle_default, "default", "Space"}, {'C', shrink_all_feeds, "toggle-collapse-all", "C"}, {'x', handle_expand, "toggle-expand", "x"}, {'M', mark_all_read, "mark-all-read", "M"}, {'D', wnch_handler, "redraw", "D"}, {0, soft_shrink_all_feeds, "toggle-set-collapse-all", ""} }, NULL }; int main(int argc, char **argv) { char *home = getenv("HOME"); int ret = 0; setlocale(LC_ALL, ""); nc = &my_nc; parse_args(argc, argv); safeset(nc->config_dir, concat(home, "/.nrss/")); safeset(nc->feed_dir, concat(nc->config_dir, "feeds/")); safeset(nc->config_file, concat(nc->config_dir, "config")); safeset(nc->log_file, concat(nc->config_dir, "log")); nc->cache_file = concat(nc->config_dir, ".cache"); ret = unlink(nc->cache_file); if ((ret) && (errno != ENOENT)) { cleanup_paths(); printf("Unlink failed: %s\n", strerror(errno)); exit(-1); } ret = unlink(nc->log_file); if ((ret) && (errno != ENOENT)) { cleanup_paths(); printf("Unlink failed: %s\n", strerror(errno)); exit(-1); } ret = mkdir(nc->config_dir, 0755); if ((ret != 0) && (errno != EEXIST)) { logit("Couldn't create config dir: %s\n", strerror(errno)); cleanup_paths(); exit(-1); } ret = mkdir(nc->feed_dir, 0755); if ((ret != 0) && (errno != EEXIST)) { logit("Couldn't create feed dir: %s\n", strerror(errno)); cleanup_paths(); exit(-1); } logit("NRSS v%s\n", VERSION); cnf_parse(nc->config_file, &cfg, &cfg_list); signal(SIGALRM, alrm); signal(SIGWINCH, wnch); signal(SIGINT, cleanup); signal(SIGCHLD, chld); signal(SIGTTOU, SIG_IGN); signal(SIGPIPE, pype); alarm(60); interface(nc->defs[DEF_COLS]); cleanup(); return 0; } nrss-0.3.9/Makefile0000644034046500244610000000152210652220460014712 0ustar jjmillermkgroup-l-d#This system type borrowed from dwm include config.mk VPATH += cnf OBJ = args.o commands.o conf.o feeds.o filter.o interface.o \ interface_draw.o list.o log.o main.o parse.o reader.o system.o \ usage.o utility.o cnf.o cache.o keys.o all: verbiage nrss verbiage: @echo CFLAGS = ${CFLAGS} @echo LDFLAGS = ${LDFLAGS} nrss: ${OBJ} @echo CC -o $@ @${CC} -o $@ ${OBJ} ${LDFLAGS} clean: @echo cleaning @rm -f *.o nrss install: nrss @mkdir -p ${DESTDIR}${PREFIX}/bin @cp -f nrss ${DESTDIR}${PREFIX}/bin @chmod 755 ${DESTDIR}${PREFIX}/bin/nrss @mkdir -p ${DESTDIR}${MANPREFIX}/man1 @sed "s/VERSION/${VERSION}/g" < nrss.1 > ${DESTDIR}${MANPREFIX}/man1/nrss.1 @chmod 644 ${DESTDIR}${MANPREFIX}/man1/nrss.1 uninstall: @rm -f ${DESTDIR}${PREFIX}/bin/nrss @rm -f ${DESTDIR}${MANPREFIX}/man1/nrss.1 .PHONY: all clean install uninstall nrss-0.3.9/nrss.10000644034046500244610000000457710761115000014330 0ustar jjmillermkgroup-l-d.TH NRSS 1 "26 February 2008" "Version 0.3.9" "NRSS" .SH NAME NRSS \- An ncurses RSS reader .SH DESCRIPTION NRSS is an RSS reader built to use minimal amounts of external libraries, using a minimal interface while maintaining a featureful client. .SH COMMAND LINE USAGE .TP \-h Simple help .TP \-v Print version .TP \-c [num] Set number of columns .TP \-D [path] Set the configuration directory (default: ~/.nrss/) .TP \-C [path] Set the configuration file (default: ~/.nrss/config) .TP \-F [path] Set the feed directory (default: ~/.nrss/feeds) .TP \-L [path] Set the log file (default: ~/.nrss/log) .SH INTERNAL USAGE Within the program you can use the following (default) keys. These can be changed in your configuration file by using the "key" command. .TP UP or DOWN Select previous or next item/feed (next) (prev) .TP PGUP or PGDOWN Goto previous or next feed (next-feed) (prev-feed) .TP h Display usage (toggle-usage) .TP C Toggle collapse all feeds (toggle-collapse-all) .TP Space Collapse a feed or read a story (default) .TP g Use the defined browser to goto the item's URL (goto) .TP x Show all items in feed (toggle-expand) .TP r Refresh the current feed (refresh) .TP R Refresh all (refresh-all) .TP M Mark all read (mark-all-read) .TP D Redraw screen (redraw) .TP q Quit NRSS (quit) .SH CONFIGURATION The ~/.nrss/config file is where all of the configuration is. You can start by using the example config below. .SH EXAMPLE CONFIG .sp 1 .nf default_rate "5" default_show "30" default_maxitems "50" #Add some feeds add "http://rss.slashdot.org/Slashdot/slashdot" "Slashdot" add "http://www.digg.com/rss/index.xml" "Digg All" add "http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml" "BBC" add "http://www.osnews.com/files/recent.xml" "OSNews" add "http://distrowatch.com/news/dw.xml" "DistroWatch" #Change rate for Slashdot rate "30" "Slashdot" #These aren't defaults, but examples browser "/usr/bin/elinks %u" #Text browsers should enable this browser_wait "1" .SH FILES .TP .I ~/.nrss/config Main configuration file. For advanced usage, see the online configuration documentation: http://codezen.org/nrss-config .TP .I ~/.nrss/log Everyday log file. .TP .I ~/.nrss/feeds/ This is where the raw XML is stored. .SH BUGS None known, but it's not outside of the realm of possibility =P. .SH HOMEPAGE http://codezen.org/nrss .SH AUTHOR Jack Miller nrss-0.3.9/nrss.h0000644034046500244610000000760510673307776014443 0ustar jjmillermkgroup-l-d#ifndef NRSSH #define NRSSH #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #ifdef NCURSESW #include #include #elif NCURSES #include #include #endif #include "macros.h" #ifndef WGET #ifndef WGET_PATH #define WGET "/usr/bin/wget -q -O \"%p\" -U %a %u" #else #define WGET WGET_PATH " -q -O \"%p\" -U %a %u" #endif #endif #ifndef BUFFER #define BUFFER 1024 #endif struct key { int bind; void (*function)(void); char *descr; char *printable; }; struct escape { char *ident; char *replacement; }; struct ternary { char ident; int status; }; #define ITEM_NEW 1 #define ITEM_UNREAD 2 #define ITEM_CACHED 4 struct item { struct item *next; struct item *prev; char *cached_line; char *title; char *link; int descr_start; int descr_len; int bits; int idx; }; #define FEED_SHRUNK 1 #define FEED_EXP 2 #define FEED_CACHED 4 struct feed { struct feed *next; struct feed *prev; char *handle; char *URL; char *title; char *link; char *cached_line; pid_t update_pid; int time; int line; int rate; int show; int keep; int bits; int nitems; int nitems_new; int nitems_unread; int nitems_visible; struct item *items; struct item *olditems; }; struct theme { int fg; int bg; }; #define CTRL_MASK 0x1F #define ALT_BITS 0x10000 #define ALT(_x) (_x | ALT_BITS) #define CTRL(_x) (_x & CTRL_MASK) #define NUM_DEFS 4 #define COLORS 8 #define THEME_DEF 1 #define NUM_BINDINGS 2 #define NUM_FBINDINGS 15 #define DEF_RATE 0 #define DEF_SHOW 1 #define DEF_MAX 2 #define DEF_COLS 3 #define CFG_BITS_BROWSER_WAIT 1 #define CFG_MUTED 2 #define CFG_OFFLINE 4 #define CFG_ALRM 8 #define CFG_PIPE 16 #define CFG_WNCH 32 #define CFG_SETCOLS 64 struct ncfg { /*Files*/ char *config_dir; char *feed_dir; char *config_file; char *log_file; char *cache_file; /*Fork lines*/ char *browser_line; char *wget_line; char *desc_filter_line; char *story_filter_line; /*Escapes*/ char *title_string; char *story_string; char *r_story_string; char *u_story_string; char *descr_string; int bits; int children; int defs[NUM_DEFS]; struct theme themes[COLORS]; struct key keys[NUM_BINDINGS]; struct key fkeys[NUM_FBINDINGS - NUM_BINDINGS]; struct feed *feeds; }; extern char **environ; struct ncfg *nc; /*Args.c*/ void parse_args(int argc, char **args); /*List.c*/ void ladd_item(struct item **head, struct item *newitem); void lfree_item(struct item *head); void ladd_feed(struct feed **head, struct feed *newfeed); void lfree_feed(struct feed *head); int lsearch(struct item *items, char *title); /*Commands.c*/ pid_t wget(char *URL, char *fname); void open_url(char *URL); char *filter_string(char *str, char *cmd); /*Utility.c*/ char *ternary_string(char *format, struct ternary *terns, int num_terns); char *escape_string(char *format, struct escape *escapes, int num_esc); char *concat(char *one, char *two); char *xstrdup(const char *s); char *xstrndup(const char *s, size_t n); void *xmalloc(size_t n); /*Main.c (signals)*/ void cleanup(); /*System.c*/ void update(struct feed *curfeed); void fetched(); void alrm(); void alrm_handler(); void wnch(); void wnch_handler(); void chld(); void chld_handler(); /* Ye old pype handler. */ void pype(); void pipe_handler(); void tick_feeds(); /*Log.c*/ void logit(char *format, ...); /*Parse.c*/ void parse_feed(struct feed *curfeed); /*Interface.c*/ void status_message(char *message, ...); /*Filter.c*/ char *filter_description(char *str); char *read_string_from_fd(int source); void write_string_to_fd(const char *str, int dest); /*Cache.c*/ char *get_cache_descr(int start, int len); void desc_cache(char *descr, int *start, int *len); #endif nrss-0.3.9/parse.c0000644034046500244610000001276110724272211014540 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include "nrss.h" static struct feed *cfd = NULL; static struct item *newitem = NULL; static char *descr = NULL; static char *current_tag = "NRSS"; static char **ptr = NULL; static int items_parsed = 0; static int atom = 0; void strings(void *data, const XML_Char * s, int len) { int size = 0; char *newstr = NULL; if (!ptr) return; else if (!*ptr) *ptr = xstrndup(s, len); else { size = strlen(*ptr) + len + 1; newstr = xmalloc(size); newstr = strcpy(newstr, *ptr); newstr = strncat(newstr, s, len); free(*ptr); *ptr = newstr; } } char *getattr(char *name, const char **attr) { int i = 0; while (attr[i] != NULL) { if (!strcmp(attr[i], name)) return xstrdup(attr[i + 1]); i++; } return NULL; } void start(void *data, const char *el, const char **attr) { if (newitem) { if (!strncmp(el, "title", 6)) { if (!newitem->title) ptr = &newitem->title; current_tag = "title"; } else if (!strncmp(el, "link", 5)) { if (!newitem->link) { if (atom) { char *tmp = getattr("rel", attr); if((tmp)&&(!strncmp(tmp, "alternate", 10))) { free(tmp); tmp = getattr("href", attr); if(tmp) newitem->link = tmp; } else free(tmp); } else ptr = &newitem->link; } current_tag = "link"; } else if (!strncmp(el, "description", 12)) { if (!descr) ptr = &descr; current_tag = "description"; } else if (!strncmp(el, "content", 8)) { if (!descr) ptr = &descr; current_tag = "content"; } } else if (!strncmp(el, "item", 5)) { newitem = xmalloc(sizeof(struct item)); memset(newitem, 0, sizeof(struct item)); current_tag = "item"; descr = NULL; atom = 0; } else if (!strncmp(el, "entry", 6)) { newitem = xmalloc(sizeof(struct item)); memset(newitem, 0, sizeof(struct item)); current_tag = "entry"; descr = NULL; atom = 1; } else if (!strncmp(el, "link", 5)) { if (!cfd->link) ptr = &cfd->link; current_tag = "link"; } else if (!strncmp(el, "title", 6)) { if (!cfd->title) ptr = &cfd->title; current_tag = "title"; } } void end(void *data, const char *el) { if ((newitem)&&((!strncmp(el, "item", 5))||(!strncmp(el, "entry", 6)))) { if (((!lsearch(cfd->items, newitem->title))) || (items_parsed >= cfd->keep)) lfree_item(newitem); else { if (cfd->nitems >= cfd->keep) { cfd->nitems--; if (nw(cfd->items->prev)) cfd->nitems_new--; if (unrd(cfd->items->prev)) cfd->nitems_unread--; cfd->items->prev = cfd->items->prev->prev; lfree_item(cfd->items->prev->next); cfd->items->prev->next = NULL; } setnw(cfd, newitem); setunrd(cfd, newitem); desc_cache(descr, &newitem->descr_start, &newitem->descr_len); free(descr); descr = NULL; ladd_item(&cfd->items, newitem); cfd->nitems++; cfd->nitems_new++; cfd->nitems_unread++; } items_parsed++; newitem = NULL; } else if ((ptr == &newitem->title) && (nc->story_filter_line)) { char *filtered_string = NULL; filtered_string = filter_string(newitem->title, nc->story_filter_line); if(filtered_string) { free(newitem->title); newitem->title = filtered_string; } } if (!strcmp(el, current_tag)) ptr = NULL; } void parse_feed(struct feed *curfeed) { FILE *fp = NULL; char *buff = xmalloc(BUFFER); char *filename = NULL; int len = 0; int error = 0; cfd = curfeed; cfd->nitems_new = 0; foreach_item(cfd, curitem) { usetnw(cfd, curitem); icachebad(curitem); } if (cfd->nitems) cfd->nitems--; newitem = NULL; ptr = NULL; items_parsed = 0; XML_Parser p = XML_ParserCreate("UTF-8"); if (!p) return; filename = concat(nc->feed_dir, curfeed->handle); XML_SetElementHandler(p, start, end); XML_SetCharacterDataHandler(p, strings); if ((fp = fopen(filename, "r"))) { while (!feof(fp)) { len = fread(buff, 1, BUFFER, fp); if (!(error = XML_Parse(p, buff, len, feof(fp)))) { logit("Parser Error: %s (%d)\n", XML_ErrorString(error), XML_GetCurrentLineNumber(p)); break; } } fclose(fp); } if (newitem) { free(newitem->title); free(newitem->link); free(newitem); free(descr); } if (cfd->nitems) cfd->nitems++; XML_ParserFree(p); free(buff); free(filename); } nrss-0.3.9/reader.c0000644034046500244610000000765710655656761014723 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include "nrss.h" #include "interface.h" #define NUM_READER_ESCAPES 3 static struct escape reader_escapes[NUM_READER_ESCAPES] = { {"%d", NULL}, {"%t", NULL}, {"%h", NULL} }; int word_length(char *string) { int i = 0; for (i = 0; string[i]; i++) { if ((string[i] == ' ') || (string[i] == '\n')) break; } return i; } int linect(char *string, int *width) { int i = 0; int offset = 0; int ct = 0; int lines = 1; while (string[i]) { if (string[i] == '\n') { lines++; if (offset > *width) *width = offset; offset = 0; i++; } else if (string[i] == ' ') i++; ct = word_length(&string[i]); offset += ct + 1; if (offset > ni->width - 2) { lines += 1 + (ct / (ni->width - 2)); offset = (ct % (ni->width - 2)); *width = ni->width - 2; } i += ct; } if (offset > *width) *width = offset; return lines; } void reader(char *string) { int lines = 0; int width = 0; char *escaped = NULL; char *filtered = NULL; char *descr = NULL; if (!string) return; descr = get_cache_descr(ni->selitem->descr_start, ni->selitem->descr_len); filtered = filter_description(descr); reader_escapes[0].replacement = filtered ? filtered : descr; reader_escapes[1].replacement = ni->selitem->title; reader_escapes[2].replacement = ni->selfeed->handle; escaped = escape_string(string, reader_escapes, NUM_READER_ESCAPES); lines = linect(escaped, &width); /* Floating placement logic */ /* Calculate some courtesy variables */ int realheight = ni->height - 5; int realidx = (ni->selfeed->line + ni->selitem->idx - ni->offset - 1); int realpos = (realidx) % realheight + 1; int realwidth; /* Realwidth is the width to the left of the reader */ /* If it's the first column, pin it to the left */ if ((realidx / realheight) == 0) realwidth = 0; /* If it's in the middle, center it on screen */ else if ((realidx / realheight) == ni->columns - 1) realwidth = ni->width - width - 2; /* If it's in the last column, pin it to the right */ else realwidth = (ni->width / 2) - (width / 2); /* Actually place the reader window. */ /* Case 1: Plenty of room below */ if (lines <= realheight - (realpos + 1)) ni->reader = newwin(lines + 2, width + 2, realpos + 1, realwidth); /* Case 2: Plenty of room above */ else if (lines <= realpos - 1) ni->reader = newwin(lines + 2, width + 2, (realpos - lines) - 2, realwidth); /* Case 3: There's room overlapping */ else if (lines <= realheight) ni->reader = newwin(lines + 2, width + 2, 0, realwidth); /* Case 4: No room, just maximize the window */ else ni->reader = newwin(realheight + 2, width + 2, 0, realwidth); wbkgdset(ni->reader, ' ' | COLOR_PAIR(THEME_DEF)); wattron(ni->reader, COLOR_PAIR(THEME_DEF)); wclear(ni->reader); ni->preader = new_panel(ni->reader); theme_print(ni->reader, 1, 1, ni->width - 2, escaped, 1); if (lines > (realheight)) theme_print(ni->reader, realheight, width - 5, ni->width - 2, "...", 0); free(descr); free(escaped); free(filtered); wborder(ni->reader, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE, ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER); update_panels(); doupdate(); } void reader_off() { del_panel(ni->preader); delwin(ni->reader); ni->reader = NULL; update_panels(); doupdate(); } nrss-0.3.9/system.c0000644034046500244610000000421510666165053014757 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include "nrss.h" #include "interface.h" void update(struct feed *curfeed) { logit("Init update of %s\n", curfeed->URL); if (!offline_mode()) { curfeed->update_pid = wget(curfeed->URL, curfeed->handle); logit("%s - %d\n", curfeed->handle, curfeed->update_pid); } else { parse_feed(curfeed); enumerate(curfeed, curfeed->line); interface_draw(); } } void fetched() { int status; pid_t pid = 0; while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { foreach_feed(curfeed) { if (pid == curfeed->update_pid) { if (status == 0) { status_message("Updated %s", curfeed->handle); logit("Updated %s\n", curfeed->handle); parse_feed(curfeed); enumerate(curfeed, curfeed->line); } else status_message("Error Updating %s", curfeed->URL); curfeed->update_pid = 0; return; } } } } void tick_feeds() { foreach_feed(curfeed) { curfeed->time--; if (!curfeed->time) { update(curfeed); curfeed->time = curfeed->rate; } } } void wnch_handler() { logit("SIGWNCH\n"); endwin(); refresh(); rfrsh(); enumerate(nc->feeds, nc->feeds->line); interface_draw(); unset_wnch(); } void wnch(int val) { nc->bits |= CFG_WNCH; } void alrm_handler() { logit("SIGALRM\n"); tick_feeds(); alarm(60); unset_alarm(); } void alrm(int val) { nc->bits |= CFG_ALRM; } void chld_handler() { fetched(); interface_draw(); unset_child(); } void chld(int val) { set_child(); } void pipe_handler() { status_message ("Pipe failed. Is your filter command a valid executable?\n"); unset_pipe(); } void pype(int val) { nc->bits |= CFG_PIPE; } nrss-0.3.9/TODO0000644034046500244610000000045010645322741013750 0ustar jjmillermkgroup-l-d-= In the future =- (In no particular order) OpenBSD support. Encapsulation (pod/vidcast) support. Separation into client server. Command line (non ncurses) interface to access. Support for methods other than HTTP/FTP (running scripts); Eliminate external HTTP client (wget/curl) requirement. nrss-0.3.9/usage.c0000644034046500244610000000337310655656761014554 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include "nrss.h" #include "interface.h" void usage() { int i = 0; int y = 0; int bound = NUM_FBINDINGS; int len = 0; int max = 0; int pmax = 0; for (i = 0; i < NUM_FBINDINGS; i++) { logit("Bind: %d\n", nc->keys[i].bind); if(nc->keys[i].bind != 0) { len = strlen(nc->keys[i].descr); if (len > max) max = len; len = strlen(nc->keys[i].printable); if (len > pmax) pmax = len; } else bound--; } ni->usage = newwin(bound + 2, max + pmax + 5, ni->height - bound - 5, ni->width - (max + pmax + 6)); wbkgdset(ni->usage, ' ' | COLOR_PAIR(THEME_DEF)); wattron(ni->usage, COLOR_PAIR(THEME_DEF)); wclear(ni->usage); ni->pusage = new_panel(ni->usage); for (i = 0; i < NUM_FBINDINGS; i++) { if(nc->keys[i].bind != 0) { mvwprintw(ni->usage, y + 1, 2 + (pmax - strlen(nc->keys[i].printable)), "%s", nc->keys[i].printable); mvwprintw(ni->usage, y + 1, 3 + pmax, "%s", nc->keys[i].descr); } y++; } wborder(ni->usage, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE, ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER); update_panels(); doupdate(); } void usage_off() { del_panel(ni->pusage); delwin(ni->usage); ni->usage = NULL; update_panels(); doupdate(); } nrss-0.3.9/utility.c0000644034046500244610000001062110671706036015132 0ustar jjmillermkgroup-l-d/* NRSS - ncurses RSS reader Copyright (C) 2007 Jack Miller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include "nrss.h" #ifdef BSD char *strndup(const char *line, int len) { char *buf = xmalloc(len + 1); int i = 0; for (i = 0; i < len; i++) { if (line[i] == 0) break; buf[i] = line[i]; } buf[i] = 0; return buf; } #endif char *xstrdup(const char *s) { char *temp; if ((temp = strdup(s)) == NULL) { logit("xstrdup: No memory! Bailing.\n"); cleanup(); } return temp; } char *xstrndup(const char *s, size_t n) { char *temp; if ((temp = strndup(s, n)) == NULL) { logit("xstrndup: No memory! Bailing.\n"); cleanup(); } return temp; } void *xmalloc(size_t n) { void *temp; if ((temp = malloc(n)) == NULL) { logit("xmalloc: No memory! Bailing.\n"); cleanup(); } return temp; } char *concat(char *one, char *two) { char *line = NULL; line = xmalloc(strlen(one) + strlen(two) + 1); line = strcpy(line, one); line = strcat(line, two); return line; } int paren_type(char *str, int idx) { if ((idx) && (str[idx - 1] != '\\')) { if (str[idx] == '(') return 1; else if (str[idx] == ')') return -1; } return 0; } void get_tern_range(char *tern, int *idx, int *len, int *end, int status) { int paren_count = 1; int i = 4; while (tern[i]) { if ((tern[i] == ':') && (paren_count == 1) && (tern[i - 1] != '\\')) { if (status) { *idx = 4; *len = i - 4; } else *idx = i + 1; break; } paren_count += paren_type(tern, i); i++; } while ((tern[i]) && (paren_count)) { paren_count += paren_type(tern, i); i++; } if (!status) *len = i - *idx - 1; *end = i; } char *get_ternary(char *line, int *idx, int *len, int *end, struct ternary *terns, int num_terns) { char *tern = line; int i = 0; while ((tern = strstr(tern, "%?")) != NULL) { if ((tern == line) || (tern[-1] != '\\')) { for (i = 0; i < num_terns; i++) { if (terns[i].ident == tern[2]) { get_tern_range(tern, idx, len, end, terns[i].status); break; } } } return tern; } return NULL; } char *ternary_string(char *format, struct ternary *terns, int num_terns) { char *line = NULL; char *sub = NULL; int idx = 0; int len = 0; int end = 0; int temp = 0; if (!format) return NULL; line = xstrdup(format); while ((sub = get_ternary(line, &idx, &len, &end, terns, num_terns)) != NULL) { temp = strlen(sub + end); memmove(sub, sub + idx, len); memmove(sub + len, sub + end, temp + 1); } sub = xmalloc(strlen(line) + 1); strcpy(sub, line); free(line); return sub; } char *get_escape(char *line, int *idx, struct escape *escapes, int num_esc) { char *esc = line; int i = 0; while ((esc = strstr(esc, "%")) != NULL) { if ((esc == line) || (esc[-1] != '\\')) { for (i = 0; i < num_esc; i++) { if (escapes[i].ident[1] == esc[1]) { *idx = i; return esc; } } } esc += 2; } return NULL; } char *escape_string(char *format, struct escape *escapes, int num_esc) { char *line = NULL; char *sub = NULL; char *temp = NULL; int idx = 0; if (!format) return NULL; line = xstrdup(format); while ((sub = get_escape(line, &idx, escapes, num_esc)) != NULL) { if (!escapes[idx].replacement) escapes[idx].replacement = " "; temp = xmalloc(strlen(line) + strlen(escapes[idx].replacement) + 1); memset(temp, 0, strlen(line) + strlen(escapes[idx].replacement) + 1); temp = strncpy(temp, line, (sub - line)); strcat(temp, escapes[idx].replacement); strcpy(strlen(temp) + temp, sub + 2); free(line); line = temp; } return line; }