16e112132382b6442b636ee39b02951d771408e8frobbiew/* 26e112132382b6442b636ee39b02951d771408e8frobbiew* Disktest 36e112132382b6442b636ee39b02951d771408e8frobbiew* Copyright (c) International Business Machines Corp., 2001 46e112132382b6442b636ee39b02951d771408e8frobbiew* 56e112132382b6442b636ee39b02951d771408e8frobbiew* 66e112132382b6442b636ee39b02951d771408e8frobbiew* This program is free software; you can redistribute it and/or modify 76e112132382b6442b636ee39b02951d771408e8frobbiew* it under the terms of the GNU General Public License as published by 86e112132382b6442b636ee39b02951d771408e8frobbiew* the Free Software Foundation; either version 2 of the License, or 96e112132382b6442b636ee39b02951d771408e8frobbiew* (at your option) any later version. 106e112132382b6442b636ee39b02951d771408e8frobbiew* 116e112132382b6442b636ee39b02951d771408e8frobbiew* This program is distributed in the hope that it will be useful, 126e112132382b6442b636ee39b02951d771408e8frobbiew* but WITHOUT ANY WARRANTY; without even the implied warranty of 136e112132382b6442b636ee39b02951d771408e8frobbiew* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 146e112132382b6442b636ee39b02951d771408e8frobbiew* GNU General Public License for more details. 156e112132382b6442b636ee39b02951d771408e8frobbiew* 166e112132382b6442b636ee39b02951d771408e8frobbiew* You should have received a copy of the GNU General Public License 176e112132382b6442b636ee39b02951d771408e8frobbiew* along with this program; if not, write to the Free Software 186e112132382b6442b636ee39b02951d771408e8frobbiew* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 196e112132382b6442b636ee39b02951d771408e8frobbiew* 206e112132382b6442b636ee39b02951d771408e8frobbiew* Please send e-mail to yardleyb@us.ibm.com if you have 216e112132382b6442b636ee39b02951d771408e8frobbiew* questions or comments. 226e112132382b6442b636ee39b02951d771408e8frobbiew* 236e112132382b6442b636ee39b02951d771408e8frobbiew* Project Website: TBD 246e112132382b6442b636ee39b02951d771408e8frobbiew* 256e112132382b6442b636ee39b02951d771408e8frobbiew* 2677e42cafa8942eba6e7706c9d9c25a04ec7cdda5subrata_modak* $Id: Getopt.c,v 1.5 2008/02/14 08:22:22 subrata_modak Exp $ 276e112132382b6442b636ee39b02951d771408e8frobbiew* $Log: Getopt.c,v $ 2877e42cafa8942eba6e7706c9d9c25a04ec7cdda5subrata_modak* Revision 1.5 2008/02/14 08:22:22 subrata_modak 2977e42cafa8942eba6e7706c9d9c25a04ec7cdda5subrata_modak* Disktest application update to version 1.4.2, by, Brent Yardley <yardleyb@us.ibm.com> 306b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* 316b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* Revision 1.4 2002/03/30 01:32:14 yardleyb 326b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* Major Changes: 336b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* 346b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* Added Dumping routines for 356b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* data miscompares, 366b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* 376b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* Updated performance output 386b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* based on command line. Gave 396b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* one decimal in MB/s output. 406b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* 416b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* Rewrote -pL IO routine to show 426b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* correct stats. Now show pass count 436b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* when using -C. 446b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* 456b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* Minor Changes: 466b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* 476b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* Code cleanup to remove the plethera 486b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* if #ifdef for windows/unix functional 496b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* differences. 506b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* 516b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* Revision 1.3 2002/02/21 21:32:19 yardleyb 526b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* Added more unix compatability 536b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* ifdef'd function out when 546b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* compiling for unix env. that 556b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew* have getopt 566e112132382b6442b636ee39b02951d771408e8frobbiew* 576e112132382b6442b636ee39b02951d771408e8frobbiew* Revision 1.2 2002/02/04 20:35:38 yardleyb 586e112132382b6442b636ee39b02951d771408e8frobbiew* Changed max. number of threads to 64k. 596e112132382b6442b636ee39b02951d771408e8frobbiew* Check for max threads in parsing. 606e112132382b6442b636ee39b02951d771408e8frobbiew* Fixed windows getopt to return correctly 616e112132382b6442b636ee39b02951d771408e8frobbiew* when a bad option is given. 626e112132382b6442b636ee39b02951d771408e8frobbiew* Update time output to be in the format: 636e112132382b6442b636ee39b02951d771408e8frobbiew* YEAR/MONTH/DAY-HOUR:MIN:SEC 646e112132382b6442b636ee39b02951d771408e8frobbiew* instead of epoch time. 656e112132382b6442b636ee39b02951d771408e8frobbiew* 666e112132382b6442b636ee39b02951d771408e8frobbiew* Revision 1.1 2001/12/04 18:57:36 yardleyb 676e112132382b6442b636ee39b02951d771408e8frobbiew* This source add for windows compatability only. 686e112132382b6442b636ee39b02951d771408e8frobbiew* 696e112132382b6442b636ee39b02951d771408e8frobbiew*/ 706e112132382b6442b636ee39b02951d771408e8frobbiew 716b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew#ifdef WINDOWS 726b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew 736e112132382b6442b636ee39b02951d771408e8frobbiew#include <stdio.h> 746e112132382b6442b636ee39b02951d771408e8frobbiew#include <stddef.h> 756e112132382b6442b636ee39b02951d771408e8frobbiew#include <ctype.h> 766e112132382b6442b636ee39b02951d771408e8frobbiew#include <string.h> 776e112132382b6442b636ee39b02951d771408e8frobbiew#include "getopt.h" 786e112132382b6442b636ee39b02951d771408e8frobbiew 796e112132382b6442b636ee39b02951d771408e8frobbiew/* 806e112132382b6442b636ee39b02951d771408e8frobbiew * 816e112132382b6442b636ee39b02951d771408e8frobbiew * FUNCTION: getopt() 826e112132382b6442b636ee39b02951d771408e8frobbiew * 836e112132382b6442b636ee39b02951d771408e8frobbiew * Get next command line option and parameter 846e112132382b6442b636ee39b02951d771408e8frobbiew * source gathered from MS examples and modified 856e112132382b6442b636ee39b02951d771408e8frobbiew * to conform with unix like getopt. 866e112132382b6442b636ee39b02951d771408e8frobbiew * 876e112132382b6442b636ee39b02951d771408e8frobbiew */ 886e112132382b6442b636ee39b02951d771408e8frobbiew 896e112132382b6442b636ee39b02951d771408e8frobbiew/* Global Exportable */ 906e112132382b6442b636ee39b02951d771408e8frobbiewint optind; 916e112132382b6442b636ee39b02951d771408e8frobbiewchar *optarg; 926e112132382b6442b636ee39b02951d771408e8frobbiew 93354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaoint getopt(int argc, char **argv, char *pszValidOpts) 94354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao{ 956e112132382b6442b636ee39b02951d771408e8frobbiew char chOpt; 96354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao char *psz = NULL; 97354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao char *pszParam = NULL; 986e112132382b6442b636ee39b02951d771408e8frobbiew static int iArg = 1; 996e112132382b6442b636ee39b02951d771408e8frobbiew 1006e112132382b6442b636ee39b02951d771408e8frobbiew if (iArg < argc) { 1016e112132382b6442b636ee39b02951d771408e8frobbiew psz = &(argv[iArg][0]); 1026e112132382b6442b636ee39b02951d771408e8frobbiew if (*psz == '-' || *psz == '/') { 1036e112132382b6442b636ee39b02951d771408e8frobbiew /* we have an option specifier */ 1046e112132382b6442b636ee39b02951d771408e8frobbiew chOpt = argv[iArg][1]; 1056e112132382b6442b636ee39b02951d771408e8frobbiew if (isalnum(chOpt) || ispunct(chOpt)) { 1066e112132382b6442b636ee39b02951d771408e8frobbiew /* we have an option character */ 1076e112132382b6442b636ee39b02951d771408e8frobbiew psz = strchr(pszValidOpts, chOpt); 1086e112132382b6442b636ee39b02951d771408e8frobbiew if (psz != NULL) { 1096e112132382b6442b636ee39b02951d771408e8frobbiew /* option is valid, we want to return chOpt */ 1106e112132382b6442b636ee39b02951d771408e8frobbiew if (psz[1] == ':') { 1116e112132382b6442b636ee39b02951d771408e8frobbiew /* option can have a parameter */ 1126e112132382b6442b636ee39b02951d771408e8frobbiew psz = &(argv[iArg][2]); 1136e112132382b6442b636ee39b02951d771408e8frobbiew if (*psz == '\0') { 1146e112132382b6442b636ee39b02951d771408e8frobbiew /* must look at next argv for param */ 115354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao if (iArg + 1 < argc) { 116354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao psz = 117354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao &(argv 118354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao [iArg + 119354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao 1][0]); 120354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao if (*psz == '-' 121354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao || *psz == 122354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao '/') { 1236e112132382b6442b636ee39b02951d771408e8frobbiew /* next argv is a new option, so param 1246e112132382b6442b636ee39b02951d771408e8frobbiew * not given for current option 125354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao */ 126354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao fprintf 127354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao (stderr, 128354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao "-%c option requires an argument.\n", 129354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao chOpt); 130354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao chOpt = 131354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao '?'; 132354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao pszParam 133354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao = 134354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao NULL; 1356e112132382b6442b636ee39b02951d771408e8frobbiew } else { 1366e112132382b6442b636ee39b02951d771408e8frobbiew /* next argv is the param */ 1376e112132382b6442b636ee39b02951d771408e8frobbiew iArg++; 138354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao pszParam 139354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao = 140354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao psz; 1416e112132382b6442b636ee39b02951d771408e8frobbiew } 1426e112132382b6442b636ee39b02951d771408e8frobbiew } else { 1436e112132382b6442b636ee39b02951d771408e8frobbiew /* reached end of args looking for param */ 1446e112132382b6442b636ee39b02951d771408e8frobbiew } 1456e112132382b6442b636ee39b02951d771408e8frobbiew } else { 1466e112132382b6442b636ee39b02951d771408e8frobbiew /* param is attached to option */ 1476e112132382b6442b636ee39b02951d771408e8frobbiew pszParam = psz; 1486e112132382b6442b636ee39b02951d771408e8frobbiew } 1496e112132382b6442b636ee39b02951d771408e8frobbiew } else { 1506e112132382b6442b636ee39b02951d771408e8frobbiew /* option is alone, has no parameter */ 1516e112132382b6442b636ee39b02951d771408e8frobbiew } 1526e112132382b6442b636ee39b02951d771408e8frobbiew } else { 1536e112132382b6442b636ee39b02951d771408e8frobbiew /* option specified is not in list of valid options */ 154354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao fprintf(stderr, 155354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao "Invalid option -- %c\n", 156354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao chOpt); 1576e112132382b6442b636ee39b02951d771408e8frobbiew chOpt = '?'; 1586b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew pszParam = NULL; 1596e112132382b6442b636ee39b02951d771408e8frobbiew } 1606e112132382b6442b636ee39b02951d771408e8frobbiew } else { 1616e112132382b6442b636ee39b02951d771408e8frobbiew /* though option specifier was given, option character 1626e112132382b6442b636ee39b02951d771408e8frobbiew * is not alpha or was was not specified 1636e112132382b6442b636ee39b02951d771408e8frobbiew */ 1646e112132382b6442b636ee39b02951d771408e8frobbiew chOpt = 0; 1656e112132382b6442b636ee39b02951d771408e8frobbiew pszParam = &(argv[iArg][0]); 1666e112132382b6442b636ee39b02951d771408e8frobbiew } 1676e112132382b6442b636ee39b02951d771408e8frobbiew } else { 1686e112132382b6442b636ee39b02951d771408e8frobbiew /* standalone arg given with no option specifier */ 1696e112132382b6442b636ee39b02951d771408e8frobbiew chOpt = -1; 1706e112132382b6442b636ee39b02951d771408e8frobbiew pszParam = &(argv[iArg][0]); 1716e112132382b6442b636ee39b02951d771408e8frobbiew } 1726e112132382b6442b636ee39b02951d771408e8frobbiew } else { 1736e112132382b6442b636ee39b02951d771408e8frobbiew /* end of argument list */ 1746e112132382b6442b636ee39b02951d771408e8frobbiew chOpt = -1; 1756e112132382b6442b636ee39b02951d771408e8frobbiew } 1766e112132382b6442b636ee39b02951d771408e8frobbiew 1776e112132382b6442b636ee39b02951d771408e8frobbiew optind = iArg++; 1786e112132382b6442b636ee39b02951d771408e8frobbiew optarg = pszParam; 1796e112132382b6442b636ee39b02951d771408e8frobbiew return (chOpt); 1806e112132382b6442b636ee39b02951d771408e8frobbiew} 1816b98df5129acc12aad3167a9c6c12fda5afc6c31robbiew 182ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman#endif /* defined WINDOWS */ 183