/* * Copyright 2010 Ole Loots * * This file is part of NetSurf, http://www.netsurf-browser.org/ * * NetSurf is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * * NetSurf is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include "utils/log.h" #include "utils/url.h" #include "atari/findfile.h" #include "atari/gui.h" #include "atari/misc.h" #include "atari/osspec.h" static void fix_path(char * path); char *path_to_url(const char *path) { int urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; char *url = malloc(urllen); if (*path == '/') { path++; /* file: paths are already absolute */ } snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path); return url; } char *url_to_path(const char *url) { char *url_path = curl_unescape(url, 0); char *path; /* return the absolute path including leading / */ if( atari_sysinfo.gdosversion > TOS4VER ) { path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1)); } else { /* do not include / within ulr_path */ path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN)); int l = strlen(path); int i; for( i = 0; i TOS4VER ){ return( realpath(path, rpath) ); } if( fsep == '/') { /* replace '\' with / */ old = 0x5C; /* / */ } else { /* replace '/' with \ */ old = '/'; } if( path[0] != '/' && path[0] != 0x5c && path[1] != ':') { /* it is not an absolute path */ char cwd[PATH_MAX]; getcwd((char*)&cwd, PATH_MAX); fix_path((char*)&cwd); strcpy(rpath, (char*)&cwd); l = strlen(rpath); if(rpath[l-1] != 0x5C && rpath[l-1] != '/') { rpath[l] = fsep; rpath[l+1] = 0; } if( (path[1] == '/' || path[1] == 0x5C ) ) { strcat(rpath, &path[2]); } else { strcat(rpath, path); } } else { strcpy(rpath, path); } /* convert path seperator to configured value: */ l = strlen(rpath); for( i = 0; i