Esempio n. 1
0
// Safe, portable snprintf().
int M_snprintf(char *buf, size_t buf_len, const char *s, ...)
{
    va_list args;
    int result;
    va_start(args, s);
    result = M_vsnprintf(buf, buf_len, s, args);
    va_end(args);
    return result;
}
Esempio n. 2
0
void DEH_snprintf(char *buffer, size_t len, const char *fmt, ...)
{
    va_list args;
    const char *repl;

    repl = FormatStringReplacement(fmt);

    va_start(args, fmt);

    M_vsnprintf(buffer, len, repl, args);

    va_end(args);
}
Esempio n. 3
0
static void NET_SV_SendConsoleMessage(net_client_t *client, char *s, ...)
{
    char buf[1024];
    va_list args;
    net_packet_t *packet;

    va_start(args, s);
    M_vsnprintf(buf, sizeof(buf), s, args);
    va_end(args);
    
    packet = NET_Conn_NewReliable(&client->connection, 
                                  NET_PACKET_TYPE_CONSOLE_MESSAGE);

    NET_WriteString(packet, buf);
}
Esempio n. 4
0
static void NET_SV_BroadcastMessage(char *s, ...)
{
    char buf[1024];
    va_list args;
    int i;

    va_start(args, s);
    M_vsnprintf(buf, sizeof(buf), s, args);
    va_end(args);
    
    for (i=0; i<MAXNETNODES; ++i)
    {
        if (ClientConnected(&clients[i]))
        {
            NET_SV_SendConsoleMessage(&clients[i], buf);
        }
    }

    NET_SafePuts(buf);
}
Esempio n. 5
0
void I_Error (char *error, ...)
{
    va_list argptr;
    atexit_listentry_t *entry;
    boolean exit_gui_popup;

    if (already_quitting)
    {
        fprintf(stderr, "Warning: recursive call to I_Error detected.\n");
        exit(-1);
    }
    else
    {
        already_quitting = true;
    }
    
    // Message first.
    va_start(argptr, error);
    //fprintf(stderr, "\nError: ");
    vfprintf(stderr, error, argptr);
    fprintf(stderr, "\n\n");
    va_end(argptr);
    fflush(stderr);

    // Shutdown. Here might be other errors.

    entry = exit_funcs;

    while (entry != NULL)
    {
        if (entry->run_on_error)
        {
            entry->func();
        }

        entry = entry->next;
    }

    exit_gui_popup = !M_ParmExists("-nogui");

#ifdef _WIN32
    // On Windows, pop up a dialog box with the error message.

    if (exit_gui_popup)
    {
        char msgbuf[512];
        wchar_t wmsgbuf[512];

        va_start(argptr, error);
        memset(msgbuf, 0, sizeof(msgbuf));
        M_vsnprintf(msgbuf, sizeof(msgbuf), error, argptr);
        va_end(argptr);

        MultiByteToWideChar(CP_ACP, 0,
                            msgbuf, strlen(msgbuf) + 1,
                            wmsgbuf, sizeof(wmsgbuf));

        MessageBoxW(NULL, wmsgbuf, L"", MB_OK);
    }
#elif defined(__MACOSX__)
    if (exit_gui_popup && !I_ConsoleStdout())
    {
        CFStringRef message;
        char msgbuf[512];
	int i;

        va_start(argptr, error);
        memset(msgbuf, 0, sizeof(msgbuf));
        M_vsnprintf(msgbuf, sizeof(msgbuf), error, argptr);
        va_end(argptr);

	// The CoreFoundation message box wraps text lines, so replace
	// newline characters with spaces so that multiline messages
	// are continuous.

	for (i = 0; msgbuf[i] != '\0'; ++i)
        {
            if (msgbuf[i] == '\n')
            {
                msgbuf[i] = ' ';
            }
        }

        message = CFStringCreateWithCString(NULL, msgbuf,
                                            kCFStringEncodingUTF8);

        CFUserNotificationDisplayNotice(0,
                                        kCFUserNotificationCautionAlertLevel,
                                        NULL,
                                        NULL,
                                        NULL,
                                        CFSTR(PACKAGE_STRING),
                                        message,
                                        NULL);
    }
#else
    if (exit_gui_popup && !I_ConsoleStdout())
    {
        ZenityErrorBox(error);
    }
#endif

    // abort();

    exit(-1);
}
Esempio n. 6
0
void I_Error (const char *error, ...)
{
	char msgbuf[512];
	va_list argptr;
	atexit_listentry_t *entry;
	boolean exit_gui_popup;

	if (already_quitting)
	{
		fprintf(stderr, "Warning: recursive call to I_Error detected.\n");
		exit(-1);
	}
	else
	{
		already_quitting = true;
	}

	// Message first.
	va_start(argptr, error);
	//fprintf(stderr, "\nError: ");
	vfprintf(stderr, error, argptr);
	fprintf(stderr, "\n\n");
	va_end(argptr);
	fflush(stderr);

	// Write a copy of the message into buffer.
	va_start(argptr, error);
	memset(msgbuf, 0, sizeof(msgbuf));
	M_vsnprintf(msgbuf, sizeof(msgbuf), error, argptr);
	va_end(argptr);

	// Shutdown. Here might be other errors.

	entry = exit_funcs;

	while (entry != NULL)
	{
		if (entry->run_on_error)
		{
			entry->func();
		}

		entry = entry->next;
	}

    //!
    // @category obscure
    //
    // If specified, don't show a GUI window for error messages when the
    // game exits with an error.
    //
	exit_gui_popup = !M_ParmExists("-nogui");

	// Pop up a GUI dialog box to show the error message, if the
	// game was not run from the console (and the user will
	// therefore be unable to otherwise see the message).
	if (exit_gui_popup && !I_ConsoleStdout())
	{
        SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
                                 PACKAGE_STRING, msgbuf, NULL);
    }

    // abort();

    SDL_Quit();

    exit(-1);
	}