home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
TEDSTRIP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-29
|
3KB
|
123 lines
/*
tedstrip.c
% ted_StripWhiteSpace (fresh and nasty)
C-scape 3.2
Copyright (c) 1989 by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
1/21/89 jdc preened
3/20/90 jmd fixed conversion of bitfield to long
3/28/90 jmd ansi-fied
4/16/90 jdc got rid of conversion warning
10/28/90 jdc fixed boolean/int ret conflict
*/
#include "ted.h"
boolean ted_StripWhiteSpace(sed_type sed)
/*
strips all trailing-one-color white space from a sed's textbuffer
returns: TRUE or FALSE
*/
{
int ref, i, row, crow, ccol, len, space;
int dlen, delrow;
boolean hit = FALSE;
byte attr;
tb_type tb;
bbpeek_struct bp;
/* strip the children */
for (i = 0; i < sed_GetFieldCount(sed); i++) {
if (obj_Who(sed_GetFieldBob(sed, i), ID_SEDWIN)) {
ted_StripWhiteSpace(sed_GetFieldBob(sed, i));
}
}
ted_GetPosition(sed, &crow, &ccol);
ref = ted_GetRefresh(sed);
ted_SetRefresh(sed, TED_NOREFRESH);
ted_GoBottom(sed);
ted_GoHome(sed);
tb = sed_GetTextbuf(sed);
for (row = tb_GetRow(tb), delrow = TRUE, attr = tb->bbc->b->attr;
row >= 0; row--) {
ted_GotoPosition(sed, row, 0);
if (!tb->nend) {
continue;
}
bp.b = tb->bbc->b;
bp.len = tb->len;
bp.off = bp.b->off;
for (space = 0, i = 0, len = 0; bp.len > 0;) {
for (dlen = bbpeek(&bp); dlen > 0;
dlen--, bp.off++, bp.len--, bp.p++) {
switch (*bp.p) {
case '\n':
if (bp.b->attr != attr
|| (bp.off == 0 && bp.b->prev != NULL && bp.b->attr != bp.b->prev->attr)) {
delrow = FALSE;
space = i;
attr = bp.b->attr;
dlen = 0;
}
break;
case '\t':
case ' ':
case '\r':
if (bp.b->attr != attr) {
space = i;
len = (int)bp.len - (tb->nend ? 1 : 0);
delrow = FALSE;
attr = (dlen == 1) ? bp.b->next->attr : bp.b->attr;
}
if (*bp.p == '\t') {
i += tb->tab_size - (i % tb->tab_size) - 1;
}
i++;
break;
default:
i++;
space = i;
len = 0;
delrow = FALSE;
attr = (dlen == 1) ? bp.b->next->attr : bp.b->attr;
break;
}
}
}
if (delrow) {
ted_DeleteString(sed, row, 0, tb->len);
hit = TRUE;
}
else if (space < tb->exp_len - 1) {
ted_DeleteString(sed, row, space, len);
hit = TRUE;
}
}
if (hit) {
menu_SetDirty(sed_GetMenu(sed), TRUE);
}
ted_GotoPosition(sed, crow, ccol);
ted_SetRefresh(sed, ref);
return(hit);
}