~ubuntu-branches/ubuntu/edgy/lynx/edgy

« back to all changes in this revision

Viewing changes to src/LYList.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-09-16 12:14:10 UTC
  • Revision ID: james.westby@ubuntu.com-20040916121410-cz1gu92c4nqfeyrg
Tags: upstream-2.8.5
ImportĀ upstreamĀ versionĀ 2.8.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*                      Lynx Document Reference List Support          LYList.c
 
2
**                      ====================================
 
3
**
 
4
**      Author: FM      Foteos Macrides (macrides@sci.wfbr.edu)
 
5
**
 
6
*/
 
7
 
 
8
#include <HTUtils.h>
 
9
#include <HTAlert.h>
 
10
#include <LYUtils.h>
 
11
#include <GridText.h>
 
12
#include <LYList.h>
 
13
#include <LYClean.h>
 
14
#include <LYGlobalDefs.h>
 
15
#include <LYCharUtils.h>
 
16
#include <LYCharSets.h>
 
17
#include <LYHistory.h>
 
18
 
 
19
#ifdef DIRED_SUPPORT
 
20
#include <LYUpload.h>
 
21
#include <LYLocal.h>
 
22
#endif /* DIRED_SUPPORT */
 
23
 
 
24
#include <LYexit.h>
 
25
#include <LYLeaks.h>
 
26
 
 
27
/*      showlist - F.Macrides (macrides@sci.wfeb.edu)
 
28
**      --------
 
29
**      Create a temporary text/html file with a list of links to
 
30
**      HyperText References in the current document.
 
31
**
 
32
**  On entry
 
33
**      titles          Set:    if we want titles where available
 
34
**                      Clear:  we only get addresses.
 
35
*/
 
36
 
 
37
 
 
38
PUBLIC int showlist ARGS2(
 
39
        DocInfo *,      newdoc,
 
40
        BOOLEAN,        titles)
 
