2
/* $Id: marks.c,v 1.3 2004/01/08 13:37:08 zas Exp $ */
13
#include "document/view.h"
14
#include "util/memory.h"
15
#include "util/string.h"
16
#include "viewer/text/form.h"
17
#include "viewer/text/link.h"
18
#include "viewer/text/view.h"
19
#include "viewer/text/vs.h"
24
* * Make it possible to go at marks which are set in a different document than
25
* the active one. This will basically need some clever hacking in the
26
* KP_MARK_GOTO handler, which first needs to load the URL and *then* jump at
27
* the exact location and just overally restore the rest of view_state. Perhaps
28
* this could also be somehow nicely unified with session.goto_position? --pasky
30
* * The lower-case chars should have per-document scope, while the upper-case
31
* chars would have per-ELinks (over all instances as well) scope. The l-c marks
32
* should be stored either in {struct document} or {struct location}, that needs
33
* further investigation. Disappearing when document gets out of all caches
34
* and/or histories is not an issue from my POV. However, it must be ensured
35
* that all instances of the document (and only the document) share the same
36
* marks. If we are dealing with frames, I mean content of one frame by
37
* 'document' - each frame in the frameset gets own set of marks. --pasky
39
* * Number marks for last ten documents in session history. XXX: To be
40
* meaningful, it needs to support last n both history and unhistory items.
43
* * "''" support (jump to the last visited mark). (What if it was per-document
44
* mark and we are already in another document now?) --pasky
46
* * When pressing "'", list of already set marks should appear. The next
47
* pressed char, if letter, would still directly get stuff from the list.
51
/* The @marks array is indexed by ASCII code of the mark. */
52
#define MARKS_SIZE 26 * 2
53
static struct view_state *marks[MARKS_SIZE];
55
#define is_valid_mark_char(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
56
#define is_valid_mark_index(i) ((i) >= 0 && (i) < MARKS_SIZE)
59
index_from_char(unsigned char mark)
61
assert(is_valid_mark_char(mark));
63
if (mark >= 'A' && mark <= 'Z')
66
return mark - 'a' + 26;
70
get_mark(unsigned char mark)
74
if (!is_valid_mark_char(mark))
77
i = index_from_char(mark);
78
assert(is_valid_mark_index(i));
84
set_mark(unsigned char mark, struct view_state *mark_vs)
86
struct view_state *vs;
89
if (!is_valid_mark_char(mark))
92
i = index_from_char(mark);
93
assert(is_valid_mark_index(i));
101
if (!mark_vs) return;
103
vs = mem_alloc(sizeof(struct view_state) + mark_vs->url_len);
105
copy_vs(vs, mark_vs);
115
for (i = 0; i < MARKS_SIZE; i++) {
116
assert(is_valid_mark_index(i));
117
if (!marks[i]) continue;
118
destroy_vs(marks[i]);