lex.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the BSD package *
*Copyright (c) 1978-2012 The Regents of the University of California an*
* *
* Redistribution and use in source and binary forms, with or *
* without modification, are permitted provided that the following *
* conditions are met: *
* *
* 1. Redistributions of source code must retain the above *
* copyright notice, this list of conditions and the *
* following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above *
* copyright notice, this list of conditions and the *
* materials provided with the distribution. *
* *
* 3. Neither the name of The Regents of the University of California*
* names of its contributors may be used to endorse or *
* promote products derived from this software without *
* specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS *
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED *
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON *
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, *
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* 1. Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in *
* distribution. *
* 3. Neither the name of the University nor the names of its *
* contributors may be used to endorse or promote products derived *
* from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" *
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF *
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, *
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT *
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *
* SUCH DAMAGE. *
* *
* Kurt Shoens (UCB) *
* gsf *
* *
***********************************************************************/
#pragma prototyped
/*
* Mail -- a mail program
*
* Lexical processing of commands.
*/
#include "mailx.h"
/*
* Inititialize the folder tmp file pointers.
*/
void
{
int fd;
if (name) {
quit();
if (dir) {
}
else
}
}
}
}
if (!dir) {
exit(1);
exit(1);
}
}
/*
* Set up editing on the given folder.
* If the first character of name is not %, we are considered to be
* editing the folder, otherwise we are reading our mail which has
* signficance for mbox and so forth.
*/
int
{
return -1;
return 0;
}
imap_setptr((char*)0, 0);
exit(1);
goto nomail;
return 0;
}
return -1;
}
exit(1);
if (isedit)
else {
goto nomail;
}
}
return 0;
}
exit(0);
/*
* Looks like all will be well. We must now relinquish our
* hold on the current set of stuff. Must hold signals
* while we are reading the new file, else we will ruin
* the message[] data structure.
*/
holdsigs();
/*
* New mail has arrived while we were reading up the mail file,
* so reset mailsize to be where we really are in the file...
*/
relsesigs();
exit(1);
else
}
return -1;
}
return 0;
}
/*
* Incorporate any new mail that has arrived since we first
* started reading mail.
*/
int
incfile(void)
{
int newsize;
return -1;
holdsigs();
return -1; /* mail box is now empty??? */
return -1; /* mail box has shrunk??? */
return 0; /* no new mail */
relsesigs();
}
/*
* The following gets called on receipt of an interrupt. 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.
* Also, unstack all source files.
*/
static void
{
else
unstack();
fileclear();
note(0, "Interrupt");
}
/*
* When we wake up after ^Z, reprint the prompt.
*/
static void
{
}
}
/*
* Branch here on hangup signal and simulate "exit".
*/
/*ARGSUSED*/
static void
{
/* nothing to do? */
exit(1);
}
/*
* Interpret user commands one by one. If standard input is not a tty,
* print no prompt.
*/
void
commands(void)
{
register int n;
int eofloop = 0;
#if SIGTSTP
#endif
#if SIGTTOU
#endif
#if SIGTTIN
#endif
}
setexit();
for (;;) {
/*
* Print the prompt, if needed. Clear out
* string space, and flush the output.
*/
moretop();
note(0, "New mail has arrived");
note(0, "");
}
sreset();
/*
* Read a line of commands from the current input
* and handle end of file specially.
*/
n = 0;
for (;;) {
if (!n)
n = -1;
break;
}
break;
n--;
if (linebuf[n] != '\\')
break;
linebuf[n++] = ' ';
}
if (n < 0) {
/* eof */
break;
unstack();
continue;
}
++eofloop < 25) {
note(0, "Use \"quit\" to quit");
continue;
}
break;
}
eofloop = 0;
break;
}
}
/*
* Execute a single command.
* Command functions return 0 for success, 1 for error, and -1
* for abort. A 1 or -1 aborts a load or source. A -1 aborts
* the interactive command loop.
* Contxt is non-zero if called while composing mail.
*/
int
{
register char* s;
register int c;
register char* a;
char* next;
int e = 1;
/*
* Strip the white space away from the beginning of the command.
*/
/*
* Look up the command and execute.
*/
switch (*s) {
case '!':
a = "shell";
s++;
break;
case '#':
return 0;
case '=':
a = "dot";
s++;
break;
case '?':
a = "help";
s++;
break;
case '|':
a = "pipe";
s++;
break;
default:
if (isalpha(*s)) {
a = s;
s = 0;
}
else {
return 0;
a = "next";
}
break;
}
note(0, "\"%s\": unknown command", a);
goto out;
}
next++;
if (!s)
s = next;
while (isspace(*s))
s++;
/*
* See if we should execute the command -- if a conditional
* we always execute it, otherwise, check the state of cond.
*/
return 0;
/*
* Process the arguments to the command, depending
* on the type expected. Default to an error.
* If we are sourcing an interactive command, it's
* an error.
*/
note(0, "Cannot execute \"%s\" while sending",
goto out;
}
note(0, "Cannot execute \"%s\" while sourcing",
goto out;
}
note(0, "Cannot execute \"%s\" -- message file is read only",
goto out;
}
goto out;
}
case MSGLIST:
/*
* A message list defaulting to nearest forward
* legal message.
*/
note(0, "Invalid use of \"message list\"");
break;
}
break;
if (!c) {
}
note(0, "No applicable messages");
break;
}
break;
case NDMLIST:
/*
* A message list with no defaults, but no error
* if none exist.
*/
note(0, "Invalid use of \"message list\"");
break;
}
break;
break;
case STRLIST:
/*
* Just the straight string.
*/
break;
case RAWLIST:
/*
* A vector of strings, in shell style.
*/
break;
note(0, "%s requires %s %d arg%s",
break;
}
note(0, "%s takes no more than %d arg%s",
break;
}
break;
case NOLIST:
/*
* Just the constant zero, for exiting, e.g.
*/
break;
default:
}
out:
/*
* Exit the current source file on error.
*/
if (e) {
return 1;
unstack();
return 0;
}
}
return 0;
}
/*
* Announce information about the current folder.
* msgcount is state.msg.count before the file was read.
* Return a likely place to set dot.
*/
struct msg*
folderinfo(int msgcount)
{
register int d;
register int m;
register int n;
register int s;
register int u;
int i;
char* name;
else {
break;
break;
else {
}
}
d = m = n = s = u = 0;
m++;
d++;
s++;
u++;
n++;
}
}
buf[i++] = '/';
}
if (n > 0)
printf(" %d new", n);
if (u > 0)
printf(" %d unread", u);
if (d > 0)
printf(" %d deleted", d);
if (s > 0)
printf(" %d saved", s);
case FIMAP:
printf(" [imap]");
break;
case FMH:
printf(" [mh]");
break;
}
printf(" [Read only]");
printf("\n");
return dot;
}
/*
* Announce the presence of the current Mail version,
* give the message count, and print a header listing.
*/
void
announce()
{
}
}
}
/*
* Print the current version number.
*/
/*ARGSUSED*/
int
version(void* a)
{
return 0;
}
/*
* Print the license and disclaimer.
*/
/*ARGSUSED*/
int
license(void* a)
{
version(a);
return 0;
}
/*
* Load a file of user definitions.
*/
void
{
return;
commands();
}