Centralise the program name into the main header file. I'm probably
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 2 Nov 2008 10:41:57 +0000 (10:41 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 2 Nov 2008 10:41:57 +0000 (10:41 +0000)
not planning to change it any more, but it seems generally more
sensible to keep it in one place just in case.

git-svn-id: svn://svn.tartarus.org/sgt/agedu@8252 cda61777-01e9-0310-a592-d414129be87e

agedu.c
agedu.h
html.c
httpd.c
licence.c
trie.c

diff --git a/agedu.c b/agedu.c
index 83f8ead..07e9415 100644 (file)
--- a/agedu.c
+++ b/agedu.c
@@ -258,7 +258,7 @@ static void text_query(const void *mappedfile, const char *querydir,
  */
 
 #define OPTHELP(NOVAL, VAL, SHORT, LONG, HELPPFX, HELPARG, HELPLINE, HELPOPT) \
-    HELPPFX("usage") HELPLINE("agedu [options] action [action...]") \
+    HELPPFX("usage") HELPLINE(PNAME " [options] action [action...]") \
     HELPPFX("actions") \
     VAL(SCAN) SHORT(s) LONG(scan) \
        HELPARG("directory") HELPOPT("scan and index a directory") \
@@ -439,7 +439,7 @@ int main(int argc, char **argv)
     triewalk *tw;
     indexbuild *ib;
     const struct trie_file *tf;
-    char *filename = "agedu.dat";
+    char *filename = PNAME ".dat";
     int doing_opts = 1;
     enum { TEXT, HTML, SCAN, DUMP, SCANDUMP, LOAD, HTTPD };
     struct action {
@@ -736,7 +736,7 @@ int main(int argc, char **argv)
                        auth = HTTPD_AUTH_MAGIC | HTTPD_AUTH_BASIC;
                    else if (!strcmp(optval, "help") ||
                             !strcmp(optval, "list")) {
-                       printf("agedu: supported HTTP authentication types"
+                       printf(PNAME ": supported HTTP authentication types"
                               " are:\n"
                               "       magic      use Linux /proc/net/tcp to"
                               " determine owner of peer socket\n"
@@ -845,7 +845,7 @@ int main(int argc, char **argv)
                char *buf = fgetline(stdin);
                unsigned newpathsep;
                buf[strcspn(buf, "\r\n")] = '\0';
-               if (1 != sscanf(buf, "agedu dump file. pathsep=%x",
+               if (1 != sscanf(buf, DUMPHDR "%x",
                                &newpathsep)) {
                    fprintf(stderr, "%s: header in dump file not recognised\n",
                            PNAME);
@@ -866,7 +866,7 @@ int main(int argc, char **argv)
                    return 1;
                }
                if (fstat(fd, &st) < 0) {
-                   perror("agedu: fstat");
+                   perror(PNAME ": fstat");
                    return 1;
                }
                ctx->datafile_dev = st.st_dev;
@@ -906,7 +906,7 @@ int main(int argc, char **argv)
            }
 
            if (mode == SCANDUMP)
-               printf("agedu dump file. pathsep=%02x\n", (unsigned char)pathsep);
+               printf(DUMPHDR "%02x\n", (unsigned char)pathsep);
 
            /*
             * Scan the directory tree, and write out the trie component
@@ -988,7 +988,7 @@ int main(int argc, char **argv)
                 * will take; enlarge the file, and memory-map it.
                 */
                if (fstat(fd, &st) < 0) {
-                   perror("agedu: fstat");
+                   perror(PNAME ": fstat");
                    return 1;
                }
 
@@ -998,11 +998,11 @@ int main(int argc, char **argv)
                totalsize = index_compute_size(st.st_size, count);
 
                if (lseek(fd, totalsize-1, SEEK_SET) < 0) {
-                   perror("agedu: lseek");
+                   perror(PNAME ": lseek");
                    return 1;
                }
                if (write(fd, "\0", 1) < 1) {
-                   perror("agedu: write");
+                   perror(PNAME ": write");
                    return 1;
                }
 
@@ -1011,7 +1011,7 @@ int main(int argc, char **argv)
 
                mappedfile = mmap(NULL, totalsize, PROT_READ|PROT_WRITE,MAP_SHARED, fd, 0);
                if (!mappedfile) {
-                   perror("agedu: mmap");
+                   perror(PNAME ": mmap");
                    return 1;
                }
 
@@ -1039,13 +1039,13 @@ int main(int argc, char **argv)
                return 1;
            }
            if (fstat(fd, &st) < 0) {
-               perror("agedu: fstat");
+               perror(PNAME ": fstat");
                return 1;
            }
            totalsize = st.st_size;
            mappedfile = mmap(NULL, totalsize, PROT_READ, MAP_SHARED, fd, 0);
            if (!mappedfile) {
-               perror("agedu: mmap");
+               perror(PNAME ": mmap");
                return 1;
            }
            pathsep = trie_pathsep(mappedfile);
@@ -1072,13 +1072,13 @@ int main(int argc, char **argv)
                return 1;
            }
            if (fstat(fd, &st) < 0) {
-               perror("agedu: fstat");
+               perror(PNAME ": fstat");
                return 1;
            }
            totalsize = st.st_size;
            mappedfile = mmap(NULL, totalsize, PROT_READ, MAP_SHARED, fd, 0);
            if (!mappedfile) {
-               perror("agedu: mmap");
+               perror(PNAME ": mmap");
                return 1;
            }
            pathsep = trie_pathsep(mappedfile);
@@ -1108,13 +1108,13 @@ int main(int argc, char **argv)
                return 1;
            }
            if (fstat(fd, &st) < 0) {
-               perror("agedu: fstat");
+               perror(PNAME ": fstat");
                return 1;
            }
            totalsize = st.st_size;
            mappedfile = mmap(NULL, totalsize, PROT_READ, MAP_SHARED, fd, 0);
            if (!mappedfile) {
-               perror("agedu: mmap");
+               perror(PNAME ": mmap");
                return 1;
            }
            pathsep = trie_pathsep(mappedfile);
@@ -1122,7 +1122,7 @@ int main(int argc, char **argv)
            maxpathlen = trie_maxpathlen(mappedfile);
            buf = snewn(maxpathlen, char);
 
-           printf("agedu dump file. pathsep=%02x\n", (unsigned char)pathsep);
+           printf(DUMPHDR "%02x\n", (unsigned char)pathsep);
            tw = triewalk_new(mappedfile);
            while ((tf = triewalk_next(tw, buf)) != NULL)
                dump_line(buf, tf);
@@ -1138,13 +1138,13 @@ int main(int argc, char **argv)
                return 1;
            }
            if (fstat(fd, &st) < 0) {
-               perror("agedu: fstat");
+               perror(PNAME ": fstat");
                return 1;
            }
            totalsize = st.st_size;
            mappedfile = mmap(NULL, totalsize, PROT_READ, MAP_SHARED, fd, 0);
            if (!mappedfile) {
-               perror("agedu: mmap");
+               perror(PNAME ": mmap");
                return 1;
            }
            pathsep = trie_pathsep(mappedfile);
diff --git a/agedu.h b/agedu.h
index 21c015a..2ad9a5b 100644 (file)
--- a/agedu.h
+++ b/agedu.h
@@ -4,6 +4,8 @@
 
 #define PNAME "agedu"
 
+#define DUMPHDR "agedu dump file. pathsep="
+
 #define lenof(x) (sizeof((x))/sizeof(*(x)))
 
 extern char pathsep;
diff --git a/html.c b/html.c
index f7f8c3e..7633dec 100644 (file)
--- a/html.c
+++ b/html.c
@@ -425,7 +425,7 @@ char *html_query(const void *t, unsigned long index,
      */
     htprintf(ctx, "<head>\n");
     trie_getpath(t, index, path);
-    htprintf(ctx, "<title>agedu: ");
+    htprintf(ctx, "<title>%s: ", PNAME);
     htescape(ctx, path, strlen(path), 0);
     htprintf(ctx, "</title>\n");
     htprintf(ctx, "</head>\n");
diff --git a/httpd.c b/httpd.c
index e71fef7..a11d6e7 100644 (file)
--- a/httpd.c
+++ b/httpd.c
@@ -20,6 +20,7 @@
 #include <netinet/in.h>
 #include <syslog.h>
 
+#include "agedu.h"
 #include "malloc.h"
 #include "html.h"
 #include "httpd.h"
@@ -66,7 +67,7 @@ static char *http_error(char *code, char *errmsg, char *extraheader,
 {
     return dupfmt("HTTP/1.1 %s %s\r\n"
                  "Date: %D\r\n"
-                 "Server: agedu\r\n"
+                 "Server: " PNAME "\r\n"
                  "Connection: close\r\n"
                  "%s"
                  "Content-Type: text/html; charset=US-ASCII\r\n"
@@ -87,7 +88,7 @@ static char *http_success(char *mimetype, int stuff_cr, char *document)
     return dupfmt("HTTP/1.1 200 OK\r\n"
                  "Date: %D\r\n"
                  "Expires: %D\r\n"
-                 "Server: agedu\r\n"
+                 "Server: " PNAME "\r\n"
                  "Connection: close\r\n"
                  "Content-Type: %s\r\n"
                  "\r\n"
@@ -186,7 +187,7 @@ char *got_data(struct connctx *ctx, char *data, int length,
            /* Restore the request to the way we received it. */
            *z2 = c2;
            *z1 = c1;
-           text = dupfmt("<code>agedu</code> received the HTTP request"
+           text = dupfmt("<code>" PNAME "</code> received the HTTP request"
                          " \"<code>%h</code>\", which contains no URL.",
                          line);
            ret = http_error("400", "Bad request", NULL, text);
@@ -279,8 +280,8 @@ char *got_data(struct connctx *ctx, char *data, int length,
        if (!magic_access && !auth_correct) {
            if (auth_string && !auth_provided) {
                ret = http_error("401", "Unauthorized",
-                                "WWW-Authenticate: Basic realm=\"agedu\"\r\n",
-                                "Please authenticate to view these pages.");
+                                "WWW-Authenticate: Basic realm=\""PNAME"\"\r",
+                                "\nPlease authenticate to view these pages.");
            } else {
                ret = http_error("403", "Forbidden", NULL,
                                 "This is a restricted-access set of pages.");
@@ -487,7 +488,7 @@ void run_httpd(const void *t, int authmask, const struct httpd_config *dcfg,
        if (dcfg->basicauthdata) {
            userpass = dcfg->basicauthdata;
        } else {
-           sprintf(username, "agedu");
+           strcpy(username, PNAME);
            rname = "/dev/urandom";
            fd = open(rname, O_RDONLY);
            if (fd < 0) {
@@ -551,7 +552,7 @@ void run_httpd(const void *t, int authmask, const struct httpd_config *dcfg,
        if (authmask != HTTPD_AUTH_NONE)
            printf("Web server is unauthenticated\n");
     } else {
-       fprintf(stderr, "agedu: authentication method not supported\n");
+       fprintf(stderr, PNAME ": authentication method not supported\n");
        exit(1);
     }
     if (!dcfg->address) {
index 22627c5..f2bffae 100644 (file)
--- a/licence.c
+++ b/licence.c
@@ -1,5 +1,7 @@
+#include "agedu.h"
+
 const char *const licence[] = {
-    "agedu is copyright 2008 Simon Tatham. All rights reserved.\n",
+    PNAME " is copyright 2008 Simon Tatham. All rights reserved.\n",
     "\n",
     "Permission is hereby granted, free of charge, to any person\n",
     "obtaining a copy of this software and associated documentation files\n",
diff --git a/trie.c b/trie.c
index b044df4..7168a9e 100644 (file)
--- a/trie.c
+++ b/trie.c
@@ -156,7 +156,7 @@ static void tb_seek(triebuild *tb, off_t off)
 {
     tb->offset = off;
     if (lseek(tb->fd, off, SEEK_SET) < 0) {
-       fprintf(stderr, "agedu: lseek: %s\n", strerror(errno));
+       fprintf(stderr, PNAME ": lseek: %s\n", strerror(errno));
        exit(1);
     }
 }
@@ -167,7 +167,7 @@ static void tb_write(triebuild *tb, const void *buf, size_t len)
     while (len > 0) {
        int ret = write(tb->fd, buf, len);
        if (ret < 0) {
-           fprintf(stderr, "agedu: write: %s\n", strerror(errno));
+           fprintf(stderr, PNAME ": write: %s\n", strerror(errno));
            exit(1);
        }
        len -= ret;