/* TRANSLATE -- Interpret input SGI Raster File format into Hewlett Packard * Raster graphics instructions and write to stdout. */ static void translate (FILE *in, FILE *out) { int n1, swap_bytes; int n, nlines, length, len_buf; register unsigned char *bp1, *buffer1; char buf_rast [SZ_RAST]; swap_bytes = isSwapped (); len_buf = dev_width / NBITS_CHAR; buffer1 = (unsigned char *)malloc (len_buf); /* Output device initialization. */ fwrite (xyencode (dev_left, dev_bottom), SZ_VECT, 1, out); fwrite (DEV_INIT, strlen(DEV_INIT), 1, out); /* Process the raster file */ nlines = dev_height; while ((n = fread (buffer1, len_buf, 1, in)) > 0) { if (swap_bytes) bswap2 (buffer1, buffer1, len_buf); /* Keep track of number of lines left on the page. */ if (!(nlines--)) { nlines += dev_height; fwrite (DEV_END, strlen (DEV_END), 1, out); fwrite (xyencode (dev_left, dev_bottom), SZ_VECT, 1, out); fwrite (DEV_INIT, strlen (DEV_INIT), 1, out); } /* Search for trailing null bytes to trim them off. */ length = len_buf; for (bp1 = buffer1+length; length && *(--bp1) == 0; length--) ; n1 = length; if (n1 == 0) { n1 = 1; *buffer1 = 0; } /* Now copy out this line and prefix it with the control codes. */ sprintf (buf_rast, DEV_RAST, n1); fwrite (buf_rast, SZ_RAST, 1, out); fwrite (buffer1, n1, 1, out); } /* Terminate plotting and exit. */ fwrite (DEV_END, strlen(DEV_END), 1, out); }
void decode_smallint(pTHX_ unsigned char *input, STRLEN len, struct cc_type *type, SV *output) { union { unsigned char bytes[2]; int16_t i; } bytes_or_smallint; if (UNLIKELY(len != 2)) croak("decode_smallint: len != 2"); memcpy(bytes_or_smallint.bytes, input, 2); bswap2(bytes_or_smallint.bytes); sv_setiv(output, bytes_or_smallint.i); }