diff options
author | Peter Breitenlohner <peb@mppmu.mpg.de> | 2011-08-10 06:20:40 +0000 |
---|---|---|
committer | Peter Breitenlohner <peb@mppmu.mpg.de> | 2011-08-10 06:20:40 +0000 |
commit | 56e0b73ad25c9335dbb3f13d12e117ed5ccc34e6 (patch) | |
tree | a7ce24a19af5318af7d3426e0eaf52a17a465e8b /Build/source/texk/kpathsea/win32/mktexfmt.c | |
parent | e9b6e32afa1f6ee5db62ee28bf91cc4a4737f48b (diff) |
WIN32: more C program replacements for Unix shell scripts (from Akira's W32TeX)
git-svn-id: svn://tug.org/texlive/trunk@23477 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/kpathsea/win32/mktexfmt.c')
-rw-r--r-- | Build/source/texk/kpathsea/win32/mktexfmt.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/Build/source/texk/kpathsea/win32/mktexfmt.c b/Build/source/texk/kpathsea/win32/mktexfmt.c new file mode 100644 index 00000000000..3b38aa038b7 --- /dev/null +++ b/Build/source/texk/kpathsea/win32/mktexfmt.c @@ -0,0 +1,95 @@ +/* mktexfmt.c + */ + +#include <kpathsea/kpathsea.h> + +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; +} |