8000 minix/commands/elvis/cut.c at R3.2.0 · lukegithub/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
700 lines (605 loc) · 13.2 KB

cut.c

File metadata and controls

700 lines (605 loc) · 13.2 KB
cbname = '\0';
return MARK_UNSET;
}
cbname = '\0';
/* adjust the insertion MARK for "after" and line-mode cuts */
if (cb->lnmode)
{
at &= ~(BLKSIZE - 1);
if (after)
{
at += BLKSIZE;
}
}
else if (after)
{
/* careful! if markidx(at) == 0 we might be pasting into an
* empty line -- so we can't blindly increment "at".
*/
if (markidx(at) == 0)
{
pfetch(markline(at));
if (plen != 0)
{
at++;
}
}
else
{
at++;
}
}
/* put a copy of the "at" mark in the mark[] array, so it stays in
* sync with changes made via add().
*/
mark[27] = at;
/* simple one-block paste? */
if (cb->nblks == 1)
{
/* get the block */
readcutblk(cb, 0);
/* isolate the text we need within it */
if (cb->end)
{
tmpblk.c[cb->end] = '\0';
}
/* insert it */
ChangeText
{
add(at, &tmpblk.c[cb->start]);
}
}
else
{
/* multi-block paste */
ChangeText
{
i = cb->nblks - 1;
/* add text from the last block first */
if (cb->end > 0)
{
readcutblk(cb, i);
tmpblk.c[cb->end] = '\0';
add(at, tmpblk.c);
i--;
}
/* add intervening blocks */
while (i > 0)
{
readcutblk(cb, i);
add(at, tmpblk.c);
i--;
}
/* add text from the first cut block */
readcutblk(cb, 0);
add(at, &tmpblk.c[cb->start]);
}
}
/* Reporting... */
rptlines = markline(mark[27]) - markline(at);
rptlabel = "pasted";
/* return the mark at the beginning/end of inserted text */
if (retend)
{
return mark[27] - 1L;
}
return at;
}
#ifndef NO_AT
/* This function copies characters from a cut buffer into a string.
* It returns the number of characters in the cut buffer. If the cut
* buffer is too large to fit in the string (i.e. if cb2str() returns
* a number >= size) then the characters will not have been copied.
* It returns 0 if the cut buffer is empty, and -1 for invalid cut buffers.
*/
int cb2str(name, buf, size)
int name; /* the name of a cut-buffer to get: a-z only! */
char *buf; /* where to put the string */
unsigned size; /* size of buf */
{
REG struct cutbuf *cb;
REG char *src;
REG char *dest;
/* decide which cut buffer to use */
if (name >= 'a' && name <= 'z')
{
cb = &named[name - 'a'];
}
else
{
return -1;
}
/* if the buffer is empty, return 0 */
if (cb->nblks == 0)
{
return 0;
}
/* !!! if not a single-block cut, then fail */
if (cb->nblks != 1)
{
return size;
}
/* if too big, return the size now, without doing anything */
if (cb->end - cb->start >= size)
{
return cb->end - cb->start;
}
/* get the block */
readcutblk(cb, 0);
/* isolate the string within that blk */
if (cb->start == 0)
{
tmpblk.c[cb->end] = '\0';
}
else
{
for (dest = tmpblk.c, src = dest + cb->start; src < tmpblk.c + cb->end; )
{
*dest++ = *src++;
}
*dest = '\0';
}
/* copy the string into the buffer */
if (buf != tmpblk.c)
{
strcpy(buf, tmpblk.c);
}
/* return the length */
return cb->end - cb->start;
}
#endif
0