~ubuntu-branches/ubuntu/feisty/elinks/feisty-updates

« back to all changes in this revision

Viewing changes to src/viewer/text/marks.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Gervai
  • Date: 2004-01-21 22:13:45 UTC
  • Revision ID: james.westby@ubuntu.com-20040121221345-ju33hai1yhhqt6kn
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Marks registry */
 
2
/* $Id: marks.c,v 1.3 2004/01/08 13:37:08 zas Exp $ */
 
3
 
 
4
#ifdef HAVE_CONFIG_H
 
5
#include "config.h"
 
6
#endif
 
7
 
 
8
#include <stdlib.h>
 
9
#include <string.h>
 
10
 
 
11
#include "elinks.h"
 
12
 
 
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"
 
20
 
 
21
 
 
22
/* TODO list:
 
23
 *
 
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
 
29
 *
 
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
 
38
 *
 
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.
 
41
 * --pasky
 
42
 *
 
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
 
45
 *
 
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.
 
48
 * --pasky */
 
49
 
 
50
 
 
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];
 
54
 
 
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)
 
57
 
 
58
static inline int
 
59
index_from_char(unsigned char mark)
 
60
{
 
61
        assert(is_valid_mark_char(mark));
 
62
 
 
63
        if (mark >= 'A' && mark <= 'Z')
 
64
                return mark - 'A';
 
65
 
 
66
        return mark - 'a' + 26;
 
67
}
 
68
 
 
69
struct view_state *
 
70
get_mark(unsigned char mark)
 
71
{
 
72
        int i;
 
73
 
 
74
        if (!is_valid_mark_char(mark))
 
75
                return NULL;
 
76
 
 
77
        i = index_from_char(mark);
 
78
        assert(is_valid_mark_index(i));
 
79
 
 
80
        return marks[i];
 
81
}
 
82
 
 
83
void
 
84
set_mark(unsigned char mark, struct view_state *mark_vs)
 
85
{
 
86
        struct view_state *vs;
 
87
        int i;
 
88
 
 
89
        if (!is_valid_mark_char(mark))
 
90
                return;
 
91
 
 
92
        i = index_from_char(mark);
 
93
        assert(is_valid_mark_index(i));
 
94
 
 
95
        if (marks[i]) {
 
96
                destroy_vs(marks[i]);
 
97
                mem_free(marks[i]);
 
98
                marks[i] = NULL;
 
99
        }
 
100
 
 
101
        if (!mark_vs) return;
 
102
 
 
103
        vs = mem_alloc(sizeof(struct view_state) + mark_vs->url_len);
 
104
        if (!vs) return;
 
105
        copy_vs(vs, mark_vs);
 
106
 
 
107
        marks[i] = vs;
 
108
}
 
109
 
 
110
void
 
111
free_marks(void)
 
112
{
 
113
        int i;
 
114
 
 
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]);
 
119
                mem_free(marks[i]);
 
120
                marks[i] = NULL;
 
121
        }
 
122
}