diff options
author | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2010-07-14 22:36:04 +0000 |
---|---|---|
committer | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2010-07-14 22:36:04 +0000 |
commit | a182a36067d962802a49921a735dce53ceb5afb8 (patch) | |
tree | e2f232c9cbd9547050a10c4ba55231d6336424c9 | |
parent | a3c2b432b50c49305c60e42f5b9f1759ef3c1368 (diff) | |
download | netsurf-a182a36067d962802a49921a735dce53ceb5afb8.tar.gz netsurf-a182a36067d962802a49921a735dce53ceb5afb8.tar.bz2 |
More intelligent path concatenation
svn path=/trunk/netsurf/; revision=10639
-rwxr-xr-x | amiga/misc.c | 3 | ||||
-rw-r--r-- | render/directory.c | 121 |
2 files changed, 69 insertions, 55 deletions
diff --git a/amiga/misc.c b/amiga/misc.c index 956de1d32..d9447aca8 100755 --- a/amiga/misc.c +++ b/amiga/misc.c @@ -73,6 +73,9 @@ char *url_to_path(const char *url) if (strncmp(url, "/", SLEN("/")) == 0) url += SLEN("/"); + if(*url == '\0') + return NULL; /* file:/// is not a valid path */ + url2 = malloc(strlen(url) + 2); strcpy(url2, url); diff --git a/render/directory.c b/render/directory.c index 6ff149713..70b754d0a 100644 --- a/render/directory.c +++ b/render/directory.c @@ -145,6 +145,8 @@ bool directory_convert(struct content *c) { struct stat filestat; char *filepath, *mimetype = NULL; int filepath_size; + char *urlpath; + int urlpath_size; char moddate[100]; char modtime[100]; bool extendedinfo, evenrow = false; @@ -196,8 +198,6 @@ bool directory_convert(struct content *c) { if (res == URL_FUNC_OK) { res = url_compare(content__get_url(c), up, false, &compare); if ((res == URL_FUNC_OK) && !compare) { - if (up[strlen(up) - 1] == '/') - up[strlen(up) - 1] = '\0'; snprintf(buffer, sizeof(buffer), "<p><a href=\"%s\">%s</a></p>", up, messages_get("FileParent")); @@ -257,68 +257,79 @@ bool directory_convert(struct content *c) { return false; } - /* Start row and print item name */ - snprintf(buffer, sizeof(buffer), - "<a href=\"%s/%s\" class=\"%s %s\">" + urlpath_size = strlen(content__get_url(c)) + strlen(entry->d_name) + 2; + urlpath = malloc(urlpath_size); + if (urlpath != NULL) { + strcpy(urlpath, content__get_url(c)); + if(urlpath[strlen(urlpath) - 1] != '/') + strncat(urlpath, "/", urlpath_size); + strncat(urlpath, entry->d_name, urlpath_size); + + /* Start row and print item name */ + snprintf(buffer, sizeof(buffer), + "<a href=\"%s\" class=\"%s %s\">" "<span class=\"name\">%s</span> ", - content__get_url(c), entry->d_name, + urlpath, evenrow ? "even" : "odd", S_ISDIR(filestat.st_mode) ? "dir" : "file", entry->d_name); - binding_parse_chunk(c->data.html.parser_binding, - (uint8_t *) buffer, strlen(buffer)); - - if (extendedinfo == true) { - /* Get date in output format */ - if (strftime((char *)&moddate, sizeof moddate, - "%a %d %b %Y", - localtime(&filestat.st_mtime)) == 0) - strncpy(moddate, "-", sizeof moddate); - /* Get time in output format */ - if (strftime((char *)&modtime, sizeof modtime, - "%H:%M", - localtime(&filestat.st_mtime)) == 0) - strncpy(modtime, "-", sizeof modtime); - - if (S_ISDIR(filestat.st_mode)) { - /* Directory: Print type and date/time */ - snprintf(buffer, sizeof(buffer), - "<span class=\"type\">%s</span> " - "<span class=\"size\"></span>" - "<span class=\"size\"></span> " - "<span class=\"date\">%s</span> " - "<span class=\"time\">%s</span></a>\n", - messages_get("FileDirectory"), - moddate, modtime); + binding_parse_chunk(c->data.html.parser_binding, + (uint8_t *) buffer, strlen(buffer)); + + if (extendedinfo == true) { + /* Get date in output format */ + if (strftime((char *)&moddate, sizeof moddate, + "%a %d %b %Y", + localtime(&filestat.st_mtime)) == 0) + strncpy(moddate, "-", sizeof moddate); + /* Get time in output format */ + if (strftime((char *)&modtime, sizeof modtime, + "%H:%M", + localtime(&filestat.st_mtime)) == 0) + strncpy(modtime, "-", sizeof modtime); + + if (S_ISDIR(filestat.st_mode)) { + /* Directory: Print type and date/time */ + snprintf(buffer, sizeof(buffer), + "<span class=\"type\">%s</span> " + "<span class=\"size\"></span>" + "<span class=\"size\"></span> " + "<span class=\"date\">%s</span> " + "<span class=\"time\">%s</span></a>\n", + messages_get("FileDirectory"), + moddate, modtime); + } else { + /* File: Print type, size, and date/time */ + mimetype = fetch_mimetype(filepath); + snprintf(buffer, sizeof(buffer), + "<span class=\"type\">%s</span> " + "<span class=\"size\">%d</span>" + "<span class=\"size\">%s</span> " + "<span class=\"date\">%s</span> " + "<span class=\"time\">%s</span></a>\n", + mimetype, + filesize_value( + (unsigned long)filestat.st_size), + messages_get(filesize_unit( + (unsigned long)filestat.st_size)), + moddate, modtime); + } } else { - /* File: Print type, size, and date/time */ - mimetype = fetch_mimetype(filepath); + /* Not got info, print empty cells */ snprintf(buffer, sizeof(buffer), - "<span class=\"type\">%s</span> " - "<span class=\"size\">%d</span>" - "<span class=\"size\">%s</span> " - "<span class=\"date\">%s</span> " - "<span class=\"time\">%s</span></a>\n", - mimetype, - filesize_value( - (unsigned long)filestat.st_size), - messages_get(filesize_unit( - (unsigned long)filestat.st_size)), - moddate, modtime); + "<span class=\"type\"></span> " + "<span class=\"size\"></span>" + "<span class=\"size\"></span> " + "<span class=\"date\"></span> " + "<span class=\"time\"></span></a>\n"); } - } else { - /* Not got info, print empty cells */ - snprintf(buffer, sizeof(buffer), - "<span class=\"type\"></span> " - "<span class=\"size\"></span>" - "<span class=\"size\"></span> " - "<span class=\"date\"></span> " - "<span class=\"time\"></span></a>\n"); - } - binding_parse_chunk(c->data.html.parser_binding, - (uint8_t *) buffer, strlen(buffer)); + binding_parse_chunk(c->data.html.parser_binding, + (uint8_t *) buffer, strlen(buffer)); + + free(urlpath); + } if (evenrow == false) evenrow = true; |