|
|
1.1 ! root 1: /* ali.c - the new ali */ ! 2: ! 3: #include "../h/mh.h" ! 4: #include "../h/addrsbr.h" ! 5: #include "../h/aliasbr.h" ! 6: #include <stdio.h> ! 7: ! 8: ! 9: #define NVEC 50 /* maximum number of names */ ! 10: ! 11: /* */ ! 12: ! 13: static struct swit switches[] = { ! 14: #define ALIASW 0 ! 15: "alias aliasfile", 0, ! 16: #define NALIASW 1 ! 17: "noalias", -7, ! 18: ! 19: #define LISTSW 2 ! 20: "list", 0, ! 21: #define NLISTSW 3 ! 22: "nolist", 0, ! 23: ! 24: #define NORMSW 4 ! 25: "normalize", 0, ! 26: #define NNORMSW 5 ! 27: "nonormalize", 0, ! 28: ! 29: #define USERSW 6 ! 30: "user", 0, ! 31: #define NUSERSW 7 ! 32: "nouser", 0, ! 33: ! 34: #define HELPSW 8 ! 35: "help", 4, ! 36: ! 37: NULL, NULL ! 38: }; ! 39: ! 40: /* */ ! 41: ! 42: static int pos = 1; ! 43: ! 44: extern struct aka *akahead; ! 45: ! 46: /* */ ! 47: ! 48: /* ARGSUSED */ ! 49: ! 50: main (argc, argv) ! 51: int argc; ! 52: char *argv[]; ! 53: { ! 54: int i, ! 55: vecp = 0, ! 56: inverted = 0, ! 57: list = 0, ! 58: noalias = 0, ! 59: normalize = AD_NHST; ! 60: char *cp, ! 61: **ap, ! 62: **argp, ! 63: buf[100], ! 64: *vec[NVEC], ! 65: *arguments[MAXARGS]; ! 66: struct aka *ak; ! 67: ! 68: invo_name = r1bindex (argv[0], '/'); ! 69: mts_init (invo_name); ! 70: if ((cp = m_find (invo_name)) != NULL) { ! 71: ap = brkstring (cp = getcpy (cp), " ", "\n"); ! 72: ap = copyip (ap, arguments); ! 73: } ! 74: else ! 75: ap = arguments; ! 76: (void) copyip (argv + 1, ap); ! 77: argp = arguments; ! 78: ! 79: /* */ ! 80: ! 81: while (cp = *argp++) { ! 82: if (*cp == '-') ! 83: switch (smatch (++cp, switches)) { ! 84: case AMBIGSW: ! 85: ambigsw (cp, switches); ! 86: done (1); ! 87: case UNKWNSW: ! 88: adios (NULLCP, "-%s unknown", cp); ! 89: case HELPSW: ! 90: (void) sprintf (buf, "%s [switches] aliases ...", ! 91: invo_name); ! 92: help (buf, switches); ! 93: done (1); ! 94: ! 95: case ALIASW: ! 96: if (!(cp = *argp++) || *cp == '-') ! 97: adios (NULLCP, "missing argument to %s", argp[-2]); ! 98: if ((i = alias (cp)) != AK_OK) ! 99: adios (NULLCP, "aliasing error in %s - %s", ! 100: cp, akerror (i)); ! 101: continue; ! 102: case NALIASW: ! 103: noalias++; ! 104: continue; ! 105: ! 106: case LISTSW: ! 107: list++; ! 108: continue; ! 109: case NLISTSW: ! 110: list = 0; ! 111: continue; ! 112: ! 113: case NORMSW: ! 114: normalize = AD_HOST; ! 115: continue; ! 116: case NNORMSW: ! 117: normalize = AD_NHST; ! 118: continue; ! 119: ! 120: case USERSW: ! 121: inverted++; ! 122: continue; ! 123: case NUSERSW: ! 124: inverted = 0; ! 125: continue; ! 126: } ! 127: vec[vecp++] = cp; ! 128: } ! 129: ! 130: if (!noalias) ! 131: (void) alias (AliasFile); ! 132: ! 133: /* */ ! 134: ! 135: if (vecp) ! 136: for (i = 0; i < vecp; i++) ! 137: if (inverted) ! 138: print_usr (vec[i], list, normalize); ! 139: else ! 140: print_aka (akvalue (vec[i]), list, 0); ! 141: else { ! 142: if (inverted) ! 143: adios (NULLCP, "usage: %s addresses ... (you forgot the addresses)", ! 144: invo_name); ! 145: ! 146: for (ak = akahead; ak; ak = ak -> ak_next) { ! 147: printf ("%s: ", ak -> ak_name); ! 148: pos += strlen (ak -> ak_name) + 1; ! 149: print_aka (akresult (ak), list, pos); ! 150: } ! 151: } ! 152: ! 153: done (0); ! 154: } ! 155: ! 156: /* */ ! 157: ! 158: print_aka (p, list, margin) ! 159: register char *p; ! 160: int list, ! 161: margin; ! 162: { ! 163: register char c; ! 164: ! 165: if (p == NULL) { ! 166: printf ("<empty>\n"); ! 167: return; ! 168: } ! 169: ! 170: while (c = *p++) ! 171: switch (c) { ! 172: case ',': ! 173: if (*p) ! 174: if (list) ! 175: printf ("\n%*s", margin, ""); ! 176: else ! 177: if (pos >= 68) { ! 178: printf (",\n "); ! 179: pos = 2; ! 180: } ! 181: else { ! 182: printf (", "); ! 183: pos += 2; ! 184: } ! 185: ! 186: case NULL: ! 187: break; ! 188: ! 189: default: ! 190: pos++; ! 191: (void) putchar (c); ! 192: } ! 193: ! 194: (void) putchar ('\n'); ! 195: pos = 1; ! 196: } ! 197: ! 198: /* */ ! 199: ! 200: print_usr (s, list, norm) ! 201: register char *s; ! 202: int list, ! 203: norm; ! 204: { ! 205: register char *cp, ! 206: *pp, ! 207: *vp; ! 208: register struct aka *ak; ! 209: register struct mailname *mp, ! 210: *np; ! 211: ! 212: if ((pp = getname (s)) == NULL) ! 213: adios (NULLCP, "no address in \"%s\"", s); ! 214: if ((mp = getm (pp, NULLCP, 0, norm, NULLCP)) == NULL) ! 215: adios (NULLCP, "bad address \"%s\"", s); ! 216: while (getname ("")) ! 217: continue; ! 218: ! 219: vp = NULL; ! 220: for (ak = akahead; ak; ak = ak -> ak_next) { ! 221: pp = akresult (ak); ! 222: while (cp = getname (pp)) { ! 223: if ((np = getm (cp, NULLCP, 0, norm, NULLCP)) == NULL) ! 224: continue; ! 225: if (uleq (mp -> m_host, np -> m_host) ! 226: && uleq (mp -> m_mbox, np -> m_mbox)) { ! 227: vp = vp ? add (ak -> ak_name, add (",", vp)) ! 228: : getcpy (ak -> ak_name); ! 229: mnfree (np); ! 230: while (getname ("")) ! 231: continue; ! 232: break; ! 233: } ! 234: mnfree (np); ! 235: } ! 236: } ! 237: mnfree (mp); ! 238: ! 239: printf ("%s: ", s); ! 240: print_aka (vp ? vp : s, list, pos += strlen (s) + 1); ! 241: if (vp) ! 242: free (vp); ! 243: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.