1 /* 2 * CDDL HEADER START 3 * 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. 8 * 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. 13 * 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] 19 * 20 * CDDL HEADER END 21 */ 22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23 /* All Rights Reserved */ 24 25 26 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 2.1 */ 27 #include "mail.h" 28 /* 29 Parse the command line. 30 Return index of first non-option field (i.e. user) 31 */ 32 parse(argc, argv) 33 int argc; 34 char **argv; 35 { 36 register int c; 37 register char *tmailsurr; 38 static char pn[] = "parse"; 39 40 /* 41 "mail +" means to print in reverse order and is 42 equivalent to "mail -r" 43 */ 44 if ((argc > 1) && (argv[1][0] == '+')) { 45 if (ismail) { 46 argv[1] = "-r"; 47 } else { 48 goerr++; 49 } 50 } 51 52 while ((c = getopt(argc, argv, "m:f:x:shrpPqeEdtT:w")) != EOF) { 53 switch(c) { 54 /* 55 Set debugging level... 56 */ 57 case 'x': 58 debug = atoi(optarg); 59 orig_dbglvl = debug; 60 if (debug < 0) { 61 /* Keep trace file even if successful */ 62 keepdbgfile = -1; 63 debug = -debug; 64 } 65 break; 66 67 /* 68 for backwards compatability with mailx... 69 */ 70 case 's': 71 /* ignore this option */ 72 break; 73 /* 74 * Deliver directly to a mailbox. Do Not go to sendmail 75 */ 76 case 'd': 77 deliverflag = TRUE; 78 break; 79 80 /* 81 do not print mail 82 */ 83 case 'e': 84 if (ismail) { 85 flge = 1; 86 } else { 87 goerr++; 88 } 89 optcnt++; 90 break; 91 /* 92 do not print mail 93 */ 94 case 'E': 95 if (ismail) { 96 flgE = 1; 97 } else { 98 goerr++; 99 } 100 optcnt++; 101 break; 102 /* 103 * use alternate file as mailfile, when reading mail 104 * use this from user when sending mail. 105 */ 106 case 'f': 107 flgf = 1; 108 fromflag = TRUE; 109 mailfile = optarg; 110 strncpy(from_user, optarg, sizeof (from_user)); 111 from_user[sizeof (from_user) - 1] = '\0'; 112 optcnt++; 113 break; 114 115 /* 116 Print headers first 117 */ 118 case 'h': 119 if (ismail) { 120 flgh = 1; 121 } else { 122 goerr++; 123 } 124 optcnt++; 125 break; 126 127 /* 128 print without prompting 129 */ 130 case 'p': 131 if (ismail) { 132 flgp++; 133 } else { 134 goerr++; 135 } 136 optcnt++; 137 break; 138 139 /* 140 override selective display default setting 141 when reading mail... 142 */ 143 case 'P': 144 if (ismail) { 145 flgP++; 146 } 147 optcnt++; 148 break; 149 150 /* 151 terminate on deletes 152 */ 153 case 'q': 154 if (ismail) { 155 delflg = 0; 156 } else { 157 goerr++; 158 } 159 optcnt++; 160 break; 161 162 /* 163 print by first in, first out order 164 */ 165 case 'r': 166 if (ismail) { 167 flgr = 1; 168 } else { 169 goerr++; 170 } 171 optcnt++; 172 break; 173 174 /* 175 add To: line to letters 176 */ 177 case 't': 178 flgt = 1; 179 optcnt++; 180 break; 181 182 /* 183 don't wait on sends 184 */ 185 case 'w': 186 flgw = 1; 187 break; 188 189 /* 190 set message-type: 191 */ 192 case 'm': 193 msgtype = optarg; 194 if (msgtype[0] == '\0' || msgtype[0] == '-') { 195 goerr++; 196 } else { 197 flgm = 1; 198 } 199 break; 200 201 /* 202 bad option 203 */ 204 case '?': 205 goerr++; 206 break; 207 } 208 } 209 210 211 212 if (argc == optind) { 213 214 if (flgm) { 215 errmsg(E_SYNTAX, 216 "-m option used but no recipient(s) specified."); 217 goerr++; 218 } 219 if (flgt) { 220 errmsg(E_SYNTAX, 221 "-t option used but no recipient(s) specified."); 222 goerr++; 223 } 224 if (flgw) { 225 errmsg(E_SYNTAX, 226 "-w option used but no recipient(s) specified."); 227 goerr++; 228 } 229 if (flgf) { 230 if (mailfile[0] == '-') { 231 errmsg(E_SYNTAX, 232 "Files names must not begin with '-'"); 233 done(0); 234 } 235 if (!ismail) 236 goerr++; 237 } 238 } 239 240 if (ismail && (goerr > 0)) { 241 errmsg(E_SYNTAX,"Usage: [-ehpPqr] [-f file] [-x debuglevel]"); 242 (void) fprintf (stderr, "or\t[-tw] [-m message_type] [-T file] [-x debuglevel] persons\n"); 243 (void) fprintf (stderr, "or\t[-x debuglevel]\n"); 244 done(0); 245 } 246 247 return (optind); 248 } 249