|
| 1 | +/****** RENAMED from xgetopt.cc to sc_getopt.cc ***********/ |
| 2 | + |
1 | 3 | // XGetopt.cpp Version 1.2 |
2 | 4 | // |
3 | 5 | // Author: Hans Dietrich |
4 | 6 | // hdietrich2@hotmail.com |
5 | 7 | // |
6 | 8 | // Description: |
7 | | -// XGetopt.cpp implements getopt(), a function to parse command lines. |
| 9 | +// XGetopt.cpp implements sc_getopt(), a function to parse command lines. |
8 | 10 | // |
9 | 11 | // History |
10 | 12 | // Version 1.2 - 2003 May 17 |
|
36 | 38 | #include <string.h> |
37 | 39 | /////////////////////////////////////////////////////////////////////////////// |
38 | 40 |
|
39 | | -#include "XGetopt.h" |
| 41 | +#include "sc_getopt.h" |
40 | 42 |
|
41 | 43 | /////////////////////////////////////////////////////////////////////////////// |
42 | 44 | // |
43 | 45 | // X G e t o p t . c p p |
44 | 46 | // |
45 | 47 | // |
46 | 48 | // NAME |
47 | | -// getopt -- parse command line options |
| 49 | +// sc_getopt -- parse command line options |
48 | 50 | // |
49 | 51 | // SYNOPSIS |
50 | | -// int getopt(int argc, char *argv[], char *optstring) |
| 52 | +// int sc_getopt(int argc, char *argv[], char *optstring) |
51 | 53 | // |
52 | 54 | // extern char *optarg; |
53 | 55 | // extern int optind; |
54 | 56 | // |
55 | 57 | // DESCRIPTION |
56 | | -// The getopt() function parses the command line arguments. Its |
| 58 | +// The sc_getopt() function parses the command line arguments. Its |
57 | 59 | // arguments argc and argv are the argument count and array as |
58 | 60 | // passed into the application on program invocation. In the case |
59 | 61 | // of Visual C++ programs, argc and argv are available via the |
60 | 62 | // variables __argc and __argv (double underscores), respectively. |
61 | | -// getopt returns the next option letter in argv that matches a |
| 63 | +// sc_getopt returns the next option letter in argv that matches a |
62 | 64 | // letter in optstring. (Note: Unicode programs should use |
63 | 65 | // __targv instead of __argv. Also, all character and string |
64 | 66 | // literals should be enclosed in _T( ) ). |
|
67 | 69 | // is followed by a colon, the option is expected to have an argument |
68 | 70 | // that may or may not be separated from it by white space. optarg |
69 | 71 | // is set to point to the start of the option argument on return from |
70 | | -// getopt. |
| 72 | +// sc_getopt. |
71 | 73 | // |
72 | 74 | // Option letters may be combined, e.g., "-ab" is equivalent to |
73 | 75 | // "-a -b". Option letters are case sensitive. |
74 | 76 | // |
75 | | -// getopt places in the external variable optind the argv index |
| 77 | +// sc_getopt places in the external variable optind the argv index |
76 | 78 | // of the next argument to be processed. optind is initialized |
77 | | -// to 0 before the first call to getopt. |
| 79 | +// to 0 before the first call to sc_getopt. |
78 | 80 | // |
79 | 81 | // When all options have been processed (i.e., up to the first |
80 | | -// non-option argument), getopt returns EOF, optarg will point |
| 82 | +// non-option argument), sc_getopt returns EOF, optarg will point |
81 | 83 | // to the argument, and optind will be set to the argv index of |
82 | 84 | // the argument. If there are no non-option arguments, optarg |
83 | 85 | // will be set to NULL. |
|
87 | 89 | // will be skipped. |
88 | 90 | // |
89 | 91 | // RETURN VALUE |
90 | | -// For option letters contained in the string optstring, getopt |
91 | | -// will return the option letter. getopt returns a question mark (?) |
| 92 | +// For option letters contained in the string optstring, sc_getopt |
| 93 | +// will return the option letter. sc_getopt returns a question mark (?) |
92 | 94 | // when it encounters an option letter not included in optstring. |
93 | 95 | // EOF is returned when processing is finished. |
94 | 96 | // |
|
98 | 100 | // 3) The environment variable POSIXLY_CORRECT is not supported. |
99 | 101 | // 4) The + syntax is not supported. |
100 | 102 | // 5) The automatic permutation of arguments is not supported. |
101 | | -// 6) This implementation of getopt() returns EOF if an error is |
| 103 | +// 6) This implementation of sc_getopt() returns EOF if an error is |
102 | 104 | // encountered, instead of -1 as the latest standard requires. |
103 | 105 | // |
104 | 106 | // EXAMPLE |
105 | 107 | // BOOL CMyApp::ProcessCommandLine(int argc, char *argv[]) |
106 | 108 | // { |
107 | 109 | // int c; |
108 | 110 | // |
109 | | -// while ((c = getopt(argc, argv, _T("aBn:"))) != EOF) |
| 111 | +// while ((c = sc_getopt(argc, argv, _T("aBn:"))) != EOF) |
110 | 112 | // { |
111 | 113 | // switch (c) |
112 | 114 | // { |
|
153 | 155 | char * optarg; // global argument pointer |
154 | 156 | int optind = 0; // global argv index |
155 | 157 |
|
156 | | -int getopt( int argc, char * argv[], char * optstring ) { |
| 158 | +int sc_getopt( int argc, char * argv[], char * optstring ) { |
157 | 159 | static char * next = NULL; |
158 | 160 | if( optind == 0 ) { |
159 | 161 | next = NULL; |
|
0 commit comments