41
{
 
42
    int cnt;
 
43
    int refs, hidden_links;
 
44
    static char tempfile[LY_MAXPATH];
 
45
    static BOOLEAN last_titles = TRUE;
 
46
    FILE *fp0;
 
47
    char *Address = NULL, *Title = NULL, *cp = NULL;
 
48
    char *LinkTitle = NULL;  /* Rel stored as property of link, not of dest */
 
49
    BOOLEAN intern_w_post = FALSE;
 
50
    char *desc = "unknown field or link";
 
51
    void* helper;
 
52
 
 
53
    refs = HText_sourceAnchors(HTMainText);
 
54
    hidden_links = HText_HiddenLinkCount(HTMainText);
 
55
    if (refs <= 0 && hidden_links > 0 &&
 
56
        LYHiddenLinks != HIDDENLINKS_SEPARATE) {
 
57
        HTUserMsg(NO_VISIBLE_REFS_FROM_DOC);
 
58
        return(-1);
 
59
    }
 
60
    if (refs <= 0 && hidden_links <= 0) {
 
61
        HTUserMsg(NO_REFS_FROM_DOC);
 
62
        return(-1);
 
63
    }
 
64
 
 
65
    if ((fp0 = InternalPageFP(tempfile, titles == last_titles)) == 0)
 
66
        return(-1);
 
67
 
 
68
    LYLocalFileToURL(&(newdoc->address), tempfile);
 
69
 
 
70
    LYRegisterUIPage(newdoc->address,
 
71
                     titles ? UIP_LIST_PAGE : UIP_ADDRLIST_PAGE);
 
72
    last_titles = titles;
 
73
    LYforce_HTML_mode = TRUE;   /* force this file to be HTML */
 
74
    LYforce_no_cache = TRUE;    /* force this file to be new */
 
75
 
 
76
#ifdef EXP_ADDRLIST_PAGE
 
77
    if (titles != TRUE)
 
78
        BeginInternalPage(fp0, ADDRLIST_PAGE_TITLE, LIST_PAGE_HELP);
 
79
    else
 
80
#endif
 
81
    BeginInternalPage(fp0, LIST_PAGE_TITLE, LIST_PAGE_HELP);
 
82
 
 
83
    StrAllocCopy(Address, HTLoadedDocumentURL());
 
84
    LYEntify(&Address, FALSE);
 
85
    fprintf(fp0, "%s%s<p>\n", gettext("References in "),
 
86
        ((Address != NULL && *Address != '\0') ? Address : gettext("this document:")));
 
87
    FREE(Address);
 
88
    if (refs > 0) {
 
89
        fprintf(fp0, "<%s compact>\n", ((keypad_mode == NUMBERS_AS_ARROWS) ?
 
90
                                       "ol" : "ul"));
 
91
        if (hidden_links > 0)
 
92
            fprintf(fp0, "<lh><em>%s</em>\n", gettext("Visible links:"));
 
93
    }
 
94
    if (hidden_links > 0) {
 
95
        if (LYHiddenLinks == HIDDENLINKS_IGNORE)
 
96
            hidden_links = 0;
 
97
    }
 
98
    helper = NULL; /* init */
 
99
    for (cnt = 1; cnt <= refs; cnt++) {
 
100
        HTChildAnchor *child = HText_childNextNumber(cnt, &helper);
 
101
        HTAnchor *dest_intl = NULL;
 
102
        HTAnchor *dest;
 
103
        HTParentAnchor *parent;
 
104
        char *address;
 
105
        CONST char *title;
 
106
 
 
107
        if (child == 0) {
 
108
            /*
 
109
             *  child should not be 0 unless form field numbering is on
 
110
             *  and cnt is the number of a form input field.
 
111
             *  HText_FormDescNumber() will set desc to a description
 
112
             *  of what type of input field this is.  We'll list it to
 
113
             *  ensure that the link numbers on the list page match the
 
114
             *  numbering in the original document, but won't create a
 
115
             *  forward link to the form. - FM && LE
 
116
             *
 
117
             *  Changed to create a fake hidden link, to get the numbering
 
118
             *  right in connection with always treating this file as
 
119
             *  HIDDENLINKS_MERGE in GridText.c - kw
 
120
             */
 
121
            if (fields_are_numbered()) {
 
122
                HText_FormDescNumber(cnt, (char **)&desc);
 
123
                fprintf(fp0,
 
124
                "<li><a id=%d href=\"#%d\">form field</a> = <em>%s</em>\n",
 
125
                        cnt, cnt, desc);
 
126
            }
 
127
            continue;
 
128
        }
 
129
#ifndef DONT_TRACK_INTERNAL_LINKS
 
130
        dest_intl = HTAnchor_followTypedLink(child, HTInternalLink);
 
131
#endif
 
132
        dest = dest_intl ?
 
133
            dest_intl : HTAnchor_followLink(child);
 
134
        parent = HTAnchor_parent(dest);
 
135
        if (!intern_w_post && dest_intl &&
 
136
            HTMainAnchor &&
 
137
            HTMainAnchor->post_data &&
 
138
            parent->post_data &&
 
139
            BINEQ(HTMainAnchor->post_data, parent->post_data)) {
 
140
            /*
 
141
             *  Set flag to note that we had at least one internal link,
 
142
             *  if the document from which we are generating the list
 
143
             *  has associated POST data; after an extra check that the
 
144
             *  link destination really has the same POST data so that
 
145
             *  we can believe it is an internal link.
 
146
             */
 
147
            intern_w_post = TRUE;
 
148
        }
 
149
        address =  HTAnchor_address(dest);
 
150
        title = titles ? HTAnchor_title(parent) : NULL;
 
151
        if (dest_intl) {
 
152
            HTSprintf0(&LinkTitle, "(internal)");
 
153
        } else if (titles && child->type &&
 
154
                   dest == child->dest &&
 
155
                   !strncmp(HTAtom_name(child->type),
 
156
                            "RelTitle: ", 10)) {
 
157
            HTSprintf0(&LinkTitle, "(%s)", HTAtom_name(child->type)+10);
 
158
        } else {
 
159
            FREE(LinkTitle);
 
160
        }
 
161
        StrAllocCopy(Address, address);
 
162
        FREE(address);
 
163
        LYEntify(&Address, TRUE);
 
164
        if (title && *title) {
 
165
            LYformTitle(&Title, title);
 
166
            LYEntify(&Title, TRUE);
 
167
            if (*Title) {
 
168
                cp = findPoundSelector(Address);
 
169
            } else {
 
170
                FREE(Title);
 
171
            }
 
172
        }
 
173
 
 
174
        fprintf(fp0, "<li><a href=\"%s\"%s>%s%s%s%s%s</a>\n", Address,
 
175
                        dest_intl ? " TYPE=\"internal link\"" : "",
 
176
                        NonNull(LinkTitle),
 
177
                        ((HTAnchor*)parent != dest) && Title ? "in " : "",
 
178
                        (char *)(Title ? Title : Address),
 
179
                        (Title && cp) ? " - " : "",
 
180
                        (Title && cp) ? (cp+1) : "");
 
181
 
 
182
        FREE(Address);
 
183
        FREE(Title);
 
184
    }
 
185
    FREE(LinkTitle);
 
186
 
 
187
    if (hidden_links > 0) {
 
188
        if (refs > 0)
 
189
            fprintf(fp0, "\n</%s>\n\n<p>\n",
 
190
                         ((keypad_mode == NUMBERS_AS_ARROWS) ?
 
191
                                                        "ol" : "ul"));
 
192
        fprintf(fp0, "<%s compact>\n", ((keypad_mode == NUMBERS_AS_ARROWS) ?
 
193
                                        "ol continue" : "ul"));
 
194
        fprintf(fp0, "<lh><em>%s</em>\n", gettext("Hidden links:"));
 
195
    }
 
196
 
 
197
    for (cnt = 0; cnt < hidden_links; cnt++) {
 
198
        StrAllocCopy(Address, HText_HiddenLinkAt(HTMainText, cnt));
 
199
        LYEntify(&Address, FALSE);
 
200
        if (!(Address && *Address)) {
 
201
            FREE(Address);
 
202
            continue;
 
203
        }
 
204
        fprintf(fp0, "<li><a href=\"%s\">%s</a>\n", Address, Address);
 
205
 
 
206
        FREE(Address);
 
207
    }
 
208
 
 
209
    fprintf(fp0,"\n</%s>\n", ((keypad_mode == NUMBERS_AS_ARROWS) ?
 
210
                             "ol" : "ul"));
 
211
    EndInternalPage(fp0);
 
212
    LYCloseTempFP(fp0);
 
213
 
 
214
    /*
 
215
     *  Make necessary changes to newdoc before returning to caller.
 
216
     *  If the intern_w_post flag is set, we keep the POST data in
 
217
     *  newdoc that have been passed in.  They should be the same as
 
218
     *  in the loaded document for which we generated the list.
 
219
     *  In that case the file we have written will be associated with
 
220
     *  the same POST data when it is loaded after we are done here,
 
221
     *  so that following one of the links we have marked as "internal
 
222
     *  link" can lead back to the underlying document with the right
 
223
     *  address+post_data combination. - kw
 
224
     */
 
225
    if (intern_w_post) {
 
226
        newdoc->internal_link = TRUE;
 
227
    } else {
 
228
        LYFreePostData(newdoc);
 
229
        newdoc->internal_link = FALSE;
 
230
    }
 
231
    newdoc->isHEAD = FALSE;
 
232
    newdoc->safe = FALSE;
 
233
    return(0);
 
234
}
 
