dev_consolekeys.c 703 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <stdio.h>
  2. #include "minilisp.h"
  3. #include "alloc.h"
  4. #include "stream.h"
  5. #include "compiler_new.h"
  6. #include <sys/mman.h>
  7. #include <unistd.h>
  8. #include <fcntl.h>
  9. Cell* consolefs_open() {
  10. system("stty raw -echo");
  11. return alloc_int(1);
  12. }
  13. Cell* consolefs_read() {
  14. int c = fgetc(stdin);
  15. if (c==13) c=10; // CR/LF
  16. Cell* str = alloc_string_copy(" ");
  17. ((char*)str->ar.addr)[0] = c;
  18. return str;
  19. }
  20. Cell* consolefs_write(Cell* a1,Cell* arg) {
  21. fputc(arg->ar.value, stdout);
  22. return arg;
  23. }
  24. void consolefs_cleanup() {
  25. system("stty sane");
  26. }
  27. void mount_consolekeys() {
  28. fs_mount_builtin("/keyboard", consolefs_open, consolefs_read, consolefs_write, 0, 0);
  29. atexit(consolefs_cleanup);
  30. }