summaryrefslogtreecommitdiff
path: root/sfeed_frames.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2014-04-19 21:08:48 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2014-04-19 21:08:48 +0200
commit2f50ad527869535106d946008fb1e09f25f3acae (patch)
tree6c36cd8b2811899bebd3df32bbb1c235eab8100e /sfeed_frames.c
parent0091772bf234cabaa318ececdd6e261e712c654a (diff)
sfeed_frames: allow without feedname
will use "unknown" as the directory name. also some cleanups Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
Diffstat (limited to 'sfeed_frames.c')
-rw-r--r--sfeed_frames.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/sfeed_frames.c b/sfeed_frames.c
index ac24638..61730e2 100644
--- a/sfeed_frames.c
+++ b/sfeed_frames.c
@@ -96,10 +96,11 @@ int
main(int argc, char **argv) {
struct feed *f, *fcur = NULL;
char *fields[FieldLast];
- char name[256]; /* TODO: bigger size? */
+ char name[64]; /* TODO: bigger size? */
char *basepath = ".";
char dirpath[PATH_MAX], filepath[PATH_MAX];
char reldirpath[PATH_MAX], relfilepath[PATH_MAX];
+ char *feedname = "";
unsigned long totalfeeds = 0, totalnew = 0;
unsigned int isnew;
time_t parsedtime, comparetime;
@@ -136,13 +137,20 @@ main(int argc, char **argv) {
"<body class=\"frame\"><div id=\"items\">", fpitems);
while(parseline(&line, &linesize, fields, FieldLast, '\t', stdin) > 0) {
- /* first of feed section or new feed section. */
- if(!totalfeeds || (fcur && strcmp(fcur->name, fields[FieldFeedName]))) {
+ feedname = fields[FieldFeedName];
+ if(feedname[0] == '\0') {
+ feedname = "unknown";
+ /* assume single feed (hide sidebar) */
+ if(!totalfeeds)
+ showsidebar = 0;
+ }
+ /* first of feed section or new feed section (differ from previous). */
+ if(!totalfeeds || (fcur && strcmp(fcur->name, feedname))) {
/* TODO: makepathname isnt necesary if fields[FieldFeedName] is the same as the previous line */
/* TODO: move this part below where FieldFeedName is checked if its different ? */
/* make directory for feedname */
- if(!(namelen = makepathname(fields[FieldFeedName], name, sizeof(name))))
+ if(!(namelen = makepathname(feedname, name, sizeof(name))))
continue;
if(snprintf(dirpath, sizeof(dirpath), "%s/%s", basepath, name) <= 0)
@@ -151,7 +159,8 @@ main(int argc, char **argv) {
/* directory doesn't exist: try to create it. */
if(stat(dirpath, &st) == -1) {
if(mkdir(dirpath, S_IRWXU) == -1) {
- fprintf(stderr, "sfeed_frames: can't make directory '%s': %s\n", dirpath, strerror(errno));
+ fprintf(stderr, "sfeed_frames: can't make directory '%s': %s\n",
+ dirpath, strerror(errno));
exit(EXIT_FAILURE);
}
}
@@ -162,23 +171,15 @@ main(int argc, char **argv) {
if(totalfeeds) { /* end previous one. */
fputs("</table>\n", fpitems);
-
-
fcur->next = f;
fcur = fcur->next;
-
-
} else {
/* first item. */
fcur = f;
-
feeds = fcur;
- /* assume single feed (hide sidebar) */
- if(fields[FieldFeedName][0] == '\0')
- showsidebar = 0;
}
/* write menu link if new. */
- if(!(fcur->name = strdup(fields[FieldFeedName])))
+ if(!(fcur->name = strdup(feedname)))
die("can't allocate enough memory");
if(fields[FieldFeedName][0] != '\0') {
fputs("<h2 id=\"", fpitems);
@@ -192,7 +193,6 @@ main(int argc, char **argv) {
fputs("<table cellpadding=\"0\" cellspacing=\"0\">\n", fpitems);
totalfeeds++;
}
-
/* write content */
if(!(namelen = makepathname(fields[FieldTitle], name, sizeof(name))))
continue;