1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
|
#include <HTUtils.h>
#include <HTTP.h>
#include <GridText.h>
#include <HTAlert.h>
#include <HText.h>
#include <LYGlobalDefs.h>
#include <LYUtils.h>
#include <LYHistory.h>
#include <LYPrint.h>
#include <LYDownload.h>
#include <LYOptions.h>
#include <LYKeymap.h>
#include <LYList.h>
#include <LYShowInfo.h>
#include <LYStrings.h>
#include <LYCharUtils.h>
#include <LYGetFile.h>
#ifdef DIRED_SUPPORT
#include <LYUpload.h>
#include <LYLocal.h>
#endif /* DIRED_SUPPORT */
#include <LYexit.h>
#include <LYLeaks.h>
PUBLIC HTList * Visited_Links = NULL; /* List of safe popped docs. */
#ifdef LY_FIND_LEAKS
/*
* Utility for freeing the list of visited links. - FM
*/
PRIVATE void Visited_Links_free NOARGS
{
VisitedLink *vl;
HTList *cur = Visited_Links;
if (!cur)
return;
while (NULL != (vl = (VisitedLink *)HTList_nextObject(cur))) {
FREE(vl->address);
FREE(vl->title);
FREE(vl);
}
HTList_delete(Visited_Links);
Visited_Links = NULL;
return;
}
#endif /* LY_FIND_LEAKS */
/*
* Utility for listing visited links, making any repeated
* links the most current in the list. - FM
*/
PUBLIC void LYAddVisitedLink ARGS1(
document *, doc)
{
VisitedLink *new;
VisitedLink *old;
HTList *cur;
if (!(doc->address && *doc->address))
return;
/*
* Exclude POST or HEAD replies, and bookmark, menu
* or list files. - FM
*/
if (doc->post_data || doc->isHEAD || doc->bookmark ||
(/* special url or a temp file */
(!strncmp(doc->address, "LYNX", 4) ||
!strncmp(doc->address, "file://localhost/", 17))
&& (
!strcmp((doc->title ? doc->title : ""), HISTORY_PAGE_TITLE) ||
!strcmp((doc->title ? doc->title : ""), PRINT_OPTIONS_TITLE) ||
!strcmp((doc->title ? doc->title : ""), DOWNLOAD_OPTIONS_TITLE) ||
!strcmp((doc->title ? doc->title : ""), OPTIONS_TITLE) ||
#ifdef DIRED_SUPPORT
!strcmp((doc->title ? doc->title : ""), DIRED_MENU_TITLE) ||
!strcmp((doc->title ? doc->title : ""), UPLOAD_OPTIONS_TITLE) ||
!strcmp((doc->title ? doc->title : ""), PERMIT_OPTIONS_TITLE) ||
#endif /* DIRED_SUPPORT */
!strcmp((doc->title ? doc->title : ""), CURRENT_KEYMAP_TITLE) ||
!strcmp((doc->title ? doc->title : ""), LIST_PAGE_TITLE) ||
#ifdef EXP_ADDRLIST_PAGE
!strcmp((doc->title ? doc->title : ""), ADDRLIST_PAGE_TITLE) ||
#endif
!strcmp((doc->title ? doc->title : ""), SHOWINFO_TITLE) ||
!strcmp((doc->title ? doc->title : ""), STATUSLINES_TITLE) ||
!strcmp((doc->title ? doc->title : ""), CONFIG_DEF_TITLE) ||
!strcmp((doc->title ? doc->title : ""), LYNXCFG_TITLE) ||
!strcmp((doc->title ? doc->title : ""), COOKIE_JAR_TITLE) ||
!strcmp((doc->title ? doc->title : ""), VISITED_LINKS_TITLE) ||
!strcmp((doc->title ? doc->title : ""), LYNX_TRACELOG_TITLE)))) {
return;
}
if ((new = (VisitedLink *)calloc(1, sizeof(*new))) == NULL)
outofmem(__FILE__, "LYAddVisitedLink");
StrAllocCopy(new->address, doc->address);
StrAllocCopy(new->title, (doc->title ? doc->title : NO_TITLE));
if (!Visited_Links) {
Visited_Links = HTList_new();
#ifdef LY_FIND_LEAKS
atexit(Visited_Links_free);
#endif
HTList_addObject(Visited_Links, new);
return;
}
cur = Visited_Links;
while (NULL != (old = (VisitedLink *)HTList_nextObject(cur))) {
if (!strcmp((old->address ? old->address : ""),
(new->address ? new->address : ""))) {
if (!(new->title && *new->title) && old->title) {
StrAllocCopy(new->title, old->title);
}
FREE(old->address);
FREE(old->title);
HTList_removeObject(Visited_Links, old);
FREE(old);
break;
}
}
HTList_addObject(Visited_Links, new);
return;
}
/*
* Returns true if this is a page that we would push onto the stack if not
* forced. If docurl is NULL, only the title is considered; otherwise
* also check the URL whether it is (likely to be) a generated special
* page.
*/
PUBLIC BOOLEAN LYwouldPush ARGS2(
CONST char *, title,
CONST char *, docurl)
{
/*
* All non-pushable generated pages have URLs that begin with
* "file://localhost/" and end with HTML_SUFFIX. - kw
*/
if (docurl) {
size_t ulen;
if (strncmp(docurl, "file://localhost/", 17) != 0 ||
(ulen = strlen(docurl)) <= strlen(HTML_SUFFIX) ||
strcmp(docurl + ulen - strlen(HTML_SUFFIX), HTML_SUFFIX) != 0)
return TRUE;
}
return (!strcmp(title, HISTORY_PAGE_TITLE)
|| !strcmp(title, PRINT_OPTIONS_TITLE)
|| !strcmp(title, DOWNLOAD_OPTIONS_TITLE)
#ifdef DIRED_SUPPORT
|| !strcmp(title, DIRED_MENU_TITLE)
|| !strcmp(title, UPLOAD_OPTIONS_TITLE)
|| !strcmp(title, PERMIT_OPTIONS_TITLE)
#endif /* DIRED_SUPPORT */
)
? FALSE
: TRUE;
}
/*
* Push the current filename, link and line number onto the history list.
*/
PUBLIC void LYpush ARGS2(
document *, doc,
BOOLEAN, force_push)
{
/*
* Don't push NULL file names.
*/
if (*doc->address == '\0')
return;
/*
* Check whether this is a document we
* don't push unless forced. - FM
*/
if (!force_push) {
/*
* Don't push the history, printer, or download lists.
*/
if (!LYwouldPush(doc->title, doc->address)) {
if (!LYforce_no_cache)
LYoverride_no_cache = TRUE;
return;
}
}
/*
* If file is identical to one before it, don't push it.
*/
if (nhist> 1 &&
STREQ(history[nhist-1].address, doc->address) &&
!strcmp(history[nhist-1].post_data ?
history[nhist-1].post_data : "",
doc->post_data ?
doc->post_data : "") &&
!strcmp(history[nhist-1].bookmark ?
history[nhist-1].bookmark : "",
doc->bookmark ?
doc->bookmark : "") &&
history[nhist-1].isHEAD == doc->isHEAD) {
if (history[nhist-1].internal_link == doc->internal_link) {
/* But it is nice to have the last position remembered!
- kw */
history[nhist-1].link = doc->link;
history[nhist-1].line = doc->line;
return;
}
}
/*
* OK, push it if we have stack space.
*/
if (nhist < MAXHIST) {
history[nhist].link = doc->link;
history[nhist].line = doc->line;
history[nhist].title = NULL;
StrAllocCopy(history[nhist].title, doc->title);
history[nhist].address = NULL;
StrAllocCopy(history[nhist].address, doc->address);
history[nhist].post_data = NULL;
StrAllocCopy(history[nhist].post_data, doc->post_data);
history[nhist].post_content_type = NULL;
StrAllocCopy(history[nhist].post_content_type, doc->post_content_type);
history[nhist].bookmark = NULL;
StrAllocCopy(history[nhist].bookmark, doc->bookmark);
history[nhist].isHEAD = doc->isHEAD;
history[nhist].safe = doc->safe;
history[nhist].internal_link = FALSE; /* by default */
history[nhist].intern_seq_start = -1; /* by default */
if (doc->internal_link) {
/* Now some tricky stuff: if the caller thinks that the doc
to push was the result of following an internal
(fragment) link, we check whether we believe it.
It is only accepted as valid if the immediately preceding
item on the history stack is actually the same document
except for fragment and location info. I.e. the Parent
Anchors are the same.
Also of course this requires that this is not the first
history item. - kw */
if (nhist > 0) {
DocAddress WWWDoc;
HTParentAnchor *thisparent, *thatparent = NULL;
WWWDoc.address = doc->address;
WWWDoc.post_data = doc->post_data;
WWWDoc.post_content_type = doc->post_content_type;
WWWDoc.bookmark = doc->bookmark;
WWWDoc.isHEAD = doc->isHEAD;
WWWDoc.safe = doc->safe;
thisparent =
HTAnchor_parent(HTAnchor_findAddress(&WWWDoc));
/* Now find the ParentAnchor for the previous history
** item - kw
*/
if (thisparent) {
/* If the last-pushed item is a LYNXIMGMAP but THIS one
** isn't, compare the physical URLs instead. - kw
*/
if (0==strncmp(history[nhist-1].address,"LYNXIMGMAP:",11) &&
0!=strncmp(doc->address,"LYNXIMGMAP:",11)) {
WWWDoc.address = history[nhist-1].address + 11;
/*
** If THIS item is a LYNXIMGMAP but the last-pushed one
** isn't, fake it by using THIS item's address for
** thatparent... - kw
*/
} else if ((0==strncmp(doc->address,"LYNXIMGMAP:",11) &&
0!=strncmp(history[nhist-1].address,"LYNXIMGMAP:",11))) {
char *temp = NULL;
StrAllocCopy(temp, "LYNXIMGMAP:");
StrAllocCat(temp, doc->address+11);
WWWDoc.address = temp;
WWWDoc.post_content_type = history[nhist-1].post_content_type;
WWWDoc.bookmark = history[nhist-1].bookmark;
WWWDoc.isHEAD = history[nhist-1].isHEAD;
WWWDoc.safe = history[nhist-1].safe;
thatparent =
HTAnchor_parent(HTAnchor_findAddress(&WWWDoc));
FREE(temp);
} else {
WWWDoc.address = history[nhist-1].address;
}
if (!thatparent) { /* if not yet done */
WWWDoc.post_data = history[nhist-1].post_data;
WWWDoc.post_content_type = history[nhist-1].post_content_type;
WWWDoc.bookmark = history[nhist-1].bookmark;
WWWDoc.isHEAD = history[nhist-1].isHEAD;
WWWDoc.safe = history[nhist-1].safe;
thatparent =
HTAnchor_parent(HTAnchor_findAddress(&WWWDoc));
}
/* In addition to equality of the ParentAnchors, require
** that IF we have a HTMainText (i.e., it wasn't just
** HTuncache'd by mainloop), THEN it has to be consistent
** with what we are trying to push.
** This may be overkill... - kw
*/
if (thatparent == thisparent &&
(!HTMainText || HTMainAnchor == thisparent)
) {
history[nhist].internal_link = TRUE;
history[nhist].intern_seq_start =
history[nhist-1].intern_seq_start >= 0 ?
history[nhist-1].intern_seq_start : nhist-1;
CTRACE(tfp, "\nLYpush: pushed as internal link, OK\n");
}
}
}
if (!history[nhist].internal_link) {
CTRACE(tfp, "\nLYpush: push as internal link requested, %s\n",
"but didn't check out!");
}
}
CTRACE(tfp, "\nLYpush[%d]: address:%s\n title:%s\n",
nhist, doc->address, doc->title);
nhist++;
} else {
if (LYCursesON) {
HTAlert(MAXHIST_REACHED);
}
CTRACE(tfp, "\nLYpush: MAXHIST reached for:\n address:%s\n title:%s\n",
doc->address, doc->title);
}
}
/*
* Pop the previous filename, link and line number from the history list.
*/
PUBLIC void LYpop ARGS1(
document *, doc)
{
if (nhist > 0) {
nhist--;
doc->link = history[nhist].link;
doc->line = history[nhist].line;
FREE(doc->title);
doc->title = history[nhist].title; /* will be freed later */
FREE(doc->address);
doc->address = history[nhist].address; /* will be freed later */
FREE(doc->post_data);
doc->post_data = history[nhist].post_data;
FREE(doc->post_content_type);
doc->post_content_type = history[nhist].post_content_type;
FREE(doc->bookmark);
doc->bookmark = history[nhist].bookmark; /* will be freed later */
doc->isHEAD = history[nhist].isHEAD;
doc->safe = history[nhist].safe;
doc->internal_link = history[nhist].internal_link;
#ifdef DISP_PARTIAL
/* assume we pop the 'doc' to show it soon... */
Newline_partial = doc->line; /* reinitialize */
#endif /* DISP_PARTIAL */
CTRACE(tfp, "LYpop[%d]: address:%s\n title:%s\n",
nhist, doc->address, doc->title);
}
}
/*
* Pop the specified hist entry, link and line number from the history
* list but don't actually remove the entry, just return it.
* (This procedure is badly named :)
*/
PUBLIC void LYpop_num ARGS2(
int, number,
document *, doc)
{
if (number >= 0 && nhist > number) {
doc->link = history[number].link;
doc->line = history[number].line;
StrAllocCopy(doc->title, history[number].title);
StrAllocCopy(doc->address, history[number].address);
StrAllocCopy(doc->post_data, history[number].post_data);
StrAllocCopy(doc->post_content_type, history[number].post_content_type);
StrAllocCopy(doc->bookmark, history[number].bookmark);
doc->isHEAD = history[number].isHEAD;
doc->safe = history[number].safe;
doc->internal_link = history[number].internal_link; /* ?? */
#ifdef DISP_PARTIAL
/* assume we pop the 'doc' to show it soon... */
Newline_partial = doc->line; /* reinitialize */
#endif /* DISP_PARTIAL */
}
}
/*
* This procedure outputs the history buffer into a temporary file.
*/
PUBLIC int showhistory ARGS1(
char **, newfile)
{
static char tempfile[LY_MAXPATH];
char *Title = NULL;
int x = 0;
FILE *fp0;
LYRemoveTemp(tempfile);
if ((fp0 = LYOpenTemp(tempfile, HTML_SUFFIX, "w")) == NULL) {
HTAlert(CANNOT_OPEN_TEMP);
return(-1);
}
LYLocalFileToURL(newfile, tempfile);
LYforce_HTML_mode = TRUE; /* force this file to be HTML */
LYforce_no_cache = TRUE; /* force this file to be new */
BeginInternalPage(fp0, HISTORY_PAGE_TITLE, HISTORY_PAGE_HELP);
fprintf(fp0, "<tr align=right> <a href=\"LYNXMESSAGES:\">[%s]</a> </tr>\n",
STATUSLINES_TITLE);
fprintf(fp0, "<pre>\n");
fprintf(fp0, "<em>%s</em>\n", gettext("You selected:"));
for (x = nhist-1; x >= 0; x--) {
/*
* The number of the document in the hist stack,
* its title in a link, and its address. - FM
*/
if (history[x].title != NULL) {
StrAllocCopy(Title, history[x].title);
LYEntify(&Title, TRUE);
LYTrimLeading(Title);
LYTrimTrailing(Title);
if (*Title == '\0')
StrAllocCopy(Title , NO_TITLE);
} else {
StrAllocCopy(Title, NO_TITLE);
}
fprintf(fp0,
"%s<em>%d</em>. <tab id=t%d><a href=\"LYNXHIST:%d\">%s</a>\n",
(x > 99 ? "" : x < 10 ? " " : " "),
x, x, x, Title);
if (history[x].address != NULL) {
StrAllocCopy(Title, history[x].address);
LYEntify(&Title, TRUE);
} else {
StrAllocCopy(Title, gettext("(no address)"));
}
if (history[x].internal_link) {
if (history[x].intern_seq_start == history[nhist-1].intern_seq_start)
StrAllocCat(Title, gettext(" (internal)"));
else
StrAllocCat(Title, gettext(" (was internal)"));
}
fprintf(fp0, "<tab to=t%d>%s\n", x, Title);
}
fprintf(fp0,"</pre>\n");
EndInternalPage(fp0);
LYCloseTempFP(fp0);
FREE(Title);
return(0);
}
/*
* This function makes the history page seem like any other type of
* file since more info is needed than can be provided by the normal
* link structure. We saved out the history number to a special URL.
* The info looks like: LYNXHIST:#
*/
PUBLIC BOOLEAN historytarget ARGS1(
document *, newdoc)
{
int number;
DocAddress WWWDoc;
HTParentAnchor *tmpanchor;
HText *text;
BOOLEAN treat_as_intern = FALSE;
if ((!newdoc || !newdoc->address) ||
strlen(newdoc->address) < 10 || !isdigit(*(newdoc->address+9)))
return(FALSE);
if ((number = atoi(newdoc->address+9)) > nhist || number < 0)
return(FALSE);
/*
* Optimization: assume we came from the History Page,
* so never return back - always a new version next time.
* But check first whether HTMainText is really the History
* Page document - in some obscure situations this may not be
* the case. If HTMainText seems to be a History Page document,
* also check that it really hasn't been pushed. - LP, kw
*/
if (HTMainText && nhist > 0 &&
!strcmp(HTLoadedDocumentTitle(), HISTORY_PAGE_TITLE) &&
!LYwouldPush(HTLoadedDocumentURL(), HTLoadedDocumentTitle()) &&
strcmp(HTLoadedDocumentURL(), history[nhist-1].address)) {
HTuncache_current_document(); /* don't waste the cache */
}
LYpop_num(number, newdoc);
if (((newdoc->internal_link &&
history[number].intern_seq_start == history[nhist-1].intern_seq_start) ||
(number < nhist-1 &&
history[nhist-1].internal_link &&
number == history[nhist-1].intern_seq_start))
&& !(LYforce_no_cache == TRUE && LYoverride_no_cache == FALSE)) {
#ifndef DONT_TRACK_INTERNAL_LINKS
LYforce_no_cache = FALSE;
LYinternal_flag = TRUE;
newdoc->internal_link = TRUE;
treat_as_intern = TRUE;
#endif
} else {
newdoc->internal_link = FALSE;
}
/*
* If we have POST content, and have LYresubmit_posts set
* or have no_cache set or do not still have the text cached,
* ask the user whether to resubmit the form. - FM
*/
if (newdoc->post_data != NULL) {
WWWDoc.address = newdoc->address;
WWWDoc.post_data = newdoc->post_data;
WWWDoc.post_content_type = newdoc->post_content_type;
WWWDoc.bookmark = newdoc->bookmark;
WWWDoc.isHEAD = newdoc->isHEAD;
WWWDoc.safe = newdoc->safe;
tmpanchor = HTAnchor_parent(HTAnchor_findAddress(&WWWDoc));
text = (HText *)HTAnchor_document(tmpanchor);
if (((((LYresubmit_posts == TRUE) ||
(LYforce_no_cache == TRUE &&
LYoverride_no_cache == FALSE)) &&
!(treat_as_intern && !reloading)) ||
text == NULL) &&
(!strncmp(newdoc->address, "LYNXIMGMAP:", 11) ||
HTConfirm(CONFIRM_POST_RESUBMISSION) == TRUE)) {
LYforce_no_cache = TRUE;
LYoverride_no_cache = FALSE;
} else if (text != NULL) {
LYforce_no_cache = FALSE;
LYoverride_no_cache = TRUE;
} else {
HTInfoMsg(CANCELLED);
return(FALSE);
}
}
if (number != 0)
StrAllocCat(newdoc->title, gettext(" (From History)"));
return(TRUE);
}
/*
* This procedure outputs the Visited Links
* list into a temporary file. - FM
*/
PUBLIC int LYShowVisitedLinks ARGS1(
char **, newfile)
{
static char tempfile[LY_MAXPATH];
char *Title = NULL;
char *Address = NULL;
int x;
FILE *fp0;
VisitedLink *vl;
HTList *cur = Visited_Links;
if (!cur)
return(-1);
LYRemoveTemp(tempfile);
if ((fp0 = LYOpenTemp(tempfile, HTML_SUFFIX, "w")) == NULL) {
HTAlert(CANNOT_OPEN_TEMP);
return(-1);
}
LYLocalFileToURL(newfile, tempfile);
LYforce_HTML_mode = TRUE; /* force this file to be HTML */
LYforce_no_cache = TRUE; /* force this file to be new */
BeginInternalPage(fp0, VISITED_LINKS_TITLE, VISITED_LINKS_HELP);
fprintf(fp0, "<pre>\n");
fprintf(fp0, "<em>%s</em>\n",
gettext("You visited (POSTs, bookmark, menu and list files excluded):"));
x = HTList_count(Visited_Links);
while (NULL != (vl = (VisitedLink *)HTList_nextObject(cur))) {
/*
* The number of the document (most recent highest),
* its title in a link, and its address. - FM
*/
x--;
if (vl->title != NULL && *vl->title != '\0') {
StrAllocCopy(Title, vl->title);
LYEntify(&Title, TRUE);
LYTrimLeading(Title);
LYTrimTrailing(Title);
if (*Title == '\0')
StrAllocCopy(Title , NO_TITLE);
} else {
StrAllocCopy(Title , NO_TITLE);
}
if (vl->address != NULL && *vl->address != '\0') {
StrAllocCopy(Address, vl->address);
LYEntify(&Address, FALSE);
fprintf(fp0,
"%s<em>%d</em>. <tab id=t%d><a href=\"%s\">%s</a>\n",
(x > 99 ? "" : x < 10 ? " " : " "),
x, x, Address, Title);
} else {
fprintf(fp0,
"%s<em>%d</em>. <tab id=t%d><em>%s</em>\n",
(x > 99 ? "" : x < 10 ? " " : " "),
x, x, Title);
}
if (Address != NULL) {
StrAllocCopy(Address, vl->address);
LYEntify(&Address, TRUE);
}
fprintf(fp0, "<tab to=t%d>%s\n", x,
((Address != NULL) ? Address : gettext("(no address)")));
}
fprintf(fp0,"</pre>\n");
EndInternalPage(fp0);
LYCloseTempFP(fp0);
FREE(Title);
FREE(Address);
return(0);
}
/*
* Keep cycled buffer for statusline messages.
*/
#define STATUSBUFSIZE 40
PRIVATE char * buffstack[STATUSBUFSIZE];
PRIVATE int topOfStack = 0;
#ifdef LY_FIND_LEAKS
PRIVATE int already_registered_free_messages_stack = 0;
#endif
#ifdef LY_FIND_LEAKS
PRIVATE void free_messages_stack NOARGS
{
topOfStack = STATUSBUFSIZE;
while (--topOfStack >= 0) {
FREE(buffstack[topOfStack]);
}
}
#endif
PRIVATE void to_stack ARGS1(char *, str)
{
/*
* Cycle buffer:
*/
if (topOfStack == STATUSBUFSIZE) {
topOfStack = 0;
}
/*
* Register string.
*/
FREE(buffstack[topOfStack]);
buffstack[topOfStack] = str;
topOfStack++;
#ifdef LY_FIND_LEAKS
if(!already_registered_free_messages_stack) {
already_registered_free_messages_stack = 1;
atexit(free_messages_stack);
}
#endif
}
/*
* Status line messages list, LYNXMESSAGES:/ internal page,
* called from getfile().
*/
PUBLIC int LYshow_statusline_messages ARGS1(
document *, newdoc)
{
static char tempfile[LY_MAXPATH];
static char *info_url;
FILE *fp0;
int i;
LYRemoveTemp(tempfile);
if ((fp0 = LYOpenTemp (tempfile, HTML_SUFFIX, "w")) == 0) {
HTAlert(CANNOT_OPEN_TEMP);
return(NOT_FOUND);
}
LYLocalFileToURL(&info_url, tempfile);
LYforce_no_cache = TRUE; /* don't cache this doc */
BeginInternalPage (fp0, STATUSLINES_TITLE, NULL);
fprintf(fp0, "<pre>\n");
fprintf(fp0, "<ol>\n");
/* print messages in reverse order: */
i = topOfStack;
while (--i >= 0) {
if (buffstack[i] != NULL)
fprintf(fp0, "<li> <em>%s</em>\n", buffstack[i]);
}
i = STATUSBUFSIZE;
while (--i >= topOfStack) {
if (buffstack[i] != NULL)
fprintf(fp0, "<li> <em>%s</em>\n", buffstack[i]);
}
fprintf(fp0, "</ol>\n");
fprintf(fp0, "</pre>\n");
EndInternalPage(fp0);
LYCloseTempFP(fp0);
/* exit to getfile() cycle */
StrAllocCopy(newdoc->address, info_url);
FREE(newdoc->post_data);
FREE(newdoc->post_content_type);
FREE(newdoc->bookmark);
newdoc->isHEAD = FALSE;
/* Leave loading it to getfile - that has the advantage to make
this kind of link 'd'ownloadable. - kw */
return(NORMAL);
}
/*
* Dump statusline messages into the buffer.
* Called from mainloop() when exit immediately with an error:
* can not access startfile (first_file) so a couple of alert messages
* will be very useful on exit.
* (Don't expect everyone will look a trace log in case of difficulties:))
*/
PUBLIC void LYstatusline_messages_on_exit ARGS1(
char **, buf)
{
int i;
StrAllocCat(*buf, "\n");
/* print messages in chronological order:
* probably a single message but let's do it.
*/
i = topOfStack - 1;
while (++i <= STATUSBUFSIZE) {
if (buffstack[i] != NULL) {
StrAllocCat(*buf, buffstack[i]);
StrAllocCat(*buf, "\n");
}
}
i = -1;
while (++i < topOfStack) {
if (buffstack[i] != NULL) {
StrAllocCat(*buf, buffstack[i]);
StrAllocCat(*buf, "\n");
}
}
}
PUBLIC void LYstore_message2 ARGS2(
CONST char *, message,
CONST char *, argument)
{
if (message != NULL) {
char *temp = NULL;
HTSprintf(&temp, message, (argument == 0) ? "" : argument);
to_stack(temp);
}
}
PUBLIC void LYstore_message ARGS1(
CONST char *, message)
{
if (message != NULL) {
char *temp = NULL;
StrAllocCopy(temp, message);
to_stack(temp);
}
}
|