09 Mar, 2007, Pedlar wrote in the 1st comment:
Votes: 0
Ok, first, I will explain what im trieing to do.

I want to wrap line <a> to <b> but leave that stuff before <a> and after <b> alone, i seem to have been having some quiant difficulty in doing so.

I do, have a text wrapper i made, but i want the wrap_lines to be seperate from it like wrap_lines(txt, <a>, <b>)

since im not the smartest in the world, what i wrote came up as:
(PSTR jus mean char*)
PSTR wraplines(PSTR txt, int minline, int maxline, CHAR_DATA *ch)
{
int linenum = 1;
PSTR p;
PSTR q;
PSTR Before, After, Between;
BUFFER *buffer;

if(maxline < minline || minline == maxline) {
ch->Send("%s", "Max line must be greater then Minimum\n\r");
return txt;
}
for(p=txt; *p != '\0'; *p++) {
if ( (*p != '\n' || *p != '\r' ) && ( linenum < minline || linenum >= maxline ) ) {
if(linenum < minline) *Before = *p;
if(linenum > maxline) *After = *p;
++linenum;
continue;
}

*q = *p;
}
*q = '\0';
Between = wraptext(q);

buffer = new_buf();
add_buf(buffer, Before);
add_buf(buffer, Between);
add_buf(buffer, After);
free_string(txt);
txt = str_dup(buf_string(buffer));
free_buf(buffer);
return txt;
}


but, apparently that dun work, or i wouldnt be here, asking for help.
09 Mar, 2007, Justice wrote in the 2nd comment:
Votes: 0
Um, not entirely sure I understand what you want. I assume you have a string that contains a certain # of lines and you want to wrap a group of them in the middle.

Unless I misunderstand your code, there are 4 problems I see. It's hard to tell without the inputs/output.

First new lines generally consist of both \r and \n. So your check would be incorrectly increment the linenum for both characters.
Second, the Before would be pointing at the end of the last "line", it should point to the beginning of the input buffer and end at that position.
Third, you're pointing at locations within the original string without any way to control how many characters are placed on the output buffer.
Finally, q looks like it would end up pointing at the last character that was not a newline.
09 Mar, 2007, Pedlar wrote in the 3rd comment:
Votes: 0
Woops, I see where i had some flaws now :P, forgot to incriment q.

but, for what im trieing to do, say i got txt:
Quote
Hey everybody this is a note to the whole mud about blahblahblahblah
$p = blah
$q = blah
this right here is something short and sweet explaining my other short and sweet shitisnt that jus so cool of
me
and that
is all


and if i wrap it all itll put everything ontop of eachother, and fuck with my formatting, what i want to do, is just wrap lines 4 to 5, so itll look like this after wrap_lines():
Quote
Hey everybody this is a note to the whole mud about blahblahblahblah
$p = blah
$q = blah
this right here is something short and sweet explaining my other short and
sweet shit isnt that jus so cool of me
and that
is alll


I hope that makes more sense.
09 Mar, 2007, Justice wrote in the 4th comment:
Votes: 0
Alright, this may help you… it's a bit rough but it should divide an input string into 3 sections based on line count. I've only done some basic testing but it might point you in the right direction.

