Index: eval_error.c =================================================================== --- eval_error.c (revision 20579) +++ eval_error.c (working copy) @@ -63,6 +63,64 @@ rb_funcall(info, rb_intern("set_backtrace"), 1, bt); } +static void +print_line_from_file(char *filename_and_line_number) { + char *c; + char *filename; + char *line_number_string; + FILE *test; + int bytes_read; + int done = 0; + int byte_at; + int line_number = 0; + int am_within_preceding_whitespace = 1; + int line_at = 1; + char read_buffer[100]; + + /* find filename from string filename:line:more */ + filename = alloca(strlen(filename_and_line_number) + 1); + strcpy(filename, filename_and_line_number ); + + for(c = &filename[0]; *c != 0 && *c != ':'; c++) { } + *c = 0; + test = fopen(filename, "r"); + if(!test) + return; // file not found + c++; + line_number_string = c; + for(; *c != 0 && *c != ':'; c++) { } + *c = 0; + line_number = atoi(line_number_string); + if(!line_number) + return; + + warn_printf("\t\t "); + while(!done) { + char current; + bytes_read = fread(&read_buffer[0], sizeof(char), 99, test); + read_buffer[bytes_read] = 0; + for(byte_at = 0; byte_at < bytes_read; byte_at++) { + current = read_buffer[byte_at]; + if(current == '\n') + line_at += 1; + if(line_at == line_number && current != '\r' && current != '\n') { + if(!(am_within_preceding_whitespace && (current == '\t' || current == ' '))) { + am_within_preceding_whitespace = 0; + printf("%c", current); + } + + } + } + if(bytes_read < 99) // EOF + done = 1; + if(line_at > line_number) + done = 1; + } + fclose(test); + warn_printf("\n"); + +} + static void error_print(void) { @@ -120,6 +178,8 @@ goto error; if (eclass == rb_eRuntimeError && elen == 0) { warn_print(": unhandled exception\n"); + if (!NIL_P(errat)) + print_line_from_file(RSTRING_PTR( RARRAY_PTR(errat)[0])); } else { VALUE epath; @@ -167,6 +227,7 @@ for (i = 1; i < len; i++) { if (TYPE(ptr[i]) == T_STRING) { warn_printf("\tfrom %s\n", RSTRING_PTR(ptr[i])); + print_line_from_file(RSTRING_PTR(ptr[i])); } if (skip && i == TRACE_HEAD && len > TRACE_MAX) { warn_printf("\t ... %ld levels...\n",