1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#include <kpathsea/kpathsea.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <fcntl.h>
#include <direct.h>
#include <io.h>
#include <malloc.h>
#include <process.h>
#include <direct.h>
#include "mktexupd.h"
#define MBUF 128
#define SBUF 256
#define LBUF 512
#define DBS "TEXMFDBS"
#define MAXTREE 16
void
mktexupd (char *s)
{
char fname[MBUF];
char lsrname[SBUF];
char path[LBUF];
char *rootdir[MAXTREE];
int i, j, treenum;
char *pa, *pb, *pc;
int existflag = 0;
FILE *f;
pa = kpse_var_value (DBS);
if (pa == NULL) {
fprintf (stderr, "No definition of TEXMFDBS.\n");
fprintf (stderr, "Maybe you are not using ls-R.\n");
return;
}
pb = kpse_brace_expand (pa);
free (pa);
if (pb == NULL) {
fprintf (stderr, "I cannot expand braces in TEXMFDBS.\n");
fprintf (stderr, "Maybe you are not using ls-R.\n");
return;
}
for (i = 0; i < MAXTREE; i++)
rootdir[i] = (char *) malloc (MBUF);
pa = pb;
i = 0;
while (*pa && i < MAXTREE) {
if (*pa == '!' && *(pa + 1) == '!') {
pa++;
pa++;
}
pc = rootdir[i];
while (*pa != ';' && *pa)
*pc++ = *pa++;
*pc = '\0';
if (*pa == ';') {
pa++;
i++;
}
}
i++;
treenum = i;
free (pb);
for (i = 0; i < treenum; i++) {
j = strlen (rootdir[i]);
if (rootdir[i][j - 1] == '/')
rootdir[i][j - 1] = '\0';
}
strcpy (path, s);
pa = strrchr (path, '/');
if (pa == NULL) {
fprintf (stderr, "Path name of the file may be incorrect.\n");
for (i = 0; i < MAXTREE; i++)
free (rootdir[i]);
return;
}
*pa = '\0';
pa++;
strcpy (fname, pa);
for (i = 0; i < treenum; i++) {
j = strlen (rootdir[i]);
if (j && strnicmp (path, rootdir[i], j) == 0) {
existflag = 1;
break;
}
}
if (existflag) {
strcpy (lsrname, rootdir[i]);
strcat (lsrname, "/ls-R");
if (_access (lsrname, 0) != 0) {
for (j = 0; j < MAXTREE; j++)
free (rootdir[j]);
return;
}
pa = path;
pb = rootdir[i];
while (tolower (*pa) == tolower (*pb) && *pb) {
pa++;
pb++;
}
f = fopen (lsrname, "ab");
fprintf (f, "\n.%s:\n%s\n", pa, fname);
fclose (f);
} else {
fprintf(stderr, "mktexupd failed\n");
}
for (i = 0; i < MAXTREE; i++)
free (rootdir[i]);
}
|