home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
SDGETTB.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-14
|
2KB
|
110 lines
/*
sdgettb.c
% sed_GetTB
C-scape 3.2
Copyright (c) 1988-1989, by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
4/29/89 jdc added attr support
5/17/89 jdc changed len names and fixed total_len += get_len
5/23/89 jdc fixed buf_len-- for terminating NULL
8/04/89 jdc added tb->cursor_set check (ted_Follow loop bug)
3/28/90 jmd ansi-fied
4/05/90 jdc fixed hardline bug
12/13/90 jdc/jra ADDED: buf_len check and decrement
*/
#include "sed.h"
#include "tbpriv.h"
#include "teddecl.h"
unsigned int _sed_gettb(sed_type sed, char *buf, unsigned buf_len, int mode, byte *attr)
/*
mode == TED_HARD or TED_SOFT
*/
{
unsigned int total_len, line_len, get_len, attr_len, col, off;
int ref, hard;
long cursor;
bblock_type b;
ref = ted_GetRefresh(sed);
if (!sed_GetTextbuf(sed)->cursor_set) {
total_len = 0;
goto QUIT;
}
ted_SetRefresh(sed, TED_NOREFRESH);
cursor = ted_GetCursor(sed);
col = tb_GetCursor(sed_GetTextbuf(sed));
/* move through textbuf by lines,
add '\n''s if wrapped and mode == TED_HARD
*/
for (total_len = 0, b = sed_GetTextbuf(sed)->bbc->b;
(line_len = ted_GetLineLen(sed)) > 0;
col = 0) {
hard = ted_IsHardLine(sed);
line_len -= col;
off = b->off + col;
while (off >= b->len) {
off -= b->len;
b = b->next;
}
/* move through line by blocks,
check for attr changes if attr != NULL
*/
for (get_len = line_len;
line_len > 0;
line_len -= get_len, col += get_len) {
if (attr != NULL && (attr_len = b->len - off) <= get_len) {
get_len = attr_len;
}
if (get_len > buf_len) {
get_len = buf_len;
}
if (attr != NULL) {
*attr = b->attr;
}
total_len += ted_GetString(sed, buf, get_len);
cursor += (long)get_len;
buf_len -= get_len;
buf += get_len;
off += get_len;
if (!ted_GotoCursor(sed, cursor) /* end of textbuf */
|| buf_len <= 0) { /* end of buf */
goto QUIT;
}
while (off >= b->len) {
if (attr != NULL && b->next->attr != b->attr) {
goto QUIT; /* attr change */
}
off -= b->len;
b = b->next;
}
}
/* jra ADDED: buf_len check and decrement */
/* to avoid buffer overrun */
if (mode == TED_HARD && !hard && buf_len > 0) {
*buf++ = '\n';
total_len++;
buf_len--;
}
}
QUIT:
*buf = '\0';
ted_SetRefresh(sed, ref);
return(total_len);
}