*** fm.h	Thu Sep 16 15:44:30 1999
--- ../w3m.tmp/fm.h	Mon Sep 20 22:59:45 1999
***************
*** 491,496 ****
--- 491,498 ----
  global int do_download init(NIL);
  global char *UserAgent init(NULL);
  global char *AcceptLang init(NULL);
+ global int WrapDefault init(NIL);
+ global int WrapSearch init(NIL);
  global int squeezeBlankLine init(NIL);
  
  global struct auth_cookie *Auth_cookie init(NULL);
*** keybind.c	Thu Aug 19 18:53:00 1999
--- ../w3m.tmp/keybind.c	Mon Sep 20 22:59:45 1999
***************
*** 8,14 ****
  /* C-h    C-i     C-j     C-k     C-l     C-m     C-n     C-o      */
    nulcmd, nextA,  followA,nulcmd, rdrwSc, followA,movD,   nulcmd,
  /* C-p    C-q     C-r     C-s     C-t     C-u     C-v     C-w      */
!   movU,   nulcmd, srchbak,srchfor,nulcmd, prevA, pgFore, nulcmd,
  /* C-x    C-y     C-z     C-[     C-\     C-]     C-^     C-_      */
    nulcmd, nulcmd, susp,   escmap, nulcmd, nulcmd, nulcmd, nulcmd,
  /* SPC    !       "       #       $       %       &       '        */
--- 8,14 ----
  /* C-h    C-i     C-j     C-k     C-l     C-m     C-n     C-o      */
    nulcmd, nextA,  followA,nulcmd, rdrwSc, followA,movD,   nulcmd,
  /* C-p    C-q     C-r     C-s     C-t     C-u     C-v     C-w      */
!   movU,   nulcmd, srchbak,srchfor,nulcmd, prevA, pgFore,  wrapToggle,
  /* C-x    C-y     C-z     C-[     C-\     C-]     C-^     C-_      */
    nulcmd, nulcmd, susp,   escmap, nulcmd, nulcmd, nulcmd, nulcmd,
  /* SPC    !       "       #       $       %       &       '        */
*** keybind_lynx.c	Mon Jul  5 11:35:05 1999
--- ../w3m.tmp/keybind_lynx.c	Mon Sep 20 22:59:45 1999
***************
*** 42,48 ****
  /* h      i       j       k       l       m       n       o        */
    movL,   nulcmd, movD,   movU, movR,   nulcmd, srchnxt,  ldOpt,
  /* p      q       r       s       t       u       v       w        */
!   svBuf,  qquitfm,nulcmd, selBuf, nulcmd, peekURL,ldBmark, nulcmd,
  /* x      y       z       {       |       }       ~       DEL      */
    nulcmd, nulcmd, ctrCsrV,nulcmd, nulcmd, nulcmd, nulcmd, nulcmd,
  };
--- 42,48 ----
  /* h      i       j       k       l       m       n       o        */
    movL,   nulcmd, movD,   movU, movR,   nulcmd, srchnxt,  ldOpt,
  /* p      q       r       s       t       u       v       w        */
!   svBuf,  qquitfm,nulcmd, selBuf, nulcmd, peekURL,ldBmark, wrapToggle,
  /* x      y       z       {       |       }       ~       DEL      */
    nulcmd, nulcmd, ctrCsrV,nulcmd, nulcmd, nulcmd, nulcmd, nulcmd,
  };
*** main.c	Thu Sep 16 15:44:30 1999
--- ../w3m.tmp/main.c	Mon Sep 20 22:59:45 1999
***************
*** 22,28 ****
  Hist    *URLHist;
  Hist    *ShellHist;
  
! void             (*searchRoutine) (Buffer*, char*);
  static void     _goLine(char *);
  
  JMP_BUF         IntReturn;
--- 22,28 ----
  Hist    *URLHist;
  Hist    *ShellHist;
  
! int             (*searchRoutine) (Buffer*, char*);
  static void     _goLine(char *);
  
  JMP_BUF         IntReturn;
***************
*** 89,94 ****
--- 89,95 ----
    fprintf(stderr, "    -no-mouse    don't use mouse\n");
  #endif
    fprintf(stderr, "    -S           squeeze multiple blank lines\n");
+   fprintf(stderr, "    -W           toggle wrap search mode\n");
    fprintf(stderr, "    -debug       DO NOT USE\n");
    exit(1);
  }
***************
*** 201,207 ****
        }
        else if (!strcmp("-F", argv[i]))
  	RenderFrame = T;
