move filename_from_path and path_add_part into gui operation tables

This commit is contained in:
Vincent Sanders 2014-01-16 00:01:25 +00:00
parent bd065d4a43
commit 38cb39339a
23 changed files with 236 additions and 190 deletions

View File

@ -209,6 +209,33 @@ static void gui_window_set_scroll(struct gui_window *g, int sx, int sy);
nsoptions[NSOPTION_##OPTION].value.i = VALUE; \
nsoptions_default[NSOPTION_##OPTION].value.i = VALUE
/**
* Return the filename part of a full path
*
* \param path full path and filename
* \return filename (will be freed with free())
*/
static char *filename_from_path(char *path)
{
return strdup(FilePart(path));
}
/**
* Add a path component/filename to an existing path
*
* \param path buffer containing path + free space
* \param length length of buffer "path"
* \param newpart string containing path component to add to path
* \return true on success
*/
static bool path_add_part(char *path, int length, const char *newpart)
{
if(AddPart(path, newpart, length)) return true;
else return false;
}
STRPTR ami_locale_langs(void)
{
struct Locale *locale;
@ -5130,6 +5157,8 @@ static struct gui_browser_table amiga_browser_table = {
.launch_url = gui_launch_url,
.create_form_select_menu = gui_create_form_select_menu,
.cert_verify = gui_cert_verify,
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
};
/** Normal entry point from OS */

View File

@ -172,33 +172,6 @@ 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));
}
/**
* Add a path component/filename to an existing path
*
* \param path buffer containing path + free space
* \param length length of buffer "path"
* \param newpart string containing path component to add to path
* \return true on success
*/
bool path_add_part(char *path, int length, const char *newpart)
{
if(AddPart(path, newpart, length)) return true;
else return false;
}
/**
* returns a string with escape chars translated.
* (based on remove_underscores from utils.c)

View File

@ -115,6 +115,27 @@ short aes_msg_out[8];
bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy);
/**
* Return the filename part of a full path
*
* \param path full path and filename
* \return filename (will be freed with free())
*/
static char *filename_from_path(char *path)
{
char *leafname;
leafname = strrchr(path, '\\');
if( !leafname )
leafname = strrchr(path, '/');
if (!leafname)
leafname = path;
else
leafname += 1;
return strdup(leafname);
}
static void gui_poll(bool active)
{
@ -1055,6 +1076,8 @@ static struct gui_browser_table atari_browser_table = {
.quit = gui_quit,
.get_resource_url = gui_get_resource_url,
.cert_verify = gui_cert_verify,
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
};
/* #define WITH_DBG_LOGFILE 1 */

View File

@ -70,28 +70,6 @@ void die(const char *error)
exit(1);
}
/**
* 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 = strrchr(path, '/');
if (!leafname)
leafname = path;
else
leafname += 1;
return strdup(leafname);
}
/**
* Add a path component/filename to an existing path
*

View File

@ -66,4 +66,6 @@ const char * file_select(const char * title, const char * name);
*/
long nkc_to_input_key(short nkc, long * ucs4_out);
bool path_add_part(char *path, int length, const char *newpart);
#endif

View File

