[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs buffer.c clang.c extras.c list.c parser....
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs buffer.c clang.c extras.c list.c parser.... |
Date: |
Fri, 23 Dec 2016 14:51:49 -0500 (EST) |
CVSROOT: /sources/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 16/12/23 14:51:48
Modified files:
. : buffer.c clang.c extras.c list.c parser.c qe.c
qe.h search.c shell.c unihex.c
Log message:
basic: simplifications
- remove `eb_nextc_style()`
- `eb_nextc()` does not modify `b->cur_style`
- add `eb_get_style()` to retrieve style for given offset in full-style
buffers
- add `eb_next()` and `eb_prev()` to skip chars
- pass `offset` to `eb_get_line()` and `generic_get_colorized_line()`...
- use `eb_skip_chars()` in `do_delete_char()` and `text_write_char()`
- replaced `eb_get_strline()` with `eb_fgets()` with similar semantics
except return value is number of bytes before the newline or end of
line
- no longer pass end offset to `isearch_colorize_matches()`
- just pass number of code points to `combine_static_colorized_line()`
- no longer call `isearch_colorize_matches` from
`generic_get_colorized_line`
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/buffer.c?cvsroot=qemacs&r1=1.103&r2=1.104
http://cvs.savannah.gnu.org/viewcvs/qemacs/clang.c?cvsroot=qemacs&r1=1.111&r2=1.112
http://cvs.savannah.gnu.org/viewcvs/qemacs/extras.c?cvsroot=qemacs&r1=1.45&r2=1.46
http://cvs.savannah.gnu.org/viewcvs/qemacs/list.c?cvsroot=qemacs&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/qemacs/parser.c?cvsroot=qemacs&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.233&r2=1.234
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.226&r2=1.227
http://cvs.savannah.gnu.org/viewcvs/qemacs/search.c?cvsroot=qemacs&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/qemacs/shell.c?cvsroot=qemacs&r1=1.113&r2=1.114
http://cvs.savannah.gnu.org/viewcvs/qemacs/unihex.c?cvsroot=qemacs&r1=1.33&r2=1.34
Patches:
Index: buffer.c
===================================================================
RCS file: /sources/qemacs/qemacs/buffer.c,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -b -r1.103 -r1.104
--- buffer.c 13 Dec 2016 17:20:51 -0000 1.103
+++ buffer.c 23 Dec 2016 19:51:48 -0000 1.104
@@ -1458,25 +1458,25 @@
return ch;
}
-int eb_nextc_style(EditBuffer *b, int offset, int *next_ptr)
+int eb_get_style(EditBuffer *b, int offset)
{
if (b->b_styles) {
if (b->style_shift == 2) {
uint32_t style = 0;
eb_read(b->b_styles, (offset >> b->char_shift) << 2, &style, 4);
- b->cur_style = style;
+ return style;
} else
if (b->style_shift == 1) {
uint16_t style = 0;
eb_read(b->b_styles, (offset >> b->char_shift) << 1, &style, 2);
- b->cur_style = style;
+ return style;
} else {
uint8_t style = 0;
eb_read(b->b_styles, (offset >> b->char_shift), &style, 1);
- b->cur_style = style;
+ return style;
}
}
- return eb_nextc(b, offset, next_ptr);
+ return 0;
}
/* compute offset after moving 'n' chars from 'offset'.
@@ -1484,13 +1484,11 @@
*/
int eb_skip_chars(EditBuffer *b, int offset, int n)
{
- while (n < 0) {
- eb_prevc(b, offset, &offset);
- n++;
- }
- while (n > 0) {
- eb_nextc(b, offset, &offset);
- n--;
+ for (; n < 0 && offset > 0; n++) {
+ offset = eb_prev(b, offset);
+ }
+ for (; n > 0 && offset < b->total_size; n--) {
+ offset = eb_next(b, offset);
}
return offset;
}
@@ -1500,7 +1498,7 @@
{
int offset1;
- eb_nextc(b, offset, &offset1);
+ offset1 = eb_next(b, offset);
if (offset < offset1) {
return eb_delete(b, offset, offset1 - offset);
} else {
@@ -1530,7 +1528,7 @@
int eb_prevc(EditBuffer *b, int offset, int *prev_ptr)
{
int ch, char_size;
- u8 buf[MAX_CHAR_BYTES], *q;
+ u8 buf[MAX_CHAR_BYTES + 1], *q;
if (offset <= 0) {
offset = 0;
@@ -1543,6 +1541,7 @@
if (utf8_is_trailing_byte(ch)) {
int offset1 = offset;
q = buf + sizeof(buf);
+ *--q = '\0';
*--q = ch;
while (utf8_is_trailing_byte(ch) && offset > 0 && q > buf) {
offset -= 1;
@@ -1551,10 +1550,10 @@
if (ch >= 0xc0) {
ch = utf8_decode((const char **)(void *)&q);
}
- if (q != buf + sizeof(buf)) {
+ if (q != buf + sizeof(buf) - 1) {
/* decoding error: only take the last byte */
offset = offset1;
- ch = buf[sizeof(buf) - 1];
+ ch = buf[sizeof(buf) - 2];
}
}
} else {
@@ -1725,6 +1724,7 @@
} else {
/* XXX: should handle rounding if EOL_DOS */
/* XXX: should fix buffer offset via charset specific method */
+ /* XXX: fails in case of encoding error */
if (b->charset == &charset_utf8) {
/* Round offset down to character boundary */
u8 buf[1];
@@ -2349,9 +2349,10 @@
size = 0;
for (offset = src_offset; offset < offset_max;) {
char buf[MAX_CHAR_BYTES];
- int c = eb_nextc_style(src, offset, &offset);
+ int style = eb_get_style(src, offset);
+ int c = eb_nextc(src, offset, &offset);
int len = eb_encode_uchar(b, buf, c);
- b->cur_style = src->cur_style;
+ b->cur_style = style;
size += eb_insert(b, offset1 + size, buf, len);
}
@@ -2363,59 +2364,67 @@
}
}
-/* get the line starting at offset 'offset' as an array of code points */
-/* offset is bumped to the beginning of the next line */
-/* returns the number of code points stored in buf, excluding '\0' */
-/* buf_size must be > 0 */
-/* XXX: cannot detect truncation */
-int eb_get_line(EditBuffer *b, unsigned int *buf, int buf_size,
- int *offset_ptr)
+/* Get the line starting at offset `offset` as an array of code points.
+ * `offset` is bumped to point to the first unread character.
+ * Returns `len` >= 0 and < buf_size, the offset into the destination
+ * of the end of the line, either the '\n' or the final '\0'.
+ * Truncation can be detected by checking if buf[len] is '\n'.
+ */
+int eb_get_line(EditBuffer *b, unsigned int *buf, int size,
+ int offset, int *offset_ptr)
{
- unsigned int *buf_ptr, *buf_end;
- int c, offset;
-
- offset = *offset_ptr;
+ int c, len = 0;
- buf_ptr = buf;
- buf_end = buf + buf_size - 1;
+ if (size > 0) {
for (;;) {
+ if (len + 1 >= size) {
+ buf[len] = '\0';
+ break;
+ }
c = eb_nextc(b, offset, &offset);
- if (c == '\n')
+ buf[len++] = c & CHAR_MASK;
+ if (c == '\n') {
+ /* add null terminator but return offset of newline */
+ buf[len--] = '\0';
break;
- if (buf_ptr < buf_end)
- *buf_ptr++ = c & CHAR_MASK;
}
- *buf_ptr = '\0';
+ }
+ }
+ if (offset_ptr)
*offset_ptr = offset;
- return buf_ptr - buf;
+
+ return len;
}
-/* get the line starting at offset 'offset' encoded in utf-8 */
-/* offset is bumped to the beginning of the next line */
-/* returns the number of bytes stored in buf, excluding '\0' */
-/* buf_size must be > 0 */
-/* XXX: cannot detect truncation */
-int eb_get_strline(EditBuffer *b, char *buf, int buf_size,
- int *offset_ptr)
+/* Get the line starting at offset `offset` encoded in UTF-8.
+ * `offset` is bumped to point to the first unread character.
+ * Returns `len` >= 0 and < buf_size, the offset into the destination
+ * of the end of the line, either the '\n' or the final '\0'.
+ * Truncation can be detected by checking if buf[len] is '\n'.
+ */
+int eb_fgets(EditBuffer *b, char *buf, int buf_size,
+ int offset, int *offset_ptr)
{
buf_t outbuf, *out;
- int offset;
-
- offset = *offset_ptr;
out = buf_init(&outbuf, buf, buf_size);
for (;;) {
- int c = eb_nextc(b, offset, &offset);
- if (c == '\n')
+ int next;
+ int c = eb_nextc(b, offset, &next);
+ if (!buf_putc_utf8(out, c)) {
+ /* truncation: offset points to the first unread character */
break;
- if (buf_putc_utf8(out, c))
- continue;
- /* overflow: skip past '\n' */
- offset = eb_next_line(b, offset);
+ }
+ offset = next;
+ if (c == '\n') {
+ /* end of line: offset points to the beginning of the next line */
+ /* adjust return value for easy stripping and truncation test */
+ out->pos--;
break;
}
+ }
*offset_ptr = offset;
- return out->len;
+ return out->pos;
}
int eb_prev_line(EditBuffer *b, int offset)
Index: clang.c
===================================================================
RCS file: /sources/qemacs/qemacs/clang.c,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -b -r1.111 -r1.112
--- clang.c 23 Dec 2016 12:21:46 -0000 1.111
+++ clang.c 23 Dec 2016 19:51:48 -0000 1.112
@@ -772,9 +772,10 @@
break;
line_num--;
offsetl = eb_prev_line(s->b, offsetl);
- offset1 = offsetl;
/* XXX: deal with truncation */
- len = s->get_colorized_line(s, buf, countof(buf), &offset1, line_num);
+ /* XXX: should only query the syntax colorizer */
+ len = s->get_colorized_line(s, buf, countof(buf),
+ offsetl, &offset1, line_num);
/* store indent position */
pos1 = find_indent1(s, buf);
p = buf + len;
@@ -897,9 +898,10 @@
}
end_parse:
/* compute special cases which depend on the chars on the current line */
- offset1 = offset;
/* XXX: deal with truncation */
- len = s->get_colorized_line(s, buf, countof(buf), &offset1, line_num1);
+ /* XXX: should only query the syntax colorizer */
+ len = s->get_colorized_line(s, buf, countof(buf),
+ offset, &offset1, line_num1);
if (stack_ptr == 0) {
if (!pos && lpos >= 0) {
@@ -1028,8 +1030,8 @@
eb_get_pos(s->b, &line_num, &col_num, offset);
level = 0;
for (;;) {
- offset1 = offset;
- s->get_colorized_line(s, buf, countof(buf), &offset1, line_num);
+ /* XXX: should only query the syntax colorizer */
+ s->get_colorized_line(s, buf, countof(buf), offset, &offset1,
line_num);
sharp = 0;
for (p = buf; *p; p++) {
int c = (*p & CHAR_MASK);
@@ -1094,8 +1096,8 @@
while (offset > 0) {
line_num--;
offset = eb_prev_line(s->b, offset);
- offset1 = offset;
- s->get_colorized_line(s, buf, countof(buf), &offset1, line_num);
+ /* XXX: should only query the syntax colorizer */
+ s->get_colorized_line(s, buf, countof(buf), offset, &offset1,
line_num);
sharp = 0;
for (p = buf; *p; p++) {
int c = (*p & CHAR_MASK);
@@ -1833,7 +1835,6 @@
"extends|false|final|foreach|for|function|goto|if|implements|"
"include_once|include|instanceof|interface|list|namespace|new|"
"overload|parent|private|protected|public|require_once|require|return|"
- "self|sizeof|static|switch|$this|throw|trait|true|try|use|var|while|"
"self|sizeof|static|switch|throw|trait|true|try|use|var|while|"
"NULL|null|$this"
// built-in pseudo functions
Index: extras.c
===================================================================
RCS file: /sources/qemacs/qemacs/extras.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- extras.c 13 Dec 2016 13:29:31 -0000 1.45
+++ extras.c 23 Dec 2016 19:51:48 -0000 1.46
@@ -430,7 +430,7 @@
offset = eb_goto_bol2(s->b, s->offset, &pos);
offset1 = offset;
/* XXX: deal with truncation */
- len = s->get_colorized_line(s, buf, countof(buf), &offset1, line_num);
+ len = s->get_colorized_line(s, buf, countof(buf), offset1, &offset1,
line_num);
if (pos > len) {
/* cannot use colorized line buffer */
/* XXX: should use buffer contents */
@@ -449,7 +449,7 @@
offset1 = offset;
/* XXX: this will actually ignore the end of very long lines */
/* XXX: deal with truncation */
- pos = s->get_colorized_line(s, buf, countof(buf), &offset1,
line_num);
+ pos = s->get_colorized_line(s, buf, countof(buf), offset1,
&offset1, line_num);
continue;
}
c = buf[--pos];
@@ -504,7 +504,7 @@
offset1 = offset;
/* XXX: this will actually ignore the end of very long lines */
/* XXX: deal with truncation */
- len = s->get_colorized_line(s, buf, countof(buf), &offset1,
line_num);
+ len = s->get_colorized_line(s, buf, countof(buf), offset1,
&offset1, line_num);
continue;
}
c = buf[pos];
@@ -586,13 +586,13 @@
end_offset = offset2 = s->offset;
if (eb_nextc(b, offset2, &offset3) == '\n') {
offset3 = offset2;
- eb_prevc(b, offset3, &offset2);
+ offset2 = eb_prev(b, offset3);
end_offset = s->offset;
offset1 = offset2;
- eb_prevc(b, offset1, &offset0);
+ offset0 = eb_prev(b, offset1);
} else {
offset1 = offset2;
- eb_prevc(b, offset1, &offset0);
+ offset0 = eb_prev(b, offset1);
if (s->qe_state->flag_split_window_change_focus) {
/* keep current position between characters */
end_offset = offset0 + offset3 - offset2;
@@ -625,7 +625,7 @@
offset3 = s->offset;
do_bol(s);
offset2 = s->offset;
- eb_prevc(b, offset2, &offset1); /* skip line feed */
+ offset1 = eb_prev(b, offset2); /* skip line feed */
s->offset = offset1;
do_bol(s);
offset0 = s->offset;
@@ -1239,7 +1239,7 @@
for (i = 0; i < lines; i++) {
chunk_array[i].start = offset;
chunk_array[i].end = offset = eb_goto_eol(s->b, offset);
- eb_nextc(s->b, offset, &offset);
+ offset = eb_next(s->b, offset);
}
qsort_r(chunk_array, lines, sizeof(*chunk_array), &ctx, chunk_cmp);
Index: list.c
===================================================================
RCS file: /sources/qemacs/qemacs/list.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- list.c 16 Sep 2015 22:18:24 -0000 1.20
+++ list.c 23 Dec 2016 19:51:48 -0000 1.21
@@ -25,14 +25,16 @@
static int list_get_colorized_line(EditState *s,
unsigned int *buf, int buf_size,
- int *offsetp, qe__unused__ int line_num)
+ int offset, int *offsetp,
+ qe__unused__ int line_num)
{
QEmacsState *qs = s->qe_state;
- int offset, len;
+ int len;
- offset = *offsetp;
/* Get line contents including static buffer styles */
- len = generic_get_colorized_line(s, buf, buf_size, offsetp, line_num);
+ /* XXX: deal with truncation */
+ /* XXX: should just use s->cur_line style */
+ len = generic_get_colorized_line(s, buf, buf_size, offset, offsetp,
line_num);
if (((qs->active_window == s) || s->force_highlight) &&
s->offset >= offset && s->offset < *offsetp)
Index: parser.c
===================================================================
RCS file: /sources/qemacs/qemacs/parser.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- parser.c 14 Sep 2015 19:05:53 -0000 1.5
+++ parser.c 23 Dec 2016 19:51:48 -0000 1.6
@@ -99,10 +99,10 @@
return fgets(buf, size, ds->f);
}
if (ds->b) {
- /* buffer should not be modified during parse! */
- // XXX: parsing will continue beyond `stop` to end of line */
+ /* EditBuffer should not be modified during parse! */
if (ds->offset < ds->stop && ds->offset < ds->b->total_size) {
- eb_get_strline(ds->b, buf, size, &ds->offset);
+ // XXX: parsing will continue beyond `stop` to end of line */
+ eb_fgets(ds->b, buf, size, ds->offset, &ds->offset);
return buf;
}
return NULL;
Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.233
retrieving revision 1.234
diff -u -b -r1.233 -r1.234
--- qe.c 23 Dec 2016 15:51:51 -0000 1.233
+++ qe.c 23 Dec 2016 19:51:48 -0000 1.234
@@ -591,7 +591,7 @@
if (eb_is_blank_line(b, offset, &offset)) {
break;
}
- eb_prevc(b, offset, &offset);
+ offset = eb_prev(b, offset);
}
return offset;
}
@@ -617,7 +617,7 @@
if (!eb_is_blank_line(s->b, offset, NULL))
break;
/* line just before */
- eb_prevc(s->b, offset, &offset);
+ offset = eb_prev(s->b, offset);
}
offset = eb_start_paragraph(s->b, offset);
@@ -803,7 +803,7 @@
void do_delete_char(EditState *s, int argval)
{
- int endpos, i;
+ int endpos;
if (s->b->flags & BF_READONLY)
return;
@@ -823,13 +823,7 @@
}
/* save kill if numeric argument given */
- endpos = s->offset;
- for (i = argval; i > 0 && endpos < s->b->total_size; i--) {
- eb_nextc(s->b, endpos, &endpos);
- }
- for (i = argval; i < 0 && endpos > 0; i++) {
- eb_prevc(s->b, endpos, &endpos);
- }
+ endpos = eb_skip_chars(s->b, s->offset, argval);
do_kill(s, s->offset, endpos, argval, 0);
}
@@ -863,7 +857,7 @@
return;
}
if (s->qe_state->last_cmd_func != (CmdFunc)do_append_next_kill) {
- eb_prevc(s->b, s->offset, &offset1);
+ offset1 = eb_prev(s->b, s->offset);
if (offset1 < s->offset) {
eb_delete_range(s->b, offset1, s->offset);
/* special case for composing */
@@ -1019,7 +1013,7 @@
if (offset_top <= 0)
return;
- eb_prevc(s->b, offset_top, &offset_top);
+ offset_top = eb_prev(s->b, offset_top);
s->offset_top = s->mode->backward_offset(s, offset_top);
/* adjust y_disp so that the cursor is at the same position */
@@ -1143,21 +1137,19 @@
it negative */
if (s->y_disp > 0) {
display_init(ds, s, DISP_CURSOR_SCREEN);
- do {
- int offset_top = s->offset_top;
-
- if (offset_top <= 0) {
+ while (s->y_disp > 0) {
+ if (s->offset_top <= 0) {
/* cannot go back: we stay at the top of the screen and
exit loop */
s->y_disp = 0;
} else {
- eb_prevc(s->b, offset_top, &offset_top);
- s->offset_top = s->mode->backward_offset(s, offset_top);
+ int offset = eb_prev(s->b, s->offset_top);
+ s->offset_top = s->mode->backward_offset(s, offset);
ds->y = 0;
s->mode->display_line(s, ds, s->offset_top);
s->y_disp -= ds->y;
}
- } while (s->y_disp > 0);
+ }
}
/* now update cursor position so that it is on screen */
@@ -1209,9 +1201,8 @@
* speeds up get_cursor_pos() on large files, except for the
* pathological case of huge lines.
*/
- int offset_top = s->offset;
- eb_prevc(s->b, offset_top, &offset_top);
- s->offset_top = s->mode->backward_offset(s, offset_top);
+ int offset = eb_prev(s->b, s->offset);
+ s->offset_top = s->mode->backward_offset(s, offset);
} else {
if (!force)
return;
@@ -1306,12 +1297,12 @@
} else {
/* no suitable position found: go to previous line */
if (yc <= 0) {
- int offset_top = s->offset_top;
+ int offset = s->offset_top;
- if (offset_top <= 0)
+ if (offset <= 0)
break;
- eb_prevc(s->b, offset_top, &offset_top);
- s->offset_top = s->mode->backward_offset(s, offset_top);
+ offset = eb_prev(s->b, offset);
+ s->offset_top = s->mode->backward_offset(s, offset);
/* adjust y_disp so that the cursor is at the same
position */
s->y_disp += cm.yc;
get_cursor_pos(s, &cm);
@@ -1538,9 +1529,7 @@
break;
} else {
/* match: delete matched chars */
- offset = s->compose_start_offset;
- for (i = 0; i < match_len; i++)
- eb_nextc(s->b, offset, &offset);
+ offset = eb_skip_chars(s->b, s->compose_start_offset,
match_len);
eb_delete_range(s->b, s->compose_start_offset, offset);
s->compose_len -= match_len;
umemmove(s->compose_buf, s->compose_buf + match_len,
@@ -1822,7 +1811,7 @@
p2 = s->offset;
if (p2 <= 0 || argval == 0)
break;
- eb_prevc(s->b, p2, &p2);
+ p2 = eb_prev(s->b, p2);
s->offset = p2;
argval += 1;
}
@@ -1832,7 +1821,7 @@
p2 = s->offset;
if (p2 >= s->b->total_size || argval == 0)
break;
- eb_nextc(s->b, p2, &p2);
+ p2 = eb_next(s->b, p2);
s->offset = p2;
argval -= 1;
}
@@ -2265,7 +2254,7 @@
QECharset *charset;
EOLType eol_type;
EditBuffer *b1, *b;
- int offset, c, len, i;
+ int offset, len, i;
EditBufferCallbackList *cb;
int pos[32];
char buf[MAX_CHAR_BYTES];
@@ -2291,8 +2280,9 @@
/* slow, but simple iterative method */
for (offset = 0; offset < b->total_size;) {
- c = eb_nextc_style(b, offset, &offset);
- b1->cur_style = b->cur_style;
+ int style = eb_get_style(b, offset);
+ int c = eb_nextc(b, offset, &offset);
+ b1->cur_style = style;
len = eb_encode_uchar(b1, buf, c);
eb_insert(b1, b1->total_size, buf, len);
}
@@ -3646,23 +3636,20 @@
buffer */
static int get_staticly_colorized_line(EditState *s, unsigned int *buf, int
buf_size,
- int *offset_ptr, int line_num)
+ int offset, int *offset_ptr, int
line_num)
{
EditBuffer *b = s->b;
unsigned int *buf_ptr, *buf_end;
- int c, offset;
-
- offset = *offset_ptr;
buf_ptr = buf;
buf_end = buf + buf_size - 1;
- b->cur_style = 0;
for (;;) {
- c = eb_nextc_style(b, offset, &offset);
+ int style = eb_get_style(b, offset);
+ int c = eb_nextc(b, offset, &offset);
if (c == '\n')
break;
if (buf_ptr < buf_end) {
- c |= b->cur_style << STYLE_SHIFT;
+ c = (c & CHAR_MASK) | (style << STYLE_SHIFT);
*buf_ptr++ = c;
}
}
@@ -3678,12 +3665,13 @@
#define COLORIZED_LINE_PREALLOC_SIZE 64
-static int syntax_get_colorized_line(EditState *s, unsigned int *buf,
- int buf_size, int *offsetp, int line_num)
+static int syntax_get_colorized_line(EditState *s,
+ unsigned int *buf, int buf_size,
+ int offset, int *offsetp, int line_num)
{
QEColorizeContext cctx;
EditBuffer *b = s->b;
- int len, line, n, col, offset, bom;
+ int len, line, n, col, bom;
/* invalidate cache if needed */
if (s->colorize_max_valid_offset != INT_MAX) {
@@ -3724,15 +3712,17 @@
cctx.state_only = 1;
for (line = s->colorize_nb_valid_lines; line <= line_num; line++) {
- len = eb_get_line(b, buf, buf_size - 1, &offset);
+ len = eb_get_line(b, buf, buf_size - 1, offset, &offset);
+ if (buf[len] != '\n') {
+ /* line was truncated */
+ /* XXX: should use reallocatable buffer */
+ offset = eb_goto_pos(b, line, 0);
+ }
+ buf[len] = '\0';
+
/* skip byte order mark if present */
bom = (buf[0] == 0xFEFF);
- if (bom) {
- SET_COLOR1(buf, 0, QE_STYLE_PREPROCESS);
- }
s->colorize_func(&cctx, buf + bom, len - bom, s->mode);
- /* buf[len] has char '\0' but may hold style, force buf ending */
- buf[len + 1] = 0;
s->colorize_states[line] = cctx.colorize_state;
}
}
@@ -3740,12 +3730,20 @@
/* compute line color */
cctx.colorize_state = s->colorize_states[line_num];
cctx.state_only = 0;
- len = eb_get_line(b, buf, buf_size - 1, offsetp);
+ len = eb_get_line(b, buf, buf_size - 1, offset, offsetp);
+ if (buf[len] != '\n') {
+ /* line was truncated */
+ /* XXX: should use reallocatable buffer */
+ *offsetp = eb_goto_pos(b, line_num + 1, 0);
+ }
+ buf[len] = '\0';
+
bom = (buf[0] == 0xFEFF);
if (bom) {
SET_COLOR1(buf, 0, QE_STYLE_PREPROCESS);
}
s->colorize_func(&cctx, buf + bom, len - bom, s->mode);
+ /* buf[len] has char '\0' but may hold style, force buf ending */
buf[len + 1] = 0;
/* XXX: if state is same as previous, minimize invalid region? */
@@ -3771,32 +3769,19 @@
e->colorize_max_valid_offset = offset;
}
-static int combine_static_colorized_line(EditState *s, unsigned int *buf, int
buf_size,
- int *offset_ptr, int line_num)
+static int combine_static_colorized_line(EditState *s, unsigned int *buf,
+ int len, int offset)
{
EditBuffer *b = s->b;
- unsigned int *buf_ptr, *buf_end;
- int c, offset;
- offset = *offset_ptr;
-
- buf_ptr = buf;
- buf_end = buf + buf_size - 1;
- b->cur_style = 0;
- for (;;) {
- c = eb_nextc_style(b, offset, &offset);
- if (c == '\n')
- break;
- if (buf_ptr < buf_end) {
- if (b->cur_style) {
- *buf_ptr = (*buf_ptr & CHAR_MASK) | (b->cur_style <<
STYLE_SHIFT);
- }
- buf_ptr++;
+ for (int i = 0; i < len; i++) {
+ int style = eb_get_style(b, offset);
+ if (style) {
+ buf[i] = (buf[i] & CHAR_MASK) | (style << STYLE_SHIFT);
}
+ offset = eb_next(b, offset);
}
- *buf_ptr = '\0';
- *offset_ptr = offset;
- return buf_ptr - buf;
+ return len;
}
#endif /* CONFIG_TINY */
@@ -3820,25 +3805,28 @@
}
int generic_get_colorized_line(EditState *s, unsigned int *buf, int buf_size,
- int *offsetp, int line_num)
+ int offset, int *offsetp, int line_num)
{
- int len, offset = *offsetp;
+ int len;
#ifndef CONFIG_TINY
if (s->colorize_func) {
- len = syntax_get_colorized_line(s, buf, buf_size, offsetp, line_num);
+ len = syntax_get_colorized_line(s, buf, buf_size, offset, offsetp,
line_num);
if (s->b->b_styles)
- len = combine_static_colorized_line(s, buf, buf_size, &offset,
line_num);
+ combine_static_colorized_line(s, buf, buf_size, len);
} else
#endif
- if (s->b->b_styles)
- len = get_staticly_colorized_line(s, buf, buf_size, offsetp, line_num);
- else
- len = eb_get_line(s->b, buf, buf_size, offsetp);
-
- if (s->isearch_state)
- isearch_colorize_matches(s, buf, len, offset, *offsetp);
-
+ if (s->b->b_styles) {
+ len = get_staticly_colorized_line(s, buf, buf_size, offset, offsetp,
line_num);
+ } else {
+ len = eb_get_line(s->b, buf, buf_size, offset, offsetp);
+ if (buf[len] != '\n') {
+ /* line was truncated */
+ /* XXX: should use reallocatable buffer */
+ *offsetp = eb_goto_pos(s->b, line_num + 1, 0);
+ }
+ buf[len] = '\0';
+ }
return len;
}
@@ -3909,9 +3897,14 @@
|| s->curline_style || s->region_style
|| s->b->b_styles
|| s->isearch_state) {
+ /* XXX: deal with truncation */
colored_nb_chars = s->get_colorized_line(s, colored_chars,
countof(colored_chars),
- &offset0, line_num);
+ offset, &offset0, line_num);
+ if (s->isearch_state) {
+ isearch_colorize_matches(s, colored_chars, colored_nb_chars,
+ offset);
+ }
}
#if 1
@@ -3919,24 +3912,25 @@
if (s->curline_style || s->region_style) {
/* CG: Should combine styles instead of replacing */
if (!s->curline_style && s->region_style) {
- int line, start, stop;
+ int line, start_offset, end_offset;
+ int start_char, end_char;
if (s->b->mark < s->offset) {
- start = max(offset, s->b->mark);
- stop = min(offset0, s->offset);
+ start_offset = max(offset, s->b->mark);
+ end_offset = min(offset0, s->offset);
} else {
- start = max(offset, s->offset);
- stop = min(offset0, s->b->mark);
+ start_offset = max(offset, s->offset);
+ end_offset = min(offset0, s->b->mark);
}
- if (start < stop) {
+ if (start_offset < end_offset) {
/* Compute character positions */
- eb_get_pos(s->b, &line, &start, start);
- if (stop >= offset0)
- stop = colored_nb_chars;
+ eb_get_pos(s->b, &line, &start_char, start_offset);
+ if (end_offset >= offset0)
+ end_char = colored_nb_chars;
else
- eb_get_pos(s->b, &line, &stop, stop);
- clear_color(colored_chars + start, stop - start);
- set_color(colored_chars + start, colored_chars + stop,
+ eb_get_pos(s->b, &line, &end_char, end_offset);
+ clear_color(colored_chars + start_char, end_char - start_char);
+ set_color(colored_chars + start_char, colored_chars + end_char,
s->region_style);
}
} else
@@ -4054,14 +4048,13 @@
}
while (ds->y < s->height && offset > 0) {
- eb_prevc(s->b, offset, &offset);
+ offset = eb_prev(s->b, offset);
offset = s->mode->backward_offset(s, offset);
bottom = s->mode->display_line(s, ds, offset);
}
s->offset_top = offset;
s->offset_bottom = bottom;
- /* adjust y_disp so that the cursor is at the bottom of the
- screen */
+ /* adjust y_disp so that the cursor is at the bottom of the screen */
s->y_disp = s->height - ds->y;
} else {
yc = m->yc;
@@ -5819,13 +5812,14 @@
/* if completion is activated, then select current file only if
the selection is highlighted */
if (cw && cw->force_highlight) {
- int offset;
+ int offset, len;
- offset = list_get_offset(cw);
- eb_get_strline(cw->b, buf, sizeof(buf), &offset);
- if (buf[0] != '\0')
+ len = eb_fgets(cw->b, buf, sizeof(buf), list_get_offset(cw), &offset);
+ buf[len] = '\0'; /* strip the trailing newline if any */
+ if (len > 0) {
set_minibuffer_str(s, buf + 1);
}
+ }
/* remove completion popup if present */
/* CG: assuming completion_popup_window != s */
Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.226
retrieving revision 1.227
diff -u -b -r1.226 -r1.227
--- qe.h 23 Dec 2016 15:51:51 -0000 1.226
+++ qe.h 23 Dec 2016 19:51:48 -0000 1.227
@@ -774,7 +774,7 @@
/* colorize & transform a line, lower level then ColorizeFunc */
typedef int (*GetColorizedLineFunc)(EditState *s,
unsigned int *buf, int buf_size,
- int *offset1, int line_num);
+ int offset, int *offsetp, int line_num);
struct QEColorizeContext {
EditState *s;
@@ -914,7 +914,7 @@
/* style system */
EditBuffer *b_styles;
- int cur_style;
+ int cur_style; /* current style for buffer writing APIs */
int style_bytes;
int style_shift;
@@ -995,8 +995,6 @@
qe__attr_nonnull((3))
int eb_nextc(EditBuffer *b, int offset, int *next_ptr);
qe__attr_nonnull((3))
-int eb_nextc_style(EditBuffer *b, int offset, int *next_ptr);
-qe__attr_nonnull((3))
int eb_prevc(EditBuffer *b, int offset, int *prev_ptr);
int eb_skip_chars(EditBuffer *b, int offset, int n);
int eb_delete_chars(EditBuffer *b, int offset, int n);
@@ -1008,6 +1006,15 @@
static inline int eb_at_bol(EditBuffer *b, int offset) {
return eb_prevc(b, offset, &offset) == '\n';
}
+static inline int eb_next(EditBuffer *b, int offset) {
+ eb_nextc(b, offset, &offset);
+ return offset;
+}
+static inline int eb_prev(EditBuffer *b, int offset) {
+ eb_prevc(b, offset, &offset);
+ return offset;
+}
+
//int eb_clip_offset(EditBuffer *b, int offset);
void do_undo(EditState *s);
void do_redo(EditState *s);
@@ -1027,6 +1034,7 @@
enum LogOperation op, int offset, int size);
int eb_create_style_buffer(EditBuffer *b, int flags);
void eb_free_style_buffer(EditBuffer *b);
+int eb_get_style(EditBuffer *b, int offset);
void eb_set_style(EditBuffer *b, int style, enum LogOperation op,
int offset, int size);
void eb_style_callback(EditBuffer *b, void *opaque, int arg,
@@ -1058,9 +1066,9 @@
EditBuffer *src, int src_offset,
int size);
int eb_get_line(EditBuffer *b, unsigned int *buf, int buf_size,
- int *offset_ptr);
-int eb_get_strline(EditBuffer *b, char *buf, int buf_size,
- int *offset_ptr);
+ int offset, int *offset_ptr);
+int eb_fgets(EditBuffer *b, char *buf, int buf_size,
+ int offset, int *offset_ptr);
int eb_prev_line(EditBuffer *b, int offset);
int eb_goto_bol(EditBuffer *b, int offset);
int eb_goto_bol2(EditBuffer *b, int offset, int *countp);
@@ -1641,7 +1649,7 @@
int wrap;
int eol_reached;
EditState *edit_state;
- int style; /* css display style */
+ int style; /* current style for display_printf... */
/* fragment buffers */
TextFragment fragments[MAX_SCREEN_WIDTH];
@@ -1850,7 +1858,7 @@
void do_write_file(EditState *s, const char *filename);
void do_write_region(EditState *s, const char *filename);
void isearch_colorize_matches(EditState *s, unsigned int *buf, int len,
- int offset, int offset_end);
+ int offset);
void do_isearch(EditState *s, int dir);
void do_query_replace(EditState *s, const char *search_str,
const char *replace_str);
@@ -1871,7 +1879,7 @@
void set_colorize_func(EditState *s, ColorizeFunc colorize_func);
int generic_get_colorized_line(EditState *s, unsigned int *buf, int buf_size,
- int *offsetp, int line_num);
+ int offset, int *offsetp, int line_num);
int do_delete_selection(EditState *s);
void do_char(EditState *s, int key, int argval);
Index: search.c
===================================================================
RCS file: /sources/qemacs/qemacs/search.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- search.c 23 Dec 2016 13:00:55 -0000 1.8
+++ search.c 23 Dec 2016 19:51:48 -0000 1.9
@@ -131,7 +131,7 @@
if (dir < 0) {
if (offset == 0)
return 0;
- eb_prevc(b, offset, &offset);
+ offset = eb_prev(b, offset);
} else {
offset = offset1;
if (offset >= end_offset)
@@ -537,16 +537,17 @@
}
void isearch_colorize_matches(EditState *s, unsigned int *buf, int len,
- int offset_start, int offset_end)
+ int offset_start)
{
ISearchState *is = s->isearch_state;
EditBuffer *b = s->b;
- int offset, char_offset, found_offset, found_end;
+ int offset, char_offset, found_offset, found_end, offset_end;
if (!is || is->search_u32_len <= 0)
return;
char_offset = eb_get_char_offset(b, offset_start);
+ offset_end = eb_goto_char(b, char_offset + len);
offset = 0;
if (char_offset > is->search_u32_len + 1)
offset = eb_goto_char(b, char_offset - is->search_u32_len - 1);
Index: shell.c
===================================================================
RCS file: /sources/qemacs/qemacs/shell.c,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -b -r1.113 -r1.114
--- shell.c 13 Dec 2016 17:20:51 -0000 1.113
+++ shell.c 23 Dec 2016 19:51:48 -0000 1.114
@@ -503,7 +503,7 @@
offset = s->cur_offset;
buf[0] = c;
- c1 = eb_nextc_style(s->b, offset, &offset1);
+ c1 = eb_nextc(s->b, offset, &offset1);
s->b->cur_style = QE_STYLE_TTY | s->color | s->attr;
if (c1 == '\n') {
/* insert */
@@ -1931,7 +1931,7 @@
p2 = eb_goto_bol(e->b, p2);
if (p2 <= 0 || argval == 0)
break;
- eb_prevc(e->b, p2, &p2);
+ p2 = eb_prev(e->b, p2);
argval += 1;
}
} else {
@@ -1939,7 +1939,7 @@
p2 = eb_goto_eol(e->b, p2);
if (p2 >= e->b->total_size || argval == 0)
break;
- eb_nextc(e->b, p2, &p2);
+ p2 = eb_next(e->b, p2);
argval -= 1;
}
}
@@ -2026,10 +2026,10 @@
{
char line[1024];
char curpath[MAX_FILENAME_SIZE];
- int start, first_blank, last_blank, stop, i;
+ int start, first_blank, last_blank, stop, i, len;
- offset = eb_goto_bol(b, offset);
- eb_get_strline(b, line, sizeof(line), &offset);
+ len = eb_fgets(b, line, sizeof(line), eb_goto_bol(b, offset), &offset);
+ line[len] = '\0'; /* strip the trailing newline if any */
first_blank = last_blank = 0;
for (i = 0;; i++) {
@@ -2132,7 +2132,7 @@
char filename[MAX_FILENAME_SIZE];
char fullpath[MAX_FILENAME_SIZE];
buf_t fnamebuf, *fname;
- int c, line_num, col_num;
+ int c, line_num, col_num, len;
char error_message[128];
/* CG: should have a buffer flag for error source.
@@ -2210,7 +2210,8 @@
goto next_line;
c = eb_nextc(b, offset, &offset);
}
- eb_get_strline(b, error_message, sizeof(error_message), &offset);
+ len = eb_fgets(b, error_message, sizeof(error_message), offset,
&offset);
+ error_message[len] = '\0'; /* strip the trailing newline if any */
if (line_num >= 1) {
if (line_num != error_line_num
|| !strequal(fullpath, error_filename)) {
Index: unihex.c
===================================================================
RCS file: /sources/qemacs/qemacs/unihex.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- unihex.c 23 Dec 2016 15:51:51 -0000 1.33
+++ unihex.c 23 Dec 2016 19:51:48 -0000 1.34
@@ -185,9 +185,9 @@
static void unihex_move_left_right(EditState *s, int dir)
{
if (dir > 0) {
- eb_nextc(s->b, s->offset, &s->offset);
+ s->offset = eb_next(s->b, s->offset);
} else {
- eb_prevc(s->b, s->offset, &s->offset);
+ s->offset = eb_prev(s->b, s->offset);
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs buffer.c clang.c extras.c list.c parser....,
Charlie Gordon <=