mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-23 05:09:43 +00:00
Remove the last global variable in libmagic ##globals
This commit is contained in:
parent
2bf0723768
commit
ac0fb10f99
@ -96,11 +96,11 @@ static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth,
|
||||
ret = -1;
|
||||
goto seek_exit;
|
||||
}
|
||||
str = r_magic_buffer (ck, core->block+delta, core->blocksize - delta);
|
||||
str = r_magic_buffer (ck, core->block + delta, core->blocksize - delta);
|
||||
if (str) {
|
||||
const char *cmdhit;
|
||||
#if USE_LIB_MAGIC
|
||||
if (!v && (!strcmp (str, "data") || strstr(str, "ASCII") || strstr (str, "ISO") || strstr (str, "no line terminator"))) {
|
||||
if (!v && (!strcmp (str, "data") || strstr (str, "ASCII") || strstr (str, "ISO") || strstr (str, "no line terminator"))) {
|
||||
#else
|
||||
if (!v && (!strcmp (str, "data"))) {
|
||||
#endif
|
||||
@ -117,8 +117,8 @@ static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth,
|
||||
p = strdup (str);
|
||||
fmt = p;
|
||||
// processing newlinez
|
||||
for (q=p; *q; q++) {
|
||||
if (q[0]=='\\' && q[1]=='n') {
|
||||
for (q = p; *q; q++) {
|
||||
if (q[0] == '\\' && q[1]=='n') {
|
||||
*q = '\n';
|
||||
strcpy (q + 1, q + ((q[2] == ' ')? 3: 2));
|
||||
}
|
||||
@ -163,7 +163,7 @@ static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth,
|
||||
} else {
|
||||
sscanf (q + 1, "%"PFMT64d, &addr);
|
||||
}
|
||||
if (!fmt || !*fmt) {
|
||||
if (R_STR_ISEMPTY (fmt)) {
|
||||
fmt = file;
|
||||
}
|
||||
r_core_magic_at (core, fmt, addr, depth, 1, pj, hits);
|
||||
|
@ -260,6 +260,7 @@ struct r_magic_set {
|
||||
union VALUETYPE ms_value; /* either number or string */
|
||||
int magic_file_formats[FILE_NAMES_SIZE];
|
||||
const char *magic_file_names[FILE_NAMES_SIZE];
|
||||
ut32 last_cont_level;
|
||||
};
|
||||
|
||||
#if USE_LIB_MAGIC
|
||||
|
@ -905,8 +905,7 @@ static int get_cond(const char *l, const char **t) {
|
||||
}
|
||||
|
||||
static int check_cond(RMagic *ms, int cond, ut32 cont_level) {
|
||||
int last_cond;
|
||||
last_cond = ms->c.li[cont_level].last_cond;
|
||||
int last_cond = ms->c.li[cont_level].last_cond;
|
||||
|
||||
switch (cond) {
|
||||
case COND_IF:
|
||||
@ -949,7 +948,6 @@ static int check_cond(RMagic *ms, int cond, ut32 cont_level) {
|
||||
* parse one line from magic file, put into magic[index++] if valid
|
||||
*/
|
||||
static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, const char *line, size_t lineno, int action) {
|
||||
static R_TH_LOCAL ut32 last_cont_level = 0;
|
||||
size_t i;
|
||||
struct r_magic_entry *me;
|
||||
struct r_magic *m;
|
||||
@ -961,12 +959,12 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con
|
||||
for (; *l == '>'; l++, cont_level++) {
|
||||
;
|
||||
}
|
||||
if (cont_level == 0 || cont_level > last_cont_level) {
|
||||
if (cont_level == 0 || cont_level > ms->last_cont_level) {
|
||||
if (file_check_mem (ms, cont_level) == -1) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
last_cont_level = cont_level;
|
||||
ms->last_cont_level = cont_level;
|
||||
#define ALLOC_CHUNK (size_t)10
|
||||
#define ALLOC_INCR (size_t)200
|
||||
if (cont_level != 0) {
|
||||
|
@ -133,6 +133,7 @@ static void file_error_core(RMagic *ms, int error, const char *f, va_list va, ut
|
||||
}
|
||||
|
||||
/*VARARGS*/
|
||||
// XXX deprecate and just use R_LOG
|
||||
void file_error(RMagic *ms, int error, const char *f, ...) {
|
||||
va_list va;
|
||||
va_start (va, f);
|
||||
@ -217,12 +218,13 @@ int file_reset(RMagic *ms) {
|
||||
if (!ms) {
|
||||
return 0;
|
||||
}
|
||||
ms->last_cont_level = 0;
|
||||
free (ms->o.buf);
|
||||
ms->o.buf = NULL;
|
||||
ms->haderr = 0;
|
||||
ms->error = -1;
|
||||
if (!ms->mlist) {
|
||||
file_error (ms, 0, "no magic files loaded! ");
|
||||
// eprintf ("no magic files loaded, nothing to scan\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user