options.c (265773) | options.c (265844) |
---|---|
1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Kenneth Almquist. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 22 unchanged lines hidden (view full) --- 31 */ 32 33#ifndef lint 34#if 0 35static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 5/4/95"; 36#endif 37#endif /* not lint */ 38#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Kenneth Almquist. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 22 unchanged lines hidden (view full) --- 31 */ 32 33#ifndef lint 34#if 0 35static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 5/4/95"; 36#endif 37#endif /* not lint */ 38#include <sys/cdefs.h> |
39__FBSDID("$FreeBSD: head/bin/sh/options.c 265773 2014-05-09 13:32:36Z jilles $"); | 39__FBSDID("$FreeBSD: head/bin/sh/options.c 265844 2014-05-10 17:42:21Z jilles $"); |
40 41#include <signal.h> 42#include <unistd.h> 43#include <stdlib.h> 44 45#include "shell.h" 46#define DEFINE_OPTIONS 47#include "options.h" --- 427 unchanged lines hidden (view full) --- 475 } 476 else { 477 out2fmt_flush("Illegal option -%c\n", c); 478 INTOFF; 479 (void) unsetvar("OPTARG"); 480 INTON; 481 } 482 c = '?'; | 40 41#include <signal.h> 42#include <unistd.h> 43#include <stdlib.h> 44 45#include "shell.h" 46#define DEFINE_OPTIONS 47#include "options.h" --- 427 unchanged lines hidden (view full) --- 475 } 476 else { 477 out2fmt_flush("Illegal option -%c\n", c); 478 INTOFF; 479 (void) unsetvar("OPTARG"); 480 INTON; 481 } 482 c = '?'; |
483 goto bad; | 483 goto out; |
484 } 485 if (*++q == ':') 486 q++; 487 } 488 489 if (*++q == ':') { 490 if (*p == '\0' && (p = **optnext) == NULL) { 491 if (optstr[0] == ':') { --- 4 unchanged lines hidden (view full) --- 496 } 497 else { 498 out2fmt_flush("No arg for -%c option\n", c); 499 INTOFF; 500 (void) unsetvar("OPTARG"); 501 INTON; 502 c = '?'; 503 } | 484 } 485 if (*++q == ':') 486 q++; 487 } 488 489 if (*++q == ':') { 490 if (*p == '\0' && (p = **optnext) == NULL) { 491 if (optstr[0] == ':') { --- 4 unchanged lines hidden (view full) --- 496 } 497 else { 498 out2fmt_flush("No arg for -%c option\n", c); 499 INTOFF; 500 (void) unsetvar("OPTARG"); 501 INTON; 502 c = '?'; 503 } |
504 goto bad; | 504 goto out; |
505 } 506 507 if (p == **optnext) 508 (*optnext)++; 509 setvarsafe("OPTARG", p, 0); 510 p = NULL; 511 } 512 else 513 setvarsafe("OPTARG", "", 0); | 505 } 506 507 if (p == **optnext) 508 (*optnext)++; 509 setvarsafe("OPTARG", p, 0); 510 p = NULL; 511 } 512 else 513 setvarsafe("OPTARG", "", 0); |
514 ind = *optnext - optfirst + 1; 515 goto out; | |
516 | 514 |
517bad: 518 ind = 1; 519 *optnext = NULL; 520 p = NULL; | |
521out: | 515out: |
516 if (*optnext != NULL) 517 ind = *optnext - optfirst + 1; |
|
522 *optptr = p; 523 fmtstr(s, sizeof(s), "%d", ind); 524 err |= setvarsafe("OPTIND", s, VNOFUNC); 525 s[0] = c; 526 s[1] = '\0'; 527 err |= setvarsafe(optvar, s, 0); 528 if (err) { 529 *optnext = NULL; --- 45 unchanged lines hidden --- | 518 *optptr = p; 519 fmtstr(s, sizeof(s), "%d", ind); 520 err |= setvarsafe("OPTIND", s, VNOFUNC); 521 s[0] = c; 522 s[1] = '\0'; 523 err |= setvarsafe(optvar, s, 0); 524 if (err) { 525 *optnext = NULL; --- 45 unchanged lines hidden --- |