annotate src/history.c @ 2048:5060d415a85a

clickable menu items (even those introducing submenus) MUST have callbacks I clicked on the "Panel size" item itself instead of any of the options in its submenu, and: Segfault!
author corvid <corvid@lavabit.com>
date Thu, 26 May 2011 02:51:18 +0000
parents 0c5d982c92a0
children
rev   line source
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
2 * File: history.c
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
3 *
35
d9e7b35430de Updated copyright lines
jcid
parents: 11
diff changeset
4 * Copyright (C) 2001-2007 Jorge Arellano Cid <jcid@dillo.org>
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
5 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
8 * the Free Software Foundation; either version 3 of the License, or
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
9 * (at your option) any later version.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
10 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
11
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
12 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
13 * Linear history (it also provides indexes for the navigation stack)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
14 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
15
162
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
16 #include "msg.h"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
17 #include "list.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
18 #include "history.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
19
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
20
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
21 typedef struct {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
22 DilloUrl *url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
23 char *title;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
24 } H_Item;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
25
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
26
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
27 /* Global history list */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
28 static H_Item *history = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
29 static int history_size = 0; /* [1 based] */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
30 static int history_size_max = 16;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
31
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
32
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
33 /*
162
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
34 * Debug procedure.
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
35 */
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
36 void History_show()
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
37 {
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
38 int i;
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
39
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
40 MSG(" {");
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
41 for (i = 0; i < history_size; ++i)
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
42 MSG(" %s", URL_STR(history[i].url));
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
43 MSG(" }\n");
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
44 }
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
45
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
46 /*
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
47 * Add a new H_Item at the end of the history list
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
48 * (taking care of not making a duplicate entry)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
49 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
50 int a_History_add_url(DilloUrl *url)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
51 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
52 int i, idx;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
53
162
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
54 _MSG("a_History_add_url: '%s' ", URL_STR(url));
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
55 for (i = 0; i < history_size; ++i)
59
9bd7bf398a0c - Switched dillo to push a URL with fragment (anchor) into the stack.
jcid
parents: 50
diff changeset
56 if (!a_Url_cmp(history[i].url, url) &&
9bd7bf398a0c - Switched dillo to push a URL with fragment (anchor) into the stack.
jcid
parents: 50
diff changeset
57 !strcmp(URL_FRAGMENT(history[i].url), URL_FRAGMENT(url)))
162
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
58 break;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
59
162
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
60 if (i < history_size) {
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
61 idx = i;
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
62 _MSG("FOUND at idx=%d\n", idx);
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
63 } else {
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
64 idx = history_size;
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
65 a_List_add(history, history_size, history_size_max);
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
66 history[idx].url = a_Url_dup(url);
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
67 history[idx].title = NULL;
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
68 ++history_size;
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
69 _MSG("ADDED at idx=%d\n", idx);
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
70 }
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
71
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
72 /* History_show(); */
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
73
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
74 return idx;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
75 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
76
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
77 /*
50
22a3dedcb1a0 - s/camp/field/ s/CAMP/FIELD/
jcid
parents: 35
diff changeset
78 * Return the DilloUrl field (by index)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
79 */
1661
0c5d982c92a0 Add const qualifier to a_History_get_url()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1151
diff changeset
80 const DilloUrl *a_History_get_url(int idx)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
81 {
162
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
82 _MSG("a_History_get_url: ");
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
83 /* History_show(); */
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
84
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
85 dReturn_val_if_fail(idx >= 0 && idx < history_size, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
86
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
87 return history[idx].url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
88 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
89
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
90 /*
50
22a3dedcb1a0 - s/camp/field/ s/CAMP/FIELD/
jcid
parents: 35
diff changeset
91 * Return the title field (by index)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
92 * ('force' returns URL_STR when there's no title)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
93 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
94 const char *a_History_get_title(int idx, int force)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
95 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
96 dReturn_val_if_fail(idx >= 0 && idx < history_size, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
97
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
98 if (history[idx].title)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
99 return history[idx].title;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
100 else if (force)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
101 return URL_STR(history[idx].url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
102 else
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
103 return NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
104 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
105
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
106 /*
50
22a3dedcb1a0 - s/camp/field/ s/CAMP/FIELD/
jcid
parents: 35
diff changeset
107 * Return the title field (by url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
108 * ('force' returns URL_STR when there's no title)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
109 */
11
4a5942beffdf Added some "const" qualifiers.
jcid
parents: 0
diff changeset
110 const char *a_History_get_title_by_url(const DilloUrl *url, int force)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
111 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
112 int i;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
113
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
114 dReturn_val_if_fail(url != NULL, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
115
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
116 for (i = 0; i < history_size; ++i)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
117 if (a_Url_cmp(url, history[i].url) == 0)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
118 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
119
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
120 if (i < history_size && history[i].title)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
121 return history[i].title;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
122 else if (force)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
123 return URL_STR_(url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
124 return NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
125 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
126
827
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
127 /*
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
128 * Set the page-title for a given URL
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
129 */
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
130 void a_History_set_title_by_url(const DilloUrl *url, const char *title)
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
131 {
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
132 int i;
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
133
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
134 dReturn_if (url == NULL);
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
135
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
136 for (i = history_size - 1; i >= 0; --i)
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
137 if (a_Url_cmp(url, history[i].url) == 0)
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
138 break;
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
139
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
140 if (i >= 0) {
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
141 dFree(history[i].title);
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
142 history[i].title = dStrdup(title);
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
143 } else {
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
144 MSG_ERR("a_History_set_title_by_url: %s not found\n", URL_STR(url));
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
145 }
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
146 }
d513abcd4949 Implemented the tools button with CSS options. Also removed nav.h from html.cc
Jorge Arellano Cid <jcid@dillo.org>
parents: 162
diff changeset
147
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
148
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
149 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
150 * Free all the memory used by this module
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
151 */
1151
278bbfd85a02 Bound at-exit memory deallocation
corvid <corvid@lavabit.com>
parents: 827
diff changeset
152 void a_History_freeall()
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
153 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
154 int i;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
155
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
156 for (i = 0; i < history_size; ++i) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
157 a_Url_free(history[i].url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
158 dFree(history[i].title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
159 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
160 dFree(history);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
161 }