utils.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include "cec.h"
  12. static int fd = -1;
  13. extern char *svc;
  14. void
  15. rawon(void)
  16. {
  17. if(svc)
  18. return;
  19. if((fd = open("/dev/consctl", OWRITE)) == -1 ||
  20. write(fd, "rawon", 5) != 5)
  21. fprint(2, "Can't make console raw\n");
  22. }
  23. void
  24. rawoff(void)
  25. {
  26. if(svc)
  27. return;
  28. close(fd);
  29. }
  30. enum {
  31. Perline = 16,
  32. Perch = 3,
  33. };
  34. char line[Perch*Perline+1];
  35. static void
  36. format(uint8_t *buf, int n, int t)
  37. {
  38. int i, r;
  39. for(i = 0; i < n; i++){
  40. r = (i + t) % Perline;
  41. if(r == 0 && i + t > 0)
  42. fprint(2, "%s\n", line);
  43. sprint(line + r*Perch, "%.2x ", buf[i]);
  44. }
  45. }
  46. void
  47. dump(uint8_t *p, int n)
  48. {
  49. format(p, n, 0);
  50. if(n % 16 > 0)
  51. print("%s\n", line);
  52. }