change to fold CR-NL into a single NL
[unix-history] / usr / src / usr.bin / finger / util.c
index 247c1d0..cf26a72 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)util.c     5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)util.c     5.8 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -80,9 +80,12 @@ userinfo(pn, pw)
                else
                        ++t;
        pn->realname = strdup(name);
                else
                        ++t;
        pn->realname = strdup(name);
-       pn->office = (p = strsep((char *)NULL, ",")) ? strdup(p) : NULL;
-       pn->officephone = (p = strsep((char *)NULL, ",")) ? strdup(p) : NULL;
-       pn->homephone = (p = strsep((char *)NULL, ",")) ? strdup(p) : NULL;
+       pn->office = ((p = strsep((char *)NULL, ",")) && *p) ?
+           strdup(p) : NULL;
+       pn->officephone = ((p = strsep((char *)NULL, ",")) && *p) ?
+           strdup(p) : NULL;
+       pn->homephone = ((p = strsep((char *)NULL, ",")) && *p) ?
+           strdup(p) : NULL;
 }
 
 match(pw, user)
 }
 
 match(pw, user)
@@ -263,3 +266,50 @@ walloc(pn)
        w->next = NULL;
        return(w);
 }
        w->next = NULL;
        return(w);
 }
+
+char *
+prphone(num)
+       char *num;
+{
+       register char *p;
+       int len;
+       static char pbuf[15];
+
+       /* don't touch anything if the user has their own formatting */
+       for (p = num; *p; ++p)
+               if (!isdigit(*p))
+                       return(num);
+       len = p - num;
+       p = pbuf;
+       switch(len) {
+       case 11:                        /* +0-123-456-7890 */
+               *p++ = '+';
+               *p++ = *num++;
+               *p++ = '-';
+               /* FALLTHROUGH */
+       case 10:                        /* 012-345-6789 */
+               *p++ = *num++;
+               *p++ = *num++;
+               *p++ = *num++;
+               *p++ = '-';
+               /* FALLTHROUGH */
+       case 7:                         /* 012-3456 */
+               *p++ = *num++;
+               *p++ = *num++;
+               *p++ = *num++;
+               break;
+       case 5:                         /* x0-1234 */
+               *p++ = 'x';
+               *p++ = *num++;
+               break;
+       default:
+               return(num);
+       }
+       *p++ = '-';
+       *p++ = *num++;
+       *p++ = *num++;
+       *p++ = *num++;
+       *p++ = *num++;
+       *p = '\0';
+       return(pbuf);
+}