beta-0.89.2
[luatex.git] / source / texk / kpathsea / win32 / mktexlsr.c
bloba7926f7eb5ee95ea06e64cd46346d59536b9f9b3
1 /* mktexlsr.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/>.
18 Web2C 2010 (2010/08/22 --ak)
21 #include <kpathsea/kpathsea.h>
22 #ifndef __MINGW32__
23 #include <kpathsea/dirent.h>
24 #endif
25 #include "mktex.h"
27 /* magic header */
28 #define HDL "%% ls-R -- filename database for kpathsea; do not change this line.\n"
30 #define VARTEXFONTS "c:/var/tex/fonts/ls-R"
32 FILE *ls_R;
34 static void
35 search(char *name)
37 DIR *dp;
38 struct dirent *de;
39 char buff[256];
40 int len;
42 normalize (name);
44 if((dp = opendir(name))) {
45 fprintf(ls_R, "\n%s:\n", name);
46 while((de = readdir(dp))) {
47 if(stricmp(de->d_name, ".") &&
48 stricmp(de->d_name, "..") &&
49 stricmp(de->d_name, ".bzr") &&
50 stricmp(de->d_name, ".git") &&
51 stricmp(de->d_name, ".hg") &&
52 stricmp(de->d_name, ".svn") &&
53 stricmp(de->d_name, "_bzr") &&
54 stricmp(de->d_name, "_git") &&
55 stricmp(de->d_name, "_hg") &&
56 stricmp(de->d_name, "_svn") &&
57 stricmp(de->d_name, "_darcs")) {
58 fprintf(ls_R, "%s\n", de->d_name);
61 closedir(dp);
63 len = (int)strlen(name);
64 strcpy(buff, name);
65 if(name[len-1] != '/') {
66 strcat(buff, "/");
67 len++;
70 dp = opendir(name);
71 while((de = readdir(dp))) {
72 if(stricmp(de->d_name, ".") &&
73 stricmp(de->d_name, "..") &&
74 stricmp(de->d_name, ".bzr") &&
75 stricmp(de->d_name, ".git") &&
76 stricmp(de->d_name, ".hg") &&
77 stricmp(de->d_name, ".svn") &&
78 stricmp(de->d_name, "_bzr") &&
79 stricmp(de->d_name, "_git") &&
80 stricmp(de->d_name, "_hg") &&
81 stricmp(de->d_name, "_svn") &&
82 stricmp(de->d_name, "_darcs")) {
83 #ifdef __MINGW32__
84 strcpy(buff + len, de->d_name);
85 if(!is_dir(buff))
86 continue;
87 #else
88 if(!de->d_isdir)
89 continue;
90 strcpy(buff + len, de->d_name);
91 #endif
92 search(buff);
95 closedir(dp);
99 int Quiet = 0;
101 char first_name[] = "./";
103 int main(int ac, char **av)
105 int cdrive, tdrive;
106 char ls_R_name[512];
107 int i, numtree;
108 size_t len;
109 char *progname;
110 char **pathbuff;
112 kpse_set_program_name(av[0], NULL);
113 progname = kpse_program_name;
115 if(ac > 1 && (!strncmp(av[1], "-v", 2) || !strncmp(av[1], "--v", 3))) {
116 puts (kpathsea_version_string);
117 puts ("mktexlsr: (C version 1.1 --ak 2002-2015)");
118 exit (0);
121 if(ac > 1 && (!strncmp(av[1], "-h", 2) || !strncmp(av[1], "--h", 3))) {
122 printf("Usage: %s [--quiet|--silent] [DIRS ...]\n\n"
123 "Rebuild all necessary ls-R filename databases completely. If one or\n"
124 "more arguments DIRS are given, these are used as texmf directories to\n"
125 "build ls-R for. Else all directories in the search path for ls-R files\n"
126 "($TEXMFDBS) are used.", av[0]);
127 exit (0);
130 if(ac > 1) {
131 if(!strncmp(av[1], "-q", 2) || !strncmp(av[1], "--q", 3) ||
132 !strncmp(av[1], "-s", 2) || !strncmp(av[1], "--s", 3)) {
133 Quiet = 1;
134 ac--;
135 av++;
139 if(ac > 1) {
140 numtree = ac - 1;
141 pathbuff = xmalloc(numtree * sizeof(char *));
142 for(i=0; i < numtree; i++) {
143 pathbuff[i] = xstrdup(av[i+1]);
144 normalize (pathbuff[i]);
146 } else {
147 if (!(pathbuff = mkpaths (&numtree))) {
148 fprintf (stderr, "Maybe you are not using ls-R.\n");
149 exit (100);
153 for(i = 0; i < numtree; i++) {
154 strcpy(ls_R_name, pathbuff[i]);
155 len = strlen(ls_R_name);
156 if(ls_R_name[len-1] != '/') strcat(ls_R_name, "/");
157 strcat(ls_R_name, "ls-R");
159 ls_R = fopen(ls_R_name, "wb");
160 if(!ls_R) {
161 fprintf(stdout, "Cannot open %s to write.\n", ls_R_name);
162 if(!stricmp(ls_R_name, VARTEXFONTS))
163 fprintf(stdout, " (Don't mind this message.)\n");
164 continue;
167 cdrive = _getdrive();
169 if(ls_R_name[1] == ':') {
170 tdrive = tolower(ls_R_name[0]) - 'a' + 1;
171 _chdrive(tdrive);
174 _chdir(pathbuff[i]);
175 if(!Quiet)
176 fprintf(stdout, "%s: Updating %s...\n", progname, ls_R_name);
177 fprintf(ls_R, HDL);
178 search(first_name);
180 fclose(ls_R);
181 if(!Quiet)
182 fprintf(stdout, "%s: Updated %s.\n", progname, ls_R_name);
183 _chdrive(cdrive);
186 if(!Quiet)
187 fprintf(stdout, "%s: Done.\n", progname);
189 for(i = 0; i < numtree; i++) {
190 free(pathbuff[i]);
193 free (pathbuff);
195 return 0;