t6.c 805 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include "reporting.h"
  6. #include "region.h"
  7. #include "tokenizer.h"
  8. #include "parser.h"
  9. #include "interpreter.h"
  10. #include "builtins.h"
  11. void prompt_()
  12. {
  13. if (interactive_mode) {
  14. printf("%s", geteuid() == 0 ? "s# " : "s$ ");
  15. fflush(stdout);
  16. }
  17. }
  18. int main(int argc, char **argv)
  19. {
  20. struct AST* n;
  21. int i, b;
  22. FILE *f;
  23. int status;
  24. pid_t p;
  25. region r;
  26. if (argc == 1) {
  27. f = stdin;
  28. interactive_mode = isatty(fileno(stdin));
  29. }
  30. else {
  31. f = fopen(argv[1], "r");
  32. if (!f) {
  33. fprintf(stderr, "Could not open file <%s>!", argv[1]);
  34. exit(-1);
  35. }
  36. interactive_mode = 0;
  37. }
  38. do {
  39. prompt_();
  40. region_create(&r);
  41. n = parse(&r, f, &b);
  42. region_free(&r);
  43. skip_newline(f);
  44. } while(!feof(f));
  45. return 0;
  46. }