summaryrefslogtreecommitdiff
path: root/src/user/dumphex/dumphex.c
blob: 4c63a065479f6d72c18df190cbabe7812877b607 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <knob/file.h>
#include <knob/user.h>
#include <knob/format.h>

void main(const char *path) {
  struct file *f = open_file(path);
  if (!f) {
    tell_user_sz("Couldn't open file.\n");
    return;
  }
  char buf[] = { ' ', '\0', '\0', '\0' };
  uint8_t v;
  uint32_t a = 0;
  while (read_from_file(f, 1, &v)) {
    if (!(a & 0xf)) {
      char buf2[] = {'0', 'x', '\0', '\0', '\0', '\0',
                               '\0', '\0', '\0', '\0', '\0' };
      itosz_h32(a, buf2 + 2);
      tell_user_sz(buf2);
      tell_user_sz(" |");
    }
    itosz_h8(v, buf + 1);
    tell_user_sz(buf);
    if (!(++a & 0xf))
      tell_user_sz("\n");
  }
  tell_user_sz("\n");
  close_file(f);
}