Move code which extracts the filename from a given path into frontend.

svn path=/trunk/netsurf/; revision=10139
This commit is contained in:
Chris Young 2010-03-21 13:32:59 +00:00
parent 1f67fed782
commit 033b5d815a
8 changed files with 132 additions and 32 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2008, 2009 Chris Young <chris@unsatisfactorysoftware.co.uk>
* Copyright 2008-2010 Chris Young <chris@unsatisfactorysoftware.co.uk>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@ -24,6 +24,7 @@
#include "utils/messages.h"
#include <stdlib.h>
#include <curl/curl.h>
#include "utils/utils.h"
void warn_user(const char *warning, const char *detail)
{
@ -83,6 +84,18 @@ char *path_to_url(const char *path)
return r;
}
/**
* Return the filename part of a full path
*
* \param path full path and filename
* \return filename (will be freed with free())
*/
char *filename_from_path(char *path)
{
return strdup(FilePart(path));
}
/**
* returns a string without escape chars or |M chars.
* (based on remove_underscores from utils.c)

View File

@ -1160,3 +1160,23 @@ static void *myrealloc(void *ptr, size_t len, void *pw)
{
return realloc(ptr, len);
}
/**
* Return the filename part of a full path
*
* \param path full path and filename
* \return filename (will be freed with free())
*/
char *filename_from_path(char *path)
{
char *leafname;
leafname = strrchr(path, '/');
if (!leafname)
leafname = path;
else
leafname += 1;
return strdup(leafname);
}

View File

@ -1219,36 +1219,9 @@ fetch_curl_post_convert(struct form_successful_control *control)
for (; control; control = control->next) {
if (control->file) {
char *leafname = 0;
#ifdef riscos
char *temp;
int leaflen;
temp = strrchr(control->value, '.');
if (!temp)
temp = control->value; /* already leafname */
else
temp += 1;
leafname = filename_from_path(control->value);
leaflen = strlen(temp);
leafname = malloc(leaflen + 1);
if (!leafname) {
LOG(("malloc failed"));
continue;
}
memcpy(leafname, temp, leaflen + 1);
/* and s/\//\./g */
for (temp = leafname; *temp; temp++)
if (*temp == '/')
*temp = '.';
#else
leafname = strrchr(control->value, '/') ;
if (!leafname)
leafname = control->value;
else
leafname += 1;
#endif
/* We have to special case filenames of "", so curl
* a) actually attempts the fetch and
* b) doesn't attempt to open the file ""
@ -1288,9 +1261,7 @@ fetch_curl_post_convert(struct form_successful_control *control)
control->value));
free(mimetype);
}
#ifdef riscos
free(leafname);
#endif
}
else {
code = curl_formadd(&post, &last,

View File

@ -44,3 +44,23 @@ char *url_to_path(const char *url)
{
return strdup(url + 5);
}
/**
* Return the filename part of a full path
*
* \param path full path and filename
* \return filename (will be freed with free())
*/
char *filename_from_path(char *path)
{
char *leafname;
leafname = strrchr(path, '/');
if (!leafname)
leafname = path;
else
leafname += 1;
return strdup(leafname);
}

View File

@ -920,3 +920,23 @@ uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *key)
key->keyval);
}
}
/**
* Return the filename part of a full path
*
* \param path full path and filename
* \return filename (will be freed with free())
*/
char *filename_from_path(char *path)
{
char *leafname;
leafname = strrchr(path, '/');
if (!leafname)
leafname = path;
else
leafname += 1;
return strdup(leafname);
}

View File

@ -2417,3 +2417,39 @@ void PDF_Password(char **owner_pass, char **user_pass, char *path)
/*TODO:this waits to be written, until then no PDF encryption*/
*owner_pass = NULL;
}
/**
* Return the filename part of a full path
*
* \param path full path and filename
* \return filename (will be freed with free())
*/
char *filename_from_path(char *path)
{
char *leafname;
char *temp;
int leaflen;
temp = strrchr(path, '.');
if (!temp)
temp = path; /* already leafname */
else
temp += 1;
leaflen = strlen(temp);
leafname = malloc(leaflen + 1);
if (!leafname) {
LOG(("malloc failed"));
continue;
}
memcpy(leafname, temp, leaflen + 1);
/* and s/\//\./g */
for (temp = leafname; *temp; temp++)
if (*temp == '/')
*temp = '.';
return leafname;
}

View File

@ -108,5 +108,5 @@ query_id query_user(const char *query, const char *detail,
const query_callback *cb, void *pw, const char *yes, const char *no);
void query_close(query_id);
void PDF_Password(char **owner_pass, char **user_pass, char *path);
char *filename_from_path(char *path);
#endif

View File

@ -50,3 +50,23 @@ char *url_to_path(const char *url)
{
return strdup(url + 5);
}
/**
* Return the filename part of a full path
*
* \param path full path and filename
* \return filename (will be freed with free())
*/
char *filename_from_path(char *path)
{
char *leafname;
leafname = strrchr(path, '\\');
if (!leafname)
leafname = path;
else
leafname += 1;
return strdup(leafname);
}