/[jscoverage]/trunk/highlight.c
ViewVC logotype

Diff of /trunk/highlight.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 343 by siliconforks, Fri Oct 24 16:15:25 2008 UTC revision 347 by siliconforks, Fri Oct 24 16:16:41 2008 UTC
# Line 91  Line 91 
91  static enum Class current_class;  static enum Class current_class;
92    
93  static void output_character(jschar c, enum Class class) {  static void output_character(jschar c, enum Class class) {
94      if (c == '\r' || c == '\n' || c == 0x2028 || c == 0x2029) {
95        class = CLASS_NONE;
96      }
97    
98    if (class != current_class) {    if (class != current_class) {
99      /* output the end tag */      /* output the end tag */
100      if (current_class != CLASS_NONE) {      if (current_class != CLASS_NONE) {
# Line 105  Line 109 
109      }      }
110    }    }
111    
112      if (column_num == UINT16_MAX) {
113        fatal("%s: script contains a line with more than 65,535 columns", g_id);
114      }
115      column_num++;
116    switch (c) {    switch (c) {
117    case '&':    case '&':
118      Stream_write_string(g_output, "&");      Stream_write_string(g_output, "&");
# Line 116  Line 124 
124      Stream_write_string(g_output, ">");      Stream_write_string(g_output, ">");
125      break;      break;
126    case '\t':    case '\t':
   case '\n':  
127      Stream_write_char(g_output, c);      Stream_write_char(g_output, c);
128      break;      break;
129      case '\r':
130      case '\n':
131      case 0x2028:
132      case 0x2029:
133        if (c == '\r' && character_offset + 1 < g_num_characters && g_characters[character_offset + 1] == '\n') {
134          break;
135        }
136        Stream_write_char(g_output, '\n');
137        column_num = 0;
138        if (line_num == UINT16_MAX) {
139          fatal("%s: script contains more than 65,535 lines", g_id);
140        }
141        line_num++;
142        break;
143    default:    default:
144      if (32 <= c && c <= 126) {      if (32 <= c && c <= 126) {
145        Stream_write_char(g_output, c);        Stream_write_char(g_output, c);
# Line 128  Line 149 
149      }      }
150      break;      break;
151    }    }
152      character_offset++;
153  }  }
154    
155  static void mark_nontoken_chars(uint16_t end_line, uint16_t end_column) {  static void mark_nontoken_chars(uint16_t end_line, uint16_t end_column) {
# Line 160  Line 182 
182          state = STATE_MULTILINE_COMMENT;          state = STATE_MULTILINE_COMMENT;
183          output_character('/', CLASS_COMMENT);          output_character('/', CLASS_COMMENT);
184          output_character('*', CLASS_COMMENT);          output_character('*', CLASS_COMMENT);
         character_offset += 2;  
         if (column_num >= UINT16_MAX - 1) {  
           fatal("%s: script contains line with more than 65,535 characters", g_id);  
         }  
         column_num += 2;  
185          continue;          continue;
186        }        }
187        break;        break;
# Line 178  Line 195 
195          output_character('*', CLASS_COMMENT);          output_character('*', CLASS_COMMENT);
196          output_character('/', CLASS_COMMENT);          output_character('/', CLASS_COMMENT);
197          state = STATE_NORMAL;          state = STATE_NORMAL;
         character_offset += 2;  
         if (column_num >= UINT16_MAX - 1) {  
           fatal("%s: script contains line with more than 65,535 characters", g_id);  
         }  
         column_num += 2;  
198          continue;          continue;
199        }        }
200        break;        break;
201      }      }
202    
203      character_offset++;      if (state == STATE_NORMAL) {
204      if (c == '\r' || c == '\n' || c == 0x2028 || c == 0x2029) {        output_character(c, CLASS_NONE);
       if (line_num == UINT16_MAX) {  
         fatal("%s: script contains more than 65,535 lines", g_id);  
       }  
       line_num++;  
       column_num = 0;  
       if (c == '\r' && character_offset < g_num_characters && g_characters[character_offset] == '\n') {  
         character_offset++;  
       }  
       output_character('\n', CLASS_NONE);  
205      }      }
206      else {      else {
207        if (column_num == UINT16_MAX) {        output_character(c, CLASS_COMMENT);
         fatal("%s: script contains line with more than 65,535 characters", g_id);  
       }  
       column_num++;  
       if (state == STATE_NORMAL) {  
         output_character(c, CLASS_NONE);  
       }  
       else {  
         output_character(c, CLASS_COMMENT);  
       }  
208      }      }
209    }    }
210  }  }
# Line 441  Line 435 
435        break;        break;
436      }      }
437    
438      if (t.pos.begin.lineno != t.pos.end.lineno) {      uint16_t start_line = t.pos.begin.lineno;
439        fatal("%s: line %u: token spans multiple lines", id, t.pos.begin.lineno);      uint16_t end_line = t.pos.end.lineno;
440      }      uint16_t start_column = t.pos.begin.index;
441      if (t.pos.begin.index > t.pos.end.index) {      uint16_t end_column = t.pos.end.index;
442        assert(line_num == start_line);
443        assert(column_num == start_column);
444        if (start_line == end_line && start_column >= end_column) {
445        fatal("%s: script contains line with more than 65,535 characters", id);        fatal("%s: script contains line with more than 65,535 characters", id);
446      }      }
447      for (uint16_t i = t.pos.begin.index; i < t.pos.end.index; i++) {      for (;;) {
448        assert(character_offset < num_characters);        assert(character_offset < num_characters);
449        jschar c = characters[character_offset];        jschar c = characters[character_offset];
450        if (tt == TOK_STRING && c == '\\') {        if (tt == TOK_STRING && c == '\\') {
451          output_character(c, CLASS_SPECIALCHAR);          output_character(c, CLASS_SPECIALCHAR);
         character_offset++;  
         i++;  
452          assert(character_offset < num_characters);          assert(character_offset < num_characters);
453          c = characters[character_offset];          c = characters[character_offset];
454          output_character(c, CLASS_SPECIALCHAR);          output_character(c, CLASS_SPECIALCHAR);
         character_offset++;  
455        }        }
456        else {        else {
457          output_character(c, class);          output_character(c, class);
458          character_offset++;        }
459    
460          if (line_num > end_line) {
461            break;
462          }
463          else if (line_num == end_line && column_num >= end_column) {
464            break;
465        }        }
466      }      }
467    
468      line_num = t.pos.end.lineno;      assert(line_num == end_line);
469      column_num = t.pos.end.index;      assert(column_num = end_column);
470    }    }
471    
472    if (current_class != CLASS_NONE) {    if (current_class != CLASS_NONE) {

Legend:
Removed from v.343  
changed lines
  Added in v.347

  ViewVC Help
Powered by ViewVC 1.1.24