123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- #include "sys-defines.h"
- #include "extern.h"
- void
- _pl_m_emit_op_code (R___(Plotter *_plotter) int c)
- {
- if (_plotter->data->outfp)
- putc (c, _plotter->data->outfp);
- #ifdef LIBPLOTTER
- else if (_plotter->data->outstream)
- _plotter->data->outstream->put ((unsigned char)c);
- #endif
- }
- void
- _pl_m_emit_integer (R___(Plotter *_plotter) int x)
- {
- if (_plotter->data->outfp)
- {
- if (_plotter->meta_portable_output)
- fprintf (_plotter->data->outfp, " %d", x);
- else
- fwrite ((void *) &x, sizeof(int), 1, _plotter->data->outfp);
- }
- #ifdef LIBPLOTTER
- else if (_plotter->data->outstream)
- {
- if (_plotter->meta_portable_output)
- (*(_plotter->data->outstream)) << ' ' << x;
- else
- _plotter->data->outstream->write((char *)&x, sizeof(int));
- }
- #endif
- }
- void
- _pl_m_emit_float (R___(Plotter *_plotter) double x)
- {
- if (_plotter->data->outfp)
- {
- if (_plotter->meta_portable_output)
- {
-
- fprintf (_plotter->data->outfp, x == 0.0 ? " 0" : " %g", x);
- }
- else
- {
- float f;
-
- f = FROUND(x);
- fwrite ((void *) &f, sizeof(float), 1, _plotter->data->outfp);
- }
- }
- #ifdef LIBPLOTTER
- else if (_plotter->data->outstream)
- {
- if (_plotter->meta_portable_output)
- (*(_plotter->data->outstream)) << ' ' << x;
- else
- {
- float f;
-
- f = FROUND(x);
- _plotter->data->outstream->write((char *)&f, sizeof(float));
- }
- }
- #endif
- }
- void
- _pl_m_emit_string (R___(Plotter *_plotter) const char *s)
- {
- bool has_newline;
- char *t = NULL;
- char *nl;
- const char *u;
-
-
- if (s == NULL)
- s = "(null)";
-
- if (strchr (s, '\n'))
-
- {
- has_newline = true;
- t = (char *)_pl_xmalloc (strlen (s) + 1);
- strcpy (t, s);
- nl = strchr (t, '\n');
- *nl = '\0';
- u = t;
- }
- else
- {
- has_newline = false;
- u = s;
- }
-
-
- if (_plotter->data->outfp)
- {
- fputs (u, _plotter->data->outfp);
- if (_plotter->meta_portable_output == false)
- putc ('\n', _plotter->data->outfp);
- }
- #ifdef LIBPLOTTER
- else if (_plotter->data->outstream)
- {
- (*(_plotter->data->outstream)) << u;
- if (_plotter->meta_portable_output == false)
- (*(_plotter->data->outstream)) << '\n';
- }
- #endif
- if (has_newline)
- free (t);
- }
- void
- _pl_m_emit_terminator (S___(Plotter *_plotter))
- {
- if (_plotter->meta_portable_output)
- {
- if (_plotter->data->outfp)
- putc ('\n', _plotter->data->outfp);
- #ifdef LIBPLOTTER
- else if (_plotter->data->outstream)
- (*(_plotter->data->outstream)) << '\n';
- #endif
- }
- }
|