v13i047: xmail, Part05/11

Michael Wagnitz stratus!voder!nsc!berlioz.nsc.com!michael at uunet.UU.NET
Sun Jun 16 05:44:38 AEST 1991


Submitted-by: stratus!voder!nsc!berlioz.nsc.com!michael at uunet.UU.NET (Michael Wagnitz)
Posting-number: Volume 13, Issue 47
Archive-name: xmail/part05

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 5 (of 11)."
# Contents:  HelpText.c parser.c
# Wrapped by michael at harley on Fri May  3 13:35:51 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'HelpText.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'HelpText.c'\"
else
echo shar: Extracting \"'HelpText.c'\" \(17221 characters\)
sed "s/^X//" >'HelpText.c' <<'END_OF_FILE'
X/*
X * xmail - X window system interface to the mail program
X *
X * Copyright 1990 by National Semiconductor Corporation
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose is hereby granted without fee, provided that
X * the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of National Semiconductor Corporation not
X * be used in advertising or publicity pertaining to distribution of the
X * software without specific, written prior permission.
X *
X * NATIONAL SEMICONDUCTOR CORPORATION MAKES NO REPRESENTATIONS ABOUT THE
X * SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE.  IT IS PROVIDED "AS IS"
X * WITHOUT EXPRESS OR IMPLIED WARRANTY.  NATIONAL SEMICONDUCTOR CORPORATION
X * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
X * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO
X * EVENT SHALL NATIONAL SEMICONDUCTOR CORPORATION BE LIABLE FOR ANY SPECIAL,
X * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
X * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
X * OR OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
X * PERFORMANCE OF THIS SOFTWARE.
X *
X * Author:  Michael C. Wagnitz - National Semiconductor Corporation
X *
X */
X
X#include	"global.h"
X
X
XString	Autograph_Info[] = {
X		"Append your .mailrc Sign (~A) autograph (if any)",
X		"Append your .mailrc sign (~a) autograph (if any)",
X		NULL
X		};
X
XString	Copy_Info[] = {
X                "Copy the selected message to the specified folder",
X                "Copy the message to a folder named for it's author",
X                NULL
X                };
X
XString	Default_Status_Info = "Use <Shift><Middle-Mouse-Button> for help on any window";
X
XString	Delete_Info[] = {
X                "Delete the currently selected message",
X                "Undelete the selected or most recently deleted message",
X                NULL
X                };
X
XString	Deliver_Info[] = {
X		"Deliver this message",
X		"Re-edit this message",
X		"Cancel the request but save the text in the dead letter file",
X		"Abort this request and discard the text",
X		NULL
X		};
X
XString	Folder_Info[] = {
X		"Access the specified folder, or select from the list",
X		"Copy this folder name to the fileWindow",
X		"Copy the folder path to the fileWindow or view the next level",
X		NULL
X		};
X
XString	Hold_Info[] = {
X                "Preserve the selected message in the system folder",
X                NULL
X                };
X
XString	NewMail_Info[] = {
X                "Re-read your system mail folder",
X                "Incorporate new mail without committing any current changes",
X                "Make xmail refresh the folder list next time it's displayed",
X                NULL
X                };
X
XString	Print_Info[] = {
X                "Print the selected message on the system printer",
X                NULL
X                };
X
XString	Quit_Info[] = {
X                "Quit xmail",
X                "Leave xmail without committing any current changes",
X                NULL
X                };
X
XString	Read_Info[] = {
X                "Read the current message",
X                "Read the next message",
X                "Read the previous message",
X                "Read the current message, and include full mail headers",
X                NULL
X                };
X
XString	Reply_Info[] = {
X                "Reply to the author of the message",
X                "Reply to the author of, and include the message text",
X                "Include all recipients of the original message in your reply",
X                "Include all recipients, and the text, of this message",
X                NULL
X                };
X
XString	Save_Info[] = {
X                "Save the selected message in the specified folder",
X                "Save the message in a folder named for it's author",
X                "Write the message to the folder, but don't include headers",
X                NULL
X                };
X
XString	Send_Info[] = {
X                "Compose and send a new mail message",
X                "Forward a copy of the selected mail message",
X                NULL
X                };
X
XString	SendMail_Info[] = {
X		"Specify the name(s) of the recipient(s)",
X		"Enter the subject of this message",
X		"Specify the names of any carbon copy recipients",
X		"Enter the names of any blind carbon copy recipients",
X		NULL
X		};
X
XString Abort_Help = "\
XPressing the \"Abort\" button cancels delivery of the\n\
Xmessage, and deletes any text that may have been created.";
X
XString	Bcc_Help = "\
XSpecify any blind carbon copy recipients for this message\n\
Xusing the Bcc: window.  Blind carbon recipient names are\n\
Xremoved from the message prior to delivery.\n\n\
XPressing the right mouse button in this window displays\n\
Xa list of your aliases.  Releasing the right mouse\n\
Xbutton while one of the alias names is highlighted\n\
Xcopies that name into the window, preceding it with a\n\
Xcomma if necessary.\n\n\
XStandard editing functions associated with the text widget\n\
Xare supported, and can be altered using the application\n\
Xresources.";
X
XString Cancel_Help = "\
XPressing the \"Cancel\" button causes delivery of this\n\
Xmessage to be abandoned, but saves a copy of the message\n\
Xtext in your dead letter file (default $HOME/dead.letter)\n\
Xwithout any header information.";
X
XString	Cc_Help = "\
XSpecify carbon copy recipients for this message using the\n\
XCc: window.  Multiple recipients should be comma separated.\n\n\
XPressing the right mouse button in this window displays a\n\
Xlist of your aliases.  Releasing the right mouse button\n\
Xwhile one of the alias names is highlighted copies that\n\
Xname into this window, preceded with a comma if needed.\n\n\
XStandard editing functions associated with the text widget\n\
Xare supported, and can be altered using the application\n\
Xresources.";
X
XString	Copy_Help = "\
XPressing this button copies the current message to the\n\
Xfile or folder named in the File: window, without marking\n\
Xthe original for removal.  (If a folder name is not\n\
Xspecified, it will be copied to your mbox folder.)\n\n\
XThe right mouse button pops up a menu for both the copy\n\
Xand Copy commands.\n\n\
XThe uppercase (Copy) command copies the message to a file\n\
Xwhose name is derived from the author of the message,\n\
Xrather than from any name currently in the File: window.\n\n\
XSee also the save command help for additional information.";
X
XString	Delete_Help = "\
XPressing this button removes the selected message from the\n\
Xcurrent folder.\n\n\
XThe right mouse button displays a menu for both the delete\n\
Xand undelete commands.\n\n\
XUndelete restores the selected message (if it has been\n\
Xmarked 'D'eleted), otherwise the deleted message with the\n\
Xsmallest message number is restored.\n\n\
XUndelete may be used repeatedly to restore all deleted\n\
Xmessages if changes have not yet been committed.\n\n\
XSee also preserve, save, folder, Newmail, and quit.";
X
XString	Deliver_Help = "\
XThe Deliver button will ship the composed message text\n\
Xto the sendmail daemon for delivery to the specified\n\
Xrecipients.";
X
XString	File_Help = "\
XThe File: window provides a mechanism for specifying a\n\
Xfile or folder name for use by other xmail commands.\n\n\
XText entered beyond the right margin of the window will\n\
Xcause a horizontal scrollbar to appear, for scrolling the\n\
Xdisplayed text to the left or right as needed for viewing.\n\n\
XPressing the backspace or delete key erases a previously\n\
Xentered character.  Control_W (^W) erases a previous word\n\
Xand Control_U (^U) the entire line.\n\n\
XSee the folder and save commands for more information.";
X
XString	Folder_Help = "\
XThe left button changes the active folder to the one\n\
Xspecified in the File: window.  Changing folders COMMITs\n\
Xany modifications to the current folder.\n\n\
XThe right button brings up a menu of folders from which\n\
Xto choose.  Clicking the left button on a directory\n\
X(indicated by trailing slash) while still holding down\n\
Xthe right, expands that directory if it has files.\n\
XReleasing the right button copies the selected name to\n\
Xthe File: window.\n\n\
XThe current menu can be erased (to include new folders\n\
Xcreated since the menu was last generated) by using the\n\
XDrop option, provided in the Newmail command button menu.";
X
XString	Hold_Help = "\
XThe Preserve command marks the selected message for\n\
Xretention in the system mailbox.  Normally when a message\n\
Xis 'saved' to some other folder file, it is automatically\n\
Xdeleted from your system folder.  'Preserve' causes mail\n\
Xto not remove the original from your system mail folder.\n\n\
XPressing the right mouse button on the Preserve command\n\
Xpresents a menu of three mail (and one xmail) settings\n\
Xthat may be toggled while currently operating in xmail.\n\n\
XCommands listed denote what state each variable will be\n\
Xchanged to, if the appropriate label is highlighted when\n\
Xthe right mouse button is released.";
X
XString	Index_Help = "\
XThe index window displays a list of mail messages in the\n\
Xcurrent folder, as well as the currently selected message.\n\n\
XPressing the left mouse button anywhere on a line marks\n\
Xthe message as selected (for other commands) but does not\n\
Xautomatically display the message in the text window.\n\n\
XPressing the right button selects and also automatically\n\
Xdisplays the message.\n\
XSee also the read command help for additional information.\n\n\
XThe index window header list may be scrolled using either\n\
Xthe scrollbar and mouse or keyboard keys.  See the Text\n\
Xwindow help for a description of the keys supported.";
X
XString	NewMail_Help = "\
XThe Newmail button will be highlighted with a hatching\n\
Xpattern whenever new mail has arrived for your account.\n\n\
XPressing the NewMail button accesses your system folder\n\
X(if mail exists) and includes any new mail delivered\n\
Xsince the last time your system folder was accessed.\n\
XThis action also resets any button highlighting, and\n\
XCOMMITS any changes that may have been made to the\n\
Xcurrent folder.  (Confirmation provided if not expert.)\n\n\
XThe right mouse button provides a menu for committing\n\
Xchanges, incorporating new messages without committing\n\
Xchanges (only if currently in your system folder), or\n\
Xcausing xmail to redetermine the list of mail folders.";
X
XString	Print_Help = "\
XPressing this button causes the selected message to be\n\
Xprinted on the system printer.\n\n\
XA message will be displayed in the status window\n\
Xindicating which message was printed, along with its\n\
Xsize in bytes.\n\n\
XSee also the Index window for help on selecting a message.";
X
XString	Quit_Help = "\
Xquit - terminates xmail, committing changes made to the\n\
Xcurrent folder.\n\n\
XThe right mouse button pops up a menu for the quit and\n\
Xexit commands.\n\n\
XUse exit when you wish to leave xmail without committing\n\
Xthe current folder's changes.\n\n\
XSee also the folder, Newmail, and delete commands.";
X
XString	Read_Help = "\
XPressing this button causes the selected message to be\n\
Xdisplayed in the text (bottom) window.\n\n\
XCurrent message selection is indicated by caret (>) in\n\
Xthe index (top) window.\n\n\
XThe right mouse button displays a menu for reading the\n\
Xcurrent message, reading the next or previous message,\n\
Xor reading the selected message with full headers (this\n\
Xoverrides any suppression of normally ignored fields).\n\n\
XSee also the Index window help for more information.";
X
XString ReEdit_Help = "\
XUse the ReEdit selection to perform additional changes\n\
Xto the current message composition.  When completed, you\n\
Xwill again be presented with the send completion menu.";
X
XString	Reply_Help = "\
Xreply - initiates the mechanism to create and send a mail\n\
Xmessage to the author of a current message.\n\n\
XThe right mouse button displays a menu for selecting\n\
X'reply', 'reply included', 'replyall' (which addresses all\n\
Xrecipients of the original mail), or 'replyall included'.\n\
XThe include options automatically copy the original\n\
Xmessage into the new one.\n\nSee also the Send command.";
X
XString	Save_Help = "\
Xsave - copies a message to the file or folder named in\n\
Xthe File: window, marking the original for deletion.\n\
XIf none is specified, the name in your environment MBOX\n\
Xis used ($HOME/mbox by default).\n\n\
XThe right button pops up a menu of related commands.\n\n\
XA written (vs. copied) message does not include mail\n\
Xheaders or trailing blank line.\n\n\
XUppercase commands create a file named from the author of\n\
Xthe message, rather than any name in the File: window.";
X
XString	Send_Help = "\
Xsend - initiates the mechanism to create and send a\n\
Xmessage to the designated recipient(s).  The right mouse\n\
Xbutton displays a menu which provides the choice of\n\
X'send'ing, or 'forwarding a message'.  Forwarding includes\n\
Xthe text of the current message in the new one.\n\n\
XAs with the 'reply' command, a dialog box is provided to\n\
Xspecify the name of the recipient(s), subject, and to whom\n\
Xto send copies of this message.  Pressing the 'Deliver'\n\
Xbutton completes the operation.\n\n\
XSee also the reply command help for additional information.";
X
XString	Sign_Help = "\
XYou may append your .mailrc defined Sign[ature] (uppercase)\n\
X'S' string to the message composition by pressing this button.\n\n\
XSee Mail(1) man page documentation for more information on\n\
Xautograph strings and .mailrc files.";
X
XString	sign_Help = "\
XYou may append your .mailrc defined sign[ature] (lowercase)\n\
Xstring to the message composition by pressing this button.\n\n\
XSee Mail(1) man page documentation for more information on\n\
Xautograph strings and .mailrc files.";
X
XString	Status_Help = "\
XThe Status window displays xmail program info, status, and\n\
Xerror messages.\n\n\
XError messages usually cause the terminal bell to ring, to\n\
Xattract the user's attention.\n\n\
XThe BELL can be disabled, by either including the command\n\
Xline option -nb, or by specifying the '*bellRing' resource\n\
Xas False.";
X
XString	Subject_Help = "\
XThe Subject: window provides a method for specifying the\n\
Xsubject for this mail message.\n\n\
XText entered beyond the right margin of the window will\n\
Xcause a horizontal scrollbar to appear, for scrolling the\n\
Xdisplayed text to the left or right as needed for viewing.\n\n\
XPressing the backspace or delete key erases a previously\n\
Xentered character, while Control_W (^W) erases the previous\n\
Xword and Control_U (^U) the entire line.";
X
XString	Text_Help = "\
XThe text window displays the currently selected message.\n\
XSee the Index window help on how to select a message.\n\n\
XText and index windows may be scrolled using either the\n\
Xmouse and scrollbar, or the keyboard keys in the manner\n\
Xof text display programs such as \"more\" and \"less\".\n\n\
Xspacebar - scroll down a page      b - scroll up a page\n\
Xreturn   - scroll down a line      k - scroll up a line\n\
X  G      - go to end of text       ' - go to top of text\n\n\
XThe both windows also support keyboard access to each of\n\
Xthe command buttons.  See the xmail man page for details\n\
Xor press the question mark key (?) within the text window.";
X
XString	Text2_Help = "\
XKeyboard key defaults that duplicate command button actions:\n\n\
X a - REPLY to all recipients    A  - REPLY to all included\n\
X c - COPY a message             C  - COPY to Author file\n\
X d - DELETE the message         u  - UNDELETE a message\n\
X f - READ with full headers     F  - FORWARD a message\n\
X m - MAIL a message             M  - REPLY to a message\n\
X i - incorporate NEW MAIL       N  - retrieve NEW MAIL\n\
X p - read PREVIOUS message      P  - PRINT a message\n\
X r - READ the message           R  - REPLY included\n\
X s - SAVE current message       S  - SAVE to author\n\
X n - read the NEXT message      w  - WRITE current message\n\
X q - QUIT, committing changes   x  - EXIT, no commits\n\
X ? - DISPLAY this help info   <LF> - REMOVE this help info";
X
XString	Title_Help = "\
XThe Titlebar window displays the xmail program name and the\n\
Xcurrent version number, along with the name of the current\n\
Xmail folder being accessed, and its message count(s).\n\n\
XPressing the left mouse button on the National Semiconductor\n\
XCorporation logo in the top left corner of the title bar\n\
Xissues an XLib request to iconify this xmail application.";
X
XString	To_Help = "\
XUse the To: window to specify the recipients for this mail\n\
Xmessage.  Text entered beyond the right margin of the\n\
Xwindow will cause a horizontal scrollbar to appear, for\n\
Xscrolling the displayed text to the left or right as needed\n\
Xfor viewing. Pressing the backspace or delete key erases a\n\
Xpreviously entered character, while Control_W (^W) erases\n\
Xthe previous word and Control_U (^U) the entire line.\n\n\
XPressing the right mouse button in this window displays a\n\
Xlist of your alias names.  Releasing the right mouse\n\
Xbutton while one of the names is highlighted will copy\n\
Xthat name into the window, prepending it with a comma if\n\
Xneeded.";
X
X/* HelpText */
END_OF_FILE
if test 17221 -ne `wc -c <'HelpText.c'`; then
    echo shar: \"'HelpText.c'\" unpacked with wrong size!
