[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs buffer.c charset.c clang.c dired.c hex.c...
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs buffer.c charset.c clang.c dired.c hex.c... |
Date: |
Mon, 06 Jan 2014 09:40:21 +0000 |
CVSROOT: /sources/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 14/01/06 09:40:21
Modified files:
. : buffer.c charset.c clang.c dired.c hex.c
latex-mode.c qe.c qe.h shell.c
plugins : my_plugin.c
Log message:
better charset handling
* make eb_insert_buffer return the number of bytes inserted
* reset page bits upon charset change
* add eb_delete_nextc: delete one encoded character at offset
* add eb_insert_uchar: insert a unicode character with encoding
* add eb_insert_utf8_buf: insert a utf8 encoded buffer with conversion
* make eb_printf insert utf8 bytes with conversion
* add eb_insert_buffer_convert: copy chars between buffers with charset
conversion
* handle charset conversion correctly in various places
* insert wide caracters from hex mode
* create most buffers as BF_UTF8 by default
* set kill-buffer charset to that of kill source
* convert charsets when yanking
* handle charsets in search/replace system
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/buffer.c?cvsroot=qemacs&r1=1.50&r2=1.51
http://cvs.savannah.gnu.org/viewcvs/qemacs/charset.c?cvsroot=qemacs&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/qemacs/clang.c?cvsroot=qemacs&r1=1.42&r2=1.43
http://cvs.savannah.gnu.org/viewcvs/qemacs/dired.c?cvsroot=qemacs&r1=1.32&r2=1.33
http://cvs.savannah.gnu.org/viewcvs/qemacs/hex.c?cvsroot=qemacs&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/qemacs/latex-mode.c?cvsroot=qemacs&r1=1.35&r2=1.36
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.110&r2=1.111
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.108&r2=1.109
http://cvs.savannah.gnu.org/viewcvs/qemacs/shell.c?cvsroot=qemacs&r1=1.73&r2=1.74
http://cvs.savannah.gnu.org/viewcvs/qemacs/plugins/my_plugin.c?cvsroot=qemacs&r1=1.1&r2=1.2
Patches:
Index: buffer.c
===================================================================
RCS file: /sources/qemacs/qemacs/buffer.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -b -r1.50 -r1.51
--- buffer.c 4 Jan 2014 17:32:42 -0000 1.50
+++ buffer.c 6 Jan 2014 09:40:20 -0000 1.51
@@ -233,21 +233,23 @@
b->cur_page = NULL;
}
-/* Insert 'size bytes of 'src' buffer from position 'src_offset' into
- buffer 'dest' at offset 'dest_offset'. 'src' MUST BE DIFFERENT from
- 'dest' */
-void eb_insert_buffer(EditBuffer *dest, int dest_offset,
+/* Insert 'size' bytes of 'src' buffer from position 'src_offset' into
+ * buffer 'dest' at offset 'dest_offset'. 'src' MUST BE DIFFERENT from
+ * 'dest'. Raw insertion performed, encoding is ignored.
+ */
+int eb_insert_buffer(EditBuffer *dest, int dest_offset,
EditBuffer *src, int src_offset,
int size)
{
Page *p, *p_start, *q;
int len, n, page_index;
+ int size0 = size;
if (dest->flags & BF_READONLY)
- return;
+ return 0;
- if (size == 0)
- return;
+ if (size <= 0)
+ return 0;
/* CG: should assert parameter consistency */
@@ -267,7 +269,7 @@
}
if (size == 0)
- return;
+ return size0;
/* cut the page at dest offset if needed */
if (dest_offset < dest->total_size) {
@@ -332,6 +334,7 @@
/* the page cache is no longer valid */
dest->cur_page = NULL;
+ return size0;
}
/* Insert 'size' bytes from 'buf' into 'b' at offset 'offset'. We must
@@ -895,6 +898,12 @@
if (charset == &charset_utf8)
b->flags |= BF_UTF8;
charset_decode_init(&b->charset_state, charset);
+
+ /* Reset page cache flags */
+ for (int n = 0; n < b->nb_pages; n++) {
+ Page *p = &b->page_table[n];
+ p->flags &= ~(PG_VALID_POS | PG_VALID_CHAR | PG_VALID_COLORS);
+ }
}
/* XXX: change API to go faster */
@@ -924,6 +933,19 @@
return ch;
}
+/* delete one character at offset 'offset', return number of bytes removed */
+int eb_delete_nextc(EditBuffer *b, int offset)
+{
+ int offset1, size = 0;
+
+ eb_nextc(b, offset, &offset1);
+ if (offset < offset1) {
+ size = offset1 - offset;
+ eb_delete(b, offset, size);
+ }
+ return size;
+}
+
/* XXX: only stateless charsets are supported */
/* XXX: suppress that */
int eb_prevc(EditBuffer *b, int offset, int *prev_ptr)
@@ -1417,6 +1439,43 @@
eb_set_buffer_name(b, get_basename(filename));
}
+/* Insert unicode character according to buffer encoding */
+int eb_insert_uchar(EditBuffer *b, int offset, int c)
+{
+ char buf[MAX_CHAR_BYTES];
+ int len;
+
+ len = unicode_to_charset(buf, c, b->charset);
+ eb_insert(b, offset, buf, len);
+ return len;
+}
+
+/* Insert buffer with utf8 chars according to buffer encoding */
+int eb_insert_utf8_buf(EditBuffer *b, int offset, const char *buf, int len)
+{
+ if (b->charset == &charset_utf8) {
+ eb_insert(b, offset, buf, len);
+ return len;
+ } else {
+ char buf1[1024];
+ int size, size1;
+ const char *bufend = buf + len;
+
+ size = size1 = 0;
+ while (buf < bufend) {
+ int c = utf8_decode(&buf);
+ int clen = unicode_to_charset(buf1 + size1, c, b->charset);
+ size1 += clen;
+ if (size1 > ssizeof(buf) - MAX_CHAR_BYTES || buf >= bufend) {
+ eb_insert(b, offset + size, buf1, size1);
+ size += size1;
+ size1 = 0;
+ }
+ }
+ return size;
+ }
+}
+
int eb_printf(EditBuffer *b, const char *fmt, ...)
{
char buf0[1024];
@@ -1440,7 +1499,8 @@
vsnprintf(buf, size, fmt, ap);
va_end(ap);
}
- eb_insert(b, b->total_size, buf, len);
+ /* CG: insert buffer translating according b->charset */
+ eb_insert_utf8_buf(b, b->total_size, buf, len);
#ifdef CONFIG_WIN32
if (buf != buf0)
free(buf);
@@ -1452,6 +1512,7 @@
void eb_line_pad(EditBuffer *b, int n)
{
int offset, i;
+
i = 0;
offset = b->total_size;
for (;;) {
@@ -1460,7 +1521,7 @@
i++;
}
while (i < n) {
- eb_printf(b, " ");
+ eb_insert_uchar(b, b->total_size, ' ');
i++;
}
}
@@ -1477,6 +1538,46 @@
return len;
}
+/* Insert 'size' bytes of 'src' buffer from position 'src_offset' into
+ * buffer 'dest' at offset 'dest_offset'. 'src' MUST BE DIFFERENT from
+ * 'dest'. Charset converson between source and destination buffer is
+ * performed.
+ */
+int eb_insert_buffer_convert(EditBuffer *dest, int dest_offset,
+ EditBuffer *src, int src_offset,
+ int size)
+{
+ if (dest->charset == src->charset) {
+ return eb_insert_buffer(dest, dest_offset, src, src_offset, size);
+ } else {
+ EditBuffer *b;
+ int offset, offset_max;
+
+ b = dest;
+ if ((b->flags & BF_SAVELOG) || dest_offset != b->total_size) {
+ b = eb_new("*tmp*", 0);
+ eb_set_charset(b, dest->charset);
+ }
+
+ /* well, not very fast, but simple */
+ offset_max = min(src->total_size, src_offset + size);
+ size = 0;
+ for (offset = src_offset; offset < offset_max;) {
+ char buf[MAX_CHAR_BYTES];
+ int c = eb_nextc(src, offset, &offset);
+ int len = unicode_to_charset(buf, c, b->charset);
+ eb_write(b, b->total_size, buf, len);
+ size += len;
+ }
+
+ if (b != dest) {
+ size = eb_insert_buffer(dest, dest_offset, b, 0, b->total_size);
+ eb_free(b);
+ }
+ return size;
+ }
+}
+
/* 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' */
Index: charset.c
===================================================================
RCS file: /sources/qemacs/qemacs/charset.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- charset.c 6 Jan 2014 04:30:09 -0000 1.26
+++ charset.c 6 Jan 2014 09:40:20 -0000 1.27
@@ -459,7 +459,7 @@
}
}
}
- return (u8 *)lp - buf;
+ return (const u8 *)lp - buf;
}
static int decode_ucs2be(CharsetDecodeState *s)
@@ -468,7 +468,7 @@
p = s->p;
s->p += 2;
- return p[1] + (p[0] << 8);
+ return (p[0] << 8) + p[1];
}
static u8 *encode_ucs2be(__unused__ QECharset *charset, u8 *p, int c)
@@ -562,11 +562,11 @@
static int charset_goto_line_ucs4(QECharset *charset, const u8 *buf, int size,
int nlines)
{
- uint32_t *p, *p1, *lp;
+ const uint32_t *p, *p1, *lp;
uint32_t nl;
- union { uint32_t n; char c[2]; } u;
+ union { uint32_t n; char c[4]; } u;
- lp = p = (uint32_t *)buf;
+ lp = p = (const uint32_t *)buf;
p1 = p + (size >> 2);
u.n = 0;
u.c[(charset == &charset_ucs2be) * 3] = charset->eol_char;
@@ -581,7 +581,7 @@
}
}
}
- return (u8 *)lp - buf;
+ return (const u8 *)lp - buf;
}
static int decode_ucs4be(CharsetDecodeState *s)
Index: clang.c
===================================================================
RCS file: /sources/qemacs/qemacs/clang.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -b -r1.42 -r1.43
--- clang.c 5 Jan 2014 23:42:54 -0000 1.42
+++ clang.c 6 Jan 2014 09:40:20 -0000 1.43
@@ -337,9 +337,7 @@
/* insert tabs */
if (s->indent_tabs_mode) {
while (i >= s->tab_size) {
- buf1[0] = '\t';
- eb_insert(s->b, offset, buf1, 1);
- offset++;
+ offset += eb_insert_uchar(s->b, offset, '\t');
i -= s->tab_size;
}
}
@@ -350,9 +348,8 @@
if (size > ssizeof(buf1))
size = ssizeof(buf1);
memset(buf1, ' ', size);
- eb_insert(s->b, offset, buf1, size);
+ offset += eb_insert_utf8_buf(s->b, offset, buf1, size);
i -= size;
- offset += size;
}
*offset_ptr = offset;
}
Index: dired.c
===================================================================
RCS file: /sources/qemacs/qemacs/dired.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- dired.c 4 Jan 2014 17:27:02 -0000 1.32
+++ dired.c 6 Jan 2014 09:40:20 -0000 1.33
@@ -432,7 +432,7 @@
e->wrap = WRAP_TRUNCATE;
b = e->b;
if (!b) {
- b = eb_new("*scratch*", BF_SAVELOG);
+ b = eb_new("*scratch*", BF_SAVELOG | BF_UTF8);
e->b = b;
}
/* mark buffer as preview, so that it will get recycled if needed */
Index: hex.c
===================================================================
RCS file: /sources/qemacs/qemacs/hex.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- hex.c 5 Jan 2014 23:23:09 -0000 1.31
+++ hex.c 6 Jan 2014 09:40:20 -0000 1.32
@@ -262,9 +262,9 @@
h = to_hex(key);
if (h < 0)
return;
- if (s->insert && s->hex_nibble == 0) {
+ if ((s->insert || s->offset >= s->b->total_size) && s->hex_nibble ==
0) {
ch = h << ((hsize - 1) * 4);
- if (s->unihex_mode) {
+ if (s->unihex_mode || s->b->charset->char_size > 1) {
len = unicode_to_charset(buf, ch, s->b->charset);
} else {
len = 1;
Index: latex-mode.c
===================================================================
RCS file: /sources/qemacs/qemacs/latex-mode.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -b -r1.35 -r1.36
--- latex-mode.c 5 Jan 2014 23:42:54 -0000 1.35
+++ latex-mode.c 6 Jan 2014 09:40:20 -0000 1.36
@@ -144,22 +144,19 @@
if (pos > len)
return;
if (pos >= 1 && buf[pos-1] == '\"') {
- eb_insert(s->b, s->offset, "\"", 1);
- s->offset++;
+ s->offset += eb_insert_uchar(s->b, s->offset, '\"');
} else
if (pos >= 2 && (buf[pos-1] == '`' || buf[pos-1] == '\'') &&
buf[pos-1] == buf[pos-2])
{
+ /* CG: this is incorrect for non 8-bit encodings */
eb_delete(s->b, s->offset - 2, 2);
- eb_insert(s->b, s->offset, "\"", 1);
- s->offset++;
+ s->offset += eb_insert_uchar(s->b, s->offset, '\"');
} else {
if (pos == 0 || buf[pos-1] == ' ') {
- eb_insert(s->b, s->offset, "``", 2);
- s->offset += 2;
+ s->offset += eb_insert_utf8_buf(s->b, s->offset, "``", 2);
} else {
- eb_insert(s->b, s->offset, "''", 2);
- s->offset += 2;
+ s->offset += eb_insert_utf8_buf(s->b, s->offset, "''", 2);
}
}
}
Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.110
retrieving revision 1.111
diff -u -b -r1.110 -r1.111
--- qe.c 5 Jan 2014 23:42:55 -0000 1.110
+++ qe.c 6 Jan 2014 09:40:20 -0000 1.111
@@ -606,9 +606,8 @@
/* insert space single space then word */
if (offset == par_end ||
(col + 1 + word_size > PARAGRAPH_WIDTH)) {
- buf[0] = '\n';
- eb_write(s->b, chunk_start, buf, 1);
- chunk_start++;
+ eb_delete_nextc(s->b, chunk_start);
+ chunk_start += eb_insert_uchar(s->b, chunk_start, '\n');
if (offset < par_end) {
/* indent */
buf[0] = ' ';
@@ -642,7 +641,6 @@
/* Upper / lower / capital case functions. Update offset, return isword */
/* arg: -1=lower-case, +1=upper-case, +2=capital-case */
-/* (XXX: use generic unicode function). */
static int eb_changecase(EditBuffer *b, int *offsetp, int arg)
{
int offset0, ch, ch1, len;
@@ -1364,11 +1362,15 @@
void do_return(EditState *s, int move)
{
+ int len;
+
if (s->b->flags & BF_READONLY)
return;
- eb_insert(s->b, s->offset, "\n", 1);
- s->offset += move;
+ /* CG: in overwrite mode, should just go to beginning of next line */
+ len = eb_insert_uchar(s->b, s->offset, '\n');
+ if (move)
+ s->offset += len;
}
#if 0
@@ -1427,7 +1429,7 @@
}
}
snprintf(bufname, sizeof(bufname), "*kill-%d*", qs->yank_current + 1);
- b = eb_new(bufname, 0);
+ b = eb_new(bufname, BF_UTF8);
qs->yank_buffers[qs->yank_current] = b;
return b;
}
@@ -1459,9 +1461,10 @@
if (!b || !dir || qs->last_cmd_func != (CmdFunc)do_append_next_kill) {
/* append kill if last command was kill already */
b = new_yank_buffer(qs);
+ eb_set_charset(b, s->b->charset);
}
/* insert at beginning or end depending on kill direction */
- eb_insert_buffer(b, dir < 0 ? 0 : b->total_size, s->b, p1, len);
+ eb_insert_buffer_convert(b, dir < 0 ? 0 : b->total_size, s->b, p1, len);
if (dir) {
eb_delete(s->b, p1, len);
s->offset = p1;
@@ -1529,8 +1532,7 @@
if (b) {
size = b->total_size;
if (size > 0) {
- eb_insert_buffer(s->b, s->offset, b, 0, size);
- s->offset += size;
+ s->offset += eb_insert_buffer_convert(s->b, s->offset, b, 0, size);
}
}
qs->this_cmd_func = (CmdFunc)do_yank;
@@ -4847,7 +4849,7 @@
buffer */
if (!completion_popup_window) {
EditBuffer *b;
- b = eb_new("*completion*", BF_SYSTEM);
+ b = eb_new("*completion*", BF_SYSTEM | BF_UTF8);
w1 = qs->screen->width;
h1 = qs->screen->height - qs->status_height;
w = (w1 * 3) / 4;
@@ -5334,7 +5336,7 @@
break;
}
if (!b1)
- b1 = eb_new("*scratch*", BF_SAVELOG);
+ b1 = eb_new("*scratch*", BF_SAVELOG | BF_UTF8);
/* if the buffer remains because we cannot delete the main
window, then switch to the scratch buffer */
@@ -5801,25 +5803,27 @@
#define SEARCH_FLAG_WORD 0x0004
/* XXX: OPTIMIZE ! */
-/* XXX: use UTF8 for words/chars ? */
int eb_search(EditBuffer *b, int offset, int dir, int flags,
- const u8 *buf, int size,
- CSSAbortFunc *abort_func, void *abort_opaque)
+ const char *buf, int size,
+ CSSAbortFunc *abort_func, void *abort_opaque,
+ int *found_offset, int *found_end)
{
int total_size = b->total_size;
- int i, c, offset1, lower_count, upper_count;
- u8 ch;
- u8 buf1[1024];
+ int c, c2, offset1, offset2;
+ char buf1[1024];
+ const char *bufp, *bufend;
if (size == 0 || size >= (int)sizeof(buf1))
- return -1;
+ return 0;
/* analyze buffer if smart case */
if (flags & SEARCH_FLAG_SMARTCASE) {
- upper_count = 0;
- lower_count = 0;
- for (i = 0; i < size; i++) {
- c = buf[i];
+ int upper_count = 0;
+ int lower_count = 0;
+ bufp = buf;
+ bufend = buf + size;
+ while (bufp < bufend) {
+ c = utf8_decode(&bufp);
lower_count += qe_islower(c);
upper_count += qe_isupper(c);
}
@@ -5828,58 +5832,64 @@
}
/* copy buffer */
- for (i = 0; i < size; i++) {
- c = buf[i];
- if (flags & SEARCH_FLAG_IGNORECASE)
- buf1[i] = qe_toupper(c);
- else
- buf1[i] = c;
+ if (flags & SEARCH_FLAG_IGNORECASE) {
+ bufp = buf;
+ bufend = buf + size;
+ size = 0;
+ while (bufp < bufend) {
+ c = utf8_decode(&bufp);
+ size += utf8_encode(buf1 + size, qe_toupper(c));
}
-
- if (dir < 0) {
- if (offset > (total_size - size))
- offset = total_size - size;
} else {
- offset--;
+ memcpy(buf1, buf, size);
}
- for (;;) {
- offset += dir;
- if (offset < 0)
- return -1;
- if (offset > (total_size - size))
- return -1;
+ *found_offset = -1;
+ *found_end = -1;
+
+ for (;; dir >= 0 && eb_nextc(b, offset, &offset)) {
+ if (dir < 0) {
+ if (offset == 0)
+ return 0;
+ eb_prevc(b, offset, &offset);
+ }
+ if (offset >= total_size)
+ return 0;
/* search abort */
if ((offset & 0xfff) == 0) {
if (abort_func && abort_func(abort_opaque))
- return -1;
+ return 0;
}
/* search start of word */
if (flags & SEARCH_FLAG_WORD) {
- ch = eb_prevc(b, offset, &offset1);
- if (qe_isword(ch))
+ c = eb_prevc(b, offset, &offset1);
+ if (qe_isword(c))
continue;
}
- i = 0;
- for (;;) {
+ bufp = buf1;
+ bufend = buf1 + size;
+ offset2 = offset;
+ while (offset2 < total_size) {
/* CG: Should bufferize a bit ? */
- eb_read(b, offset + i, &ch, 1);
+ c = eb_nextc(b, offset2, &offset2);
if (flags & SEARCH_FLAG_IGNORECASE)
- ch = qe_toupper(ch);
- if (ch != buf1[i])
+ c = qe_toupper(c);
+ c2 = utf8_decode(&bufp);
+ if (c != c2)
break;
- i++;
- if (i == size) {
+ if (bufp >= bufend) {
/* check end of word */
if (flags & SEARCH_FLAG_WORD) {
- ch = eb_nextc(b, offset + size, &offset1);
- if (qe_isword(ch))
+ c = eb_nextc(b, offset2, &offset1);
+ if (qe_isword(c))
break;
}
- return offset;
+ *found_offset = offset;
+ *found_end = offset2;
+ return 1;
}
}
}
@@ -5905,7 +5915,7 @@
int pos;
int stack_ptr;
int search_flags;
- int found_offset;
+ int found_offset, found_end;
unsigned int search_string[SEARCH_LENGTH];
} ISearchState;
@@ -5914,7 +5924,7 @@
EditState *s = is->s;
char ubuf[256];
buf_t out;
- u8 buf[2*SEARCH_LENGTH], *q; /* XXX: incorrect size */
+ char buf[2*SEARCH_LENGTH], *q; /* XXX: incorrect size */
int i, len, hex_nibble, h;
unsigned int v;
int search_offset;
@@ -5939,10 +5949,11 @@
}
/* CG: should handle unihex mode */
} else {
- q += unicode_to_charset((char *)q, v, s->b->charset);
+ q += utf8_encode(q, v);
}
}
} else {
+ /* CG: XXX: offset cannot be adjusted this way */
search_offset = (v & ~FOUND_TAG) + is->dir;
}
}
@@ -5954,10 +5965,11 @@
flags = is->search_flags;
if (s->hex_mode)
flags = 0;
- is->found_offset = eb_search(s->b, search_offset, is->dir, flags,
- buf, len, search_abort_func, NULL);
- if (is->found_offset >= 0)
- s->offset = is->found_offset + len;
+ if (eb_search(s->b, search_offset, is->dir, flags,
+ buf, len, search_abort_func, NULL,
+ &is->found_offset, &is->found_end)) {
+ s->offset = is->found_end;
+ }
}
/* display search string */
@@ -6022,6 +6034,8 @@
}
qe_ungrab_keys();
qe_free(&is);
+ edit_display(s->qe_state);
+ dpy_flush(s->screen);
return;
case KEY_CTRL('s'):
is->dir = 1;
@@ -6106,11 +6120,11 @@
isearch_display(is);
}
-static int to_bytes(EditState *s1, u8 *dst, int dst_size, const char *str)
+static int to_bytes(EditState *s1, char *dst, int dst_size, const char *str)
{
const char *s;
int c, len, hex_nibble, h;
- u8 *d;
+ char *d;
d = dst;
if (s1->hex_mode) {
@@ -6134,7 +6148,7 @@
}
return d - dst;
} else {
- /* XXX: potentially incorrect if charset change */
+ /* dest buffer has utf8 contents */
len = strlen(str);
if (len > dst_size)
len = dst_size;
@@ -6146,13 +6160,13 @@
typedef struct QueryReplaceState {
EditState *s;
int nb_reps;
- int search_bytes_len, replace_bytes_len, found_offset;
+ int search_bytes_len, replace_bytes_len, found_offset, found_end;
int replace_all;
int flags;
- char search_str[SEARCH_LENGTH];
- char replace_str[SEARCH_LENGTH];
- u8 search_bytes[SEARCH_LENGTH];
- u8 replace_bytes[SEARCH_LENGTH];
+ char search_str[SEARCH_LENGTH]; /* may be in hex */
+ char replace_str[SEARCH_LENGTH]; /* may be in hex */
+ char search_bytes[SEARCH_LENGTH]; /* utf8 bytes */
+ char replace_bytes[SEARCH_LENGTH]; /* utf8 bytes */
} QueryReplaceState;
static void query_replace_abort(QueryReplaceState *is)
@@ -6170,9 +6184,9 @@
{
EditState *s = is->s;
- eb_delete(s->b, is->found_offset, is->search_bytes_len);
- eb_insert(s->b, is->found_offset, is->replace_bytes,
is->replace_bytes_len);
- is->found_offset += is->replace_bytes_len;
+ eb_delete(s->b, is->found_offset, is->found_end - is->found_offset);
+ is->found_offset += eb_insert_utf8_buf(s->b, is->found_offset,
+ is->replace_bytes,
is->replace_bytes_len);
is->nb_reps++;
}
@@ -6181,10 +6195,9 @@
EditState *s = is->s;
redo:
- is->found_offset = eb_search(s->b, is->found_offset, 1, is->flags,
+ if (!eb_search(s->b, is->found_offset, 1, is->flags,
is->search_bytes, is->search_bytes_len,
- NULL, NULL);
- if (is->found_offset < 0) {
+ NULL, NULL, &is->found_offset, &is->found_end)) {
query_replace_abort(is);
return;
}
@@ -6253,7 +6266,7 @@
replace_str);
is->nb_reps = 0;
is->replace_all = all;
- is->found_offset = s->offset;
+ is->found_offset = is->found_end = s->offset;
is->flags = flags;
qe_grab_keys(query_replace_key, is);
@@ -6275,17 +6288,16 @@
void do_search_string(EditState *s, const char *search_str, int dir)
{
- u8 search_bytes[SEARCH_LENGTH];
+ char search_bytes[SEARCH_LENGTH];
int search_bytes_len;
- int found_offset;
+ int found_offset, found_end;
search_bytes_len = to_bytes(s, search_bytes, sizeof(search_bytes),
search_str);
- found_offset = eb_search(s->b, s->offset, dir, 0,
- search_bytes, search_bytes_len, NULL, NULL);
- if (found_offset >= 0) {
- s->offset = found_offset;
+ if (eb_search(s->b, s->offset, dir, 0, search_bytes, search_bytes_len,
+ NULL, NULL, &found_offset, &found_end)) {
+ s->offset = (dir < 0) ? found_offset : found_end;
do_center_cursor(s);
}
}
@@ -7019,6 +7031,7 @@
memcpy(s, saved_data->generic_data, SAVED_DATA_SIZE);
}
s->hex_mode = 0;
+ s->insert = 1;
set_colorize_func(s, NULL);
return 0;
}
@@ -7817,7 +7830,7 @@
qs->screen = &global_screen;
/* create first buffer */
- b = eb_new("*scratch*", BF_SAVELOG);
+ b = eb_new("*scratch*", BF_SAVELOG | BF_UTF8);
/* will be positionned by do_refresh() */
s = edit_new(b, 0, 0, 0, 0, WF_MODELINE);
Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -b -r1.108 -r1.109
--- qe.h 5 Jan 2014 23:42:54 -0000 1.108
+++ qe.h 6 Jan 2014 09:40:21 -0000 1.109
@@ -797,7 +797,7 @@
void eb_init(void);
int eb_read(EditBuffer *b, int offset, void *buf, int size);
void eb_write(EditBuffer *b, int offset, const void *buf, int size);
-void eb_insert_buffer(EditBuffer *dest, int dest_offset,
+int eb_insert_buffer(EditBuffer *dest, int dest_offset,
EditBuffer *src, int src_offset,
int size);
void eb_insert(EditBuffer *b, int offset, const void *buf, int size);
@@ -843,9 +843,15 @@
enum LogOperation op,
int offset,
int size);
+int eb_delete_nextc(EditBuffer *b, int offset);
+int eb_insert_uchar(EditBuffer *b, int offset, int c);
+int eb_insert_utf8_buf(EditBuffer *b, int offset, const char *buf, int len);
int eb_printf(EditBuffer *b, const char *fmt, ...) __attr_printf(2,3);
void eb_line_pad(EditBuffer *b, int n);
int eb_get_contents(EditBuffer *b, char *buf, int buf_size);
+int eb_insert_buffer_convert(EditBuffer *dest, int dest_offset,
+ 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,
@@ -1723,8 +1729,9 @@
void do_set_visited_file_name(EditState *s, const char *filename,
const char *renamefile);
int eb_search(EditBuffer *b, int offset, int dir, int flags,
- const u8 *buf, int size,
- CSSAbortFunc *abort_func, void *abort_opaque);
+ const char *buf, int size,
+ CSSAbortFunc *abort_func, void *abort_opaque,
+ int *found_start, int *found_end);
int search_abort_func(void *opaque);
void do_doctor(EditState *s);
void do_delete_other_windows(EditState *s);
Index: shell.c
===================================================================
RCS file: /sources/qemacs/qemacs/shell.c,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -b -r1.73 -r1.74
--- shell.c 5 Jan 2014 12:51:41 -0000 1.73
+++ shell.c 6 Jan 2014 09:40:21 -0000 1.74
@@ -433,7 +433,6 @@
static void tty_goto_xy(ShellState *s, int x, int y, int relative)
{
int total_lines, cur_line, line_num, col_num, offset, offset1, c;
- unsigned char buf1[10];
/* compute offset */
eb_get_pos(s->b, &total_lines, &col_num, s->b->total_size);
@@ -466,18 +465,15 @@
line_num += y;
/* add lines if necessary */
while (line_num >= total_lines) {
- buf1[0] = '\n';
- eb_insert(s->b, s->b->total_size, buf1, 1);
+ eb_insert_uchar(s->b, s->b->total_size, '\n');
total_lines++;
}
offset = eb_goto_pos(s->b, line_num, 0);
for (; x > 0; x--) {
c = eb_nextc(s->b, offset, &offset1);
if (c == '\n') {
- buf1[0] = ' ';
for (; x > 0; x--) {
- eb_insert(s->b, offset, buf1, 1);
- offset++;
+ offset += eb_insert_uchar(s->b, offset, ' ');
}
break;
} else {
@@ -487,6 +483,7 @@
s->cur_offset = offset;
}
+/* CG: XXX: tty_put_char purposely ignores charset when inserting chars */
static int tty_put_char(ShellState *s, int c)
{
char buf[1];
@@ -793,6 +790,7 @@
for (;;) {
if (offset == s->b->total_size) {
/* add a new line */
+ /* CG: XXX: ignoring charset */
buf1[0] = '\n';
eb_insert(s->b, offset, buf1, 1);
offset = s->b->total_size;
Index: plugins/my_plugin.c
===================================================================
RCS file: /sources/qemacs/qemacs/plugins/my_plugin.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- plugins/my_plugin.c 5 Jun 2008 07:12:51 -0000 1.1
+++ plugins/my_plugin.c 6 Jan 2014 09:40:21 -0000 1.2
@@ -7,11 +7,9 @@
static void insert_hello(EditState *s)
{
static char hello[] = "Hello";
- int len;
- len = strlen(hello);
+ int len = strlen(hello);
- eb_insert(s->b, s->offset, hello, len);
- s->offset += len;
+ s->offset += eb_insert_utf8_buf(s->b, s->offset, hello, len);
}
static CmdDef my_commands[] = {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs buffer.c charset.c clang.c dired.c hex.c...,
Charlie Gordon <=