1
/* Lynx Document Reference List Support LYList.c
2
** ====================================
4
** Author: FM Foteos Macrides (macrides@sci.wfbr.edu)
14
#include <LYGlobalDefs.h>
15
#include <LYCharUtils.h>
16
#include <LYCharSets.h>
17
#include <LYHistory.h>
22
#endif /* DIRED_SUPPORT */
27
/* showlist - F.Macrides (macrides@sci.wfeb.edu)
29
** Create a temporary text/html file with a list of links to
30
** HyperText References in the current document.
33
** titles Set: if we want titles where available
34
** Clear: we only get addresses.
38
PUBLIC int showlist ARGS2(
43
int refs, hidden_links;
44
static char tempfile[LY_MAXPATH];
45
static BOOLEAN last_titles = TRUE;
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";
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);
60
if (refs <= 0 && hidden_links <= 0) {
61
HTUserMsg(NO_REFS_FROM_DOC);
65
if ((fp0 = InternalPageFP(tempfile, titles == last_titles)) == 0)
68
LYLocalFileToURL(&(newdoc->address), tempfile);
70
LYRegisterUIPage(newdoc->address,
71
titles ? UIP_LIST_PAGE : UIP_ADDRLIST_PAGE);
73
LYforce_HTML_mode = TRUE; /* force this file to be HTML */
74
LYforce_no_cache = TRUE; /* force this file to be new */
76
#ifdef EXP_ADDRLIST_PAGE
78
BeginInternalPage(fp0, ADDRLIST_PAGE_TITLE, LIST_PAGE_HELP);
81
BeginInternalPage(fp0, LIST_PAGE_TITLE, LIST_PAGE_HELP);
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:")));
89
fprintf(fp0, "<%s compact>\n", ((keypad_mode == NUMBERS_AS_ARROWS) ?
92
fprintf(fp0, "<lh><em>%s</em>\n", gettext("Visible links:"));
94
if (hidden_links > 0) {
95
if (LYHiddenLinks == HIDDENLINKS_IGNORE)
98
helper = NULL; /* init */
99
for (cnt = 1; cnt <= refs; cnt++) {
100
HTChildAnchor *child = HText_childNextNumber(cnt, &helper);
101
HTAnchor *dest_intl = NULL;
103
HTParentAnchor *parent;
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
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
121
if (fields_are_numbered()) {
122
HText_FormDescNumber(cnt, (char **)&desc);
124
"<li><a id=%d href=\"#%d\">form field</a> = <em>%s</em>\n",
129
#ifndef DONT_TRACK_INTERNAL_LINKS
130
dest_intl = HTAnchor_followTypedLink(child, HTInternalLink);
133
dest_intl : HTAnchor_followLink(child);
134
parent = HTAnchor_parent(dest);
135
if (!intern_w_post && dest_intl &&
137
HTMainAnchor->post_data &&
139
BINEQ(HTMainAnchor->post_data, parent->post_data)) {
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.
147
intern_w_post = TRUE;
149
address = HTAnchor_address(dest);
150
title = titles ? HTAnchor_title(parent) : NULL;
152
HTSprintf0(&LinkTitle, "(internal)");
153
} else if (titles && child->type &&
154
dest == child->dest &&
155
!strncmp(HTAtom_name(child->type),
157
HTSprintf0(&LinkTitle, "(%s)", HTAtom_name(child->type)+10);
161
StrAllocCopy(Address, address);
163
LYEntify(&Address, TRUE);
164
if (title && *title) {
165
LYformTitle(&Title, title);
166
LYEntify(&Title, TRUE);
168
cp = findPoundSelector(Address);
174
fprintf(fp0, "<li><a href=\"%s\"%s>%s%s%s%s%s</a>\n", Address,
175
dest_intl ? " TYPE=\"internal link\"" : "",
177
((HTAnchor*)parent != dest) && Title ? "in " : "",
178
(char *)(Title ? Title : Address),
179
(Title && cp) ? " - " : "",
180
(Title && cp) ? (cp+1) : "");
187
if (hidden_links > 0) {
189
fprintf(fp0, "\n</%s>\n\n<p>\n",
190
((keypad_mode == NUMBERS_AS_ARROWS) ?
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:"));
197
for (cnt = 0; cnt < hidden_links; cnt++) {
198
StrAllocCopy(Address, HText_HiddenLinkAt(HTMainText, cnt));
199
LYEntify(&Address, FALSE);
200
if (!(Address && *Address)) {
204
fprintf(fp0, "<li><a href=\"%s\">%s</a>\n", Address, Address);
209
fprintf(fp0,"\n</%s>\n", ((keypad_mode == NUMBERS_AS_ARROWS) ?
211
EndInternalPage(fp0);
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
226
newdoc->internal_link = TRUE;
228
LYFreePostData(newdoc);
229
newdoc->internal_link = FALSE;
231
newdoc->isHEAD = FALSE;
232
newdoc->safe = FALSE;
236
/* printlist - F.Macrides (macrides@sci.wfeb.edu)
238
** Print a text/plain list of HyperText References
239
** in the current document.
242
** titles Set: if we want titles where available
243
** Clear: we only get addresses.
245
PUBLIC void printlist ARGS2(
250
int refs, hidden_links;
251
char *address = NULL;
252
char *desc = gettext("unknown field or link");
255
refs = HText_sourceAnchors(HTMainText);
256
if (refs <= 0 && LYHiddenLinks != HIDDENLINKS_SEPARATE)
258
hidden_links = HText_HiddenLinkCount(HTMainText);
259
if (refs <= 0 && hidden_links <= 0) {
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)
268
helper = NULL; /* init */
269
for (cnt = 1; cnt <= refs; cnt++) {
270
HTChildAnchor *child = HText_childNextNumber(cnt, &helper);
272
HTParentAnchor *parent;
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
285
if (fields_are_numbered()) {
286
HText_FormDescNumber(cnt, (char **)&desc);
287
fprintf(fp, "%4d. form field = %s\n", cnt, desc);
291
dest = HTAnchor_followLink(child);
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
299
if (dest == (HTAnchor *)child)
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));
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)) {
322
fprintf(fp, "%4d. %s\n", ((cnt + 1) + refs), address);