1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
|
/* @(#)options.c (c) copyright 10/10/88 (Dan Heller, Bart Schaefer) */
#include "mush.h"
#include "options.h"
/*
* NOTE: Any word flag which is a prefix of another word flag must be
* listed AFTER the flag it prefixes in the list below
*/
char *word_flags[][2] = {
{ "-bcc", "-b" },
{ "-blindcarbon", "-b" },
{ "-blind", "-b" },
{ "-carbon", "-c" },
{ "-cc", "-c" },
{ "-copy", "-c" },
{ "-curses", "-C" },
{ "-debug", "-d" },
{ "-draft", "-h" },
{ "-echo", "-e" },
{ "-folder", "-f" }, /* Maybe -file should become -f too? */
{ "-file", "-F" }, /* Don't really like -file for -F */
{ "-headerfile", "-h" },
{ "-headers", "-H" },
{ "-initialize", "-I" },
{ "-init", "-I" },
{ "-interactive", "-i" },
{ "-interact", "-i" },
{ "-mailbox", "-m" },
{ "-message", "-h" },
{ "-noheaders", "-N" },
{ "-noinit", "-n" },
{ "-popmail", "-p" },
{ "-nopopmail", "-P" },
{ "-readonly", "-r" },
{ "-send", "-U" },
{ "-shell", "-S" },
{ "-source", "-F" }, /* This is better for -F */
{ "-subject", "-s" },
{ "-timeout", "-T" },
{ "-toolhelp", "-2" },
{ "-tool", "-t" },
{ "-user", "-u" },
{ "-verbose", "-v" },
{ "-visual", "-C" },
{ NULL, NULL } /* This must be the last entry */
};
fix_word_flag(argp)
register char **argp;
{
int i;
Debug("%s --> ", *argp);
for (i = 0; word_flags[i][0]; i++) {
int len = strlen(word_flags[i][0]);
if (! strncmp(*argp, word_flags[i][0], len)) {
char buf[BUFSIZ], *p = buf;
p += Strcpy(buf, word_flags[i][1]);
(void) strcpy(p, *argp + len);
(void) strcpy(*argp, buf);
}
}
Debug("%s\n", *argp);
}
/*
* preparse the command line to determine whether or not we're going
* to bail out after checking that the user has no mail. Also, check
* to see if we're going to run a tool because it must be built first.
*/
preparse_opts(argcp, argv)
register int *argcp; /* Pointer to argument count */
register char **argv; /* Argument vector */
{
int n = FALSE;
char **args;
#ifdef POP3_SUPPORT
pop3 = -1;
#endif
#ifdef SUNTOOL
/* Note: we are assigning a boolean result to n and istool here */
if (n = istool = (strlen(prog_name) > 3 &&
(!strcmp(prog_name+strlen(prog_name)-4, "tool") ||
!strcmp(prog_name+strlen(prog_name)-4, "view")))) {
turnon(glob_flags, DO_SHELL);
parse_tool_opts(argcp, argv);
}
#endif /* SUNTOOL */
if (!istool && *argcp > 1) {
for (args = argv+1; *args && args[0][0] == '-'; args++) {
int next = 1;
fix_word_flag(&args[0]);
DoNext:
switch (args[0][next]) {
#ifdef POP3_SUPPORT
case 'p':
pop3 = 1;
break;
case 'P':
pop3 = 0;
break;
#endif
#if defined(SUNTOOL) || defined(POP3_SUPPORT)
case 'T' :
if (args[1])
args++;
#ifdef POP3_SUPPORT
break;
#endif /* POP3_SUPPORT */
#ifdef SUNTOOL
case 't' :
/* Note: we won't ever get here if started as
* "mushtool" or "mushview" because istool is true.
*/
istool = 1;
parse_tool_opts(argcp, argv);
turnon(glob_flags, DO_SHELL);
return TRUE;
/* break; */
#endif /* SUNTOOL */
#endif /* SUNTOOL || POP3_SUPPORT */
case 'S' :
turnon(glob_flags, DO_SHELL);
n = TRUE;
break;
case 'f' :
case 'F' :
case 'h' :
case 'm' :
case 'u' :
n = TRUE;
case 'b' :
case 'c' :
case 'I' :
case 's' :
if (args[1]) {
args++;
next = 0;
}
break;
case 'H' :
if (args[0][next+1] == ':')
next = 0;
break;
case '\0':
next = 0;
default : ;
}
if (next) {
++next;
goto DoNext;
}
}
if (*args) { /* unused args indicates sending mail to someone */
n = TRUE;
if (!istool)
turnon(glob_flags, IS_SENDING);
}
}
return n;
}
static char *usage_str =
#ifdef SUNTOOL
"usage: %s %s%s[-T timeout] [-t] [-C] [-H[:c]] [-i] [-f [folder] ] [-v] [-S] [-s subject] [users]\n";
#else
#ifdef CURSES
"usage: %s %s%s[-C] [-H[:c]] [-i] [-f [folder] ] [-v] [-S] [-s subject] [user list]\n";
#else
"usage: %s %s%s[-H[:c]] [-i] [-f [folder] ] [-v] [-S] [-s subject] [user list]\n";
#endif /* CURSES */
#endif /* SUNTOOL */
static char* pop_str =
#ifdef POP3_SUPPORT
"[-p] [-P] ";
#else
"";
#endif
static char* pop_to_str =
#if defined(POP3_SUPPORT) && !defined(SUNTOOLS)
"[-T timeout] ";
#else
"";
#endif
parse_options(argvp, flags)
register char ***argvp;
struct mush_flags *flags;
{
char buf[256];
bzero((char *) flags, sizeof (struct mush_flags));
flags->source_rc = TRUE;
flags->folder = "";
for (++(*argvp); **argvp && ***argvp == '-'; (*argvp)++) {
int look_again;
DoLookAgain:
look_again = TRUE;
switch ((*argvp)[0][1]) {
#ifdef POP3_SUPPORT
case 'p':
pop3 = 1;
break;
case 'P':
pop3 = 0;
break;
#endif
case 'e':
/*
* don't set tty modes -- e.g. echo and cbreak modes aren't
* changed.
*/
turnon(glob_flags, ECHO_FLAG);
#ifdef CURSES
when 'C':
/* don't init curses -- don't even set iscurses. */
if (istool) {
puts("-C: You are already running in tool mode");
turnoff(glob_flags, PRE_CURSES);
} else if (hdrs_only)
puts("headers only: ignoring -C flag");
else
turnon(glob_flags, PRE_CURSES);
#endif /* CURSES */
when 'F':
flags->src_n_exit = ((*argvp)[0][2] == '!');
if (!(flags->src_file = *++(*argvp)))
puts("specify filename to source"), exit(1);
look_again = FALSE;
/* fall thru! */
case 'N':
(void) strcat(flags->f_flags, "-N ");
when 'r':
(void) strcat(flags->f_flags, "-r "); /* folder() argument */
when 'H':
if (istool) {
puts("running in tool-mode; -H option ignored.");
break;
}
turnoff(glob_flags, PRE_CURSES);
if (*(hdrs_only = (*(*argvp))+2) != ':')
hdrs_only = ":a";
else
look_again = FALSE;
/* read only cuz no updates */
(void) strcat(flags->f_flags, "-N -r ");
when 'i':
/* force interactive even if !isatty(0) */
turnoff(glob_flags, REDIRECT);
when 'u': /* specify a user's mailbox */
if (*(flags->folder))
puts("You can't specify more than one mailbox"), exit(1);
#ifdef HOMEMAIL
{
char *p;
int isdir = 1;
(void) sprintf(buf, "%%%s",
(*argvp)[1] ? (*argvp)[1] : "root");
if ((p = getpath(buf, &isdir)) && !isdir)
strdup(flags->folder, p);
else if (isdir < 0)
puts(p), exit(1);
else if (isdir)
(void) printf("Mailbox \"%s\" is a directory\n", p), exit(1);
}
#else /* HOMEMAIL */
strdup(flags->folder, sprintf(buf, "%s/%s",
MAILDIR, ((*argvp)[1])? (*argvp)[1] : "root"));
#endif /* HOMEMAIL */
if ((*argvp)[1])
++(*argvp);
look_again = FALSE;
when 'h':
if (istool)
puts("bad option when run as a tool"), exit(1);
if ((*argvp)[1])
flags->draft = *++(*argvp);
else
(void) printf("-h: missing file name.\n"), exit(1);
look_again = FALSE;
turnon(glob_flags, IS_SENDING);
when 'U':
if (istool)
puts("bad option when run as a tool"), exit(1);
turnon(flags->flg, SEND_NOW);
if ((*argvp)[0][2] == '!') {
turnon(flags->flg, NO_SIGN);
++(**argvp);
}
when 'm':
if ((*argvp)[1])
strdup(spoolfile, *++(*argvp));
else
(void) printf("-m: missing mailbox name.\n"), exit(1);
look_again = FALSE;
when 'f':
if (*(flags->folder))
puts("You can't specify more than one mailbox"), exit(1);
if ((*argvp)[1]) {
strdup(flags->folder, *++(*argvp));
look_again = FALSE;
} else
strdup(flags->folder, "&");
when 's':
if (istool)
puts("bad option when run as a tool"), exit(1);
else if ((*argvp)[1])
flags->Subj = *++(*argvp);
else
puts("-s \"subject\""), exit(1);
look_again = FALSE;
when 'b':
if (istool)
puts("-b: bad option when run as a tool"), exit(1);
else if ((*argvp)[1])
flags->Bcc = *++(*argvp);
else
puts("-b \"bcc list\""), exit(1);
look_again = FALSE;
when 'c':
if (istool)
puts("-c: bad option when run as a tool"), exit(1);
else if ((*argvp)[1])
flags->Cc = *++(*argvp);
else
puts("-c \"cc list\""), exit(1);
look_again = FALSE;
break;
#ifdef VERBOSE_ARG
case 'v':
if (istool)
puts("bad option when run as a tool"), exit(1);
turnon(flags->flg, VERBOSE);
break;
#endif /* VERBOSE_ARG */
#if defined(SUNTOOL) || defined(POP3_SUPPORT)
case 'T':
if (!(*argvp)[1]
|| !isdigit((*argvp)[1][0]))
print(usage_str, prog_name, pop_str, pop_to_str);
else {
if ((time_out = atoi(*++*argvp)) < MIN_TIME_OUT
&& getuid())
time_out = MIN_TIME_OUT;
else if (time_out < MIN_ROOT_TIME_OUT)
time_out = MIN_ROOT_TIME_OUT;
look_again = FALSE;
}
#ifdef POP3_SUPPORT
break;
#endif /* POP3_SUPPORT */
#ifdef SUNTOOL
/* -T implies -t */
case 't': istool = 1;
#endif /* SUNTOOL */
#endif /* SUNTOOL || POP3_SUPPORT */
case 'S': turnon(glob_flags, DO_SHELL);
when 'n':
if ((*argvp)[0][2] == '!') {
++(**argvp);
flags->source_rc = -1; /* No init files sourced */
} else
flags->source_rc = 0; /* Only ~/.mushrc sourced */
when 'I':
if ((*argvp)[0][2] == '!' && flags->source_rc > 0)
flags->source_rc = 0; /* Only ~/.mushrc sourced */
if (!(flags->init_file = *++(*argvp)))
puts("specify filename for init"), exit(1);
look_again = FALSE;
when 'd': debug = 1;
when '\0' : look_again = FALSE;
otherwise:
print("%s: unknown option: `%c'\n", prog_name,
(*argvp)[0][1]? (*argvp)[0][1] : '-');
print(usage_str, prog_name, pop_str, pop_to_str);
}
if (look_again && ++(**argvp) != '\0')
goto DoLookAgain;
}
if (ison(flags->flg, SEND_NOW) && !flags->draft) {
print("You must specify a draft file to autosend\n");
exit(1);
}
}
|