3 Copyright 2000, 2015 Akira Kakuto.
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this library; if not, see <http://www.gnu.org/licenses/>.
22 #include <kpathsea/kpathsea.h>
26 int main(int ac
, char **av
)
37 kpse_set_program_name(av
[0], NULL
);
39 p
= kpse_program_name
;
41 fprintf(stderr
,"%s : Usage %s formatname\n", p
, p
);
42 fprintf(stderr
,"formatname : (foo.fmt, foo.nfmt, foo.mem, foo.base)\n");
45 if(!strncmp(av
[1], "-h", 2) || !strncmp(av
[1], "--h", 3)) {
46 fprintf(stderr
,"%s : Usage %s formatname\n", p
, p
);
47 fprintf(stderr
,"formatname : (foo.fmt, foo.nfmt, foo.mem, foo.base)\n");
50 if(!strncmp(av
[1], "-v", 2) || !strncmp(av
[1], "--v", 3)) {
51 fprintf(stderr
,"%s : Version %s\n", p
, VERSION
);
55 if(strlen(av
[1]) > 127) {
56 fprintf(stderr
, "\nToo long a format name.\n");
60 p
= kpse_var_value("SELFAUTOLOC");
62 fprintf(stderr
, "I cannot get SELFAUTOLOC\n");
67 for(p
=texbindir
; *p
; p
++) {
68 if(*p
== '/') *p
= '\\';
70 strcat(texbindir
, "\\");
72 strcpy(orgname
, av
[1]);
74 p
= strrchr(av
[1], '.');
76 fprintf(stderr
, "formatname needs a suffix.\n");
80 if(stricmp(p
, ".fmt") && stricmp(p
, ".nfmt") &&
81 stricmp(p
, ".base") && stricmp(p
, ".mem")) {
82 fprintf(stderr
, "%s : unknown format type.\n", av
[1]);
88 /* save stdout and stdin */
89 savo
= _dup(fileno(stdout
));
90 savi
= _dup(fileno(stdin
));
92 /* connect stdout to stderr */
93 _dup2(fileno(stderr
), fileno(stdout
));
95 /* connect stdin to nul device */
96 if(!(fnul
= fopen("nul", "r"))) {
97 fprintf(stderr
, "Cannot open nul device to read\n");
100 _dup2(fileno(fnul
), fileno(stdin
));
103 strcpy(fullbin
, texbindir
);
104 strcat(fullbin
, "fmtutil.exe");
105 fprintf(stderr
, "Running the command %s\n", fullbin
);
106 _spawnlp(_P_WAIT
, fullbin
, "fmtutil", "--byfmt", av
[1], NULL
);
110 /* return to original stdout and stdin */
111 _dup2(savo
, fileno(stdout
));
113 _dup2(savi
, fileno(stdin
));
116 /* close nul device */
119 fmtname
= kpse_find_file(orgname
, kpse_fmt_format
, 0);
121 printf("%s\n", fmtname
);