help with word wrap in online edit buffer

Posted by Bryn on Tue 07 Jan 2003 05:06 AM — 5 posts, 18,069 views.

#0
I found this code for a word wrap function in the edit buffer for smaug, but when i used it, it would not recognize any other commands.

/* added format command - shogar */
if ( !str_cmp( cmd+1, "f" ) )
{
char cword[MAX_INPUT_LENGTH];
char cline[MAX_INPUT_LENGTH + 80];
char *sptr,*lwptr,*wptr,*tptr;
int x,linecnt = -1, spacercnt=0;

pager_printf( ch, "Reformating...\n\r");
for ( x = edit->on_line; x < edit->numlines; x++ )
{
if(linecnt < 0)
{
linecnt = x;
lwptr = edit->line[linecnt];
}
tptr = edit->line[x];
while(*tptr)
{
if(!isspace(*tptr))
break;
tptr++;
}
if(! *tptr)
{
if(! spacercnt)
{
linecnt++;
lwptr = edit->line[linecnt];
*lwptr=0;
linecnt++;
spacercnt++;
lwptr = edit->line[linecnt];
}
continue;
}
spacercnt = 0;
strcpy(cline,edit->line[x]);
sptr=cline;
*lwptr = 0;
while(*sptr)
{
wptr = cword;
while(isspace(*sptr) && *sptr)
sptr++;
while(!isspace(*sptr) && *sptr)
*wptr++ = *sptr++;
*wptr=0;

if(! *cword)
{
sptr = cline;
*sptr = 0;
continue;
}
if((strlen(edit->line[linecnt]) + strlen(cword) + 1) > 79)

{
if ( edit->numlines >= max_buf_lines )
{
send_to_pager( "Buffer is full.\n\r> ", ch );
return;
}
else
{
strcpy(edit->line[edit->numlines],"");
edit->numlines++;
linecnt++;
lwptr = edit->line[linecnt];
*lwptr = 0;

}
}
strcat(lwptr,cword);
lwptr += strlen(cword);
strcat(lwptr," ");
lwptr++;
}
}
if(linecnt != -1)
{
for ( x = linecnt + 1; x < edit->numlines; x++ )
{
strcpy(edit->line[x],"");
}
edit->numlines = linecnt + 2;
edit->on_line = linecnt + 1;
}
pager_printf( ch, "Reformating done...\n\r> ");
return;

}

can some one help me?

-Bryn
USA #1
That is actually specific to the note editor. It applies to the .f command to format a note before posting. It is also used by various description editors thruout the olc for formatting.
#2
ah, ok. Does anyone know where i can find a word wrap snippet for the edit buffer?
#3
ah, ok. Does anyone know where i can find a word wrap snippet for the edit buffer?
Australia Forum Administrator #4
The Area Editor (available on this site) lets you type in descriptions which wrap and then forces them into 78-character lines when you finish.