void ErrMsg_set_with_errno(const char *fmt, ...) { int cur_errno = errno; CharBuf *buf = CB_new(0); va_list args; va_start(args, fmt); CB_VCatF(buf, fmt, args); va_end(args); CB_Cat_Trusted_Utf8(buf, ": ", 2); const char *msg = ErrMsg_strerror(cur_errno); if (msg != NULL) { CB_Cat_Trusted_Utf8(buf, msg, strlen(msg)); } else { CB_catf(buf, "Unknown error: %i32", (int32_t)cur_errno); } Err_set_error(Err_new(CB_Yield_String(buf))); DECREF(buf); }
void CB_catf(CharBuf *self, const char *pattern, ...) { va_list args; va_start(args, pattern); CB_VCatF(self, pattern, args); va_end(args); }
static String* S_str_vnewf(char *pattern, va_list args) { CharBuf *buf = CB_new(strlen(pattern) + 10); CB_VCatF(buf, pattern, args); String *message = CB_Yield_String(buf); DECREF(buf); return message; }
void CB_setf(CharBuf *self, const char *pattern, ...) { va_list args; CB_Set_Size(self, 0); va_start(args, pattern); CB_VCatF(self, pattern, args); va_end(args); }
CharBuf* CB_newf(const char *pattern, ...) { CharBuf *self = CB_new(strlen(pattern)); va_list args; va_start(args, pattern); CB_VCatF(self, pattern, args); va_end(args); return self; }
String* Str_newf(const char *pattern, ...) { CharBuf *buf = CB_new(strlen(pattern)); va_list args; va_start(args, pattern); CB_VCatF(buf, pattern, args); va_end(args); String *self = CB_Yield_String(buf); DECREF(buf); return self; }
CharBuf* CFISH_MAKE_MESS(char *pattern, ...) { va_list args; CharBuf *const message = CB_new(strlen(pattern) + 10); va_start(args, pattern); CB_VCatF(message, pattern, args); va_end(args); return message; }
void CFISH_WARN(char *pattern, ...) { va_list args; CharBuf *const message = CB_new(strlen(pattern) + 10); va_start(args, pattern); CB_VCatF(message, pattern, args); va_end(args); Err_warn_mess(message); }
void THROW(char *pattern, ...) { va_list args; CharBuf *const message = CB_new(strlen(pattern) + 10); va_start(args, pattern); CB_VCatF(message, pattern, args); va_end(args); Err_throw_mess(message); }
void ErrMsg_set(const char *fmt, ...) { CharBuf *buf = CB_new(0); va_list args; va_start(args, fmt); CB_VCatF(buf, fmt, args); va_end(args); Err_set_error(Err_new(CB_Yield_String(buf))); DECREF(buf); }
void THROW(VTable *vtable, char *pattern, ...) { va_list args; Err_Make_t make = METHOD_PTR(CERTIFY(vtable, VTABLE), Lucy_Err_Make); Err *err = (Err*)CERTIFY(make(NULL), ERR); CharBuf *mess = Err_Get_Mess(err); va_start(args, pattern); CB_VCatF(mess, pattern, args); va_end(args); Err_do_throw(err); }
static void S_vcat_mess(CharBuf *message, const char *file, int line, const char *func, const char *pattern, va_list args) { size_t guess_len = strlen(file) + func ? strlen(func) : 0 + strlen(pattern) + 30; CB_Grow(message, guess_len); CB_VCatF(message, pattern, args); if (func != NULL) CB_catf(message, " at %s:%i32 %s ", file, (i32_t)line, func); else CB_catf(message, " at %s:%i32", file, (i32_t)line); }
void ErrMsg_set_with_win_error(const char *fmt, ...) { char *win_error = Err_win_error(); CharBuf *buf = CB_new(0); va_list args; va_start(args, fmt); CB_VCatF(buf, fmt, args); va_end(args); CB_Cat_Trusted_Utf8(buf, ": ", 2); CB_Cat_Utf8(buf, win_error, strlen(win_error)); Err_set_error(Err_new(CB_Yield_String(buf))); DECREF(buf); FREEMEM(win_error); }
static String* S_vmake_mess(const char *file, int line, const char *func, const char *pattern, va_list args) { size_t guess_len = strlen(file) + (func ? strlen(func) : 0) + strlen(pattern) + 30; CharBuf *buf = CB_new(guess_len); CB_VCatF(buf, pattern, args); if (func != NULL) { CB_catf(buf, "\n\t%s at %s line %i32\n", func, file, (int32_t)line); } else { CB_catf(buf, "\n\t%s line %i32\n", file, (int32_t)line); } String *message = CB_Yield_String(buf); DECREF(buf); return message; }