FreeBSD/usr.bin/whereis/whereis.c
/*
 * Scan options passed to program.
 *
 * Note that the -B/-M/-S options expect a list of directory
 * names that must be terminated with -f.
 */
Scan options passed to program.
Note that the -B/-M/-S options expect a list of directory
names that must be terminated with -f.
Scan options passed to program . Note that the - B / - M / - S options expect a list of directory names that must be terminated with - f .
static void
scanopts(int argc, char **argv)
{
	int c, i;
	ccharp **dirlist;
	while ((c = getopt(argc, argv, "BMSabfmqsux")) != -1)
		switch (c) {
		case 'B':
			dirlist = &bindirs;
			goto dolist;
		case 'M':
			dirlist = &mandirs;
			goto dolist;
		case 'S':
			dirlist = &sourcedirs;
		  dolist:
			i = 0;
			*dirlist = realloc(*dirlist, (i + 1) * sizeof(char *));
			(*dirlist)[i] = NULL;
			while (optind < argc &&
			       strcmp(argv[optind], "-f") != 0 &&
			       strcmp(argv[optind], "-B") != 0 &&
			       strcmp(argv[optind], "-M") != 0 &&
			       strcmp(argv[optind], "-S") != 0) {
				decolonify(argv[optind], dirlist, &i);
				optind++;
			}
			break;
		case 'a':
			opt_a = 1;
			break;
		case 'b':
			opt_b = 1;
			break;
		case 'f':
			goto breakout;
		case 'm':
			opt_m = 1;
			break;
		case 'q':
			opt_q = 1;
			break;
		case 's':
			opt_s = 1;
			break;
		case 'u':
			opt_u = 1;
			break;
		case 'x':
			opt_x = 1;
			break;
		default:
			usage();
		}
  breakout:
	if (optind == argc)
		usage();
	query = argv + optind;
}
static void scanopts ( int argc , char * * argv ) { int c , i ; ccharp * * dirlist ; while ( ( c = getopt ( argc , argv , " " ) ) != -1 ) switch ( c ) { case ' ' : dirlist = & bindirs ; goto dolist ; case ' ' : dirlist = & mandirs ; goto dolist ; case ' ' : dirlist = & sourcedirs ; dolist : i = 0 ; * dirlist = realloc ( * dirlist , ( i + 1 ) * sizeof ( char * ) ) ; ( * dirlist ) [ i ] = NULL ; while ( optind < argc && strcmp ( argv [ optind ] , " " ) != 0 && strcmp ( argv [ optind ] , " " ) != 0 && strcmp ( argv [ optind ] , " " ) != 0 && strcmp ( argv [ optind ] , " " ) != 0 ) { decolonify ( argv [ optind ] , dirlist , & i ) ; optind ++ ; } break ; case ' ' : opt_a = 1 ; break ; case ' ' : opt_b = 1 ; break ; case ' ' : goto breakout ; case ' ' : opt_m = 1 ; break ; case ' ' : opt_q = 1 ; break ; case ' ' : opt_s = 1 ; break ; case ' ' : opt_u = 1 ; break ; case ' ' : opt_x = 1 ; break ; default : usage ( ) ; } breakout : if ( optind == argc ) usage ( ) ; query = argv + optind ; }
Scan options passed to program.
Scan options passed to program .