sh.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef SH_H
  2. #define SH_H
  3. #define BUFSIZ 1024 /* initial user input size */
  4. #define NTOK_MAX 16 /* maximum number of tokens */
  5. #define TOKLEN_MAX 512 /* maximum token length */
  6. #define PS1 "% " /* user prompt for interactive shell */
  7. #define RUN_FG 0
  8. #define RUN_BG 1
  9. #define PROMPT(p) (void)fprintf(stderr, "%s", p)
  10. #define LEN(x) (sizeof(x) / sizeof(*x))
  11. /*
  12. * free dynamically allocated buffers and exit with given status
  13. */
  14. __dead void die(const int);
  15. /*
  16. * print error message and exit
  17. */
  18. __dead void pexit(const char*, const int);
  19. /*
  20. * parse syntax on token vector and set (global) flags accordingly
  21. * returns 0, +1/-1 on valid syntax, forgivable/fatal errors
  22. * respectively
  23. */
  24. int parse(char ** restrict, size_t * restrict);
  25. /*
  26. * read from standard input into buffer until first newline exclusively
  27. * returns buffer length otherwise -1 on error
  28. */
  29. ssize_t readline(char ** restrict, size_t * restrict n,
  30. const char * restrict);
  31. /*
  32. * Fork and execute program (in background)
  33. * returns 0 otherwise -1 on error
  34. */
  35. int run(char *const *, const int);
  36. /*
  37. * handle user dispatched SIGINT, SIGTSTP et al for basic job control
  38. */
  39. void sighandle(const int);
  40. /*
  41. * split buffer on whitespaces (' ' and '\t') and store tokens in array
  42. * returns the number of tokens
  43. */
  44. size_t tokenize(char *, char ** restrict);
  45. #endif /* SH_H */