|
|
1.1 ! root 1: /* post.c - postal address handling */ ! 2: ! 3: #ifndef lint ! 4: static char *rcsid = "$Header: /f/osi/dsap/common/RCS/post.c,v 7.0 89/11/23 21:44:22 mrose Rel $"; ! 5: #endif ! 6: ! 7: /* ! 8: * $Header: /f/osi/dsap/common/RCS/post.c,v 7.0 89/11/23 21:44:22 mrose Rel $ ! 9: * ! 10: * ! 11: * $Log: post.c,v $ ! 12: * Revision 7.0 89/11/23 21:44:22 mrose ! 13: * Release 6.0 ! 14: * ! 15: */ ! 16: ! 17: /* ! 18: * NOTICE ! 19: * ! 20: * Acquisition, use, and distribution of this module and related ! 21: * materials are subject to the restrictions of a license agreement. ! 22: * Consult the Preface in the User's Manual for the full terms of ! 23: * this agreement. ! 24: * ! 25: */ ! 26: ! 27: /* ! 28: SYNTAX: ! 29: address = <address_component> | <address_component> '$' <address> ! 30: address_component = [ '{T61}' ] <string> ! 31: ! 32: EXAMPLE: ! 33: UCL $ Gower Street $ London ! 34: ! 35: Maximum of 6 (UB_POSTAL_LINE) <address_component>'s ! 36: ! 37: */ ! 38: ! 39: /* LINTLIBRARY */ ! 40: ! 41: #include "quipu/util.h" ! 42: #include "quipu/attrvalue.h" ! 43: ! 44: static addrfree (addr) ! 45: struct postaddr * addr; ! 46: { ! 47: struct postaddr * next; ! 48: for (; addr != (struct postaddr *) NULL; addr = next) { ! 49: next = addr->pa_next; ! 50: free (addr->addrcomp); ! 51: free ( (char *)addr); ! 52: } ! 53: } ! 54: ! 55: static addrcmp (a,b) ! 56: struct postaddr * a, *b; ! 57: { ! 58: int res; ! 59: for (; (a != (struct postaddr *) NULL) && (b != (struct postaddr *) NULL) ; ! 60: a = a->pa_next, b=b->pa_next) ! 61: if ((res = lexequ (a->addrcomp, b->addrcomp)) != 0) ! 62: return (res); ! 63: ! 64: if ( a != b) ! 65: return ( a > b ? 1 : -1 ); ! 66: else ! 67: return (0); ! 68: ! 69: } ! 70: ! 71: static struct postaddr * addrcpy (a) ! 72: struct postaddr * a; ! 73: { ! 74: struct postaddr * b, *c, *result = (struct postaddr *) NULL; ! 75: ! 76: c = result; /* to keep lint quiet ! */ ! 77: ! 78: for (; a != (struct postaddr *) NULL; a = a->pa_next) { ! 79: b = (struct postaddr *) smalloc (sizeof (struct postaddr)); ! 80: b -> addrtype = a->addrtype; ! 81: b -> addrcomp = strdup (a->addrcomp); ! 82: ! 83: if (result == (struct postaddr *) NULL) ! 84: result = b; ! 85: else ! 86: c->pa_next = b; ! 87: c = b; ! 88: } ! 89: ! 90: b->pa_next = (struct postaddr *) NULL; ! 91: return (result); ! 92: } ! 93: ! 94: static struct postaddr* addrparse (str) ! 95: char * str; ! 96: { ! 97: struct postaddr * result = (struct postaddr *) NULL; ! 98: struct postaddr * a, *b; ! 99: char * ptr; ! 100: char * mark = NULLCP; ! 101: char t61_str = FALSE; ! 102: extern char t61_flag; ! 103: int i; ! 104: char * octparse (); ! 105: char * prtparse (); ! 106: ! 107: b = result; /* to keep lint quiet */ ! 108: ! 109: if (t61_flag) { ! 110: t61_str = TRUE; ! 111: t61_flag = FALSE; /* indicate recognition */ ! 112: } ! 113: ! 114: str = SkipSpace(str); ! 115: ! 116: for (i=0; i < UB_POSTAL_LINE; i++) { ! 117: mark = NULLCP; ! 118: a = (struct postaddr *) smalloc (sizeof (struct postaddr)); ! 119: ! 120: if ( (ptr=index (str,'$')) != NULLCP) { ! 121: *ptr-- = 0; ! 122: if (isspace (*ptr)) { ! 123: *ptr = 0; ! 124: mark = ptr; ! 125: } ! 126: ptr++; ! 127: } ! 128: ! 129: if (t61_str) { ! 130: a -> addrtype = 1; ! 131: if ((a -> addrcomp = octparse (str)) == NULLCP) ! 132: return ((struct postaddr *)NULL); ! 133: if (strlen (a->addrcomp) > UB_POSTAL_STRING) { ! 134: parse_error ("address string too long",NULLCP); ! 135: return ((struct postaddr *)NULL); ! 136: } ! 137: } else { ! 138: a -> addrtype = 2; ! 139: if ((a -> addrcomp = prtparse (str)) == NULLCP) ! 140: return ((struct postaddr *)NULL); ! 141: if (strlen (a->addrcomp) > UB_POSTAL_STRING) { ! 142: parse_error ("address string too long",NULLCP); ! 143: return ((struct postaddr *)NULL); ! 144: } ! 145: } ! 146: ! 147: ! 148: if (result == (struct postaddr *) NULL) ! 149: result = a; ! 150: else ! 151: b->pa_next = a; ! 152: b = a; ! 153: ! 154: t61_str = FALSE; ! 155: ! 156: if (ptr != NULLCP) { ! 157: *ptr++ = '$'; ! 158: if (mark != NULLCP) ! 159: *mark = ' '; ! 160: str = (SkipSpace(ptr)); ! 161: ptr = str; ! 162: ! 163: if (*ptr++ == '{') { ! 164: if (( str = index (ptr,'}')) == 0) { ! 165: parse_error ("close bracket missing '%s'",--ptr); ! 166: return ((struct postaddr *) NULL); ! 167: } ! 168: *str = 0; ! 169: if (lexequ ("T.61",ptr) != 0) { ! 170: *str = '}'; ! 171: parse_error ("{T.61} expected '%s'",--ptr); ! 172: return ((struct postaddr *) NULL); ! 173: } ! 174: *str++ = '}'; ! 175: str = (SkipSpace(str)); ! 176: t61_str = TRUE; ! 177: } ! 178: } else ! 179: break; ! 180: } ! 181: ! 182: if (ptr != NULLCP) { ! 183: parse_error ("Too many address components",NULLCP); ! 184: return ((struct postaddr *) NULL); ! 185: } ! 186: a -> pa_next = (struct postaddr *) NULL ; ! 187: ! 188: return (result); ! 189: } ! 190: ! 191: ! 192: int postal_indent = -1; ! 193: ! 194: static addrprint (ps,addr,format) ! 195: PS ps; ! 196: struct postaddr * addr; ! 197: int format; ! 198: { ! 199: char * prefix = NULLCP; ! 200: ! 201: for (; addr != (struct postaddr *) NULL; addr = addr->pa_next) { ! 202: if (prefix != NULLCP) ! 203: if (format != READOUT || postal_indent < 0) ! 204: ps_print (ps,prefix); ! 205: else { ! 206: ps_print (ps, "\n"); ! 207: if (postal_indent > 0) ! 208: ps_printf (ps, "%*s", postal_indent, ""); ! 209: } ! 210: ! 211: if (addr->addrtype == 1) { ! 212: if (format != READOUT) ! 213: ps_print (ps,"{T.61}"); ! 214: octprint (ps,addr->addrcomp,format); ! 215: } else ! 216: ps_print (ps,addr->addrcomp); ! 217: if (format == READOUT) { ! 218: prefix = "\n\t\t\t"; ! 219: if (postal_indent == 0) ! 220: postal_indent = 2; ! 221: } ! 222: else ! 223: prefix = " $ "; ! 224: } ! 225: } ! 226: ! 227: ! 228: static PE addrenc (m) ! 229: struct postaddr * m; ! 230: { ! 231: PE ret_pe; ! 232: ! 233: (void) encode_SA_PostalAddress (&ret_pe,0,0,NULLCP,m); ! 234: ! 235: return (ret_pe); ! 236: } ! 237: ! 238: static struct postaddr * addrdec (pe) ! 239: PE pe; ! 240: { ! 241: struct postaddr * m; ! 242: ! 243: if (decode_SA_PostalAddress (pe,1,NULLIP,NULLVP,&m) == NOTOK) ! 244: return ((struct postaddr *) NULL); ! 245: return (m); ! 246: } ! 247: ! 248: post_syntax () ! 249: { ! 250: (void) add_attribute_syntax ("PostalAddress", ! 251: (IFP) addrenc, (IFP) addrdec, ! 252: (IFP) addrparse,addrprint, ! 253: (IFP) addrcpy, addrcmp, ! 254: addrfree, NULLCP, ! 255: NULLIFP, TRUE); ! 256: ! 257: } ! 258:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.