Lots of little code cleanups to prevent warnings - mostly making sure
[mmh] / sbr / fmt_scan.c
index 2086a94..ae31162 100644 (file)
 #include <zotnet/tws/tws.h>
 #include <h/fmt_compile.h>
 
+#ifdef TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# ifdef TM_IN_SYS_TIME
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
 #define        NFMTS MAXARGS
 
 extern char *formataddr ();    /* hook for custom address formatting */
@@ -234,7 +245,7 @@ get_x400_friendly (char *mbox, char *buffer, int buffer_len)
        return NULL;
 
     if (get_x400_comp (mbox, "/PN=", buffer, buffer_len)) {
-       for (mbox = buffer; mbox = strchr(mbox, '.'); )
+       for (mbox = buffer; (mbox = strchr(mbox, '.')); )
            *mbox++ = ' ';
 
        return buffer;
@@ -636,7 +647,7 @@ fmt_scan (struct format *format, char *scanl, int width, int *dat)
            }
            if (fmt->f_type == FT_LS_ADDR)
                goto unfriendly;
-           if ((str = mn->m_pers) == NULL)
+           if ((str = mn->m_pers) == NULL) {
                if ((str = mn->m_note)) {
                    strncpy (buffer, str, sizeof(buffer));
                    str = buffer;
@@ -674,6 +685,7 @@ fmt_scan (struct format *format, char *scanl, int width, int *dat)
                        break;
                  }
                }
+           }
            break;
 
        case FT_LOCALDATE:
@@ -729,16 +741,22 @@ fmt_scan (struct format *format, char *scanl, int width, int *dat)
                *cp++ = c;
            while (len > wid) {
                /* try to break at a comma; failing that, break at a
-                * space, failing that, just split the line.
+                * space.
                 */
                lastb = 0; sp = lp + wid;
                while (sp > lp && (c = *--sp) != ',') {
                    if (! lastb && isspace(c))
                        lastb = sp - 1;
                }
-               if (sp == lp)
-                   if (! (sp = lastb))
+               if (sp == lp) {
+                   if (! (sp = lastb)) {
                        sp = lp + wid - 1;
+                       while (*sp && *sp != ',' && !isspace(*sp))
+                           sp++;
+                       if (*sp != ',')
+                           sp--;
+                   }
+               }
                len -= sp - lp + 1;
                while (cp < ep && lp <= sp)
                    *cp++ = *lp++;
@@ -747,6 +765,12 @@ fmt_scan (struct format *format, char *scanl, int width, int *dat)
                    *cp++ = ' ';
                while (isspace(*lp))
                    lp++, len--;
+               if (*lp) {
+                   if (cp < ep)
+                       *cp++ = '\n';
+                   for (i=indent; cp < ep && i > 0; i--)
+                       *cp++ = ' ';
+               }
            }
            PUTS (cp, lp);
            }