~ubuntu-branches/ubuntu/gutsy/plotutils/gutsy

« back to all changes in this revision

Viewing changes to libplot/c_emit.c

  • Committer: Bazaar Package Importer
  • Author(s): Floris Bruynooghe
  • Date: 2007-05-10 19:48:54 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070510194854-mrr3lgwzpxd8hovo
Tags: 2.5-2
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the GNU plotutils package.  Copyright (C) 1995,
 
2
   1996, 1997, 1998, 1999, 2000, 2005, Free Software Foundation, Inc.
 
3
 
 
4
   The GNU plotutils package is free software.  You may redistribute it
 
5
   and/or modify it under the terms of the GNU General Public License as
 
6
   published by the Free Software foundation; either version 2, or (at your
 
7
   option) any later version.
 
8
 
 
9
   The GNU plotutils package is distributed in the hope that it will be
 
10
   useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
   General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU General Public License along
 
15
   with the GNU plotutils package; see the file COPYING.  If not, write to
 
16
   the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
 
17
   Boston, MA 02110-1301, USA. */
 
18
 
1
19
/* This file contains low-level functions used by CGMPlotters.  E.g.,
2
20
   _cgm_emit_command_header and _cgm_emit_command_terminator, which begin
3
21
   and end a CGM command.  A CGM output file, in either the binary or clear
75
93
(((data_len) > 30) && ((*(data_byte_count)) % CGM_BINARY_DATA_BYTES_PER_PARTITION == 0))
76
94
 
77
95
/* forward references */
78
 
static void _cgm_emit_partition_control_word ____P((plOutbuf *outbuf, int data_len, const int *data_byte_count, int *byte_count));
79
 
static void _double_to_ieee_single_precision ____P((double d, unsigned char output[4]));
80
 
static void _int_to_cgm_int ____P((int n, unsigned char *cgm_int, int octets_per_cgm_int));
81
 
static void _unsigned_int_to_cgm_unsigned_int ____P((unsigned int n, unsigned char *cgm_unsigned_int, int octets_per_cgm_unsigned_int));
 
96
static void cgm_emit_partition_control_word (plOutbuf *outbuf, int data_len, const int *data_byte_count, int *byte_count);
 
97
static void double_to_ieee_single_precision (double d, unsigned char output[4]);
 
98
static void int_to_cgm_int (int n, unsigned char *cgm_int, int octets_per_cgm_int);
 
99
static void unsigned_int_to_cgm_unsigned_int (unsigned int n, unsigned char *cgm_unsigned_int, int octets_per_cgm_unsigned_int);
82
100
 
83
101
 
84
102
/* Write the header of a CGM command.  
98
116
   latter is updated by the argument-emitting functions).  */
99
117
 
100
118
void
101
 
#ifdef _HAVE_PROTOS
102
119
_cgm_emit_command_header (plOutbuf *outbuf, int cgm_encoding, int element_class, int id, int data_len, int *byte_count, const char *op_code)
103
 
#else
104
 
_cgm_emit_command_header (outbuf, cgm_encoding, element_class, id, data_len, byte_count, op_code)
105
 
     plOutbuf *outbuf;
106
 
     int cgm_encoding;
107
 
     int element_class, id;
108
 
     int data_len;
109
 
     int *byte_count;
110
 
     const char *op_code;
111
 
