1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 #ifndef NEDIT_TEXTBUF_H_INCLUDED
28 #define NEDIT_TEXTBUF_H_INCLUDED
29
30 #include <fontconfig/fontconfig.h>
31 #include <wchar.h>
32
33
34
35 #define MAX_EXP_CHAR_LEN 256
36
37 typedef struct _RangesetTable RangesetTable;
38
39 typedef struct {
40 char selected;
41 char rectangular;
42 char zeroWidth;
43
44
45 int start;
46
47 int end;
48
49 int rectStart;
50 int rectEnd;
51 } selection;
52
53 typedef void (*bufModifyCallbackProc)(
int pos,
int nInserted,
int nDeleted,
54 int nRestyled,
const char *deletedText,
void *cbArg);
55 typedef void (*bufPreDeleteCallbackProc)(
int pos,
int nDeleted,
void *cbArg);
56 typedef void (*bufBeginModifyCallbackProc)(
void *cbArg);
57 typedef void (*bufEndModifyCallbackProc)(
void *cbArg);
58
59 typedef struct _textBuffer {
60 int length;
61
62
63 char *buf;
64 int gapStart;
65 int gapEnd;
66 selection primary;
67 selection secondary;
68 selection highlight;
69 int tabDist;
70 int useTabs;
71
72 int nModifyProcs;
73 bufModifyCallbackProc
74 *modifyProcs;
75 void **cbArgs;
76 int nPreDeleteProcs;
77 bufPreDeleteCallbackProc
78 *preDeleteProcs;
79 void **preDeleteCbArgs;
80 int nBeginModifyProcs;
81 bufBeginModifyCallbackProc
82 *beginModifyProcs;
83 void **beginModifyCbArgs;
84 int nEndModifyProcs;
85 bufEndModifyCallbackProc
86 *endModifyProcs;
87 void **endModifyCbArgs;
88 int cursorPosHint;
89
90 char nullSubsChar;
91
92
93
94
95 RangesetTable *rangesetTable;
96
97 size_t *ansi_escpos;
98 size_t alloc_ansi_escpos;
99 size_t num_ansi_escpos;
100 } textBuffer;
101
102 typedef struct EscSeqStr {
103 char *seq;
104 size_t len;
105 size_t off_orig;
106 size_t off_trans;
107 } EscSeqStr;
108
109 typedef struct EscSeqArray {
110 EscSeqStr *esc;
111 size_t num_esc;
112 char *text;
113 } EscSeqArray;
114
115 textBuffer *BufCreate(
void);
116 textBuffer *BufCreatePreallocated(
int requestedSize);
117 void BufFree(textBuffer *buf);
118 char *BufGetAll(textBuffer *buf);
119 const char *BufAsString(textBuffer *buf);
120 const char *BufAsStringCleaned(textBuffer *buf, EscSeqArray **esc);
121 void BufReintegrateEscSeq(textBuffer *buf, EscSeqArray *escseq);
122 void BufSetAll(textBuffer *buf,
const char *text);
123 char* BufGetRange(
const textBuffer* buf,
int start,
int end);
124 const char* BufGetRange2(
const textBuffer* buf,
ssize_t start,
ssize_t end,
char **free_str);
125 char BufGetCharacter(
const textBuffer* buf,
int pos);
126 wchar_t BufGetCharacterW(
const textBuffer *buf,
int pos);
127 FcChar32 BufGetCharacter32(
const textBuffer* buf,
int pos,
int *charlen);
128 char *BufGetTextInRect(textBuffer *buf,
int start,
int end,
129 int rectStart,
int rectEnd);
130 void BufBeginModifyBatch(textBuffer *buf);
131 void BufEndModifyBatch(textBuffer *buf);
132 void BufInsert(textBuffer *buf,
int pos,
const char *text);
133 void BufRemove(textBuffer *buf,
int start,
int end);
134 void BufReplace(textBuffer *buf,
int start,
int end,
const char *text);
135 void BufCopyFromBuf(textBuffer *fromBuf, textBuffer *toBuf,
int fromStart,
136 int fromEnd,
int toPos);
137 void BufInsertCol(textBuffer *buf,
int column,
int startPos,
const char *text,
138 int *charsInserted,
int *charsDeleted);
139 void BufReplaceRect(textBuffer *buf,
int start,
int end,
int rectStart,
140 int rectEnd,
const char *text);
141 void BufRemoveRect(textBuffer *buf,
int start,
int end,
int rectStart,
142 int rectEnd);
143 void BufOverlayRect(textBuffer *buf,
int startPos,
int rectStart,
144 int rectEnd,
const char *text,
int *charsInserted,
int *charsDeleted);
145 void BufClearRect(textBuffer *buf,
int start,
int end,
int rectStart,
146 int rectEnd);
147 int BufGetTabDistance(textBuffer *buf);
148 void BufSetTabDistance(textBuffer *buf,
int tabDist);
149 void BufCheckDisplay(textBuffer *buf,
int start,
int end);
150 void BufSelect(textBuffer *buf,
int start,
int end);
151 void BufUnselect(textBuffer *buf);
152 void BufRectSelect(textBuffer *buf,
int start,
int end,
int rectStart,
153 int rectEnd);
154 int BufGetSelectionPos(textBuffer *buf,
int *start,
int *end,
155 int *isRect,
int *rectStart,
int *rectEnd);
156 int BufGetEmptySelectionPos(textBuffer *buf,
int *start,
int *end,
157 int *isRect,
int *rectStart,
int *rectEnd);
158 char *BufGetSelectionText(textBuffer *buf);
159 void BufRemoveSelected(textBuffer *buf);
160 void BufReplaceSelected(textBuffer *buf,
const char *text);
161 void BufSecondarySelect(textBuffer *buf,
int start,
int end);
162 void BufSecondaryUnselect(textBuffer *buf);
163 void BufSecRectSelect(textBuffer *buf,
int start,
int end,
164 int rectStart,
int rectEnd);
165 int BufGetSecSelectPos(textBuffer *buf,
int *start,
int *end,
166 int *isRect,
int *rectStart,
int *rectEnd);
167 char *BufGetSecSelectText(textBuffer *buf);
168 void BufRemoveSecSelect(textBuffer *buf);
169 void BufReplaceSecSelect(textBuffer *buf,
const char *text);
170 void BufHighlight(textBuffer *buf,
int start,
int end);
171 void BufUnhighlight(textBuffer *buf);
172 void BufRectHighlight(textBuffer *buf,
int start,
int end,
173 int rectStart,
int rectEnd);
174 int BufGetHighlightPos(textBuffer *buf,
int *start,
int *end,
175 int *isRect,
int *rectStart,
int *rectEnd);
176 void BufAddModifyCB(textBuffer *buf, bufModifyCallbackProc bufModifiedCB,
177 void *cbArg);
178 void BufAddHighPriorityModifyCB(textBuffer *buf, bufModifyCallbackProc bufModifiedCB,
179 void *cbArg);
180 void BufRemoveModifyCB(textBuffer *buf, bufModifyCallbackProc bufModifiedCB,
181 void *cbArg);
182 void BufAddPreDeleteCB(textBuffer *buf, bufPreDeleteCallbackProc bufPreDeleteCB,
183 void *cbArg);
184 void BufRemovePreDeleteCB(textBuffer *buf, bufPreDeleteCallbackProc
185 bufPreDeleteCB,
void *cbArg);
186 void BufAddBeginModifyCB(textBuffer *buf, bufBeginModifyCallbackProc bufBeginModifyCB,
187 void *cbArg);
188 void BufRemoveBeginModifyCB(textBuffer *buf, bufBeginModifyCallbackProc
189 bufBeginModifyCB,
void *cbArg);
190 void BufAddEndModifyCB(textBuffer *buf, bufEndModifyCallbackProc bufEndModifyCB,
191 void *cbArg);
192 void BufRemoveEndModifyCB(textBuffer *buf, bufEndModifyCallbackProc
193 bufEndModifyCB,
void *cbArg);
194 int BufStartOfLine(textBuffer *buf,
int pos);
195 int BufEndOfLine(textBuffer *buf,
int pos);
196 int BufGetExpandedChar(
const textBuffer* buf,
int pos,
int indent,
197 char* outStr);
198 int BufExpandCharacter(
const char *c,
int clen,
int indent,
char *outStr,
int tabDist,
199 char nullSubsChar,
int *isMB);
200 int BufExpandCharacter4(
char c,
int indent, FcChar32 *outStr,
201 int tabDist,
char nullSubsChar);
202 int BufCharWidth(
char c,
int indent,
int tabDist,
char nullSubsChar);
203 int BufCountDispChars(
const textBuffer* buf,
int lineStartPos,
204 int targetPos);
205 int BufCountForwardDispChars(textBuffer *buf,
int lineStartPos,
int nChars);
206 int BufCountLines(textBuffer *buf,
int startPos,
int endPos);
207 int BufCountForwardNLines(
const textBuffer* buf,
int startPos,
208 unsigned nLines);
209 int BufCountBackwardNLines(textBuffer *buf,
int startPos,
int nLines);
210 int BufSearchForward(textBuffer *buf,
int startPos,
const char *searchChars,
211 int *foundPos);
212 int BufSearchBackward(textBuffer *buf,
int startPos,
const char *searchChars,
213 int *foundPos);
214 int BufSubstituteNullChars(
char *string,
int length, textBuffer *buf);
215 void BufUnsubstituteNullChars(
char *string, textBuffer *buf);
216 int BufCmp(textBuffer * buf,
int pos,
int len,
const char *cmpText);
217
218 void BufEnableAnsiEsc(textBuffer *buf);
219 void BufDisableAnsiEsc(textBuffer *buf);
220 void BufParseEscSeq(textBuffer *buf,
size_t pos,
size_t nInserted,
size_t nDeleted);
221 int BufEscPos2Index(
222 const textBuffer *buf,
223 size_t startIndex,
224 size_t startValue,
225 size_t pos,
226 ssize_t *index,
227 size_t *value);
228
229 int BufCharLen(
const textBuffer *buf,
int pos);
230 int BufLeftPos(textBuffer *buf,
int pos);
231 int BufRightPos(textBuffer *buf,
int pos);
232
233 int Utf8ToUcs4(
const char *src_orig, FcChar32 *dst,
int len);
234 int Ucs4ToUtf8(FcChar32 ucs4,
char *dst);
235 int Utf8CharLen(
const unsigned char *u);
236
237 #endif
238