@@ -254,9 +254,22 @@ void run_demo(const char *path) {
254
254
demo_free (demo );
255
255
}
256
256
257
- int main (void ) {
258
- g_errfile = fopen (ERR_FILE , "w" );
259
- g_outfile = fopen (OUT_FILE , "w" );
257
+ int main (int argc , char * * argv ) {
258
+ const char * dem_name = NULL ;
259
+ if (argc == 1 ) {
260
+ g_errfile = fopen (ERR_FILE , "w" );
261
+ g_outfile = fopen (OUT_FILE , "w" );
262
+ } else if (argc == 2 ) {
263
+ g_errfile = stderr ;
264
+ g_outfile = stdout ;
265
+ dem_name = argv [1 ];
266
+ } else {
267
+ const char * name = argv [0 ] ? argv [0 ] : "mdp" ;
268
+ fprintf (stderr , "Usage:\n" );
269
+ fprintf (stderr , " %s Traverses every demo in ./demos; outputs to " OUT_FILE " and " ERR_FILE "\n" , name );
270
+ fprintf (stderr , " %s [in.dem] Runs on a specific demo; outputs to stdio\n" , name );
271
+ return 1 ;
272
+ }
260
273
261
274
_g_expected_maps = (const char * * )config_read_newline_sep (EXPECTED_MAPS_FILE );
262
275
g_cmd_whitelist = config_read_newline_sep (CMD_WHITELIST_FILE );
@@ -304,39 +317,46 @@ int main(void) {
304
317
config_free_var_whitelist (general_conf );
305
318
}
306
319
307
- DIR * d = opendir (DEMO_DIR );
308
- if (d ) {
309
- size_t demo_dir_len = strlen (DEMO_DIR );
310
- struct dirent * ent ;
311
- bool is_first = true;
312
- while ((ent = readdir (d ))) {
313
- if (!strcmp (ent -> d_name , "." )) continue ;
314
- if (!strcmp (ent -> d_name , ".." )) continue ;
315
-
316
- if (!is_first ) {
317
- fputs ("\n" , g_outfile );
318
- }
320
+ if (dem_name ) {
321
+ run_demo (dem_name );
322
+ if (_g_detected_timescale ) {
323
+ fputs ("\nTIMESCALE DETECTED\n" , g_outfile );
324
+ }
325
+ } else {
326
+ DIR * d = opendir (DEMO_DIR );
327
+ if (d ) {
328
+ size_t demo_dir_len = strlen (DEMO_DIR );
329
+ struct dirent * ent ;
330
+ bool is_first = true;
331
+ while ((ent = readdir (d ))) {
332
+ if (!strcmp (ent -> d_name , "." )) continue ;
333
+ if (!strcmp (ent -> d_name , ".." )) continue ;
334
+
335
+ if (!is_first ) {
336
+ fputs ("\n" , g_outfile );
337
+ }
319
338
320
- is_first = false;
339
+ is_first = false;
321
340
322
- char * path = malloc (demo_dir_len + strlen (ent -> d_name ) + 2 );
323
- strcpy (path , DEMO_DIR );
324
- strcat (path , "/" );
325
- strcat (path , ent -> d_name );
341
+ char * path = malloc (demo_dir_len + strlen (ent -> d_name ) + 2 );
342
+ strcpy (path , DEMO_DIR );
343
+ strcat (path , "/" );
344
+ strcat (path , ent -> d_name );
326
345
327
- _g_detected_timescale = false;
328
- run_demo (path );
346
+ _g_detected_timescale = false;
347
+ run_demo (path );
329
348
330
- free (path );
349
+ free (path );
350
+ }
351
+
352
+ closedir (d );
353
+ } else {
354
+ fprintf (g_errfile , "failed to open demos folder '%s'\n" , DEMO_DIR );
331
355
}
332
356
333
- closedir (d );
334
- } else {
335
- fprintf (g_errfile , "failed to open demos folder '%s'\n" , DEMO_DIR );
357
+ fprintf (g_outfile , "\ntimescale detected on %u demos\n" , _g_num_timescale );
336
358
}
337
359
338
- fprintf (g_outfile , "\ntimescale detected on %u demos\n" , _g_num_timescale );
339
-
340
360
if (_g_expected_maps ) {
341
361
bool did_hdr = false;
342
362
for (size_t i = 0 ; _g_expected_maps [i ]; ++ i ) {
0 commit comments