tRemove code to write index file - scribo - Email-based phlog generator
HTML git clone git://git.z3bra.org/scribo.git
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 221ff7e7716ea3e1ae9fa803d51b4f6bd77e7c78
DIR parent e3e9057cb649b0bcb76dc85fc3181cd0c7235260
HTML Author: Willy Goiffon <dev@z3bra.org>
Date: Sat, 19 Sep 2020 23:41:38 +0200
Remove code to write index file
Diffstat:
M config.def.h | 17 ++++-------------
M scribo.c | 61 +++----------------------------
2 files changed, 10 insertions(+), 68 deletions(-)
---
DIR diff --git a/config.def.h b/config.def.h
t@@ -1,15 +1,6 @@
-char *basedir = ".";
-char *datefmt = "%c";
-
char *author = NULL;
-char *host = "server";
-int port = 70;
-
-/* must include "%s" */
-char *titlefmt = "# %s\n\n";
+char *basedir = ".";
+char *ext = ".txt";
-char *head =
- "[i| Proudly powered by smtpd(1)|Err||]\n"
- "[i|──────────────────────────────────────────────────────────────────────|Err||]\n"
- "[i||Err||]\n"
- "[i|Entries in readdir(3) order:|Err||]\n";
+char *titlefmt = "# %s\n\n"; /* printf(fmt, subject) */
+char *datefmt = "%c"; /* see strftime(3) */
DIR diff --git a/scribo.c b/scribo.c
t@@ -45,13 +45,12 @@ int write_8bit(FILE *, FILE *);
int write_base64(FILE *, FILE *);
int write_qp(FILE *, FILE *);
int writeentry(FILE *, const char *, char *, struct headers *);
-int writeindex(FILE *, char *);
void
usage(char *pgm)
{
- fprintf(stderr, "usage: %s [-h] [-a address] [-b basedir] [-d fmt] [-io file] [-x cmd]\n", pgm);
+ fprintf(stderr, "usage: %s [-h] [-a address] [-b basedir] [-d fmt] [-x cmd] [file]\n", pgm);
}
char *
t@@ -287,7 +286,7 @@ writeentry(FILE *in, const char *cmd, char *dir, struct headers *head)
date = header(head, "Date");
transfer = header(head, "Content-Transfer-Encoding");
- snprintf(entry, sizeof(entry), "%s/%s.txt", dir, sanitize(subject));
+ snprintf(entry, sizeof(entry), "%s/%s%s", dir, sanitize(subject), ext);
out = fopen(entry, "w");
if (!out) {
perror(entry);
t@@ -321,39 +320,13 @@ writeentry(FILE *in, const char *cmd, char *dir, struct headers *head)
}
int
-writeindex(FILE *out, char *dir)
-{
- DIR *dirp;
- struct dirent *d;
-
- dirp = opendir(dir);
- if (!dirp)
- return -1;
-
- fprintf(out, "%s", head);
-
- while ((d = readdir(dirp))) {
- if (d->d_type != DT_REG || !strstr(d->d_name, ".txt"))
- continue;
-
- fprintf(out, "[0|%s|%s|%s|%d]\n", d->d_name, d->d_name, host, port);
- }
-
- closedir(dirp);
-
- return 0;
-}
-
-int
main(int argc, char *argv[])
{
- FILE *in = stdin, *out = stdout;
- char *argv0, *infile, *outfile, *cmd;
+ FILE *in = stdin;
+ char *argv0, *cmd;
struct headers headers;
cmd = NULL;
- infile = NULL;
- outfile = NULL;
ARGBEGIN {
case 'a':
t@@ -365,12 +338,6 @@ main(int argc, char *argv[])
case 'd':
datefmt = EARGF(usage(argv0));
break;
- case 'i':
- infile = EARGF(usage(argv0));
- break;
- case 'o':
- outfile = EARGF(usage(argv0));
- break;
case 'x':
cmd = EARGF(usage(argv0));
break;
t@@ -379,11 +346,8 @@ main(int argc, char *argv[])
exit(1);
} ARGEND;
- if (infile && strcmp(infile, "-"))
- in = fopen(infile, "r");
-
- if (!in) {
- perror(infile);
+ if (argc && !(in = fopen(*argv, "r"))) {
+ perror(*argv);
return -1;
}
t@@ -405,18 +369,5 @@ main(int argc, char *argv[])
fclose(in);
- if (outfile && strcmp(outfile, "-"))
- out = fopen(outfile, "w");
-
- if (!out) {
- perror(outfile);
- return -1;
- }
-
- if (writeindex(out, basedir) < 0)
- return -1;
-
- fclose(out);
-
return 0;
}