abstract
| - Below is the full text to lev_main.c from the source code of NetHack 3.0.0. To link to a particular line, write [[NetHack 3.0.0/lev_main.c#line123]], for example. Warning! This is the source code from an old release. For the latest release, see Source code 1. /* SCCS Id: @(#)lev_main.c 3.0 89/07/02 2. /* Copyright (c) 1989 by Jean-Christophe Collet */ 3. /* NetHack may be freely redistributed. See license for details. */ 4. 5. /* 6. * This file contains the main function for the parser 7. * and some useful functions needed by yacc 8. */ 9. 10. #include 11. 12. #define MAX_ERRORS 25 13. 14. extern int line_number; 15. char *fname = "(stdin)"; 16. int fatal_error = 0; 17. 18. main(argc, argv) 19. int argc; 20. char **argv; 21. { 22. FILE *fin; 23. int i; 24. 25. if (argc == 1) /* Read standard input */ 26. yyparse(); 27. else /* Otherwise every argument is a filename */ 28. for(i=1; i 29. fin = freopen(argv[i], "r", stdin); 30. fname = argv[i]; 31. if (!fin) 32. fprintf(stderr,"Can't open %s
", argv[i]); 33. else 34. yyparse(); 35. line_number = 1; 36. fatal_error = 0; 37. } 38. return 0; 39. } 40. 41. /* 42. * Each time the parser detects an error, it uses this function. 43. * Here we take count of the errors. To continue farther than 44. * MAX_ERRORS wouldn't be reasonable. 45. */ 46. 47. yyerror(s) 48. char *s; 49. { 50. fprintf(stderr,"%s : line %d : %s
",fname,line_number, s); 51. if (++fatal_error > MAX_ERRORS) { 52. fprintf(stderr,"Too many errors, good bye!
"); 53. exit(1); 54. } 55. } 56. 57. /* 58. * Just display a warning (that is : a non fatal error) 59. */ 60. 61. yywarning(s) 62. char *s; 63. { 64. fprintf(stderr,"%s : line %d : WARNING : %s
",fname,line_number,s); 65. } 66. 67. yywrap() 68. { 69. return 1; 70. }
|