=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mg/region.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- src/usr.bin/mg/region.c 2000/04/13 06:12:17 1.2 +++ src/usr.bin/mg/region.c 2000/09/01 14:59:09 1.3 @@ -1,63 +1,73 @@ /* * Region based commands. - * The routines in this file - * deal with the region, that magic space - * between "." and mark. Some functions are - * commands. Some functions are just for + * The routines in this file deal with the region, that magic space between + * "." and mark. Some functions are commands. Some functions are just for * internal use. */ -#include "def.h" +#include "def.h" + +static int getregion __P((REGION *)); +static int setsize __P((REGION *, RSIZE)); + /* - * Kill the region. Ask "getregion" - * to figure out the bounds of the region. + * Kill the region. Ask "getregion" to figure out the bounds of the region. * Move "." to the start, and kill the characters. */ /* ARGSUSED */ +int killregion(f, n) + int f, n; { - register int s; - REGION region; + int s; + REGION region; if ((s = getregion(®ion)) != TRUE) return (s); - if ((lastflag & CFKILL) == 0) /* This is a kill type */ - kdelete(); /* command, so do magic */ - thisflag |= CFKILL; /* kill buffer stuff. */ + /* This is a kill-type command, so do magic kill buffer stuff. */ + if ((lastflag & CFKILL) == 0) + kdelete(); + thisflag |= CFKILL; curwp->w_dotp = region.r_linep; curwp->w_doto = region.r_offset; return (ldelete(region.r_size, KFORW)); } /* - * Copy all of the characters in the - * region to the kill buffer. Don't move dot - * at all. This is a bit like a kill region followed - * by a yank. + * Copy all of the characters in the region to the kill buffer. Don't move + * dot at all. This is a bit like a kill region followed by a yank. */ /* ARGSUSED */ +int copyregion(f, n) + int f, n; { - register LINE *linep; - register int loffs; - register int s; - REGION region; - VOID kdelete(); + LINE *linep; + REGION region; + int loffs; + int s; if ((s = getregion(®ion)) != TRUE) return s; - if ((lastflag & CFKILL) == 0) /* Kill type command. */ + + /* kill type command */ + if ((lastflag & CFKILL) == 0) kdelete(); thisflag |= CFKILL; - linep = region.r_linep; /* Current line. */ - loffs = region.r_offset;/* Current offset. */ + + /* current line */ + linep = region.r_linep; + + /* current offset */ + loffs = region.r_offset; + while (region.r_size--) { if (loffs == llength(linep)) { /* End of line. */ if ((s = kinsert('\n', KFORW)) != TRUE) return (s); linep = lforw(linep); loffs = 0; - } else { /* Middle of line. */ + } else { /* Middle of line. */ if ((s = kinsert(lgetc(linep, loffs), KFORW)) != TRUE) return s; ++loffs; @@ -67,20 +77,19 @@ } /* - * Lower case region. Zap all of the upper - * case characters in the region to lower case. Use - * the region code to set the limits. Scan the buffer, - * doing the changes. Call "lchange" to ensure that - * redisplay is done in all buffers. + * Lower case region. Zap all of the upper case characters in the region to + * lower case. Use the region code to set the limits. Scan the buffer, doing + * the changes. Call "lchange" to ensure that redisplay is done in all + * buffers. */ /* ARGSUSED */ +int lowerregion(f, n) + int f, n; { - register LINE *linep; - register int loffs; - register int c; - register int s; - REGION region; + LINE *linep; + REGION region; + int loffs, c, s; if ((s = getregion(®ion)) != TRUE) return s; @@ -102,21 +111,19 @@ } /* - * Upper case region. Zap all of the lower - * case characters in the region to upper case. Use - * the region code to set the limits. Scan the buffer, - * doing the changes. Call "lchange" to ensure that - * redisplay is done in all buffers. + * Upper case region. Zap all of the lower case characters in the region to + * upper case. Use the region code to set the limits. Scan the buffer, + * doing the changes. Call "lchange" to ensure that redisplay is done in all + * buffers. */ /* ARGSUSED */ +int upperregion(f, n) + int f, n; { - register LINE *linep; - register int loffs; - register int c; - register int s; - REGION region; - VOID lchange(); + LINE *linep; + REGION region; + int loffs, c, s; if ((s = getregion(®ion)) != TRUE) return s; @@ -138,42 +145,42 @@ } /* - * This routine figures out the bound of the region - * in the current window, and stores the results into the fields - * of the REGION structure. Dot and mark are usually close together, - * but I don't know the order, so I scan outward from dot, in both - * directions, looking for mark. The size is kept in a long. At the - * end, after the size is figured out, it is assigned to the size - * field of the region structure. If this assignment loses any bits, - * then we print an error. This is "type independent" overflow - * checking. All of the callers of this routine should be ready to - * get an ABORT status, because I might add a "if regions is big, - * ask before clobberring" flag. + * This routine figures out the bound of the region in the current window, + * and stores the results into the fields of the REGION structure. Dot and + * mark are usually close together, but I don't know the order, so I scan + * outward from dot, in both directions, looking for mark. The size is kept + * in a long. At the end, after the size is figured out, it is assigned to + * the size field of the region structure. If this assignment loses any bits, + * then we print an error. This is "type independent" overflow checking. All + * of the callers of this routine should be ready to get an ABORT status, + * because I might add a "if regions is big, ask before clobberring" flag. */ +static int getregion(rp) - register REGION *rp; + REGION *rp; { - register LINE *flp; - register LINE *blp; - register long fsize; /* Long now. */ - register long bsize; + LINE *flp, *blp; + long fsize, bsize; if (curwp->w_markp == NULL) { ewprintf("No mark set in this window"); return (FALSE); } - if (curwp->w_dotp == curwp->w_markp) { /* "r_size" always ok. */ + + /* "r_size" always ok */ + if (curwp->w_dotp == curwp->w_markp) { rp->r_linep = curwp->w_dotp; if (curwp->w_doto < curwp->w_marko) { rp->r_offset = curwp->w_doto; - rp->r_size = (RSIZE) (curwp->w_marko - curwp->w_doto); + rp->r_size = (RSIZE)(curwp->w_marko - curwp->w_doto); } else { rp->r_offset = curwp->w_marko; - rp->r_size = (RSIZE) (curwp->w_doto - curwp->w_marko); + rp->r_size = (RSIZE)(curwp->w_doto - curwp->w_marko); } return TRUE; } - flp = blp = curwp->w_dotp; /* Get region size. */ + /* get region size */ + flp = blp = curwp->w_dotp; bsize = curwp->w_doto; fsize = llength(flp) - curwp->w_doto + 1; while (lforw(flp) != curbp->b_linep || lback(blp) != curbp->b_linep) { @@ -183,7 +190,7 @@ rp->r_linep = curwp->w_dotp; rp->r_offset = curwp->w_doto; return (setsize(rp, - (RSIZE) (fsize + curwp->w_marko))); + (RSIZE)(fsize + curwp->w_marko))); } fsize += llength(flp) + 1; } @@ -194,22 +201,22 @@ rp->r_linep = blp; rp->r_offset = curwp->w_marko; return (setsize(rp, - (RSIZE) (bsize - curwp->w_marko))); + (RSIZE)(bsize - curwp->w_marko))); } } } - ewprintf("Bug: lost mark"); /* Gak! */ + ewprintf("Bug: lost mark"); return FALSE; } /* * Set size, and check for overflow. */ +static int setsize(rp, size) - register REGION *rp; - register RSIZE size; + REGION *rp; + RSIZE size; { - rp->r_size = size; if (rp->r_size != size) { ewprintf("Region is too large"); @@ -218,7 +225,7 @@ return TRUE; } -#ifdef PREFIXREGION +#ifdef PREFIXREGION /* * Implements one of my favorite keyboard macros; put a string at the * beginning of a number of lines in a buffer. The quote string is @@ -228,23 +235,23 @@ */ #define PREFIXLENGTH 40 -static char prefix_string[PREFIXLENGTH] = {'>', '\0'}; +static char prefix_string[PREFIXLENGTH] = {'>', '\0'}; /* - * Prefix the region with whatever is in prefix_string. - * Leaves dot at the beginning of the line after the end - * of the region. If an argument is given, prompts for the - * line prefix string. + * Prefix the region with whatever is in prefix_string. Leaves dot at the + * beginning of the line after the end of the region. If an argument is + * given, prompts for the line prefix string. */ - /* ARGSUSED */ +int prefixregion(f, n) + int f, n; { - register int s; - register LINE *first, *last; - register int nline; - REGION region; - char *prefix = prefix_string; + LINE *first, *last; + REGION region; + char *prefix = prefix_string; + int nline; + int s; if ((f == TRUE) && ((s = setprefix(FFRAND, 1)) != TRUE)) return s; @@ -263,24 +270,25 @@ /* for each line, go to beginning and insert the prefix string */ while (nline--) { - (VOID) gotobol(FFRAND, 1); + (VOID)gotobol(FFRAND, 1); for (prefix = prefix_string; *prefix; prefix++) - (VOID) linsert(1, *prefix); - (VOID) forwline(FFRAND, 1); + (VOID)linsert(1, *prefix); + (VOID)forwline(FFRAND, 1); } - (VOID) gotobol(FFRAND, 1); + (VOID)gotobol(FFRAND, 1); return TRUE; } /* - * Set prefix string. + * Set line prefix string. */ - /* ARGSUSED */ +int setprefix(f, n) + int f, n; { - char buf[PREFIXLENGTH]; - register int s; + char buf[PREFIXLENGTH]; + int s; if (prefix_string[0] == '\0') s = ereply("Prefix string: ", buf, sizeof buf); @@ -288,9 +296,10 @@ s = ereply("Prefix string (default %s): ", buf, sizeof buf, prefix_string); if (s == TRUE) - (VOID) strcpy(prefix_string, buf); - if ((s == FALSE) && (prefix_string[0] != '\0')) /* CR -- use old one */ + (VOID)strcpy(prefix_string, buf); + /* CR -- use old one */ + if ((s == FALSE) && (prefix_string[0] != '\0')) s = TRUE; return s; } -#endif +#endif /* PREFIXREGION */