static int zwritecvp_at(i_ctx_t *i_ctx_p, os_ptr op, uint start, bool first) { stream *s; byte str[100]; /* arbitrary */ ref rstr; const byte *data = str; uint len; int code, status; check_write_file(s, op - 2); check_type(*op, t_integer); code = obj_cvp(op - 1, str, sizeof(str), &len, (int)op->value.intval, start, imemory, true); if (code == e_rangecheck) { code = obj_string_data(imemory, op - 1, &data, &len); if (len < start) return_error(e_rangecheck); data += start; len -= start; } if (code < 0) return code; r_set_size(&rstr, len); rstr.value.const_bytes = data; status = write_string(&rstr, s); switch (status) { default: return_error(e_ioerror); case 0: break; case INTC: case CALLC: len = start + len - r_size(&rstr); if (!first) --osp; /* pop(1) without affecting op */ return handle_write_status(i_ctx_p, status, op - 2, &len, zwritecvp_continue); } if (code == 1) { if (first) check_ostack(1); push_op_estack(zwritecvp_continue); if (first) push(1); make_int(osp, start + len); return o_push_estack; } if (first) /* zwritecvp */ pop(3); else /* zwritecvp_continue */ pop(4); return 0; }
static int zwritehexstring_at(i_ctx_t *i_ctx_p, os_ptr op, uint odd) { register stream *s; register byte ch; register const byte *p; register const char *const hex_digits = "0123456789abcdef"; register uint len; int status; #define MAX_HEX 128 byte buf[MAX_HEX]; check_write_file(s, op - 1); check_read_type(*op, t_string); p = op->value.bytes; len = r_size(op); while (len) { uint len1 = min(len, MAX_HEX / 2); register byte *q = buf; uint count = len1; ref rbuf; do { ch = *p++; *q++ = hex_digits[ch >> 4]; *q++ = hex_digits[ch & 0xf]; } while (--count); r_set_size(&rbuf, (len1 << 1) - odd); rbuf.value.bytes = buf + odd; status = write_string(&rbuf, s); switch (status) { default: return_error(e_ioerror); case 0: len -= len1; odd = 0; continue; case INTC: case CALLC: count = rbuf.value.bytes - buf; op->value.bytes += count >> 1; r_set_size(op, len - (count >> 1)); count &= 1; return handle_write_status(i_ctx_p, status, op - 1, &count, zwritehexstring_continue); } } pop(2); return 0; #undef MAX_HEX }
/* <file> <string> writestring - */ static int zwritestring(i_ctx_t *i_ctx_p) { os_ptr op = osp; stream *s; int status; check_write_file(s, op - 1); check_read_type(*op, t_string); status = write_string(op, s); if (status >= 0) { pop(2); return 0; } return handle_write_status(i_ctx_p, status, op - 1, NULL, zwritestring); }
/* <file> <int> write - */ int zwrite(i_ctx_t *i_ctx_p) { os_ptr op = osp; stream *s; byte ch; int status; check_write_file(s, op - 1); check_type(*op, t_integer); ch = (byte) op->value.intval; status = sputc(s, (byte) ch); if (status >= 0) { pop(2); return 0; } return handle_write_status(i_ctx_p, status, op - 1, NULL, zwrite); }
static int zwritecmap(i_ctx_t *i_ctx_p) { os_ptr op = osp; ref *pcodemap; gs_cmap_t *pcmap; int code; stream *s; check_type(*op, t_dictionary); if (dict_find_string(op, "CodeMap", &pcodemap) <= 0 || !r_is_struct(pcodemap) ) return_error(e_typecheck); check_write_file(s, op - 1); pcmap = r_ptr(pcodemap, gs_cmap_t); code = psf_write_cmap(s, pcmap, zfcmap_put_name_default, NULL, -1); if (code >= 0) pop(2); return code; }
/* <file> <cid9font> .writefont9 - */ static int zwritefont9(i_ctx_t *i_ctx_p) { os_ptr op = osp; gs_font *pfont; gs_font_cid0 *pfcid; int code = font_param(op, &pfont); stream *s; if (code < 0) return code; if (pfont->FontType != ft_CID_encrypted) return_error(e_invalidfont); check_write_file(s, op - 1); pfcid = (gs_font_cid0 *)pfont; code = psf_write_cid0_font(s, pfcid, WRITE_TYPE2_NO_LENIV | WRITE_TYPE2_CHARSTRINGS, NULL, 0, NULL); if (code >= 0) pop(2); return code; }