static int search_list(const_char_ptr const *list, int len, unsigned char *name) { int result; #define T_EQUAL(n, k) !casestrcmp(cast_uchar list[n], k) #define T_ABOVE(n, k) casestrcmp(cast_uchar list[n], k) > 0 BIN_SEARCH(len, T_EQUAL, T_ABOVE, name, result); return result != -1; }
/** * Turns the backtrace into a string that can be displayed * * @param bt * @return */ char *arch_debug_bt2string(struct bt *bt) { #if defined(__SASC) && defined(DEBUG_RESTRACK) string str; char buf[120]; int i; int last_line = -1; char *last_file = NULL; if (!bt) return NULL; if (!(string_initialize(&str,200))) return NULL; /* Load debug infos if not done yet */ arch_debug_load(); string_append(&str,"Backtrace\n"); for (i=0;i<bt->addr_used;i++) { ULONG offset = (ULONG)bt->addr[i] - (ULONG)__code_base; sm_snprintf(buf,sizeof(buf),"\t\t%p (offset %p",bt->addr[i],offset); string_append(&str,buf); if (debug_info_count > 0) { struct debug_info *di; int offset = (ULONG)bt->addr[i] - (ULONG)__code_base; BIN_SEARCH(debug_info_array, 0, debug_info_count-1, (debug_info_array[m].offset <= offset) ? (offset < debug_info_array[m+1].offset?0:(1)):(-1), di); if (di && (di->filename != last_file || di->line != last_line)) { string_append(&str,", "); sm_snprintf(buf,sizeof(buf),"%s/%d",di->filename,di->line); string_append(&str,buf); last_file = di->filename; last_line = di->line; } } string_append(&str,")\n"); } return str.str; #else return NULL; #endif }
unsigned char *u2cp(int u, int to, int fallback) { int j, s; again: if (u < 128) return cast_uchar strings[u]; if (is_nbsp(u)) return cast_uchar strings[1]; if (u == 0xad) return cast_uchar strings[0]; if (to == utf8_table) return encode_utf_8(u); if (u < 0xa0) { u = strange_chars[u - 0x80]; if (!u) return NULL; goto again; } for (j = 0; codepages[to].table[j].c; j++) if (codepages[to].table[j].u == u) return cast_uchar strings[codepages[to].table[j].c]; if (!fallback) return NULL; BIN_SEARCH(N_UNICODE_7B, U_EQUAL, U_ABOVE, u, s); if (s != -1) return cast_uchar unicode_7b[s].s; return NULL; }
const unsigned char * u2cp_(unicode_val_T u, int to, enum nbsp_mode nbsp_mode) { int j; int s; if (u < 128) return strings[u]; if (u < 0xa0) { u = strange_chars[u - 0x80]; if (!u) return NULL; } to &= ~SYSTEM_CHARSET_FLAG; if (is_cp_ptr_utf8(&codepages[to])) return encode_utf8(u); /* To mark non breaking spaces in non-UTF-8 strings, we use a * special char NBSP_CHAR. */ if (u == UCS_NO_BREAK_SPACE) { if (nbsp_mode == NBSP_MODE_HACK) return NBSP_CHAR_STRING; else /* NBSP_MODE_ASCII */ return " "; } if (u == UCS_SOFT_HYPHEN) return ""; if (u < 0xFFFF) for (j = 0; j < 0x80; j++) if (codepages[to].highhalf[j] == u) return strings[0x80 + j]; for (j = 0; codepages[to].table[j].c; j++) if (codepages[to].table[j].u == u) return strings[codepages[to].table[j].c]; BIN_SEARCH(unicode_7b, x, N_UNICODE_7B, u, s); if (s != -1) return unicode_7b[s].s; return no_str; }