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/>.
18 Assumes the cx mode in mf.base .
19 Usage: mktextfm [--destdir DESTDIR] name
22 #include <kpathsea/kpathsea.h>
24 #include <web2c/w2c/c-auto.h>
37 fprintf (stderr
, "Usage: %s [--destdir destdir] name\n", progname
);
44 fprintf (stderr
, "%s, (C version 1.5 --ak 2009-2012)\n", progname
);
45 fprintf (stderr
, KPSEVERSION WEB2CVERSION
"\n");
52 fprintf (stderr
, "Usage (1): %s name\n", progname
);
53 fprintf (stderr
, " tfm is saved following TDS\n");
54 fprintf (stderr
, "Usage (2): %s --destdir destdir name\n", progname
);
55 fprintf (stderr
, " destdir must be an absolute path of dir\n");
56 fprintf (stderr
, "Usage (3): %s --version\n", progname
);
57 fprintf (stderr
, "Usage (4): %s --help\n", progname
);
66 for (j
= 0; j
< 4; j
++)
72 main (int ac
, char **av
)
80 static char execfile
[SBUF
];
97 kpse_set_program_name (av
[0], NULL
);
98 progname
= kpse_program_name
;
104 p
= kpse_var_value("SELFAUTOLOC");
106 fprintf(stderr
, "I cannot get SELFAUTOLOC\n");
109 strcpy(texbindir
, p
);
111 for(p
=texbindir
; *p
; p
++) {
112 if(*p
== '/') *p
= '\\';
117 tmp
= getenv ("TEMP");
119 tmp
= getenv ("TMP");
121 tmp
= getenv ("TMPDIR");
123 fprintf (stderr
, "Please define TEMP | TMP | TMPDIR.\n");
129 for (fpp
= tmp
; *fpp
; fpp
++) {
132 else if (*fpp
== '\\')
137 issetdest = 1 : user setting
138 issetdest = 2 : current directory
149 if ((!strcmp (av
[1], "--version")) || (!strcmp (av
[1], "-version"))) {
155 if ((!strcmp (av
[1], "--help")) || (!strcmp (av
[1], "-help"))) {
161 for (i
= 0; i
< 4; i
++)
162 arg
[i
] = (char *) malloc (SBUF
);
164 if ((!strcmp (av
[1], "--destdir")) || (!strcmp (av
[1], "-destdir"))) {
172 strcpy (buff
, av
[2]);
173 strcpy (fontname
, av
[3]);
174 for (p
= buff
; *p
; p
++) {
181 strcpy (fontname
, av
[1]);
185 /* fontname = font name
187 if ((p
= strrchr (fontname
, '.')))
190 /* mffile is METAFONT file name
192 strcpy (mffile
, fontname
);
193 strcat (mffile
, ".mf");
195 if (!(fp
= kpse_var_value ("MFINPUTS"))) {
196 fprintf (stderr
, "Cannot get value of MFINPUTS\n");
204 xputenv("MKTEXMF", "1");
205 if (!(p
= kpse_find_file (mffile
, kpse_mf_format
, 1))) {
206 fprintf (stderr
, "Cannot find %s.\n", mffile
);
212 fpp
= _getcwd (currdir
, SBUF
);
214 fprintf (stderr
, "Failed to get current working directory.\n");
219 for (fpp
= currdir
; *fpp
; fpp
++) {
222 else if (*fpp
== '\\')
226 i
= (int)strlen (currdir
);
227 if (currdir
[i
- 1] == '/')
228 currdir
[i
- 1] = '\0';
229 strcpy (kpsedot
, "KPSE_DOT=.;");
230 strcat (kpsedot
, currdir
);
233 if ((p
[0] == '.') && (p
[1] == '/') && (issetdest
!= 1)) {
235 strcpy (buff
, currdir
);
238 if (issetdest
== 0) {
239 /* now path of ${name}.mf is in p */
240 strcpy (arg
[0], "Dummy");
241 strcpy (arg
[1], "tfm");
244 if (!(p
= getdestdir (3, arg
))) {
245 fprintf (stderr
, "Cannot get destination directory name.\n");
253 /* Now buff is the destdir */
260 strcat (p
, fontname
);
263 /* now p (or buff) is the full path name of the tfm font */
264 /* check if it exists */
265 if (_access (p
, 0) == 0) {
266 fprintf (stderr
, "%s exists\n", p
);
273 cdrive
= _getdrive ();
275 tdrive
= tolower (*tmp
) - 'a' + 1;
280 /* save stdout and stdin */
281 savo
= _dup (fileno (stdout
));
282 savi
= _dup (fileno (stdin
));
284 /* connect stdout to stderr */
285 _dup2 (fileno (stderr
), fileno (stdout
));
287 /* connect stdin to nul device */
288 if (!(fnul
= fopen ("nul", "r"))) {
289 fprintf (stderr
, "Cannot open nul device to read\n");
296 _dup2 (fileno (fnul
), fileno (stdin
));
298 /* METAFONT command line */
299 strcpy (cmd
, "--progname=mf --base=mf ");
300 strcat (cmd
, "\\mode:=ljfour; \\mag:=1; nonstopmode; input ");
301 strcat (cmd
, fontname
);
304 strcpy (execfile
, "mf-nowin.exe");
305 fprintf (stderr
, "%s %s\n", execfile
, cmd
);
306 strcpy(fullbin
, texbindir
);
307 strcat(fullbin
, execfile
);
308 (void) _spawnlp (_P_WAIT
, fullbin
, execfile
, cmd
, NULL
);
310 /* return to original stdout and stdin */
311 _dup2 (savo
, fileno (stdout
));
313 _dup2 (savi
, fileno (stdin
));
316 /* close nul device */
319 /* check consistency */
320 strcpy (cmd
, fontname
);
321 strcat (cmd
, ".600gf");
323 if (_access (cmd
, 0) == -1) {
324 fprintf (stderr
, "METAFONT failed to make gf font.\n");
334 strcpy (cmd
, fontname
);
335 strcat (cmd
, ".tfm");
337 /* copy the tfm file */
338 if (!(fr
= fopen (cmd
, "rb"))) {
339 fprintf (stderr
, "Cannot open %s to read\n", cmd
);
346 if (!(fw
= fopen (buff
, "wb"))) {
347 fprintf (stderr
, "Cannot open %s to write\n", buff
);
355 while ((i
= (int)fread (rbuff
, 1, LBUF
, fr
)))
356 fwrite (rbuff
, 1, i
, fw
);
360 strcpy(savebuff
, buff
);
363 copy log file into the current directory
364 in the case that issetdest == 2,
365 because feynmf package requires the
370 i
= (int)strlen(buff
);
374 strcat(buff
, ".log");
375 strcpy(cmd
, fontname
);
377 if (!(fr
= fopen (cmd
, "rb"))) {
378 fprintf (stderr
, "Cannot open %s to read\n", cmd
);
385 if (!(fw
= fopen (buff
, "wb"))) {
386 fprintf (stderr
, "Cannot open %s to write\n", buff
);
393 while ((i
= (int)fread (rbuff
, 1, LBUF
, fr
)))
394 fwrite (rbuff
, 1, i
, fw
);
405 strcpy (cmd
, fontname
);
406 strcat (cmd
, ".log");
409 strcpy (cmd
, fontname
);
410 strcat (cmd
, ".tfm");
416 /* send message to Kpathsea */
417 printf ("%s\n", savebuff
);