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).
26 #include <ac/string.h>
27 #include <ac/unistd.h>
31 #define TPCDOMAIN "tpc.int"
34 * Remove everything from 'str' which is not a digit
37 strip_nonnum( char *str )
47 if (isdigit((u_char) *p)) {
60 * Remove anything of the form (blah) where
61 * "blah" contains a non-numeric character.
64 remove_parens( char *ibuf, char *obuf )
73 /* look for a closing paren */
74 if (( s = strchr(p, ')')) != NULL) {
75 /* Check the string between p and s */
76 /* for non-numeric characters */
79 if (!isdigit((u_char) *t)) {
87 /* when we get here, p points to the first */
88 /* thing we want to keep, t to the last. */
93 /* no closing paren, what to do? keep it */
99 /* not a paren - copy out */
105 *q = '\0'; /* terminate output string */
113 * Apply local fixups to phone numbers here. Replace this routine
114 * with code to expand common "abbreviations" for phone numbers. For
115 * example, on the U-M campus, it's only necessary to dial the last
116 * 5 digits of the telephone number, and hence people here tend to
117 * give only the last 5 digits of their fax numbers.
120 * If exactly 5 digits were provided, assume it's a campus
121 * phone number and prepend "1313nm" where "mn" are computed
122 * according to the following:
127 * 3 76 e.g. "31234" -> "7631234"
134 munge_phone( char *ibuf, char *obuf )
136 #define UMAREACODE "1313"
140 if (strlen(ibuf) == 7) {
141 /* Assume local number w/o area code */
142 sprintf(obuf, "%s%s", UMAREACODE, ibuf);
145 if (strlen(ibuf) == 10) {
146 /* Assume local number with area code */
147 sprintf(obuf, "%s%s", "1", ibuf);
150 if (strlen(ibuf) != 5) {
151 /* Not 5 digits - leave alone */
158 case '4' : strcpy(prefix, "76");
160 case '7' : strcpy(prefix, "74");
162 case '6' : strcpy(prefix, "93");
164 case '8' : strcpy(prefix, "99");
166 default : /* Unknown, leave alone */
170 sprintf(obuf, "%s%s%s", UMAREACODE, prefix, ibuf);
177 * Convert string to "tpc.int" domain name.
180 faxtotpc( char *phone, char *userinfo )
189 for (p = ibuf, q = obuf; *p != '\0'; p++) {
198 remove_parens(ibuf, obuf);
201 /* Look for "+" - if followed by a number,
202 assume it's an international number and leave
205 if ((p = strchr(ibuf, '+')) != NULL) {
206 if (isdigit((u_char) *(p + 1))) {
207 /* strip any non-digits */
213 /* Apply local munges */
214 munge_phone(ibuf, obuf);
218 /* Convert string of form abcd to remote-printer@d.c.b.a.tpc.int */
220 for (p = ibuf + strlen(ibuf) - 1; p >= ibuf; p--) {
226 strcpy(obuf, "remote-printer");
228 /* include userinfo if present */
229 if (userinfo != NULL && strlen(userinfo)) {
231 strcat(obuf, userinfo);
234 strcat(obuf, ibuf); /* tack on reversed phone number */
235 strcat(obuf, TPCDOMAIN); /* tack on domain name */