aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LuaSL_LSL_tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/src/LuaSL_LSL_tree.c')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.c95
1 files changed, 42 insertions, 53 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.c b/LuaSL/src/LuaSL_LSL_tree.c
index 65ccbc8..8eed579 100644
--- a/LuaSL/src/LuaSL_LSL_tree.c
+++ b/LuaSL/src/LuaSL_LSL_tree.c
@@ -394,9 +394,29 @@ static void convertLeaf2Lua(FILE *file, LSL_Leaf *leaf)
394 } 394 }
395} 395}
396 396
397int nextFile(LuaSL_yyparseExtra *extra)
398{
399 if (NULL != extra->file)
400 fclose(extra->file);
401 if (--(extra->argc) > 0 && *++(extra->argv) != '\0')
402 {
403 strncpy(extra->fileName, *(extra->argv), PATH_MAX - 1);
404 extra->fileName[PATH_MAX - 1] = '\0';
405 extra->file = fopen(extra->fileName, "r");
406 if (NULL == extra->file)
407 {
408 fprintf(stderr, "Error opening file %s.\n", extra->fileName);
409 return 1;
410 }
411 printf("Opened %s.\n", extra->fileName);
412 return(0);
413 }
414 return(1);
415}
416
397int main(int argc, char **argv) 417int main(int argc, char **argv)
398{ 418{
399 char *programName = argv[0]; 419// char *programName = argv[0];
400 int i; 420 int i;
401 421
402 // Figure out what numbers yacc gave to our tokens. 422 // Figure out what numbers yacc gave to our tokens.
@@ -412,9 +432,7 @@ int main(int argc, char **argv)
412 char fileName[PATH_MAX]; 432 char fileName[PATH_MAX];
413 LuaSL_yyparseParam param; 433 LuaSL_yyparseParam param;
414 LuaSL_yyparseExtra extra; 434 LuaSL_yyparseExtra extra;
415 int file;
416 int count; 435 int count;
417 boolean badArgs = FALSE;
418 436
419 // Sort the token table. 437 // Sort the token table.
420 for (i = 0; LSL_Tokens[i].token != NULL; i++) 438 for (i = 0; LSL_Tokens[i].token != NULL; i++)
@@ -425,44 +443,18 @@ int main(int argc, char **argv)
425 } 443 }
426 444
427 fileName[0] = '\0'; 445 fileName[0] = '\0';
428 446 param.ast = NULL;
429 // get the arguments passed in 447 param.lval = calloc(1, sizeof(LSL_Leaf));
430 while (--argc > 0 && *++argv != '\0') 448 memset(&extra, 0, sizeof(extra));
431 { 449 extra.argc = argc;
432 if (*argv[0] == '-') 450 extra.argv = argv;
433 { 451 extra.fileName = fileName;
434 // point to the characters after the '-' sign 452 extra.file = NULL;
435 char *s = argv[0] + 1; 453 // Grab the first file name, if any.
436 454 if (1 == nextFile(&extra))
437 switch (*s)
438 {
439 case 'f': // file
440 {
441 if (--argc > 0 && *++argv != '\0')
442 {
443 strncpy(fileName, *argv, PATH_MAX - 1);
444 fileName[PATH_MAX - 1] = '\0';;
445 }
446 else
447 badArgs = TRUE;
448 break;
449 }
450 default:
451 badArgs = TRUE;
452 }
453 }
454 else
455 badArgs = TRUE;
456 }
457
458 if (badArgs)
459 {
460 printf("Usage: %s [-f filename]\n", programName);
461 printf(" -f: Script file to run.\n");
462 printf("Or pass filenames in stdin.\n");
463 return 1; 455 return 1;
464 }
465 456
457/*
466 if ('\0' == fileName[0]) 458 if ('\0' == fileName[0])
467 { 459 {
468//strcpy(fileName, "test.lsl"); 460//strcpy(fileName, "test.lsl");
@@ -485,40 +477,37 @@ int main(int argc, char **argv)
485 } 477 }
486 478
487 } 479 }
488 else 480*/
489 printf("Filename %s in argument.\n", fileName);
490 481
491 file = open(fileName, 0); 482 if (yylex_init_extra(&extra, &(param.scanner)))
492 if (-1 == file)
493 {
494 printf("Error opening file %s.\n", fileName);
495 return 1; 483 return 1;
496 } 484
497#ifdef LUASL_DEBUG 485#ifdef LUASL_DEBUG
498// yydebug= 5; 486// yydebug= 5;
499#endif 487#endif
500 488
501 param.ast = NULL;
502 param.lval = calloc(1, sizeof(LSL_Leaf));
503 memset(&extra, 0, sizeof(extra));
504 if (yylex_init_extra(&extra, &(param.scanner)))
505 return 1;
506 489
507#ifdef LUASL_DEBUG 490#ifdef LUASL_DEBUG
508 yyset_debug(1, param.scanner); 491 yyset_debug(1, param.scanner);
509#endif 492#endif
510// yyset_in(file, param.scanner);
511 493
494#ifdef LUASL_FILES
495 yyset_in(extra.file, &(param.scanner));
496#endif
512 { 497 {
513 void *pParser = ParseAlloc(malloc); 498 void *pParser = ParseAlloc(malloc);
514 int yv; 499 int yv;
515 500
516 ParseTrace(stdout, "LSL_lemon "); 501 ParseTrace(stdout, "LSL_lemon ");
517 502
518 while ((i = read(file, buffer, PATH_MAX - 1)) > 0) 503#ifndef LUASL_FILES
504 while ((i = fread(buffer, 1, PATH_MAX - 1, extra.file)) > 0)
505#endif
519 { 506 {
507#ifndef LUASL_FILES
520 buffer[i] = '\0'; 508 buffer[i] = '\0';
521 yy_scan_string(buffer, param.scanner); 509 yy_scan_string(buffer, param.scanner);
510#endif
522 // on EOF yylex will return 0 511 // on EOF yylex will return 0
523 while((yv = yylex(param.lval, param.scanner)) != 0) 512 while((yv = yylex(param.lval, param.scanner)) != 0)
524 { 513 {