static int ref_param_begin_write_collection(gs_param_list * plist, gs_param_name pkey, gs_param_dict * pvalue, gs_param_collection_type_t coll_type) { iparam_list *const iplist = (iparam_list *) plist; gs_ref_memory_t *imem = iplist->ref_memory; dict_param_list *dlist = (dict_param_list *) gs_alloc_bytes(plist->memory, size_of(dict_param_list), "ref_param_begin_write_collection"); int code; if (dlist == 0) return_error(e_VMerror); if (coll_type != gs_param_collection_array) { ref dref; code = dict_alloc(imem, pvalue->size, &dref); if (code >= 0) { code = dict_param_list_write(dlist, &dref, NULL, imem); dlist->int_keys = coll_type == gs_param_collection_dict_int_keys; } } else { ref aref; code = gs_alloc_ref_array(imem, &aref, a_all, pvalue->size, "ref_param_begin_write_collection"); if (code >= 0) code = array_new_indexed_plist_write(dlist, &aref, NULL, imem); } if (code < 0) gs_free_object(plist->memory, dlist, "ref_param_begin_write_collection"); else pvalue->list = (gs_param_list *) dlist; return code; }
/* <dict> <string> .parse_dsc_comments <dict> <dsc code> */ static int zparse_dsc_comments(i_ctx_t *i_ctx_p) { #define MAX_DSC_MSG_SIZE (DSC_LINE_LENGTH + 4) /* Allow for %% and CR/LF */ os_ptr const opString = osp; os_ptr const opDict = opString - 1; uint ssize; int comment_code, code; char dsc_buffer[MAX_DSC_MSG_SIZE + 2]; const cmdlist_t *pCmdList = DSCcmdlist; const char * const *pBadList = BadCmdlist; ref * pvalue; CDSC * dsc_data = NULL; dict_param_list list; /* * Verify operand types and length of DSC comment string. If a comment * is too long then we simply truncate it. Russell's parser gets to * handle any errors that may result. (Crude handling but the comment * is bad, so ...). */ check_type(*opString, t_string); check_dict_write(*opDict); ssize = r_size(opString); if (ssize > MAX_DSC_MSG_SIZE) /* need room for EOL + \0 */ ssize = MAX_DSC_MSG_SIZE; /* * Pick up the comment string to be parsed. */ memcpy(dsc_buffer, opString->value.bytes, ssize); dsc_buffer[ssize] = 0x0d; /* Russell wants a 'line end' */ dsc_buffer[ssize + 1] = 0; /* Terminate string */ /* * Skip data block comments (see comments in front of BadCmdList). */ while (*pBadList && strncmp(*pBadList, dsc_buffer, strlen(*pBadList))) pBadList++; if (*pBadList) { /* If found in list, then skip comment */ comment_code = 0; /* Force NOP */ } else { /* * Parse comments - use Russell Lang's DSC parser. We need to get * data area for Russell Lang's parser. Note: We have saved the * location of the data area for the parser in our DSC dict. */ code = dict_find_string(opDict, dsc_dict_name, &pvalue); dsc_data = r_ptr(pvalue, dsc_data_t)->dsc_data_ptr; if (code < 0) return code; comment_code = dsc_scan_data(dsc_data, dsc_buffer, ssize + 1); if_debug1('%', "[%%].parse_dsc_comments: code = %d\n", comment_code); /* * We ignore any errors from Russell's parser. The only value that * it will return for an error is -1 so there is very little information. * We also do not want bad DSC comments to abort processing of an * otherwise valid PS file. */ if (comment_code < 0) comment_code = 0; } /* * Transfer data from DSC structure to postscript variables. * Look up proper handler in the local cmd decode list. */ while (pCmdList->code && pCmdList->code != comment_code ) pCmdList++; if (pCmdList->dsc_proc) { code = dict_param_list_write(&list, opDict, NULL, iimemory); if (code < 0) return code; code = (pCmdList->dsc_proc)((gs_param_list *)&list, dsc_data); iparam_list_release(&list); if (code < 0) return code; } /* Put DSC comment name onto operand stack (replace string). */ return name_enter_string(imemory, pCmdList->comment_name, opString); }