home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume12 / mush / part04 < prev    next >
Encoding:
Text File  |  1990-05-05  |  54.8 KB  |  1,620 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v12i032: Mail User's Shell, Part04/19
  3. from: argv@Eng.Sun.COM (Dan Heller)
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 12, Issue 32
  7. Submitted-by: argv@Eng.Sun.COM (Dan Heller)
  8. Archive-name: mush/part04
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then feed it
  12. # into a shell via "sh file" or similar.  To overwrite existing files,
  13. # type "sh file -c".
  14. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  15. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  16. # If this archive is complete, you will see the following message at the end:
  17. #        "End of archive 4 (of 19)."
  18. # Contents:  mush/cmd_help mush/init.c
  19. # Wrapped by argv@turnpike on Wed May  2 13:59:21 1990
  20. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  21. if test -f 'mush/cmd_help' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'mush/cmd_help'\"
  23. else
  24. echo shar: Extracting \"'mush/cmd_help'\" \(39046 characters\)
  25. sed "s/^X//" >'mush/cmd_help' <<'END_OF_FILE'
  26. X/* @(#)cmd_help    1.4    10/24/88 (Dan heller) */
  27. X
  28. X%?%
  29. X      ? [command]
  30. X
  31. XThe `?' command will give you a list of legal commands.  Most
  32. Xcommands accept -? as an option.  This will give you specialized
  33. Xhelp with that particular command.
  34. X
  35. XIf the optional argument is given, help for that command is shown.
  36. X%%
  37. X
  38. X%ignore%
  39. X      ignore/unignore [headers]
  40. X
  41. XUse this command to set the message headers you would like not
  42. Xto be printed when you read a message. If no header specified,
  43. Xthen a list of all headers currently being ignored is printed.
  44. XYou must specify a header for unignore.
  45. X
  46. XYou can set the variable $alwaysignore to force normally
  47. Xignored headers to be ignored while saving messages, forwarding
  48. Xmessages or including messages into message buffers.
  49. X
  50. XSee also the variable $show_hdrs.
  51. X%%
  52. X
  53. X%set%
  54. X      set/unset [variable [= value]]
  55. X
  56. XWith no parameters, set lists all variables and their values.
  57. XTo set a boolean variable (on or off), use:
  58. X    set variable
  59. XTo set a variable's value to a string, use:
  60. X    set variable = value
  61. X
  62. XIf you want double-quotes or white-space embedded in a string,
  63. Xencase the string in single quotes.  If you want single quotes
  64. Xin a string, encase the string in double quotes.
  65. X
  66. XFor a list of all variables with special meanings, use:
  67. X    set ?all
  68. XFor help on a particular one of these variables, use:
  69. X    set ?variable_name
  70. X%%
  71. X
  72. X%readmsg%
  73. X      print [msg_list]
  74. X      type [msg_list]
  75. X      top [msg_list]
  76. X      next [msg_list]
  77. X      previous [msg_list]
  78. X
  79. XYou can read messages in different ways.  "type" and "print"
  80. Xwill print the current message.  "top" will only print the first
  81. XN lines of the current message where N is the value of the
  82. Xvariable "crt".  "next" will go to the next unread message and
  83. Xprint that.  "previous" will go back and read the first unread
  84. Xmessage previous to the current.  "^" will print the first
  85. Xmessage, "$" will print the last.
  86. X
  87. XAny of these commands can be followed by a message list, and
  88. Xeach message in that list will be printed (or piped to other
  89. Xcommands).
  90. X
  91. XSee also "help msg_list" and the variable $autoprint.
  92. X%%
  93. X
  94. X%alts%
  95. X      alts [hostnames]
  96. X
  97. XThe alts command sets a list of hostnames on which you have an
  98. Xaccount.  Normally, when you respond to all recipients of mail,
  99. Xyour account name will be listed as if you wished to send
  100. Xyourself mail.  If you don't have metoo set, then your name will
  101. Xbe removed from the mailing list if your login name is on the
  102. Xlist and the host specified is in the alternates list.  The
  103. Xspecial parameter `*' instructs alts to match all hostnames; in
  104. Xthat case, only the login name is tested.
  105. X%%
  106. X
  107. X%source%
  108. X      source/saveopts [file]
  109. X
  110. XThe source/saveopts commands will load/save all variable
  111. Xsettings, options, aliases, cmd's, ignored headers ...
  112. Xeverything you can set, it loads or saves.  The file read or
  113. Xwritten follows these rules:
  114. X
  115. X1) If a filename is given, that file is used
  116. X2) The file described by the environment variable MAILRC
  117. X3) In the user's home directory: .mushrc (if it exists)
  118. X4) In the user's home directory: .mailrc (if it exists)
  119. X
  120. XIf saveopts is used and the file exists, confirmation will be
  121. Xrequested before the file is overwritten.
  122. X%%
  123. X
  124. X%help%
  125. X      help [item]
  126. X
  127. XType "help" with no arguments for a list of valid items.
  128. X%%
  129. X
  130. X%general%
  131. XThis is the general help message.  To get help on a specific
  132. Xcommand, try "command -?".  Extended help is given by typing
  133. X"help item" where item is one of:
  134. X    path, msg_list, prompt, hdr_format
  135. XHelp with msg_list is highly advisable!
  136. X
  137. XType "?" to get a list of available commands.  Try "? command"
  138. Xto get help on the particular command that you specify.
  139. X
  140. XUse "set ?variable" to get help with specific variables.
  141. X%%
  142. X
  143. X%path%
  144. XWhenever "path" is specified, the following syntax is legal
  145. Xbesides the normal path addressing scheme used by unix:
  146. X ~[user]   -- the home directory of specified user (yours by default)
  147. X %[user]   --/usr/spool/mail/login_name [user_name] (yours by default)
  148. X +file     --the directory described by `set folder'; file is `file'
  149. X%%
  150. X
  151. X%msg_list%
  152. XA "msg_list" references one or more messages.  The user
  153. Xspecifies a group of messages according to a special syntax.
  154. X
  155. X *      All messages.
  156. X ^      The first message.
  157. X $      The last message.
  158. X .      The current message.
  159. X N-M    A range of messages between N and M, inclusive.
  160. X
  161. XIn the last case, N and M may be * ^ $ . or digits referencing
  162. Xexplicit message numbers.  The range must be in ascending order.
  163. X
  164. XYou can also negate messages by placing the message list inside
  165. Xbraces, `{' `}' -- thus, the expression "2-19 {11-14}"
  166. Xreferences messages 2 through 19 except for those from 11
  167. Xthrough 14.
  168. X
  169. XCommands can be "piped" to one another, because the return value
  170. Xof a command is a msg_list, not text.  For example,
  171. X    pick -f fred | lpr
  172. Xwill find all messages "from fred" and send them to the printer.
  173. X
  174. XCommands dealing with more than one message process them in
  175. Xnumeric order -- not necessarily the order specified.  Thus, the
  176. Xcommand "save 1-5 9 7 6 file" will save the messages in
  177. Xascending order, not in the order given.
  178. X%%
  179. X
  180. X%hdr_format%
  181. XThis variable controls the display of message headers.  Use:
  182. X    set hdr_format="string"
  183. Xto change the header display.  The string uses printf style
  184. Xformatting and follows these conventions:
  185. X    %a  address of the author
  186. X    %c  number of characters (bytes) in the message
  187. X    %d  entire date of the message (see "date_received" variable)
  188. X    %f  "From" field (author name and address)
  189. X    %i  the message-id (may or may not be present)
  190. X    %l  number of lines in the message
  191. X    %M  month name of the message
  192. X    %N  day of the month (number)
  193. X    %n  name of the author
  194. X    %s  subject of the message
  195. X    %t  "To" field (recipients)
  196. X    %T  time of the message (see "mil_time" variable)
  197. X    %W  day of the week (Sun, Mon, etc.)
  198. X    %Y  year of the message 
  199. X    %y  year (last 2 digits only)
  200. X    \n  a newline
  201. X    \t  a tab
  202. X
  203. XA field specifier may be used in any % expansion.  Thus, "%20s"
  204. Xwill print the first 20 characters of the Subject.  No matter
  205. Xwhat the formatting string, the message number, the status of
  206. Xthe message and a '>' (if this is the "current" message) is
  207. Xbefore any user defined format is printed.
  208. X%%
  209. X
  210. X%prompt%
  211. XThis variable controls the prompt that mush will display.
  212. X    set prompt = "string"
  213. XThe "string" follows printf style formatting conventions:
  214. X    %F  full path of the current working folder
  215. X    %f  name (path tail) of the current folder
  216. X    %m  current message number
  217. X    %n  number of new messages
  218. X    %u  number of unread messages
  219. X    %d  number of deleted messages
  220. X    %t  total number of messages
  221. X    %T  current time
  222. X    %N  day of the month (number) (today)
  223. X    %W  weekday name (today)
  224. X    %M  month name (this month)
  225. X    %Y  year (this year)
  226. X    %y  year (last 2 digits only)
  227. X    \n  newline
  228. X    \t  tab
  229. X%%
  230. X
  231. X%preserve%
  232. X      preserve [msg_list]
  233. X
  234. XThe "preserve" command marks messages to be saved in your system
  235. Xmailbox.  Unless explicitly preserved, all mail that you read
  236. Xwill be saved in ~/mbox (or the file specified by $mbox).  Deleted
  237. Xmessages are preserved only if also undeleted (see "delete -?").
  238. XWhen a message is preserved, the `P' status bit will appear in the
  239. Xheader summary display for that message.
  240. X
  241. XThe "unpreserve" command reverses the effect of "preserve".
  242. X
  243. XSetting the boolean variable $hold is equivalent to preserving
  244. Xeach message as you read it, except that no `P' status is set.
  245. X%%
  246. X
  247. X%save%
  248. X      save/write/copy [-s|-S|-a|-A] [-f] [msg_list] [filename]
  249. X
  250. XIf no filename is specified, ~/mbox (or the value of the
  251. Xvariable "mbox") is used.  Save and write will append msg if
  252. X`file' already exists.  Specifying -f will overwrite the
  253. Xfile (e.g., erasing it first).
  254. X
  255. XTo save messages to a filename beginning with a digit, escape
  256. Xthe filename with a backslash (\).
  257. X
  258. XThe "write" command will write message without the headers (msg
  259. Xbody only).  Save and write both mark messages for deletion
  260. Xunless $keepsave is set.  The "copy" command is identical to
  261. X"save" except that messages are not marked for deletion
  262. X(identical to having the variable "keepsave" set).
  263. X
  264. XThe -s and -S options save messages to files named by the
  265. Xsubject of the message.  If more than one message is specified,
  266. Xthen the message subject of each message is used.  If -S is
  267. Xspecified, then the subject of the first message is used for all
  268. Xmessages.  Spaces and forward slashes (/) are converted to
  269. Xunderscores (_).
  270. X
  271. XThe -a and -A options save messages by author's login name.
  272. X%%
  273. X
  274. X%lpr%
  275. X      lpr [-n] [-h] [msg_list]
  276. X
  277. XSend a message to the printer.  The options are:
  278. X  -n      print body of message only (no headers)
  279. X  -h      do not print ignored headers
  280. X  -Pxx    print on printer xx
  281. X
  282. XThe variable $printer can be used to specify a default printer;
  283. Xfor example, "set printer=lp" is the same as always using "-Plp".
  284. XThe variable $print_cmd can be used to specify a program other
  285. Xthan "lpr" to use for printing.
  286. X
  287. XSee also the variable $alwaysignore.
  288. X%%
  289. X
  290. X%mail%
  291. X      mail [mail-flags] [recipients]
  292. X
  293. XCompose and send a mail message.  The possible flags are:
  294. X  -b bcc-addrs    set blind-carbon-copy recipients
  295. X  -c cc-addrs     set carbon-copy recipients
  296. X  -e              immediately enter editor (autoedit)
  297. X  -E              edit outgoing headers
  298. X  -f [msg-list]   forward msg-list (not indented)
  299. X  -F              add fortune to the end of message
  300. X  -h file         read file as prepared draft (with headers)
  301. X  -H file         read file as prepared text (without headers)
  302. X  -i [msg-list]   include msg-list in letter
  303. X  -I [msg-list]   include msg-list with headers in letter
  304. X  -s [subject]    prompt for or set subject
  305. X  -u              do not append signatures and fortunes
  306. X  -U              send draft immediately (use with -h or -H)
  307. X  -v              verbose (not available on some systems)
  308. X
  309. XThe -f option will add new headers and automatically send the
  310. Xindicated messages to the list of recipients unless -E or -e
  311. Xis also given.  The -I and -i options will read the indicated
  312. Xmessages into the text of your letter, surrounded by the text
  313. Xof variables pre_indent_str, indent_str, and post_indent_str.
  314. X
  315. XThe -h option reads a draft file, which should already include
  316. Xmessage headers.  The -H option reads a text file, which should
  317. XNOT include headers.  If the -U option is also given, the draft
  318. Xis sent immediately.
  319. X
  320. XSee also the variables $ask, $askcc, $autoedit, $autoinclude,
  321. X$autosign, $autosign2, $dot, $edit_hdrs, $escape, $fortune,
  322. X$fortunates, $logfile, $record, $no_expand, $no_hdrs, $realname,
  323. X$sendmail, $verbose, $verify, and $wrapcolumn.
  324. X%%
  325. X
  326. X%respond%
  327. X      replysender/replyall [msg-list] [-r path] [mail-flags] [recipients]
  328. X
  329. XThe "replysender" command replies only to the sender of a
  330. Xmessage, whereas "replyall" responds to everyone on the To: and
  331. XCc: lines of the message.
  332. X
  333. XThe command "reply" is identical to "replysender".
  334. X
  335. XIf a message list is indicated, then each message on the list is
  336. Xreplied to in the same manner.  If -r is specified with a host or
  337. Xpath (uucp-style), then each address in the list is routed via
  338. Xthis path.  This overrides the value of auto_route (see man page).
  339. X
  340. XThe address of the author is obtained from certain headers in
  341. Xhis message to you.  Unless you specify otherwise, mush will
  342. Xsearch for the headers Reply-To: Return-Path: and From:.  You
  343. Xcan override these values by setting the variable reply_to_hdr.
  344. X
  345. X    set reply_to_hdr = "sender reply-to return-path from_"
  346. X
  347. XThis example shows that mush will search for (in order), the
  348. Xheaders listed in the reply_to_hdr variable.  If one header isn't
  349. Xfound, then mush looks for the next in the list.  If none of the
  350. Xheaders in the list are found, the default headers (mentioned
  351. Xabove) are searched.  The last header listed in the example is
  352. Xthe special "From " header.  See the man page for more details.
  353. X
  354. XType "mail -?" for information on legal mail flags.
  355. X
  356. XSee also the variables $auto_route, $domain_route, $in_reply_to,
  357. X$known_hosts, $metoo, $reply_to_hdr, and those listed by "mail -?".
  358. X%%
  359. X
  360. X%sort%
  361. X      sort [-i] [-r|a|d|l|R|s|S]
  362. X
  363. X  -i         ignore case in alphabetical sorts
  364. X  -r         reverse order of next criteria
  365. X
  366. X  -a         by author (alphabetical)
  367. X  -d         according to date
  368. X  -l         by length (size)
  369. X  -R         by subject including Re: (alphabetical)
  370. X  -s         by subject ignoring Re: (alphabetical)
  371. X  -S         by status
  372. X
  373. XAny combination of the options can be given.  Each comparison
  374. Xproceeds from left to right through the list of criteria,
  375. Xstopping when an ordering has been determined or no criteria
  376. Xremain.  The optional -r flag will reverse the order of the
  377. Xnext comparison specified.  Example:
  378. X
  379. X      sort -i -a -r -d
  380. X
  381. XThe above will sort by author first, ignoring case, and will
  382. Xsort by reverse date (most recent first) for each author.  The
  383. X-r option can be given once for each criterion and applies
  384. Xonly to the first criterion that follows it.  Giving -r twice
  385. Xin succession (-r -r) does NOT negate the reversal!  Whatever
  386. Xoption follows the rightmost -r will have its sense reversed.
  387. X
  388. XUnlike -r, the -i option is recognized at most once and applies
  389. Xto all alphabetical sorts in the list of criteria.
  390. X
  391. XBy default (no parameters), sort orders messages by status:
  392. XNew, unread messages are first, followed by preserved messages
  393. Xand finally the deleted messages are placed at the end.  If -r
  394. Xis the only flag given, the status order is reversed.
  395. X
  396. XIf the $date_received variable is set, sorting by date is
  397. Xdone using the date you received the message.  Otherwise,
  398. Xmessages are sorted by date sent by the original author.
  399. X
  400. XSee also the variable $sort.
  401. X%%
  402. X
  403. X%pick%
  404. X      pick [+<num>] [-<num>] [-r msg_list] [-x] [-i] [-h hdr] [-f|s|t]
  405. X    [-d [-][date]] [-ago [+|-] [n days] [n weeks] [n months]] [[-e] <pat>]
  406. X
  407. XSearch for patterns within messages.  Entire messages are
  408. Xsearched for <pattern> unless -f, -h, -s, or -t is specified.
  409. XOnly one of -d, -f, -h, -s, -t and -ago can be specified; no
  410. Xpattern is used with -d and -ago; and -x may not be used in
  411. Xconjunction with +<num> and/or -<num>.
  412. X
  413. X  +<num>        return only the first <num>ber messages matched
  414. X  -<num>        return only the last <num>ber messages matched
  415. X  -x            return all the messages which do NOT match
  416. X  -e        remaining arguments are the <pat> (`e'xpression)
  417. X  -f            match pattern in the "From:" field (author) only
  418. X  -s            match pattern in the "Subject:" header only
  419. X  -t            match pattern in the "To:" field only
  420. X  -h hdr        match pattern in specified header field only
  421. X  -i            ignore case of letters in when matching
  422. X  -r msg_list   restrict the range of messages search to msg_list
  423. X  -d            select messages sent on [+ after] [- before] date
  424. X        A "date" is of the form:  [+-][month]/[date[/year]]
  425. X        Omitted fields default to today's values.  Examples:
  426. X          pick -d 4/20     messages on Apr 20, this year
  427. X          pick -d -/2/85   on or before the 2nd, this month, 1985
  428. X          pick -d +5/4     on or after May 4, this year
  429. X          pick -d /        finds today's messages only
  430. X        At least one `/' char must be used in a date.  There is
  431. X    no strong date checking; 2/30 would be considered valid.
  432. X  -ago          select messages relative to the current date
  433. X    Date formats for "ago" are more verbose than for -d; see
  434. X    the manual page for details.
  435. X
  436. XExamples:
  437. X    Find the first 5 messages with the subject "Telephone Message":
  438. X    pick +5 -s Telephone Message
  439. X    Find the first 2 messages of the last 4 that are to "mush-users":
  440. X    pick -4 +2 -t mush-users
  441. X    Find those among messages 1 to 10 that are 2 months or more old:
  442. X    pick -r 1-10 -ago -2m
  443. X    Find messages that are 1 week old or newer:
  444. X    pick -ago +1w
  445. X    Find messages that contain "-request" in the Resent-From field:
  446. X    pick -h resent-from -e -request
  447. X
  448. XA description of the pick operation will be printed before the search
  449. Xis performed, unless the value of the variable $quiet contains the
  450. Xfield "pick", or pick is piped to another mush command.
  451. X%%
  452. X
  453. X%alias%
  454. X      alias [name [namelist]]
  455. X
  456. XOptions for alias:
  457. X alias                       print all namelists
  458. X alias name                  print namelist associated with name
  459. X alias name namelist         set "name" to the value of namelist
  460. X unalias namelist            unalias names in namelist
  461. X
  462. XA "namelist" consists of one or more addresses.  An address may
  463. Xbe a name already set to another list, a valid user, a file or
  464. Xa program.  Filenames must be full pathnames, i.e., they must
  465. Xbegin with a '/' (or with a ~, which expands to some home dir).
  466. XA "program" must start with a pipe symbol and be encased in
  467. Xquotes:
  468. X
  469. X    "|program_name"
  470. X
  471. XThe command "expand" will print addresses (including sublists)
  472. Xassociated with the given alias.
  473. X
  474. XSee also the variable $no_expand.
  475. X%%
  476. X
  477. X%from%
  478. X      from [+|-] [msg-list]
  479. X
  480. XWith no parameters, "from" will print the current message's
  481. Xheader line.  If given a message list, "from" will print the
  482. Xheaders of the listed messages.
  483. X
  484. XThe special parameters `-' and `+' can be given to move the
  485. Xcurrent message pointer to the previous or next message
  486. Xrespectively, while also printing that message's header.
  487. X
  488. XIf a message list was given in addition to `-' or `+', then
  489. Xthe current message pointer will be set to the first or last
  490. Xmessage, respectively, in the message list given.
  491. X
  492. XExamples:
  493. X
  494. X    from - 10-30 {16}
  495. Xwill print the headers of messages 10 through 30 except for
  496. Xmessage 16 and set the current message pointer to 10.
  497. X
  498. X    pick -f Dan | from +
  499. Xwill print the headers of all messages that contain "Dan" in the
  500. Xauthor's name and set the current message pointer to the last
  501. Xone of that kind in the list.
  502. X
  503. X    from +
  504. Xwill print the header of the message after the current message
  505. Xand increment the current message pointer to that message.
  506. X
  507. XSee also the "headers" command and "help hdr_format".
  508. X%%
  509. X
  510. X%my_hdr%
  511. X      my_hdr [header[: string]]
  512. X
  513. XThis command is used to set, unset or view your personalized
  514. Xmessage headers.  These headers are included in all your
  515. Xoutgoing mail.
  516. X
  517. XOptions for my_hdr:
  518. X  my_hdr            show all headers
  519. X  my_hdr header            show value of header
  520. X  my_hdr header: string        set header to string
  521. X  un_hdr header            unset header
  522. X
  523. XNote that there is no space between the header name and the
  524. Xcolon in the third form of the command.
  525. X%%
  526. X
  527. X%fkey%
  528. X      fkey [<sequence> [command]]
  529. X      unfkey <sequence>
  530. X
  531. XThis command is used to make function key settings in Suntools
  532. X(graphics) mode.  When run as a tool (-t on command line),
  533. Xchoose the Options item, and the "function key" menu option.
  534. X
  535. XThe unfkey command removes the setting for a given string.
  536. X%%
  537. X
  538. X%cmd%
  539. X      cmd [name [value]]
  540. X
  541. XThis function is used to establish command aliases; cmd's are
  542. Xjust like aliases in the C-shell.  Options are:
  543. X  cmd                       view all commands
  544. X  cmd command               show value of command
  545. X  cmd command value         set command to value
  546. X  uncmd command             unset command
  547. X
  548. XThe value must be quoted if it is to contain command separators
  549. Xsuch as `;' or `|'.
  550. X
  551. XIf you want to reference history commands within a cmd,
  552. Xescape the ! with a backslash.  For example:
  553. X
  554. X    cmd r 'replysender \!* ; delete -t'
  555. X
  556. Xwill cmd "r" to reply using whatever parameters you have given on
  557. Xthe command line and then delete that message and print the next
  558. Xmessage (-t parameter to "delete").
  559. X%%
  560. X
  561. X%headers%
  562. X      headers [+|-|N] [[-H]:c]
  563. X  +    print the next screenful (or use the 'z' command).
  564. X  -    print the previous screenful (or use 'z-' ).
  565. X  N    print a screenful starting at message number N.
  566. X  -H:c  where `c' is one of
  567. X     a  all messages (mostly for the mush startup option -H:c)
  568. X     d  deleted messages
  569. X     n  new messages
  570. X     o  old messages
  571. X     p  preserved messages
  572. X     r  replied-to messages
  573. X     s  saved messages
  574. X     u  unread messages
  575. X
  576. XThe "headers" command prints out a screenful of headers.
  577. XDeleted messages are not normally shown; set "show_deleted" to
  578. Xinclude deleted messages.
  579. X
  580. XThe command ":c" is equivalent to "headers -H:c".  The -H can be
  581. Xomitted, i.e., "headers :c" will also work.
  582. X
  583. XSee also "help hdr_format".
  584. X%%
  585. X
  586. X%folder%
  587. X      folder [-N] [-n] [-r] [%[user]|#|&|file]
  588. X
  589. X  -N       do not display the list of headers
  590. X  -n       do not update the current folder before changing
  591. X  -r       read only mode (cannot write changes to new folder)
  592. X  %[user]  change to /usr/spool/mail/[user] (you by default)
  593. X  #        change to folder accessed previous to current folder
  594. X  &        change to "mbox" -- default is $mbox or ~/mbox
  595. X
  596. XThe "folder" command changes the current folder; with no parameters,
  597. Xit prints the name of the current folder.  For compatibility with
  598. Xolder versions, the single character `!' is equivalent to -n.
  599. X
  600. X"Folder" treats the characters `+' and `~' as metacharacters when
  601. Xthey are the first character of a file name.  `~' is expanded to the
  602. Xname of the user's home directory, or to another user's home if it
  603. Xis given as "~username" (no `/' between the `~' and the name).  `+'
  604. Xis expanded to the user's folder directory ("~/Mail" or the value of
  605. X$folder); no `/' is required between `+' and the file name, so both
  606. X"+file" and "+/file" refer to the same file.
  607. X
  608. XThe "update" command updates the current folder.  In this case, only
  609. Xthe -N and -r options are recognized; "update -r" changes the current
  610. Xfolder to read only mode AFTER updating it.
  611. X
  612. XSee also the variable $folder.
  613. X%%
  614. X
  615. X%quit%
  616. X      quit/exit
  617. X
  618. XThese commands end a mush session.  "quit" will update your
  619. Xmailbox; if new mail has come in, you will be told so and given
  620. Xan option whether to really quit or not.  "exit" will leave mush
  621. Xneither updating your mailbox nor checking for new mail.
  622. X%%
  623. X
  624. X%ls%
  625. X      ls [options]
  626. X
  627. XThe "ls" command is exactly like the UNIX command "ls".  All
  628. Xparameters are the same.  The "folders" command is equivalent
  629. Xto doing "ls -FR $folder" from the Mush prompt.
  630. X%%
  631. X
  632. X%shell%
  633. X      sh [command]
  634. X
  635. XIf a "command" is given, that UNIX command will be executed
  636. Xunder the Bourne shell.  If no command is specified, then an
  637. Xinteractive shell will be started. The environment variable
  638. XSHELL or the local mail shell variable $shell describes the
  639. Xshell to invoke.  If none is set, then the default shell is
  640. Xdefined by the system administrator (currently set to csh).
  641. X
  642. XUsers on systems with job control will probably have little
  643. Xuse for the sh command.
  644. X%%
  645. X
  646. X%stop%
  647. X      stop
  648. X
  649. XThe stop command sends a stop signal to the mail shell.  It is
  650. Xequivalent to your tty job-control stop character (often ^Z).
  651. XSince the mush shell never needs to be exited, the command 'q'
  652. Xmay be "cmd"ed to "stop;await" and csh users may have
  653. X    alias mail %mush
  654. Xto bring mush into the foreground rather than having to invoke
  655. Xit again.  New mail will be read into the shell automatically
  656. Xand much time and energy is saved.
  657. X%%
  658. X
  659. X%curses%
  660. X      curses
  661. X
  662. XThe curses-based interface for Mush does not require a graphics
  663. Xdisplay, but does requires a terminal which can handle upline
  664. Xcursor movement capabilities.  All commands are one or two
  665. Xkeystroke commands and are executed as soon as the key is typed.
  666. X
  667. XFor a list of current key-to-command bindings, use the "bind"
  668. Xcommand (defaults to 'b' in curses mode).
  669. X
  670. XSee also the variable $curses_help.
  671. X%%
  672. X
  673. X%bind%
  674. X      bind [<sequence> <curses-command> [<parameters>]]
  675. X      unbind <sequence>
  676. X
  677. XBinding is done for the curses interface only.  It allows the
  678. Xuser to bind keystrokes or key sequences to curses-interface
  679. Xcommands.  You cannot bind keystrokes to regular mush commands
  680. Xusing bind.
  681. X
  682. XA bound key-sequence (input by the user) will be converted into
  683. Xthe curses command it is bound to.  For a list of all curses
  684. Xcommands, issue the "bind" command and follow the instructions
  685. Xto get a list.  Currently, parameters are ignored for all curses
  686. Xcommands except the special command "macro".
  687. X
  688. XWhen specifying sequences, you may enter almost anything at the
  689. Xkeyboard that you want to type.  This includes most control
  690. Xcharacters.  A special syntax is provided to specify control
  691. Xcharacters if you wish to set up default key bindings in your
  692. Xinitialization file without using real control characters.
  693. X
  694. XTo bind keystrokes that are control characters in the
  695. Xinitialization file, you must use the notation "\CX" where "X"
  696. Xis an upper-case letter representing the control key you want to
  697. Xuse. "\CN" would be control-N; "\n" is carriage return.  You may
  698. Xnot bind keyboard generated signals; for most users, those key
  699. Xsequences are control-C and control-\.  For users with job
  700. Xcontrol, the suspend characters (usually control-Z and
  701. Xcontrol-Y) are also ignored.
  702. X
  703. XTo specify the escape key, use "\E"; "\C[" will not work.
  704. X
  705. XTrying to bind a key sequence which prefixes another sequence is
  706. Xan error and the user is warned that the longer binding will not
  707. Xwork.  The binding will take place, however, because it is
  708. Xpossible to unbind the shorter sequence, thus validating the
  709. Xlonger sequence.
  710. X
  711. XThe special curses command "macro" allows a string to be
  712. Xexecuted just as if the user typed it directly.  Issue the
  713. X"bind-macro" command for more details.
  714. X
  715. XBindings are removed with the "unbind" command.
  716. X%%
  717. X
  718. X%msg_flags%
  719. X      flags [[+|-] [flag-bits]] [msg-list]
  720. X
  721. XAny sensible combination of these flag-bits may be used:
  722. X  D    deleted
  723. X  f    forwarded
  724. X  N    new
  725. X  O    old
  726. X  P    preserved
  727. X  p    printed
  728. X  R    read
  729. X  r    replied-to
  730. X  S    saved
  731. X  U    unread
  732. X
  733. XThis command displays the status of messages by default.
  734. XIf a msg-list is specified, it will tell which bits of the
  735. Xmessage are set.  If any (one or more) of the bits are
  736. Xgiven and no + or - modifier is specified, then the status
  737. Xof each message in the list will be set to that status
  738. Xabsolutely (other status flags are lost).  However, if a +
  739. Xor - is specified, then the status is modified for that bit
  740. Xto on (+) or off (-).
  741. X
  742. XIf no list is given, then the list of messages is taken
  743. Xfrom a pipe (if piped) or the current message is used.
  744. X%%
  745. X
  746. X%setenv%
  747. X      setenv VARIABLE [value]
  748. X
  749. XVariable names may be any string, but traditionally environment
  750. Xvariables are all upper case.  If no "value" is specified, then
  751. Xthe variable name will be set to an empty string.  If the value
  752. Xcontains spaces, you should enclose the string in quotation
  753. Xmarks.  Use printenv to print a list of all your environment
  754. Xvariables.
  755. X%%
  756. X
  757. X%unsetenv%
  758. X      unsetenv VARIABLE
  759. X
  760. XYou must specify one and only one variable to unset in your
  761. Xenvironment variable settings.  Use printenv to print a list of
  762. Xall your environment variables.
  763. X%%
  764. X
  765. X%printenv%
  766. X      printenv [VARIABLE]
  767. X
  768. XDisplay the entire current environment, or the value of the
  769. Xspecified environment variable.
  770. X
  771. XAlso see "setenv" and "unsetenv".
  772. X%%
  773. X
  774. X%edit_msg%
  775. X      edit [msg_list]
  776. X
  777. XThe "edit" command lets you edit messages in your folder.  The
  778. Xeditor used is determined by the variable $editor, the environment
  779. Xvariable EDITOR, the variable $visual and the environment variable
  780. XVISUAL in that order.  If none of those variables are set, the
  781. Xdefault visual editor will be used.  The "v" command is the same
  782. Xas "edit" but will test only $visual and VISUAL.
  783. X
  784. XWhen editing messages, be careful not to remove certain message
  785. Xheaders such as Date:, From:, or any others that look important.
  786. XIf you remove or change something you shouldn't have, you will
  787. Xbe notified and the temporary file used to edit the message will
  788. Xnot be removed.
  789. X%%
  790. X
  791. X%bind-macro%
  792. X      bind-macro [<sequence> [<expansion>]]
  793. X
  794. XThe "bind-macro" command allows you to set macros in curses
  795. Xmode, so that one keystroke (or a few) will act as though you
  796. Xhad typed a longer sequence.  Using "bind-macro" is equivalent
  797. Xto specifying the "macro" special command as a parameter to
  798. Xthe "bind" command.
  799. X
  800. XGiven no parameters, "bind-macro" will list all current curses
  801. Xmode macros.  Given only a <sequence>, it will show the current
  802. Xbinding for that sequence.  Given both a <sequence> and an
  803. X<expansion>, it will create a macro such that, when the
  804. X<sequence> is typed in curses mode, the effect will be the same
  805. Xas if the <expansion> had been typed instead.
  806. X
  807. XThe same format for control characters that is used for the
  808. X"bind" command may be used in both the <sequence> and the
  809. X<expansion>, i.e.,
  810. X    \Cx     control-x (where x is a capital letter)
  811. X    \E      the escape character (\C[ does NOT work!)
  812. X    \n      a newline (other C-style escapes also work)
  813. X
  814. XExample:
  815. X    bind-macro F [folder]+record\n
  816. X
  817. XIf you are in curses mode and hit the F key, then the curses
  818. Xmode command "folder" will execute and +record (followed by
  819. Xa carriage return) will be entered as if you typed it.
  820. X
  821. XMacros are removed with the "unbind" command, see "bind -?".
  822. X
  823. XAlso see the "map" and "map!" commands.
  824. X%%
  825. X
  826. X%map%
  827. X      map [<sequence> [<expansion>]]
  828. X      unmap <sequence>
  829. X
  830. XThe "map" command allows you to use one keystroke (or a few) and
  831. Xhave it act as though you had typed a longer sequence.
  832. X
  833. XGiven no parameters, "map" will list all current line mode
  834. Xmacros.  Given only a <sequence>, it will show the current
  835. Xbinding for that sequence.  Given both a <sequence> and an
  836. X<expansion>, it will create a macro such that, when the
  837. X<sequence> is typed in line mode, the effect will be the same
  838. Xas if the <expansion> had been typed instead.
  839. X
  840. XThe same format for control characters that is used for the
  841. X"bind" command may be used in both the <sequence> and the
  842. X<expansion>, i.e.,
  843. X    \Cx     control-x (where x is a capital letter)
  844. X    \E      the escape character (\C[ does NOT work!)
  845. X    \n      a newline (other C-style escapes also work)
  846. X
  847. XExample:
  848. X    map & print\n
  849. X
  850. XIf you are not in curses mode and hit the & key, then it will
  851. Xbe as if you typed the word "print" and hit carriage return.
  852. X
  853. XTo type a character without having the mapping expanded, precede
  854. Xthe character with a backslash (\).
  855. X
  856. XMappings are removed with the "unmap" command.
  857. X
  858. XAlso see the "map!" and "bind" commands.
  859. X%%
  860. X
  861. X%map!%
  862. X      map! [<sequence> [<expansion>]]
  863. X      unmap! <sequence>
  864. X
  865. XThe "map!" command allows you to set macros in message
  866. Xcomposition mode, so that one keystroke (or a few) will act
  867. Xas though you had typed a longer sequence.  map!'s take
  868. Xeffect regardless of whether you started the letter from
  869. Xcurses mode or line mode.
  870. X
  871. XGiven no parameters, "map!" will list all composition mode
  872. Xmacros.  Given only a <sequence>, it will show the current
  873. Xbinding for that sequence.  Given both a <sequence> and an
  874. X<expansion>, it will create a macro such that, when the
  875. X<sequence> is typed in message composition mode, the effect will
  876. Xbe the same as if the <expansion> had been typed instead.
  877. X
  878. XThe same format for control characters that is used for the
  879. X"bind" command may be used in both the <sequence> and the
  880. X<expansion>, i.e.,
  881. X    \Cx     control-x (where x is a capital letter)
  882. X    \E      the escape character (\C[ does NOT work!)
  883. X    \n      a newline (other C-style escapes also work)
  884. X
  885. XExample:
  886. X    map! ! <BANG>
  887. X
  888. XIf you are typing in a letter regardless of which interface you
  889. Xuse and you hit the ! key, then it would be as if you typed the
  890. Xkeys "<BANG>".
  891. X
  892. XTo type a character without having the mapping expanded, precede
  893. Xthe character with a backslash (\).
  894. X
  895. XMappings are removed with the "unmap!" command.
  896. X
  897. XAlso see the "bind" and "map" commands.
  898. X%%
  899. X
  900. X%eval%
  901. X      eval [-h|-p] args ...
  902. X
  903. XThis command causes its arguments to be re-parsed and then
  904. Xexecuted as a mush command.  Example:
  905. X
  906. X    set initprompt='"$hostname:$cwd "'
  907. X    eval set prompt=$initprompt
  908. X
  909. XIf the -h flag is given, then eval looks for formatting parameters
  910. Xas defined for the variable $hdr_format, and expands the formats
  911. Xfor the "current" message before executing the command.  Example:
  912. X
  913. X    eval -h pick -f %f
  914. X
  915. Xwill find all messages from the same author as the current message.
  916. X
  917. XIf the -p flag is given, then eval expands formatting parameters as
  918. Xas defined for the variable $prompt.  The -h and -p flags may not be
  919. Xused together in the same eval.
  920. X%%
  921. X
  922. X%pipe_msg%
  923. X      pipe [-p pattern] [msg-list] [unix-command] [cmd-args]
  924. X
  925. XThis command is used to send a message to a unix command.  The
  926. Xcommand will take its input from the message(s) passed to the pipe
  927. Xcommand.  By default, the entire message (including headers) is
  928. Xsent.  Ignored headers (see "ignore -?" and "set ?show_hdrs") can
  929. Xbe suppressed by setting the variable $alwaysignore.
  930. X
  931. XYou can pipe (|) messages to this command rather than give a
  932. Xmsg-list, but if no msg-list is given and there is no pipe, the
  933. Xcurrent message is used.  The unix-command is executed via "sh",
  934. Xso csh aliases may not be used.
  935. X
  936. XIf invoked with a capital letter (Pipe), only the bodies of the
  937. Xmessages will be fed to the unix-command -- all headers will be
  938. Xomitted.
  939. X
  940. XA pattern can be specified to indicate which line should start
  941. Xthe lines that are sent to the unix command.  The pattern must
  942. Xmatch literally (no regular-expressions) at the beginning of a
  943. Xline.  Once the pattern is found, that line and all succeeding
  944. Xlines are sent to the unix command.
  945. X
  946. XIf the unix-command is omitted, then /bin/sh is used and the 
  947. Xpattern searched for is "#!".  Therefore, "pipe" with no arguments
  948. Xcan be used to treat a message as a shell script.
  949. X
  950. XExamples:
  951. X    pipe patch         -- send the current message to "patch"
  952. X    pipe -p %! lpr     -- send the message to a postscript printer
  953. X    pipe 2 7 more      -- send messages 2 and 7 through "more"
  954. X    1 | Pipe nroff     -- send the body of message 1 to "nroff"
  955. X%%
  956. X
  957. X%merge%
  958. X      merge [-N] folder-name
  959. X
  960. XThe contents of the specified folder are read into the current
  961. Xfolder.  If -N is not specified, a header summary is printed
  962. Xfor each message read (see "headers -?").
  963. X
  964. XA list of all the merged messages is returned for use in pipes.
  965. X%%
  966. X
  967. X%echo%
  968. X    echo [-n] [-h | -p] args
  969. X
  970. XEcho simply echoes the parameters to the command back to the user.
  971. X
  972. XIf the -n flag is given, then no newline is appended.
  973. XIf the -h flag is given, then echo looks for formatting parameters
  974. Xas if the "from" command were given on the "current" message.
  975. XIf the -p flag is given, then echo looks for formatting parameters
  976. Xas if your prompt were changed temporarily.
  977. X
  978. XExamples:
  979. X    echo -h This message is from %a and is dated %d
  980. Xmight produce:
  981. X    This message is from island!argv and is dated Dec 14, 1988.
  982. X
  983. X    echo -p There are %n new messages to read in %f.
  984. Xmight produce:
  985. X    There are 5 new messages to read in /usr/spool/mail/argv.
  986. X
  987. XNote that -h and -p cannot be specified together.
  988. X%%
  989. X
  990. X%undigest%
  991. X    undigest [-m] [-p pattern] [msg_list] [filename]
  992. X
  993. XA "digest" is a mail message which is a collection of other mail messages
  994. Xmailed to a "moderator" by other users.  The moderator compiles all the
  995. Xmessages into a folder and sends the result to all the subscribers of the
  996. Xmailing list.  The undigest command disassembles the entries into the set
  997. Xof messages which comprises the digest.
  998. X
  999. XThe -m option will merge these messages into the current folder.  Otherwise,
  1000. Xif a filename is specified, a new folder is created and the user can change
  1001. Xfolders to read the messages separately.
  1002. X
  1003. XThe -p option specifies an alternate pattern to use as the digest article
  1004. Xseparator.  The pattern must match literally at the beginning of a line.
  1005. XThe default pattern is "--------" (eight hyphens).
  1006. X
  1007. XIf a message list is specified, each digest is disassembled to the same
  1008. Xfilename (if given).  If no filename is given and the user did not request
  1009. Xa merge, then a folder is created based on the subject of the digest.
  1010. X%%
  1011. X
  1012. X%await%
  1013. X    await [-T delay]
  1014. X
  1015. XInstructs the shell to wait for new mail to arrive.  New mail is checked
  1016. Xevery 30 seconds by default; a different delay can be specified by using
  1017. Xthe -T option.
  1018. X
  1019. XIf this command is used in a pipe, its output is its input plus the list
  1020. Xof new messages that have arrived.  For example, to show the headers of
  1021. Xall new messages, and set the current message to the first new message:
  1022. X
  1023. X    await | from -
  1024. X
  1025. XThe await command terminates only when new mail arrives or a keyboard
  1026. Xinterrupt is generated.
  1027. X%%
  1028. X
  1029. X%cd%
  1030. X      cd [directory]
  1031. X
  1032. XChange the current working directory to the specified directory,
  1033. Xor to the user's home directory if none was given.
  1034. X
  1035. XIf the variable $cdpath is set to a list of directory names,
  1036. Xand the argument directory is not an absolute path, mush will
  1037. Xsearch the cdpath directories in the order given for the new
  1038. Xdirectory and change to the first one found.  NOTE:  The current
  1039. Xdirectory "." MUST BE INCLUDED in the cdpath or it will not be
  1040. Xsearched!  This differs from csh, which prefers "." be left out.
  1041. X%%
  1042. X
  1043. X%pwd%
  1044. X      pwd
  1045. X
  1046. XPrints the current working directory.  The variable $cwd also
  1047. Xholds the current working directory unless reset by the user.
  1048. X%%
  1049. X
  1050. X%delete%
  1051. X      delete/undelete [msg-list]
  1052. X
  1053. XThe "delete" command marks the listed messages as deleted.  If
  1054. Xno message list is given, the current message is deleted.
  1055. X
  1056. XDeleted messages are not shown in the header summary display
  1057. Xexcept in curses mode and when the variable $show_deleted is set.
  1058. XDeleted messages are ignored by the "pipe" command and by the
  1059. Xcommands that display messages (see "print -?"), but most other
  1060. Xcommands include all messages whether deleted or not.
  1061. X
  1062. XDeleted messages are lost forever when the folder is updated (by
  1063. Xthe "update" command, by changing folders without the "!" flag,
  1064. Xor by exiting with "quit").  Messages can be recovered by the
  1065. X"undelete" command at any time BEFORE the folder is updated.
  1066. X
  1067. XSee also the variable $show_deleted.
  1068. X%%
  1069. X
  1070. X%history%
  1071. X      history [-h] [-r] [number]
  1072. X
  1073. XDisplay the command history that mush has recorded, as in csh.
  1074. XOption -h suppresses the history numbers, and option -r shows
  1075. Xthe history in reverse order (most recent first).  If a number
  1076. Xis given, that many commands of history are displayed.
  1077. X
  1078. XThe number of commands that mush records is controlled by the
  1079. Xvariable $history.  If $history is not set, mush will save only
  1080. Xthe previous command (equivalent to history=1).
  1081. X
  1082. XThe basic forms of history reference are (N is a number and
  1083. Xstr is any string):
  1084. X
  1085. X  !str      most recent command beginning with str
  1086. X  !?str?    most recent command containing str
  1087. X  !N        command N from the history list
  1088. X  !-N       command N previous to the current one
  1089. X  !!        previous command (same as !-1)
  1090. X  !$        last word of previous command
  1091. X  !*        all arguments of previous command
  1092. X
  1093. XModifiers (H can be str, ?str?, N or -N, n is a number or $):
  1094. X
  1095. X  !H:$      last word of referenced command
  1096. X  !H:n      n'th word of referenced command
  1097. X  !H:n-m    n'th through m'th words of command
  1098. X  !H:-n     word 0 (command name) through n of command
  1099. X  !H:*      all arguments of command (same as !H:1-$)
  1100. X  !H:n-     word n through next-to-last word
  1101. X  !H:p      print but don't execute command
  1102. X
  1103. X  !{R}str   append str to reference R (R is any form above)
  1104. X
  1105. XIt is not currently possible to combine :p with any of the
  1106. Xother modifiers.
  1107. X
  1108. XAlso see the variable $nonobang.
  1109. X%%
  1110. X
  1111. X%folders%
  1112. X      folders
  1113. X
  1114. XList the files in the directory described by the variable $folder.
  1115. XThese files are assumed to be folders of mail messages that can
  1116. Xbe read in by the "folder" command (see "folder -?").
  1117. X
  1118. XAlso see the "ls" command.
  1119. X%%
  1120. X
  1121. X%stty%
  1122. X      stty [options]
  1123. X
  1124. XThe "stty" command is equivalent to the UNIX command "stty".  All
  1125. Xoptions are the same.  Some settings will be temporarily changed
  1126. Xwhile mush is running, but will be restored when mush exits.
  1127. X%%
  1128. END_OF_FILE
  1129. if test 39046 -ne `wc -c <'mush/cmd_help'`; then
  1130.     echo shar: \"'mush/cmd_help'\" unpacked with wrong size!
  1131. fi
  1132. # end of 'mush/cmd_help'
  1133. fi
  1134. if test -f 'mush/init.c' -a "${1}" != "-c" ; then 
  1135.   echo shar: Will not clobber existing file \"'mush/init.c'\"
  1136. else
  1137. echo shar: Extracting \"'mush/init.c'\" \(13422 characters\)
  1138. sed "s/^X//" >'mush/init.c' <<'END_OF_FILE'
  1139. X/* init.c    (c) copyright 1986 (Dan Heller) */
  1140. X
  1141. X/* init.c -- functions and whatnot that initialize everything */
  1142. X#include "mush.h"
  1143. X#include <pwd.h>
  1144. X
  1145. X#ifdef BSD
  1146. X#include <netdb.h>
  1147. X#endif /* BSD */
  1148. X
  1149. X#ifdef SYSV
  1150. X#include <sys/utsname.h>
  1151. X#endif /* SYSV */
  1152. X
  1153. Xvoid
  1154. Xinit()
  1155. X{
  1156. X    char         *home, *realname, *argv[4];
  1157. X    extern char        *getlogin();
  1158. X    char        buf[MAXPATHLEN];
  1159. X#ifdef SYSV
  1160. X    extern struct passwd *getpwuid();  /* sys-v forgot this in pwd.h! */
  1161. X    struct utsname ourhost;
  1162. X#else
  1163. X    char ourhost[128];
  1164. X#endif /* SYSV */
  1165. X    register char     *p;
  1166. X    struct passwd     *entry;
  1167. X    int            cnt;
  1168. X#ifdef BSD
  1169. X    struct hostent     *hp;
  1170. X#endif /* BSD */
  1171. X
  1172. X    home = getenv("HOME");
  1173. X    if (realname = getenv("NAME")) {
  1174. X    (void) strcpy(buf, realname);
  1175. X    }
  1176. X    argv[1] = "=";
  1177. X    argv[3] = NULL;
  1178. X
  1179. X    if (!(entry = getpwuid(getuid())))
  1180. X    if (p = getlogin())
  1181. X        strdup(login, p);
  1182. X    else {
  1183. X        login = "unknown";
  1184. X        print("I don't know you, but that's ok.\n");
  1185. X    }
  1186. X    else {
  1187. X    strdup(login, entry->pw_name);
  1188. X    if (!home || !*home)
  1189. X        home = entry->pw_dir;
  1190. X    if (!realname && (realname = entry->pw_gecos)) {
  1191. X        if (p = index(realname, ','))
  1192. X        *p = 0;
  1193. X        for (p = buf; *realname; realname++)
  1194. X        if (*realname == '&')
  1195. X            *p++ = upper(*login), p += Strcpy(p, login+1);
  1196. X        else
  1197. X            *p++ = *realname;
  1198. X        *p = 0;
  1199. X    }
  1200. X    endpwent();
  1201. X    }
  1202. X    if (!home || !*home || Access(home, W_OK)) {
  1203. X    if (home && *home)
  1204. X        error(home);
  1205. X    else
  1206. X        print("No home!? ");
  1207. X    print_more("Using \"%s\" as home.\n", ALTERNATE_HOME);
  1208. X    } else {
  1209. X    argv[0] = "home";
  1210. X    argv[2] = home;
  1211. X    (void) add_option(&set_options, argv);
  1212. X    }
  1213. X    if (realname) {
  1214. X    /* realname has already been copied to buf */
  1215. X    argv[0] = "realname";
  1216. X    argv[2] = buf;
  1217. X    (void) add_option(&set_options, argv);
  1218. X    }
  1219. X    crt = 24;
  1220. X    screen = 18;
  1221. X    wrapcolumn = 0; /* Default is no wrap */
  1222. X    escape = DEF_ESCAPE;
  1223. X    prompt = DEF_PROMPT;
  1224. X
  1225. X#ifdef BSD
  1226. X    (void) gethostname(ourhost, sizeof ourhost);
  1227. X    if (!(hp = gethostbyname(ourhost))) {
  1228. X    error("gethostbyname: %s", ourhost);
  1229. X    if (ourname = (char **)calloc((unsigned)2, sizeof (char *)))
  1230. X        strdup(ourname[0], ourhost);
  1231. X    } else {
  1232. X    int n = 0;
  1233. X    cnt = 2; /* 1 for ourhost and 1 for NULL terminator */
  1234. X    for (p = hp->h_name; p && *p; p = hp->h_aliases[n++])
  1235. X        if (strcmp(ourhost, p)) /* if host name is different */
  1236. X        cnt++;
  1237. X    if (ourname = (char **)calloc((unsigned)cnt, sizeof (char *))) {
  1238. X        ourname[--cnt] = NULL;
  1239. X        for (p = hp->h_name; p && *p && n >= 0; p = hp->h_aliases[--n])
  1240. X        if (strcmp(ourhost, p)) /* if host name is different */
  1241. X            ourname[--cnt] = savestr(p);
  1242. X        strdup(ourname[0], ourhost); /* cnt better be 0! */
  1243. X    }
  1244. X    }
  1245. X#endif /* BSD */
  1246. X#ifdef SYSV
  1247. X    if (ourname = (char **)calloc((unsigned)2, sizeof (char *))) {
  1248. X    if ((uname (&ourhost) >= 0) && (*ourhost.nodename))
  1249. X        ourname[0] = savestr(ourhost.nodename);
  1250. X    else {
  1251. X        /* Try to use uuname -l to get host's name if uname didn't work */
  1252. X        char buff[50];
  1253. X        char *p;
  1254. X        FILE *F;
  1255. X
  1256. X        if (F = popen("exec uuname -l", "r")) {
  1257. X        if ((fgets(buff, sizeof buff, F) == buff) &&
  1258. X            (p = strchr(buff, '\n'))) {
  1259. X            *p = '\0';        /* eliminate newline */
  1260. X            ourname[0] = savestr (buff);
  1261. X        }
  1262. X        (void)pclose(F);
  1263. X        }
  1264. X    }
  1265. X    }
  1266. X#endif /* SYSV */
  1267. X    if (ourname && ourname[0]) {
  1268. X    for (p = buf, cnt = 0; ourname[cnt]; cnt++) {
  1269. X        if (cnt)
  1270. X        *p++ = ' ';
  1271. X        p += Strcpy(p, ourname[cnt]);
  1272. X    }
  1273. X    argv[0] = "hostname";
  1274. X    argv[2] = buf;
  1275. X    (void) add_option(&set_options, argv);
  1276. X    }
  1277. X
  1278. X    init_bindings();
  1279. X}
  1280. X
  1281. X/*
  1282. X * Source a file, or just the default file.  Since sourcing files
  1283. X * means reading possible aliases, don't expand the ! as history
  1284. X * by setting the IGN_BANG flag.  Since a command in the sourced file
  1285. X * may call source on another file, this routine may be called from
  1286. X * within itself.  Continue to ignore ! chars by setting save_bang (local).
  1287. X *
  1288. X * Try opening the file passed to us.  If not given, check for the correct
  1289. X * .rc file which is found in the user's home dir.
  1290. X *
  1291. X * return -1 for filesystem errors, -2 for attempting to read a directory.
  1292. X */
  1293. Xsource(argc, argv)
  1294. Xchar **argv;
  1295. X{
  1296. X    register char *p;
  1297. X    FILE      *fp;
  1298. X    char       file[MAXPATHLEN];
  1299. X    u_long      save_bang = ison(glob_flags, IGN_BANG);
  1300. X    int          line_no = 0;
  1301. X
  1302. X    if (argc && *++argv && !strcmp(*argv, "-?"))
  1303. X    return help(0, "source", cmd_help);
  1304. X    if (argc && *argv)
  1305. X    (void) strcpy(file, *argv);
  1306. X    else if ((p = getenv("MUSHRC")) && *p || (p = getenv("MAILRC")) && *p)
  1307. X    (void) strcpy(file, p);
  1308. X    else {
  1309. X    char *home = do_set(set_options, "home");
  1310. X    if (!home || !*home)
  1311. X        home = ALTERNATE_HOME;
  1312. X    if (Access(sprintf(file, "%s/%s", home, MAILRC), R_OK)
  1313. X        && Access(sprintf(file, "%s/%s", home, ALTERNATE_RC), R_OK))
  1314. X        if (argc || argv)
  1315. X        (void) strcpy(file, DEFAULT_RC);
  1316. X        else
  1317. X        return -1;
  1318. X    }
  1319. X
  1320. X    argc = 0; /* don't ignore ENOENT */
  1321. X    p = getpath(file, &argc);
  1322. X    /* Try the ALT_DEF_RC if DEFAULT_RC fails */
  1323. X    if (argc && !strcmp(file, DEFAULT_RC)) {
  1324. X    argc = 0; /* don't ignore ENOENT */
  1325. X    (void) strcpy(file, ALT_DEF_RC);
  1326. X    p = getpath(file, &argc);
  1327. X    }
  1328. X    if (argc) {
  1329. X    /* Don't print error messages for missing default files */
  1330. X    if (strcmp(file, ALT_DEF_RC))
  1331. X        if (argc == -1) {
  1332. X        print("%s: %s\n", file, p);
  1333. X        return -1;
  1334. X        } else {
  1335. X        print("%s is a directory.\n", file);
  1336. X        return -2;
  1337. X        }
  1338. X    return -1;
  1339. X    }
  1340. X    if (!(fp = fopen(p, "r"))) {
  1341. X    if (errno != ENOENT)
  1342. X        error("Can't open %s", p);
  1343. X    return -1;
  1344. X    }
  1345. X    turnon(glob_flags, IGN_BANG); /* ignore ! when reading record files */
  1346. X    (void) strcpy(file, p);
  1347. X    (void) src_parse(file, fp, 0, 0, &line_no);
  1348. X    /* if we entered the routine ignoring !, leave it that way. */
  1349. X    if (!save_bang)
  1350. X    turnoff(glob_flags, IGN_BANG);
  1351. X    /* Sourcing might change things, so abort pipes/macros */
  1352. X    return 0 - (in_pipe() || in_macro());
  1353. X}
  1354. X
  1355. X/*
  1356. X * Do the actual file parsing for source().  The first argument should
  1357. X * be the name of the file referenced by the second argument.  The third
  1358. X * argument is used for handling nested if_else_endif expressions.  The
  1359. X * fourth argument is used to keep track of the recursion depth, and the
  1360. X * last argument keeps track of the line number in the current file.
  1361. X *
  1362. X * This function calls itself recursively.  It also calls do_command(),
  1363. X * which may in turn call source() recursively.
  1364. X *
  1365. X * If-then-else nesting algorithm:
  1366. X *  On any "if" (whether parsing or not), increment if_else
  1367. X *  On true "if" when parsing, evaluate by recursion
  1368. X *  On false "if" when parsing, set find_else equal to if_else
  1369. X *  On any "if" when not parsing, set find_endif equal to if_else
  1370. X *  On "else", invert parsing only when find_else equals if_else
  1371. X *  When "if" was false and there is nesting, recur for "else"
  1372. X *  Skip nested "if...endif" when find_else or find_endif true
  1373. X *  On "endif" or when recursion returns, decrement if_else
  1374. X *  On "endif", test both find_endif and find_else against if_else:
  1375. X *   when either matches, reset that one;
  1376. X *   when the lesser (less nested) matches, resume parsing
  1377. X *  On "endif", when if_else hits 0, continue (depth 0) or return
  1378. X */
  1379. Xsrc_parse(file, fp, if_else, depth, line_no)
  1380. Xchar    *file;
  1381. XFILE    *fp;
  1382. Xint      if_else, depth, *line_no;
  1383. X{
  1384. X    register char *p, *p2, **newargv;
  1385. X    static int    exited;
  1386. X    int       parsing = 1, cont_line = 0;
  1387. X    int          find_else = 0, find_endif = 0;
  1388. X    char       line[BUFSIZ];
  1389. X    int          argc;
  1390. X
  1391. X    exited = 0;
  1392. X
  1393. X    while (p = fgets(&line[cont_line], BUFSIZ - cont_line, fp)) {
  1394. X    (*line_no)++;
  1395. X    if (*(p2 = no_newln(p)) == '\\') {
  1396. X        *p2++ = ' ';
  1397. X        cont_line = p2 - line;
  1398. X        continue;
  1399. X    } else
  1400. X        cont_line = 0;
  1401. X    /* don't consider comments (#) in lines. check if # is within quotes */
  1402. X    if (p = any(line, "\"'#\\")) {
  1403. X        register int balanced = 1;
  1404. X        do {
  1405. X        if (*p == '\\' && p[1])
  1406. X            p = any(p+2, "\"'#\\");
  1407. X        else if (*p != '#') {
  1408. X            /* first find matching quote */
  1409. X            register char *quote = index(p+1, *p);
  1410. X            if (!quote) {
  1411. X            print("%s: line %d: unbalanced %c.\n",
  1412. X                file, *line_no, *p);
  1413. X            balanced = 0;
  1414. X            } else
  1415. X            p = any(quote+1, "\"'#\\");
  1416. X        }
  1417. X        } while (p && *p != '#' && balanced);
  1418. X        if (!balanced)
  1419. X        continue;
  1420. X        if (p && *p == '#')
  1421. X        *p = 0; /* found a Comment: null terminate line at comment */
  1422. X    }
  1423. X    if (!*line || !parsing && !(newargv = mk_argv(line, &argc, 0))
  1424. X    || parsing && !(newargv = make_command(line, TRPL_NULL, &argc))) {
  1425. X        if (!strncmp(line, "if", 2))
  1426. X        find_else = ++if_else, parsing = FALSE;
  1427. X        continue;
  1428. X    }
  1429. X    if (!strcmp(newargv[0], "endif")) {
  1430. X        if (!if_else)
  1431. X        print("%s: line %d: endif with no \"if\".\n", file, *line_no);
  1432. X        else {
  1433. X        /* If looking for an else or endif, reset parsing */
  1434. X        if (find_endif && find_endif == if_else) {
  1435. X            if (find_endif <= find_else || !find_else)
  1436. X            parsing = 1, find_else = 0;
  1437. X            find_endif = 0;
  1438. X        }
  1439. X        /* Note: find_else never < find_endif */
  1440. X        if (find_else && find_else == if_else)
  1441. X            parsing = !parsing, find_else = 0;
  1442. X        /* Decrement if_else and check depth */
  1443. X        if (--if_else == 0)
  1444. X            /* Resume parsing if at the top */
  1445. X            if (depth == 0)
  1446. X            parsing = 1;
  1447. X            /* Return if not at the top */
  1448. X            else
  1449. X            return 1;
  1450. X        }
  1451. X        goto bad;
  1452. X    } else if (!strcmp(newargv[0], "else")) {
  1453. X        if (!if_else)
  1454. X        print("%s: line %d: if-less \"else\".\n", file, *line_no);
  1455. X        /* If inside an else, ignore nested else;
  1456. X         *  otherwise, recur when if_else > 1 */
  1457. X        else if (!find_else && !find_endif && !parsing) {
  1458. X        parsing = src_parse(file, fp, 1, depth + 1, line_no);
  1459. X        --if_else;
  1460. X        } else if (find_else == if_else || if_else == 1) {
  1461. X        find_else = 0;
  1462. X        parsing = !parsing;
  1463. X        if (!parsing)
  1464. X            find_endif = if_else;
  1465. X        }
  1466. X        goto bad;
  1467. X    } else if (!strcmp(newargv[0], "if")) {
  1468. X        /* if statements are of the form:
  1469. X         *     if expr
  1470. X         *     if !expr  or  if ! expr
  1471. X         *     if expr == expr   or   if expr != expr
  1472. X         */
  1473. X        int equals = TRUE, pattern = FALSE;
  1474. X        register char *lhs = newargv[1], *rhs = NULL;
  1475. X
  1476. X        if_else++;
  1477. X        /* If parsing, set parsing to 0 until
  1478. X         *  evaluating the "if" proves otherwise.
  1479. X         * If not parsing, skip to the "endif".
  1480. X         */
  1481. X        if (parsing)
  1482. X        parsing = 0;
  1483. X        else {
  1484. X        if (!find_endif)
  1485. X            find_endif = if_else;
  1486. X        goto bad;
  1487. X        }
  1488. X        if (!lhs || !*lhs) {
  1489. X        print("%s: line %d: if what?\n", file, *line_no);
  1490. X        goto bad;
  1491. X        }
  1492. X        /* "lhs" is the left hand side of the equation
  1493. X         * In this instance, we're doing case 2 above (check for negation).
  1494. X         */
  1495. X        if (*lhs == '!') {
  1496. X        if (!*++lhs && !(lhs = newargv[2])) {
  1497. X            print("%s: line %d: syntax error: \"if ! <what?>\"\n",
  1498. X            file, *line_no);
  1499. X            goto bad;
  1500. X        }
  1501. X        equals = FALSE;
  1502. X        }
  1503. X        if (*lhs == '-' && (lhs[1] == 'e' || lhs[1] == 'z') && !lhs[2]) {
  1504. X        char *path;
  1505. X        int n = 1; /* ignore ENOENT, I'll handle it here */
  1506. X        struct stat statb;
  1507. X
  1508. X        /* check for existence or zero-length folders/files */
  1509. X        if (argc > 3 + (!equals)) {
  1510. X            print("%s: line %d: if %s \"filename\"\n",
  1511. X            file, *line_no, lhs);
  1512. X            goto bad;
  1513. X        }
  1514. X        path = getpath(newargv[argc-1], &n);
  1515. X        parsing = !equals ^ (n == -1 || n == 1 && lhs[1] == 'e' ||
  1516. X            !stat(path, &statb) && (lhs[1] == 'e' || !statb.st_size));
  1517. X        } else {
  1518. X        if (equals && argc > 2) {
  1519. X            if (argc != 4) {
  1520. X            print("%s: %d: argument count error: %d args.\n",
  1521. X                file, *line_no, argc);
  1522. X            goto bad;
  1523. X            }
  1524. X            /* now check newargv[2] for == or != or =~ or !~ */
  1525. X            if (!strcmp(newargv[2], "!=") ||
  1526. X                (pattern = !strcmp(newargv[2], "!~")))
  1527. X            equals = !equals;
  1528. X            else if (!strcmp(newargv[2], "=~"))
  1529. X            pattern = TRUE;
  1530. X            else if (strcmp(newargv[2], "==")) {
  1531. X            print("%s: %d: use `==' or `!=' only.\n",
  1532. X                file, *line_no);
  1533. X            goto bad;
  1534. X            }
  1535. X            rhs = newargv[3];
  1536. X        }
  1537. X        if (rhs) {
  1538. X            /* Some fun tricks with booleans here.
  1539. X             * Extra ! ops make sure all == are on 0 or 1;
  1540. X             * aside from that, we want (glob == equals)
  1541. X             * or (!strcmp == equals).  Make sense?  
  1542. X             */
  1543. X            if (pattern && !glob(lhs,rhs) == !equals)
  1544. X            parsing = 1;
  1545. X            else if (!pattern && !strcmp(lhs, rhs) == !!equals)
  1546. X            parsing = 1;
  1547. X        } else if (isdigit(*lhs))
  1548. X            parsing = !!(atoi(lhs) ? equals : !equals);
  1549. X        else if (!strcmp(lhs, "redirect") && (!isatty(0) != !equals)
  1550. X              /* (ison(glob_flags, REDIRECT) && equals ||
  1551. X               isoff(glob_flags, REDIRECT) && !equals) */
  1552. X            || !strcmp(lhs, "is_shell") && (!is_shell == !equals)
  1553. X            || !strcmp(lhs, "is_sending") &&
  1554. X              (ison(glob_flags, IS_SENDING) && equals ||
  1555. X               isoff(glob_flags, IS_SENDING) && !equals)
  1556. X            || !strcmp(lhs, "hdrs_only") &&
  1557. X              (hdrs_only && equals || !hdrs_only && !equals)
  1558. X            || !strcmp(lhs, "istool") &&
  1559. X              (istool && equals || !istool && !equals)
  1560. X            || !strcmp(lhs, "iscurses") &&
  1561. X              ((iscurses || ison(glob_flags, PRE_CURSES)) && equals
  1562. X              || (isoff(glob_flags, PRE_CURSES) &&
  1563. X                  !iscurses && !equals)))
  1564. X            parsing = 1;
  1565. X        }
  1566. X        if (parsing) {
  1567. X        parsing = src_parse(file, fp, 1, depth + 1, line_no);
  1568. X        --if_else;
  1569. X        }
  1570. X        else
  1571. X        find_else = if_else; /* Look for a matching else */
  1572. Xbad:
  1573. X        free_vec(newargv);
  1574. X        continue;
  1575. X    }
  1576. X    if (parsing && argc > 0)
  1577. X        if (!strcmp(newargv[0], "exit")) {
  1578. X        if_else = find_else = find_endif = 0;
  1579. X        exited = 1;
  1580. X        break;
  1581. X        } else {
  1582. X        (void) do_command(argc, newargv, msg_list);
  1583. X        exited = 0;
  1584. X        }
  1585. X    else
  1586. X        free_vec(newargv);
  1587. X    }
  1588. X    if (if_else && !exited)
  1589. X    print("%s: missing endif\n", file);
  1590. X    if (depth == 0)
  1591. X    (void) fclose(fp);
  1592. X    else
  1593. X    (void) fseek(fp, 0L, 2); /* Skip ahead to the end */
  1594. X    return 0;
  1595. X}
  1596. END_OF_FILE
  1597. if test 13422 -ne `wc -c <'mush/init.c'`; then
  1598.     echo shar: \"'mush/init.c'\" unpacked with wrong size!
  1599. fi
  1600. # end of 'mush/init.c'
  1601. fi
  1602. echo shar: End of archive 4 \(of 19\).
  1603. cp /dev/null ark4isdone
  1604. MISSING=""
  1605. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ; do
  1606.     if test ! -f ark${I}isdone ; then
  1607.     MISSING="${MISSING} ${I}"
  1608.     fi
  1609. done
  1610. if test "${MISSING}" = "" ; then
  1611.     echo You have unpacked all 19 archives.
  1612.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1613. else
  1614.     echo You still need to unpack the following archives:
  1615.     echo "        " ${MISSING}
  1616. fi
  1617. ##  End of shell archive.
  1618. exit 0
  1619.  
  1620.