Dillo v3.1.1-119-g140d9ebd
Loading...
Searching...
No Matches
history.c
Go to the documentation of this file.
1/*
2 * File: history.c
3 *
4 * Copyright (C) 2001-2007 Jorge Arellano Cid <jcid@dillo.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 */
11
16#include "msg.h"
17#include "list.h"
18#include "history.h"
19
20
21typedef struct {
22 DilloUrl *url;
23 char *title;
24} H_Item;
25
26
27/* Global history list */
28static H_Item *history = NULL;
29static int history_size = 0; /* [1 based] */
30static int history_size_max = 16;
31
32
36void History_show(void)
37{
38 int i;
39
40 MSG(" {");
41 for (i = 0; i < history_size; ++i)
42 MSG(" %s", URL_STR(history[i].url));
43 MSG(" }\n");
44}
45
51{
52 int i, idx;
53
54 _MSG("a_History_add_url: '%s' ", URL_STR(url));
55 for (i = 0; i < history_size; ++i)
56 if (!a_Url_cmp(history[i].url, url) &&
57 !strcmp(URL_FRAGMENT(history[i].url), URL_FRAGMENT(url)))
58 break;
59
60 if (i < history_size) {
61 idx = i;
62 _MSG("FOUND at idx=%d\n", idx);
63 } else {
64 idx = history_size;
66 history[idx].url = a_Url_dup(url);
67 history[idx].title = NULL;
69 _MSG("ADDED at idx=%d\n", idx);
70 }
71
72 /* History_show(); */
73
74 return idx;
75}
76
81{
82 _MSG("a_History_get_url: ");
83 /* History_show(); */
84
85 dReturn_val_if_fail(idx >= 0 && idx < history_size, NULL);
86
87 return history[idx].url;
88}
89
94const char *a_History_get_title(int idx, int force)
95{
96 dReturn_val_if_fail(idx >= 0 && idx < history_size, NULL);
97
98 if (history[idx].title)
99 return history[idx].title;
100 else if (force)
101 return URL_STR(history[idx].url);
102 else
103 return NULL;
104}
105
110const char *a_History_get_title_by_url(const DilloUrl *url, int force)
111{
112 int i;
113
114 dReturn_val_if_fail(url != NULL, NULL);
115
116 for (i = 0; i < history_size; ++i)
117 if (a_Url_cmp(url, history[i].url) == 0)
118 break;
119
120 if (i < history_size && history[i].title)
121 return history[i].title;
122 else if (force)
123 return URL_STR_(url);
124 return NULL;
125}
126
130void a_History_set_title_by_url(const DilloUrl *url, const char *title)
131{
132 int i;
133
134 dReturn_if (url == NULL);
135
136 for (i = history_size - 1; i >= 0; --i)
137 if (a_Url_cmp(url, history[i].url) == 0)
138 break;
139
140 if (i >= 0) {
141 dFree(history[i].title);
142 history[i].title = dStrdup(title);
143 } else {
144 MSG_ERR("a_History_set_title_by_url: %s not found\n", URL_STR(url));
145 }
146}
147
148
153{
154 int i;
155
156 for (i = 0; i < history_size; ++i) {
157 a_Url_free(history[i].url);
158 dFree(history[i].title);
159 }
160 dFree(history);
161}
#define _MSG(...)
Definition bookmarks.c:45
#define MSG(...)
Definition bookmarks.c:46
void dFree(void *mem)
Definition dlib.c:68
char * dStrdup(const char *s)
Definition dlib.c:77
#define dReturn_val_if_fail(expr, val)
Definition dlib.h:76
#define dReturn_if(expr)
Definition dlib.h:64
#define a_List_add(list, num_items, alloc_step)
Definition cookies.c:68
#define MSG_ERR(...)
Definition dpid_common.h:23
const DilloUrl * a_History_get_url(int idx)
Return the DilloUrl field (by index)
Definition history.c:80
static int history_size_max
Definition history.c:30
int a_History_add_url(DilloUrl *url)
Add a new H_Item at the end of the history list (taking care of not making a duplicate entry)
Definition history.c:50
static H_Item * history
Definition history.c:28
const char * a_History_get_title(int idx, int force)
Return the title field (by index) ('force' returns URL_STR when there's no title)
Definition history.c:94
void a_History_set_title_by_url(const DilloUrl *url, const char *title)
Set the page-title for a given URL.
Definition history.c:130
void History_show(void)
Debug procedure.
Definition history.c:36
const char * a_History_get_title_by_url(const DilloUrl *url, int force)
Return the title field (by url) ('force' returns URL_STR when there's no title)
Definition history.c:110
void a_History_freeall(void)
Free all the memory used by this module.
Definition history.c:152
static int history_size
Definition history.c:29
Fast list methods.
Definition url.h:88
int a_Url_cmp(const DilloUrl *A, const DilloUrl *B)
Compare two Url's to check if they're the same, or which one is bigger.
Definition url.c:506
void a_Url_free(DilloUrl *url)
Free a DilloUrl.
Definition url.c:208
DilloUrl * a_Url_dup(const DilloUrl *ori)
Duplicate a Url structure.
Definition url.c:477
#define URL_FRAGMENT(u)
Definition url.h:74
#define URL_STR(u)
Definition url.h:76
#define URL_STR_(u)
Definition url.h:55