mhl and mhbuild ignore to long lines
[mmh] / sbr / error.c
index 42511c9..1841ce4 100644 (file)
@@ -7,25 +7,20 @@
 */
 
 #include <h/mh.h>
-
-#ifdef HAVE_WRITEV
-# include <sys/types.h>
-# include <sys/uio.h>
-#endif
-
 #include <errno.h>
+#include <stdarg.h>
 
 
 /*
 ** print out error message
 */
 void
-advise (char *what, char *fmt, ...)
+advise(char *what, char *fmt, ...)
 {
        va_list ap;
 
        va_start(ap, fmt);
-       advertise (what, NULL, fmt, ap);
+       advertise(what, NULL, fmt, ap);
        va_end(ap);
 }
 
@@ -34,14 +29,14 @@ advise (char *what, char *fmt, ...)
 ** print out error message and exit
 */
 void
-adios (char *what, char *fmt, ...)
+adios(int status, char *what, char *fmt, ...)
 {
        va_list ap;
 
        va_start(ap, fmt);
-       advertise (what, NULL, fmt, ap);
+       advertise(what, NULL, fmt, ap);
        va_end(ap);
-       done (1);
+       exit(status);
 }
 
 
@@ -49,12 +44,12 @@ adios (char *what, char *fmt, ...)
 ** admonish the user
 */
 void
-admonish (char *what, char *fmt, ...)
+admonish(char *what, char *fmt, ...)
 {
        va_list ap;
 
        va_start(ap, fmt);
-       advertise (what, "continuing...", fmt, ap);
+       advertise(what, "continuing...", fmt, ap);
        va_end(ap);
 }
 
@@ -62,80 +57,39 @@ admonish (char *what, char *fmt, ...)
 /*
 ** main routine for printing error messages.
 **
-** Use writev() if available, for slightly better performance.
-** Why?  Well, there are a couple of reasons.  Primarily, it
-** gives a smoother output...  More importantly though, it's a
-** sexy syscall()...
+** Until 2011-11-01, this routine used writev(). In order to remove
+** ``sexy'' syscalls, in favor for mainstream programming, I removed
+** it. But I want to preserve the following comment:
+**
+**     Use writev() if available, for slightly better performance.
+**     Why?  Well, there are a couple of reasons.  Primarily, it
+**     gives a smoother output...  More importantly though, it's a
+**     sexy syscall()...
+**
+** advertise() does *not* use writev() anymore, and that's good so.
+** -- meillo@marmaro.de
 */
 void
-advertise (char *what, char *tail, char *fmt, va_list ap)
+advertise(char *what, char *tail, char *fmt, va_list ap)
 {
        int  eindex = errno;
 
-#ifdef HAVE_WRITEV
-       char buffer[BUFSIZ], err[BUFSIZ];
-       struct iovec iob[20], *iov;
-#endif
-
-       fflush (stdout);
-
-#ifdef HAVE_WRITEV
-       fflush (stderr);
-       iov = iob;
-
-       if (invo_name && *invo_name) {
-               iov->iov_len = strlen (iov->iov_base = invo_name);
-               iov++;
-               iov->iov_len = strlen (iov->iov_base = ": ");
-               iov++;
-       }
-
-       vsnprintf (buffer, sizeof(buffer), fmt, ap);
-       iov->iov_len = strlen (iov->iov_base = buffer);
-       iov++;
-       if (what) {
-               if (*what) {
-                       iov->iov_len = strlen (iov->iov_base = " ");
-                       iov++;
-                       iov->iov_len = strlen (iov->iov_base = what);
-                       iov++;
-                       iov->iov_len = strlen (iov->iov_base = ": ");
-                       iov++;
-               }
-               if (!(iov->iov_base = strerror (eindex))) {
-                       /* this shouldn't happen, but we'll test for it just in case */
-                       snprintf (err, sizeof(err), "Error %d", eindex);
-                       iov->iov_base = err;
-               }
-               iov->iov_len = strlen (iov->iov_base);
-               iov++;
-       }
-       if (tail && *tail) {
-               iov->iov_len = strlen (iov->iov_base = ", ");
-               iov++;
-               iov->iov_len = strlen (iov->iov_base = tail);
-               iov++;
-       }
-       iov->iov_len = strlen (iov->iov_base = "\n");
-       iov++;
-       writev (fileno (stderr), iob, iov - iob);
-#else
+       fflush(stdout);
        if (invo_name && *invo_name)
-               fprintf (stderr, "%s: ", invo_name);
-       vfprintf (stderr, fmt, ap);
+               fprintf(stderr, "%s: ", invo_name);
+       vfprintf(stderr, fmt, ap);
 
        if (what) {
                char *s;
 
                if (*what)
-                       fprintf (stderr, " %s: ", what);
+                       fprintf(stderr, " %s: ", what);
                if ((s = strerror(eindex)))
-                       fprintf (stderr, "%s", s);
+                       fprintf(stderr, "%s", s);
                else
-                       fprintf (stderr, "Error %d", eindex);
+                       fprintf(stderr, "Error %d", eindex);
        }
        if (tail)
-               fprintf (stderr, ", %s", tail);
-       fputc ('\n', stderr);
-#endif
+               fprintf(stderr, ", %s", tail);
+       fputc('\n', stderr);
 }