標籤:nbsp efault struct extend res c語言 highlight express tps
awk實在是太強大了, 非常複雜的任務,幾行代碼就可以解決, awk經常需要用到, 但是在c語言裡面, 調用system不太優雅, 能不能直接在c語言中直接調用呢,簡單實現了一些功能, 但大多數情況,夠用了,參考
https://github.com/yiifburj/my_tools/blob/master/simple_use_of_awk_in_c.c
後面有一個樣本, 可以參考, 使用方法主要是 填寫
struct awk_st{#define PATTERN_NUM 3#define PATTERN_SIZE 16 int pattern_num; char pattern[PATTERN_NUM][PATTERN_SIZE]; awk_begin_t fun_begin; awk_end_t fun_end; char action_default[0]; awk_action_t actions[PATTERN_NUM]; char data[0];};
pattern可以不寫, 但至少寫一個action,除非不需要, 多個pattern的時候個數要和action保持一致並且一一對應,同時要設定 pattern_num, pattern使用POSIX Extended Regular Expression , fun_begin fun_end fun_action都需要自己實現, 可以為NULL, data[0]指向的部分會被傳入到fun_begin fun_end fun_action中.
同時提供了字串替代函數
/* not found also return 0 */
int awk_str_replace_inplace(char *src, const char *old, const char *new);
int awk_str_replace(const char *src, const char *old, const char *new, char buf[], int bufsize);
int awk_str_replace_regex(const char *src, const char *pattern, const char *new, char buf[], int bufsize);
int awk_str_replace_regex_inplace(char *src, const char *pattern, const char *new);
失敗返回負數
詳情參考代碼。
C語言中使用類似awk的功能