summaryrefslogtreecommitdiff
path: root/pico/basic.c
diff options
context:
space:
mode:
Diffstat (limited to 'pico/basic.c')
-rw-r--r--pico/basic.c378
1 files changed, 351 insertions, 27 deletions
diff --git a/pico/basic.c b/pico/basic.c
index 49b04bd6..4479d099 100644
--- a/pico/basic.c
+++ b/pico/basic.c
@@ -26,9 +26,10 @@ static char rcsid[] = "$Id: basic.c 831 2007-11-27 01:04:19Z hubert@u.washington
* framing, are hard.
*/
#include "headers.h"
-
+#include "../pith/osdep/color.h"
#include "osdep/terminal.h"
+int indent_match(char **, LINE *, char *, int, int);
/*
* Move the cursor to the
@@ -285,7 +286,7 @@ int
gotobop(int f, int n)
{
int quoted, qlen;
- UCS qstr[NLINE], qstr2[NLINE];
+ char qstr[NLINE], qstr2[NLINE], ind_str[NLINE], pqstr[NLINE];;
if (n < 0) /* the other way...*/
return(gotoeop(f, -n));
@@ -297,6 +298,14 @@ gotobop(int f, int n)
curwp->w_dotp = lback(curwp->w_dotp);
curwp->w_doto = 0;
}
+
+ if (indent_match(default_qstr(glo_quote_str, 1), curwp->w_dotp,ind_str, NLINE, 0)){
+ if (n){ /* look for another paragraph ? */
+ curwp->w_dotp = lback(curwp->w_dotp);
+ continue;
+ }
+ break;
+ }
/* scan line by line until we come to a line ending with
* a <NL><NL> or <NL><TAB> or <NL><SPACE>
@@ -304,20 +313,58 @@ gotobop(int f, int n)
* PLUS: if there's a quote string, a quoted-to-non-quoted
* line transition.
*/
- quoted = glo_quote_str ? quote_match(glo_quote_str, curwp->w_dotp, qstr, NLINE) : 0;
- qlen = quoted ? ucs4_strlen(qstr) : 0;
+ quoted = quote_match(default_qstr(glo_quote_str, 1), curwp->w_dotp, qstr, NLINE, 0);
+ qlen = quoted ? strlen(qstr) : 0;
while(lback(curwp->w_dotp) != curbp->b_linep
&& llength(lback(curwp->w_dotp)) > qlen
- && (glo_quote_str
- ? (quoted == quote_match(glo_quote_str,
- lback(curwp->w_dotp),
- qstr2, NLINE)
- && !ucs4_strcmp(qstr, qstr2))
- : 1)
- && lgetc(curwp->w_dotp, qlen).c != TAB
- && lgetc(curwp->w_dotp, qlen).c != ' ')
+ && (quoted == quote_match(default_qstr(glo_quote_str, 1),
+ lback(curwp->w_dotp), qstr2, NLINE, 0))
+ && !strcmp(qstr, qstr2) /* processed string */
+ && (quoted == quote_match(default_qstr(glo_quote_str, 1),
+ lback(curwp->w_dotp), qstr2, NLINE, 1))
+ && !strcmp(qstr, qstr2) /* raw string */
+ && !indent_match(default_qstr(glo_quote_str, 1),
+ lback(curwp->w_dotp),ind_str, NLINE, 0)
+ && !ISspace(lgetc(curwp->w_dotp, qlen).c))
curwp->w_dotp = lback(curwp->w_dotp);
+ /*
+ * Ok, we made it here and we assume that we are at the begining
+ * of the paragraph. Let's double check this now. In order to do
+ * so we shell check if the first line was indented in a special
+ * way.
+ */
+ if(lback(curwp->w_dotp) == curbp->b_linep)
+ break;
+ else{
+ int i, j;
+
+ /*
+ * First we test if the preceding line is indented.
+ * for the following test we need to have the raw values,
+ * not the processed values
+ */
+ quote_match(default_qstr(glo_quote_str, 1), curwp->w_dotp, qstr, NLINE, 1);
+ quote_match(default_qstr(glo_quote_str, 1), lback(curwp->w_dotp), qstr2, NLINE, 1);
+ for (i = 0, j = 0;
+ qstr[i] && qstr2[i] && (qstr[i] == qstr2[i]); i++, j++);
+ for (; ISspace(qstr2[i]); i++);
+ for (; ISspace(qstr[j]); j++);
+ if ((indent_match(default_qstr(glo_quote_str, 1), lback(curwp->w_dotp),
+ ind_str, NLINE, 1)
+ && (strlenis(qstr2)
+ + strlenis(ind_str) >= strlenis(qstr)))
+ || (lback(curwp->w_dotp) != curbp->b_linep
+ && llength(lback(curwp->w_dotp)) > qlen
+ && (quoted == quote_match(default_qstr(glo_quote_str, 1),
+ lback(curwp->w_dotp), pqstr, NLINE, 0))
+ && !strcmp(qstr, pqstr)
+ && !ISspace(lgetc(curwp->w_dotp, qlen).c)
+ && (strlenis(qstr2) > strlenis(qstr)))
+ && !qstr2[i] && !qstr[j])
+ curwp->w_dotp = lback(curwp->w_dotp);
+ }
+
if(n){
/* keep looking */
if(lback(curwp->w_dotp) == curbp->b_linep)
@@ -330,7 +377,7 @@ gotobop(int f, int n)
else{
/* leave cursor on first word in para */
curwp->w_doto = 0;
- while(ucs4_isspace(lgetc(curwp->w_dotp, curwp->w_doto).c))
+ while(ISspace(lgetc(curwp->w_dotp, curwp->w_doto).c))
if(++curwp->w_doto >= llength(curwp->w_dotp)){
curwp->w_doto = 0;
curwp->w_dotp = lforw(curwp->w_dotp);
@@ -344,6 +391,189 @@ gotobop(int f, int n)
return(TRUE);
}
+unsigned char GetAccent()
+{
+ UCS c,d;
+ c = GetKey();
+ if ((c == '?') || (c == '!')) {
+ d = c;
+ c = '\\';
+ }
+ else
+ if ((c == 's') || (c == 'S')){
+ c = d = 's';
+ }
+ else
+ if ((c == 'l') || (c == 'L')){
+ c = d = 'l';
+ }
+ else
+ d = GetKey();
+ return accent(c,d);
+}
+
+int pineaccent(f,n)
+ int f,n;
+{ unsigned char e;
+
+ if (e = GetAccent())
+ execute(e, 0, 1);
+ return 1;
+}
+
+unsigned char accent(f,n)
+UCS f,n;
+{ UCS c,d;
+
+ c = f;
+ d = n;
+ switch(c){
+ case '~' :
+ switch(d){
+ case 'a' : return '\343';
+ case 'n' : return '\361';
+ case 'o' : return '\365';
+ case 'A' : return '\303';
+ case 'N' : return '\321';
+ case 'O' : return '\325';
+ }
+ break;
+ case '\047' :
+ switch(d){
+ case 'a' : return '\341';
+ case 'e' : return '\351';
+ case 'i' : return '\355';
+ case 'o' : return '\363';
+ case 'u' : return '\372';
+ case 'y' : return '\375';
+ case 'A' : return '\301';
+ case 'E' : return '\311';
+ case 'I' : return '\315';
+ case 'O' : return '\323';
+ case 'U' : return '\332';
+ case 'Y' : return '\335';
+ }
+ break;
+ case '"' :
+ switch(d){
+ case 'a' : return '\344';
+ case 'e' : return '\353';
+ case 'i' : return '\357';
+ case 'o' : return '\366';
+ case 'u' : return '\374';
+ case 'y' : return '\377';
+ case 'A' : return '\304';
+ case 'E' : return '\313';
+ case 'I' : return '\317';
+ case 'O' : return '\326';
+ case 'U' : return '\334';
+ }
+ break;
+ case '^' :
+ switch(d){
+ case 'a' : return '\342';
+ case 'e' : return '\352';
+ case 'i' : return '\356';
+ case 'o' : return '\364';
+ case 'u' : return '\373';
+ case 'A' : return '\302';
+ case 'E' : return '\312';
+ case 'I' : return '\316';
+ case 'O' : return '\324';
+ case 'U' : return '\333';
+ case '0' : return '\260';
+ case '1' : return '\271';
+ case '2' : return '\262';
+ case '3' : return '\263';
+ }
+ break;
+ case '`' :
+ switch(d){
+ case 'a' : return '\340';
+ case 'e' : return '\350';
+ case 'i' : return '\354';
+ case 'o' : return '\362';
+ case 'u' : return '\371';
+ case 'A' : return '\300';
+ case 'E' : return '\310';
+ case 'I' : return '\314';
+ case 'O' : return '\322';
+ case 'U' : return '\331';
+ }
+ break;
+ case 'o' :
+ switch(d){
+ case 'a' : return '\345';
+ case 'A' : return '\305';
+ case '/' : return '\370';
+ case 'r' : return '\256';
+ case 'R' : return '\256';
+ case 'c' : return '\251';
+ case 'C' : return '\251';
+ }
+ break;
+ case '-' :
+ switch(d){
+ case 'o' : return '\272';
+ case 'O' : return '\272';
+ case '0' : return '\272';
+ case 'a' : return '\252';
+ case 'A' : return '\252';
+ case 'l' : return '\243';
+ case 'L' : return '\243';
+ }
+ break;
+ case 'O' :
+ switch(d){
+ case '/' : return '\330';
+ case 'r' : return '\256';
+ case 'R' : return '\256';
+ case 'c' : return '\251';
+ case 'C' : return '\251';
+ }
+ case '/' :
+ switch(d){
+ case 'o' : return '\370';
+ case 'O' : return '\330';
+ }
+ break;
+ case 'a' :
+ switch(d){
+ case 'e' : return '\346';
+ case 'E' : return '\346';
+ }
+ break;
+ case 'A' :
+ switch(d){
+ case 'E' : return '\306';
+ case 'e' : return '\306';
+ }
+ break;
+ case ',' :
+ switch(d){
+ case 'c' : return '\347';
+ case 'C' : return '\307';
+ }
+ break;
+ case '\\' :
+ switch(d){
+ case '?' : return '\277';
+ case '!' : return '\241';
+ }
+ break;
+ case 's' :
+ switch(d){
+ case 's' : return '\337';
+ }
+ break;
+ case 'l' :
+ switch(d){
+ case 'l' : return '\243';
+ }
+ break;
+ }
+ return '\0';
+}
/*
* go forword to the end of the current paragraph
@@ -353,8 +583,9 @@ gotobop(int f, int n)
int
gotoeop(int f, int n)
{
- int quoted, qlen;
- UCS qstr[NLINE], qstr2[NLINE];
+ int quoted, qlen, indented, changeqstr = 0;
+ int i,j, fli = 0; /* fli = first line indented a boolean variable */
+ char qstr[NLINE], qstr2[NLINE], ind_str[NLINE];
if (n < 0) /* the other way...*/
return(gotobop(f, -n));
@@ -367,27 +598,70 @@ gotoeop(int f, int n)
break;
}
+ /*
+ * We need to figure out if this line is the first line of
+ * a paragraph that has been indented in a special way. If this
+ * is the case, we advance one more line before we use the
+ * algorithm below
+ */
+
+ if(curwp->w_dotp != curbp->b_linep){
+ quote_match(default_qstr(glo_quote_str, 1), curwp->w_dotp, qstr, NLINE, 1);
+ quote_match(default_qstr(glo_quote_str, 1), lforw(curwp->w_dotp), qstr2, NLINE, 1);
+ indented = indent_match(default_qstr(glo_quote_str, 1), curwp->w_dotp, ind_str,
+ NLINE, 1);
+ if (strlenis(qstr)
+ + strlenis(ind_str) < strlenis(qstr2)){
+ curwp->w_doto = llength(curwp->w_dotp);
+ if(n){ /* this line is a paragraph by itself */
+ curwp->w_dotp = lforw(curwp->w_dotp);
+ continue;
+ }
+ break;
+ }
+ for (i=0,j=0; qstr[i] && qstr2[i] && (qstr[i] == qstr2[i]);i++,j++);
+ for (; ISspace(qstr[i]); i++);
+ for (; ISspace(qstr2[j]); j++);
+ if (!qstr[i] && !qstr2[j] && indented){
+ fli++;
+ if (indent_match(default_qstr(glo_quote_str, 1), lforw(curwp->w_dotp),
+ ind_str, NLINE, 0)){
+ if (n){ /* look for another paragraph ? */
+ curwp->w_dotp = lforw(curwp->w_dotp);
+ continue;
+ }
+ }
+ else{
+ if (!lisblank(lforw(curwp->w_dotp)))
+ curwp->w_dotp = lforw(curwp->w_dotp);
+ }
+ }
+ }
+
/* scan line by line until we come to a line ending with
* a <NL><NL> or <NL><TAB> or <NL><SPACE>
*
* PLUS: if there's a quote string, a quoted-to-non-quoted
* line transition.
*/
- quoted = glo_quote_str
- ? quote_match(glo_quote_str,
- curwp->w_dotp, qstr, NLINE) : 0;
- qlen = quoted ? ucs4_strlen(qstr) : 0;
+ /* if the first line is indented (fli == 1), then the test below
+ is on the second line, and in that case we will need the raw
+ string, not the processed string
+ */
+ quoted = quote_match(default_qstr(glo_quote_str, 1), curwp->w_dotp, qstr, NLINE, fli);
+ qlen = quoted ? strlen(qstr) : 0;
while(curwp->w_dotp != curbp->b_linep
&& llength(lforw(curwp->w_dotp)) > qlen
- && (glo_quote_str
- ? (quoted == quote_match(glo_quote_str,
- lforw(curwp->w_dotp),
- qstr2, NLINE)
- && !ucs4_strcmp(qstr, qstr2))
- : 1)
- && lgetc(lforw(curwp->w_dotp), qlen).c != TAB
- && lgetc(lforw(curwp->w_dotp), qlen).c != ' ')
+ && (quoted == quote_match(default_qstr(glo_quote_str, 1),
+ lforw(curwp->w_dotp), qstr2, NLINE, fli))
+ && !strcmp(qstr, qstr2)
+ && (quoted == quote_match(default_qstr(glo_quote_str, 1),
+ lforw(curwp->w_dotp), qstr2, NLINE, 1))
+ && !strcmp(qstr, qstr2)
+ && !indent_match(default_qstr(glo_quote_str, 1),
+ lforw(curwp->w_dotp), ind_str, NLINE, 0)
+ && !ISspace(lgetc(lforw(curwp->w_dotp), qlen).c))
curwp->w_dotp = lforw(curwp->w_dotp);
curwp->w_doto = llength(curwp->w_dotp);
@@ -684,7 +958,57 @@ scrolldownline(int f, int n)
return (scrollforw (1, FALSE));
}
+/* deltext deletes from the specified position until the end of the file
+ * or until the signature (when called from Pine), whichever comes first.
+ */
+int
+deltext (f,n)
+int f,n;
+{
+ LINE *currline = curwp->w_dotp;
+ static int firsttime = 0;
+
+ if ((lastflag&CFKILL) == 0)
+ kdelete();
+
+ curwp->w_markp = curwp->w_dotp;
+ curwp->w_marko = curwp->w_doto;
+
+ while (curwp->w_dotp != curbp->b_linep){
+ if ((Pmaster)
+ && (llength(curwp->w_dotp) == 3)
+ && (lgetc(curwp->w_dotp, 0).c == '-')
+ && (lgetc(curwp->w_dotp, 1).c == '-')
+ && (lgetc(curwp->w_dotp, 2).c == ' ')){
+ if (curwp->w_dotp == currline){
+ if (curwp->w_doto)
+ curwp->w_dotp = lforw(curwp->w_dotp);
+ else
+ break;
+ }
+ else{
+ curwp->w_dotp = lback(curwp->w_dotp);
+ curwp->w_doto = llength(curwp->w_dotp);
+ break;
+ }
+ }
+ else{
+ if(lforw(curwp->w_dotp) != curbp->b_linep)
+ curwp->w_dotp = lforw(curwp->w_dotp);
+ else{
+ curwp->w_doto = llength(curwp->w_dotp);
+ break;
+ }
+ }
+ }
+ killregion(FALSE,1);
+ lastflag |= CFKILL;
+ if(firsttime == 0)
+ emlwrite("Deleted text can be recovered with the ^U command", NULL);
+ firsttime = 1;
+ return TRUE;
+}
/*
* Scroll to a position.