int lua_char_exists_callback (internal_font_number f, integer c) { integer callback_id ; lua_State *L = Luas[0]; int ret=0; callback_id = callback_defined(char_exists_callback); if (callback_id!=0) { lua_rawgeti(L,LUA_REGISTRYINDEX,callback_callbacks_id); lua_rawgeti(L,-1, callback_id); if (!lua_isfunction(L,-1)) { lua_pop(L,2); return 0; } lua_pushnumber(L,f); lua_pushnumber(L,c); if (lua_pcall(L,2,1,0) != 0) { /* two args, 1 result */ fprintf(stdout,"error: %s\n",lua_tostring(L,-1)); lua_pop(L,2); error(); } else { ret = lua_toboolean(L,-1); } } return ret; }
ff_entry *check_ff_exist(char *ff_name, boolean is_tt) { ff_entry *ff; ff_entry tmp; void **aa; int callback_id; char *filepath=NULL; assert(ff_name != NULL); tmp.ff_name = ff_name; ff = (ff_entry *) avl_find(ff_tree, &tmp); if (ff == NULL) { /* not yet in database */ ff = new_ff_entry(); ff->ff_name = xstrdup(ff_name); if (is_tt) { callback_id=callback_defined(find_truetype_file_callback); if (callback_id>0) { run_callback(callback_id,"S->S",ff_name,&filepath); if (filepath && strlen(filepath)==0) filepath=NULL; ff->ff_path = filepath; } else { ff->ff_path = kpse_find_file (ff_name, kpse_truetype_format, 0); } } else { callback_id=callback_defined(find_type1_file_callback); if (callback_id>0) { run_callback(callback_id,"S->S",ff_name,&filepath); if (filepath && strlen(filepath)==0) filepath=NULL; ff->ff_path = filepath; } else { ff->ff_path = kpse_find_file (ff_name, kpse_type1_format, 0); } } aa = avl_probe(ff_tree, ff); assert(aa != NULL); } return ff; }
void write_out(halfword p) { int old_setting; int j; char*s,*ss; int callback_id; int lua_retval; expand_macros_in_tokenlist(p); old_setting= selector; j= write_stream(p); if(file_can_be_written(j)){ selector= j; }else if((j==term_only)&&(selector==term_and_log)){ selector= log_only; tprint_nl(""); }else{ tprint_nl(""); } s= tokenlist_to_cstring(def_ref,false,NULL); if(selector<no_print){ callback_id= callback_defined(process_output_buffer_callback); if(callback_id> 0){ lua_retval= run_callback(callback_id,"S->S",s,&ss); if((lua_retval==true)&&(ss!=NULL)){ xfree(s); s= ss; } } } tprint(s); xfree(s); print_ln(); flush_list(def_ref); selector= old_setting; }
void print_banner(const char*v) { int callback_id= callback_defined(start_run_callback); if(callback_id==0){ fprintf(term_out,"This is "MyName", Version %s%s ",v,WEB2CVERSION); if(format_ident> 0) print(format_ident); print_ln(); if(show_luahashchars){ wterm(' '); fprintf(term_out,"Number of bits used by the hash function ("my_name"): %d",LUAI_HASHLIMIT); print_ln(); } if(shellenabledp){ wterm(' '); if(restrictedshell) fprintf(term_out,"restricted "); fprintf(term_out,"system commands enabled.\n"); } }else if(callback_id> 0){ run_callback(callback_id,"->"); } }
static sfd_entry *read_sfd (char *sfd_name) { void **aa; sfd_entry *sfd, tmp_sfd; subfont_entry *sf; char *ftemp = NULL; char buf[SMALL_BUF_SIZE], *p; long int i, j, k; int n; int callback_id=0; int file_opened=0; /* check whether this sfd has been read */ tmp_sfd.name = sfd_name; if (sfd_tree == NULL) { sfd_tree = avl_create (comp_sfd_entry, NULL, &avl_xallocator); assert (sfd_tree != NULL); } sfd = (sfd_entry *) avl_find (sfd_tree, &tmp_sfd); if (sfd != NULL) return sfd; set_cur_file_name (sfd_name); if (sfd_buffer!=NULL) { xfree(sfd_buffer); sfd_buffer=NULL; } sfd_curbyte=0; sfd_size=0; callback_id=callback_defined(find_sfd_file_callback); if (callback_id>0) { if(run_callback(callback_id,"S->S",cur_file_name,&ftemp)) { if(ftemp!=NULL&&strlen(ftemp)) { if (cur_file_name) free(cur_file_name); cur_file_name = xstrdup(ftemp); free(ftemp); } } } callback_id=callback_defined(read_sfd_file_callback); if (callback_id>0) { if(! (run_callback(callback_id,"S->bSd",cur_file_name, &file_opened, &sfd_buffer,&sfd_size) && file_opened && sfd_size>0 ) ) { pdftex_warn ("cannot open SFD file for reading"); cur_file_name = NULL; return NULL; } sfd_read_file(); sfd_close(); } tex_printf ("{"); tex_printf (cur_file_name); sfd = new_sfd_entry (); sfd->name = xstrdup (sfd_name); while (!sfd_eof ()) { sfd_getline (true); if (*sfd_line == 10) /* empty line indicating eof */ break; sf = new_subfont_entry (); sf->next = sfd->subfont; sfd->subfont = sf; sscanf (sfd_line, "%s %n", buf, &n); sf->infix = xstrdup (buf); p = sfd_line + n; /* skip to the next word */ k = 0; read_ranges: for (;;) { if (*p == '\\') { /* continue on next line */ sfd_getline (false); p = sfd_line; goto read_ranges; } else if (*p == 0) /* end of subfont */ break; if (sscanf (p, " %li %n", &i, &n) == 0) pdftex_fail ("invalid token:\n%s", p); p += n; if (*p == ':') { /* offset */ k = i; p++; } else if (*p == '_') { /* range */ if (sscanf (p + 1, " %li %n", &j, &n) == 0) pdftex_fail ("invalid token:\n%s", p); if (i > j || k + (j - i) > 255) pdftex_fail ("invalid range:\n%s", p); while (i <= j) sf->charcodes[k++] = i++; p += n + 1; } else /* codepoint */ sf->charcodes[k++] = i; } } tex_printf ("}"); aa = avl_probe (sfd_tree, sfd); assert (aa != NULL); return sfd; }
void read_img(image_dict * idict) { char *filepath = NULL; int callback_id; if (img_filename(idict) == NULL) { normal_error("pdf backend","image file name missing"); } callback_id = callback_defined(find_image_file_callback); if (img_filepath(idict) == NULL) { if (callback_id > 0) { /*tex We always callback, also for a mem stream. */ if (run_callback(callback_id, "S->S", img_filename(idict),&filepath)) { if (filepath && (strlen(filepath) > 0)) { img_filepath(idict) = strdup(filepath); } } } if (img_filepath(idict) == NULL && (strstr(img_filename(idict),"data:application/pdf,") != NULL)) { /*tex We need to check here for a pdf memstream. */ img_filepath(idict) = strdup(img_filename(idict)); } else if (callback_id == 0) { /*tex Otherwise we use kpse but only when we don't callback. */ img_filepath(idict) = kpse_find_file(img_filename(idict), kpse_tex_format, true); } if (img_filepath(idict) == NULL) { /*tex In any case we need a name. */ formatted_error("pdf backend","cannot find image file '%s'", img_filename(idict)); } } recorder_record_input(img_filepath(idict)); /*tex A few type checks. */ check_type_by_header(idict); check_type_by_extension(idict); /*tex Now we're ready to read the image. */ switch (img_type(idict)) { case IMG_TYPE_PDFMEMSTREAM: case IMG_TYPE_PDF: read_pdf_info(idict); break; case IMG_TYPE_PNG: read_png_info(idict); break; case IMG_TYPE_JPG: read_jpg_info(idict); break; case IMG_TYPE_JP2: read_jp2_info(idict); break; case IMG_TYPE_JBIG2: read_jbig2_info(idict); break; default: img_type(idict) = IMG_TYPE_NONE; if (pdf_ignore_unknown_images) { normal_warning("pdf backend","internal error: ignoring unknown image type"); } else { normal_error("pdf backend","internal error: unknown image type"); } break; } cur_file_name = NULL; if (img_type(idict) == IMG_TYPE_NONE) { img_state(idict) = DICT_NEW; } else if (img_state(idict) < DICT_FILESCANNED) { img_state(idict) = DICT_FILESCANNED; } }
void fm_read_info () { int callback_id; int file_opened = 0; char *ftemp = NULL; if (tfm_tree == NULL) create_avl_trees (); if (mitem->line == NULL) /* nothing to do */ return; mitem->lineno = 1; switch (mitem->type) { case MAPFILE: set_cur_file_name (mitem->line); if (fm_buffer!=NULL) { xfree(fm_buffer); fm_buffer=NULL; } fm_curbyte=0; fm_size=0; callback_id=callback_defined(find_map_file_callback); if (callback_id>0) { if(run_callback(callback_id,"S->S",(char *)(nameoffile+1),&ftemp)) { if(ftemp!=NULL&&strlen(ftemp)) { free(nameoffile); namelength = strlen(ftemp); nameoffile = xmalloc(namelength+2); strcpy((char *)(nameoffile+1),ftemp); free(ftemp); } } } callback_id=callback_defined(read_map_file_callback); if (callback_id>0) { if(run_callback(callback_id,"S->bSd",(char *)(nameoffile+1), &file_opened, &fm_buffer,&fm_size)) { if(file_opened) { if (fm_size>0) { cur_file_name = (char *) nameoffile + 1; if (tracefilenames) tex_printf ("{%s", cur_file_name); while (!fm_eof ()) { fm_scan_line (); mitem->lineno++; } if (tracefilenames) tex_printf ("}"); fm_file = NULL; } } else { pdftex_warn ("cannot open font map file"); } } else { pdftex_warn ("cannot open font map file"); } } else { if (!fm_open ()) { pdftex_warn ("cannot open font map file"); } else { fm_read_file(); cur_file_name = (char *) nameoffile + 1; tex_printf ("{%s", cur_file_name); while (!fm_eof ()) { fm_scan_line (); mitem->lineno++; } fm_close (); tex_printf ("}"); fm_file = NULL; } } break; case MAPLINE: cur_file_name = NULL; /* makes pdftex_warn() shorter */ fm_scan_line (); break; default: assert (0); } mitem->line = NULL; /* done with this line */ cur_file_name = NULL; return; }
static int do_define_font (integer f, char *cnom, char *caire, scaled s, integer natural_dir) { boolean res; /* was the callback successful? */ integer callback_id; char *cnam; #if TIMERS struct timeval tva; struct timeval tvb; double tvdiff; #endif int r; res = 0; callback_id=callback_defined(define_font_callback); if (callback_id>0) { if (caire == NULL || strlen(caire)==0) { cnam = xstrdup(cnom); } else { cnam = xmalloc(strlen(cnom)+strlen(caire)+2); sprintf(cnam,"%s/%s",caire,cnom); } #if TIMERS gettimeofday(&tva,NULL); #endif callback_id = run_and_save_callback(callback_id,"Sdd->",cnam,s,f); #if TIMERS gettimeofday(&tvb,NULL); tvdiff = tvb.tv_sec*1000000.0; tvdiff += (double)tvb.tv_usec; tvdiff -= (tva.tv_sec*1000000.0); tvdiff -= (double)tva.tv_usec; tvdiff /= 1000000; fprintf(stdout,"\ncallback('define_font',%s,%i): %f seconds\n", cnam,f,tvdiff); #endif free(cnam); if (callback_id>0) { /* success */ luaL_checkstack(Luas[0],1,"out of stack space"); lua_rawgeti(Luas[0],LUA_REGISTRYINDEX, callback_id); if (lua_istable(Luas[0],-1)) { #if TIMERS gettimeofday(&tva,NULL); #endif res = font_from_lua(Luas[0],f); destroy_saved_callback (callback_id); #if TIMERS gettimeofday(&tvb,NULL); tvdiff = tvb.tv_sec*1000000.0; tvdiff += (double)tvb.tv_usec; tvdiff -= (tva.tv_sec*1000000.0); tvdiff -= (double)tva.tv_usec; tvdiff /= 1000000; fprintf(stdout,"font_from_lua(%s,%i): %f seconds\n", font_name(f),f,tvdiff); #endif lua_pop(Luas[0],1); } else if (lua_isnumber(Luas[0],-1)) { r = lua_tonumber(Luas[0],-1); destroy_saved_callback (callback_id); delete_font(f); lua_pop(Luas[0],1); return r; } else { lua_pop(Luas[0],1); delete_font(f); return 0; } } } else { res = read_tfm_info(f,cnom,caire,s); if (res) { set_hyphen_char(f,get_default_hyphen_char()); set_skew_char(f,get_default_skew_char()); } } if (res) { do_vf(f); set_font_natural_dir(f,natural_dir); return f; } else { delete_font(f); return 0; } }