summaryrefslogtreecommitdiff
path: root/usr/src/cmd/mailx
diff options
context:
space:
mode:
authoras145665 <none@none>2006-10-16 17:00:43 -0700
committeras145665 <none@none>2006-10-16 17:00:43 -0700
commiteb2b0a6162b47bdee86cc3d2e844dc8f89d95371 (patch)
tree3851e6b70fdcd650c0371e22742f1a6b498c906b /usr/src/cmd/mailx
parentd33d82f2b6ab8328bfc542feecd2c3935051f51a (diff)
downloadillumos-joyent-eb2b0a6162b47bdee86cc3d2e844dc8f89d95371.tar.gz
6460901 UNIX03: *vsc* mailx(1) "next" command does not handle message lists properly
Diffstat (limited to 'usr/src/cmd/mailx')
-rw-r--r--usr/src/cmd/mailx/cmd2.c273
-rw-r--r--usr/src/cmd/mailx/hdr/def.h318
-rw-r--r--usr/src/cmd/mailx/lex.c176
-rw-r--r--usr/src/cmd/mailx/list.c191
4 files changed, 495 insertions, 463 deletions
diff --git a/usr/src/cmd/mailx/cmd2.c b/usr/src/cmd/mailx/cmd2.c
index 2b436088b7..868f4db952 100644
--- a/usr/src/cmd/mailx/cmd2.c
+++ b/usr/src/cmd/mailx/cmd2.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * 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
* or http://www.opensolaris.org/os/licensing.
@@ -21,7 +20,7 @@
*/
/*
- * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -67,59 +66,35 @@ static int retshow(void);
#define S_NOIGNORE 8 /* don't do ignore processing */
/*
- * If any arguments were given, go to the next applicable argument
- * following dot, otherwise, go to the next applicable message.
- * If given as first command with no arguments, print first message.
+ * If any arguments were given, print the first message
+ * identified by the first argument. If no arguments are given,
+ * print the next applicable message after dot.
*/
-int
+int
next(int *msgvec)
{
register struct message *mp;
- register int *ip, *ip2;
- int list[2], mdot;
+ int list[2];
if (*msgvec != NULL) {
-
- /*
- * If some messages were supplied, find the
- * first applicable one following dot using
- * wrap around.
- */
-
- mdot = dot - &message[0] + 1;
-
- /*
- * Find the first message in the supplied
- * message list which follows dot.
- */
-
- for (ip = msgvec; *ip != NULL; ip++)
- if (*ip > mdot)
- break;
- if (*ip == NULL)
- ip = msgvec;
- ip2 = ip;
- do {
- mp = &message[*ip2 - 1];
- if ((mp->m_flag & MDELETED) == 0) {
- dot = mp;
- goto hitit;
- }
- if (*ip2 != NULL)
- ip2++;
- if (*ip2 == NULL)
- ip2 = msgvec;
- } while (ip2 != ip);
- printf(gettext("No messages applicable\n"));
- return(1);
+ if (*msgvec < 0) {
+ printf((gettext("Negative message given\n")));
+ return (1);
+ }
+ mp = &message[*msgvec - 1];
+ if ((mp->m_flag & MDELETED) == 0) {
+ dot = mp;
+ goto hitit;
+ }
+ printf(gettext("No applicable message\n"));
+ return (1);
}
/*
* If this is the first command, select message 1.
* Note that this must exist for us to get here at all.
*/
-
if (!sawcom)
goto hitit;
@@ -127,93 +102,91 @@ next(int *msgvec)
* Just find the next good message after dot, no
* wraparound.
*/
-
for (mp = dot+1; mp < &message[msgCount]; mp++)
if ((mp->m_flag & (MDELETED|MSAVED)) == 0)
break;
if (mp >= &message[msgCount]) {
printf(gettext("At EOF\n"));
- return(0);
+ return (0);
}
dot = mp;
hitit:
/*
* Print dot.
*/
-
list[0] = dot - &message[0] + 1;
list[1] = NULL;
- return(type(list));
+ return (type(list));
}
/*
* Save a message in a file. Mark the message as saved
* so we can discard when the user quits.
*/
-int
+int
save(char str[])
{
- return(save1(str, S_MARK));
+ return (save1(str, S_MARK));
}
/*
* Copy a message to a file without affected its saved-ness
*/
-int
+int
copycmd(char str[])
{
- return(save1(str, 0));
+ return (save1(str, 0));
}
/*
* Save/copy the indicated messages at the end of the passed file name.
* If mark is true, mark the message "saved."
*/
-static int
+static int
save1(char str[], int mark)
{
char *file, *cmd;
int f, *msgvec;
cmd = mark ? "save" : "copy";
- msgvec = (int *) salloc((msgCount + 2) * sizeof *msgvec);
+ msgvec = (int *)salloc((msgCount + 2) * sizeof (*msgvec));
if ((file = snarf(str, &f, 0)) == NOSTR)
file = Getf("MBOX");
- if (f==-1)
- return(1);
+ if (f == -1)
+ return (1);
if (!f) {
*msgvec = first(0, MMNORM);
if (*msgvec == NULL) {
printf(gettext("No messages to %s.\n"), cmd);
- return(1);
+ return (1);
}
msgvec[1] = NULL;
}
if (f && getmsglist(str, msgvec, 0) < 0)
- return(1);
+ return (1);
if ((file = expand(file)) == NOSTR)
- return(1);
+ return (1);
savemsglist(file, msgvec, mark | S_SAVING);
- return(0);
+ return (0);
}
-int
+int
Save(int *msgvec)
{
- return(Save1(msgvec, S_MARK));
+ return (Save1(msgvec, S_MARK));
}
-int
+int
Copy(int *msgvec)
{
- return(Save1(msgvec, 0));
+ return (Save1(msgvec, 0));
}
/*
* save/copy the indicated messages at the end of a file named
* by the sender of the first message in the msglist.
*/
-static int
+static int
Save1(int *msgvec, int mark)
{
register char *from;
@@ -227,49 +200,49 @@ Save1(int *msgvec, int mark)
getrecf(from, recfile, 1, sizeof (recfile));
if (*recfile != '\0')
savemsglist(safeexpand(recfile), msgvec, mark | S_SAVING);
- return(0);
+ return (0);
}
-int
+int
sput(char str[])
{
- return(put1(str, 0));
+ return (put1(str, 0));
}
-int
+int
Sput(char str[])
{
- return(put1(str, S_NOIGNORE));
+ return (put1(str, S_NOIGNORE));
}
/*
* Put the indicated messages at the end of the passed file name.
*/
-static int
+static int
put1(char str[], int doign)
{
char *file;
int f, *msgvec;
- msgvec = (int *) salloc((msgCount + 2) * sizeof *msgvec);
+ msgvec = (int *)salloc((msgCount + 2) * sizeof (*msgvec));
if ((file = snarf(str, &f, 0)) == NOSTR)
file = Getf("MBOX");
- if (f==-1)
- return(1);
+ if (f == -1)
+ return (1);
if (!f) {
*msgvec = first(0, MMNORM);
if (*msgvec == NULL) {
printf(gettext("No messages to put.\n"));
- return(1);
+ return (1);
}
msgvec[1] = NULL;
}
if (f && getmsglist(str, msgvec, 0) < 0)
- return(1);
+ return (1);
if ((file = expand(file)) == NOSTR)
- return(1);
+ return (1);
savemsglist(file, msgvec, doign);
- return(0);
+ return (0);
}
/*
@@ -285,7 +258,7 @@ static int wr_inlines; /* count of lines read */
static long wr_maxlines; /* total lines in message */
static int wr_inhead; /* in header of message */
-static void
+static void
savemsglist(char *file, int *msgvec, int flag)
{
register int *ip, mesg;
@@ -358,7 +331,7 @@ svputs(const char *line, FILE *obuf)
{
wr_linecount++;
wr_charcount += strlen(line);
- return(fputs(line, obuf));
+ return (fputs(line, obuf));
}
static int
@@ -374,13 +347,13 @@ wrputs(const char *line, FILE *obuf)
if (wr_inhead) {
if (strcmp(line, "\n") == 0)
wr_inhead = 0;
- return(0);
+ return (0);
}
if (wr_inlines >= wr_maxlines && strcmp(line, "\n") == 0)
- return(0);
+ return (0);
wr_linecount++;
wr_charcount += strlen(line);
- return(fputs(line, obuf));
+ return (fputs(line, obuf));
}
/*
@@ -388,31 +361,31 @@ wrputs(const char *line, FILE *obuf)
* file name, minus header and trailing blank line.
*/
-int
+int
swrite(char str[])
{
register char *file;
int f, *msgvec;
- msgvec = (int *) salloc((msgCount + 2) * sizeof *msgvec);
+ msgvec = (int *)salloc((msgCount + 2) * sizeof (*msgvec));
if ((file = snarf(str, &f, 1)) == NOSTR)
- return(1);
- if (f==-1)
- return(1);
+ return (1);
+ if (f == -1)
+ return (1);
if ((file = expand(file)) == NOSTR)
- return(1);
+ return (1);
if (!f) {
*msgvec = first(0, MMNORM);
if (*msgvec == NULL) {
printf(gettext("No messages to write.\n"));
- return(1);
+ return (1);
}
msgvec[1] = NULL;
}
if (f && getmsglist(str, msgvec, 0) < 0)
- return(1);
+ return (1);
savemsglist(file, msgvec, S_MARK|S_NOHEADER);
- return(0);
+ return (0);
}
/*
@@ -445,12 +418,12 @@ snarf(char linebuf[], int *flag, int erf)
char *line_beg; /* beginning of line, after */
/* leading whitespace */
- /*
+ /*
* Skip leading whitespace.
*/
for (line_beg = linebuf;
- *line_beg && any(*line_beg, " \t");
- line_beg++) {
+ *line_beg && any(*line_beg, " \t");
+ line_beg++) {
/* empty body */
}
if (!*line_beg) {
@@ -458,13 +431,15 @@ snarf(char linebuf[], int *flag, int erf)
printf(gettext("No file specified\n."));
}
*flag = 0;
- return(NOSTR);
+ return (NOSTR);
}
/*
* Process line from left-to-right, 1 char at a time.
*/
- for (pc_type = SN_DELIM, tok_beg = tok_end = NOSTR, p = line_beg;
- *p != '\0'; ) {
+ pc_type = SN_DELIM;
+ tok_beg = tok_end = NOSTR;
+ p = line_beg;
+ while (*p != '\0') {
if (any(*p, " \t")) {
/* This character is a DELIMITER */
if (pc_type & (SN_TOKEN|SN_QUOTE)) {
@@ -482,17 +457,17 @@ snarf(char linebuf[], int *flag, int erf)
}
/* Search for the matching QUOTE character */
for (tok_beg = p, tok_end = NOSTR, p++;
- *p != '\0' && *p != qc;
- p++) {
+ *p != '\0' && *p != qc;
+ p++) {
if (*p == '\\' && *(p+1) == qc) {
p++;
}
}
if (*p == '\0') {
printf(gettext("Syntax error: missing "
- "%c.\n"), qc);
+ "%c.\n"), qc);
*flag = -1;
- return(NOSTR);
+ return (NOSTR);
}
tok_end = p;
pc_type = SN_QUOTE;
@@ -506,15 +481,15 @@ snarf(char linebuf[], int *flag, int erf)
}
} else {
printf(gettext("improper quotes"
- " at \"%s\".\n"), p);
+ " at \"%s\".\n"), p);
*flag = -1;
- return(NOSTR);
+ return (NOSTR);
}
if (*p == '\\' && *++p == '\0') {
printf(gettext("\'\\\' at "
- "end of line.\n"));
+ "end of line.\n"));
*flag = -1;
- return(NOSTR);
+ return (NOSTR);
}
pc_type = SN_TOKEN;
p++;
@@ -531,13 +506,13 @@ snarf(char linebuf[], int *flag, int erf)
*flag = 1;
}
tok_end[1] = '\0';
- return(tok_beg);
+ return (tok_beg);
} else {
if (erf) {
printf(gettext("No file specified\n."));
}
*flag = 0;
- return(NOSTR);
+ return (NOSTR);
}
}
@@ -545,7 +520,7 @@ snarf(char linebuf[], int *flag, int erf)
* Delete messages, then type the new dot.
*/
-int
+int
deltype(int msgvec[])
{
int list[2];
@@ -558,14 +533,13 @@ deltype(int msgvec[])
if (list[0] > lastdot) {
touch(list[0]);
list[1] = NULL;
- return(type(list));
+ return (type(list));
}
printf(gettext("At EOF\n"));
- return(0);
- }
- else {
+ return (0);
+ } else {
printf(gettext("No more messages\n"));
- return(0);
+ return (0);
}
}
@@ -573,7 +547,7 @@ deltype(int msgvec[])
* Delete the indicated messages.
* Set dot to some nice place afterwards.
*/
-int
+int
delm(int *msgvec)
{
register struct message *mp;
@@ -594,11 +568,10 @@ delm(int *msgvec)
last = first(0, MDELETED);
if (last != NULL) {
dot = &message[last-1];
- return(0);
- }
- else {
+ return (0);
+ } else {
dot = &message[0];
- return(-1);
+ return (-1);
}
}
@@ -606,13 +579,13 @@ delm(int *msgvec)
* Following can't happen -- it keeps lint happy
*/
- return(-1);
+ return (-1);
}
/*
* Undelete the indicated messages.
*/
-int
+int
undelete(int *msgvec)
{
register struct message *mp;
@@ -621,20 +594,20 @@ undelete(int *msgvec)
for (ip = msgvec; ip-msgvec < msgCount; ip++) {
mesg = *ip;
if (mesg == 0)
- return(0);
+ return (0);
touch(mesg);
mp = &message[mesg-1];
dot = mp;
mp->m_flag &= ~MDELETED;
}
- return(0);
+ return (0);
}
/*
* Add the given header fields to the retained list.
* If no arguments, print the current list of retained fields.
*/
-int
+int
retfield(char *list[])
{
char field[BUFSIZ];
@@ -643,7 +616,7 @@ retfield(char *list[])
char **ap;
if (argcount(list) == 0)
- return(retshow());
+ return (retshow());
for (ap = list; *ap != 0; ap++) {
istrcpy(field, sizeof (field), *ap);
@@ -664,13 +637,13 @@ retfield(char *list[])
retain[h] = igp;
nretained++;
}
- return(0);
+ return (0);
}
/*
* Print out all currently retained fields.
*/
-static int
+static int
retshow(void)
{
register int h, count;
@@ -683,9 +656,9 @@ retshow(void)
count++;
if (count == 0) {
printf(gettext("No fields currently being retained.\n"));
- return(0);
+ return (0);
}
- ring = (char **) salloc((count + 1) * sizeof (char *));
+ ring = (char **)salloc((count + 1) * sizeof (char *));
ap = ring;
for (h = 0; h < HSHSIZE; h++)
for (igp = retain[h]; igp != 0; igp = igp->i_link)
@@ -694,13 +667,13 @@ retshow(void)
qsort(ring, count, sizeof (char *), igcomp);
for (ap = ring; *ap != 0; ap++)
printf("%s\n", *ap);
- return(0);
+ return (0);
}
/*
* Remove a list of fields from the retain list.
*/
-int
+int
unretfield(char *list[])
{
char **ap, field[BUFSIZ];
@@ -713,7 +686,7 @@ unretfield(char *list[])
while (ig1) {
free(ig1->i_field);
ig2 = ig1->i_link;
- free((char *) ig1);
+ free((char *)ig1);
ig1 = ig2;
count++;
}
@@ -723,7 +696,7 @@ unretfield(char *list[])
printf(gettext(
"No fields currently being retained.\n"));
nretained = 0;
- return 0;
+ return (0);
}
for (ap = list; *ap; ap++) {
istrcpy(field, sizeof (field), *ap);
@@ -735,19 +708,19 @@ unretfield(char *list[])
else
ig2->i_link = ig1->i_link;
free(ig1->i_field);
- free((char *) ig1);
+ free((char *)ig1);
nretained--;
break;
}
}
- return 0;
+ return (0);
}
/*
* Add the given header fields to the ignored list.
* If no arguments, print the current list of ignored fields.
*/
-int
+int
igfield(char *list[])
{
char field[BUFSIZ];
@@ -756,7 +729,7 @@ igfield(char *list[])
char **ap;
if (argcount(list) == 0)
- return(igshow());
+ return (igshow());
for (ap = list; *ap != 0; ap++) {
if (isign(*ap, 0))
continue;
@@ -775,13 +748,13 @@ igfield(char *list[])
igp->i_link = ignore[h];
ignore[h] = igp;
}
- return(0);
+ return (0);
}
/*
* Print out all currently ignored fields.
*/
-static int
+static int
igshow(void)
{
register int h, count;
@@ -794,33 +767,33 @@ igshow(void)
count++;
if (count == 0) {
printf(gettext("No fields currently being ignored.\n"));
- return(0);
+ return (0);
}
- ring = (char **) salloc((count + 1) * sizeof (char *));
+ ring = (char **)salloc((count + 1) * sizeof (char *));
ap = ring;
for (h = 0; h < HSHSIZE; h++)
for (igp = ignore[h]; igp != 0; igp = igp->i_link)
*ap++ = igp->i_field;
*ap = 0;
- qsort((char *) ring, (unsigned) count, sizeof (char *), igcomp);
+ qsort((char *)ring, (unsigned)count, sizeof (char *), igcomp);
for (ap = ring; *ap != 0; ap++)
printf("%s\n", *ap);
- return(0);
+ return (0);
}
/*
* Compare two names for sorting ignored field list.
*/
-static int
+static int
igcomp(const void *l, const void *r)
{
- return(strcmp(*(char **)l, *(char **)r));
+ return (strcmp(*(char **)l, *(char **)r));
}
/*
* Remove a list of fields from the ignore list.
*/
-int
+int
unigfield(char *list[])
{
char **ap, field[BUFSIZ];
@@ -833,7 +806,7 @@ unigfield(char *list[])
while (ig1) {
free(ig1->i_field);
ig2 = ig1->i_link;
- free((char *) ig1);
+ free((char *)ig1);
ig1 = ig2;
count++;
}
@@ -841,7 +814,7 @@ unigfield(char *list[])
}
if (count == 0)
printf(gettext("No fields currently being ignored.\n"));
- return 0;
+ return (0);
}
for (ap = list; *ap; ap++) {
istrcpy(field, sizeof (field), *ap);
@@ -853,9 +826,9 @@ unigfield(char *list[])
else
ig2->i_link = ig1->i_link;
free(ig1->i_field);
- free((char *) ig1);
+ free((char *)ig1);
break;
}
}
- return 0;
+ return (0);
}
diff --git a/usr/src/cmd/mailx/hdr/def.h b/usr/src/cmd/mailx/hdr/def.h
index f78a53648e..53a9fe9842 100644
--- a/usr/src/cmd/mailx/hdr/def.h
+++ b/usr/src/cmd/mailx/hdr/def.h
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * 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
* or http://www.opensolaris.org/os/licensing.
@@ -19,15 +18,15 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
- * All Rights Reserved
- *
- *
- * Copyright (c) 1985-2001 by Sun Microsystems, Inc.
- * All rights reserved.
+ * 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
@@ -60,10 +59,10 @@ extern "C" {
#include <ctype.h>
#include <errno.h>
#ifndef preSVr4
-# include <unistd.h>
-# include <stdlib.h>
-# include <ulimit.h>
-# include <wait.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ulimit.h>
+#include <wait.h>
#endif
#ifdef VMUNIX
#include <sys/wait.h>
@@ -82,16 +81,21 @@ extern "C" {
#define HSHSIZE 59 /* Hash size for aliases and vars */
#define HDRFIELDS 3 /* Number of header fields */
#define LINESIZE 5120 /* max readable line width */
-#define STRINGSIZE ((unsigned) 128)/* Dynamic allocation units */
+#define STRINGSIZE ((unsigned)128) /* Dynamic allocation units */
#define MAXARGC 1024 /* Maximum list of raw strings */
-#define NOSTR ((char *) 0) /* Nill string pointer */
-#define NOSTRPTR ((char **) 0) /* Nill pointer to string pointer */
-#define NOINTPTR ((int *) 0) /* Nill pointer */
+#define NOSTR ((char *)0) /* Nill string pointer */
+#define NOSTRPTR ((char **)0) /* Nill pointer to string pointer */
+#define NOINTPTR ((int *)0) /* Nill pointer */
#define MAXEXP 25 /* Maximum expansion of aliases */
-#define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */
-#define fopen(s,t) my_fopen(s,t) /* Keep a list of all opened files */
-#define fclose(s) my_fclose(s) /* delete closed file from the list*/
+/* A nice function to string compare */
+#define equal(a, b) (strcmp(a, b) == 0)
+
+/* Keep a list of all opened files */
+#define fopen(s, t) my_fopen(s, t)
+
+/* Delete closed file from the list */
+#define fclose(s) my_fclose(s)
struct message {
off_t m_offset; /* offset in block of message */
@@ -127,31 +131,32 @@ typedef struct fplst {
#define H_AFWDCNT 1 /* "Auto-Forward-Count:" */
#define H_AFWDFROM 2 /* "Auto-Forwarded-From:" */
-#define H_CLEN 3 /* "Content-Length:" */
-#define H_CTYPE 4 /* "Content-Type:" */
-#define H_DATE 5 /* "Date:" */
-#define H_DEFOPTS 6 /* "Default-Options:" */
-#define H_EOH 7 /* "End-of-Header:" */
-#define H_FROM 8 /* "From " */
-#define H_FROM1 9 /* ">From " */
-#define H_FROM2 10 /* "From: " */
-#define H_MTSID 11 /* "MTS-Message-ID:" */
-#define H_MTYPE 12 /* "Message-Type:" */
-#define H_MVERS 13 /* "Message-Version:" */
-#define H_MSVC 14 /* "Message-Service:" */
-#define H_RECEIVED 15 /* "Received:" */
-#define H_RVERS 16 /* "Report-Version:" */
-#define H_STATUS 17 /* "Status:" */
-#define H_SUBJ 18 /* "Subject:" */
-#define H_TO 19 /* "To:" */
-#define H_TCOPY 20 /* ">To:" */
+#define H_CLEN 3 /* "Content-Length:" */
+#define H_CTYPE 4 /* "Content-Type:" */
+#define H_DATE 5 /* "Date:" */
+#define H_DEFOPTS 6 /* "Default-Options:" */
+#define H_EOH 7 /* "End-of-Header:" */
+#define H_FROM 8 /* "From " */
+#define H_FROM1 9 /* ">From " */
+#define H_FROM2 10 /* "From: " */
+#define H_MTSID 11 /* "MTS-Message-ID:" */
+#define H_MTYPE 12 /* "Message-Type:" */
+#define H_MVERS 13 /* "Message-Version:" */
+#define H_MSVC 14 /* "Message-Service:" */
+#define H_RECEIVED 15 /* "Received:" */
+#define H_RVERS 16 /* "Report-Version:" */
+#define H_STATUS 17 /* "Status:" */
+#define H_SUBJ 18 /* "Subject:" */
+#define H_TO 19 /* "To:" */
+#define H_TCOPY 20 /* ">To:" */
#define H_TROPTS 21 /* "Transport-Options:" */
#define H_UAID 22 /* "UA-Content-ID:" */
-#define H_DAFWDFROM 23 /* Hold A-F-F when sending Del. Notf. */
-#define H_DTCOPY 24 /* Hold ">To:" when sending Del. Notf.*/
-#define H_DRECEIVED 25 /* Hold Rcvd: when sending Del. Notf.*/
-#define H_CONT 26 /* Continuation of previous line */
-#define H_NAMEVALUE 27 /* unrecognized "name: value" hdr line*/
+
+#define H_DAFWDFROM 23 /* Hold A-F-F when sending Del. Notf. */
+#define H_DTCOPY 24 /* Hold ">To:" when sending Del. Notf. */
+#define H_DRECEIVED 25 /* Hold Rcvd: when sending Del. Notf. */
+#define H_CONT 26 /* Continuation of previous line */
+#define H_NAMEVALUE 27 /* unrecognized "name: value" hdr line */
/*
* Format of the command description table.
@@ -194,8 +199,8 @@ struct cmd {
* Oft-used mask values
*/
-#define MMNORM (MDELETED|MSAVED)/* Look at both save and delete bits */
-#define MMNDEL MDELETED /* Look only at deleted bit */
+#define MMNORM (MDELETED|MSAVED) /* Look at both save and delete bits */
+#define MMNDEL MDELETED /* Look only at deleted bit */
/*
* Structure used to return a break down of a head
@@ -214,7 +219,7 @@ struct headline {
#define GBCC 8 /* And also the Bcc: line */
#define GDEFOPT 16 /* And the Default-Options: lines */
#define GNL 32 /* Print blank line after */
-#define GOTHER 64 /* Other header lines */
+#define GOTHER 64 /* Other header lines */
#define GMASK (GTO|GSUBJECT|GCC|GBCC|GDEFOPT|GNL|GOTHER)
/* Mask of all header lines */
#define GDEL 128 /* Entity removed from list */
@@ -272,22 +277,22 @@ struct grouphead {
struct mgroup *g_list; /* Users in group. */
};
-#define NIL ((struct name *) 0) /* The nil pointer for namelists */
-#define NONE ((struct cmd *) 0) /* The nil pointer to command tab */
-#define NOVAR ((struct var *) 0) /* The nil pointer to variables */
-#define NOGRP ((struct grouphead *) 0)/* The nil grouphead pointer */
-#define NOGE ((struct mgroup *) 0) /* The nil group pointer */
-#define NOFP ((struct fplst *) 0) /* The nil file pointer */
+#define NIL ((struct name *)0) /* The nil pointer for namelists */
+#define NONE ((struct cmd *)0) /* The nil pointer to command tab */
+#define NOVAR ((struct var *)0) /* The nil pointer to variables */
+#define NOGRP ((struct grouphead *)0) /* The nil grouphead pointer */
+#define NOGE ((struct mgroup *)0) /* The nil group pointer */
+#define NOFP ((struct fplst *)0) /* The nil file pointer */
-#define TRUE 1
-#define FALSE 0
+#define TRUE 1
+#define FALSE 0
-#define DEADPERM 0600 /* permissions of dead.letter */
-#define TEMPPERM 0600 /* permissions of temp files */
-#define MBOXPERM 0600 /* permissions of ~/mbox */
+#define DEADPERM 0600 /* permissions of dead.letter */
+#define TEMPPERM 0600 /* permissions of temp files */
+#define MBOXPERM 0600 /* permissions of ~/mbox */
#ifndef MFMODE
-# define MFMODE 0600 /* create mode for `/var/mail' files */
+#define MFMODE 0600 /* create mode for `/var/mail' files */
#endif
/*
@@ -304,7 +309,7 @@ struct utimbuf {
time_t modtime;
};
#else
-# include <utime.h>
+#include <utime.h>
#endif
/*
@@ -322,7 +327,7 @@ struct utimbuf {
#define TSTAR 7 /* A "*" */
#define TOPEN 8 /* An '(' */
#define TCLOSE 9 /* A ')' */
-#define TPLUS 10 /* A '+' */
+#define TPLUS 10 /* A '+' */
#define REGDEP 2 /* Maximum regret depth. */
#define STRINGLEN 1024 /* Maximum length of string token */
@@ -381,7 +386,7 @@ struct utimbuf {
* useful just before closing an old file that was opened
* for read/write.
*/
-#define trunc(stream) ftruncate(fileno(stream), (long) ftell(stream))
+#define trunc(stream) ftruncate(fileno(stream), (long)ftell(stream))
/*
* The pointers for the string allocation routines,
@@ -468,100 +473,105 @@ extern int followup(int *msgvec);
extern int from(int *msgvec);
extern off_t fsize(FILE *iob);
extern int getfold(char *name);
-extern int gethfield(register FILE *f, char linebuf[], register long rem);
-extern int getline(char *line, int size, FILE *f, int *hasnulls);
-extern int getmsglist(char *buf, int *vector, int flags);
-extern int getname(uid_t uid, char namebuf[]);
-extern int getrawlist(char line[], char **argv, int argc);
-extern void getrecf(char *buf, char *recfile, int useauthor, int sz_recfile);
-extern uid_t getuserid(char name[]);
-extern int grabh(register struct header *hp, int gflags, int subjtop);
-extern int group(char **argv);
-extern void hangup(int);
-extern int hash(char name[]);
-extern char *hcontents(char hfield[]);
-extern int headerp(register char *line);
-extern int headers(int *msgvec);
-extern int help(void);
-extern char *helppath(char *file);
-extern char *hfield(char field[], struct message *mp, char *(*add)(char *, char *));
-extern void holdsigs(void);
-extern int icequal(register char *s1, register char *s2);
-extern int ifcmd(char **argv);
-extern int igfield(char *list[]);
-extern int inc(void);
-extern void inithost(void);
-extern int isdir(char name[]);
-extern int ishead(char linebuf[]);
-extern int ishfield(char linebuf[], char field[]);
-extern int ishost(char *sys, char *rest);
-extern int isign(char *field, int saving);
-extern void istrcpy(char *dest, int dstsize, char *src);
-extern void lcwrite(char *fn, FILE *fi, FILE *fo, int addnl);
-extern void load(char *name);
-extern int loadmsg(char str[]);
-extern int lock(FILE *fp, char *mode, int blk);
-extern void lockmail(void);
-extern int mail(char **people);
-extern void mail1(struct header *hp, int use_to, char *orig_to);
-extern void mapf(register struct name *np, char *from);
-extern int mboxit(int msgvec[]);
-extern void mechk(struct name *names);
-extern int member(register char *realfield, register struct ignore **table);
-extern int messize(int *msgvec);
-extern void minit(void);
-extern int more(int *msgvec);
-extern long msend(struct message *mailp, FILE *obuf, int flag, int (*fp)(const char *, FILE *));
-extern int my_fclose(register FILE *iop);
-extern FILE *my_fopen(char *file, char *mode);
-extern char *nameof(register struct message *mp);
-extern char *netmap(char name[], char from[]);
-extern int newfileinfo(int start);
-extern int next(int *msgvec);
-extern int npclose(FILE *ptr);
-extern FILE *npopen(char *cmd, char *mode);
-extern char *nstrcpy(char *dst, int dstsize, char *src);
-extern char *nstrcat(char *dst, int dstsize, char *src);
-extern int null(char *e);
-extern int outof(struct name *names, FILE *fo);
+extern int gethfield(register FILE *f, char linebuf[], register long rem);
+extern int getline(char *line, int size, FILE *f, int *hasnulls);
+extern int getmessage(char *buf, int *vector, int flags);
+extern int getmsglist(char *buf, int *vector, int flags);
+extern int getname(uid_t uid, char namebuf[]);
+extern int getrawlist(char line[], char **argv, int argc);
+extern void getrecf(char *buf, char *recfile,
+ int useauthor, int sz_recfile);
+extern uid_t getuserid(char name[]);
+extern int grabh(register struct header *hp, int gflags, int subjtop);
+extern int group(char **argv);
+extern void hangup(int);
+extern int hash(char name[]);
+extern char *hcontents(char hfield[]);
+extern int headerp(register char *line);
+extern int headers(int *msgvec);
+extern int help(void);
+extern char *helppath(char *file);
+extern char *hfield(char field[], struct message *mp,
+ char *(*add)(char *, char *));
+extern void holdsigs(void);
+extern int icequal(register char *s1, register char *s2);
+extern int ifcmd(char **argv);
+extern int igfield(char *list[]);
+extern int inc(void);
+extern void inithost(void);
+extern int isdir(char name[]);
+extern int ishead(char linebuf[]);
+extern int ishfield(char linebuf[], char field[]);
+extern int ishost(char *sys, char *rest);
+extern int isign(char *field, int saving);
+extern void istrcpy(char *dest, int dstsize, char *src);
+extern void lcwrite(char *fn, FILE *fi, FILE *fo, int addnl);
+extern void load(char *name);
+extern int loadmsg(char str[]);
+extern int lock(FILE *fp, char *mode, int blk);
+extern void lockmail(void);
+extern int mail(char **people);
+extern void mail1(struct header *hp, int use_to, char *orig_to);
+extern void mapf(register struct name *np, char *from);
+extern int mboxit(int msgvec[]);
+extern void mechk(struct name *names);
+extern int member(register char *realfield,
+ register struct ignore **table);
+extern int messize(int *msgvec);
+extern void minit(void);
+extern int more(int *msgvec);
+extern long msend(struct message *mailp, FILE *obuf,
+ int flag, int (*fp)(const char *, FILE *));
+extern int my_fclose(register FILE *iop);
+extern FILE *my_fopen(char *file, char *mode);
+extern char *nameof(register struct message *mp);
+extern char *netmap(char name[], char from[]);
+extern int newfileinfo(int start);
+extern int next(int *msgvec);
+extern int npclose(FILE *ptr);
+extern FILE *npopen(char *cmd, char *mode);
+extern char *nstrcpy(char *dst, int dstsize, char *src);
+extern char *nstrcat(char *dst, int dstsize, char *src);
+extern int null(char *e);
+extern int outof(struct name *names, FILE *fo);
extern struct name *outpre(struct name *to);
-extern void panic(char *str);
-extern void parse(char line[], struct headline *hl, char pbuf[]);
-extern int pcmdlist(void);
-extern int pdot(void);
-extern int preserve(int *msgvec);
-extern void printgroup(char name[]);
-extern void printhead(int mesg);
-extern int puthead(struct header *hp, FILE *fo, int w, long clen);
-extern int pversion(char *e);
-extern void quit(int noremove);
-extern int readline(FILE *ibuf, char *linebuf);
-extern void receipt(struct message *mp);
-extern void relsesigs(void);
-extern int removefile(char name[]);
-extern int replyall(int *msgvec);
-extern int replysender(int *msgvec);
-extern int respond(int *msgvec);
-extern int retfield(char *list[]);
-extern int rexit(int e);
-extern char *safeexpand(char name[]);
-extern void *salloc(unsigned size);
-extern void *srealloc(void *optr, unsigned size);
-extern int samebody(register char *user, register char *addr,
- int fuzzy);
-extern int save(char str[]);
-extern void savedead(int s);
-extern char *savestr(char *str);
-extern int schdir(char *str);
-extern int screensize(void);
-extern int scroll(char arg[]);
-extern int sendm(char *str);
-extern int set(char **arglist);
-extern void setclen(register struct message *mp);
-extern int setfile(char *name, int isedit);
-extern FILE *setinput(register struct message *mp);
-extern void setptr(register FILE *ibuf);
-extern int shell(char *str);
+extern void panic(char *str);
+extern void parse(char line[], struct headline *hl, char pbuf[]);
+extern int pcmdlist(void);
+extern int pdot(void);
+extern int preserve(int *msgvec);
+extern void printgroup(char name[]);
+extern void printhead(int mesg);
+extern int puthead(struct header *hp, FILE *fo, int w, long clen);
+extern int pversion(char *e);
+extern void quit(int noremove);
+extern int readline(FILE *ibuf, char *linebuf);
+extern void receipt(struct message *mp);
+extern void relsesigs(void);
+extern int removefile(char name[]);
+extern int replyall(int *msgvec);
+extern int replysender(int *msgvec);
+extern int respond(int *msgvec);
+extern int retfield(char *list[]);
+extern int rexit(int e);
+extern char *safeexpand(char name[]);
+extern void *salloc(unsigned size);
+extern void *srealloc(void *optr, unsigned size);
+extern int samebody(register char *user, register char *addr,
+ int fuzzy);
+extern int save(char str[]);
+extern void savedead(int s);
+extern char *savestr(char *str);
+extern int schdir(char *str);
+extern int screensize(void);
+extern int scroll(char arg[]);
+extern int sendm(char *str);
+extern int set(char **arglist);
+extern void setclen(register struct message *mp);
+extern int setfile(char *name, int isedit);
+extern FILE *setinput(register struct message *mp);
+extern void setptr(register FILE *ibuf);
+extern int shell(char *str);
#ifndef sigchild
extern void sigchild(void);
#endif
diff --git a/usr/src/cmd/mailx/lex.c b/usr/src/cmd/mailx/lex.c
index cd757dc911..d231a8412d 100644
--- a/usr/src/cmd/mailx/lex.c
+++ b/usr/src/cmd/mailx/lex.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * 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
* or http://www.opensolaris.org/os/licensing.
@@ -19,15 +18,15 @@
*
* CDDL HEADER END
*/
-/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
-/* All Rights Reserved */
-
/*
- * Copyright 1998-2002 Sun Microsystems, Inc. All rights reserved.
+ * 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
@@ -65,7 +64,7 @@ static void setmsize(int sz);
* mbox and so forth.
*/
-int
+int
setfile(char *name, int isedit)
{
FILE *ibuf;
@@ -86,16 +85,16 @@ setfile(char *name, int isedit)
goto doret;
}
if ((ibuf = fopen(name, "r")) == NULL) {
- extern int errno;
+ extern int errno;
int sverrno = errno;
- int filethere = (access(name,0) == 0);
+ int filethere = (access(name, 0) == 0);
errno = sverrno;
if (exitflg)
goto doexit; /* no mail, return error */
if (isedit || filethere)
perror(name);
else if (!Hflag) {
- char *f = strrchr(name,'/');
+ char *f = strrchr(name, '/');
if (f == NOSTR)
fprintf(stderr, gettext("No mail.\n"));
else
@@ -116,7 +115,7 @@ name);
fprintf(stderr,
gettext("%s: not a regular file\n"), name);
else if (!Hflag) {
- if (strrchr(name,'/') == NOSTR)
+ if (strrchr(name, '/') == NOSTR)
fprintf(stderr, gettext("No mail.\n"));
else
fprintf(stderr, gettext("No mail for %s\n"),
@@ -126,7 +125,11 @@ strrchr(name, '/') + 1);
goto doret;
}
- fgets(fortest, sizeof fortest, ibuf);
+ if (fgets(fortest, sizeof (fortest), ibuf) == NULL) {
+ perror(gettext("mailx: Unable to read from mail file"));
+ goto doexit;
+ }
+
fseek(ibuf, (long)(BUFSIZ+1), 0); /* flush input buffer */
fseek(ibuf, 0L, 0);
if (strncmp(fortest, "Forward to ", 11) == 0) {
@@ -170,11 +173,11 @@ fortest+11);
fclose(itf);
fclose(otf);
free(message);
- space=0;
+ space = 0;
}
readonly = 0;
if (!isedit && issysmbox && !Hflag)
- readonly = Passeren()==-1;
+ readonly = Passeren() == -1;
lock(ibuf, "r", 1);
fstat(fileno(ibuf), &stbuf);
utimep->actime = stbuf.st_atime;
@@ -215,12 +218,12 @@ fortest+11);
sawcom = 0;
rc = 0;
- doret:
+doret:
if (!isedit && issysmbox)
unlockmail();
- return(rc);
+ return (rc);
- doexit:
+doexit:
if (!isedit && issysmbox)
unlockmail();
exit(exrc ? exrc : rpterr);
@@ -240,14 +243,14 @@ Passeren(void)
char *home;
if ((home = getenv("HOME")) == NULL)
- return 0;
- snprintf(semfn, sizeof (semfn), "%s%s", home, "/.Maillock");
+ return (0);
+ snprintf(semfn, sizeof (semfn), "%s%s", home, "/.Maillock");
if ((semfp = fopen(semfn, "w")) == NULL) {
fprintf(stderr,
gettext("WARNING: Can't open mail lock file (%s).\n"), semfn);
fprintf(stderr,
gettext("\t Assuming you are not already reading mail.\n"));
- return 0;
+ return (0);
}
if (lock(semfp, "w", 0) < 0) {
if (errno == ENOLCK) {
@@ -255,7 +258,7 @@ Passeren(void)
gettext("WARNING: Unable to acquire mail lock, no record locks available.\n"));
fprintf(stderr,
gettext("\t Assuming you are not already reading mail.\n"));
- return 0;
+ return (0);
}
fprintf(stderr,
gettext("WARNING: You are already reading mail.\n"));
@@ -263,12 +266,12 @@ gettext("WARNING: Unable to acquire mail lock, no record locks available.\n"));
gettext("\t This instance of mail is read only.\n"));
fclose(semfp);
semfp = NULL;
- return -1;
+ return (-1);
}
- return 0;
+ return (0);
}
-void
+void
Verhogen(void)
{
if (semfp != NULL) {
@@ -285,7 +288,7 @@ Verhogen(void)
static int *msgvec;
static int shudprompt;
-void
+void
commands(void)
{
int eofloop;
@@ -317,17 +320,17 @@ commands(void)
eofloop = 0;
top:
if ((shudprompt = (intty && !sourcing)) != 0) {
- if (prompt==NOSTR) {
+ if (prompt == NOSTR) {
if ((int)value("bsdcompat"))
prompt = "& ";
else
- prompt = "";
+ prompt = "";
}
#ifdef SIGCONT
sigset(SIGCONT, contin);
#endif
if (intty && value("autoinc") &&
- stat(editfile, &minfo) >=0 &&
+ stat(editfile, &minfo) >= 0 &&
minfo.st_size > mailsize) {
int OmsgCount, i;
@@ -336,7 +339,7 @@ top:
holdsigs();
if (!edit && issysmbox)
lockmail();
- if ((ibuf = fopen(editfile, "r")) == NULL ) {
+ if ((ibuf = fopen(editfile, "r")) == NULL) {
fprintf(stderr,
gettext("Can't reopen %s\n"),
editfile);
@@ -366,7 +369,7 @@ top:
msgCount-OmsgCount);
if (value("header") != NOSTR)
for (i = OmsgCount+1;
- i <= msgCount; i++) {
+ i <= msgCount; i++) {
printhead(i);
sreset();
}
@@ -427,13 +430,13 @@ top:
}
return;
}
- strncat(linebuf, line, n);
+ strncat(linebuf, line, n);
#ifdef SIGCONT
sigset(SIGCONT, SIG_DFL);
#endif
if (execute(linebuf, 0))
return;
-more: ;
+more:;
}
}
@@ -444,7 +447,7 @@ more: ;
* Contxt is non-zero if called while composing mail.
*/
-int
+int
execute(char linebuf[], int contxt)
{
char word[LINESIZE];
@@ -483,19 +486,19 @@ execute(char linebuf[], int contxt)
*/
if (sourcing && equal(word, ""))
- return(0);
+ return (0);
com = lex(word);
if (com == NONE) {
fprintf(stderr, gettext("Unknown command: \"%s\"\n"), word);
if (loading) {
cond = CANY;
- return(1);
+ return (1);
}
if (sourcing) {
cond = CANY;
unstack();
}
- return(0);
+ return (0);
}
/*
@@ -506,7 +509,7 @@ execute(char linebuf[], int contxt)
if ((com->c_argtype & F) == 0)
if (cond == CRCV && !rcvmode || cond == CSEND && rcvmode ||
cond == CTTY && !intty || cond == CNOTTY && intty)
- return(0);
+ return (0);
/*
* Special case so that quit causes a return to
@@ -517,11 +520,11 @@ execute(char linebuf[], int contxt)
if (com->c_func == (int (*)(void *))edstop) {
if (sourcing) {
if (loading)
- return(1);
+ return (1);
unstack();
- return(0);
+ return (0);
}
- return(1);
+ return (1);
}
/*
@@ -536,10 +539,10 @@ execute(char linebuf[], int contxt)
gettext("May not execute \"%s\" while sending\n"),
com->c_name);
if (loading)
- return(1);
+ return (1);
if (sourcing)
unstack();
- return(0);
+ return (0);
}
if (sourcing && com->c_argtype & I) {
fprintf(stderr,
@@ -547,24 +550,24 @@ execute(char linebuf[], int contxt)
com->c_name);
rpterr = 1;
if (loading)
- return(1);
+ return (1);
unstack();
- return(0);
+ return (0);
}
if (readonly && com->c_argtype & W) {
fprintf(stderr, gettext(
"May not execute \"%s\" -- message file is read only\n"),
com->c_name);
if (loading)
- return(1);
+ return (1);
if (sourcing)
unstack();
- return(0);
+ return (0);
}
if (contxt && com->c_argtype & R) {
fprintf(stderr, gettext("Cannot recursively invoke \"%s\"\n"),
com->c_name);
- return(0);
+ return (0);
}
e = 1;
switch (com->c_argtype & ~(F|P|I|M|T|W|R)) {
@@ -576,7 +579,7 @@ execute(char linebuf[], int contxt)
if (msgvec == 0) {
fprintf(stderr,
gettext("Illegal use of \"message list\"\n"));
- return(-1);
+ return (-1);
}
if ((c = getmsglist(cp, msgvec, com->c_msgflag)) < 0)
break;
@@ -597,15 +600,16 @@ execute(char linebuf[], int contxt)
case NDMLIST:
/*
- * A message list with no defaults, but no error
- * if none exist.
+ * 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) {
fprintf(stderr,
- gettext("Illegal use of \"message list\"\n"));
- return(-1);
+ gettext("Illegal use of \"message operand\"\n"));
+ return (-1);
}
- if (getmsglist(cp, msgvec, com->c_msgflag) < 0)
+ if (getmessage(cp, msgvec, com->c_msgflag) < 0)
break;
e = (*com->c_func)(msgvec);
break;
@@ -625,7 +629,7 @@ execute(char linebuf[], int contxt)
* A vector of strings, in shell style.
*/
if ((c = getrawlist(cp, arglist,
- sizeof arglist / sizeof *arglist)) < 0)
+ sizeof (arglist) / sizeof (*arglist))) < 0)
break;
if (c < com->c_minargs) {
fprintf(stderr,
@@ -660,11 +664,11 @@ execute(char linebuf[], int contxt)
*/
if (e && loading)
- return(1);
+ return (1);
if (e && sourcing)
unstack();
if (com->c_func == (int (*)(void *))edstop)
- return(1);
+ return (1);
if (value("autoprint") != NOSTR && com->c_argtype & P)
if ((dot->m_flag & MDELETED) == 0) {
muvec[0] = dot - &message[0] + 1;
@@ -673,14 +677,14 @@ execute(char linebuf[], int contxt)
}
if (!sourcing && (com->c_argtype & T) == 0)
sawcom = 1;
- return(0);
+ return (0);
}
#ifdef SIGCONT
/*
* When we wake up after ^Z, reprint the prompt.
*/
-static void
+static void
#ifdef __cplusplus
contin(int)
#else
@@ -697,7 +701,7 @@ contin(int s)
/*
* Branch here on hangup signal and simulate quit.
*/
-void
+void
#ifdef __cplusplus
hangup(int)
#else
@@ -707,9 +711,9 @@ hangup(int s)
{
holdsigs();
-# ifdef OLD_BSD_SIGS
+#ifdef OLD_BSD_SIGS
sigignore(SIGHUP);
-# endif
+#endif
if (edit) {
if (setjmp(srbuf))
exit(rpterr);
@@ -730,11 +734,11 @@ hangup(int s)
* lists to message list functions.
*/
-static void
+static void
setmsize(int sz)
{
- if (msgvec != (int *) 0)
+ if (msgvec != (int *)0)
free(msgvec);
if (sz < 1)
sz = 1; /* need at least one cell for terminating 0 */
@@ -755,14 +759,14 @@ lex(char word[])
for (cp = &cmdtab[0]; cp->c_name != NOSTR; cp++)
if (isprefix(word, cp->c_name))
- return(cp);
- return(NONE);
+ return (cp);
+ return (NONE);
}
/*
* Determine if as1 is a valid prefix of as2.
*/
-static int
+static int
isprefix(char *as1, char *as2)
{
register char *s1, *s2;
@@ -771,8 +775,8 @@ isprefix(char *as1, char *as2)
s2 = as2;
while (*s1++ == *s2)
if (*s2++ == '\0')
- return(1);
- return(*--s1 == '\0');
+ return (1);
+ return (*--s1 == '\0');
}
/*
@@ -787,7 +791,7 @@ isprefix(char *as1, char *as2)
static int inithdr; /* am printing startup headers */
-void
+void
stop(int s)
{
register NODE *head;
@@ -798,7 +802,7 @@ stop(int s)
inithdr = 0;
while (sourcing)
unstack();
- getuserid((char *) 0);
+ (void) getuserid((char *)0);
for (head = fplist; head != (NODE *)NULL; head = head->next) {
if (head->fp == stdin || head->fp == stdout)
continue;
@@ -822,9 +826,9 @@ stop(int s)
if (s) {
fprintf(stderr, gettext("Interrupt\n"));
fflush(stderr);
-# ifdef OLD_BSD_SIGS
+#ifdef OLD_BSD_SIGS
sigrelse(s);
-# endif
+#endif
}
longjmp(srbuf, 1);
}
@@ -836,13 +840,13 @@ stop(int s)
#define GREETING "%s Type ? for help.\n"
-void
+void
announce(void)
{
int vec[2], mdot;
extern const char *const version;
- if (!Hflag && value("quiet")==NOSTR)
+ if (!Hflag && value("quiet") == NOSTR)
printf(gettext(GREETING), version);
mdot = newfileinfo(1);
vec[0] = mdot;
@@ -859,7 +863,7 @@ announce(void)
* Announce information about the file we are editing.
* Return a likely place to set dot.
*/
-int
+int
newfileinfo(int start)
{
register struct message *mp;
@@ -867,7 +871,7 @@ newfileinfo(int start)
char fname[BUFSIZ], zname[BUFSIZ], *ename;
if (Hflag)
- return(1); /* fake it--return message 1 */
+ return (1); /* fake it--return message 1 */
for (mp = &message[start - 1]; mp < &message[msgCount]; mp++)
if ((mp->m_flag & (MNEW|MREAD)) == MNEW)
break;
@@ -890,7 +894,7 @@ newfileinfo(int start)
if (mp->m_flag & MSAVED)
s++;
}
- ename=origname;
+ ename = origname;
if (getfold(fname) >= 0) {
nstrcat(fname, sizeof (fname), "/");
if (strncmp(fname, editfile, strlen(fname)) == 0) {
@@ -915,14 +919,14 @@ newfileinfo(int start)
if (readonly)
printf(gettext(" [Read only]"));
printf("\n");
- return(mdot);
+ return (mdot);
}
/*
* Print the current version number.
*/
-int
+int
#ifdef __cplusplus
pversion(char *)
#else
@@ -931,13 +935,13 @@ pversion(char *s)
#endif
{
printf("%s\n", version);
- return(0);
+ return (0);
}
/*
* Load a file of user definitions.
*/
-void
+void
load(char *name)
{
register FILE *in, *oldin;
@@ -962,7 +966,7 @@ load(char *name)
* system mailbox, this probably ought to as well.
*/
-int
+int
inc(void)
{
FILE *ibuf;
@@ -972,7 +976,7 @@ inc(void)
if (edit) {
fprintf(stderr, gettext("Not in system mailbox\n"));
- return(-1);
+ return (-1);
}
if (((ibuf = fopen(mailname, "r")) == NULL) ||
(fstat(fileno(ibuf), &stbuf) < 0) || stbuf.st_size == 0L ||
@@ -984,7 +988,7 @@ inc(void)
strrchr(mailname, '/')+1);
if (ibuf != NULL)
fclose(ibuf);
- return(-1);
+ return (-1);
}
fseek(otf, 0L, 2);
@@ -1002,5 +1006,5 @@ inc(void)
mdot = newfileinfo(firstnewmsg);
dot = &message[mdot - 1];
sawcom = 0;
- return(0);
+ return (0);
}
diff --git a/usr/src/cmd/mailx/list.c b/usr/src/cmd/mailx/list.c
index 20d9d6e517..4c608a1103 100644
--- a/usr/src/cmd/mailx/list.c
+++ b/usr/src/cmd/mailx/list.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * 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
* or http://www.opensolaris.org/os/licensing.
@@ -19,15 +18,15 @@
*
* CDDL HEADER END
*/
-/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
-/* All Rights Reserved */
-
/*
- * Copyright (c) 1985-2001 by Sun Microsystems, Inc.
- * All rights reserved.
+ * 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
@@ -37,7 +36,6 @@
* software developed by the University of California, Berkeley, and its
* contributors.
*/
-
#pragma ident "%Z%%M% %I% %E% SMI"
#include "rcv.h"
@@ -63,28 +61,76 @@ static int sender(char *str, int mesg);
static void unmark(int mesg);
/*
+ * Process message operand list.
+ * Convert the user string of message numbers and
+ * store the numbers into vector.
+ *
+ * Returns the count of messages picked up or -1 on error.
+ */
+int
+getmessage(char *buf, int *vector, int flags)
+{
+ register int *ip;
+ register struct message *mp;
+ int i, firstmsg = -1;
+
+ if (markall(buf, flags) < 0)
+ return (-1);
+ ip = vector;
+
+ /*
+ * Check for first message number and make sure it is
+ * at the beginning of the vector.
+ */
+ i = 0;
+ while (any(buf[i], " \t"))
+ i++;
+
+ if (isdigit(buf[i])) {
+ firstmsg = buf[i] - '0';
+ *ip++ = firstmsg;
+ }
+
+ /*
+ * Add marked messages to vector and skip first
+ * message number because it is already at the
+ * beginning of the vector
+ */
+ for (mp = &message[0]; mp < &message[msgCount]; mp++) {
+ if (firstmsg == mp - &message[0] + 1)
+ continue;
+ if (mp->m_flag & MMARK)
+ *ip++ = mp - &message[0] + 1;
+ }
+ *ip = NULL;
+ return (ip - vector);
+}
+
+/*
+ * Process msglist operand list.
* Convert the user string of message numbers and
* store the numbers into vector.
*
* Returns the count of messages picked up or -1 on error.
*/
-int
+int
getmsglist(char *buf, int *vector, int flags)
{
register int *ip;
register struct message *mp;
if (markall(buf, flags) < 0)
- return(-1);
+ return (-1);
ip = vector;
for (mp = &message[0]; mp < &message[msgCount]; mp++)
if (mp->m_flag & MMARK)
*ip++ = mp - &message[0] + 1;
*ip = NULL;
- return(ip - vector);
+ return (ip - vector);
}
+
/*
* Mark all messages that the user wanted from the command
* line in the message structure. Return 0 on success, -1
@@ -122,7 +168,7 @@ static struct coltab {
static int lastcolmod;
-static int
+static int
markall(char buf[], int f)
{
register char **np;
@@ -148,13 +194,13 @@ markall(char buf[], int f)
number:
if (star) {
printf(gettext("No numbers mixed with *\n"));
- return(-1);
+ return (-1);
}
mc++;
other++;
if (beg != 0) {
if (check(lexnumber, f))
- return(-1);
+ return (-1);
for (i = beg; i <= lexnumber; i++)
if ((message[i-1].m_flag&MDELETED) == f)
mark(i);
@@ -163,7 +209,7 @@ number:
}
beg = lexnumber;
if (check(beg, f))
- return(-1);
+ return (-1);
tok = scan(&bufp);
if (tok != TDASH) {
regret(tok);
@@ -176,7 +222,7 @@ number:
if (beg != 0) {
printf(gettext(
"Non-numeric second argument\n"));
- return(-1);
+ return (-1);
}
other++;
if (lexstring[0] == ':') {
@@ -185,7 +231,7 @@ number:
printf(gettext(
"Unknown colon modifier \"%s\"\n"),
lexstring);
- return(-1);
+ return (-1);
}
colmod |= colresult;
}
@@ -200,14 +246,14 @@ number:
case TDOT:
lexnumber = metamess(lexstring[0], f);
if (lexnumber == -1)
- return(-1);
+ return (-1);
goto number;
case TSTAR:
if (other) {
printf(gettext(
"Can't mix \"*\" with anything\n"));
- return(-1);
+ return (-1);
}
star++;
break;
@@ -225,9 +271,9 @@ number:
}
if (mc == 0) {
printf(gettext("No applicable messages\n"));
- return(-1);
+ return (-1);
}
- return(0);
+ return (0);
}
/*
@@ -254,8 +300,7 @@ number:
mc++;
break;
}
- }
- else {
+ } else {
if (sender(*np, i)) {
mc++;
break;
@@ -281,7 +326,7 @@ namelist[0]);
for (np = &namelist[1]; *np != NOSTR; np++)
printf(", %s", *np);
printf("}\n");
- return(-1);
+ return (-1);
}
}
@@ -313,47 +358,47 @@ namelist[0]);
if (colp->co_bit & colmod)
printf(" :%c", colp->co_char);
printf("\n");
- return(-1);
+ return (-1);
}
}
- return(0);
+ return (0);
}
/*
* Turn the character after a colon modifier into a bit
* value.
*/
-static int
+static int
evalcol(int col)
{
register struct coltab *colp;
if (col == 0)
- return(lastcolmod);
+ return (lastcolmod);
for (colp = &coltab[0]; colp->co_char; colp++)
if (colp->co_char == col)
- return(colp->co_bit);
- return(0);
+ return (colp->co_bit);
+ return (0);
}
/*
* Check the passed message number for legality and proper flags.
*/
-static int
+static int
check(int mesg, int f)
{
register struct message *mp;
if (mesg < 1 || mesg > msgCount) {
printf(gettext("%d: Invalid message number\n"), mesg);
- return(-1);
+ return (-1);
}
mp = &message[mesg-1];
if ((mp->m_flag & MDELETED) != f) {
printf(gettext("%d: Inappropriate message\n"), mesg);
- return(-1);
+ return (-1);
}
- return(0);
+ return (0);
}
/*
@@ -361,7 +406,7 @@ check(int mesg, int f)
* for a RAWLIST.
*/
-int
+int
getrawlist(char line[], char **argv, int argc)
{
register char **ap, *cp, *cp2;
@@ -379,7 +424,7 @@ getrawlist(char line[], char **argv, int argc)
while (*cp != '\0') {
if (quotec) {
if (*cp == quotec) {
- quotec=0;
+ quotec = 0;
cp++;
} else
*cp2++ = *cp++;
@@ -390,7 +435,7 @@ getrawlist(char line[], char **argv, int argc)
cp++;
} else {
printf(gettext(
- "Trailing \\; ignoring\n"));
+ "Trailing \\; ignoring\n"));
break;
}
}
@@ -406,14 +451,14 @@ getrawlist(char line[], char **argv, int argc)
if (cp2 == linebuf)
break;
if (ap >= last) {
- printf(gettext(
- "Too many elements in the list; excess discarded\n"));
+ printf(gettext("Too many elements in the list;"
+ " excess discarded\n"));
break;
}
*ap++ = savestr(linebuf);
}
*ap = NOSTR;
- return(ap-argv);
+ return (ap-argv);
}
/*
@@ -438,7 +483,7 @@ static struct lex {
0, 0
};
-static int
+static int
scan(char **sp)
{
register char *cp, *cp2;
@@ -449,7 +494,7 @@ scan(char **sp)
if (regretp >= 0) {
copy(stringstack[regretp], lexstring);
lexnumber = numberstack[regretp];
- return(regretstack[regretp--]);
+ return (regretstack[regretp--]);
}
cp = *sp;
cp2 = lexstring;
@@ -469,7 +514,7 @@ scan(char **sp)
if (c == '\0') {
*sp = --cp;
- return(TEOL);
+ return (TEOL);
}
/*
@@ -487,7 +532,7 @@ scan(char **sp)
}
*cp2 = '\0';
*sp = --cp;
- return(TNUMBER);
+ return (TNUMBER);
}
/*
@@ -500,7 +545,7 @@ scan(char **sp)
lexstring[0] = c;
lexstring[1] = '\0';
*sp = cp;
- return(lp->l_token);
+ return (lp->l_token);
}
/*
@@ -539,14 +584,14 @@ scan(char **sp)
fprintf(stderr, gettext("Missing %c\n"), quotec);
*sp = --cp;
*cp2 = '\0';
- return(TSTRING);
+ return (TSTRING);
}
/*
* Unscan the named token by pushing it onto the regret stack.
*/
-static void
+static void
regret(int token)
{
if (++regretp >= REGDEP)
@@ -561,7 +606,7 @@ regret(int token)
* Reset all the scanner global variables.
*/
-static void
+static void
scaninit(void)
{
regretp = -1;
@@ -572,7 +617,7 @@ scaninit(void)
* its message number.
*/
-int
+int
first(int f, int m)
{
register int mesg;
@@ -583,23 +628,23 @@ first(int f, int m)
m &= MDELETED;
for (mp = dot; mp < &message[msgCount]; mp++) {
if ((mp->m_flag & m) == f)
- return(mesg);
+ return (mesg);
mesg++;
}
mesg = dot - &message[0];
for (mp = dot-1; mp >= &message[0]; mp--) {
if ((mp->m_flag & m) == f)
- return(mesg);
+ return (mesg);
mesg--;
}
- return(NULL);
+ return (NULL);
}
/*
* See if the passed name sent the passed message number. Return true
* if so.
*/
-static int
+static int
sender(char *str, int mesg)
{
return (samebody(str, skin(nameof(&message[mesg-1])), TRUE));
@@ -615,7 +660,7 @@ sender(char *str, int mesg)
static char lastscan[128];
-static int
+static int
matchsubj(char *str, int mesg)
{
register struct message *mp;
@@ -635,24 +680,24 @@ matchsubj(char *str, int mesg)
cp = str;
cp2 = hfield("subject", mp, addone);
if (cp2 == NOSTR)
- return(0);
+ return (0);
backup = cp2;
while (*cp2) {
if (*cp == 0)
- return(1);
+ return (1);
if (toupper(*cp++) != toupper(*cp2++)) {
cp2 = ++backup;
cp = str;
}
}
- return(*cp == 0);
+ return (*cp == 0);
}
/*
* Mark the named message by setting its mark bit.
*/
-static void
+static void
mark(int mesg)
{
register int i;
@@ -667,7 +712,7 @@ mark(int mesg)
* Unmark the named message.
*/
-static void
+static void
unmark(int mesg)
{
register int i;
@@ -681,7 +726,7 @@ unmark(int mesg)
/*
* Return the message number corresponding to the passed meta character.
*/
-static int
+static int
metamess(int meta, int f)
{
register int c, m;
@@ -695,9 +740,9 @@ metamess(int meta, int f)
*/
for (mp = &message[0]; mp < &message[msgCount]; mp++)
if ((mp->m_flag & MDELETED) == f)
- return(mp - &message[0] + 1);
+ return (mp - &message[0] + 1);
printf(gettext("No applicable messages\n"));
- return(-1);
+ return (-1);
case '+':
/*
@@ -705,9 +750,9 @@ metamess(int meta, int f)
*/
for (mp = dot + 1; mp < &message[msgCount]; mp++)
if ((mp->m_flag & MDELETED) == f)
- return(mp - &message[0] + 1);
+ return (mp - &message[0] + 1);
printf(gettext("Referencing beyond last message\n"));
- return(-1);
+ return (-1);
case '-':
/*
@@ -715,9 +760,9 @@ metamess(int meta, int f)
*/
for (mp = dot - 1; mp >= &message[0]; mp--)
if ((mp->m_flag & MDELETED) == f)
- return(mp - &message[0] + 1);
+ return (mp - &message[0] + 1);
printf(gettext("Referencing before first message\n"));
- return(-1);
+ return (-1);
case '$':
/*
@@ -725,23 +770,23 @@ metamess(int meta, int f)
*/
for (mp = &message[msgCount-1]; mp >= &message[0]; mp--)
if ((mp->m_flag & MDELETED) == f)
- return(mp - &message[0] + 1);
+ return (mp - &message[0] + 1);
printf(gettext("No applicable messages\n"));
- return(-1);
+ return (-1);
case '.':
- /*
+ /*
* Current message.
*/
m = dot - &message[0] + 1;
if ((dot->m_flag & MDELETED) != f) {
printf(gettext("%d: Inappropriate message\n"), m);
- return(-1);
+ return (-1);
}
- return(m);
+ return (m);
default:
printf(gettext("Unknown metachar (%c)\n"), c);
- return(-1);
+ return (-1);
}
}