Debian Codegraph @

texk/kpathsea/win32/mkpaths.c

raw
1 /* mkpaths.c
2
3 Copyright 2015, 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 char **
23 mkpaths (int *numptr)
24 {
25 char **pathbuff;
26 char *texmfdbs;
27 char *p, *pa, *pc;
28 int i;
29
30 if (!(p = kpse_var_value ("TEXMFDBS"))) {
31 fprintf (stderr, "No definition of TEXMFDBS.\n");
32 return NULL;
33 }
34
35 texmfdbs = kpse_brace_expand (p);
36 free (p);
37 if (!texmfdbs) {
38 fprintf (stderr, "I cannot expand braces in TEXMFDBS.\n");
39 return NULL;
40 }
41
42 p = texmfdbs;
43 i = 0;
44
45 while(*p) {
46 if(*p == '!' && *(p+1) == '!')
47 p += 2;
48 if(*p == ';')
49 while(*p == ';')
50 p++;
51 if(*p && *p != '!') {
52 while(*p != ';' && *p)
53 p++;
54 i++;
55 while(*p == ';')
56 p++;
57 }
58 }
59
60 if (!i) {
61 free (texmfdbs);
62 fprintf (stderr, "No database paths in TEXMFDBS.\n");
63 return NULL;
64 }
65
66 *numptr = i;
67 pathbuff = xmalloc(i * sizeof(char *));
68
69 p = texmfdbs;
70 i = 0;
71
72 while (*p) {
73 if (*p == '!' && *(p + 1) == '!')
74 p += 2;
75 if (*p == ';') {
76 while (*p == ';')
77 p++;
78 }
79 if(*p && *p != '!') {
80 pa = p;
81 while(*p != ';' && *p)
82 p++;
83 pc = p;
84 pathbuff[i] = xmalloc(pc - pa + 1);
85 strncpy(pathbuff[i], pa, pc - pa);
86 pathbuff[i][pc - pa] = 0;
87 i++;
88 while(*p == ';')
89 p++;
90 }
91 }
92
93 free(texmfdbs);
94 return pathbuff;
95 }