eefed.c

Go to the documentation of this file.
00001 /* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
00002  *      This software is quasi-public; it may be used freely with
00003  *      like software, but may NOT be sold or made part of licensed
00004  *      products without permission of the author.
00005  */
00006 /*      EEFED - ED-type functions
00007  */
00008 #include "elle.h"
00009 
00010 /*
00011  * ED_INSERT -- Insert character given as argument.
00012  */
00013 
00014 ed_insert(c)
00015 int c;
00016 {       register SBBUF *sb;
00017 
00018         sb = (SBBUF *) cur_buf;         /* For a little speed */
00019         sb_putc(sb,c);          /* Insert the char */
00020         cur_dot++;              /* Advance dot */
00021         buf_tmod((chroff)-1);   /* Mark buffer modified, for redisplay etc. */
00022                                 /* Perhaps later use specialized routine? */
00023 }
00024 
00025 ed_insn(ch, cnt)
00026 int ch, cnt;
00027 {       register int i;
00028         if((i = cnt) > 0)
00029                 do { ed_insert(ch);
00030                   } while(--i);
00031 }
00032 
00033 ed_crins()
00034 {
00035 #if FX_EOLMODE
00036         if (eolcrlf(cur_buf))   /* If EOL is made of CR-LF */
00037                 ed_insert(CR);  /* then first insert CR, then drop down to */
00038 #endif
00039         ed_insert(LF);          /* Insert LF */
00040 }
00041 
00042 
00043 ed_sins (s)                            /* insert this string */
00044 register char *s;
00045 {       register c;
00046         while (c = *s++)
00047                 ed_insert (c);
00048 }
00049 
00050 ed_nsins (s, i)         /* Insert string of N chars */
00051 register char *s;
00052 register int i;
00053 {       if(i > 0)
00054                 do { ed_insert(*s++); } while(--i);
00055 }
00056 
00057 /* ED_INDTO(col) - Indent to specified column.
00058 **      Finds current cursor position, and inserts tabs and spaces
00059 ** so cursor ends up at column goal.  Does nothing if already at or past
00060 ** specified column.
00061 */
00062 
00063 ed_indto(goal)
00064 register int goal;
00065 {       register int ng;
00066 
00067         ng = goal & ~07;                /* Get distance to tab stop */
00068         ed_insn(TAB, ((ng - (d_curind() & ~07)) >> 3));
00069         ed_insn(SP, goal-ng);
00070 }
00071 
00072 /* Oddball routine - Set cur_dot to actual I/O location and
00073  * tell display that cursor probably moved.  This is not really a
00074  * function of itself; it provides support for real functions.
00075  */
00076 ed_setcur()
00077 {       e_setcur();     /* Set cur_dot */
00078         redp(RD_MOVE);  /* Alert redisplay to check cursor loc */
00079 }
00080 
00081 /* Go to given dot */
00082 ed_go (dot)
00083 chroff dot;
00084 {       e_go(dot);
00085         ed_setcur();
00086 }
00087 
00088 /* Go to given offset from current location */
00089 ed_goff(off)
00090 chroff off;
00091 {       e_goff(off);
00092         ed_setcur();
00093 }
00094 
00095 /* Go to given INTEGER offset from current location */
00096 ed_igoff(ioff)
00097 int ioff;
00098 {       e_igoff(ioff);
00099         ed_setcur();
00100 }
00101 
00102 /* Reset (delete all of) Buffer
00103  * Should buffer be marked modified or not? Currently isn't.
00104  */
00105 ed_reset()
00106 {       if(e_blen() == 0)
00107                 return;         /* Already empty */
00108         e_reset();
00109         cur_dot = 0;
00110         cur_win->w_topldot = 0; /* Is this necessary? */
00111 #if IMAGEN
00112         redp(RD_WINRES|RD_REDO);
00113 #else
00114         redp(RD_WINRES);        /* This window needs complete update */
00115 #endif /*-IMAGEN*/
00116 
00117 /*      buf_mod(); */           /* Mark modified ?? */
00118 /*      mark_p = 0; */          /* Say no mark set ?? */
00119 }
00120 
00121 ed_deln(off)
00122 chroff off;
00123 {       chroff dot;
00124         dot = e_dot();
00125         e_goff(off);    
00126         ed_delete(e_dot(), dot);
00127 }
00128 
00129 /* ED_DELETE(dot1,dot2) -  Delete all characters between the two
00130  *      positions indicated by dot1 and dot2.  Their order does not
00131  *      matter; cur_dot and mark_dot are updated as necessary.
00132  */
00133 ed_delete(dot1,dot2)
00134 chroff dot1,dot2;
00135 {       chroff tmpdot, savdot;
00136 
00137         if(dot1 > dot2)
00138           {     tmpdot = dot1;
00139                 dot1 = dot2;
00140                 dot2 = tmpdot;
00141           }
00142         e_go(dot1);
00143         tmpdot = dot2-dot1;
00144         sb_deln((SBBUF *)cur_buf,tmpdot);
00145 
00146         savdot = cur_dot;               /* Save cur_dot value */
00147         cur_dot = dot1;                 /* so can set up for */
00148         buf_tmod((chroff)0);            /* call to update disp-change vars */
00149         cur_dot = savdot;
00150 
00151         if(cur_dot >= dot2)
00152                 cur_dot -= tmpdot;
00153         else if(cur_dot > dot1)
00154                 cur_dot = dot1;
00155         if(mark_dot >= dot2)
00156                 mark_dot -= tmpdot;
00157         else if(mark_dot > dot1)
00158                 mark_dot = dot1;
00159         e_gocur();
00160 }
00161 
00162 /* ED_KILL(dot1,dot2) - Kill (save and delete) text between two places in
00163  *      the buffer.
00164  * We assume we are deleting from dot1 to dot2, thus if dot1 > dot2
00165  * then backwards deletion is implied, and the saved text is prefixed
00166  * (instead of appended) to any previously killed text.
00167  */
00168 ed_kill(dot1,dot2)
00169 chroff dot1,dot2;
00170 {       register SBSTR *sd, *sdo;
00171         SBSTR *e_copyn();
00172 
00173         e_go(dot1);
00174         sd = e_copyn(dot2-dot1);
00175         if(sd == 0) return;
00176         if(last_cmd == KILLCMD && (sdo = kill_ring[kill_ptr]))
00177           {     if(dot1 > dot2) /* Prefix new killed stuff onto old stuff */
00178                   {     sbs_app(sd,sdo);
00179                         kill_ring[kill_ptr] = sd;
00180                   }
00181                 else            /* Append new stuff to old stuff */
00182                         sbs_app(sdo,sd);
00183           }
00184         else kill_push(sd);
00185         ed_delete(dot1,dot2);
00186 }
00187 
00188 kill_push(sdp)
00189 SBSTR *sdp;
00190 {       register SBSTR *sd;
00191 
00192         if(++kill_ptr >= KILL_LEN) kill_ptr = 0;
00193         if(sd = kill_ring[kill_ptr])
00194                 sbs_del(sd);
00195         kill_ring[kill_ptr] = sdp;
00196 }
00197 
00198 
00199 #define isupper(c) (('A' <= c) && (c <= 'Z'))
00200 #define islower(c) (('a' <= c) && (c <= 'z'))
00201 #define toupper(c) (c + ('A' - 'a'))
00202 #define tolower(c) (c + ('a' - 'A'))
00203 
00204 #if FX_UCWORD||FX_LCWORD||FX_UCIWORD||FX_UCREG||FX_LCREG
00205 
00206 /* ED_CASE(dot1,dot2,downp) - Change the case within a region.
00207  *      downp = 0 for uppercase, 1 for lowercase, 2 for capitalize.
00208  */
00209 ed_case(dot1, dot2, downp)
00210 chroff dot1, dot2;
00211 int downp;
00212 {       chroff dcnt;
00213         register int c, a, z;
00214         int modflg;
00215 
00216         modflg = 0;
00217         if((dcnt = dot2 - dot1) < 0)
00218           {     dcnt = dot1;
00219                 dot1 = dot2;
00220                 dot2 = dcnt;
00221                 dcnt -= dot1;
00222           }
00223         e_go(dot1);
00224 
00225         if(downp==2)
00226           {     a = 0;  /* 0 looking for wd, 1 in word */
00227                 while(--dcnt >= 0)
00228                   {     if(delimp(c = e_getc()))        /* Char in wd? */
00229                           {     a = 0;                  /* No */
00230                                 continue;
00231                           }
00232                          if(a)          /* If already inside word */
00233                           {     if(isupper(c))
00234                                         c = tolower(c);
00235                                 else continue;
00236                           }
00237                         else    /* If encountered start of word */
00238                           {     a = 1;
00239                                 if(islower(c))
00240                                         c = toupper(c);
00241                                 else continue;
00242                           }
00243                         e_backc();
00244                         e_ovwc(c);
00245                         modflg++;
00246                   }
00247                 goto casdon;
00248           }
00249         if(downp==0)
00250           {     a = 'a';                /* Convert to lower case */
00251                 z = 'z';
00252                 downp = -040;
00253           }
00254         else
00255           {     a = 'A';                /* Convert to upper case */
00256                 z = 'Z';
00257                 downp = 040;
00258           }
00259         while(--dcnt >= 0)
00260           {     if(a <= (c = e_getc()) && c <= z)
00261                   {     e_backc();
00262                         e_ovwc(c+downp);
00263                         modflg++;
00264                   }
00265           }
00266 
00267 casdon: dot2 = cur_dot;                 /* Save dot */
00268         e_setcur();                     /* Set up for modification range chk*/
00269         if(modflg)
00270                 buf_tmat(dot1);         /* Stuff munged from there to here */
00271         ed_go(dot2);
00272 }
00273 #endif /* any ed_case caller */
00274 
00275 
00276 /* UPCASE(c) - Return upper-case version of character */
00277 upcase(ch)
00278 int ch;
00279 {       register int c;
00280         c = ch&0177;
00281         return(islower(c) ? toupper(c) : c);
00282 }
00283 

Generated on Fri Apr 14 22:56:48 2006 for minix by  doxygen 1.4.6