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 / LYTraversal.c < prev    next >
C/C++ Source or Header  |  1998-03-25  |  4KB  |  195 lines

  1. #include <HTUtils.h>
  2. #include <tcp.h>
  3. #include <LYGlobalDefs.h>
  4. #include <LYUtils.h>
  5. #include <LYSignal.h>
  6. #include <LYTraversal.h>
  7.  
  8. #include <LYexit.h>
  9. #include <LYLeaks.h>
  10.  
  11. /* routines to handle special traversal feature */
  12.  
  13. PUBLIC BOOLEAN lookup ARGS1(char *,target)
  14. {
  15.     FILE *ifp;
  16.     char buffer[200], line[200];
  17.  
  18.     if ((ifp = fopen(TRAVERSE_FILE,"r")) == NULL) {
  19.         if ((ifp = LYNewTxtFile(TRAVERSE_FILE)) == NULL) {
  20.             perror("unable to open or create a traversal file");
  21. #ifndef NOSIGHUP
  22.         (void) signal(SIGHUP, SIG_DFL);
  23. #endif /* NOSIGHUP */
  24.         (void) signal(SIGTERM, SIG_DFL);
  25. #ifndef VMS
  26.         (void) signal(SIGINT, SIG_DFL);
  27. #endif /* !VMS */
  28. #ifdef SIGTSTP
  29.         if (no_suspend)
  30.             (void) signal(SIGTSTP,SIG_DFL);
  31. #endif /* SIGTSTP */
  32.             exit(-1);
  33.     } else {
  34.             fclose(ifp);
  35.             return(FALSE);
  36.         }
  37.     }
  38.  
  39.     sprintf(line,"%s\n",target);
  40.  
  41.     while(fgets(buffer, 200, ifp) != NULL) {
  42.     if (STREQ(line,buffer)) {
  43.         fclose(ifp);
  44.         return(TRUE);
  45.     }
  46.     } /* end while */
  47.  
  48.     fclose(ifp);
  49.     return(FALSE);
  50. }
  51.  
  52. PUBLIC void add_to_table ARGS1(char *,target)
  53. {
  54.  
  55.     FILE *ifp;
  56.  
  57.     if ((ifp = LYAppendToTxtFile(TRAVERSE_FILE)) == NULL) {
  58.     perror("unable to open traversal file");
  59. #ifndef NOSIGHUP
  60.     (void) signal(SIGHUP, SIG_DFL);
  61. #endif /* NOSIGHUP */
  62.     (void) signal(SIGTERM, SIG_DFL);
  63. #ifndef VMS
  64.     (void) signal(SIGINT, SIG_DFL);
  65. #endif /* !VMS */
  66. #ifdef SIGTSTP
  67.     if (no_suspend)
  68.         (void) signal(SIGTSTP,SIG_DFL);
  69. #endif /* SIGTSTP */
  70.     exit(-1);
  71.     }
  72.  
  73.     fprintf(ifp,"%s\n",target);
  74.  
  75.     fclose(ifp);
  76. }
  77.  
  78. PUBLIC void add_to_traverse_list ARGS2(char *,fname, char *,prev_link_name)
  79. {
  80.  
  81.     FILE *ifp;
  82.  
  83.     if ((ifp = LYAppendToTxtFile(TRAVERSE_FOUND_FILE)) == NULL) {
  84.     perror("unable to open traversal found file");
  85. #ifndef NOSIGHUP
  86.     (void) signal(SIGHUP, SIG_DFL);
  87. #endif /* NOSIGHUP */
  88.     (void) signal(SIGTERM, SIG_DFL);
  89. #ifndef VMS
  90.     (void) signal(SIGINT, SIG_DFL);
  91. #endif /* !VMS */
  92. #ifdef SIGTSTP
  93.     if (no_suspend)
  94.         (void) signal(SIGTSTP,SIG_DFL);
  95. #endif /* SIGTSTP */
  96.     exit(-1);
  97.     }
  98.  
  99.     fprintf(ifp,"%s\t%s\n",fname, prev_link_name);
  100.  
  101.     fclose(ifp);
  102. }
  103.  
  104. PUBLIC void dump_traversal_history NOARGS
  105. {
  106.     int x;
  107.     FILE *ifp;
  108.  
  109.     if (nhist <= 0)
  110.         return;
  111.  
  112.     if ((ifp = LYAppendToTxtFile(TRAVERSE_FILE)) == NULL) {
  113.         perror("unable to open traversal file");
  114.     return;
  115.     }
  116.  
  117.     fprintf(ifp, "\n\nTRAVERSAL WAS INTERUPTED\n\n\
  118. \t    here is a list of the history stack so that you may rebuild\n\n");
  119.  
  120.     for (x = nhist-1; x >= 0; x--) {
  121.     fprintf(ifp,"%s\t%s\n", history[x].title, history[x].address);
  122.     }
  123.  
  124.     fclose(ifp);
  125. }
  126.  
  127. PUBLIC void add_to_reject_list ARGS1(char *,target)
  128. {
  129.  
  130.     FILE *ifp;
  131.  
  132.     if ((ifp = LYAppendToTxtFile(TRAVERSE_REJECT_FILE)) == NULL) {
  133.     perror("unable to open reject file");
  134. #ifndef NOSIGHUP
  135.     (void) signal(SIGHUP, SIG_DFL);
  136. #endif /* NOSIGHUP */
  137.     (void) signal(SIGTERM, SIG_DFL);
  138. #ifndef VMS
  139.     (void) signal(SIGINT, SIG_DFL);
  140. #endif /* !VMS */
  141. #ifdef SIGTSTP
  142.     if (no_suspend)
  143.         (void) signal(SIGTSTP,SIG_DFL);
  144. #endif /* SIGTSTP */
  145.     exit(-1);
  146.     }
  147.  
  148.     fprintf(ifp,"%s\n",target);
  149.  
  150.     fclose(ifp);
  151. }
  152.  
  153. /* there need not be a reject file, so if it doesn't open, just return
  154.    FALSE, meaning "target not in reject file" If the last character in
  155.    a line in a reject file is "*", then also reject if target matches up to
  156.    that point in the string
  157.    Blank lines are ignored
  158.    Lines that contain just a * are allowed, but since they mean "reject
  159.    everything" it shouldn't come up much!
  160.  */
  161.  
  162. PUBLIC BOOLEAN lookup_reject ARGS1(char *,target)
  163. {
  164.     FILE *ifp;
  165.     char buffer[200], line[200], ch;
  166.     int  frag;
  167.  
  168.     if ((ifp = fopen(TRAVERSE_REJECT_FILE,"r")) == NULL){
  169.         return(FALSE);
  170.     }
  171.  
  172.     sprintf(line,"%s\n",target);
  173.  
  174.     while (fgets(buffer, 200, ifp) != NULL) {
  175.     frag = strlen(buffer) - 1; /* real length, minus trailing null */
  176.     ch   = buffer[frag - 1];   /* last character in buffer */
  177.     if (frag > 0) {            /* if not an empty line */
  178.         if (ch == '*') {
  179.             if (frag == 1 || ((strncmp(line,buffer,frag - 1)) == 0)) {
  180.                fclose(ifp);
  181.                return(TRUE);
  182.             }
  183.         } else { /* last character = "*" test */
  184.             if (STREQ(line,buffer)) {
  185.                 fclose(ifp);
  186.                 return(TRUE);
  187.             }
  188.         } /* last character = "*" test */
  189.     } /* frag >= 0 */
  190.     } /* end while */
  191.  
  192.     fclose(ifp);
  193.     return(FALSE);
  194. }
  195.