[Cgdb-devel] The Patch
Brought to you by:
bobbybrasko,
crouchingturbo
From: Peter K. <pe...@ko...> - 2003-06-14 15:28:31
|
Just for reference, and since its pretty small, the patch that I just committed is below. - Peter Index: cgdb.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/cgdb/cgdb/cgdb/src/cgdb.c,v retrieving revision 1.4 diff -w -u -r1.4 cgdb.c --- cgdb.c 5 Jun 2003 01:29:36 -0000 1.4 +++ cgdb.c 14 Jun 2003 14:38:26 -0000 @@ -70,6 +70,7 @@ #include "ibuf.h" #include "input.h" #include "fs_util.h" +#include "commands.h" =20 /* --------------- */ /* Local Variables */ @@ -647,6 +648,17 @@ /* Initialize the pipe that is used for resize */ if( init_resize_pipe() =3D=3D -1 ) err_quit("%s: init_resize_pipe error\n", my_name);=20 + + { + char config_file[ PATH_MAX ]; + FILE *config; + fs_util_get_path( cgdb_home_dir, "cgdbrc", config_file ); + config =3D fopen( config_file, "r" ); + if( config ) {=20 + command_parse_file( config ); + fclose( config ); + } + } =20 /* Enter main loop */ main_loop(); Index: commands.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/cgdb/cgdb/cgdb/src/commands.c,v retrieving revision 1.3 diff -w -u -r1.3 commands.c --- commands.c 13 Jun 2003 01:06:28 -0000 1.3 +++ commands.c 14 Jun 2003 14:38:26 -0000 @@ -28,16 +28,31 @@ extern int shortcut_option ; extern int line_coverage_option; =20 +enum ConfigType +{ + CONFIG_TYPE_BOOL, /* set ic / set noic */ + CONFIG_TYPE_INT, /* set tabspace=3D8 */ + CONFIG_TYPE_STRING, + CONFIG_TYPE_FUNC_VOID, + CONFIG_TYPE_FUNC_INT, + CONFIG_TYPE_FUNC_STRING, +}; =20 -static struct variables +static int command_set_focus( const char *value ); +static int command_set_tabspace( int tab ); + +static struct ConfigVariable { const char * name, *s_name; - int * variable; + enum ConfigType type; + void *data; } VARIABLES[] =3D { // keep this stuff sorted! !sort - /* ignorecase */ { "ignorecase", "ic", ®ex_icase }, - /* line coverage */ { "line_coverage", "lc", &line_coverage_option }, - /* shortcut */ { "shortcut", "sc", &shortcut_option }, + /* focus */ { "focus", "fo", CONFIG_TYPE_FUNC_STRING, command_set= _focus }, + /* ignorecase */ { "ignorecase", "ic", CONFIG_TYPE_BOOL, ®ex_icase= }, + /* line_coverage */ { "line_coverage", "lc", CONFIG_TYPE_BOOL, &line_c= overage_option }, + /* shortcut */ { "shortcut", "sc", CONFIG_TYPE_BOOL, &shortcut_opti= on }, + /* tabspace */ { "tabspace", "ts", CONFIG_TYPE_FUNC_INT, command_= set_tabspace }, }; =20 static int command_focus_cgdb( void ); @@ -95,20 +110,41 @@ return NULL; } =20 -int * get_variable( const char *variable )=20 +struct ConfigVariable* get_variable( const char *variable )=20 { /* FIXME: replace with binary search */ int i; for ( i =3D 0; i < (sizeof( VARIABLES )/sizeof( VARIABLES[0])); ++i ) { if ( strcmp( variable, VARIABLES[i].name ) =3D=3D 0 || strcmp( variable, VARIABLES[i].s_name ) =3D=3D 0 ) { - return VARIABLES[i].variable; + return &VARIABLES[i]; } } =20 return NULL; } =20 +int command_set_focus( const char *value ) +{ + if( strcasecmp( value, "cgdb" ) =3D=3D 0 ) { + command_focus_cgdb(); + } else if (strcasecmp( value, "gdb" ) =3D=3D 0 ) { + command_focus_gdb(); + } else if( strcasecmp( value, "tty" ) =3D=3D 0 ) { + command_focus_tty(); + } else { + return 1; + } + + return 0; +} + +int command_set_tabspace( int value ) +{ + fprintf( stderr, "Unimplemented.\n" ); + return 1; +} + int command_focus_cgdb( void ) { if_set_focus( CGDB ); @@ -205,25 +241,112 @@ =20 int command_parse_set( void ) { + /* commands could look like the following: + * set ignorecase + * set noignorecase + * set focus=3Dgdb + * set tabspace=3D8 + */ + int rv =3D 1; - int val =3D 1; + int boolean =3D 1; const char * value =3D NULL; =20 switch ( (rv =3D yylex()) ) { case IDENTIFIER: { const char *token =3D get_token(); int length =3D strlen( token ); - int *variable =3D NULL; + struct ConfigVariable *variable =3D NULL; + if ( length > 2 && token[0] =3D=3D 'n' && token[1] =3D=3D 'o' ) { value =3D token + 2; - val =3D 0; + boolean =3D 0; } else { value =3D token; } =20 if ( (variable =3D get_variable( value )) !=3D NULL ) { rv =3D 0; - *variable =3D val; + if( boolean =3D=3D 0 && + variable->type !=3D CONFIG_TYPE_BOOL ) { + /* this is an error, you cant' do: + * set notabspace=20 + */ + rv =3D 1; + } + + switch( variable->type ) { + case CONFIG_TYPE_BOOL: + *(int*)(variable->data) =3D boolean; + break; + case CONFIG_TYPE_INT: { + if( yylex() =3D=3D '=3D' && + yylex() =3D=3D NUMBER ) { + int data =3D strtol( get_token(), NULL, 10 ); + *(int*)(variable->data) =3D data; + } else { + rv =3D 1; + } + } break; + case CONFIG_TYPE_STRING: { + if( yylex() =3D=3D '=3D' && + (rv =3D yylex(), rv =3D=3D STRING || rv =3D=3D IDENTIFI= ER) ) { + /* BAM! comma operator */ + char * data =3D (char*)get_token(); + if( rv =3D=3D STRING ) { + /* get rid of quotes */ + data =3D data + 1; + data[ strlen( data ) - 1 ] =3D '\0'; + }=20 + if( variable->data )=20 + { free( variable->data ); } + (char *)variable->data =3D strdup( data ); + } else { + rv =3D 1; + } + } break; + case CONFIG_TYPE_FUNC_VOID: { + int(*functor)( void ) =3D (int(*)(void))variable->data; + if( functor ) + { rv =3D functor(); } + else=20 + { rv =3D 1; } + } break; + case CONFIG_TYPE_FUNC_INT: { + int (*functor)( int ) =3D (int(*)(int))variable->data; + if( yylex() =3D=3D '=3D' && + yylex() =3D=3D NUMBER ) { + int data =3D strtol( get_token(), NULL, 10 ); + if( functor ) + { rv =3D functor( data ); } + else + { rv =3D 1; } + } else { + rv =3D 1; + } + } break; + case CONFIG_TYPE_FUNC_STRING: { + int (*functor)( const char* ) =3D (int(*)(const char*))var= iable->data; + if( yylex() =3D=3D '=3D' && + (rv =3D yylex(), rv =3D=3D STRING || rv =3D=3D IDENTIFI= ER) ) { + /* BAM! comma operator */ + char * data =3D (char*)get_token(); + if( rv =3D=3D STRING ) { + /* get rid of quotes */ + data =3D data + 1; + data[ strlen( data ) - 1 ] =3D '\0'; + }=20 + if( functor ) + { rv =3D functor(data); } + else + { rv =3D 1; } + } else=20 + { rv =3D 1; } + } break; + default:=20 + rv =3D 1; + break; + } } } break; default: @@ -289,3 +412,19 @@ return rv; } =20 +int command_parse_file( FILE *fp ) +{ + char buffer[4096]; + extern int yylinenumber; + + while( fgets( buffer, sizeof(buffer), fp ) ) + { + if( command_parse_string( buffer ) ) + { + fprintf( stderr, "Error parsing line %d: %s\n", yylinenumber, b= uffer ); + return 1; + } + } + + return 0; +} --=20 Peter D. Kovacs <pe...@ko...> |