return sz;
}
+static void buf_resize(Buf* buf, size_t sz) {
+ /* allocate the new buffer and gap */
+ Buf copy = *buf;
+ copy.bufsize = sz;
+ copy.bufstart = (char*)malloc(copy.bufsize);
+ copy.bufend = copy.bufstart + copy.bufsize;
+ copy.gapstart = copy.bufstart;
+ copy.gapend = copy.bufend;
+ /* copy the data from the old buffer to the new one */
+ for (char* curr = buf->bufstart; curr < buf->gapstart; curr++)
+ *(copy.gapstart++) = *(curr);
+ for (char* curr = buf->gapend; curr < buf->bufend; curr++)
+ *(copy.gapstart++) = *(curr);
+ /* free the buffer and commit the changes */
+ free(buf->bufstart);
+ memcpy(buf, ©, sizeof(Buf));
+}
+
+static void buf_syncgap(Buf* buf, size_t off) {
+ assert(off <= buf_end(buf));
+ /* If the buffer is full, resize it before syncing */
+ if (0 == (buf->gapend - buf->gapstart))
+ buf_resize(buf, buf->bufsize << 1);
+ /* Move the gap to the desired offset */
+ char* newpos = (buf->bufstart + off);
+ if (newpos < buf->gapstart)
+ while (newpos < buf->gapstart)
+ *(--buf->gapend) = *(--buf->gapstart);
+ else
+ while (newpos > buf->gapstart)
+ *(buf->gapstart++) = *(buf->gapend++);
+}
+
static char getb(Buf* buf, size_t off) {
if (off >= buf_end(buf)) return '\n'; // TODO: get rid of this hack
size_t bsz = (buf->gapstart - buf->bufstart);
buf->status = NORMAL;
buf->modtime = (uint64_t)sb.st_mtime;
buf_logclear(buf);
-
+
/* use the EOL style of the first line to determine EOL style */
DosLineFeed = (getb(buf, buf_eol(buf, 0)) == '\r');
}
return buf->status;
}
-static void buf_resize(Buf* buf, size_t sz) {
- /* allocate the new buffer and gap */
- Buf copy = *buf;
- copy.bufsize = sz;
- copy.bufstart = (char*)malloc(copy.bufsize);
- copy.bufend = copy.bufstart + copy.bufsize;
- copy.gapstart = copy.bufstart;
- copy.gapend = copy.bufend;
- /* copy the data from the old buffer to the new one */
- for (char* curr = buf->bufstart; curr < buf->gapstart; curr++)
- *(copy.gapstart++) = *(curr);
- for (char* curr = buf->gapend; curr < buf->bufend; curr++)
- *(copy.gapstart++) = *(curr);
- /* free the buffer and commit the changes */
- free(buf->bufstart);
- memcpy(buf, ©, sizeof(Buf));
-}
-
-static void buf_syncgap(Buf* buf, size_t off) {
- assert(off <= buf_end(buf));
- /* If the buffer is full, resize it before syncing */
- if (0 == (buf->gapend - buf->gapstart))
- buf_resize(buf, buf->bufsize << 1);
- /* Move the gap to the desired offset */
- char* newpos = (buf->bufstart + off);
- if (newpos < buf->gapstart)
- while (newpos < buf->gapstart)
- *(--buf->gapend) = *(--buf->gapstart);
- else
- while (newpos > buf->gapstart)
- *(buf->gapstart++) = *(buf->gapend++);
-}
-
static Sel buf_getsel(Buf* buf) {
size_t temp;
Sel sel = buf->selection;