getopt.cpp
资源名称:h323.zip [点击查看]
上传用户:hnnddl
上传日期:2007-01-06
资源大小:3580k
文件大小:3k
源码类别:
IP电话/视频会议
开发平台:
WINDOWS
- /*
- * $Revision: 1.2 $
- * $Date: 1998/10/14 22:48:26 $
- */
- ////////////////////////////////////////////////////////////////
- // Copyright (c) 1996-98 Lucent Technologies //
- // All Rights Reserved //
- // //
- // THIS IS UNPUBLISHED //
- // PROPRIETARY SOURCE //
- // CODE OF Lucent Technologies //
- // AND elemedia //
- // //
- ////////////////////////////////////////////////////////////////
- //
- ////////////////////////////////////////////////////////////////
- // Example programs are provided soley to demonstrate one //
- // possible use of the stack libraries and are included for //
- // instructional purposes only. You are free to use, modify //
- // and/or redistribute any portion of code in the example //
- // programs. However, such examples are not intended to //
- // represent production quality code. //
- // //
- // THE COPYRIGHT HOLDERS PROVIDE THESE EXAMPLE PROGRAMS //
- // "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED //
- // OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED //
- // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A //
- // PARTICULAR PURPOSE. //
- ////////////////////////////////////////////////////////////////
- #if defined(WIN32)
- #include <windows.h>
- #endif
- #include <stdio.h>
- /*****************************************************************************
- getopt
- This routine is based on a UNIX standard for parsing options in command
- lines, and is provided because some system libraries do not include it.
- Check UNIX manuals for more info on the arguments
- */
- #ifndef unix
- #include <ctype.h>
- char *optarg = NULL;
- int optind = 1;
- int opterr = 1;
- int getopt (int argc, char ** argv, const char * optstring)
- {
- static int multi = 0; /* remember that we are in the middle of a group */
- static char * pi = NULL; /* .. and where we are in the group */
- char * po;
- int c;
- if (optind >= argc)
- return -1;
- if (! multi) {
- pi = argv [optind];
- if ((* pi != '-') && (* pi != '/'))
- return -1;
- else {
- c = * ++ pi;
- /* test for null option - usually means use stdin
- * but this is treated as an arg, not an option
- */
- if (c == ' ')
- return -1;
- else if (c == '-') {
- /* '--' terminates options */
- ++ optind;
- return -1;
- }
- }
- }
- else
- c = * pi;
- ++ pi;
- if ((! isalnum (c)) || ((po = strchr (optstring, c)) == NULL))
- {
- if (opterr && (c != '?'))
- fprintf (stderr, "%s: illegal option -- %cn", argv [0], c);
- c = '?';
- }
- else if (* (po + 1) == ':')
- {
- /* opt-arg required.
- * Note that the standard requires white space, but current
- * practice has it optional.
- */
- if (* pi != ' ')
- {
- optarg = pi;
- multi = 0;
- ++ optind;
- }
- else
- {
- multi = 0;
- if (++ optind >= argc)
- {
- if (opterr)
- fprintf (stderr,
- "%s: option requires an argument -- %cn", argv [0], c);
- return '?';
- }
- optarg = argv [optind ++];
- }
- return c;
- }
- if (* pi == ' ')
- {
- multi = 0;
- ++ optind;
- }
- else
- {
- multi = 1;
- }
- return c;
- }
- #endif