UNIXworkcode

1 /******************************************************************************* 2 * * 3 * textBuf.h -- Nirvana Editor Text Buffer Header File * 4 * * 5 * Copyright 2003 The NEdit Developers * 6 * * 7 * This is free software; you can redistribute it and/or modify it under the * 8 * terms of the GNU General Public License as published by the Free Software * 9 * Foundation; either version 2 of the License, or (at your option) any later * 10 * version. In addition, you may distribute versions of this program linked to * 11 * Motif or Open Motif. See README for details. * 12 * * 13 * This software is distributed in the hope that it will be useful, but WITHOUT * 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * 15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * 16 * more details. * 17 * * 18 * You should have received a copy of the GNU General Public License along with * 19 * software; if not, write to the Free Software Foundation, Inc., 59 Temple * 20 * Place, Suite 330, Boston, MA 02111-1307 USA * 21 * * 22 * Nirvana Text Editor * 23 * July 31, 2001 * 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 /* Maximum length in characters of a tab or control character expansion 34 of a single buffer character */ 35 #define MAX_EXP_CHAR_LEN 256 36 37 typedef struct _RangesetTable RangesetTable; 38 39 typedef struct { 40 char selected; /* True if the selection is active */ 41 char rectangular; /* True if the selection is rectangular */ 42 char zeroWidth; /* Width 0 selections aren't "real" selections, but 43 they can be useful when creating rectangular 44 selections from the keyboard. */ 45 int start; /* Pos. of start of selection, or if rectangular 46 start of line containing it. */ 47 int end; /* Pos. of end of selection, or if rectangular 48 end of line containing it. */ 49 int rectStart; /* Indent of left edge of rect. selection */ 50 int rectEnd; /* Indent of right edge of rect. selection */ 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; /* length of the text in the buffer (the length 61 of the buffer itself must be calculated: 62 gapEnd - gapStart + length) */ 63 char *buf; /* allocated memory where the text is stored */ 64 int gapStart; /* points to the first character of the gap */ 65 int gapEnd; /* points to the first char after the gap */ 66 selection primary; /* highlighted areas */ 67 selection secondary; 68 selection highlight; 69 int tabDist; /* equiv. number of characters in a tab */ 70 int useTabs; /* True if buffer routines are allowed to use 71 tabs for padding in rectangular operations */ 72 int nModifyProcs; /* number of modify-redisplay procs attached */ 73 bufModifyCallbackProc /* procedures to call when buffer is */ 74 *modifyProcs; /* modified to redisplay contents */ 75 void **cbArgs; /* caller arguments for modifyProcs above */ 76 int nPreDeleteProcs; /* number of pre-delete procs attached */ 77 bufPreDeleteCallbackProc /* procedure to call before text is deleted */ 78 *preDeleteProcs; /* from the buffer; at most one is supported. */ 79 void **preDeleteCbArgs; /* caller argument for pre-delete proc above */ 80 int nBeginModifyProcs; /* number of begin-modify procs attached */ 81 bufBeginModifyCallbackProc /* procedure to call before a batch of */ 82 *beginModifyProcs; /* modifications is done. */ 83 void **beginModifyCbArgs; /* caller args for begin-modify proc above */ 84 int nEndModifyProcs; /* number of end-modify procs attached */ 85 bufEndModifyCallbackProc /* procedure to call after a batch of */ 86 *endModifyProcs; /* modifications is done. */ 87 void **endModifyCbArgs; /* caller args for end-modify proc above */ 88 int cursorPosHint; /* hint for reasonable cursor position after 89 a buffer modification operation */ 90 char nullSubsChar; /* NEdit is based on C null-terminated strings, 91 so ascii-nul characters must be substituted 92 with something else. This is the else, but 93 of course, things get quite messy when you 94 use it */ 95 RangesetTable *rangesetTable; 96 /* current range sets */ 97 size_t *ansi_escpos; /* indices of all ansi escape positions */ 98 size_t alloc_ansi_escpos; /* ansi_escpos allocation size */ 99 size_t num_ansi_escpos; /* number of ansi escape sequences */ 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 /* NEDIT_TEXTBUF_H_INCLUDED */ 238