/* * STevie - ST editor for VI enthusiasts. ...Tim Thompson...twitch!tjt... */ #include #include #include "stevie.h" /* * opencmd * * Add a blank line below the current line. */ opencmd() { /* get to the end of the current line */ while ( Curschar= Fileend ) Curschar = Fileend-1; /* Add the blank line */ appchar('\n'); } issepchar(c) char c; { if ( strchr(WORDSEP,c) != NULL ) return(1); return(0); } cntlines(pbegin,pend) char *pbegin, *pend; { int lnum = 1; char *p; for ( p=pbegin; p 0 ) { if ( (p=nextline(Curschar)) == NULL ) break; Curschar = p; } } Topchar = Curschar; for ( n=0; n1 ) Curschar--; if ( k == 1 ) Curschar--; beginline(); message(""); updatescreen(); } inschar(c) int c; { register char *p; /* Move everything in the file over to make */ /* room for the new char. */ if ( ! canincrease(1) ) return; for ( p=Fileend; p>Curschar; p-- ) { *p = *(p-1); } *Curschar++ = c; Fileend++; CHANGED; } insstr(s) char *s; { register char *p; int k, n = strlen(s); /* Move everything in the file over to make */ /* room for the new string. */ if ( ! canincrease(n) ) return; for ( p=Fileend-1+n; p>Curschar; p-- ) { *p = *(p-n); } for ( k=0; kendp; p-- ) { *p = *(p-1); } *(++Curschar) = c; Fileend++; CHANGED; } canincrease(n) int n; { if ( (Fileend+n) >= Filemax ) { message("Can't add anything, file is too big!"); State = NORMAL; return(0); } return(1); } #define NULL 0 delchar() { char *p; /* Check for degenerate case; there's nothing in the file. */ if ( Filemem == Fileend ) return; /* Delete the character at Curschar by shifting everything */ /* in the file down. */ for ( p=Curschar+1; pFilemem && *(Curschar-1)!='\n' ) Curschar--; Fileend--; CHANGED; } delword(deltrailing) int deltrailing; /* 1 if trailing white space should be removed. */ { int c = *Curschar; char *p = Undobuff; /* The Undo string is an 'i'nsert of the word we're deleting. */ *p++ = 'i'; /* If we're positioned on a word separator... */ if ( issepchar(c) && ! isspace(c) ) { /* If we're on a non-space separator, remove */ /* the separators and any following space. */ while ( issepchar(c) && ! isspace(c) ) { /* Add the deleted character to the Undobuff */ *p++ = *Curschar; delchar(); c = *Curschar; } } else { /* we're positioned in the middle of a word */ int endofline = 0; while ( ! issepchar(*Curschar) && *Curschar != '\n' ) { /* If the next char is a newline, we note */ /* that fact here, because delchar() won't */ /* position us there afterword. */ if ( *(Curschar+1) == '\n' ) endofline = 1; /* Add the deleted character to the Undobuff */ *p++ = *Curschar; delchar(); if ( endofline ) break; } } if ( deltrailing ) { /* remove any trailing white space */ while ( isspace(*Curschar) && *Curschar != '\n' ) { /* Add the deleted character to the Undobuff */ *p++ = *Curschar; delchar(); } } *p++ = '\033'; *p = '\0'; } delline(nlines) { int nchars; char *p, *q; /* If we're not at the beginning of the line, get there. */ if ( *Curschar != '\n' ) { /* back up to the previous newline (or the beginning */ /* of the file. */ while ( Curschar > Filemem ) { if ( *Curschar == '\n' ) { Curschar++; break; } Curschar--; } } message("Deleting..."); while ( nlines-- > 0 ) { /* Count the characters in the line */ for ( nchars=1,p=Curschar; p= Fileend ) { if ( (Curschar=prevline(Curschar)) == NULL ) Curschar = Filemem; /* and don't try to delete any more lines */ break; } } message(""); } char *strchr(s,c) char *s; int c; { do { if ( *s == c ) return(s); } while (*s++); return(NULL); }