| 1 |
/* mktexupd.c |
| 2 |
|
| 3 |
Copyright 2000, 2016 Akira Kakuto. |
| 4 |
|
| 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. |
| 9 |
|
| 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. |
| 14 |
|
| 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/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include <kpathsea/kpathsea.h> |
| 20 |
#include "mktex.h" |
| 21 |
|
| 22 |
#define MBUF 512 |
| 23 |
#define SBUF 512 |
| 24 |
#define LBUF 512 |
| 25 |
|
| 26 |
void |
| 27 |
mktexupd (char *s) |
| 28 |
{ |
| 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; |
| 37 |
|
| 38 |
if (!(pathbuff = mkpaths (&numtree))) { |
| 39 |
fprintf (stderr, "Maybe you are not using ls-R.\n"); |
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 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'; |
| 47 |
} |
| 48 |
|
| 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; |
| 57 |
} |
| 58 |
|
| 59 |
*pa = '\0'; |
| 60 |
pa++; |
| 61 |
strcpy (fname, pa); |
| 62 |
|
| 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; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 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; |
| 79 |
} |
| 80 |
pa = path; |
| 81 |
pb = pathbuff[i]; |
| 82 |
while (tolower (*pa) == tolower (*pb) && *pb) { |
| 83 |
pa++; |
| 84 |
pb++; |
| 85 |
} |
| 86 |
f = fopen (lsrname, "ab"); |
| 87 |
fprintf (f, "\n.%s:\n%s\n", pa, fname); |
| 88 |
fclose (f); |
| 89 |
} |
| 90 |
for (i = 0; i < numtree; i++) |
| 91 |
free (pathbuff[i]); |
| 92 |
free (pathbuff); |
| 93 |
} |