MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1#ifndef ANT_UTILS_H
2#define ANT_UTILS_H
3#define ARGTABLE_COUNT 10
4
5#include <stdlib.h>
6#include <stdint.h>
7#include <stdbool.h>
8#include <string.h>
9
10typedef struct {
11 char *ptr;
12 char *heap;
13} cstr_buf_t;
14
15extern const char *const module_resolve_extensions[];
16uint64_t hash_key(const char *key, size_t len);
17
18double half_to_double(uint16_t bits16);
19uint16_t double_to_half(double value);
20
21char hex_char(int v);
22char *resolve_js_file(const char *filename);
23char *resolve_typescript_source_fallback(const char *filename);
24
25int hex_digit(char c);
26int is_typescript_file(const char *filename);
27
28int ant_mkdir_p(const char *path);
29int ant_user_bin_path(char *out, size_t out_size);
30
31int ant_xdg_cache_path(char *out, size_t out_size, const char *suffix);
32int ant_xdg_data_path(char *out, size_t out_size, const char *suffix);
33int ant_xdg_state_path(char *out, size_t out_size, const char *suffix);
34
35int strip_typescript_inplace(
36 char **buffer,
37 size_t len,
38 const char *filename,
39 int is_module,
40 size_t *out_len,
41 const char **error_detail
42);
43
44void ant_ts_hints_store(const char *filename, const char *hints);
45const char *ant_ts_hints_find(const char *filename);
46
47void *try_oom(size_t size);
48void cstr_free(cstr_buf_t *buf);
49
50char *cstr_init(
51 cstr_buf_t *buf,
52 char *stack,
53 size_t stack_size,
54 const char *src,
55 size_t len
56);
57
58#define CSTR_BUF(name, size) \
59 char name##_stack[size]; \
60 cstr_buf_t name = {0}
61
62#define CSTR_INIT(buf, src, len) \
63 cstr_init(&(buf), buf##_stack, sizeof(buf##_stack), (src), (len))
64
65typedef struct {
66 const char *ptr;
67 size_t len;
68} repl_capture_t;
69
70bool repl_template(
71 const char *repl, size_t repl_len,
72 const char *matched, size_t matched_len,
73 const char *str, size_t str_len, size_t position,
74 const repl_capture_t *caps, int ncaptures,
75 char **buf, size_t *buf_len, size_t *buf_cap
76);
77
78#endif