Beispiel #1
0
bool SplitFileSysURL(LPCTSTR url, String& dir_out, String& fname_out)
{
	if (!_tcsnicmp(url, TEXT("file://"), 7)) {
		url += 7;

		 // remove third slash in front of drive characters
		if (*url == '/')
			++url;
	}

	if (exists_path(url)) {
		TCHAR path[_MAX_PATH];

		 // convert slashes to back slashes
		GetFullPathName(url, COUNTOF(path), path, NULL);

		if (GetFileAttributes(path) & FILE_ATTRIBUTE_DIRECTORY)
			fname_out.erase();
		else {
			TCHAR drv[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];

			_tsplitpath_s(path, drv, COUNTOF(drv), dir, COUNTOF(dir), fname, COUNTOF(fname), ext, COUNTOF(ext));
			_stprintf(path, TEXT("%s%s"), drv, dir);

			fname_out.printf(TEXT("%s%s"), fname, ext);
		}

		dir_out = path;

		return true;
	} else
		return false;
}
Beispiel #2
0
struct inclist *inc_path(char *file, char *include, boolean dot, struct IncludesCollection *incCollection)
{
    static char path[ BUFSIZ ];
    char   **pp, *p;
    struct inclist *ip;
    struct stat st;
    boolean found = FALSE;
    (void)dot;

    /*
     * Check all previously found include files for a path that
     * has already been expanded.
     */
    for (ip = inclist; ip->i_file; ip++)
        if ((strcmp(ip->i_incstring, include) == 0) && !ip->i_included_sym)
        {
          found = TRUE;
          break;
        }

    /*
     * If the path was surrounded by "" or is an absolute path,
     * then check the exact path provided.
     */
// FIXME: creates duplicates in the dependency files if absolute paths are
// given, which certainly is not the intended behavior. Also it slows down
// makedepend performance considerably.
//  if (!found && (dot || *include == '/')) {
//
//      if ((exists_path(incCollection, include)) && stat(include, &st) == 0 && !( st.st_mode & S_IFDIR)) {
//          ip = newinclude(include, include);
//          found = TRUE;
//      }
//      else if (show_where_not)
//          warning1("\tnot in %s\n", include);
//  }

    /*
     * See if this include file is in the directory of the
     * file being compiled.
     */
    if (!found) {
        for (p=file+strlen(file); p>file; p--)
            if (*p == '/')
                break;
        if (p == file)
            strcpy(path, include);
        else {
            strncpy(path, file, (p-file) + 1);
            path[ (p-file) + 1 ] = '\0';
            strcpy(path + (p-file) + 1, include);
        }
        remove_dotdot(path);
        if ((exists_path(incCollection, path)) && stat(path, &st) == 0 && !( st.st_mode & S_IFDIR)) {
            ip = newinclude(path, include);
            found = TRUE;
        }
        else if (show_where_not)
            warning1("\tnot in %s\n", path);
    }

    /*
     * Check the include directories specified. (standard include dir
     * should be at the end.)
     */
    if (!found)
        for (pp = includedirs; *pp; pp++) {
            sprintf(path, "%s/%s", *pp, include);
            remove_dotdot(path);
            if ((exists_path(incCollection, path)) && stat(path, &st) == 0 && !(st.st_mode & S_IFDIR)) {
                ip = newinclude(path, include);
                found = TRUE;
                break;
            }
            else if (show_where_not)
                warning1("\tnot in %s\n", path);
        }

    if (!found)
        ip = NULL;
    return(ip);
}