home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / mush.lzh / mush.15 < prev    next >
Encoding:
Text File  |  1990-05-06  |  54.7 KB  |  1,738 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 15 (of 19)."
  10. # Contents:  mush/README-7.0 mush/glob.c mush/options.h mush/panels.c
  11. # Wrapped by argv@turnpike on Wed May  2 13:59:46 1990
  12. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  13. if test -f 'mush/README-7.0' -a "${1}" != "-c" ; then 
  14.   echo shar: Will not clobber existing file \"'mush/README-7.0'\"
  15. else
  16. echo shar: Extracting \"'mush/README-7.0'\" \(15679 characters\)
  17. sed "s/^X//" >'mush/README-7.0' <<'END_OF_FILE'
  18. X
  19. XThis is the official release of the Mush port to SunView, referred to in
  20. Xalpha and beta versions as "mushview".  This file describes most of the
  21. Xchanges from revision 6.5.6 of "mush" and "mushtool".  Sorry, IBM, we
  22. Xnever managed to get the DOS code integrated.  Note that this is version
  23. X7.0.0, not to be confused (we hope) with alpha-test releases that had a
  24. Xthird zero appended to the number.  Check the dates if you aren't sure.
  25. X
  26. XThanks up front to Rich Burridge of Sun Australia for his work on
  27. Xconverting mush's SunWindows code to SunView, and for giving mush a really
  28. Xthorough linting, which it had needed for some time.  Thanks also to the
  29. Xmany alpha and beta testers who sent valuable comments.
  30. X
  31. XVersion 7.0.0 differs from the several 6.5.6 Beta releases in that a
  32. Xlarge portion of the Sun code has changed to use text subwindows instead
  33. Xof pixrects.  This is a significant enough change in "look and feel" that
  34. Xthe release number was increased from 6 to 7.  Addition of file completion
  35. Xto the line/curses modes is also considered a major improvement, as are
  36. Xchanges to the "mail" command (described below).
  37. X
  38. XTool mode changes include:
  39. X    * The message display window is a textsw, with scrollbars.
  40. X    * The composition window is also a textsw, and opens in a separate
  41. X      frame, so you can read messages in the main frame while composing.
  42. X      You can still invoke an editor, and the default window size is
  43. X      such that vi no longer gets confused (as far as we can tell).
  44. X    * There are variables to control the sizes of most subwindows.
  45. X    * Header-editing works in tool mode (in fact, you MUST use it).
  46. X    * Help, options, and alias settings also pop up in their own frames.
  47. X      The help descriptions have been improved (we believe).
  48. X    * Interactive function-key binding is no longer supported; the clash
  49. X      of mush function keys with SunView functions has been eliminated.
  50. X    * The list of folders in your folder directory is made into a
  51. X      walking menu.  (Handling of this may improve in future patches.)
  52. X
  53. XIn addition to the SunView conversions and linting, which make up the bulk
  54. Xof the changes, there have been a number of bug fixes and enhancements to
  55. Xthe 6.5.6 baseline.  These include:
  56. X
  57. Xmush -h file
  58. Xmush -U -h file
  59. Xmush -U! -h file
  60. X    The new -h (-draft) options allows mush to read in a prepared message
  61. X    for sending, in the same manner as Rnmail.  The specified file must
  62. X    contain the message headers (either when first read or after editing
  63. X    by the user); mush will not add headers to it.  The intended use of
  64. X    this option is to write a partially finished message to a file and
  65. X    then return to it later.  (See commentary below on "mail -h".)  The
  66. X    new -U (-send) option allows the draft file to be sent immediately
  67. X    without editing (-U means "unedited").  Signatures and fortunes are
  68. X    not appended when -U! is used ("unsigned" as well as unedited).
  69. X
  70. Xmush -I file
  71. Xmush -I! file
  72. X    The new -I (-init) option allows the user to specify an init file that
  73. X    is read before any of the other init files.  -I! causes the specified
  74. X    file to replace the system Mushrc file; otherwise, the given file and
  75. X    the system Mushrc are both read.  -I has no effect on reading of the
  76. X    user's own $HOME/.mushrc file (except that the indicated file could
  77. X    "setenv MAILRC", thus changing the location of the user's file).
  78. X
  79. Xmush -n
  80. Xmush -n!
  81. X    The first form of this option now works like the ucbMail -n option,
  82. X    that is, it prevents sourcing of the system Mushrc but the user's own
  83. X    $HOME/.mushrc is still read.  The new -n! variation prevents either
  84. X    file from being sourced, which was the old behavior of -n.  Using -n
  85. X    does not change the effect of -I, so the following are equivalent:
  86. X        mush -n -I file            mush -I! file
  87. X
  88. Xcd
  89. X    The cdpath variable now works correctly when specified with either
  90. X    colons or spaces separating the list of directories.
  91. X
  92. Xhelp
  93. X    The help facility has been expanded; there is now a help file entry
  94. X    consisting of a usage line and short explanation for every documented
  95. X    line-mode command except "debug" and "version", all accessible via
  96. X    "? command" or "command -?".  In addition, there are variables:
  97. X    set cmd_help = path    Give new location for cmd_help file
  98. X    set tool_help = path    Give new location for tool_help file
  99. X    These variables, which can be set in the system or user init files,
  100. X    have replaced the old -1 and -2 startup options, i.e. cmd_help and
  101. X    tool_help can no longer be specified on the mush command line.
  102. X
  103. Xmail -E
  104. Xmail -h file
  105. Xmail -H file
  106. Xmail -I
  107. Xmail -u
  108. Xmail -U -h file
  109. X    The new "-h file" option of the mail command corresponds to the -h
  110. X    option of mush itself, and is intended for reading in previously
  111. X    begun letters.  It implies -E (edit_hdrs).  The previous meaning of
  112. X    -h (include and indent a message with its headers) is now supported
  113. X    by the -I option, corresponding to the ~I escape (see below).  The
  114. X    -H option is analogous to -h, except that the file need not contain
  115. X    message headers (edit_hdrs is not implied).  (Some alpha versions
  116. X    used -H for the function now supplied by -I.)
  117. X    The -E option no longer implies autoedit.
  118. X    The new -u option turns off autosign and fortune.  Most useful
  119. X    with "-h file" when you want to continue editing the draft but a
  120. X    signature or fortune has already been appended; but -h is not
  121. X    required for -u.  The new -U option sends the file immediately; it
  122. X    cannot be used without -h or -H, and will be ignored if no To:
  123. X    address has been specified.
  124. X    Also, the user is no longer required to provide a To: address in
  125. X    order to begin composing a letter (one is still required before
  126. X    sending it), and the To: address may be only files and/or pipes if
  127. X    desired (in which case the MTA is not run).
  128. X    Finally, the tilde-escape ~I has replaced ~H for purposes of
  129. X    including a message and its headers in the letter being composed.
  130. X    This is analagous to the -i and -I options and the ~i escape.
  131. X
  132. Xmy_hdr From: address
  133. X    This is now allowed (it is allowed but neither documented nor correctly
  134. X    used in 6.5.6, and was not allowed previously).  The user's From: header
  135. X    is verified as best mush can, and used if it appears valid.  It is up
  136. X    to the MTA to assure authenticity and/or add a Sender: header.  Mush
  137. X    provides a From: if the user does not or if it cannot verify the one
  138. X    given.
  139. X
  140. Xpipe -p pattern unix-command
  141. X    The pipe command has been modified to allow its use as a shell script
  142. X    extractor.  See the man page and "pipe -?" for details.  KNOWN BUG:
  143. X    given a list of messages, all are sent to the same unix process.
  144. X    This can cause havoc e.g. when each of the messages is a shell script
  145. X    intended to be run by a virgin shell.  Changes are being discussed.
  146. X    Also, pipe is now affected by $alwaysignore (see below).
  147. X
  148. XPipe
  149. X    See the comments under "write" below.
  150. X
  151. Xpwd
  152. X    This now prints the actual current working directory rather than
  153. X    simply echoing the value of $cwd.
  154. X
  155. Xreply
  156. X    Assorted repairs have been made to to take_me_off() (implements the
  157. X    inverse of $metoo) and reply_to().  These include doing a better
  158. X    (though still not perfect) job of getting the name and address to
  159. X    match when replying to forwarded mail.
  160. X
  161. Xsort
  162. X    The current message now moves with the sort, that is, the same actual
  163. X    message (not necessarily the same message *number*) will be the
  164. X    current message after the sort as was current before the sort.
  165. X
  166. Xsave/copy
  167. X    The 'p' (printed) and 'f' (forwarded) Status flags are now properly
  168. X    saved when messages are saved/copied, and restored when the folders
  169. X    are read.  Also, a "-f" (force) flag has been added, which has the
  170. X    same meaning as the old "!" flag, that is, overwrite the file rather
  171. X    than appending to it.  "save !" is still supported.
  172. X
  173. Xundigest -p pattern
  174. X    The specified pattern is used as the article separator for unpacking
  175. X    digests.  The default is "--------".  A literal match (no regexps or
  176. X    wildcards) is done at beginning-of-line.
  177. X
  178. Xwrite
  179. X    The write command (and other commands such as Pipe that omit message
  180. X    headers) no longer outputs the blank line that separates the message
  181. X    body from the headers, and also does not output the trailing blank
  182. X    line that separates messages from one another.  (This applies only
  183. X    when MSG_SEPARATOR is not defined during compilation.)  This makes
  184. X    the command more useful for saving multi-part uuencoded files, etc.
  185. X
  186. X$$
  187. X$name:l
  188. X$name:u
  189. X$name:<number>
  190. X    Four new variable forms.  The first returns the PID of the running
  191. X    mush; the second converts all alphabetics in the value of $name to
  192. X    lower case; the third converts all alphabetics in the value of $name
  193. X    to uppercase; the fourth splits the value into words and returns the
  194. X    <number>th word.  Only one modifier can be used at a time.
  195. X
  196. X$[%fmt]
  197. X    This special variable form expands %fmt (a string with no spaces) as
  198. X    a hdr_format format.  E.g., $h%a is the author of the current message.
  199. X    Any colon-modifier may be applied, e.g.
  200. X    $[%n]:1        First name of author of current message
  201. X
  202. X$(%c)
  203. X    This special variable form expands %c (c is a character) as a prompt
  204. X    format.  E.g., $(%T) is the current time.  Colon-modifiers apply.
  205. X
  206. X$alwaysignore
  207. X    This variable now actually works as documented.  If you've gotten used
  208. X    to the old behavior, you'll need to set this.  Note, however, that the
  209. X    documented behavior has changed slightly.  The (erroneous) behavior of
  210. X    Mush 6.5.6 when this variable was UNset is now achieved by:
  211. X    set alwaysignore = "include,forward,pipe"
  212. X    Setting this variable with no value has the same effect as in 6.5.6.
  213. X
  214. X$autosign
  215. X    You can now specify a program to be run, whose output will sign the
  216. X    letter; the syntax is
  217. X    set autosign = '|program-name'
  218. X    This syntax has not been finalized and may change.  The argument list
  219. X    passed to the program is the list of addresses that will go to the MTA,
  220. X    in exactly the same form as that which will be used for the MTA (e.g.,
  221. X    there may be a comma after each address).
  222. X
  223. X$complete
  224. X    Mush now supports filename completion and will eventually support
  225. X    command completion as well.  This variable has a two-character "string"
  226. X    value; the first character is used for name completion, the second for
  227. X    listing, ala ESC and ^D in 4.3 BSD csh.
  228. X
  229. X$domain_route
  230. X    This variable allows the user to specify that domain short-circuiting
  231. X    should be done in conjunction with auto_route.  Addresses that are
  232. X    already in RFC822 domain form (user@domain) are not normally changed.
  233. X    UUCP paths that contain fully-qualified domains are short-circuited
  234. X    to the rightmost such domain.  Optionally, domain_route may be set
  235. X    to a string, in which case all addresses are rewritten to UUCP form,
  236. X    short-circuited, and the given string is then prepended as the first
  237. X    host in the path.  This variable is intended for use at RFC976 Class 3
  238. X    UUCP hosts, or UUCP sites with a connection to a Class 3 host.
  239. X
  240. X$fignore
  241. X    This variable modifies the behavior of file completion by specifying
  242. X    file name forms that should NOT be completed.  See the man page for
  243. X    more details.
  244. X
  245. X$hdr_format
  246. X    A new formatting string now allows access to *any* message header.
  247. X    The format is:    %?header-name?
  248. X    For example,
  249. X    set hdr_format='%n "%?x-mailer?"'
  250. X    might display
  251. X    1 >   Barton E. Schaefer "Mail User's Shell (7.0.0 12/10/89)"
  252. X    This can be used to avoid mush's TO: display for messages you
  253. X    authored; just replace "%f" with "%?from?".
  254. X
  255. X$lister
  256. X    Has been removed.  The "folders" command now supplies its own set
  257. X    of flags to ls, and "cmd ls 'ls ...'" suffices for other uses.
  258. X
  259. X$quiet
  260. X    This variable now has a value of one to six comma-delimited words.
  261. X    For compatibility with previous versions, setting quiet without a
  262. X    value has the original behavior of suppressing the startup message.
  263. X    The recognized words are:
  264. X    autosign    Don't tell me when a signature is appended
  265. X    await        Await command doesn't ring for new mail
  266. X    complete    Word completion doesn't ring on failure
  267. X    fortune        Don't tell me when a fortune is appended
  268. X    startup        Don't print the startup message
  269. X    tool        Tool mode doesn't ring for new mail
  270. X    Errors in autosigning or fortunes are still reported.  (Some beta
  271. X    releases assigned three of these fields, with the on/off sense
  272. X    reversed, to a variable named $bell; that variable is gone.)
  273. X
  274. X$version
  275. X    The version string, as printed on startup.
  276. X____________
  277. X
  278. XMMDF Changes and File Locking Improvements
  279. X------------------------------------------
  280. X
  281. XThe MMDF support code has been modified to use the MMDF library calls for
  282. Xfile locking.  The files makefile.* were modified to make the need to link
  283. Xin the MMDF library more obvious, and the comments in config.h-dist now
  284. Xreflect the current (simpler) installation instructions for MMDF sites.
  285. X
  286. XIn the course of these updates, the structure of the file locking calls
  287. Xwas reworked to make open and lock a single (non-atomic) operation.  Many
  288. Xthanks to lmjm@doc.imperial.ac.uk (Lee McLoughlin) and marc@virginia.edu
  289. X(Marc Rouleau) for instigation and help with implementation and testing of
  290. Xthese changes.
  291. X
  292. XIn the course of making these changes, a number of errors were discovered
  293. Xand repaired:
  294. X
  295. X    An "update" would remove empty files and then try to reload them,
  296. X    generating error messages.  The copyback() function now returns -1 if
  297. X    it removes a file; folder() recognizes this and does not attempt to
  298. X    load_folder() on a removed file.
  299. X
  300. X    There was a remote possibility of a race condition in in copyback()
  301. X    because open-and-lock is non-atomic.  copyback() now checks for new
  302. X    mail AFTER locking the spool file; this guarantees the MTA can't
  303. X    slip a new message into the file just before it gets truncated.  The
  304. X    check_new_mail() function has been broken into three specialized
  305. X    parts to allow this:  get_new_mail() and show_new_mail() work as you
  306. X    probably expect, and check_new_mail() now calls them.
  307. X
  308. X    The mbox file ($HOME/mbox or whatever) is locked by copyback(), and
  309. X    all folders are locked by save_msg().
  310. X
  311. X    The dead.letter file is locked by dead_letter().
  312. X
  313. X    "Reinitializing" of a folder that was modified behind mush's back
  314. X    would do pretty strange things in curses mode.  It now behaves more
  315. X    sensibly.  Also, if your spool folder shrinks while you are using a
  316. X    non-spool folder, mush won't incorrectly re-initialize the current
  317. X    folder (a bug no one ever saw, we hope).
  318. X
  319. X    All mailboxes are locked for reading when they are first loaded or
  320. X    when new mail comes in, whenever possible (DOT_LOCK and old Xenix
  321. X    installations cannot read-lock).  If the MTA also uses a compatible
  322. X    locking scheme (as one would hope), this should prevent "truncation"
  323. X    of new messages without unduly restricting the reading of folders.
  324. X
  325. X    NOTE:  All this precautionary locking has its drawbacks.  Sending
  326. X    mail can deadlock if you mention the same file twice in the list
  327. X    of addresses.  (Of course, before the advent of locking, this would
  328. X    cause interleaved writes; which is the lesser evil?)  Be careful.
  329. X
  330. XAdditional changes apply to installations where SYSV is defined:
  331. X
  332. X    Because lockf() requires a file open for writing, the locking code
  333. X    has been rewritten to call fcntl(F_SETLK) directly.  Read and write
  334. X    locks are used as appropriate.
  335. X
  336. X    This locking code has been only minimally tested, because none of the
  337. X    authors has direct access to a true SysV machine.  Bug reports with
  338. X    suggestions for improvement are requested.
  339. END_OF_FILE
  340. if test 15679 -ne `wc -c <'mush/README-7.0'`; then
  341.     echo shar: \"'mush/README-7.0'\" unpacked with wrong size!
  342. fi
  343. # end of 'mush/README-7.0'
  344. fi
  345. if test -f 'mush/glob.c' -a "${1}" != "-c" ; then 
  346.   echo shar: Will not clobber existing file \"'mush/glob.c'\"
  347. else
  348. echo shar: Extracting \"'mush/glob.c'\" \(19617 characters\)
  349. sed "s/^X//" >'mush/glob.c' <<'END_OF_FILE'
  350. X#include "mush.h"
  351. X#include "glob.h"
  352. X
  353. X/*
  354. X * Buried somewhere in here is the skeleton of a pattern matcher posted
  355. X * by koblas@mips.COM (David Koblas).  It has been hacked almost beyond
  356. X * recognition to handle more complex patterns, and directory search has
  357. X * been added (patterns are split at '/' characters when file globbing).
  358. X */
  359. X
  360. X#ifdef TEST    /* Define TEST to build a stand-alone file globbing program */
  361. X
  362. Xextern char *malloc(), *realloc();
  363. X
  364. X#define getpath(x,y) (*(y) = 0, (x))
  365. X#define Access access
  366. X#define Strcpy(x,y) (strcpy(x,y), strlen(x))
  367. X#define savestr(x)  (strcpy(malloc(strlen(x)+1),x))
  368. X#ifndef max
  369. X#define max(x,y) ((x) > (y) ? (x) : (y))
  370. X#endif /* max */
  371. X#ifndef min
  372. X#define min(x,y) ((x) > (y) ? (y) : (x))
  373. X#endif /* min */
  374. X#define xfree free
  375. X#undef wprint
  376. X#define wprint printf
  377. X#define debug 0
  378. X#undef sprintf
  379. X
  380. X#define TESTGLOB(str1,str2) \
  381. X    printf("%s %s = %s\n",str1,str2,glob(str1,str2)?"TRUE":"FALSE")
  382. X
  383. Xmain(argc, argv)
  384. Xint argc;
  385. Xchar **argv;
  386. X{
  387. X    char **e;
  388. X    int f;
  389. X
  390. X    if (argc > 1)
  391. X    while (*++argv) {
  392. X        (void) printf("%s -->\n", *argv);
  393. X        if (f = filexp(*argv, &e)) {
  394. X        columnate(f, e, 0);
  395. X        }
  396. X    }
  397. X#ifdef TEST2    /* Define TEST2 to automatically run these test cases */
  398. X    TESTGLOB("abcdefg", "abcdefg");
  399. X    TESTGLOB("abcdefg", "a?cd?fg");
  400. X    TESTGLOB("abcdefg", "ab[cde]defg");
  401. X    TESTGLOB("abcdefg", "ab[a-z]defg");
  402. X    TESTGLOB("abcdefg", "ab[a-z]defg");
  403. X    TESTGLOB("ab]defg", "ab[a]c]defg");
  404. X    TESTGLOB("ab]defg", "ab[a\\]c]defg");
  405. X    TESTGLOB("abcdefg", "ab*fg");
  406. X    TESTGLOB("./bc/def/gh/ij", "*de*");
  407. X    TESTGLOB("./der/den/deq/der/", "*deq*");
  408. X    TESTGLOB("./bc/def/gh/ij", "*ij");
  409. X    TESTGLOB("./ij", ".?ij");
  410. X    TESTGLOB("./bc/def/gh/ij", "./*");
  411. X    TESTGLOB("abcdef", "*def");
  412. X    TESTGLOB("abcdef", "*abcdef");
  413. X    TESTGLOB("abcdef", "abc*");
  414. X    TESTGLOB("abcdef", "abcdef*");
  415. X    TESTGLOB("abcdef", "*?*{xxx,,yy}");
  416. X    TESTGLOB("abcdef", "abcde{f}");
  417. X    TESTGLOB("abcdef", "abcdef{xxx,,yyy}");
  418. X    TESTGLOB("abcdef", "abc{def,qwrx}");
  419. X    TESTGLOB("abcdef", "abc{ab,def,qwrx}");
  420. X    TESTGLOB("abcdef", "{naqrwer,fuwnwer,as,abc,a}{ab,def,qwrx}");
  421. X    TESTGLOB("abcdef", "{naqrwer,*,as,abc,a}{ab,def,qwrx}");
  422. X    TESTGLOB("abcdef", "{{a*,b*},as,a}{ab,def,qwrx}");
  423. X    TESTGLOB("abcdef", "{{c*,b*},as,a}{ab,def,qwrx}");
  424. X    TESTGLOB("abcdef", "{{c*,?b*},as,a}{ab,def,qwrx}");
  425. X    TESTGLOB("abcdef", "{naqrwer,fuwnwer,as,abc,a}{ab,d*f,qwrx}");
  426. X#endif /* TEST2 */
  427. X}
  428. X
  429. Xchar *
  430. Xany(s1, s2)
  431. Xregister char *s1, *s2;
  432. X{
  433. X    register char *p;
  434. X    if (!s1 || !*s1 || !s2 || !*s2)
  435. X    return 0;
  436. X    for( ; *s1; s1++) {
  437. X    for(p = s2; *p; p++)
  438. X        if (*p == *s1)
  439. X        return s1;
  440. X    }
  441. X    return 0;
  442. X}
  443. X
  444. X#endif /* TEST */
  445. X
  446. X/*
  447. X * Make a string into a one-element vector
  448. X */
  449. Xchar **
  450. Xunitv(s)
  451. Xchar *s;
  452. X{
  453. X    char **v;
  454. X
  455. X    if (v = (char **)malloc((unsigned)(2 * sizeof(char *)))) {
  456. X    v[0] = savestr(s);
  457. X    v[1] = NULL;
  458. X    }
  459. X    return v;
  460. X}
  461. X
  462. X/*
  463. X * Append one vector to another
  464. X */
  465. Xcatv(s1, v1, s2, v2)
  466. Xint s1, s2;
  467. Xchar ***v1, **v2;
  468. X{
  469. X    int i;
  470. X
  471. X    if (s1 < 0 || !v1)
  472. X    return -1;
  473. X    if (s2 < 0 || !v2)
  474. X    return s1;
  475. X
  476. X    /* realloc(NULL, size) should be legal, but Sun doesn't support it. */
  477. X    if (*v1)
  478. X        *v1 = (char **)realloc(*v1,(unsigned)((s1+s2+1) * sizeof(char **)));
  479. X    else
  480. X        *v1 = (char **)malloc((unsigned)((s1+s2+1) * sizeof(char **)));
  481. X
  482. X    if (*v1) {
  483. X    for (i = 0; i < s2 && v2[i]; i++)
  484. X        (*v1)[s1 + i] = v2[i]; 
  485. X    (*v1)[s1 + i] = NULL;
  486. X    xfree(v2);
  487. X    return s1 + i;
  488. X    }
  489. X    return -1;
  490. X}
  491. X
  492. X/*
  493. X * A duplicate-eliminating comparison for sorting.  It treats an empty
  494. X * string as greater than any other string, and forces empty one of any
  495. X * pair of of equal strings.  Two passes are sufficient to move the empty
  496. X * strings to the end where they can be deleted by the calling function.
  497. X *
  498. X * This is NOT compatible with the ANSI C qsort(), which requires that the
  499. X * comparison function will not modify its arguments!
  500. X */
  501. Xuniqcmp(p1, p2)
  502. Xchar **p1, **p2;
  503. X{
  504. X    int cmp;
  505. X
  506. X    if (**p1 && !**p2)
  507. X    return -1;
  508. X    if (**p2 && !**p1)
  509. X    return 1;
  510. X    if (cmp = strcmp(*p1, *p2))
  511. X    return cmp;
  512. X    **p2 = 0;
  513. X    return -1;
  514. X}
  515. X
  516. X/*
  517. X * Expand a pattern into a list of file names.  Returns the number of
  518. X * matches.  As in csh, names generated from pattern sets are returned
  519. X * even if there are no actual matches.
  520. X */
  521. Xfilexp(pat, exp)
  522. Xchar *pat, ***exp;
  523. X{
  524. X    char **t1, **t2;
  525. X    int n, new, cnt;
  526. X
  527. X    if (!exp)
  528. X    return -1;
  529. X    if (!pat || !*pat)
  530. X    return 0;
  531. X
  532. X    if ((n = sxp(pat, &t1)) > 0)
  533. X    cnt = 0;
  534. X    else
  535. X    return n;
  536. X    *exp = DUBL_NULL;
  537. X    while (n--)
  538. X    if ((new = fxp(t1[n], &t2)) > 0 || new++ == 0 && t2)
  539. X        cnt = catv(cnt, exp, new, t2);
  540. X    if (cnt > 1) {
  541. X    /* Two sort passes to eliminate duplicates -- see uniqcmp() */
  542. X    qsort((char *)*exp, cnt, sizeof(char *), uniqcmp);
  543. X    qsort((char *)*exp, cnt, sizeof(char *), uniqcmp);
  544. X    while (!(*exp)[cnt - 1][0]) {
  545. X        xfree((*exp)[--cnt]);
  546. X        (*exp)[cnt] = NULL;
  547. X    }
  548. X    }
  549. X    return cnt;
  550. X}
  551. X
  552. X/*
  553. X * Expand a filename with globbing chars into a list of matching filenames.
  554. X * Pattern set notatation which crosses directories is not handled, e.g.
  555. X * "fi{le/exp,nger/h}and" will NOT expand to "file/expand finger/hand".
  556. X * Such patterns must be pre-expanded by sxp() before calling fxp().
  557. X *
  558. X * The list of expansions is placed in *exp, and the number of matches
  559. X * is returned, or -1 on an error.
  560. X */
  561. Xfxp(name, exp)
  562. Xchar *name, ***exp;
  563. X{
  564. X    char *p;
  565. X    int isdir;
  566. X
  567. X    if (!exp)
  568. X    return -1;
  569. X
  570. X    isdir = 1; /* ignore no such file */
  571. X    p = getpath(name, &isdir);
  572. X    if (isdir < 0)
  573. X    return -1;
  574. X    else if (isdir)
  575. X    return ((*exp = unitv(p)) ? 1 : -1);
  576. X    return pglob(p, 0, exp);
  577. X}
  578. X
  579. X/*
  580. X * Match all globbings in a path.  Mutually recursive with dglob(), below.
  581. X * The first "skip" characters of the path are not globbed, see dglob().
  582. X *
  583. X * Returns the number of matches, or -1 on an error.  *exp is set to the
  584. X * list of matches.
  585. X *
  586. X * If the path has no metachars, it is returned in *exp whether it matches
  587. X * a real file or not.  This allows patterns built by sxp() to be recognized
  588. X * and returned even when there are no matches (ala csh generation of names
  589. X * from pattern sets).  pglob() still returns zero in this case.
  590. X */
  591. Xpglob(path, skip, exp)
  592. Xchar *path, ***exp;
  593. Xint skip;
  594. X{
  595. X    char *t, *t2;
  596. X    int ret = 0;
  597. X
  598. X    if (!path || !exp || skip < 0)
  599. X    return -1;
  600. X    *exp = DUBL_NULL; /* Must be null in case of zero matches and no sets */
  601. X
  602. X    for (t = t2 = path + skip; (t2 = any(t2, META)) && *t2 == '/'; t = t2++)
  603. X    ;
  604. X    if (!t2) {
  605. X    ret = ((*exp = unitv(path)) ? 1 : -1);
  606. X    if (ret > 0 && Access(path, F_OK) < 0)
  607. X        ret = 0;
  608. X    } else {
  609. X    if (t2 = index(t + 1, '/'))
  610. X        *t2++ = 0;
  611. X    if (*t == '/') {
  612. X        *t++ = 0;
  613. X        if (!*path)
  614. X        ret = dglob("/", t, t2, exp);
  615. X        else
  616. X        ret = dglob(path, t, t2, exp);
  617. X    } else {
  618. X        ret = dglob("", t, t2, exp);
  619. X    }
  620. X    }
  621. X    return ret;
  622. X}
  623. X
  624. X/*
  625. X * Search a directory (possibly recursively) for glob matches.
  626. X * Argument pat1 is a pattern to be matched in this directory,
  627. X * and pat2 is a pattern to be matched in matched subdirectories.
  628. X *
  629. X * Matches are returned through *exp.
  630. X */
  631. Xdglob(dir, pat1, pat2, exp)
  632. Xchar *dir, *pat1, *pat2, ***exp;
  633. X{
  634. X    DIR *dirp;
  635. X    struct dirent *dp;
  636. X    char *b, *d, buf[MAXPATHLEN], **tmp;
  637. X    int n, ret = 0, skip;
  638. X
  639. X    if (!dir || !exp)
  640. X    return -1;
  641. X    d = (*dir ? dir : ".");
  642. X    if (!(dirp = opendir(d)))
  643. X    return -1;
  644. X    b = buf + Strcpy(buf, dir);
  645. X    if (b > buf && *(b - 1) != '/')
  646. X    *b++ = '/';
  647. X    skip = b - buf; /* We know this much matches, don't glob it again */
  648. X    while (ret >= 0 && (dp = readdir(dirp))) {
  649. X    if (fglob(dp->d_name, pat1)) {
  650. X        if (pat2) {
  651. X        (void) sprintf(b, "%s/%s", dp->d_name, pat2);
  652. X        n = pglob(buf, skip, &tmp);
  653. X        ret = catv(ret, exp, n, tmp);
  654. X        } else {
  655. X        (void) strcpy(b, dp->d_name);
  656. X        ret = catv(ret, exp, 1, unitv(buf));
  657. X        }
  658. X    }
  659. X    }
  660. X    closedir(dirp);
  661. X    return ret;
  662. X}
  663. X
  664. X/*
  665. X * Match file names.  This means that metachars do not match leading ".".
  666. X */
  667. Xfglob(str, pat)
  668. Xchar *str, *pat;
  669. X{
  670. X    if (!str || !pat || *str == '.' && *pat != '.')
  671. X    return FALSE;
  672. X    else
  673. X    return glob(str, pat);
  674. X}
  675. X
  676. X/*
  677. X * Match two concatenated patterns.  Mainly for use by sglob().
  678. X */
  679. Xstatic
  680. Xglob2(str, pat1, pat2)
  681. Xchar *str, *pat1, *pat2;
  682. X{
  683. X    char buf[MAXPATHLEN];
  684. X
  685. X    if (!str || !pat1 && !pat2)
  686. X    return FALSE;
  687. X    (void) sprintf(buf, "%s%s", pat1? pat1 : "", pat2? pat2 : "");
  688. X    return glob(str, buf);
  689. X}
  690. X
  691. X/*
  692. X * The basic globbing matcher.
  693. X *
  694. X * "*"           = match 0 or more occurances of anything
  695. X * "[abc]"       = match any of "abc" (ranges supported)
  696. X * "{xx,yy,...}" = match any of "xx", "yy", ... where
  697. X *                 "xx", "yy" can be any pattern or empty
  698. X * "?"           = match any character
  699. X */
  700. Xglob(str, pat)
  701. Xchar *str, *pat;
  702. X{
  703. X    int done = FALSE, ret = FALSE;
  704. X
  705. X    if (!str || !pat)
  706. X    return FALSE;
  707. X
  708. X    while (*pat && !done && (*str || (*pat == '{' || *pat == '*'))) /*}*/ {
  709. X    /*
  710. X     * First look for a literal match, stepping over backslashes
  711. X     * in the pattern to match against the "protected" character.
  712. X     * Ordering and precendence are important in this expression!
  713. X     */
  714. X    if (*pat == '\\' && *str == *++pat || *str == *pat) {
  715. X        str++;
  716. X        pat++;
  717. X    } else switch (*pat++) {
  718. X        case '*':    /* Match any string */
  719. X        if (!*pat) {
  720. X            while (*str)
  721. X            str++;
  722. X            break;
  723. X        }
  724. X        /*
  725. X         * Try the rest of the glob against every
  726. X         * possible suffix of the string.  A bit
  727. X         * inefficient in cases that eventually fail.
  728. X         */
  729. X        while (*str && !(ret = glob(str++, pat)))
  730. X            ;
  731. X        return ret;
  732. X        break;
  733. X        case '[':    /* Match a set */
  734. X        repeat:
  735. X        /* If we've hit the end of the set, give up. */
  736. X        if (!*pat || *pat == ']' || *pat == '\\' && !*++pat) {
  737. X            done = TRUE;
  738. X            break;
  739. X        }
  740. X        /* Check for a range. */
  741. X        if (*(pat + 1) == '-') {
  742. X            char c = *pat++;
  743. X            /* We don't handle open-ended ranges. */
  744. X            if (*++pat == ']' || *pat == '\\' && !*++pat) {
  745. X            done = TRUE;
  746. X            break;
  747. X            }
  748. X            if (*str < c || *str > *pat) {
  749. X            pat++;
  750. X            goto repeat;
  751. X            }
  752. X        } else if (*pat != *str) {
  753. X            pat++;
  754. X            goto repeat;
  755. X        }
  756. X        /*
  757. X         * We matched either the range or a literal member of
  758. X         * the set.  Skip to the end of the set.
  759. X         */
  760. X        pat++;
  761. X        while (*pat && *pat != ']')
  762. X            if (*pat++ == '\\' && *pat)
  763. X            pat++;
  764. X        /*
  765. X         * If no pattern remains, the set was never closed,
  766. X         * so don't increment.  This will cause a FALSE return.
  767. X         */
  768. X        if (*pat) {
  769. X            pat++;
  770. X            str++;
  771. X        }
  772. X        break;
  773. X        case '?':    /* Match any one character */
  774. X        str++;
  775. X        break;
  776. X        case '{':    /* } Match any of a set of patterns */
  777. X        return sglob(str, pat - 1, TRPL_NULL);
  778. X        break;
  779. X        default:
  780. X        done = TRUE;
  781. X    }
  782. X    }
  783. X    while (*pat == '*')
  784. X    pat++;
  785. X    return ((*str == '\0') && (*pat == '\0'));
  786. X}
  787. X
  788. X/*
  789. X * Match a pattern set {s1,s2,...} followed by any other pattern.
  790. X * Pattern sets and other patterns may nest arbitrarily.
  791. X *
  792. X * If "mat" is not a null pointer, a vector of possible expansions
  793. X * is generated and placed in *mat; otherwise, the expansions are
  794. X * matched against str and a truth value is returned ("/" is NOT
  795. X * treated as a directory separator in this case).  NOTE: The vector
  796. X * of expansions may still contain nested pattern sets, which must
  797. X * be expanded separately.  See sxp().
  798. X *
  799. X * Currently allows at most 256 alternatives per set.  Enough? :-)
  800. X */
  801. Xstatic
  802. Xsglob(str, pat, mat)
  803. Xchar *str, *pat, ***mat;
  804. X{
  805. X    char *p, *newpat[256], *oldpat[256], buf[MAXPATHLEN], *b = buf;
  806. X    int copy = 1, nest = 0, i = 0, ret = 0;
  807. X
  808. X    if (!pat)
  809. X    return FALSE;
  810. X
  811. X    while (*pat) {
  812. X    if (copy)
  813. X        if (*pat != '{') /*}*/ {
  814. X        if (*pat == '\\' && pat[1])
  815. X            *b++ = *pat++;
  816. X        *b++ = *pat++;
  817. X        continue;
  818. X        } else {
  819. X        copy = 0;
  820. X        pat++;
  821. X        }
  822. X    p = pat;
  823. X    while (*pat && (nest || *pat != ',' && /*{*/ *pat != '}')) {
  824. X        if (*pat == '\\')
  825. X        pat++;
  826. X        else if (*pat == '{')
  827. X        nest++;
  828. X        else if (*pat == '}')
  829. X        nest--;
  830. X        if (*pat)
  831. X        pat++;
  832. X    }
  833. X    if (*pat) {
  834. X        oldpat[i] = pat;
  835. X        newpat[i++] = p;
  836. X        if (*pat != ',') {
  837. X        *pat++ = 0;
  838. X        break;
  839. X        } else
  840. X        *pat++ = 0;
  841. X    }
  842. X    }
  843. X    oldpat[i] = NULL;
  844. X    if (i > 0 && mat) {
  845. X    *mat = (char **)malloc((unsigned)((i + 1) * sizeof(char *)));
  846. X    if (*mat)
  847. X        (*mat)[i] = NULL;
  848. X    else
  849. X        return -1;
  850. X    ret = i;
  851. X    }
  852. X    while (!mat && i-- > 0)
  853. X    if (ret = glob2(str, newpat[i], pat))
  854. X        break;
  855. X    for (i = 0; oldpat[i]; i++) {
  856. X    if (mat && *mat) {
  857. X        (void) sprintf(b, "%s%s", newpat[i], pat);
  858. X        (*mat)[i] = savestr(buf);
  859. X    }
  860. X    if (oldpat[i + 1])
  861. X        oldpat[i][0] = ',';
  862. X    else
  863. X        oldpat[i][0] = /*{*/ '}';
  864. X    }
  865. X    if (ret == 0 && b > buf && mat) {
  866. X    *b = 0;
  867. X    ret = ((*mat = unitv(buf)) ? 1 : -1);
  868. X    }
  869. X    return ret;
  870. X}
  871. X
  872. X/*
  873. X * Pre-expand pattern set notations so sets containing "/" separators
  874. X * can be globbed successfully.  Returns the number of expansions.
  875. X */
  876. Xsxp(pat, exp)
  877. Xchar *pat, ***exp;
  878. X{
  879. X    char **t1 = DUBL_NULL, **t2;
  880. X    int n, new, cnt = 0;
  881. X
  882. X    if ((n = sglob(NULL, pat, &t1)) < 2) {
  883. X    *exp = t1;
  884. X    return n;
  885. X    }
  886. X    *exp = DUBL_NULL;
  887. X    while (n-- && cnt >= 0) {
  888. X    new = sxp(t1[n], &t2);
  889. X    cnt = catv(cnt, exp, new, t2);
  890. X    }
  891. X    xfree(t1);
  892. X    return cnt;
  893. X}
  894. X
  895. X/*
  896. X * Generate the "glob difference" of two vectors (*argvp and patv).
  897. X * The "glob difference" means to remove all strings from argv that
  898. X * match any of the glob patterns in patv.
  899. X *
  900. X * Returns the number of strings remaining in *argvp.  The strings "removed"
  901. X * from argv are actually left at the end of *argvp, so they can still be
  902. X * accessed; their number will of course be argc - (returned value).
  903. X */
  904. Xgdiffv(argc, argvp, patc, patv)
  905. Xint argc, patc;
  906. Xchar ***argvp, **patv;
  907. X{
  908. X    char **argv, *t;
  909. X    int ac, pc, oldac = argc;
  910. X
  911. X    if (argc < 1 || patc < 1 || !patv || !*patv)
  912. X    return argc;
  913. X    if (!argvp || !(argv = *argvp) || !*argv)
  914. X    return -1;
  915. X    for (ac = 0; ac < argc && argv[ac]; ac++) {
  916. X    for (pc = 0; ac < argc && pc < patc && patv[pc]; pc++) {
  917. X        /*
  918. X         * We shouldn't cross '/' characters, so test
  919. X         * only the "tail" of each element of argv.
  920. X         */
  921. X        if (!(t = rindex(argv[ac], '/')))
  922. X            t = argv[ac];
  923. X        if (glob(t, patv[pc])) {
  924. X        /* Move matches to the end and reduce argc */
  925. X        t = argv[ac];
  926. X        argv[ac] = argv[--argc];
  927. X        argv[argc] = t;
  928. X        /* Start patterns over on the new string */
  929. X        pc = -1; /* It'll be incremented to 0 */
  930. X        }
  931. X    }
  932. X    }
  933. X    /*
  934. X     * Sort the two parts of the argv.  uniqcmp() works here only if
  935. X     * there already are no duplicates, but we assume that for now.
  936. X     */
  937. X    if (argc)
  938. X    qsort((char *)argv, argc, sizeof(char *), uniqcmp);
  939. X    if (oldac > argc)
  940. X    qsort((char *)&argv[argc], oldac - argc, sizeof(char *), uniqcmp);
  941. X    return argc;
  942. X}
  943. X
  944. X/*
  945. X * Generate the longest common prefix from all strings in a vector
  946. X * If "skip" is nonzero, that many chars are assumed to be in common
  947. X * and are not tested.  WARNING: skip must be <= than the length of
  948. X * the shortest string in the vector!  Safest to call with skip = 0.
  949. X *
  950. X * Returns the length of the longest common prefix.
  951. X */
  952. Xlcprefix(vec, skip)
  953. Xchar **vec;
  954. Xint skip;
  955. X{
  956. X    char c, **v;
  957. X    int done = FALSE;
  958. X
  959. X    if (!vec || !*vec || skip < 0)
  960. X    return 0;
  961. X    do {
  962. X    for (v = vec + 1, c = vec[0][skip]; c && *v; v++)
  963. X        if (v[0][skip] != c) {
  964. X        done = TRUE;
  965. X        break;
  966. X        }
  967. X    } while (!done && c && ++skip);
  968. X    return skip;
  969. X}
  970. X
  971. X#define MAXCOLS 8    /* Max number of columns of words to make */
  972. X#define MINWIDTH 10    /* Minimum width of each column of words */
  973. X#ifdef CURSES
  974. X#define MAXWIDTH (iscurses? COLS : 80)
  975. X#else /* CURSES */
  976. X#define MAXWIDTH 80    /* Maximum width of all columns */
  977. X#endif /* CURSES */
  978. X
  979. X/*
  980. X * Print a vector in columns
  981. X *
  982. X * If "skip" is nonzero, that many chars are assumed to be in common
  983. X * and are not printed.  WARNING: skip must be <= than the length of
  984. X * the shortest string in the vector!  Safest to call with skip = 0.
  985. X */
  986. Xcolumnate(argc, argv, skip)
  987. Xint argc;
  988. Xchar **argv;
  989. Xint skip;
  990. X{
  991. X    int colstep, colwidth[MAXCOLS + 1];
  992. X    int maxcols = min(argc, MAXCOLS);
  993. X    int minwidth, maxwidth, *widths;
  994. X    int maxword = 0, n, c;
  995. X
  996. X    if (argc <= 0 || !argv || !*argv)
  997. X    return -1;
  998. X    if (!(widths = (int *)malloc((unsigned)((argc + 1) * sizeof(int)))))
  999. X    return -1;
  1000. X
  1001. X    /*
  1002. X     * Compute the widths of all words in the vector, and
  1003. X     * remember the maximum width and which word had it.
  1004. X     * Also remember the minimum width.
  1005. X     */
  1006. X    for (minwidth = MAXWIDTH, maxwidth = n = 0; n < argc; n++) {
  1007. X    widths[n] = max(strlen(argv[n] + skip) + 2, MINWIDTH);
  1008. X    if (widths[n] > MAXWIDTH - MINWIDTH)
  1009. X        break;
  1010. X    if (widths[n] > maxwidth) {
  1011. X        maxwidth = widths[n];
  1012. X        maxword = n;
  1013. X    } 
  1014. X    if (widths[n] < minwidth)
  1015. X        minwidth = widths[n];
  1016. X    }
  1017. X
  1018. X    for (; maxcols > 0; maxcols--) {
  1019. X    if (argc % maxcols)
  1020. X        colstep = argc / maxcols + 1;
  1021. X    else
  1022. X        colstep = argc / maxcols;
  1023. X    colwidth[MAXCOLS] = 0;
  1024. X    for (c = 0; c < maxcols; c++) {
  1025. X        colwidth[c] = 0;
  1026. X        for (n = c * colstep; n < (c + 1) * colstep && n < argc; n++)
  1027. X        colwidth[c] = max(colwidth[c], widths[n]);
  1028. X        colwidth[MAXCOLS] += colwidth[c];
  1029. X    }
  1030. X    if (colwidth[MAXCOLS] <= MAXWIDTH)
  1031. X        break;
  1032. X    }
  1033. X    xfree(widths);
  1034. X
  1035. X    if (maxcols < 2 && minwidth <= MAXWIDTH / 2) {
  1036. X    /*
  1037. X     * The maxword fills too much screen, so redo everything
  1038. X     * above it, print maxword, then do everything below it.
  1039. X     */
  1040. X    if (maxword > 0 && columnate(maxword, argv, skip) < 0)
  1041. X        return -1;
  1042. X    wprint("%s\n", argv[maxword] + skip);
  1043. X    if (argc - maxword < 2)
  1044. X        return 0;
  1045. X    return columnate(argc - maxword - 1, &argv[maxword + 1], skip);
  1046. X    }
  1047. X
  1048. X    for (n = 0; n < colstep; n++) {
  1049. X    for (c = 0; c < maxcols && n + c * colstep < argc - colstep; c++)
  1050. X        wprint("%-*.*s", colwidth[c], colwidth[c],
  1051. X                        argv[n + c * colstep] + skip);
  1052. X    wprint("%s\n", argv[n + c * colstep] + skip);
  1053. X    }
  1054. X
  1055. X    return 0;
  1056. X}
  1057. X
  1058. X#ifndef DIRECTORY
  1059. X
  1060. X#undef NULL
  1061. X#define NULL 0
  1062. X
  1063. X/*
  1064. X *  4.2BSD directory access emulation for non-4.2 systems.
  1065. X *  Based upon routines in appendix D of Portable C and Unix System
  1066. X *  Programming by J. E. Lapin (Rabbit Software).
  1067. X *
  1068. X *  No responsibility is taken for any error in accuracies inherent
  1069. X *  either to the comments or the code of this program, but if
  1070. X *  reported to me then an attempt will be made to fix them.
  1071. X */
  1072. X
  1073. X/*  Support for Berkeley directory reading routines on a V7/SysV file
  1074. X *  system.
  1075. X */
  1076. X
  1077. X/*  Open a directory. */
  1078. X
  1079. XDIR *
  1080. Xopendir(name)
  1081. Xchar *name ;
  1082. X{
  1083. X  register DIR *dirp ;
  1084. X  register int fd ;
  1085. X
  1086. X  if ((fd = open(name, 0)) == -1) return NULL ;
  1087. X  if ((dirp = (DIR *) malloc(sizeof(DIR))) == NULL)
  1088. X    {
  1089. X      close(fd) ;
  1090. X      return NULL ;
  1091. X    }
  1092. X  dirp->dd_fd = fd ;
  1093. X  dirp->dd_loc = 0 ;
  1094. X  return dirp ;
  1095. X}
  1096. X
  1097. X
  1098. X/*  Read an old style directory entry and present it as a new one. */
  1099. X
  1100. X#define  ODIRSIZ  14
  1101. X
  1102. Xstruct olddirent
  1103. X{
  1104. X  short  od_ino ;
  1105. X  char   od_name[ODIRSIZ] ;
  1106. X} ;
  1107. X
  1108. X
  1109. X/*  Get next entry in a directory. */
  1110. X
  1111. Xstruct dirent *
  1112. Xreaddir(dirp)
  1113. Xregister DIR *dirp ;
  1114. X{
  1115. X  register struct olddirent *dp ;
  1116. X  static struct dirent dir ;
  1117. X
  1118. X  for (;;)
  1119. X    {
  1120. X      if (dirp->dd_loc == 0)
  1121. X        {
  1122. X          dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ) ;
  1123. X          if (dirp->dd_size <= 0) return NULL ;
  1124. X        }
  1125. X      if (dirp->dd_loc >= dirp->dd_size)
  1126. X        {
  1127. X          dirp->dd_loc = 0 ;
  1128. X          continue ;
  1129. X        }
  1130. X
  1131. X      dp = (struct olddirent *)(dirp->dd_buf + dirp->dd_loc) ;
  1132. X      dirp->dd_loc += sizeof(struct olddirent) ;
  1133. X
  1134. X      if (dp->od_ino == 0) continue ;
  1135. X
  1136. X      dir.d_fileno = dp->od_ino ;
  1137. X      strncpy(dir.d_name, dp->od_name, ODIRSIZ) ;
  1138. X      dir.d_name[ODIRSIZ] = '\0' ;       /* Ensure termination. */
  1139. X      dir.d_namlen = strlen(dir.d_name) ;
  1140. X      dir.d_reclen = DIRSIZ(&dir) ;
  1141. X      return(&dir) ;
  1142. X    }
  1143. X}
  1144. X
  1145. X
  1146. X/*  Close a directory. */
  1147. X
  1148. Xvoid
  1149. Xclosedir(dirp)
  1150. Xregister DIR *dirp ;
  1151. X{
  1152. X  close(dirp->dd_fd) ;
  1153. X  dirp->dd_fd = -1 ;
  1154. X  dirp->dd_loc = 0 ;
  1155. X  xfree(dirp) ;
  1156. X} 
  1157. X
  1158. X#endif /* DIRECTORY */
  1159. END_OF_FILE
  1160. if test 19617 -ne `wc -c <'mush/glob.c'`; then
  1161.     echo shar: \"'mush/glob.c'\" unpacked with wrong size!
  1162. fi
  1163. # end of 'mush/glob.c'
  1164. fi
  1165. if test -f 'mush/options.h' -a "${1}" != "-c" ; then 
  1166.   echo shar: Will not clobber existing file \"'mush/options.h'\"
  1167. else
  1168. echo shar: Extracting \"'mush/options.h'\" \(1248 characters\)
  1169. sed "s/^X//" >'mush/options.h' <<'END_OF_FILE'
  1170. X/* @(#)options.h    (c) copyright 10/10/88 (Dan Heller, Bart Schaefer) */
  1171. X
  1172. X/* Must #include mush.h before #including this file */
  1173. X
  1174. X/* Structure to hold assorted information collected from command line flags.  
  1175. X *  Other information is held in the following global variables:
  1176. X *    cmd_help    General help file, specified by -1
  1177. X *    debug        Debugging mode, toggled by -d
  1178. X *    glob_flags    Bits set by -C, -e, -i, -S, -t and many commands
  1179. X *    hdrs_only    Show headers and exit, specified by -H
  1180. X *    iscurses    Curses mode, specified by -C or "curses" command
  1181. X *    istool        Tool mode, specified by -t or -T
  1182. X *    mailfile    File specified by -u or -f or "folder" command
  1183. X *    prog_name    Name under which mush is running
  1184. X *    time_out    Tool mode timeout, specified by -T
  1185. X *    tool_help    Tool mode help file, specified by -2
  1186. X */
  1187. X
  1188. Xstruct mush_flags {
  1189. X    u_long flg;        /* Set by -v, -h, -U, vars */
  1190. X    char *init_file;    /* Set by -I or -I! */
  1191. X    char *src_file;    /* Set by -F */
  1192. X    int src_n_exit;    /* Set by -F! */
  1193. X    char *folder;    /* Set by -f or -u */
  1194. X    char *draft;    /* Set by -h */
  1195. X    char f_flags[10];    /* Set by -r, -N, etc.; passed to folder() */
  1196. X    char *Subj;        /* Set by -s */
  1197. X    char *Cc;        /* Set by -c */
  1198. X    char *Bcc;        /* Set by -b */
  1199. X    int source_rc;    /* Set by -n */
  1200. X};
  1201. END_OF_FILE
  1202. if test 1248 -ne `wc -c <'mush/options.h'`; then
  1203.     echo shar: \"'mush/options.h'\" unpacked with wrong size!
  1204. fi
  1205. # end of 'mush/options.h'
  1206. fi
  1207. if test -f 'mush/panels.c' -a "${1}" != "-c" ; then 
  1208.   echo shar: Will not clobber existing file \"'mush/panels.c'\"
  1209. else
  1210. echo shar: Extracting \"'mush/panels.c'\" \(15200 characters\)
  1211. sed "s/^X//" >'mush/panels.c' <<'END_OF_FILE'
  1212. X/* @(#)panel.c    (c) copyright    10/18/86 (Dan Heller) */
  1213. X/* @(#)panels.c    (c) copyright    9/29/89 (Dan Heller) */
  1214. X
  1215. X#include "mush.h"
  1216. X/* mouse symbols */
  1217. Xshort dat_mouse_left[] = {
  1218. X    0x1FF8, 0x3FFC, 0x336C, 0x336C, 0x336C, 0x336C, 0x336C, 0x336C, 
  1219. X    0x3FFC, 0x3FFC, 0x3FFC, 0x3FFC, 0x3FFC, 0x3FC4, 0x3FFC, 0x1FF8
  1220. X};
  1221. X
  1222. Xshort dat_mouse_middle[] = {
  1223. X    0x1FF8, 0x3FFC, 0x366C, 0x366C, 0x366C, 0x366C, 0x366C, 0x366C, 
  1224. X    0x3FFC, 0x3FFC, 0x3FFC, 0x3FFC, 0x3FFC, 0x3FC4, 0x3FFC, 0x1FF8
  1225. X};
  1226. X
  1227. Xshort dat_mouse_right[] = {
  1228. X    0x1FF8, 0x3FFC, 0x36CC, 0x36CC, 0x36CC, 0x36CC, 0x36CC, 0x36CC, 
  1229. X    0x3FFC, 0x3FFC, 0x3FFC, 0x3FFC, 0x3FFC, 0x3FC4, 0x3FFC, 0x1FF8
  1230. X};
  1231. X
  1232. Xmpr_static(mouse_left,      16, 16, 1, dat_mouse_left);
  1233. Xmpr_static(mouse_middle,    16, 16, 1, dat_mouse_middle);
  1234. Xmpr_static(mouse_right,     16, 16, 1, dat_mouse_right);
  1235. X
  1236. XPanel_item
  1237. X    folder_item,    /* change folders */
  1238. X    folder_text_item,    /* text item for the folder item */
  1239. X    file_item,         /* text item for the save item */
  1240. X    msg_num_item,    /* text item explicitly states which message to read */
  1241. X    read_item,        /* read the current message */
  1242. X    save_item,        /* saves messages */
  1243. X    sub_hdr_item[6];    /* display items that just sit there and give help */
  1244. X
  1245. X/* These global panel items for letter composition should eventually go away */
  1246. XPanel_item
  1247. X    edit_item,        /* edit a message */
  1248. X    reply_item;        /* reply button -- also called from hdr_sw menu */
  1249. X
  1250. Xextern void
  1251. X    close_frame(), do_options(), do_compose(), do_send(), do_sort(),
  1252. X    do_edit(), delete_mail(), respond_mail(), do_help(), do_lpr(),
  1253. X    do_update(), abort_mail(), do_include(), load_from_file(),
  1254. X    save_to_file(), tilde_from_menu(), fkey_interposer();
  1255. X
  1256. Xextern Panel_setting
  1257. X    msg_num_done(), file_dir();
  1258. X
  1259. XPanel
  1260. Xmake_hdr_panel(parent, choice_args, button_args)
  1261. XFrame parent;
  1262. Xchar **choice_args, **button_args;
  1263. X{
  1264. X    Panel panel = window_create(parent, PANEL,
  1265. X    WIN_CONSUME_KBD_EVENTS,
  1266. X        WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS, NULL,
  1267. X    NULL);
  1268. X    (void) notify_interpose_event_func(panel, fkey_interposer, NOTIFY_SAFE);
  1269. X
  1270. X    (void) panel_create_item(panel, PANEL_CHOICE,
  1271. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1272. X    PANEL_LABEL_IMAGE,
  1273. X        panel_button_image(panel, "Done", 4, mush_font),
  1274. X    PANEL_CHOICE_STRINGS,
  1275. X        "Close to Icon", "Quit Tool", "Help", NULL,
  1276. X    PANEL_NOTIFY_PROC,         toolquit,
  1277. X    NULL);
  1278. X
  1279. X    (void) panel_create_item(panel, PANEL_CHOICE,
  1280. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1281. X    PANEL_LABEL_IMAGE,
  1282. X        panel_button_image(panel, "Help", 4, mush_font),
  1283. X    PANEL_CHOICE_STRINGS,
  1284. X        "General", "Help with \"help\"", "The Mouse", "Windows",
  1285. X        "Message headers", "Message lists", "Folders", NULL,
  1286. X    PANEL_NOTIFY_PROC,         do_help,
  1287. X    NULL);
  1288. X
  1289. X    folder_item = panel_create_item(panel, PANEL_CHOICE,
  1290. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1291. X    PANEL_LABEL_IMAGE,
  1292. X        panel_button_image(panel, "Folder", 6, mush_font),
  1293. X    PANEL_CHOICE_STRINGS,
  1294. X        "System Mailbox", "Main Mailbox", "Last Accessed Folder", NULL,
  1295. X    PANEL_NOTIFY_PROC,         do_file_dir,
  1296. X    NULL);
  1297. X
  1298. X    add_folder_to_menu(folder_item, 3);
  1299. X
  1300. X    folder_text_item = panel_create_item(panel, PANEL_TEXT,
  1301. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1302. X    PANEL_LABEL_FONT,         mush_font,
  1303. X    PANEL_LABEL_STRING,        "Filename:",
  1304. X    PANEL_VALUE_DISPLAY_LENGTH,     28,
  1305. X    PANEL_NOTIFY_STRING,         "\n\r\033",
  1306. X    PANEL_NOTIFY_PROC,         file_dir,
  1307. X    NULL);
  1308. X
  1309. X    (void) panel_create_item(panel, PANEL_CHOICE,
  1310. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1311. X    PANEL_LABEL_IMAGE,
  1312. X        panel_button_image(panel, "Update", 6, mush_font),
  1313. X    PANEL_CHOICE_STRINGS,         "New Mail", "Help", NULL,
  1314. X    PANEL_NOTIFY_PROC,         do_update,
  1315. X    NULL);
  1316. X
  1317. X    (void) panel_create_item(panel, PANEL_CHOICE,
  1318. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1319. X    PANEL_LABEL_IMAGE,
  1320. X        panel_button_image(panel, "Options", 7, mush_font),
  1321. X    PANEL_CHOICE_STRINGS,        "Variables", "Headers", "Aliases", NULL,
  1322. X    PANEL_NOTIFY_PROC,         do_options,
  1323. X    NULL);
  1324. X
  1325. X    msg_num_item = panel_create_item(panel, PANEL_TEXT,
  1326. X    PANEL_ATTRIBUTE_LIST,        choice_args,
  1327. X    PANEL_LABEL_STRING,        "Range:",
  1328. X    PANEL_MENU_CHOICE_STRINGS,     "Help", NULL,
  1329. X    PANEL_VALUE_DISPLAY_LENGTH,     17,
  1330. X    PANEL_VALUE_STORED_LENGTH,     80,
  1331. X    PANEL_LABEL_FONT,         mush_font,
  1332. X    PANEL_NOTIFY_STRING,         "\n\r",
  1333. X    PANEL_NOTIFY_PROC,         msg_num_done,
  1334. X    NULL);
  1335. X
  1336. X    sub_hdr_item[0] = panel_create_item(panel, PANEL_CHOICE,
  1337. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1338. X    PANEL_LABEL_IMAGE,            &mouse_left,
  1339. X    PANEL_CHOICE_STRINGS,         "Help", NULL,
  1340. X    PANEL_NOTIFY_PROC,            read_mail,
  1341. X    NULL);
  1342. X    sub_hdr_item[1] = panel_create_item(panel, PANEL_CHOICE,
  1343. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1344. X    PANEL_LABEL_STRING,           "Read ",
  1345. X    PANEL_MENU_TITLE_IMAGE,     &mouse_left,
  1346. X    PANEL_CHOICE_STRINGS,        "Help", NULL,
  1347. X    PANEL_NOTIFY_PROC,            read_mail,
  1348. X    NULL);
  1349. X    sub_hdr_item[2] = panel_create_item(panel, PANEL_CHOICE,
  1350. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1351. X    PANEL_LABEL_IMAGE,            &mouse_middle,
  1352. X    PANEL_CHOICE_STRINGS,         "Help", NULL,
  1353. X    PANEL_NOTIFY_PROC,            delete_mail,
  1354. X    NULL);
  1355. X    sub_hdr_item[3] = panel_create_item(panel, PANEL_CHOICE,
  1356. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1357. X    PANEL_LABEL_STRING,           "Delete ",
  1358. X    PANEL_MENU_TITLE_IMAGE,     &mouse_middle,
  1359. X    PANEL_CHOICE_STRINGS,         "Help", NULL,
  1360. X    PANEL_NOTIFY_PROC,            delete_mail,
  1361. X    NULL);
  1362. X    sub_hdr_item[4] = panel_create_item(panel, PANEL_CHOICE,
  1363. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1364. X    PANEL_LABEL_IMAGE,            &mouse_right,
  1365. X    PANEL_CHOICE_STRINGS,         "Help", NULL,
  1366. X    PANEL_NOTIFY_PROC,            read_mail,
  1367. X    NULL);
  1368. X    sub_hdr_item[5] = panel_create_item(panel, PANEL_CHOICE,
  1369. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1370. X    PANEL_LABEL_STRING,           "Menu         ",
  1371. X    PANEL_MENU_TITLE_IMAGE,            &mouse_right,
  1372. X    PANEL_CHOICE_STRINGS,         "Help", NULL,
  1373. X    PANEL_NOTIFY_PROC,            read_mail,
  1374. X    NULL);
  1375. X
  1376. X    (void) panel_create_item(panel, PANEL_CHOICE,
  1377. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1378. X    PANEL_LABEL_IMAGE,
  1379. X        panel_button_image(panel, "Printer", 7, mush_font),
  1380. X    PANEL_CHOICE_STRINGS,         "Help", NULL,
  1381. X    PANEL_NOTIFY_PROC,         do_lpr,
  1382. X    NULL);
  1383. X
  1384. X    (void) panel_create_item(panel, PANEL_CHOICE,
  1385. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1386. X    PANEL_LABEL_IMAGE,
  1387. X        panel_button_image(panel, "Sort", 4, mush_font),
  1388. X    PANEL_CHOICE_STRINGS,
  1389. X        "By Date", "By Author", "By Size", "By Subject",
  1390. X        "By Subject (ignore Re:)", "By Status", "Help", NULL,
  1391. X    PANEL_NOTIFY_PROC,         do_sort,
  1392. X    NULL);
  1393. X
  1394. X    window_fit_height(panel);
  1395. X    return panel;
  1396. X}
  1397. X
  1398. XPanel
  1399. Xmake_main_panel(parent, choice_args, button_args)
  1400. XFrame parent;
  1401. Xchar **choice_args, **button_args;
  1402. X{
  1403. X    /* main panel stuff: */
  1404. X    Panel panel = window_create(parent, PANEL,
  1405. X    WIN_CONSUME_KBD_EVENTS,
  1406. X        WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS, NULL,
  1407. X    NULL);
  1408. X    (void) notify_interpose_event_func(panel, fkey_interposer, NOTIFY_SAFE);
  1409. X
  1410. X    read_item = panel_create_item(panel, PANEL_CHOICE,
  1411. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1412. X    PANEL_LABEL_IMAGE,
  1413. X        panel_button_image(panel, "Next", 4, mush_font),
  1414. X    PANEL_CHOICE_STRINGS,         "Help", NULL,
  1415. X    PANEL_NOTIFY_PROC,         read_mail,
  1416. X    NULL);
  1417. X
  1418. X    (void) panel_create_item(panel, PANEL_CHOICE,
  1419. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1420. X    PANEL_LABEL_IMAGE,
  1421. X        panel_button_image(panel, "Delete", 6, mush_font),
  1422. X    PANEL_CHOICE_STRINGS,         "Delete",
  1423. X                    "Undelete",
  1424. X                    "Help", NULL,
  1425. X    PANEL_NOTIFY_PROC,         delete_mail,
  1426. X    NULL);
  1427. X
  1428. X    {
  1429. X    char *mbox = do_set(set_options, "mbox");
  1430. X    if (!mbox || !*mbox)
  1431. X        mbox = DEF_MBOX;
  1432. X    save_item = panel_create_item(panel, PANEL_CHOICE,
  1433. X        PANEL_ATTRIBUTE_LIST,     choice_args,
  1434. X        PANEL_LABEL_IMAGE, panel_button_image(panel, "Save", 4, mush_font),
  1435. X        PANEL_CHOICE_STRINGS,     trim_filename(mbox), NULL,
  1436. X        PANEL_NOTIFY_PROC,         do_file_dir,
  1437. X        NULL);
  1438. X    }
  1439. X
  1440. X    add_folder_to_menu(save_item, 1);
  1441. X
  1442. X    file_item = panel_create_item(panel, PANEL_TEXT,
  1443. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1444. X    PANEL_LABEL_FONT,         mush_font,
  1445. X    PANEL_SHOW_MENU,        TRUE,
  1446. X    PANEL_LABEL_STRING,         "Filename:",
  1447. X    PANEL_MENU_CHOICE_STRINGS,    "Save message without message header",
  1448. X                    NULL,
  1449. X    PANEL_VALUE_DISPLAY_LENGTH,     28,
  1450. X    PANEL_NOTIFY_STRING,         "\n\r\033",
  1451. X    PANEL_NOTIFY_PROC,         file_dir,
  1452. X    NULL);
  1453. X
  1454. X    (void) panel_create_item(panel, PANEL_CHOICE,
  1455. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1456. X    PANEL_LABEL_IMAGE,
  1457. X        panel_button_image(panel, "Compose", 7, mush_font),
  1458. X    PANEL_CHOICE_STRINGS,         "Help", NULL,
  1459. X    PANEL_NOTIFY_PROC,        do_compose,
  1460. X    NULL);
  1461. X
  1462. X    reply_item = panel_create_item(panel, PANEL_CHOICE,
  1463. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1464. X    PANEL_LABEL_IMAGE,
  1465. X        panel_button_image(panel, "Reply", 5, mush_font),
  1466. X    PANEL_CHOICE_STRINGS,
  1467. X        "Sender Only", "Sender Only (include msg)",
  1468. X        "All Recipients", "All Recipients (include msg)", "Help", NULL,
  1469. X    PANEL_NOTIFY_PROC,         respond_mail,
  1470. X    NULL);
  1471. X
  1472. X    window_fit_height(panel);
  1473. X    return panel;
  1474. X}
  1475. X
  1476. XPanel
  1477. Xmake_compose_panel(parent, choice_args, button_args)
  1478. XFrame parent;
  1479. Xchar **choice_args, **button_args;
  1480. X{
  1481. X    Panel panel = window_create(parent, PANEL, NULL);
  1482. X    Panel_item filename_item, fortune_item, sign_item, send_item;
  1483. X
  1484. X    (void) notify_interpose_event_func(panel, fkey_interposer, NOTIFY_SAFE);
  1485. X
  1486. X    (void) panel_create_item(panel, PANEL_BUTTON,
  1487. X    PANEL_ATTRIBUTE_LIST,         button_args,
  1488. X    PANEL_LABEL_IMAGE,
  1489. X        panel_button_image(panel, "Close", 5, mush_font),
  1490. X    PANEL_NOTIFY_PROC,         close_frame,
  1491. X    NULL);
  1492. X
  1493. X    (void) panel_create_item(panel, PANEL_CHOICE,
  1494. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1495. X    PANEL_LABEL_IMAGE,
  1496. X        panel_button_image(panel, "Compose", 7, mush_font),
  1497. X    PANEL_CHOICE_STRINGS,         "Help", NULL,
  1498. X    PANEL_NOTIFY_PROC,         do_compose,
  1499. X    NULL);
  1500. X
  1501. X    send_item = panel_create_item(panel, PANEL_BUTTON,
  1502. X    PANEL_ATTRIBUTE_LIST,         button_args,
  1503. X    PANEL_SHOW_ITEM,         FALSE,
  1504. X    PANEL_LABEL_IMAGE,
  1505. X        panel_button_image(panel, "Send", 4, mush_font),
  1506. X    PANEL_NOTIFY_PROC,         do_send,
  1507. X    NULL);
  1508. X
  1509. X    (void) panel_create_item(panel, PANEL_BUTTON,
  1510. X    PANEL_ATTRIBUTE_LIST,         button_args,
  1511. X    PANEL_SHOW_ITEM,        FALSE,
  1512. X    PANEL_LABEL_IMAGE,
  1513. X        panel_button_image(panel, "Abort", 5, mush_font),
  1514. X    PANEL_NOTIFY_PROC,         abort_mail,
  1515. X    NULL);
  1516. X
  1517. X    (void) panel_create_item(panel, PANEL_CHOICE,
  1518. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1519. X    PANEL_SHOW_ITEM,         FALSE,
  1520. X    PANEL_LABEL_IMAGE,
  1521. X        panel_button_image(panel, "Include", 7, mush_font),
  1522. X    PANEL_CHOICE_STRINGS,         "Include Message",
  1523. X                    "Forward Message",
  1524. X                    "Help", NULL,
  1525. X    PANEL_NOTIFY_PROC,         do_include,
  1526. X    NULL);
  1527. X
  1528. X    edit_item = panel_create_item(panel, PANEL_BUTTON,
  1529. X    PANEL_ATTRIBUTE_LIST,         button_args,
  1530. X    PANEL_SHOW_ITEM,         FALSE,
  1531. X    PANEL_LABEL_IMAGE,
  1532. X        panel_button_image(panel, "Edit", 4, mush_font),
  1533. X    PANEL_NOTIFY_PROC,         do_edit,
  1534. X    NULL);
  1535. X
  1536. X    (void) panel_create_item(panel, PANEL_CHOICE,
  1537. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1538. X    PANEL_SHOW_ITEM,        FALSE,
  1539. X    PANEL_LABEL_IMAGE,
  1540. X        panel_button_image(panel, "Headers", 7, mush_font),
  1541. X    PANEL_CHOICE_STRINGS,    
  1542. X        "ALL      ~h", "To:      ~t", "Subject: ~s",
  1543. X        "Cc:      ~c", "Bcc:     ~b", "Fcc:", NULL,
  1544. X    PANEL_NOTIFY_PROC,        tilde_from_menu,
  1545. X    NULL);
  1546. X
  1547. X    sign_item = panel_create_item(panel, PANEL_CHOICE,
  1548. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1549. X    PANEL_DISPLAY_LEVEL,        PANEL_ALL,
  1550. X    PANEL_SHOW_MENU_MARK,        TRUE,
  1551. X    PANEL_SHOW_ITEM,         FALSE,
  1552. X    PANEL_LABEL_STRING,        "Autosign:",
  1553. X    PANEL_CHOICE_STRINGS,        "Off", "On", NULL,
  1554. X    NULL);
  1555. X    panel_set_value(sign_item, !!do_set(set_options, "autosign"));
  1556. X    /* Create a link to avoid global */
  1557. X    panel_set(send_item, PANEL_CLIENT_DATA, sign_item, NULL);
  1558. X
  1559. X    filename_item = panel_create_item(panel, PANEL_TEXT,
  1560. X    PANEL_ATTRIBUTE_LIST,         button_args,
  1561. X    PANEL_SHOW_ITEM,        FALSE,
  1562. X    PANEL_LABEL_STRING,        "Filename:",
  1563. X    PANEL_VALUE_DISPLAY_LENGTH,     30,
  1564. X    PANEL_NOTIFY_STRING,         "\033",
  1565. X    PANEL_NOTIFY_PROC,         file_dir,
  1566. X    NULL);
  1567. X
  1568. X    (void) panel_create_item(panel, PANEL_CHOICE,
  1569. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1570. X    PANEL_SHOW_ITEM,        FALSE,
  1571. X    PANEL_CLIENT_DATA,        filename_item,
  1572. X    PANEL_LABEL_IMAGE,
  1573. X        panel_button_image(panel, "Import", 6, mush_font),
  1574. X    PANEL_CHOICE_STRINGS,        "Insert", "Replace", NULL,
  1575. X    PANEL_NOTIFY_PROC,        load_from_file,
  1576. X    NULL);
  1577. X
  1578. X    (void) panel_create_item(panel, PANEL_BUTTON,
  1579. X    PANEL_ATTRIBUTE_LIST,         button_args,
  1580. X    PANEL_SHOW_ITEM,        FALSE,
  1581. X    PANEL_CLIENT_DATA,        filename_item,
  1582. X    PANEL_LABEL_IMAGE,
  1583. X        panel_button_image(panel, "Export", 6, mush_font),
  1584. X    PANEL_NOTIFY_PROC,        save_to_file,
  1585. X    NULL);
  1586. X
  1587. X    fortune_item = panel_create_item(panel, PANEL_CHOICE,
  1588. X    PANEL_ATTRIBUTE_LIST,         choice_args,
  1589. X    PANEL_DISPLAY_LEVEL,        PANEL_ALL,
  1590. X    PANEL_SHOW_MENU_MARK,        TRUE,
  1591. X    PANEL_SHOW_ITEM,         FALSE,
  1592. X    PANEL_LABEL_STRING,        "Fortune:",
  1593. X    PANEL_CHOICE_STRINGS,        "Off", "On", NULL,
  1594. X    NULL);
  1595. X    panel_set_value(fortune_item, !!do_set(set_options, "fortune"));
  1596. X    /* Create a link to avoid global */
  1597. X    panel_set(sign_item, PANEL_CLIENT_DATA, fortune_item, NULL);
  1598. X
  1599. X    window_fit_height(panel);
  1600. X    return panel;
  1601. X}
  1602. X
  1603. X#include "glob.h"
  1604. X
  1605. X#ifdef WALK_MENUS
  1606. Xfolder_menu_notify(menu, mi)
  1607. XMenu menu;
  1608. XMenu_item mi;
  1609. X{
  1610. X}
  1611. X
  1612. Xstatic Menu_item
  1613. Xadd_path_to_menu(menu, path)
  1614. XMenu menu;
  1615. Xchar *path;
  1616. X{
  1617. X    DIR            *dirp;
  1618. X    struct dirent    *dp;
  1619. X    struct stat     s_buf;
  1620. X    Menu_item        mi;
  1621. X    Menu        next_menu;
  1622. X    char        buf[MAXPATHLEN];
  1623. X
  1624. X    /* don't add a folder to the list if user can't read it */
  1625. X    if (stat(path, &s_buf) == -1 || !(s_buf.st_mode & S_IREAD))
  1626. X    return NULL;
  1627. X    if ((s_buf.st_mode & S_IFMT) == S_IFDIR) {
  1628. X    int cnt = 0;
  1629. X    if (!(dirp = opendir(path)))
  1630. X        return NULL; /* don't bother adding to list if we can't scan it */
  1631. X    next_menu = menu_create(MENU_NOTIFY_PROC, folder_menu_notify, NULL);
  1632. X    while (dp = readdir(dirp))
  1633. X        if (strcmp(dp->d_name, ".") && strcmp(dp->d_name, ".."))
  1634. X        if (mi = add_path_to_menu(next_menu,
  1635. X            sprintf(buf, "%s/%s", path, dp->d_name))) {
  1636. X            menu_set(next_menu, MENU_APPEND_ITEM, mi, NULL);
  1637. X            cnt++;
  1638. X        }
  1639. X    closedir(dirp);
  1640. X    mi = menu_create_item(MENU_STRING, trim_filename(path), NULL);
  1641. X    if (!cnt) {
  1642. X        menu_destroy(next_menu);
  1643. X        menu_set(mi, MENU_INACTIVE, TRUE, NULL);
  1644. X    } else
  1645. X        menu_set(mi, MENU_PULLRIGHT, next_menu, NULL);
  1646. X    return mi;
  1647. X    }
  1648. X    /* we should check that this file is actually a folder */
  1649. X    return menu_create_item(MENU_STRING, trim_filename(path), NULL);
  1650. X}
  1651. X#endif /* WALK_MENUS */
  1652. X
  1653. Xstatic
  1654. Xadd_path_to_menu(item, path, n)
  1655. XPanel_item item;
  1656. Xchar *path;
  1657. Xint *n;
  1658. X{
  1659. X    char        **names, **np;
  1660. X    struct stat     s_buf;
  1661. X    char        buf[MAXPATHLEN];
  1662. X
  1663. X    /* don't add a folder to the list if user can't read it */
  1664. X    if (stat(path, &s_buf) == -1 || !(s_buf.st_mode & S_IREAD))
  1665. X    return;
  1666. X    if ((s_buf.st_mode & S_IFMT) == S_IFDIR) {
  1667. X    sprintf(buf, "%s/{.*,*}", path);
  1668. X    if (filexp(buf, &names) > 0) {
  1669. X        for (np = names; np && *np; np++) {
  1670. X        if (!glob(*np, "*/{.,..}"))
  1671. X            add_path_to_menu(item, *np, n);
  1672. X        }
  1673. X        free_vec(names);
  1674. X    }
  1675. X    } else if (test_folder(path, NULL))
  1676. X    panel_set(item,
  1677. X        PANEL_CHOICE_STRING, (*n)++, savestr(trim_filename(path)),
  1678. X        NULL);
  1679. X}
  1680. X
  1681. X/*
  1682. X * Open the user's mail folder (either user set or default path) and find all
  1683. X * the files (assumed to be mail folders) and add them to the menu list of
  1684. X * folders to use.
  1685. X */
  1686. Xadd_folder_to_menu(item, n)
  1687. XPanel_item item;
  1688. X{
  1689. X    char    *tmp = NULL, *p;
  1690. X#ifdef WALK_MENUS
  1691. X    Menu_item    mi;
  1692. X#endif /* WALK_MENUS */
  1693. X
  1694. X    if (!(p = do_set(set_options, "folder")) || !*p)
  1695. X    p = DEF_FOLDER;
  1696. X    if (p) {
  1697. X    int x = 0;
  1698. X    tmp = getpath(p, &x);
  1699. X    if (x == -1) {
  1700. X        if (errno != ENOENT)
  1701. X        print("%s: %s\n", p, tmp);
  1702. X        tmp = NULL;
  1703. X    }
  1704. X    }
  1705. X    if (tmp) {
  1706. X#ifdef WALK_MENUS
  1707. X    mi = add_path_to_menu(menu, tmp);
  1708. X#else /* WALK_MENUS */
  1709. X    add_path_to_menu(item, tmp, &n);
  1710. X#endif /* WALK_MENUS */
  1711. X    }
  1712. X}
  1713. END_OF_FILE
  1714. if test 15200 -ne `wc -c <'mush/panels.c'`; then
  1715.     echo shar: \"'mush/panels.c'\" unpacked with wrong size!
  1716. fi
  1717. # end of 'mush/panels.c'
  1718. fi
  1719. echo shar: End of archive 15 \(of 19\).
  1720. cp /dev/null ark15isdone
  1721. MISSING=""
  1722. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ; do
  1723.     if test ! -f ark${I}isdone ; then
  1724.     MISSING="${MISSING} ${I}"
  1725.     fi
  1726. done
  1727. if test "${MISSING}" = "" ; then
  1728.     echo You have unpacked all 19 archives.
  1729.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1730. else
  1731.     echo You still need to unpack the following archives:
  1732.     echo "        " ${MISSING}
  1733. fi
  1734. ##  End of shell archive.
  1735. exit 0
  1736.  
  1737.  
  1738.