Annotation of 43BSDReno/contrib/mh/uip/ali.c, revision 1.1.1.1

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, margin;
                    161: {
                    162:     register char   c;
                    163: 
                    164:     if (p == NULL) {
                    165:        printf ("<empty>\n");
                    166:        return;
                    167:     }
                    168: 
                    169:     while (c = *p++)
                    170:        switch (c) {
                    171:            case ',':
                    172:                if (*p)
                    173:                    if (list)
                    174:                        printf ("\n%*s", margin, "");
                    175:                    else
                    176:                        if (pos >= 68) {
                    177:                            printf (",\n ");
                    178:                            pos = 2;
                    179:                        }
                    180:                        else {
                    181:                            printf (", ");
                    182:                            pos += 2;
                    183:                        }
                    184: 
                    185:            case NULL:
                    186:                break;
                    187: 
                    188:            default:
                    189:                pos++;
                    190:                (void) putchar (c);
                    191:        }
                    192: 
                    193:     (void) putchar ('\n');
                    194:     pos = 1;
                    195: }
                    196: 
                    197: /*  */
                    198: 
                    199: print_usr(s, list, norm)
                    200:        register char *s;
                    201:        int list, norm;
                    202: {
                    203:     register char  *cp,
                    204:                    *pp,
                    205:                    *vp;
                    206:     register struct aka *ak;
                    207:     register struct mailname   *mp,
                    208:                                *np;
                    209: 
                    210:     if ((pp = getname (s)) == NULL)
                    211:        adios (NULLCP, "no address in \"%s\"", s);
                    212:     if ((mp = getm (pp, NULLCP, 0, norm, NULLCP)) == NULL)
                    213:        adios (NULLCP, "bad address \"%s\"", s);
                    214:     while (getname (""))
                    215:        continue;
                    216: 
                    217:     vp = NULL;
                    218:     for (ak = akahead; ak; ak = ak -> ak_next) {
                    219:        pp = akresult (ak);
                    220:        while (cp = getname (pp)) {
                    221:            if ((np = getm (cp, NULLCP, 0, norm, NULLCP)) == NULL)
                    222:                continue;
                    223:            if (uleq (mp -> m_host, np -> m_host)
                    224:                    && uleq (mp -> m_mbox, np -> m_mbox)) {
                    225:                vp = vp ? add (ak -> ak_name, add (",", vp))
                    226:                    : getcpy (ak -> ak_name);
                    227:                mnfree (np);
                    228:                while (getname (""))
                    229:                    continue;
                    230:                break;
                    231:            }
                    232:            mnfree (np);
                    233:        }
                    234:     }
                    235:     mnfree (mp);
                    236: 
                    237:     printf ("%s: ", s);
                    238:     print_aka (vp ? vp : s, list, pos += strlen (s) + 1);
                    239:     if (vp)
                    240:        free (vp);
                    241: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.