pure-data/src/s_print.c

/* Copyright (c) 1997-1999 Miller Puckette.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */

#include "m_pd.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include "s_stuff.h"
#include "m_private_utils.h"

#ifdef _WIN32
#ifndef PD_FWPRINTF_NARROW_FORMATTER
#if __USE_MINGW_ANSI_STDIO
    /* This is a workaround for a bug in the old msvcrt.dll used by MinGW */
    #define PD_FWPRINTF_NARROW_FORMATTER
#else
    /* Covers modern C runtimes on MSYS2 & MSVC */
    #define PD_FWPRINTF_NARROW_FORMATTER
#endif
#endif /* PD_FWPRINTF_NARROW_FORMATTER */
#endif /* _WIN32 */

t_printhook sys_printhook =;
int sys_printtostderr;

#ifdef _WIN32

    /* NB: Unlike vsnprintf(), _vsnprintf() does *not* null-terminate
    the output if the resulting string is too large to fit into the buffer.
    Also, it just returns -1 instead of the required number of bytes.
    Strictly speaking, the UCRT in Windows 10 actually contains a standard-
    conforming vsnprintf() function that is not just an alias for _vsnprintf().
    However, MinGW traditionally links against the old msvcrt.dll runtime library.
    Recent versions of MinGW seem to have their own (standard-conformating)
    implementation of vsnprintf(), but to ensure portability we rather use our
    own implementation for all Windows builds. */
int pd_vsnprintf(char *buf, size_t size, const char *fmt, va_list argptr)
{
    int ret = _vsnprintf(buf, size, fmt, argptr);
    if (ret < 0)
    {
            /* null-terminate the buffer and get the required number of bytes. */
        ret = _vscprintf(fmt, argptr);
        buf[size - 1] = '\0';
    }
    return ret;
}

int pd_snprintf(char *buf, size_t size, const char *fmt, ...)
{
    int ret;
    va_list ap;
    va_start(ap, fmt);
    ret = pd_vsnprintf(buf, size, fmt, ap);
    va_end(ap);
    return ret;
}

#else

int pd_vsnprintf(char *buf, size_t size, const char *fmt, va_list argptr)
{}

int pd_snprintf(char *buf, size_t size, const char *fmt, ...)
{}

#endif

/* escape characters for tcl/tk */
char* pdgui_strnescape(char *dst, size_t dstlen, const char *src, size_t srclen)
{}

static void dopost(const char *s)
{}

static void doerror(const void *object, const char *s)
{}

static void dologpost(const void *object, const int level, const char *s)
{}

void logpost(const void *object, int level, const char *fmt, ...)
{}

void startlogpost(const void *object, const int level, const char *fmt, ...)
{}


void post(const char *fmt, ...)
{}

void startpost(const char *fmt, ...)
{}

void poststring(const char *s)
{}

void postatom(int argc, const t_atom *argv)
{}

void postfloat(t_float f)
{}

void endpost(void)
{}

  /* keep this in the Pd app for binary extern compatibility but don't
  include in libpd because it conflicts with the posix pd_error(0, ) function. */
#ifdef PD_INTERNAL
EXTERN void error(const char *fmt, ...)
{}
#endif

/* deprecated in favor of logpost() */
void verbose(int level, const char *fmt, ...)
{}

    /* here's the good way to log errors -- keep a pointer to the
    offending or offended object around so the user can search for it
    later. */

static const void *error_object;
static char error_string[256];
void canvas_finderror(const void *object);

void pd_error(const void *object, const char *fmt, ...)
{}

void glob_finderror(t_pd *dummy)
{}

void glob_findinstance(t_pd *dummy, t_symbol*s)
{}

void bug(const char *fmt, ...)
{}

    /* don't use these.  They're included for binary compatibility with
    old externs but never worked and now do nothing. */
void sys_logerror(const char *object, const char *s) {}
void sys_unixerror(const char *object) {}
void sys_ouch(void) {}