diff options
author | Dave Chapman <dave@dchapman.com> | 2008-03-22 00:31:22 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2008-03-22 00:31:22 +0000 |
commit | 45b2d8802d1e8fcc47fd1148adb7b1173ad5b311 (patch) | |
tree | 849eea4153daaf7dfafd571ca6b93b6f985b1ff9 | |
parent | 7ee63e22c58f4a7017136871e7b55dd702c5f460 (diff) | |
download | rockbox-45b2d8802d1e8fcc47fd1148adb7b1173ad5b311.tar.gz rockbox-45b2d8802d1e8fcc47fd1148adb7b1173ad5b311.zip |
Reduce the shocking amount of RAM my viewports implementation was using. The first version stored an array of lines for each of the 16 possible viewports (MAX_VIEWPORTS * the number of lines on the LCD with a 5-pixel high font). This version reverts back to a single global array of lines, with each viewport specifying the first and last lines as indexes into that array. This also turns out to be simpler, reducing binsize a little as well.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16735 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/gui/gwps-common.c | 70 | ||||
-rw-r--r-- | apps/gui/gwps.h | 24 | ||||
-rw-r--r-- | apps/gui/wps_debug.c | 7 | ||||
-rw-r--r-- | apps/gui/wps_parser.c | 36 |
4 files changed, 70 insertions, 67 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index ae5492a66c..3c3bad3056 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c | |||
@@ -1466,7 +1466,7 @@ static bool evaluate_conditional(struct gui_wps *gwps, int *token_index) | |||
1466 | The return value indicates whether the line needs to be updated. | 1466 | The return value indicates whether the line needs to be updated. |
1467 | */ | 1467 | */ |
1468 | static bool get_line(struct gui_wps *gwps, | 1468 | static bool get_line(struct gui_wps *gwps, |
1469 | int v, int line, int subline, | 1469 | int line, int subline, |
1470 | struct align_pos *align, | 1470 | struct align_pos *align, |
1471 | char *linebuf, | 1471 | char *linebuf, |
1472 | int linebuf_size) | 1472 | int linebuf_size) |
@@ -1494,8 +1494,8 @@ static bool get_line(struct gui_wps *gwps, | |||
1494 | #endif | 1494 | #endif |
1495 | 1495 | ||
1496 | /* Process all tokens of the desired subline */ | 1496 | /* Process all tokens of the desired subline */ |
1497 | last_token_idx = wps_last_token_index(data, v, line, subline); | 1497 | last_token_idx = wps_last_token_index(data, line, subline); |
1498 | for (i = wps_first_token_index(data, v, line, subline); | 1498 | for (i = wps_first_token_index(data, line, subline); |
1499 | i <= last_token_idx; i++) | 1499 | i <= last_token_idx; i++) |
1500 | { | 1500 | { |
1501 | switch(data->tokens[i].type) | 1501 | switch(data->tokens[i].type) |
@@ -1594,16 +1594,16 @@ static bool get_line(struct gui_wps *gwps, | |||
1594 | return update; | 1594 | return update; |
1595 | } | 1595 | } |
1596 | 1596 | ||
1597 | static void get_subline_timeout(struct gui_wps *gwps, int v, int line, int subline) | 1597 | static void get_subline_timeout(struct gui_wps *gwps, int line, int subline) |
1598 | { | 1598 | { |
1599 | struct wps_data *data = gwps->data; | 1599 | struct wps_data *data = gwps->data; |
1600 | int i; | 1600 | int i; |
1601 | int subline_idx = wps_subline_index(data, v, line, subline); | 1601 | int subline_idx = wps_subline_index(data, line, subline); |
1602 | int last_token_idx = wps_last_token_index(data, v, line, subline); | 1602 | int last_token_idx = wps_last_token_index(data, line, subline); |
1603 | 1603 | ||
1604 | data->sublines[subline_idx].time_mult = DEFAULT_SUBLINE_TIME_MULTIPLIER; | 1604 | data->sublines[subline_idx].time_mult = DEFAULT_SUBLINE_TIME_MULTIPLIER; |
1605 | 1605 | ||
1606 | for (i = wps_first_token_index(data, v, line, subline); | 1606 | for (i = wps_first_token_index(data, line, subline); |
1607 | i <= last_token_idx; i++) | 1607 | i <= last_token_idx; i++) |
1608 | { | 1608 | { |
1609 | switch(data->tokens[i].type) | 1609 | switch(data->tokens[i].type) |
@@ -1631,7 +1631,7 @@ static void get_subline_timeout(struct gui_wps *gwps, int v, int line, int subli | |||
1631 | 1631 | ||
1632 | /* Calculates which subline should be displayed for the specified line | 1632 | /* Calculates which subline should be displayed for the specified line |
1633 | Returns true iff the subline must be refreshed */ | 1633 | Returns true iff the subline must be refreshed */ |
1634 | static bool update_curr_subline(struct gui_wps *gwps, int v, int line) | 1634 | static bool update_curr_subline(struct gui_wps *gwps, int line) |
1635 | { | 1635 | { |
1636 | struct wps_data *data = gwps->data; | 1636 | struct wps_data *data = gwps->data; |
1637 | 1637 | ||
@@ -1640,13 +1640,13 @@ static bool update_curr_subline(struct gui_wps *gwps, int v, int line) | |||
1640 | bool new_subline_refresh; | 1640 | bool new_subline_refresh; |
1641 | bool only_one_subline; | 1641 | bool only_one_subline; |
1642 | 1642 | ||
1643 | num_sublines = data->viewports[v].lines[line].num_sublines; | 1643 | num_sublines = data->lines[line].num_sublines; |
1644 | reset_subline = (data->viewports[v].lines[line].curr_subline == SUBLINE_RESET); | 1644 | reset_subline = (data->lines[line].curr_subline == SUBLINE_RESET); |
1645 | new_subline_refresh = false; | 1645 | new_subline_refresh = false; |
1646 | only_one_subline = false; | 1646 | only_one_subline = false; |
1647 | 1647 | ||
1648 | /* if time to advance to next sub-line */ | 1648 | /* if time to advance to next sub-line */ |
1649 | if (TIME_AFTER(current_tick, data->viewports[v].lines[line].subline_expire_time - 1) || | 1649 | if (TIME_AFTER(current_tick, data->lines[line].subline_expire_time - 1) || |
1650 | reset_subline) | 1650 | reset_subline) |
1651 | { | 1651 | { |
1652 | /* search all sublines until the next subline with time > 0 | 1652 | /* search all sublines until the next subline with time > 0 |
@@ -1654,46 +1654,46 @@ static bool update_curr_subline(struct gui_wps *gwps, int v, int line) | |||
1654 | if (reset_subline) | 1654 | if (reset_subline) |
1655 | search_start = 0; | 1655 | search_start = 0; |
1656 | else | 1656 | else |
1657 | search_start = data->viewports[v].lines[line].curr_subline; | 1657 | search_start = data->lines[line].curr_subline; |
1658 | 1658 | ||
1659 | for (search = 0; search < num_sublines; search++) | 1659 | for (search = 0; search < num_sublines; search++) |
1660 | { | 1660 | { |
1661 | data->viewports[v].lines[line].curr_subline++; | 1661 | data->lines[line].curr_subline++; |
1662 | 1662 | ||
1663 | /* wrap around if beyond last defined subline or WPS_MAX_SUBLINES */ | 1663 | /* wrap around if beyond last defined subline or WPS_MAX_SUBLINES */ |
1664 | if (data->viewports[v].lines[line].curr_subline == num_sublines) | 1664 | if (data->lines[line].curr_subline == num_sublines) |
1665 | { | 1665 | { |
1666 | if (data->viewports[v].lines[line].curr_subline == 1) | 1666 | if (data->lines[line].curr_subline == 1) |
1667 | only_one_subline = true; | 1667 | only_one_subline = true; |
1668 | data->viewports[v].lines[line].curr_subline = 0; | 1668 | data->lines[line].curr_subline = 0; |
1669 | } | 1669 | } |
1670 | 1670 | ||
1671 | /* if back where we started after search or | 1671 | /* if back where we started after search or |
1672 | only one subline is defined on the line */ | 1672 | only one subline is defined on the line */ |
1673 | if (((search > 0) && | 1673 | if (((search > 0) && |
1674 | (data->viewports[v].lines[line].curr_subline == search_start)) || | 1674 | (data->lines[line].curr_subline == search_start)) || |
1675 | only_one_subline) | 1675 | only_one_subline) |
1676 | { | 1676 | { |
1677 | /* no other subline with a time > 0 exists */ | 1677 | /* no other subline with a time > 0 exists */ |
1678 | data->viewports[v].lines[line].subline_expire_time = (reset_subline ? | 1678 | data->lines[line].subline_expire_time = (reset_subline ? |
1679 | current_tick : | 1679 | current_tick : |
1680 | data->viewports[v].lines[line].subline_expire_time) + 100 * HZ; | 1680 | data->lines[line].subline_expire_time) + 100 * HZ; |
1681 | break; | 1681 | break; |
1682 | } | 1682 | } |
1683 | else | 1683 | else |
1684 | { | 1684 | { |
1685 | /* get initial time multiplier for this subline */ | 1685 | /* get initial time multiplier for this subline */ |
1686 | get_subline_timeout(gwps, v, line, data->viewports[v].lines[line].curr_subline); | 1686 | get_subline_timeout(gwps, line, data->lines[line].curr_subline); |
1687 | 1687 | ||
1688 | int subline_idx = wps_subline_index(data, v, line, | 1688 | int subline_idx = wps_subline_index(data, line, |
1689 | data->viewports[v].lines[line].curr_subline); | 1689 | data->lines[line].curr_subline); |
1690 | 1690 | ||
1691 | /* only use this subline if subline time > 0 */ | 1691 | /* only use this subline if subline time > 0 */ |
1692 | if (data->sublines[subline_idx].time_mult > 0) | 1692 | if (data->sublines[subline_idx].time_mult > 0) |
1693 | { | 1693 | { |
1694 | new_subline_refresh = true; | 1694 | new_subline_refresh = true; |
1695 | data->viewports[v].lines[line].subline_expire_time = (reset_subline ? | 1695 | data->lines[line].subline_expire_time = (reset_subline ? |
1696 | current_tick : data->viewports[v].lines[line].subline_expire_time) + | 1696 | current_tick : data->lines[line].subline_expire_time) + |
1697 | BASE_SUBLINE_TIME*data->sublines[subline_idx].time_mult; | 1697 | BASE_SUBLINE_TIME*data->sublines[subline_idx].time_mult; |
1698 | break; | 1698 | break; |
1699 | } | 1699 | } |
@@ -1909,12 +1909,9 @@ bool gui_wps_refresh(struct gui_wps *gwps, | |||
1909 | { | 1909 | { |
1910 | display->clear_display(); | 1910 | display->clear_display(); |
1911 | 1911 | ||
1912 | for (v = 0; v < data->num_viewports; v++) | 1912 | for (i = 0; i <= data->num_lines; i++) |
1913 | { | 1913 | { |
1914 | for (i = 0; i < data->viewports[v].num_lines; i++) | 1914 | data->lines[i].curr_subline = SUBLINE_RESET; |
1915 | { | ||
1916 | data->viewports[v].lines[i].curr_subline = SUBLINE_RESET; | ||
1917 | } | ||
1918 | } | 1915 | } |
1919 | } | 1916 | } |
1920 | 1917 | ||
@@ -1951,23 +1948,24 @@ bool gui_wps_refresh(struct gui_wps *gwps, | |||
1951 | } | 1948 | } |
1952 | #endif | 1949 | #endif |
1953 | 1950 | ||
1954 | for (line = 0; line < data->viewports[v].num_lines; line++) | 1951 | for (line = data->viewports[v].first_line; |
1952 | line <= data->viewports[v].last_line; line++) | ||
1955 | { | 1953 | { |
1956 | memset(linebuf, 0, sizeof(linebuf)); | 1954 | memset(linebuf, 0, sizeof(linebuf)); |
1957 | update_line = false; | 1955 | update_line = false; |
1958 | 1956 | ||
1959 | /* get current subline for the line */ | 1957 | /* get current subline for the line */ |
1960 | new_subline_refresh = update_curr_subline(gwps, v, line); | 1958 | new_subline_refresh = update_curr_subline(gwps, line); |
1961 | 1959 | ||
1962 | subline_idx = wps_subline_index(data, v, line, | 1960 | subline_idx = wps_subline_index(data, line, |
1963 | data->viewports[v].lines[line].curr_subline); | 1961 | data->lines[line].curr_subline); |
1964 | flags = data->sublines[subline_idx].line_type; | 1962 | flags = data->sublines[subline_idx].line_type; |
1965 | 1963 | ||
1966 | if (refresh_mode == WPS_REFRESH_ALL || (flags & refresh_mode) | 1964 | if (refresh_mode == WPS_REFRESH_ALL || (flags & refresh_mode) |
1967 | || new_subline_refresh) | 1965 | || new_subline_refresh) |
1968 | { | 1966 | { |
1969 | /* get_line tells us if we need to update the line */ | 1967 | /* get_line tells us if we need to update the line */ |
1970 | update_line = get_line(gwps, v, line, data->viewports[v].lines[line].curr_subline, | 1968 | update_line = get_line(gwps, line, data->lines[line].curr_subline, |
1971 | &align, linebuf, sizeof(linebuf)); | 1969 | &align, linebuf, sizeof(linebuf)); |
1972 | } | 1970 | } |
1973 | 1971 | ||
@@ -2021,10 +2019,10 @@ bool gui_wps_refresh(struct gui_wps *gwps, | |||
2021 | /* if the line is a scrolling one we don't want to update | 2019 | /* if the line is a scrolling one we don't want to update |
2022 | too often, so that it has the time to scroll */ | 2020 | too often, so that it has the time to scroll */ |
2023 | if ((refresh_mode & WPS_REFRESH_SCROLL) || new_subline_refresh) | 2021 | if ((refresh_mode & WPS_REFRESH_SCROLL) || new_subline_refresh) |
2024 | write_line(display, &align, line, true); | 2022 | write_line(display, &align, line - data->viewports[v].first_line, true); |
2025 | } | 2023 | } |
2026 | else | 2024 | else |
2027 | write_line(display, &align, line, false); | 2025 | write_line(display, &align, line - data->viewports[v].first_line, false); |
2028 | } | 2026 | } |
2029 | 2027 | ||
2030 | } | 2028 | } |
diff --git a/apps/gui/gwps.h b/apps/gui/gwps.h index d31471c2a4..e72b41308b 100644 --- a/apps/gui/gwps.h +++ b/apps/gui/gwps.h | |||
@@ -88,7 +88,7 @@ struct align_pos { | |||
88 | + (2*LCD_HEIGHT*LCD_WIDTH/8)) | 88 | + (2*LCD_HEIGHT*LCD_WIDTH/8)) |
89 | 89 | ||
90 | #define WPS_MAX_VIEWPORTS 16 | 90 | #define WPS_MAX_VIEWPORTS 16 |
91 | #define WPS_MAX_LINES (LCD_HEIGHT/5+1) | 91 | #define WPS_MAX_LINES ((LCD_HEIGHT/5+1) * 2) |
92 | #define WPS_MAX_SUBLINES (WPS_MAX_LINES*3) | 92 | #define WPS_MAX_SUBLINES (WPS_MAX_LINES*3) |
93 | #define WPS_MAX_TOKENS 1024 | 93 | #define WPS_MAX_TOKENS 1024 |
94 | #define WPS_MAX_STRINGS 128 | 94 | #define WPS_MAX_STRINGS 128 |
@@ -321,10 +321,9 @@ struct wps_line { | |||
321 | struct wps_viewport { | 321 | struct wps_viewport { |
322 | struct viewport vp; /* The LCD viewport struct */ | 322 | struct viewport vp; /* The LCD viewport struct */ |
323 | 323 | ||
324 | /* Number of lines in this viewport. During WPS parsing, this is | 324 | /* Indexes of the first and last lines belonging to this viewport in the |
325 | the index of the line being parsed. */ | 325 | lines[] array */ |
326 | int num_lines; | 326 | int first_line, last_line; |
327 | struct wps_line lines[WPS_MAX_LINES]; | ||
328 | }; | 327 | }; |
329 | 328 | ||
330 | /* wps_data | 329 | /* wps_data |
@@ -371,10 +370,16 @@ struct wps_data | |||
371 | bool remote_wps; | 370 | bool remote_wps; |
372 | #endif | 371 | #endif |
373 | 372 | ||
373 | /* Number of lines in the WPS. During WPS parsing, this is | ||
374 | the index of the line being parsed. */ | ||
375 | int num_lines; | ||
376 | |||
374 | /* Number of viewports in the WPS */ | 377 | /* Number of viewports in the WPS */ |
375 | int num_viewports; | 378 | int num_viewports; |
376 | struct wps_viewport viewports[WPS_MAX_VIEWPORTS]; | 379 | struct wps_viewport viewports[WPS_MAX_VIEWPORTS]; |
377 | 380 | ||
381 | struct wps_line lines[WPS_MAX_LINES]; | ||
382 | |||
378 | /* Total number of sublines in the WPS. During WPS parsing, this is | 383 | /* Total number of sublines in the WPS. During WPS parsing, this is |
379 | the index of the subline where the parsed tokens are added to. */ | 384 | the index of the subline where the parsed tokens are added to. */ |
380 | int num_sublines; | 385 | int num_sublines; |
@@ -403,25 +408,22 @@ bool wps_data_load(struct wps_data *wps_data, | |||
403 | bool isfile); | 408 | bool isfile); |
404 | 409 | ||
405 | /* Returns the index of the subline in the subline array | 410 | /* Returns the index of the subline in the subline array |
406 | v - 0-based viewport number | ||
407 | line - 0-based line number | 411 | line - 0-based line number |
408 | subline - 0-based subline number within the line | 412 | subline - 0-based subline number within the line |
409 | */ | 413 | */ |
410 | int wps_subline_index(struct wps_data *wps_data, int v, int line, int subline); | 414 | int wps_subline_index(struct wps_data *wps_data, int line, int subline); |
411 | 415 | ||
412 | /* Returns the index of the first subline's token in the token array | 416 | /* Returns the index of the first subline's token in the token array |
413 | v - 0-based viewport number | ||
414 | line - 0-based line number | 417 | line - 0-based line number |
415 | subline - 0-based subline number within the line | 418 | subline - 0-based subline number within the line |
416 | */ | 419 | */ |
417 | int wps_first_token_index(struct wps_data *data, int v, int line, int subline); | 420 | int wps_first_token_index(struct wps_data *data, int line, int subline); |
418 | 421 | ||
419 | /* Returns the index of the last subline's token in the token array. | 422 | /* Returns the index of the last subline's token in the token array. |
420 | v - 0-based viewport number | ||
421 | line - 0-based line number | 423 | line - 0-based line number |
422 | subline - 0-based subline number within the line | 424 | subline - 0-based subline number within the line |
423 | */ | 425 | */ |
424 | int wps_last_token_index(struct wps_data *data, int v, int line, int subline); | 426 | int wps_last_token_index(struct wps_data *data, int line, int subline); |
425 | 427 | ||
426 | /* wps_data end */ | 428 | /* wps_data end */ |
427 | 429 | ||
diff --git a/apps/gui/wps_debug.c b/apps/gui/wps_debug.c index 0c13fd2c22..9bff1d23ae 100644 --- a/apps/gui/wps_debug.c +++ b/apps/gui/wps_debug.c | |||
@@ -502,7 +502,8 @@ static void print_line_info(struct wps_data *data) | |||
502 | DEBUGF("Number of viewports : %d\n", data->num_viewports); | 502 | DEBUGF("Number of viewports : %d\n", data->num_viewports); |
503 | for (v = 0; v < data->num_viewports; v++) | 503 | for (v = 0; v < data->num_viewports; v++) |
504 | { | 504 | { |
505 | DEBUGF("vp %d: Number of lines: %d\n", v, data->viewports[v].num_lines); | 505 | DEBUGF("vp %d: First line: %d\n", v, data->viewports[v].first_line); |
506 | DEBUGF("vp %d: Last line: %d\n", v, data->viewports[v].last_line); | ||
506 | } | 507 | } |
507 | DEBUGF("Number of sublines : %d\n", data->num_sublines); | 508 | DEBUGF("Number of sublines : %d\n", data->num_sublines); |
508 | DEBUGF("Number of tokens : %d\n", data->num_tokens); | 509 | DEBUGF("Number of tokens : %d\n", data->num_tokens); |
@@ -517,7 +518,7 @@ static void print_line_info(struct wps_data *data) | |||
517 | data->viewports[v].vp.y, | 518 | data->viewports[v].vp.y, |
518 | data->viewports[v].vp.width, | 519 | data->viewports[v].vp.width, |
519 | data->viewports[v].vp.height); | 520 | data->viewports[v].vp.height); |
520 | for (i = 0, line = data->viewports[v].lines; i < data->viewports[v].num_lines; i++,line++) | 521 | for (i = data->viewports[v].first_line, line = &data->lines[data->viewports[v].first_line]; i <= data->viewports[v].last_line; i++,line++) |
521 | { | 522 | { |
522 | DEBUGF("Line %2d (num_sublines=%d, first_subline=%d)\n", | 523 | DEBUGF("Line %2d (num_sublines=%d, first_subline=%d)\n", |
523 | i, line->num_sublines, line->first_subline_idx); | 524 | i, line->num_sublines, line->first_subline_idx); |
@@ -527,7 +528,7 @@ static void print_line_info(struct wps_data *data) | |||
527 | { | 528 | { |
528 | DEBUGF(" Subline %d: first_token=%3d, last_token=%3d", | 529 | DEBUGF(" Subline %d: first_token=%3d, last_token=%3d", |
529 | j, subline->first_token_idx, | 530 | j, subline->first_token_idx, |
530 | wps_last_token_index(data, v, i, j)); | 531 | wps_last_token_index(data, i, j)); |
531 | 532 | ||
532 | if (subline->line_type & WPS_REFRESH_SCROLL) | 533 | if (subline->line_type & WPS_REFRESH_SCROLL) |
533 | DEBUGF(", scrolled"); | 534 | DEBUGF(", scrolled"); |
diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c index c641f2c247..be3d2fb882 100644 --- a/apps/gui/wps_parser.c +++ b/apps/gui/wps_parser.c | |||
@@ -338,11 +338,9 @@ static int skip_end_of_line(const char *wps_bufptr) | |||
338 | /* Starts a new subline in the current line during parsing */ | 338 | /* Starts a new subline in the current line during parsing */ |
339 | static void wps_start_new_subline(struct wps_data *data) | 339 | static void wps_start_new_subline(struct wps_data *data) |
340 | { | 340 | { |
341 | struct wps_viewport* vp = &data->viewports[data->num_viewports]; | ||
342 | |||
343 | data->num_sublines++; | 341 | data->num_sublines++; |
344 | data->sublines[data->num_sublines].first_token_idx = data->num_tokens; | 342 | data->sublines[data->num_sublines].first_token_idx = data->num_tokens; |
345 | vp->lines[vp->num_lines].num_sublines++; | 343 | data->lines[data->num_lines].num_sublines++; |
346 | } | 344 | } |
347 | 345 | ||
348 | #ifdef HAVE_LCD_BITMAP | 346 | #ifdef HAVE_LCD_BITMAP |
@@ -585,12 +583,14 @@ static int parse_viewport(const char *wps_bufptr, | |||
585 | } | 583 | } |
586 | } | 584 | } |
587 | #endif | 585 | #endif |
588 | 586 | ||
589 | wps_data->viewports[wps_data->num_viewports].num_lines = 0; | 587 | wps_data->viewports[wps_data->num_viewports-1].last_line = wps_data->num_lines - 1; |
588 | |||
589 | wps_data->viewports[wps_data->num_viewports].first_line = wps_data->num_lines; | ||
590 | 590 | ||
591 | if (wps_data->num_sublines < WPS_MAX_SUBLINES) | 591 | if (wps_data->num_sublines < WPS_MAX_SUBLINES) |
592 | { | 592 | { |
593 | wps_data->viewports[wps_data->num_viewports].lines[0].first_subline_idx = | 593 | wps_data->lines[wps_data->num_lines].first_subline_idx = |
594 | wps_data->num_sublines; | 594 | wps_data->num_sublines; |
595 | 595 | ||
596 | wps_data->sublines[wps_data->num_sublines].first_token_idx = | 596 | wps_data->sublines[wps_data->num_sublines].first_token_idx = |
@@ -599,7 +599,7 @@ static int parse_viewport(const char *wps_bufptr, | |||
599 | 599 | ||
600 | /* Skip the rest of the line */ | 600 | /* Skip the rest of the line */ |
601 | return skip_end_of_line(wps_bufptr); | 601 | return skip_end_of_line(wps_bufptr); |
602 | } | 602 | } |
603 | 603 | ||
604 | 604 | ||
605 | static int parse_image_special(const char *wps_bufptr, | 605 | static int parse_image_special(const char *wps_bufptr, |
@@ -1072,7 +1072,7 @@ static bool wps_parse(struct wps_data *data, const char *wps_bufptr) | |||
1072 | 1072 | ||
1073 | while(*wps_bufptr && !fail && data->num_tokens < WPS_MAX_TOKENS - 1 | 1073 | while(*wps_bufptr && !fail && data->num_tokens < WPS_MAX_TOKENS - 1 |
1074 | && data->num_viewports < WPS_MAX_VIEWPORTS | 1074 | && data->num_viewports < WPS_MAX_VIEWPORTS |
1075 | && data->viewports[data->num_viewports].num_lines < WPS_MAX_LINES) | 1075 | && data->num_lines < WPS_MAX_LINES) |
1076 | { | 1076 | { |
1077 | switch(*wps_bufptr++) | 1077 | switch(*wps_bufptr++) |
1078 | { | 1078 | { |
@@ -1180,12 +1180,12 @@ static bool wps_parse(struct wps_data *data, const char *wps_bufptr) | |||
1180 | 1180 | ||
1181 | line++; | 1181 | line++; |
1182 | wps_start_new_subline(data); | 1182 | wps_start_new_subline(data); |
1183 | data->viewports[data->num_viewports].num_lines++; /* Start a new line */ | 1183 | data->num_lines++; /* Start a new line */ |
1184 | 1184 | ||
1185 | if ((data->viewports[data->num_viewports].num_lines < WPS_MAX_LINES) && | 1185 | if ((data->num_lines < WPS_MAX_LINES) && |
1186 | (data->num_sublines < WPS_MAX_SUBLINES)) | 1186 | (data->num_sublines < WPS_MAX_SUBLINES)) |
1187 | { | 1187 | { |
1188 | data->viewports[data->num_viewports].lines[data->viewports[data->num_viewports].num_lines].first_subline_idx = | 1188 | data->lines[data->num_lines].first_subline_idx = |
1189 | data->num_sublines; | 1189 | data->num_sublines; |
1190 | 1190 | ||
1191 | data->sublines[data->num_sublines].first_token_idx = | 1191 | data->sublines[data->num_sublines].first_token_idx = |
@@ -1262,6 +1262,8 @@ static bool wps_parse(struct wps_data *data, const char *wps_bufptr) | |||
1262 | if (!fail && level >= 0) /* there are unclosed conditionals */ | 1262 | if (!fail && level >= 0) /* there are unclosed conditionals */ |
1263 | fail = PARSE_FAIL_UNCLOSED_COND; | 1263 | fail = PARSE_FAIL_UNCLOSED_COND; |
1264 | 1264 | ||
1265 | data->viewports[data->num_viewports].last_line = data->num_lines - 1; | ||
1266 | |||
1265 | /* We have finished with the last viewport, so increment count */ | 1267 | /* We have finished with the last viewport, so increment count */ |
1266 | data->num_viewports++; | 1268 | data->num_viewports++; |
1267 | 1269 | ||
@@ -1512,20 +1514,20 @@ bool wps_data_load(struct wps_data *wps_data, | |||
1512 | } | 1514 | } |
1513 | } | 1515 | } |
1514 | 1516 | ||
1515 | int wps_subline_index(struct wps_data *data, int v, int line, int subline) | 1517 | int wps_subline_index(struct wps_data *data, int line, int subline) |
1516 | { | 1518 | { |
1517 | return data->viewports[v].lines[line].first_subline_idx + subline; | 1519 | return data->lines[line].first_subline_idx + subline; |
1518 | } | 1520 | } |
1519 | 1521 | ||
1520 | int wps_first_token_index(struct wps_data *data, int v, int line, int subline) | 1522 | int wps_first_token_index(struct wps_data *data, int line, int subline) |
1521 | { | 1523 | { |
1522 | int first_subline_idx = data->viewports[v].lines[line].first_subline_idx; | 1524 | int first_subline_idx = data->lines[line].first_subline_idx; |
1523 | return data->sublines[first_subline_idx + subline].first_token_idx; | 1525 | return data->sublines[first_subline_idx + subline].first_token_idx; |
1524 | } | 1526 | } |
1525 | 1527 | ||
1526 | int wps_last_token_index(struct wps_data *data, int v, int line, int subline) | 1528 | int wps_last_token_index(struct wps_data *data, int line, int subline) |
1527 | { | 1529 | { |
1528 | int first_subline_idx = data->viewports[v].lines[line].first_subline_idx; | 1530 | int first_subline_idx = data->lines[line].first_subline_idx; |
1529 | int idx = first_subline_idx + subline; | 1531 | int idx = first_subline_idx + subline; |
1530 | if (idx < data->num_sublines - 1) | 1532 | if (idx < data->num_sublines - 1) |
1531 | { | 1533 | { |