dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / mail / parse.c
blob6fc32764f1eb10c89fc847e8235c0da64d5cc6d1
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include "mail.h"
35 Parse the command line.
36 Return index of first non-option field (i.e. user)
38 int
39 parse(int argc, char **argv)
41 int c;
42 char *tmailsurr;
43 static char pn[] = "parse";
46 "mail +" means to print in reverse order and is
47 equivalent to "mail -r"
49 if ((argc > 1) && (argv[1][0] == '+')) {
50 if (ismail) {
51 argv[1] = "-r";
52 } else {
53 goerr++;
57 while ((c = getopt(argc, argv, "m:f:x:shrpPqeEdtT:w")) != EOF) {
58 switch(c) {
60 Set debugging level...
62 case 'x':
63 debug = atoi(optarg);
64 orig_dbglvl = debug;
65 if (debug < 0) {
66 /* Keep trace file even if successful */
67 keepdbgfile = -1;
68 debug = -debug;
70 break;
73 for backwards compatability with mailx...
75 case 's':
76 /* ignore this option */
77 break;
78 /*
79 * Deliver directly to a mailbox. Do Not go to sendmail
81 case 'd':
82 deliverflag = TRUE;
83 break;
86 do not print mail
88 case 'e':
89 if (ismail) {
90 flge = 1;
91 } else {
92 goerr++;
94 optcnt++;
95 break;
97 do not print mail
99 case 'E':
100 if (ismail) {
101 flgE = 1;
102 } else {
103 goerr++;
105 optcnt++;
106 break;
108 * use alternate file as mailfile, when reading mail
109 * use this from user when sending mail.
111 case 'f':
112 flgf = 1;
113 fromflag = TRUE;
114 mailfile = optarg;
115 strncpy(from_user, optarg, sizeof (from_user));
116 from_user[sizeof (from_user) - 1] = '\0';
117 optcnt++;
118 break;
121 Print headers first
123 case 'h':
124 if (ismail) {
125 flgh = 1;
126 } else {
127 goerr++;
129 optcnt++;
130 break;
133 print without prompting
135 case 'p':
136 if (ismail) {
137 flgp++;
138 } else {
139 goerr++;
141 optcnt++;
142 break;
145 override selective display default setting
146 when reading mail...
148 case 'P':
149 if (ismail) {
150 flgP++;
152 optcnt++;
153 break;
156 terminate on deletes
158 case 'q':
159 if (ismail) {
160 delflg = 0;
161 } else {
162 goerr++;
164 optcnt++;
165 break;
168 print by first in, first out order
170 case 'r':
171 if (ismail) {
172 flgr = 1;
173 } else {
174 goerr++;
176 optcnt++;
177 break;
180 add To: line to letters
182 case 't':
183 flgt = 1;
184 optcnt++;
185 break;
188 don't wait on sends
190 case 'w':
191 flgw = 1;
192 break;
195 set message-type:
197 case 'm':
198 msgtype = optarg;
199 if (msgtype[0] == '\0' || msgtype[0] == '-') {
200 goerr++;
201 } else {
202 flgm = 1;
204 break;
207 bad option
209 case '?':
210 goerr++;
211 break;
217 if (argc == optind) {
219 if (flgm) {
220 errmsg(E_SYNTAX,
221 "-m option used but no recipient(s) specified.");
222 goerr++;
224 if (flgt) {
225 errmsg(E_SYNTAX,
226 "-t option used but no recipient(s) specified.");
227 goerr++;
229 if (flgw) {
230 errmsg(E_SYNTAX,
231 "-w option used but no recipient(s) specified.");
232 goerr++;
234 if (flgf) {
235 if (mailfile[0] == '-') {
236 errmsg(E_SYNTAX,
237 "Files names must not begin with '-'");
238 done(0);
240 if (!ismail)
241 goerr++;
245 if (ismail && (goerr > 0)) {
246 errmsg(E_SYNTAX,"Usage: [-ehpPqr] [-f file] [-x debuglevel]");
247 (void) fprintf (stderr, "or\t[-tw] [-m message_type] [-T file] [-x debuglevel] persons\n");
248 (void) fprintf (stderr, "or\t[-x debuglevel]\n");
249 done(0);
252 return (optind);