⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getopt.cpp

📁 从国外网站上下载的关于 逆向工程和协议分析练习 的一个分析文档 对你的加密与解密很有帮助
💻 CPP
字号:
/*
* Disktest
* Copyright (c) International Business Machines Corp., 2001
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*  Please send e-mail to yardleyb@us.ibm.com if you have
*  questions or comments.
*
*  Project Website:  TBD
*
*
* $Id: Getopt.c,v 1.3 2003/09/17 17:15:28 robbiew Exp $
* $Log: Getopt.c,v $
* Revision 1.3  2003/09/17 17:15:28  robbiew
* Update to 1.1.12
*
* Revision 1.4  2002/03/30 01:32:14  yardleyb
* Major Changes:
*
* Added Dumping routines for
* data miscompares,
*
* Updated performance output
* based on command line.  Gave
* one decimal in MB/s output.
*
* Rewrote -pL IO routine to show
* correct stats.  Now show pass count
* when using -C.
*
* Minor Changes:
*
* Code cleanup to remove the plethera
* if #ifdef for windows/unix functional
* differences.
*
* Revision 1.3  2002/02/21 21:32:19  yardleyb
* Added more unix compatability
* ifdef'd function out when
* compiling for unix env. that
* have getopt
*
* Revision 1.2  2002/02/04 20:35:38  yardleyb
* Changed max. number of threads to 64k.
* Check for max threads in parsing.
* Fixed windows getopt to return correctly
* when a bad option is given.
* Update time output to be in the format:
*   YEAR/MONTH/DAY-HOUR:MIN:SEC
* instead of epoch time.
*
* Revision 1.1  2001/12/04 18:57:36  yardleyb
* This source add for windows compatability only.
*
*/

#include "StdAfx.h"
#include <stdio.h>
#include <stddef.h>
#include <ctype.h>
#include <string.h>
#include "getopt.h"

/*
 *
 *  FUNCTION: getopt()
 *
 *	  Get next command line option and parameter
 *	  source gathered from MS examples and modified
 *	  to conform with unix like getopt.
 *
 */

/* Global Exportable */
int optind;
char *optarg;

int getopt (int argc, char** argv, char* pszValidOpts) {
	char chOpt;
	char* psz = NULL;
	char* pszParam = NULL;
	static int iArg = 1;

	if (iArg < argc) {
		psz = &(argv[iArg][0]);
		if (*psz == '-' || *psz == '/') {
			/* we have an option specifier */
			chOpt = argv[iArg][1];
			if (isalnum(chOpt) || ispunct(chOpt)) {
				/* we have an option character */
				psz = strchr(pszValidOpts, chOpt);
				if (psz != NULL) {
					/* option is valid, we want to return chOpt */
					if (psz[1] == ':') {
						/* option can have a parameter */
						psz = &(argv[iArg][2]);
						if (*psz == '\0') {
							/* must look at next argv for param */
							if (iArg+1 < argc) {
								psz = &(argv[iArg+1][0]);
								if (*psz == '-' || *psz == '/') {
									/* next argv is a new option, so param
									 * not given for current option
									*/
									fprintf(stderr, "-%c option requires an argument.\n", chOpt);
									chOpt = '?';
									pszParam = NULL;
								} else {
									/* next argv is the param */
									iArg++;
									pszParam = psz;
								}
							} else {
								/* reached end of args looking for param */
							}
						} else {
							/* param is attached to option */
							pszParam = psz;
						}
					} else {
						/* option is alone, has no parameter */
					}
				} else {
					/* option specified is not in list of valid options */
					fprintf(stderr, "Invalid option -- %c\n", chOpt);
					chOpt = '?';
					pszParam = NULL;
				}
			} else {
				/* though option specifier was given, option character
				 * is not alpha or was was not specified
				 */
				chOpt = 0;
				pszParam = &(argv[iArg][0]);
			}
		} else {
			/* standalone arg given with no option specifier */
			chOpt = -1;
			pszParam = &(argv[iArg][0]);
		}
	} else {
		/* end of argument list */
		chOpt = -1;
	}

	optind = iArg++;
	optarg = pszParam;
	return (chOpt);
}


⌨️ 快捷键说明

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