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 argv[0] = "Dummy", argv[1] = "source", argv[2] = path
21 argv[0] = "Dummy", argv[1] = "pk", argv[2] = path, argv[3] = mode
23 argv[0] = "Dummy", argv[1] = "tfm", argv[2] = path
26 #include <kpathsea/kpathsea.h>
38 fprintf (stderr
, "%s\n", s
);
42 getdestdir (int ac
, char **av
)
44 static char buff
[MPATH
];
48 int i
, Num
= 0, ispk
, k
;
53 for (i
= 0; i
< NUMBUF
; i
++) {
54 if (!(pb
[i
] = (char *) malloc (LENBUF
))) {
55 fatal ("Memory allocation error.");
60 if (ac
!= 3 && ac
!= 4) {
61 fatal ("Argument error.");
62 for (k
= 0; k
< NUMBUF
; k
++)
69 normalize (av
[2]); /* path */
74 /* UNC name support */
76 if (p
[0] == '/' && p
[1] == '/') {
93 *q
= '\0'; /* now path name of ${name}.mf is in buff. */
100 ispk
= 1; /* called from mktexpk */
102 if (!(p
= strrchr (buff
, '/'))) {
103 fatal ("Invalid path name.");
104 for (k
= 0; k
< NUMBUF
; k
++)
109 *p
= '\0'; /* get directory name */
111 for (i
= 0; i
< NUMBUF
; i
++) {
112 if (!(p
= strrchr (buff
, '/'))) {
113 fatal ("Invalid path name.");
114 for (k
= 0; k
< NUMBUF
; k
++)
121 if (!stricmp (pb
[i
], FTOP
)) {
129 fprintf (stderr
, "Font resources should be under a directory ");
130 fprintf (stderr
, "with the name \"fonts\".\n");
131 fprintf (stderr
, "Furthermore, there must be at least two directories ");
132 fprintf (stderr
, "under the directory \"fonts\".\n");
133 fatal ("Invalid path name.");
134 for (k
= 0; k
< NUMBUF
; k
++)
139 topdir
= kpse_var_value ("MAKETEXPK_TOP_DIR");
140 if (topdir
&& *topdir
&& ispk
) {
142 i
= (int)strlen (topdir
);
143 while(topdir
[i
- 1] == '/')
147 if(!is_dir(topdir
)) {
148 if(make_dir_p(topdir
)) {
149 fprintf(stderr
, "Failed to access %s.\n", topdir
);
154 printf ("%s\n", topdir
);
156 if (strnicmp (&topdir
[i
- 3], "/pk", 3) != 0) {
157 strcat (topdir
, "/pk");
158 if (!is_dir(topdir
)) {
159 if (make_dir(topdir
)) {
160 fprintf(stderr
, "Faild to access %s.\n", topdir
);
161 for (k
= 0; k
< NUMBUF
; k
++)
167 strcpy (buff
, topdir
);
170 if((topdir
= kpse_var_value("TEXMFVAR")) != NULL
) {
172 i
= (int)strlen (topdir
);
173 while(topdir
[i
- 1] == '/')
177 if(!is_dir(topdir
)) {
178 if(make_dir_p(topdir
)) {
179 fprintf(stderr
, "Failed to access %s.\n", topdir
);
184 strcpy(buff
, topdir
);
188 strcat (buff
, "/fonts");
189 if (!is_dir (buff
)) {
190 if (make_dir (buff
)) {
191 for (k
= 0; k
< NUMBUF
; k
++)
198 if (!is_dir (buff
)) {
199 if (make_dir (buff
)) {
200 for (k
= 0; k
< NUMBUF
; k
++)
209 strcat (buff
, av
[3]);
210 if (!is_dir (buff
)) {
211 if (make_dir (buff
)) {
212 for (k
= 0; k
< NUMBUF
; k
++)
219 for (i
= Num
; i
> -1; i
--) {
221 strcat (buff
, pb
[i
]);
225 if (make_dir (buff
)) {
226 for (k
= 0; k
< NUMBUF
; k
++)
233 for (k
= 0; k
< NUMBUF
; k
++)
242 main (int ac
, char *av
[])
244 kpse_set_program_name (av
[0], "getdestdir");
245 printf ("%s", getdestdir (ac
, av
));