home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / mush.lzh / mush.7 < prev    next >
Text File  |  1990-05-06  |  55KB  |  1,763 lines

  1.  
  2. #! /bin/sh
  3. # This is a shell archive.  Remove anything before this line, then feed it
  4. # into a shell via "sh file" or similar.  To overwrite existing files,
  5. # type "sh file -c".
  6. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  7. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  8. # If this archive is complete, you will see the following message at the end:
  9. #        "End of archive 7 (of 19)."
  10. # Contents:  mush/addrs.c mush/viewopts.c
  11. # Wrapped by argv@turnpike on Wed May  2 13:59:26 1990
  12. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  13. if test -f 'mush/addrs.c' -a "${1}" != "-c" ; then 
  14.   echo shar: Will not clobber existing file \"'mush/addrs.c'\"
  15. else
  16. echo shar: Extracting \"'mush/addrs.c'\" \(33359 characters\)
  17. sed "s/^X//" >'mush/addrs.c' <<'END_OF_FILE'
  18. X/* addrs.c -- copyright (c) Dan Heller 1/25/1989 */
  19. X
  20. X#include "mush.h"
  21. X
  22. X/*
  23. X * Check to see if all addressees in list1 is in list2.
  24. X * The lists must be as clean as the driven snow (no comments, aliases
  25. X * must have been expanded, all are separated by whitespace (for mk_argv).
  26. X *
  27. X * "user" matches "user" and "user@localhost"
  28. X * "*user" matches "user" at any address whatsoever."
  29. X * !host matches any user destined for the specified host.
  30. X * !some!path is the same, but can be more specifiec in the path.
  31. X * @dom.ain can match any user destined for any host within the domain.
  32. X *      @berkeley.edu would match: dheller@cory.berkeley.edu
  33. X */
  34. Xcompare_addrs(list1, list2, ret_buf)
  35. Xchar *list1, *list2, ret_buf[];
  36. X{
  37. X    register char    *p;
  38. X    char        **addrv, **listv, buf[256]; /* addrs aren't long */
  39. X    int            addrc, listc, a, l, h, ret_val;
  40. X
  41. X    /* autosign2 list contains non-comment addresses */
  42. X    listv = mk_argv(list1, &listc, FALSE);
  43. X    addrv = mk_argv(list2, &addrc, FALSE);
  44. X
  45. X    /* loop thru both lists and convert addresses to !-format
  46. X     * then remove ourhost names so "user" matches "user!local"
  47. X     * also remove possible trailing commas (from list).
  48. X     */
  49. X    for (a = 0; a < addrc; a++) {
  50. X    if (a != addrc-1 && (p = index(addrv[a], ',')) && !p[1])
  51. X        *p = 0;
  52. X    if (addrv[a][0] == '!' || addrv[a][0] == '@')
  53. X        continue;
  54. X    (void) bang_form(buf, addrv[a]);
  55. X    if (strcmp(addrv[a], buf)) /* if they differ... */
  56. X        (void) strcpy(addrv[a], buf); /* save new version */
  57. X    }
  58. X    for (l = 0; l < listc; l++) {
  59. X    if (l != listc-1 && (p = index(listv[l], ',')) && !p[1])
  60. X        *p = 0;
  61. X    if (listv[l][0] == '!' || listv[l][0] == '@')
  62. X        continue;
  63. X    (void) bang_form(buf, listv[l]);
  64. X    if (strcmp(listv[l], buf)) /* if they differ... */
  65. X        (void) strdup(listv[l], buf); /* save new version */
  66. X    }
  67. X
  68. X    Debug("\nlist1 = "), print_argv(listv);
  69. X    Debug("list2 = "), print_argv(addrv), putchar('\n');
  70. X
  71. X    /* loop thru each list comparing each element with the
  72. X     * other, if necessary.
  73. X     */
  74. X    for (l = 0; l < listc; l++) {
  75. X    ret_val = 0;
  76. X    /* check if local recipient with was specified. */
  77. X    if (!(p = rindex(listv[l], '!')))
  78. X        for (a = 0; a < addrc; a++) {
  79. X        /* we have a local user so far.  If addrv[] is
  80. X         * not remote, then strcmp() immediately.
  81. X         * Note that "!" with no host indicates *all*
  82. X         * local users!!!
  83. X         */
  84. X        if (addrv[a][0] == '*') {
  85. X            /* "*user" == "user" or "*" == login */
  86. X            if (!addrv[a][1] && !lcase_strncmp(listv[l], login, -1) ||
  87. X            !lcase_strncmp(listv[l], addrv[a]+1, -1))
  88. X            ret_val = 1;
  89. X        } else if (addrv[a][0] != '!') {
  90. X           if (!lcase_strncmp(addrv[a], listv[l], -1) || !addrv[a][1])
  91. X            ret_val = 1;
  92. X        } else for (h = 0; ourname && ourname[h]; h++)
  93. X            if (!lcase_strncmp(addrv[a]+1, ourname[h], -1)) {
  94. X            ret_val = 1;
  95. X            break;
  96. X            }
  97. X        if (ret_val)
  98. X            break;
  99. X        }
  100. X    /* else this is a remote user */
  101. X    else {
  102. X        /* check all the addresses for @dom.ain stuff or
  103. X         * !path!name type stuff only.
  104. X         */
  105. X        /* first back up p to the previous '!' */
  106. X        char *start, *user = p + 1;
  107. X        while (p > listv[l] && *--p != '!')
  108. X        ;
  109. X        start = p; /* Where to start for _domain_ addrs */
  110. X        for (a = 0; a < addrc; a++) {
  111. X        int len;
  112. X        char *path;
  113. X
  114. X        /* first check the cases of address unmodified by @ and !
  115. X         * or check to see if  *user  is specified.
  116. X         */ 
  117. X        if (addrv[a][0] != '@' && addrv[a][0] != '!') {
  118. X            if (addrv[a][0] == '*') {
  119. X            /* we saved the username at "user" declaration. */
  120. X            /* if "*" is by itself, check against user's login */
  121. X            if (!addrv[a][1] && !lcase_strncmp(user, login, -1) ||
  122. X                addrv[a][1] && !lcase_strncmp(user,addrv[a]+1,-1)){
  123. X                ret_val = 1;
  124. X                break;
  125. X            }
  126. X            } else if (!lcase_strncmp(addrv[a], listv[l], -1)) {
  127. X            ret_val = 1;
  128. X            break;
  129. X            }
  130. X            continue;
  131. X        }
  132. X        path = addrv[a]+1;
  133. X        while (addrv[a][0] == '@' && *path == '.')
  134. X            path++;
  135. X        if ((len = strlen(path)) == 0)
  136. X            continue; /* localhost stuff only -- can't match */
  137. X        /* first check against specified domains */
  138. X        if (addrv[a][0] == '@') {
  139. X            for (p = start; p; (p = index(p, '.')) && ++p)
  140. X            if (!lcase_strncmp(p, path, len) &&
  141. X                (p[len] == '.' || p[len] == 0 || p[len] == '!')) {
  142. X                ret_val = 1;
  143. X                break;
  144. X            }
  145. X        } else if (addrv[a][0] == '!') {
  146. X            /* for !path style, start at head of addr */
  147. X            for (p = listv[l]; p; (p = index(p, '!')) && ++p)
  148. X            if (!lcase_strncmp(p, path, len) &&
  149. X                (p[len] == '!' || p[len] == 0)) {
  150. X                ret_val = 1;
  151. X                break;
  152. X            }
  153. X        }
  154. X        /* If address is in autosign2, goto next addr */
  155. X        if (ret_val)
  156. X            break;
  157. X        }
  158. X    }
  159. X    if (!ret_val) {
  160. X        /* this address isn't in autosign2 list */
  161. X        if (ret_buf)
  162. X        (void) strcpy(ret_buf, listv[l]);
  163. X        break;
  164. X    }
  165. X    }
  166. X    free_vec(listv);
  167. X    free_vec(addrv);
  168. X
  169. X    return ret_val;
  170. X}
  171. X
  172. X/*
  173. X * Parser for stupidly-formed RFC822 addresses.  It has been tested on
  174. X * several bizzare cases as well as the normal stuff and uucp paths.  It
  175. X * takes a string which is a bunch of addresses and unscrambles the first
  176. X * one in the string.  It returns a pointer to the first char past what it
  177. X * unscrambled and copies the unscrambled address to its second argument.
  178. X * 
  179. X * It does NOT deal with trailing (comment) strings --
  180. X *         <whoever@somewhere> (This is a comment)
  181. X *                            ^unscramble_addr return points here
  182. X * 
  183. X * It also does not deal well with malformed <addresses> --
  184. X *         <whoever@somewhere,nowhere>
  185. X *                           ^unscramble_addr return points here
  186. X * 
  187. X * In each of the above cases, the string "whoever@somewhere" is copied
  188. X * to the second argument.
  189. X * 
  190. X * Nothing is done to un-<>ed route-less RFC822/976 addresses, nor to
  191. X * uucp paths, nor to mixed-mode addresses not containing a route.
  192. X * Hopelessly scrambled addresses are not handled brilliantly --
  193. X *     @some.dumb.place,@any.other.place:sys2!user%sys3@sys1
  194. X * parses to
  195. X *     sys2!user%sys3@sys1
  196. X * i.e., the route is simply dropped.
  197. X *
  198. X * If UUCP is defined, a little more work is done with @: routes.  The
  199. X * mangled address given above will unwind to
  200. X *    some.dumb.place!any.other.place!sys1!sys2!sys3!user
  201. X * thanks to intelligence in bang_form().
  202. X */
  203. Xchar *
  204. Xunscramble_addr(addr, naddr)
  205. Xchar *addr;
  206. Xchar *naddr;
  207. X{
  208. X    char *i, *r, *at;
  209. X    char s[BUFSIZ], t[BUFSIZ];
  210. X    int anglebrace = 0;
  211. X
  212. X    /* Make a copy of the address so we can mangle it freely. */
  213. X    if (addr && *addr) {
  214. X    /* Skip any leading whitespace. */
  215. X    for (i = addr; *i && (r = any(i, " \t")) == i;)
  216. X        if (r)
  217. X        i = r + 1;
  218. X    if (*i == '\0')
  219. X        return NULL;
  220. X    /* Skip any leading double-quoted comment. */
  221. X    if (*i == '"') {
  222. X        if ((i = index(i + 1, '"')) && (*i == '\0' || *(++i) == '\0'))
  223. X            return NULL;
  224. X    }
  225. X    /* Skip any more whitespace. */
  226. X    for (; *i && (r = any(i, " \t")) == i;)
  227. X        if (r)
  228. X        i = r + 1;
  229. X    if (*i == '\0')
  230. X        return NULL;
  231. X    /* Check for angle braces around the address. */
  232. X    if (*i == '<') {
  233. X        if (*(++i) == '\0')
  234. X        return NULL;
  235. X        ++anglebrace;
  236. X    }
  237. X    /*
  238. X     * Look for a route.  A route is a comma-separated set of @-tagged
  239. X     *  domains terminated by a colon.  Later versions might try to use
  240. X     *  the route, but for now it confuses too many mailers.
  241. X     */
  242. X    if ((*i == '@') && (r = any(i, " \t:"))) {
  243. X        if (*r != ':')
  244. X        return NULL;
  245. X        if (*(r + 1) == '\0')
  246. X        return NULL;
  247. X#ifndef UUCP
  248. X        /*
  249. X         * Back up to the rightmost @-tagged domain
  250. X         *  (see note below about unwinding)
  251. X         */
  252. X        *r = '\0';
  253. X        i = rindex(i, '@');
  254. X        *r = ':';
  255. X#endif /* !UUCP */
  256. X    }
  257. X    /* Remember how much we've skipped, and copy the rest. */
  258. X    at = i;
  259. X    (void) strncpy(t, i, sizeof t);
  260. X    t[sizeof t - 1] = 0;
  261. X    /* Strip from a trailing angle brace, if present. */
  262. X    if (anglebrace) {
  263. X        if (r = any(t, "> \t")) {
  264. X        if (r == t || *r != '>')
  265. X            return NULL;
  266. X        else
  267. X            *r = '\0';
  268. X        --anglebrace;
  269. X        } else
  270. X        return NULL;
  271. X    }
  272. X    if (t[0] == '@') {
  273. X        /* Chop off any invalid stuff after the address. */
  274. X        if (r = any(index(t, ':'), " \t,(<"))
  275. X        *r = '\0';
  276. X    }
  277. X    } else
  278. X    return NULL;
  279. X    /* Remember where we are so we can return it. */
  280. X    at += strlen(t) + 1;
  281. X    /*
  282. X     * Unscramble the route, if present.
  283. X     *  NOTE:  We assume that a route is present in only two cases:
  284. X     *   1) addr was taken from the "From " line of a stupid mailer
  285. X     *   2) addr was a well-formed, <> enclosed RFC822 address
  286. X     */
  287. X    if (t[0] == '@') {
  288. X#ifdef UUCP
  289. X    if (!bang_form(s, t))
  290. X        return NULL;
  291. X#else /* UUCP */
  292. X    if (r = index(t, ':'))
  293. X        r++;
  294. X    else
  295. X        return NULL;
  296. X    /* Delete the route if extraneous, otherwise unwind it. */
  297. X    if (i = index(r, '@'))
  298. X        (void) strcpy(s, r);
  299. X    else {
  300. X        /*
  301. X         * NOTE:  Unwinding currently uses only the rightmost domain
  302. X         *  in the route.  This will break for mailers that need the
  303. X         *  entire route.  Complete unwinding would require the use
  304. X         *  of % characters, which are avoided for other reasons.
  305. X         */
  306. X        (void) strcpy(s, r);
  307. X        *(--r) = '\0';
  308. X        (void) strcat(s, t);
  309. X    }
  310. X#endif /* UUCP */
  311. X    } else
  312. X    (void) strcpy(s, t);
  313. X    /*
  314. X     * Ok, now the address should be in the form user@domain and
  315. X     *  is held in buffer s (t[] is not copied directly to naddr
  316. X     *  to allow future additional processing to be added here).
  317. X     */
  318. X    if (debug > 1) /* Don't dump this on trivial debugging */
  319. X    wprint("Converting \"%s\" to \"%s\"\n", addr, s);
  320. X    (void) strcpy(naddr, s);
  321. X    return at;
  322. X}
  323. X
  324. X/*
  325. X * Convert RFC822 or mixed addresses to RFC976 `!' form,
  326. X *  copying the new address to d.  The source address is
  327. X *  translated according to RFC822 rules.
  328. X * Return a pointer to the end (nul terminus) of d.
  329. X */
  330. Xchar *
  331. Xbang_form (d, s)
  332. Xchar *d, *s;
  333. X{
  334. X    char *r, *t, *ab = NULL;
  335. X
  336. X    *d = '\0';
  337. X    /* If nothing to do, quit now */
  338. X    if (!s || !*s) {
  339. X    return d;
  340. X    }
  341. X    /* Avoid any angle braces */
  342. X    if (*s == '<') {
  343. X    if (ab = index(s + 1, '>'))
  344. X        s++, *ab = '\0';
  345. X    else
  346. X        return NULL;
  347. X    }
  348. X    /*
  349. X     * Look backwards for the first `@'; this gives us the
  350. X     * primary domain of the RFC822 address
  351. X     */
  352. X    if (*s == '@') {
  353. X    /* An RFC-822 "@domain1,@domain2:" routing */
  354. X    if (t = any(++s, ",:")) {
  355. X        char c = *t;
  356. X        *t = '\0';
  357. X        d += Strcpy(d, s);
  358. X        *d++ = '!';
  359. X        *t++ = c;
  360. X        r = bang_form(d, t);
  361. X    } else
  362. X        r = NULL;
  363. X    } else if ((t = rindex(s, '@')) && t != s) {
  364. X    /* Copy the RFC822 domain as the UUCP head */
  365. X    d += Strcpy(d, t + 1);
  366. X    *d++ = '!';
  367. X    *t = '\0';
  368. X    r = bang_form(d, s);
  369. X    *t = '@';
  370. X    } else if (t = index(s, '!')) {
  371. X    /* A normal UUCP path */
  372. X    *t = '\0';
  373. X    d += Strcpy(d, s);
  374. X    *t++ = *d++ = '!';
  375. X    r = bang_form(d, t);
  376. X    } else if (t = rindex(s, '%')) {
  377. X    /* An imbedded `%' -- treat as low-priority `@' */
  378. X    *t = '@';
  379. X    r = bang_form(d, s);
  380. X    *t = '%';
  381. X    } else
  382. X    r = d + Strcpy(d, s);  /* No `@', `!', or `%' */
  383. X    if (ab)
  384. X    *ab = '>';
  385. X    return r;
  386. X}
  387. X
  388. X/*
  389. X * Route addresses according to certain criteria.  This function is really
  390. X * just a front end for improve_uucp_paths() which does routing (differently).
  391. X * If "route" is null, this routine is being called incorrectly.
  392. X * If route is an address, just call improve_uucp_paths() and return.
  393. X * If route is the null string, then route all addresses via the sender's
  394. X * which is the first name/address on the To: list. If he's on a remote
  395. X * machine, chances are that the addresses of everyone else he mailed to
  396. X * are addresses from his machine.  Reconstruct those addresses to route
  397. X * thru the senders machine first.
  398. X */
  399. Xroute_addresses(to, cc, route_path)
  400. Xchar *to, *cc, *route_path;
  401. X{
  402. X    char pre_path[256], sender[HDRSIZ], tmp[256];
  403. X    register char *next, *p;
  404. X    int c;
  405. X
  406. X    Debug("route_addresses()\n");
  407. X    if (!route_path)
  408. X    return;
  409. X    if (*route_path) {
  410. X    improve_uucp_paths(to, HDRSIZ, route_path);
  411. X    improve_uucp_paths(cc, HDRSIZ, route_path);
  412. X    return;
  413. X    }
  414. X
  415. X    pre_path[0] = 0;
  416. X    /* Get the address of the sender (which is always listed first) */
  417. X    if (!(next = get_name_n_addr(to, NULL, NULL)))
  418. X    return;
  419. X    c = *next, *next = 0;
  420. X    (void) strcpy(sender, to);
  421. X    *next = c;
  422. X    /* fix up the sender's address; improve_uucp_paths to optimize pre_path */
  423. X    improve_uucp_paths(sender, sizeof sender, NULL);
  424. X
  425. X    /* check to see if there is only one addr on To: line and no Cc: header */
  426. X    if (!*next && (!cc || !*cc)) {
  427. X    (void) strcpy(to, sender);
  428. X    return;
  429. X    }
  430. X    /* otherwise, get the pre_path */
  431. X    if (p = get_name_n_addr(sender, NULL, tmp))
  432. X    c = p - sender; /* save the original length */
  433. X    if (*tmp) {
  434. X    (void) bang_form(pre_path, tmp);
  435. X    if (p = rindex(pre_path, '!')) {
  436. X        *p = 0;
  437. X        Debug("Routing thru \"%s\"\n", pre_path);
  438. X    } else
  439. X        pre_path[0] = 0;
  440. X    } else
  441. X    pre_path[0] = 0;
  442. X
  443. X    while (*next == ',' || isspace(*next))
  444. X    next++;
  445. X    improve_uucp_paths(next, HDRSIZ - (int)(next - to), pre_path);
  446. X    improve_uucp_paths(cc, HDRSIZ, pre_path);
  447. X    p = sender + c;
  448. X    *p++ = ',', *p++ = ' ';
  449. X    (void) strcpy(p, next);
  450. X    (void) strcpy(to, sender);
  451. X}
  452. X
  453. X/*
  454. X * pass a string describing header like, "Subject: ", current value, and
  455. X * whether or not to prompt for it or to just post the information.
  456. X * If do_prompt is true, "type in" the current value so user can either
  457. X * modify it, erase it, or add to it.
  458. X */
  459. Xchar *
  460. Xset_header(str, curstr, do_prompt)
  461. Xregister char *str, *curstr;
  462. X{
  463. X    static char       buf[HDRSIZ];
  464. X    int        offset = 0;
  465. X    register char  *p = curstr;
  466. X
  467. X    if (!str)
  468. X    str = "";
  469. X
  470. X    buf[0] = 0;
  471. X    print(str);
  472. X    (void) fflush(stdout);         /* force str curstr */
  473. X    if (do_prompt) {
  474. X    if (curstr)
  475. X        if (isoff(glob_flags, ECHO_FLAG)) {
  476. X        Ungetstr(curstr);
  477. X        } else
  478. X#ifdef TIOCSTI
  479. X        for (p = curstr; *p; p++)
  480. X            if (ioctl(0, TIOCSTI, p) == -1) {
  481. X            error("ioctl: TIOCSTI");
  482. X            print("You must retype the entire line.\n%s", str);
  483. X            break;
  484. X            }
  485. X#else /* !TIOCSTI */
  486. X        print("WARNING: -e flag! Type the line over.\n%s", str);
  487. X#endif /* TIOCSTI */
  488. X
  489. X    if (istool)
  490. X        return NULL;
  491. X    /* simulate the fact that we're getting input for the letter even tho
  492. X     * we may not be.  set_header is called before IS_GETTING is true,
  493. X     * but if we set it to true temporarily, then signals will return to
  494. X     * the right place (stop/continue).
  495. X     */
  496. X    {
  497. X        u_long getting = ison(glob_flags, IS_GETTING);
  498. X        int wrapping = wrapcolumn;
  499. X        /* Funky trick here.  If the prompt string is empty,
  500. X         * assume that we are allowed to do line wrap;
  501. X         * otherwise, temporarily disable line wrap
  502. X         */
  503. X        if (*str)
  504. X        wrapcolumn = 0;
  505. X        if (!getting)
  506. X        turnon(glob_flags, IS_GETTING);
  507. X        if (Getstr(buf, sizeof(buf), offset) == -1) {
  508. X        putchar('\n');
  509. X        buf[0] = 0;
  510. X        }
  511. X        if (!getting)
  512. X        turnoff(glob_flags, IS_GETTING);
  513. X        wrapcolumn = wrapping;
  514. X    }
  515. X    } else
  516. X    puts(strcpy(buf, curstr));
  517. X    if (debug > 1)
  518. X    print("returning (%s) from set_header\n", buf);
  519. X    return buf;
  520. X}
  521. X
  522. X/*
  523. X * improve uucp paths by looking at the name of each host listed in the
  524. X * path given.
  525. X *    sun!island!pixar!island!argv
  526. X * It's a legal address, but redundant. Also, if we know we talk to particular
  527. X * hosts via uucp, then we can just start with that host and disregard the path
  528. X * preceding it.  So, first get the known hosts and save them. Then start
  529. X * at the end of the original path (at the last ! found), and move backwards
  530. X * saving each hostname.  If we get to a host that we know about, stop there
  531. X * and use that address.  If the system knows about domains, skip all paths
  532. X * that precede a domain hostname.  If we get to a host we've already seen,
  533. X * then delete it and all the hosts since then until the first occurrence of
  534. X * that hostname.  When we get to the beginning, the address will be complete.
  535. X * The route_path is prepended to each address to check make sure this path
  536. X * is used if no known_hosts precede it in that address.
  537. X *
  538. X * Return all results into the original buffer passed to us.  If route_path
  539. X * adds to the length of all the paths, then the original buffer could be
  540. X * overwritten.  someone should check for this!
  541. X */
  542. Ximprove_uucp_paths(original, size, route_path)
  543. Xchar *original, *route_path;
  544. X{
  545. X    char       name[256], addr[256], buf[2 * HDRSIZ], *end;
  546. X    char      *hostnames[32], tmp[sizeof addr], *domain_path;
  547. X    register char *p, *p2, *recipient, *start = original, *b = buf;
  548. X    int           saved_hosts, i, is_domain;
  549. X
  550. X    if (!original || !*original)
  551. X    return;
  552. X
  553. X    /* use domain_path to point to the path for pathnames that have
  554. X     * a fully qualified domain host in them.
  555. X     */
  556. X    domain_path = do_set(set_options, "domain_route");
  557. X    while (end = get_name_n_addr(start, name, tmp)) {
  558. X    /* first copy the route path, then the rest of the address. */
  559. X    p = addr;
  560. X    if (route_path && *route_path) {
  561. X        p += Strcpy(addr, route_path);
  562. X        *p++ = '!';
  563. X    }
  564. X    (void) bang_form(p, tmp);
  565. X    saved_hosts = 0;
  566. X    if (p2 = rindex(p, '!')) {
  567. X        recipient = p2+1;
  568. X        /* save the uucp-style address *without* route_path in tmp */
  569. X        (void) strcpy(tmp, p);
  570. X        for (p = p2; p > addr; p--) {
  571. X        is_domain = 0;
  572. X        /* null the '!' separating the rest of the path from the part
  573. X         * of the path preceding it and move p back to the previous
  574. X         * '!' (or beginning to addr) for hostname to point to.
  575. X         */
  576. X        for (*p-- = 0; p > addr && *p != '!'; p--)
  577. X            if (!is_domain && domain_path && *p == '.' &&
  578. X                lcase_strncmp(p, ".uucp", 5))
  579. X            is_domain++;
  580. X        /* if p is not at the addr, move it forward past the '!' */
  581. X        if (p != addr)
  582. X            ++p; /* now points to a null terminated hostname */
  583. X        /* if host is ourselves, ignore this and preceding hosts */
  584. X        for (i = 0; ourname && ourname[i]; i++)
  585. X            if (!lcase_strncmp(p, ourname[i], -1))
  586. X            break;
  587. X        if (ourname && ourname[i]) {
  588. X            is_domain = 0; /* we've eliminated all domains */
  589. X            break;
  590. X        }
  591. X        /* check already saved hostnames. If host is one of them,
  592. X         * delete remaining hostnames since there is a redundant path.
  593. X         */
  594. X        for (i = 0; i < saved_hosts; i++)
  595. X            if (!lcase_strncmp(hostnames[i], p, -1))
  596. X            saved_hosts = i;
  597. X
  598. X        /* Add the hostname to the path being constructed */
  599. X        hostnames[saved_hosts++] = p;
  600. X
  601. X        /* If the original path or the address is a fully qualified
  602. X         * hostname (domain info is included), then break here
  603. X         */
  604. X        if (p == addr || is_domain && domain_path)
  605. X            break;
  606. X        /* If we know that we call this host, break */
  607. X        for (i = 0; known_hosts && known_hosts[i]; i++)
  608. X            if (!lcase_strncmp(p, known_hosts[i], -1))
  609. X            break;
  610. X        if (known_hosts && known_hosts[i])
  611. X            break;
  612. X        }
  613. X        /* temporary holder for where we are in buffer (save address) */
  614. X        p2 = b;
  615. X        if (is_domain && domain_path && *domain_path)
  616. X        b += Strcpy(b, domain_path), *b++ = '!';
  617. X        while (saved_hosts-- > 0) {
  618. X        b += Strcpy(b, hostnames[saved_hosts]);
  619. X        *b++ = '!';
  620. X        }
  621. X        b += Strcpy(b, recipient);
  622. X        if (!strcmp(p2, tmp)) { /* if the same, address was unmodified */
  623. X        b = p2; /* reset offset in buf (b) to where we were (p2) */
  624. X        goto unmodified;
  625. X        }
  626. X        if (*name)
  627. X        b += strlen(sprintf(b, " (%s)", name));
  628. X    } else {
  629. X        char c;
  630. Xunmodified:
  631. X        c = *end;
  632. X        *end = 0;
  633. X        b += Strcpy(b, start); /* copy the entire address with comments */
  634. X        *end = c;
  635. X    }
  636. X    if (b - buf > size) {
  637. X        wprint("Warning: address list truncated!\n");
  638. X        /* Use a very poor heuristic to find the last complete address */
  639. X        for (b = buf+size - 1; *b != ','; b--)
  640. X        ;
  641. X        wprint("Lost addresses: %s%s\n", b, end); /* end = not yet parsed */
  642. X        while (isspace(*b) || *b == ',')
  643. X        b--;
  644. X        break;
  645. X    }
  646. X    for (start = end; *start == ',' || isspace(*start); start++)
  647. X        ;
  648. X    if (!*start)
  649. X        break;
  650. X    *b++ = ',', *b++ = ' ', *b = '\0';
  651. X    }
  652. X    (void) strcpy(original, buf);
  653. X}
  654. X
  655. X/*
  656. X * rm_cmts_in_addr() removes the comment lines in addresses that result from
  657. X * sendmail or other mailers which append the user's "real name" on the
  658. X * from lines.  See get_name_n_addr().
  659. X */
  660. Xrm_cmts_in_addr(str)
  661. Xregister char *str;
  662. X{
  663. X    char addr[BUFSIZ], buf[HDRSIZ], *start = str;
  664. X    register char *b = buf;
  665. X
  666. X    *b = 0;
  667. X    do  {
  668. X    if (!(str = get_name_n_addr(str, NULL, addr)))
  669. X        break;
  670. X    b += Strcpy(b, addr);
  671. X    while (*str == ',' || isspace(*str))
  672. X        str++;
  673. X    if (*str)
  674. X        *b++ = ',', *b++ = ' ', *b = '\0';
  675. X    } while (*str);
  676. X    for (b--; b > start && (*b == ',' || isspace(*b)); b--)
  677. X    *b = 0;
  678. X    (void) strcpy(start, buf);
  679. X}
  680. X
  681. X/*
  682. X * take_me_off() is intended to search for the user's login name in an
  683. X * address string and remove it.  If "metoo" is set, return without change.
  684. X * determine which addresses are the "user'"'s addresses by comparing them
  685. X * against the host/path names in alternates.  If the "*" is used, then
  686. X * this matches the address against the user's current login and -any- path.
  687. X *
  688. X * Note that the alternates list is an array of addresses stored *reversed*!
  689. X */
  690. Xtake_me_off(str)
  691. Xchar *str;
  692. X{
  693. X    int i = 0, rm_me;
  694. X    char tmp[256], addr[256], buf[HDRSIZ], *start = str;
  695. X    register char *p, *p2, *b = buf;
  696. X
  697. X    if (!str || !*str)
  698. X    return;
  699. X
  700. X    Debug("take_me_off()\n");
  701. X    *b = 0;
  702. X    do  {
  703. X    rm_me = FALSE;
  704. X    /* get the first "address" and advance p to next addr (ignore name) */
  705. X    if (!(p = get_name_n_addr(str, NULL, tmp)))
  706. X        break; /* we've reached the end of the address list */
  707. X    /* see if user's login is in the address */
  708. X    if (!strcmp(login, tmp))
  709. X        rm_me = TRUE;
  710. X    else {
  711. X        int len;
  712. X        /* put address in !-format and store in "addr" */
  713. X        (void) bang_form(addr, tmp);
  714. X        (void) reverse(addr);
  715. X        for (i = 0; alternates && alternates[i] && !rm_me; i++) {
  716. X        if (alternates[i][0] == '*') {
  717. X            if (alternates[i][1] == '\0')
  718. X            p2 = reverse(strcpy(tmp, login));
  719. X            else
  720. X            p2 = reverse(strcpy(tmp, &alternates[i][1]));
  721. X        } else
  722. X            p2 = alternates[i];
  723. X        if (!lcase_strncmp(p2, addr, (len = strlen(p2))) &&
  724. X            (!addr[len] || addr[len] == '!')) {
  725. X            Debug("\t%s\n", reverse(addr));
  726. X            rm_me = TRUE;
  727. X        }
  728. X        }
  729. X        for (i = 0; !rm_me && ourname && ourname[i]; i++) {
  730. X        p2 = tmp + Strcpy(tmp, ourname[i]);
  731. X        *p2++ = '!';
  732. X        (void) strcpy(p2, login);
  733. X        (void) reverse(tmp);
  734. X        if (!lcase_strncmp(tmp, addr, (len = strlen(tmp))) &&
  735. X            (!addr[len] || addr[len] == '!')) {
  736. X            Debug("\t%s\n", reverse(addr));
  737. X            rm_me = TRUE;
  738. X        }
  739. X        }
  740. X    }
  741. X    /* The address is not the user's -- put it into the returned list */
  742. X    if (!rm_me) {
  743. X        char c = *p;
  744. X        *p = 0;
  745. X        b += Strcpy(b, str);
  746. X        *p = c;
  747. X    }
  748. X    while (*p == ',' || isspace(*p))
  749. X        p++;
  750. X    if (*p && !rm_me)
  751. X        *b++ = ',', *b++ = ' ', *b = '\0';
  752. X    } while (*(str = p));
  753. X    for (b--; b > buf && (*b == ',' || isspace(*b)); b--)
  754. X    *b = 0;
  755. X    (void) strcpy(start, buf);
  756. X}
  757. X
  758. X/*
  759. X * Place commas in between all addresses that don't already have
  760. X * them.  Addresses which use comments which are in parens or _not_
  761. X * within angle brackets *must* already have commas around them or
  762. X * you can't determine what is a comment and what is an address.
  763. X */
  764. Xfix_up_addr(str)
  765. Xchar *str;
  766. X{
  767. X    char buf[HDRSIZ], *start = str;
  768. X    register char c, *p, *b = buf;
  769. X
  770. X    *b = 0;
  771. X    do  {
  772. X    /* get_name returns a pointer to the next address */
  773. X    if (!(p = get_name_n_addr(str, NULL, NULL)))
  774. X        break;
  775. X    c = *p, *p = 0;
  776. X    if (strlen(str) + (b - buf) >= sizeof(buf) - 2) {
  777. X        /* wprint("Address too long! Lost address: \"%s\"\n", str); */
  778. X        *p = c;
  779. X        break;
  780. X    }
  781. X    for (b += Strcpy(b, str); b > buf && isspace(*(b-1)); b--)
  782. X        *b = 0;
  783. X    for (*p = c; *p == ',' || isspace(*p); p++)
  784. X        ;
  785. X    if (*p)
  786. X        *b++ = ',', *b++ = ' ', *b = '\0';
  787. X    } while (*(str = p));
  788. X    for (b--; b > buf && (*b == ',' || isspace(*b)); b--)
  789. X    *b = 0;
  790. X    (void) strcpy(start, buf);
  791. X}
  792. X
  793. X/*
  794. X * Remove redundant addresses.
  795. X * Assume improve_uucp_paths, fix_up_addr or whatever have already been called.
  796. X */
  797. Xrm_redundant_addrs(to, cc)
  798. Xchar *to, *cc;
  799. X{
  800. X    char tmp[256], addr[256], buf[HDRSIZ];
  801. X    char **list; /* a list of addresses for comparison */
  802. X    int list_cnt = 0, l;
  803. X    register char c, *p, *b, *start;
  804. X
  805. X    Debug("rm_redundant_addrs()\n");
  806. X    list = (char **) calloc(256, sizeof(char *));
  807. X    if (!list) {
  808. X    error("out of memory in rm_redundant_addrs");
  809. X    return;
  810. X    }
  811. X    start = to;
  812. X    b = buf, *b = 0;
  813. X    /* first do the To header */
  814. X    do  {
  815. X    /* get_name returns a pointer to the next address */
  816. X    if (!(p = get_name_n_addr(to, NULL, tmp)))
  817. X        break;
  818. X    c = *p, *p = 0;
  819. X    (void) bang_form(addr, tmp);
  820. X    for (l = 0; l < list_cnt; l++)
  821. X        if (!lcase_strncmp(addr, list[l], -1))
  822. X        break;
  823. X    /* if l == list_cnt, we got a new address, store it and add to buf */
  824. X    if (l == list_cnt) {
  825. X        /* Don't overwrite buffer. */
  826. X        if (list_cnt < 256)
  827. X        list[list_cnt++] = savestr(addr);
  828. X        if (b > buf)
  829. X        *b++ = ',', *b++ = ' ', *b = '\0';
  830. X        for (b += Strcpy(b, to); b > buf && isspace(*(b-1)); b--)
  831. X        *b = 0;
  832. X    } else
  833. X        Debug("\t%s\n", tmp); /* already specified (removed from list) */
  834. X    for (*p = c; *p == ',' || isspace(*p); p++)
  835. X        ;
  836. X    } while (*(to = p));
  837. X    for (b--; b > buf && (*b == ',' || isspace(*b)); b--)
  838. X    *b = 0;
  839. X    (void) strcpy(start, buf);
  840. X    b = buf, *b = 0;
  841. X    /* Now do the Cc header.  If addr is listed in the To field, rm it in cc */
  842. X    start = cc;
  843. X    do  {
  844. X    /* get_name returns a pointer to the next address */
  845. X    if (!(p = get_name_n_addr(cc, NULL, tmp)))
  846. X        break;
  847. X    c = *p, *p = 0;
  848. X    (void) bang_form(addr, tmp);
  849. X    for (l = 0; l < list_cnt; l++)
  850. X        if (!lcase_strncmp(addr, list[l], -1))
  851. X        break;
  852. X    if (l == list_cnt) {
  853. X        /* Don't overwrite buffer. */
  854. X        if (list_cnt < sizeof(list)/sizeof(char *))
  855. X        list[list_cnt++] = savestr(addr);
  856. X        if (b > buf)
  857. X        *b++ = ',', *b++ = ' ', *b = '\0';
  858. X        for (b += Strcpy(b, cc); b > buf && isspace(*(b-1)); b--)
  859. X        *b = 0;
  860. X    } else
  861. X        Debug("\t%s\n", tmp); /* already specified (removed from list) */
  862. X    for (*p = c; *p == ',' || isspace(*p); p++)
  863. X        ;
  864. X    } while (*(cc = p));
  865. X    list[list_cnt] = NULL; /* for free_vec */
  866. X    free_vec(list);
  867. X    for (b--; b > buf && (*b == ',' || isspace(*b)); b--)
  868. X    *b = 0;
  869. X    (void) strcpy(start, buf);
  870. X}
  871. X
  872. X/*
  873. X * Get address and name from a string (str) which came from an address header
  874. X * in a message or typed by the user.  The string may contain one or more
  875. X * well-formed addresses.  Each must be separated by a comma.
  876. X *
  877. X * address, address, address
  878. X * address (comment or name here)
  879. X * comment or name <address>
  880. X * "Comment, even those with comma's!" <address>
  881. X * address (comma, (more parens), etc...)
  882. X *
  883. X * This does *not* handle cases like:
  884. X *    comment <address (comment)>
  885. X *
  886. X * find the *first* address here and return a pointer to the end of the
  887. X * address (usually a comma).  Return NULL on error: non-matching parens,
  888. X * brackets, quotes...
  889. X */
  890. Xchar *
  891. Xget_name_n_addr(str, name, addr)
  892. Xregister char *str, *name, *addr;
  893. X{
  894. X    register char *p, *p2, *beg_addr = addr, *beg_name = name, c;
  895. X
  896. X    if (addr)
  897. X    *addr = 0;
  898. X    if (name)
  899. X    *name = 0;
  900. X    if (!str || !*str)
  901. X    return NULL;
  902. X
  903. X    while (isspace(*str))
  904. X    str++;
  905. X
  906. X    /* first check to see if there's something to look for */
  907. X    if (!(p = any(str, ",(<\""))) {
  908. X    /* no comma or indication of a quote character. Find a space and
  909. X     * return that.  If nothing, the entire string is a complete address
  910. X     */
  911. X    if (p = any(str, " \t"))
  912. X        c = *p, *p = 0;
  913. X    if (addr)
  914. X        (void) strcpy(addr, str);
  915. X    if (p)
  916. X        *p = c;
  917. X    return p? p : str + strlen(str);
  918. X    }
  919. X
  920. X    /* comma terminated before any comment stuff.  If so, check for whitespace
  921. X     * before-hand cuz it's possible that strings aren't comma separated yet
  922. X     * and they need to be.
  923. X     *
  924. X     * address address address, address
  925. X     *                        ^p  <- p points here.
  926. X     *        ^p2 <- should point here.
  927. X     */
  928. X    if (*p == ',') {
  929. X    c = *p, *p = 0;
  930. X    if (p2 = any(str, " \t"))
  931. X        *p = ',', c = *p2, p = p2, *p = 0;
  932. X    if (addr)
  933. X        (void) strcpy(addr, str);
  934. X    *p = c;
  935. X    return p;
  936. X    }
  937. X
  938. X    /* starting to get hairy -- we found an angle bracket. This means that
  939. X     * everything outside of those brackets are comments until we find that
  940. X     * all important comma.  A comment AFTER the <addr> :
  941. X     *  <address> John Doe
  942. X     * can't call this function recursively or it'll think that "John Doe"
  943. X     * is a string with two legal address on it (each name being an address).
  944. X     */
  945. X    if (*p == '<') { /* note that "str" still points to comment stuff! */
  946. X    if (name && *str) {
  947. X        *p = 0;
  948. X        name += Strcpy(name, str);
  949. X        *p = '<';
  950. X    }
  951. X    if (!(p2 = index(p+1, '>'))) {
  952. X        wprint("Warning! Malformed address: \"%s\"\n", str);
  953. X        return NULL;
  954. X    }
  955. X    if (addr) {
  956. X        /* to support <addr (comment)> style addresses, add code here */
  957. X        *p2 = 0;
  958. X        skipspaces(1);
  959. X        addr += Strcpy(addr, p);
  960. X        while (addr > beg_addr && isspace(*(addr-1)))
  961. X        *--addr = 0;
  962. X        *p2 = '>';
  963. X    }
  964. X    /* take care of the case "... <addr> com (ment)" */
  965. X    {
  966. X        int p_cnt = 0; /* parenthesis counter */
  967. X        p = p2;
  968. X        /* don't recurse yet -- scan till null, comma or '<'(add to name) */
  969. X        for (p = p2; p[1] && (p_cnt || p[1] != ',' && p[1] != '<'); p++) {
  970. X        if (p[1] == '(')
  971. X            p_cnt++;
  972. X        else if (p[1] == ')')
  973. X            p_cnt--;
  974. X        if (name)
  975. X            *name++ = p[1];
  976. X        }
  977. X        if (p_cnt) {
  978. X        wprint("Warning! Malformed name: \"%s\"\n", name);
  979. X        return NULL;
  980. X        }
  981. X    }
  982. X    if (name && name > beg_name) {
  983. X        while (isspace(*(name-1)))
  984. X        --name;
  985. X        *name = 0;
  986. X    }
  987. X    }
  988. X
  989. X    /* this is the worst -- now we have parentheses/quotes.  These guys can
  990. X     * recurse pretty badly and contain commas within them.
  991. X     */
  992. X    if (*p == '(' || *p == '"') {
  993. X    char *start = p;
  994. X    int comment = 1;
  995. X    c = *p;
  996. X    /* "str" points to address while p points to comments */
  997. X    if (addr && *str) {
  998. X        *p = 0;
  999. X        while (isspace(*str))
  1000. X        str++;
  1001. X        addr += Strcpy(addr, str);
  1002. X        while (addr > beg_addr && isspace(*(addr-1)))
  1003. X        *--addr = 0;
  1004. X        *p = c;
  1005. X    }
  1006. X    while (comment) {
  1007. X        if (c == '"' && !(p = index(p+1, '"')) ||
  1008. X        c == '(' && !(p = any(p+1, "()"))) {
  1009. X        wprint("Warning! Malformed address: \"%s\"\n", str);
  1010. X        return NULL;
  1011. X        }
  1012. X        if (*p == '(') /* loop again on parenthesis. quote ends loop */
  1013. X        comment++;
  1014. X        else
  1015. X        comment--;
  1016. X    }
  1017. X    /* Something like ``Comment (Comment) <addr>''.  In this case
  1018. X     * the name should include both comment parts with the
  1019. X     * parenthesis.   We have to redo addr.
  1020. X     */
  1021. X    if ((p2 = any(p+1, "<,")) && *p2 == '<') {
  1022. X        if (!(p = index(p2, '>'))) {
  1023. X        wprint("Warning! Malformed address: \"%s\"\n", str);
  1024. X        return NULL;
  1025. X        }
  1026. X        if (addr = beg_addr) { /* reassign addr and compare to null */
  1027. X        c = *p; *p = 0;
  1028. X        addr += Strcpy(addr, p2+1);
  1029. X        while (addr > beg_addr && isspace(*(addr-1)))
  1030. X            *--addr = 0;
  1031. X        *p = c;
  1032. X        }
  1033. X        if (name) {
  1034. X        c = *p2; *p2 = 0;
  1035. X        name += Strcpy(name, str);
  1036. X        while (name > beg_name && isspace(*(name-1)))
  1037. X            *--name = 0;
  1038. X        *p2 = c;
  1039. X        }
  1040. X    } else if (name && start[1]) {
  1041. X        c = *p, *p = 0; /* c may be ')' instead of '(' now */
  1042. X        name += Strcpy(name, start+1);
  1043. X        while (name > beg_name && isspace(*(name-1)))
  1044. X        *--name = 0;
  1045. X        *p = c;
  1046. X    }
  1047. X    }
  1048. X    skipspaces(1);
  1049. X    /* this is so common, save time by returning now */
  1050. X    if (!*p || *p == ',')
  1051. X    return p;
  1052. X    return get_name_n_addr(p, name, addr);
  1053. X}
  1054. X
  1055. X/* takes string 's' which can be a name or list of names separated by
  1056. X * commas and checks to see if each is aliased to something else.
  1057. X * return address of the static buf.
  1058. X */
  1059. Xchar *
  1060. Xalias_to_address(s)
  1061. Xregister char *s;
  1062. X{
  1063. X    static char buf[HDRSIZ];
  1064. X    register char *p, *p2, *tmp;
  1065. X    char newbuf[HDRSIZ], c;
  1066. X    static int recursive;
  1067. X
  1068. X    if (!aliases)
  1069. X    return strcpy(buf, s);
  1070. X    if (!s || !*s)
  1071. X    return NULL;
  1072. X    if (!recursive) {
  1073. X    bzero(buf, sizeof buf);
  1074. X    p2 = buf;  /* if we're starting all this, p2 starts at &buf[0] */
  1075. X    } else
  1076. X    p2 = buf+strlen(buf);   /* else, pick up where we left off */
  1077. X
  1078. X    if (++recursive == 30) {
  1079. X    wprint("alias references too many addresses!\n");
  1080. X    recursive = 0;
  1081. X    return NULL;
  1082. X    }
  1083. X    do  {
  1084. X    char addr[256];
  1085. X    if (!(p = get_name_n_addr(s, NULL, addr)))
  1086. X        break;
  1087. X    c = *p, *p = 0;
  1088. X
  1089. X    /* On recursive calls, compare against the entire
  1090. X     * previous expansion, not just the address part.
  1091. X     */
  1092. X    if (recursive > 1)
  1093. X        (void) strcpy(addr, s);
  1094. X
  1095. X    /* if this is an alias, recurse this routine to expand it out */
  1096. X    if ((tmp = do_set(aliases, addr)) && *tmp) {
  1097. X        if (!alias_to_address(strcpy(newbuf, tmp))) {
  1098. X        *p = c;
  1099. X        return NULL;
  1100. X        } else
  1101. X        p2 = buf+strlen(buf);
  1102. X    /* Now, make sure the buffer doesn't overflow */
  1103. X    } else if (strlen(s) + (p2-buf) + 2 > sizeof buf) {  /* add ", " */
  1104. X        wprint("address length too long.\n");
  1105. X        recursive = 0;
  1106. X        *p = c;
  1107. X        return NULL;
  1108. X    } else {
  1109. X        /* append the new alias (or unchanged address) onto the buffer */
  1110. X        p2 += Strcpy(p2, s);
  1111. X        *p2++ = ',', *p2++ = ' ', *p2 = '\0';
  1112. X    }
  1113. X    for (*p = c; *p == ',' || isspace(*p); p++)
  1114. X        ;
  1115. X    } while (*(s = p));
  1116. X    if (recursive)
  1117. X    recursive--;
  1118. X    if (!recursive)
  1119. X    *(p2-2) = 0;  /* get rid of last ", " if end of recursion */
  1120. X    return buf;
  1121. X}
  1122. X
  1123. X/*
  1124. X * Wrap addresses so that the headers don't exceed n chars (typically 80).
  1125. X */
  1126. Xchar *
  1127. Xwrap_addrs(str, n)
  1128. Xchar *str;
  1129. X{
  1130. X    char buf[HDRSIZ * 2], *start = str;
  1131. X    register char *b = buf, *p, c, *line_start = buf;
  1132. X
  1133. X    *b = 0;
  1134. X    do  {
  1135. X    /* get_name returns a pointer to the next address */
  1136. X    if (!(p = get_name_n_addr(str, NULL, NULL)))
  1137. X        break;
  1138. X    c = *p, *p = 0;
  1139. X    if (b > buf) {
  1140. X        *b++ = ',', *b++ = ' ', *b = '\0';
  1141. X        if (b - line_start + strlen(str) + 8 /* \t = 8 */ >= n)
  1142. X        *b++ = '\n', *b++ = '\t', line_start = b;
  1143. X    }
  1144. X    for (b += Strcpy(b, str); b > buf && isspace(*(b-1)); b--)
  1145. X        *b = 0;
  1146. X    for (*p = c; *p == ',' || isspace(*p); p++)
  1147. X        ;
  1148. X    } while (*(str = p));
  1149. X    for (b--; b > buf && (*b == ',' || isspace(*b)); b--)
  1150. X    *b = 0;
  1151. X    return strcpy(start, buf);
  1152. X}
  1153. END_OF_FILE
  1154. if test 33359 -ne `wc -c <'mush/addrs.c'`; then
  1155.     echo shar: \"'mush/addrs.c'\" unpacked with wrong size!
  1156. fi
  1157. # end of 'mush/addrs.c'
  1158. fi
  1159. if test -f 'mush/viewopts.c' -a "${1}" != "-c" ; then 
  1160.   echo shar: Will not clobber existing file \"'mush/viewopts.c'\"
  1161. else
  1162. echo shar: Extracting \"'mush/viewopts.c'\" \(18292 characters\)
  1163. sed "s/^X//" >'mush/viewopts.c' <<'END_OF_FILE'
  1164. X/* @(#)viewopts.c    (c) copyright    10/18/86 (Dan Heller) */
  1165. X
  1166. X#include "mush.h"
  1167. X
  1168. Xstruct viewopts {
  1169. X    char *v_opt;
  1170. X    char *v_prompt;
  1171. X    char *v_description;
  1172. X#ifdef SUNTOOL
  1173. X    Panel_item v_choice;
  1174. X    Panel_item v_text;
  1175. X#endif /* SUNTOOL */
  1176. X};
  1177. X
  1178. X#ifdef SUNTOOL
  1179. Xshort dat_cycle_cursor[] = {
  1180. X    0x07C0, 0x0FE0, 0x1834, 0x301C, 0x601C, 0x203C, 0x0000, 0x0000,
  1181. X    0x7808, 0x700C, 0x7018, 0x5830, 0x0FE0, 0x07C0, 0x0000, 0x0000
  1182. X
  1183. X};
  1184. Xmpr_static(cycle,           16, 16, 1, dat_cycle_cursor);
  1185. X#endif /* SUNTOOL */
  1186. X
  1187. X/*
  1188. X * struct contains the option, a prompt if it has a string value, whether
  1189. X * or not it applies to non suntools, line mode, or both, and a
  1190. X * string describing what the option does. If the prompt string starts
  1191. X * with a minus sign, then the value can be set without a value. This
  1192. X * is there to indicate to option_line to print a toggle (cycle) pixrect
  1193. X * and to print TRUE/FALSE telling whether the value is on or off regardless
  1194. X * of it's "string" value.
  1195. X */
  1196. Xstruct viewopts viewopts[] = {
  1197. X    { "alwaysignore", NULL,
  1198. X    "Always ignore the message headers on the 'ignored' list." },
  1199. X    { "ask", NULL,
  1200. X    "Prompts for a subject on outgoing mail." },
  1201. X    { "askcc", NULL,
  1202. X    "Ask for list of Carbon Copy recipients whenever sending mail." },
  1203. X    { "autodelete", NULL,
  1204. X    "Automatically delete ALL READ messages whenever you update mail." },
  1205. X    { "autoedit", NULL,
  1206. X    "Automatically enter editor for REPLIES only (not toolmode)." },
  1207. X    { "autoinclude", NULL,
  1208. X    "Include a copy of author's message each time you reply to mail." },
  1209. X    { "autoprint", NULL,
  1210. X    "Display the next message on the list when you delete a message." },
  1211. X    { "auto_route", "-Host/Path:",
  1212. X    "Remove redundant uucp addresses when replying to messages." },
  1213. X    { "autosign", "-Filename:",
  1214. X    "Add file (~/.signature if set but no value) at end of all letters." },
  1215. X    { "autosign2", "Addr:File:",
  1216. X    "Signature to use for specific addresses. \"addr, ... : <signature>\""},
  1217. X    { "cdpath", "Path:",
  1218. X    "Path to search for directories when the \"cd\" command is issued." },
  1219. X    { "cmd_help", "Path:",
  1220. X    "Location of the general help file for line and curses modes." },
  1221. X    { "complete", "Character:",
  1222. X    "The character typed to cause a word completion to occur." },
  1223. X    { "crt", "Lines:",
  1224. X    "The number of lines a message must have for 'pager' to be invoked." },
  1225. X    { "crt_win", "Lines:",
  1226. X    "Lines in the tool mode text subwindow for paging messages." },
  1227. X    { "curses_help", "-Commands:",
  1228. X    "List of curses commands whose bindings appear in the help display." },
  1229. X    { "date_received", NULL,
  1230. X    "Time displayed for message headers shows date received (or sent)." },
  1231. X    { "dead", "Filename:",
  1232. X    "The name of the file to store dead mail (default = ~/dead.letter)." },
  1233. X    { "domain_route", "-Host/Path:",
  1234. X    "Cause short-circuiting of domain addresses when auto-routing." },
  1235. X    { "dot", NULL,
  1236. X    "Allow \".\" on a line by itself to send letter." },
  1237. X    { "edit_hdrs", NULL,
  1238. X    "Allow headers of messages to be edited using your editor." },
  1239. X    { "editor", "Editor:",
  1240. X    "Editor for message editing (default = env EDITOR or \"vi\")." },
  1241. X    { "escape", "Character:",
  1242. X    "Escape character for extended editing commands (default = ~)." },
  1243. X    { "fignore", "Patterns:",
  1244. X    "Filename extensions or patterns ignored in completions." },
  1245. X    { "folder", "Pathname:",
  1246. X    "Full pathname to the directory where personal folders are kept." },
  1247. X    { "fortune", "-Flag:",
  1248. X    "Add fortune to end of letters.  Flag to \"fortune\" is optional." },
  1249. X    { "fortunates", "Users:",
  1250. X    "Those who will receive fortunes if fortune is set (default: All)." },
  1251. X    { "hdr_format", "Format:",
  1252. X    "Formatting string for headers.  \"headers -?\" or help hdr_format." },
  1253. X    { "history", "Number:",
  1254. X    "How many commands to remember (like csh)." },
  1255. X    { "hold", NULL,
  1256. X    "Read but not deleted messages are saved in spool -- not mbox." },
  1257. X    { "home", "Directory:",
  1258. X    "The user's home directory." },
  1259. X    { "hostname", "Hostname:",
  1260. X    "User-definable name for the name of your machine." },
  1261. X    { "ignore_bang", NULL,
  1262. X    "Ignore '!' as a history reference.  Otherwise, escape by: \\!" },
  1263. X    { "ignoreeof", "-Command:",
  1264. X    "Ignores ^D as exit, or (if set), execute \"command\"." },
  1265. X    { "indent_str", "String:",
  1266. X    "String to offset included messages within your letters." },
  1267. X    { "in_reply_to", "-String:",
  1268. X    "When responding to mail, add In-Reply-To: to message headers." },
  1269. X    { "keepsave", NULL,
  1270. X    "Prevents messages from being marked as `deleted' when you `save'." },
  1271. X    { "known_hosts", "Host list:",
  1272. X    "List of hosts that your site is known to uucp mail to." },
  1273. X    { "logfile", "Filename:",
  1274. X    "Log outgoing mail headers only.  Message text not logged." },
  1275. X    { "mail_icon", "Filename:",
  1276. X    "Alternate pixmap to use when tool is closed to an icon." },
  1277. X    { "mbox", "Filename:",
  1278. X    "Filename to use instead of ~/mbox for default mailbox." },
  1279. X    { "metoo", NULL,
  1280. X    "When replying to mail, metoo preserves your name on mailing list." },
  1281. X    { "mil_time", NULL,
  1282. X    "24-hour military time format is used whenever a time is printed." },
  1283. X    { "msg_win", "Lines:",
  1284. X    "Number of lines in the message composition window for tool mode." },
  1285. X    { "newline", "-Command:",
  1286. X    "Ignore RETURN.  If set to a command, execute that command." },
  1287. X    { "newmail_icon", "Filename:",
  1288. X    "Alternate icon shown when new mail is available." },
  1289. X    { "no_expand", NULL,
  1290. X    "Prevents expansion of Mush aliases in outgoing mail headers." },
  1291. X    { "no_hdrs", NULL,
  1292. X    "If set, personalized headers are NOT inserted to outgoing mail." },
  1293. X    { "no_reverse", NULL,
  1294. X    "Disables reverse video in curses mode -- uses \"bold\" in tool mode."},
  1295. X    { "nonobang", NULL,
  1296. X    "Suppresses errors from unsuccessful history references." },
  1297. X    { "nosave", NULL,
  1298. X    "Prevents aborted mail from being saved in $dead." },
  1299. X    { "output", NULL,
  1300. X    "The message list produced as output of the last command." },
  1301. X    { "pager", "Program:",
  1302. X    "Program name to be used as a pager for messages longer than crt." },
  1303. X    { "pre_indent_str", "String:",
  1304. X    "String to precede message text interpolated into message body." },
  1305. X    { "post_indent_str", "String:",
  1306. X    "String to succeed message text interpolated into message body." },
  1307. X    { "print_cmd", "Program:",
  1308. X    "Alternate program to use to send messages to the printer." },
  1309. X    { "printer", "Printer:",
  1310. X    "Printer to send messages to (default = environment PRINTER)." },
  1311. X    { "prompt", "String:",
  1312. X    "Your prompt.  \"help prompt\" for more information." },
  1313. X    { "quiet", "-Conditions:",
  1314. X    "Turn off verbose messages and error bells in various conditions." },
  1315. X    { "realname", "Name:",
  1316. X    "Your real name." },
  1317. X    { "record", "Filename:",
  1318. X    "Save all outgoing mail in specified filename." },
  1319. X    { "reply_to_hdr", "Headers:",
  1320. X    "List of headers use to construct reply addresses from a message." },
  1321. X    { "save_empty", NULL,
  1322. X    "Folders which have all messages deleted are NOT removed on updates." },
  1323. X    { "screen", "# of Headers:",
  1324. X    "Number of headers to print in non-suntools (text) mode." },
  1325. X    { "screen_win", "# of Headers:",
  1326. X    "Set the size of the header window for the tool mode only." },
  1327. X    { "show_deleted", NULL,
  1328. X    "Show deleted messages in headers listings (unused in curses mode)." },
  1329. X    { "show_hdrs", "Headers:",
  1330. X    "When displaying a message, show list of \"headers\" only." },
  1331. X    { "sendmail", "Program:",
  1332. X    "Program to use to deliver mail instead of using the default."},
  1333. X    { "sort", "-Option:",
  1334. X    "Pre-sorting of messages on mush startup (set to valid sort option)." },
  1335. X    { "squeeze", NULL,
  1336. X    "When reading messages, squeeze all blank lines into one." },
  1337. X    { "status", NULL,
  1338. X    "The success or failure status of the most recent command." },
  1339. X    { "thisfolder", "Folder:",
  1340. X    "This read-only variable gives the current folder name." },
  1341. X    { "tool_help", "Path:",
  1342. X    "Location of the help file for tool mode."  },
  1343. X    { "toplines", "Lines:",
  1344. X    "Number of lines to print of a message for the 'top' command."  },
  1345. X    { "tmpdir", "Directory:",
  1346. X    "Directory to use for temporary files used by Mush." },
  1347. X    { "unix", NULL,
  1348. X    "Non-mush commands are considered to be UNIX commands." },
  1349. X    { "verify", NULL,
  1350. X    "Verify to send, re-edit, or abort letter after editing." },
  1351. X    { "visual", "Visual editor:",
  1352. X    "Visual editor for messages (default = $editor or env VISUAL)."},
  1353. X    { "warning", NULL,
  1354. X    "Print warning messages for non-fatal errors." },
  1355. X    { "wrap", NULL,
  1356. X    "After referencing last message, message pointer wraps to start." },
  1357. X    { "wrapcolumn", "-Column to wrap [78]:",
  1358. X    "Column at which to wrap lines when composing messages." },
  1359. X};
  1360. X
  1361. X#ifdef SUNTOOL
  1362. X
  1363. X#define OPTIONS_PANEL_WIDTH    550
  1364. X
  1365. Xint set_value(), toggle_value(), help_opt();
  1366. X
  1367. XFrame opts_frame;
  1368. XPanel opts_panel;
  1369. XPanel_item desc_msg;
  1370. XPanel_item file_text_item;
  1371. X
  1372. Xstatic void
  1373. Xframe_done()
  1374. X{
  1375. X#ifdef SUN_4_0 /* SunOS 4.0+ */
  1376. X    window_set(opts_frame, WIN_SHOW, FALSE, NULL);
  1377. X#else /* SUN_4_0 */
  1378. X    /* not enough fd's to keep it lying around for SunOS 3.X */
  1379. X    window_destroy(opts_frame);
  1380. X    opts_frame = (Frame) 0;
  1381. X#endif /* SUN_4_0 */
  1382. X}
  1383. X
  1384. Xstatic void
  1385. Xopts_help()
  1386. X{
  1387. X    help(0, "options", tool_help);
  1388. X}
  1389. X
  1390. Xstatic void
  1391. Xopts_save_load(item)
  1392. XPanel_item item;
  1393. X{
  1394. X    int (*func)() = (int (*)())panel_get(item, PANEL_CLIENT_DATA);
  1395. X    int result;
  1396. X    char buf[MAXPATHLEN];
  1397. X    char *argv[3], *file = panel_get_value(file_text_item);
  1398. X
  1399. X    if (!*file) {
  1400. X    result = (*func)(0, DUBL_NULL);
  1401. X    file = ".mushrc";
  1402. X    } else {
  1403. X    argv[1] = file;
  1404. X    argv[2] = NULL;
  1405. X    result = (*func)(2, argv);
  1406. X    }
  1407. X    switch (result) {
  1408. X    case 0:
  1409. X        sprintf(buf, "%s %s",
  1410. X        (func == source)? "Loaded options from" : "Saved options to",
  1411. X        file);
  1412. X    when -1:
  1413. X        sprintf(buf, "%s: %s", file, sys_errlist[errno]);
  1414. X    when -2:
  1415. X        sprintf(buf, "%s is a directory.", file);
  1416. X    when -3:
  1417. X        /* save_opts() returns -3 if user doesn't confirm overwrite */
  1418. X        strcpy(buf, "Save operation aborted.");
  1419. X    }
  1420. X    panel_set(desc_msg, PANEL_LABEL_STRING, buf, NULL);
  1421. X}
  1422. X
  1423. Xstatic void
  1424. Xunset_opts()
  1425. X{
  1426. X    cmd_line("unset *", NULL);
  1427. X}
  1428. X
  1429. Xstatic void
  1430. Xreset_opts()
  1431. X{
  1432. X    source(0, DUBL_NULL);
  1433. X}
  1434. X
  1435. X/*
  1436. X * Public routine which creates a subframe which contains two panels.
  1437. X * The first contains options for loading and saving options from a
  1438. X * file (text item) and so on... the second panel contains all the items
  1439. X * which correspond to each mush variable that exists.
  1440. X */
  1441. Xvoid
  1442. Xview_options()
  1443. X{
  1444. X    extern Notify_value fkey_interposer();
  1445. X    register char *p;
  1446. X    int count;
  1447. X
  1448. X    if (opts_frame) {
  1449. X    window_set(opts_frame, WIN_SHOW, TRUE, NULL);
  1450. X    opts_panel_item(NULL);
  1451. X    return;
  1452. X    }
  1453. X#ifdef SUN_3_5
  1454. X    if (nopenfiles(0) < 3) {
  1455. X    ok_box("Too many frames; close one first!\n");
  1456. X    return;
  1457. X    }
  1458. X#endif /* SUN_3_5 */
  1459. X
  1460. X    opts_frame = window_create(tool, FRAME,
  1461. X    FRAME_DONE_PROC,    frame_done,
  1462. X    FRAME_LABEL,        "Mush Options",
  1463. X    FRAME_NO_CONFIRM,    TRUE,
  1464. X    FRAME_SHOW_LABEL,    TRUE,
  1465. X    WIN_WIDTH,        OPTIONS_PANEL_WIDTH,
  1466. X    NULL);
  1467. X
  1468. X    opts_panel = window_create(opts_frame, PANEL,
  1469. X    WIN_WIDTH,        OPTIONS_PANEL_WIDTH,
  1470. X    NULL);
  1471. X    (void) notify_interpose_event_func(opts_panel,
  1472. X    fkey_interposer, NOTIFY_SAFE);
  1473. X    panel_create_item(opts_panel, PANEL_BUTTON,
  1474. X    PANEL_LABEL_IMAGE,
  1475. X        panel_button_image(opts_panel, "Done", 4, mush_font),
  1476. X    PANEL_NOTIFY_PROC,    frame_done,
  1477. X    NULL);
  1478. X    panel_create_item(opts_panel, PANEL_BUTTON,
  1479. X    PANEL_LABEL_IMAGE,
  1480. X        panel_button_image(opts_panel, "Help", 4, mush_font),
  1481. X    PANEL_NOTIFY_PROC,    opts_help,
  1482. X    NULL);
  1483. X    panel_create_item(opts_panel, PANEL_BUTTON,
  1484. X    PANEL_LABEL_IMAGE,
  1485. X        panel_button_image(opts_panel, "Save", 4, mush_font),
  1486. X    PANEL_NOTIFY_PROC,    opts_save_load,
  1487. X    PANEL_CLIENT_DATA,    save_opts,
  1488. X    NULL);
  1489. X    panel_create_item(opts_panel, PANEL_BUTTON,
  1490. X    PANEL_LABEL_IMAGE,
  1491. X        panel_button_image(opts_panel, "Load", 4, mush_font),
  1492. X    PANEL_NOTIFY_PROC,    opts_save_load,
  1493. X    PANEL_CLIENT_DATA,    source,
  1494. X    NULL);
  1495. X    panel_create_item(opts_panel, PANEL_BUTTON,
  1496. X    PANEL_LABEL_IMAGE,
  1497. X        panel_button_image(opts_panel, "Clear", 5, mush_font),
  1498. X    PANEL_NOTIFY_PROC,    unset_opts,
  1499. X    NULL);
  1500. X    panel_create_item(opts_panel, PANEL_BUTTON,
  1501. X    PANEL_LABEL_IMAGE,
  1502. X        panel_button_image(opts_panel, "Restart", 7, mush_font),
  1503. X    PANEL_NOTIFY_PROC,    reset_opts,
  1504. X    NULL);
  1505. X    file_text_item = panel_create_item(opts_panel, PANEL_TEXT,
  1506. X    PANEL_LABEL_STRING,    "Save/Load File:",
  1507. X    PANEL_VALUE_DISPLAY_LENGTH, 30,
  1508. X    NULL);
  1509. X    desc_msg = panel_create_item(opts_panel, PANEL_MESSAGE,
  1510. X    PANEL_LABEL_STRING,    "Help Descriptions -- Click on Variable Name",
  1511. X    NULL);
  1512. X    window_fit_height(opts_panel);
  1513. X
  1514. X    /* reuse opts_panel -- we don't need the other one */
  1515. X    opts_panel = window_create(opts_frame, PANEL,
  1516. X    WIN_BELOW,            opts_panel,
  1517. X    WIN_X,                0,
  1518. X    WIN_COLUMN_GAP,            120,
  1519. X    WIN_TOP_MARGIN,            10,
  1520. X    WIN_LEFT_MARGIN,        10,
  1521. X    WIN_WIDTH,            OPTIONS_PANEL_WIDTH,
  1522. X    PANEL_VERTICAL_SCROLLBAR,    scrollbar_create(NULL),
  1523. X    NULL);
  1524. X    (void) notify_interpose_event_func(opts_panel,
  1525. X    fkey_interposer, NOTIFY_SAFE);
  1526. X
  1527. X    for (count = 0; count < ArraySize(viewopts); count++) {
  1528. X    panel_create_item(opts_panel, PANEL_MESSAGE,
  1529. X        PANEL_ITEM_X,    ATTR_COL(0),
  1530. X        PANEL_ITEM_Y,    ATTR_ROW(count),
  1531. X        PANEL_LABEL_STRING,    viewopts[count].v_opt,
  1532. X        PANEL_NOTIFY_PROC,    help_opt,
  1533. X        PANEL_CLIENT_DATA,    count,
  1534. X        NULL);
  1535. X
  1536. X    if (!(p = viewopts[count].v_prompt) || *p == '-') {
  1537. X        if (p && *p)
  1538. X        p++;
  1539. X        viewopts[count].v_choice = panel_create_item(opts_panel,
  1540. X        PANEL_CHOICE,
  1541. X        PANEL_LABEL_IMAGE,    &cycle,
  1542. X        PANEL_LAYOUT,        PANEL_HORIZONTAL,
  1543. X        PANEL_CHOICE_STRINGS,    "False", "True", NULL,
  1544. X        PANEL_DISPLAY_LEVEL,    PANEL_CURRENT,
  1545. X        PANEL_ITEM_X,        ATTR_COL(1),
  1546. X        PANEL_ITEM_Y,        ATTR_ROW(count),
  1547. X        PANEL_NOTIFY_PROC,    toggle_value,
  1548. X        PANEL_CLIENT_DATA,    count,
  1549. X        NULL);
  1550. X    }
  1551. X    if (p) {
  1552. X        viewopts[count].v_text = panel_create_item(opts_panel, PANEL_TEXT,
  1553. X        PANEL_VALUE_DISPLAY_LENGTH,    10,
  1554. X        PANEL_VALUE_UNDERLINED,        TRUE,
  1555. X        PANEL_LABEL_STRING,        p,
  1556. X        PANEL_ITEM_X,            ATTR_COL(2),
  1557. X        PANEL_ITEM_Y,            ATTR_ROW(count),
  1558. X        PANEL_NOTIFY_PROC,        set_value,
  1559. X        PANEL_CLIENT_DATA,        count,
  1560. X        NULL);
  1561. X    }
  1562. X    }
  1563. X    /* set the panel items' values */
  1564. X    opts_panel_item(NULL);
  1565. X
  1566. X    window_set(opts_panel,
  1567. X    WIN_HEIGHT,    400,
  1568. X    WIN_FIT_HEIGHT,    0,
  1569. X    NULL);
  1570. X    window_set(opts_frame, WIN_SHOW, TRUE, NULL);
  1571. X}
  1572. X
  1573. X/*
  1574. X * Sets the items in the panels to reflect that variable's value.
  1575. X * If "var" is NULL, do it for all the items.
  1576. X */
  1577. Xvoid
  1578. Xopts_panel_item(var)
  1579. Xchar *var;
  1580. X{
  1581. X    int count;
  1582. X    char *value;
  1583. X
  1584. X    if (!opts_frame)
  1585. X    return;
  1586. X
  1587. X    for (count = 0; count < ArraySize(viewopts); count++) {
  1588. X    if (var && strcmp(var, viewopts[count].v_opt))
  1589. X        continue;
  1590. X    value = do_set(set_options, viewopts[count].v_opt);
  1591. X
  1592. X    if (!viewopts[count].v_prompt || *viewopts[count].v_prompt == '-')
  1593. X        panel_set_value(viewopts[count].v_choice, value != NULL);
  1594. X    if (viewopts[count].v_prompt)
  1595. X        panel_set_value(viewopts[count].v_text, value? value : "");
  1596. X    if (var)
  1597. X        break;
  1598. X    }
  1599. X}
  1600. X
  1601. X/*
  1602. X * Callback for choice items -- for variables that have boolean settings.
  1603. X * CLIENT_DATA is the index in the viewopts array.
  1604. X */
  1605. Xstatic
  1606. Xtoggle_value(item, value)
  1607. XPanel_item item;
  1608. Xint value;
  1609. X{
  1610. X    int count = (int) panel_get(item, PANEL_CLIENT_DATA);
  1611. X    char *p, *argv[4];
  1612. X    char *text_value = NULL;
  1613. X
  1614. X    if (check_internal(viewopts[count].v_opt)) {
  1615. X    panel_set(desc_msg, PANEL_LABEL_STRING,
  1616. X        "This is an internal variable which cannot be changed.",
  1617. X        NULL);
  1618. X    return -1;
  1619. X    }
  1620. X
  1621. X    if (p = viewopts[count].v_prompt) /* set equal */
  1622. X    text_value = panel_get_value(viewopts[count].v_text);
  1623. X
  1624. X    if (!value)
  1625. X    (void) un_set(&set_options, viewopts[count].v_opt);
  1626. X    else {
  1627. X    /* Turn it on if it's entirely boolean or bool/str, but no str value */
  1628. X    if (!p || text_value && !*text_value) {
  1629. X        argv[0] = viewopts[count].v_opt; /* it's a boolean */
  1630. X        argv[1] = NULL;
  1631. X    } else {
  1632. X        /* string value -- determine the text from the typed in value */
  1633. X        argv[0] = viewopts[count].v_opt;
  1634. X        argv[1] = "=";
  1635. X        argv[2] = text_value;
  1636. X        argv[3] = NULL;
  1637. X    }
  1638. X    (void) add_option(&set_options, argv);
  1639. X    }
  1640. X
  1641. X    if (!strcmp(viewopts[count].v_opt, "no_reverse") ||
  1642. X    !strcmp(viewopts[count].v_opt, "show_deleted"))
  1643. X    do_hdrs(0, DUBL_NULL, NULL);
  1644. X
  1645. X    return 0;
  1646. X}
  1647. X
  1648. X/* callback for text items -- set vars to the string typed. */
  1649. Xstatic
  1650. Xset_value(item, event)
  1651. XPanel_item item;
  1652. XEvent *event;
  1653. X{
  1654. X    int count = (int)panel_get(item, PANEL_CLIENT_DATA);
  1655. X    char *p, *argv[4], *value;
  1656. X
  1657. X    if (event_id(event) == '\t')
  1658. X    return (int) PANEL_NEXT;
  1659. X
  1660. X    p = viewopts[count].v_prompt;
  1661. X    value = panel_get_value(item);
  1662. X
  1663. X    if (check_internal(viewopts[count].v_opt)) {
  1664. X    panel_set(desc_msg, PANEL_LABEL_STRING,
  1665. X        "This is an internal variable which cannot be changed.",
  1666. X        NULL);
  1667. X    return (int) PANEL_NONE;
  1668. X    }
  1669. X
  1670. X    /*
  1671. X     * You can "unset" string-only values by entering a blank string.
  1672. X     * If the "prompt" starts with a -, then you can only "unset" the
  1673. X     * variable by setting the associated choice item to false.
  1674. X     */
  1675. X    if (*p != '-' && !*value) {
  1676. X    (void) un_set(&set_options, viewopts[count].v_opt);
  1677. X    return (int) PANEL_NONE; /* do not advance caret */
  1678. X    }
  1679. X    /* Turn it on, but not to a value */
  1680. X    if (!*value) {
  1681. X    argv[0] = viewopts[count].v_opt; /* it's a boolean */
  1682. X    argv[1] = NULL;
  1683. X    } else {
  1684. X    /* string value -- determine the text from the typed in value */
  1685. X    argv[0] = viewopts[count].v_opt;
  1686. X    argv[1] = "=";
  1687. X    argv[2] = value;
  1688. X    argv[3] = NULL;
  1689. X    }
  1690. X
  1691. X    (void) add_option(&set_options, argv);
  1692. X    if (p && *p == '-')
  1693. X    panel_set_value(viewopts[count].v_choice, TRUE);
  1694. X
  1695. X    return (int) PANEL_NONE;
  1696. X}
  1697. X
  1698. X/* when user clicks on variable label itself */
  1699. Xstatic
  1700. Xhelp_opt(item, event)
  1701. XPanel_item item;
  1702. XEvent *event;
  1703. X{
  1704. X    int count = (int)panel_get(item, PANEL_CLIENT_DATA);
  1705. X
  1706. X    panel_set(desc_msg,
  1707. X    PANEL_LABEL_STRING, viewopts[count].v_description,
  1708. X    NULL);
  1709. X    return 0;
  1710. X}
  1711. X
  1712. X#endif /* SUNTOOL */
  1713. X
  1714. X/*
  1715. X * return a string describing a variable.
  1716. X * parameters: count, str, buf.
  1717. X * If str != NULL, check str against ALL variables
  1718. X * in viewopts array.  The one that matches, set count to it and 
  1719. X * print up all the stuff from the viewopts[count] into the buffer
  1720. X * space in "buf" and return it.
  1721. X */
  1722. Xchar *
  1723. Xvariable_stuff(count, str, buf)
  1724. Xregister char *str, *buf;
  1725. X{
  1726. X    if (str)
  1727. X    for (count = 0; count < ArraySize(viewopts); count++)
  1728. X        if (!strcmp(str, viewopts[count].v_opt))
  1729. X        break;
  1730. X    if (count >= ArraySize(viewopts)) {
  1731. X    (void) sprintf(buf, "%s: Not a default %s variable.",
  1732. X               str? str : itoa(count), prog_name);
  1733. X    return NULL;
  1734. X    }
  1735. X    return sprintf(buf, "%s: %s",
  1736. X    viewopts[count].v_opt, viewopts[count].v_description);
  1737. X}
  1738. END_OF_FILE
  1739. if test 18292 -ne `wc -c <'mush/viewopts.c'`; then
  1740.     echo shar: \"'mush/viewopts.c'\" unpacked with wrong size!
  1741. fi
  1742. # end of 'mush/viewopts.c'
  1743. fi
  1744. echo shar: End of archive 7 \(of 19\).
  1745. cp /dev/null ark7isdone
  1746. MISSING=""
  1747. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ; do
  1748.     if test ! -f ark${I}isdone ; then
  1749.     MISSING="${MISSING} ${I}"
  1750.     fi
  1751. done
  1752. if test "${MISSING}" = "" ; then
  1753.     echo You have unpacked all 19 archives.
  1754.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1755. else
  1756.     echo You still need to unpack the following archives:
  1757.     echo "        " ${MISSING}
  1758. fi
  1759. ##  End of shell archive.
  1760. exit 0
  1761.  
  1762.  
  1763.