#include "mail.h"
int
parse(int argc, char **argv)
{
int c;
char *tmailsurr;
static char pn[] = "parse";
if ((argc > 1) && (argv[1][0] == '+')) {
if (ismail) {
argv[1] = "-r";
} else {
goerr++;
}
}
while ((c = getopt(argc, argv, "m:f:x:shrpPqeEdtT:w")) != EOF) {
switch(c) {
case 'x':
debug = atoi(optarg);
orig_dbglvl = debug;
if (debug < 0) {
keepdbgfile = -1;
debug = -debug;
}
break;
case 's':
break;
case 'd':
deliverflag = TRUE;
break;
case 'e':
if (ismail) {
flge = 1;
} else {
goerr++;
}
optcnt++;
break;
case 'E':
if (ismail) {
flgE = 1;
} else {
goerr++;
}
optcnt++;
break;
case 'f':
flgf = 1;
fromflag = TRUE;
mailfile = optarg;
strncpy(from_user, optarg, sizeof (from_user));
from_user[sizeof (from_user) - 1] = '\0';
optcnt++;
break;
case 'h':
if (ismail) {
flgh = 1;
} else {
goerr++;
}
optcnt++;
break;
case 'p':
if (ismail) {
flgp++;
} else {
goerr++;
}
optcnt++;
break;
case 'P':
if (ismail) {
flgP++;
}
optcnt++;
break;
case 'q':
if (ismail) {
delflg = 0;
} else {
goerr++;
}
optcnt++;
break;
case 'r':
if (ismail) {
flgr = 1;
} else {
goerr++;
}
optcnt++;
break;
case 't':
flgt = 1;
optcnt++;
break;
case 'w':
flgw = 1;
break;
case 'm':
msgtype = optarg;
if (msgtype[0] == '\0' || msgtype[0] == '-') {
goerr++;
} else {
flgm = 1;
}
break;
case '?':
goerr++;
break;
}
}
if (argc == optind) {
if (flgm) {
errmsg(E_SYNTAX,
"-m option used but no recipient(s) specified.");
goerr++;
}
if (flgt) {
errmsg(E_SYNTAX,
"-t option used but no recipient(s) specified.");
goerr++;
}
if (flgw) {
errmsg(E_SYNTAX,
"-w option used but no recipient(s) specified.");
goerr++;
}
if (flgf) {
if (mailfile[0] == '-') {
errmsg(E_SYNTAX,
"Files names must not begin with '-'");
done(0);
}
if (!ismail)
goerr++;
}
}
if (ismail && (goerr > 0)) {
errmsg(E_SYNTAX,"Usage: [-ehpPqr] [-f file] [-x debuglevel]");
(void) fprintf (stderr, "or\t[-tw] [-m message_type] [-T file] [-x debuglevel] persons\n");
(void) fprintf (stderr, "or\t[-x debuglevel]\n");
done(0);
}
return (optind);
}