]> git.donarmstrong.com Git - lilypond.git/blob - flower/file-cookie.cc
Make relative-includes configurable with a -d option.
[lilypond.git] / flower / file-cookie.cc
1
2 #include <cassert>
3 #include <cstdio>
4 using namespace std;
5
6 #include "memory-stream.hh"
7
8 extern "C" {
9
10   bool
11   is_memory_stream (void *foo)
12   {
13     Memory_out_stream *cookie = (Memory_out_stream *) foo;
14     return dynamic_cast<Memory_out_stream *> (cookie);
15   }
16
17   void *
18   lily_fopencookie (void *cookie, char const *modes,
19                     lily_cookie_io_functions_t io_funcs)
20   {
21     (void) cookie;
22     (void) modes;
23     (void) io_funcs;
24     assert (is_memory_stream (cookie));
25     return (FILE *) cookie;
26   }
27
28   int
29   lily_cookie_fclose (void *file)
30   {
31     assert (is_memory_stream (file));
32     return Memory_out_stream::cleaner (file);
33   }
34
35   int
36   lily_cookie_fprintf (void *file, char const *format, ...)
37   {
38     assert (is_memory_stream (file));
39     va_list ap;
40     va_start (ap, format);
41
42     static char buf[65536];
43     int i = vsnprintf (buf, sizeof (buf), format, ap);
44     if (i == -1 || (unsigned) i > sizeof (buf))
45       assert (false);
46     va_end (ap);
47     return Memory_out_stream::writer (file, buf, i);
48   }
49
50   int
51   lily_cookie_putc (int c, void *file)
52   {
53     assert (is_memory_stream (file));
54     char buf[1];
55     buf[0] = (char) c;
56     return Memory_out_stream::writer (file, buf, 1);
57   }
58 } /* extern C */