summaryrefslogtreecommitdiff
path: root/atari/findfile.c
diff options
context:
space:
mode:
authorOle Loots <ole@monochrom.net>2013-10-26 17:24:09 +0200
committerOle Loots <ole@monochrom.net>2013-10-26 17:24:09 +0200
commit77129038ee8aa8ccdf8f4a264fd1189459e69326 (patch)
treedacbbc96fb24b913b9daa57626b5ce253bf993d5 /atari/findfile.c
parent164571aa98871d47f2efda842d75507f9bd03150 (diff)
downloadnetsurf-77129038ee8aa8ccdf8f4a264fd1189459e69326.tar.gz
netsurf-77129038ee8aa8ccdf8f4a264fd1189459e69326.tar.bz2
Handle the fact that / is NOT the root of the filesystem on MiNT.
(/ means current drive!) This may break under Classic TOS versions, because it may rely on the U: drive. However, that can be fixed later on.
Diffstat (limited to 'atari/findfile.c')
-rwxr-xr-xatari/findfile.c71
1 files changed, 22 insertions, 49 deletions
diff --git a/atari/findfile.c b/atari/findfile.c
index d4c4c308d..61dc3a292 100755
--- a/atari/findfile.c
+++ b/atari/findfile.c
@@ -37,6 +37,9 @@ char * local_file_to_url( const char * filename )
{
#define BACKSLASH 0x5C
char * url;
+
+ LOG(("in: %s", filename));
+
if( strlen(filename) <= 2){
return( NULL );
}
@@ -45,22 +48,6 @@ char * local_file_to_url( const char * filename )
char * start = (char*)fname_local;
strcpy( start, filename );
- /* if path points to unified filesystem, skip that info: */
- if( fname_local[1] == ':' && fname_local[0] == 'U' ){
- start = &fname_local[2];
- }
-
- /* if we got something like "C:\folder\file.txt", handle that: */
- if( start[1] == ':' ){
- start[1] = (char)tolower(start[0]);
- start++;
- }
-
- /* skip leading slash, already included in file scheme: */
- if( start[0] == (char)BACKSLASH || start[0] == '/' ){
- start++;
- }
-
/* convert backslashes: */
for( unsigned int i=0; i<strlen(start); i++ ){
if( start[i] == BACKSLASH ){
@@ -70,11 +57,13 @@ char * local_file_to_url( const char * filename )
// TODO: make file path absolute if it isn't yet.
url = malloc( strlen(start) + FILE_SCHEME_PREFIX_LEN + 1);
- strcpy( url, FILE_SCHEME_PREFIX );
- strcat( url, start );
+ strcpy(url, FILE_SCHEME_PREFIX );
+ strcat(url, start );
free(fname_local);
+ LOG(("out: %s", url));
+
return( url );
#undef BACKSLASH
}
@@ -83,27 +72,11 @@ char * local_file_to_url( const char * filename )
char *path_to_url(const char *path_in)
{
#define BACKSLASH 0x5C
- char * path_ptr=NULL;
char * path;
- LOG(("path2url in: %s\n", path_in));
- if (*path_in == '/') {
- path_in++; /* file: path is are already absolute */
- path = (char*)path_in;
- } else {
- path = path_ptr = (char*)malloc(PATH_MAX+1);
- gemdos_realpath(path_in, path);
+ LOG(("path2url in: %s\n", path_in));
- if( *path == '/' || *path == BACKSLASH ) {
- path++;
- }
- if( sys_type() != SYS_MINT ){
- if( path[1] == ':' ) {
- path[1] = path[0];
- path++;
- }
- }
- }
+ path = (char*)path_in;
int urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1;
char *url = malloc(urllen);
@@ -117,8 +90,7 @@ char *path_to_url(const char *path_in)
}
i++;
}
- if( path_ptr )
- free( path_ptr );
+
LOG(("path2url out: %s\n", url));
return url;
#undef BACKSLASH
@@ -130,21 +102,22 @@ char *url_to_path(const char *url)
char *url_path = curl_unescape(url, 0);
char *path;
char abspath[PATH_MAX+1];
- LOG(( "url2path in: %s\n", url ));
- /* printf( "url2path in: %s\n", url_path ); */
- /* return the absolute path including leading / */
- /* todo: better check for filesystem? */
- if( sys_type() & SYS_MINT ) {
- /* it's ok to have relative paths with mint, just strip proto: */
- path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN -1));
+
+ LOG(( "url2path in: %s (%s)\n", url, url_path ));
+
+ // is the URL relative?
+ if (url_path[7] == '.') {
+ // yes, make it absolute...
+ gemdos_realpath(url_path + (FILE_SCHEME_PREFIX_LEN-1), abspath);
+ path = strdup(abspath);
} else {
- /* do not include / within url_path */
- char * tmp = url_path + (FILE_SCHEME_PREFIX_LEN-1);
- gemdos_realpath( tmp, (char*)&abspath );
- path = strdup( (char*)&abspath );
+ path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN));
}
+
curl_free(url_path);
+
LOG(( "url2path out: %s\n", path ));
+
return path;
}