Improved path conversion for DOS Filesystems.

svn path=/trunk/netsurf/; revision=12236
This commit is contained in:
Ole Loots 2011-04-23 20:09:24 +00:00
parent 8d2bb4bd3a
commit 45778bbb36
5 changed files with 137 additions and 64 deletions

View File

@ -182,7 +182,7 @@ struct gui_download_window *gui_download_window_create(download_context *ctx,
strcat( tpath, "/");
}
strcat( tpath, filename );
gdos_realpath(tpath, tpath2);
gemdos_realpath(tpath, tpath2);
gdw->destination = malloc(strlen(tpath2) + 2);
strcpy(gdw->destination, tpath2);
gdw->fd = fopen(gdw->destination, "wb" );

View File

@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <curl/curl.h>
#include <windom.h>
@ -32,16 +33,32 @@
#include "atari/misc.h"
#include "atari/osspec.h"
char *path_to_url(const char *path)
char *path_to_url(const char *path_in)
{
/* printf("path2url in: %s\n", path); */
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);
if( *path == '/' || *path == 0x5C ) {
path++;
}
if( sys_type() != SYS_MINT ){
if( path[1] == ':' ) {
path[1] = path[0];
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);
int i=0;
@ -51,8 +68,9 @@ char *path_to_url(const char *path)
}
i++;
}
/* printf("path2url out: %s\n", url); */
if( path_ptr )
free( path_ptr );
LOG(("path2url out: %s\n", url));
return url;
}
@ -61,31 +79,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 ) {
path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1));
/* it's ok to have relative paths with mint, just strip proto: */
path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN -1));
} else {
/* do not include / within url_path */
char * drive = url_path + (FILE_SCHEME_PREFIX_LEN);
path = malloc( strlen(drive) + 4 );
int i=0;
path[i++] = drive[0];
path[i++] = ':';
path[i++] = 0x5C;
while( drive[i-1] != 0){
path[i] = drive[i-1];
if( path[i] == '/' ){
path[i] = 0x5C;
}
i++;
}
path[i] = 0;
LOG(("%s", path));
char * tmp = url_path + (FILE_SCHEME_PREFIX_LEN-1);
gemdos_realpath( tmp, (char*)&abspath );
path = strdup( (char*)&abspath );
}
curl_free(url_path);
/* printf( "url2path out: %s\n", path ); */
LOG(( "url2path out: %s\n", path ));
return path;
}
@ -113,7 +122,7 @@ char * atari_find_resource(char *buf, const char *filename, const char *def)
strcpy(t, NETSURF_GEM_RESPATH);
strcat(t, filename);
LOG(("checking %s", (char*)&t));
if (gdos_realpath(t, buf) != NULL) {
if (gemdos_realpath(t, buf) != NULL) {
if (access(buf, R_OK) == 0) {
return buf;
}
@ -121,7 +130,7 @@ char * atari_find_resource(char *buf, const char *filename, const char *def)
strcpy(t, "./");
strcat(t, filename);
LOG(("checking %s", (char*)&t));
if (gdos_realpath(t, buf) != NULL) {
if (gemdos_realpath(t, buf) != NULL) {
if (access(buf, R_OK) == 0) {
return buf;
}
@ -133,7 +142,7 @@ char * atari_find_resource(char *buf, const char *filename, const char *def)
strcat(t, "/.netsurf/");
strcat(t, filename);
LOG(("checking %s", (char*)&t));
if (gdos_realpath(t, buf) != NULL) {
if (gemdos_realpath(t, buf) != NULL) {
if (access(buf, R_OK) == 0)
return buf;
}
@ -141,7 +150,7 @@ char * atari_find_resource(char *buf, const char *filename, const char *def)
cdir = getenv("NETSURFRES");
if (cdir != NULL) {
if (gdos_realpath(cdir, buf) != NULL) {
if (gemdos_realpath(cdir, buf) != NULL) {
strcat(buf, "/");
strcat(buf, filename);
LOG(("checking %s", (char*)&t));
@ -152,12 +161,12 @@ char * atari_find_resource(char *buf, const char *filename, const char *def)
if (def[0] == '~') {
snprintf(t, PATH_MAX, "%s%s", getenv("HOME"), def + 1);
LOG(("checking %s", (char*)&t));
if (gdos_realpath(t, buf) == NULL) {
if (gemdos_realpath(t, buf) == NULL) {
strcpy(buf, t);
}
} else {
LOG(("checking %s", (char*)def));
if (gdos_realpath(def, buf) == NULL) {
if (gemdos_realpath(def, buf) == NULL) {
strcpy(buf, def);
}
}

View File

@ -150,17 +150,22 @@ void gui_poll(bool active)
}
}
if( evnt.timer >= 0 ) {
/*printf("time: %d, active: %d, pending: %d\n", evnt.timer,
active, browser_reformat_pending );*/
if( evnt.timer > 0 ) {
flags |= MU_TIMER;
EvntWindom( flags );
}
EvntWindom( flags );
struct gui_window * g;
for( g = window_list; g != NULL; g=g->next ) {
if( browser_redraw_required( g ) ){
browser_redraw( g );
}
}
hotlist_redraw();
if( evnt.timer != 0 && !active ){
/* this suits for stuff with lower priority */
hotlist_redraw();
}
}
struct gui_window *
@ -1088,6 +1093,8 @@ static void gui_init(int argc, char** argv)
nkc_init();
atari_plotter_init( option_atari_screen_driver, option_atari_font_driver );
LOG(("Knockout rendering: %s\n", option_atari_knockout ? "yes" : "no"));
plot_set_knockout( option_atari_knockout );
/* Interface colours */
option_gui_colour_bg_1 = 0xFFFFFF; /** Background (bbggrr) */
option_gui_colour_fg_1 = 0xFF0000; /** Foreground (bbggrr) */
@ -1124,18 +1131,14 @@ int main(int argc, char** argv)
setbuf(stderr, NULL);
setbuf(stdout, NULL);
#ifdef WITH_DBG_LOGFILE
verbose_log = true;
freopen("stdout.log", "a+", stdout);
freopen("stderr.log", "a+", stderr);
#endif
ApplInit();
graf_mouse(BUSY_BEE, NULL);
init_os_info();
atari_find_resource((char*)&messages, "messages", "res/messages");
atari_find_resource((char*)&options, "Choices", "Choices");
netsurf_init(&argc, &argv, options, messages);
gui_init(argc, argv);
gui_init2(argc, argv);

View File

@ -42,6 +42,7 @@ unsigned short _systype (void)
_systype_v |= SYS_XAAES;
}
}
LOG(("Detected OS: %d\n", _systype_v ));
return _systype_v;
}
@ -104,32 +105,92 @@ int tos_getcookie(long tag, long * value)
return( C_NOTFOUND );
}
/* convert nonsense getcwd path (returned by mintlib getcwd on plain TOS) */
void fix_path(char * path)
{
char npath[PATH_MAX];
/* only apply fix to paths that contain /dev/ */
if( strlen(path) < 6 ){
return;
}
if( strncmp(path, "/dev/", 5) != 0 ) {
/* path is okay, nothing to fix: */
return;
}
strncpy((char*)&npath, path, PATH_MAX);
npath[0] = path[5];
npath[1] = ':';
npath[2] = 0;
strcat((char*)&npath, &path[6]);
strcpy(path, (char*)&npath);
LOG(("fixed path: %s\n", path ));
}
/*
a fixed version of realpath() which returns valid
paths for TOS which have no root fs. (/ , U: )
*/
char * gdos_realpath(const char * path, char * rpath)
char * gemdos_realpath(const char * path, char * rpath)
{
char work[PATH_MAX+1];
char * work_ptr;
size_t l;
printf("gdos rpath in: %s\n", path);
if( rpath == NULL ){
return( NULL );
}
if( sys_type() & SYS_MINT ){
return( realpath(path, rpath) );
}
memset( rpath, 0, PATH_MAX );
/* first, absolutize relative path: */
if( *path == '.' ){
char cwd[PATH_MAX+1];
getcwd((char*)&cwd, PATH_MAX);
l = strlen( cwd );
if( cwd[l-1] != 0x5C && cwd[l-1] != '/' ){
cwd[l] = 0x5C;
cwd[l+1] = 0;
l++;
}
strncpy( (char*)&work, cwd, PATH_MAX );
/* check for path, or maybe just a file name? */
if( strlen(path) > 2 ) {
int off = 0;
if( path[1] == '/' || path[1] == 0x5C ){
off = 2;
}
strncat( (char*)&work, (char*)(path+off), PATH_MAX-l );
}
work_ptr = (char*)&work;
} else {
work_ptr = (char*)path;
}
/* handle invalid cwd path */
/* mintlib produces these on plain TOS systems: */
if( strncmp( (char*)work_ptr, "/dev/", 5) == 0 ){
work_ptr += 4;
}
/* make TOS compatible path, step 1: */
l = strlen( work_ptr);
if( l > 1 ){
if( *work_ptr == '/' || *work_ptr == 0x5C ){
rpath[0] = work_ptr[1];
rpath[1] = ':';
strncat( rpath, &work_ptr[2], PATH_MAX-2 );
} else {
strncpy( rpath, work_ptr, PATH_MAX );
}
/* step 2, perform seperator conversion: */
l = strlen( rpath );
rpath[PATH_MAX-1]=0;
work_ptr = rpath;
do{
if( *work_ptr == '/' )
*work_ptr = 0x5C;
work_ptr++;
} while( *work_ptr != 0 );
if( rpath[l-1] == 0x5C || rpath[l-1] == '/' )
rpath[l-1] = 0;
} else {
strcpy( rpath, work_ptr );
}
l = strlen( rpath );
printf("gdos rpath out: %s\n", rpath);
return( rpath );
}
char * gemdos_realpathX(const char * path, char * rpath)
{
size_t l;
size_t i;
@ -141,12 +202,12 @@ char * gdos_realpath(const char * path, char * rpath)
if( sys_type() & SYS_MINT ){
return( realpath(path, rpath) );
}
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);
//fix_path((char*)&cwd);
strcpy(rpath, (char*)&cwd);
l = strlen(rpath);
/* append path seperator if needed: */

View File

@ -57,6 +57,6 @@ extern unsigned short _systype_v;
void init_os_info(void);
int tos_getcookie( long tag, long * value );
void fix_path(char * path);
char * gdos_realpath(const char * path, char * rpath);
char * gemdos_realpath(const char * path, char * rpath);
unsigned short _systype (void);
#endif