print out certain types of phone numbers in US formats
[unix-history] / usr / src / usr.bin / finger / util.c
index 247c1d0..398fa91 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.6 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -263,3 +263,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);
+}