!       else if (!strcmp("-dump", argv[i])) {
  	w3m_dump = T;
  	if (COLS == 0)
  	  COLS = 80;
--- 202,214 ----
        }
        else if (!strcmp("-F", argv[i]))
  	RenderFrame = T;
!       else if (!strcmp("-W", argv[i])) {
! 	if (WrapSearch) {
! 	  WrapSearch = NIL;
! 	} else {
! 	  WrapSearch = T;
! 	}
!       } else if (!strcmp("-dump", argv[i])) {
  	w3m_dump = T;
  	if (COLS == 0)
  	  COLS = 80;
***************
*** 610,615 ****
--- 617,623 ----
    MySignalHandler(*prevtrap) ();
    char           *SearchString;
    int i;
+   int wrapped;
  
    SearchString = inputStrHist("Forward: ", NULL, SearchHist);
    if (SearchString != NULL && *SearchString == '\0' && SearchHist->length)
***************
*** 622,631 ****
    crmode();
    if (SETJMP(IntReturn) == 0)
      for (i=0; i < PREC_NUM; i++)
!       forwardSearch(Currentbuf, SearchString);
    signal(SIGINT, prevtrap);
    term_raw();
    displayBuffer(Currentbuf, B_NORMAL);
    searchRoutine = forwardSearch;
  }
  
--- 630,642 ----
    crmode();
    if (SETJMP(IntReturn) == 0)
      for (i=0; i < PREC_NUM; i++)
!       wrapped = forwardSearch(Currentbuf, SearchString);
    signal(SIGINT, prevtrap);
    term_raw();
    displayBuffer(Currentbuf, B_NORMAL);
+   if (wrapped) {
+     disp_message("Search wrapped", NIL);
+   }
    searchRoutine = forwardSearch;
  }
  
***************
*** 636,641 ****
--- 647,653 ----
    MySignalHandler(*prevtrap) ();
    char           *SearchString;
    int i;
+   int wrapped;
  
    SearchString = inputStrHist("Backward: ", NULL, SearchHist);
    if (SearchString != NULL && *SearchString == '\0' && SearchHist->length)
***************
*** 648,657 ****
    crmode();
    if (SETJMP(IntReturn) == 0)
      for (i=0; i < PREC_NUM; i++)
!       backwardSearch(Currentbuf, SearchString);
    signal(SIGINT, prevtrap);
    term_raw();
    displayBuffer(Currentbuf, B_NORMAL);
    searchRoutine = backwardSearch;
  }
  
--- 660,672 ----
    crmode();
    if (SETJMP(IntReturn) == 0)
      for (i=0; i < PREC_NUM; i++)
!       wrapped = backwardSearch(Currentbuf, SearchString);
    signal(SIGINT, prevtrap);
    term_raw();
    displayBuffer(Currentbuf, B_NORMAL);
+   if (wrapped) {
+     disp_message("Search wrapped", NIL);
+   }
    searchRoutine = backwardSearch;
  }
  
***************
*** 661,666 ****
--- 676,682 ----
  {
    char *SearchString;
    int i;
+   int wrapped;
  
    MySignalHandler(*prevtrap) ();
    if (searchRoutine == NULL) {
***************
*** 678,687 ****
    crmode();
    if (SETJMP(IntReturn) == 0)
      for (i=0; i < PREC_NUM; i++)
!       (*searchRoutine) (Currentbuf, SearchString);
    signal(SIGINT, prevtrap);
    term_raw();
    displayBuffer(Currentbuf, B_NORMAL);
  }
  
  /* Shift screen left */
--- 694,706 ----
    crmode();
    if (SETJMP(IntReturn) == 0)
      for (i=0; i < PREC_NUM; i++)
!       wrapped = (*searchRoutine) (Currentbuf, SearchString);
    signal(SIGINT, prevtrap);
    term_raw();
    displayBuffer(Currentbuf, B_NORMAL);
+   if (wrapped) {
+     disp_message("Search wrapped", NIL);
+   }
  }
  
  /* Shift screen left */
***************
*** 2509,2511 ****
--- 2528,2541 ----
    displayBuffer(Currentbuf,B_FORCE_REDRAW);
  }
  #endif