void handle_line(char *buf, int start, int stop)
{
char *wrap_ptr;
int wrap_pos;
char *stop_ptr;
int stop_pos;
char *ptr;
int pos;
int cnt;

wrap_pos = 0;
stop_pos = 0;
pos = 0;
cnt = -1;
for(ptr = buf; (*ptr != '\0'); ptr++)
{
pos++;
if (*ptr != '\n')
continue;

++cnt;
if (cnt == start)
{
wrap_ptr = ptr+1;
wrap_pos = pos;
continue;
}

if (cnt == stop)
{
printf("%s", ptr);
stop_ptr = ptr+1;
stop_pos = pos;
break;
}
}

printf("%d %d\r\n", wrap_pos, stop_pos);
printf("PRE:\r\n%*.*s\r\n", 0,wrap_pos, buf);
printf("Wrap:\r\n%*.*s\r\n", 0,(stop_pos-wrap_pos), wrap_ptr);
printf("POST:\r\n%s\r\n", stop_ptr);
}
09 Mar, 2007, Pedlar wrote in the 5th comment:
Votes: 0
Thanks ^^, I have to wait for Zeno to come around, to reset the server, cuase MySQL on it dropped, and i use MySQL extensivily fr critical stuff on my MUD, Ill stick it in there when its backup, and run it, and post if it works out for me or not :)
10 Mar, 2007, Pedlar wrote in the 6th comment:
Votes: 0
Ok, so itd appear strings are not my thing ><

Ok, so i think i pinpointed the problem somewhat, im having troubles freeing it, i get this:
Sat Mar 10 02:05:33 2007 :: [*****] BUG: Attempt to recyle invalid memory of size 14.
Sat Mar 10 02:05:33 2007 :: [*****] BUG: I wana wrap:

Sat Mar 10 02:05:33 2007 :: [****] BUG FILE: comm.c LINE: 3528
Sat Mar 10 02:05:33 2007 :: [*****] BUG: Attempt to recyle invalid memory of size 32.
at Mar 10 02:05:33 2007 :: [*****] BUG:
this
this
this
and this

Sat Mar 10 02:05:33 2007 :: [****] BUG FILE: comm.c LINE: 3625
Sat Mar 10 02:05:33 2007 :: [*****] BUG: Attempt to recyle invalid memory of size 32.
at Mar 10 02:05:33 2007 :: [*****] BUG:
this
this
this
and this

Sat Mar 10 02:05:33 2007 :: [****] BUG FILE: comm.c LINE: 3531
Sat Mar 10 02:05:33 2007 :: [*****] BUG: Attempt to recyle invalid memory of size 10.
Sat Mar 10 02:05:33 2007 :: [*****] BUG: together

Sat Mar 10 02:05:33 2007 :: [****] BUG FILE: comm.c LINE: 3534


heres the lines of code:
WrapLines:
buffer = new_buf();
sprintf(buf3, "%*.*s", 0, wrap_pos, buf);
add_buf(buffer, buf3);
(3528) free_string(buf3);
sprintf(buf3, "%*.*s", 0, (stop_pos-wrap_pos), wrap_ptr);
add_buf(buffer, wraptext(buf3));
(3531) free_string(buf3);
sprintf(buf3, "%s", stop_ptr);
add_buf(buffer, buf3);
(3534) free_string(buf3);
WrapText:
(3624) free_string(text);
return str_dup(wrap2);


both of these functions are here:
Wraptext Wraplines Pastebin
10 Mar, 2007, Justice wrote in the 7th comment:
Votes: 0
Well, I can't see why it's freezing, but the bug messages are because you don't need to free buf3 in wraplines or text in wraptext.
10 Mar, 2007, Pedlar wrote in the 8th comment:
Votes: 0
sutff keeping coming back at me, from the last wrap like i can do $2 3 and itll wrap lines and then do $4 5, and the wrap from 2 3 will appear in there as well.

also, with the wraplines, if i have cnt = -1 t skips lines 1 and 2, and always has em in the PRE: if i use 1 as start, and if i move it to 0, it always has line 1 in the PRE:, any ideas how to fix that?
10 Mar, 2007, Justice wrote in the 9th comment:
Votes: 0
Well, as I said that code was pretty rough. Basically it only checks the count after a newline has been found. The count is then incremented and the checks are done. What you'll want to do is init cnt to 0. Then before the loop, add something like:
if (!start)
{
wrap_ptr = ptr;
wrap_pos = 0;
}


You'll also want to make sure that start is not 0 before adding the pre to your output. Also, you may want to use strncpy for filling the buffer, it would be more efficient.
0.0/9