コード例 #1
0
ファイル: str.hpp プロジェクト: IchiroWang/OpenTTD
	/** Add formated string (like vsprintf) at the end of existing contents. */
	int AddFormatL(const char *format, va_list args)
	{
		size_t addSize = max<size_t>(strlen(format), 16);
		addSize += addSize / 2;
		int ret;
		int err = 0;
		for (;;) {
			char *buf = MakeFreeSpace(addSize);
			ret = vseprintf(buf, buf + base::GetReserve() - 1, format, args);
			if (ret >= (int)base::GetReserve()) {
				/* Greater return than given count means needed buffer size. */
				addSize = ret + 1;
				continue;
			}
			if (ret >= 0) {
				/* success */
				break;
			}
			err = errno;
			if (err != ERANGE && err != ENOENT && err != 0) {
				/* some strange failure */
				break;
			}
			/* small buffer (M$ implementation) */
			addSize *= 2;
		}
		if (ret > 0) {
			GrowSizeNC(ret);
		} else {
			base::FixTail();
		}
		return ret;
	}
コード例 #2
0
ファイル: hm2_eth.c プロジェクト: XNShen/linuxcnc-mirror
static char *seprintf(char *buf, char *ebuf, const char *fmt, ...) {
    va_list ap;
    va_start(ap, fmt);
    char *result = vseprintf(buf, ebuf, fmt, ap);
    va_end(ap);
    return result;
}
コード例 #3
0
/**
 * Print a formatted string into the textbuffer.
 */
void Textbuf::Print(const char *format, ...)
{
	va_list va;
	va_start(va, format);
	vseprintf(this->buf, &this->buf[this->max_bytes - 1], format, va);
	va_end(va);
	this->UpdateSize();
}
コード例 #4
0
ファイル: openttd.cpp プロジェクト: IchiroWang/OpenTTD
/**
 * Shows some information on the console/a popup box depending on the OS.
 * @param str the text to show.
 */
void CDECL ShowInfoF(const char *str, ...)
{
	va_list va;
	char buf[1024];
	va_start(va, str);
	vseprintf(buf, lastof(buf), str, va);
	va_end(va);
	ShowInfo(buf);
}
コード例 #5
0
/**
 * Safer implementation of snprintf; same as snprintf except:
 * - last instead of size, i.e. replace sizeof with lastof.
 * - return gives the amount of characters added, not what it would add.
 * @param str    buffer to write to up to last
 * @param last   last character we may write to
 * @param format the formatting (see snprintf)
 * @return the number of added characters
 */
int CDECL seprintf(char *str, const char *last, const char *format, ...)
{
	va_list ap;

	va_start(ap, format);
	int ret = vseprintf(str, last, format, ap);
	va_end(ap);
	return ret;
}
コード例 #6
0
void NORETURN CDECL strgen_fatal(const char *s, ...)
{
	char buf[1024];
	va_list va;
	va_start(va, s);
	vseprintf(buf, lastof(buf), s, va);
	va_end(va);
	DEBUG(script, 0, "%s:%d: FATAL: %s", _file, _cur_line, buf);
	throw std::exception();
}
コード例 #7
0
void CDECL strgen_error(const char *s, ...)
{
	char buf[1024];
	va_list va;
	va_start(va, s);
	vseprintf(buf, lastof(buf), s, va);
	va_end(va);
	DEBUG(script, 0, "%s:%d: error: %s", _file, _cur_line, buf);
	_errors++;
}
コード例 #8
0
ファイル: settingsgen.cpp プロジェクト: J0anJosep/OpenTTD
/**
 * Report a fatal error.
 * @param s Format string.
 * @note Function does not return.
 */
void NORETURN CDECL error(const char *s, ...)
{
	char buf[1024];
	va_list va;
	va_start(va, s);
	vseprintf(buf, lastof(buf), s, va);
	va_end(va);
	fprintf(stderr, "FATAL: %s\n", buf);
	exit(1);
}
コード例 #9
0
ファイル: sqdebug.cpp プロジェクト: SamKeightley/OpenTTD
void SQVM::Raise_Error(const SQChar *s, ...)
{
	va_list vl;
	va_start(vl, s);
	size_t len = strlen(s)+(NUMBER_MAX_CHAR*2);
	char *buffer = MallocT<char>(len + 1);
	vseprintf(buffer, buffer + len, s, vl);
	va_end(vl);
	_lasterror = SQString::Create(_ss(this),buffer,-1);
	free(buffer);
}
コード例 #10
0
/**
 * Format, "printf", into a newly allocated string.
 * @param str The formatting string.
 * @return The formatted string. You must free this!
 */
char *CDECL str_fmt(const char *str, ...)
{
	char buf[4096];
	va_list va;

	va_start(va, str);
	int len = vseprintf(buf, lastof(buf), str, va);
	va_end(va);
	char *p = MallocT<char>(len + 1);
	memcpy(p, buf, len + 1);
	return p;
}
コード例 #11
0
ファイル: console.cpp プロジェクト: Johnnei/OpenTTD
/**
 * Handle the printing of text entered into the console or redirected there
 * by any other means. Uses printf() style format, for more information look
 * at IConsolePrint()
 */
