Skip to content

Commit 2014a75

Browse files
committed
prefix optind, optarg, opterr with sc_ because emscripten complained
1 parent 8cb5c79 commit 2014a75

File tree

5 files changed

+46
-46
lines changed

5 files changed

+46
-46
lines changed

src/base/sc_getopt.cc

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
// SYNOPSIS
5252
// int sc_getopt(int argc, char *argv[], char *optstring)
5353
//
54-
// extern char *optarg;
55-
// extern int optind;
54+
// extern char *sc_optarg;
55+
// extern int sc_optind;
5656
//
5757
// DESCRIPTION
5858
// The sc_getopt() function parses the command line arguments. Its
@@ -67,21 +67,21 @@
6767
//
6868
// optstring is a string of recognized option letters; if a letter
6969
// is followed by a colon, the option is expected to have an argument
70-
// that may or may not be separated from it by white space. optarg
70+
// that may or may not be separated from it by white space. sc_optarg
7171
// is set to point to the start of the option argument on return from
7272
// sc_getopt.
7373
//
7474
// Option letters may be combined, e.g., "-ab" is equivalent to
7575
// "-a -b". Option letters are case sensitive.
7676
//
77-
// sc_getopt places in the external variable optind the argv index
78-
// of the next argument to be processed. optind is initialized
77+
// sc_getopt places in the external variable sc_optind the argv index
78+
// of the next argument to be processed. sc_optind is initialized
7979
// to 0 before the first call to sc_getopt.
8080
//
8181
// When all options have been processed (i.e., up to the first
82-
// non-option argument), sc_getopt returns EOF, optarg will point
83-
// to the argument, and optind will be set to the argv index of
84-
// the argument. If there are no non-option arguments, optarg
82+
// non-option argument), sc_getopt returns EOF, sc_optarg will point
83+
// to the argument, and sc_optind will be set to the argv index of
84+
// the argument. If there are no non-option arguments, sc_optarg
8585
// will be set to NULL.
8686
//
8787
// The special option "--" may be used to delimit the end of the
@@ -127,14 +127,14 @@
127127
// break;
128128
//
129129
// case _T('n'):
130-
// TRACE(_T("option n: value=%d\n"), atoi(optarg));
130+
// TRACE(_T("option n: value=%d\n"), atoi(sc_optarg));
131131
// //
132132
// // do something with value here
133133
// //
134134
// break;
135135
//
136136
// case _T('?'):
137-
// TRACE(_T("ERROR: illegal option %s\n"), argv[optind-1]);
137+
// TRACE(_T("ERROR: illegal option %s\n"), argv[sc_optind-1]);
138138
// return FALSE;
139139
// break;
140140
//
@@ -152,42 +152,42 @@
152152
//
153153
///////////////////////////////////////////////////////////////////////////////
154154

155-
char * optarg; // global argument pointer
156-
int optind = 0; // global argv index
155+
char * sc_optarg; // global argument pointer
156+
int sc_optind = 0; // global argv index
157157

