home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / lynx2.8.1dev.10.tar.gz / lynx2.8.1dev.10.tar / lynx2-8 / src / LYHistory.c < prev    next >
C/C++ Source or Header  |  1998-04-23  |  19KB  |  633 lines

  1. #include <HTUtils.h>
  2. #include <tcp.h>
  3. #include <HTTP.h>
  4. #include <HTAlert.h>
  5. #include <HText.h>
  6. #include <LYGlobalDefs.h>
  7. #include <LYUtils.h>
  8. #include <LYHistory.h>
  9. #include <LYPrint.h>
  10. #include <LYDownload.h>
  11. #include <LYKeymap.h>
  12. #include <LYList.h>
  13. #include <LYShowInfo.h>
  14. #include <LYSignal.h>
  15. #include <LYStrings.h>
  16. #include <LYCharUtils.h>
  17.  
  18. #ifdef DIRED_SUPPORT
  19. #include <LYUpload.h>
  20. #include <LYLocal.h>
  21. #endif /* DIRED_SUPPORT */
  22.  
  23. #include <LYexit.h>
  24. #include <LYLeaks.h>
  25.  
  26. #define FREE(x) if (x) {free(x); x = NULL;}
  27.  
  28. PUBLIC HTList * Visited_Links = NULL;    /* List of safe popped docs. */
  29.  
  30. /*
  31.  *  Utility for freeing the list of visited links. - FM
  32.  */
  33. PRIVATE void Visited_Links_free NOARGS
  34. {
  35.     VisitedLink *vl;
  36.     HTList *cur = Visited_Links;
  37.  
  38.     if (!cur)
  39.     return;
  40.  
  41.     while (NULL != (vl = (VisitedLink *)HTList_nextObject(cur))) {
  42.     FREE(vl->address);
  43.     FREE(vl->title);
  44.     FREE(vl);
  45.     }
  46.     HTList_delete(Visited_Links);
  47.     Visited_Links = NULL;
  48.     return;
  49. }
  50.  
  51. /*
  52.  *  Utility for listing visited links, making any repeated
  53.  *  links the most current in the list. - FM
  54.  */
  55. PUBLIC void LYAddVisitedLink ARGS1(
  56.     document *,    doc)
  57. {
  58.     VisitedLink *new;
  59.     VisitedLink *old;
  60.     HTList *cur;
  61.  
  62.     if (!(doc->address && *doc->address))
  63.     return;
  64.  
  65.     /*
  66.      *    Exclude POST or HEAD replies, and bookmark, menu
  67.      *    or list files. - FM
  68.      */
  69.     if (doc->post_data || doc->isHEAD || doc->bookmark ||
  70.     !strcmp((doc->title ? doc->title : ""), HISTORY_PAGE_TITLE) ||
  71.     !strcmp((doc->title ? doc->title : ""), PRINT_OPTIONS_TITLE) ||
  72.     !strcmp((doc->title ? doc->title : ""), DOWNLOAD_OPTIONS_TITLE) ||
  73. #ifdef DIRED_SUPPORT
  74.     !strcmp((doc->title ? doc->title : ""), DIRED_MENU_TITLE) ||
  75.     !strcmp((doc->title ? doc->title : ""), UPLOAD_OPTIONS_TITLE) ||
  76.     !strcmp((doc->title ? doc->title : ""), PERMIT_OPTIONS_TITLE) ||
  77. #endif /* DIRED_SUPPORT */
  78.     !strcmp((doc->title ? doc->title : ""), CURRENT_KEYMAP_TITLE) ||
  79.     !strcmp((doc->title ? doc->title : ""), LIST_PAGE_TITLE) ||
  80.     !strcmp((doc->title ? doc->title : ""), SHOWINFO_TITLE) ||
  81.     !strcmp((doc->title ? doc->title : ""), COOKIE_JAR_TITLE) ||
  82.     !strcmp((doc->title ? doc->title : ""), VISITED_LINKS_TITLE) ||
  83.     !strcmp((doc->title ? doc->title : ""), LYNX_TRACELOG_TITLE)) {
  84.     return;
  85.     }
  86.  
  87.     if ((new = (VisitedLink *)calloc(1, sizeof(*new))) == NULL)
  88.     outofmem(__FILE__, "HTAddVisitedLink");
  89.     StrAllocCopy(new->address, doc->address);
  90.     StrAllocCopy(new->title, (doc->title ? doc->title : "(no title)"));
  91.  
  92.     if (!Visited_Links) {
  93.     Visited_Links = HTList_new();
  94.     atexit(Visited_Links_free);
  95.     HTList_addObject(Visited_Links, new);
  96.     return;
  97.     }
  98.  
  99.     cur = Visited_Links;
  100.     while (NULL != (old = (VisitedLink *)HTList_nextObject(cur))) {
  101.     if (!strcmp((old->address ? old->address : ""),
  102.             (new->address ? new->address : "")) &&
  103.         !strcmp((old->title ? new->title : ""),
  104.             (new->title ? new->title : ""))) {
  105.         FREE(old->address);
  106.         FREE(old->title);
  107.         HTList_removeObject(Visited_Links, old);
  108.         FREE(old);
  109.         break;
  110.     }
  111.     }
  112.     HTList_addObject(Visited_Links, new);
  113.  
  114.     return;
  115. }
  116.  
  117. /*
  118.  *  Push the current filename, link and line number onto the history list.
  119.  */
  120. PUBLIC void LYpush ARGS2(
  121.     document *,    doc,
  122.     BOOLEAN,    force_push)
  123. {
  124.     /*
  125.      *    Don't push NULL file names.
  126.      */
  127.     if (*doc->address == '\0')
  128.     return;
  129.  
  130.     /*
  131.      *    Check whether this is a document we
  132.      *    don't push unless forced. - FM
  133.      */
  134.     if (!force_push) {
  135.     /*
  136.      *  Don't push the history, printer, or download lists.
  137.      */
  138.     if (!strcmp(doc->title, HISTORY_PAGE_TITLE) ||
  139.         !strcmp(doc->title, PRINT_OPTIONS_TITLE) ||
  140.         !strcmp(doc->title, DOWNLOAD_OPTIONS_TITLE)) {
  141.         if (!LYforce_no_cache)
  142.         LYoverride_no_cache = TRUE;
  143.         return;
  144.     }
  145.  
  146. #ifdef DIRED_SUPPORT
  147.     /*
  148.      *  Don't push DIRED menu, upload or permit lists.
  149.      */
  150.     if (!strcmp(doc->title, DIRED_MENU_TITLE) ||
  151.         !strcmp(doc->title, UPLOAD_OPTIONS_TITLE) ||
  152.         !strcmp(doc->title, PERMIT_OPTIONS_TITLE)) {
  153.         if (!LYforce_no_cache)
  154.         LYoverride_no_cache = TRUE;
  155.         return;
  156.     }
  157. #endif /* DIRED_SUPPORT */
  158.     }
  159.  
  160.     /*
  161.      *    If file is identical to one before it, don't push it.
  162.      */
  163.     if (nhist> 1 &&
  164.     STREQ(history[nhist-1].address, doc->address) &&
  165.     !strcmp(history[nhist-1].post_data ?
  166.         history[nhist-1].post_data : "",
  167.         doc->post_data ?
  168.         doc->post_data : "") &&
  169.     !strcmp(history[nhist-1].bookmark ?
  170.         history[nhist-1].bookmark : "",
  171.         doc->bookmark ?
  172.         doc->bookmark : "") &&
  173.     history[nhist-1].isHEAD == doc->isHEAD) {
  174.     if (history[nhist-1].internal_link == doc->internal_link) {
  175.         /* But it is nice to have the last position remembered!
  176.            - kw */
  177.         history[nhist-1].link = doc->link;
  178.         history[nhist-1].page = doc->line;
  179.         return;
  180.     }
  181.     }
  182.  
  183. #ifdef NOTDEFINED
  184. /*
  185. **  The following segment not used any more - What's it good for,
  186. **  anyway??  Doing a pop when a push is requested is confusing,
  187. **  also to the user.  Moreover, the way it was done seems to cause
  188. **  a memory leak. - KW
  189. */  /*
  190.      *    If file is identical to one two before it, don't push it.
  191.      */
  192.     if (nhist > 2 &&
  193.     STREQ(history[nhist-2].address, doc->address) &&
  194.     !strcmp(history[nhist-2].post_data ?
  195.         history[nhist-2].post_data : "",
  196.         doc->post_data ?
  197.         doc->post_data : "") &&
  198.     !strcmp(history[nhist-2].bookmark ?
  199.         history[nhist-2].bookmark : "",
  200.         doc->bookmark ?
  201.         doc->bookmark : "") &&
  202.     history[nhist-2].isHEAD == doc->isHEAD) {
  203.     /*
  204.      *  Pop one off the stack.
  205.      */
  206.     nhist--;
  207.     return;
  208.     }
  209. #endif /* NOTDEFINED */
  210.  
  211.     /*
  212.      *    OK, push it if we have stack space.
  213.      */
  214.     if (nhist < MAXHIST)  {
  215.     history[nhist].link = doc->link;
  216.     history[nhist].page = doc->line;
  217.     history[nhist].title = NULL;
  218.     StrAllocCopy(history[nhist].title, doc->title);
  219.     history[nhist].address = NULL;
  220.     StrAllocCopy(history[nhist].address, doc->address);
  221.     history[nhist].post_data = NULL;
  222.     StrAllocCopy(history[nhist].post_data, doc->post_data);
  223.     history[nhist].post_content_type = NULL;
  224.     StrAllocCopy(history[nhist].post_content_type, doc->post_content_type);
  225.     history[nhist].bookmark = NULL;
  226.     StrAllocCopy(history[nhist].bookmark, doc->bookmark);
  227.     history[nhist].isHEAD = doc->isHEAD;
  228.     history[nhist].safe = doc->safe;
  229.  
  230.     history[nhist].internal_link = FALSE; /* by default */
  231.     history[nhist].intern_seq_start = -1; /* by default */
  232.     if (doc->internal_link) {
  233.         /* Now some tricky stuff: if the caller thinks that the doc
  234.            to push was the result of following an internal
  235.            (fragment) link, we check whether we believe it.
  236.            It is only accepted as valid if the immediately preceding
  237.            item on the history stack is actually the same document
  238.            except for fragment and location info.  I.e. the Parent
  239.            Anchors are the same.
  240.            Also of course this requires that this is not the first
  241.            history item. - kw */
  242.         if (nhist > 0) {
  243.         DocAddress WWWDoc;
  244.         HTParentAnchor *thisparent, *thatparent = NULL;
  245.         WWWDoc.address = doc->address;
  246.         WWWDoc.post_data = doc->post_data;
  247.         WWWDoc.post_content_type = doc->post_content_type;
  248.         WWWDoc.bookmark = doc->bookmark;
  249.         WWWDoc.isHEAD = doc->isHEAD;
  250.         WWWDoc.safe = doc->safe;
  251.         thisparent =
  252.             HTAnchor_parent(HTAnchor_findAddress(&WWWDoc));
  253.         /* Now find the ParentAnchor for the previous history
  254.         ** item - kw
  255.         */
  256.         if (thisparent) {
  257.             /* If the last-pushed item is a LYNXIMGMAP but THIS one
  258.             ** isn't, compare the physical URLs instead. - kw
  259.             */
  260.             if (0==strncmp(history[nhist-1].address,"LYNXIMGMAP:",11) &&
  261.             0!=strncmp(doc->address,"LYNXIMGMAP:",11)) {
  262.             WWWDoc.address = history[nhist-1].address + 11;
  263.             /*
  264.             ** If THIS item is a LYNXIMGMAP but the last-pushed one
  265.             ** isn't, fake it by using THIS item's address for
  266.             ** thatparent... - kw
  267.             */
  268.             } else if ((0==strncmp(doc->address,"LYNXIMGMAP:",11) &&
  269.                0!=strncmp(history[nhist-1].address,"LYNXIMGMAP:",11))) {
  270.             char *temp = NULL;
  271.             StrAllocCopy(temp, "LYNXIMGMAP:");
  272.             StrAllocCat(temp, doc->address+11);
  273.             WWWDoc.address = temp;
  274.             WWWDoc.post_content_type = history[nhist-1].post_content_type;
  275.             WWWDoc.bookmark = history[nhist-1].bookmark;
  276.             WWWDoc.isHEAD = history[nhist-1].isHEAD;
  277.             WWWDoc.safe = history[nhist-1].safe;
  278.             thatparent =
  279.                 HTAnchor_parent(HTAnchor_findAddress(&WWWDoc));
  280.             FREE(temp);
  281.             } else {
  282.             WWWDoc.address = history[nhist-1].address;
  283.             }
  284.             if (!thatparent) { /* if not yet done */
  285.             WWWDoc.post_data = history[nhist-1].post_data;
  286.             WWWDoc.post_content_type = history[nhist-1].post_content_type;
  287.             WWWDoc.bookmark = history[nhist-1].bookmark;
  288.             WWWDoc.isHEAD = history[nhist-1].isHEAD;
  289.             WWWDoc.safe = history[nhist-1].safe;
  290.             thatparent =
  291.                 HTAnchor_parent(HTAnchor_findAddress(&WWWDoc));
  292.             }
  293.         /* In addition to equality of the ParentAnchors, require
  294.         ** that IF we have a HTMainText (i.e. it wasn't just
  295.         ** HTuncache'd by mainloop), THEN it has to be consistent
  296.         ** with what we are trying to push.
  297.         **   This may be overkill... - kw
  298.         */
  299.             if (thatparent == thisparent &&
  300.             (!HTMainText || HTMainAnchor == thisparent)
  301.             ) {
  302.             history[nhist].internal_link = TRUE;
  303.             history[nhist].intern_seq_start =
  304.                 history[nhist-1].intern_seq_start >= 0 ?
  305.                 history[nhist-1].intern_seq_start : nhist-1;
  306.             CTRACE(tfp, "\nLYpush: pushed as internal link, OK\n");
  307.             }
  308.         }
  309.         }
  310.         if (!history[nhist].internal_link) {
  311.         CTRACE(tfp, "\nLYpush: push as internal link requested, %s\n",
  312.                 "but didn't check out!");
  313.         }
  314.     }
  315.     nhist++;
  316.     CTRACE(tfp, "\nLYpush: address:%s\n        title:%s\n",
  317.             doc->address, doc->title);
  318.     } else {
  319.     if (LYCursesON) {
  320.         _statusline(MAXHIST_REACHED);
  321.         sleep(AlertSecs);
  322.     }
  323.     CTRACE(tfp, "\nLYpush: MAXHIST reached for:\n        address:%s\n        title:%s\n",
  324.             doc->address, doc->title);
  325.     }
  326. }
  327.  
  328. /*
  329.  *  Pop the previous filename, link and line number from the history list.
  330.  */
  331. PUBLIC void LYpop ARGS1(
  332.     document *,    doc)
  333. {
  334.     if (nhist > 0) {
  335.     nhist--;
  336.     doc->link = history[nhist].link;
  337.     doc->line = history[nhist].page;
  338.     FREE(doc->title);
  339.     doc->title = history[nhist].title;     /* will be freed later */
  340.     FREE(doc->address);
  341.     doc->address = history[nhist].address;     /* will be freed later */
  342.     FREE(doc->post_data);
  343.     doc->post_data = history[nhist].post_data;
  344.     FREE(doc->post_content_type);
  345.     doc->post_content_type = history[nhist].post_content_type;
  346.     FREE(doc->bookmark);
  347.     doc->bookmark = history[nhist].bookmark; /* will be freed later */
  348.     doc->isHEAD = history[nhist].isHEAD;
  349.     doc->safe = history[nhist].safe;
  350.     doc->internal_link = history[nhist].internal_link;
  351.     CTRACE(tfp, "LYpop: address:%s\n     title:%s\n",
  352.             doc->address, doc->title);
  353.     }
  354. }
  355.  
  356. /*
  357.  *  Pop the specified hist entry, link and line number from the history
  358.  *  list but don't actually remove the entry, just return it.
  359.  *  (This procedure is badly named :)
  360.  */
  361. PUBLIC void LYpop_num ARGS2(
  362.     int,        number,
  363.     document *,    doc)
  364. {
  365.     if (number >= 0 && nhist > number) {
  366.     doc->link = history[number].link;
  367.     doc->line = history[number].page;
  368.     StrAllocCopy(doc->title, history[number].title);
  369.     StrAllocCopy(doc->address, history[number].address);
  370.     StrAllocCopy(doc->post_data, history[number].post_data);
  371.     StrAllocCopy(doc->post_content_type, history[number].post_content_type);
  372.     StrAllocCopy(doc->bookmark, history[number].bookmark);
  373.     doc->isHEAD = history[number].isHEAD;
  374.     doc->safe = history[number].safe;
  375.     doc->internal_link = history[number].internal_link; /* ?? */
  376.     }
  377. }
  378.  
  379. /*
  380.  *  This procedure outputs the history buffer into a temporary file.
  381.  */
  382. PUBLIC int showhistory ARGS1(
  383.     char **,    newfile)
  384. {
  385.     static char tempfile[256];
  386.     static BOOLEAN first = TRUE;
  387.     static char hist_filename[256];
  388.     char *Title = NULL;
  389.     int x = 0;
  390.     FILE *fp0;
  391.  
  392.     if (first) {
  393.     tempname(tempfile, NEW_FILE);
  394.     /*
  395.      *  Make the file a URL now.
  396.      */
  397. #if defined (VMS) || defined (DOSPATH) || defined (__EMX__)
  398.     sprintf(hist_filename,"file://localhost/%s", tempfile);
  399. #else
  400.     sprintf(hist_filename,"file://localhost%s", tempfile);
  401. #endif /* VMS */
  402.     first = FALSE;
  403. #ifdef VMS
  404.     } else {
  405.     remove(tempfile);  /* Remove duplicates on VMS. */
  406. #endif /* VMS */
  407.     }
  408.  
  409.     if ((fp0 = LYNewTxtFile(tempfile)) == NULL) {
  410.     HTAlert(CANNOT_OPEN_TEMP);
  411.     return(-1);
  412.     }
  413.  
  414.     StrAllocCopy(*newfile, hist_filename);
  415.     LYforce_HTML_mode = TRUE;    /* force this file to be HTML */
  416.     LYforce_no_cache = TRUE;    /* force this file to be new */
  417.  
  418.     fprintf(fp0, "<head>\n");
  419.     LYAddMETAcharsetToFD(fp0, -1);
  420.     fprintf(fp0, "<title>%s</title>\n</head>\n<body>\n",
  421.          HISTORY_PAGE_TITLE);
  422.     fprintf(fp0, "<h1>You have reached the History Page</h1>\n");
  423.     fprintf(fp0, "<h2>%s Version %s</h2>\n<pre>", LYNX_NAME, LYNX_VERSION);
  424.     fprintf(fp0, "<em>You selected:</em>\n");
  425.     for (x = nhist-1; x >= 0; x--) {
  426.     /*
  427.      *  The number of the document in the hist stack,
  428.      *  its title in a link, and its address. - FM
  429.      */
  430.     if (history[x].title != NULL) {
  431.         StrAllocCopy(Title, history[x].title);
  432.         LYEntify(&Title, TRUE);
  433.     } else {
  434.         StrAllocCopy(Title, "(no title)");
  435.     }
  436.     fprintf(fp0,
  437.         "%s<em>%d</em>. <tab id=t%d><a href=\"LYNXHIST:%d\">%s</a>\n",
  438.         (x > 99 ? "" : x < 10 ? "  " : " "),
  439.         x, x, x, Title);
  440.     if (history[x].address != NULL) {
  441.         StrAllocCopy(Title, history[x].address);
  442.         LYEntify(&Title, TRUE);
  443.     } else {
  444.         StrAllocCopy(Title, "(no address)");
  445.     }
  446.     if (history[x].internal_link) {
  447.         if (history[x].intern_seq_start == history[nhist-1].intern_seq_start)
  448.         StrAllocCat(Title, " (internal)");
  449.         else
  450.         StrAllocCat(Title, " (was internal)");
  451.     }
  452.     fprintf(fp0, "<tab to=t%d>%s\n", x, Title);
  453.     }
  454.  
  455.     fprintf(fp0,"</pre>\n</body>\n");
  456.  
  457.     fclose(fp0);
  458.     FREE(Title);
  459.     return(0);
  460. }
  461.  
  462. /*
  463.  *  This function makes the history page seem like any other type of
  464.  *  file since more info is needed than can be provided by the normal
  465.  *  link structure.  We saved out the history number to a special URL.
  466.  *  The info looks like:  LYNXHIST:#
  467.  */
  468. PUBLIC BOOLEAN historytarget ARGS1(
  469.     document *,    newdoc)
  470. {
  471.     int number;
  472.     DocAddress WWWDoc;
  473.     HTParentAnchor *tmpanchor;
  474.     HText *text;
  475.     BOOLEAN treat_as_intern = FALSE;
  476.  
  477.     if ((!newdoc || !newdoc->address) ||
  478.     strlen(newdoc->address) < 10 || !isdigit(*(newdoc->address+9)))
  479.     return(FALSE);
  480.  
  481.     if ((number = atoi(newdoc->address+9)) > nhist || number < 0)
  482.     return(FALSE);
  483.  
  484.     LYpop_num(number, newdoc);
  485.     if (((newdoc->internal_link &&
  486.       history[number].intern_seq_start == history[nhist-1].intern_seq_start) ||
  487.      (number < nhist-1 &&
  488.       history[nhist-1].internal_link &&
  489.       number == history[nhist-1].intern_seq_start))
  490.     && !(LYforce_no_cache == TRUE && LYoverride_no_cache == FALSE)) {
  491. #ifndef DONT_TRACK_INTERNAL_LINKS
  492.     LYforce_no_cache = FALSE;
  493.     LYinternal_flag = TRUE;
  494.     newdoc->internal_link = TRUE;
  495.     treat_as_intern = TRUE;
  496. #endif
  497.     } else {
  498.     newdoc->internal_link = FALSE;
  499.     }
  500.     /*
  501.      *    If we have POST content, and have LYresubmit_posts set
  502.      *    or have no_cache set or do not still have the text cached,
  503.      *    ask the user whether to resubmit the form. - FM
  504.      */
  505.     if (newdoc->post_data != NULL) {
  506.     WWWDoc.address = newdoc->address;
  507.     WWWDoc.post_data = newdoc->post_data;
  508.     WWWDoc.post_content_type = newdoc->post_content_type;
  509.     WWWDoc.bookmark = newdoc->bookmark;
  510.     WWWDoc.isHEAD = newdoc->isHEAD;
  511.     WWWDoc.safe = newdoc->safe;
  512.     tmpanchor = HTAnchor_parent(HTAnchor_findAddress(&WWWDoc));
  513.     text = (HText *)HTAnchor_document(tmpanchor);
  514.     if (((((LYresubmit_posts == TRUE) ||
  515.            (LYforce_no_cache == TRUE &&
  516.         LYoverride_no_cache == FALSE)) &&
  517.           !(treat_as_intern && !reloading)) ||
  518.          text == NULL) &&
  519.         (!strncmp(newdoc->address, "LYNXIMGMAP:", 11) ||
  520.          HTConfirm(CONFIRM_POST_RESUBMISSION) == TRUE)) {
  521.         LYforce_no_cache = TRUE;
  522.         LYoverride_no_cache = FALSE;
  523.     } else if (text != NULL) {
  524.         LYforce_no_cache = FALSE;
  525.         LYoverride_no_cache = TRUE;
  526.     } else {
  527.         _statusline(CANCELLED);
  528.         sleep(InfoSecs);
  529.         return(FALSE);
  530.     }
  531.     }
  532.  
  533.     if (number != 0)
  534.     StrAllocCat(newdoc->title," (From History)");
  535.     return(TRUE);
  536. }
  537.  
  538. /*
  539.  *  This procedure outputs the Visited Links
  540.  *  list into a temporary file. - FM
  541.  */
  542. PUBLIC int LYShowVisitedLinks ARGS1(
  543.     char **,    newfile)
  544. {
  545.     static char tempfile[256];
  546.     static BOOLEAN first = TRUE;
  547.     static char vl_filename[256];
  548.     char *Title = NULL;
  549.     char *Address = NULL;
  550.     int x;
  551.     FILE *fp0;
  552.     VisitedLink *vl;
  553.     HTList *cur = Visited_Links;
  554.  
  555.     if (!cur)
  556.     return(-1);
  557.  
  558.     if (first) {
  559.     tempname(tempfile, NEW_FILE);
  560.     /*
  561.      *  Make the file a URL now.
  562.      */
  563. #if defined (VMS) || defined (DOSPATH) || defined (__EMX__)
  564.     sprintf(vl_filename,"file://localhost/%s", tempfile);
  565. #else
  566.     sprintf(vl_filename,"file://localhost%s", tempfile);
  567. #endif /* VMS */
  568.     first = FALSE;
  569. #ifdef VMS
  570.     } else {
  571.     remove(tempfile);  /* Remove duplicates on VMS. */
  572. #endif /* VMS */
  573.     }
  574.  
  575.     if ((fp0 = LYNewTxtFile(tempfile)) == NULL) {
  576.     HTAlert(CANNOT_OPEN_TEMP);
  577.     return(-1);
  578.     }
  579.  
  580.     StrAllocCopy(*newfile, vl_filename);
  581.     LYforce_HTML_mode = TRUE;    /* force this file to be HTML */
  582.     LYforce_no_cache = TRUE;    /* force this file to be new */
  583.  
  584.     fprintf(fp0, "<head>\n");
  585.     LYAddMETAcharsetToFD(fp0, -1);
  586.     fprintf(fp0, "<title>%s</title>\n</head>\n<body>\n",
  587.          VISITED_LINKS_TITLE);
  588.     fprintf(fp0, "<h1>You have reached the Visited Links Page</h1>\n");
  589.     fprintf(fp0, "<h2>%s Version %s</h2>\n<pre>", LYNX_NAME, LYNX_VERSION);
  590.     fprintf(fp0,
  591.   "<em>You visited (POSTs, bookmark, menu and list files excluded):</em>\n");
  592.     x = HTList_count(Visited_Links);
  593.     while (NULL != (vl = (VisitedLink *)HTList_nextObject(cur))) {
  594.     /*
  595.      *  The number of the document (most recent highest),
  596.      *  its title in a link, and its address. - FM
  597.      */
  598.     x--;
  599.     if (vl->title != NULL && *vl->title != '\0') {
  600.         StrAllocCopy(Title, vl->title);
  601.         LYEntify(&Title, TRUE);
  602.     } else {
  603.         StrAllocCopy(Title , "(no title)");
  604.     }
  605.     if (vl->address != NULL && *vl->address != '\0') {
  606.         StrAllocCopy(Address, vl->address);
  607.         LYEntify(&Address, FALSE);
  608.         fprintf(fp0,
  609.             "%s<em>%d</em>. <tab id=t%d><a href=\"%s\">%s</a>\n",
  610.             (x > 99 ? "" : x < 10 ? "  " : " "),
  611.             x, x, Address, Title);
  612.     } else {
  613.         fprintf(fp0,
  614.             "%s<em>%d</em>. <tab id=t%d><em>%s</em>\n",
  615.             (x > 99 ? "" : x < 10 ? "  " : " "),
  616.             x, x, Title);
  617.     }
  618.     if (Address != NULL) {
  619.         StrAllocCopy(Address, vl->address);
  620.         LYEntify(&Address, TRUE);
  621.     }
  622.     fprintf(fp0, "<tab to=t%d>%s\n", x,
  623.              ((Address != NULL) ? Address : "(no address)"));
  624.     }
  625.  
  626.     fprintf(fp0,"</pre>\n</body>\n");
  627.  
  628.     fclose(fp0);
  629.     FREE(Title);
  630.     FREE(Address);
  631.     return(0);
  632. }
  633.