235
 
 
236
/*      printlist - F.Macrides (macrides@sci.wfeb.edu)
 
237
**      ---------
 
238
**      Print a text/plain list of HyperText References
 
239
**      in the current document.
 
240
**
 
241
**  On entry
 
242
**      titles          Set:    if we want titles where available
 
243
**                      Clear:  we only get addresses.
 
244
*/
 
245
PUBLIC void printlist ARGS2(
 
246
        FILE *,         fp,
 
247
        BOOLEAN,        titles)
 
248
{
 
249
    int cnt;
 
250
    int refs, hidden_links;
 
251
    char *address = NULL;
 
252
    char *desc = gettext("unknown field or link");
 
253
    void* helper;
 
254
 
 
255
    refs = HText_sourceAnchors(HTMainText);
 
256
    if (refs <= 0 && LYHiddenLinks != HIDDENLINKS_SEPARATE)
 
257
        return;
 
258
    hidden_links = HText_HiddenLinkCount(HTMainText);
 
259
    if (refs <= 0 && hidden_links <= 0) {
 
260
        return;
 
261
    } else {
 
262
        fprintf(fp, "\n%s\n\n", gettext("References"));
 
263
        if (hidden_links > 0) {
 
264
            fprintf(fp, "   %s\n", gettext("Visible links"));
 
265
            if (LYHiddenLinks == HIDDENLINKS_IGNORE)
 
266
                hidden_links = 0;
 
267
        }
 
268
       helper = NULL; /* init */
 
269
        for (cnt = 1; cnt <= refs; cnt++) {
 
270
            HTChildAnchor *child = HText_childNextNumber(cnt, &helper);
 
271
            HTAnchor *dest;
 
272
            HTParentAnchor *parent;
 
273
            CONST char *title;
 
274
 
 
275
            if (child == 0) {
 
276
                /*
 
277
                 *  child should not be 0 unless form field numbering is on
 
278
                 *  and cnt is the number of a form input field.
 
279
                 *  HText_FormDescNumber() will set desc to a description
 
280
                 *  of what type of input field this is.  We'll create a
 
281
                 *  within-document link to ensure that the link numbers on
 
282
                 *  the list page match the numbering in the original document,
 
283
                 *  but won't create a forward link to the form. - FM && LE
 
284
                 */
 
285
                if (fields_are_numbered()) {
 
286
                    HText_FormDescNumber(cnt, (char **)&desc);
 
287
                    fprintf(fp, "%4d. form field = %s\n", cnt, desc);
 
288
                }
 
289
                continue;
 
290
            }
 
291
            dest = HTAnchor_followLink(child);
 
292
            /*
 
293
             *  Ignore if child anchor points to itself, i.e., we had
 
294
             *  something like <A NAME=xyz HREF="#xyz"> and it is not
 
295
             *  treated as a hidden link.  Useful if someone 'P'rints
 
296
             *  the List Page (which isn't a very useful action to do,
 
297
             *  but anyway...) - kw
 
298
             */
 
299
            if (dest == (HTAnchor *)child)
 
300
                continue;
 
301
            parent = HTAnchor_parent(dest);
 
302
            title = titles ? HTAnchor_title(parent) : NULL;
 
303
            address =  HTAnchor_address(dest);
 
304
            fprintf(fp, "%4d. %s%s\n", cnt,
 
305
                    ((HTAnchor*)parent != dest) && title ? "in " : "",
 
306
                    (title ? title : address));
 
307
            FREE(address);
 
308
#ifdef VMS
 
309
            if (HadVMSInterrupt)
 
310
                break;
 
311
#endif /* VMS */
 
312
        }
 
313
 
 
314
        if (hidden_links > 0)
 
315
            fprintf(fp, "%s   %s\n", ((refs > 0) ? "\n" : ""), gettext("Hidden links:"));
 
316
        for (cnt = 0; cnt < hidden_links; cnt++) {
 
317
            StrAllocCopy(address, HText_HiddenLinkAt(HTMainText, cnt));
 
318
            if (!(address && *address)) {
 
319
                FREE(address);
 
320
                continue;
 
321
            }
 
322
            fprintf(fp, "%4d. %s\n", ((cnt + 1) + refs), address);
 
323
            FREE(address);
 
324
#ifdef VMS
 
325
            if (HadVMSInterrupt)
 
326
                break;
 
327
#endif /* VMS */
 
328
        }
 
329
    }
 
330
    return;
 
331
}