+ 
+ void wrapToggle( void )
+ {
+   if (WrapSearch) {
+     WrapSearch = NIL;
+     disp_message("Wrap search off", NIL);
+   } else {
+     WrapSearch = T;
+     disp_message("Wrap search on", NIL);
+   }
+ }
*** proto.h	Thu Sep 16 15:44:30 1999
--- ../w3m.tmp/proto.h	Mon Sep 20 22:59:45 1999
***************
*** 189,196 ****
  extern char* mybasename ( char* s );
  extern int next_status ( char c, int *status );
  extern int read_token ( Str buf, char **instr, int *status, int pre, int append );
! extern void forwardSearch ( Buffer * buf, char *str );
! extern void backwardSearch ( Buffer * buf, char *str );
  extern void escmap ( void );
  extern void escbmap ( void );
  extern void escdmap ( char c );
--- 189,196 ----
  extern char* mybasename ( char* s );
  extern int next_status ( char c, int *status );
  extern int read_token ( Str buf, char **instr, int *status, int pre, int append );
! extern int forwardSearch ( Buffer * buf, char *str );
! extern int backwardSearch ( Buffer * buf, char *str );
  extern void escmap ( void );
  extern void escbmap ( void );
  extern void escdmap ( char c );
***************
*** 420,422 ****
--- 420,424 ----
  #define dictword nulcmd
  #define dictwordat nulcmd
  #endif
+ 
+ extern void wrapToggle( void );
*** rc.c	Tue Aug 31 19:24:13 1999
--- ../w3m.tmp/rc.c	Mon Sep 20 22:59:45 1999
***************
*** 48,53 ****
--- 48,54 ----
  #define CMT_FTPPASS      "FTP¤Î¥Ñ¥¹¥ï¡¼¥É(ÉáÄÌ¤Ï¼«Ê¬¤Îmail address¤ò»È¤¦)"
  #define CMT_USERAGENT    "User-Agent"
  #define CMT_ACCEPTLANG   "¼õ¤±¤Ä¤±¤ë¸À¸ì(Accept-Language:)"
+ #define CMT_WRAP         "ÀÞ¤êÊÖ¤·¸¡º÷"
  #else
  #define CMT_TABSTOP      "Tab width"
  #define CMT_PAGERLINE    "# of reserved line when w3m is used as a pager"
***************
*** 78,83 ****
--- 79,85 ----
  #define CMT_FTPPASS      "Password for FTP(use your mail address)"
  #define CMT_USERAGENT    "User-Agent"
  #define CMT_ACCEPTLANG   "Accept-Language"
+ #define CMT_WRAP         "Wrap search"
  #endif
  
  #define PI_TEXT    0
***************
*** 152,157 ****
--- 154,160 ----
    {"ftppasswd",       P_STRING, PI_TEXT,  (void*)&ftppasswd, CMT_FTPPASS, NULL},
    {"user_agent",      P_STRING, PI_TEXT,  (void*)&UserAgent, CMT_USERAGENT,NULL},
    {"accept_language", P_STRING, PI_TEXT,  (void*)&AcceptLang, CMT_ACCEPTLANG, NULL},
+   {"wrap_search",     P_INT,    PI_ONOFF, (void*)&WrapDefault, CMT_WRAP, NULL},
    {NULL, 0, 0, NULL, NULL, NULL},
  };
  
***************
*** 323,328 ****
--- 326,332 ----
      interpret_rc(f);
      fclose(f);
      parse_proxy();
+     WrapSearch = WrapDefault;
    }
    UserMailcap = loadMailcap(USER_MAILCAP);
    SysMailcap = loadMailcap(SYS_MAILCAP);
***************
*** 436,440 ****
--- 440,445 ----
    }
    fclose(f);
    parse_proxy();
+   WrapSearch = WrapDefault;
    backBf();
  }
*** search.c	Wed May 19 17:38:52 1999
--- ../w3m.tmp/search.c	Mon Sep 20 22:59:45 1999
***************
*** 4,57 ****
  int regexMatch(char*,int);
  void matchedPosition(char**,char**);
  
! void
  forwardSearch(Buffer * buf, char *str)
  {
    char           *p, *first, *last;
!   Line           *l;
  
    if ((p = regexCompile(str,1)) != NULL) {
      message(p, 0, 0);
!     return;
    }
!   l = buf->currentLine;
    if (regexMatch(&l->lineBuf[buf->pos + 1], 0) == 1) {
      matchedPosition(&first, &last);
      buf->pos = first - l->lineBuf;
      arrangeCursor(buf);
!     return;
    }
    for (l = l->next;; l = l->next) {
      if (l == NULL) {
        if (buf->pagerSource) {
  	l = getNextPage(buf, 1);
! 	if (l == NULL)
! 	  break;
!       } else
  	break;
      }
      if (regexMatch(l->lineBuf, 1) == 1) {
-       buf->currentLine = l;
        matchedPosition(&first, &last);
        buf->pos = first - l->lineBuf;
        arrangeCursor(buf);
!       return;
      }
    }
    disp_message("Not found", NIL);
  }
  
