summaryrefslogtreecommitdiff
path: root/pico
diff options
context:
space:
mode:
authorEduardo Chappa <chappa@washington.edu>2013-08-04 21:50:43 -0600
committerEduardo Chappa <chappa@washington.edu>2013-08-04 21:50:43 -0600
commit82ec113957d8297ed08c51c20cbc4b0a6f623d4e (patch)
treebc58ae92ca1627554947f894206af9a47e8cee60 /pico
parent33d5c0604e830bb65c2f5ccd69170b1c1453802b (diff)
downloadalpine-82ec113957d8297ed08c51c20cbc4b0a6f623d4e.tar.xz
* New version 2.10.99999
* Pico: search backwards. * do not allow List- headers to be set up by users in accordance with RFC 2369. * minor fixes for new justification support (add comparison of a line with the previous *and* the next).
Diffstat (limited to 'pico')
-rw-r--r--pico/Makefile.in4
-rw-r--r--pico/browse.c8
-rw-r--r--pico/efunc.h8
-rw-r--r--pico/osdep/Makefile.in4
-rw-r--r--pico/osdep/spell.c6
-rw-r--r--pico/search.c151
-rw-r--r--pico/word.c2
7 files changed, 121 insertions, 62 deletions
diff --git a/pico/Makefile.in b/pico/Makefile.in
index 948e1ea4..4d5fd37c 100644
--- a/pico/Makefile.in
+++ b/pico/Makefile.in
@@ -170,7 +170,6 @@ C_CLIENT_TARGET = @C_CLIENT_TARGET@
C_CLIENT_WITH_IPV6 = @C_CLIENT_WITH_IPV6@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
-DLLTOOL = @DLLTOOL@
DSYMUTIL = @DSYMUTIL@
DUMPBIN = @DUMPBIN@
ECHO_C = @ECHO_C@
@@ -206,7 +205,6 @@ LTLIBOBJS = @LTLIBOBJS@
MAINT = @MAINT@
MAKE = @MAKE@
MAKEINFO = @MAKEINFO@
-MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
MSGFMT = @MSGFMT@
MSGFMT_015 = @MSGFMT_015@
@@ -253,7 +251,6 @@ abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
-ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
acx_pthread_config = @acx_pthread_config@
@@ -289,6 +286,7 @@ libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
diff --git a/pico/browse.c b/pico/browse.c
index 46e01fd0..93de8066 100644
--- a/pico/browse.c
+++ b/pico/browse.c
@@ -4,8 +4,8 @@ static char rcsid[] = "$Id: browse.c 942 2008-03-04 18:21:33Z hubert@u.washingto
/*
* ========================================================================
- * Copyright 2006-2008 University of Washington
* Copyright 2013 Eduardo Chappa
+ * Copyright 2006-2008 University of Washington
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1595,8 +1595,9 @@ FileBrowse(char *dir, size_t dirlen, char *fn, size_t fnlen,
i = 0;
while(!i){
+ int bsearch = 0;
- switch(readpattern(_("File name to find"), FALSE)){
+ switch(readpattern(_("File name to find"), FALSE, bsearch)){
case HELPCH:
emlwrite(_("\007No help yet!"), NULL);
/* remove break and sleep after help text is installed */
@@ -1605,6 +1606,9 @@ FileBrowse(char *dir, size_t dirlen, char *fn, size_t fnlen,
case (CTRL|'L'):
PaintBrowser(gmp, 0, &crow, &ccol);
break;
+ case (CTRL|'P'):
+ bsearch = bsearch == 0 ? 1 : 0;
+ break;
case (CTRL|'Y'): /* first first cell */
for(tp = gmp->top; tp->prev; tp = tp->prev)
;
diff --git a/pico/efunc.h b/pico/efunc.h
index b551dfc7..16522f80 100644
--- a/pico/efunc.h
+++ b/pico/efunc.h
@@ -2,8 +2,8 @@
* $Id: efunc.h 807 2007-11-09 01:21:33Z hubert@u.washington.edu $
*
* ========================================================================
- * Copyright 2006-2007 University of Washington
* Copyright 2013 Eduardo Chappa
+ * Copyright 2006-2007 University of Washington
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -229,9 +229,9 @@ extern void unmarkbuffer(void);
/* search.c */
extern int forwsearch(int, int);
-extern int readpattern(char *, int);
-extern int forscan(int *, UCS *, LINE *, int, int);
-extern void chword(UCS *, UCS *);
+extern int readpattern(char *, int, int);
+extern int forscan(int *, UCS *, int, LINE *, int, int);
+extern void chword(UCS *, UCS *, int);
/* spell.c */
#ifdef SPELLER
diff --git a/pico/osdep/Makefile.in b/pico/osdep/Makefile.in
index cd78db7c..35ad3095 100644
--- a/pico/osdep/Makefile.in
+++ b/pico/osdep/Makefile.in
@@ -121,7 +121,6 @@ C_CLIENT_TARGET = @C_CLIENT_TARGET@
C_CLIENT_WITH_IPV6 = @C_CLIENT_WITH_IPV6@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
-DLLTOOL = @DLLTOOL@
DSYMUTIL = @DSYMUTIL@
DUMPBIN = @DUMPBIN@
ECHO_C = @ECHO_C@
@@ -157,7 +156,6 @@ LTLIBOBJS = @LTLIBOBJS@
MAINT = @MAINT@
MAKE = @MAKE@
MAKEINFO = @MAKEINFO@
-MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
MSGFMT = @MSGFMT@
MSGFMT_015 = @MSGFMT_015@
@@ -204,7 +202,6 @@ abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
-ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
acx_pthread_config = @acx_pthread_config@
@@ -240,6 +237,7 @@ libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
diff --git a/pico/osdep/spell.c b/pico/osdep/spell.c
index 87b345eb..2b22beb2 100644
--- a/pico/osdep/spell.c
+++ b/pico/osdep/spell.c
@@ -4,8 +4,8 @@ static char rcsid[] = "$Id: spell.c 854 2007-12-07 17:44:43Z hubert@u.washington
/*
* ========================================================================
- * Copyright 2006-2007 University of Washington
* Copyright 2013 Eduardo Chappa
+ * Copyright 2006-2007 University of Washington
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -207,7 +207,7 @@ spell(int f, int n)
switch(status){
case TRUE:
- chword(wb, cb); /* correct word */
+ chword(wb, cb, 0); /* correct word */
case FALSE:
update(); /* place cursor */
break;
@@ -285,7 +285,7 @@ movetoword(UCS *w)
olddotp = curwp->w_dotp;
curwp->w_bufp->b_mode |= MDEXACT; /* case sensitive */
- while(forscan(&i, w, NULL, 0, 1) == TRUE){
+ while(forscan(&i, w, 0, NULL, 0, 1) == TRUE){
if(i)
break; /* wrap NOT allowed! */
diff --git a/pico/search.c b/pico/search.c
index 0886b24c..62b529a3 100644
--- a/pico/search.c
+++ b/pico/search.c
@@ -4,8 +4,8 @@ static char rcsid[] = "$Id: search.c 1266 2009-07-14 18:39:12Z hubert@u.washingt
/*
* ========================================================================
- * Copyright 2006-2008 University of Washington
* Copyright 2013 Eduardo Chappa
+ * Copyright 2006-2008 University of Washington
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,10 +32,10 @@ int eq(UCS, UCS);
int expandp(UCS *, UCS *, int);
int readnumpat(char *);
void get_pat_cases(UCS *, UCS *);
-int srpat(char *, UCS *, size_t, int);
-int readpattern(char *, int);
-int replace_pat(UCS *, int *);
-int replace_all(UCS *, UCS *);
+int srpat(char *, UCS *, size_t, int, int);
+int readpattern(char *, int, int);
+int replace_pat(UCS *, int *, int);
+int replace_all(UCS *, UCS *, int);
#define FWS_RETURN(RV) { \
@@ -109,7 +109,7 @@ eq(UCS bc, UCS pc)
int
forwsearch(int f, int n)
{
- int status;
+ int status, bsearch;
int wrapt = FALSE, wrapt2 = FALSE;
int repl_mode = FALSE;
UCS defpat[NPAT];
@@ -124,14 +124,15 @@ forwsearch(int f, int n)
FWS_RETURN(0);
defpat[0] = '\0';
+ bsearch = 0; /* search forward by default */
/* ask the user for the text of a pattern */
while(1){
if (gmode & MDREPLACE)
- status = srpat("Search", defpat, NPAT, repl_mode);
+ status = srpat("Search", defpat, NPAT, repl_mode, bsearch);
else
- status = readpattern("Search", TRUE);
+ status = readpattern("Search", TRUE, bsearch);
switch(status){
case TRUE: /* user typed something */
@@ -158,6 +159,10 @@ forwsearch(int f, int n)
update();
break;
+ case (CTRL|'P'):
+ bsearch = bsearch == 0 ? 1 : 0;
+ break;
+
case (CTRL|'V'):
gotoeob(0, 1);
mlerase();
@@ -268,21 +273,21 @@ forwsearch(int f, int n)
*/
status = 0; /* using "status" as int temporarily! */
while(1){
- if(defpat[status] == '\0'){
- forwchar(0, 1);
- break; /* find next occurence! */
- }
+ if(defpat[status] == '\0'){
+ forwchar(0, 1 - 2*bsearch); /* move back if searching backward */
+ break;
+ }
- if(status + curwp->w_doto >= llength(curwp->w_dotp) ||
+ if(curwp->w_doto + status >= llength(curwp->w_dotp) ||
!eq(defpat[status],lgetc(curwp->w_dotp, curwp->w_doto + status).c))
- break; /* do nothing! */
- status++;
+ break;
+ status++;
}
/* search for the pattern */
while (n-- > 0) {
- if((status = forscan(&wrapt,defpat,NULL,0,PTBEG)) == FALSE)
+ if((status = forscan(&wrapt,defpat, bsearch, NULL,0,PTBEG)) == FALSE)
break;
}
@@ -301,7 +306,7 @@ forwsearch(int f, int n)
fs_give((void **) &utf8);
}
else if((gmode & MDREPLACE) && repl_mode == TRUE){
- status = replace_pat(defpat, &wrapt2); /* replace pattern */
+ status = replace_pat(defpat, &wrapt2, bsearch); /* replace pattern */
if (wrapt == TRUE || wrapt2 == TRUE){
eml.s = (status == ABORT) ? "cancelled but wrapped" : "Wrapped";
emlwrite("Replacement %s", &eml);
@@ -320,7 +325,7 @@ forwsearch(int f, int n)
/* Replace a pattern with the pattern the user types in one or more times. */
int
-replace_pat(UCS *defpat, int *wrapt)
+replace_pat(UCS *defpat, int *wrapt, int bsearch)
{
register int status;
UCS lpat[NPAT], origpat[NPAT]; /* case sensitive pattern */
@@ -331,7 +336,7 @@ replace_pat(UCS *defpat, int *wrapt)
UCS prompt[NPMT];
UCS *promptp;
- forscan(wrapt, defpat, NULL, 0, PTBEG); /* go to word to be replaced */
+ forscan(wrapt, defpat, bsearch, NULL, 0, PTBEG); /* go to word to be replaced */
lpat[0] = '\0';
@@ -416,10 +421,10 @@ replace_pat(UCS *defpat, int *wrapt)
}
if (repl_all){
- status = replace_all(defpat, lpat);
+ status = replace_all(defpat, lpat, bsearch);
}
else{
- chword(defpat, lpat); /* replace word */
+ chword(defpat, lpat, bsearch); /* replace word */
update();
status = TRUE;
}
@@ -470,7 +475,7 @@ replace_pat(UCS *defpat, int *wrapt)
}
else{
mlerase();
- chword(defpat, origpat);
+ chword(defpat, origpat, bsearch);
}
update();
@@ -501,7 +506,7 @@ get_pat_cases(UCS *realpat, UCS *searchpat)
/* Ask the user about every occurence of orig pattern and replace it with a
repl pattern if the response is affirmative. */
int
-replace_all(UCS *orig, UCS *repl)
+replace_all(UCS *orig, UCS *repl, int bsearch)
{
register int status = 0;
UCS *b;
@@ -515,7 +520,7 @@ replace_all(UCS *orig, UCS *repl)
EML eml;
while (1)
- if (forscan(&wrapt, orig, stop_line, stop_offset, PTBEG)){
+ if (forscan(&wrapt, orig, bsearch, stop_line, stop_offset, PTBEG)){
curwp->w_flag |= WFMOVE; /* put cursor back */
update();
@@ -562,10 +567,10 @@ replace_all(UCS *orig, UCS *repl)
if (status == TRUE){
n++;
- chword(realpat, repl); /* replace word */
+ chword(realpat, repl, bsearch); /* replace word */
update();
}else{
- chword(realpat, realpat); /* replace word by itself */
+ chword(realpat, realpat, bsearch); /* replace word by itself */
update();
if(status == ABORT){ /* if cancelled return */
eml.s = comatose(n);
@@ -593,14 +598,14 @@ replace_all(UCS *orig, UCS *repl)
/* Read a replacement pattern. Modeled after readpattern(). */
int
-srpat(char *utf8prompt, UCS *defpat, size_t defpatlen, int repl_mode)
+srpat(char *utf8prompt, UCS *defpat, size_t defpatlen, int repl_mode, int bsearch)
{
register int s;
int i = 0;
UCS *b;
UCS prompt[NPMT];
UCS *promptp;
- EXTRAKEYS menu_pat[8];
+ EXTRAKEYS menu_pat[9];
menu_pat[i = 0].name = "^Y";
menu_pat[i].label = N_("FirstLine");
@@ -643,13 +648,24 @@ srpat(char *utf8prompt, UCS *defpat, size_t defpatlen, int repl_mode)
KS_OSDATASET(&menu_pat[i], KS_NONE);
}
+ menu_pat[++i].name = "^P";
+ menu_pat[i].label = bsearch ? N_("Forward") : N_("Backward") ;
+ menu_pat[i].key = (CTRL|'P');
+ KS_OSDATASET(&menu_pat[i], KS_NONE);
+
menu_pat[++i].name = NULL;
b = utf8_to_ucs4_cpystr(utf8prompt);
if(b){
ucs4_strncpy(prompt, b, NPMT);
prompt[NPMT-1] = '\0';
- fs_give((void **) &b);
+ if(bsearch){
+ fs_give((void **) &b);
+ b = utf8_to_ucs4_cpystr(N_(" backward"));
+ if(b) ucs4_strncat(prompt, b, ucs4_strlen(b));
+ prompt[NPMT-1] = '\0';
+ }
+ if(b) fs_give((void **) &b);
}
promptp = &prompt[ucs4_strlen(prompt)];
@@ -762,14 +778,14 @@ readnumpat(char *utf8prompt)
int
-readpattern(char *utf8prompt, int text_mode)
+readpattern(char *utf8prompt, int text_mode, int bsearch)
{
register int s;
int i;
UCS *b;
UCS tpat[NPAT+20];
UCS *tpatp;
- EXTRAKEYS menu_pat[7];
+ EXTRAKEYS menu_pat[8];
menu_pat[i = 0].name = "^Y";
menu_pat[i].label = N_("FirstLine");
@@ -803,13 +819,24 @@ readpattern(char *utf8prompt, int text_mode)
KS_OSDATASET(&menu_pat[i], KS_NONE);
}
+ menu_pat[++i].name = "^P";
+ menu_pat[i].label = bsearch ? N_("Forward") : N_("Backward") ;
+ menu_pat[i].key = (CTRL|'P');
+ KS_OSDATASET(&menu_pat[i], KS_NONE);
+
menu_pat[++i].name = NULL;
b = utf8_to_ucs4_cpystr(utf8prompt);
if(b){
ucs4_strncpy(tpat, b, NPAT+20);
tpat[NPAT+20-1] = '\0';
- fs_give((void **) &b);
+ if(bsearch){
+ fs_give((void **) &b);
+ b = utf8_to_ucs4_cpystr(N_(" backward"));
+ if(b) ucs4_strncat(tpat, b, ucs4_strlen(b));
+ tpat[NPAT+20-1] = '\0';
+ }
+ if(b) fs_give((void **) &b);
}
tpatp = &tpat[ucs4_strlen(tpat)];
@@ -858,6 +885,7 @@ readpattern(char *utf8prompt, int text_mode)
int
forscan(int *wrapt, /* boolean indicating search wrapped */
UCS *patrn, /* string to scan for */
+ int bsearch, /* search backwards */
LINE *limitp, /* stop searching if reached */
int limito, /* stop searching if reached */
int leavep) /* place to leave point
@@ -885,8 +913,23 @@ forscan(int *wrapt, /* boolean indicating search wrapped */
*
* first, test to see if we are at the end of the line,
* otherwise start searching on the next character.
+ * For a backward search, test if we are at the beginning
+ * of a line, and move backward in this case.
*/
- if(curwp->w_doto == llength(curwp->w_dotp)){
+ if(bsearch){
+ if(curwp->w_doto == 0){
+ stopline = curline = lback(curwp->w_dotp);
+ stopoff = curoff = llength(stopline);
+ if (stopline == curbp->b_linep)
+ *wrapt = TRUE;
+ }
+ else{
+ stopoff = curoff = curwp->w_doto;
+ stopline = curline = curwp->w_dotp;
+ }
+ }
+ else {
+ if(curwp->w_doto == llength(curwp->w_dotp)){
/*
* dot is not on end of a line
* start at 0 offset of the next line
@@ -895,10 +938,11 @@ forscan(int *wrapt, /* boolean indicating search wrapped */
stopline = curline = lforw(curwp->w_dotp);
if (curwp->w_dotp == curbp->b_linep)
*wrapt = TRUE;
- }
- else{
+ }
+ else{
stopoff = curoff = curwp->w_doto;
stopline = curline = curwp->w_dotp;
+ }
}
/* scan each character until we hit the head link record */
@@ -908,7 +952,8 @@ forscan(int *wrapt, /* boolean indicating search wrapped */
*/
while (curline){
- if (curline == curbp->b_linep)
+ if ((bsearch && lback(curline) == curbp->b_linep)
+ || (!bsearch && curline == curbp->b_linep))
*wrapt = TRUE;
/* save the current position in case we need to
@@ -917,29 +962,39 @@ forscan(int *wrapt, /* boolean indicating search wrapped */
lastline = curline;
lastoff = curoff;
- /* get the current character resolving EOLs */
- if (curoff == llength(curline)) { /* if at EOL */
+ if(bsearch){
+ if (curoff == -1) { /* if at BOL */
+ curline = lback(curline); /* skip to next line */
+ curoff = llength(curline) - 1;
+ c = '\0';
+ }
+ else
+ c = lgetc(curline, curoff--).c; /* get the char */
+ } else {
+ /* get the current character resolving EOLs */
+ if (curoff == llength(curline)) { /* if at EOL */
curline = lforw(curline); /* skip to next line */
curoff = 0;
c = '\n'; /* and return a <NL> */
+ }
+ else
+ c = lgetc(curline, curoff++).c; /* get the char */
}
- else
- c = lgetc(curline, curoff++).c; /* get the char */
/* test it against first char in pattern */
if (eq(c, patrn[0]) != FALSE) { /* if we find it..*/
/* setup match pointers */
matchline = curline;
- matchoff = curoff;
+ matchoff = bsearch ? curoff + 2 : curoff;
patptr = &patrn[0];
/* scan through patrn for a match */
while (*++patptr != '\0') {
/* advance all the pointers */
- if (matchoff == llength(matchline)) {
+ if (matchoff >= llength(matchline)) {
/* advance past EOL */
matchline = lforw(matchline);
- matchoff = 0;
+ matchoff = 0;
c = '\n';
} else
c = lgetc(matchline, matchoff++).c;
@@ -1027,11 +1082,15 @@ expandp(UCS *srcstr, /* string to expand */
* pointers to the word in cb
*/
void
-chword(UCS *wb, UCS *cb)
+chword(UCS *wb, UCS *cb, int bsearch)
{
- ldelete((long) ucs4_strlen(wb), NULL); /* not saved in kill buffer */
- while(*cb != '\0')
+ long l;
+ ldelete(ucs4_strlen(wb), NULL); /* not saved in kill buffer */
+ for(l = 0L; *cb != '\0'; l++)
linsert(1, *cb++);
+ if(bsearch)
+ backchar(0, l);
+
curwp->w_flag |= WFEDIT;
}
diff --git a/pico/word.c b/pico/word.c
index e5b361b7..1f176ab3 100644
--- a/pico/word.c
+++ b/pico/word.c
@@ -517,7 +517,7 @@ quote_match(UCS *q, LINE *gl, UCS *bufl, size_t buflen)
do_quote_match(q, gl, bufl, buflen); /* given line */
do_quote_match(q, nl, bufn, sizeof(bufn)); /* next line */
- if(!ucs4_strcmp(bufp, bufl))
+ if(!ucs4_strcmp(bufp, bufl) || !ucs4_strcmp(bufl, bufn))
return ucs4_strlen(bufl);
/* is this line quoted? */