123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987 |
- #include "sys-defines.h"
- #include "extern.h"
- #define CGM_BINARY_DATA_BYTES_PER_PARTITION 3000
- #define CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count) \
- (((data_len) > 30) && ((*(data_byte_count)) % CGM_BINARY_DATA_BYTES_PER_PARTITION == 0))
- static void cgm_emit_partition_control_word (plOutbuf *outbuf, int data_len, const int *data_byte_count, int *byte_count);
- static void double_to_ieee_single_precision (double d, unsigned char output[4]);
- static void int_to_cgm_int (int n, unsigned char *cgm_int, int octets_per_cgm_int);
- static void unsigned_int_to_cgm_unsigned_int (unsigned int n, unsigned char *cgm_unsigned_int, int octets_per_cgm_unsigned_int);
- void
- _cgm_emit_command_header (plOutbuf *outbuf, int cgm_encoding, int element_class, int id, int data_len, int *byte_count, const char *op_code)
- {
- switch (cgm_encoding)
- {
- case CGM_ENCODING_BINARY:
- default:
- {
- int temp;
-
- if (data_len > 30)
- data_len = 31;
- temp = (element_class & 017) << 4;
- temp |= (id >> 3) & 017;
- outbuf->point[0] = (char)(unsigned char)temp;
- temp = (id & 0177) << 5;
- temp |= (data_len & 037);
- outbuf->point[1] = (char)(unsigned char)temp;
- _update_buffer_by_added_bytes (outbuf, 2);
- (*byte_count) += 2;
- }
- break;
- case CGM_ENCODING_CHARACTER:
- break;
- case CGM_ENCODING_CLEAR_TEXT:
- sprintf (outbuf->point, "%s", op_code);
- _update_buffer (outbuf);
- break;
- }
- }
- static void
- cgm_emit_partition_control_word (plOutbuf *outbuf, int data_len, const int *data_byte_count, int *byte_count)
- {
- int bytes_remaining = data_len - (*data_byte_count);
- int bytes_in_partition;
- unsigned int control_word;
- if (bytes_remaining > CGM_BINARY_DATA_BYTES_PER_PARTITION)
- {
- bytes_in_partition = CGM_BINARY_DATA_BYTES_PER_PARTITION;
- control_word = 1 << 15;
- }
- else
- {
- bytes_in_partition = bytes_remaining;
- control_word = 0;
- }
- control_word |= (unsigned int)bytes_in_partition;
-
- outbuf->point[0] = (char)(unsigned char)((control_word >> 8) & 0377);
- outbuf->point[1] = (char)(unsigned char)(control_word & 0377);
- _update_buffer_by_added_bytes (outbuf, 2);
- (*byte_count) += 2;
- }
- static void
- int_to_cgm_int (int n, unsigned char *cgm_int, int octets_per_cgm_int)
- {
- int max_int, i;
- unsigned int u;
- bool negative = false;
-
- max_int = 0;
- for (i = 0; i < (8 * octets_per_cgm_int - 1); i++)
- max_int += (1 << i);
- if (n > max_int)
- n = max_int;
- else if (n < -max_int)
- n = -max_int;
-
- if (n < 0)
- {
- int temp;
- negative = true;
- temp = -(n + 1);
- u = (unsigned int)(max_int - temp);
- }
- else
- u = (unsigned int)n;
-
- for (i = 0; i < octets_per_cgm_int; i++)
- {
- unsigned char v;
- v = 0xff & (u >> (8 * ((octets_per_cgm_int - 1) - i)));
- if (i == 0 && negative)
- v |= 0x80;
- cgm_int[i] = v;
- }
- }
- static void
- unsigned_int_to_cgm_unsigned_int (unsigned int n, unsigned char *cgm_unsigned_int, int octets_per_cgm_unsigned_int)
- {
- unsigned int max_unsigned_int;
- int i;
-
- max_unsigned_int = 0;
- for (i = 0; i < (8 * octets_per_cgm_unsigned_int); i++)
- max_unsigned_int += (1 << i);
- if (n > max_unsigned_int)
- n = max_unsigned_int;
-
- for (i = 0; i < octets_per_cgm_unsigned_int; i++)
- {
- unsigned char v;
- v = 0xff & (n >> (8 * ((octets_per_cgm_unsigned_int - 1) - i)));
- cgm_unsigned_int[i] = v;
- }
- }
- void
- _cgm_emit_integer (plOutbuf *outbuf, bool no_partitioning, int cgm_encoding, int x, int data_len, int *data_byte_count, int *byte_count)
- {
- int i;
- unsigned char cgm_int[CGM_BINARY_BYTES_PER_INTEGER];
- switch (cgm_encoding)
- {
- case CGM_ENCODING_BINARY:
- default:
- int_to_cgm_int (x, cgm_int, CGM_BINARY_BYTES_PER_INTEGER);
- for (i = 0; i < CGM_BINARY_BYTES_PER_INTEGER; i++)
- {
- if (no_partitioning == false
- && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
- cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
-
- *(outbuf->point) = (char)(cgm_int[i]);
- _update_buffer_by_added_bytes (outbuf, 1);
- (*data_byte_count)++;
- (*byte_count)++;
- }
- break;
- case CGM_ENCODING_CHARACTER:
- break;
- case CGM_ENCODING_CLEAR_TEXT:
- sprintf (outbuf->point, " %d", x);
- _update_buffer (outbuf);
- break;
- }
- }
- void
- _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)
- {
- int i;
- unsigned char cgm_unsigned_int[CGM_BINARY_BYTES_PER_INTEGER];
- switch (cgm_encoding)
- {
- case CGM_ENCODING_BINARY:
- default:
- unsigned_int_to_cgm_unsigned_int (x, cgm_unsigned_int, CGM_BINARY_BYTES_PER_INTEGER);
- for (i = 0; i < CGM_BINARY_BYTES_PER_INTEGER; i++)
- {
- if (no_partitioning == false
- && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
- cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
-
- *(outbuf->point) = (char)(cgm_unsigned_int[i]);
- _update_buffer_by_added_bytes (outbuf, 1);
- (*data_byte_count)++;
- (*byte_count)++;
- }
- break;
- case CGM_ENCODING_CHARACTER:
- break;
- case CGM_ENCODING_CLEAR_TEXT:
- sprintf (outbuf->point, " %u", x);
- _update_buffer (outbuf);
- break;
- }
- }
- void
- _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)
- {
-
- if (x > (unsigned int)255)
- x = (unsigned int)255;
- switch (cgm_encoding)
- {
- case CGM_ENCODING_BINARY:
- default:
- if (no_partitioning == false
- && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
- cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
-
- *(outbuf->point) = (char)(unsigned char)x;
- _update_buffer_by_added_bytes (outbuf, 1);
- (*data_byte_count)++;
- (*byte_count)++;
- break;
- case CGM_ENCODING_CHARACTER:
- break;
- case CGM_ENCODING_CLEAR_TEXT:
- sprintf (outbuf->point, " %u", x);
- _update_buffer (outbuf);
- break;
- }
- }
- void
- _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)
- {
- int i;
- unsigned char cgm_int[CGM_BINARY_BYTES_PER_INTEGER];
- switch (cgm_encoding)
- {
- case CGM_ENCODING_BINARY:
- default:
- int_to_cgm_int (x, cgm_int, CGM_BINARY_BYTES_PER_INTEGER);
- for (i = 0; i < CGM_BINARY_BYTES_PER_INTEGER; i++)
- {
- if (no_partitioning == false
- && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
- cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
-
- *(outbuf->point) = (char)(cgm_int[i]);
- _update_buffer_by_added_bytes (outbuf, 1);
- (*data_byte_count)++;
- (*byte_count)++;
- }
- int_to_cgm_int (y, cgm_int, CGM_BINARY_BYTES_PER_INTEGER);
- for (i = 0; i < CGM_BINARY_BYTES_PER_INTEGER; i++)
- {
- if (no_partitioning == false
- && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
- cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
-
- *(outbuf->point) = (char)(cgm_int[i]);
- _update_buffer_by_added_bytes (outbuf, 1);
- (*data_byte_count)++;
- (*byte_count)++;
- }
- break;
- case CGM_ENCODING_CHARACTER:
- break;
- case CGM_ENCODING_CLEAR_TEXT:
- sprintf (outbuf->point, " (%d, %d)", x, y);
- _update_buffer (outbuf);
- break;
- }
- }
- void
- _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)
- {
- int i, j;
- unsigned char cgm_int[CGM_BINARY_BYTES_PER_INTEGER];
- switch (cgm_encoding)
- {
- case CGM_ENCODING_BINARY:
- default:
- for (j = 0; j < npoints; j++)
- {
- int_to_cgm_int (x[j], cgm_int, CGM_BINARY_BYTES_PER_INTEGER);
- for (i = 0; i < CGM_BINARY_BYTES_PER_INTEGER; i++)
- {
- if (no_partitioning == false
- && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
- cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
-
- *(outbuf->point) = (char)(cgm_int[i]);
- _update_buffer_by_added_bytes (outbuf, 1);
- (*data_byte_count)++;
- (*byte_count)++;
- }
- int_to_cgm_int (y[j], cgm_int, CGM_BINARY_BYTES_PER_INTEGER);
- for (i = 0; i < CGM_BINARY_BYTES_PER_INTEGER; i++)
- {
- if (no_partitioning == false
- && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
- cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
-
- *(outbuf->point) = (char)(cgm_int[i]);
- _update_buffer_by_added_bytes (outbuf, 1);
- (*data_byte_count)++;
- (*byte_count)++;
- }
- }
- break;
- case CGM_ENCODING_CHARACTER:
- break;
-
- case CGM_ENCODING_CLEAR_TEXT:
- for (i = 0; i < npoints; i++)
- {
- sprintf (outbuf->point, " (%d, %d)", x[i], y[i]);
- _update_buffer (outbuf);
- }
- break;
- }
- }
- void
- _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)
- {
- int i;
- unsigned char cgm_int[2];
- switch (cgm_encoding)
- {
- case CGM_ENCODING_BINARY:
- default:
- int_to_cgm_int (x, cgm_int, 2);
- for (i = 0; i < 2; i++)
- {
- if (no_partitioning == false
- && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
- cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
-
- *(outbuf->point) = (char)(cgm_int[i]);
- _update_buffer_by_added_bytes (outbuf, 1);
- (*data_byte_count)++;
- (*byte_count)++;
- }
- break;
- case CGM_ENCODING_CHARACTER:
- break;
- case CGM_ENCODING_CLEAR_TEXT:
- sprintf (outbuf->point, " %s", text_string);
- _update_buffer (outbuf);
- break;
- }
- }
- void
- _cgm_emit_index (plOutbuf *outbuf, bool no_partitioning, int cgm_encoding, int x, int data_len, int *data_byte_count, int *byte_count)
- {
- int i;
- unsigned char cgm_int[2];
- switch (cgm_encoding)
- {
- case CGM_ENCODING_BINARY:
- default:
- int_to_cgm_int (x, cgm_int, 2);
- for (i = 0; i < 2; i++)
- {
- if (no_partitioning == false
- && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
- cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
-
- *(outbuf->point) = (char)(cgm_int[i]);
- _update_buffer_by_added_bytes (outbuf, 1);
- (*data_byte_count)++;
- (*byte_count)++;
- }
- break;
- case CGM_ENCODING_CHARACTER:
- break;
- case CGM_ENCODING_CLEAR_TEXT:
- sprintf (outbuf->point, " %d", x);
- _update_buffer (outbuf);
- break;
- }
- }
- void
- _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)
- {
- int i;
- unsigned char cgm_unsigned_int[CGM_BINARY_BYTES_PER_COLOR_COMPONENT];
- switch (cgm_encoding)
- {
- case CGM_ENCODING_BINARY:
- default:
- unsigned_int_to_cgm_unsigned_int (x, cgm_unsigned_int,
- CGM_BINARY_BYTES_PER_COLOR_COMPONENT);
- for (i = 0; i < CGM_BINARY_BYTES_PER_COLOR_COMPONENT; i++)
- {
- if (no_partitioning == false
- && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
- cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
-
- *(outbuf->point) = (char)(cgm_unsigned_int[i]);
- _update_buffer_by_added_bytes (outbuf, 1);
- (*data_byte_count)++;
- (*byte_count)++;
- }
- break;
- case CGM_ENCODING_CHARACTER:
- break;
- case CGM_ENCODING_CLEAR_TEXT:
- sprintf (outbuf->point, " %u", x);
- _update_buffer (outbuf);
- break;
- }
- }
- void
- _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)
- {
- int x_floor;
- unsigned int x_frac;
- int i;
- unsigned char cgm_int[2], cgm_unsigned_int[2];
-
- if (x < -32767.0)
- x = -32767.0;
- else if (x > 32767.0)
- x = 32767.0;
- x_floor = (x >= 0.0 ? (int)x : -1 - ((int)(-x)));
- x_frac = (unsigned int)(65536 * (x - x_floor));
- switch (cgm_encoding)
- {
- case CGM_ENCODING_BINARY:
- default:
- int_to_cgm_int (x_floor, cgm_int, 2);
- for (i = 0; i < 2; i++)
- {
- if (no_partitioning == false
- && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
- cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
-
- *(outbuf->point) = (char)(cgm_int[i]);
- _update_buffer_by_added_bytes (outbuf, 1);
- (*data_byte_count)++;
- (*byte_count)++;
- }
- unsigned_int_to_cgm_unsigned_int (x_frac, cgm_unsigned_int, 2);
- for (i = 0; i < 2; i++)
- {
- if (no_partitioning == false
- && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
- cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
-
- *(outbuf->point) = (char)(cgm_unsigned_int[i]);
- _update_buffer_by_added_bytes (outbuf, 1);
- (*data_byte_count)++;
- (*byte_count)++;
- }
- break;
- case CGM_ENCODING_CHARACTER:
- break;
- case CGM_ENCODING_CLEAR_TEXT:
- if (x != 0.0)
- sprintf (outbuf->point, " %.8f", x);
- else
- sprintf (outbuf->point, " 0.0");
- _update_buffer (outbuf);
- break;
- }
- }
- static void
- double_to_ieee_single_precision (double d, unsigned char output[4])
- {
- double min_magnitude, max_magnitude, tmp_power, max_power;
- bool got_a_bit;
- int i, j;
- int sign_bit;
- int mantissa_bits[23];
- int exponent_bits[8];
- int biased_exponent = 0;
- int bits[256];
- int output_bits[32];
-
-
-
- min_magnitude = 1.0;
- for (i = 0; i < 127-1; i++)
- min_magnitude /= 2;
-
- tmp_power = 1.0;
- max_magnitude = 0.0;
- for (i = 0; i <= 254-127; i++)
- {
- if (i >= 104)
- max_magnitude += tmp_power;
- tmp_power *= 2;
- }
-
-
- if (d != d)
- d = max_magnitude;
-
-
- if (d < 0.0)
- {
- sign_bit = 1;
- d = -d;
- }
- else
- sign_bit = 0;
-
- if (d != 0.0 && d < min_magnitude)
- d = min_magnitude;
- else if (d > max_magnitude)
- d = max_magnitude;
-
-
- max_power = 1.0;
- for (i = 0; i < 254-127; i++)
- max_power *= 2;
-
- for (i = 0; i < 256; i++)
- bits[i] = 0;
- got_a_bit = false;
- for (i = 254, tmp_power = max_power; i >= 1; i--, tmp_power /= 2)
- if (d >= tmp_power)
- {
- if (got_a_bit == false)
- {
- biased_exponent = i;
- got_a_bit = true;
- }
- bits[i] = 1;
- d -= tmp_power;
- }
- if (got_a_bit == false)
-
- biased_exponent = 0;
-
-
- for (j = 0; j < 23; j++)
- mantissa_bits[j] = 0;
- if (got_a_bit == true)
- for (i = biased_exponent - 1, j = 0; i >= 1 && j < 23; i--, j++)
- mantissa_bits[j] = bits[i];
-
-
- for (j = 7; j >= 0; j--)
- {
- exponent_bits[j] = biased_exponent % 2;
- biased_exponent /= 2;
- }
-
- output_bits[0] = sign_bit;
- for (j = 0; j < 8; j++)
- output_bits[j + 1] = exponent_bits[j];
- for (j = 0; j < 23; j++)
- output_bits[j + 9] = mantissa_bits[j];
-
- for (j = 0; j < 4; j++)
- output[j] = (unsigned char)0;
- for (j = 0; j < 32; j++)
- if (output_bits[j] == 1)
- output[j / 8] |= (1 << ((31 - j) % 8));
- }
- void
- _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)
- {
- int i;
- unsigned char cp[4];
- switch (cgm_encoding)
- {
- case CGM_ENCODING_BINARY:
- default:
- double_to_ieee_single_precision (x, cp);
- for (i = 0; i < 4; i++)
- {
- if (no_partitioning == false
- && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
- cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
- *(outbuf->point) = (char)(cp[i]);
- _update_buffer_by_added_bytes (outbuf, 1);
- (*data_byte_count)++;
- (*byte_count)++;
- }
- break;
- case CGM_ENCODING_CHARACTER:
- break;
- case CGM_ENCODING_CLEAR_TEXT:
- sprintf (outbuf->point, " %.8f", x);
- _update_buffer (outbuf);
- break;
- }
- }
- void
- _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)
- {
- int i, encoded_string_length;
- const char *sp = s;
- char *t, *tp, c;
-
- switch (cgm_encoding)
- {
- case CGM_ENCODING_BINARY:
- default:
- {
- #if 0
- fprintf (stderr, "cgm_emit_string(), length=%d\n", string_length);
- for (i = 0; i < string_length; i++)
- putc (s[i], stderr);
- putc ('\n', stderr);
- #endif
-
-
- encoded_string_length = CGM_BINARY_BYTES_PER_STRING(string_length);
- tp = t = (char *)_pl_xmalloc (encoded_string_length * sizeof(char));
- if (string_length <= 254)
- {
-
- *tp++ = (char)(unsigned char)string_length;
- for (i = 0; i < string_length; i++)
- *tp++ = *sp++;
- }
- else
- {
-
- *tp++ = (char)255;
-
- for (i = 0; i < string_length; i++, sp++)
- {
- if (i % CGM_STRING_PARTITION_SIZE == 0)
-
- {
- int bytes_remaining = string_length - i;
- int string_header_word;
- if (bytes_remaining <= CGM_STRING_PARTITION_SIZE)
- string_header_word = bytes_remaining;
- else
-
- {
- string_header_word = (1 << 15);
- string_header_word |= CGM_STRING_PARTITION_SIZE;
- }
-
- *tp++ = (char)((string_header_word >> 8) & 0377);
- *tp++ = (char)(string_header_word & 0377);
- }
-
- *tp++ = *sp;
- }
- }
-
- for (i = 0; i < encoded_string_length; i++)
- {
- if (no_partitioning == false
- && CGM_BINARY_DATA_PARTITION_BEGINS(data_len, data_byte_count))
- cgm_emit_partition_control_word (outbuf, data_len, data_byte_count, byte_count);
- *(outbuf->point) = t[i];
- _update_buffer_by_added_bytes (outbuf, 1);
- (*data_byte_count)++;
- (*byte_count)++;
- }
-
-
- free (t);
- }
- break;
- case CGM_ENCODING_CHARACTER:
- break;
- case CGM_ENCODING_CLEAR_TEXT:
- {
-
- encoded_string_length = 2 * string_length + 3;
- tp = t = (char *)_pl_xmalloc ((encoded_string_length + 1) * sizeof(char));
-
- *tp++ = ' ';
- *tp++ = (use_double_quotes ? '"' : '\'');
- while ((c = *sp++) != '\0')
- {
-
- if (((use_double_quotes == true) && c == '"')
- || ((use_double_quotes == false) && c == '\''))
- *tp++ = c;
- *tp++ = c;
- }
-
- *tp++ = (use_double_quotes ? '"' : '\'');
- *tp++ = '\0';
- strcpy (outbuf->point, t);
- _update_buffer (outbuf);
- free (t);
- }
- break;
- }
- }
- void
- _cgm_emit_command_terminator (plOutbuf *outbuf, int cgm_encoding, int *byte_count)
- {
- switch (cgm_encoding)
- {
- case CGM_ENCODING_BINARY:
- default:
- if ((*byte_count) % 2 == 1)
- {
- *(outbuf->point) = '\0';
- _update_buffer_by_added_bytes (outbuf, 1);
- (*byte_count)++;
- }
- break;
- case CGM_ENCODING_CHARACTER:
- break;
- case CGM_ENCODING_CLEAR_TEXT:
- strcpy (outbuf->point, ";\n");
- _update_buffer (outbuf);
- break;
- }
- }
|