Hi,
This
text
here
to
be wrapped
Sincerly Pedlar
Hi,
This text here to be wrapped
Sincerly Pedlar
PSTR wraptext(PSTR text, BOOL lines, int start, int end, CHAR_DATA *ch)
{
STR wrap1[MAX_STRING_LENGTH*2];
STR wrap2[MAX_STRING_LENGTH*2];
STR word[MAX_INPUT_LENGTH*2];
PSTR p, q;
LONG count=0;
/// Wraplines Vars
char *start_pos = text, *end_pos = text+strlen(text), *last=text, *pos=text;
char chunk[MSL], pre[MSL], post[MSL], txt[MSL];
int line=1;
size_t len = strlen(text);
if(lines) {
pre[0] = '\0';
chunk[0] = '\0';
post[0] = '\0';
txt[0] = '\0';
if(start < 1)
{
ch->SendAlways("%s", "Start must be above 1.\n\r");
return text;
}
if(start > end)
{
ch->SendAlways("%s", "Stop must be greater then start.\n\r");
return text;
}
if(end > line_count(text))
{
ch->SendAlways("%s", "Not that many lines.\n\r");
return text;
}
while( (pos = strstr(pos, "\n") ) )
{
while(isspace(*pos) )
++pos;
if(!pos)
break;
if(line == start)
start_pos = last;
if(line == end)
end_pos = pos;
last = pos;
line++;
}
strncpy(chunk, start_pos, end_pos-start_pos);
strncpy(pre, text, start_pos-text);
strncpy(post, end_pos, (text+len)-end_pos);
p = wrap1;
q = chunk;
} else {
p = wrap1;
q = text;
}
while (*q != '\0')
{
if (*q == '\n')
{
q+=2;
*p++ = ' ';
while (*q==' ' && *(q+1)== '\n')
{
*p++ = -1;
q+=3;
}
}
else
{
*p++ = *q++;
}
}
*p = '\0';
p = wrap2;
q = wrap1;
wrap2[0] = '\0';
while (*q != '\0')
{
if (*q == -1)
{
q++;
if (count != 0)
strcat(wrap2,"\n\r");
strcat(wrap2," \n\r");
count = 0;
continue;
}
q = One_Argument(q,word);
if (count + count_color_string(word) > 75)
{
if (count_color_string(word)>75)
{
strcat(wrap2,"\n\r");
strcat(wrap2,word);
strcat(wrap2,"\n\r");
count = 0;
}
else
{
count = count_color_string(word)+1;
strcat(wrap2,"\n\r");
strcat(wrap2,word);
strcat(wrap2," ");
}
}
else
{
count += count_color_string(word)+1;
strcat(wrap2,word);
strcat(wrap2," ");
}
}
if(lines) {
strcat(txt, pre);
strcat(txt, wrap2);
strcat(txt, post);
FREE_STRING(text);
return str_dup(txt);
} else {
if (count != 0)
strcat(wrap2,"\n\r");
FREE_STRING(text);
return str_dup(wrap2);
}
}
the functions are here:
wraptext and wraplines
and the reults are:
any help is appreciated