A few of my builders have said the format feature in the editor would be much better if it had a way of providing a hanging indent, so I tried to do it. This is the SWRFUSS codebase.
Anyway, it keeps crashing, and gdb doesn't seem to be able to catch the cause. Would anyone be able to help me?
// handler.c
char *strlinwrp( char *src, int length, int indent )
{
int wrdlen, marker = 0;
char newstr[MSL], word[MSL];
// indents = repeat_string( indent, " " );
char indents[MSL], token[MSL];
if( indent ) {
sprintf( token, "%%%ds", indent );
sprintf( indents, token, "" );
}
while( strlen( src ) ) {
while( marker < length ) {
if( src[marker] == '\n' )
break;
src = one_argument( src, word );
wrdlen = strlen_color( word );
// If it won't fit on the line, put it back and wrap.
if( marker + wrdlen == length ) {
sprintf( src, "%s %s", src, word );
break;
}
sprintf( newstr, "%s %s", newstr, word );
marker += wrdlen;
}
if( indent )
sprintf( newstr, "%s%s", indents, newstr);
sprintf( newstr, "%s\n", newstr );
marker = indent;
}
// Append color reset.
sprintf( newstr, "%s&w", newstr );
return STRALLOC( newstr );
}// void edit_buffer( CHAR_DATA * ch, char *argument ); [it's in editor.c]
if( argument[0] == '/' || argument[0] == '\\' )
{
argument = one_argument( argument, cmd );
if( !str_cmp( cmd + 1, "?" ) )
editor_help( ch, edd, argument );
else if( !str_cmp( cmd + 1, "c" ) )
editor_clear_buf( ch, edd, argument );
else if( !str_cmp( cmd + 1, "r" ) )
editor_search_and_replace( ch, edd, argument );
else if( !str_cmp( cmd + 1, "i" ) )
editor_insert_line( ch, edd, argument );
else if( !str_cmp( cmd + 1, "d" ) )
editor_delete_line( ch, edd, argument );
else if( !str_cmp( cmd + 1, "g" ) )
editor_goto_line( ch, edd, argument );
else if( !str_cmp( cmd + 1, "l" ) )
editor_list( ch, edd, argument );
else if( !str_cmp( cmd + 1, "a" ) )
editor_abort( ch, edd, argument );
else if( !str_cmp( cmd + 1, "s" ) )
editor_save( ch, edd, argument );
else if( !str_cmp( cmd + 1, "!" ) )
editor_escaped_cmd( ch, edd, argument );
else if( !str_cmp( cmd + 1, "p" ) )
editor_print_info( ch, edd, argument );
else if( !str_cmp( cmd + 1, "f" ) )
{
int indent;
if( !str_cmp( argument, "" ) )
indent = 0;
else
indent = atoi( argument );
editor_format_lines( ch, edd, indent );
} /* There's a lot in here that I haven't put in, and I bolded what I added */// void editor_format_lines( CHAR_DATA * ch, EDITOR_DATA * edd, int indent ); [It's in editor.c also]
void editor_format_lines( CHAR_DATA * ch, EDITOR_DATA * edd, int indent )
{
EDITOR_LINE *eline;
short from, to;
int srclen, x, inp;
char src[MAX_STRING_LENGTH];
char newsrc[MAX_STRING_LENGTH];
char newsrc2[MAX_STRING_LENGTH];
from = 1;
to = edd->line_count;
eline = edd->first_line;
inp = 0;
while( eline )
{
srclen = strlen( eline->line );
for( x = 0; x < srclen; x++ )
src[inp++] = eline->line[x];
if(src[inp-1] != ' ')
src[inp++] = ' ';
eline = eline->next;
}
src[inp] = '\0';
strcpy( newsrc, strrep( src, "(NL)", "\r\n" ) );
strcpy( newsrc, strlinwrp( newsrc, 75, indent ) );
edit_buffer( ch, "/c" );
inp = 0;
srclen = strlen( newsrc );
for( x = 0; x < srclen; x++ )
{
if( newsrc[x] == '\r' || newsrc[x] == '\n' )
{
x++;
newsrc2[inp] = '\0';
inp = 0;
edit_buffer( ch, newsrc2 );
continue;
}
newsrc2[inp++] = newsrc[x];
}
send_to_char( "\r\nOk - Reformatted.\r\n", ch );
}Anyway, it keeps crashing, and gdb doesn't seem to be able to catch the cause. Would anyone be able to help me?