void CDECL IConsolePrintF(TextColour colour_code, const char *format, ...)
{
	assert(IsValidConsoleColour(colour_code));

	va_list va;
	char buf[ICON_MAX_STREAMSIZE];

	va_start(va, format);
	vseprintf(buf, lastof(buf), format, va);
	va_end(va);

	IConsolePrint(colour_code, buf);
}
コード例 #12
0
ファイル: openttd.cpp プロジェクト: IchiroWang/OpenTTD
/**
 * Error handling for fatal user errors.
 * @param s the string to print.
 * @note Does NEVER return.
 */
void CDECL usererror(const char *s, ...)
{
	va_list va;
	char buf[512];

	va_start(va, s);
	vseprintf(buf, lastof(buf), s, va);
	va_end(va);

	ShowOSErrorBox(buf, false);
	if (VideoDriver::GetInstance() != NULL) VideoDriver::GetInstance()->Stop();

	exit(1);
}
コード例 #13
0
ファイル: openttd.cpp プロジェクト: IchiroWang/OpenTTD
/**
 * Error handling for fatal non-user errors.
 * @param s the string to print.
 * @note Does NEVER return.
 */
void CDECL error(const char *s, ...)
{
	va_list va;
	char buf[512];

	va_start(va, s);
	vseprintf(buf, lastof(buf), s, va);
	va_end(va);

	ShowOSErrorBox(buf, true);

	/* Set the error message for the crash log and then invoke it. */
	CrashLog::SetErrorMessage(buf);
	abort();
}
コード例 #14
0
ファイル: squirrel.cpp プロジェクト: IchiroWang/OpenTTD
void Squirrel::ErrorPrintFunc(HSQUIRRELVM vm, const SQChar *s, ...)
{
	va_list arglist;
	SQChar buf[1024];

	va_start(arglist, s);
	vseprintf(buf, lastof(buf), s, arglist);
	va_end(arglist);

	/* Check if we have a custom print function */
	SQPrintFunc *func = ((Squirrel *)sq_getforeignptr(vm))->print_func;
	if (func == NULL) {
		fprintf(stderr, "%s", buf);
	} else {
		(*func)(true, buf);
	}
}
コード例 #15
0
ファイル: squirrel.cpp プロジェクト: IchiroWang/OpenTTD
void Squirrel::PrintFunc(HSQUIRRELVM vm, const SQChar *s, ...)
{
	va_list arglist;
	SQChar buf[1024];

	va_start(arglist, s);
	vseprintf(buf, lastof(buf) - 2, s, arglist);
	va_end(arglist);
	strecat(buf, "\n", lastof(buf));

	/* Check if we have a custom print function */
	SQPrintFunc *func = ((Squirrel *)sq_getforeignptr(vm))->print_func;
	if (func == NULL) {
		printf("%s", buf);
	} else {
		(*func)(false, buf);
	}
}
コード例 #16
0
ファイル: hm2_eth.c プロジェクト: XNShen/linuxcnc-mirror
static int install_iptables_rule(const char *fmt, ...) {
    char commandbuf[1024], *ptr = commandbuf,
        *ebuf = commandbuf + sizeof(commandbuf);
    ptr = seprintf(ptr, ebuf, IPTABLES" -A "CHAIN" ");
    va_list ap;
    va_start(ap, fmt);
    ptr = vseprintf(ptr, ebuf, fmt, ap);
    va_end(ap);

    if(ptr == ebuf)
    {
        LL_PRINT("ERROR: commandbuf too small\n");
        return -ENOSPC;
    }

    int res = shell(commandbuf);
    if(res == EXIT_SUCCESS) return 0;

    LL_PRINT("ERROR: Failed to execute '%s'\n", commandbuf);
    return -EINVAL;
}
コード例 #17
0
ファイル: cons.c プロジェクト: AlffiTheBerry/akaros
int pprint(char *fmt, ...)
{
	ERRSTACK(1);
	int n;
	struct chan *c;
	Osenv *o;
	va_list arg;
	char buf[2 * PRINTSIZE];

	n = sprint(buf, "%s %ld: ", up->text, up->pid);
	va_start(arg, fmt);
	n = vseprintf(buf + n, buf + sizeof(buf), fmt, arg) - buf;
	va_end(arg);

	o = up->env;
	if (o->fgrp == 0) {
		printd("%s", buf);
		return 0;
	}
	/* TODO: this is probably wrong (VFS hack) */
	c = o->fgrp->fd[2];
	if (c == 0 || (c->mode != OWRITE && c->mode != ORDWR)) {
		printd("%s", buf);
		return 0;
	}

	if (waserror()) {
		printd("%s", buf);
		poperror();
		return 0;
	}
	devtab[c->type].write(c, buf, n, c->offset);
	poperror();

	spin_lock(&c->lock);
	c->offset += n;
	spin_unlock(&c->lock);

	return n;
}