@ -1027,7 +1027,7 @@ static void *myrealloc(void *ptr, size_t len, void *pw)
* \return filename (will be freed with free())
*/
char *filename_from_path(char *path)
static char *filename_from_path(char *path)
{
char *leafname;
@ -1049,7 +1049,7 @@ char *filename_from_path(char *path)
* \return true on success
*/
bool path_add_part(char *path, int length, const char *newpart)
static bool path_add_part(char *path, int length, const char *newpart)
{
if(path[strlen(path) - 1] != '/')
strncat(path, "/", length);
@ -1067,9 +1067,10 @@ static struct gui_clipboard_table beos_clipboard_table = {
static struct gui_browser_table beos_browser_table = {
.poll = gui_poll,
.quit = gui_quit,
.get_resource_url = gui_get_resource_url,
.launch_url = gui_launch_url,
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
};

View File

@ -281,6 +281,20 @@ void gui_401login_open(nsurl *url, const char *realm,
cb( false, cbpw );
}
static char *filename_from_path(char *path)
{
return strdup( [[[NSString stringWithUTF8String: path] lastPathComponent] UTF8String] );
}
static bool path_add_part(char *path, int length, const char *newpart)
{
NSString *newPath = [[NSString stringWithUTF8String: path] stringByAppendingPathComponent: [NSString stringWithUTF8String: newpart]];
strncpy( path, [newPath UTF8String], length );
return true;
}
static struct gui_window_table window_table = {
.create = gui_window_create,
@ -321,6 +335,8 @@ static struct gui_browser_table browser_table = {
.launch_url = gui_launch_url,
.create_form_select_menu = gui_create_form_select_menu,
.cert_verify = gui_cert_verify,
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
};
struct gui_browser_table *cocoa_browser_table = &browser_table;

View File

@ -41,16 +41,3 @@ void PDF_Password(char **owner_pass, char **user_pass, char *path)
UNIMPL();
}
char *filename_from_path(char *path)
{
return strdup( [[[NSString stringWithUTF8String: path] lastPathComponent] UTF8String] );
}
bool path_add_part(char *path, int length, const char *newpart)
{
NSString *newPath = [[NSString stringWithUTF8String: path] stringByAppendingPathComponent: [NSString stringWithUTF8String: newpart]];
strncpy( path, [newPath UTF8String], length );
return true;
}

View File

@ -45,6 +45,7 @@
#include "content/fetchers/curl.h"
#include "content/urldb.h"
#include "desktop/netsurf.h"
#include "desktop/gui_factory.h"
#include "utils/nsoption.h"
#include "utils/log.h"
#include "utils/messages.h"
@ -1268,7 +1269,7 @@ fetch_curl_post_convert(const struct fetch_multipart_data *control)
if (control->file) {
char *leafname = 0;
leafname = filename_from_path(control->value);
leafname = guit->browser->filename_from_path(control->value);
if (leafname == NULL)
continue;

View File

@ -47,6 +47,7 @@
#include "content/fetchers/file.h"
#include "content/urldb.h"
#include "desktop/netsurf.h"
#include "desktop/gui_factory.h"
#include "utils/nsoption.h"
#include "utils/errors.h"
#include "utils/log.h"
@ -574,7 +575,7 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx,
continue;
strncpy(urlpath, ctx->path, sizeof urlpath);
if (path_add_part(urlpath, sizeof urlpath,
if (guit->browser->path_add_part(urlpath, sizeof urlpath,
ent->d_name) == false)
continue;

View File

@ -344,6 +344,24 @@ struct gui_browser_table {
*/
void (*cert_verify)(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw);
/**
* 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);
/**
* Add a path component/filename to an existing path
*
* \param path buffer containing path + free space
* \param length length of buffer "path"
* \param newpart string containing path component to add to path
* \return true on success
*/
bool (*path_add_part)(char *path, int length, const char *newpart);
};

View File

@ -316,6 +316,13 @@ static nserror verify_browser_register(struct gui_browser_table *gbt)
if (gbt->poll == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (gbt->filename_from_path == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (gbt->path_add_part == NULL) {
return NSERROR_BAD_PARAMETER;
}
/* fill in the optional entries with defaults */
if (gbt->quit == NULL) {

View File

@ -23,7 +23,7 @@
#ifndef _NETSURF_DESKTOP_GUI_FACTORY_H_
#define _NETSURF_DESKTOP_GUI_FACTORY_H_
struct gui_table;
#include "desktop/gui.h"
extern struct gui_table *guit; /* the gui vtable */

View File

@ -37,6 +37,7 @@
#include "content/hlcache.h"
#include "css/css.h"
#include "desktop/save_complete.h"
#include "desktop/gui_factory.h"
#include "render/box.h"
#include "render/html.h"
#include "utils/corestrings.h"
@ -147,7 +148,7 @@ static bool save_complete_save_buffer(save_complete_ctx *ctx,
char fullpath[PATH_MAX];
strncpy(fullpath, ctx->path, sizeof fullpath);
error = path_add_part(fullpath, sizeof fullpath, leafname);
error = guit->browser->path_add_part(fullpath, sizeof fullpath, leafname);
if (error == false) {
warn_user("NoMemory", NULL);
return false;
@ -1048,7 +1049,7 @@ static bool save_complete_save_html_document(save_complete_ctx *ctx,
else
snprintf(filename, sizeof filename, "%p", c);
error = path_add_part(fullpath, sizeof fullpath, filename);
error = guit->browser->path_add_part(fullpath, sizeof fullpath, filename);
if (error == false) {
warn_user("NoMemory", NULL);
return false;
@ -1125,7 +1126,7 @@ static bool save_complete_inventory(save_complete_ctx *ctx)
char fullpath[PATH_MAX];
strncpy(fullpath, ctx->path, sizeof fullpath);
error = path_add_part(fullpath, sizeof fullpath, "Inventory");
error = guit->browser->path_add_part(fullpath, sizeof fullpath, "Inventory");
if (error == false) {
warn_user("NoMemory", NULL);
return false;

View File

@ -1767,6 +1767,43 @@ gui_window_remove_caret(struct gui_window *g)
}
}
/**
* Return the filename part of a full path
*
* \param path full path and filename
* \return filename (will be freed with free())
*/
static char *filename_from_path(char *path)
{
char *leafname;
leafname = strrchr(path, '/');
if (!leafname)
leafname = path;
else
leafname += 1;
return strdup(leafname);
}
/**
* Add a path component/filename to an existing path
*
* \param path buffer containing path + free space
* \param length length of buffer "path"
* \param newpart string containing path component to add to path
* \return true on success
*/
static bool path_add_part(char *path, int length, const char *newpart)
{
if(path[strlen(path) - 1] != '/')
strncat(path, "/", length);
strncat(path, newpart, length);
return true;
}
static struct gui_window_table framebuffer_window_table = {
.create = gui_window_create,
@ -1791,6 +1828,8 @@ static struct gui_browser_table framebuffer_browser_table = {
.poll = gui_poll,
.quit = gui_quit,
.get_resource_url = gui_get_resource_url,
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
};
/** Entry point from OS.

View File

@ -37,40 +37,3 @@ void die(const char *error)
exit(1);
}
/**
* 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);
}
/**
* Add a path component/filename to an existing path
*
* \param path buffer containing path + free space
* \param length length of buffer "path"
* \param newpart string containing path component to add to path
* \return true on success
*/
bool path_add_part(char *path, int length, const char *newpart)
{
if(path[strlen(path) - 1] != '/')
strncat(path, "/", length);
strncat(path, newpart, length);
return true;
}

View File

@ -1096,7 +1096,7 @@ uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *key)
* \return filename (will be freed with free())
*/
char *filename_from_path(char *path)
static char *filename_from_path(char *path)
{
char *leafname;
@ -1118,7 +1118,7 @@ char *filename_from_path(char *path)
* \return true on success
*/
bool path_add_part(char *path, int length, const char *newpart)
static bool path_add_part(char *path, int length, const char *newpart)
{
if(path[strlen(path) - 1] != '/')
strncat(path, "/", length);
@ -1141,6 +1141,8 @@ static struct gui_browser_table nsgtk_browser_table = {
.launch_url = gui_launch_url,
.create_form_select_menu = gui_create_form_select_menu,
.cert_verify = gui_cert_verify,
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
};
/**

View File

@ -114,12 +114,53 @@ static bool nslog_stream_configure(FILE *fptr)
return true;
}
/**
* Return the filename part of a full path
*
* \param path full path and filename
* \return filename (will be freed with free())
*/
static char *filename_from_path(char *path)
{
char *leafname;
leafname = strrchr(path, '/');
if (!leafname)
leafname = path;
else
leafname += 1;
return strdup(leafname);
}
/**
* Add a path component/filename to an existing path
*
* \param path buffer containing path + free space
* \param length length of buffer "path"
* \param newpart string containing path component to add to path
* \return true on success
*/
static bool path_add_part(char *path, int length, const char *newpart)
{
if(path[strlen(path) - 1] != '/')
strncat(path, "/", length);
strncat(path, newpart, length);
return true;
}
static struct gui_browser_table monkey_browser_table = {
.poll = monkey_poll,
.quit = monkey_quit,
.get_resource_url = gui_get_resource_url,
.launch_url = gui_launch_url,
.cert_verify = gui_cert_verify,
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
};
int

View File

@ -70,44 +70,6 @@ char *url_to_path(const char *url)
return respath;
}
/**
* 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);
}
/**
* Add a path component/filename to an existing path
*
* \param path buffer containing path + free space
* \param length length of buffer "path"
* \param newpart string containing path component to add to path
* \return true on success
*/
bool path_add_part(char *path, int length, const char *newpart)
{
if(path[strlen(path) - 1] != '/')
strncat(path, "/", length);
strncat(path, newpart, length);
return true;
}
void warn_user(const char *warning, const char *detail)
{

View File

@ -2288,7 +2288,7 @@ void PDF_Password(char **owner_pass, char **user_pass, char *path)
* \return filename (will be freed with free())
*/
char *filename_from_path(char *path)
static char *filename_from_path(char *path)
{
char *leafname;
char *temp;
@ -2326,7 +2326,7 @@ char *filename_from_path(char *path)
* \return true on success
*/
bool path_add_part(char *path, int length, const char *newpart)
static bool path_add_part(char *path, int length, const char *newpart)
{
size_t path_len = strlen(path);
@ -2360,6 +2360,8 @@ static struct gui_browser_table riscos_browser_table = {
.launch_url = gui_launch_url,
.create_form_select_menu = gui_create_form_select_menu,
.cert_verify = gui_cert_verify,
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
};

View File

@ -188,6 +188,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);
bool path_add_part(char *path, int length, const char *newpart);
#endif

View File

@ -1809,6 +1809,43 @@ nsws_create_main_class(HINSTANCE hinstance) {
return ret;
}
/**
* Return the filename part of a full path
*
* \param path full path and filename
* \return filename (will be freed with free())
*/
static char *filename_from_path(char *path)
{
char *leafname;
leafname = strrchr(path, '\\');
if (!leafname)
leafname = path;
else
leafname += 1;
return strdup(leafname);
}
/**
* Add a path component/filename to an existing path
*
* \param path buffer containing path + free space
* \param length length of buffer "path"
* \param newpart string containing path component to add to path
* \return true on success
*/
static bool path_add_part(char *path, int length, const char *newpart)
{
if(path[strlen(path) - 1] != '\\')
strncat(path, "\\", length);
strncat(path, newpart, length);
return true;
}
static struct gui_window_table window_table = {
.create = gui_window_create,
.destroy = gui_window_destroy,
@ -1840,6 +1877,8 @@ struct gui_clipboard_table *win32_clipboard_table = &clipboard_table;
static struct gui_table browser_table = {
.poll = gui_poll,
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
};
struct gui_browser_table *win32_browser_table = &browser_table;

View File

@ -43,41 +43,3 @@ void die(const char *error)
exit(1);
}
/**
* 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);
}
/**
* Add a path component/filename to an existing path
*
* \param path buffer containing path + free space
* \param length length of buffer "path"
* \param newpart string containing path component to add to path
* \return true on success
*/
bool path_add_part(char *path, int length, const char *newpart)
{
if(path[strlen(path) - 1] != '\\')
strncat(path, "\\", length);
strncat(path, newpart, length);
return true;
}