Back to index

tetex-bin  3.0
absolute.c
Go to the documentation of this file.
00001 /* absolute.c: Test if a filename is absolute or explicitly relative.
00002 
00003 Copyright (C) 1993, 94, 95 Karl Berry.
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Library General Public
00007 License as published by the Free Software Foundation; either
00008 version 2 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Library General Public License for more details.
00014 
00015 You should have received a copy of the GNU Library General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00018 
00019 #include <kpathsea/config.h>
00020 
00021 #include <kpathsea/absolute.h>
00022 #include <kpathsea/c-pathch.h>
00023 
00024 /* Sorry this is such a system-dependent mess, but I can't see any way
00025    to usefully generalize.  */
00026 
00027 boolean
00028 kpse_absolute_p P2C(const_string, filename,  boolean, relative_ok)
00029 {
00030 #ifdef VMS
00031 #include <string.h>
00032   return strcspn (filename, "]>:") != strlen (filename);
00033 #else /* not VMS */
00034   boolean absolute = IS_DIR_SEP (*filename)
00035 #ifdef DOSISH
00036                      /* Novell allows non-alphanumeric drive letters. */
00037                      || (*filename && IS_DEVICE_SEP (filename[1]))
00038 #endif /* DOSISH */
00039 #ifdef AMIGA
00040                    /* Colon anywhere means a device.  */
00041                    || strchr (filename, ':')
00042 #endif /* AMIGA */
00043                     ;
00044   boolean explicit_relative
00045     = relative_ok
00046 #ifdef AMIGA
00047       /* Leading / is like `../' on Unix and DOS.  Allow Unix syntax,
00048          too, though, because of possible patch programs like
00049          `UnixDirsII' by Martin Scott.  */
00050       && IS_DIR_SEP (*filename) || 0
00051 #endif /* AMIGA */
00052       && (*filename == '.' && (IS_DIR_SEP (filename[1])
00053                          || (filename[1] == '.' && IS_DIR_SEP (filename[2]))));
00054 
00055   /* FIXME: On UNIX an IS_DIR_SEP of any but the last character in the name
00056      implies relative.  */
00057   return absolute || explicit_relative;
00058 #endif /* not VMS */
00059 }
00060 
00061 #ifdef TEST
00062 int main()
00063 {
00064   char **name;
00065   char *t[] = { "./foo", "\\\\server\\foo\\bar", "ftp://localhost/foo" };
00066 
00067   for (name = t; name - t < sizeof(t)/sizeof(char*); name++) {
00068     printf("Path `%s' %s absolute.\n", *name, (kpse_absolute_p(*name, true) ? "is" : "is not"));
00069   }
00070 }
00071 #endif /* TEST */