aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/matplotlib/py3/extern/ttconv/ttutil.cpp
blob: 6028e1d45d4a976e6922ecf835a20131fa4c5b8c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* -*- mode: c++; c-basic-offset: 4 -*- */

/*
 * Modified for use within matplotlib
 * 5 July 2007
 * Michael Droettboom
 */

/* Very simple interface to the ppr TT routines */
/* (c) Frank Siegert 1996 */

#include <cstdio>
#include <cstdarg>
#include <cstdlib>
#include "pprdrv.h"

#define PRINTF_BUFFER_SIZE 512
void TTStreamWriter::printf(const char* format, ...)
{
  va_list arg_list;
  va_start(arg_list, format);
  char buffer[PRINTF_BUFFER_SIZE];

#if defined(WIN32) || defined(_MSC_VER)
  int size = _vsnprintf(buffer, PRINTF_BUFFER_SIZE, format, arg_list);
#else
  int size = vsnprintf(buffer, PRINTF_BUFFER_SIZE, format, arg_list);
#endif
  if (size >= PRINTF_BUFFER_SIZE) {
    char* buffer2 = (char*)malloc(size);
#if defined(WIN32) || defined(_MSC_VER)
    _vsnprintf(buffer2, size, format, arg_list);
#else
    vsnprintf(buffer2, size, format, arg_list);
#endif
    this->write(buffer2);
    free(buffer2);
  } else {
    this->write(buffer);
  }

  va_end(arg_list);
}

void TTStreamWriter::put_char(int val)
{
  char c[2];
  c[0] = (char)val;
  c[1] = 0;
  this->write(c);
}

void TTStreamWriter::puts(const char *a)
{
  this->write(a);
}

void TTStreamWriter::putline(const char *a)
{
  this->write(a);
  this->write("\n");
}

void replace_newlines_with_spaces(char *a) {
  char* i = a;
  while (*i != 0) {
    if (*i == '\r' || *i == '\n')
      *i = ' ';
    i++;
  }
}