AcePerl
view release on metacpan or search on metacpan
acelib/arraysub.c view on Meta::CPAN
while ((long)s->ptr % STACK_ALIGNMENT)
*(s->ptr)++ = 0 ;
}
char* popText (Stack s)
{
char *base = s->a->base ;
while (s->ptr > base && !*--(s->ptr)) ;
while (s->ptr >= base && *--(s->ptr)) ;
return ++(s->ptr) ;
}
void catText (Stack s, char* text)
{
while (s->ptr + strlen(text) > s->safe)
stackExtend (s,strlen(text)+1) ;
*s->ptr = 0 ;
while (s->ptr >= s->a->base && *s->ptr == 0)
s->ptr -- ;
s->ptr ++ ;
while ((*(s->ptr)++ = *text++)) ;
if (!s->textOnly)
while ((long)s->ptr % STACK_ALIGNMENT)
*(s->ptr)++ = 0 ;
}
void catBinary (Stack s, char* data, int size)
{
int total;
total = size + 1;
while (s->ptr + total > s->safe)
stackExtend (s,size+1) ;
*s->ptr = 0 ;
while (s->ptr >= s->a->base && *s->ptr == 0)
s->ptr -- ;
s->ptr ++ ;
memcpy(s->ptr,data,size);
s->ptr += size;
/* end with a newline to prevent truncation by next cat */
*(s->ptr)++ = '\n';
if (!s->textOnly)
while ((long)s->ptr % STACK_ALIGNMENT)
*(s->ptr)++ = 0 ;
}
char* stackNextText (Stack s)
{ char *text = s->pos ;
if (text>= s->ptr)
return 0 ; /* JTM, so while stackNextText makes sense */
while (*s->pos++) ;
if (!s->textOnly)
while ((long)s->pos % STACK_ALIGNMENT)
++s->pos ;
return text ;
}
/*********/
/* Push text in stack s, after breaking it on delimiters */
/* You can later access the tokens with command
while (token = stackNextText(s)) work on your tokens ;
*/
void stackTokeniseTextOn(Stack s, char *text, char *delimiters)
{
char *cp, *cq , *cend, *cd, old, oldend ;
int i, n ;
if(!stackExists(s) || !text || !delimiters)
messcrash("stackTextOn received some null parameter") ;
n = strlen(delimiters) ;
cp = cq = text ;
while(TRUE)
{
while(*cp == ' ')
cp++ ;
cq = cp ;
old = 0 ;
while(*cq)
{ for (cd = delimiters, i = 0 ; i < n ; cd++, i++)
if (*cd == *cq)
{ old = *cq ;
*cq = 0 ;
goto found ;
}
cq++ ;
}
found:
cend = cq ;
while(cend > cp && *--cend == ' ') ;
if (*cend != ' ') cend++ ;
oldend = *cend ; *cend = 0 ;
if (*cp && cend > cp)
pushText(s,cp) ;
*cend = oldend ;
if(!old)
{ stackCursor(s, 0) ;
return ;
}
*cq = old ;
cp = cq + 1 ;
}
}
void stackClear(Stack s)
{ if (stackExists(s))
{ s->pos = s->ptr = s->a->base;
s->a->max = 0;
}
}
/****************** routines to set text into lines ***********************/
static char *linesText ;
static Array lines ;
static Array textcopy ;
static int kLine, popLine ;
/**********/
( run in 0.928 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )