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 / LYMainLoop.c < prev    next >
C/C++ Source or Header  |  1998-05-10  |  163KB  |  5,807 lines

  1. #include <HTUtils.h>
  2. #include <tcp.h>
  3. #include <HTAccess.h>
  4. #include <HTParse.h>
  5. #include <HTList.h>
  6. #include <HTML.h>
  7. #include <HTFTP.h>
  8. #include <HTFile.h>
  9. #include <HTTP.h>
  10. #include <HTAABrow.h>
  11. #include <HTNews.h>
  12. #include <LYCurses.h>
  13. #include <LYStyle.h>
  14. #include <LYGlobalDefs.h>
  15. #include <HTAlert.h>
  16. #include <LYUtils.h>
  17. #include <GridText.h>
  18. #include <LYStrings.h>
  19. #include <LYOptions.h>
  20. #include <LYSignal.h>
  21. #include <LYGetFile.h>
  22. #include <HTForms.h>
  23. #include <LYSearch.h>
  24. #include <LYClean.h>
  25. #include <LYHistory.h>
  26. #include <LYPrint.h>
  27. #include <LYMail.h>
  28. #include <LYEdit.h>
  29. #include <LYShowInfo.h>
  30. #include <LYBookmark.h>
  31. #include <LYSystem.h>
  32. #include <LYKeymap.h>
  33. #include <LYJump.h>
  34. #include <LYDownload.h>
  35. #include <LYList.h>
  36. #include <LYMap.h>
  37. #include <LYTraversal.h>
  38. #include <LYCharSets.h>
  39. #include <LYCharUtils.h>
  40. #include <LYCookie.h>
  41. #include <LYMainLoop.h>
  42. #ifdef DOSPATH
  43. #include <HTDOS.h>
  44. #endif
  45.  
  46. #ifdef USE_EXTERNALS
  47. #include <LYExtern.h>
  48. #endif
  49.  
  50. #ifdef VMS
  51. #include <HTVMSUtils.h>
  52. #endif /* VMS */
  53.  
  54. #ifdef DIRED_SUPPORT
  55. #include <LYLocal.h>
  56. #include <LYUpload.h>
  57. #endif /* DIRED_SUPPORT */
  58.  
  59. #include <LYexit.h>
  60. #include <LYLeaks.h>
  61.  
  62. PRIVATE BOOL confirm_post_resub PARAMS((
  63.     CONST char*     address,
  64.     CONST char*     title,
  65.     int         if_imgmap,
  66.     int         if_file));
  67. PRIVATE int are_different PARAMS((document *doc1, document *doc2));
  68. PUBLIC void HTGotoURLs_free NOPARAMS;
  69. PUBLIC void HTAddGotoURL PARAMS((char *url));
  70.  
  71. #ifndef DONT_TRACK_INTERNAL_LINKS
  72. PRIVATE int are_phys_different PARAMS((document *doc1, document *doc2));
  73. #endif
  74.  
  75. #define FASTTAB
  76. #ifdef FASTTAB
  77. PRIVATE int sametext ARGS2(
  78.     char *,     een,
  79.     char *,     twee)
  80. {
  81.     if (een && twee)
  82.     return (strcmp(een, twee) == 0);
  83.     return TRUE;
  84. }
  85. #endif /* FASTTAB */
  86.  
  87. #define FREE(x) if (x) {free(x); x = NULL;}
  88.  
  89. PUBLIC    HTList * Goto_URLs = NULL;  /* List of Goto URLs */
  90.  
  91. PUBLIC char * LYRequestTitle = NULL; /* newdoc.title in calls to getfile() */
  92.  
  93. PUBLIC int Newline = 0; /* HText_pageDisplay() requires it */
  94.  
  95. PRIVATE document newdoc;
  96. PRIVATE document curdoc;
  97. PRIVATE char *traversal_host = NULL;
  98. PRIVATE char *traversal_link_to_add = NULL;
  99. PRIVATE char *CurrentUserAgent = NULL;
  100. PRIVATE char *CurrentNegoLanguage = NULL;
  101. PRIVATE char *CurrentNegoCharset = NULL;
  102.  
  103. /*
  104.  *  Function for freeing allocated mainloop() variables. - FM
  105.  */
  106. PRIVATE void free_mainloop_variables NOARGS
  107. {
  108.     FREE(newdoc.title);
  109.     FREE(newdoc.address);
  110.     FREE(newdoc.post_data);
  111.     FREE(newdoc.post_content_type);
  112.     FREE(newdoc.bookmark);
  113.     FREE(curdoc.title);
  114.     FREE(curdoc.address);
  115.     FREE(curdoc.post_data);
  116.     FREE(curdoc.post_content_type);
  117.     FREE(curdoc.bookmark);
  118. #ifdef USE_HASH
  119.     FREE(curdoc.style);
  120.     FREE(newdoc.style);
  121. #endif
  122.     FREE(traversal_host);
  123.     FREE(traversal_link_to_add);
  124.     FREE(CurrentUserAgent);
  125.     FREE(CurrentNegoLanguage);
  126.     FREE(CurrentNegoCharset);
  127. #ifdef DIRED_SUPPORT
  128.     clear_tags();
  129. #endif /* DIRED_SUPPORT */
  130.  
  131.     return;
  132. }
  133.  
  134. PUBLIC FILE *TraceFP NOARGS
  135. {
  136.     if (LYTraceLogFP != 0) {
  137.     return LYTraceLogFP;
  138.     }
  139.     return stderr;
  140. }
  141.  
  142. PRIVATE void TracelogOpenFailed NOARGS
  143. {
  144.     WWW_TraceFlag = FALSE;
  145.     _statusline(TRACELOG_OPEN_FAILED);
  146.     sleep(MessageSecs);
  147. }
  148.  
  149. PUBLIC void LYCloseTracelog NOARGS
  150. {
  151.     if (LYTraceLogFP != 0) {
  152.     fflush(stdout);
  153.     fflush(stderr);
  154.     fclose(LYTraceLogFP);
  155.     LYTraceLogFP = 0;
  156.     }
  157. }
  158.  
  159. PRIVATE BOOLEAN LYReopenTracelog ARGS1(BOOLEAN *, trace_flag_ptr)
  160. {
  161.     CTRACE(tfp, "\nTurning off TRACE for fetch of log.\n");
  162.     LYCloseTracelog();
  163.     if ((LYTraceLogFP = LYAppendToTxtFile(LYTraceLogPath)) == NULL) {
  164.     TracelogOpenFailed();
  165.     return FALSE;
  166.     }
  167.     if (TRACE) {
  168.     WWW_TraceFlag = FALSE;
  169.     *trace_flag_ptr = TRUE;
  170.     }
  171.     return TRUE;
  172. }
  173.  
  174. /*
  175.  *  Here's where we do all the work.
  176.  *  mainloop is basically just a big switch dependent on the users input.
  177.  *  I have tried to offload most of the work done here to procedures to
  178.  *  make it more modular, but this procedure still does a lot of variable
  179.  *  manipulation.  This needs some work to make it neater. - Lou Moutilli
  180.  *                    (memoir from the original Lynx - FM)
  181.  */
  182.  
  183. int mainloop NOARGS
  184. {
  185.     int c = 0, real_c = 0, old_c = 0;
  186.     int cmd = LYK_DO_NOTHING, real_cmd = LYK_DO_NOTHING;
  187.     int getresult;
  188.     int arrowup = FALSE, show_help = FALSE;
  189.     int lines_in_file = -1;
  190.     char prev_target[512];
  191.     char user_input_buffer[1024];
  192.     char *owner_address = NULL;  /* Holds the responsible owner's address     */
  193.     char *ownerS_address = NULL; /* Holds owner's address during source fetch */
  194.     BOOLEAN first_file = TRUE;
  195.     BOOLEAN popped_doc = FALSE;
  196.     BOOLEAN refresh_screen = FALSE;
  197.     BOOLEAN force_load = FALSE;
  198.     BOOLEAN try_internal = FALSE;
  199.     BOOLEAN crawl_ok = FALSE;
  200.     BOOLEAN rlink_exists;
  201.     BOOLEAN rlink_allowed;
  202.     BOOLEAN vi_keys_flag = vi_keys;
  203.     BOOLEAN emacs_keys_flag = emacs_keys;
  204.     BOOLEAN keypad_mode_flag = keypad_mode;
  205.     BOOLEAN user_mode_flag = user_mode;
  206.     BOOLEAN HTfileSortMethod_flag = HTfileSortMethod;
  207.     int CurrentCharSet_flag = current_char_set;
  208.     int CurrentAssumeCharSet_flag = UCLYhndl_for_unspec;
  209.     int CurrentAssumeLocalCharSet_flag = UCLYhndl_HTFile_for_unspec;
  210.     BOOLEAN show_dotfiles_flag = show_dotfiles;
  211.     BOOLEAN LYRawMode_flag = LYRawMode;
  212.     BOOLEAN LYSelectPopups_flag = LYSelectPopups;
  213.     BOOLEAN trace_mode_flag = FALSE;
  214.     BOOLEAN forced_HTML_mode = LYforce_HTML_mode;
  215.     char cfile[128];
  216.     FILE *cfp;
  217.     char *cp, *toolbar;
  218. #ifdef VMS
  219.     extern BOOLEAN HadVMSInterrupt;   /* Flag from cleanup_sig */
  220. #endif /* VMS */
  221.     int ch, recall;
  222.     int URLTotal;
  223.     int URLNum;
  224.     BOOLEAN FirstURLRecall = TRUE;
  225.     char *temp = NULL;
  226.     BOOLEAN ForcePush = FALSE;
  227.     BOOLEAN override_LYresubmit_posts = FALSE;
  228.     unsigned int len;
  229.     int i;
  230.  
  231. #ifdef DIRED_SUPPORT
  232.     char *tp = NULL;
  233.     struct stat dir_info;
  234. #endif /* DIRED_SUPPORT */
  235.  
  236. /*
  237.  *  curdoc.address contains the name of the file that is currently open.
  238.  *  newdoc.address contains the name of the file that will soon be
  239.  *             opened if it exits.
  240.  *  prev_target    contains the last search string the user searched for.
  241.  *  newdoc.title   contains the link name that the user last chose to get
  242.  *             into the current link (file).
  243.  */
  244.     /* initialize some variables*/
  245.     newdoc.address = NULL;
  246.     newdoc.title = NULL;
  247.     newdoc.post_data = NULL;
  248.     newdoc.post_content_type = NULL;
  249.     newdoc.bookmark = NULL;
  250.     curdoc.address = NULL;
  251.     curdoc.title = NULL;
  252.     curdoc.post_data = NULL;
  253.     curdoc.post_content_type = NULL;
  254.     curdoc.bookmark = NULL;
  255. #ifdef USE_HASH
  256.     curdoc.style = NULL;
  257.     newdoc.style = NULL;
  258. #endif
  259.     nhist = 0;
  260.     user_input_buffer[(sizeof(user_input_buffer) - 1)] = '\0';
  261.     *prev_target = '\0';
  262.     *user_input_buffer = '\0';
  263.     StrAllocCopy(CurrentUserAgent, (LYUserAgent ?
  264.                     LYUserAgent : ""));
  265.     StrAllocCopy(CurrentNegoLanguage, (language ?
  266.                        language : ""));
  267.     StrAllocCopy(CurrentNegoCharset, (pref_charset ?
  268.                       pref_charset : ""));
  269.     atexit(free_mainloop_variables);
  270. initialize:
  271.     StrAllocCopy(newdoc.address, startfile);
  272.     StrAllocCopy(startrealm, startfile);
  273.     StrAllocCopy(newdoc.title, "Entry into main screen");
  274.     newdoc.isHEAD = FALSE;
  275.     newdoc.safe = FALSE;
  276.     newdoc.internal_link = FALSE;
  277.     newdoc.line = 1;
  278.     newdoc.link = 0;
  279.  
  280. #ifdef USE_SLANG
  281.     if (TRACE && LYCursesON) {
  282.     addstr("\n");
  283.     refresh();
  284.     }
  285. #endif /* USE_SLANG */
  286.     CTRACE(tfp,"Entering mainloop, startfile=%s\n",startfile);
  287.  
  288.     if (form_post_data) {
  289.     StrAllocCopy(newdoc.post_data, form_post_data);
  290.     StrAllocCopy(newdoc.post_content_type,
  291.              "application/x-www-form-urlencoded");
  292.     } else if (form_get_data) {
  293.     StrAllocCat(newdoc.address, form_get_data);
  294.     }
  295.  
  296.     if (bookmark_start) {
  297.     if (LYValidate) {
  298.         _statusline(BOOKMARKS_DISABLED);
  299.         sleep(AlertSecs);
  300.         bookmark_start = FALSE;
  301.         goto initialize;
  302.     } else if (traversal) {
  303.         _statusline(BOOKMARKS_NOT_TRAVERSED);
  304.         sleep(AlertSecs);
  305.         traversal = FALSE;
  306.         crawl = FALSE;
  307.         bookmark_start = FALSE;
  308.         goto initialize;
  309.     } else {
  310.         /*
  311.          *    See if a bookmark page exists.    If it does,
  312.          *    replace newdoc.address with it's name
  313.          */
  314.         if ((cp = get_bookmark_filename(&newdoc.address)) != NULL &&
  315.          *cp != '\0' && strcmp(cp, " ")) {
  316.         StrAllocCopy(newdoc.title, BOOKMARK_TITLE);
  317.         StrAllocCopy(newdoc.bookmark, BookmarkPage);
  318.         StrAllocCopy(startrealm, newdoc.address);
  319.         FREE(newdoc.post_data);
  320.         FREE(newdoc.post_content_type);
  321.         newdoc.isHEAD = FALSE;
  322.         newdoc.safe = FALSE;
  323.         CTRACE(tfp, "Using bookmarks=%s\n", newdoc.address);
  324.         } else {
  325.         _statusline(BOOKMARKS_NOT_OPEN);
  326.         sleep(MessageSecs);
  327.         bookmark_start = FALSE;
  328.         goto initialize;
  329.         }
  330.     }
  331.     }
  332.  
  333.     FREE(form_post_data);
  334.     FREE(form_get_data);
  335.  
  336.     if (user_mode == NOVICE_MODE)
  337.     display_lines = LYlines-4;
  338.     else
  339.     display_lines = LYlines-2;
  340.  
  341.     while (TRUE) {
  342. #ifdef USE_HASH
  343.     if (curdoc.style != NULL) force_load = TRUE;
  344. #endif
  345.     /*
  346.      *  If newdoc.address is different then curdoc.address then
  347.      *  we need to go out and find and load newdoc.address.
  348.      */
  349.     if (LYforce_no_cache || force_load ||
  350.         are_different(&curdoc, &newdoc)) {
  351.  
  352.         force_load = FALSE;  /* done */
  353.         if (TRACE && LYCursesON) {
  354.             move(LYlines-1, LYcols-1);    /* make sure cursor is down */
  355. #ifdef USE_SLANG
  356.             addstr("\n");
  357. #endif /* USE_SLANG */
  358.             refresh();
  359.         }
  360. try_again:
  361.         /*
  362.          *  Push the old file onto the history stack if we
  363.          *  have a current doc and a new address. - FM
  364.          */
  365.         if (curdoc.address && newdoc.address) {
  366.             /*
  367.              *    Don't actually push if this is a LYNXDOWNLOAD
  368.              *    URL, because that returns NORMAL even if it
  369.              *    fails due to a spoof attempt or file access
  370.              *    problem, and we set the newdoc structure
  371.              *    elements to the curdoc structure elements
  372.              *    under case NORMAL.  - FM
  373.              */
  374.             if (strncmp(newdoc.address, "LYNXDOWNLOAD:", 13)) {
  375.             LYpush(&curdoc, ForcePush);
  376.             }
  377.         } else if (!newdoc.address) {
  378.             /*
  379.              *    If newdoc.address is empty then pop a file
  380.              *    and load it.  - FM
  381.              */
  382.             LYpop(&newdoc);
  383.             popped_doc = TRUE;
  384.  
  385.  
  386. #ifndef DONT_TRACK_INTERNAL_LINKS
  387. #define NO_INTERNAL_OR_DIFFERENT(c,n) TRUE
  388. #define NONINTERNAL_OR_PHYS_DIFFERENT(p,n) (!curdoc.internal_link || \
  389.                are_phys_different(p,n))
  390. #else /* TRACK_INTERNAL_LINKS */
  391. #define NO_INTERNAL_OR_DIFFERENT(c,n) are_different(c,n)
  392. #define NONINTERNAL_OR_PHYS_DIFFERENT(p,n) are_different(p,n)
  393. #endif /* TRACK_INTERNAL_LINKS */
  394.  
  395.  
  396. #ifndef DONT_TRACK_INTERNAL_LINKS
  397.             /*
  398.             ** If curdoc had been reached via an internal
  399.             ** (fragment) link from what we now have just
  400.             ** popped into newdoc, then override non-caching in
  401.             ** all cases. - kw
  402.             */
  403.             if (curdoc.internal_link &&
  404.             !are_phys_different(&curdoc, &newdoc)) {
  405.             LYinternal_flag = TRUE;
  406.             LYoverride_no_cache = TRUE;
  407.             LYforce_no_cache = FALSE;
  408.             try_internal = TRUE;
  409.             } else
  410. #endif /* TRACK_INTERNAL_LINKS */
  411.             /*
  412.              * Force a no_cache override unless
  413.              *  it's a bookmark file, or it has POST content
  414.              *  and LYresubmit_posts is set without safe also
  415.              *  set, and we are not going to another position
  416.              *  in the current document or restoring the previous
  417.              *  document due to a NOT_FOUND or NULLFILE return
  418.              *  value from getfile(). - FM
  419.              */
  420.             if ((newdoc.bookmark != NULL) ||
  421.             (newdoc.post_data != NULL &&
  422.              !newdoc.safe &&
  423.              LYresubmit_posts &&
  424.              !override_LYresubmit_posts &&
  425.                 NO_INTERNAL_OR_DIFFERENT(&curdoc, &newdoc))) {
  426.             LYoverride_no_cache = FALSE;
  427.             } else {
  428.             LYoverride_no_cache = TRUE;
  429.             }
  430.         }
  431.         override_LYresubmit_posts = FALSE;
  432.  
  433.         if (HEAD_request) {
  434.             /*
  435.              *    Make SURE this is an appropriate request. - FM
  436.              */
  437.             if (newdoc.address) {
  438.             if (LYCanDoHEAD(newdoc.address) == TRUE) {
  439.                 newdoc.isHEAD = TRUE;
  440.             } else if (!strncmp(newdoc.address, "LYNXIMGMAP:", 11)) {
  441.                 if (LYCanDoHEAD(newdoc.address + 11) == TRUE) {
  442.                 StrAllocCopy(temp, newdoc.address + 11);
  443.                 FREE(newdoc.address);
  444.                 newdoc.address = temp;
  445.                 newdoc.isHEAD = TRUE;
  446.                 temp = NULL;
  447.                 }
  448.             }
  449.             }
  450.             try_internal = FALSE;
  451.             HEAD_request = FALSE;
  452.         }
  453.  
  454.         /*
  455.          *  If we're getting the TRACE log and it's not new,
  456.          *  check whether its HText structure has been dumped,
  457.          *  and if so, fflush() and fclose() it to ensure it's
  458.          *  fully updated, and then fopen() it again. - FM
  459.          */
  460.         if (LYUseTraceLog == TRUE &&
  461.             trace_mode_flag == FALSE &&
  462.             LYTraceLogFP != NULL &&
  463.             !strcmp((newdoc.title ? newdoc.title : ""),
  464.                  LYNX_TRACELOG_TITLE)) {
  465.             DocAddress WWWDoc;
  466.             HTParentAnchor *tmpanchor;
  467.  
  468.             WWWDoc.address = newdoc.address;
  469.             WWWDoc.post_data = newdoc.post_data;
  470.             WWWDoc.post_content_type = newdoc.post_content_type;
  471.             WWWDoc.bookmark = newdoc.bookmark;
  472.             WWWDoc.isHEAD = newdoc.isHEAD;
  473.             WWWDoc.safe = newdoc.safe;
  474.             tmpanchor = HTAnchor_parent(HTAnchor_findAddress(&WWWDoc));
  475.             if ((HText *)HTAnchor_document(tmpanchor) == NULL) {
  476.             if (!LYReopenTracelog(&trace_mode_flag)) {
  477.                 old_c = 0;
  478.                 cmd = LYK_PREV_DOC;
  479.                 goto new_cmd;
  480.             }
  481.             }
  482.         }
  483.  
  484.         LYRequestTitle = newdoc.title;
  485.         if (newdoc.bookmark)
  486.             LYforce_HTML_mode = TRUE;
  487.         if (LYValidate &&
  488.             startfile_ok &&
  489.             newdoc.address && startfile && homepage &&
  490.             (!strcmp(newdoc.address, startfile) ||
  491.              !strcmp(newdoc.address, homepage))) {
  492.             LYPermitURL = TRUE;
  493.         }
  494.  
  495. #ifndef DONT_TRACK_INTERNAL_LINKS
  496.         if (try_internal) {
  497.             if (newdoc.address &&
  498.             0==strncmp(newdoc.address, "LYNXIMGMAP:", 11)) {
  499.             try_internal = FALSE;
  500.             } else if (curdoc.address &&
  501.             0==strncmp(curdoc.address, "LYNXIMGMAP:", 11)) {
  502.             try_internal = FALSE;
  503.             }
  504.         }
  505.         if (try_internal) {
  506.             char *hashp = strchr(newdoc.address,'#');
  507.             if (hashp) {
  508.             HTFindPoundSelector(hashp+1);
  509.             }
  510.             getresult = (HTMainText != NULL) ? NORMAL : NOT_FOUND;
  511.             try_internal = FALSE; /* done */
  512.             /* fix up newdoc.address which may have been fragment-only */
  513.             if (getresult == NORMAL && (!hashp || hashp == newdoc.address)) {
  514.             if (!hashp) {
  515.                 StrAllocCopy(newdoc.address, HTLoadedDocumentURL());
  516.             } else {
  517.                 StrAllocCopy(temp, HTLoadedDocumentURL());
  518.                 StrAllocCat(temp, hashp); /* append fragment */
  519.                 StrAllocCopy(newdoc.address, temp);
  520.                 FREE(temp);
  521.             }
  522.             }
  523.         } else {
  524.             if (newdoc.internal_link && newdoc.address &&
  525.             *newdoc.address == '#' && nhist > 0) {
  526.             char *cp0;
  527.             if (0==strncmp(history[nhist-1].address, "LYNXIMGMAP:", 11))
  528.                 cp0 = history[nhist-1].address + 11;
  529.             else
  530.                 cp0 = history[nhist-1].address;
  531.             StrAllocCopy(temp, cp0);
  532.             cp0 = strchr(temp, '#');
  533.             if (cp0)
  534.                 *cp0 = '\0';
  535.             StrAllocCat(temp, newdoc.address);
  536.             FREE(newdoc.address);
  537.             newdoc.address = temp;
  538.             temp = NULL;
  539.             }
  540.             getresult = getfile(&newdoc);
  541.         }
  542. #else  /* TRACK_INTERNAL_LINKS */
  543.         getresult = getfile(&newdoc);
  544. #endif /* TRACK_INTERNAL_LINKS */
  545.  
  546.         switch(getresult) {
  547.  
  548.         case NOT_FOUND:
  549.             /*
  550.              *    OK! can't find the file, so it must not be around now.
  551.              *    Do any error logging, if appropriate.
  552.              */
  553.             LYoverride_no_cache = FALSE; /* Was TRUE if popped. - FM */
  554.             popped_doc = FALSE;      /* Was TRUE if popped. - FM */
  555.             LYinternal_flag = FALSE;     /* Reset to default. - kw */
  556.             if (trace_mode_flag == TRUE) {
  557.             WWW_TraceFlag = TRUE;
  558.             trace_mode_flag = FALSE;
  559.             fprintf(tfp, "Turning TRACE back on.\n\n");
  560.             }
  561.             if (error_logging &&
  562.             first_file && owner_address && !LYCancelledFetch) {
  563.             /*
  564.              *  Email a bad link message to the owner of
  565.              *  the document (but NOT to lynx-dev). - FM
  566.              */
  567.             if (strncasecomp(owner_address, "mailto:", 7)) {
  568.                 if (strncasecomp((owner_address + 7),
  569.                          "lynx-dev@", 9)) {
  570.                 mailmsg(curdoc.link,
  571.                     (owner_address+7),
  572.                     history[nhist-1].address,
  573.                     history[nhist-1].title);
  574.                 }
  575.             }
  576.             }
  577.             if (traversal && !first_file && !LYCancelledFetch) {
  578.             FILE *ofp;
  579.  
  580.             if ((ofp = LYAppendToTxtFile(TRAVERSE_ERRORS)) == NULL) {
  581.                 if ((ofp = LYNewTxtFile(TRAVERSE_ERRORS)) == NULL) {
  582.                 perror(NOOPEN_TRAV_ERR_FILE);
  583. #ifndef NOSIGHUP
  584.                 (void) signal(SIGHUP, SIG_DFL);
  585. #endif /* NOSIGHUP */
  586.                 (void) signal(SIGTERM, SIG_DFL);
  587. #ifndef VMS
  588.                 (void) signal(SIGINT, SIG_DFL);
  589. #endif /* !VMS */
  590. #ifdef SIGTSTP
  591.                 if (no_suspend)
  592.                     (void) signal(SIGTSTP,SIG_DFL);
  593. #endif /* SIGTSTP */
  594.                 exit(-1);
  595.                 }
  596.             }
  597.             fprintf(ofp, "%s %s\tin %s\n",
  598.                      links[curdoc.link].lname,
  599.                      links[curdoc.link].target,
  600.                      history[nhist-1].address);
  601.             fclose(ofp);
  602.             }
  603.  
  604.             /*
  605.              *    Fall through to do the NULL stuff and reload the
  606.              *    old file, unless the first file wasn't found or
  607.              *    has gone missing.
  608.              */
  609.             if (!nhist) {
  610.             /*
  611.              *  If nhist = 0 then it must be the first file.
  612.              */
  613.             if (!dump_output_immediately)
  614.                 cleanup();
  615. #ifdef UNIX
  616.             if (dump_output_immediately)
  617.                 fprintf(stderr,"\nlynx: Can't access startfile %s\n",
  618.                    startfile);
  619.             else
  620. #endif /* UNIX */
  621.                 printf("\nlynx: Can't access startfile %s\n",
  622.                    startfile);
  623.             if (!dump_output_immediately) {
  624. #ifndef NOSIGHUP
  625.                 (void) signal(SIGHUP, SIG_DFL);
  626. #endif /* NOSIGHUP */
  627.                 (void) signal(SIGTERM, SIG_DFL);
  628. #ifndef VMS
  629.                 (void) signal(SIGINT, SIG_DFL);
  630. #endif /* !VMS */
  631. #ifdef SIGTSTP
  632.                 if (no_suspend)
  633.                 (void) signal(SIGTSTP,SIG_DFL);
  634. #endif /* SIGTSTP */
  635.                 exit(-1);
  636.             }
  637.             return(-1);
  638.             }
  639.  
  640.         case NULLFILE:
  641.             /*
  642.              *    Not supposed to return any file.
  643.              */
  644.             LYoverride_no_cache = FALSE; /* Was TRUE if popped. - FM */
  645.             popped_doc = FALSE;      /* Was TRUE if popped. - FM */
  646.             LYinternal_flag = FALSE;     /* Reset to default. - kw */
  647.             if (trace_mode_flag == TRUE) {
  648.             WWW_TraceFlag = TRUE;
  649.             trace_mode_flag = FALSE;
  650.             fprintf(tfp, "Turning TRACE back on.\n\n");
  651.             }
  652.             FREE(newdoc.address); /* to pop last doc */
  653.             FREE(newdoc.bookmark);
  654.             LYJumpFileURL = FALSE;
  655.             reloading = FALSE;
  656.             LYPermitURL = FALSE;
  657.             LYCancelledFetch = FALSE;
  658.             ForcePush = FALSE;
  659.             LYforce_HTML_mode = FALSE;
  660.             if (traversal) {
  661.             crawl_ok = FALSE;
  662.             if (traversal_link_to_add) {
  663.                 /*
  664.                  *    It's a binary file, or the fetch attempt
  665.                  *    failed.  Add it to TRAVERSE_REJECT_FILE
  666.                  *    so we don't try again in this run.
  667.                  */
  668.                 if (!lookup_reject(traversal_link_to_add)) {
  669.                 add_to_reject_list(traversal_link_to_add);
  670.                 }
  671.                 FREE(traversal_link_to_add);
  672.             }
  673.             }
  674.            /*
  675.             *  Make sure the first file was found and
  676.             *  has not gone missing.
  677.             */
  678.            if (!nhist) {
  679.                /*
  680.             *  If nhist = 0 then it must be the first file.
  681.             */
  682.                if (first_file && homepage &&
  683. #ifdef VMS
  684.                strcasecomp(homepage, startfile) != 0
  685. #else
  686.                strcmp(homepage, startfile) != 0
  687. #endif /* VMS */
  688.                ) {
  689.                /*
  690.                 *  Couldn't return to the first file but there is a
  691.                 *  homepage we can use instead. Useful for when the
  692.                 *  first URL causes a program to be invoked. - GL
  693.                 *
  694.                 *  But first make sure homepage is different from
  695.                 *  startfile (above), then make it the same (below)
  696.                 *  so we don't enter an infinite getfile() loop on
  697.                 *  on failures to find the files. - FM
  698.                 */
  699.                StrAllocCopy(newdoc.address, homepage);
  700.                FREE(newdoc.post_data);
  701.                FREE(newdoc.post_content_type);
  702.                FREE(newdoc.bookmark);
  703.                StrAllocCopy(startfile, homepage);
  704.                newdoc.isHEAD = FALSE;
  705.                newdoc.safe = FALSE;
  706.                newdoc.internal_link = FALSE;
  707.                goto try_again;
  708.                } else {
  709.                if (!dump_output_immediately)
  710.                    cleanup();
  711. #ifdef UNIX
  712.                if (dump_output_immediately) {
  713.                    fprintf(stderr,
  714.  "\nlynx: Start file could not be found or is not text/html or text/plain\n");
  715.                    fprintf(stderr,"      Exiting...\n");
  716.                } else
  717. #endif /* UNIX */
  718.                {
  719.                    printf(
  720.  "\nlynx: Start file could not be found or is not text/html or text/plain\n");
  721.                    printf("      Exiting...\n");
  722.                }
  723.                if (!dump_output_immediately) {
  724. #ifndef NOSIGHUP
  725.                 (void) signal(SIGHUP, SIG_DFL);
  726. #endif /* NOSIGHUP */
  727.                 (void) signal(SIGTERM, SIG_DFL);
  728. #ifndef VMS
  729.                 (void) signal(SIGINT, SIG_DFL);
  730. #endif /* !VMS */
  731. #ifdef SIGTSTP
  732.                 if (no_suspend)
  733.                     (void) signal(SIGTSTP,SIG_DFL);
  734. #endif /* SIGTSTP */
  735.                    exit(-1);
  736.                }
  737.                return(-1);
  738.                }
  739.             }
  740.  
  741.            /*
  742.             *  Retrieval of a newdoc just failed, and just
  743.             *  going to try_again would pop the next doc
  744.             *  from history and try to get it without further
  745.             *  questions.  This may not be the right thing to do if
  746.             *  we have POST data, so fake a PREV_DOC key if it seems
  747.             *  that some prompting should be done.  Dunno about the
  748.             *  traversal logic, so I leave that case alone.
  749.             */
  750.            if (history[nhist - 1].post_data &&
  751.                !history[nhist - 1].safe) {
  752.                if (HText_POSTReplyLoaded((document *)&history[(nhist - 1)])) {
  753.                override_LYresubmit_posts = TRUE;
  754.                goto try_again;
  755.                }
  756.                /*  Set newdoc fields, just in case the PREV_DOC
  757.             *  gets cancelled. - kw */
  758.                if (!curdoc.address) {
  759.                StrAllocCopy(newdoc.address, HTLoadedDocumentURL());
  760.                StrAllocCopy(newdoc.title, HTLoadedDocumentTitle());
  761.                if (HTMainAnchor && HTMainAnchor->post_data) {
  762.                    StrAllocCopy(newdoc.post_data,
  763.                         HTMainAnchor->post_data);
  764.                    StrAllocCopy(newdoc.post_content_type,
  765.                         HTMainAnchor->post_content_type);
  766.                } else {
  767.                    FREE(newdoc.post_data);
  768.                }
  769.                newdoc.isHEAD = HTLoadedDocumentIsHEAD();
  770.                newdoc.safe = HTLoadedDocumentIsSafe();
  771.                newdoc.internal_link = FALSE;
  772.                } else {
  773.                StrAllocCopy(newdoc.address, curdoc.address);
  774.                StrAllocCopy(newdoc.title, curdoc.title);
  775.                StrAllocCopy(newdoc.post_data, curdoc.post_data);
  776.                StrAllocCopy(newdoc.post_content_type,
  777.                     curdoc.post_content_type);
  778.                newdoc.isHEAD = curdoc.isHEAD;
  779.                newdoc.safe = curdoc.safe;
  780.                newdoc.internal_link = curdoc.internal_link;
  781.                newdoc.line = curdoc.line;
  782.                newdoc.link = curdoc.link;
  783.                }
  784.                cmd = LYK_PREV_DOC;
  785.                goto new_cmd;
  786.                }
  787.             override_LYresubmit_posts = TRUE;
  788.             goto try_again;
  789.             break;
  790.  
  791.         case NORMAL:
  792.             /*
  793.              *    Marvelously, we got the document!
  794.              */
  795.             LYoverride_no_cache = FALSE; /* Was TRUE if popped. - FM */
  796.             LYinternal_flag = FALSE;     /* Reset to default. - kw */
  797.             if (trace_mode_flag == TRUE) {
  798.             WWW_TraceFlag = TRUE;
  799.             trace_mode_flag = FALSE;
  800.             fprintf(tfp, "Turning TRACE back on.\n\n");
  801.             }
  802.             *prev_target = '\0';    /* Reset for this document. - FM */
  803.  
  804.             /*
  805.              *    If it's the first file and we're interactive,
  806.              *    check whether it's a bookmark file which was
  807.              *    not accessed via the -book switch. - FM
  808.              */
  809.             if (((first_file == TRUE) &&
  810.              (dump_output_immediately == FALSE) &&
  811.              !(newdoc.bookmark && *newdoc.bookmark)) &&
  812.             ((LYisLocalFile(newdoc.address) == TRUE) &&
  813.              !(strcmp((HText_getTitle() ? HText_getTitle() : ""),
  814.                   BOOKMARK_TITLE))) &&
  815.             (temp = HTParse(newdoc.address, "",
  816.                      PARSE_PATH+PARSE_PUNCTUATION)) != NULL) {
  817. #ifdef DOSPATH
  818.             cp = HTDOS_wwwName((char *)Home_Dir());
  819. #else
  820. #ifdef VMS
  821.             cp = HTVMS_wwwName((char *)Home_Dir());
  822. #else
  823.             cp = (char *)Home_Dir();
  824. #endif /* VMS */
  825. #endif /* DOSPATH */
  826.             len = strlen(cp);
  827. #ifdef VMS
  828.             if (!strncasecomp(temp, cp, len) &&
  829.                 strlen(temp) > len)
  830. #else
  831.             if (!strncmp(temp, cp, len) &&
  832.                 strlen(temp) > len)
  833. #endif /* VMS */
  834.             {
  835.                 /*
  836.                  *    We're interactive and this might be a
  837.                  *    bookmark file entered as a startfile
  838.                  *    rather than invoked via -book.    Check
  839.                  *    if it's in our bookmark file list, and
  840.                  *    if so, reload if with the relevant
  841.                  *    bookmark elements set. - FM
  842.                  */
  843.                 if ((cp = (char *)calloc(1,
  844.                   (strlen((char *)&temp[len]) + 2))) == NULL)
  845.                 outofmem(__FILE__, "mainloop");
  846.                 if (temp[len] == '/') {
  847.                 if (strchr((char *)&temp[(len + 1)], '/')) {
  848.                     sprintf(cp, ".%s", (char *)&temp[len]);
  849.                 } else {
  850.                     strcpy(cp, (char *)&temp[(len + 1)]);
  851.                 }
  852.                 } else {
  853.                 strcpy(cp, (char *)&temp[len]);
  854.                 }
  855.                 for (i = 0; i <= MBM_V_MAXFILES; i++) {
  856.                 if (MBM_A_subbookmark[i] &&
  857. #ifdef VMS
  858.                     !strcasecomp(cp, MBM_A_subbookmark[i])
  859. #else
  860.                     !strcmp(cp, MBM_A_subbookmark[i])
  861. #endif /* VMS */
  862.                     ) {
  863.                     StrAllocCopy(BookmarkPage,
  864.                          MBM_A_subbookmark[i]);
  865.                     break;
  866.                 }
  867.                 }
  868.                 FREE(cp);
  869.                 if (i <= MBM_V_MAXFILES) {
  870.                 FREE(temp);
  871.                 if (LYValidate) {
  872.                     _statusline(BOOKMARKS_DISABLED);
  873.                     sleep(AlertSecs);
  874.                     return(-1);
  875.                 }
  876.                 if ((temp = HTParse(newdoc.address, "",
  877.                  PARSE_ACCESS+PARSE_HOST+PARSE_PUNCTUATION))) {
  878.                     StrAllocCopy(newdoc.address, temp);
  879.                     HTuncache_current_document();
  880.                     FREE(curdoc.address);
  881. #ifdef DOSPATH
  882.                     StrAllocCat(newdoc.address,
  883.                         HTDOS_wwwName((char *)Home_Dir()));
  884. #else
  885. #ifdef VMS
  886.                     StrAllocCat(newdoc.address,
  887.                         HTVMS_wwwName((char *)Home_Dir()));
  888. #else
  889.                     StrAllocCat(newdoc.address, Home_Dir());
  890. #endif /* VMS */
  891. #endif /* DOSPATH */
  892.                     StrAllocCat(newdoc.address, "/");
  893.                     StrAllocCat(newdoc.address,
  894.                     (strncmp(BookmarkPage, "./", 2) ?
  895.                                BookmarkPage :
  896.                             (BookmarkPage + 2)));
  897.                     StrAllocCopy(newdoc.title, BOOKMARK_TITLE);
  898.                     StrAllocCopy(newdoc.bookmark, BookmarkPage);
  899. #ifdef USE_HASH
  900.                     if (curdoc.style)
  901.                     StrAllocCopy(newdoc.style, curdoc.style);
  902. #endif
  903.                     StrAllocCopy(startrealm, newdoc.address);
  904.                     FREE(newdoc.post_data);
  905.                     FREE(newdoc.post_content_type);
  906.                     newdoc.isHEAD = FALSE;
  907.                     newdoc.safe = FALSE;
  908.                     FREE(temp);
  909.                     if (!strcmp(homepage, startfile))
  910.                     StrAllocCopy(homepage, newdoc.address);
  911.                     StrAllocCopy(startfile, newdoc.address);
  912.                     CTRACE(tfp, "Reloading as bookmarks=%s\n",
  913.                         newdoc.address);
  914.                     goto try_again;
  915.                 }
  916.                 }
  917.             }
  918.             cp = NULL;
  919.             }
  920.             FREE(temp);
  921.  
  922.             if (traversal) {
  923.             /*
  924.              *  During traversal build up lists of all links
  925.              *  traversed.    Traversal mode is a special
  926.              *  feature for traversing http links in the web.
  927.              */
  928.             if (traversal_link_to_add) {
  929.                 /*
  930.                  *    Add the address we sought to TRAVERSE_FILE.
  931.                  */
  932.                 if (!lookup(traversal_link_to_add))
  933.                 add_to_table(traversal_link_to_add);
  934.                 FREE(traversal_link_to_add);
  935.             }
  936.             if (curdoc.address && curdoc.title &&
  937.                 strncmp(curdoc.address, "LYNXIMGMAP:", 11))
  938.                 /*
  939.                  *    Add the address we got to TRAVERSE_FOUND_FILE.
  940.                  */
  941.                 add_to_traverse_list(curdoc.address, curdoc.title);
  942.             }
  943.  
  944.             /*
  945.              *    If this was a LYNXDOWNLOAD, we still have curdoc,
  946.              *    not a newdoc, so reset the address, title and
  947.              *    positioning elements. - FM
  948.              */
  949.             if (newdoc.address && curdoc.address &&
  950.             !strncmp(newdoc.address, "LYNXDOWNLOAD:", 13)) {
  951.             StrAllocCopy(newdoc.address, curdoc.address);
  952.             StrAllocCopy(newdoc.title, (curdoc.title ?
  953.                             curdoc.title : ""));
  954.             StrAllocCopy(newdoc.bookmark, curdoc.bookmark);
  955.             newdoc.line = curdoc.line;
  956.             newdoc.link = curdoc.link;
  957.             newdoc.internal_link = FALSE; /* can't be true. - kw */
  958.             }
  959.  
  960.             /*
  961.              *    Set Newline to the saved line.    It contains the
  962.              *    line the user was on if s/he has been in the file
  963.              *    before, or it is 1 if this is a new file.
  964.              */
  965.             Newline = newdoc.line;
  966.  
  967.             /*
  968.              *    If we are going to a target line or
  969.              *    the first page of a popped document,
  970.              *    override any www_search line result.
  971.              */
  972.             if (Newline > 1 || popped_doc == TRUE)
  973.              www_search_result = -1;
  974.  
  975.             /*
  976.              *    Make sure curdoc.line will not be equal
  977.              *    to Newline, so we get a redraw.
  978.              */
  979.             curdoc.line = -1;
  980.  
  981.             break;
  982.         }  /* end switch */
  983.  
  984.         if (TRACE) {
  985.         if (!LYTraceLogFP || trace_mode_flag) {
  986.             sleep(AlertSecs); /* allow me to look at the results */
  987.         }
  988.         }
  989.  
  990.         /*
  991.          *    Set the files the same.
  992.          */
  993.         StrAllocCopy(curdoc.address, newdoc.address);
  994.         StrAllocCopy(curdoc.post_data, newdoc.post_data);
  995.         StrAllocCopy(curdoc.post_content_type, newdoc.post_content_type);
  996.         StrAllocCopy(curdoc.bookmark, newdoc.bookmark);
  997. #ifdef USE_HASH
  998.         StrAllocCopy(curdoc.style, HText_getStyle());
  999.         if (curdoc.style != NULL)
  1000.         style_readFromFile (curdoc.style);
  1001. #endif
  1002.         curdoc.isHEAD = newdoc.isHEAD;
  1003.         curdoc.internal_link = newdoc.internal_link;
  1004.  
  1005.         /*
  1006.          *    Set the remaining document elements and add to
  1007.          *    the visitied links list. - FM
  1008.          */
  1009.         if (ownerS_address != NULL) {
  1010.         if (HTOutputFormat == WWW_SOURCE && !HText_getOwner())
  1011.             HText_setMainTextOwner(ownerS_address);
  1012.         FREE(ownerS_address);
  1013.         }
  1014.         if (HText_getTitle()) {
  1015.         StrAllocCopy(curdoc.title, HText_getTitle());
  1016.         } else if (!dump_output_immediately) {
  1017.         StrAllocCopy(curdoc.title, newdoc.title);
  1018.         }
  1019.         owner_address = HText_getOwner();
  1020.         curdoc.safe = HTLoadedDocumentIsSafe();
  1021.         if (!dump_output_immediately) {
  1022.         LYAddVisitedLink(&curdoc);
  1023.         }
  1024.  
  1025.  
  1026.        /*
  1027.         *  Reset WWW present mode so that if we were getting
  1028.         *  the source, we get rendered HTML from now on.
  1029.         */
  1030.        HTOutputFormat = WWW_PRESENT;
  1031.  
  1032.        /*
  1033.         *  Reset all of the other relevant flags. - FM
  1034.         */
  1035.        LYUserSpecifiedURL = FALSE;    /* only set for goto's and jumps's */
  1036.        LYJumpFileURL = FALSE;    /* only set for jump's */
  1037.        LYNoRefererForThis = FALSE;    /* always reset on return here */
  1038.        reloading = FALSE;        /* only set for RELOAD and RESUBMIT */
  1039.        HEAD_request = FALSE;    /* only set for HEAD requests */
  1040.        LYPermitURL = FALSE;     /* only set for LYValidate */
  1041.        ForcePush = FALSE;        /* only set for some PRINT requests. */
  1042.        LYforce_HTML_mode = FALSE;
  1043.        popped_doc = FALSE;
  1044.  
  1045.     } /* end if (LYforce_no_cache || force_load || are_different(...)) */
  1046.  
  1047.     if (dump_output_immediately) {
  1048.         if (crawl) {
  1049.         print_crawl_to_fd(stdout, curdoc.address, curdoc.title);
  1050.         } else {
  1051.         print_wwwfile_to_fd(stdout,0);
  1052.         }
  1053.         return(0);
  1054.     }
  1055.  
  1056.     /*
  1057.      *  If the recent_sizechange variable is set to TRUE
  1058.      *  then the window size changed recently.
  1059.      */
  1060.     if (recent_sizechange) {
  1061.         stop_curses();
  1062.         start_curses();
  1063.         clear();
  1064.         refresh_screen = TRUE; /* to force a redraw */
  1065.         recent_sizechange = FALSE;
  1066.         if (user_mode == NOVICE_MODE) {
  1067.             display_lines = LYlines-4;
  1068.         } else {
  1069.             display_lines = LYlines-2;
  1070.         }
  1071.     }
  1072.  
  1073.     if (www_search_result != -1) {
  1074.          /*
  1075.           *  This was a WWW search, set the line
  1076.           *  to the result of the search.
  1077.           */
  1078.          Newline = www_search_result;
  1079.          www_search_result = -1;  /* reset */
  1080.          more = HText_canScrollDown();
  1081.     }
  1082.  
  1083.     if (first_file == TRUE) {
  1084.         /*
  1085.          *    We can never again have the first file.
  1086.          */
  1087.         first_file = FALSE;
  1088.  
  1089.         /*
  1090.          *    Set the startrealm, and deal as best we can
  1091.          *    with preserving forced HTML mode for a local
  1092.          *    startfile. - FM
  1093.          */
  1094.         temp = HTParse(curdoc.address, "",
  1095.                PARSE_ACCESS+PARSE_HOST+PARSE_PUNCTUATION);
  1096.         if (!temp || *temp == '\0') {
  1097.         StrAllocCopy(startrealm, "None");
  1098.         } else {
  1099.         StrAllocCopy(startrealm, temp);
  1100.         FREE(temp);
  1101.         if (!(temp = HTParse(curdoc.address, "",
  1102.                      PARSE_PATH+PARSE_PUNCTUATION))) {
  1103.             if (startrealm[strlen(startrealm)-1] != '/') {
  1104.             StrAllocCat(startrealm, "/");
  1105.             }
  1106.         } else {
  1107.             if (forced_HTML_mode &&
  1108.             !dump_output_immediately &&
  1109.             !curdoc.bookmark &&
  1110.             !strncasecomp(curdoc.address, "file:", 5) &&
  1111.             strlen(temp) > 1) {
  1112.             /*
  1113.              *  We forced HTML for a local startfile which
  1114.              *  is not a bookmark file and has a path of at
  1115.              *  least two letters.    If it doesn't have a
  1116.              *  suffix mapped to text/html, we'll set the
  1117.              *  entire path (including the lead slash) as a
  1118.              *  "suffix" mapped to text/html to ensure it is
  1119.              *  always treated as an HTML source file.  We
  1120.              *  are counting on a tail match to this full path
  1121.              *  for some other URL fetched during the session
  1122.              *  having too low a probability to worry about,
  1123.              *  but it could happen. - FM
  1124.              */
  1125.             HTAtom *encoding;
  1126.  
  1127.             if (HTFileFormat(temp, &encoding, NULL) != WWW_HTML) {
  1128.                 HTSetSuffix(temp, "text/html", "8bit", 1.0);
  1129.             }
  1130.             }
  1131.             if ((cp = strrchr(temp, '/')) != NULL) {
  1132.             *(cp+1) = '\0';
  1133.             StrAllocCat(startrealm, temp);
  1134.             }
  1135.         }
  1136.         }
  1137.         FREE(temp);
  1138.         CTRACE(tfp, "Starting realm is '%s'\n\n", startrealm);
  1139.         if (traversal) {
  1140.         /*
  1141.          *  Set up the crawl output stuff.
  1142.          */
  1143.         if (curdoc.address && !lookup(curdoc.address)) {
  1144.             if (strncmp(curdoc.address, "LYNXIMGMAP:", 11))
  1145.             crawl_ok = TRUE;
  1146.             add_to_table(curdoc.address);
  1147.         }
  1148.         /*
  1149.          *  Set up the traversal_host comparison string.
  1150.          */
  1151.         if (strncmp((curdoc.address ? curdoc.address : "NULL"),
  1152.                 "http", 4)) {
  1153.             StrAllocCopy(traversal_host, "None");
  1154.         } else if (check_realm) {
  1155.             StrAllocCopy(traversal_host, startrealm);
  1156.         } else {
  1157.             temp = HTParse(curdoc.address, "",
  1158.                    PARSE_ACCESS+PARSE_HOST+PARSE_PUNCTUATION);
  1159.             if (!temp || *temp == '\0') {
  1160.             StrAllocCopy(traversal_host, "None");
  1161.             } else {
  1162.             StrAllocCopy(traversal_host, temp);
  1163.             if (traversal_host[strlen(traversal_host)-1] != '/') {
  1164.                 StrAllocCat(traversal_host, "/");
  1165.             }
  1166.             }
  1167.             FREE(temp);
  1168.         }
  1169.         CTRACE(tfp, "Traversal host is '%s'\n\n", traversal_host);
  1170.         }
  1171.         if (startfile) {
  1172.         /*
  1173.          *  If homepage was not equated to startfile,
  1174.          *  make the homepage URL the first goto
  1175.          *  entry. - FM
  1176.          */
  1177.         if (homepage && strcmp(startfile, homepage))
  1178.             HTAddGotoURL(homepage);
  1179.         /*
  1180.          *  If we are not starting up with startfile
  1181.          *  (e.g., had -book), or if we are using the
  1182.          *  startfile and it has no POST content, make
  1183.          *  the startfile URL a goto entry. - FM
  1184.          */
  1185.         if (strcmp(startfile, newdoc.address) ||
  1186.             newdoc.post_data == NULL)
  1187.             HTAddGotoURL(startfile);
  1188.         }
  1189.         if (TRACE) {
  1190.         refresh_screen = TRUE;
  1191.         if (!LYTraceLogFP || trace_mode_flag) {
  1192.             sleep(AlertSecs);
  1193.         }
  1194.         }
  1195.     }
  1196.  
  1197.     /*
  1198.      *  If the curdoc.line is different than Newline then there must
  1199.      *  have been a change since last update.  Run HText_pageDisplay()
  1200.      *  create a fresh screen of text out.
  1201.      */
  1202.     if (curdoc.line != Newline) {
  1203.  
  1204.         refresh_screen = FALSE;
  1205.  
  1206.         HText_pageDisplay(Newline, prev_target);
  1207.  
  1208. #ifdef DIRED_SUPPORT
  1209.         if (lynx_edit_mode && nlinks > 0 && !HTList_isEmpty(tagged))
  1210.           showtags(tagged);
  1211. #endif /* DIRED_SUPPORT */
  1212.         /*
  1213.          *    If more equals TRUE, then there is more
  1214.          *    info below this page .
  1215.          */
  1216.         more = HText_canScrollDown();
  1217.         curdoc.line = Newline = HText_getTopOfScreen()+1;
  1218.         lines_in_file = HText_getNumOfLines();
  1219.  
  1220.         if (curdoc.title == NULL) {
  1221.         /*
  1222.          *  If we don't yet have a title, try to get it,
  1223.          *  or set to that for newdoc.title. - FM
  1224.          */
  1225.         if (HText_getTitle()) {
  1226.             StrAllocCopy(curdoc.title, HText_getTitle());
  1227.         } else {
  1228.             StrAllocCopy(curdoc.title, newdoc.title);
  1229.         }
  1230.         }
  1231.  
  1232.         if (arrowup) {
  1233.         /*
  1234.          *  arrowup is set if we just came up from
  1235.          *  a page below.
  1236.          */
  1237.         curdoc.link = nlinks - 1;
  1238.         arrowup = FALSE;
  1239.         } else {
  1240.         curdoc.link = newdoc.link;
  1241.         if (curdoc.link >= nlinks) {
  1242.             curdoc.link = nlinks - 1;
  1243.         } else if (curdoc.link < 0 && nlinks > 0) {
  1244.             /*
  1245.              *    We may have popped a doc (possibly in local_dired)
  1246.              *    which didn't have any links when it was pushed, but
  1247.              *    does have links now (e.g. a file was created) - KW
  1248.              */
  1249.             curdoc.link = 0;
  1250.         }
  1251.         }
  1252.  
  1253.         show_help = FALSE; /* reset */
  1254.         newdoc.line = 1;
  1255.         newdoc.link = 0;
  1256.         curdoc.line = Newline; /* set */
  1257.     }
  1258.  
  1259.     /*
  1260.      *  Refresh the screen if necessary.
  1261.      */
  1262.     if (refresh_screen) {
  1263. #if defined(FANCY_CURSES) || defined (USE_SLANG)
  1264.         if (enable_scrollback) {
  1265.         clear();
  1266.         } else {
  1267.         erase();
  1268.         }
  1269. #else
  1270.         clear();
  1271. #endif /* FANCY_CURSES || USE_SLANG */
  1272.         HText_pageDisplay(Newline, prev_target);
  1273.  
  1274. #ifdef DIRED_SUPPORT
  1275.         if (lynx_edit_mode && nlinks > 0 && !HTList_isEmpty(tagged))
  1276.         showtags(tagged);
  1277. #endif /* DIRED_SUPPORT */
  1278.         if (user_mode == NOVICE_MODE)
  1279.         noviceline(more);  /* print help message */
  1280.         refresh_screen = FALSE;
  1281.  
  1282.     }
  1283.  
  1284.     /*
  1285.      *  Report unread or new mail, if appropriate.
  1286.      */
  1287.     if (check_mail && !no_mail && LYCheckMail())
  1288.         sleep(MessageSecs);
  1289.  
  1290.     /*
  1291.      *  If help is not on the screen,
  1292.      *  then put a message on the screen
  1293.      *  to tell the user other misc info.
  1294.      */
  1295.     if (!show_help) {
  1296.         /*
  1297.          *    Make sure form novice lines are replaced.
  1298.          */
  1299.         if (user_mode == NOVICE_MODE) {
  1300.         noviceline(more);
  1301.         }
  1302.  
  1303.         /*
  1304.          *    If we are in forms mode then explicitly
  1305.          *    tell the user what each kind of link is.
  1306.          */
  1307.         if (HTisDocumentSource()) {
  1308.         /*
  1309.          *  Currently displaying HTML source.
  1310.          */
  1311.         _statusline(SOURCE_HELP);
  1312.  
  1313. #ifdef INDICATE_FORMS_MODE_FOR_ALL_LINKS_ON_PAGE
  1314.         } else if (lynx_mode == FORMS_LYNX_MODE && nlinks > 0) {
  1315. #else
  1316. #ifdef NORMAL_NON_FORM_LINK_STATUSLINES_FOR_ALL_USER_MODES
  1317.         } else if (lynx_mode == FORMS_LYNX_MODE && nlinks > 0 &&
  1318.                !(links[curdoc.link].type & WWW_LINK_TYPE)) {
  1319. #else
  1320.         } else if (lynx_mode == FORMS_LYNX_MODE && nlinks > 0 &&
  1321.                !(user_mode == ADVANCED_MODE &&
  1322.              (links[curdoc.link].type & WWW_LINK_TYPE))) {
  1323. #endif /* NORMAL_NON_FORM_LINK_STATUSLINES_FOR_ALL_USER_MODES */
  1324. #endif /* INDICATE_FORMS_MODE_FOR_ALL_LINKS_ON_PAGE */
  1325.         if (links[curdoc.link].type == WWW_FORM_LINK_TYPE)
  1326.             switch(links[curdoc.link].form->type) {
  1327.             case F_PASSWORD_TYPE:
  1328.             if (links[curdoc.link].form->disabled == YES)
  1329.                 statusline(FORM_LINK_PASSWORD_UNM_MSG);
  1330.             else
  1331.                 statusline(FORM_LINK_PASSWORD_MESSAGE);
  1332.             break;
  1333.             case F_OPTION_LIST_TYPE:
  1334.             if (links[curdoc.link].form->disabled == YES)
  1335.                 statusline(FORM_LINK_OPTION_LIST_UNM_MSG);
  1336.             else
  1337.                 statusline(FORM_LINK_OPTION_LIST_MESSAGE);
  1338.             break;
  1339.             case F_CHECKBOX_TYPE:
  1340.             if (links[curdoc.link].form->disabled == YES)
  1341.                 statusline(FORM_LINK_CHECKBOX_UNM_MSG);
  1342.             else
  1343.                 statusline(FORM_LINK_CHECKBOX_MESSAGE);
  1344.             break;
  1345.             case F_RADIO_TYPE:
  1346.             if (links[curdoc.link].form->disabled == YES)
  1347.                 statusline(FORM_LINK_RADIO_UNM_MSG);
  1348.             else
  1349.                 statusline(FORM_LINK_RADIO_MESSAGE);
  1350.             break;
  1351.             case F_TEXT_SUBMIT_TYPE:
  1352.             if (links[curdoc.link].form->disabled == YES) {
  1353.                 statusline(FORM_LINK_TEXT_SUBMIT_UNM_MSG);
  1354.             } else if (links[curdoc.link].form->submit_method ==
  1355.                  URL_MAIL_METHOD) {
  1356.                 if (no_mail)
  1357.                 statusline(
  1358.                        FORM_LINK_TEXT_SUBMIT_MAILTO_DIS_MSG);
  1359.                 else
  1360.                 statusline(FORM_LINK_TEXT_SUBMIT_MAILTO_MSG);
  1361.             } else if (links[curdoc.link].form->no_cache) {
  1362.                 statusline(FORM_LINK_TEXT_RESUBMIT_MESSAGE);
  1363.             } else {
  1364.                 statusline(FORM_LINK_TEXT_SUBMIT_MESSAGE);
  1365.             }
  1366.             break;
  1367.             case F_SUBMIT_TYPE:
  1368.             case F_IMAGE_SUBMIT_TYPE:
  1369.             if (links[curdoc.link].form->disabled == YES) {
  1370.                 statusline(FORM_LINK_SUBMIT_DIS_MSG);
  1371.             } else if (links[curdoc.link].form->submit_method ==
  1372.                  URL_MAIL_METHOD) {
  1373.                 if (no_mail) {
  1374.                 statusline(FORM_LINK_SUBMIT_MAILTO_DIS_MSG);
  1375.                 } else {
  1376.                 statusline(FORM_LINK_SUBMIT_MAILTO_MSG);
  1377.                 }
  1378.             } else if (links[curdoc.link].form->no_cache) {
  1379.                 statusline(FORM_LINK_RESUBMIT_MESSAGE);
  1380.             } else {
  1381.                 statusline(FORM_LINK_SUBMIT_MESSAGE);
  1382.             }
  1383.             break;
  1384.             case F_RESET_TYPE:
  1385.             if (links[curdoc.link].form->disabled == YES)
  1386.                 statusline(FORM_LINK_RESET_DIS_MSG);
  1387.             else
  1388.                 statusline(FORM_LINK_RESET_MESSAGE);
  1389.             break;
  1390.             case F_TEXT_TYPE:
  1391.             case F_TEXTAREA_TYPE:
  1392.             if (links[curdoc.link].form->disabled == YES)
  1393.                 statusline(FORM_LINK_TEXT_UNM_MSG);
  1394.             else
  1395.                 statusline(FORM_LINK_TEXT_MESSAGE);
  1396.             break;
  1397.             }
  1398.         else
  1399.             statusline(NORMAL_LINK_MESSAGE);
  1400.  
  1401.         /*
  1402.          *  Let them know if it's an index -- very rare.
  1403.          */
  1404.         if (is_www_index) {
  1405.             move(LYlines-1,LYcols-8);
  1406.             start_reverse();
  1407.             addstr("-index-");
  1408.             stop_reverse();
  1409.         }
  1410.  
  1411.         } else if (user_mode == ADVANCED_MODE && nlinks > 0) {
  1412.         /*
  1413.          *  Show the URL or, for some internal links, the fragment
  1414.          */
  1415.         cp = NULL;
  1416.         if (links[curdoc.link].type == WWW_INTERN_LINK_TYPE &&
  1417.             strncmp(links[curdoc.link].lname, "LYNXIMGMAP:", 11)) {
  1418.             cp = strchr(links[curdoc.link].lname, '#');
  1419.         }
  1420.         if (!cp)
  1421.             cp = links[curdoc.link].lname;
  1422.         if (more)
  1423.             if (is_www_index)
  1424.             _user_message("-more- -index- %s",
  1425.                          cp);
  1426.             else
  1427.             _user_message("-more- %s",cp);
  1428.         else
  1429.             if (is_www_index)
  1430.             _user_message("-index- %s",cp);
  1431.             else
  1432.             statusline(cp);
  1433.         } else if (is_www_index && more) {
  1434.         char buf[128];
  1435.  
  1436.         sprintf(buf, WWW_INDEX_MORE_MESSAGE, key_for_func(LYK_INDEX_SEARCH));
  1437.         _statusline(buf);
  1438.         } else if (is_www_index) {
  1439.         char buf[128];
  1440.  
  1441.         sprintf(buf, WWW_INDEX_MESSAGE, key_for_func(LYK_INDEX_SEARCH));
  1442.         _statusline(buf);
  1443.         } else if (more) {
  1444.         if (user_mode == NOVICE_MODE)
  1445.             _statusline(MORE);
  1446.         else
  1447.             _statusline(MOREHELP);
  1448.         } else {
  1449.            _statusline(HELP);
  1450.         }
  1451.     } else {
  1452.        show_help = FALSE;
  1453.     }
  1454.  
  1455.     if (!(nlinks > 0 &&
  1456.           links[curdoc.link].type == WWW_FORM_LINK_TYPE &&
  1457.           (links[curdoc.link].form->type == F_TEXT_TYPE ||
  1458.            links[curdoc.link].form->type == F_TEXTAREA_TYPE)))
  1459.          /*
  1460.           *  Highlight current link.
  1461.           */
  1462.         highlight(ON, curdoc.link, prev_target);
  1463.  
  1464.     if (traversal) {
  1465.         /*
  1466.          *    Don't go interactively into forms,
  1467.          *    or accept keystrokes from the user
  1468.          */
  1469.         if (crawl && crawl_ok) {
  1470.         crawl_ok = FALSE;
  1471. #ifdef FNAMES_8_3
  1472.         sprintf(cfile,"lnk%05d.dat",ccount);
  1473. #else
  1474.         sprintf(cfile,"lnk%08d.dat",ccount);
  1475. #endif /* FNAMES_8_3 */
  1476.         ccount = ccount + 1;
  1477.         if ((cfp = LYNewTxtFile(cfile))  != NULL) {
  1478.             print_crawl_to_fd(cfp,curdoc.address,curdoc.title);
  1479.             fclose(cfp);
  1480.         } else {
  1481.             if (!dump_output_immediately)
  1482.             cleanup();
  1483. #ifdef UNIX
  1484.             if (dump_output_immediately)
  1485.             fprintf(stderr,
  1486.             "Fatal error - could not open output file %s\n",cfile);
  1487.             else
  1488. #endif
  1489.             printf(
  1490.             "Fatal error - could not open output file %s\n",cfile);
  1491.             if (!dump_output_immediately) {
  1492. #ifndef NOSIGHUP
  1493.             (void) signal(SIGHUP, SIG_DFL);
  1494. #endif /* NOSIGHUP */
  1495.             (void) signal(SIGTERM, SIG_DFL);
  1496. #ifndef VMS
  1497.             (void) signal(SIGINT, SIG_DFL);
  1498. #endif /* !VMS */
  1499. #ifdef SIGTSTP
  1500.             if (no_suspend)
  1501.                 (void) signal(SIGTSTP,SIG_DFL);
  1502. #endif /* SIGTSTP */
  1503.             exit(-1);
  1504.             }
  1505.             return(-1);
  1506.         }
  1507.         }
  1508.     } else {
  1509.         /*
  1510.          *    Normal, non-traversal handling.
  1511.          */
  1512.         if (nlinks > 0 &&
  1513.         links[curdoc.link].type == WWW_FORM_LINK_TYPE &&
  1514.         (links[curdoc.link].form->type == F_TEXT_TYPE ||
  1515.          links[curdoc.link].form->type == F_TEXT_SUBMIT_TYPE ||
  1516.          links[curdoc.link].form->type == F_PASSWORD_TYPE ||
  1517.          links[curdoc.link].form->type == F_TEXTAREA_TYPE)) {
  1518.         /*
  1519.          *  Replace novice lines if in NOVICE_MODE.
  1520.          */
  1521.         if (user_mode==NOVICE_MODE) {
  1522.             move(LYlines-2,0); clrtoeol();
  1523.             addstr(FORM_NOVICELINE_ONE);
  1524.             move(LYlines-1,0); clrtoeol();
  1525.             addstr(FORM_NOVICELINE_TWO);
  1526.         }
  1527.         c = change_form_link(&links[curdoc.link],
  1528.                      FORM_UP, &newdoc, &refresh_screen,
  1529.                      links[curdoc.link].form->name,
  1530.                      links[curdoc.link].form->value);
  1531.  
  1532.         if (c == '\n' || c == '\r')
  1533. #ifdef FASTTAB
  1534.             /*
  1535.              *    Make return act like down-arrow.
  1536.              */
  1537.             c = DNARROW;
  1538. #else
  1539.             /*
  1540.              *    Make return act like tab.
  1541.              */
  1542.             c = '\t';
  1543. #endif /* FASTTAB */
  1544.         } else {
  1545.         /*
  1546.          *  Get a keystroke from the user.
  1547.          *  Save the last keystroke to avoid
  1548.          *  redundant error reporting.
  1549.          */
  1550.         real_c = c = LYgetch(); /* get user input */
  1551.  
  1552. #ifndef VMS
  1553.         if (c == 3) {        /* ^C */
  1554.             /*
  1555.              *    This shouldn't happen.    We'll try to
  1556.              *    deal with whatever bug caused it. - FM
  1557.              */
  1558.             signal(SIGINT, cleanup_sig);
  1559.             old_c = 0;
  1560.             cmd = LYK_QUIT;
  1561.             goto new_cmd;
  1562.         }
  1563. #endif /* !VMS */
  1564.         if (old_c != real_c) {
  1565.             old_c = 0;
  1566.         }
  1567.         }
  1568.     }
  1569.  
  1570. #ifdef VMS
  1571.     if (HadVMSInterrupt) {
  1572.         HadVMSInterrupt = FALSE;
  1573.         c = DO_NOTHING;
  1574.     }
  1575. #else
  1576.     if (recent_sizechange) {
  1577.         if (c <= 0)
  1578.         c = DO_NOTHING;
  1579.     }
  1580. #endif /* VMS */
  1581.  
  1582. new_keyboard_input:
  1583.     /*
  1584.      *  A goto point for new input without going
  1585.      *  back through the getch() loop.
  1586.      */
  1587.     if (traversal) {
  1588.         /*
  1589.          *    This is a special feature to traverse every http link
  1590.          *    derived from startfile and check for errors or create
  1591.          *    crawl output files.  Only URL's that begin with
  1592.          *    "traversal_host" are searched - this keeps the search
  1593.          *    from crossing to other servers (a feature, not a bug!).
  1594.          */
  1595.         rlink_exists = (nlinks > 0 && links[curdoc.link].lname != NULL);
  1596.         if (rlink_exists) {
  1597.         rlink_allowed =
  1598.             (!lookup_reject(links[curdoc.link].lname) &&
  1599.              traversal_host && links[curdoc.link].lname &&
  1600.              !strncmp(traversal_host,
  1601.                   (strncmp(links[curdoc.link].lname,
  1602.                        "LYNXIMGMAP:", 11)
  1603.                      ?
  1604.         links[curdoc.link].lname : (links[curdoc.link].lname + 11)),
  1605.                   strlen(traversal_host)));
  1606.         } else {
  1607.         rlink_allowed = FALSE;
  1608.         }
  1609.         if (rlink_exists && rlink_allowed) {
  1610.         if (lookup(links[curdoc.link].lname)) {
  1611.             if (more_links ||
  1612.             (curdoc.link > -1 && curdoc.link < nlinks -1))
  1613.              c= DNARROW;
  1614.             else {
  1615.             if (STREQ(curdoc.title,"Entry into main screen") ||
  1616.                 (nhist <= 0 )) {
  1617.                 if (!dump_output_immediately) {
  1618.                 cleanup();
  1619. #ifndef NOSIGHUP
  1620.                 (void) signal(SIGHUP, SIG_DFL);
  1621. #endif /* NOSIGHUP */
  1622.                 (void) signal(SIGTERM, SIG_DFL);
  1623. #ifndef VMS
  1624.                 (void) signal(SIGINT, SIG_DFL);
  1625. #endif /* !VMS */
  1626. #ifdef SIGTSTP
  1627.                 if (no_suspend)
  1628.                     (void) signal(SIGTSTP,SIG_DFL);
  1629. #endif /* SIGTSTP */
  1630.                 exit(-1);
  1631.                 }
  1632.                 return(-1);
  1633.             }
  1634.             c = LTARROW;
  1635.             }
  1636.         } else {
  1637.             StrAllocCopy(traversal_link_to_add,
  1638.                  links[curdoc.link].lname);
  1639.             if (strncmp(traversal_link_to_add, "LYNXIMGMAP:", 11))
  1640.             crawl_ok = TRUE;
  1641.             c = RTARROW;
  1642.         }
  1643.         } else { /* no good right link, so only down and left arrow ok*/
  1644.         if (rlink_exists)
  1645.             add_to_reject_list(links[curdoc.link].lname);
  1646.         if (more_links ||
  1647.             (curdoc.link > -1 && curdoc.link < nlinks-1))
  1648.             c = DNARROW;
  1649.         else {
  1650.             /*
  1651.              *    curdoc.title doesn't always work, so
  1652.              *    bail out if the history list is empty.
  1653.              */
  1654.             if (STREQ(curdoc.title,"Entry into main screen") ||
  1655.             (nhist <= 0 )) {
  1656.             if (!dump_output_immediately) {
  1657.                 cleanup();
  1658. #ifndef NOSIGHUP
  1659.                 (void) signal(SIGHUP, SIG_DFL);
  1660. #endif /* NOSIGHUP */
  1661.                 (void) signal(SIGTERM, SIG_DFL);
  1662. #ifndef VMS
  1663.                 (void) signal(SIGINT, SIG_DFL);
  1664. #endif /* !VMS */
  1665. #ifdef SIGTSTP
  1666.                 if (no_suspend)
  1667.                 (void) signal(SIGTSTP,SIG_DFL);
  1668. #endif /* SIGTSTP */
  1669.                 exit(-1);
  1670.             }
  1671.             return(-1);
  1672.             }
  1673.             c = LTARROW;
  1674.         }
  1675.         } /* right link not NULL or link to another site*/
  1676.     } /* traversal */
  1677.  
  1678.     cmd = keymap[c+1];  /* add 1 to map EOF to 0 */
  1679.  
  1680. #if defined(DIRED_SUPPORT) && defined(OK_OVERRIDE)
  1681.     if (lynx_edit_mode && override[c+1] && !no_dired_support)
  1682.       cmd = override[c+1];
  1683. #endif /* DIRED_SUPPORT && OK_OVERRIDE */
  1684.  
  1685.     real_cmd = cmd;
  1686.  
  1687. new_cmd:  /*
  1688.        *  A goto point for new input without going
  1689.        *  back through the getch() loop.
  1690.        */
  1691.  
  1692.     switch(cmd) {
  1693.     case 0: /* unmapped character */
  1694.     default:
  1695.         if (more)
  1696.         _statusline(MOREHELP);
  1697.         else
  1698.         _statusline(HELP);
  1699.         show_help = TRUE;
  1700.  
  1701.         if (TRACE) {
  1702.         sprintf(cfile, "%d", c);
  1703.         addstr(cfile);    /* show the user input */
  1704.         cfile[0] = '\0';
  1705.         }
  1706.         break;
  1707.  
  1708.     case LYK_INTERRUPT:
  1709.         /*
  1710.          *    No network transmission to interrupt - 'til we multithread.
  1711.          */
  1712.         break;
  1713.  
  1714.     case LYK_F_LINK_NUM:
  1715.          c = '\0';
  1716.     case LYK_1:
  1717.     case LYK_2:
  1718.     case LYK_3:
  1719.     case LYK_4:
  1720.     case LYK_5:
  1721.     case LYK_6:
  1722.     case LYK_7:
  1723.     case LYK_8:
  1724.     case LYK_9:
  1725.     {
  1726.         /*
  1727.          *    Get a number from the user and follow that link number.
  1728.          */
  1729.         int lindx = ((nlinks > 0) ? curdoc.link : 0);
  1730.         int number;
  1731.  
  1732.         switch (follow_link_number(c, lindx, &newdoc, &number)) {
  1733.         case DO_LINK_STUFF:
  1734.         /*
  1735.          *  Follow a normal link.
  1736.          */
  1737.         StrAllocCopy(newdoc.address, links[lindx].lname);
  1738.         StrAllocCopy(newdoc.title, links[lindx].hightext);
  1739. #ifndef DONT_TRACK_INTERNAL_LINKS
  1740.         /*
  1741.          *  For internal links, retain POST content if present.
  1742.          *  If we are on the List Page, prevent pushing it on
  1743.          *  the history stack.    Otherwise set try_internal to
  1744.          *  signal that the top of the loop should attempt to
  1745.          *  reposition directly, without calling getfile. - kw
  1746.          */
  1747.         if (links[lindx].type == WWW_INTERN_LINK_TYPE) {
  1748.             LYinternal_flag = TRUE;
  1749.             newdoc.internal_link = TRUE;
  1750.             if (0==strcmp((curdoc.title ? curdoc.title : ""),
  1751.                       LIST_PAGE_TITLE) &&
  1752.             0==strcmp(HTLoadedDocumentURL(), LYlist_temp_url())) {
  1753.             if (!curdoc.post_data ||
  1754.                 /*
  1755.                  *    Normal case - List Page is not associated
  1756.                  *    with post data. - kw
  1757.                  */
  1758.                 (!LYresubmit_posts && curdoc.post_data &&
  1759.                  history[nhist - 1].post_data &&
  1760.                  !strcmp(curdoc.post_data,
  1761.                      history[nhist - 1].post_data) &&
  1762.                  HText_getContentBase() &&
  1763.                  !strncmp(HText_getContentBase(),
  1764.                       strncmp(history[nhist - 1].address,
  1765.                           "LYNXIMGMAP:", 11) ?
  1766.                       history[nhist - 1].address :
  1767.                       history[nhist - 1].address + 11,
  1768.                       strlen(HText_getContentBase())))) {
  1769.                 /*
  1770.                  *    Normal case - as best as we can check, the
  1771.                  *    document at the top of the history stack
  1772.                  *    seems to be the document the List Page is
  1773.                  *    about (or a LYNXIMGMAP derived from it),
  1774.                  *    and LYresubmit_posts is not set, so don't
  1775.                  *    prompt here.  If we actually have to repeat
  1776.                  *    a POST because, against expectations, the
  1777.                  *    underlying document isn't cached any more,
  1778.                  *    HTAccess will prompt for confirmation,
  1779.                  *    unless we had LYK_NOCACHE. - kw
  1780.                  */
  1781.                 LYinternal_flag = TRUE;
  1782.             } else {
  1783.                 HTLastConfirmCancelled(); /* reset flag */
  1784.                 if (!confirm_post_resub(newdoc.address,
  1785.                             newdoc.title,
  1786.                             (LYresubmit_posts &&
  1787.                              HText_POSTReplyLoaded(&newdoc)) ? 1 : 2,
  1788.                             2)) {
  1789.                 if (HTLastConfirmCancelled() ||
  1790.                     (LYresubmit_posts &&
  1791.                      !HText_POSTReplyLoaded(&newdoc))) {
  1792.                     /* cancel the whole thing */
  1793.                     LYforce_no_cache = FALSE;
  1794.                     reloading = FALSE;
  1795.                     StrAllocCopy(newdoc.address, curdoc.address);
  1796.                     StrAllocCopy(newdoc.title, curdoc.title);
  1797.                     newdoc.internal_link = curdoc.internal_link;
  1798.                     _statusline(CANCELLED);
  1799.                     sleep(InfoSecs);
  1800.                     if (nlinks > 0)
  1801.                     HText_pageDisplay(curdoc.line, prev_target);
  1802.                     break;
  1803.                 } else if (LYresubmit_posts) {
  1804.                     /* If LYresubmit_posts is set, and the
  1805.                        answer was No, and we have a cached
  1806.                        copy, then use it. - kw */
  1807.                     LYforce_no_cache = FALSE;
  1808.                 } else {
  1809.                     /* if No, but not ^C or ^G, drop
  1810.                      * the post data.  Maybe the link
  1811.                      * wasn't meant to be internal after
  1812.                      * all, here we can recover from that
  1813.                      * assumption. - kw */
  1814.                     FREE(newdoc.post_data);
  1815.                     FREE(newdoc.post_content_type);
  1816.                     newdoc.internal_link = FALSE;
  1817.                     _statusline(DISCARDING_POST_DATA);
  1818.                     sleep(AlertSecs);
  1819.                 }
  1820.                 }
  1821.             }
  1822.             /*
  1823.              *  Don't push the List Page if we follow an
  1824.              *  internal link given by it. - kw
  1825.              */
  1826.             FREE(curdoc.address);
  1827.             } else
  1828.             try_internal = TRUE;
  1829.             if (!(LYresubmit_posts && newdoc.post_data))
  1830.             LYinternal_flag = TRUE;
  1831.             force_load = TRUE;
  1832.             break;
  1833.         } else {
  1834.             /*
  1835.              *    Free POST content if not an internal link. - kw
  1836.              */
  1837.             FREE(newdoc.post_data);
  1838.             FREE(newdoc.post_content_type);
  1839.         }
  1840. #endif /* DONT_TRACK_INTERNAL_LINKS */
  1841.         /*
  1842.          *  Might be an anchor in the same doc from a POST
  1843.          *  form.  If so, don't free the content. -- FM
  1844.          */
  1845.         if (are_different(&curdoc, &newdoc)) {
  1846.             FREE(newdoc.post_data);
  1847.             FREE(newdoc.post_content_type);
  1848.             FREE(newdoc.bookmark);
  1849.             newdoc.isHEAD = FALSE;
  1850.             newdoc.safe = FALSE;
  1851.         }
  1852.         newdoc.internal_link = FALSE;
  1853.         force_load = TRUE;  /* force MainLoop to reload */
  1854.         break;
  1855.  
  1856.         case DO_GOTOLINK_STUFF:
  1857.         /*
  1858.          *  Position on a normal link, don't follow it. - KW
  1859.          */
  1860.         Newline = newdoc.line;
  1861.         newdoc.line = 1;
  1862.         if (Newline == curdoc.line) {
  1863.             /*
  1864.              *    It's a link in the current page. - FM
  1865.              */
  1866.             if (nlinks > 0 && curdoc.link > -1) {
  1867.             if (curdoc.link == newdoc.link) {
  1868.                 /*
  1869.                  *    It's the current link, and presumably
  1870.                  *    reflects a typo in the statusline entry,
  1871.                  *    so issue a statusline message for the
  1872.                  *    typo-prone users (like me 8-). - FM
  1873.                  */
  1874.                 StrAllocCopy(temp, user_input_buffer);
  1875.                 sprintf(user_input_buffer,
  1876.                     LINK_ALREADY_CURRENT, number);
  1877.                 _statusline(user_input_buffer);
  1878.                 sleep(MessageSecs);
  1879.                 strcpy(user_input_buffer, temp);
  1880.                 FREE(temp);
  1881.             } else {
  1882.                 /*
  1883.                  *    It's a different link on this page,
  1884.                  *    so turn the highlighting off, set the
  1885.                  *    current link to the new link value from
  1886.                  *    follow_link_number(), and re-initialize
  1887.                  *    the new link value. - FM
  1888.                  */
  1889.                 highlight(OFF, curdoc.link, prev_target);
  1890.                 curdoc.link = newdoc.link;
  1891.                 newdoc.link = 0;
  1892.             }
  1893.             }
  1894.         }
  1895.         break;        /* nothing more to do */
  1896.  
  1897.         case DO_GOTOPAGE_STUFF:
  1898.         /*
  1899.          *  Position on a page in this document. - FM
  1900.          */
  1901.         Newline = newdoc.line;
  1902.         newdoc.line = 1;
  1903.         if (Newline == curdoc.line) {
  1904.             /*
  1905.              *    It's the current page, so issue a
  1906.              *    statusline message for the typo-prone
  1907.              *    users (like me 8-). - FM
  1908.              */
  1909.             if (Newline <= 1) {
  1910.             _statusline(ALREADY_AT_BEGIN);
  1911.             } else if (!more) {
  1912.             _statusline(ALREADY_AT_END);
  1913.             } else {
  1914.             StrAllocCopy(temp, user_input_buffer);
  1915.             sprintf(user_input_buffer,
  1916.                 ALREADY_AT_PAGE, number);
  1917.             _statusline(user_input_buffer);
  1918.             sleep(MessageSecs);
  1919.             strcpy(user_input_buffer, temp);
  1920.             FREE(temp);
  1921.             }
  1922.             sleep(MessageSecs);
  1923.         }
  1924.         break;
  1925.  
  1926.         case PRINT_ERROR:
  1927.         old_c = real_c;
  1928.         _statusline(BAD_LINK_NUM_ENTERED);
  1929.         sleep(MessageSecs);
  1930.         break;
  1931.         }
  1932.         break;
  1933.     }
  1934.  
  1935.     case LYK_SOURCE:  /* toggle view source mode */
  1936.         /*
  1937.          *    Check if this is a reply from a POST, and if so,
  1938.          *    seek confirmation if the safe element is not set. - FM
  1939.          */
  1940.         if ((curdoc.post_data != NULL &&
  1941.          curdoc.safe != TRUE) &&
  1942.         confirm_post_resub(curdoc.address, curdoc.title,
  1943.                    1, 1) == FALSE) {
  1944.         _statusline(CANCELLED);
  1945.         sleep(InfoSecs);
  1946.         break;
  1947.         }
  1948.  
  1949.         if (HTisDocumentSource()) {
  1950.         HTOutputFormat = WWW_PRESENT;
  1951.         } else {
  1952.         if (HText_getOwner())
  1953.             StrAllocCopy(ownerS_address, HText_getOwner());
  1954.         LYUCPushAssumed(HTMainAnchor);
  1955.         HTOutputFormat = WWW_SOURCE;
  1956.         }
  1957.         LYforce_no_cache = TRUE;
  1958.         FREE(curdoc.address); /* so it doesn't get pushed */
  1959.         break;
  1960.  
  1961.     case LYK_RELOAD:  /* control-R to reload and refresh */
  1962.         /*
  1963.          *    Check if this is a reply from a POST, and if so,
  1964.          *    seek confirmation if the safe element is not set. - FM
  1965.          */
  1966.         if ((curdoc.post_data != NULL &&
  1967.          curdoc.safe != TRUE) &&
  1968.         HTConfirm(CONFIRM_POST_RESUBMISSION) == FALSE) {
  1969.         _statusline(CANCELLED);
  1970.         sleep(InfoSecs);
  1971.         break;
  1972.         }
  1973.  
  1974.         /*
  1975.          *    Check to see if should reload source, or load html
  1976.          */
  1977.         if (HTisDocumentSource()) {
  1978.         HTOutputFormat = WWW_SOURCE;
  1979.         }
  1980.         HEAD_request = HTLoadedDocumentIsHEAD();
  1981.         HTuncache_current_document();
  1982. #ifdef NO_ASSUME_SAME_DOC
  1983.         /*
  1984.          *    Don't assume the reloaded document will be the same. - FM
  1985.          */
  1986.         newdoc.line = 1;
  1987.         newdoc.link = 0;
  1988. #else
  1989.         /*
  1990.          *    Do assume the reloaded document will be the same. - FM
  1991.          *    (I don't remember all the reasons why we couldn't assume
  1992.          *     this.    As the problems show up, we'll try to fix them,
  1993.          *     or add warnings.  - FM)
  1994.          */
  1995.         if (lynx_mode == FORMS_LYNX_MODE) {
  1996.         /*
  1997.          *  Note that if there are no form links on the current
  1998.          *  page, lynx_mode won't have this setting and we won't
  1999.          *  know that this warning should be issued. - FM
  2000.          */
  2001.         _statusline(RELOADING_FORM);
  2002.         sleep(AlertSecs);
  2003.         }
  2004.         newdoc.line = ((curdoc.line > 0) ?
  2005.                  curdoc.line : 1);
  2006.         newdoc.link = ((curdoc.link > -1) ?
  2007.                   curdoc.link : 0);
  2008. #endif /* NO_ASSUME_SAME_DOC */
  2009.         FREE(curdoc.address); /* so it doesn't get pushed */
  2010. #ifdef VMS
  2011.         lynx_force_repaint();
  2012. #endif /* VMS */
  2013.         /*
  2014.          *    Reload should force a cache refresh on a proxy.
  2015.          *          -- Ari L. <luotonen@dxcern.cern.ch>
  2016.          *
  2017.          *    -- but only if this was really a reload requested by
  2018.          *    the user, not if we jumped here to handle reloading for
  2019.          *    INLINE_TOGGLE, IMAGE_TOGGLE, RAW_TOGGLE, etc. - KW
  2020.          */
  2021.         if (real_cmd == LYK_RELOAD)
  2022.         reloading = TRUE;
  2023.         break;
  2024.  
  2025.     case LYK_HISTORICAL:
  2026.         /*
  2027.          *    Check if this is a reply from a POST, and if so,
  2028.          *    seek confirmation of reload if the safe element
  2029.          *    is not set. - FM
  2030.          */
  2031.         if ((curdoc.post_data != NULL &&
  2032.          curdoc.safe != TRUE) &&
  2033.         confirm_post_resub(curdoc.address, NULL,
  2034.                    0, 0) == FALSE) {
  2035.         _statusline(WILL_NOT_RELOAD_DOC);
  2036.         sleep(InfoSecs);
  2037.         } else {
  2038.         HTuncache_current_document();
  2039.         StrAllocCopy(newdoc.address, curdoc.address);
  2040.         FREE(curdoc.address);
  2041.         }
  2042.         if (historical_comments)
  2043.         historical_comments = FALSE;
  2044.         else
  2045.         historical_comments = TRUE;
  2046.         if (minimal_comments) {
  2047.         _statusline(historical_comments ?
  2048.               HISTORICAL_ON_MINIMAL_OFF : HISTORICAL_OFF_MINIMAL_ON);
  2049.         } else {
  2050.         _statusline(historical_comments ?
  2051.             HISTORICAL_ON_VALID_OFF : HISTORICAL_OFF_VALID_ON);
  2052.         }
  2053.         sleep(AlertSecs);
  2054.         break;
  2055.  
  2056.     case LYK_MINIMAL:
  2057.         if (!historical_comments) {
  2058.         /*
  2059.          *  Check if this is a reply from a POST, and if so,
  2060.          *  seek confirmation of reload if the safe element
  2061.          *  is not set. - FM
  2062.          */
  2063.         if ((curdoc.post_data != NULL &&
  2064.              curdoc.safe != TRUE) &&
  2065.             confirm_post_resub(curdoc.address, NULL,
  2066.                        0, 0) == FALSE) {
  2067.             _statusline(WILL_NOT_RELOAD_DOC);
  2068.             sleep(InfoSecs);
  2069.         } else {
  2070.             HTuncache_current_document();
  2071.             StrAllocCopy(newdoc.address, curdoc.address);
  2072.             FREE(curdoc.address);
  2073.         }
  2074.         }
  2075.         if (minimal_comments)
  2076.         minimal_comments = FALSE;
  2077.         else
  2078.         minimal_comments = TRUE;
  2079.         if (!historical_comments) {
  2080.         _statusline(minimal_comments ?
  2081.             MINIMAL_ON_IN_EFFECT : MINIMAL_OFF_VALID_ON);
  2082.         } else {
  2083.         _statusline(minimal_comments ?
  2084.            MINIMAL_ON_BUT_HISTORICAL : MINIMAL_OFF_HISTORICAL_ON);
  2085.         }
  2086.         sleep(AlertSecs);
  2087.         break;
  2088.  
  2089.     case LYK_SOFT_DQUOTES:
  2090.         /*
  2091.          *    Check if this is a reply from a POST, and if so,
  2092.          *    seek confirmation of reload if the safe element
  2093.          *    is not set. - FM
  2094.          */
  2095.         if ((curdoc.post_data != NULL &&
  2096.          curdoc.safe != TRUE) &&
  2097.         confirm_post_resub(curdoc.address, NULL,
  2098.                    1, 1) == FALSE) {
  2099.         _statusline(WILL_NOT_RELOAD_DOC);
  2100.         sleep(InfoSecs);
  2101.         } else {
  2102.         HTuncache_current_document();
  2103.         StrAllocCopy(newdoc.address, curdoc.address);
  2104.         FREE(curdoc.address);
  2105.         }
  2106.         if (soft_dquotes)
  2107.         soft_dquotes = FALSE;
  2108.         else
  2109.         soft_dquotes = TRUE;
  2110.         _statusline(soft_dquotes ?
  2111.         SOFT_DOUBLE_QUOTE_ON : SOFT_DOUBLE_QUOTE_OFF);
  2112.         sleep(MessageSecs);
  2113.         break;
  2114.  
  2115.     case LYK_SWITCH_DTD:
  2116.         /*
  2117.          *    Check if this is a reply from a POST, and if so,
  2118.          *    seek confirmation of reload if the safe element
  2119.          *    is not set. - FM, kw
  2120.          */
  2121.         if ((curdoc.post_data != NULL &&
  2122.          curdoc.safe != TRUE) &&
  2123.         confirm_post_resub(curdoc.address, NULL,
  2124.                    1, 1) == FALSE) {
  2125.         _statusline(WILL_NOT_RELOAD_DOC);
  2126.         sleep(InfoSecs);
  2127.         } else {
  2128.         /*
  2129.          *  If currently viewing preparsed source, switching
  2130.          *  to the other DTD parsing may show source differences,
  2131.          *  so stay in source view - kw
  2132.          */
  2133.         if (HTisDocumentSource() && LYPreparsedSource) {
  2134.             HTOutputFormat = WWW_SOURCE;
  2135.         }
  2136.         HTuncache_current_document();
  2137.         StrAllocCopy(newdoc.address, curdoc.address);
  2138.         FREE(curdoc.address);
  2139.         }
  2140. #ifdef NO_ASSUME_SAME_DOC
  2141.         newdoc.line=1;
  2142.         newdoc.link=0;
  2143. #else
  2144.         newdoc.line = ((curdoc.line > 0) ? curdoc.line : 1);
  2145.         newdoc.link = ((curdoc.link > -1) ? curdoc.link : 0);
  2146. #endif /* NO_ASSUME_SAME_DOC */
  2147.         if (New_DTD)
  2148.         New_DTD = NO;
  2149.         else
  2150.         New_DTD = YES;
  2151.         HTSwitchDTD(New_DTD);
  2152.         _statusline(New_DTD ? USING_DTD_1 : USING_DTD_0);
  2153.         sleep(MessageSecs);
  2154.         break;
  2155.  
  2156. #ifdef NOT_DONE_YET
  2157.     case LYK_PIPE:
  2158.         /* ignore for now */
  2159.         break;
  2160. #endif /* NOT_DONE_YET */
  2161.  
  2162.     case LYK_QUIT:    /* quit */
  2163.         if (LYQuitDefaultYes == TRUE) {
  2164.         _statusline(REALLY_QUIT_Y);
  2165.         } else {
  2166.         _statusline(REALLY_QUIT_N);
  2167.         }
  2168.         c = LYgetch();
  2169.         if (LYQuitDefaultYes == TRUE) {
  2170.         if (TOUPPER(c) != 'N' &&
  2171.             c != 7) {
  2172.             return(0);
  2173.         } else {
  2174.             statusline(NO_CANCEL);
  2175.             sleep(InfoSecs);
  2176.         }
  2177.         } else if (TOUPPER(c) == 'Y') {
  2178.         return(0);
  2179.         } else {
  2180.         statusline(NO_CANCEL);
  2181.         sleep(InfoSecs);
  2182.         }
  2183.         break;
  2184.  
  2185.     case LYK_ABORT:     /* don't ask the user about quitting */
  2186.         return(0);
  2187.         break;
  2188.  
  2189.     case LYK_NEXT_PAGE:    /* next page */
  2190.         if (more) {
  2191.         Newline += display_lines;
  2192.         } else if (curdoc.link < nlinks-1) {
  2193.         highlight(OFF, curdoc.link, prev_target);
  2194.         curdoc.link = nlinks-1;  /* put on last link */
  2195.         } else if (old_c != real_c) {
  2196.            old_c = real_c;
  2197.            _statusline(ALREADY_AT_END);
  2198.            sleep(MessageSecs);
  2199.         }
  2200.         break;
  2201.  
  2202.     case LYK_PREV_PAGE:  /* page up */
  2203.         if (Newline > 1) {
  2204.         Newline -= display_lines;
  2205.         } else if (curdoc.link > 0) {
  2206.         highlight(OFF, curdoc.link, prev_target);
  2207.         curdoc.link = 0;  /* put on first link */
  2208.         } else if (old_c != real_c) {
  2209.         old_c = real_c;
  2210.         _statusline(ALREADY_AT_BEGIN);
  2211.         sleep(MessageSecs);
  2212.         }
  2213.         break;
  2214.  
  2215.     case  LYK_UP_TWO:
  2216.         if (Newline > 1) {
  2217.         int scrollamount = (Newline > 2 ? 2 : 1);
  2218.         Newline -= scrollamount;
  2219.         if (nlinks > 0 && curdoc.link > -1) {
  2220.             if (links[curdoc.link].ly + scrollamount <= display_lines) {
  2221.             newdoc.link = curdoc.link +
  2222.                       HText_LinksInLines(HTMainText,
  2223.                              Newline, scrollamount);
  2224.             } else {
  2225.             arrowup = TRUE;
  2226.             }
  2227.         }
  2228.         } else if (old_c != real_c) {
  2229.         old_c = real_c;
  2230.         _statusline(ALREADY_AT_BEGIN);
  2231.         sleep(MessageSecs);
  2232.         }
  2233.         break;
  2234.  
  2235.     case  LYK_DOWN_TWO:
  2236.         if (more) {
  2237.         Newline += 2;
  2238.         if (nlinks > 0 && curdoc.link > -1 &&
  2239.             links[curdoc.link].ly > 2) {
  2240.             newdoc.link = curdoc.link;
  2241.             for (i = 0; links[i].ly <= 2; i++)
  2242.             --newdoc.link;
  2243.         }
  2244.         } else if (old_c != real_c) {
  2245.         old_c = real_c;
  2246.         _statusline(ALREADY_AT_END);
  2247.         sleep(MessageSecs);
  2248.         }
  2249.         break;
  2250.  
  2251.     case  LYK_UP_HALF:
  2252.         if (Newline > 1) {
  2253.         int scrollamount = display_lines/2;
  2254.         if (Newline - scrollamount < 1)
  2255.             scrollamount = Newline - 1;
  2256.         Newline -= scrollamount;
  2257.         if (nlinks > 0 && curdoc.link > -1) {
  2258.             if (links[curdoc.link].ly + scrollamount <= display_lines) {
  2259.             newdoc.link = curdoc.link +
  2260.                       HText_LinksInLines(HTMainText,
  2261.                              Newline,
  2262.                              scrollamount);
  2263.             } else {
  2264.             arrowup = TRUE;
  2265.             }
  2266.         }
  2267.         } else if (old_c != real_c) {
  2268.         old_c = real_c;
  2269.         _statusline(ALREADY_AT_BEGIN);
  2270.         sleep(MessageSecs);
  2271.         }
  2272.         break;
  2273.  
  2274.     case  LYK_DOWN_HALF:
  2275.         if (more) {
  2276.         Newline += (display_lines/2);
  2277.         if (nlinks > 0 && curdoc.link > -1 &&
  2278.             links[curdoc.link].ly > display_lines/2) {
  2279.             newdoc.link = curdoc.link;
  2280.             for (i = 0; links[i].ly <= (display_lines/2); i++)
  2281.             --newdoc.link;
  2282.         }
  2283.         } else if (old_c != real_c) {
  2284.         old_c = real_c;
  2285.         _statusline(ALREADY_AT_END);
  2286.         sleep(MessageSecs);
  2287.         }
  2288.         break;
  2289.  
  2290.     case LYK_REFRESH:
  2291.        refresh_screen = TRUE;
  2292.        lynx_force_repaint();
  2293.        break;
  2294.  
  2295.     case LYK_HOME:
  2296.         if (curdoc.line > 1)
  2297.         Newline = 1;
  2298.         else {
  2299.         cmd = LYK_PREV_PAGE;
  2300.         goto new_cmd;
  2301.         }
  2302.         break;
  2303.  
  2304.     case LYK_END:
  2305.         if (more) {
  2306.            Newline = MAXINT; /* go to end of file */
  2307.            arrowup = TRUE;     /* position on last link */
  2308.         } else {
  2309.         cmd = LYK_NEXT_PAGE;
  2310.         goto new_cmd;
  2311.         }
  2312.         break;
  2313.  
  2314.     case LYK_PREV_LINK:
  2315.         if (curdoc.link > 0) {         /* previous link */
  2316.         /*
  2317.          *  Unhighlight current link.
  2318.          */
  2319.         highlight(OFF, curdoc.link, prev_target);
  2320.         curdoc.link--;
  2321.  
  2322.         } else if (!more &&
  2323.                curdoc.link==0 && Newline==1) { /* at the top of list */
  2324.         /*
  2325.          *  If there is only one page of data and the user
  2326.          *  goes off the top, then unhighlight the current
  2327.          *  link and just move the cursor to last link on
  2328.          *  the page.
  2329.          */
  2330.         highlight(OFF, curdoc.link, prev_target);
  2331.         curdoc.link = nlinks-1;  /* the last link */
  2332.  
  2333.         } else if (curdoc.line > 1) {    /* previous page */
  2334.         /*
  2335.          *  Go back to the previous page.
  2336.          */
  2337.         int scrollamount = (Newline > display_lines ?
  2338.                           display_lines : Newline - 1);
  2339.         Newline -= scrollamount;
  2340.         if (scrollamount < display_lines &&
  2341.             nlinks > 0 && curdoc.link == 0 &&
  2342.             links[0].ly - 1 + scrollamount <= display_lines) {
  2343.             newdoc.link = HText_LinksInLines(HTMainText,
  2344.                              1,
  2345.                              scrollamount) - 1;
  2346.         } else {
  2347.             arrowup = TRUE;
  2348.         }
  2349.  
  2350.         } else if (old_c != real_c) {
  2351.         old_c = real_c;
  2352.         _statusline(ALREADY_AT_BEGIN);
  2353.         sleep(MessageSecs);
  2354.         }
  2355.         break;
  2356.  
  2357.     case LYK_NEXT_LINK:
  2358.         if (curdoc.link < nlinks-1) {    /* next link */
  2359.         highlight(OFF, curdoc.link, prev_target);
  2360. #ifdef FASTTAB
  2361.         /*
  2362.          *  Move to different textarea if TAB in textarea.
  2363.          */
  2364.         if (links[curdoc.link].type == WWW_FORM_LINK_TYPE &&
  2365.             links[curdoc.link].form->type == F_TEXTAREA_TYPE &&
  2366.             c=='\t') {
  2367.             int thisgroup = links[curdoc.link].form->number;
  2368.             char *thisname = links[curdoc.link].form->name;
  2369.  
  2370.             do curdoc.link++;
  2371.             while ((curdoc.link < nlinks-1) &&
  2372.                links[curdoc.link].type == WWW_FORM_LINK_TYPE &&
  2373.                links[curdoc.link].form->type == F_TEXTAREA_TYPE &&
  2374.                links[curdoc.link].form->number == thisgroup &&
  2375.                sametext(links[curdoc.link].form->name, thisname));
  2376.         } else {
  2377.             curdoc.link++;
  2378.         }
  2379. #else
  2380.         curdoc.link++;
  2381. #endif /* FASTTAB */
  2382.         /*
  2383.          *    At the bottom of list and there is only one page.
  2384.          *    Move to the top link on the page.
  2385.          */
  2386.         } else if (!more && Newline == 1 && curdoc.link == nlinks-1) {
  2387.         highlight(OFF, curdoc.link, prev_target);
  2388.         curdoc.link = 0;
  2389.  
  2390.         } else if (more) {    /* next page */
  2391.          Newline += (display_lines);
  2392.  
  2393.         } else if (old_c != real_c) {
  2394.         old_c = real_c;
  2395.         _statusline(ALREADY_AT_END);
  2396.         sleep(MessageSecs);
  2397.         }
  2398.         break;
  2399.  
  2400.     case LYK_UP_LINK:
  2401.         if (curdoc.link > 0 &&
  2402.         (links[0].ly != links[curdoc.link].ly ||
  2403.          !HText_LinksInLines(HTMainText, 1, Newline - 1))) {
  2404.         /* more links before this on screen, and first of them on
  2405.            a different line or no previous links before this screen? */
  2406.         int newlink = -1;
  2407.         for (i = curdoc.link; i >= 0; i--) {
  2408.             if (links[i].ly < links[curdoc.link].ly) {
  2409.             newlink = i;
  2410.             break;
  2411.             }
  2412.         }
  2413.         if (newlink > -1) {
  2414.             highlight(OFF, curdoc.link, prev_target);
  2415.             curdoc.link = newlink;
  2416. #ifdef NOTDEFINED
  2417.         } else if (!more && Newline == 1 && curdoc.link == 0) {
  2418.             highlight(OFF, curdoc.link, prev_target);
  2419.             curdoc.link = (nlinks-1);
  2420.         } else if (more) {  /* next page */
  2421.             Newline += (display_lines);
  2422. #else
  2423.         } else if (old_c != real_c) {
  2424.             old_c = real_c;
  2425.             _statusline(NO_LINKS_ABOVE);
  2426.             sleep(MessageSecs);
  2427. #endif /* NOTDEFINED */
  2428.         }
  2429.  
  2430. #ifdef NOTDEFINED
  2431.         /*
  2432.          *    At the bottom of list and there is only one page.
  2433.          *    Move to the top link on the page.
  2434.          */
  2435.         } else if (!more && Newline == 1 && curdoc.link == (nlinks-1)) {
  2436.         highlight(OFF, curdoc.link, prev_target);
  2437.         curdoc.link = 0;
  2438. #endif /* NOTDEFINED */
  2439.  
  2440.         } else if (curdoc.line > 1 && Newline > 1) {  /* previous page */
  2441.         int scrollamount = (Newline > display_lines ?
  2442.                           display_lines : Newline - 1);
  2443.         Newline -= scrollamount;
  2444.         if (scrollamount < display_lines &&
  2445.             nlinks > 0 && curdoc.link > -1 &&
  2446.             links[0].ly -1 + scrollamount <= display_lines) {
  2447.             newdoc.link = HText_LinksInLines(HTMainText,
  2448.                              1,
  2449.                              scrollamount) - 1;
  2450.         } else {
  2451.             arrowup = TRUE;
  2452.         }
  2453.  
  2454.         } else if (old_c != real_c) {
  2455.         old_c = real_c;
  2456.         _statusline(ALREADY_AT_BEGIN);
  2457.         sleep(MessageSecs);
  2458.         }
  2459.         break;
  2460.  
  2461.     case LYK_DOWN_LINK:
  2462.         if (curdoc.link < (nlinks-1)) {    /* more links? */
  2463.         int newlink = -1;
  2464.         for (i = curdoc.link; i < nlinks; i++)
  2465.            if (links[i].ly > links[curdoc.link].ly) {
  2466.             newlink = i;
  2467.             break;
  2468.            }
  2469.  
  2470.         if (newlink > -1) {
  2471.             highlight(OFF, curdoc.link, prev_target);
  2472.             curdoc.link = newlink;
  2473. #ifdef NOTDEFINED
  2474.         } else if (!more &&
  2475.                Newline == 1 && curdoc.link == (nlinks-1)) {
  2476.             highlight(OFF, curdoc.link, prev_target);
  2477.             curdoc.link = 0;
  2478. #endif /* NOTDEFINED */
  2479.         } else if (more) {  /* next page */
  2480.             Newline += (display_lines);
  2481.         } else if (old_c != real_c) {
  2482.             old_c = real_c;
  2483.             _statusline(NO_LINKS_BELOW);
  2484.             sleep(MessageSecs);
  2485.             break;
  2486.         }
  2487. #ifdef NOTDEFINED
  2488.         /*
  2489.          *    At the bottom of list and there is only one page.
  2490.          *    Move to the top link on the page.
  2491.          */
  2492.         } else if (!more && Newline == 1 && curdoc.link == (nlinks-1)) {
  2493.         highlight(OFF, curdoc.link, prev_target);
  2494.         curdoc.link = 0;
  2495. #endif /* NOTDEFINED */
  2496.         } else if (more) {    /* next page */
  2497.             Newline += (display_lines);
  2498.  
  2499.         } else if (old_c != real_c) {
  2500.         old_c = real_c;
  2501.         _statusline(ALREADY_AT_END);
  2502.         sleep(MessageSecs);
  2503.         }
  2504.         break;
  2505.  
  2506.     case LYK_RIGHT_LINK:
  2507.         if (curdoc.link<nlinks-1 &&
  2508.             links[curdoc.link].ly == links[curdoc.link+1].ly) {
  2509.         highlight(OFF, curdoc.link, prev_target);
  2510.         curdoc.link++;
  2511.         }
  2512.         break;
  2513.  
  2514.     case LYK_LEFT_LINK:
  2515.         if (curdoc.link>0 &&
  2516.             links[curdoc.link].ly == links[curdoc.link-1].ly) {
  2517.         highlight(OFF, curdoc.link, prev_target);
  2518.         curdoc.link--;
  2519.         }
  2520.         break;
  2521.  
  2522.     case LYK_COOKIE_JAR:       /* show the cookie jar */
  2523.         /*
  2524.          *    Don't do if already viewing the cookie jar.
  2525.          */
  2526.         if (strcmp((curdoc.title ? curdoc.title : ""),
  2527.                COOKIE_JAR_TITLE)) {
  2528.         StrAllocCopy(newdoc.address, "LYNXCOOKIE:/");
  2529.         FREE(newdoc.post_data);
  2530.         FREE(newdoc.post_content_type);
  2531.         FREE(newdoc.bookmark);
  2532.         newdoc.isHEAD = FALSE;
  2533.         newdoc.safe = FALSE;
  2534.         newdoc.internal_link = FALSE;
  2535.         LYforce_no_cache = TRUE;
  2536.         if (LYValidate || check_realm) {
  2537.             LYPermitURL = TRUE;
  2538.         }
  2539.         } else {
  2540.         /*
  2541.          *  If already in the cookie jar, get out.
  2542.          */
  2543.         cmd = LYK_PREV_DOC;
  2544.         goto new_cmd;
  2545.         }
  2546.         break;
  2547.  
  2548.     case LYK_HISTORY:    /* show the history page */
  2549.         if (curdoc.title && strcmp(curdoc.title, HISTORY_PAGE_TITLE)) {
  2550.         /*
  2551.          *  Don't do this if already viewing history page.
  2552.          *
  2553.          *  Push the current file so that the history list
  2554.          *  contains the current file for printing purposes.
  2555.          *  Pop the file afterwards to prevent multiple copies.
  2556.          */
  2557.         if (TRACE && !LYUseTraceLog && LYCursesON) {
  2558.             move(LYlines-1, LYcols-1);    /* make sure cursor is down */
  2559. #ifdef USE_SLANG
  2560.             addstr("\n");
  2561. #endif /* USE_SLANG */
  2562.             refresh();
  2563.         }
  2564.         LYpush(&curdoc, ForcePush);
  2565.  
  2566.         /*
  2567.          *  Print history options to file.
  2568.          */
  2569.         if (showhistory(&newdoc.address) < 0) {
  2570.             LYpop(&curdoc);
  2571.             break;
  2572.         }
  2573.         StrAllocCopy(newdoc.title, HISTORY_PAGE_TITLE);
  2574.         FREE(newdoc.post_data);
  2575.         FREE(newdoc.post_content_type);
  2576.         FREE(newdoc.bookmark);
  2577.         newdoc.isHEAD = FALSE;
  2578.         newdoc.safe = FALSE;
  2579.         newdoc.internal_link = FALSE;
  2580.         FREE(curdoc.address);  /* so it doesn't get pushed */
  2581.  
  2582.         refresh_screen = TRUE;
  2583.         if (LYValidate || check_realm) {
  2584.             LYPermitURL = TRUE;
  2585.         }
  2586.         break;
  2587.         } /* end if strncmp */
  2588.         /*
  2589.          *    Don't put break here so that if the backspace key
  2590.          *    is pressed in the history page, we fall though,
  2591.          *    i.e., it acts like a left arrow.
  2592.          */
  2593.  
  2594.     case LYK_PREV_DOC:             /* back up a level */
  2595.         if (nhist > 0) {  /* if there is anything to go back to */
  2596.         /*
  2597.          *  Check if the previous document is a reply from a POST,
  2598.          *  and if so, seek confirmation of resubmission if the safe
  2599.          *  element is not set and the document is not still in the
  2600.          *  cache or LYresubmit_posts is set. If not confirmed and
  2601.          *  it is not the startfile, pop it so we go to the yet
  2602.          *  previous document, until we're OK or reach the startfile.
  2603.          *  If we reach the startfile and its not OK or we don't get
  2604.          *  confirmation, cancel. - FM
  2605.          */
  2606.         DocAddress WWWDoc;
  2607.         HTParentAnchor *tmpanchor;
  2608.         HText *text;
  2609.         BOOLEAN conf = FALSE, first = TRUE;
  2610.  
  2611.         HTLastConfirmCancelled(); /* reset flag */
  2612.         while (nhist > 0) {
  2613.             conf = FALSE;
  2614.             if (history[(nhist - 1)].post_data == NULL) {
  2615.             break;
  2616.             }
  2617.             WWWDoc.address = history[(nhist - 1)].address;
  2618.             WWWDoc.post_data = history[(nhist - 1)].post_data;
  2619.             WWWDoc.post_content_type =
  2620.                        history[(nhist - 1)].post_content_type;
  2621.             WWWDoc.bookmark = history[(nhist - 1)].bookmark;
  2622.             WWWDoc.isHEAD = history[(nhist - 1)].isHEAD;
  2623.             WWWDoc.safe = history[(nhist - 1)].safe;
  2624.             tmpanchor = HTAnchor_parent(HTAnchor_findAddress(&WWWDoc));
  2625.             if (HTAnchor_safe(tmpanchor)) {
  2626.             break;
  2627.             }
  2628.             if (((text =
  2629.               (HText *)HTAnchor_document(tmpanchor)) == NULL &&
  2630.              (!strncmp(WWWDoc.address, "LYNXIMGMAP:", 11) ||
  2631.              (conf = confirm_post_resub(WWWDoc.address,
  2632.                             history[(nhist - 1)].title,
  2633.                             0, 0))
  2634.               == FALSE)) ||
  2635.             ((LYresubmit_posts && !conf &&
  2636.               (NONINTERNAL_OR_PHYS_DIFFERENT(
  2637.                   (document *)&history[(nhist - 1)],
  2638.                   &curdoc) ||
  2639.                NONINTERNAL_OR_PHYS_DIFFERENT(
  2640.                    (document *)&history[(nhist - 1)],
  2641.                    &newdoc))) &&
  2642.              !confirm_post_resub(WWWDoc.address,
  2643.                          history[(nhist - 1)].title,
  2644.                          2, 2))) {
  2645.             if (HTLastConfirmCancelled()) {
  2646.                 if (!first && curdoc.internal_link)
  2647.                 FREE(curdoc.address);
  2648.                 cmd = LYK_DO_NOTHING;
  2649.                 goto new_cmd;
  2650.             }
  2651.             if (nhist == 1) {
  2652.                 _statusline(CANCELLED);
  2653.                 sleep(InfoSecs);
  2654.                 old_c = 0;
  2655.                 cmd = LYK_DO_NOTHING;
  2656.                 goto new_cmd;
  2657.             } else {
  2658.                 _user_message(WWW_SKIP_MESSAGE, WWWDoc.address);
  2659.                 sleep(MessageSecs);
  2660.                 do {
  2661.                 LYpop(&curdoc);
  2662.                 } while (nhist > 1 && !are_different(
  2663.                 (document *)&history[(nhist - 1)],
  2664.                 &curdoc));
  2665.                 first = FALSE; /* have popped at least one */
  2666.                 continue;
  2667.             }
  2668.             } else {
  2669.             /*
  2670.              *  Break from loop; if user just confirmed to
  2671.              *  load again because document wasn't in cache,
  2672.              *  set LYforce_no_cache to avoid unnecessary
  2673.              *  repeat question down the road. - kw
  2674.              */
  2675.             if (conf)
  2676.                 LYforce_no_cache = TRUE;
  2677.             break;
  2678.             }
  2679.         }
  2680.  
  2681.         if (!first)
  2682.             curdoc.internal_link = FALSE;
  2683.  
  2684.         /*
  2685.          *  Set newdoc.address to empty to pop a file.
  2686.          */
  2687.         FREE(newdoc.address);
  2688. #ifdef DIRED_SUPPORT
  2689.         if (lynx_edit_mode)
  2690.             HTuncache_current_document();
  2691. #endif /* DIRED_SUPPORT */
  2692.         } else if (child_lynx == TRUE) {
  2693.         return(0); /* exit on left arrow in main screen */
  2694.  
  2695.         } else if (old_c != real_c) {
  2696.         old_c = real_c;
  2697.         _statusline(ALREADY_AT_FIRST);
  2698.         sleep(MessageSecs);
  2699.         }
  2700.         break;
  2701.  
  2702.     case LYK_NOCACHE: /* Force submission of form or link with no-cache */
  2703.         if (nlinks > 0) {
  2704.         if (links[curdoc.link].type == WWW_FORM_LINK_TYPE &&
  2705.             links[curdoc.link].form->type != F_SUBMIT_TYPE &&
  2706.             links[curdoc.link].form->type != F_IMAGE_SUBMIT_TYPE) {
  2707.             if (old_c == real_c)
  2708.             break;
  2709.             old_c = real_c;
  2710.             _statusline(NOT_ON_SUBMIT_OR_LINK);
  2711.             sleep(MessageSecs);
  2712.             break;
  2713.         } else {
  2714.             LYforce_no_cache = TRUE;
  2715.             reloading = TRUE;
  2716.         }
  2717.         } /* fall through to LYK_ACTIVATE */
  2718.  
  2719.     case LYK_ACTIVATE:            /* follow a link */
  2720.         {
  2721.          /* Is there a mouse-clicked link waiting? */
  2722.          int mouse_tmp = get_mouse_link();
  2723.          /* If yes, use it as the link */
  2724.          if (mouse_tmp != -1) curdoc.link = mouse_tmp;
  2725.         }
  2726.          if (nlinks > 0) {
  2727.         if (links[curdoc.link].type == WWW_FORM_LINK_TYPE) {
  2728.             /*
  2729.              *    Don't try to submit forms with bad actions. - FM
  2730.              */
  2731.             if (links[curdoc.link].form->type == F_SUBMIT_TYPE ||
  2732.             links[curdoc.link].form->type == F_IMAGE_SUBMIT_TYPE ||
  2733.             links[curdoc.link].form->type ==
  2734.                             F_TEXT_SUBMIT_TYPE) {
  2735.             /*
  2736.              *  Do nothing if it's disabled. - FM
  2737.              */
  2738.             if (links[curdoc.link].form->disabled == YES) {
  2739.                 HTOutputFormat = WWW_PRESENT;
  2740.                 LYforce_no_cache = FALSE;
  2741.                 reloading = FALSE;
  2742.                 break;
  2743.             }
  2744.             /*
  2745.              *  Make sure we have an action. - FM
  2746.              */
  2747.             if (!links[curdoc.link].form->submit_action ||
  2748.                 *links[curdoc.link].form->submit_action
  2749.                                 == '\0') {
  2750.                 _statusline(NO_FORM_ACTION);
  2751.                 sleep(MessageSecs);
  2752.                 HTOutputFormat = WWW_PRESENT;
  2753.                 LYforce_no_cache = FALSE;
  2754.                 reloading = FALSE;
  2755.                 break;
  2756.             }
  2757.             /*
  2758.              *  Check for no_mail if the form action
  2759.              *  is a mailto URL. - FM
  2760.              */
  2761.             if (links[curdoc.link].form->submit_method
  2762.                      == URL_MAIL_METHOD && no_mail) {
  2763.                 HTAlert(FORM_MAILTO_DISALLOWED);
  2764.                 HTOutputFormat = WWW_PRESENT;
  2765.                 LYforce_no_cache = FALSE;
  2766.                 reloading = FALSE;
  2767.                 break;
  2768.             }
  2769.             /*
  2770.              *  Make sure this isn't a spoof in an account
  2771.              *  with restrictions on file URLs. - FM
  2772.              */
  2773.             if (no_file_url &&
  2774.                 !strncasecomp(
  2775.                     links[curdoc.link].form->submit_action,
  2776.                       "file:", 5)) {
  2777.                 HTAlert(FILE_ACTIONS_DISALLOWED);
  2778.                 HTOutputFormat = WWW_PRESENT;
  2779.                 LYforce_no_cache = FALSE;
  2780.                 reloading = FALSE;
  2781.                 break;
  2782.             }
  2783.             /*
  2784.              *  Make sure this isn't a spoof attempt
  2785.              *  via an internal URL. - FM
  2786.              */
  2787.             if (!strncasecomp(
  2788.                     links[curdoc.link].form->submit_action,
  2789.                       "LYNXCOOKIE:", 11) ||
  2790. #ifdef DIRED_SUPPORT
  2791. #ifdef OK_PERMIT
  2792.                 (!(strncasecomp(
  2793.                     links[curdoc.link].form->submit_action,
  2794.                        "LYNXDIRED:", 10)) &&
  2795.                  (no_dired_support ||
  2796.                   strncasecomp(
  2797.                 (links[curdoc.link].form->submit_action + 10),
  2798.                        "//PERMIT_LOCATION", 17) ||
  2799.                   strcmp(curdoc.address, LYPermitFileURL) ||
  2800.                   strcmp((curdoc.title ? curdoc.title : ""),
  2801.                      PERMIT_OPTIONS_TITLE)))  ||
  2802. #else
  2803.                 !strncasecomp(
  2804.                     links[curdoc.link].form->submit_action,
  2805.                       "LYNXDIRED:", 10) ||
  2806. #endif /* OK_PERMIT */
  2807. #endif /* DIRED_SUPPORT */
  2808.                 !strncasecomp(
  2809.                     links[curdoc.link].form->submit_action,
  2810.                       "LYNXDOWNLOAD:", 13) ||
  2811.                 !strncasecomp(
  2812.                     links[curdoc.link].form->submit_action,
  2813.                       "LYNXHIST:", 9) ||
  2814.                 !strncasecomp(
  2815.                     links[curdoc.link].form->submit_action,
  2816.                       "LYNXKEYMAP:", 11) ||
  2817.                 !strncasecomp(
  2818.                     links[curdoc.link].form->submit_action,
  2819.                       "LYNXIMGMAP:", 11) ||
  2820.                 !strncasecomp(
  2821.                     links[curdoc.link].form->submit_action,
  2822.                       "LYNXPRINT:", 10) ||
  2823.                 !strncasecomp(
  2824.                     links[curdoc.link].form->submit_action,
  2825.                       "lynxexec:", 9) ||
  2826.                 !strncasecomp(
  2827.                     links[curdoc.link].form->submit_action,
  2828.                       "lynxprog:", 9)) {
  2829.                 HTAlert(SPECIAL_ACTION_DISALLOWED);
  2830.                 CTRACE(tfp, "LYMainLoop: Rejected '%s'\n",
  2831.                     links[curdoc.link].form->submit_action);
  2832.                 HTOutputFormat = WWW_PRESENT;
  2833.                 LYforce_no_cache = FALSE;
  2834.                 reloading = FALSE;
  2835.                 break;
  2836.             }
  2837. #ifdef NOTDEFINED /* We're disabling form inputs instead of using this. - FM */
  2838.             /*
  2839.              *  Check for enctype and let user know we
  2840.              *  don't yet support multipart/form-data - FM
  2841.              */
  2842.             if (links[curdoc.link].form->submit_enctype) {
  2843.                 if (!strcmp(
  2844.                      links[curdoc.link].form->submit_enctype,
  2845.                     "multipart/form-data")) {
  2846.                 HTAlert(
  2847.     "Enctype multipart/form-data not yet supported!  Cannot submit.");
  2848.                 HTOutputFormat = WWW_PRESENT;
  2849.                 LYforce_no_cache = FALSE;
  2850.                 reloading = FALSE;
  2851.                 break;
  2852.                 }
  2853.             }
  2854. #endif /* NOTDEFINED */
  2855.             if (check_realm) {
  2856.                 LYPermitURL = TRUE;
  2857.             }
  2858.             if (no_filereferer == TRUE &&
  2859.                 !strncmp(curdoc.address, "file:", 5)) {
  2860.                 LYNoRefererForThis = TRUE;
  2861.             }
  2862.             StrAllocCopy(newdoc.title,
  2863.                      links[curdoc.link].hightext);
  2864.             }
  2865.             c = change_form_link(&links[curdoc.link],
  2866.                      FORM_UP, &newdoc, &refresh_screen,
  2867.                      links[curdoc.link].form->name,
  2868.                      links[curdoc.link].form->value);
  2869.             if (HTOutputFormat == HTAtom_for("www/download") &&
  2870.             newdoc.post_data != NULL &&
  2871.             newdoc.safe == FALSE) {
  2872.             if ((HText_POSTReplyLoaded(&newdoc) == TRUE) &&
  2873.                 HTConfirm(CONFIRM_POST_RESUBMISSION) == FALSE) {
  2874.                 _statusline(CANCELLED);
  2875.                 sleep(InfoSecs);
  2876.                 HTOutputFormat = WWW_PRESENT;
  2877.                 LYforce_no_cache = FALSE;
  2878.                 StrAllocCopy(newdoc.address, curdoc.address);
  2879.                 StrAllocCopy(newdoc.title, curdoc.title);
  2880.                 StrAllocCopy(newdoc.post_data, curdoc.post_data);
  2881.                 StrAllocCopy(newdoc.post_content_type,
  2882.                      curdoc.post_content_type);
  2883.                 StrAllocCopy(newdoc.bookmark, curdoc.bookmark);
  2884.                 newdoc.isHEAD = curdoc.isHEAD;
  2885.                 newdoc.safe = curdoc.safe;
  2886.                 newdoc.internal_link = curdoc.internal_link;
  2887.                 break;
  2888.             }
  2889.             }
  2890.             if (c == 23) {
  2891.             c = DO_NOTHING;
  2892.             refresh_screen = TRUE;
  2893.             }
  2894.             goto new_keyboard_input;
  2895.         } else {
  2896.             /*
  2897.              *    Not a forms link.
  2898.              *
  2899.              *    Make sure this isn't a spoof in an account
  2900.              *    with restrictions on file URLs. - FM
  2901.              */
  2902.             if (no_file_url &&
  2903.             !strncmp(links[curdoc.link].lname, "file:", 5)) {
  2904.             if (strncmp(curdoc.address, "file:", 5)) {
  2905.                 HTAlert(FILE_SERVED_LINKS_DISALLOWED);
  2906.                 reloading = FALSE;
  2907.                 break;
  2908.             } else if (curdoc.bookmark != NULL) {
  2909.                 HTAlert(FILE_BOOKMARKS_DISALLOWED);
  2910.                 reloading = FALSE;
  2911.                 break;
  2912.             }
  2913.             }
  2914.             /*
  2915.              *    Make sure this isn't a spoof attempt
  2916.              *    via an internal URL in a non-internal
  2917.              *    document. - FM
  2918.              */
  2919.             if ((!strncmp(links[curdoc.link].lname,
  2920.                   "LYNXCOOKIE:", 11) &&
  2921.              strcmp((curdoc.title ? curdoc.title : ""),
  2922.                 COOKIE_JAR_TITLE)) ||
  2923. #ifdef DIRED_SUPPORT
  2924.             (!strncmp(links[curdoc.link].lname,
  2925.                   "LYNXDIRED:", 10) &&
  2926.              (strcmp(curdoc.address, LYDiredFileURL) ||
  2927.               strcmp((curdoc.title ? curdoc.title : ""),
  2928.                 DIRED_MENU_TITLE)) &&
  2929.              (strcmp(curdoc.address, LYPermitFileURL) ||
  2930.               strcmp((curdoc.title ? curdoc.title : ""),
  2931.                 PERMIT_OPTIONS_TITLE)) &&
  2932.              (strcmp(curdoc.address, LYUploadFileURL) ||
  2933.               strcmp((curdoc.title ? curdoc.title : ""),
  2934.                 UPLOAD_OPTIONS_TITLE))) ||
  2935. #endif /* DIRED_SUPPORT */
  2936.             (!strncmp(links[curdoc.link].lname,
  2937.                  "LYNXDOWNLOAD:", 13) &&
  2938.              strcmp((curdoc.title ? curdoc.title : ""),
  2939.                 DOWNLOAD_OPTIONS_TITLE)) ||
  2940.             (!strncmp(links[curdoc.link].lname,
  2941.                   "LYNXHIST:", 9) &&
  2942.              strcmp((curdoc.title ? curdoc.title : ""),
  2943.                 HISTORY_PAGE_TITLE) &&
  2944.              strcmp(curdoc.address, LYlist_temp_url())) ||
  2945.             (!strncmp(links[curdoc.link].lname,
  2946.                   "LYNXPRINT:", 10) &&
  2947.              strcmp((curdoc.title ? curdoc.title : ""),
  2948.                 PRINT_OPTIONS_TITLE))) {
  2949.                 HTAlert(SPECIAL_VIA_EXTERNAL_DISALLOWED);
  2950.                 HTOutputFormat = WWW_PRESENT;
  2951.                 LYforce_no_cache = FALSE;
  2952.                 reloading = FALSE;
  2953.                 break;
  2954.             }
  2955.             /*
  2956.              *    Follow a normal link or anchor.
  2957.              */
  2958.             StrAllocCopy(newdoc.address, links[curdoc.link].lname);
  2959.             StrAllocCopy(newdoc.title, links[curdoc.link].hightext);
  2960. #ifndef DONT_TRACK_INTERNAL_LINKS
  2961.         /*
  2962.          *  For internal links, retain POST content if present.
  2963.          *  If we are on the List Page, prevent pushing it on
  2964.          *  the history stack.    Otherwise set try_internal to
  2965.          *  signal that the top of the loop should attempt to
  2966.          *  reposition directly, without calling getfile. - kw
  2967.          */
  2968.             /*
  2969.              *    Might be an internal link anchor in the same doc.
  2970.              *    If so, take the try_internal shortcut if we didn't
  2971.              *    fall through from LYK_NOCACHE. - kw
  2972.              */
  2973.             newdoc.internal_link =
  2974.             (links[curdoc.link].type == WWW_INTERN_LINK_TYPE);
  2975.             if (newdoc.internal_link) {
  2976.             /*
  2977.              *  Special case of List Page document with an
  2978.              *  internal link indication, which may really stand
  2979.              *  for an internal link within the document the
  2980.              *  List Page is about. - kw
  2981.              */
  2982.             if (0==strcmp(curdoc.address, LYlist_temp_url()) &&
  2983.                 0==strcmp((curdoc.title ? curdoc.title : ""),
  2984.                       LIST_PAGE_TITLE)) {
  2985.                 if (!curdoc.post_data ||
  2986.                 /*
  2987.                  *  Normal case - List Page is not associated
  2988.                  *  with post data. - kw
  2989.                  */
  2990.                 (!LYresubmit_posts && curdoc.post_data &&
  2991.                 history[nhist - 1].post_data &&
  2992.                 !strcmp(curdoc.post_data,
  2993.                      history[nhist - 1].post_data) &&
  2994.                 HText_getContentBase() &&
  2995.                 !strncmp(HText_getContentBase(),
  2996.                      strncmp(history[nhist - 1].address,
  2997.                          "LYNXIMGMAP:", 11) ?
  2998.                      history[nhist - 1].address :
  2999.                      history[nhist - 1].address + 11,
  3000.                      strlen(HText_getContentBase())))) {
  3001.                 /*
  3002.                  *  Normal case - as best as we can check, the
  3003.                  *  document at the top of the history stack
  3004.                  *  seems to be the document the List Page is
  3005.                  *  about (or a LYNXIMGMAP derived from it),
  3006.                  *  and LYresubmit_posts is not set, so don't
  3007.                  *  prompt here.  If we actually have to repeat
  3008.                  *  a POST because, against expectations, the
  3009.                  *  underlying document isn't cached any more,
  3010.                  *  HTAccess will prompt for confirmation,
  3011.                  *  unless we had LYK_NOCACHE. - kw
  3012.                  */
  3013.                 LYinternal_flag = TRUE;
  3014.                 } else {
  3015.                 HTLastConfirmCancelled(); /* reset flag */
  3016.                 if (!confirm_post_resub(newdoc.address,
  3017.                             newdoc.title,
  3018.                         (LYresubmit_posts &&
  3019.                        HText_POSTReplyLoaded(&newdoc)) ? 1 : 2,
  3020.                             2)) {
  3021.                     if (HTLastConfirmCancelled() ||
  3022.                     (LYresubmit_posts &&
  3023.                      cmd != LYK_NOCACHE &&
  3024.                      !HText_POSTReplyLoaded(&newdoc))) {
  3025.                     /* cancel the whole thing */
  3026.                     LYforce_no_cache = FALSE;
  3027.                     reloading = FALSE;
  3028.                     StrAllocCopy(newdoc.address, curdoc.address);
  3029.                     StrAllocCopy(newdoc.title, curdoc.title);
  3030.                     newdoc.internal_link = curdoc.internal_link;
  3031.                     _statusline(CANCELLED);
  3032.                     sleep(InfoSecs);
  3033.                     break;
  3034.                     } else if (LYresubmit_posts &&
  3035.                            cmd != LYK_NOCACHE) {
  3036.                     /* If LYresubmit_posts is set, and the
  3037.                        answer was No, and the key wasn't
  3038.                        NOCACHE, and we have a cached copy,
  3039.                        then use it. - kw */
  3040.                     LYforce_no_cache = FALSE;
  3041.                     } else {
  3042.                     /* if No, but not ^C or ^G, drop
  3043.                      * the post data.  Maybe the link
  3044.                      * wasn't meant to be internal after
  3045.                      * all, here we can recover from that
  3046.                      * assumption. - kw */
  3047.                     FREE(newdoc.post_data);
  3048.                     FREE(newdoc.post_content_type);
  3049.                     newdoc.internal_link = FALSE;
  3050.                     _statusline(DISCARDING_POST_DATA);
  3051.                     sleep(AlertSecs);
  3052.                     }
  3053.                 }
  3054.                 }
  3055.                 /*
  3056.                  *    Don't push the List Page if we follow an
  3057.                  *    internal link given by it. - kw
  3058.                  */
  3059.                 FREE(curdoc.address);
  3060.             } else if (cmd != LYK_NOCACHE) {
  3061.                 try_internal = TRUE;
  3062.             }
  3063.             if (!(LYresubmit_posts && newdoc.post_data))
  3064.                 LYinternal_flag = TRUE;
  3065.             /* We still set force_load so that history pushing
  3066.             ** etc. will be done.  - kw */
  3067.             force_load = TRUE;
  3068.             break;
  3069.             } else {
  3070.             /*
  3071.              *  Free POST content if not an internal link. - kw
  3072.              */
  3073.             FREE(newdoc.post_data);
  3074.             FREE(newdoc.post_content_type);
  3075.             }
  3076. #endif /* TRACK_INTERNAL_LINKS */
  3077.             /*
  3078.              *    Might be an anchor in the same doc from a POST
  3079.              *    form.  If so, dont't free the content. -- FM
  3080.              */
  3081.             if (are_different(&curdoc, &newdoc)) {
  3082.             FREE(newdoc.post_data);
  3083.             FREE(newdoc.post_content_type);
  3084.             FREE(newdoc.bookmark);
  3085.             }
  3086.             if (!no_jump && lynxjumpfile && curdoc.address &&
  3087.             !strcmp(lynxjumpfile, curdoc.address)) {
  3088.             LYJumpFileURL = TRUE;
  3089.             LYUserSpecifiedURL = TRUE;
  3090.             } else if ((curdoc.title &&
  3091.                    !strcmp(curdoc.title, HISTORY_PAGE_TITLE)) ||
  3092.                    curdoc.bookmark != NULL ||
  3093.                    (lynxjumpfile &&
  3094.                 !strcmp(lynxjumpfile, curdoc.address))) {
  3095.             LYUserSpecifiedURL = TRUE;
  3096.             } else if (no_filereferer == TRUE &&
  3097.                    !strncmp(curdoc.address, "file:", 5)) {
  3098.             LYNoRefererForThis = TRUE;
  3099.             }
  3100.             newdoc.link = 0;
  3101.             force_load = TRUE;    /* force MainLoop to reload */
  3102. #ifdef DIRED_SUPPORT
  3103.             if (lynx_edit_mode) {
  3104.               HTuncache_current_document();
  3105.               /*
  3106.                *  Unescaping any slash chars in the URL,
  3107.                *  but avoid double unescaping and too-early
  3108.                *  unescaping of other chars. - KW
  3109.                */
  3110.               HTUnEscapeSome(newdoc.address,"/");
  3111.               strip_trailing_slash(newdoc.address);
  3112.             }
  3113. #endif /* DIRED_SUPPORT */
  3114.             if (!strncmp(curdoc.address, "LYNXCOOKIE:", 11)) {
  3115.             HTuncache_current_document();
  3116.             }
  3117.         }
  3118.         }
  3119.         break;
  3120.  
  3121.     case LYK_ELGOTO:   /* edit URL of current link and go to it  */
  3122.         if (no_goto && !LYValidate) {
  3123.         /*
  3124.          *  Go to not allowed. - FM
  3125.          */
  3126.         if (old_c != real_c) {
  3127.             old_c = real_c;
  3128.             _statusline(GOTO_DISALLOWED);
  3129.             sleep(MessageSecs);
  3130.         }
  3131.         break;
  3132.         }
  3133.         if (!(nlinks > 0 && curdoc.link > -1) ||
  3134.         (links[curdoc.link].type == WWW_FORM_LINK_TYPE &&
  3135.          links[curdoc.link].form->type != F_SUBMIT_TYPE &&
  3136.          links[curdoc.link].form->type != F_IMAGE_SUBMIT_TYPE &&
  3137.          links[curdoc.link].form->type != F_TEXT_SUBMIT_TYPE)) {
  3138.         /*
  3139.          *  No links on page, or not a normal link
  3140.          *  or form submit button. - FM
  3141.          */
  3142.         if (old_c != real_c) {
  3143.             old_c = real_c;
  3144.             _statusline(NOT_ON_SUBMIT_OR_LINK);
  3145.             sleep(MessageSecs);
  3146.         }
  3147.         break;
  3148.         }
  3149.         if ((links[curdoc.link].type == WWW_FORM_LINK_TYPE) &&
  3150.         (!links[curdoc.link].form->submit_action ||
  3151.          *links[curdoc.link].form->submit_action == '\0')) {
  3152.         /*
  3153.          *  Form submit button with no ACTION defined. - FM
  3154.          */
  3155.         if (old_c != real_c) {
  3156.             old_c = real_c;
  3157.             _statusline(NO_FORM_ACTION);
  3158.             sleep(MessageSecs);
  3159.         }
  3160.         break;
  3161.         }
  3162. #ifdef DIRED_SUPPORT
  3163.         if (!strncmp(links[curdoc.link].lname,
  3164.              "LYNXDIRED:", 10) ||
  3165.         !strcmp(curdoc.address, LYDiredFileURL) ||
  3166.         !strcmp((curdoc.title ? curdoc.title : ""),
  3167.             DIRED_MENU_TITLE) ||
  3168.         !strcmp(curdoc.address, LYPermitFileURL) ||
  3169.         !strcmp((curdoc.title ? curdoc.title : ""),
  3170.             PERMIT_OPTIONS_TITLE) ||
  3171.         !strcmp(curdoc.address, LYUploadFileURL) ||
  3172.         !strcmp((curdoc.title ? curdoc.title : ""),
  3173.             UPLOAD_OPTIONS_TITLE)) {
  3174.         /*
  3175.          *  Disallow editing of File Management URLs. - FM
  3176.          */
  3177.         if (old_c != real_c) {
  3178.             old_c = real_c;
  3179.             _statusline(EDIT_FM_MENU_URLS_DISALLOWED);
  3180.             sleep(MessageSecs);
  3181.         }
  3182.         break;
  3183.         }
  3184. #endif /* DIRED_SUPPORT */
  3185.  
  3186.         /*
  3187.          *    Save the current user_input_buffer string,
  3188.          *    and load the current link's address. - FM
  3189.          */
  3190.         StrAllocCopy(temp, user_input_buffer);
  3191.         LYstrncpy(user_input_buffer,
  3192.               ((links[curdoc.link].type == WWW_FORM_LINK_TYPE)
  3193.                         ?
  3194.      links[curdoc.link].form->submit_action : links[curdoc.link].lname),
  3195.               (sizeof(user_input_buffer) - 1));
  3196.  
  3197.         /*
  3198.          *    Offer the current link's URL for editing. - FM
  3199.          */
  3200.         _statusline(EDIT_CURLINK_URL);
  3201.         if (((ch = LYgetstr(user_input_buffer, VISIBLE,
  3202.                 sizeof(user_input_buffer), RECALL)) >= 0) &&
  3203.         user_input_buffer[0] != '\0' &&
  3204.         strcmp(user_input_buffer,
  3205.                ((links[curdoc.link].type == WWW_FORM_LINK_TYPE)
  3206.                 ? links[curdoc.link].form->submit_action
  3207.                 : links[curdoc.link].lname))) {
  3208.         LYTrimHead(user_input_buffer);
  3209.         if (!strncasecomp(user_input_buffer, "lynxexec:", 9) ||
  3210.             !strncasecomp(user_input_buffer, "lynxprog:", 9)) {
  3211.             /*
  3212.              *    The original implementations of these schemes expected
  3213.              *    white space without hex escaping, and did not check
  3214.              *    for hex escaping, so we'll continue to support that,
  3215.              *    until that code is redone in conformance with SGML
  3216.              *    principles.  - FM
  3217.              */
  3218.             HTUnEscapeSome(user_input_buffer, " \r\n\t");
  3219.             convert_to_spaces(user_input_buffer, TRUE);
  3220.         } else {
  3221.             LYRemoveBlanks(user_input_buffer);
  3222.         }
  3223.         if (user_input_buffer[0] != '\0') {
  3224.             goto check_goto_URL;
  3225.         }
  3226.         }
  3227.         /*
  3228.          *    User cancelled via ^G, a full deletion,
  3229.          *    or not modifying the URL. - FM
  3230.          */
  3231.         _statusline(CANCELLED);
  3232.         sleep(InfoSecs);
  3233.         strcpy(user_input_buffer, temp);
  3234.         FREE(temp);
  3235.         break;
  3236.  
  3237.     case LYK_ECGOTO:   /* edit current URL and go to to it    */
  3238.         if (no_goto && !LYValidate) {
  3239.         /*
  3240.          *  Go to not allowed. - FM
  3241.          */
  3242.         if (old_c != real_c) {
  3243.             old_c = real_c;
  3244.             _statusline(GOTO_DISALLOWED);
  3245.             sleep(MessageSecs);
  3246.         }
  3247.         break;
  3248.         }
  3249. #ifdef DIRED_SUPPORT
  3250.         if (!strcmp(curdoc.address, LYDiredFileURL) ||
  3251.         !strcmp((curdoc.title ? curdoc.title : ""),
  3252.             DIRED_MENU_TITLE) ||
  3253.         !strcmp(curdoc.address, LYPermitFileURL) ||
  3254.         !strcmp((curdoc.title ? curdoc.title : ""),
  3255.             PERMIT_OPTIONS_TITLE) ||
  3256.         !strcmp(curdoc.address, LYUploadFileURL) ||
  3257.         !strcmp((curdoc.title ? curdoc.title : ""),
  3258.             UPLOAD_OPTIONS_TITLE)) {
  3259.         /*
  3260.          *  Disallow editing of File Management URLs. - FM
  3261.          */
  3262.         if (old_c != real_c) {
  3263.             old_c = real_c;
  3264.             _statusline(EDIT_FM_MENU_URLS_DISALLOWED);
  3265.             sleep(MessageSecs);
  3266.         }
  3267.         break;
  3268.         }
  3269. #endif /* DIRED_SUPPORT */
  3270.  
  3271.         /*
  3272.          *    Save the current user_input_buffer string,
  3273.          *    and load the current document's address.
  3274.          */
  3275.         StrAllocCopy(temp, user_input_buffer);
  3276.         LYstrncpy(user_input_buffer,
  3277.               curdoc.address,
  3278.               (sizeof(user_input_buffer) - 1));
  3279.  
  3280.         /*
  3281.          *    Warn the user if the current document has POST
  3282.          *    data associated with it. - FM
  3283.          */
  3284.         if (curdoc.post_data)
  3285.         HTAlert(CURRENT_DOC_HAS_POST_DATA);
  3286.  
  3287.         /*
  3288.          *    Offer the current document's URL for editing. - FM
  3289.          */
  3290.         _statusline(EDIT_CURDOC_URL);
  3291.         if (((ch = LYgetstr(user_input_buffer, VISIBLE,
  3292.                 sizeof(user_input_buffer), RECALL)) >= 0) &&
  3293.         user_input_buffer[0] != '\0' &&
  3294.         strcmp(user_input_buffer, curdoc.address)) {
  3295.         LYTrimHead(user_input_buffer);
  3296.         if (!strncasecomp(user_input_buffer, "lynxexec:", 9) ||
  3297.             !strncasecomp(user_input_buffer, "lynxprog:", 9)) {
  3298.             /*
  3299.              *    The original implementations of these schemes expected
  3300.              *    white space without hex escaping, and did not check
  3301.              *    for hex escaping, so we'll continue to support that,
  3302.              *    until that code is redone in conformance with SGML
  3303.              *    principles.  - FM
  3304.              */
  3305.             HTUnEscapeSome(user_input_buffer, " \r\n\t");
  3306.             convert_to_spaces(user_input_buffer, TRUE);
  3307.         } else {
  3308.             LYRemoveBlanks(user_input_buffer);
  3309.         }
  3310.         if (user_input_buffer[0] != '\0') {
  3311.             goto check_goto_URL;
  3312.         }
  3313.         }
  3314.         /*
  3315.          *    User cancelled via ^G, a full deletion,
  3316.          *    or not modifying the URL. - FM
  3317.          */
  3318.         _statusline(CANCELLED);
  3319.         sleep(InfoSecs);
  3320.         strcpy(user_input_buffer, temp);
  3321.         FREE(temp);
  3322.         break;
  3323.  
  3324.     case LYK_GOTO:     /* 'g' to goto a random URL  */
  3325.         if (no_goto && !LYValidate) {
  3326.         if (old_c != real_c) {
  3327.             old_c = real_c;
  3328.             _statusline(GOTO_DISALLOWED);
  3329.             sleep(MessageSecs);
  3330.         }
  3331.         break;
  3332.         }
  3333.  
  3334.         StrAllocCopy(temp, user_input_buffer);
  3335.         if (!goto_buffer)
  3336.         *user_input_buffer = '\0';
  3337.  
  3338.         URLTotal = (Goto_URLs ? HTList_count(Goto_URLs) : 0);
  3339.         if (goto_buffer && *user_input_buffer) {
  3340.         recall = ((URLTotal > 1) ? RECALL : NORECALL);
  3341.         URLNum = 0;
  3342.         FirstURLRecall = FALSE;
  3343.         } else {
  3344.         recall = ((URLTotal >= 1) ? RECALL : NORECALL);
  3345.         URLNum = URLTotal;
  3346.         FirstURLRecall = TRUE;
  3347.         }
  3348.  
  3349.         /*
  3350.          *    Ask the user.
  3351.          */
  3352.         _statusline(URL_TO_OPEN);
  3353.         if ((ch = LYgetstr(user_input_buffer, VISIBLE,
  3354.                    sizeof(user_input_buffer), recall)) < 0 ) {
  3355.         /*
  3356.          *  User cancelled the Goto via ^G.
  3357.          *  Restore user_input_buffer and break. - FM
  3358.          */
  3359.         strcpy(user_input_buffer, temp);
  3360.         FREE(temp);
  3361.         _statusline(CANCELLED);
  3362.         sleep(InfoSecs);
  3363.         break;
  3364.         }
  3365.  
  3366. check_recall:
  3367.         /*
  3368.          *    Get rid of leading spaces (and any other spaces).
  3369.          */
  3370.         LYTrimHead(user_input_buffer);
  3371.         if (!strncasecomp(user_input_buffer, "lynxexec:", 9) ||
  3372.         !strncasecomp(user_input_buffer, "lynxprog:", 9)) {
  3373.         /*
  3374.          *  The original implementations of these schemes expected
  3375.          *  white space without hex escaping, and did not check
  3376.          *  for hex escaping, so we'll continue to support that,
  3377.          *  until that code is redone in conformance with SGML
  3378.          *  principles.  - FM
  3379.          */
  3380.         HTUnEscapeSome(user_input_buffer, " \r\n\t");
  3381.         convert_to_spaces(user_input_buffer, TRUE);
  3382.         } else {
  3383.         LYRemoveBlanks(user_input_buffer);
  3384.         }
  3385.         if (*user_input_buffer == '\0' &&
  3386.         !(recall && (ch == UPARROW || ch == DNARROW))) {
  3387.         strcpy(user_input_buffer, temp);
  3388.         FREE(temp);
  3389.         _statusline(CANCELLED);
  3390.         sleep(InfoSecs);
  3391.         break;
  3392.         }
  3393.         if (recall && ch == UPARROW) {
  3394.         if (FirstURLRecall) {
  3395.             /*
  3396.              *    Use last URL in the list. - FM
  3397.              */
  3398.             FirstURLRecall = FALSE;
  3399.             URLNum = 0;
  3400.         } else {
  3401.             /*
  3402.              *    Go back to the previous URL in the list. - FM
  3403.              */
  3404.             URLNum++;
  3405.         }
  3406.         if (URLNum >= URLTotal)
  3407.             /*
  3408.              *    Roll around to the last URL in the list. - FM
  3409.              */
  3410.             URLNum = 0;
  3411.         if ((cp = (char *)HTList_objectAt(Goto_URLs,
  3412.                           URLNum)) != NULL) {
  3413.             strcpy(user_input_buffer, cp);
  3414.             if (goto_buffer && *temp &&
  3415.             !strcmp(temp, user_input_buffer)) {
  3416.             _statusline(EDIT_CURRENT_GOTO);
  3417.             } else if ((goto_buffer && URLTotal == 2) ||
  3418.                    (!goto_buffer && URLTotal == 1)) {
  3419.             _statusline(EDIT_THE_PREV_GOTO);
  3420.             } else {
  3421.             _statusline(EDIT_A_PREV_GOTO);
  3422.             }
  3423.             if ((ch = LYgetstr(user_input_buffer, VISIBLE,
  3424.                       sizeof(user_input_buffer),
  3425.                       recall)) < 0) {
  3426.             /*
  3427.              *  User cancelled the Goto via ^G.
  3428.              *  Restore user_input_buffer and break. - FM
  3429.              */
  3430.             strcpy(user_input_buffer, temp);
  3431.             FREE(temp);
  3432.             _statusline(CANCELLED);
  3433.             sleep(InfoSecs);
  3434.             break;
  3435.             }
  3436.             goto check_recall;
  3437.         }
  3438.         } else if (recall && ch == DNARROW) {
  3439.         if (FirstURLRecall) {
  3440.             /*
  3441.              *    Use the first URL in the list. - FM
  3442.              */
  3443.             FirstURLRecall = FALSE;
  3444.             URLNum = URLTotal - 1;
  3445.         } else {
  3446.             /*
  3447.              *    Advance to the next URL in the list. - FM
  3448.              */
  3449.             URLNum--;
  3450.         }
  3451.         if (URLNum < 0)
  3452.             /*
  3453.              *    Roll around to the first URL in the list. - FM
  3454.              */
  3455.             URLNum = URLTotal - 1;
  3456.         if ((cp=(char *)HTList_objectAt(Goto_URLs,
  3457.                             URLNum)) != NULL) {
  3458.             strcpy(user_input_buffer, cp);
  3459.             if (goto_buffer && *temp &&
  3460.             !strcmp(temp, user_input_buffer)) {
  3461.             _statusline(EDIT_CURRENT_GOTO);
  3462.             } else if ((goto_buffer && URLTotal == 2) ||
  3463.                    (!goto_buffer && URLTotal == 1)) {
  3464.             _statusline(EDIT_THE_PREV_GOTO);
  3465.             } else {
  3466.             _statusline(EDIT_A_PREV_GOTO);
  3467.             }
  3468.             if ((ch = LYgetstr(user_input_buffer, VISIBLE,
  3469.                        sizeof(user_input_buffer),
  3470.                        recall)) < 0) {
  3471.             /*
  3472.              *  User cancelled the Goto via ^G.
  3473.              *  Restore user_input_buffer and break. - FM
  3474.              */
  3475.             strcpy(user_input_buffer, temp);
  3476.             FREE(temp);
  3477.             _statusline(CANCELLED);
  3478.             sleep(InfoSecs);
  3479.             break;
  3480.             }
  3481.             goto check_recall;
  3482.         }
  3483.         }
  3484.  
  3485. check_goto_URL:
  3486.         /*
  3487.          *    If its not a URL then make it one.
  3488.          */
  3489.         StrAllocCopy(temp, user_input_buffer);
  3490.         LYFillLocalFileURL((char **)&temp, "file://localhost");
  3491.         LYEnsureAbsoluteURL((char **)&temp, "");
  3492.         sprintf(user_input_buffer, "%.*s",
  3493.             (int)(sizeof(user_input_buffer) - 1), temp);
  3494.         FREE(temp);
  3495.         if ((no_file_url || no_goto_file) &&
  3496.         !strncmp(user_input_buffer,"file:",5)) {
  3497.         _statusline(GOTO_FILE_DISALLOWED);
  3498.         sleep(MessageSecs);
  3499.  
  3500.         } else if ((no_shell || no_goto_lynxexec
  3501. #ifdef EXEC_LINKS
  3502.             || local_exec_on_local_files
  3503. #endif /* EXEC_LINKS */
  3504.             ) &&
  3505.                !strncmp(user_input_buffer, "lynxexec:",9)) {
  3506.         _statusline(GOTO_EXEC_DISALLOWED);
  3507.         sleep(MessageSecs);
  3508.  
  3509.         } else if ((no_shell || no_goto_lynxprog
  3510. #ifdef EXEC_LINKS
  3511.             || local_exec_on_local_files
  3512. #endif /* EXEC_LINKS */
  3513.             ) &&
  3514.                !strncmp(user_input_buffer, "lynxprog:",9)) {
  3515.         _statusline(GOTO_PROG_DISALLOWED);
  3516.         sleep(MessageSecs);
  3517.  
  3518.         } else if ((no_shell || no_goto_lynxcgi) &&
  3519.                !strncmp(user_input_buffer, "lynxcgi:", 8)) {
  3520.         _statusline(GOTO_CGI_DISALLOWED);
  3521.         sleep(MessageSecs);
  3522.  
  3523.         } else if (LYValidate &&
  3524.                strncmp(user_input_buffer, "http:", 5) &&
  3525.                strncmp(user_input_buffer, "https:", 6)) {
  3526.         _statusline(GOTO_NON_HTTP_DISALLOWED);
  3527.         sleep(MessageSecs);
  3528.  
  3529.         } else if (no_goto_cso &&
  3530.                !strncmp(user_input_buffer, "cso:", 4)) {
  3531.         _statusline(GOTO_CSO_DISALLOWED);
  3532.         sleep(MessageSecs);
  3533.  
  3534.         } else if (no_goto_finger &&
  3535.                !strncmp(user_input_buffer, "finger:", 7)) {
  3536.         _statusline(GOTO_FINGER_DISALLOWED);
  3537.         sleep(MessageSecs);
  3538.  
  3539.         } else if (no_goto_ftp &&
  3540.                !strncmp(user_input_buffer, "ftp:", 4)) {
  3541.         _statusline(GOTO_FTP_DISALLOWED);
  3542.         sleep(MessageSecs);
  3543.  
  3544.          } else if (no_goto_gopher &&
  3545.                !strncmp(user_input_buffer, "gopher:", 7)) {
  3546.         _statusline(GOTO_GOPHER_DISALLOWED);
  3547.         sleep(MessageSecs);
  3548.  
  3549.         } else if (no_goto_http &&
  3550.                !strncmp(user_input_buffer, "http:", 5)) {
  3551.         _statusline(GOTO_HTTP_DISALLOWED);
  3552.         sleep(MessageSecs);
  3553.  
  3554.         } else if (no_goto_https &&
  3555.                !strncmp(user_input_buffer, "https:", 6)) {
  3556.         _statusline(GOTO_HTTPS_DISALLOWED);
  3557.         sleep(MessageSecs);
  3558.  
  3559.         } else if (no_goto_mailto &&
  3560.                !strncmp(user_input_buffer, "mailto:", 7)) {
  3561.         _statusline(GOTO_MAILTO_DISALLOWED);
  3562.         sleep(MessageSecs);
  3563.  
  3564.         } else if (no_goto_news &&
  3565.                !strncmp(user_input_buffer, "news:", 5)) {
  3566.         _statusline(GOTO_NEWS_DISALLOWED);
  3567.         sleep(MessageSecs);
  3568.  
  3569.         } else if (no_goto_nntp &&
  3570.                !strncmp(user_input_buffer, "nntp:", 5)) {
  3571.         _statusline(GOTO_NNTP_DISALLOWED);
  3572.         sleep(MessageSecs);
  3573.  
  3574.         } else if (no_goto_rlogin &&
  3575.                !strncmp(user_input_buffer, "rlogin:", 7)) {
  3576.         _statusline(GOTO_RLOGIN_DISALLOWED);
  3577.         sleep(MessageSecs);
  3578.  
  3579.         } else if (no_goto_snews &&
  3580.                !strncmp(user_input_buffer, "snews:", 6)) {
  3581.         _statusline(GOTO_SNEWS_DISALLOWED);
  3582.         sleep(MessageSecs);
  3583.  
  3584.         } else if (no_goto_telnet &&
  3585.                !strncmp(user_input_buffer, "telnet:", 7)) {
  3586.         _statusline(GOTO_TELNET_DISALLOWED);
  3587.         sleep(MessageSecs);
  3588.  
  3589.         } else if (no_goto_tn3270 &&
  3590.                !strncmp(user_input_buffer, "tn3270:", 7)) {
  3591.         _statusline(GOTO_TN3270_DISALLOWED);
  3592.         sleep(MessageSecs);
  3593.  
  3594.         } else if (no_goto_wais &&
  3595.                !strncmp(user_input_buffer, "wais:", 5)) {
  3596.         _statusline(GOTO_WAIS_DISALLOWED);
  3597.         sleep(MessageSecs);
  3598.  
  3599.         } else if (!strncmp(user_input_buffer, "LYNXCOOKIE:", 11) ||
  3600.                !strncmp(user_input_buffer, "LYNXDIRED:", 10) ||
  3601.                !strncmp(user_input_buffer, "LYNXDOWNLOAD:", 13) ||
  3602.                !strncmp(user_input_buffer, "LYNXPRINT:", 10)) {
  3603.         _statusline(GOTO_SPECIAL_DISALLOWED);
  3604.         sleep(MessageSecs);
  3605.  
  3606.        } else {
  3607.         StrAllocCopy(newdoc.address, user_input_buffer);
  3608.         newdoc.isHEAD = FALSE;
  3609.         /*
  3610.          *  Might be an anchor in the same doc from a POST
  3611.          *  form.  If so, dont't free the content. -- FM
  3612.          */
  3613.         if (are_different(&curdoc, &newdoc)) {
  3614.             /*
  3615.              *    Make a name for this new URL.
  3616.              */
  3617.             StrAllocCopy(newdoc.title, "A URL specified by the user");
  3618.             FREE(newdoc.post_data);
  3619.             FREE(newdoc.post_content_type);
  3620.             FREE(newdoc.bookmark);
  3621.             newdoc.safe = FALSE;
  3622.             newdoc.internal_link = FALSE;
  3623.             force_load = TRUE;
  3624. #ifdef DIRED_SUPPORT
  3625.             if (lynx_edit_mode)
  3626.             HTuncache_current_document();
  3627. #endif /* DIRED_SUPPORT */
  3628.         }
  3629.         LYUserSpecifiedURL = TRUE;
  3630.         HTAddGotoURL(newdoc.address);
  3631.         }
  3632.         break;
  3633.  
  3634.     case LYK_HELP:            /* show help file */
  3635.         if (!STREQ(curdoc.address, helpfile)) {
  3636.         /*
  3637.          *  Set the filename.
  3638.          */
  3639.         StrAllocCopy(newdoc.address, helpfile);
  3640.         /*
  3641.          *  Make a name for this help file.
  3642.          */
  3643.         StrAllocCopy(newdoc.title, "Help Screen");
  3644.         FREE(newdoc.post_data);
  3645.         FREE(newdoc.post_content_type);
  3646.         FREE(newdoc.bookmark);
  3647.         newdoc.isHEAD = FALSE;
  3648.         newdoc.safe = FALSE;
  3649.         newdoc.internal_link = FALSE;
  3650.         }
  3651.         break;
  3652.  
  3653.     case LYK_INDEX:  /* index file */
  3654.         /*
  3655.          *    Make sure we are not in the index already.
  3656.          */
  3657.         if (!STREQ(curdoc.address, indexfile)) {
  3658.  
  3659.         if (indexfile[0]=='\0') { /* no defined index */
  3660.             if (old_c != real_c)    {
  3661.                 old_c = real_c;
  3662.                 _statusline(NO_INDEX_FILE);
  3663.                 sleep(MessageSecs);
  3664.             }
  3665.  
  3666.         } else {
  3667.             StrAllocCopy(newdoc.address, indexfile);
  3668.             StrAllocCopy(newdoc.title, "System Index"); /* name it */
  3669.             FREE(newdoc.post_data);
  3670.             FREE(newdoc.post_content_type);
  3671.             FREE(newdoc.bookmark);
  3672.             newdoc.isHEAD = FALSE;
  3673.             newdoc.safe = FALSE;
  3674.             newdoc.internal_link = FALSE;
  3675.         } /* end else */
  3676.         }  /* end if */
  3677.         break;
  3678.  
  3679. #ifdef NOT_USED
  3680.     case LYK_FORM_UP:  /* change form */
  3681.         break;       /* not implemented */
  3682.         if (lynx_mode == FORMS_LYNX_MODE) {
  3683.         if (links[curdoc.link].type == WWW_FORM_LINK_TYPE) {
  3684.             c = change_form_link(&links[curdoc.link],
  3685.                      FORM_UP, &newdoc, &refresh_screen,
  3686.                      links[curdoc.link].form->name,
  3687.                      links[curdoc.link].form->value);
  3688.             /*
  3689.              *    Code to handle multiple submit buttons?
  3690.              *    Taken out due to bug it causes.
  3691.             if (links[curdoc.link].form->type == F_SUBMIT_TYPE ||
  3692.             links[curdoc.link].form->type == F_IMAGESUBMIT_TYPE) {
  3693.             curdoc.address = NULL;
  3694.             }
  3695.              */
  3696.             goto new_keyboard_input;
  3697.         } else {
  3698.             _statusline("'X' can only toggle a form link");
  3699.         }
  3700.         } else {
  3701.         _statusline("'X' only toggles in forms mode");
  3702.         }
  3703.         break;
  3704.  
  3705.     case LYK_FORM_DOWN:  /* change form */
  3706.         break;         /* not implemented */
  3707.         if (lynx_mode==FORMS_LYNX_MODE) {
  3708.         if (links[curdoc.link].type == WWW_FORM_LINK_TYPE) {
  3709.             c = change_form_link(&links[curdoc.link],
  3710.                      FORM_DOWN,&newdoc,&refresh_screen,
  3711.                      links[curdoc.link].form->name,
  3712.                      links[curdoc.link].form->value);
  3713.             goto new_keyboard_input;
  3714.         } else {
  3715.             _statusline("'Z' can only toggle a form link");
  3716.         }
  3717.         } else {
  3718.         _statusline("'Z' only toggles in forms mode");
  3719.         }
  3720.         break;
  3721. #endif /* NOT_USED */
  3722.  
  3723.     case LYK_MAIN_MENU:    /* return to main screen */
  3724.         /*
  3725.          *    If its already the homepage then don't reload it.
  3726.          */
  3727.         if (!STREQ(curdoc.address,homepage)) {
  3728.  
  3729.         _statusline(CONFIRM_MAIN_SCREEN);
  3730.         c = LYgetch();
  3731.         if (TOUPPER(c)=='Y') {
  3732.             StrAllocCopy(newdoc.address, homepage);
  3733.             StrAllocCopy(newdoc.title, "Entry into main screen");
  3734.             FREE(newdoc.post_data);
  3735.             FREE(newdoc.post_content_type);
  3736.             FREE(newdoc.bookmark);
  3737.             newdoc.isHEAD = FALSE;
  3738.             newdoc.safe = FALSE;
  3739.             newdoc.internal_link = FALSE;
  3740.             highlight(OFF, curdoc.link, prev_target);
  3741. #ifdef DIRED_SUPPORT
  3742.             if (lynx_edit_mode)
  3743.               HTuncache_current_document();
  3744. #endif /* DIRED_SUPPORT */
  3745.         }
  3746. #ifdef VMS
  3747.         if (HadVMSInterrupt)
  3748.             HadVMSInterrupt = FALSE;
  3749. #endif /* VMS */
  3750.         } else {
  3751.         if (old_c != real_c)    {
  3752.             old_c = real_c;
  3753.             _statusline(IN_MAIN_SCREEN);
  3754.             sleep(MessageSecs);
  3755.         }
  3756.         }
  3757.         break;
  3758.  
  3759.     case LYK_OPTIONS:     /* options screen */
  3760. #ifdef DIRED_SUPPORT
  3761.         c = dir_list_style;
  3762. #endif /* DIRED_SUPPORT */
  3763.         options(); /* do the options stuff */
  3764.  
  3765.         if (keypad_mode_flag != keypad_mode ||
  3766.         (user_mode_flag != user_mode &&
  3767.          (user_mode_flag == NOVICE_MODE ||
  3768.           user_mode == NOVICE_MODE)) ||
  3769.         (((HTfileSortMethod_flag != HTfileSortMethod) ||
  3770. #ifdef DIRED_SUPPORT
  3771.           (c != dir_list_style) ||
  3772. #endif /* DIRED_SUPPORT */
  3773.           (show_dotfiles_flag != show_dotfiles)) &&
  3774.          (!strncmp(curdoc.address, "file:", 5) ||
  3775.           !strncmp(curdoc.address, "ftp:", 4))) ||
  3776.         CurrentCharSet_flag != current_char_set ||
  3777.         CurrentAssumeCharSet_flag != UCLYhndl_for_unspec ||
  3778.         CurrentAssumeLocalCharSet_flag != UCLYhndl_HTFile_for_unspec ||
  3779.         LYRawMode_flag != LYRawMode ||
  3780.         LYSelectPopups_flag != LYSelectPopups ||
  3781.         ((strcmp(CurrentUserAgent, (LYUserAgent ?
  3782.                         LYUserAgent : "")) ||
  3783.           strcmp(CurrentNegoLanguage, (language ?
  3784.                            language : "")) ||
  3785.           strcmp(CurrentNegoCharset, (pref_charset ?
  3786.                           pref_charset : ""))) &&
  3787.          (!strncmp(curdoc.address, "http", 4) ||
  3788.           !strncmp(curdoc.address, "lynxcgi:", 8)))) {
  3789.         /*
  3790.          *  Check if this is a reply from a POST, and if so,
  3791.          *  seek confirmation of reload if the safe element
  3792.          *  is not set. - FM
  3793.          */
  3794.         if ((curdoc.post_data != NULL &&
  3795.              curdoc.safe != TRUE) &&
  3796.             confirm_post_resub(curdoc.address, curdoc.title,
  3797.                        2, 1) == FALSE) {
  3798.             _statusline(WILL_NOT_RELOAD_DOC);
  3799.             sleep(InfoSecs);
  3800.  
  3801.         } else {
  3802.             StrAllocCopy(newdoc.address, curdoc.address);
  3803.             if (((strcmp(CurrentUserAgent, (LYUserAgent ?
  3804.                         LYUserAgent : "")) ||
  3805.               strcmp(CurrentNegoLanguage,
  3806.                  (language ? language : "")) ||
  3807.               strcmp(CurrentNegoCharset,
  3808.                  (pref_charset ? pref_charset : ""))) &&
  3809.              (strncmp(curdoc.address, "http", 4) == 0 ||
  3810.               strncmp(curdoc.address, "lynxcgi:", 8) == 0))) {
  3811.             /*
  3812.              *  An option has changed which may influence
  3813.              *  content negotiation, and the resource is from
  3814.              *  a http or https or lynxcgi URL (the only protocols
  3815.              *  which currently do anything with this information).
  3816.              *  Set reloading = TRUE so that proxy caches will be
  3817.              *  flushed, which is necessary until the time when
  3818.              *  all proxies understand HTTP 1.1 Vary: and all
  3819.              *  Servers properly use it...    Treat like
  3820.              *  case LYK_RELOAD (see comments there). - KW
  3821.              */
  3822.             reloading = TRUE;
  3823.             }
  3824.             if (lynx_mode == FORMS_LYNX_MODE) {
  3825.             _statusline(RELOADING_FORM);
  3826.             sleep(AlertSecs);
  3827.             }
  3828.             if (HTisDocumentSource()) {
  3829.             HTOutputFormat = WWW_SOURCE;
  3830.             }
  3831.             HEAD_request = HTLoadedDocumentIsHEAD();
  3832.             HTuncache_current_document();
  3833. #ifdef NO_ASSUME_SAME_DOC
  3834.             newdoc.line = 1;
  3835.             newdoc.link = 0;
  3836. #else
  3837.             newdoc.line = ((curdoc.line > 0) ?
  3838.                      curdoc.line : 1);
  3839.             newdoc.link = ((curdoc.link > -1) ?
  3840.                       curdoc.link : 0);
  3841. #endif /* NO_ASSUME_SAME_DOC */
  3842.             LYforce_no_cache = TRUE;
  3843.             FREE(curdoc.address); /* So it doesn't get pushed. */
  3844.         }
  3845.         }
  3846.         keypad_mode_flag = keypad_mode;
  3847.         user_mode_flag = user_mode;
  3848.         HTfileSortMethod_flag = HTfileSortMethod;
  3849.         CurrentCharSet_flag = current_char_set;
  3850.         CurrentAssumeCharSet_flag = UCLYhndl_for_unspec;
  3851.         CurrentAssumeLocalCharSet_flag = UCLYhndl_HTFile_for_unspec;
  3852.         show_dotfiles_flag = show_dotfiles;
  3853.         LYRawMode_flag = LYRawMode;
  3854.         LYSelectPopups_flag = LYSelectPopups;
  3855.         StrAllocCopy(CurrentUserAgent, (LYUserAgent ?
  3856.                         LYUserAgent : ""));
  3857.         StrAllocCopy(CurrentNegoLanguage, (language ?
  3858.                            language : ""));
  3859.         StrAllocCopy(CurrentNegoCharset, (pref_charset ?
  3860.                           pref_charset : ""));
  3861.         refresh_screen = TRUE; /* to repaint screen */
  3862.         break;
  3863.  
  3864.     case LYK_INDEX_SEARCH: /* search for a user string */
  3865.         if (is_www_index) {
  3866.         /*
  3867.          *  Perform a database search.
  3868.          *
  3869.          *  do_www_search will try to go out and get the document.
  3870.          *  If it returns TRUE, a new document was returned and is
  3871.          *  named in the newdoc.address.
  3872.          */
  3873.         newdoc.isHEAD = FALSE;
  3874.         newdoc.safe = FALSE;
  3875.         if (do_www_search(&newdoc) == NORMAL) {
  3876.             /*
  3877.              *    Yah, the search succeeded.
  3878.              */
  3879.             if (TRACE && !LYUseTraceLog && LYCursesON) {
  3880.             /*
  3881.              *  Make sure cursor is down.
  3882.              */
  3883.             move(LYlines-1, LYcols-1);
  3884. #ifdef USE_SLANG
  3885.             addstr("\n");
  3886. #endif /* USE_SLANG */
  3887.             refresh();
  3888.             }
  3889.             LYpush(&curdoc, ForcePush);
  3890.             /*
  3891.              *    Make the curdoc.address the newdoc.address so that
  3892.              *    getfile doesn't try to get the newdoc.address.
  3893.              *    Since we have already gotten it.
  3894.              */
  3895.             StrAllocCopy(curdoc.address, newdoc.address);
  3896.             StrAllocCopy(newdoc.post_data, curdoc.post_data);
  3897.             newdoc.internal_link = FALSE;
  3898.             curdoc.line = -1;
  3899.             Newline = 0;
  3900.             refresh_screen = TRUE; /* redisplay it */
  3901.         } else if (use_this_url_instead != NULL) {
  3902.             /*
  3903.              *    Got back a redirecting URL.  Check it out.
  3904.              */
  3905.             _user_message("Using %s", use_this_url_instead);
  3906.             /*
  3907.              *    Make a name for this URL.
  3908.              */
  3909.             StrAllocCopy(newdoc.title,
  3910.                  "A URL specified by redirection");
  3911.             StrAllocCopy(newdoc.address, use_this_url_instead);
  3912.             FREE(newdoc.post_data);
  3913.             FREE(newdoc.post_content_type);
  3914.             FREE(newdoc.bookmark);
  3915.             newdoc.isHEAD = FALSE;
  3916.             newdoc.safe = FALSE;
  3917.             newdoc.internal_link = FALSE;
  3918.             FREE(use_this_url_instead);
  3919.             force_load = TRUE;
  3920.             break;
  3921.         } else {
  3922.             /*
  3923.              *    Yuk, the search failed.  Restore the old file.
  3924.              */
  3925.             StrAllocCopy(newdoc.address, curdoc.address);
  3926.             StrAllocCopy(newdoc.post_data, curdoc.post_data);
  3927.             StrAllocCopy(newdoc.post_content_type,
  3928.                  curdoc.post_content_type);
  3929.             StrAllocCopy(newdoc.bookmark, curdoc.bookmark);
  3930.             newdoc.isHEAD = curdoc.isHEAD;
  3931.             newdoc.safe = curdoc.safe;
  3932.             newdoc.internal_link = curdoc.internal_link;
  3933.         }
  3934.         } else if (old_c != real_c) {
  3935.         old_c = real_c;
  3936.         _statusline(NOT_ISINDEX);
  3937.         sleep(MessageSecs);
  3938.         }
  3939.         break;
  3940.  
  3941.     case LYK_WHEREIS: /* search within the document */
  3942.     case LYK_NEXT:      /* search for the next occurrence in the document */
  3943.         /* user search */
  3944.     {
  3945.         BOOLEAN have_target_onscreen = (*prev_target != '\0' &&
  3946.                         HText_pageHasPrevTarget());
  3947.         BOOL found;
  3948.         int oldcur = curdoc.link; /* temporarily remember */
  3949.         char *remember_old_target = NULL;
  3950.         if (have_target_onscreen)
  3951.         StrAllocCopy(remember_old_target, prev_target);
  3952.         else
  3953.         StrAllocCopy(remember_old_target, "");
  3954.  
  3955.         if (cmd != LYK_NEXT) {
  3956.         /*
  3957.          *  Reset prev_target to force prompting
  3958.          *  for a new search string and to turn
  3959.          *  off highlighting in no search string
  3960.          *  is entered by the user.
  3961.          */
  3962.         *prev_target = '\0';
  3963.         found = textsearch(&curdoc, prev_target, FALSE);
  3964.         } else {
  3965.         /*
  3966.          *  When the third argument is TRUE, the previous
  3967.          *  search string, if any, will be recalled from
  3968.          *  a buffer, loaded into prev_target, and used
  3969.          *  for the search without prompting for a new
  3970.          *  search string.  This allows the LYK_NEXT
  3971.          *  command to repeat a search in a new document,
  3972.          *  after prev_target was reset on fetch of that
  3973.          *  document.
  3974.          */
  3975.         found = textsearch(&curdoc, prev_target, TRUE);
  3976.         }
  3977.  
  3978.         /*
  3979.          *    Force a redraw to ensure highlighting of hits
  3980.          *    even when found on the same page, or clearing
  3981.          *    of highlighting is the default search string
  3982.          *    was erased without replacement. - FM
  3983.          */
  3984.         /*
  3985.         ** Well let's try to avoid it at least in a few cases
  3986.         ** where it is not needed. - kw
  3987.         */
  3988.         if (www_search_result >= 0 && www_search_result != curdoc.line) {
  3989.         refresh_screen = TRUE; /* doesn't really matter */
  3990.         } else if (!found) {
  3991.         refresh_screen = have_target_onscreen;
  3992.         } else if (!have_target_onscreen && found) {
  3993.         refresh_screen = TRUE;
  3994.         } else if (www_search_result == curdoc.line &&
  3995.                curdoc.link == oldcur &&
  3996.                curdoc.link >= 0 && nlinks > 0 &&
  3997.                links[curdoc.link].ly >= (display_lines/3)) {
  3998.         refresh_screen = TRUE;
  3999.         } else if ((case_sensitive && 0!=strcmp(prev_target,
  4000.                             remember_old_target)) ||
  4001.               (!case_sensitive && 0!=strcasecomp8(prev_target,
  4002.                             remember_old_target))) {
  4003.         refresh_screen = TRUE;
  4004.         }
  4005.         FREE(remember_old_target);
  4006.     }
  4007.         break;
  4008.  
  4009.     case LYK_COMMENT:  /* reply by mail */
  4010.         if (!owner_address &&
  4011.         strncasecomp(curdoc.address, "http", 4)) {
  4012.         if (old_c != real_c)    {
  4013.             old_c = real_c;
  4014.             _statusline(NO_OWNER);
  4015.             sleep(MessageSecs);
  4016.         }
  4017.         } else if (no_mail) {
  4018.         if (old_c != real_c) {
  4019.             old_c = real_c;
  4020.             _statusline(MAIL_DISALLOWED);
  4021.             sleep(MessageSecs);
  4022.         }
  4023.         } else {
  4024.         _statusline(CONFIRM_COMMENT);
  4025.         c = LYgetch();
  4026.         if (TOUPPER(c) == 'Y') {
  4027.             if (!owner_address) {
  4028.             /*
  4029.              *  No owner defined, so make a guess and
  4030.              *  and offer it to the user. - FM
  4031.              */
  4032.             char *address = NULL;
  4033.             temp = HTParse(curdoc.address, "", PARSE_PATH);
  4034.  
  4035.             if (temp != NULL) {
  4036.                 HTUnEscape(temp);
  4037.                 if (*temp == '~' && strlen(temp) > 1) {
  4038.                 /*
  4039.                  *  It's a ~user URL so guess user@host. - FM
  4040.                  */
  4041.                 if ((cp = strchr((temp+1), '/')) != NULL)
  4042.                     *cp = '\0';
  4043.                 StrAllocCopy(address, "mailto:");
  4044.                 StrAllocCat(address, (temp+1));
  4045.                 StrAllocCat(address, "@");
  4046.                 }
  4047.                 FREE(temp);
  4048.             }
  4049.             if (address == NULL)
  4050.                 /*
  4051.                  *    Wasn't a ~user URL so guess WebMaster@host. - FM
  4052.                  */
  4053.                 StrAllocCopy(address, "mailto:WebMaster@");
  4054.             temp = HTParse(curdoc.address, "", PARSE_HOST);
  4055.             StrAllocCat(address, temp);
  4056.             FREE(temp);
  4057.             _user_message(NO_OWNER_USE, address);
  4058.             c = LYgetch();
  4059.             if (TOUPPER(c) == 'Y') {
  4060.                 StrAllocCopy(owner_address, address);
  4061.                 FREE(address);
  4062.             } else {
  4063.                 FREE(address);
  4064.                 break;
  4065.             }
  4066.             }
  4067.             if (is_url(owner_address) != MAILTO_URL_TYPE) {
  4068.             /*
  4069.              *  The address is a URL.  Just follow the link.
  4070.              */
  4071.             StrAllocCopy(newdoc.address, owner_address);
  4072.             newdoc.internal_link = FALSE;
  4073.             } else {
  4074.             /*
  4075.              *  The owner_address is a mailto: URL.
  4076.              */
  4077.             cp = HText_getRevTitle();
  4078.             if (strchr(owner_address,':')!=NULL)
  4079.                  /*
  4080.                   *  Send a reply.    The address is after the colon.
  4081.                   */
  4082.                  reply_by_mail(strchr(owner_address,':')+1,
  4083.                        curdoc.address,
  4084.                        (cp ? cp : ""));
  4085.             else
  4086.                 reply_by_mail(owner_address, curdoc.address,
  4087.                       (cp ? cp : ""));
  4088.  
  4089.             refresh_screen = TRUE;    /* to force a showpage */
  4090.            }
  4091.            }
  4092.        }
  4093.        break;
  4094.  
  4095. #ifdef DIRED_SUPPORT
  4096.     case LYK_TAG_LINK:    /* tag or untag the current link */
  4097.         if (lynx_edit_mode && nlinks > 0 && !no_dired_support) {
  4098.         if (!strcmp(links[curdoc.link].hightext, ".."))
  4099.             break;    /* Never tag the parent directory */
  4100.         if (dir_list_style == MIXED_STYLE) {
  4101.             if (!strcmp(links[curdoc.link].hightext, "../"))
  4102.             break;
  4103.         } else if (!strncmp(links[curdoc.link].hightext, "Up to ", 6))
  4104.             break;
  4105.         {
  4106.             /*
  4107.              *    HTList-based management of tag list, see LYLocal.c - KW
  4108.              */
  4109.             HTList * t1 = tagged;
  4110.             char * tagname = NULL;
  4111.             BOOLEAN found = FALSE;
  4112.  
  4113.             while ((tagname = (char *)HTList_nextObject(t1)) != NULL) {
  4114.             if (!strcmp(links[curdoc.link].lname, tagname)) {
  4115.                 found = TRUE;
  4116.                 HTList_removeObject(tagged, tagname);
  4117.                 FREE(tagname);
  4118.                 tagflag(OFF,curdoc.link);
  4119.                 break;
  4120.             }
  4121.             }
  4122.             if (!found) {
  4123.             if (tagged == NULL)
  4124.                 tagged = HTList_new();
  4125.             tagname = NULL;
  4126.             StrAllocCopy(tagname,links[curdoc.link].lname);
  4127.             HTList_addObject(tagged,tagname);
  4128.             tagflag(ON,curdoc.link);
  4129.             }
  4130.         }
  4131.         if (curdoc.link < nlinks-1) {
  4132.             highlight(OFF, curdoc.link, prev_target);
  4133.             curdoc.link++;
  4134.         } else if (!more && Newline == 1 && curdoc.link == nlinks-1) {
  4135.             highlight(OFF, curdoc.link, prev_target);
  4136.             curdoc.link = 0;
  4137.         } else if (more) {  /* next page */
  4138.             Newline += (display_lines);
  4139.         }
  4140.         }
  4141.         break;
  4142.  
  4143.     case LYK_MODIFY:  /* rename a file or directory */
  4144.         if (lynx_edit_mode && nlinks > 0 && !no_dired_support) {
  4145.         int ret;
  4146.  
  4147.         ret = local_modify(&curdoc, &newdoc.address);
  4148.         if (ret == PERMIT_FORM_RESULT) { /* Permit form thrown up */
  4149.             refresh_screen = TRUE;
  4150.         } else if (ret) {
  4151.             HTuncache_current_document();
  4152.             StrAllocCopy(newdoc.address, curdoc.address);
  4153.             FREE(curdoc.address);
  4154.             FREE(newdoc.post_data);
  4155.             FREE(newdoc.post_content_type);
  4156.             FREE(newdoc.bookmark);
  4157.             newdoc.isHEAD = FALSE;
  4158.             newdoc.safe = FALSE;
  4159.             newdoc.internal_link = FALSE;
  4160.             newdoc.line = curdoc.line;
  4161.             newdoc.link = curdoc.link;
  4162.             clear();
  4163.         }
  4164.         }
  4165.         break;
  4166.  
  4167.     case LYK_CREATE:  /* create a new file or directory */
  4168.         if (lynx_edit_mode && !no_dired_support) {
  4169.         if (local_create(&curdoc)) {
  4170.             HTuncache_current_document();
  4171.             StrAllocCopy(newdoc.address, curdoc.address);
  4172.             FREE(curdoc.address);
  4173.             FREE(newdoc.post_data);
  4174.             FREE(newdoc.post_content_type);
  4175.             FREE(newdoc.bookmark);
  4176.             newdoc.isHEAD = FALSE;
  4177.             newdoc.safe = FALSE;
  4178.             newdoc.line = curdoc.line;
  4179.             newdoc.link = curdoc.link > -1 ? curdoc.link : 0;
  4180.             clear();
  4181.         }
  4182.         }
  4183.         break;
  4184. #endif /* DIRED_SUPPORT */
  4185.  
  4186.     case LYK_EDIT:    /* edit */
  4187.         if (no_editor) {
  4188.         if (old_c != real_c)    {
  4189.             old_c = real_c;
  4190.             _statusline(EDIT_DISABLED);
  4191.             sleep(MessageSecs);
  4192.         }
  4193.         break;
  4194.         }
  4195.  
  4196. #ifdef DIRED_SUPPORT
  4197.         /*
  4198.          *    Allow the user to edit the link rather
  4199.          *    than curdoc in edit mode.
  4200.          */
  4201.         if (lynx_edit_mode &&
  4202.         editor && *editor != '\0' && !no_dired_support) {
  4203.         if (nlinks > 0) {
  4204.             cp = links[curdoc.link].lname;
  4205.             if (is_url(cp) == FILE_URL_TYPE) {
  4206.             if (!strncmp(cp, "file://localhost", 16)) {
  4207.                 /*
  4208.                  *    This is the only case that should occur. - kw
  4209.                  */
  4210.                 StrAllocCopy(tp, cp + 16);
  4211.             } else if (!strncmp(cp, "file:", 5)) {
  4212.                 StrAllocCopy(tp, cp + 5);
  4213.             } else {
  4214.                 StrAllocCopy(tp, cp);
  4215.             }
  4216.             HTUnEscape(tp);
  4217.             if (stat(tp, &dir_info) == -1) {
  4218.                 _statusline(NO_STATUS);
  4219.                 sleep(AlertSecs);
  4220.             } else {
  4221.                 if (((dir_info.st_mode) & S_IFMT) == S_IFREG) {
  4222.                 StrAllocCopy(tp, cp);
  4223.                 HTUnEscapeSome(tp, "/");
  4224.                 if (edit_current_file(tp,
  4225.                               curdoc.link, Newline)) {
  4226.                     HTuncache_current_document();
  4227.                     StrAllocCopy(newdoc.address,
  4228.                          curdoc.address);
  4229.                     FREE(curdoc.address);
  4230. #ifdef NO_SEEK_OLD_POSITION
  4231.                     /*
  4232.                      *    Go to top of file.
  4233.                      */
  4234.                     newdoc.line = 1;
  4235.                     newdoc.link = 0;
  4236. #else
  4237.                     /*
  4238.                      *    Seek old position,
  4239.                      *    which probably changed.
  4240.                      */
  4241.                     newdoc.line =
  4242.                     ((curdoc.line > 0) ? curdoc.line : 1);
  4243.                     newdoc.link =
  4244.                     ((curdoc.link > -1) ? curdoc.link : 0);
  4245. #endif /* NO_SEEK_OLD_POSITION */
  4246.                     clear();  /* clear the screen */
  4247.                 }
  4248.                 }
  4249.             }
  4250.             FREE(tp);
  4251.             }
  4252.         }
  4253.         } else
  4254. #endif /* DIRED_SUPPORT */
  4255.         if (editor && *editor != '\0') {
  4256.         if (edit_current_file(newdoc.address, curdoc.link, Newline)) {
  4257.             HTuncache_current_document();
  4258.             LYforce_no_cache = TRUE;  /*force reload of document */
  4259.             FREE(curdoc.address); /* so it doesn't get pushed */
  4260. #ifdef NO_SEEK_OLD_POSITION
  4261.             /*
  4262.              *    Go to top of file.
  4263.              */
  4264.             newdoc.line = 1;
  4265.             newdoc.link = 0;
  4266. #else
  4267.             /*
  4268.              *    Seek old position, which probably changed.
  4269.              */
  4270.             newdoc.line = curdoc.line;
  4271.             newdoc.link = curdoc.link;
  4272. #endif /* NO_SEEK_OLD_POSITION */
  4273.             clear();  /* clear the screen */
  4274.         }
  4275.  
  4276.         } else {
  4277.         if (old_c != real_c) {
  4278.             old_c = real_c;
  4279.             _statusline(NO_EDITOR);
  4280.             sleep(MessageSecs);
  4281.         }
  4282.         }
  4283.         break;
  4284.  
  4285.     case LYK_DEL_BOOKMARK:    /* remove a bookmark file link */
  4286. #ifdef DIRED_SUPPORT
  4287.     case LYK_REMOVE:    /* remove files and directories */
  4288.         c = 'N';
  4289.         if (lynx_edit_mode && nlinks > 0 && !no_dired_support) {
  4290.         local_remove(&curdoc);
  4291.         c = 'Y';
  4292.         } else
  4293. #endif /* DIRED_SUPPORT */
  4294.         if (curdoc.bookmark != NULL) {
  4295.         _statusline(CONFIRM_BOOKMARK_DELETE);
  4296.         c = LYgetch();
  4297.         if (TOUPPER(c) != 'Y')
  4298.             break;
  4299.         remove_bookmark_link(links[curdoc.link].anchor_number-1,
  4300.                      curdoc.bookmark);
  4301.         } else {    /* behave like REFRESH for backward compatibility */
  4302.         refresh_screen = TRUE;
  4303.         if (old_c != real_c) {
  4304.             old_c = real_c;
  4305.             lynx_force_repaint();
  4306.         }
  4307.         break;
  4308.         }
  4309.         if (TOUPPER(c) == 'Y') {
  4310.         HTuncache_current_document();
  4311.         StrAllocCopy(newdoc.address, curdoc.address);
  4312.         FREE(curdoc.address);
  4313.         newdoc.line = curdoc.line;
  4314.         if (curdoc.link == nlinks-1) {
  4315.             /*
  4316.              *    We deleted the last link on the page. - FM
  4317.              */
  4318.             newdoc.link = curdoc.link-1;
  4319.         } else {
  4320.             newdoc.link = curdoc.link;
  4321.         }
  4322.         }
  4323.         break;
  4324.  
  4325. #ifdef DIRED_SUPPORT
  4326.     case LYK_INSTALL:  /* install a file into system area */
  4327.         if (lynx_edit_mode && nlinks > 0 && !no_dired_support)
  4328.         local_install(NULL, links[curdoc.link].lname, &newdoc.address);
  4329.         break;
  4330. #endif /* DIRED_SUPPORT */
  4331.  
  4332.     case LYK_INFO:    /* show document info */
  4333.         /*
  4334.          *    Don't do if already viewing info page.
  4335.          */
  4336.         if (strcmp((curdoc.title ? curdoc.title : ""),
  4337.                SHOWINFO_TITLE)) {
  4338.         if (!showinfo(&curdoc, lines_in_file,
  4339.                   &newdoc, owner_address))
  4340.             break;
  4341.         StrAllocCopy(newdoc.title, SHOWINFO_TITLE);
  4342.         FREE(newdoc.post_data);
  4343.         FREE(newdoc.post_content_type);
  4344.         FREE(newdoc.bookmark);
  4345.         newdoc.isHEAD = FALSE;
  4346.         newdoc.safe = FALSE;
  4347.         newdoc.internal_link = FALSE;
  4348.         LYforce_no_cache = TRUE;
  4349.         if (LYValidate || check_realm)
  4350.             LYPermitURL = TRUE;
  4351.         } else {
  4352.         /*
  4353.          *  If already in info page, get out.
  4354.          */
  4355.         cmd = LYK_PREV_DOC;
  4356.         goto new_cmd;
  4357.         }
  4358.         break;
  4359.  
  4360.     case LYK_PRINT:  /* print the file */
  4361.         if (LYValidate) {
  4362.         if (old_c != real_c)    {
  4363.             old_c = real_c;
  4364.             _statusline(PRINT_DISABLED);
  4365.             sleep(MessageSecs);
  4366.         }
  4367.         break;
  4368.         }
  4369.  
  4370.         /*
  4371.          *    Don't do if already viewing print options page.
  4372.          */
  4373.         if (strcmp((curdoc.title ? curdoc.title : ""),
  4374.                PRINT_OPTIONS_TITLE)) {
  4375.  
  4376.         if (print_options(&newdoc.address, lines_in_file) < 0)
  4377.             break;
  4378.         StrAllocCopy(newdoc.title, PRINT_OPTIONS_TITLE);
  4379.         FREE(newdoc.post_data);
  4380.         FREE(newdoc.post_content_type);
  4381.         FREE(newdoc.bookmark);
  4382.         newdoc.isHEAD = FALSE;
  4383.         newdoc.safe = FALSE;
  4384.         ForcePush = TRUE;
  4385.         if (check_realm)
  4386.             LYPermitURL = TRUE;
  4387.         refresh_screen = TRUE;    /* redisplay */
  4388.         }
  4389.         break;
  4390.  
  4391.     case LYK_LIST:    /* list links in the current document */
  4392.         /*
  4393.          *    Don't do if already viewing list page.
  4394.          */
  4395.         if (!strcmp((curdoc.title ? curdoc.title : ""),
  4396.             LIST_PAGE_TITLE)) {
  4397.         /*
  4398.          *  Already viewing list page, so get out.
  4399.          */
  4400.         cmd = LYK_PREV_DOC;
  4401.         goto new_cmd;
  4402.         }
  4403.  
  4404.         /*
  4405.          *    Print list page to file.
  4406.          */
  4407.         if (showlist(&newdoc, TRUE) < 0)
  4408.         break;
  4409.         StrAllocCopy(newdoc.title, LIST_PAGE_TITLE);
  4410.         /*
  4411.          *    showlist will set newdoc's other fields.  It may leave
  4412.          *    post_data intact so the list can be used to follow
  4413.          *    internal links in the current document even if it is
  4414.          *    a POST response. - kw
  4415.          */
  4416.  
  4417.         refresh_screen = TRUE;  /* redisplay */
  4418.         if (LYValidate || check_realm) {
  4419.         LYPermitURL = TRUE;
  4420.         StrAllocCopy(lynxlistfile, newdoc.address);
  4421.         }
  4422.         break;
  4423.  
  4424.     case LYK_VLINKS:  /* list links visited during the current session */
  4425.         if (!strcmp((curdoc.title ? curdoc.title : ""),
  4426.             VISITED_LINKS_TITLE)) {
  4427.         /*
  4428.          *  Already viewing visited links page, so get out.
  4429.          */
  4430.         cmd = LYK_PREV_DOC;
  4431.         goto new_cmd;
  4432.         }
  4433.  
  4434.         /*
  4435.          *    Print visited links page to file.
  4436.          */
  4437.         if (LYShowVisitedLinks(&newdoc.address) < 0) {
  4438.         _statusline(VISITED_LINKS_EMPTY);
  4439.         sleep(MessageSecs);
  4440.         break;
  4441.         }
  4442.         StrAllocCopy(newdoc.title, VISITED_LINKS_TITLE);
  4443.         FREE(newdoc.post_data);
  4444.         FREE(newdoc.post_content_type);
  4445.         FREE(newdoc.bookmark);
  4446.         newdoc.isHEAD = FALSE;
  4447.         newdoc.safe = FALSE;
  4448.         newdoc.internal_link = FALSE;
  4449.         refresh_screen = TRUE;
  4450.         if (LYValidate || check_realm) {
  4451.         LYPermitURL = TRUE;
  4452.         StrAllocCopy(lynxlinksfile, newdoc.address);
  4453.         }
  4454.         break;
  4455.  
  4456.     case LYK_TOOLBAR:  /* go to Toolbar or Banner in current document */
  4457.         if (!HText_hasToolbar(HTMainText)) {
  4458.         if (old_c != real_c) {
  4459.             old_c = real_c;
  4460.             _statusline(NO_TOOLBAR);
  4461.             sleep(MessageSecs);
  4462.         }
  4463.         } else if (old_c != real_c) {
  4464.         old_c = real_c;
  4465.         if ((cp = strchr(curdoc.address, '#')) != NULL)
  4466.             *cp = '\0';
  4467.         toolbar = (char *)malloc(strlen(curdoc.address) +
  4468.                      strlen(LYToolbarName) + 2);
  4469.         sprintf(toolbar, "%s#%s", curdoc.address, LYToolbarName);
  4470.         if (cp)
  4471.             *cp = '#';
  4472.         StrAllocCopy(newdoc.address, toolbar);
  4473.         FREE(toolbar);
  4474.         try_internal = TRUE;
  4475.         force_load = TRUE;  /* force MainLoop to reload */
  4476.         }
  4477.         break;
  4478.  
  4479. #if defined(DIRED_SUPPORT) || defined(VMS)
  4480.        case LYK_DIRED_MENU:  /* provide full file management menu */
  4481. #ifdef VMS
  4482.         /*
  4483.          *    Check if the CSwing Directory/File Manager is available.
  4484.          *    Will be disabled if LYCSwingPath is NULL, zero-length,
  4485.          *    or "none" (case insensitive), if no_file_url was set via
  4486.          *    the file_url restriction, if no_goto_file was set for
  4487.          *    the anonymous account, or if HTDirAccess was set to
  4488.          *    HT_DIR_FORBID or HT_DIR_SELECTIVE via the -nobrowse
  4489.          *    or -selective switches. - FM
  4490.          */
  4491.         if (!(LYCSwingPath && *LYCSwingPath) ||
  4492.         !strcasecomp(LYCSwingPath, "none") ||
  4493.         no_file_url || no_goto_file ||
  4494.         HTDirAccess == HT_DIR_FORBID ||
  4495.         HTDirAccess == HT_DIR_SELECTIVE) {
  4496.         if (old_c != real_c)    {
  4497.             old_c = real_c;
  4498.             _statusline(DFM_NOT_AVAILABLE);
  4499.             sleep(MessageSecs);
  4500.         }
  4501.         break;
  4502.         }
  4503.  
  4504.         /*
  4505.          *    If we are viewing a local directory listing or a
  4506.          *    local file which is not temporary, invoke CSwing
  4507.          *    with the URL's directory converted to VMS path specs
  4508.          *    and passed as the argument, so we start up CSwing
  4509.          *    positioned on that node of the directory tree.
  4510.          *    Otherwise, pass the current default directory as
  4511.          *    the argument. - FM
  4512.          */
  4513.         if (LYisLocalFile(curdoc.address) &&
  4514.         strncasecomp(curdoc.address,
  4515.                  lynx_temp_space, strlen(lynx_temp_space))) {
  4516.         /*
  4517.          *  We are viewing a local directory or a local file
  4518.          *  which is not temporary. - FM
  4519.          */
  4520.         struct stat stat_info;
  4521.  
  4522.         cp = HTParse(curdoc.address, "", PARSE_PATH|PARSE_PUNCTUATION);
  4523.         HTUnEscape(cp);
  4524.         if (HTStat(cp, &stat_info) == -1) {
  4525.             CTRACE(tfp, "mainloop: Can't stat %s\n", cp);
  4526.             FREE(cp);
  4527.             temp = (char *)calloc(1, (strlen(LYCSwingPath) + 4));
  4528.             if (temp == NULL)
  4529.             outofmem(__FILE__, "mainloop");
  4530.             sprintf(temp, "%s []", LYCSwingPath);
  4531.             refresh_screen = TRUE;  /* redisplay */
  4532.         } else {
  4533.             char *VMSdir = NULL;
  4534.  
  4535.             if (((stat_info.st_mode) & S_IFMT) == S_IFDIR) {
  4536.             /*
  4537.              *  We're viewing a local directory.  Make
  4538.              *  that the CSwing argument. - FM
  4539.              */
  4540.             if (cp[(strlen(cp) - 1)] != '/')
  4541.                 StrAllocCat(cp, "/");
  4542.             StrAllocCopy(VMSdir, HTVMS_name("", cp));
  4543.             FREE(cp);
  4544.             } else {
  4545.             /*
  4546.              *  We're viewing a local file.  Make it's
  4547.              *  directory the CSwing argument. - FM
  4548.              */
  4549.             StrAllocCopy(VMSdir, HTVMS_name("", cp));
  4550.             FREE(cp);
  4551.             if ((cp = strrchr(VMSdir, ']')) != NULL) {
  4552.                 *(cp + 1) = '\0';
  4553.                 cp == NULL;
  4554.             } else if ((cp = strrchr(VMSdir, ':')) != NULL) {
  4555.                 *(cp + 1) = '\0';
  4556.                 cp == NULL;
  4557.             }
  4558.             }
  4559.             temp = (char *)calloc(1,
  4560.                       (strlen(LYCSwingPath) +
  4561.                        strlen(VMSdir) +
  4562.                        2));
  4563.             if (temp == NULL)
  4564.             outofmem(__FILE__, "mainloop");
  4565.             sprintf(temp, "%s %s", LYCSwingPath, VMSdir);
  4566.             FREE(VMSdir);
  4567.             /*
  4568.              *    Uncache the current document in case we
  4569.              *    change, move, or delete it during the
  4570.              *    CSwing session. - FM
  4571.              */
  4572.             HTuncache_current_document();
  4573.             StrAllocCopy(newdoc.address, curdoc.address);
  4574.             StrAllocCopy(newdoc.title,
  4575.                  curdoc.title ? curdoc.title : "");
  4576.             StrAllocCopy(newdoc.bookmark, curdoc.bookmark);
  4577.             FREE(curdoc.address);
  4578.             newdoc.line = curdoc.line;
  4579.             newdoc.link = curdoc.link;
  4580.         }
  4581.         } else {
  4582.         /*
  4583.          *  We're not viewing a local directory or file.
  4584.          *  Pass CSwing the current default directory as
  4585.          *  an argument and don't uncache the current
  4586.          *  document. - FM
  4587.          */
  4588.         temp = (char *)calloc(1, (strlen(LYCSwingPath) + 4));
  4589.         if (temp == NULL)
  4590.             outofmem(__FILE__, "mainloop");
  4591.         sprintf(temp, "%s []", LYCSwingPath);
  4592.         refresh_screen = TRUE;    /* redisplay */
  4593.         }
  4594.         stop_curses();
  4595.         system(temp);
  4596.         start_curses();
  4597.         FREE(temp);
  4598.         break;
  4599. #else
  4600.         /*
  4601.          *    Don't do if not allowed or already viewing the menu.
  4602.          */
  4603.         if (lynx_edit_mode && !no_dired_support &&
  4604.         strcmp(curdoc.address, LYDiredFileURL) &&
  4605.         strcmp((curdoc.title ? curdoc.title : ""),
  4606.                DIRED_MENU_TITLE)) {
  4607.         dired_options(&curdoc,&newdoc.address);
  4608.         refresh_screen = TRUE;    /* redisplay */
  4609.         }
  4610.         break;
  4611. #endif /* VMS */
  4612. #endif /* DIRED_SUPPORT || VMS*/
  4613.  
  4614. #ifdef USE_EXTERNALS
  4615.     case LYK_EXTERN:  /* use external program on url */
  4616.         if  ((nlinks > 0) && (links[curdoc.link].lname != NULL))
  4617.         {
  4618.            run_external(links[curdoc.link].lname);
  4619.            refresh_screen = TRUE;
  4620.         }
  4621.         break;
  4622. #endif /* USE_EXTERNALS */
  4623.  
  4624.     case LYK_ADD_BOOKMARK:    /* add link to bookmark file */
  4625.         if (LYValidate) {
  4626.         if (old_c != real_c)    {
  4627.             old_c = real_c;
  4628.             _statusline(BOOKMARKS_DISABLED);
  4629.             sleep(MessageSecs);
  4630.         }
  4631.         break;
  4632.         }
  4633.  
  4634.         if (strcmp((curdoc.title ? curdoc.title : ""),
  4635.                HISTORY_PAGE_TITLE) &&
  4636.         strcmp((curdoc.title ? curdoc.title : ""),
  4637.                SHOWINFO_TITLE) &&
  4638.         strcmp((curdoc.title ? curdoc.title : ""),
  4639.                PRINT_OPTIONS_TITLE) &&
  4640. #ifdef DIRED_SUPPORT
  4641.         strcmp(curdoc.address, LYDiredFileURL) &&
  4642.         strcmp((curdoc.title ? curdoc.title : ""),
  4643.                DIRED_MENU_TITLE) &&
  4644.         strcmp(curdoc.address, LYPermitFileURL) &&
  4645.         strcmp((curdoc.title ? curdoc.title : ""),
  4646.                PERMIT_OPTIONS_TITLE) &&
  4647.         strcmp(curdoc.address, LYUploadFileURL) &&
  4648.         strcmp((curdoc.title ? curdoc.title : ""),
  4649.                UPLOAD_OPTIONS_TITLE) &&
  4650. #endif /* DIRED_SUPPORT */
  4651.         strcmp((curdoc.title ? curdoc.title : ""),
  4652.                DOWNLOAD_OPTIONS_TITLE) &&
  4653.         strcmp((curdoc.title ? curdoc.title : ""),
  4654.                COOKIE_JAR_TITLE) &&
  4655.         ((nlinks <= 0) ||
  4656.          (links[curdoc.link].lname != NULL &&
  4657.           strncmp(links[curdoc.link].lname,
  4658.              "LYNXHIST:", 9) &&
  4659.           strncmp(links[curdoc.link].lname,
  4660.              "LYNXPRINT:", 10) &&
  4661.           strncmp(links[curdoc.link].lname,
  4662.              "LYNXDIRED:", 10) &&
  4663.           strncmp(links[curdoc.link].lname,
  4664.              "LYNXDOWNLOAD:", 13) &&
  4665.           strncmp(links[curdoc.link].lname,
  4666.              "LYNXCOOKIE:", 11) &&
  4667.           strncmp(links[curdoc.link].lname,
  4668.              "LYNXLIST:", 9)))) {
  4669.         if (nlinks > 0) {
  4670.             if (curdoc.post_data == NULL &&
  4671.             curdoc.bookmark == NULL &&
  4672.             strcmp((curdoc.title ? curdoc.title : ""),
  4673.                    LIST_PAGE_TITLE) &&
  4674.             strcmp((curdoc.title ? curdoc.title : ""),
  4675.                    VISITED_LINKS_TITLE)) {
  4676.             /*
  4677.              *  The document doesn't have POST content,
  4678.              *  and is not a bookmark file, nor is the
  4679.              *  list or visited links page, so we can
  4680.              *  save either that or the link. - FM
  4681.              */
  4682.             _statusline(BOOK_D_L_OR_CANCEL);
  4683.             c = LYgetch();
  4684.             if (TOUPPER(c) == 'D') {
  4685.                 save_bookmark_link(curdoc.address, curdoc.title);
  4686.                 refresh_screen = TRUE; /* MultiBookmark support */
  4687.                 goto check_add_bookmark_to_self;
  4688.             }
  4689.             } else {
  4690.             if (LYMultiBookmarks == FALSE &&
  4691.                 curdoc.bookmark != NULL &&
  4692.                 strstr(curdoc.address,
  4693.                    (*bookmark_page == '.'
  4694.                           ?
  4695.                 (bookmark_page+1) : bookmark_page)) != NULL) {
  4696.                 /*
  4697.                  *    If multiple bookmarks are disabled, offer
  4698.                  *    the L)ink or C)ancel, but with wording
  4699.                  *    which indicates that the link already
  4700.                  *    exists in this bookmark file. - FM
  4701.                  */
  4702.                 _statusline(MULTIBOOKMARKS_SELF);
  4703.             } else if (curdoc.post_data != NULL &&
  4704.                    links[curdoc.link].type == WWW_INTERN_LINK_TYPE) {
  4705.                 /*
  4706.                  *    Internal link, and document has POST content.
  4707.                  */
  4708.                 _statusline(NOBOOK_POST_FORM);
  4709.                 sleep(MessageSecs);
  4710.                 break;
  4711.             } else {
  4712.                 /*
  4713.                  *    Only offer the link in a document with
  4714.                  *    POST content, or if the current document
  4715.                  *    is a bookmark file and multiple bookmarks
  4716.                  *    are enabled. - FM
  4717.                  */
  4718.                 _statusline(BOOK_L_OR_CANCEL);
  4719.             }
  4720.             c = LYgetch();
  4721.             }
  4722.             if (TOUPPER(c) == 'L') {
  4723.             if (curdoc.post_data != NULL &&
  4724.                 links[curdoc.link].type == WWW_INTERN_LINK_TYPE) {
  4725.                 /*
  4726.                  *    Internal link, and document has POST content.
  4727.                  */
  4728.                 _statusline(NOBOOK_POST_FORM);
  4729.                 sleep(MessageSecs);
  4730.                 break;
  4731.             }
  4732.             /*
  4733.              *  User does want to save the link. - FM
  4734.              */
  4735.             if (links[curdoc.link].type != WWW_FORM_LINK_TYPE) {
  4736.                 save_bookmark_link(links[curdoc.link].lname,
  4737.                            links[curdoc.link].hightext);
  4738.                 refresh_screen = TRUE; /* MultiBookmark support */
  4739.             } else {
  4740.                 _statusline(NOBOOK_FORM_FIELD);
  4741.                 sleep(MessageSecs);
  4742.                 break;
  4743.             }
  4744.             } else {
  4745.             break;
  4746.             }
  4747.         } else if (curdoc.post_data != NULL) {
  4748.             /*
  4749.              *    No links, and document has POST content. - FM
  4750.              */
  4751.             _statusline(NOBOOK_POST_FORM);
  4752.             sleep(MessageSecs);
  4753.             break;
  4754.         } else if (curdoc.bookmark != NULL) {
  4755.             /*
  4756.              *    It's a bookmark file from which all
  4757.              *    of the links were deleted. - FM
  4758.              */
  4759.             _statusline(BOOKMARKS_NOLINKS);
  4760.             sleep(MessageSecs);
  4761.             break;
  4762.         } else {
  4763.             _statusline(BOOK_D_OR_CANCEL);
  4764.             c = LYgetch();
  4765.             if (TOUPPER(c) == 'D') {
  4766.             save_bookmark_link(curdoc.address, curdoc.title);
  4767.             refresh_screen = TRUE; /* MultiBookmark support */
  4768.             } else {
  4769.             break;
  4770.             }
  4771.         }
  4772. check_add_bookmark_to_self:
  4773.         if (curdoc.bookmark && BookmarkPage &&
  4774.             !strcmp(curdoc.bookmark, BookmarkPage)) {
  4775.             HTuncache_current_document();
  4776.             StrAllocCopy(newdoc.address, curdoc.address);
  4777.             StrAllocCopy(newdoc.bookmark, curdoc.bookmark);
  4778.             FREE(curdoc.address);
  4779.             newdoc.line = curdoc.line;
  4780.             newdoc.link = curdoc.link;
  4781.             newdoc.internal_link = FALSE;
  4782.         }
  4783.         FREE(temp);
  4784.         } else {
  4785.         if (old_c != real_c)    {
  4786.             old_c = real_c;
  4787.             _statusline(NOBOOK_HSML);
  4788.             sleep(MessageSecs);
  4789.         }
  4790.         }
  4791.         break;
  4792.  
  4793.     case LYK_VIEW_BOOKMARK:   /* v to view home page */
  4794.         if (LYValidate) {
  4795.         if (old_c != real_c)    {
  4796.             old_c = real_c;
  4797.             _statusline(BOOKMARKS_DISABLED);
  4798.             sleep(MessageSecs);
  4799.         }
  4800.         break;
  4801.         }
  4802.  
  4803.         /*
  4804.          *    See if a bookmark exists.
  4805.          *    If it does replace newdoc.address with it's name.
  4806.          */
  4807.         if ((cp = get_bookmark_filename(&newdoc.address)) != NULL) {
  4808.         if (*cp == '\0' || !strcmp(cp, " ") ||
  4809.             !strcmp(curdoc.address, newdoc.address)) {
  4810.             if (LYMultiBookmarks == TRUE)
  4811.             refresh_screen = TRUE;
  4812.             break;
  4813.         }
  4814.         LYforce_no_cache = TRUE;  /*force the document to be reloaded*/
  4815.         StrAllocCopy(newdoc.title, BOOKMARK_TITLE);
  4816.         StrAllocCopy(newdoc.bookmark, BookmarkPage);
  4817.         FREE(newdoc.post_data);
  4818.         FREE(newdoc.post_content_type);
  4819.         newdoc.isHEAD = FALSE;
  4820.         newdoc.safe = FALSE;
  4821.         newdoc.internal_link = FALSE;
  4822.         } else {
  4823.         if (old_c != real_c) {
  4824.             old_c = real_c;
  4825.             LYMBM_statusline(BOOKMARKS_NOT_OPEN);
  4826.             sleep(AlertSecs);
  4827.             if (LYMultiBookmarks == TRUE) {
  4828.             refresh_screen = TRUE;
  4829.             }
  4830.         }
  4831.         }
  4832.         break;
  4833.  
  4834.     case LYK_SHELL:  /* shell escape */
  4835.         if (!no_shell) {
  4836.         stop_curses();
  4837.         printf(SPAWNING_MSG);
  4838.         fflush(stdout);
  4839.         fflush(stderr);
  4840. #ifdef DOSPATH
  4841. #ifdef __DJGPP__
  4842.         __djgpp_set_ctrl_c(0);
  4843.         _go32_want_ctrl_break(1);
  4844. #endif /* __DJGPP__ */
  4845.         if (getenv("SHELL") != NULL) {
  4846.             system(getenv("SHELL"));
  4847.         } else {
  4848.             system(getenv("COMSPEC") == NULL ? "command.com" : getenv("COMSPEC"));
  4849.         }
  4850. #ifdef __DJGPP__
  4851.         __djgpp_set_ctrl_c(1);
  4852.         _go32_want_ctrl_break(0);
  4853. #endif /* __DJGPP__ */
  4854. #else
  4855. #ifdef __EMX__
  4856.         if (getenv("SHELL") != NULL) {
  4857.             system(getenv("SHELL"));
  4858.         } else {
  4859.             system(getenv("COMSPEC") == NULL ? "cmd.exe" : getenv("COMSPEC"));
  4860.         }
  4861. #else
  4862. #ifdef VMS
  4863.         system("");
  4864. #else
  4865.         system("exec $SHELL");
  4866. #endif /* __EMX__ */
  4867. #endif /* VMS */
  4868. #endif /* DOSPATH */
  4869.         start_curses();
  4870.         refresh_screen = TRUE;    /* for an HText_pageDisplay() */
  4871.         } else {
  4872.         if (old_c != real_c)    {
  4873.             old_c = real_c;
  4874.             _statusline(SPAWNING_DISABLED);
  4875.             sleep(MessageSecs);
  4876.         }
  4877.         }
  4878.         break;
  4879.  
  4880.     case LYK_DOWNLOAD:
  4881.         /*
  4882.          *    Don't do if both download and disk_save are restricted.
  4883.          */
  4884.         if (LYValidate ||
  4885.         (no_download && !override_no_download && no_disk_save)) {
  4886.         if (old_c != real_c)    {
  4887.             old_c = real_c;
  4888.             _statusline(DOWNLOAD_DISABLED);
  4889.             sleep(MessageSecs);
  4890.         }
  4891.         break;
  4892.         }
  4893.  
  4894.         /*
  4895.          *    Don't do if already viewing download options page.
  4896.          */
  4897.         if (!strcmp((curdoc.title ? curdoc.title : ""),
  4898.             DOWNLOAD_OPTIONS_TITLE))
  4899.         break;
  4900.  
  4901.         if (nlinks > 0) {
  4902.         if (links[curdoc.link].type == WWW_FORM_LINK_TYPE) {
  4903.             if (links[curdoc.link].form->type == F_SUBMIT_TYPE ||
  4904.             links[curdoc.link].form->type == F_IMAGE_SUBMIT_TYPE) {
  4905.             if (links[curdoc.link].form->submit_method ==
  4906.                  URL_MAIL_METHOD) {
  4907.                 if (old_c != real_c) {
  4908.                 old_c = real_c;
  4909.                 _statusline(NO_DOWNLOAD_MAILTO_ACTION);
  4910.                 sleep(MessageSecs);
  4911.                 }
  4912.                 break;
  4913.             }
  4914.             HTOutputFormat = HTAtom_for("www/download");
  4915.             LYforce_no_cache = TRUE;
  4916.             cmd = LYK_ACTIVATE;
  4917.             goto new_cmd;
  4918.             }
  4919.             if (old_c != real_c) {
  4920.             old_c = real_c;
  4921.             _statusline(NO_DOWNLOAD_INPUT);
  4922.             sleep(MessageSecs);
  4923.             }
  4924.  
  4925.         } else if (!strcmp((curdoc.title ? curdoc.title : ""),
  4926.                    COOKIE_JAR_TITLE)) {
  4927.             if (old_c != real_c)    {
  4928.             old_c = real_c;
  4929.             _statusline(NO_DOWNLOAD_COOKIES);
  4930.             sleep(MessageSecs);
  4931.             }
  4932.  
  4933.         } else if (!strcmp((curdoc.title ? curdoc.title : ""),
  4934.                    PRINT_OPTIONS_TITLE)) {
  4935.             if (old_c != real_c)    {
  4936.             old_c = real_c;
  4937.             _statusline(NO_DOWNLOAD_PRINT_OP);
  4938.             sleep(MessageSecs);
  4939.             }
  4940.  
  4941. #ifdef DIRED_SUPPORT
  4942.         } else if (!strcmp(curdoc.address, LYUploadFileURL) ||
  4943.                !strcmp((curdoc.title ? curdoc.title : ""),
  4944.                    UPLOAD_OPTIONS_TITLE)) {
  4945.             if (old_c != real_c)    {
  4946.             old_c = real_c;
  4947.             _statusline(NO_DOWNLOAD_UPLOAD_OP);
  4948.             sleep(MessageSecs);
  4949.             }
  4950.  
  4951.         } else if (!strcmp(curdoc.address, LYPermitFileURL) ||
  4952.                !strcmp((curdoc.title ? curdoc.title : ""),
  4953.                    PERMIT_OPTIONS_TITLE)) {
  4954.             if (old_c != real_c)    {
  4955.             old_c = real_c;
  4956.             _statusline(NO_DOWNLOAD_PERMIT_OP);
  4957.             sleep(MessageSecs);
  4958.             }
  4959.  
  4960.         } else if (lynx_edit_mode && !no_dired_support) {
  4961.             /*
  4962.              *    Don't bother making a /tmp copy of the local file.
  4963.              */
  4964.             StrAllocCopy(temp, newdoc.address);
  4965.             StrAllocCopy(newdoc.address, links[curdoc.link].lname);
  4966.             if (LYdownload_options(&newdoc.address,
  4967.                        links[curdoc.link].lname) < 0)
  4968.             StrAllocCopy(newdoc.address, temp);
  4969.             else
  4970.             newdoc.internal_link = FALSE;
  4971.             FREE(temp);
  4972. #endif /* DIRED_SUPPORT */
  4973.  
  4974.         } else if (!strcmp((curdoc.title ? curdoc.title : ""),
  4975.                    HISTORY_PAGE_TITLE) &&
  4976.             !strncmp(links[curdoc.link].lname, "LYNXHIST:", 9)) {
  4977.             int number = atoi(links[curdoc.link].lname+9);
  4978.             if ((history[number].post_data != NULL &&
  4979.              history[number].safe != TRUE) &&
  4980.             HTConfirm(CONFIRM_POST_RESUBMISSION) == FALSE) {
  4981.             _statusline(CANCELLED);
  4982.             sleep(InfoSecs);
  4983.             break;
  4984.             }
  4985.             StrAllocCopy(newdoc.address, history[number].address);
  4986.             StrAllocCopy(newdoc.title, links[curdoc.link].hightext);
  4987.             StrAllocCopy(newdoc.bookmark, history[number].bookmark);
  4988.             FREE(newdoc.post_data);
  4989.             FREE(newdoc.post_content_type);
  4990.             if (history[number].post_data)
  4991.             StrAllocCopy(newdoc.post_data,
  4992.                      history[number].post_data);
  4993.             if (history[number].post_content_type)
  4994.             StrAllocCopy(newdoc.post_content_type,
  4995.                      history[number].post_content_type);
  4996.             newdoc.isHEAD = history[number].isHEAD;
  4997.             newdoc.safe = history[number].safe;
  4998.             newdoc.internal_link = FALSE;
  4999.             newdoc.link = 0;
  5000.             HTOutputFormat = HTAtom_for("www/download");
  5001.             LYUserSpecifiedURL = TRUE;
  5002.             /*
  5003.              *    Force the document to be reloaded.
  5004.              */
  5005.             LYforce_no_cache = TRUE;
  5006.  
  5007.         } else if (!strncmp(links[curdoc.link].lname, "data:", 5)) {
  5008.             if (old_c != real_c) {
  5009.             old_c = real_c;
  5010.             HTAlert(UNSUPPORTED_DATA_URL);
  5011.             }
  5012.  
  5013.         } else if (!strncmp(links[curdoc.link].lname,
  5014.                     "LYNXCOOKIE:", 11) ||
  5015.                !strncmp(links[curdoc.link].lname,
  5016.                     "LYNXDIRED:", 10) ||
  5017.                !strncmp(links[curdoc.link].lname,
  5018.                     "LYNXDOWNLOAD:", 13) ||
  5019.                !strncmp(links[curdoc.link].lname,
  5020.                     "LYNXPRINT:", 10) ||
  5021.                !strncmp(links[curdoc.link].lname,
  5022.                     "lynxexec:", 9) ||
  5023.                !strncmp(links[curdoc.link].lname,
  5024.                     "lynxprog:", 9)) {
  5025.             _statusline(NO_DOWNLOAD_SPECIAL);
  5026.             sleep(MessageSecs);
  5027.  
  5028.         } else {   /* Not a forms, options or history link */
  5029.             /*
  5030.              *    Follow a normal link or anchor.  Note that
  5031.              *    if it's an anchor within the same document,
  5032.              *    entire document will be downloaded.
  5033.              */
  5034.             StrAllocCopy(newdoc.address, links[curdoc.link].lname);
  5035.             StrAllocCopy(newdoc.title, links[curdoc.link].hightext);
  5036. #ifndef DONT_TRACK_INTERNAL_LINKS
  5037.             /*
  5038.              *    Might be an internal link in the same doc from a
  5039.              *    POST form.  If so, don't free the content. - kw
  5040.              */
  5041.             if (links[curdoc.link].type != WWW_INTERN_LINK_TYPE)
  5042. #else
  5043.             /*
  5044.              *    Might be an anchor in the same doc from a POST
  5045.              *    form.  If so, don't free the content. -- FM
  5046.              */
  5047.             if (are_different(&curdoc, &newdoc))
  5048. #endif /* TRACK_INTERNAL_LINKS */
  5049.             {
  5050.             FREE(newdoc.post_data);
  5051.             FREE(newdoc.post_content_type);
  5052.             FREE(newdoc.bookmark);
  5053.             newdoc.isHEAD = FALSE;
  5054.             newdoc.safe = FALSE;
  5055.             }
  5056.             newdoc.internal_link = FALSE;
  5057.             newdoc.link = 0;
  5058.             HTOutputFormat = HTAtom_for("www/download");
  5059.             /*
  5060.              *    Force the document to be reloaded.
  5061.              */
  5062.             LYforce_no_cache = TRUE;
  5063.         }
  5064.         } else if (old_c != real_c) {
  5065.         old_c = real_c;
  5066.         _statusline(NO_DOWNLOAD_CHOICE);
  5067.         sleep(MessageSecs);
  5068.         }
  5069.         break;
  5070.  
  5071. #ifdef DIRED_SUPPORT
  5072.       case LYK_UPLOAD:
  5073.         /*
  5074.          *    Don't do if already viewing upload options page.
  5075.          */
  5076.         if (!strcmp(curdoc.address, LYUploadFileURL) ||
  5077.         !strcmp((curdoc.title ? curdoc.title : ""),
  5078.             UPLOAD_OPTIONS_TITLE))
  5079.         break;
  5080.  
  5081.         if (lynx_edit_mode && !no_dired_support) {
  5082.         LYUpload_options((char **)&newdoc.address,
  5083.                  (char *)curdoc.address);
  5084.         StrAllocCopy(newdoc.title, UPLOAD_OPTIONS_TITLE);
  5085.         FREE(newdoc.post_data);
  5086.         FREE(newdoc.post_content_type);
  5087.         FREE(newdoc.bookmark);
  5088.         newdoc.isHEAD = FALSE;
  5089.         newdoc.safe = FALSE;
  5090.         newdoc.internal_link = FALSE;
  5091.         /*
  5092.          *  Uncache the current listing so that it will
  5093.          *  be updated to included the uploaded file if
  5094.          *  placed in the current directory. - FM
  5095.          */
  5096.         HTuncache_current_document();
  5097.          }
  5098.         break;
  5099. #endif /* DIRED_SUPPORT */
  5100.  
  5101.     case LYK_TRACE_TOGGLE:    /*  Toggle TRACE mode. */
  5102.         if (WWW_TraceFlag)
  5103.         WWW_TraceFlag = FALSE;
  5104.         else
  5105.         WWW_TraceFlag = TRUE;
  5106.  
  5107.         _statusline(WWW_TraceFlag ? TRACE_ON : TRACE_OFF);
  5108.         sleep(MessageSecs);
  5109.  
  5110.         if (TRACE && LYUseTraceLog && LYTraceLogFP == NULL) {
  5111.         /*
  5112.          *  We haven't yet started a TRACE log for this
  5113.          *  session.  If we can't open the file with write
  5114.          *  access, turn off TRACE and give up.  Otherwise,
  5115.          *  on VMS we'll close it and delete it and any
  5116.          *  log file from a previous session, so they don't
  5117.          *  accumulate, and then open it again, including
  5118.          *  "shr=get" to overcome open file locking when
  5119.          *  attempting to read the log via the TRACE_LOG
  5120.          *  command. - FM
  5121.          */
  5122.         if ((LYTraceLogFP = LYNewTxtFile(LYTraceLogPath)) == NULL) {
  5123.             TracelogOpenFailed();
  5124.             break;
  5125.         }
  5126. #ifdef VMS
  5127.         LYCloseTracelog();
  5128.         while (remove(LYTraceLogPath) == 0)
  5129.             ;
  5130.         if ((LYTraceLogFP = LYNewTxtFile(LYTraceLogPath)) == NULL) {
  5131.             TracelogOpenFailed();
  5132.             break;
  5133.         }
  5134. #endif /* VMS */
  5135.         fprintf(tfp, "\t\t%s\n\n", LYNX_TRACELOG_TITLE);
  5136.         }
  5137.         break;
  5138.  
  5139.     case LYK_TRACE_LOG:    /*  View TRACE log. */
  5140.         /*
  5141.          *    Check whether we've started a TRACE log
  5142.          *    in this session. - FM
  5143.          */
  5144.         if (LYTraceLogFP == NULL) {
  5145.         _statusline(NO_TRACELOG_STARTED);
  5146.         sleep(MessageSecs);
  5147.         break;
  5148.         }
  5149.  
  5150.         /*
  5151.          *    Don't do if already viewing the TRACE log. - FM
  5152.          */
  5153.         if (!strcmp((curdoc.title ? curdoc.title : ""),
  5154.             LYNX_TRACELOG_TITLE))
  5155.         break;
  5156.  
  5157.         /*
  5158.          *    If TRACE mode is on, turn it off during this fetch of the
  5159.          *    TRACE log, so we don't enter stuff about this fetch, and
  5160.          *    set a flag for turning it back on when we return to this
  5161.          *    loop.  Note that we'll miss any messages about memory
  5162.          *    exhaustion if it should occur.    It seems unlikely that
  5163.          *    anything else bad might happen, but if it does, we'll
  5164.          *    miss messages about that too.  We also fflush(), close,
  5165.          *    and open it again, to make sure all stderr messages thus
  5166.          *    far will be in the log. - FM
  5167.          */
  5168.         if (!LYReopenTracelog(&trace_mode_flag))
  5169.         break;
  5170.  
  5171.         StrAllocCopy(newdoc.address, "file://localhost");
  5172. #ifdef VMS
  5173.         StrAllocCat(newdoc.address, HTVMS_wwwName(LYTraceLogPath));
  5174. #else
  5175.         StrAllocCat(newdoc.address, LYTraceLogPath);
  5176. #endif /* VMS */
  5177.         StrAllocCopy(newdoc.title, LYNX_TRACELOG_TITLE);
  5178.         FREE(newdoc.post_data);
  5179.         FREE(newdoc.post_content_type);
  5180.         FREE(newdoc.bookmark);
  5181.         newdoc.isHEAD = FALSE;
  5182.         newdoc.safe = FALSE;
  5183.         newdoc.internal_link = FALSE;
  5184.         if (LYValidate || check_realm) {
  5185.         LYPermitURL = TRUE;
  5186.         }
  5187.         LYforce_no_cache = TRUE;
  5188.         break;
  5189.  
  5190.     case LYK_IMAGE_TOGGLE:
  5191.         if (clickable_images)
  5192.         clickable_images = FALSE;
  5193.         else
  5194.         clickable_images = TRUE;
  5195.  
  5196.         _statusline(clickable_images ?
  5197.              CLICKABLE_IMAGES_ON : CLICKABLE_IMAGES_OFF);
  5198.         sleep(MessageSecs);
  5199.         cmd = LYK_RELOAD;
  5200.         goto new_cmd;
  5201.         break;
  5202.  
  5203.     case LYK_INLINE_TOGGLE:
  5204.         if (pseudo_inline_alts)
  5205.         pseudo_inline_alts = FALSE;
  5206.         else
  5207.         pseudo_inline_alts = TRUE;
  5208.  
  5209.         _statusline(pseudo_inline_alts ?
  5210.              PSEUDO_INLINE_ALTS_ON : PSEUDO_INLINE_ALTS_OFF);
  5211.         sleep(MessageSecs);
  5212.         cmd = LYK_RELOAD;
  5213.         goto new_cmd;
  5214.         break;
  5215.  
  5216.     case LYK_RAW_TOGGLE:
  5217.         if (LYUseDefaultRawMode)
  5218.         LYUseDefaultRawMode = FALSE;
  5219.         else
  5220.         LYUseDefaultRawMode = TRUE;
  5221.         _statusline(LYRawMode ? RAWMODE_OFF : RAWMODE_ON);
  5222.         HTMLSetCharacterHandling(current_char_set);
  5223.         LYRawMode_flag = LYRawMode;
  5224.         sleep(MessageSecs);
  5225.         cmd = LYK_RELOAD;
  5226.         goto new_cmd;
  5227.         break;
  5228.  
  5229.     case LYK_HEAD:
  5230.         if (nlinks > 0 &&
  5231.         (links[curdoc.link].type != WWW_FORM_LINK_TYPE ||
  5232.          links[curdoc.link].form->type == F_SUBMIT_TYPE ||
  5233.          links[curdoc.link].form->type == F_IMAGE_SUBMIT_TYPE)) {
  5234.         /*
  5235.          *  We have links, and the current link is a
  5236.          *  normal link or a form's submit button. - FM
  5237.          */
  5238.         _statusline(HEAD_D_L_OR_CANCEL);
  5239.         c = LYgetch();
  5240.         if (TOUPPER(c) == 'D') {
  5241.             char *scheme = strncmp(curdoc.address, "LYNXIMGMAP:", 11) ?
  5242.             curdoc.address : curdoc.address + 11;
  5243.             if (LYCanDoHEAD(scheme) != TRUE) {
  5244.             _statusline(DOC_NOT_HTTP_URL);
  5245.             sleep(MessageSecs);
  5246.             } else {
  5247.             /*
  5248.              *  Check if this is a reply from a POST,
  5249.              *  and if so, seek confirmation if the
  5250.              *  safe element is not set. - FM
  5251.              */
  5252.             if ((curdoc.post_data != NULL &&
  5253.                  curdoc.safe != TRUE) &&
  5254.                 HTConfirm(CONFIRM_POST_DOC_HEAD) == FALSE) {
  5255.                 _statusline(CANCELLED);
  5256.                 sleep(InfoSecs);
  5257.                 break;
  5258.             }
  5259.             HEAD_request = TRUE;
  5260.             LYforce_no_cache = TRUE;
  5261.             StrAllocCopy(newdoc.title, curdoc.title);
  5262.             if (HTLoadedDocumentIsHEAD()) {
  5263.                 HTuncache_current_document();
  5264.                 FREE(curdoc.address);
  5265.             } else {
  5266.                 StrAllocCat(newdoc.title, " - HEAD");
  5267.             }
  5268.             }
  5269.             break;
  5270.         } else if (TOUPPER(c) == 'L') {
  5271.             if (links[curdoc.link].type != WWW_FORM_LINK_TYPE &&
  5272.             strncmp(links[curdoc.link].lname, "http", 4) &&
  5273.             strncmp(links[curdoc.link].lname,
  5274.                 "LYNXIMGMAP:http", 15) &&
  5275.             LYCanDoHEAD(links[curdoc.link].lname) != TRUE &&
  5276.             (links[curdoc.link].type != WWW_INTERN_LINK_TYPE ||
  5277.              !curdoc.address ||
  5278.              strncmp(curdoc.address, "http", 4))) {
  5279.             _statusline(LINK_NOT_HTTP_URL);
  5280.             sleep(MessageSecs);
  5281.             } else if (links[curdoc.link].type == WWW_FORM_LINK_TYPE &&
  5282.                    links[curdoc.link].form->disabled) {
  5283.             _statusline(FORM_ACTION_DISABLED);
  5284.             sleep(MessageSecs);
  5285.             } else if (links[curdoc.link].type == WWW_FORM_LINK_TYPE &&
  5286.                    strncmp(links[curdoc.link].form->submit_action,
  5287.                                   "lynxcgi:", 8) &&
  5288.                    strncmp(links[curdoc.link].form->submit_action,
  5289.                                  "http", 4)) {
  5290.             _statusline(FORM_ACTION_NOT_HTTP_URL);
  5291.             sleep(MessageSecs);
  5292.             } else if (links[curdoc.link].type == WWW_FORM_LINK_TYPE &&
  5293.                    links[curdoc.link].form->submit_method ==
  5294.                               URL_POST_METHOD &&
  5295.                    HTConfirm(CONFIRM_POST_LINK_HEAD) == FALSE) {
  5296.             _statusline(CANCELLED);
  5297.             sleep(InfoSecs);
  5298.             } else {
  5299.             HEAD_request = TRUE;
  5300.             LYforce_no_cache = TRUE;
  5301.             cmd = LYK_ACTIVATE;
  5302.             goto new_cmd;
  5303.             }
  5304.             break;
  5305.         }
  5306.         break;
  5307.         } else {
  5308.         /*
  5309.          *  We can offer only this document for a HEAD request.
  5310.          *  Check if this is a reply from a POST, and if so,
  5311.          *  seek confirmation if the safe element is not set. - FM
  5312.          */
  5313.         if ((curdoc.post_data != NULL &&
  5314.              curdoc.safe != TRUE) &&
  5315.             HTConfirm(CONFIRM_POST_DOC_HEAD) == FALSE) {
  5316.             _statusline(CANCELLED);
  5317.             sleep(InfoSecs);
  5318.             break;
  5319.         } else if (nlinks > 0) {
  5320.             /*
  5321.              *    The current link is a non-submittable form
  5322.              *    link, so prompt the user to make it clear
  5323.              *    that the HEAD request would be for the
  5324.              *    current document, not the form link. - FM
  5325.              */
  5326.             _statusline(HEAD_D_OR_CANCEL);
  5327.             c = LYgetch();
  5328.         } else {
  5329.             /*
  5330.              *    No links, so we can just assume that
  5331.              *    the user wants a HEAD request for the
  5332.              *    current document. - FM
  5333.              */
  5334.             c = 'D';
  5335.         }
  5336.         if (TOUPPER(c) == 'D') {
  5337.             char *scheme = strncmp(curdoc.address, "LYNXIMGMAP:", 11) ?
  5338.             curdoc.address : curdoc.address + 11;
  5339.             /*
  5340.              *    The user didn't cancel, so check if
  5341.              *    a HEAD request is appropriate for the
  5342.              *    current document. - FM
  5343.              */
  5344.             if (LYCanDoHEAD(scheme) != TRUE) {
  5345.             _statusline(DOC_NOT_HTTP_URL);
  5346.             sleep(MessageSecs);
  5347.             } else {
  5348.             HEAD_request = TRUE;
  5349.             LYforce_no_cache = TRUE;
  5350.             StrAllocCopy(newdoc.title, curdoc.title);
  5351.             if (HTLoadedDocumentIsHEAD()) {
  5352.                 HTuncache_current_document();
  5353.                 FREE(curdoc.address);
  5354.             } else {
  5355.                 StrAllocCat(newdoc.title, " - HEAD");
  5356.             }
  5357.             }
  5358.         }
  5359.         }
  5360.         break;
  5361.  
  5362.     case LYK_TOGGLE_HELP:
  5363.         if (user_mode == NOVICE_MODE) {
  5364.         toggle_novice_line();
  5365.         noviceline(more);
  5366.         }
  5367.         break;
  5368.  
  5369.     case LYK_KEYMAP:
  5370.         if (old_c != real_c) {
  5371.         old_c = real_c;
  5372.         StrAllocCopy(newdoc.address, "LYNXKEYMAP:");
  5373.         StrAllocCopy(newdoc.title, CURRENT_KEYMAP_TITLE);
  5374.         FREE(newdoc.post_data);
  5375.         FREE(newdoc.post_content_type);
  5376.         FREE(newdoc.bookmark);
  5377.         newdoc.isHEAD = FALSE;
  5378.         newdoc.safe = FALSE;
  5379.         newdoc.internal_link = FALSE;
  5380.         /*
  5381.          *  If vi_keys changed, the keymap did too,
  5382.          *  so force no cache, and reset the flag. - FM
  5383.          */
  5384.         if (vi_keys_flag != vi_keys ||
  5385.             emacs_keys_flag != emacs_keys) {
  5386.             LYforce_no_cache = TRUE;
  5387.             vi_keys_flag = vi_keys;
  5388.             emacs_keys_flag = emacs_keys;
  5389.         }
  5390. #if defined(DIRED_SUPPORT) && defined(OK_OVERRIDE)
  5391.         /*
  5392.          *  Remember whether we are in dired menu
  5393.          *  so we can display the right keymap.
  5394.          */
  5395.         if (!no_dired_support) {
  5396.             prev_lynx_edit_mode = lynx_edit_mode;
  5397.         }
  5398. #endif /* DIRED_SUPPORT && OK_OVERRIDE */
  5399.         LYforce_no_cache = TRUE;
  5400.         }
  5401.         break;
  5402.  
  5403.     case LYK_JUMP:
  5404.         {
  5405.         char *ret;
  5406.  
  5407.         if (no_jump || JThead == NULL) {
  5408.             if (old_c != real_c) {
  5409.             old_c = real_c;
  5410.             if (no_jump)
  5411.                 _statusline(JUMP_DISALLOWED);
  5412.             else
  5413.                 _statusline(NO_JUMPFILE);
  5414.             sleep(MessageSecs);
  5415.             }
  5416.         } else {
  5417.             LYJumpFileURL = TRUE;
  5418.             if ((ret = LYJump(c)) != NULL) {
  5419. #ifdef PERMIT_GOTO_FROM_JUMP
  5420.             if (!strncasecomp(ret, "Go ", 3)) {
  5421.                 LYJumpFileURL = FALSE;
  5422.                 StrAllocCopy(temp, user_input_buffer);
  5423.                 URLTotal = (Goto_URLs ?
  5424.               HTList_count(Goto_URLs) : 0);
  5425.                 recall = ((URLTotal >= 1) ? RECALL : NORECALL);
  5426.                 URLNum = URLTotal;
  5427.                 FirstURLRecall = TRUE;
  5428.                 if (!strcasecomp(ret, "Go :")) {
  5429.                 if (recall) {
  5430.                     ch = UPARROW;
  5431.                     goto check_recall;
  5432.                 }
  5433.                 FREE(temp);
  5434.                 statusline(NO_RANDOM_URLS_YET);
  5435.                 sleep(MessageSecs);
  5436.                 break;
  5437.                 }
  5438.                 ret = HTParse((ret+3), startfile, PARSE_ALL);
  5439.                 strcpy(user_input_buffer, ret);
  5440.                 FREE(ret);
  5441.                 goto check_recall;
  5442.             }
  5443. #endif /* PERMIT_GOTO_FROM_JUMP */
  5444.             ret = HTParse(ret, startfile, PARSE_ALL);
  5445.             LYTrimHead(ret);
  5446.             if (!strncasecomp(ret, "lynxexec:", 9) ||
  5447.                 !strncasecomp(ret, "lynxprog:", 9)) {
  5448.                 /*
  5449.                  *    The original implementations of these schemes
  5450.                  *    expected white space without hex escaping,
  5451.                  *    and did not check for hex escaping, so we'll
  5452.                  *    continue to support that, until that code is
  5453.                  *    redone in conformance with SGML principles.
  5454.                  *    - FM
  5455.                  */
  5456.                 HTUnEscapeSome(ret, " \r\n\t");
  5457.                 convert_to_spaces(ret, TRUE);
  5458.             } else {
  5459.                 LYRemoveBlanks(user_input_buffer);
  5460.             }
  5461.             StrAllocCopy(newdoc.address, ret);
  5462.             StrAllocCopy(lynxjumpfile, ret);
  5463.             FREE(newdoc.post_data);
  5464.             FREE(newdoc.post_content_type);
  5465.             FREE(newdoc.bookmark);
  5466.             newdoc.isHEAD = FALSE;
  5467.             newdoc.safe = FALSE;
  5468.             newdoc.internal_link = FALSE;
  5469.             FREE(ret);
  5470.             LYUserSpecifiedURL = TRUE;
  5471.             } else {
  5472.             LYJumpFileURL = FALSE;
  5473.             }
  5474.         }
  5475.         }
  5476.         break;
  5477.  
  5478.     case LYK_CLEAR_AUTH:
  5479.         if (old_c != real_c) {
  5480.         old_c = real_c;
  5481.         if (HTConfirm(CLEAR_ALL_AUTH_INFO)) {
  5482.             FREE(authentication_info[0]);
  5483.             FREE(authentication_info[1]);
  5484.             FREE(proxyauth_info[0]);
  5485.             FREE(proxyauth_info[1]);
  5486.             HTClearHTTPAuthInfo();
  5487.             HTClearNNTPAuthInfo();
  5488.             HTClearFTPPassword();
  5489.             _statusline(AUTH_INFO_CLEARED);
  5490.         } else {
  5491.             _statusline(CANCELLED);
  5492.         }
  5493.         sleep(MessageSecs);
  5494.         }
  5495.         break;
  5496.  
  5497. #ifdef NOT_USED
  5498.     case LYK_VERSION:
  5499.         if (old_c != real_c) {
  5500.         char version[128];
  5501.         old_c = real_c;
  5502.         sprintf(version, "*** %s Version %s ***",
  5503.                  LYNX_NAME, LYNX_VERSION);
  5504.         statusline(version);
  5505.         sleep(AlertMessage);
  5506.         }
  5507.         break;
  5508. #endif /* NOT_USED */
  5509.  
  5510.     case LYK_DO_NOTHING:    /* pretty self explanatory */
  5511.         break;
  5512.  
  5513.     } /* end of BIG switch */
  5514.     }
  5515. }
  5516.  
  5517. /*
  5518.  *  Ask a post resubmission prompt with some indication of what would
  5519.  *  be resubmitted, useful especially for going backward in history.
  5520.  *  Try to use parts of the address or, if given, the title, depending
  5521.  *  on how much fits on the statusline.
  5522.  *  if_imgmap and if_file indicate how to handle an address that is
  5523.  *  a "LYNXIMGMAP:", or a "file:" URL (presumably the List Page file),
  5524.  *  respectively: 0: auto-deny, 1: auto-confirm, 2: prompt.
  5525.  *  - kw
  5526.  */
  5527.  
  5528. PRIVATE BOOL confirm_post_resub ARGS4(
  5529.     CONST char*,    address,
  5530.     CONST char*,    title,
  5531.     int,        if_imgmap,
  5532.     int,        if_file)
  5533. {
  5534.     size_t len1;
  5535.     CONST char *msg = CONFIRM_POST_RESUBMISSION_TO;
  5536.     char buf[240];
  5537.     char *temp = NULL;
  5538.     BOOL res;
  5539.     size_t maxlen = LYcols - 6;
  5540.     if (!address) {
  5541.     return(NO);
  5542.     } else if (!strncmp(address, "LYNXIMGMAP:", 11)) {
  5543.     if (if_imgmap <= 0)
  5544.         return(NO);
  5545.     else if (if_imgmap == 1)
  5546.         return(YES);
  5547.     else
  5548.         msg = CONFIRM_POST_LIST_RELOAD;
  5549.     } else if (!strncmp(address, "file:", 5)) {
  5550.     if (if_file <= 0)
  5551.         return(NO);
  5552.     else if (if_file == 1)
  5553.         return(YES);
  5554.     else
  5555.         msg = CONFIRM_POST_LIST_RELOAD;
  5556.     } else if (dump_output_immediately) {
  5557.     return(NO);
  5558.     }
  5559.     if (maxlen >= sizeof(buf))
  5560.     maxlen = sizeof(buf) - 1;
  5561.     if ((len1 = strlen(msg)) +
  5562.     strlen(address) <= maxlen) {
  5563.     sprintf(buf, msg, address);
  5564.     return HTConfirm(buf);
  5565.     }
  5566.     if (len1 + strlen(temp = HTParse(address, "",
  5567.                      PARSE_ACCESS+PARSE_HOST+PARSE_PATH
  5568.                      +PARSE_PUNCTUATION)) <= maxlen) {
  5569.     sprintf(buf, msg, temp);
  5570.     res = HTConfirm(buf);
  5571.     FREE(temp);
  5572.     return(res);
  5573.     }
  5574.     FREE(temp);
  5575.     if (title && (len1 + strlen(title) <= maxlen)) {
  5576.     sprintf(buf, msg, title);
  5577.     return HTConfirm(buf);
  5578.     }
  5579.     if (len1 + strlen(temp = HTParse(address, "",
  5580.                      PARSE_ACCESS+PARSE_HOST
  5581.                      +PARSE_PUNCTUATION)) <= maxlen) {
  5582.     sprintf(buf, msg, temp);
  5583.     res = HTConfirm(buf);
  5584.     FREE(temp);
  5585.     return(res);
  5586.     }
  5587.     FREE(temp);
  5588.     if ((temp = HTParse(address, "", PARSE_HOST)) && *temp &&
  5589.     len1 + strlen(temp) <= maxlen) {
  5590.     sprintf(buf, msg, temp);
  5591.     res = HTConfirm(buf);
  5592.     FREE(temp);
  5593.     return(res);
  5594.     }
  5595.     FREE(temp);
  5596.     return HTConfirm(CONFIRM_POST_RESUBMISSION);
  5597. }
  5598.  
  5599. PRIVATE int are_different ARGS2(
  5600.     document *,    doc1,
  5601.     document *,    doc2)
  5602. {
  5603.     char *cp1, *cp2;
  5604.  
  5605.     /*
  5606.      *    Do we have two addresses?
  5607.      */
  5608.     if (!doc1->address || !doc2->address)
  5609.     return (TRUE);
  5610.  
  5611.     /*
  5612.      *    Do they differ in the type of request?
  5613.      */
  5614.     if (doc1->isHEAD != doc2->isHEAD)
  5615.     return (TRUE);
  5616.  
  5617.     /*
  5618.      *    See if the addresses are different, making sure
  5619.      *    we're not tripped up by multiple anchors in the
  5620.      *    the same document from a POST form. -- FM
  5621.      */
  5622.     if ((cp1 = strchr(doc1->address, '#')) != NULL)
  5623.     *cp1 = '\0';
  5624.     if ((cp2 = strchr(doc2->address, '#')) != NULL)
  5625.     *cp2 = '\0';
  5626.     /*
  5627.      *    Are the base addresses different?
  5628.      */
  5629.     if (strcmp(doc1->address, doc2->address))
  5630.       {
  5631.     if (cp1)
  5632.         *cp1 = '#';
  5633.     if (cp2)
  5634.         *cp2 = '#';
  5635.     return(TRUE);
  5636.       }
  5637.     if (cp1)
  5638.     *cp1 = '#';
  5639.     if (cp2)
  5640.     *cp2 = '#';
  5641.  
  5642.     /*
  5643.      *    Do the docs have different contents?
  5644.      */
  5645.     if (doc1->post_data)
  5646.       {
  5647.     if (doc2->post_data)
  5648.       {
  5649.         if (strcmp(doc1->post_data, doc2->post_data))
  5650.         return(TRUE);
  5651.       }
  5652.     else
  5653.         return(TRUE);
  5654.       }
  5655.     else
  5656.     if (doc2->post_data)
  5657.         return(TRUE);
  5658.  
  5659.     /*
  5660.      *    We'll assume the two documents in fact are the same.
  5661.      */
  5662.     return(FALSE);
  5663. }
  5664.  
  5665. /* This determines whether two docs are _physically_ different,
  5666.  * meaning they are "from different files". - kw
  5667.  */
  5668. #ifndef DONT_TRACK_INTERNAL_LINKS
  5669. PRIVATE int are_phys_different ARGS2(
  5670.     document *,    doc1,
  5671.     document *,    doc2)
  5672. {
  5673.     char *cp1, *cp2, *ap1 = doc1->address, *ap2 = doc2->address;
  5674.  
  5675.     /*
  5676.      *    Do we have two addresses?
  5677.      */
  5678.     if (!doc1->address || !doc2->address)
  5679.     return (TRUE);
  5680.  
  5681.     /*
  5682.      *    Do they differ in the type of request?
  5683.      */
  5684.     if (doc1->isHEAD != doc2->isHEAD)
  5685.     return (TRUE);
  5686.  
  5687.     /*
  5688.      * Skip over possible LYNXIMGMAP parts. - kw
  5689.      */
  5690.     if (0==strncmp(doc1->address, "LYNXIMGMAP:", 11))
  5691.     ap1 += 11;
  5692.     if (0==strncmp(doc2->address, "LYNXIMGMAP:", 11))
  5693.     ap2 += 11;
  5694.     /*
  5695.      * If there isn't any real URL in doc2->address, but maybe just
  5696.      * a fragment, doc2 is assumed to be an internal reference in
  5697.      * the same physical document, so return FALSE. - kw
  5698.      */
  5699.     if (*ap2 == '\0' || *ap2 == '#')
  5700.     return(FALSE);
  5701.  
  5702.     /*
  5703.      *    See if the addresses are different, making sure
  5704.      *    we're not tripped up by multiple anchors in the
  5705.      *    the same document from a POST form. -- FM
  5706.      */
  5707.     if ((cp1 = strchr(doc1->address, '#')) != NULL)
  5708.     *cp1 = '\0';
  5709.     if ((cp2 = strchr(doc2->address, '#')) != NULL)
  5710.     *cp2 = '\0';
  5711.     /*
  5712.      *    Are the base addresses different?
  5713.      */
  5714.     if (strcmp(ap1, ap2))
  5715.       {
  5716.     if (cp1)
  5717.         *cp1 = '#';
  5718.     if (cp2)
  5719.         *cp2 = '#';
  5720.     return(TRUE);
  5721.       }
  5722.     if (cp1)
  5723.     *cp1 = '#';
  5724.     if (cp2)
  5725.     *cp2 = '#';
  5726.  
  5727.     /*
  5728.      *    Do the docs have different contents?
  5729.      */
  5730.     if (doc1->post_data)
  5731.       {
  5732.     if (doc2->post_data)
  5733.       {
  5734.         if (strcmp(doc1->post_data, doc2->post_data))
  5735.         return(TRUE);
  5736.       }
  5737.     else
  5738.         return(TRUE);
  5739.       }
  5740.     else
  5741.     if (doc2->post_data)
  5742.         return(TRUE);
  5743.  
  5744.     /*
  5745.      *    We'll assume the two documents in fact are the same.
  5746.      */
  5747.     return(FALSE);
  5748. }
  5749. #endif
  5750.  
  5751. /*
  5752.  *  Utility for freeing the list of goto URLs. - FM
  5753.  */
  5754. PUBLIC void HTGotoURLs_free NOARGS
  5755. {
  5756.     char *url;
  5757.     HTList *cur = Goto_URLs;
  5758.  
  5759.     if (!cur)
  5760.     return;
  5761.  
  5762.     while (NULL != (url = (char *)HTList_nextObject(cur))) {
  5763.     FREE(url);
  5764.     }
  5765.     HTList_delete(Goto_URLs);
  5766.     Goto_URLs = NULL;
  5767.     return;
  5768. }
  5769.  
  5770. /*
  5771.  *  Utility for listing Goto URLs, making any
  5772.  *  repeated URLs the most current in the list. - FM
  5773.  */
  5774. PUBLIC void HTAddGotoURL ARGS1(
  5775.     char *,     url)
  5776. {
  5777.     char *new;
  5778.     char *old;
  5779.     HTList *cur;
  5780.  
  5781.     if (!(url && *url))
  5782.     return;
  5783.  
  5784.     if ((new = (char *)calloc(1, (strlen(url) + 1))) == NULL)
  5785.     outofmem(__FILE__, "HTAddGotoURL");
  5786.     strcpy(new, url);
  5787.  
  5788.     if (!Goto_URLs) {
  5789.     Goto_URLs = HTList_new();
  5790.     atexit(HTGotoURLs_free);
  5791.     HTList_addObject(Goto_URLs, new);
  5792.     return;
  5793.     }
  5794.  
  5795.     cur = Goto_URLs;
  5796.     while (NULL != (old = (char *)HTList_nextObject(cur))) {
  5797.     if (!strcmp(old, new)) {
  5798.         HTList_removeObject(Goto_URLs, old);
  5799.         FREE(old);
  5800.         break;
  5801.     }
  5802.     }
  5803.     HTList_addObject(Goto_URLs, new);
  5804.  
  5805.     return;
  5806. }
  5807.