... | ... |
@@ -147,8 +147,8 @@ int redata_loadquestions_wipe(redata_t *redata); |
147 | 147 |
int redata_load(redata_t *redata, char *filename, char **errordesc); |
148 | 148 |
int redata_save(redata_t *redata, char *filename, char **errordesc); |
149 | 149 |
|
150 |
-int redata_needs_saving(redata_t *redata); |
|
151 |
- |
|
150 |
+int redata_needssaving(redata_t *redata); |
|
151 |
+int redata_needssaving_reset(redata_t *redata); |
|
152 | 152 |
|
153 | 153 |
int redata_op_add(redata_t *redata, long pos, char *buf, long buflen, undostack_t *fromhere); |
154 | 154 |
int redata_op_addn(redata_t *redata, long pos, char character, long n, undostack_t *fromhere); |
... | ... |
@@ -174,6 +174,8 @@ long redata_searchbackwards(redata_t *redata, long posini, char *str, int len); |
174 | 174 |
int redata_memcmp(redata_t *redata, long pos, char *str, int len); |
175 | 175 |
|
176 | 176 |
int redata_getutf8char(redata_t *redata, long pos, char *buf, int len, int *usedbuf); |
177 |
+int redata_getprevutf8char(redata_t *redata, long pos, char *buf, int len, int *usedbuf); |
|
178 |
+int redata_getsubstr(redata_t *redata, long posini, long posend, char *buf, int len, int *usedbuf); |
|
177 | 179 |
|
178 | 180 |
/* utf8 convenience functions */ |
179 | 181 |
|
... | ... |
@@ -109,6 +109,7 @@ long redata_getused(redata_t *redata); |
109 | 109 |
long redata_getavailable(redata_t *redata); |
110 | 110 |
int redata_getposptr(redata_t *redata, long pos, int *numchunk, int *offset); |
111 | 111 |
int redata_getchar(redata_t *redata, long pos); |
112 |
+int redata_getdata(redata_t *redata, long frompos, long size, char *dest); |
|
112 | 113 |
|
113 | 114 |
/* low level stuff */ |
114 | 115 |
int redata_wipe(redata_t *redata); |
... | ... |
@@ -209,4 +210,11 @@ int redata_pos2linecol(redata_t *redata, long pos, int *line, int *col); |
209 | 210 |
/* get the pos of that line/col (calculated using the utf8 convenience functions) */ |
210 | 211 |
int redata_linecol2pos(redata_t *redata, int line, int colrequest, long *pos, int *coldone); |
211 | 212 |
|
213 |
+int redata_line_total(redata_t *redata); |
|
214 |
+int redata_line_getendstr(redata_t *redata, int line, char *buf, int sizebuf); |
|
215 |
+int redata_line_getendstrtrimmed(redata_t *redata, int line, char *buf, int sizebuf, char *trimchars); |
|
216 |
+int redata_line_getsize(redata_t *redata, int line); /* includes the \n */ |
|
217 |
+int redata_line_getstartstr(redata_t *redata, int line, char *buf, int sizebuf); |
|
218 |
+int redata_line_getstartstrtrimmed(redata_t *redata, int line, char *buf, int sizebuf, char *trimchars); |
|
219 |
+ |
|
212 | 220 |
#endif |
... | ... |
@@ -108,7 +108,8 @@ long redata_getsize(redata_t *redata); |
108 | 108 |
long redata_getused(redata_t *redata); |
109 | 109 |
long redata_getavailable(redata_t *redata); |
110 | 110 |
int redata_getposptr(redata_t *redata, long pos, int *numchunk, int *offset); |
111 |
- |
|
111 |
+int redata_getchar(redata_t *redata, long pos); |
|
112 |
+ |
|
112 | 113 |
/* low level stuff */ |
113 | 114 |
int redata_wipe(redata_t *redata); |
114 | 115 |
int redata_preallocate(redata_t *redata, long size); |
... | ... |
@@ -171,10 +171,17 @@ long redata_searchforward(redata_t *redata, long posini, char *str, int len); |
171 | 171 |
long redata_searchbackwards(redata_t *redata, long posini, char *str, int len); |
172 | 172 |
int redata_memcmp(redata_t *redata, long pos, char *str, int len); |
173 | 173 |
|
174 |
+int redata_getutf8char(redata_t *redata, long pos, char *buf, int len, int *usedbuf); |
|
175 |
+ |
|
174 | 176 |
/* utf8 convenience functions */ |
175 | 177 |
|
176 | 178 |
/* calculate the number of utf8-charaters in buffer */ |
177 | 179 |
int redata_generic_utf8len(char *ptr, int size); |
180 |
+ |
|
181 |
+/* calculate the number of utf8-charaters in buffer ignoring incomplete multibytechars at start and end */ |
|
182 |
+int redata_generic_utf8lenincomplete(char *ptr, int size, int *nstartincomplete,int *nendincomplete, int *nendrequired |
|
183 |
+); |
|
184 |
+ |
|
178 | 185 |
/* return a pointer to the "n"th ("col"th) utf8-character in buffer */ |
179 | 186 |
char *redata_generic_utf8col(char *ptr, int size, int col); |
180 | 187 |
/* returns the len in bytes of the character starting at ptr (zero on error)*/ |
... | ... |
@@ -74,8 +74,7 @@ typedef struct redata_plugin_t { |
74 | 74 |
int (*loadquestion)(/*redata_t *redata, redata_plugin_t *plugin,char *filename */); |
75 | 75 |
int (*postload)(/*redata_t *redata, redata_plugin_t *plugin,char *filename */); |
76 | 76 |
int (*postsave)(/*redata_t *redata, redata_plugin_t *plugin,char *oldfilename,char *newfilename*/); |
77 |
- int (*add)(/*redata_t *redata, redata_plugin_t *plugin,undo_t *undo*/); |
|
78 |
- int (*unadd)(/*redata_t *redata, redata_plugin_t *plugin,undo_t *undo*/); |
|
77 |
+ int (*add_or_unadd)(/*redata_t *redata, redata_plugin_t *plugin,undo_t *undo, int is_unadd*/); |
|
79 | 78 |
int (*commit)(/*redata_t *redata, redata_plugin_t *plugin,char *filename*/); |
80 | 79 |
void *userptr; |
81 | 80 |
} redata_plugin_t; |
... | ... |
@@ -82,6 +82,7 @@ typedef struct redata_plugin_t { |
82 | 82 |
|
83 | 83 |
typedef struct redata_t { |
84 | 84 |
char filename[PATH_MAX]; |
85 |
+ int needs_saving; |
|
85 | 86 |
/* data */ |
86 | 87 |
long chunkdatasize; |
87 | 88 |
int sizechunks; |
... | ... |
@@ -145,6 +146,9 @@ int redata_loadquestions_wipe(redata_t *redata); |
145 | 146 |
int redata_load(redata_t *redata, char *filename, char **errordesc); |
146 | 147 |
int redata_save(redata_t *redata, char *filename, char **errordesc); |
147 | 148 |
|
149 |
+int redata_needs_saving(redata_t *redata); |
|
150 |
+ |
|
151 |
+ |
|
148 | 152 |
int redata_op_add(redata_t *redata, long pos, char *buf, long buflen, undostack_t *fromhere); |
149 | 153 |
int redata_op_addn(redata_t *redata, long pos, char character, long n, undostack_t *fromhere); |
150 | 154 |
int redata_op_del(redata_t *redata, long pos, long size, undostack_t *fromhere); |
... | ... |
@@ -163,6 +163,11 @@ undostack_t *redata_getstack(redata_t *redata, undo_t *undo); |
163 | 163 |
|
164 | 164 |
char *redata_generic_genname(char *filename,char *prefix, char *postfix, char *buf, int bufsize); |
165 | 165 |
|
166 |
+/* search */ |
|
167 |
+long redata_searchforward(redata_t *redata, long posini, char *str, int len); |
|
168 |
+long redata_searchbackwards(redata_t *redata, long posini, char *str, int len); |
|
169 |
+int redata_memcmp(redata_t *redata, long pos, char *str, int len); |
|
170 |
+ |
|
166 | 171 |
/* utf8 convenience functions */ |
167 | 172 |
|
168 | 173 |
/* calculate the number of utf8-charaters in buffer */ |
... | ... |
@@ -100,7 +100,6 @@ typedef struct redata_t { |
100 | 100 |
|
101 | 101 |
redata_t *redata_init( int (*pluginregisterfn)(redata_t *redata, redata_plugin_t *slot), ...); |
102 | 102 |
void redata_free(redata_t *redata); |
103 |
- |
|
104 | 103 |
void redata_idleproc(redata_t *redata, char *filename); |
105 | 104 |
|
106 | 105 |
int redata_config_chunkdatasize(redata_t *redata, int chunkdatasize); |
... | ... |
@@ -47,9 +47,11 @@ typedef struct undo_t { |
47 | 47 |
long len; |
48 | 48 |
long posorig; |
49 | 49 |
long posdest; |
50 |
+ int hint_groupedwithnext; |
|
51 |
+#ifdef REDATA_HASHUNDO |
|
50 | 52 |
char prehash[129]; |
51 | 53 |
char posthash[129]; |
52 |
- int hint_groupedwithnext; |
|
54 |
+#endif |
|
53 | 55 |
} undo_t; |
54 | 56 |
|
55 | 57 |
typedef struct undostack_t { |
... | ... |
@@ -13,8 +13,22 @@ |
13 | 13 |
|
14 | 14 |
#include <limits.h> |
15 | 15 |
|
16 |
+#ifndef RE_DATA_H |
|
17 |
+#define RE_DATA_H |
|
16 | 18 |
#define MAXPLUGINNAME 32 |
17 | 19 |
|
20 |
+typedef struct question_t { |
|
21 |
+ int active; |
|
22 |
+ int is_postload; |
|
23 |
+ char *id; |
|
24 |
+ char *title,*titleshort; |
|
25 |
+ char *body,*bodyshort; |
|
26 |
+ int nopts; |
|
27 |
+ char **opts,**optsshort; |
|
28 |
+ int defaultoption; |
|
29 |
+ int selectedoption; |
|
30 |
+} question_t; |
|
31 |
+ |
|
18 | 32 |
typedef struct whatin_t { |
19 | 33 |
int nlcount; |
20 | 34 |
int iscontinuation; |
... | ... |
@@ -51,11 +65,12 @@ typedef struct undostack_t { |
51 | 65 |
typedef struct redata_plugin_t { |
52 | 66 |
int active; |
53 | 67 |
char name[MAXPLUGINNAME]; |
68 |
+ char *questionfilename[PATH_MAX]; |
|
69 |
+ question_t question; |
|
54 | 70 |
int (*unregister)(/*redata_t *redata, redata_plugin_t *plugin,char *filename*/); |
55 | 71 |
int (*wipe)(/*redata_t *redata, redata_plugin_t *plugin,char *filename*/); |
56 |
- /* loadquestion returns -1 if no question needed */ |
|
57 |
- int (*loadquestion)(/*redata_t *redata, redata_plugin_t *plugin,char *filename, char **title, char **body, int *nopts, char **opts[] */); |
|
58 |
- int (*postload)(/*redata_t *redata, redata_plugin_t *plugin,char *filename,int questionreply */); |
|
72 |
+ int (*loadquestion)(/*redata_t *redata, redata_plugin_t *plugin,char *filename */); |
|
73 |
+ int (*postload)(/*redata_t *redata, redata_plugin_t *plugin,char *filename */); |
|
59 | 74 |
int (*postsave)(/*redata_t *redata, redata_plugin_t *plugin,char *oldfilename,char *newfilename*/); |
60 | 75 |
int (*add)(/*redata_t *redata, redata_plugin_t *plugin,undo_t *undo*/); |
61 | 76 |
int (*unadd)(/*redata_t *redata, redata_plugin_t *plugin,undo_t *undo*/); |
... | ... |
@@ -84,6 +99,8 @@ typedef struct redata_t { |
84 | 99 |
redata_t *redata_init( int (*pluginregisterfn)(redata_t *redata, redata_plugin_t *slot), ...); |
85 | 100 |
void redata_free(redata_t *redata); |
86 | 101 |
|
102 |
+void redata_idleproc(redata_t *redata, char *filename); |
|
103 |
+ |
|
87 | 104 |
int redata_config_chunkdatasize(redata_t *redata, int chunkdatasize); |
88 | 105 |
|
89 | 106 |
long redata_getsize(redata_t *redata); |
... | ... |
@@ -119,8 +136,13 @@ int redata_undo_groupinit(redata_t *redata, undostack_t *stack); |
119 | 136 |
int redata_undo_groupcommit(redata_t *redata, undostack_t *stack); |
120 | 137 |
|
121 | 138 |
/* high level stuff */ |
122 |
-int redata_load(redata_t *redata, char *filename, int (*callback_question)(/*char *title, char *body, int nopts, char *opts[],void *userptr*/), void *userptr); |
|
123 |
-int redata_save(redata_t *redata, char *filename); |
|
139 |
+int redata_loadquestions_setup(redata_t *redata, char *filename); |
|
140 |
+question_t *redata_loadquestions_getnext(redata_t *redata); |
|
141 |
+int redata_loadquestions_reply(redata_t *redata, question_t *question, int selectedoption); |
|
142 |
+int redata_loadquestions_wipe(redata_t *redata); |
|
143 |
+ |
|
144 |
+int redata_load(redata_t *redata, char *filename, char **errordesc); |
|
145 |
+int redata_save(redata_t *redata, char *filename, char **errordesc); |
|
124 | 146 |
|
125 | 147 |
int redata_op_add(redata_t *redata, long pos, char *buf, long buflen, undostack_t *fromhere); |
126 | 148 |
int redata_op_addn(redata_t *redata, long pos, char character, long n, undostack_t *fromhere); |
... | ... |
@@ -170,3 +192,4 @@ int redata_pos2linecol(redata_t *redata, long pos, int *line, int *col); |
170 | 192 |
/* get the pos of that line/col (calculated using the utf8 convenience functions) */ |
171 | 193 |
int redata_linecol2pos(redata_t *redata, int line, int colrequest, long *pos, int *coldone); |
172 | 194 |
|
195 |
+#endif |
... | ... |
@@ -126,8 +126,8 @@ int redata_op_add(redata_t *redata, long pos, char *buf, long buflen, undostack_ |
126 | 126 |
int redata_op_addn(redata_t *redata, long pos, char character, long n, undostack_t *fromhere); |
127 | 127 |
int redata_op_del(redata_t *redata, long pos, long size, undostack_t *fromhere); |
128 | 128 |
int redata_op_move(redata_t *redata, long posorig, long size, long posdest, undostack_t *fromhere); |
129 |
-int redata_op_undo(redata_t *redata); |
|
130 |
-int redata_op_redo(redata_t *redata); |
|
129 |
+int redata_op_undo(redata_t *redata, long *newcursorpos); |
|
130 |
+int redata_op_redo(redata_t *redata, long *newcursorpos); |
|
131 | 131 |
|
132 | 132 |
int redata_data_compare(redata_t *redata, long pos, char *buf, long buflen); |
133 | 133 |
|
... | ... |
@@ -148,7 +148,7 @@ int redata_generic_utf8len(char *ptr, int size); |
148 | 148 |
char *redata_generic_utf8col(char *ptr, int size, int col); |
149 | 149 |
/* returns the len in bytes of the character starting at ptr (zero on error)*/ |
150 | 150 |
int redata_generic_utf8charlen(char *ptr, int maxsize); |
151 |
-/* returns true if it's the forst byte of an UTF char */ |
|
151 |
+/* returns true if it's the first byte of an UTF char */ |
|
152 | 152 |
int redata_generic_utf8isstartbyte(int candidate); |
153 | 153 |
|
154 | 154 |
|
... | ... |
@@ -17,6 +17,7 @@ |
17 | 17 |
|
18 | 18 |
typedef struct whatin_t { |
19 | 19 |
int nlcount; |
20 |
+ int iscontinuation; |
|
20 | 21 |
} whatin_t; |
21 | 22 |
|
22 | 23 |
typedef struct rechunk_t { |
... | ... |
@@ -34,12 +35,14 @@ typedef struct undo_t { |
34 | 35 |
long posdest; |
35 | 36 |
char prehash[129]; |
36 | 37 |
char posthash[129]; |
38 |
+ int hint_groupedwithnext; |
|
37 | 39 |
} undo_t; |
38 | 40 |
|
39 | 41 |
typedef struct undostack_t { |
40 | 42 |
int sizeundo; |
41 | 43 |
int usedundo; |
42 | 44 |
undo_t *undo; |
45 |
+ int groupinit; |
|
43 | 46 |
long sizebuf; |
44 | 47 |
long usedbuf; |
45 | 48 |
char *buf; |
... | ... |
@@ -98,6 +101,9 @@ int redata_chunk_insertdata(redata_t *redata, int chunkto, long posto, char *buf |
98 | 101 |
int redata_chunk_deletedata(redata_t *redata, int chunkno, long pos, long n); |
99 | 102 |
int redata_chunk_splithere(redata_t *redata, int chunkno, int pos); |
100 | 103 |
int redata_chunk_fillfromnext(redata_t *redata, int chunkno, int n); |
104 |
+int redata_chunk_unfreshnext(redata_t *redata, int chunkno); |
|
105 |
+int redata_chunk_unfreshrange(redata_t *redata, int fromchunkno, int tochunkno); |
|
106 |
+ |
|
101 | 107 |
int redata_whatin_refresh(redata_t *redata, int chunkno); |
102 | 108 |
int redata_fix_nl(redata_t *redata, int chunkno); |
103 | 109 |
int redata_undobuf_reserve(redata_t *redata, undostack_t *stack, int minavail); |
... | ... |
@@ -109,6 +115,8 @@ int redata_undo_removelast(redata_t *redata, undostack_t *stack); |
109 | 115 |
int redata_undo_wipe(redata_t *redata, undostack_t *stack); |
110 | 116 |
int redata_undo_inactivatelast(redata_t *redata, undostack_t *stack); |
111 | 117 |
int redata_undo_reactivatelast(redata_t *redata, undostack_t *stack); |
118 |
+int redata_undo_groupinit(redata_t *redata, undostack_t *stack); |
|
119 |
+int redata_undo_groupcommit(redata_t *redata, undostack_t *stack); |
|
112 | 120 |
|
113 | 121 |
/* high level stuff */ |
114 | 122 |
int redata_load(redata_t *redata, char *filename, int (*callback_question)(/*char *title, char *body, int nopts, char *opts[],void *userptr*/), void *userptr); |
... | ... |
@@ -140,10 +148,25 @@ int redata_generic_utf8len(char *ptr, int size); |
140 | 148 |
char *redata_generic_utf8col(char *ptr, int size, int col); |
141 | 149 |
/* returns the len in bytes of the character starting at ptr (zero on error)*/ |
142 | 150 |
int redata_generic_utf8charlen(char *ptr, int maxsize); |
151 |
+/* returns true if it's the forst byte of an UTF char */ |
|
152 |
+int redata_generic_utf8isstartbyte(int candidate); |
|
143 | 153 |
|
144 | 154 |
|
145 | 155 |
/* line convenience funtions */ |
146 |
-int redata_line_info(redata_t *redata, long pos, long *startpos, char **startptr, int *len); |
|
156 |
+/* get pointer to full line (if it doesn't fit in a chunk, is_continuation is 1 and/or doesn't have an ending nl */ |
|
157 |
+int redata_line_rawinfo(redata_t *redata, long pos, long *startpos, char **startptr, int *len, int *is_continuation); |
|
158 |
+/* get the startpos of line, even if it doesn't fit in one chunk */ |
|
159 |
+int redata_line_realstart(redata_t *redata, long pos, long *startpos); |
|
160 |
+/* get the endpos of line, even if it doesn't fit in one chunk */ |
|
161 |
+int redata_line_realend(redata_t *redata, long pos, long *endpos); |
|
162 |
+/* get pos of previous line real start */ |
|
163 |
+int redata_line_prevrealstart(redata_t *redata, long pos, long *startpos); |
|
164 |
+/* get pos of next line real start */ |
|
165 |
+int redata_line_nextrealstart(redata_t *redata, long pos, long *startpos); |
|
166 |
+/* advance "n" cols */ |
|
167 |
+int redata_line_inccol(redata_t *redata, long pos, int ncolrequest, long *newpos, int *ncoldone); |
|
168 |
+/* get the line/col of a pos (col is calculated using the utf8 convenience functions) */ |
|
147 | 169 |
int redata_pos2linecol(redata_t *redata, long pos, int *line, int *col); |
148 |
-int redata_linecol2pos(redata_t *redata, int line, int col, long *pos); |
|
170 |
+/* get the pos of that line/col (calculated using the utf8 convenience functions) */ |
|
171 |
+int redata_linecol2pos(redata_t *redata, int line, int colrequest, long *pos, int *coldone); |
|
149 | 172 |
|
... | ... |
@@ -144,4 +144,6 @@ int redata_generic_utf8charlen(char *ptr, int maxsize); |
144 | 144 |
|
145 | 145 |
/* line convenience funtions */ |
146 | 146 |
int redata_line_info(redata_t *redata, long pos, long *startpos, char **startptr, int *len); |
147 |
+int redata_pos2linecol(redata_t *redata, long pos, int *line, int *col); |
|
148 |
+int redata_linecol2pos(redata_t *redata, int line, int col, long *pos); |
|
147 | 149 |
|
... | ... |
@@ -132,8 +132,13 @@ undostack_t *redata_getstack(redata_t *redata, undo_t *undo); |
132 | 132 |
|
133 | 133 |
char *redata_generic_genname(char *filename,char *prefix, char *postfix, char *buf, int bufsize); |
134 | 134 |
|
135 |
+/* utf8 convenience functions */ |
|
136 |
+ |
|
137 |
+/* calculate the number of utf8-charaters in buffer */ |
|
135 | 138 |
int redata_generic_utf8len(char *ptr, int size); |
139 |
+/* return a pointer to the "n"th ("col"th) utf8-character in buffer */ |
|
136 | 140 |
char *redata_generic_utf8col(char *ptr, int size, int col); |
141 |
+/* returns the len in bytes of the character starting at ptr (zero on error)*/ |
|
137 | 142 |
int redata_generic_utf8charlen(char *ptr, int maxsize); |
138 | 143 |
|
139 | 144 |
|
... | ... |
@@ -68,6 +68,8 @@ typedef struct redata_t { |
68 | 68 |
rechunk_t **chunks; |
69 | 69 |
long available; |
70 | 70 |
rechunk_t *tmpchunk; |
71 |
+ long sizeaddnbuf; |
|
72 |
+ char *addnbuf; |
|
71 | 73 |
/* undo */ |
72 | 74 |
undostack_t undostack; |
73 | 75 |
undostack_t redostack; |
... | ... |
@@ -113,6 +115,7 @@ int redata_load(redata_t *redata, char *filename, int (*callback_question)(/*cha |
113 | 115 |
int redata_save(redata_t *redata, char *filename); |
114 | 116 |
|
115 | 117 |
int redata_op_add(redata_t *redata, long pos, char *buf, long buflen, undostack_t *fromhere); |
118 |
+int redata_op_addn(redata_t *redata, long pos, char character, long n, undostack_t *fromhere); |
|
116 | 119 |
int redata_op_del(redata_t *redata, long pos, long size, undostack_t *fromhere); |
117 | 120 |
int redata_op_move(redata_t *redata, long posorig, long size, long posdest, undostack_t *fromhere); |
118 | 121 |
int redata_op_undo(redata_t *redata); |
... | ... |
@@ -126,7 +129,14 @@ int redata_hash(redata_t *redata, char *resbuf129bytes); |
126 | 129 |
int redata_filehash(redata_t *redata, char *filename, char *resbuf129bytes); |
127 | 130 |
int redata_memhash(redata_t *redata, char *buf, long buflen, char *resbuf129bytes); |
128 | 131 |
undostack_t *redata_getstack(redata_t *redata, undo_t *undo); |
132 |
+ |
|
129 | 133 |
char *redata_generic_genname(char *filename,char *prefix, char *postfix, char *buf, int bufsize); |
130 | 134 |
|
135 |
+int redata_generic_utf8len(char *ptr, int size); |
|
136 |
+char *redata_generic_utf8col(char *ptr, int size, int col); |
|
137 |
+int redata_generic_utf8charlen(char *ptr, int maxsize); |
|
138 |
+ |
|
139 |
+ |
|
131 | 140 |
/* line convenience funtions */ |
132 | 141 |
int redata_line_info(redata_t *redata, long pos, long *startpos, char **startptr, int *len); |
142 |
+ |
... | ... |
@@ -128,3 +128,5 @@ int redata_memhash(redata_t *redata, char *buf, long buflen, char *resbuf129byte |
128 | 128 |
undostack_t *redata_getstack(redata_t *redata, undo_t *undo); |
129 | 129 |
char *redata_generic_genname(char *filename,char *prefix, char *postfix, char *buf, int bufsize); |
130 | 130 |
|
131 |
+/* line convenience funtions */ |
|
132 |
+int redata_line_info(redata_t *redata, long pos, long *startpos, char **startptr, int *len); |
... | ... |
@@ -84,7 +84,7 @@ int redata_config_chunkdatasize(redata_t *redata, int chunkdatasize); |
84 | 84 |
long redata_getsize(redata_t *redata); |
85 | 85 |
long redata_getused(redata_t *redata); |
86 | 86 |
long redata_getavailable(redata_t *redata); |
87 |
-int redata_getposptr(redata_t *redata, long pos, int *numchunk, long *offset); |
|
87 |
+int redata_getposptr(redata_t *redata, long pos, int *numchunk, int *offset); |
|
88 | 88 |
|
89 | 89 |
/* low level stuff */ |
90 | 90 |
int redata_wipe(redata_t *redata); |
... | ... |
@@ -13,6 +13,8 @@ |
13 | 13 |
|
14 | 14 |
#include <limits.h> |
15 | 15 |
|
16 |
+#define MAXPLUGINNAME 32 |
|
17 |
+ |
|
16 | 18 |
typedef struct whatin_t { |
17 | 19 |
int nlcount; |
18 | 20 |
} whatin_t; |
... | ... |
@@ -43,22 +45,19 @@ typedef struct undostack_t { |
43 | 45 |
char *buf; |
44 | 46 |
} undostack_t; |
45 | 47 |
|
46 |
-#define PLUGIN_CHECKUSERCONFIRM 1 /* if check is Ok, confirm with user whether to postload or go inactive */ |
|
47 |
- |
|
48 | 48 |
typedef struct redata_plugin_t { |
49 | 49 |
int active; |
50 |
+ char name[MAXPLUGINNAME]; |
|
50 | 51 |
int (*unregister)(/*redata_t *redata, redata_plugin_t *plugin,char *filename*/); |
51 |
- /* checkload returns 0:Ok, 1:Not needed, -1: error, go inactive */ |
|
52 | 52 |
int (*wipe)(/*redata_t *redata, redata_plugin_t *plugin,char *filename*/); |
53 |
- int (*checkload)(/*redata_t *redata, redata_plugin_t *plugin,char *filename*/); |
|
54 |
- int (*postload)(/*redata_t *redata, redata_plugin_t *plugin,char *filename*/); |
|
55 |
- int (*truncload)(/*redata_t *redata, redata_plugin_t *plugin,char *filename*/); |
|
53 |
+ /* loadquestion returns -1 if no question needed */ |
|
54 |
+ int (*loadquestion)(/*redata_t *redata, redata_plugin_t *plugin,char *filename, char **title, char **body, int *nopts, char **opts[] */); |
|
55 |
+ int (*postload)(/*redata_t *redata, redata_plugin_t *plugin,char *filename,int questionreply */); |
|
56 | 56 |
int (*postsave)(/*redata_t *redata, redata_plugin_t *plugin,char *oldfilename,char *newfilename*/); |
57 | 57 |
int (*add)(/*redata_t *redata, redata_plugin_t *plugin,undo_t *undo*/); |
58 | 58 |
int (*unadd)(/*redata_t *redata, redata_plugin_t *plugin,undo_t *undo*/); |
59 | 59 |
int (*commit)(/*redata_t *redata, redata_plugin_t *plugin,char *filename*/); |
60 | 60 |
void *userptr; |
61 |
- int flags; |
|
62 | 61 |
} redata_plugin_t; |
63 | 62 |
|
64 | 63 |
typedef struct redata_t { |
... | ... |
@@ -77,7 +76,6 @@ typedef struct redata_t { |
77 | 76 |
redata_plugin_t plugins[1]; |
78 | 77 |
} redata_t; |
79 | 78 |
|
80 |
-#warning TODO: Make redata_xxx call the plugins |
|
81 | 79 |
redata_t *redata_init( int (*pluginregisterfn)(redata_t *redata, redata_plugin_t *slot), ...); |
82 | 80 |
void redata_free(redata_t *redata); |
83 | 81 |
|
... | ... |
@@ -111,7 +109,7 @@ int redata_undo_inactivatelast(redata_t *redata, undostack_t *stack); |
111 | 109 |
int redata_undo_reactivatelast(redata_t *redata, undostack_t *stack); |
112 | 110 |
|
113 | 111 |
/* high level stuff */ |
114 |
-int redata_load(redata_t *redata, char *filename, int use_unsaved); |
|
112 |
+int redata_load(redata_t *redata, char *filename, int (*callback_question)(/*char *title, char *body, int nopts, char *opts[],void *userptr*/), void *userptr); |
|
115 | 113 |
int redata_save(redata_t *redata, char *filename); |
116 | 114 |
|
117 | 115 |
int redata_op_add(redata_t *redata, long pos, char *buf, long buflen, undostack_t *fromhere); |
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
/* |
2 |
- * re_data.c |
|
2 |
+ * re_data.h |
|
3 | 3 |
* |
4 | 4 |
* A programmers editor |
5 | 5 |
* |
... | ... |
@@ -43,13 +43,26 @@ typedef struct undostack_t { |
43 | 43 |
char *buf; |
44 | 44 |
} undostack_t; |
45 | 45 |
|
46 |
-typedef struct unsaved_t { |
|
47 |
- long sizebuf; |
|
48 |
- long usedbuf; |
|
49 |
- char *buf; |
|
50 |
-} unsaved_t; |
|
46 |
+#define PLUGIN_CHECKUSERCONFIRM 1 /* if check is Ok, confirm with user whether to postload or go inactive */ |
|
47 |
+ |
|
48 |
+typedef struct redata_plugin_t { |
|
49 |
+ int active; |
|
50 |
+ int (*unregister)(/*redata_t *redata, redata_plugin_t *plugin,char *filename*/); |
|
51 |
+ /* checkload returns 0:Ok, 1:Not needed, -1: error, go inactive */ |
|
52 |
+ int (*wipe)(/*redata_t *redata, redata_plugin_t *plugin,char *filename*/); |
|
53 |
+ int (*checkload)(/*redata_t *redata, redata_plugin_t *plugin,char *filename*/); |
|
54 |
+ int (*postload)(/*redata_t *redata, redata_plugin_t *plugin,char *filename*/); |
|
55 |
+ int (*truncload)(/*redata_t *redata, redata_plugin_t *plugin,char *filename*/); |
|
56 |
+ int (*postsave)(/*redata_t *redata, redata_plugin_t *plugin,char *oldfilename,char *newfilename*/); |
|
57 |
+ int (*add)(/*redata_t *redata, redata_plugin_t *plugin,undo_t *undo*/); |
|
58 |
+ int (*unadd)(/*redata_t *redata, redata_plugin_t *plugin,undo_t *undo*/); |
|
59 |
+ int (*commit)(/*redata_t *redata, redata_plugin_t *plugin,char *filename*/); |
|
60 |
+ void *userptr; |
|
61 |
+ int flags; |
|
62 |
+} redata_plugin_t; |
|
51 | 63 |
|
52 | 64 |
typedef struct redata_t { |
65 |
+ char filename[PATH_MAX]; |
|
53 | 66 |
/* data */ |
54 | 67 |
long chunkdatasize; |
55 | 68 |
int sizechunks; |
... | ... |
@@ -59,14 +72,13 @@ typedef struct redata_t { |
59 | 72 |
/* undo */ |
60 | 73 |
undostack_t undostack; |
61 | 74 |
undostack_t redostack; |
62 |
- /* unsaved (for recovery when the program closes unexpectedly) */ |
|
63 |
- char filename[PATH_MAX]; |
|
64 |
- char initialhash[129]; |
|
65 |
- int unsavedfd; |
|
66 |
- unsaved_t unsaved; |
|
75 |
+ /* plugins */ |
|
76 |
+ int sizeplugins; |
|
77 |
+ redata_plugin_t plugins[1]; |
|
67 | 78 |
} redata_t; |
68 | 79 |
|
69 |
-redata_t *redata_init(void); |
|
80 |
+#warning TODO: Make redata_xxx call the plugins |
|
81 |
+redata_t *redata_init( int (*pluginregisterfn)(redata_t *redata, redata_plugin_t *slot), ...); |
|
70 | 82 |
void redata_free(redata_t *redata); |
71 | 83 |
|
72 | 84 |
int redata_config_chunkdatasize(redata_t *redata, int chunkdatasize); |
... | ... |
@@ -98,17 +110,7 @@ int redata_undo_wipe(redata_t *redata, undostack_t *stack); |
98 | 110 |
int redata_undo_inactivatelast(redata_t *redata, undostack_t *stack); |
99 | 111 |
int redata_undo_reactivatelast(redata_t *redata, undostack_t *stack); |
100 | 112 |
|
101 |
- |
|
102 | 113 |
/* high level stuff */ |
103 |
-int redata_unsaved_exists(redata_t *redata, char *filename); |
|
104 |
-int redata_unsaved_check(redata_t *redata, char *filename); |
|
105 |
-int redata_unsaved_loadappend(redata_t *redata); |
|
106 |
-int redata_unsaved_unlink(redata_t *redata); |
|
107 |
-int redata_unsaved_trunc(redata_t *redata); |
|
108 |
-int redata_unsaved_add(redata_t *redata, undostack_t *stack, int undono); |
|
109 |
-int redata_unsaved_unadd(redata_t *redata, undostack_t *stack, int undono); |
|
110 |
-int redata_unsaved_commit(redata_t *redata); |
|
111 |
- |
|
112 | 114 |
int redata_load(redata_t *redata, char *filename, int use_unsaved); |
113 | 115 |
int redata_save(redata_t *redata, char *filename); |
114 | 116 |
|
... | ... |
@@ -125,4 +127,6 @@ int redata_compact(redata_t *redata); |
125 | 127 |
int redata_hash(redata_t *redata, char *resbuf129bytes); |
126 | 128 |
int redata_filehash(redata_t *redata, char *filename, char *resbuf129bytes); |
127 | 129 |
int redata_memhash(redata_t *redata, char *buf, long buflen, char *resbuf129bytes); |
130 |
+undostack_t *redata_getstack(redata_t *redata, undo_t *undo); |
|
131 |
+char *redata_generic_genname(char *filename,char *prefix, char *postfix, char *buf, int bufsize); |
|
128 | 132 |
|
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,128 @@ |
1 |
+/* |
|
2 |
+ * re_data.c |
|
3 |
+ * |
|
4 |
+ * A programmers editor |
|
5 |
+ * |
|
6 |
+ * Structures to hold the current file contents. |
|
7 |
+ * |
|
8 |
+ * HEADER FILE |
|
9 |
+ * |
|
10 |
+ * Author: Dario Rodriguez dario@softhome.net |
|
11 |
+ * This program is licensed under the terms of GNU GPL v2.1+ |
|
12 |
+ */ |
|
13 |
+ |
|
14 |
+#include <limits.h> |
|
15 |
+ |
|
16 |
+typedef struct whatin_t { |
|
17 |
+ int nlcount; |
|
18 |
+} whatin_t; |
|
19 |
+ |
|
20 |
+typedef struct rechunk_t { |
|
21 |
+ whatin_t whatin; |
|
22 |
+ int whatin_fresh; |
|
23 |
+ int useddata; |
|
24 |
+ unsigned char data[1]; |
|
25 |
+} rechunk_t; |
|
26 |
+ |
|
27 |
+typedef struct undo_t { |
|
28 |
+ char type; |
|
29 |
+ long off; |
|
30 |
+ long len; |
|
31 |
+ long posorig; |
|
32 |
+ long posdest; |
|
33 |
+ char prehash[129]; |
|
34 |
+ char posthash[129]; |
|
35 |
+} undo_t; |
|
36 |
+ |
|
37 |
+typedef struct undostack_t { |
|
38 |
+ int sizeundo; |
|
39 |
+ int usedundo; |
|
40 |
+ undo_t *undo; |
|
41 |
+ long sizebuf; |
|
42 |
+ long usedbuf; |
|
43 |
+ char *buf; |
|
44 |
+} undostack_t; |
|
45 |
+ |
|
46 |
+typedef struct unsaved_t { |
|
47 |
+ long sizebuf; |
|
48 |
+ long usedbuf; |
|
49 |
+ char *buf; |
|
50 |
+} unsaved_t; |
|
51 |
+ |
|
52 |
+typedef struct redata_t { |
|
53 |
+ /* data */ |
|
54 |
+ long chunkdatasize; |
|
55 |
+ int sizechunks; |
|
56 |
+ rechunk_t **chunks; |
|
57 |
+ long available; |
|
58 |
+ rechunk_t *tmpchunk; |
|
59 |
+ /* undo */ |
|
60 |
+ undostack_t undostack; |
|
61 |
+ undostack_t redostack; |
|
62 |
+ /* unsaved (for recovery when the program closes unexpectedly) */ |
|
63 |
+ char filename[PATH_MAX]; |
|
64 |
+ char initialhash[129]; |
|
65 |
+ int unsavedfd; |
|
66 |
+ unsaved_t unsaved; |
|
67 |
+} redata_t; |
|
68 |
+ |
|
69 |
+redata_t *redata_init(void); |
|
70 |
+void redata_free(redata_t *redata); |
|
71 |
+ |
|
72 |
+int redata_config_chunkdatasize(redata_t *redata, int chunkdatasize); |
|
73 |
+ |
|
74 |
+long redata_getsize(redata_t *redata); |
|
75 |
+long redata_getused(redata_t *redata); |
|
76 |
+long redata_getavailable(redata_t *redata); |
|
77 |
+int redata_getposptr(redata_t *redata, long pos, int *numchunk, long *offset); |
|
78 |
+ |
|
79 |
+/* low level stuff */ |
|
80 |
+int redata_wipe(redata_t *redata); |
|
81 |
+int redata_preallocate(redata_t *redata, long size); |
|
82 |
+int redata_chunk_insertnew(redata_t *redata, int afterthischunk); |
|
83 |
+int redata_chunk_deletechunk(redata_t *redata, int chunkno); |
|
84 |
+int redata_chunk_movedata(redata_t *redata, int chunkfrom, long posfrom, int chunkto, long posto, long size); |
|
85 |
+int redata_chunk_insertdata(redata_t *redata, int chunkto, long posto, char *buf, long buflen); |
|
86 |
+int redata_chunk_deletedata(redata_t *redata, int chunkno, long pos, long n); |
|
87 |
+int redata_chunk_splithere(redata_t *redata, int chunkno, int pos); |
|
88 |
+int redata_chunk_fillfromnext(redata_t *redata, int chunkno, int n); |
|
89 |
+int redata_whatin_refresh(redata_t *redata, int chunkno); |
|
90 |
+int redata_fix_nl(redata_t *redata, int chunkno); |
|
91 |
+int redata_undobuf_reserve(redata_t *redata, undostack_t *stack, int minavail); |
|
92 |
+undo_t *redata_undo_new(redata_t *redata, undostack_t *stack, char type); |
|
93 |
+undo_t *redata_undo_newfromchunks(redata_t *redata, undostack_t *stack, char type, int pos1, int len); |
|
94 |
+undo_t *redata_undo_newfrombuf(redata_t *redata, undostack_t *stack, char type, char *buf, int buflen); |
|
95 |
+int redata_undo_movelast(redata_t *redata, undostack_t *from, undostack_t *to); |
|
96 |
+int redata_undo_removelast(redata_t *redata, undostack_t *stack); |
|
97 |
+int redata_undo_wipe(redata_t *redata, undostack_t *stack); |
|
98 |
+int redata_undo_inactivatelast(redata_t *redata, undostack_t *stack); |
|
99 |
+int redata_undo_reactivatelast(redata_t *redata, undostack_t *stack); |
|
100 |
+ |
|
101 |
+ |
|
102 |
+/* high level stuff */ |
|
103 |
+int redata_unsaved_exists(redata_t *redata, char *filename); |
|
104 |
+int redata_unsaved_check(redata_t *redata, char *filename); |
|
105 |
+int redata_unsaved_loadappend(redata_t *redata); |
|
106 |
+int redata_unsaved_unlink(redata_t *redata); |
|
107 |
+int redata_unsaved_trunc(redata_t *redata); |
|
108 |
+int redata_unsaved_add(redata_t *redata, undostack_t *stack, int undono); |
|
109 |
+int redata_unsaved_unadd(redata_t *redata, undostack_t *stack, int undono); |
|
110 |
+int redata_unsaved_commit(redata_t *redata); |
|
111 |
+ |
|
112 |
+int redata_load(redata_t *redata, char *filename, int use_unsaved); |
|
113 |
+int redata_save(redata_t *redata, char *filename); |
|
114 |
+ |
|
115 |
+int redata_op_add(redata_t *redata, long pos, char *buf, long buflen, undostack_t *fromhere); |
|
116 |
+int redata_op_del(redata_t *redata, long pos, long size, undostack_t *fromhere); |
|
117 |
+int redata_op_move(redata_t *redata, long posorig, long size, long posdest, undostack_t *fromhere); |
|
118 |
+int redata_op_undo(redata_t *redata); |
|
119 |
+int redata_op_redo(redata_t *redata); |
|
120 |
+ |
|
121 |
+int redata_data_compare(redata_t *redata, long pos, char *buf, long buflen); |
|
122 |
+ |
|
123 |
+int redata_compact(redata_t *redata); |
|
124 |
+ |
|
125 |
+int redata_hash(redata_t *redata, char *resbuf129bytes); |
|
126 |
+int redata_filehash(redata_t *redata, char *filename, char *resbuf129bytes); |
|
127 |
+int redata_memhash(redata_t *redata, char *buf, long buflen, char *resbuf129bytes); |
|
128 |
+ |