! void
  backwardSearch(Buffer * buf, char *str)
  {
    char           *p, *q, *found, *first, *last;
!   Line           *l;
  
    if ((p = regexCompile(str,1)) != NULL) {
      message(p, 0, 0);
!     return;
    }
!   l = buf->currentLine;
    if (buf->pos > 0) {
      p = &l->lineBuf[buf->pos - 1];
      found = NULL;
--- 4,75 ----
  int regexMatch(char*,int);
  void matchedPosition(char**,char**);
  
! int
  forwardSearch(Buffer * buf, char *str)
  {
    char           *p, *first, *last;
!   Line           *l, *begin;
!   int            wrapped = NIL;
  
    if ((p = regexCompile(str,1)) != NULL) {
      message(p, 0, 0);
!     return NIL;
    }
!   l = begin = buf->currentLine;
    if (regexMatch(&l->lineBuf[buf->pos + 1], 0) == 1) {
      matchedPosition(&first, &last);
      buf->pos = first - l->lineBuf;
      arrangeCursor(buf);
!     return NIL;
    }
    for (l = l->next;; l = l->next) {
      if (l == NULL) {
        if (buf->pagerSource) {
  	l = getNextPage(buf, 1);
! 	if (l == NULL) {
! 	  if (WrapSearch) {
! 	    l = buf->firstLine;
! 	    wrapped = T;
! 	  } else {
! 	    break;
! 	  }
! 	}
!       } else if (WrapSearch) {
! 	l = buf->firstLine;
! 	wrapped = T;
!       } else {
  	break;
+       }
      }
      if (regexMatch(l->lineBuf, 1) == 1) {
        matchedPosition(&first, &last);
+       if (wrapped && l == begin && buf->pos == first - l->lineBuf)
+ 	/* exactly same match */
+ 	break;
        buf->pos = first - l->lineBuf;
+       buf->currentLine = l;
        arrangeCursor(buf);
!       return wrapped;
      }
+     if (wrapped && l == begin) /* no match */
+       break;
    }
    disp_message("Not found", NIL);
+   return NIL;
  }
  
! int
  backwardSearch(Buffer * buf, char *str)
  {
    char           *p, *q, *found, *first, *last;
!   Line           *l, *begin;
!   int            wrapped = NIL;
  
    if ((p = regexCompile(str,1)) != NULL) {
      message(p, 0, 0);
!     return NIL;
    }
!   l = begin = buf->currentLine;
    if (buf->pos > 0) {
      p = &l->lineBuf[buf->pos - 1];
      found = NULL;
***************
*** 67,80 ****
      if (found) {
        buf->pos = found - l->lineBuf;
        arrangeCursor(buf);
!       return;
      }
    }
!   for (l = l->prev; l != NULL; l = l->prev) {
      found = NULL;
      q = l->lineBuf;
      while (regexMatch(q, q == l->lineBuf) == 1) {
        matchedPosition(&first, &last);
        found = first;
        q++;
      }
--- 85,109 ----
      if (found) {
        buf->pos = found - l->lineBuf;
        arrangeCursor(buf);
!       return NIL;
      }
    }
!   for (l = l->prev;; l = l->prev) {
!     if (l == NULL) {
!       if (WrapSearch) {
! 	l = buf->lastLine;
! 	wrapped = T;
!       } else {
! 	break;
!       }
!     }
      found = NULL;
      q = l->lineBuf;
      while (regexMatch(q, q == l->lineBuf) == 1) {
        matchedPosition(&first, &last);
+       if (wrapped && l == begin && buf->pos == first - l->lineBuf)
+ 	/* exactly same match */
+ 	break;
        found = first;
        q++;
      }
***************
*** 82,89 ****
        buf->pos = found - l->lineBuf;
        buf->currentLine = l;
        arrangeCursor(buf);
!       return;
      }
    }
    disp_message("Not found", NIL);
  }
--- 111,121 ----
        buf->pos = found - l->lineBuf;
        buf->currentLine = l;
        arrangeCursor(buf);
!       return wrapped;
      }
+     if (wrapped && l == begin) /* no match */
+       break;
    }
    disp_message("Not found", NIL);
+   return NIL;
  }
