Modernize asm/code.c

This commit is contained in:
pancake 2016-01-30 03:02:06 +01:00
parent b08892dbb3
commit bb073cf5db
2 changed files with 22 additions and 24 deletions

View File

@ -1,42 +1,41 @@
/* radare - LGPL - Copyright 2009-2013 - pancake */
/* radare - LGPL - Copyright 2009-2016 - pancake */
#include <stdio.h>
#include <r_asm.h>
R_API RAsmCode *r_asm_code_new() {
R_API RAsmCode *r_asm_code_new(void) {
return R_NEW0 (RAsmCode);
}
R_API void* r_asm_code_free(struct r_asm_code_t *acode) {
if (!acode)
return NULL;
if (acode->buf)
free (acode->buf);
if (acode->buf_hex)
free (acode->buf_hex);
if (acode->buf_asm)
free (acode->buf_asm);
R_API void* r_asm_code_free(RAsmCode *acode) {
if (!acode) return NULL;
free (acode->buf);
free (acode->buf_hex);
free (acode->buf_asm);
free (acode);
return NULL;
}
R_API int r_asm_code_set_equ (RAsmCode *code, const char *key, const char *value) {
R_API bool r_asm_code_set_equ (RAsmCode *code, const char *key, const char *value) {
RAsmEqu *equ;
RListIter *iter;
if (key == NULL || value == NULL) {
if (!code || !key || !value) {
eprintf ("Oops, no key or value defined in r_asm_code_set_equ ()\n");
return false;
}
if (!code->equs) {
code->equs = r_list_new ();
code->equs->free = free;
} else r_list_foreach (code->equs, iter, equ)
if (!strcmp (equ->key, key)) {
free (equ->value);
equ->value = strdup (value);
return true;
} else {
r_list_foreach (code->equs, iter, equ) {
if (!strcmp (equ->key, key)) {
free (equ->value);
equ->value = strdup (value);
return true;
}
}
equ = R_NEW (RAsmEqu);
}
equ = R_NEW0 (RAsmEqu);
equ->key = strdup (key);
equ->value = strdup (value);
r_list_append (code->equs, equ);
@ -46,9 +45,8 @@ R_API int r_asm_code_set_equ (RAsmCode *code, const char *key, const char *value
R_API char *r_asm_code_equ_replace (RAsmCode *code, char *str) {
RAsmEqu *equ;
RListIter *iter;
if (code->equs)
r_list_foreach (code->equs, iter, equ) {
str = r_str_replace (str, equ->key, equ->value, true);
}
r_list_foreach (code->equs, iter, equ) {
str = r_str_replace (str, equ->key, equ->value, true);
}
return str;
}

View File

@ -155,7 +155,7 @@ R_API RList* r_asm_get_plugins(RAsm *a);
/* code.c */
R_API RAsmCode *r_asm_code_new(void);
R_API void* r_asm_code_free(RAsmCode *acode);
R_API int r_asm_code_set_equ (RAsmCode *code, const char *key, const char *value);
R_API bool r_asm_code_set_equ (RAsmCode *code, const char *key, const char *value);
R_API char *r_asm_code_equ_replace (RAsmCode *code, char *str);
// accessors, to make bindings happy