1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

bug 153, 1066: Add add_bookmark_cp().

This commit is contained in:
Kalle Olavi Niemitalo 2008-10-20 01:08:20 +03:00 committed by Kalle Olavi Niemitalo
parent d1f2f8df80
commit 1cb81679f4
2 changed files with 55 additions and 1 deletions

View File

@ -371,7 +371,9 @@ add_bookmark_item_to_bookmarks(struct bookmark *bm, struct bookmark *root, int p
* URL to which the bookmark will point. Must be in UTF-8. * URL to which the bookmark will point. Must be in UTF-8.
* NULL or "" means add a bookmark folder. * NULL or "" means add a bookmark folder.
* *
* @return the new bookmark, or NULL on error. */ * @return the new bookmark, or NULL on error.
*
* @see add_bookmark_cp() */
struct bookmark * struct bookmark *
add_bookmark(struct bookmark *root, int place, unsigned char *title, add_bookmark(struct bookmark *root, int place, unsigned char *title,
unsigned char *url) unsigned char *url)
@ -408,6 +410,56 @@ add_bookmark(struct bookmark *root, int place, unsigned char *title,
return bm; return bm;
} }
/** Add a bookmark to the bookmark list.
*
* @param root
* The folder in which to add the bookmark, or NULL to add it at
* top level.
* @param place
* 0 means add to the top. 1 means add to the bottom.
* @param codepage
* Codepage of @a title and @a url.
* @param title
* Title of the bookmark. Must not be NULL.
* "-" means add a separator.
* @param url
* URL to which the bookmark will point.
* NULL or "" means add a bookmark folder.
*
* @return the new bookmark.
*
* @see add_bookmark() */
struct bookmark *
add_bookmark_cp(struct bookmark *root, int place, int codepage,
unsigned char *title, unsigned char *url)
{
const int utf8_cp = get_cp_index("UTF-8");
struct conv_table *table;
unsigned char *utf8_title = NULL;
unsigned char *utf8_url = NULL;
struct bookmark *bookmark = NULL;
if (!url)
url = "";
table = get_translation_table(codepage, utf8_cp);
if (!table)
return NULL;
utf8_title = convert_string(table, title, strlen(title),
utf8_cp, CSM_NONE,
NULL, NULL, NULL);
utf8_url = convert_string(table, url, strlen(url),
utf8_cp, CSM_NONE,
NULL, NULL, NULL);
if (utf8_title && utf8_url)
bookmark = add_bookmark(root, place,
utf8_title, utf8_url);
mem_free_if(utf8_title);
mem_free_if(utf8_url);
return bookmark;
}
/* Updates an existing bookmark. /* Updates an existing bookmark.
* *
* If there's any problem, return 0. Otherwise, return 1. * If there's any problem, return 0. Otherwise, return 1.

View File

@ -45,6 +45,8 @@ int bookmarks_are_dirty(void);
void delete_bookmark(struct bookmark *); void delete_bookmark(struct bookmark *);
struct bookmark *add_bookmark(struct bookmark *, int, unsigned char *, unsigned char *); struct bookmark *add_bookmark(struct bookmark *, int, unsigned char *, unsigned char *);
struct bookmark *add_bookmark_cp(struct bookmark *, int, int,
unsigned char *, unsigned char *);
struct bookmark *get_bookmark_by_name(struct bookmark *folder, struct bookmark *get_bookmark_by_name(struct bookmark *folder,
unsigned char *title); unsigned char *title);
struct bookmark *get_bookmark(unsigned char *url); struct bookmark *get_bookmark(unsigned char *url);