dvitomp fix from Akira
[mplib] / src / texk / kpathsea / absolute.c
1 /* absolute.c: test if a filename is absolute or explicitly relative.
2
3    Copyright 1993, 1994, 1995, 2008 Karl Berry.
4    Copyright 1997, 2002, 2005 Olaf Weber.
5
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public License
17    along with this library; if not, see <http://www.gnu.org/licenses/>.  */
18
19 #include <kpathsea/config.h>
20
21 #include <kpathsea/absolute.h>
22 #include <kpathsea/c-pathch.h>
23
24 /* Sorry this is such a system-dependent mess, but I can't see any way
25    to usefully generalize.  */
26
27 boolean
28 kpse_absolute_p P2C(const_string, filename,  boolean, relative_ok)
29 {
30 #ifdef VMS
31 #include <string.h>
32   return strcspn (filename, "]>:") != strlen (filename);
33 #else /* not VMS */
34   boolean absolute = IS_DIR_SEP (*filename)
35 #ifdef DOSISH
36                      /* Novell allows non-alphanumeric drive letters. */
37                      || (*filename && IS_DEVICE_SEP (filename[1]))
38 #endif /* DOSISH */
39 #ifdef AMIGA
40                      /* Colon anywhere means a device.  */
41                      || strchr (filename, ':')
42 #endif /* AMIGA */
43                       ;
44   boolean explicit_relative
45     = relative_ok
46 #ifdef AMIGA
47       /* Leading / is like `../' on Unix and DOS.  Allow Unix syntax,
48          too, though, because of possible patch programs like
49          `UnixDirsII' by Martin Scott.  */
50       && IS_DIR_SEP (*filename) || 0
51 #endif /* AMIGA */
52       && (*filename == '.' && (IS_DIR_SEP (filename[1])
53                          || (filename[1] == '.' && IS_DIR_SEP (filename[2]))));
54
55   /* FIXME: On UNIX an IS_DIR_SEP of any but the last character in the name
56      implies relative.  */
57   return absolute || explicit_relative;
58 #endif /* not VMS */
59 }
60
61 #ifdef TEST
62 int main()
63 {
64   char **name;
65   char *t[] = { "./foo", "\\\\server\\foo\\bar", "ftp://localhost/foo" };
66
67   for (name = t; name - t < sizeof(t)/sizeof(char*); name++) {
68     printf("Path `%s' %s absolute.\n", *name, (kpse_absolute_p(*name, true) ? "is" : "is not"));
69   }
70 }
71 #endif /* TEST */