X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/ad214d52fb2975aabd270de884f892fd1897a5bb..2a795362ca3ea8da3879ea14d81ee2238e40ad91:/sbr/utils.c diff --git a/sbr/utils.c b/sbr/utils.c index 783ac222..4a460762 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -56,7 +56,7 @@ mh_xrealloc(void *ptr, size_t size) return mh_xmalloc(size); if (size == 0) - adios(NULL, "Tried to realloc 0bytes"); + adios(NULL, "Tried to realloc 0 bytes"); memory = realloc(ptr, size); if (!memory) @@ -367,41 +367,38 @@ nmh_init(const char *argv0, int read_context) { /* Read context, if supposed to. */ if (read_context) { + int allow_version_check = 1; + int check_older_version = 0; + char *cp; + context_read(); - /* Check to see if the user is running a different version of nmh - than they had last run, and notify them if so. But only if - they seem to be running an interactive program. */ - if (isatty (fileno (stdin)) && isatty (fileno (stdout)) && - strcmp (invo_name, "ap") && - strcmp (invo_name, "dp") && - strcmp (invo_name, "fmtdump") && - strcmp (invo_name, "install-mh") && - strcmp (invo_name, "mhbuild") && - strcmp (invo_name, "mhfixmsg") && - strcmp (invo_name, "mhl") && - strcmp (invo_name, "mhparam") && - strcmp (invo_name, "mhpath") && - strcmp (invo_name, "mkstemp") && - strcmp (invo_name, "post") && - strcmp (invo_name, "prompter") && - strncmp (invo_name, "rcv", 3) && - strcmp (invo_name, "slocal") && - strcmp (invo_name, "viamail") && - strcmp (invo_name, "whatnow") && - strcmp (invo_name, "whom")) { - - if (nmh_version_changed ()) { + if (read_context != 1 || + ((cp = context_find ("Welcome")) && strcasecmp (cp, "disable") == 0)) { + allow_version_check = 0; + } else if ((cp = getenv ("MHCONTEXT")) != NULL && *cp != '\0') { + /* Context file comes from $MHCONTEXT, so only print the message + if the context file has an older version. If it does, or if it + doesn't have a version at all, update the version. */ + check_older_version = 1; + } + + /* Check to see if the user is running a different (or older, if + specified) version of nmh than they had run bfore, and notify them + if so. But only if read_context was set to a value to enable. */ + if (allow_version_check && isatty (fileno (stdin)) && + isatty (fileno (stdout)) && isatty (fileno (stderr))) { + if (nmh_version_changed (check_older_version)) { printf ("===================================================" - "====================\n"); + "=====================\n"); printf ("Welcome to nmh version %s\n\n", VERSION); - printf ("See the release notes in %s/NEWS .\n\n", + printf ("See the release notes in %s/NEWS\n\n", mhdocdir); print_intro (stdout, 1); printf ("\nThis message will not be repeated until " "nmh is next updated.\n"); printf ("===================================================" - "====================\n\n"); + "=====================\n\n"); fputs ("Press enter to continue: ", stdout); (void) read_line (); @@ -421,20 +418,36 @@ nmh_init(const char *argv0, int read_context) { /* - * Check stored version, and if out-of-date or non-existent, notify the user - * and update. + * Check stored version, and return 1 if out-of-date or non-existent. + * Because the output of "mhparam version" is prefixed with "nmh-", + * use that prefix here. */ int -nmh_version_changed () { - const char *const old_version = context_find("Version"); - - /* mhparam version includes the nmh- prefix, so be consistent with that. */ - if (old_version == NULL || strcmp(old_version, "nmh-" VERSION) != 0) { - context_replace ("Version", "nmh-" VERSION); +nmh_version_changed (int older) { + const char *const context_version = context_find("Version"); + + if (older) { + /* Convert the version strings to floats and compare them. This will + break for versions with multiple decimal points, etc. */ + const float current_version = strtof (VERSION, NULL); + const float old_version = + context_version && strncmp (context_version, "nmh-", 4) == 0 + ? strtof (context_version + 4, NULL) + : 99999999; + + if (context_version == NULL || old_version < current_version) { + context_replace ("Version", "nmh-" VERSION); + } - return 1; + return old_version < current_version ? 1 : 0; } else { - return 0; + if (context_version == NULL || strcmp(context_version, "nmh-" VERSION) != 0) { + context_replace ("Version", "nmh-" VERSION); + + return 1; + } else { + return 0; + } } } @@ -471,3 +484,25 @@ contains8bit(const char *start, const char *end) return 0; } + + +/* + * See if input has any 8-bit bytes. + */ +int +scan_input (int fd, int *eightbit) { + int state; + char buf[BUFSIZ]; + + *eightbit = 0; + lseek (fd, (off_t) 0, SEEK_SET); + + while ((state = read (fd, buf, sizeof buf)) > 0) { + if (contains8bit (buf, buf + state)) { + *eightbit = 1; + return OK; + } + } + + return state == NOTOK ? NOTOK : OK; +}