int ztoken(i_ctx_t *i_ctx_p) { os_ptr op = osp; switch (r_type(op)) { default: return_op_typecheck(op); case t_file: { stream *s; scanner_state state; check_read_file(i_ctx_p, s, op); check_ostack(1); gs_scanner_init(&state, op); return token_continue(i_ctx_p, &state, true); } case t_string: { ref token; /* -1 is to remove the string operand in case of error. */ int orig_ostack_depth = ref_stack_count(&o_stack) - 1; int code; /* Don't pop the operand in case of invalidaccess. */ if (!r_has_attr(op, a_read)) return_error(e_invalidaccess); code = gs_scan_string_token(i_ctx_p, op, &token); switch (code) { case scan_EOF: /* no tokens */ make_false(op); return 0; default: if (code < 0) { /* * Clear anything that may have been left on the ostack, * including the string operand. */ if (orig_ostack_depth < ref_stack_count(&o_stack)) pop(ref_stack_count(&o_stack)- orig_ostack_depth); return code; } } push(2); op[-1] = token; make_true(op); return 0; } } }
/* <string> cvi <int> */ int zcvi(i_ctx_t *i_ctx_p) { os_ptr op = osp; float fval; switch (r_type(op)) { case t_integer: return 0; case t_real: fval = op->value.realval; break; default: return_op_typecheck(op); case t_string: { ref str, token; int code; ref_assign(&str, op); code = gs_scan_string_token(i_ctx_p, &str, &token); if (code > 0) /* anything other than a plain token */ code = gs_note_error(e_syntaxerror); if (code < 0) return code; switch (r_type(&token)) { case t_integer: *op = token; return 0; case t_real: fval = token.value.realval; break; default: return_error(e_typecheck); } } } if (!REAL_CAN_BE_INT(fval)) return_error(e_rangecheck); make_int(op, (long)fval); /* truncates towards 0 */ return 0; }
/* <string> cvr <real> */ int zcvr(i_ctx_t *i_ctx_p) { os_ptr op = osp; switch (r_type(op)) { case t_integer: make_real(op, (float)op->value.intval); case t_real: return 0; default: return_op_typecheck(op); case t_string: { ref str, token; int code; ref_assign(&str, op); code = gs_scan_string_token(i_ctx_p, &str, &token); if (code > 0) /* anything other than a plain token */ code = gs_note_error(e_syntaxerror); if (code < 0) return code; switch (r_type(&token)) { case t_integer: make_real(op, (float)token.value.intval); return 0; case t_real: *op = token; return 0; default: return_error(e_typecheck); } } } }