#endif
112
120
{
113
121
  switch (cgm_encoding)
114
122
    {
148
156
   word, to indicate that another data partition will follow. */
149
157
 
150
158
static void
151
 
#ifdef _HAVE_PROTOS
152
 
_cgm_emit_partition_control_word (plOutbuf *outbuf, int data_len, const int *data_byte_count, int *byte_count)
153
 
#else
154
 
_cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count)
155
 
     plOutbuf *outbuf;
156
 
     int data_len;
157
 
     const int *data_byte_count;
158
 
     int *byte_count;
159
 
#endif
 
159
cgm_emit_partition_control_word (plOutbuf *outbuf, int data_len, const int *data_byte_count, int *byte_count)
160
160
{
161
161
  int bytes_remaining = data_len - (*data_byte_count);
162
162
  int bytes_in_partition;
196
196
   unsigned chars to chars with impunity. */
197
197
 
198
198
static void
199
 
#ifdef _HAVE_PROTOS
200
 
_int_to_cgm_int (int n, unsigned char *cgm_int, int octets_per_cgm_int)
201
 
#else
202
 
_int_to_cgm_int (n, cgm_int, octets_per_cgm_int)
203
 
     int n;
204
 
     unsigned char *cgm_int;
205
 
     int octets_per_cgm_int;
206
 
#endif
 
199
int_to_cgm_int (int n, unsigned char *cgm_int, int octets_per_cgm_int)
207
200
{
208
201
  int max_int, i;
209
202
  unsigned int u;
246
239
/* similar to the preceding, but for unsigned ints rather than signed ints */
247
240
 
248
241
static void
249
 
#ifdef _HAVE_PROTOS
250
 
_unsigned_int_to_cgm_unsigned_int (unsigned int n, unsigned char *cgm_unsigned_int, int octets_per_cgm_unsigned_int)
251
 
#else
252
 
_unsigned_int_to_cgm_unsigned_int (n, cgm_unsigned_int, octets_per_cgm_unsigned_int)
253
 
     unsigned int n;
254
 
     unsigned char *cgm_unsigned_int;
255
 
     int octets_per_cgm_unsigned_int;
256
 
#endif
 
242
unsigned_int_to_cgm_unsigned_int (unsigned int n, unsigned char *cgm_unsigned_int, int octets_per_cgm_unsigned_int)
257
243
{
258
244
  unsigned int max_unsigned_int;
259
245
  int i;
283
269
   be increased. */
284
270
 
285
271
void
286
 
#ifdef _HAVE_PROTOS
287
272
_cgm_emit_integer (plOutbuf *outbuf, bool no_partitioning, int cgm_encoding, int x, int data_len, int *data_byte_count, int *byte_count)
288
 
#else
289
 
_cgm_emit_integer (outbuf, no_partitioning, cgm_encoding, x, data_len, data_byte_count, byte_count)
290
 
     plOutbuf *outbuf;
291
 
     bool no_partitioning;
292
 
     int cgm_encoding;
293
 
     int x;
294
 
     int data_len;
295
 
     int *data_byte_count, *byte_count;
296
 
#endif
297
273
{
298
274
  int i;
299
275
  unsigned char cgm_int[CGM_BINARY_BYTES_PER_INTEGER];
302
278
    {
303
279
    case CGM_ENCODING_BINARY:
304
280
    default:
305
 
      _int_to_cgm_int (x, cgm_int, CGM_BINARY_BYTES_PER_INTEGER);
 
281
      int_to_cgm_int (x, cgm_int, CGM_BINARY_BYTES_PER_INTEGER);
306
282
      for (i = 0; i < CGM_BINARY_BYTES_PER_INTEGER; i++)
307
283
        {
308
284
          if (no_partitioning == false
309
285
              && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
310
 
            _cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
 
286
            cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
311
287
          
312
288
          *(outbuf->point) = (char)(cgm_int[i]);
313
289
          _update_buffer_by_added_bytes (outbuf, 1);
330
306
   signed integer. */
331
307
 
332
308
void
333
 
#ifdef _HAVE_PROTOS
334
309
_cgm_emit_unsigned_integer (plOutbuf *outbuf, bool no_partitioning, int cgm_encoding, unsigned int x, int data_len, int *data_byte_count, int *byte_count)
335
 
#else
336
 
_cgm_emit_unsigned_integer (outbuf, no_partitioning, cgm_encoding, x, data_len, data_byte_count, byte_count)
337
 
     plOutbuf *outbuf;
338
 
     bool no_partitioning;
339
 
     int cgm_encoding;
340
 
     unsigned int x;
341
 
     int data_len;
342
 
     int *data_byte_count, *byte_count;
343
 
#endif
344
310
{
345
311
  int i;
346
312
  unsigned char cgm_unsigned_int[CGM_BINARY_BYTES_PER_INTEGER];
349
315
    {
350
316
    case CGM_ENCODING_BINARY:
351
317
    default:
352
 
      _unsigned_int_to_cgm_unsigned_int (x, cgm_unsigned_int, CGM_BINARY_BYTES_PER_INTEGER);
 
318
      unsigned_int_to_cgm_unsigned_int (x, cgm_unsigned_int, CGM_BINARY_BYTES_PER_INTEGER);
353
319
      for (i = 0; i < CGM_BINARY_BYTES_PER_INTEGER; i++)
354
320
        {
355
321
          if (no_partitioning == false
356
322
              && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
357
 
            _cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
 
323
            cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
358
324
          
359
325
          *(outbuf->point) = (char)(cgm_unsigned_int[i]);
360
326
          _update_buffer_by_added_bytes (outbuf, 1);
377
343
   unsigned integer in the range 0.255) as a single byte.  */
378
344
 
379
345
void
380
 
#ifdef _HAVE_PROTOS
381
346
_cgm_emit_unsigned_integer_8bit (plOutbuf *outbuf, bool no_partitioning, int cgm_encoding, unsigned int x, int data_len, int *data_byte_count, int *byte_count)
382
 
#else
383
 
_cgm_emit_unsigned_integer_8bit (outbuf, no_partitioning, cgm_encoding, x, data_len, data_byte_count, byte_count)
384
 
     plOutbuf *outbuf;
385
 
     bool no_partitioning;
386
 
     int cgm_encoding;
387
 
     unsigned int x;
388
 
     int data_len;
389
 
     int *data_byte_count, *byte_count;
390
 
#endif
391
347
{
392
348
  /* clamp to 0..255 */
393
349
  if (x > (unsigned int)255)
399
355
    default:
400
356
      if (no_partitioning == false
401
357
          && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
402
 
        _cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
 
358
        cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
403
359
          
404
360
      *(outbuf->point) = (char)(unsigned char)x;
405
361
      _update_buffer_by_added_bytes (outbuf, 1);
421
377
   binary encoding, 2 * CGM_BINARY_BYTES_PER_INTEGER bytes are written. */
422
378
 
423
379
void
424
 
#ifdef _HAVE_PROTOS
425
380
_cgm_emit_point (plOutbuf *outbuf, bool no_partitioning, int cgm_encoding, int x, int y, int data_len, int *data_byte_count, int *byte_count)
426
 
#else
427
 
_cgm_emit_point (outbuf, no_partitioning, cgm_encoding, x, y, data_len, data_byte_count, byte_count)
428
 
     plOutbuf *outbuf;
429
 
     bool no_partitioning;
430
 
     int cgm_encoding;
431
 
     int x, y;
432
 
     int data_len;
433
 
     int *data_byte_count, *byte_count;
434
 
#endif
435
381
{
436
382
  int i;
437
383
  unsigned char cgm_int[CGM_BINARY_BYTES_PER_INTEGER];
440
386
    {
441
387
    case CGM_ENCODING_BINARY:
442
388
    default:
443
 
      _int_to_cgm_int (x, cgm_int, CGM_BINARY_BYTES_PER_INTEGER);
 
389
      int_to_cgm_int (x, cgm_int, CGM_BINARY_BYTES_PER_INTEGER);
444
390
      for (i = 0; i < CGM_BINARY_BYTES_PER_INTEGER; i++)
445
391
        {
446
392
          if (no_partitioning == false
447
393
              && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
448
 
            _cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
 
394
            cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
449
395
          
450
396
          *(outbuf->point) = (char)(cgm_int[i]);
451
397
          _update_buffer_by_added_bytes (outbuf, 1);
452
398
          (*data_byte_count)++;
453
399
          (*byte_count)++;
454
400
        }
455
 
      _int_to_cgm_int (y, cgm_int, CGM_BINARY_BYTES_PER_INTEGER);
 
401
      int_to_cgm_int (y, cgm_int, CGM_BINARY_BYTES_PER_INTEGER);
456
402
      for (i = 0; i < CGM_BINARY_BYTES_PER_INTEGER; i++)
457
403
        {
458
404
          if (no_partitioning == false
459
405
              && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
460
 
            _cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
 
406
            cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
461
407
          
462
408
          *(outbuf->point) = (char)(cgm_int[i]);
463
409
          _update_buffer_by_added_bytes (outbuf, 1);
480
426
   CGM format.  */
481
427
 
482
428
void
483
 
#ifdef _HAVE_PROTOS
484
429
_cgm_emit_points (plOutbuf *outbuf, bool no_partitioning, int cgm_encoding, const int *x, const int *y, int npoints, int data_len, int *data_byte_count, int *byte_count)
485
 
#else
486
 
_cgm_emit_points (outbuf, no_partitioning, cgm_encoding, x, y, npoints, data_len, data_byte_count, byte_count)
487
 
     plOutbuf *outbuf;
488
 
     bool no_partitioning;
489
 
     int cgm_encoding;
490
 
     const int *x, *y;
491
 
     int npoints;
492
 
     int data_len;
493
 
     int *data_byte_count, *byte_count;
494
 
#endif
495
430
{
496
431
  int i, j;
497
432
  unsigned char cgm_int[CGM_BINARY_BYTES_PER_INTEGER];
502
437
    default:
503
438
      for (j = 0; j < npoints; j++)
504
439
        {
505
 
          _int_to_cgm_int (x[j], cgm_int, CGM_BINARY_BYTES_PER_INTEGER);
 
440
          int_to_cgm_int (x[j], cgm_int, CGM_BINARY_BYTES_PER_INTEGER);
506
441
          for (i = 0; i < CGM_BINARY_BYTES_PER_INTEGER; i++)
507
442
            {
508
443
              if (no_partitioning == false
509
444
                  && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
510
 
                _cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
 
445
                cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
511
446
              
512
447
              *(outbuf->point) = (char)(cgm_int[i]);
513
448
              _update_buffer_by_added_bytes (outbuf, 1);
514
449
              (*data_byte_count)++;
515
450
              (*byte_count)++;
516
451
            }
517
 
          _int_to_cgm_int (y[j], cgm_int, CGM_BINARY_BYTES_PER_INTEGER);
 
452
          int_to_cgm_int (y[j], cgm_int, CGM_BINARY_BYTES_PER_INTEGER);
518
453
          for (i = 0; i < CGM_BINARY_BYTES_PER_INTEGER; i++)
519
454
            {
520
455
              if (no_partitioning == false
521
456
                  && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
522
 
                _cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
 
457
                cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
523
458
              
524
459
              *(outbuf->point) = (char)(cgm_int[i]);
525
460
              _update_buffer_by_added_bytes (outbuf, 1);
548
483
   string is written. */
549
484
 
550
485
void
551
 
#ifdef _HAVE_PROTOS
552
486
_cgm_emit_enum (plOutbuf *outbuf, bool no_partitioning, int cgm_encoding, int x, int data_len, int *data_byte_count, int *byte_count, const char *text_string)
553
 
#else
554
 
_cgm_emit_enum (outbuf, no_partitioning, cgm_encoding, x, data_len, data_byte_count, byte_count, text_string)
555
 
     plOutbuf *outbuf;
556
 
     bool no_partitioning;
557
 
     int cgm_encoding;
558
 
     int x;
559
 
     int data_len;
560
 
     int *data_byte_count, *byte_count;
561
 
     const char *text_string;
562
 
#endif
563
487
{
564
488
  int i;
565
489
  unsigned char cgm_int[2];
568
492
    {
569
493
    case CGM_ENCODING_BINARY:
570
494
    default:
571
 
      _int_to_cgm_int (x, cgm_int, 2);
 
495
      int_to_cgm_int (x, cgm_int, 2);
572
496
      for (i = 0; i < 2; i++)
573
497
        {
574
498
          if (no_partitioning == false
575
499
              && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
576
 
            _cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
 
500
            cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
577
501
          
578
502
          *(outbuf->point) = (char)(cgm_int[i]);
579
503
          _update_buffer_by_added_bytes (outbuf, 1);
602
526
   precisions). */
603
527
 
604
528
void
605
 
#ifdef _HAVE_PROTOS
606
529
_cgm_emit_index (plOutbuf *outbuf, bool no_partitioning, int cgm_encoding, int x, int data_len, int *data_byte_count, int *byte_count)
607
 
#else
608
 
_cgm_emit_index (outbuf, no_partitioning, cgm_encoding, x, data_len, data_byte_count, byte_count)
609
 
     plOutbuf *outbuf;
610
 
     bool no_partitioning;
611
 
     int cgm_encoding;
612
 
     int x;
613
 
     int data_len;
614
 
     int *data_byte_count, *byte_count;
615
 
#endif
616
530
{
617
531
  int i;
618
532
  unsigned char cgm_int[2];
621
535
    {
622
536
    case CGM_ENCODING_BINARY:
623
537
    default:
624
 
      _int_to_cgm_int (x, cgm_int, 2);
 
538
      int_to_cgm_int (x, cgm_int, 2);
625
539
      for (i = 0; i < 2; i++)
626
540
        {
627
541
          if (no_partitioning == false
628
542
              && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
629
 
            _cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
 
543
            cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
630
544
          
631
545
          *(outbuf->point) = (char)(cgm_int[i]);
632
546
          _update_buffer_by_added_bytes (outbuf, 1);
651
565
   c_color.c supports only 1 or 2, i.e. 24-bit color or 48-bit color. */
652
566
 
653
567
void
654
 
#ifdef _HAVE_PROTOS
655
568
_cgm_emit_color_component (plOutbuf *outbuf, bool no_partitioning, int cgm_encoding, unsigned int x, int data_len, int *data_byte_count, int *byte_count)
656
 
#else
657
 
_cgm_emit_color_component (outbuf, no_partitioning, cgm_encoding, x, data_len, data_byte_count, byte_count)
658
 
     plOutbuf *outbuf;
659
 
     bool no_partitioning;
660
 
     int cgm_encoding;
661
 
     unsigned int x;
662
 
     int data_len;
663
 
     int *data_byte_count, *byte_count;
664
 
#endif
665
569
{
666
570
  int i;
667
571
  unsigned char cgm_unsigned_int[CGM_BINARY_BYTES_PER_COLOR_COMPONENT];
670
574
    {
671
575
    case CGM_ENCODING_BINARY:
672
576
    default:
673
 
      _unsigned_int_to_cgm_unsigned_int (x, cgm_unsigned_int,
 
577
      unsigned_int_to_cgm_unsigned_int (x, cgm_unsigned_int,
674
578
                                         CGM_BINARY_BYTES_PER_COLOR_COMPONENT);
675
579
      for (i = 0; i < CGM_BINARY_BYTES_PER_COLOR_COMPONENT; i++)
676
580
        {
677
581
          if (no_partitioning == false
678
582
              && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
679
 
            _cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
 
583
            cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
680
584
          
681
585
          *(outbuf->point) = (char)(cgm_unsigned_int[i]);
682
586
          _update_buffer_by_added_bytes (outbuf, 1);
702
606
   encoding, a conventional representation is used. */
703
607
 
704
608
void
705
 
#ifdef _HAVE_PROTOS
706
609
_cgm_emit_real_fixed_point (plOutbuf *outbuf, bool no_partitioning, int cgm_encoding, double x, int data_len, int *data_byte_count, int *byte_count)
707
 
#else
708
 
_cgm_emit_real_fixed_point (outbuf, no_partitioning, cgm_encoding, x, data_len, data_byte_count, byte_count)
709
 
     plOutbuf *outbuf;
710
 
     bool no_partitioning;
711
 
     int cgm_encoding;
712
 
     double x;
713
 
     int data_len;
714
 
     int *data_byte_count, *byte_count;
715
 
#endif
716
610
{
717
611
  int x_floor;
718
612
  unsigned int x_frac;
732
626
    {
733
627
    case CGM_ENCODING_BINARY:
734
628
    default:
735
 
      _int_to_cgm_int (x_floor, cgm_int, 2);
 
629
      int_to_cgm_int (x_floor, cgm_int, 2);
736
630
      for (i = 0; i < 2; i++)
737
631
        {
738
632
          if (no_partitioning == false
739
633
              && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
740
 
            _cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
 
634
            cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
741
635
          
742
636
          *(outbuf->point) = (char)(cgm_int[i]);
743
637
          _update_buffer_by_added_bytes (outbuf, 1);
744
638
          (*data_byte_count)++;
745
639
          (*byte_count)++;
746
640
        }
747
 
      _unsigned_int_to_cgm_unsigned_int (x_frac, cgm_unsigned_int, 2);
 
641
      unsigned_int_to_cgm_unsigned_int (x_frac, cgm_unsigned_int, 2);
748
642
      for (i = 0; i < 2; i++)
749
643
        {
750
644
          if (no_partitioning == false
751
645
              && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
752
 
            _cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
 
646
            cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
753
647
          
754
648
          *(outbuf->point) = (char)(cgm_unsigned_int[i]);
755
649
          _update_buffer_by_added_bytes (outbuf, 1);
781
675
   unsigned chars to chars with impunity. */
782
676
 
783
677
static void
784
 
#ifdef _HAVE_PROTOS
785
 
_double_to_ieee_single_precision (double d, unsigned char output[4])
786
 
#else
787
 
_double_to_ieee_single_precision (d, output)
788
 
     double d;
789
 
     unsigned char output[4];
790
 
#endif
 
678
double_to_ieee_single_precision (double d, unsigned char output[4])
791
679
{
792
680
  double min_magnitude, max_magnitude, tmp_power, max_power;
793
681
  bool got_a_bit;
901
789
   factor' that is probably bogus.  See c_defplot.c. */
902
790
 
903
791
void
904
 
#ifdef _HAVE_PROTOS
905
792
_cgm_emit_real_floating_point (plOutbuf *outbuf, bool no_partitioning, int cgm_encoding, double x, int data_len, int *data_byte_count, int *byte_count)
906
 
#else
907
 
_cgm_emit_real_floating_point (outbuf, no_partitioning, cgm_encoding, x, data_len, data_byte_count, byte_count)
908
 
     plOutbuf *outbuf;
909
 
     bool no_partitioning;
910
 
     int cgm_encoding;
911
 
     double x;
912
 
     int data_len;
913
 
     int *data_byte_count, *byte_count;
914
 
#endif
915
793
{
916
794
  int i;
917
795
  unsigned char cp[4];
920
798
    {
921
799
    case CGM_ENCODING_BINARY:
922
800
    default:
923
 
      _double_to_ieee_single_precision (x, cp);
 
801
      double_to_ieee_single_precision (x, cp);
924
802
      for (i = 0; i < 4; i++)
925
803
        {
926
804
          if (no_partitioning == false
927
805
              && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
928
 
            _cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
 
806
            cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
929
807
          *(outbuf->point) = (char)(cp[i]);
930
808
          _update_buffer_by_added_bytes (outbuf, 1);
931
809
          (*data_byte_count)++;
963
841
   the `use_double_quotes' flag is set. */
964
842
 
965
843
void
966
 
#ifdef _HAVE_PROTOS
967
844
_cgm_emit_string (plOutbuf *outbuf, bool no_partitioning, int cgm_encoding, const char *s, int string_length, bool use_double_quotes, int data_len, int *data_byte_count, int *byte_count)
968
 
#else
969
 
_cgm_emit_string (outbuf, no_partitioning, cgm_encoding, s, string_length, use_double_quotes, data_len, data_byte_count, byte_count)
970
 
     plOutbuf *outbuf;
971
 
     bool no_partitioning;
972
 
     int cgm_encoding;
973
 
     const char *s;
974
 
     int string_length;
975
 
     bool use_double_quotes;
976
 
     int data_len;
977
 
     int *data_byte_count, *byte_count;
978
 
#endif
979
845
{
980
846
  int i, encoded_string_length;
981
847
  const char *sp = s;
996
862
        /* first, encode the string */
997
863
 
998
864
        encoded_string_length = CGM_BINARY_BYTES_PER_STRING(string_length);
999
 
        tp = t = (char *)_plot_xmalloc (encoded_string_length * sizeof(char));
 
865
        tp = t = (char *)_pl_xmalloc (encoded_string_length * sizeof(char));
1000
866
 
1001
867
        if (string_length <= 254)
1002
868
          {
1008
874
        else
1009
875
          {
1010
876
            /* first byte is `255' */
1011
 
            *tp++ = 255;
 
877
            *tp++ = (char)255;
1012
878
 
1013
879
            /* copy data bytes, with string partition headers interpolated
1014
880
               as needed; `i' counts data bytes copied */
1044
910
          {
1045
911
            if (no_partitioning == false
1046
912
                && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
1047
 
              _cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
 
913
              cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
1048
914
            *(outbuf->point) = t[i];
1049
915
            _update_buffer_by_added_bytes (outbuf, 1);
1050
916
            (*data_byte_count)++;
1064
930
        /* allocate space for encoded string, including initial and final
1065
931
           quotes, a space for readability, and a final NULL */
1066
932
        encoded_string_length = 2 * string_length + 3;
1067
 
        tp = t = (char *)_plot_xmalloc ((encoded_string_length + 1) * sizeof(char));
 
933
        tp = t = (char *)_pl_xmalloc ((encoded_string_length + 1) * sizeof(char));
1068
934
 
1069
935
        /* begin with a space for readability, and a quote */
1070
936
        *tp++ = ' ';
1095
961
   it does nothing.  In the clear text encoding it writes ";\n". */
1096
962
 
1097
963
void
1098
 
#ifdef _HAVE_PROTOS
1099
964
_cgm_emit_command_terminator (plOutbuf *outbuf, int cgm_encoding, int *byte_count)
1100
 
#else
1101
 
_cgm_emit_command_terminator (outbuf, cgm_encoding, byte_count)
1102
 
     plOutbuf *outbuf;
1103
 
     int cgm_encoding;
1104
 
     int *byte_count;
1105
 
#endif
1106
965
{
1107
966
  switch (cgm_encoding)
1108
967
    {