3 * Copyright (c) 1993 Regents of the University of Michigan.
6 * Redistribution and use in source and binary forms are permitted
7 * provided that this notice is preserved and that due credit is given
8 * to the University of Michigan at Ann Arbor. The name of the University
9 * may not be used to endorse or promote products derived from this
10 * software without specific prior written permission. This software
11 * is provided ``as is'' without express or implied warranty.
14 * Routines for parsing the facsimileTelephoneNumber field out of
15 * an X.500 entry and converting it to a "tpc.int" domain name.
17 * char *faxtotpc( char *str, char *userinfo)
19 * faxtotpc() returns a pointer to a string allocated with malloc(3).
27 #include <ac/string.h>
28 #include <ac/unistd.h>
32 #define TPCDOMAIN "tpc.int"
35 * Remove everything from 'str' which is not a digit
38 strip_nonnum( char *str )
48 if (isdigit((u_char) *p)) {
61 * Remove anything of the form (blah) where
62 * "blah" contains a non-numeric character.
65 remove_parens( char *ibuf, char *obuf )
74 /* look for a closing paren */
75 if (( s = strchr(p, ')')) != NULL) {
76 /* Check the string between p and s */
77 /* for non-numeric characters */
80 if (!isdigit((u_char) *t)) {
88 /* when we get here, p points to the first */
89 /* thing we want to keep, t to the last. */
94 /* no closing paren, what to do? keep it */
100 /* not a paren - copy out */
106 *q = '\0'; /* terminate output string */
114 * Apply local fixups to phone numbers here. Replace this routine
115 * with code to expand common "abbreviations" for phone numbers. For
116 * example, on the U-M campus, it's only necessary to dial the last
117 * 5 digits of the telephone number, and hence people here tend to
118 * give only the last 5 digits of their fax numbers.
121 * If exactly 5 digits were provided, assume it's a campus
122 * phone number and prepend "1313nm" where "mn" are computed
123 * according to the following:
128 * 3 76 e.g. "31234" -> "7631234"
135 munge_phone( char *ibuf, char *obuf )
137 #define UMAREACODE "1313"
141 if (strlen(ibuf) == 7) {
142 /* Assume local number w/o area code */
143 sprintf(obuf, "%s%s", UMAREACODE, ibuf);
146 if (strlen(ibuf) == 10) {
147 /* Assume local number with area code */
148 sprintf(obuf, "%s%s", "1", ibuf);
151 if (strlen(ibuf) != 5) {
152 /* Not 5 digits - leave alone */
159 case '4' : strcpy(prefix, "76");
161 case '7' : strcpy(prefix, "74");
163 case '6' : strcpy(prefix, "93");
165 case '8' : strcpy(prefix, "99");
167 default : /* Unknown, leave alone */
171 sprintf(obuf, "%s%s%s", UMAREACODE, prefix, ibuf);
178 * Convert string to "tpc.int" domain name.
181 faxtotpc( char *phone, char *userinfo )
190 for (p = ibuf, q = obuf; *p != '\0'; p++) {
199 remove_parens(ibuf, obuf);
202 /* Look for "+" - if followed by a number,
203 assume it's an international number and leave
206 if ((p = strchr(ibuf, '+')) != NULL) {
207 if (isdigit((u_char) *(p + 1))) {
208 /* strip any non-digits */
214 /* Apply local munges */
215 munge_phone(ibuf, obuf);
219 /* Convert string of form abcd to remote-printer@d.c.b.a.tpc.int */
221 for (p = ibuf + strlen(ibuf) - 1; p >= ibuf; p--) {
227 strcpy(obuf, "remote-printer");
229 /* include userinfo if present */
230 if (userinfo != NULL && strlen(userinfo)) {
232 strcat(obuf, userinfo);
235 strcat(obuf, ibuf); /* tack on reversed phone number */
236 strcat(obuf, TPCDOMAIN); /* tack on domain name */