Project

General

Profile

Feature #839 ยป add_code_output.diff

rogerdpack (Roger Pack), 12/08/2008 06:29 PM

View differences:

eval_error.c (working copy)
63 63
    rb_funcall(info, rb_intern("set_backtrace"), 1, bt);
64 64
}
65 65

  
66
static void 
67
print_line_from_file(char *filename_and_line_number) {
68
 char *c;
69
 char *filename;
70
 char *line_number_string;
71
 FILE *test;
72
 int bytes_read;
73
 int done = 0;
74
 int byte_at;
75
 int line_number = 0;
76
 int am_within_preceding_whitespace = 1;
77
 int line_at = 1;
78
 char read_buffer[100];
79
  
80
  /* find filename from string filename:line:more */
81
 filename = alloca(strlen(filename_and_line_number) + 1);
82
 strcpy(filename, filename_and_line_number );
83
 
84
 for(c = &filename[0]; *c != 0 && *c != ':'; c++) {  }
85
 *c = 0;
86
 test = fopen(filename, "r");
87
 if(!test)
88
  return; // file not found
89
 c++;
90
 line_number_string = c;
91
 for(; *c != 0 && *c != ':'; c++) { }
92
 *c = 0;
93
 line_number = atoi(line_number_string);
94
 if(!line_number)
95
  return;
96

  
97
 warn_printf("\t\t ");
98
 while(!done) {
99
   char current;
100
   bytes_read = fread(&read_buffer[0], sizeof(char), 99, test);
101
   read_buffer[bytes_read] = 0;
102
   for(byte_at = 0; byte_at < bytes_read; byte_at++) {
103
      current = read_buffer[byte_at];
104
      if(current == '\n')
105
        line_at += 1;
106
      if(line_at == line_number && current != '\r' && current != '\n') {
107
        if(!(am_within_preceding_whitespace && (current == '\t' || current  == ' '))) {
108
          am_within_preceding_whitespace = 0;
109
          printf("%c", current);
110
        }
111
        
112
      }
113
   }
114
   if(bytes_read < 99) // EOF
115
     done = 1;
116
   if(line_at > line_number)
117
     done = 1;
118
 }
119
 fclose(test);
120
 warn_printf("\n");
121
 
122
}
123

  
66 124
static void
67 125
error_print(void)
68 126
{
......
120 178
	goto error;
121 179
    if (eclass == rb_eRuntimeError && elen == 0) {
122 180
	warn_print(": unhandled exception\n");
181
        if (!NIL_P(errat))
182
        	print_line_from_file(RSTRING_PTR( RARRAY_PTR(errat)[0]));
123 183
    }
124 184
    else {
125 185
	VALUE epath;
......
167 227
	for (i = 1; i < len; i++) {
168 228
	    if (TYPE(ptr[i]) == T_STRING) {
169 229
		warn_printf("\tfrom %s\n", RSTRING_PTR(ptr[i]));
230
        	print_line_from_file(RSTRING_PTR(ptr[i]));
170 231
	    }
171 232
	    if (skip && i == TRACE_HEAD && len > TRACE_MAX) {
172 233
		warn_printf("\t ... %ld levels...\n",