void init_shell_escape(void) { if (shellenabledp < 0) { /* --no-shell-escape on cmd line */ shellenabledp = 0; } else { if (shellenabledp == 0) { /* no shell options on cmd line, check cnf */ char *v1 = kpse_var_value("shell_escape"); if (v1) { if (*v1 == 't' || *v1 == 'y' || *v1 == '1') { shellenabledp = 1; } else if (*v1 == 'p') { shellenabledp = 1; restrictedshell = 1; } free(v1); } } /* If shell escapes are restricted, get allowed cmds from cnf. */ if (shellenabledp && restrictedshell == 1) { char *v2 = kpse_var_value("shell_escape_commands"); if (v2) { mk_shellcmdlist(v2); free(v2); } } } }
/* TeXlive uses its own gs in $SELFAUTOPARENT/tlpkg/tlgs */ void texlive_gs_init(void) { char *nptr, *path; char tlgsbindir[512]; char tlgslibdir[512]; nptr = kpse_var_value("TEXLIVE_WINDOWS_EXTERNAL_GS"); if (nptr == NULL || !strcmp(nptr, "0") || !strcmp(nptr, "n") || !strcmp(nptr, "f")) { if (nptr) free (nptr); nptr = kpse_var_value("SELFAUTOPARENT"); if (nptr) { strcpy(tlgsbindir, nptr); strcat(tlgsbindir,"/tlpkg/tlgs"); if(is_dir(tlgsbindir)) { strcpy(tlgslibdir, tlgsbindir); strcat(tlgslibdir, "/lib;"); strcat(tlgslibdir, tlgsbindir); strcat(tlgslibdir, "/fonts"); strcat(tlgsbindir, "/bin;"); free(nptr); for(nptr = tlgsbindir; *nptr; nptr++) { if(*nptr == '/') *nptr = '\\'; } nptr = getenv("PATH"); path = (char *)malloc(strlen(nptr) + strlen(tlgsbindir) + 6); strcpy(path, tlgsbindir); strcat(path, nptr); xputenv("PATH", path); xputenv("GS_LIB", tlgslibdir); } } } else { free (nptr); } }
static void misstex P2C(kpse_file_format_type, format, string *, args) { static FILE *missfont = NULL; string *s; /* If we weren't trying to make a font, do nothing. Maybe should allow people to specify what they want recorded? */ if (format != kpse_gf_format && format != kpse_pk_format && format != kpse_any_glyph_format && format != kpse_tfm_format && format != kpse_vf_format) return; /* If this is the first time, have to open the log file. But don't bother logging anything if they were discarding errors. */ if (!missfont && !kpse_make_tex_discard_errors) { const_string missfont_name = kpse_var_value ("MISSFONT_LOG"); if (!missfont_name || *missfont_name == '1') { missfont_name = "missfont.log"; /* take default name */ } else if (missfont_name && (*missfont_name == 0 || *missfont_name == '0')) { missfont_name = NULL; /* user requested no missfont.log */ } /* else use user's name */ missfont = missfont_name ? fopen (missfont_name, FOPEN_A_MODE) : NULL; if (!missfont && kpse_var_value ("TEXMFOUTPUT")) { missfont_name = concat3 (kpse_var_value ("TEXMFOUTPUT"), DIR_SEP_STRING, missfont_name); missfont = fopen (missfont_name, FOPEN_A_MODE); } if (missfont) fprintf (stderr, "kpathsea: Appending font creation commands to %s.\n", missfont_name); } /* Write the command if we have a log file. */ if (missfont) { fputs (args[0], missfont); for (s = &args[1]; *s != NULL; s++) { putc(' ', missfont); fputs (*s, missfont); } putc ('\n', missfont); } }
void init_start_time(void) { if (start_time < 0) { unsigned long long epoch; char *endptr; /* We don't really care how kpse sets up this variable but we prefer to just use its abstract interface. */ char *source_date_epoch = kpse_var_value("SOURCE_DATE_EPOCH"); if (source_date_epoch) { errno = 0; epoch = strtoull(source_date_epoch, &endptr, 10); if (*endptr != '\0' || errno != 0) { epoch = 0; } #if defined(_MSC_VER) /* We avoid to crash if users test a large value which is not supported by Visual Studio 2010: a later time than 3001/01/01 20:59:59. */ if (epoch > 32535291599ULL) epoch = 32535291599ULL; #endif start_time = epoch; } } }
static int var_value(lua_State * L) { const char *st = luaL_checkstring(L, 1); TEST_PROGRAM_NAME_SET; lua_pushstring(L, kpse_var_value(st)); return 1; }
/* 'mode' must be read */ FILE *nkf_open(const char *path, const char *mode) { char buff[PATH_MAX * 2 + 20]; /* 20 is enough gaps */ char *name; FILE *fp; if (in_filter == NULL) { in_filter = kpse_var_value("PTEX_IN_FILTER"); if (in_filter == NULL || strcasecmp(in_filter, "no") == 0) { nkf_disable(); } #ifdef NKF_TEST atexit(nkf_check); #endif /* NKF_TEST */ } if (in_filter[0] == '\0') return fopen(path, mode); name = xstrdup(path); if (kpse_readable_file(name) == NULL) { free(name); return NULL; /* can't read */ } sprintf(buff, "%.*s < '%.*s'", PATH_MAX, in_filter, PATH_MAX, path); free(name); /* fprintf(stderr, "\n`%s`", buff); */ fp = popen(buff , "r"); if (piped_num < NOFILE) piped_fp[piped_num++] = fp; return fp; }
boolean kpse_tex_hush P1C(const_string, what) { string h; string hush = kpse_var_value ("TEX_HUSH"); if (hush) { for (h = kpse_path_element (hush); h; h = kpse_path_element (NULL)) { /* Don't do anything special with empty elements. */ if (STREQ (h, what) || STREQ (h, "all")) return true; } } return false; }
boolean open_output (FILE **f_ptr, const_string fopen_mode) { string fname; boolean absolute = kpse_absolute_p(nameoffile+1, false); /* If we have an explicit output directory, use it. */ if (output_directory && !absolute) { fname = concat3(output_directory, DIR_SEP_STRING, nameoffile + 1); } else { fname = nameoffile + 1; } /* Is the filename openable as given? */ *f_ptr = fopen (fname, fopen_mode); if (!*f_ptr) { /* Can't open as given. Try the envvar. */ string texmfoutput = kpse_var_value("TEXMFOUTPUT"); if (texmfoutput && *texmfoutput && !absolute) { if (fname != nameoffile + 1) free(fname); fname = concat3(texmfoutput, DIR_SEP_STRING, nameoffile+1); *f_ptr = fopen(fname, fopen_mode); } } /* If this succeeded, change nameoffile accordingly. */ if (*f_ptr) { if (fname != nameoffile + 1) { free (nameoffile); namelength = strlen (fname); nameoffile = xmalloc (namelength + 2); strcpy (nameoffile + 1, fname); } recorder_record_output (fname); } if (fname != nameoffile +1) free(fname); return *f_ptr != NULL; }
static void log_search P1C(str_list_type, filenames) { static FILE *log_file = NULL; static boolean first_time = true; /* Need to open the log file? */ if (first_time) { /* Get name from either envvar or config file. */ string log_name = kpse_var_value ("TEXMFLOG"); first_time = false; if (log_name) { log_file = fopen (log_name, FOPEN_A_MODE); if (!log_file) perror (log_name); free (log_name); } } if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH) || log_file) { unsigned e; /* FILENAMES should never be null, but safety doesn't hurt. */ for (e = 0; e < STR_LIST_LENGTH (filenames) && STR_LIST_ELT (filenames, e); e++) { string filename = STR_LIST_ELT (filenames, e); /* Only record absolute filenames, for privacy. */ if (log_file && kpse_absolute_p (filename, false)) fprintf (log_file, "%lu %s\n", (long unsigned) time (NULL), filename); /* And show them online, if debugging. We've already started the debugging line in `search', where this is called, so just print the filename here, don't use DEBUGF. */ if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) { putc (' ', stderr); fputs (filename, stderr); } } } }
int shell_cmd_is_allowed(const char *cmd, char **safecmd, char **cmdname) { char **p; char *buf; char *c, *d; const char *s; int pre; unsigned spaces; int allow = 0; /* pre == 1 means that the previous character is a white space pre == 0 means that the previous character is not a white space */ buf = xmalloc(strlen(cmd) + 1); strcpy(buf, cmd); c = buf; while (Isspace(*c)) c++; d = c; while (!Isspace(*d) && *d) d++; *d = '\0'; /* *cmdname is the first word of the command line. For example, *cmdname == "kpsewhich" for: \write18{kpsewhich --progname=dvipdfm --format="other text files" config} */ *cmdname = xstrdup(c); free(buf); /* Is *cmdname listed in a texmf.cnf vriable as shell_escape_commands = foo,bar,... ? */ p = cmdlist; if (p) { while (*p) { if (strcmp(*p, *cmdname) == 0) { /* *cmdname is found in the list, so restricted shell escape is allowed */ allow = 2; break; } p++; } } if (allow == 2) { spaces = 0; for (s = cmd; *s; s++) { if (Isspace(*s)) spaces++; } /* allocate enough memory (too much?) */ # ifdef WIN32 *safecmd = xmalloc(2 * strlen(cmd) + 3 + 2 * spaces); # else *safecmd = xmalloc(strlen(cmd) + 3 + 2 * spaces); # endif /* make a safe command line *safecmd */ s = cmd; while (Isspace(*s)) s++; d = *safecmd; while (!Isspace(*s) && *s) *d++ = *s++; pre = 1; while (*s) { /* Quotation given by a user. " should always be used; we transform it below. On Unix, if ' is used, simply immediately return a quotation error. */ if (*s == '\'') { return -1; } if (*s == '"') { /* All arguments are quoted as 'foo' (Unix) or "foo" (Windows) before calling system(). Therefore closing QUOTE is necessary if the previous character is not a white space. For example: --format="other text files" becomes '--format=''other text files' (Unix) "--format"="other text files" (Windows) */ if (pre == 0) { # ifdef WIN32 if (*(s-1) == '=') { *(d-1) = QUOTE; *d++ = '='; } else { *d++ = QUOTE; } # else *d++ = QUOTE; # endif } pre = 0; /* Output the quotation mark for the quoted argument. */ *d++ = QUOTE; s++; while (*s != '"') { /* Illegal use of ', or closing quotation mark is missing */ if (*s == '\'' || *s == '\0') return -1; # if 0 # ifdef WIN32 if (char_needs_quote(*s)) *d++ = '^'; # endif # endif *d++ = *s++; } /* Closing quotation mark will be output afterwards, so we do nothing here. */ s++; /* The character after the closing quotation mark should be a white space or NULL. */ if (!Isspace(*s) && *s) return -1; /* Beginning of a usual argument. */ } else if (pre == 1 && !Isspace(*s)) { pre = 0; *d++ = QUOTE; # if 0 # ifdef WIN32 if (char_needs_quote(*s)) *d++ = '^'; # endif # endif *d++ = *s++; /* Ending of a usual argument. */ } else if (pre == 0 && Isspace(*s)) { pre = 1; /* Closing quotation mark */ *d++ = QUOTE; *d++ = *s++; } else { /* Copy a character from cmd to *safecmd. */ # if 0 # ifdef WIN32 if (char_needs_quote(*s)) *d++ = '^'; # endif # endif *d++ = *s++; } } /* End of the command line. */ if (pre == 0) { *d++ = QUOTE; } *d = '\0'; #ifdef WIN32 { char *p, *q, *r; p = *safecmd; if (strlen (p) > 2 && p[1] == ':' && !IS_DIR_SEP (p[2])) { q = xmalloc (strlen (p) + 2); q[0] = p[0]; q[1] = p[1]; q[2] = '/'; q[3] = '\0'; strcat (q, (p + 2)); free (*safecmd); *safecmd = q; } else if (!IS_DIR_SEP (p[0]) && !(p[1] == ':' && IS_DIR_SEP (p[2]))) { p = kpse_var_value ("SELFAUTOLOC"); if (p) { r = *safecmd; while (*r && !Isspace(*r)) r++; if (*r == '\0') q = concatn ("\"", p, "/", *safecmd, "\"", NULL); else { *r = '\0'; r++; while (*r && Isspace(*r)) r++; if (*r) q = concatn ("\"", p, "/", *safecmd, "\" ", r, NULL); else q = concatn ("\"", p, "/", *safecmd, "\"", NULL); } free (p); free (*safecmd); *safecmd = q; } } } #endif } return allow; }
int main(int argc, char **argv) { int i,j,cc=0,startpagenum=-1,ecount=0,chkopt=1; const char *envbuff; UVersionInfo icuVersion; char icu_version[U_MAX_VERSION_STRING_LENGTH] = ""; #ifdef WIN32 char **av; int ac; _setmaxstdio(2048); #endif kpse_set_program_name(argv[0], "upmendex"); #ifdef WIN32 file_system_codepage = CP_UTF8; is_cp932_system = 0; if (get_command_line_args_utf8("utf-8", &ac, &av)) { argv = av; argc = ac; } #endif kp_ist.var_name = "INDEXSTYLE"; kp_ist.path = DEFAULT_INDEXSTYLES; /* default path. */ kp_ist.suffix = "ist"; KP_entry_filetype(&kp_ist); kp_dict.var_name = "INDEXDICTIONARY"; kp_dict.path = DEFAULT_INDEXDICTS; /* default path */ kp_dict.suffix = "dict"; KP_entry_filetype(&kp_dict); /* check options */ for (i=1,j=0; i<argc && j<256; i++) { if ((argv[i][0]=='-')&&(strlen(argv[i])>=2)&&chkopt) { switch (argv[i][1]) { case 'c': bcomp=1; break; case 'd': if ((argv[i][2]=='\0')&&(i+1<argc)) { dicfile=xstrdup(argv[++i]); } else { dicfile=xstrdup(&argv[i][2]); } break; case 'f': force=1; break; case 'g': gflg=1; break; case 'i': fsti=1; break; case 'l': lorder=1; break; case 'o': if ((argv[i][2]=='\0')&&(i+1<argc)) { indfile=xstrdup(argv[++i]); } else { indfile=xstrdup(&argv[i][2]); } break; case 'p': if ((argv[i][2]=='\0')&&(i+1<argc)) { i++; if (strcmp(argv[i],"any")==0) fpage=2; else if (strcmp(argv[i],"odd")==0) fpage=3; else if (strcmp(argv[i],"even")==0) fpage=4; else { fpage=1; startpagenum=atoi(argv[i]); } } else { if (strcmp(&argv[i][2],"any")==0) fpage=2; else if (strcmp(&argv[i][2],"odd")==0) fpage=3; else if (strcmp(&argv[i][2],"even")==0) fpage=4; else { fpage=1; startpagenum=atoi(&argv[i][2]); } } break; case 'q': verb=0; break; case 't': if ((argv[i][2]=='\0')&&(i+1<argc)) { logfile=xstrdup(argv[++i]); } else { logfile=xstrdup(&argv[i][2]); } break; case 'r': prange=0; break; case 's': if ((argv[i][2]=='\0')&&(i+1<argc)) { styfile=xstrdup(argv[++i]); } else { styfile=xstrdup(&argv[i][2]); } break; case 'v': debug=1; break; case '-': if (strlen(argv[i])==2) chkopt=0; if (strcmp(argv[i],"--help")!=0) break; default: u_getVersion(icuVersion); u_versionToString(icuVersion, icu_version); fprintf(stderr,"upmendex - index processor, %s (%s).\n",VERSION, TL_VERSION); fprintf(stderr," Copyright 2009 ASCII MEDIA WORKS, 2015-2016 TANAKA Takuji\n"); fprintf(stderr," using ICU version %s\n",icu_version); fprintf(stderr,"usage:\n"); fprintf(stderr,"%% upmendex [-ilqrcgf] [-s sty] [-d dic] [-o ind] [-t log] [-p no] [--] [idx0 idx1 ...]\n"); fprintf(stderr,"options:\n"); fprintf(stderr,"-i use stdin as the input file.\n"); fprintf(stderr,"-l use letter ordering.\n"); fprintf(stderr,"-q quiet mode.\n"); fprintf(stderr,"-r disable implicit page formation.\n"); fprintf(stderr,"-c compress blanks. (ignore leading and trailing blanks.)\n"); fprintf(stderr,"-g make Japanese index head <%s>.\n", AKASATANAutf8); fprintf(stderr,"-f force to output unknown scripts.\n"); fprintf(stderr,"-s sty take sty as style file.\n"); fprintf(stderr,"-d dic take dic as dictionary file.\n"); fprintf(stderr,"-o ind take ind as the output index file.\n"); fprintf(stderr,"-t log take log as the error log file.\n"); fprintf(stderr,"-p no set the starting page number of index.\n"); fprintf(stderr,"idx... input files.\n"); exit(0); break; } } else { cc=strlen(argv[i]); if (cc<4) cc+=4; else if (strcmp(&argv[i][cc-4],".idx")) cc+=4; idxfile[j]=xmalloc(cc+1); strcpy(idxfile[j++],argv[i]); } } idxcount=j+fsti; /* check option errors */ if (idxcount==0) idxcount=fsti=1; if (styfile==NULL) { envbuff=kpse_var_value("INDEXDEFAULTSTYLE"); if (envbuff!=NULL) { styfile=xstrdup(envbuff); } } /* init hangul tumunja table */ u_strcpy(tumunja,GANADA); if (styfile!=NULL) styread(styfile); if (!indfile &&(idxcount-fsti>0)) { indfile=xmalloc(strlen(idxfile[0]+6)); for (i=strlen(idxfile[0]); i>=0; i--) { if (idxfile[0][i]=='.') { strncpy(indfile,idxfile[0],i); sprintf(&indfile[i],".ind"); break; } } if (i==-1) sprintf(indfile,"%s.ind",idxfile[0]); } if (!logfile && (idxcount-fsti > 0)) { logfile=xmalloc(strlen(idxfile[0]+6)); for (i=strlen(idxfile[0]); i>=0; i--) { if (idxfile[0][i]=='.') { strncpy(logfile,idxfile[0],i); sprintf(&logfile[i],".ilg"); break; } } if (i==-1) sprintf(logfile,"%s.ilg",idxfile[0]); } if (logfile && kpse_out_name_ok(logfile)) efp=fopen(logfile,"wb"); if(efp == NULL) { efp=stderr; logfile=xstrdup("stderr"); } set_icu_attributes(); if (strcmp(argv[0],"makeindex")==0) { verb_printf(efp,"This is Not `MAKEINDEX\', But `UPMENDEX\' %s (%s).\n", VERSION, TL_VERSION); } else { verb_printf(efp,"This is upmendex %s (%s).\n", VERSION, TL_VERSION); } /* init kanatable */ initkanatable(); /* read dictionary */ ecount+=dicread(dicfile); switch (letter_head) { case 0: case 1: if (gflg==1) { u_strcpy(atama,akasatana); } else { u_strcpy(atama,aiueo); } break; case 2: if (gflg==1) { u_strcpy(atama,AKASATANA); } else { u_strcpy(atama,AIUEO); } break; default: break; } /* read idx file */ lines=0; ecount=0; ind=xmalloc(sizeof(struct index)); for (i=0; i<idxcount-fsti; i++) { ecount+=idxread(idxfile[i],lines); } if (fsti==1) { ecount+=idxread(NULL,lines); } verb_printf(efp,"%d entries accepted, %d rejected.\n",acc,reject); if (ecount!=0) { verb_printf(efp,"%d errors, written in %s.\n",ecount,logfile); lines=0; } if (lines==0) { verb_printf(efp,"Nothing written in output file.\n"); if (efp!=stderr) fclose(efp); exit(255); } /* sort index */ verb_printf(efp,"Sorting index."); scount=0; wsort(ind,lines); verb_printf(efp,"...done(%d comparisons).\n",scount); /* sort pages */ verb_printf(efp,"Sorting pages."); scount=0; pagesort(ind,lines); verb_printf(efp,"...done(%d comparisons).\n",scount); /* get last page */ if ((fpage>1)&&(idxcount-fsti>0)) cc=lastpage(idxfile[0]); switch (fpage) { case 2: startpagenum=cc+1; break; case 3: if ((cc+1)%2==0) startpagenum=cc+2; else startpagenum=cc+1; break; case 4: if ((cc+1)%2==1) startpagenum=cc+2; else startpagenum=cc+1; break; default: break; } /* write indfile */ verb_printf(efp,"Making index file."); indwrite(indfile,ind,startpagenum); verb_printf(efp,"...done.\n"); if (idxcount-fsti==0) indfile=xstrdup("stdout"); verb_printf(efp,"%d warnings, written in %s.\n",warn,logfile); verb_printf(efp,"Output written in %s.\n",indfile); if (efp!=stderr) fclose(efp); return 0; }
int main(int ac, char **av) { int savo, savi; FILE *fnul; char *fmtname; char *p; char orgname[256]; char texbindir[256]; char fullbin[256]; kpse_set_program_name(av[0], NULL); if(ac != 2) { fprintf(stderr,"%s : Usage %s formatname\n", av[0], av[0]); fprintf(stderr,"formatname : (foo.fmt, foo.nfmt, foo.mem, foo.base)\n"); return 1; } if(strlen(av[1]) > 127) { fprintf(stderr, "\nToo long a format name.\n"); return 100; } p = kpse_var_value("SELFAUTOLOC"); if(p == 0) { fprintf(stderr, "I cannot get SELFAUTOLOC\n"); exit(1); } strcpy(texbindir, p); free(p); for(p=texbindir; *p; p++) { if(*p == '/') *p = '\\'; } strcat(texbindir, "\\"); strcpy(orgname, av[1]); p = strrchr(av[1], '.'); if(!p) { fprintf(stderr, "formatname needs a suffix.\n"); return 1; } if(stricmp(p, ".fmt") && stricmp(p, ".nfmt") && stricmp(p, ".base") && stricmp(p, ".mem")) { fprintf(stderr, "%s : unknown format type.\n", av[1]); return 1; } *p = '\0'; /* save stdout and stdin */ savo = _dup(fileno(stdout)); savi = _dup(fileno(stdin)); /* connect stdout to stderr */ _dup2(fileno(stderr), fileno(stdout)); /* connect stdin to nul device */ if(!(fnul = fopen("nul", "r"))) { fprintf(stderr, "Cannot open nul device to read\n"); exit(100); } _dup2(fileno(fnul), fileno(stdin)); /* COMMAND */ strcpy(fullbin, texbindir); strcat(fullbin, "fmtutil.exe"); fprintf(stderr, "Running the command %s\n", fullbin); _spawnlp(_P_WAIT, fullbin, "fmtutil", "--byfmt", av[1], NULL); /* END COMMAND */ /* return to original stdout and stdin */ _dup2(savo, fileno(stdout)); close(savo); _dup2(savi, fileno(stdin)); close(savi); /* close nul device */ fclose(fnul); fmtname = kpse_find_file(orgname , kpse_fmt_format, 0); if(fmtname) { printf("%s\n", fmtname); free(fmtname); } return 0; }
boolean open_output (FILE ** f, const char * fopen_mode) { unsigned temp_length; name_of_file[name_length + 1] = '\0'; if (pseudo_tilde != 0 || pseudo_space != 0) retwiddle(name_of_file + 1); /* 8 + 3 file names on Windows NT 95/Feb/20 */ if (shorten_file_name) check_short_name(name_of_file + 1); if (prepend_path_if(name_of_file + 1, name_of_file + 1, ".dvi", dvi_directory) || prepend_path_if(name_of_file + 1, name_of_file + 1, ".log", log_directory) || prepend_path_if(name_of_file + 1, name_of_file + 1, ".aux", aux_directory) || prepend_path_if(name_of_file + 1, name_of_file + 1, ".fmt", fmt_directory) || prepend_path_if(name_of_file + 1, name_of_file + 1, ".pdf", pdf_directory)) { if (open_trace_flag) printf("After prepend %s\n", name_of_file + 1); } if (open_trace_flag) printf(" Open `%s' for output ", name_of_file + 1); *f = fopen((char *) name_of_file + 1, fopen_mode); if (*f == NULL) { string temp_dir = kpse_var_value("TEXMFOUTPUT"); if (temp_dir != NULL) { unsigned char temp_name[file_name_size]; xconcat3((char *) temp_name, temp_dir, PATH_SEP_STRING, (char *) name_of_file + 1); if (deslash) unixify((char *) temp_name); *f = fopen((char *) temp_name, fopen_mode); if (*f) strcpy((char *) name_of_file + 1, (char *) temp_name); } } #ifdef COMPACTFORMAT if (strstr((char *) name_of_file + 1, ".fmt") != NULL) gz_fmt_file = gzdopen(fileno(*f), "wb9"); #endif if (strstr((char *) name_of_file + 1, ".dvi") != NULL) dvi_file_name = xstrdup_name(); else if (strstr((char *) name_of_file + 1, ".pdf") != NULL) pdf_file_name = xstrdup_name(); else if (strstr((char *) name_of_file + 1, ".log") != NULL) log_file_name = xstrdup_name(); temp_length = strlen((char *) name_of_file + 1); name_of_file[temp_length + 1] = ' '; if (*f) name_length = temp_length; return (*f != NULL); }
int main (int ac, char **av) { static char execfile[SBUF]; char rbuff[LBUF]; char buff[LBUF]; char cmd[LBUF]; char mfname[TBUF]; char tfname[TBUF]; char pkname[TBUF]; char name[TBUF]; char dpi[TBUF]; char ydpi[TBUF]; char bdpi[TBUF]; char mag[TBUF]; char mode[TBUF]; char destdir[SBUF]; char designsize[64]; char *arg[4]; char currdir[SBUF]; char kpsedot[SBUF]; char *tmp; int cdrive, tdrive; FILE *fr, *fw, *fnul, *tfmfileptr; int i, savo, savi, ret; int style; int issetdest; int app; int oldform; int ps2pkok; char *env; char *p, *fpp; double Xdpi, Ydpi; char texname[TBUF], pfbname[TBUF], slant[TBUF], extend[TBUF], encname[TBUF]; char texbindir[256]; char fullbin[512]; /* * style = 0 : MAKETEXPK_STYLE undefined or other than dosnames * style = 1 : MAKETEXPK_STYLE = dosnames */ /* * issetdest = 0 : no destdir * issetdest = 1 : destdir * issetdest = 2 : current working dir */ /* * app = 0 : mf * app = 1 : ps2pk * app = 2 : gsftopk * app = 3 : ttf2pk * app = 4 : hbf2gf */ /* * oldform = 0 : newform of the command line * oldform = 1 : oldform of the command line */ /* * TEMP | TMP | TMPDIR (necessary) * */ tmp = getenv ("TEMP"); if (!tmp) tmp = getenv ("TMP"); if (!tmp) tmp = getenv ("TMPDIR"); if (!tmp) { tpkerr ("Please define TEMP | TMP | TMPDIR."); return (100); } tmp = xstrdup(tmp); /* * normalize directory separators */ normalize (tmp); for (i = 0; i < 4; i++) arg[i] = (char *) malloc (SBUF); kpse_set_program_name (av[0], NULL); progname = kpse_program_name; /* * get tex binary dir * */ p = kpse_var_value("SELFAUTOLOC"); if(p == 0) { fprintf(stderr, "I cannot get SELFAUTOLOC\n"); exit(100); } strcpy(texbindir, p); free(p); for(p=texbindir; *p; p++) { if(*p == '/') *p = '\\'; } *p = '\\'; *(p+1) = '\0'; if (ac < 2) { usage (); relmem (arg); free(tmp); return (100); } issetdest = 0; ps2pkok = 0; /* * oldform or newform ? * */ if (av[1][0] == '-') oldform = 0; else oldform = 1; /* * Old form of the command line */ if (oldform == 1) { if (ac < 5) { usage (); relmem (arg); free(tmp); return (100); } if((strlen(av[1]) > TBUF -1 ) || (strlen(av[2]) > TBUF -1 ) || (strlen(av[3]) > TBUF -1 ) || (strlen(av[4]) > TBUF -1 )) { fprintf(stderr, "\nToo long a string.\n"); free(tmp); return 100; } strcpy (name, av[1]); strcpy (dpi, av[2]); strcpy (bdpi, av[3]); strcpy (mag, av[4]); if (ac > 5) { if(strlen(av[5]) > TBUF -1) { fprintf(stderr, "\nToo long a string.\n"); free(tmp); return 100; } strcpy (mode, av[5]); } else mode[0] = '\0'; } else { /* * New form of the command line */ name[0] = dpi[0] = bdpi[0] = mag[0] = mode[0] = destdir[0] = '\0'; i = 1; while (i < ac) { if(strlen(av[i]) > TBUF - 1) { fprintf(stderr, "\nToo long a string.\n"); free(tmp); return 100; } if (av[i][0] != '-') { strcpy (name, av[i]); break; } if (!strcmp (av[i], "--dpi") || !strcmp (av[i], "-dpi")) { i++; if (i >= ac) { tpkerr ("Invalid arguments."); relmem (arg); free(tmp); return (100); } strcpy (dpi, av[i]); i++; } else if (!strcmp (av[i], "--bdpi") || !strcmp (av[i], "-bdpi")) { i++; if (i >= ac) { tpkerr ("Invalid arguments."); relmem (arg); free(tmp); return (100); } strcpy (bdpi, av[i]); i++; } else if (!strcmp (av[i], "--mag") || !strcmp (av[i], "-mag")) { i++; if (i >= ac) { tpkerr ("Invalid arguments."); relmem (arg); free(tmp); return (100); } strcpy (mag, av[i]); i++; } else if (!strcmp (av[i], "--mfmode") || !strcmp (av[i], "-mfmode")) { i++; if (i >= ac) { tpkerr ("Invalid arguments."); relmem (arg); free(tmp); return (100); } strcpy (mode, av[i]); i++; } else if (!strcmp (av[i], "--destdir") || !strcmp (av[i], "-destdir")) { i++; if (i >= ac) { tpkerr ("Invalid arguments."); relmem (arg); free(tmp); return (100); } strcpy (destdir, av[i]); issetdest = 1; i++; } else if (!strcmp (av[i], "--version") || !strcmp (av[i], "-version")) { version (); relmem (arg); free(tmp); return (0); } else if (!strcmp (av[i], "--help") || !strcmp (av[i], "-help")) { help (); relmem (arg); free(tmp); return (0); } else { tpkerr ("Argument error."); relmem (arg); free(tmp); return (100); } } } /* End of command line analysis */ env = kpse_var_value ("MAKETEXPK_STYLE"); if ((env == NULL) || !(*env) || (env && strcmp (env, "dosnames"))) { style = 0; } else style = 1; /* * Default program is mf */ app = 0; /* * check if mfmode and bdpi are consistent or not */ if (bdpi[0] && mode[0] && mode[0] != '/') { FILE *frd; char buff[128]; int len; strcpy (fullbin, texbindir); strcat (fullbin, "mf-nowin.exe \"\\mode:="); strcat (fullbin, mode); strcat (fullbin, ";mode_setup;message"); strcat (fullbin, "(decimal round pixels_per_inch);"); strcat (fullbin, "end. <nul\""); frd = popen (fullbin, "r"); if (!frd) { tpkerr ("I cannot find METAFONT.\n"); relmem (arg); free(tmp); return (100); } (void) fgets (buff, 126, frd); (void) fgets (buff, 126, frd); pclose (frd); system("del /Q mfput.*"); len = (int)strlen (buff); if (buff[len - 1] == '\n') { buff[len - 1] = '\0'; if (buff[len - 2] == '\r') buff[len - 2] = '\0'; } if (strcmp (bdpi, buff)) { fprintf(stderr, "mode_dpi %s and bdpi %s are inconsistent.\n", buff, bdpi); fprintf(stderr, "therefore I reset mfmode.\n"); mode[0] = '\0'; } } /* * determine mfmode if not given */ if (mode[0] == 0 || mode[0] == '/') { if (bdpi[0] == 0) { tpkerr ("Cannot determine the mode."); tpkerr ("I will try other possibilities."); app = 1; } else { strcpy (rbuff, "MAKETEXPK_MODE_"); strcat (rbuff, bdpi); if ((env = kpse_var_value ("MAKETEXPK_MODE")) && *env) strcpy (mode, env); else if ((env = kpse_var_value (rbuff))) strcpy (mode, env); else if (!strcmp (bdpi, "85")) strcpy (mode, "sun"); else if (!strcmp (bdpi, "100")) strcpy (mode, "nextscrn"); else if (!strcmp (bdpi, "118")) strcpy (mode, "pcprevw"); else if (!strcmp (bdpi, "160")) strcpy (mode, "nectzo"); else if (!strcmp (bdpi, "180")) strcpy (mode, "toshiba"); else if (!strcmp (bdpi, "200")) strcpy (mode, "highfax"); else if (!strcmp (bdpi, "240")) strcpy (mode, "canonlbp"); else if (!strcmp (bdpi, "300")) strcpy (mode, "cx"); else if (!strcmp (bdpi, "320")) strcpy (mode, "neclm"); else if (!strcmp (bdpi, "360")) strcpy (mode, "epstylus"); else if (!strcmp (bdpi, "400")) strcpy (mode, "nexthi"); else if (!strcmp (bdpi, "600")) strcpy (mode, "ljfour"); else if (!strcmp (bdpi, "720")) strcpy (mode, "epscszz"); else if (!strcmp (bdpi, "800")) strcpy (mode, "lwpro"); else if (!strcmp (bdpi, "1000")) strcpy (mode, "lmaster"); else if (!strcmp (bdpi, "1200")) strcpy (mode, "ultre"); else if (!strcmp (bdpi, "1270")) strcpy (mode, "linoone"); else if (!strcmp (bdpi, "1800")) strcpy (mode, "vtftzz"); else if (!strcmp (bdpi, "2400")) strcpy (mode, "supre"); else if (!strcmp (bdpi, "2540")) strcpy (mode, "linotzzh"); else if (!strcmp (bdpi, "3386")) strcpy (mode, "linolttz"); else if (!strcmp (bdpi, "8000")) strcpy (mode, "dpdfezzz"); else if (!strcmp (bdpi, "9600")) strcpy (mode, "ibx"); else { tpkerr ("Cannot determine the mode."); tpkerr ("I will try other possibilities."); app = 1; } } } if (env) free (env); if (name[0] == 0) { tpkerr ("Font name is not given."); relmem (arg); free(tmp); return (100); } if ((p = strrchr (name, '.'))) *p = '\0'; strcpy (mfname, name); strcat (mfname, ".mf"); if (app == 0) { if (!(p = kpse_var_value ("MFINPUTS"))) { tpkerr ("Cannot get value of MFINPUTS."); relmem (arg); free(tmp); return (100); } free (p); xputenv("MKTEXMF", "1"); if (!(p = kpse_find_file (mfname, kpse_mf_format, 1))) { fprintf (stderr, "Cannot find %s .\n", mfname); tpkerr ("I try ps2pk --> gsftopk --> ttf2pk --> hbf2gf."); app = 1; } } if (app != 0) { strcpy (mode, "modeless"); strcpy (tfname, name); strcat (tfname, ".tfm"); if (!(p = kpse_var_value ("TFMFONTS"))) { tpkerr ("Cannot get value of TFMFONTS."); relmem (arg); free(tmp); return (100); } free (p); /* I don't try to create nonexisting tfm here. */ if (!(p = kpse_find_file (tfname, kpse_tfm_format, 0))) { fprintf (stderr, "Cannot find %s .\n", tfname); relmem (arg); free(tmp); return 100; } tfmfileptr = fopen (p, "rb"); if (!tfmfileptr) { fprintf (stderr, "I cannot open %s.\n", p); relmem (arg); free(tmp); return 100; } i = 256 * getc (tfmfileptr); i += getc (tfmfileptr); fclose (tfmfileptr); if ((i == 9) || (i == 11)) { fprintf (stderr, "Current font seems to be a Japanese one.\n"); fprintf (stderr, "I give up to create a PK font.\n"); relmem (arg); free(tmp); return 100; } } if ((p[0] == '.') && (p[1] == '/') && (issetdest != 1)) issetdest = 2; fpp = _getcwd (currdir, SBUF); if (!fpp) { fprintf (stderr, "Failed to get current working directory.\n"); relmem (arg); free(tmp); return (100); } normalize (currdir); i = (int)strlen (currdir); if (currdir[i - 1] == '/') currdir[i - 1] = '\0'; strcpy (kpsedot, "KPSE_DOT=.;"); strcat (kpsedot, currdir); _putenv (kpsedot); if (issetdest == 2) { strcpy (destdir, currdir); } if (issetdest == 0) { strcpy (arg[0], "Dummy"); strcpy (arg[1], "pk"); strcpy (arg[2], p); strcpy (arg[3], mode); if (!(p = getdestdir (4, arg))) { tpkerr ("Cannot get destination directory name."); relmem (arg); free(tmp); return (100); } strcpy (rbuff, p); } else strcpy (rbuff, destdir); /* * Change backslash into slash */ normalize (rbuff); p = rbuff; i = (int)strlen (p); if (p[i - 1] == '/') p[i - 1] = '\0'; if (issetdest) { if (!is_dir (p)) { fprintf (stderr, "Destination %s is not found.\n", p); relmem (arg); free(tmp); return (100); } } else if (!is_dir (p)) { if (make_dir (p)) { tpkerr ("Error in make_dir."); relmem (arg); free(tmp); return (100); } } strcpy (buff, p); p = buff; i = (int)strlen (p); if (p[i - 1] != '/') strcat (p, "/"); if (dpi[0] == 0) { tpkerr ("Cannot determine DPI."); relmem (arg); free(tmp); return (100); } if (style == 1 && issetdest != 2) { /* dosnames */ strcat (p, "dpi"); strcat (p, dpi); if (!is_dir (p)) { if (make_dir (p)) { tpkerr ("Error in make_dir."); relmem (arg); free(tmp); return (100); } } strcat (p, "/"); } strcat (p, name); strcat (p, "."); if (style != 1 || issetdest == 2) strcat (p, dpi); /* long suffix */ strcat (p, "pk"); /* Now buff and p is the full path name of pk file */ /* check the existence of pk file */ if (_access (p, 0) == 0) { fprintf (stderr, "%s exists.\n", p); relmem (arg); printf ("%s\n", p); free(tmp); return (0); } /* * Go to the temporary directory */ cdrive = _getdrive (); if (tmp[1] == ':') { tdrive = tolower (*tmp) - 'a' + 1; _chdrive (tdrive); } _chdir (tmp); /* * save stdout and stdin */ savo = _dup (fileno (stdout)); savi = _dup (fileno (stdin)); /* * connect stdout to stderr */ _dup2 (fileno (stderr), fileno (stdout)); /* * connect stdin to nul */ if (!(fnul = fopen ("nul", "rb"))) { fprintf (stderr, "Cannot open nul device to read.\n"); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } _dup2 (fileno (fnul), fileno (stdin)); /* * pkname is the filename of PK font */ sprintf (pkname, "%s.%spk", name, dpi); if (app == 0) { /* * METAFONT command line */ if (mag[0] == 0) { tpkerr ("Cannot determine MAG."); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } sprintf (cmd, "--progname=mf --base=mf \\mode:=%s; \\mag:=%s; nonstopmode; input %s;", mode, mag, name); strcpy (execfile, "mf-nowin.exe"); fprintf (stderr, "%s %s\n", execfile, cmd); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, NULL); sprintf (cmd, "%s.%sgf", name, dpi); /* * check the consistency */ if (_access (cmd, 0) != 0) { tpkerr ("Failed to make gf font by METAFONT."); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } /* * Change gf into pk */ strcpy (execfile, "gftopk.exe"); fprintf (stderr, "%s %s %s\n", execfile, cmd, pkname); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, pkname, NULL); if (_access (pkname, 0) != 0) { tpkerr ("Failed to make pk from gf."); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } /* * erase gf file */ remove (cmd); /* * erase log file */ sprintf (cmd, "%s.log", name); remove (cmd); /* * erase tfm file */ sprintf (cmd, "%s.tfm", name); remove (cmd); goto finale; } /* * app = 1 : ps2pk --> gsftopk --> ttf2pk --> hbf2gf */ p = kpse_find_file ("pspksupp.map", kpse_fontmap_format, 0); if(p) { fr = fopen (p, "r"); /* Read pspksupp.map */ free (p); if (!fr) { tpkerr ("Cannot open pspksupp.map to read."); ps2pkok = 0; goto do_ps2pk; } while (fgets (rbuff, SBUF, fr)) { if (rbuff[0] == '%' || rbuff[0] == '#' || rbuff[0] == '\n') continue; texname[0] = pfbname[0] = slant[0] = extend[0] = encname[0] = '\0'; i = sscanf (rbuff, "%s %s %s %s %s", texname, pfbname, slant, extend, encname); if (i == 2 && !strncmp (texname, "AspectRatio", 11)) { if (!sscanf (pfbname, "%lf", &AspectRatio)) { tpkerr ("File format of pspksupp.map is wrong."); fclose (fr); ps2pkok = 0; goto do_ps2pk; } UseAspectRatio = 1; continue; } else if (i > 0 && !stricmp (texname, name)) { p = kpse_var_value ("T1FONTS"); if (!p) { tpkerr ("T1FONTS is not defined."); ps2pkok = 0; break; } free (p); p = kpse_find_file (pfbname, kpse_type1_format, 0); if (!p) { fprintf (stderr, "%s is not found.\n", pfbname); ps2pkok = 0; break; } free (p); ps2pkok = 1; if(bdpi[0] == 0) i--; break; } } fclose (fr); goto do_ps2pk; } else { char *q; char a[SBUF]; char b[SBUF]; char psname[SBUF]; char pscommand[SBUF]; double slantval, extendval; texname[0] = pfbname[0] = encname[0] = '\0'; a[0] = b[0] = psname[0] = pscommand[0] = '\0'; FileName = 0; strcpy(slant, "0"); strcpy(extend, "1"); ps2pkok = 0; p = kpse_find_file ("ps2pk.map", kpse_fontmap_format, 0); if(!p) { tpkerr("Necessary map file for ps2pk is not found."); goto do_ps2pk; } fr = fopen(p,"rb"); free(p); if (!fr) { tpkerr ("Cannot open ps2pk.map to read."); goto do_ps2pk; } while ((ret=ffgets (rbuff, LBUF, fr)) != FFILE_END) { if(ret == BBUFF_FUL) { fprintf(stderr, "A line in ps2pk.map seems to be too long.\n"); fprintf(stderr, "I try to continue. But something may be wrong.\n"); } p = rbuff; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) continue; q = texname; while(!isskip(*p) && (*p != '\n')) *q++ = *p++; *q = '\0'; if(stricmp(texname, name)) continue; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) { fprintf(stderr, "Incorrect line in \"ps2pk.map\".\n"); break; } if(FileName) q = a; else q = psname; while(!isskip(*p) && (*p != '\n')) *q++ = *p++; *q = '\0'; skipchar(&p); /* skip flag */ if(!FileName) { while(isdigit(*p)) p++; skipchar(&p); } if((*p == '%') || (*p == '#') || (*p == '\n')) { tpkerr("I cannot use ps2pk due to lack of data."); break; } if(*p == '\"') { q = pscommand; *q++ = *p++; while(*p != '\"') *q++ = *p++; *q++ = *p++; *q = '\0'; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; } if(FileName && a[0] == '\0') q = a; else if(FileName && b[0] == '\0') q = b; else { tpkerr("Incorrect line in ps2pk.map."); break; } while(!isskip(*p) && (*p != '\n')) *q++ = *p++; *q = '\0'; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; if(*p == '\"') { q = pscommand; *q++ = *p++; while(*p != '\"') *q++ = *p++; *q++ = *p++; *q = '\0'; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; } if (FileName && a[0] == '\0') q = a; else if (FileName && b[0] == '\0') q = b; else { fprintf(stderr, "Incorrect line in \"ps2pk.map\".\n"); break; } while(!isskip(*p) && (*p != '\n')) *q++ = *p++; *q = '\0'; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; if(*p == '\"') { q = pscommand; *q++ = *p++; while(*p != '\"') *q++ = *p++; *q++ = *p++; *q = '\0'; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; } skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; else { fprintf(stderr, "Incorrect line in \"ps2pk.map\".\n"); break; } } fclose(fr); if(pscommand[0]) { p = strstr(pscommand, "SlantFont"); if(p) { p--; while(*p == ' ' || *p == '\t') p--; while(*p != ' ' && *p != '\t' && *p != '\"') p--; p++; sscanf(p, "%lf SlantFont", &slantval); sprintf(slant, "%lf", slantval); p = slant + strlen(slant) - 1; while(*p == '0') { *p = '\0'; p--; } } p = strstr(pscommand, "ExtendFont"); if(p) { p--; while(*p == ' ' || *p == '\t') p--; while(*p != ' ' && *p != '\t' && *p != '\"') p--; p++; sscanf(p, "%lf ExtendFont", &extendval); sprintf(extend, "%lf", extendval); p = extend + strlen(extend) - 1; while(*p == '0') { *p = '\0'; p--; } } } if(a[0]) { p = strrchr(a, '.'); if(p && !stricmp(p, ".enc")) { *p = '\0'; strcpy(encname, a); } else if(p && !stricmp(p, ".pfb")) { *p = '\0'; strcpy(pfbname, a); } } if(b[0]) { p = strrchr(b, '.'); if(p && !stricmp(p, ".enc")) { *p = '\0'; strcpy(encname, b); } else if(p && !stricmp(p, ".pfb")) { *p = '\0'; strcpy(pfbname, b); } } if(pfbname[0] == '\0') goto do_ps2pk; p = kpse_find_file (pfbname, kpse_type1_format, 0); if(!p) goto do_ps2pk; free(p); ps2pkok = 1; if(encname[0] && bdpi[0]) { i = 5; } else if(!encname[0] && !bdpi[0]) { i = 3; } else { i = 4; } } do_ps2pk: if (ps2pkok) { if (UseAspectRatio) { sscanf (dpi, "%lf", &Xdpi); Ydpi = Xdpi * AspectRatio; sprintf (ydpi, "%d", (int) Ydpi); } else strcpy (ydpi, dpi); strcpy(tfname, name); strcat(tfname, ".tfm"); get_designsize(tfname, designsize); if (i == 3) { sprintf (cmd, "-X%s -Y%s -S%s -E%s -P%s %s %s", dpi, ydpi, slant, extend, designsize, pfbname, pkname); } else if (i == 4 && bdpi[0]) { sprintf (cmd, "-X%s -Y%s -R%s -S%s -E%s -P%s %s %s", dpi, ydpi, bdpi, slant, extend, designsize, pfbname, pkname); } else if (i == 4 && encname[0]) { sprintf (cmd, "-e%s -X%s -Y%s -S%s -E%s -P%s %s %s", encname, dpi, ydpi, slant, extend, designsize, pfbname, pkname); } else if (i == 5) { sprintf (cmd, "-e%s -X%s -Y%s -R%s -S%s -E%s -P%s %s %s", encname, dpi, ydpi, bdpi, slant, extend, designsize, pfbname, pkname); } else { tpkerr ("File format of pspksupp.map is wrong."); goto do_gsftopk; } strcpy (execfile, "ps2pk.exe"); fprintf (stderr, "%s %s\n", execfile, cmd); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, NULL); if (_access (pkname, 0) != 0) { tpkerr ("ps2pk failed to make pk font."); goto do_gsftopk; } goto finale; } /* * ps2pk is impossible to use */ do_gsftopk: tpkerr ("ps2pk cannot be used."); tpkerr ("I try gsftopk."); app = 2; strcpy (execfile, "gsftopk.exe"); fprintf (stderr, "%s %s %s\n", execfile, name, dpi); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, name, dpi, NULL); if (_access (pkname, 0) != 0) { tpkerr ("gsftopk cannot be used."); tpkerr ("Next I try ttf2pk."); app = 3; strcpy (execfile, "ttf2pk.exe"); fprintf (stderr, "%s -q %s %s\n", execfile, name, dpi); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, "-q", name, dpi, NULL); if (_access (pkname, 0) != 0) { tpkerr ("ttf2pk failed."); tpkerr ("Finally I try hbf2gf."); app = 4; strcpy (execfile, "hbf2gf.exe"); fprintf (stderr, "%s -q -p %s %s\n", execfile, name, dpi); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, "-q -p", name, dpi, NULL); sprintf (cmd, "%s.%sgf", name, dpi); if (_access (cmd, 0) != 0) { tpkerr ("All trials failed."); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } strcpy (execfile, "gftopk.exe"); fprintf (stderr, "%s %s %s\n", execfile, cmd, pkname); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, pkname, NULL); if (_access (pkname, 0) != 0) { tpkerr ("All trials failed."); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } remove (cmd); } } finale: /* * return to original stdout and stdin */ _dup2 (savo, fileno (stdout)); close (savo); _dup2 (savi, fileno (stdin)); close (savi); /* * close nul device */ fclose (fnul); /* * copy the pk file */ if (!(fr = fopen (pkname, "rb"))) { fprintf (stderr, "Cannot open %s to read.\n", pkname); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } if (!(fw = fopen (buff, "wb"))) { fprintf (stderr, "Cannot open %s to write.\n", buff); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } while ((i = (int)fread (rbuff, 1, LBUF, fr))) fwrite (rbuff, 1, i, fw); fclose (fr); fclose (fw); remove (pkname); relmem (arg); /* * update ls-R if it exists */ mktexupd (buff); /* * tell kpathsea */ printf ("%s\n", buff); _chdrive (cdrive); _chdir (currdir); free(tmp); return (0); }
#else # ifdef SIGINT signal (SIGINT, sigint_handler); # endif # ifdef SIGQUIT signal (SIGQUIT, sigint_handler); # endif # ifdef SIGHUP signal (SIGHUP, sigint_handler); # endif # ifdef SIGTERM signal (SIGTERM, sigint_handler); # endif #endif dvilj = kpse_var_value ("DVILJ"); spool = kpse_var_value ("SPOOL"); tmpdir = kpse_var_value ("TMPDIR"); opt[0] = '\0'; if(!tmpdir) tmpdir = kpse_var_value ("TMP"); if(!tmpdir) tmpdir = kpse_var_value ("TEMP"); /* Set default values for variables: ${DVILJ=dvilj4} the dvilj variant to run ${SPOOL=lpr} used to print an LJ file ${TMPDIR=/tmp} for the dvicopy output */ if (!dvilj || !*dvilj)
int main (int ac, char **av) { char rbuff[TBUF]; char buff[TBUF]; char savebuff[TBUF]; char cmd[TBUF]; char mffile[TBUF]; char *arg[4]; static char execfile[TBUF]; char kpsedot[TBUF]; char currdir[TBUF]; char *tmp; int cdrive, tdrive; FILE *fr, *fw, *fnul; int i, savo, savi; char *p, *fp, *fpp; int issetdest; char fontname[TBUF]; char texbindir[TBUF]; char fullbin[TBUF]; kpse_set_program_name (av[0], NULL); progname = kpse_program_name; /* * get tex binary dir * */ p = kpse_var_value("SELFAUTOLOC"); if(p == 0) { fprintf(stderr, "I cannot get SELFAUTOLOC\n"); exit(100); } strcpy(texbindir, p); free(p); for(p=texbindir; *p; p++) { if(*p == '/') *p = '\\'; } *p = '\\'; *(p+1) = '\0'; tmp = getenv ("TEMP"); if (!tmp) tmp = getenv ("TMP"); if (!tmp) tmp = getenv ("TMPDIR"); if (!tmp) { fprintf (stderr, "Please define TEMP | TMP | TMPDIR.\n"); return (100); } tmp = xstrdup(tmp); for (fpp = tmp; *fpp; fpp++) { if (IS_KANJI(fpp)) fpp++; else if (*fpp == '\\') *fpp = '/'; } /* issetdest = 0 : TDS issetdest = 1 : user setting issetdest = 2 : current directory */ issetdest = 0; if (ac < 2) { usage (); free(tmp); return (100); } if ((!strcmp (av[1], "--version")) || (!strcmp (av[1], "-version"))) { version (); free(tmp); return (100); } if ((!strcmp (av[1], "--help")) || (!strcmp (av[1], "-help"))) { help (); free(tmp); return (100); } for (i = 0; i < 4; i++) arg[i] = (char *) malloc (TBUF); if ((!strcmp (av[1], "--destdir")) || (!strcmp (av[1], "-destdir"))) { if (ac != 4) { usage (); relmem (arg); free(tmp); return (100); } issetdest = 1; if (strlen(av[2]) > TBUF - 1 || strlen(av[3]) > TBUF - 1) { fprintf (stderr, "Too long a string.\n"); return (100); } strcpy (buff, av[2]); strcpy (fontname, av[3]); for (p = buff; *p; p++) { if (IS_KANJI(p)) p++; else if (*p == '\\') *p = '/'; } } else { if (strlen(av[1]) > TBUF - 1) { fprintf (stderr, "Too long a string.\n"); return (100); } strcpy (fontname, av[1]); } /* fontname = font name */ if ((p = strrchr (fontname, '.'))) *p = '\0'; /* mffile is METAFONT file name */ strcpy (mffile, fontname); strcat (mffile, ".mf"); if (!(fp = kpse_var_value ("MFINPUTS"))) { fprintf (stderr, "Cannot get value of MFINPUTS\n"); relmem (arg); free(tmp); return (100); } free (fp); xputenv("MKTEXMF", "1"); if (!(p = kpse_find_file (mffile, kpse_mf_format, 1))) { fprintf (stderr, "Cannot find %s.\n", mffile); relmem (arg); free(tmp); return (100); } fpp = _getcwd (currdir, TBUF); if (!fpp) { fprintf (stderr, "Failed to get current working directory.\n"); relmem (arg); free(tmp); return (100); } for (fpp = currdir; *fpp; fpp++) { if (IS_KANJI(fpp)) fpp++; else if (*fpp == '\\') *fpp = '/'; } i = (int)strlen (currdir); if (currdir[i - 1] == '/') currdir[i - 1] = '\0'; strcpy (kpsedot, "KPSE_DOT=.;"); strcat (kpsedot, currdir); _putenv (kpsedot); if ((p[0] == '.') && (p[1] == '/') && (issetdest != 1)) { issetdest = 2; strcpy (buff, currdir); } if (issetdest == 0) { /* now path of ${name}.mf is in p */ strcpy (arg[0], "Dummy"); strcpy (arg[1], "tfm"); strcpy (arg[2], p); if (!(p = getdestdir (3, arg))) { fprintf (stderr, "Cannot get destination directory name.\n"); relmem (arg); free(tmp); return (100); } strcpy (buff, p); } /* Now buff is the destdir */ p = buff; i = (int)strlen (p); if (p[i - 1] != '/') strcat (p, "/"); strcat (p, fontname); strcat (p, ".tfm"); /* now p (or buff) is the full path name of the tfm font */ /* check if it exists */ if (_access (p, 0) == 0) { fprintf (stderr, "%s exists\n", p); printf ("%s\n", p); relmem (arg); free(tmp); return (0); } cdrive = _getdrive (); if (tmp[1] == ':') { tdrive = tolower (*tmp) - 'a' + 1; _chdrive (tdrive); } _chdir (tmp); /* save stdout and stdin */ savo = _dup (fileno (stdout)); savi = _dup (fileno (stdin)); /* connect stdout to stderr */ _dup2 (fileno (stderr), fileno (stdout)); /* connect stdin to nul device */ if (!(fnul = fopen ("nul", "r"))) { fprintf (stderr, "Cannot open nul device to read\n"); relmem (arg); _chdrive (cdrive); _chdir (currdir); free(tmp); return (100); } _dup2 (fileno (fnul), fileno (stdin)); /* METAFONT command line */ strcpy (cmd, "--progname=mf --base=mf "); strcat (cmd, "\\mode:=ljfour; \\mag:=1; nonstopmode; input "); strcat (cmd, fontname); strcat (cmd, ";"); strcpy (execfile, "mf-nowin.exe"); fprintf (stderr, "%s %s\n", execfile, cmd); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, NULL); /* return to original stdout and stdin */ _dup2 (savo, fileno (stdout)); close (savo); _dup2 (savi, fileno (stdin)); close (savi); /* close nul device */ fclose (fnul); /* check consistency */ strcpy (cmd, fontname); strcat (cmd, ".600gf"); if (_access (cmd, 0) == -1) { fprintf (stderr, "METAFONT failed to make gf font.\n"); relmem (arg); _chdrive (cdrive); _chdir (currdir); free(tmp); return (100); } remove (cmd); strcpy (cmd, fontname); strcat (cmd, ".tfm"); /* copy the tfm file */ if (!(fr = fopen (cmd, "rb"))) { fprintf (stderr, "Cannot open %s to read\n", cmd); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } if (!(fw = fopen (buff, "wb"))) { fprintf (stderr, "Cannot open %s to write\n", buff); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } while ((i = (int)fread (rbuff, 1, TBUF, fr))) fwrite (rbuff, 1, i, fw); fclose (fr); fclose (fw); strcpy(savebuff, buff); /* copy log file into the current directory in the case that issetdest == 2, because feynmf package requires the log file. */ if(issetdest == 2) { i = (int)strlen(buff); if(i > 3) { i -= 4; buff[i] = '\0'; strcat(buff, ".log"); strcpy(cmd, fontname); strcat(cmd, ".log"); if (!(fr = fopen (cmd, "rb"))) { fprintf (stderr, "Cannot open %s to read\n", cmd); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } if (!(fw = fopen (buff, "wb"))) { fprintf (stderr, "Cannot open %s to write\n", buff); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } while ((i = (int)fread (rbuff, 1, TBUF, fr))) fwrite (rbuff, 1, i, fw); fclose (fr); fclose (fw); } } relmem (arg); if(issetdest != 2) mktexupd (savebuff); /* erase files */ strcpy (cmd, fontname); strcat (cmd, ".log"); remove (cmd); strcpy (cmd, fontname); strcat (cmd, ".tfm"); remove (cmd); _chdrive (cdrive); _chdir (currdir); /* send message to Kpathsea */ printf ("%s\n", savebuff); free(tmp); return (0); }
char * getdestdir (int ac, char **av) { static char buff[MPATH]; char *pb[NUMBUF]; char *p, *q; char spec[32]; int i, Num = 0, ispk, k; char *topdir; ispk = 0; for (i = 0; i < NUMBUF; i++) { if (!(pb[i] = (char *) malloc (LENBUF))) { fatal ("Memory allocation error."); return (NULL); } } if (ac != 3 && ac != 4) { fatal ("Argument error."); for (k = 0; k < NUMBUF; k++) free (pb[k]); return (NULL); } strcpy (spec, av[1]); normalize (av[2]); /* path */ p = av[2]; q = buff; /* UNC name support */ if (p[0] == '/' && p[1] == '/') { *q++ = *p++; *q++ = *p++; } while (*p) { if (*p == '/') { *q = *p; while (*p == '/') p++; p--; } else { *q = *p; } p++; q++; } *q = '\0'; /* now path name of ${name}.mf is in buff. */ /* #ifdef TEST return xstrdup(buff); #endif */ if (ac == 4) ispk = 1; /* called from mktexpk */ if (!(p = strrchr (buff, '/'))) { fatal ("Invalid path name."); for (k = 0; k < NUMBUF; k++) free (pb[k]); return (NULL); } *p = '\0'; /* get directory name */ for (i = 0; i < NUMBUF; i++) { if (!(p = strrchr (buff, '/'))) { fatal ("Invalid path name."); for (k = 0; k < NUMBUF; k++) free (pb[k]); return (NULL); } *p = '\0'; p++; strcpy (pb[i], p); if (!stricmp (pb[i], FTOP)) { Num = i; break; } } Num -= 2; if (Num < 0) { fprintf (stderr, "Font resources should be under a directory "); fprintf (stderr, "with the name \"fonts\".\n"); fprintf (stderr, "Furthermore, there must be at least two directories "); fprintf (stderr, "under the directory \"fonts\".\n"); fatal ("Invalid path name."); for (k = 0; k < NUMBUF; k++) free (pb[k]); return (NULL); } topdir = kpse_var_value ("MAKETEXPK_TOP_DIR"); if (topdir && *topdir && ispk) { normalize (topdir); i = (int)strlen (topdir); while(topdir[i - 1] == '/') i--; topdir[i] = '\0'; if(!is_dir(topdir)) { if(make_dir_p(topdir)) { fprintf(stderr, "Failed to access %s.\n", topdir); return NULL; } } #ifdef TEST printf ("%s\n", topdir); #endif if (strnicmp (&topdir[i - 3], "/pk", 3) != 0) { strcat (topdir, "/pk"); if (!is_dir(topdir)) { if (make_dir(topdir)) { fprintf(stderr, "Faild to access %s.\n", topdir); for (k = 0; k < NUMBUF; k++) free (pb[k]); return (NULL); } } } strcpy (buff, topdir); free(topdir); } else { if((topdir = kpse_var_value("TEXMFVAR")) != NULL) { normalize (topdir); i = (int)strlen (topdir); while(topdir[i - 1] == '/') i--; topdir[i] = '\0'; if(!is_dir(topdir)) { if(make_dir_p(topdir)) { fprintf(stderr, "Failed to access %s.\n", topdir); return NULL; } } strcpy(buff, topdir); free(topdir); } strcat (buff, "/fonts"); if (!is_dir (buff)) { if (make_dir (buff)) { for (k = 0; k < NUMBUF; k++) free (pb[k]); return (NULL); } } strcat (buff, "/"); strcat (buff, spec); if (!is_dir (buff)) { if (make_dir (buff)) { for (k = 0; k < NUMBUF; k++) free (pb[k]); return (NULL); } } } if (ispk) { strcat (buff, "/"); strcat (buff, av[3]); if (!is_dir (buff)) { if (make_dir (buff)) { for (k = 0; k < NUMBUF; k++) free (pb[k]); return (NULL); } } } for (i = Num; i > -1; i--) { strcat (buff, "/"); strcat (buff, pb[i]); if (is_dir (buff)) continue; else { if (make_dir (buff)) { for (k = 0; k < NUMBUF; k++) free (pb[k]); return (NULL); } } } for (k = 0; k < NUMBUF; k++) free (pb[k]); p = xstrdup(buff); return p; }
void mktexupd (char *s) { char fname[MBUF]; char lsrname[SBUF]; char path[LBUF]; char *rootdir[MAXTREE]; int i, j, treenum; char *pa, *pb, *pc; int existflag = 0; FILE *f; pa = kpse_var_value (DBS); if (pa == NULL) { fprintf (stderr, "No definition of TEXMFDBS.\n"); fprintf (stderr, "Maybe you are not using ls-R.\n"); return; } pb = kpse_brace_expand (pa); free (pa); if (pb == NULL) { fprintf (stderr, "I cannot expand braces in TEXMFDBS.\n"); fprintf (stderr, "Maybe you are not using ls-R.\n"); return; } for (i = 0; i < MAXTREE; i++) rootdir[i] = (char *) malloc (MBUF); pa = pb; i = 0; while (*pa && i < MAXTREE) { if (*pa == '!' && *(pa + 1) == '!') { pa++; pa++; } pc = rootdir[i]; while (*pa != ';' && *pa) *pc++ = *pa++; *pc = '\0'; if (*pa == ';') { pa++; i++; } } i++; treenum = i; free (pb); for (i = 0; i < treenum; i++) { j = strlen (rootdir[i]); if (rootdir[i][j - 1] == '/') rootdir[i][j - 1] = '\0'; } strcpy (path, s); pa = strrchr (path, '/'); if (pa == NULL) { fprintf (stderr, "Path name of the file may be incorrect.\n"); for (i = 0; i < MAXTREE; i++) free (rootdir[i]); return; } *pa = '\0'; pa++; strcpy (fname, pa); for (i = 0; i < treenum; i++) { j = strlen (rootdir[i]); if (j && strnicmp (path, rootdir[i], j) == 0) { existflag = 1; break; } } if (existflag) { strcpy (lsrname, rootdir[i]); strcat (lsrname, "/ls-R"); if (_access (lsrname, 0) != 0) { for (j = 0; j < MAXTREE; j++) free (rootdir[j]); return; } pa = path; pb = rootdir[i]; while (tolower (*pa) == tolower (*pb) && *pb) { pa++; pb++; } f = fopen (lsrname, "ab"); fprintf (f, "\n.%s:\n%s\n", pa, fname); fclose (f); } else { fprintf(stderr, "mktexupd failed\n"); } for (i = 0; i < MAXTREE; i++) free (rootdir[i]); }
int mf_mftalk_initscreen (void) { int app; /* Client application type. */ char *prog, *name; /* Client program name. */ /* Size of METAFONT window. */ char height[MAX_INT_LENGTH], width[MAX_INT_LENGTH]; /* Inherited pipe handles. */ char input[MAX_INT_LENGTH], output[MAX_INT_LENGTH]; char parent[MAX_INT_LENGTH]; /* My own process ID. */ int sc_pipe[2]; /* Server->Client pipe. */ int cs_pipe[2]; /* Client->Server pipe. */ int res, ack; /* Wait until child is ready. */ prog = kpse_var_value ("MFTALK"); if (prog == NULL) prog = "mftalk.exe"; name = app_type (prog, &app); if (!name) return 0; if (pipe (sc_pipe) == -1) return 0; if (pipe (cs_pipe) == -1) { close (sc_pipe[0]); close (sc_pipe[1]); return 0; } #ifdef OS2 fatal (setmode, setmode (sc_pipe[0], O_BINARY) == -1); fatal (setmode, setmode (sc_pipe[1], O_BINARY) == -1); fatal (setmode, setmode (cs_pipe[0], O_BINARY) == -1); fatal (setmode, setmode (cs_pipe[1], O_BINARY) == -1); #endif old = signal (SIGCHLD, child_died); fatal (old, old == SIG_ERR); sprintf (height, "-h%d", screendepth); sprintf (width, "-w%d", screenwidth); sprintf (input, "-i%d", sc_pipe[0]); sprintf (output, "-o%d", cs_pipe[1]); sprintf (parent, "-p%d", getpid ()); #ifdef OS2 pid = spawnl (app, name, prog, height, width, input, output, parent, NULL); #else pid = fork (); if (pid == 0) { fatal (close, close (0) == -1); fatal (dup, dup (sc_pipe[0]) != 0); fatal (close, close (sc_pipe[0]) == -1); fatal (close, close (sc_pipe[1]) == -1); fatal (close, close (1) == -1); fatal (dup, dup (cs_pipe[1]) != 1); fatal (close, close (cs_pipe[0]) == -1); fatal (close, close (cs_pipe[1]) == -1); /* We still pass the file handles as parameters for * backward compatibility. instead of sc_pipe[0] and * cs_pipe[1] we just pass 0 (stdin) and 1 (stdout). */ sprintf (input, "-i0"); sprintf (output, "-o1"); execl (name, prog, height, width, input, output, parent, NULL); } #endif /* not OS2 */ switch (pid) { case -1: failure: fatal (close, close (sc_pipe[0]) == -1); fatal (close, close (sc_pipe[1]) == -1); fatal (close, close (cs_pipe[0]) == -1); fatal (close, close (cs_pipe[1]) == -1); fatal (signal, signal (SIGCHLD, old) == SIG_ERR); break; default: res = read (cs_pipe[0], &ack, sizeof (int)); if (res != sizeof (int) || ack != MF_ACK) goto failure; fatal (close, close (cs_pipe[0]) == -1); win = sc_pipe[1]; break; } return (win == -1) ? 0 : 1; }