@@ -289,6 +289,7 @@ int main(int argc, char **argv)
289
289
char * expr = NULL ;
290
290
int interactive = 0 ;
291
291
int dump_memory = 0 ;
292
+ int dump_flags = 0 ;
292
293
int trace_memory = 0 ;
293
294
int empty_run = 0 ;
294
295
int module = -1 ;
@@ -308,36 +309,42 @@ int main(int argc, char **argv)
308
309
while (optind < argc && * argv [optind ] == '-' ) {
309
310
char * arg = argv [optind ] + 1 ;
310
311
const char * longopt = "" ;
312
+ char * opt_arg = NULL ;
311
313
/* a single - is not an option, it also stops argument scanning */
312
314
if (!* arg )
313
315
break ;
314
316
optind ++ ;
315
317
if (* arg == '-' ) {
316
318
longopt = arg + 1 ;
319
+ opt_arg = strchr (longopt , '=' );
320
+ if (opt_arg )
321
+ * opt_arg ++ = '\0' ;
317
322
arg += strlen (arg );
318
323
/* -- stops argument scanning */
319
324
if (!* longopt )
320
325
break ;
321
326
}
322
327
for (; * arg || * longopt ; longopt = "" ) {
323
328
char opt = * arg ;
324
- if (opt )
329
+ if (opt ) {
325
330
arg ++ ;
331
+ if (!opt_arg && * arg )
332
+ opt_arg = arg ;
333
+ }
326
334
if (opt == 'h' || opt == '?' || !strcmp (longopt , "help" )) {
327
335
help ();
328
336
continue ;
329
337
}
330
338
if (opt == 'e' || !strcmp (longopt , "eval" )) {
331
- if (* arg ) {
332
- expr = arg ;
333
- break ;
334
- }
335
- if (optind < argc ) {
336
- expr = argv [optind ++ ];
337
- break ;
339
+ if (!opt_arg ) {
340
+ if (optind >= argc ) {
341
+ fprintf (stderr , "qjs: missing expression for -e\n" );
342
+ exit (2 );
343
+ }
344
+ opt_arg = argv [optind ++ ];
338
345
}
339
- fprintf ( stderr , "qjs: missing expression for -e\n" ) ;
340
- exit ( 2 ) ;
346
+ expr = opt_arg ;
347
+ break ;
341
348
}
342
349
if (opt == 'I' || !strcmp (longopt , "include" )) {
343
350
if (optind >= argc ) {
@@ -364,6 +371,10 @@ int main(int argc, char **argv)
364
371
continue ;
365
372
}
366
373
if (opt == 'd' || !strcmp (longopt , "dump" )) {
374
+ if (opt_arg ) {
375
+ dump_flags = strtol (opt_arg , NULL , 16 );
376
+ break ;
377
+ }
367
378
dump_memory ++ ;
368
379
continue ;
369
380
}
@@ -384,20 +395,28 @@ int main(int argc, char **argv)
384
395
continue ;
385
396
}
386
397
if (!strcmp (longopt , "memory-limit" )) {
387
- if (optind >= argc ) {
388
- fprintf (stderr , "expecting memory limit" );
389
- exit (1 );
398
+ if (!opt_arg ) {
399
+ if (optind >= argc ) {
400
+ fprintf (stderr , "expecting memory limit" );
401
+ exit (1 );
402
+ }
403
+ opt_arg = argv [optind ++ ];
390
404
}
391
- memory_limit = (size_t )strtod (argv [optind ++ ], NULL );
392
- continue ;
405
+ // TODO(chqrlie): accept kmg suffixes
406
+ memory_limit = (size_t )strtod (opt_arg , NULL );
407
+ break ;
393
408
}
394
409
if (!strcmp (longopt , "stack-size" )) {
395
- if (optind >= argc ) {
396
- fprintf (stderr , "expecting stack size" );
397
- exit (1 );
410
+ if (!opt_arg ) {
411
+ if (optind >= argc ) {
412
+ fprintf (stderr , "expecting stack size" );
413
+ exit (1 );
414
+ }
415
+ opt_arg = argv [optind ++ ];
398
416
}
399
- stack_size = (size_t )strtod (argv [optind ++ ], NULL );
400
- continue ;
417
+ // TODO(chqrlie): accept kmg suffixes
418
+ stack_size = (size_t )strtod (opt_arg , NULL );
419
+ break ;
401
420
}
402
421
if (opt ) {
403
422
fprintf (stderr , "qjs: unknown option '-%c'\n" , opt );
@@ -422,6 +441,8 @@ int main(int argc, char **argv)
422
441
JS_SetMemoryLimit (rt , memory_limit );
423
442
if (stack_size != 0 )
424
443
JS_SetMaxStackSize (rt , stack_size );
444
+ if (dump_flags != 0 )
445
+ JS_SetDumpFlags (rt , dump_flags );
425
446
js_std_set_worker_new_context_func (JS_NewCustomContext );
426
447
js_std_init_handlers (rt );
427
448
ctx = JS_NewCustomContext (rt );
0 commit comments