liyu1981/translate_c_extract
a simple tool to clean zig translate-c result with annotation.
a simple tool to clean zig translate-c
result with annotation.
example hello.h
#ifndef __HELLO_H__
#define __HELLO_H__
#include <stddef.h>
#include <stdint.h>
// translate-c provide-begin: /#define\s(?<tk>\S+)\s.+/
#define CONST_A 'a'
#define CONST_ONE 1
// translate-c provide-end: /#define\s(?<tk>\S+)\s.+/
// translate-c provide: RegexMatchResult
typedef struct {
size_t start;
size_t len;
} Loc;
// translate-c provide: get_last_error_message
void get_last_error_message(Loc* loc);
// translate-c provide: my_create_a_hello_string
int my_create_a_hello_string(char** buf);
#endif
if zig build run -- tests/hello.h
, will produce
// generated by: ` zig-cache/o/b211bd45d7e3d2d5cee3d2849990c1b8/translate_c_extract tests/hello.h `
// timestamp: 1706073955549678
pub extern fn get_last_error_message(loc: [*c]Loc) void;
pub extern fn my_create_a_hello_string(buf: [*c][*c]u8) c_int;
pub const CONST_A = 'a';
pub const CONST_ONE = @as(c_int, 1);
if use "// translate-c provide: ", the then will be looked up in zig translate-c
result for filtering.
if use // translate-c provide-begin:
, then follow a PCRE2
regex, and must with a name group called tk
. the matched names will be searched in zig translate-c
result for filtering. The // translate-c provide-end
part must match previous regex.
MIT License :)