void pdf_add_pdflib_resource(PDF *p, const char *category, const char *resname) { char *newresname; int newlen; pdc_encoding htenc; int htcp; pdf_prepare_name_string(p, resname, 0, PDC_FILENAMELEN, &newresname, &newlen, &htenc, &htcp); if (newlen) { char *tmpresname = pdc_utf16_to_utf8(p->pdc, newresname, newlen, PDC_CONV_EBCDIC | PDC_CONV_WITHBOM, &newlen); pdc_free(p->pdc, newresname); newresname = tmpresname; newlen = 0; } pdc_add_resource_ext(p->pdc, category, newresname, NULL, htenc, htcp); if (newresname != resname) pdc_free(p->pdc, newresname); }
/* Free outline entries */ void pdf_cleanup_outlines(PDF *p) { int i; if (!p->outlines || p->outline_count == 0) return; /* outlines[0] is the outline root object */ for (i = 0; i <= p->outline_count; i++) { if (p->outlines[i].text) { pdc_free(p->pdc, p->outlines[i].text); p->outlines[i].text = NULL; } if (p->outlines[i].action) { pdc_free(p->pdc, p->outlines[i].action); p->outlines[i].action = NULL; } pdf_cleanup_destination(p, p->outlines[i].dest); p->outlines[i].dest = NULL; } pdc_free(p->pdc, (void*) p->outlines); p->outlines = NULL; }
void pdc_fclose(pdc_file *sfp) { if (sfp) { if (sfp->fp) { pdc_fclose_logg(sfp->pdc, sfp->fp); sfp->fp = NULL; } else if (sfp->wrmode) { if (sfp->data) { pdc_free(sfp->pdc, sfp->data); sfp->data = NULL; } } if (sfp->filename) { pdc_free(sfp->pdc, sfp->filename); sfp->filename = NULL; } pdc_free(sfp->pdc, sfp); } }
int pdf__delete_pvf(PDF *p, const char *filename, int reserved) { pdf_virtfile *vfile, *lastvfile = NULL; (void) reserved; /* Find virtual file in file system */ vfile = pdf_find_pvf(p, filename, &lastvfile); if (vfile) { /* File exists but locked */ if (vfile->lockcount > 0) { return pdc_undef; } /* Delete */ if (vfile->iscopy == pdc_true) { pdc_free(p->pdc, (void *) vfile->data); vfile->data = NULL; } pdc_free(p->pdc, vfile->name); if (lastvfile) lastvfile->next = vfile->next; else p->filesystem = vfile->next; pdc_free(p->pdc, vfile); } return pdc_true; }
static void fnt_cleanup_font_metric(pdc_core *pdc, fnt_font_metric *metric) { if (metric->name != NULL) { pdc_free(pdc, metric->name); metric->name = NULL; } if (metric->widths != NULL) { pdc_free(pdc, metric->widths); metric->widths = NULL; } if (metric->ciw != NULL) { pdc_free(pdc, metric->ciw); metric->ciw = NULL; } if (metric->glw != NULL) { pdc_free(pdc, metric->glw); metric->glw = NULL; } }
static void pdc_delete_optvalue(pdc_core *pdc, pdc_resopt *resopt) { if (resopt->val && !(resopt->flags & PDC_OPT_SAVEALL)) { int j; int ja = (resopt->flags & PDC_OPT_SAVE1ELEM) ? 1 : 0; if (resopt->defopt->type == pdc_stringlist) { char **s = (char **) resopt->val; for (j = ja; j < resopt->num; j++) if (s[j] != NULL) pdc_free(pdc, s[j]); } else if (resopt->defopt->type == pdc_polylinelist) { pdc_polyline *pl = (pdc_polyline *) resopt->val; for (j = ja; j < resopt->num; j++) if (pl[j].p != NULL) pdc_free(pdc, pl[j].p); } pdc_free(pdc, resopt->val); resopt->val = NULL; } if (resopt->origval && !(resopt->flags & PDC_OPT_SAVEORIG)) { pdc_free(pdc, resopt->origval); resopt->origval = NULL; } resopt->num = 0; }
void pdc_cleanup_optstringlist(pdc_core *pdc, char **stringlist, int ns) { int j; for (j = 0; j < ns; j++) { if (stringlist[j] != NULL) pdc_free(pdc, stringlist[j]); } pdc_free(pdc, stringlist); }
void * pdc_delete_polylinelist(pdc_core *pdc, pdc_polyline *polylinelist, int nplines) { int i; if (polylinelist != NULL) { for (i = 0; i < nplines; i++) pdc_free(pdc, polylinelist[i].p); pdc_free(pdc, polylinelist); } return NULL; }
void fnt_cleanup_fontimg(pdc_core *pdc, fnt_font *font) { if (font->img != NULL && font->imgname == NULL) { pdc_free(pdc, font->img); font->img = NULL; } if (font->imgname != NULL) { pdc_free(pdc, font->imgname); font->imgname = NULL; } }
/* * pdc_convert_filename_ext converts a file name as string of name type * (see function pdc_convert_name) to a [EBCDIC-]UTF-8 string with or * without a BOM. If the compiler doesn't allow Unicode filenames * (see define PDC_UNICODE_FILENAME) the filename is Latin-1 encoded * if possible or an exception will be thrown. * */ const char * pdc_convert_filename_ext(pdc_core *pdc, const char *filename, int len, const char *paramname, pdc_encoding enc, int codepage, int flags) { char *fname = NULL; const char *outfilename = NULL; int i = 0; if (filename == NULL) pdc_error(pdc, PDC_E_ILLARG_EMPTY, paramname, 0, 0, 0); fname = pdc_convert_name_ext(pdc, filename, len, enc, codepage, flags); if (fname == NULL || *fname == '\0') pdc_error(pdc, PDC_E_ILLARG_EMPTY, paramname, 0, 0, 0); if (pdc_is_utf8_bytecode(fname)) { #if defined(PDC_UNICODE_FILENAME) i = 3; #else fname = pdc_check_filename(pdc, fname); #endif } outfilename = pdc_errprintf(pdc, "%s", &fname[i]); pdc_free(pdc, fname); return outfilename; }
void * pdc_read_file(pdc_core *pdc, FILE *fp, pdc_off_t *o_filelen, int incore) { static const char fn[] = "pdc_read_file"; pdc_off_t filelen = 0, len = 0; char *content = NULL; #if !defined(MVS) || !defined(I370) pdc__fseek(fp, 0, SEEK_END); filelen = pdc__ftell(fp); pdc__fseek(fp, 0, SEEK_SET); if (incore && filelen) { content = (char *) pdc_malloc(pdc, (size_t) (filelen + 1), fn); len = (pdc_off_t) pdc__fread(content, 1, (size_t) filelen, fp); /* because pdc__ftell lies! */ filelen = len; if (!filelen) { pdc_free(pdc, content); filelen = 0; content = NULL; } } #endif if (content) content[filelen] = 0; *o_filelen = filelen; return (void *) content; }
void pdf__delete(PDF *p) { /* * Close the output stream, because it could be open */ pdc_close_output(p->out); /* * Clean up page-related stuff if necessary. Do not raise * an error here since we may be called from the error handler. */ pdf_cleanup_document(p); pdf_cleanup_stringlists(p); pdf_cleanup_font_curroptions(p); pdc_cleanup_output(p->out, pdc_false); if (p->out) pdc_free(p->pdc, p->out); /* we never reach this point if (p->pdc == NULL). */ pdc_delete_core(p->pdc); /* free the PDF structure and try to protect against duplicated calls */ p->magic = 0L; /* we don't reach this with the wrong magic */ (*p->freeproc)(p, (void *) p); }
void pdc_free_tmp(pdc_core *pdc, void *mem) { pdc_tmpmem_list *tm_list = &pdc->pr->tm_list; int i, j; pdc_logg_cond(pdc, 2, trc_memory, "\tTemporary memory %p to be freed\n", mem); /* we search the list backwards since chances are good ** that the most recently allocated items are freed first. */ for (i = tm_list->size - 1; 0 <= i; --i) { if (tm_list->tmpmem[i].mem == mem) { if (tm_list->tmpmem[i].destr) tm_list->tmpmem[i].destr( tm_list->tmpmem[i].opaque, tm_list->tmpmem[i].mem); pdc_free(pdc, tm_list->tmpmem[i].mem); tm_list->tmpmem[i].mem = (void *) 0; --tm_list->size; for (j = i; j < tm_list->size; j++) tm_list->tmpmem[j] = tm_list->tmpmem[j + 1]; return; } } pdc_error(pdc, PDC_E_INT_FREE_TMP, 0, 0, 0, 0); }
PDFLIB_API void PDFLIB_CALL PDF_setdashpattern(PDF *p, const char *optlist) { static const char fn[] = "PDF_setdashpattern"; pdc_resopt *results; float *darray, phase; int length; if (!pdf_enter_api(p, fn, pdf_state_content, "(p[%p], \"%s\")\n", (void *) p, optlist)) return; /* parsing optlist */ results = pdc_parse_optionlist(p->pdc, optlist, pdf_dashoptions, NULL, pdc_true); length = pdc_get_optvalues(p->pdc, "dasharray", results, NULL, (void **) &darray); phase = (float) 0.0; (void) pdc_get_optvalues(p->pdc, "dashphase", results, &phase, NULL); pdc_cleanup_optionlist(p->pdc, results); pdf__setdashpattern(p, darray, length, phase); if (darray) pdc_free(p->pdc, darray); }
pdc_jmpbuf * pdc_jbuf(pdc_core *pdc) { static const char fn[] = "pdc_jbuf"; if (++pdc->pr->x_sp == pdc->pr->x_ssize) { pdc_xframe *aux; #ifdef PDC_ALIGN16 char *cp = (char *) (*pdc->pr->allocproc)(pdc->pr->opaque, 16 + 2 * pdc->pr->x_ssize * sizeof (pdc_xframe), fn); if (cp == (char *) 0) { aux = (pdc_xframe *) 0; } else { /* remember the pointer in order to free it only after the memcpy * below, as pdc->pr->x_stack points into the memory allocated * to pdc->pr->x_alias */ char *free_me_later = pdc->pr->x_alias; pdc->pr->x_alias = cp; aux = (pdc_xframe *) (((unsigned long) cp + 16) & 0xFFFFFFFFFFFFFFF0); memcpy(aux, pdc->pr->x_stack, pdc->pr->x_ssize * sizeof (pdc_xframe)); pdc_free(pdc, free_me_later); } #else aux = (pdc_xframe *) (*pdc->pr->reallocproc)( pdc->pr->opaque, pdc->pr->x_stack, 2 * pdc->pr->x_ssize * sizeof (pdc_xframe), fn); #endif if (aux == (pdc_xframe *) 0) { --pdc->pr->x_sp; pdc->pr->x_thrown = pdc_true; pdc->pr->in_error = pdc_true; pdc->pr->errnum = PDC_E_MEM_OUT; pdc->pr->apiname[0] = 0; sprintf(pdc->pr->errbuf, "Out of memory in TRY function (nesting level: %d)", pdc->pr->x_sp + 1); longjmp(pdc->pr->x_stack[pdc->pr->x_sp].jbuf.jbuf, 1); } pdc->pr->x_stack = aux; pdc->pr->x_ssize *= 2; } pdc->pr->x_thrown = pdc_false; return &pdc->pr->x_stack[pdc->pr->x_sp].jbuf; } /* pdc_jbuf */
int pdc_get_opt_utf8strings(pdc_core *pdc, const char *keyword, pdc_resopt *resopt, int flags, char ***strings) { int ns = pdc_get_optvalues(keyword, resopt, NULL, strings); if (ns) { if (pdc_is_lastopt_utf8(resopt)) { int i = resopt[0].lastind; pdc_resopt *ropt = &resopt[i]; char **s = (char **) ropt->val; int j; for (j = 0; j < ropt->num; j++) { char *sb = pdc_strdup_withbom(pdc, s[j]); if (s[j] != NULL) pdc_free(pdc, s[j]); s[j] = sb; } } pdc_save_lastopt(resopt, flags); } return ns; }
void pdf_cleanup_extgstates(PDF *p) { int i; if (!p->extgstates) return; for (i = 0; i < p->extgstates_number; i++) { if (p->extgstates[i].dash_array) pdc_free(p->pdc, p->extgstates[i].dash_array); } pdc_free(p->pdc, p->extgstates); p->extgstates = NULL; }
int pdf_insert_utilstring(PDF *p, const char *utilstring, pdc_bool kdup) { static const char fn[] = "pdf_insert_utilstring"; char **utilstrlist; int i = 0; if (p->utilstrlist_index == -1) { utilstrlist = (char **) pdc_calloc(p->pdc, PDF_MAX_UTILSTRLISTS * sizeof (char *), fn); p->utilstrlist_index = pdf_insert_stringlist(p, utilstrlist, PDF_MAX_UTILSTRLISTS); } utilstrlist = p->stringlists[p->utilstrlist_index]; if (p->utilstring_number >= PDF_MAX_UTILSTRLISTS) p->utilstring_number = 0; i = p->utilstring_number; if (utilstrlist[i] != NULL) pdc_free(p->pdc, utilstrlist[i]); if (kdup) utilstrlist[i] = pdc_strdup_ext(p->pdc, utilstring, 0, fn); else utilstrlist[i] = (char *) utilstring; p->utilstring_number++; return i; }
void pdf_cleanup_filesystem(PDF *p) { pdf_virtfile *vfile, *nextvfile; for (vfile = p->filesystem; vfile != NULL; /* */) { nextvfile = vfile->next; if (vfile->iscopy == pdc_true && vfile->data) pdc_free(p->pdc, (void *) vfile->data); if (vfile->name) pdc_free(p->pdc, vfile->name); pdc_free(p->pdc, vfile); vfile = nextvfile; } p->filesystem = NULL; }
void pdf_cleanup_pattern(PDF *p) { if (p->pattern) { pdc_free(p->pdc, p->pattern); p->pattern = NULL; } }
void pdc_bs_shutdown(pdc_bstr *s) { if (s->buf != (pdc_byte *) 0) pdc_free(s->pdc, s->buf); pdc_bs_boot(s->pdc, s); } /* pdc_bs_shutdown */
void pdf_cleanup_page_cstate(PDF *p, pdf_ppt *ppt) { if (ppt->cstate != NULL) pdc_free(p->pdc, ppt->cstate); ppt->cstate = NULL; }
void pdc_us_shutdown(pdc_ustr *s) { if (s->buf != (pdc_ucval *) 0) pdc_free(s->pdc, s->buf); pdc_us_boot(s->pdc, s); } /* pdc_us_shutdown */
void pdf_cleanup_shadings(PDF *p) { if (p->shadings) { pdc_free(p->pdc, p->shadings); p->shadings = NULL; } }
void pdf_cleanup_t3font(PDF *p, pdf_t3font *t3font) { int i; for (i = 0; i < t3font->next_glyph; i++) { if (t3font->glyphs[i].name) { pdc_free(p->pdc, t3font->glyphs[i].name); t3font->glyphs[i].name = NULL; } } pdc_free(p->pdc, t3font->glyphs); t3font->glyphs = NULL; }
/* * pdc_fopen_logg opens a file. The function expects a UTF-8 encoded file name. * (see function pdc_convert_filename), if define PDC_UNICODE_FILENAME is set. * */ FILE * pdc_fopen_logg(pdc_core *pdc, const char *filename, const char *mode) { FILE *fp = NULL; int i = 0; #if defined(PDC_UNICODE_FILENAME) pdc_byte *outfilename = NULL; pdc_text_format nameformat = PDC_UTF8; pdc_text_format targetnameformat = pdc_utf16; int len = (int) pdc_strlen(filename); int outlen = 0; if (pdc_is_utf16be_unicode(filename)) nameformat = pdc_utf16be; /* convert filename from UTF-8 / UTF-16BE to UTF-16 or Latin-1 */ pdc_convert_string(pdc, nameformat, 0, NULL, (pdc_byte *) filename, len, &targetnameformat, NULL, &outfilename, &outlen, PDC_CONV_TRYBYTES | PDC_CONV_NOBOM, pdc_true); if (targetnameformat == pdc_bytes) { fp = fopen((const char *) outfilename, mode); } else { wchar_t wmode[8]; len = (int) strlen(mode); for (i = 0; i < len; i++) wmode[i] = (wchar_t) mode[i]; wmode[len] = 0; fp = _wfopen((wchar_t *) outfilename, wmode); } pdc_free(pdc, outfilename); #else (void) pdc; /* due to honorlang, codeset of LANG: UTF-8 */ if (pdc_is_utf8_bytecode(filename)) i = 3; fp = fopen(&filename[i], mode); #endif pdc_logg_openclose(pdc, fp, pdc_true); return fp; }
void pdc_pop_errmsg(pdc_core *pdc) { if (pdc->pr->premsg) { pdc_free(pdc, pdc->pr->premsg); pdc->pr->premsg = NULL; } } /* pdc_pop_errmsg */
void pdf_data_source_file_terminate(PDF *p, PDF_data_source *src) { pdc_free(p->pdc, (void *) src->buffer_start); pdc_fclose((pdc_file *) src->private_data); if (src->length != (long) 0 && src->total != src->length) pdc_error(p->pdc, PDC_E_IO_READ, "?", 0, 0, 0); }
void pdf_delete_mbox(PDF *p, pdf_mbox *mbox) { if (mbox != NULL) { pdf_release_mbox(p, mbox); pdc_free(p->pdc, mbox); } }
int pdf__add_bookmark(PDF *p, const char *text, int len, int parent, int open) { static const char *fn = "pdf__add_bookmark"; pdf_outline self; pdf_dest *dest = (pdf_dest *) p->bookmark_dest; char *hypertext = NULL; int acthdl; int retval = 0; len = pdc_check_text_length(p->pdc, &text, len, PDF_MAXSTRINGSIZE); if (!len) pdc_error(p->pdc, PDC_E_ILLARG_EMPTY, "text", 0, 0, 0); pdf_init_outline(p, &self); if (parent != 0) pdf_check_handle(p, parent, pdc_bookmarkhandle); self.parent = parent; self.open = open; /* creating a Launch action - defined via bookmarkdest */ if (dest->filename) { char *actoptlist; actoptlist = (char *) pdc_malloc(p->pdc, strlen(dest->filename) + 80, fn); pdc_sprintf(p->pdc, pdc_false, actoptlist, "filename {%s} ", dest->filename); acthdl = pdf__create_action(p, "Launch", actoptlist); if (acthdl != -1) { if (p->pdc->hastobepos) acthdl++; pdc_sprintf(p->pdc, pdc_false, actoptlist, "activate %d", acthdl); self.action = pdc_strdup(p->pdc, actoptlist); } pdc_free(p->pdc, actoptlist); } else { self.dest = pdf_init_destination(p); *self.dest = *dest; if (dest->name) self.dest->name = pdc_strdup(p->pdc, dest->name); } memcpy(self.textcolor, dest->color, 3 * sizeof(pdc_scalar)); self.fontstyle = dest->fontstyle; hypertext = pdf_convert_hypertext_depr(p, text, len); if (hypertext) retval = pdf_insert_bookmark(p, hypertext, &self, -1); return retval; }