💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Vgmi › files › de9ca697e2024f3efc30976939f87… captured on 2023-12-28 at 15:44:16. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

Go Back

0 /*

1 * ISC License

2 * Copyright (c) 2023 RMF <rawmonk@firemail.cc>

3 */

4 #include <stdio.h>

5 #include <stdlib.h>

6 #include <stdint.h>

7 #include <unistd.h>

8 #include "macro.h"

9 #include "wcwidth.h"

10 #include "termbox.h"

11 #define PAGE_INTERNAL

12 #include "page.h"

13 #include "request.h"

14 #define PARSER_INTERNAL

15 #include "parser.h"

16

17 int parse_binary(int in, size_t length, int width, int out) {

18

19 size_t i;

20 struct termwriter termwriter = {0};

21 unsigned int x;

22

23 if (width < 10) width = 10;

24

25 termwriter.width = width - OFFSETX;

26 termwriter.fd = out;

27 termwriter.pos = 0;

28

29 x = 0;

30 for (i = 0; i < length; i++) {

31 uint8_t byte;

32 char buf[8];

33

34 read(in, &byte, 1);

35 snprintf(V(buf), "%02X ", byte);

36

37 x += 3;

38 if (x >= termwriter.width - 3) {

39 buf[2] = '\n';

40 x = 0;

41 }

42

43 writeto(&termwriter, buf, TB_DEFAULT, 0, i);

44 }

45

46 {

47 struct page_cell cell = {0};

48 cell.special = PAGE_EOF;

49 writecell(&termwriter, cell, i);

50 }

51 return 0;

52 }

53