getopt.c

来自「speech signal process tools」· C语言 代码 · 共 68 行

C
68
字号
/* * getopt - get option letter from argv * by Henry Spencer * posted to Usenet net.sources list */#ifndef OS5#ifdef SCCS	static char *sccsid = "@(#)getopt.c	1.3	21 Mar 1998";#endif#include <stdio.h>char	*optarg;	/* Global argument pointer. */int	optind = 0;	/* Global argv index. */static char	*scan = NULL;	/* Private scan pointer. */extern char	*index();intgetopt(argc, argv, optstring)int argc;char *argv[];char *optstring;{	register char c;	register char *place;	optarg = NULL;	if (scan == NULL || *scan == '\0') {		if (optind == 0)			optind++;			if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0')			return(EOF);		if (strcmp(argv[optind], "--")==0) {			optind++;			return(EOF);		}			scan = argv[optind]+1;		optind++;	}	c = *scan++;	place = index(optstring, c);	if (place == NULL || c == ':') {		fprintf(stderr, "%s: unknown option -%c\n", argv[0], c);		return('?');	}	place++;	if (*place == ':') {		if (*scan != '\0') {			optarg = scan;			scan = NULL;		} else {			optarg = argv[optind];			optind++;		}	}	return(c);}#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?