2009-02-05 21:08:46 +00:00
|
|
|
#ifndef _INCLUDE_UTIL_R_
|
|
|
|
#define _INCLUDE_UTIL_R_
|
|
|
|
|
|
|
|
#include "r_types.h"
|
2009-04-04 19:38:59 +00:00
|
|
|
#include <btree.h>
|
2009-03-27 11:28:25 +00:00
|
|
|
#include "list.h"
|
|
|
|
|
|
|
|
/* r_cache */
|
|
|
|
// TOTHINK: move into a separated library?
|
|
|
|
struct r_cache_item_t {
|
|
|
|
u64 addr;
|
|
|
|
char *str;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct r_cache_t {
|
|
|
|
u64 from;
|
|
|
|
u64 to;
|
|
|
|
struct list_head items;
|
|
|
|
};
|
|
|
|
|
|
|
|
void r_cache_init(struct r_cache_t *lang);
|
|
|
|
struct r_cache_t *r_cache_new();
|
|
|
|
void r_cache_free(struct r_cache_t *c);
|
|
|
|
char *r_cache_get(struct r_cache_t *c, u64 addr);
|
|
|
|
int r_cache_set(struct r_cache_t *c, u64 addr, char *str);
|
|
|
|
int r_cache_validate(struct r_cache_t *c, u64 from, u64 to);
|
|
|
|
int r_cache_invalidate(struct r_cache_t *c, u64 from, u64 to);
|
2009-02-05 21:08:46 +00:00
|
|
|
|
2009-03-13 11:28:36 +00:00
|
|
|
/* profiling */
|
|
|
|
#include <sys/time.h>
|
|
|
|
struct r_prof_t {
|
|
|
|
struct timeval begin;
|
|
|
|
double result;
|
|
|
|
};
|
|
|
|
void r_prof_start(struct r_prof_t *p);
|
|
|
|
double r_prof_end(struct r_prof_t *p);
|
|
|
|
|
2009-02-05 21:08:46 +00:00
|
|
|
/* memory */
|
2009-02-16 10:24:45 +00:00
|
|
|
void r_mem_copyloop (u8 *dest, const u8 *orig, int dsize, int osize);
|
|
|
|
void r_mem_copyendian (u8 *dest, const u8 *orig, int size, int endian);
|
|
|
|
int r_mem_cmp_mask(const u8 *dest, const u8 *orig, const u8 *mask, int len);
|
2009-02-05 21:08:46 +00:00
|
|
|
|
|
|
|
/* numbers */
|
|
|
|
struct r_num_t {
|
|
|
|
u64 (*callback)(void *userptr, const char *str, int *ok);
|
|
|
|
u64 value;
|
|
|
|
void *userptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
void r_num_minmax_swap(u64 *a, u64 *b);
|
2009-02-09 11:42:54 +00:00
|
|
|
void r_num_minmax_swap_i(int *a, int *b);
|
2009-02-05 21:08:46 +00:00
|
|
|
u64 r_num_math(struct r_num_t *num, const char *str);
|
|
|
|
u64 r_num_get(struct r_num_t *num, const char *str);
|
|
|
|
struct r_num_t *r_num_new(u64 (*cb)(void*,const char *,int*), void *ptr);
|
|
|
|
void r_num_init(struct r_num_t *num);
|
|
|
|
|
|
|
|
/* strings */
|
|
|
|
|
2009-04-02 10:23:32 +00:00
|
|
|
/* TODO ..use as uppercase maybe? they are macros! */
|
2009-02-05 21:08:46 +00:00
|
|
|
#define strnull(x) (!x||!*x)
|
|
|
|
#define iswhitechar(x) (x==' '||x=='\t'||x=='\n'||x=='\r')
|
|
|
|
#define iswhitespace(x) (x==' '||x=='\t')
|
2009-04-19 18:09:07 +00:00
|
|
|
#define isseparator(x) (x==' '||x=='\t'||x==','||x==';'||\
|
2009-04-15 12:37:18 +00:00
|
|
|
x==':'||x=='['||x==']'||x=='('||x==')'||x=='{'||x=='}')
|
2009-02-05 21:08:46 +00:00
|
|
|
#define ishexchar(x) ((x>='0'&&x<='9') || (x>='a'&&x<='f') || (x>='A'&&x<='F')) {
|
|
|
|
|
|
|
|
/* stabilized */
|
|
|
|
int r_str_word_count(const char *string);
|
|
|
|
int r_str_word_set0(char *str);
|
|
|
|
const char *r_str_word_get0(const char *str, int idx);
|
2009-04-15 12:37:18 +00:00
|
|
|
char *r_str_word_get_first(const char *string);
|
2009-02-05 21:08:46 +00:00
|
|
|
|
2009-04-03 11:11:17 +00:00
|
|
|
char *r_str_chop(char *str);
|
2009-04-06 22:53:25 +00:00
|
|
|
R_API const char *r_str_chop_ro(const char *str);
|
2009-04-11 16:49:09 +00:00
|
|
|
R_API char *r_str_trim(char *str);
|
2009-03-06 00:00:41 +00:00
|
|
|
int r_str_hash(const char *str);
|
2009-02-05 21:08:46 +00:00
|
|
|
char *r_str_clean(char *str);
|
|
|
|
int r_str_nstr(char *from, char *to, int size);
|
|
|
|
char *r_str_lchr(char *str, char chr);
|
|
|
|
int r_str_nchr(const char *str, char chr);
|
|
|
|
char *r_str_ichr(char *str, char chr);
|
|
|
|
int r_str_ccmp(const char *dst, const char *orig, int ch);
|
|
|
|
int r_str_cmp(const char *dst, const char *orig, int len);
|
|
|
|
int r_str_ccpy(char *dst, char *orig, int ch);
|
|
|
|
const char *r_str_get(const char *str);
|
|
|
|
char *r_str_dup(char *ptr, const char *string);
|
|
|
|
void *r_str_free(void *ptr);
|
|
|
|
int r_str_inject(char *begin, char *end, char *str, int maxlen);
|
|
|
|
int r_str_delta(char *p, char a, char b);
|
|
|
|
|
|
|
|
int r_str_re_match(const char *str, const char *reg);
|
|
|
|
int r_str_re_replace(const char *str, const char *reg, const char *sub);
|
|
|
|
char *r_str_sub(char *string, char *pat, char *rep, int global);
|
|
|
|
int r_str_escape(char *buf);
|
|
|
|
char *r_str_home(const char *str);
|
2009-02-16 02:14:19 +00:00
|
|
|
char *r_str_concat(char *ptr, const char *string);
|
|
|
|
char *r_str_concatf(char *ptr, const char *fmt, ...);
|
2009-04-06 12:01:56 +00:00
|
|
|
inline void r_str_concatch(char *x, char y);
|
2009-02-05 21:08:46 +00:00
|
|
|
|
|
|
|
/* hex */
|
|
|
|
int r_hex_pair2bin(const char *arg);
|
|
|
|
int r_hex_str2bin(const char *in, u8 *out);
|
|
|
|
int r_hex_bin2str(const u8 *in, int len, char *out);
|
|
|
|
|
|
|
|
int r_hex_to_byte(u8 *val, u8 c);
|
|
|
|
|
|
|
|
/* file */
|
2009-02-09 00:54:09 +00:00
|
|
|
char *r_file_path(const char *bin);
|
2009-02-10 23:56:20 +00:00
|
|
|
char *r_file_slurp(const char *str, int *usz);
|
2009-02-05 21:08:46 +00:00
|
|
|
char *r_file_slurp_range(const char *str, u64 off, u64 sz);
|
|
|
|
char *r_file_slurp_random_line(const char *file);
|
2009-04-15 18:24:19 +00:00
|
|
|
u8 *r_file_slurp_hexpairs(const char *str, int *usz);
|
2009-02-05 21:08:46 +00:00
|
|
|
int r_file_dump(const char *file, const u8 *buf, int len);
|
|
|
|
int r_file_rm(const char *file);
|
|
|
|
int r_file_exist(const char *str);
|
2009-03-22 04:37:46 +00:00
|
|
|
char *r_file_slurp_line(const char *file, int line, int context);
|
2009-02-05 21:08:46 +00:00
|
|
|
|
2009-04-03 11:11:17 +00:00
|
|
|
int r_sys_sleep(int secs);
|
|
|
|
int r_sys_usleep(int usecs);
|
|
|
|
R_API const char *r_sys_getenv(const char *key);
|
|
|
|
R_API int r_sys_setenv(const char *key, const char *value, int ow);
|
2009-04-13 22:47:02 +00:00
|
|
|
R_API char *r_sys_cmd_str(const char *cmd, const char *input, int *len);
|
2009-04-04 19:38:59 +00:00
|
|
|
|
2009-02-05 21:08:46 +00:00
|
|
|
#endif
|