static void _add_chars(const int8_t* data, hlt_string_size len, int8_t* buffer, hlt_string_size* bpos, hlt_string* dst, hlt_exception** excpt, hlt_execution_context* ctx) { while ( len-- ) { _add_char(*data++, buffer, bpos, dst, excpt, ctx); if ( *excpt ) return; } }
static void _add_asciiz(const char* asciiz, int8_t* buffer, hlt_string_size* bpos, hlt_string* dst, hlt_exception** excpt, hlt_execution_context* ctx) { while ( *asciiz ) { _add_char(*asciiz++, buffer, bpos, dst, excpt, ctx); if ( *excpt ) return; } }
hlt_string hilti_fmt(hlt_string fmt, const hlt_type_info* type, void* tuple, hlt_exception** excpt, hlt_execution_context* ctx) // { assert(type->type == HLT_TYPE_TUPLE); int8_t buffer[BufferSize]; hlt_string result; const int8_t* p = fmt->bytes; hlt_string dst = 0; int64_t bpos = 0; int type_param = 0; hlt_string_size i = 0; while ( i < fmt->len ) { if ( p[i] == '%' ) { if ( ++i == fmt->len ) { hlt_set_exception(excpt, &hlt_exception_wrong_arguments, 0, ctx); return 0; } // Control character. if ( p[i] != '%' ) { _do_fmt(fmt, type, tuple, &type_param, &i, buffer, &bpos, &dst, excpt, ctx); if ( *excpt ) return 0; continue; } // Fall-through with quoted '%'. } _add_char(p[i++], buffer, &bpos, &dst, excpt, ctx); if ( *excpt ) return 0; } result = hlt_string_from_data(buffer, bpos, excpt, ctx); if ( *excpt ) return 0; if ( dst ) result = hlt_string_concat(dst, result, excpt, ctx); return result; }
void ERROR_define(const char *pattern, const char *arg[]) { int i, n; uchar c; bool subst; void _add_char(uchar c) { if (n >= MAX_ERROR_MSG) return; ERROR_info.msg[n++] = c; } void _add_string(const char *s) { while (*s) { _add_char(*s); s++; } } if ((intptr_t)pattern > 0 && (intptr_t)pattern < 256) { ERROR_info.code = (int)(intptr_t)pattern; pattern = _message[(int)(intptr_t)pattern]; } else ERROR_info.code = -1; n = 0; subst = FALSE; if (ERROR_translate) { int nsubst = 0; _add_string(pattern); for (;;) { c = *pattern++; if (c == 0) break; if (subst) { if (c >= '1' && c <= '4') { c -= '0'; if (c > nsubst) nsubst = c; } subst = FALSE; } else { if (c == '&') subst = TRUE; } } for (i = 0; i < nsubst; i++) { _add_char('\t'); _add_string(arg[i]); } } else { for (;;) { c = *pattern++; if (c == 0) break; if (subst) { if (c >= '1' && c <= '4') _add_string(arg[c - '1']); else { _add_char('&'); _add_char(c); } subst = FALSE; } else { if (c == '&') subst = TRUE; else _add_char(c); } } } _add_char(0); }