2 * Copyright (c) 1993 Regents of the University of Michigan.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of Michigan at Ann Arbor. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
13 * Routines for parsing the facsimileTelephoneNumber field out of
14 * an X.500 entry and converting it to a "tpc.int" domain name.
16 * char *faxtotpc( char *str, char *userinfo)
18 * faxtotpc() returns a pointer to a string allocated with malloc(3).
23 #include <sys/types.h>
25 #define TPCDOMAIN "tpc.int"
28 * Remove everything from 'str' which is not a digit
31 strip_nonnum( char *str )
41 if (isdigit((u_char) *p)) {
54 * Remove anything of the form (blah) where
55 * "blah" contains a non-numeric character.
58 remove_parens( char *ibuf, char *obuf )
67 /* look for a closing paren */
68 if (( s = strchr(p, ')')) != NULL) {
69 /* Check the string between p and s */
70 /* for non-numeric characters */
73 if (!isdigit((u_char) *t)) {
81 /* when we get here, p points to the first */
82 /* thing we want to keep, t to the last. */
87 /* no closing paren, what to do? keep it */
93 /* not a paren - copy out */
99 *q = '\0'; /* terminate output string */
107 * Apply local fixups to phone numbers here. Replace this routine
108 * with code to expand common "abbreviations" for phone numbers. For
109 * example, on the U-M campus, it's only necessary to dial the last
110 * 5 digits of the telephone number, and hence people here tend to
111 * give only the last 5 digits of their fax numbers.
114 * If exactly 5 digits were provided, assume it's a campus
115 * phone number and prepend "1313nm" where "mn" are computed
116 * according to the following:
121 * 3 76 e.g. "31234" -> "7631234"
128 munge_phone( char *ibuf, char *obuf )
130 #define UMAREACODE "1313"
134 if (strlen(ibuf) == 7) {
135 /* Assume local number w/o area code */
136 sprintf(obuf, "%s%s", UMAREACODE, ibuf);
139 if (strlen(ibuf) == 10) {
140 /* Assume local number with area code */
141 sprintf(obuf, "%s%s", "1", ibuf);
144 if (strlen(ibuf) != 5) {
145 /* Not 5 digits - leave alone */
152 case '4' : strcpy(prefix, "76");
154 case '7' : strcpy(prefix, "74");
156 case '6' : strcpy(prefix, "93");
158 case '8' : strcpy(prefix, "99");
160 default : /* Unknown, leave alone */
164 sprintf(obuf, "%s%s%s", UMAREACODE, prefix, ibuf);
171 * Convert string to "tpc.int" domain name.
174 faxtotpc( char *phone, char *userinfo )
183 for (p = ibuf, q = obuf; *p != '\0'; p++) {
192 remove_parens(ibuf, obuf);
195 /* Look for "+" - if followed by a number,
196 assume it's an international number and leave
199 if ((p = strchr(ibuf, '+')) != NULL) {
200 if (isdigit((u_char) *(p + 1))) {
201 /* strip any non-digits */
207 /* Apply local munges */
208 munge_phone(ibuf, obuf);
212 /* Convert string of form abcd to remote-printer@d.c.b.a.tpc.int */
214 for (p = ibuf + strlen(ibuf) - 1; p >= ibuf; p--) {
220 strcpy(obuf, "remote-printer");
222 /* include userinfo if present */
223 if (userinfo != NULL && strlen(userinfo)) {
225 strcat(obuf, userinfo);
228 strcat(obuf, ibuf); /* tack on reversed phone number */
229 strcat(obuf, TPCDOMAIN); /* tack on domain name */