[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs buffer.c qe.h
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs buffer.c qe.h |
Date: |
Thu, 20 Dec 2007 11:49:54 +0000 |
CVSROOT: /cvsroot/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 07/12/20 11:49:54
Modified files:
. : buffer.c qe.h
Log message:
added offsetof macro for platforms that do not have it
added eb_clear, eb_scratch, eb_replace, eb_delete_range
added remarks about inconsistentcies
check buffer readonly status in low level buffer primitives
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/buffer.c?cvsroot=qemacs&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.39&r2=1.40
Patches:
Index: buffer.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/buffer.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- buffer.c 18 Dec 2007 17:59:48 -0000 1.20
+++ buffer.c 20 Dec 2007 11:49:54 -0000 1.21
@@ -127,6 +127,9 @@
int len, left;
const u8 *buf = buf_arg;
+ if (b->flags & BF_READONLY)
+ return;
+
len = eb_rw(b, offset, (void *)buf, size, 1);
left = size - len;
if (left > 0) {
@@ -241,9 +244,14 @@
Page *p, *p_start, *q;
int size_start, len, n, page_index;
+ if (dest->flags & BF_READONLY)
+ return;
+
if (size == 0)
return;
+ /* CG: should assert parameter consistency */
+
eb_addlog(dest, LOGOP_INSERT, dest_offset, size);
/* insert the data from the first page if it is not completely
@@ -332,6 +340,9 @@
have : 0 <= offset <= b->total_size */
void eb_insert(EditBuffer *b, int offset, const void *buf, int size)
{
+ if (b->flags & BF_READONLY)
+ return;
+
/* sanity checks */
if (offset > b->total_size)
offset = b->total_size;
@@ -353,6 +364,9 @@
int n, len;
Page *del_start, *p;
+ if (b->flags & BF_READONLY)
+ return;
+
if (offset + size > b->total_size)
size = b->total_size - offset;
@@ -477,6 +491,37 @@
return b;
}
+/* Return an empty scratch buffer, create one if necessary */
+EditBuffer *eb_scratch(const char *name)
+{
+ EditBuffer *b;
+
+ b = eb_find(name);
+ if (b != NULL) {
+ eb_clear(b);
+ } else {
+ b = eb_new(name, 0);
+ }
+ return b;
+}
+
+void eb_clear(EditBuffer *b)
+{
+ b->flags &= ~BF_READONLY;
+ b->save_log = 0;
+ eb_delete(b, 0, b->total_size);
+ log_reset(b);
+
+ /* close and reset file handle */
+ if (b->file_handle > 0) {
+ close(b->file_handle);
+ }
+ b->file_handle = 0;
+
+ /* TODO: clear buffer structure */
+ //memset(b, 0, offsetof(EditBuffer, remanent_area));
+}
+
void eb_free(EditBuffer *b)
{
QEmacsState *qs = &qe_state;
@@ -498,14 +543,7 @@
}
b->first_callback = NULL;
- b->save_log = 0;
- eb_delete(b, 0, b->total_size);
- log_reset(b);
-
- /* suppress mmap file handle */
- if (b->file_handle > 0) {
- close(b->file_handle);
- }
+ eb_clear(b);
/* suppress from buffer list */
pb = &qs->first_buffer;
@@ -920,7 +958,7 @@
line++;
}
/* now compute number of chars (XXX: potential problem if out of
- block, but for UTF8 it works) */
+ * block, but for UTF8 it works) */
col = 0;
while (lp < p1) {
ch = s->table[*lp];
@@ -1136,6 +1174,35 @@
return pos;
}
+/* delete a range of bytes from the buffer, bounds in any order, return
+ * lower bound.
+ */
+int eb_delete_range(EditBuffer *b, int p1, int p2)
+{
+ if (p1 > p2) {
+ int tmp = p1;
+ p1 = p2;
+ p2 = tmp;
+ }
+ eb_delete(b, p1, p2 - p1);
+ return p1;
+}
+
+/* replace 'size' bytes at offset 'offset' with 'size1' bytes from 'buf' */
+void eb_replace(EditBuffer *b, int offset, int size, const u8 *buf, int size1)
+{
+ /* CG: behaviour is not exactly identical: mark, point and other
+ * callback based offsets will be updated differently. should
+ * write portion that fits and insert or delete remainder?
+ */
+ if (size == size1) {
+ eb_write(b, offset, buf, size1);
+ } else {
+ eb_delete(b, offset, size);
+ eb_insert(b, offset, buf, size1);
+ }
+}
+
/************************************************************/
/* buffer I/O */
Index: qe.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.h,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -b -r1.39 -r1.40
--- qe.h 18 Dec 2007 17:57:11 -0000 1.39
+++ qe.h 20 Dec 2007 11:49:54 -0000 1.40
@@ -63,6 +63,9 @@
#define force_cast(type, expr) ((type)(expr))
#endif
+#ifndef offsetof
+#define offsetof(s,m) ((size_t)(&((s *)0)->m))
+#endif
#ifndef countof
#define countof(a) ((int)(sizeof(a) / sizeof((a)[0])))
#endif
@@ -209,6 +212,7 @@
void skip_spaces(const char **pp);
int strfind(const char *keytable, const char *str, int casefold);
+
#define stristart(str, val, ptr) qe_stristart(str, val, ptr)
int stristart(const char *str, const char *val, const char **ptr);
int strxstart(const char *str, const char *val, const char **ptr);
@@ -224,6 +228,9 @@
}
int umemcmp(const unsigned int *s1, const unsigned int *s2, int count);
+int strsubst(char *buf, int buf_size, const char *from,
+ const char *s1, const char *s2);
+
void get_str(const char **pp, char *buf, int buf_size, const char *stop);
int css_get_enum(const char *str, const char *enum_str);
int compose_keys(unsigned int *keys, int *nb_keys);
@@ -319,9 +326,6 @@
int buf_printf(buf_t *bp, const char *fmt, ...) __attr_printf(2,3);
int buf_putc_utf8(buf_t *bp, int c);
-int strsubst(char *buf, int buf_size, const char *from,
- const char *s1, const char *s2);
-
/* command line option */
#define CMD_OPT_ARG 0x0001 /* argument */
#define CMD_OPT_STRING 0x0002 /* string */
@@ -695,8 +699,6 @@
char filename[MAX_FILENAME_SIZE]; /* file name */
};
-struct ModeProbeData;
-
/* high level buffer type handling */
typedef struct EditBufferDataType {
const char *name; /* name of buffer data type (text, image, ...) */
@@ -731,9 +733,11 @@
int size);
void eb_insert(EditBuffer *b, int offset, const void *buf, int size);
void eb_delete(EditBuffer *b, int offset, int size);
-//void eb_replace(EditBuffer *b, int offset, int size, const u8 *buf, int
size1);
+void eb_replace(EditBuffer *b, int offset, int size, const u8 *buf, int size1);
void log_reset(EditBuffer *b);
EditBuffer *eb_new(const char *name, int flags);
+EditBuffer *eb_scratch(const char *name);
+void eb_clear(EditBuffer *b);
void eb_free(EditBuffer *b);
EditBuffer *eb_find(const char *name);
EditBuffer *eb_find_file(const char *filename);
@@ -746,13 +750,14 @@
int eb_get_pos(EditBuffer *b, int *line_ptr, int *col_ptr, int offset);
int eb_goto_char(EditBuffer *b, int pos);
int eb_get_char_offset(EditBuffer *b, int offset);
-//int eb_delete_range(EditBuffer *b, int p1, int p2);
+int eb_delete_range(EditBuffer *b, int p1, int p2);
//int eb_clip_offset(EditBuffer *b, int offset);
void do_undo(EditState *s);
int raw_load_buffer1(EditBuffer *b, FILE *f, int offset);
int mmap_buffer(EditBuffer *b, const char *filename);
int save_buffer(EditBuffer *b);
+// should rename to eb_set_buffername and eb_set_filename
void set_buffer_name(EditBuffer *b, const char *name1);
void set_filename(EditBuffer *b, const char *filename);
int eb_add_callback(EditBuffer *b, EditBufferCallback cb, void *opaque);
@@ -874,12 +879,12 @@
int hex_mode; /* true if we are currently editing hexa */
int unihex_mode; /* true if unihex editing (hex_mode must be true too) */
int hex_nibble; /* current hexa nibble */
- int insert;
+ int insert; /* insert/overtype mode */
int bidir;
int cur_rtl; /* TRUE if the cursor on over RTL chars */
enum WrapType wrap;
int line_numbers;
- int tab_size;
+ int tab_size; /* the tab width for the window in chars */
int indent_size;
int indent_tabs_mode; /* if true, use tabs to indent */
int interactive; /* true if interaction is done instead of editing
@@ -919,11 +924,13 @@
redraw should be done */
int borders_invalid; /* true if window borders should be redrawn */
int show_selection; /* if true, the selection is displayed */
+
/* display area info */
int width, height;
int ytop, xleft;
/* full window size, including borders */
int x1, y1, x2, y2;
+
int flags; /* display flags */
#define WF_POPUP 0x0001 /* popup window (with borders) */
#define WF_MODELINE 0x0002 /* mode line must be displayed */
@@ -949,7 +956,6 @@
#define SAVED_DATA_SIZE ((int)&((EditState *)0)->end_of_saved_data)
-
struct DisplayState;
typedef struct ModeProbeData {
@@ -990,6 +996,7 @@
int (*text_backward_offset)(EditState *, int);
/* common functions are defined here */
+ /* TODO: Should have single move function with move type and argument */
void (*move_up_down)(EditState *, int);
void (*move_left_right)(EditState *, int);
void (*move_bol)(EditState *);
@@ -999,6 +1006,7 @@
void (*scroll_line_up_down)(EditState *, int);
void (*write_char)(EditState *, int);
void (*mouse_goto)(EditState *, int x, int y);
+
int mode_flags;
#define MODEF_NOCMD 0x0001 /* do not register xxx-mode command automatically */
EditBufferDataType *data_type; /* native buffer data type (NULL = raw) */
@@ -1061,7 +1069,7 @@
EditState *first_window;
EditState *active_window; /* window in which we edit */
EditBuffer *first_buffer;
- //struct EditBuffer *message_buffer;
+ //EditBuffer *message_buffer;
/* global layout info : DO NOT modify these directly. do_refresh
does it */
int status_height;
@@ -1142,14 +1150,18 @@
int n;
} CmdArg;
+// should have enum for supported signatures
+
typedef struct CmdDef {
unsigned short key; /* normal key */
unsigned short alt_key; /* alternate key */
const char *name;
union {
+ // should have union members for all supported signatures
void *func;
struct CmdDef *next;
} action;
+ // should be CmdArg arg;
void *val;
} CmdDef;
@@ -1330,6 +1342,7 @@
} CompletionEntry;
void register_completion(const char *name, CompletionFunc completion_func);
+//void vput_status(EditState *s, const char *fmt, va_list ap);
void put_status(EditState *s, const char *fmt, ...) __attr_printf(2,3);
void put_error(EditState *s, const char *fmt, ...) __attr_printf(2,3);
void minibuffer_edit(const char *input, const char *prompt,
@@ -1375,9 +1388,11 @@
void edit_append(EditState *s, EditState *e);
EditState *edit_find(EditBuffer *b);
void do_refresh(EditState *s);
+// should take direction argument
void do_other_window(EditState *s);
void do_previous_window(EditState *s);
void do_delete_window(EditState *s, int force);
+// should take argval
void do_split_window(EditState *s, int horiz);
void edit_display(QEmacsState *qs);
void edit_invalidate(EditState *s);
@@ -1407,7 +1422,10 @@
int get_colorized_line(EditState *s, unsigned int *buf, int buf_size,
int offset1, int line_num);
+// should take argval
void do_char(EditState *s, int key);
+// bad name!
+// void do_set_mode(EditState *s, const char *mode_name);
void do_set_mode(EditState *s, ModeDef *m, ModeSavedData *saved_data);
void text_move_left_right_visual(EditState *s, int dir);
void text_move_word_left_right(EditState *s, int dir);
@@ -1417,6 +1435,7 @@
void do_return(EditState *s);
void do_backspace(EditState *s, int argval);
void do_delete_char(EditState *s, int argval);
+// should take argval
void do_tab(EditState *s);
EditBuffer *new_yank_buffer(void);
void do_append_next_kill(EditState *s);
@@ -1459,12 +1478,15 @@
int cursor_func(DisplayState *ds,
int offset1, int offset2, int line_num,
int x, int y, int w, int h, int hex_mode);
+// should take argval
void do_scroll_up_down(EditState *s, int dir);
void perform_scroll_up_down(EditState *s, int h);
void do_center_cursor(EditState *s);
+// should take argval
void do_quote(EditState *s);
void do_insert(EditState *s);
void do_open_line(EditState *s);
+// should take argval
void do_set_mark(EditState *s);
void do_mark_whole_buffer(EditState *s);
void do_yank(EditState *s);
@@ -1535,6 +1557,7 @@
void set_user_option(const char *user);
/* hex.c */
+
void hex_write_char(EditState *s, int key);
/* list.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs buffer.c qe.h,
Charlie Gordon <=