04 Jul, 2008, Pedlar wrote in the 1st comment:
Votes: 0
ok, i have 2 wrapping functions, wraptext and wraplines. wraplines wrapes the lines #1 to #2 and leaves anything before #1 alone and everyhting after #2 alone but wrapes anything between #1 and #2.

the functions are here:
wraptext and wraplines

and the reults are:
Wrap it the first time its fineish, mines the block error at the end of the wrapped text.

?n
1. This
2. is
3. a
4. test
5. of
6. the
7. national
8. wrapping
9. association
10.

]
$4 7
]
?n
1. This
2. is
3. a
4. test of the national al  wrapping ô‘
5. wrapping
6. association
7.
8. ¡(EeÀ¡0

]
$2 5
]
?
This
À¡0is a test of the national al  wrapping ô‘ wrapping



association

¡(EeÀ¡0¿(EeÀ¡0


any help is appreciated
08 Jul, 2008, Pedlar wrote in the 2nd comment:
Votes: 0
whered everybody go? all the helpers fight eachother off?
08 Jul, 2008, David Haley wrote in the 3rd comment:
Votes: 0
You could give some more information, like what exactly you are passing in as input to which of the functions, what you expect, and what is coming out. Judging from the form of the input, you aren't copying from the right position, although it seems that you are copying into the right position (more or less). Have you tried testing this with valgrind to see if you aren't doing strange things to the memory?
08 Jul, 2008, Conner wrote in the 4th comment:
Votes: 0
Yeah what he said, we need more info to be able to help you.. and we need to stop draining our brains trying to ponder Midboss' thread…
08 Jul, 2008, Pedlar wrote in the 5th comment:
Votes: 0
*is still pondering Midboss period. not only his thread*

Im passing a string such as:
Hi, 

This
text
here
to
be wrapped

Sincerly Pedlar


and want it to look like:
Hi,

This text here to be wrapped

Sincerly Pedlar


and that gets passed into wraplines with startline 3 and endline 7

and Me and Valgrind are like an NHL player and Figure skating.
08 Jul, 2008, David Haley wrote in the 6th comment:
Votes: 0
You have two functions, which are you calling? And it looks like you're not wrapping, but "unwrapping" text. Is that correct?
08 Jul, 2008, Conner wrote in the 7th comment:
Votes: 0
I think he's wanting to wrap at a designated line length even if it means unwrapping to get there. (Why that wouldn't be considered breaking functionality is beyond me, but each to his own…)
08 Jul, 2008, Pedlar wrote in the 8th comment:
Votes: 0
yea im running 2 functions, wraplines finds the chunk to wrap and sends the chunk to Wraptext and wrayea im running 2 functions, wraplines finds the chunk to wrap and sends the chunk to Wraptext and wra[text wraps said chunk and returns it to wraplines :D
08 Jul, 2008, Pedlar wrote in the 9th comment:
Votes: 0
fixed it :D

took the two functions and just broke down and combined them (I wanted two seperate ones since wraptext is used alot of other places as well) but hey, whatya gonna do :D.

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);
}

}


thats the fixed code for those who wana see ! :D
0.0/9