fi
# end of 'HelpText.c'
fi
if test -f 'parser.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'parser.c'\"
else
echo shar: Extracting \"'parser.c'\" \(17348 characters\)
sed "s/^X//" >'parser.c' <<'END_OF_FILE'
X/*
X * xmail - X window system interface to the mail program
X *
X * Copyright 1989 The University of Texas at Austin
X *
X * Author:	Po Cheung
X * Date:	March 10, 1989
X *
X * Permission to use, copy, modify, and distribute this software and
X * its documentation for any purpose and without fee is hereby granted,
X * provided that the above copyright notice appear in all copies and that
X * both that copyright notice and this permission notice appear in
X * supporting documentation.  The University of Texas at Austin makes no 
X * representations about the suitability of this software for any purpose.  
X * It is provided "as is" without express or implied warranty.
X *
X * Copyright 1990 by National Semiconductor Corporation
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose is hereby granted without fee, provided that
X * the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of National Semiconductor Corporation not
X * be used in advertising or publicity pertaining to distribution of the
X * software without specific, written prior permission.
X *
X * NATIONAL SEMICONDUCTOR CORPORATION MAKES NO REPRESENTATIONS ABOUT THE
X * SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE.  IT IS PROVIDED "AS IS"
X * WITHOUT EXPRESS OR IMPLIED WARRANTY.  NATIONAL SEMICONDUCTOR CORPORATION
X * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
X * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO
X * EVENT SHALL NATIONAL SEMICONDUCTOR CORPORATION BE LIABLE FOR ANY SPECIAL,
X * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
X * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
X * OR OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
X * PERFORMANCE OF THIS SOFTWARE.
X *
X * Author:  Michael C. Wagnitz - National Semiconductor Corporation
X *
X */
X
X#define	PARSER
X
X#include	"global.h"
X#include	"regex.h"
X#include	"xmailregex.h"
X
X#define		BYTEWIDTH	8
X#define		RE_BUFFER	100
X
Xextern void	reset_mailbox();
X
X/*
X**  @(#)compile() - regular expression patterns into a pattern table.
X**  A pattern table is an array of pattern records.
X**  Each pattern record consists of a regular expression,
X**  and a buffer for the to-be-compiled regular expression,
X*/
Xstatic void
Xcompile(patternTable)
XPatternRec *patternTable;
X{
X PatternRec	*p;
X char 	fastmap[(1 << BYTEWIDTH)];
X int		i;
X
X    for (i=0; patternTable[i].pat; i++) {
X	p = &patternTable[i];
X	p->buf = (struct re_pattern_buffer *) 
X	  XtMalloc (sizeof (struct re_pattern_buffer));
X	p->buf->allocated = RE_BUFFER;
X	p->buf->buffer = (char *) XtMalloc (p->buf->allocated);
X	p->buf->fastmap = fastmap;
X	p->buf->translate = NULL;
X	re_compile_pattern(p->pat, strlen(p->pat), p->buf);
X	re_compile_fastmap(p->buf);
X    }
X} 
X
X/*
X** @(#)match() - string against regular expressions in pattern table.
X** The best match is found, and function returns index to the pattern table.
X*/
Xint
Xmatch(patternTable, string)
XPatternRec 	*patternTable;
Xchar 	*string;
X{
X    int			m, bestmatch = -1, index = -1, i;
X
X    if (strcmp(string, "") == NULL) return -1;
X    for (i=0; patternTable[i].pat; i++) {
X	m = re_match(patternTable[i].buf, string, strlen(string), 0, NULL);
X	if (m > bestmatch) {
X	    bestmatch = m;
X	    index = i;
X	}
X    }
X    return index;
X}
X
X/*
X** @(#)parser_init()- compile output and command pattern tables.
X*/
Xvoid
Xparser_init()
X{
X compile(output_pattern);
X compile(command_pattern);
X}
X
X
X/*
X** @(#)parse() - command and output and call appropriate handler
X*/
Xvoid
Xparse(msg)
XString	msg;
X{
X Cardinal	j, k, msgnum;
X Widget		button, icon, iw;
X char		tmp[128], *c, *s;
X static	Boolean	first_time = True;
X
X
X j = match(command_pattern, Command);
X switch (j) {
X/*
X** If error on startup, mail has terminated connection.  Remove our input
X** handler, close the file from our end, and indicate that no connection
X** exists.  Otherwise, establish conversation requirements and display the
X** current message.  If *Show_Last: resource is NOT False, show latest, if
X** none are newer.  We delay setting the icon event handler until now, to
X** ensure mail startup completed before being interrupted by a map event,
X** for the case where we have been started iconic.
X*/
X    case C_START :  if (O_BELL == match(output_pattern, msg)) {
X                       if (mailpid) {
X                          XtRemoveInput(mailInputId);
X                          close(mail_fd);
X                          mailpid = 0;
X                         }
X		       LASTCH(msg) = '\0';    /* Don't ring Bell() for this */
X		       Bell(msg);
X		       (void) UpdateTitleBar("No current folder");
X                       XtFree(msg);
X		       *msg = '\0';
X                      } else {
X/*
X** To prevent a race condition (?) when starting the application iconic,
X** (which would cause this loop to repeat multiple times), test the value
X** of the ``screen'' mail environment variable.  If 10,000 then we're done.
X*/
X                       j = True;
X                       if (c = GetMailEnv("screen")) {
X                          j = (strcmp("10000", c) != 0) ? True : False;
X                          XtFree(c);
X                         }
X                       if (j) {			/* if not yet set to 10000... */
X                          strcpy(tmp, "set screen=10000 toplines=100 ");
X
X                          /* default action for xmail is hold (ala mailtool) */
X
X                          if (c = GetMailrc("nohold")) XtFree(c);
X                          else strcat(tmp, "hold");
X
X                          c = QueryMail(tmp);
X                          XtFree(c);
X
X                          strcpy(tmp, "unset crt replyall");
X
X                          c = QueryMail(tmp);
X                          XtFree(c);
X
X                          if (msgnum = file_handler()) {
X                             sprintf(tmp, "%d", msgnum);
X                             XtFree(msg);
X                             msg = QueryMail(tmp);
X                            }
X                          Bell("");		/* reset any worthy-ness flag */
X                          Bell(Default_Status_Info);
X                         }
X                      }
X                    if (first_time) {		/* only need to do this once */
X                       first_time = False;
X                       icon = XtNameToWidget(toplevel, "icon");
X                       XtAddEventHandler(icon, StructureNotifyMask, False,
X                                         icon_handler, NULL);
X                       if (In_Bogus_Mail_File) {
X                          unlink(sprintf(tmp, "%s+", tmpName));
X                          XtFree(msg);
X		          *msg = '\0';		/* ignore 'skipping' message */
X                         }
X                      }
X	            break;
X/*
X** In response to normal or change folder commands, test output.  If an
X** error, display message in status window, and ring bell unless command
X** was save, Save to author, or undelete.  If our current mail message
X** folder is the bogus folder, erase any text and index and note state.
X** If we have text of next mail message, tell index_handler to mark its
X** number, else retrieve the appropriate message text (which also marks
X** its number).  If *Show_Last: resource is NOT False, file cmd shows
X** latest, if none new.
X*/
X    case C_EXEC  :
X    case C_FILE  :  j = match(output_pattern, msg);
X		    switch (j) {
X		       case O_BELL  :
X		                      if (strchr("Ssu", *Command))
X		                         LASTCH(msg) = '\0';
X		                      Bell(msg);
X                                      XtFree(msg);
X/*
X** Save our current message number, because asking about our 'file' status
X** will reset mail's idea of the 'current message' count to one, regardless.
X*/
X                                      msgnum = SelectionNumber(False);
X/*
X** Now ask for 'file' status to determine if we are still caught in our 'bogus'
X** mailfile, in order to generate a more meaningful title-bar status message.
X*/
X                                      msg = QueryMail("file");
X                                      if (strncmp(&msg[1], tmpName, strlen(tmpName)) == 0) {
X		                         (void) UpdateTitleBar("No current folder");
X                                         iw = XtNameToWidget(toplevel, "topBox");
X                                         writeTo(XtNameToWidget(iw, "indexWindow"), " ");
X                                         writeTo(XtNameToWidget(iw, "textWindow.text"), " ");
X                                        } else {
X                                         (void) UpdateTitleBar(msg);
X                                         XtFree(msg);
X/*
X** If not in our bogus mail folder, reset the current message
X** number in Mail by again pointing at that numbered message.
X*/
X                                         sprintf(tmp, "f %d", msgnum);
X                                         msg = QueryMail(tmp);
X                                         if (strchr("Ss", *Command))
X                                            markIndex(">S");
X                                        }
X                                      XtFree(msg);
X                                      *msg='\0';
X                                      break;
X		       case O_EXEC  : msgnum = index_handler(0, 0);
X                                      break;
X		       case O_FILE  : msgnum = file_handler();
X		                      c = strchr(msg, '\n');
X		                      if ((int)(c - msg) < strlen(msg) - 1) {
X                                         *c = '\0';	/* don't bell this */
X					 Bell("");	/* clear worthy flag */
X					 Bell(msg);
X		                        }
X                                      XtFree(msg);
X                                      *msg = '\0';
X                                      if (msgnum) {
X                                         sprintf(tmp, "%d", msgnum);
X                                         msg = QueryMail(tmp);
X                                        }
X		                      break;
X	              }
X                    break;
X/*
X** When deleting a message, simply mark that index line with a capital 'D'.
X** If un-deleting, mark that index line with a blank ' '.  If no current
X** index, restore it.  If autoprinting, mail will include text of next msg.
X*/
X    case C_DELETE : if (O_BELL == match(output_pattern, msg)) {
X                       Bell(msg);
X                       XtFree(msg);
X                       *msg = '\0';
X                      } else {
X                       msgnum = SelectionNumber(False);
X                       if (*Command == 'd') {
X                          if (msgnum) {
X                             markIndex("D");
X		             msgnum = index_handler(msgnum+1, 0);
X                            }
X                         } else {		/* if we are 'undeleting' */
X		          c = QueryMail("=");
X		          sscanf(c, "%d", &msgnum);
X		          XtFree(c);
X                          iw = XtNameToWidget(toplevel, "topBox.indexWindow");
X                          if (TextGetLastPos(iw) < (XawTextPosition) 4) {
X                             c = QueryMail("h");
X                             writeTo(iw, c);
X		             XtFree(c);
X                            }
X		          msgnum = index_handler(msgnum, 1);
X                         }
X                       c = QueryMail("file");	/* resets current msg to 1 */
X                       (void) UpdateTitleBar(c);
X		       XtFree(c);
X
X                       if (msgnum == 0)	{	/* if was last msg in file */
X                          XtFree(msg);
X                          msg = XtNewString("\n");	/* erase its text */
X                         } else {		/* reset mail's idea of the */
X                          sprintf(tmp, "f %d", msgnum); /* current message */
X                          c = QueryMail(tmp);
X                          XtFree(c);
X                         }
X                       if (! *msg)		/* Don't allow memory leaks */
X                          XtFree(msg);		/* to accumulate if no text */
X                      }
X		    break;
X/*
X** In response to a request to view new mail, first reset the mailbox flag.
X** If mail came back with an error, complain to the user.  Otherwise, clear
X** the Newmail command button highlighting. Then display any new mail text.
X*/
X    case C_NEWMAIL:
X		    button = XtNameToWidget(toplevel, "topBox.commandPanel.Folder");
X		    UnsetNewmail(button, NULL, NULL);
X                    if (O_BELL == match(output_pattern, msg)) {
X                       if (strncmp(msg, "No mail for ", 12) == 0) {
X                          Bell("No mail in your system mailbox\n");
X                         } else { Bell(msg); }
X                       XtFree(msg);
X                       *msg = '\0';
X                      } else {
X                       Bell("");		/* reset any worthy-ness flag */
X                       Bell(Default_Status_Info);
X                       msgnum = file_handler();
X		       if (*msg) {
X		          s = msg;
X		          c = strchr(msg, '\n');
X		          if ((c - s) + 1 < strlen(msg)) {
X                             *c = '\0';	/* don't bell this */
X			     Bell(msg);
X                            }
X                         }
X                       XtFree(msg);
X                       *msg = '\0';
X                       if (msgnum) {
X                          sprintf(tmp, "%d", msgnum);
X                          msg = QueryMail(tmp);
X                         }
X                      }
X		    break;
X
X           default: j = match(output_pattern, msg);
X		    switch (j) {
X                       case O_BELL:
X                            Bell(msg);
X                            XtFree(msg);
X                            *msg = '\0';
X		            break;
X/*
X** If output is from the print command, display a status message
X*/
X		       case O_PRINT:
X                            sscanf(&Command[2], "%d", &j);
X                            c = strrchr(msg, '/');
X                            sscanf(c, "/%d", &k);
X                            sprintf(tmp,
X                             "Message %d sent to printer -- %d bytes\n", j, k);
X                            Bell(tmp);
X                            XtFree(msg);
X                            *msg = '\0';
X		            break;
X                      }
X		    break;
X   }
X/*
X** If any text remains, display it in the bottom (text) window.
X*/
X if (*msg) {
X    for (j = strlen(msg)-1; j > 1 && msg[j] == '\n' && msg[j-1] == '\n'; j--);
X    msg[++j] = '\0';			/* drop all but the last newline */
X    writeTo(XtNameToWidget(toplevel, "topBox.textWindow.text"), msg);
X    XtFree(msg);
X    *msg = '\0';
X   }
X} /* parse */
X
X#define	FILEBUF	4096
X
X/*
X** @(#)QueryMail() - Sends a command and returns corresponding output.
X** If called by the Xt input procedure readMail, no command is included.
X*/
Xchar *
XQueryMail(cmd)
Xchar	*cmd;
X{
X int		j, outputsize, size, length = strlen(MailPrompt);
X char		*temp, s[FILEBUF];
X static char	*output;
X
X
X SetCursor(1);
X/*
X** allocate one block to 'output' to begin with
X*/
X outputsize = FILEBUF;
X output = XtMalloc(outputsize);
X output[0] = '\0';
X
X if (! mailpid)
X    Bell("No current mail program connection\n");
X else {
X    if (*cmd) {				/* allow us to be called by readMail */
X       if (LASTCH(cmd) != '\n')
X          sprintf(s, "%s\n", cmd);
X       else
X          strcpy(s, cmd);
X       writeMail(s);
X      }
X
X    for (;;) {
X        if ((size = read(mail_fd, s, FILEBUF)) < 1) {	/* EOF or an error? */
X           if (! *output) {
X              strcpy(output, "No current mail service connection\n");
X              if (mailpid) {
X                 XtRemoveInput(mailInputId);
X                 close(mail_fd);
X                 mailpid = 0;
X                }
X             }
X           break;
X          }
X
X        if (size < FILEBUF)
X           s[size] = '\0';
X
X        if (strlen(output) + size > outputsize) {
X           outputsize += FILEBUF;
X           temp = XtRealloc(output, outputsize);
X           output = temp;
X          }
X        strcat(output, s);
X
X        j = strlen(output) - length;	/* no accidents allowed here */
X        if (j < 0) j = 0;		/* no references before zero */
X        if (strcmp(&output[j], MailPrompt) == 0) {
X           output[j] = '\0';		/* Drop prompt from end of text */
X           break;			/* and return from read routine */
X          }
X
X        if (!strcmp(Command,"Start")) {	/* see if somehow missed the prompt */
X           j = strlen(output) - 3;	/* no accidents allowed here either */
X           if (j < 0) j = 0;		/* no string references before zero */
X           if (strcmp(&output[j], "\n& ") == 0) { /* if default mail prompt */
X              output[++j] = '\0';	/* drop prompt from end of string */
X              XtFree(MailPrompt);	/* intended prompt is now bogus */
X              MailPrompt = XtNewString("& ");	/* reset the mail prompt */
X              break;			/* and return from read routine */
X             }
X          }
X
X        if (O_BELL == match(output_pattern,output) && !strcmp(Command,"Start"))
X           break;
X       }
X
X    if (*cmd) 
X       LASTCH(output) = '\0';		/* drop newline for normal queries */
X   }
X
X temp = XtRealloc(output, strlen(output) + 1);
X output = temp;
X
X SetCursor(0);
X
X return(output);
X} /* QueryMail */
END_OF_FILE
if test 17348 -ne `wc -c <'parser.c'`; then
    echo shar: \"'parser.c'\" unpacked with wrong size!
fi
# end of 'parser.c'
fi
echo shar: End of archive 5 \(of 11\).
cp /dev/null ark5isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 11 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0

--
Dan Heller
O'Reilly && Associates       Z-Code Software    Comp-sources-x:
Senior Writer                President          comp-sources-x at uunet.uu.net
argv at ora.com                 argv at zipcode.com



More information about the Comp.sources.x mailing list