beta-0.89.2
[luatex.git] / source / texk / kpathsea / win32 / mktexupd.c
blobc05ae1f74b87c9f936b8299c9ccdc2ee0bdec779
1 /* mktexupd.c
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/>.
19 #include <kpathsea/kpathsea.h>
20 #include "mktex.h"
22 #define MBUF 512
23 #define SBUF 512
24 #define LBUF 512
26 void
27 mktexupd (char *s)
29 char fname[MBUF];
30 char lsrname[SBUF];
31 char path[LBUF];
32 char **pathbuff;
33 int i, j, numtree;
34 char *pa, *pb;
35 int existflag = 0;
36 FILE *f;
38 if (!(pathbuff = mkpaths (&numtree))) {
39 fprintf (stderr, "Maybe you are not using ls-R.\n");
40 return;
43 for (i = 0; i < numtree; i++) {
44 j = (int)strlen (pathbuff[i]);
45 if (pathbuff[i][j - 1] == '/')
46 pathbuff[i][j - 1] = '\0';
49 strcpy (path, s);
50 pa = strrchr (path, '/');
51 if (pa == NULL) {
52 fprintf (stderr, "Path name of the file may be incorrect.\n");
53 for (i = 0; i < numtree; i++)
54 free (pathbuff[i]);
55 free (pathbuff);
56 return;
59 *pa = '\0';
60 pa++;
61 strcpy (fname, pa);
63 for (i = 0; i < numtree; i++) {
64 j = (int)strlen (pathbuff[i]);
65 if (j && strnicmp (path, pathbuff[i], j) == 0) {
66 existflag = 1;
67 break;
71 if (existflag) {
72 strcpy (lsrname, pathbuff[i]);
73 strcat (lsrname, "/ls-R");
74 if (_access (lsrname, 0) != 0) {
75 for (j = 0; j < numtree; j++)
76 free (pathbuff[j]);
77 free (pathbuff);
78 return;
80 pa = path;
81 pb = pathbuff[i];
82 while (tolower (*pa) == tolower (*pb) && *pb) {
83 pa++;
84 pb++;
86 f = fopen (lsrname, "ab");
87 fprintf (f, "\n.%s:\n%s\n", pa, fname);
88 fclose (f);
89 } else
90 fprintf(stderr, "mktexupd failed\n");
91 for (i = 0; i < numtree; i++)
92 free (pathbuff[i]);
93 free (pathbuff);