/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "rcv.h"
#include <locale.h>
/*
* mailx -- a modified version of a University of California at Berkeley
* mail program
*
* Lexical processing of commands.
*/
#ifdef SIGCONT
static void contin(int);
#endif
static int Passeren(void);
/*
* Set up editing on the given file name.
* If isedit is true, we are considered to be editing the file,
* otherwise we are reading our mail which has signficance for
* mbox and so forth.
*/
int
{
int i;
static int shudclob;
lockmail();
" accept incoming mail\n"), name);
goto doret;
}
extern int errno;
if (exitflg)
goto doexit; /* no mail, return error */
else if (!Hflag) {
if (f == NOSTR)
else
f+1);
}
goto doret;
}
if (exitflg)
goto doexit; /* no mail, return error */
if (isedit)
name);
else
else if (!Hflag) {
else
}
goto doret;
}
goto doexit;
}
if (exitflg)
goto doexit; /* no mail, return error */
fortest+11);
goto doret;
}
if (exitflg) {
exrc = 0;
goto doexit; /* there is mail, return success */
}
/*
* Looks like all will be well. Must hold signals
* while we are reading the new file, else we will ruin
* the message[] data structure.
* Copy the messages into /tmp and set pointers.
*/
holdsigs();
if (shudclob) {
/*
* Now that we know we can switch to the new file
* it's safe to close out the current file.
*
* If we're switching to the file we are currently
* editing, don't allow it to be removed as a side
* effect of closing it out.
*/
if (edit)
else {
if (issysmbox)
Verhogen();
}
space = 0;
}
readonly = 0;
if (!readonly)
readonly++;
else
close(i);
shudclob = 1;
#ifdef notdef
#endif
Verhogen();
goto doexit;
}
Verhogen();
goto doexit;
}
relsesigs();
sawcom = 0;
rc = 0;
unlockmail();
return (rc);
unlockmail();
/* NOTREACHED */
}
/* global to semaphores */
/*
* return -1 if file is already being read, 0 otherwise
*/
static int
Passeren(void)
{
char *home;
return (0);
gettext("\t Assuming you are not already reading mail.\n"));
return (0);
}
gettext("WARNING: Unable to acquire mail lock, no record locks available.\n"));
gettext("\t Assuming you are not already reading mail.\n"));
return (0);
}
gettext("WARNING: You are already reading mail.\n"));
gettext("\t This instance of mail is read only.\n"));
return (-1);
}
return (0);
}
void
Verhogen(void)
{
}
}
/*
* Interpret user commands one by one. If standard input is not a tty,
* print no prompt.
*/
static int *msgvec;
static int shudprompt;
void
commands(void)
{
int eofloop;
register int n;
#ifdef SIGCONT
#endif
}
for (;;) {
/*
* Print the prompt, if needed. Clear out
* string space, and flush the output.
*/
return;
eofloop = 0;
top:
if ((int)value("bsdcompat"))
prompt = "& ";
else
prompt = "";
}
#ifdef SIGCONT
#endif
int OmsgCount, i;
holdsigs();
lockmail();
gettext("Can't reopen %s\n"),
editfile);
unlockmail();
exit(1);
/* NOTREACHED */
}
unlockmail();
"New mail has arrived.\n"));
"Loaded 1 new message\n"));
else
"Loaded %d new messages\n"),
for (i = OmsgCount+1;
i <= msgCount; i++) {
printhead(i);
sreset();
}
}
relsesigs();
}
}
flush();
sreset();
/*
* Read a line of commands from the current input
* and handle end of file specially.
*/
n = 0;
linebuf[0] = '\0';
for (;;) {
if (n != 0)
break;
if (loading)
return;
if (sourcing) {
unstack();
goto more;
}
if (++eofloop < 25) {
"Use \"quit\" to quit.\n"));
goto top;
}
}
return;
}
break;
n--;
if (line[n] != '\\')
break;
line[n++] = ' ';
break;
}
"Line plus continuation line too long:\n\t%s\n\nplus\n\t%s\n"),
if (loading)
return;
if (sourcing) {
unstack();
goto more;
}
return;
}
#ifdef SIGCONT
#endif
return;
more:;
}
}
/*
* Execute a single command. If the command executed
* is "quit," then return non-zero so that the caller
* will know to return back to main, if he cares.
* Contxt is non-zero if called while composing mail.
*/
int
{
register int c, e;
/*
* Strip the white space away from the beginning
* of the command, then scan out a word, which
* consists of anything except digits and white space.
*
* Handle |, ! and # differently to get the correct
* lexical conventions.
*/
cp++;
else
*cp2 = '\0';
/*
* Look up the command; if not found, complain.
* Normally, a blank command would map to the
* first command in the table; while sourcing,
* however, we ignore blank lines to eliminate
* confusion.
*/
return (0);
if (loading) {
return (1);
}
if (sourcing) {
unstack();
}
return (0);
}
/*
* See if we should execute the command -- if a conditional
* we always execute it, otherwise, check the state of cond.
*/
return (0);
/*
* Special case so that quit causes a return to
* main, who will call the quit code directly.
* If we are in a source file, just unstack.
*/
if (sourcing) {
if (loading)
return (1);
unstack();
return (0);
}
return (1);
}
/*
* Process the arguments to the command, depending
* on the type he expects. Default to an error.
* If we are sourcing an interactive command, it's
* an error.
*/
gettext("May not execute \"%s\" while sending\n"),
if (loading)
return (1);
if (sourcing)
unstack();
return (0);
}
gettext("May not execute \"%s\" while sourcing\n"),
rpterr = 1;
if (loading)
return (1);
unstack();
return (0);
}
"May not execute \"%s\" -- message file is read only\n"),
if (loading)
return (1);
if (sourcing)
unstack();
return (0);
}
return (0);
}
e = 1;
case MSGLIST:
/*
* A message list defaulting to nearest forward
* legal message.
*/
if (msgvec == 0) {
gettext("Illegal use of \"message list\"\n"));
return (-1);
}
break;
if (c == 0)
if (msgCount == 0)
else {
}
break;
}
break;
case NDMLIST:
/*
* A message operand with no defaults, but no error
* if none exists. There will be an error if the
* msgvec pointer is of zero value.
*/
if (msgvec == 0) {
gettext("Illegal use of \"message operand\"\n"));
return (-1);
}
break;
break;
case STRLIST:
/*
* Just the straight string, with
* leading blanks removed.
*/
cp++;
break;
case RAWLIST:
/*
* A vector of strings, in shell style.
*/
break;
gettext("%s requires at least %d arg(s)\n"),
break;
}
gettext("%s takes no more than %d arg(s)\n"),
break;
}
break;
case NOLIST:
/*
* Just the constant zero, for exiting,
* eg.
*/
break;
default:
panic("Unknown argtype");
}
/*
* Exit the current source file on
* error.
*/
if (e && loading)
return (1);
if (e && sourcing)
unstack();
return (1);
muvec[1] = 0;
}
sawcom = 1;
return (0);
}
#ifdef SIGCONT
/*
* When we wake up after ^Z, reprint the prompt.
*/
static void
#ifdef __cplusplus
contin(int)
#else
/* ARGSUSED */
contin(int s)
#endif
{
if (shudprompt)
}
#endif
/*
* Branch here on hangup signal and simulate quit.
*/
void
#ifdef __cplusplus
hangup(int)
#else
/* ARGSUSED */
hangup(int s)
#endif
{
holdsigs();
#ifdef OLD_BSD_SIGS
#endif
if (edit) {
edstop(0);
} else {
if (issysmbox)
Verhogen();
exit(1);
else
quit(0);
}
}
/*
* Set the size of the message vector used to construct argument
* lists to message list functions.
*/
static void
{
if (msgvec != (int *)0)
if (sz < 1)
if ((msgvec = (int *)
panic("Failed to allocate memory for message vector");
}
/*
* Find the correct command in the command table corresponding
* to the passed command "word"
*/
static const struct cmd *
{
return (cp);
return (NONE);
}
/*
* Determine if as1 is a valid prefix of as2.
*/
static int
{
if (*s2++ == '\0')
return (1);
return (*--s1 == '\0');
}
/*
* The following gets called on receipt of a rubout. This is
* to abort printout of a command, mainly.
* Dispatching here when command() is inactive crashes rcv.
* Close all open files except 0, 1, 2, and the temporary.
* The special call to getuserid() is needed so it won't get
* annoyed about losing its open file.
* Also, unstack all source files.
*/
void
stop(int s)
{
noreset = 0;
if (!inithdr)
sawcom++;
inithdr = 0;
while (sourcing)
unstack();
(void) getuserid((char *)0);
continue;
continue;
continue;
continue;
continue;
}
}
if (image >= 0) {
image = -1;
}
if (s) {
#ifdef OLD_BSD_SIGS
sigrelse(s);
#endif
}
}
/*
* Announce the presence of the current mailx version,
* give the message count, and print a header listing.
*/
void
announce(void)
{
extern const char *const version;
vec[1] = 0;
inithdr++;
inithdr = 0;
}
}
/*
* Announce information about the file we are editing.
* Return a likely place to set dot.
*/
int
{
register int u, n, mdot, d, s;
if (Hflag)
return (1); /* fake it--return message 1 */
break;
break;
else
mdot = 1;
n = u = d = s = 0;
n++;
u++;
d++;
s++;
}
}
}
if (msgCount == 1)
else
if (n > 0)
if (u-n > 0)
if (d > 0)
if (s > 0)
if (readonly)
printf("\n");
return (mdot);
}
/*
* Print the current version number.
*/
int
#ifdef __cplusplus
pversion(char *)
#else
/* ARGSUSED */
pversion(char *s)
#endif
{
return (0);
}
/*
* Load a file of user definitions.
*/
void
{
return;
loading = 1;
sourcing = 1;
commands();
loading = 0;
sourcing = 0;
}
/*
* Incorporate any new mail into the current session.
*
* XXX - Since autoinc works on "edited" files as well as the
* system mailbox, this probably ought to as well.
*/
int
inc(void)
{
int mdot;
if (edit) {
return (-1);
}
else
return (-1);
}
holdsigs();
if (issysmbox)
lockmail();
if (issysmbox)
unlockmail();
relsesigs();
sawcom = 0;
return (0);
}