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 "utf8.h"

10 #include "wcwidth.h"

11 #define PAGE_INTERNAL

12 #include "page.h"

13 #include "request.h"

14 #define PARSER_INTERNAL

15 #include "parser.h"

16

17 int renderable(uint32_t codepoint) {

18 return !(codepoint == 0xFEFF ||

19 (codepoint < ' ' && codepoint != '\n' && codepoint != '\t'));

20 }

21

22 int readnext(int fd, uint32_t *ch, size_t *pos) {

23

24 char buf[64];

25 int len;

26

27 if (read(fd, buf, 1) != 1) return -1;

28 len = utf8_char_length(*buf);

29 if (len > 1 && read(fd, &buf[1], len - 1) != len - 1) return -1;

30 if (len > 0 && pos) *pos += len;

31 utf8_char_to_unicode(ch, buf);

32

33 return 0;

34 }

35

36 int vread(int fd, void *buf, size_t nbytes) {

37 ssize_t len = read(fd, buf, nbytes);

38 return len != (ssize_t)nbytes;

39 }

40