158158
int sc_getopt( int argc, char * argv[], char * optstring ) {
159159
static char * next = NULL;
160-
if( optind == 0 ) {
160+
if( sc_optind == 0 ) {
161161
next = NULL;
162162
}
163163

164-
optarg = NULL;
164+
sc_optarg = NULL;
165165

166166
if( next == NULL || *next == '\0' ) {
167-
if( optind == 0 ) {
168-
optind++;
167+
if( sc_optind == 0 ) {
168+
sc_optind++;
169169
}
170170

171-
if( optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0' ) {
172-
optarg = NULL;
173-
if( optind < argc ) {
174-
optarg = argv[optind];
171+
if( sc_optind >= argc || argv[sc_optind][0] != '-' || argv[sc_optind][1] == '\0' ) {
172+
sc_optarg = NULL;
173+
if( sc_optind < argc ) {
174+
sc_optarg = argv[sc_optind];
175175
}
176176
return EOF;
177177
}
178178

179-
if( strcmp( argv[optind], "--" ) == 0 ) {
180-
optind++;
181-
optarg = NULL;
182-
if( optind < argc ) {
183-
optarg = argv[optind];
179+
if( strcmp( argv[sc_optind], "--" ) == 0 ) {
180+
sc_optind++;
181+
sc_optarg = NULL;
182+
if( sc_optind < argc ) {
183+
sc_optarg = argv[sc_optind];
184184
}
185185
return EOF;
186186
}
187187

188-
next = argv[optind];
188+
next = argv[sc_optind];
189189
next++; // skip past -
190-
optind++;
190+
sc_optind++;
191191
}
192192

193193
char c = *next++;
@@ -200,11 +200,11 @@ int sc_getopt( int argc, char * argv[], char * optstring ) {
200200
cp++;
201201
if( *cp == ':' ) {
202202
if( *next != '\0' ) {
203-
optarg = next;
203+
sc_optarg = next;
204204
next = NULL;
205-
} else if( optind < argc ) {
206-
optarg = argv[optind];
207-
optind++;
205+
} else if( sc_optind < argc ) {
206+
sc_optarg = argv[sc_optind];
207+
sc_optind++;
208208
} else {
209209
return '?';
210210
}

src/base/sc_getopt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
extern "C" {
2121
#endif
2222

23-
extern SC_BASE_EXPORT int optind, opterr;
24-
extern SC_BASE_EXPORT char * optarg;
23+
extern SC_BASE_EXPORT int sc_optind, sc_opterr;
24+
extern SC_BASE_EXPORT char * sc_optarg;
2525

2626
int SC_BASE_EXPORT sc_getopt( int argc, char * argv[], char * optstring );
2727

src/express/Changes

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,13 @@ ERRORcreate_option.
290290

291291
To actually set or unset an option, it suffices to say:
292292

293-
ERRORset_option(optarg,set);
293+
ERRORset_option(sc_optarg,set);
294294

295295
where set is a true/false value. This is especially convenient with
296296
getopt, since you can use the same code to set or unset an option just
297297
by testing the option letter inside of the 'set' argument. I.e.
298298

299-
ERRORset_option(optarg,c == 'w');
299+
ERRORset_option(sc_optarg,c == 'w');
300300

301301
To print all the options out, say:
302302

src/express/fedex.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ int main( int argc, char ** argv ) {
117117
( *EXPRESSinit_args )( argc, argv );
118118
}
119119

120-
optind = 1;
120+
sc_optind = 1;
121121
while( ( c = sc_getopt( argc, argv, EXPRESSgetopt_options ) ) != -1 ) {
122122
switch( c ) {
123123
case 'd':
124124
ERRORdebugging = 1;
125-
switch( atoi( optarg ) ) {
125+
switch( atoi( sc_optarg ) ) {
126126
case 0:
127127
fprintf( stderr, "\ndebug codes:\n" );
128128
fprintf( stderr, " 0 - this help\n" );
@@ -164,18 +164,18 @@ int main( int argc, char ** argv ) {
164164
buffer_messages = false;
165165
break;
166166
case 'e':
167-
input_filename = optarg;
167+
input_filename = sc_optarg;
168168
break;
169169
case 'r':
170170
resolve = 0;
171171
break;
172172
case 'i':
173173
case 'w':
174174
no_warnings = 0;
175-
ERRORset_warning( optarg, c == 'w' );
175+
ERRORset_warning( sc_optarg, c == 'w' );
176176
break;
177177
case 'p':
178-
for( cp = optarg; *cp; cp++ ) {
178+
for( cp = sc_optarg; *cp; cp++ ) {
179179
if( *cp == '#' ) {
180180
print_objects_while_running |= OBJ_PASS_BITS;
181181
} else if( *cp == 'E' ) {
@@ -192,7 +192,7 @@ int main( int argc, char ** argv ) {
192192
default:
193193
rc = 1;
194194
if( EXPRESSgetopt ) {
195-
rc = ( *EXPRESSgetopt )( c, optarg );
195+
rc = ( *EXPRESSgetopt )( c, sc_optarg );
196196
}
197197
if( rc == 1 ) {
198198
if( ERRORusage_function ) {
@@ -205,7 +205,7 @@ int main( int argc, char ** argv ) {
205205
}
206206
}
207207
if( !input_filename ) {
208-
input_filename = argv[optind];
208+
input_filename = argv[sc_optind];
209209
if( !input_filename ) {
210210
EXPRESScleanup();
211211
if( no_need_to_work ) {

src/test/p21read/p21read.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ int main( int argc, char * argv[] ) {
153153
benchmark stats( "p21 ReadExchangeFile()" );
154154

155155
cout << argv[0] << ": load file ..." << endl;
156-
if( argc >= ( optind + 1 ) ) {
157-
flnm = argv[optind];
156+
if( argc >= ( sc_optind + 1 ) ) {
157+
flnm = argv[sc_optind];
158158
} else {
159159
flnm = ( char * )"testfile.step";
160160
}
@@ -177,8 +177,8 @@ int main( int argc, char * argv[] ) {
177177
Severity readSev = sfile.Error().severity(); //otherwise, errors from reading will be wiped out by sfile.WriteExchangeFile()
178178

179179
cout << argv[0] << ": write file ..." << endl;
180-
if( argc == optind + 2 ) {
181-
flnm = argv[optind + 1];
180+
if( argc == sc_optind + 2 ) {
181+
flnm = argv[sc_optind + 1];
182182
} else {
183183
flnm = ( char * )"file.out";
184184
}

0 commit comments

Comments
 (0)