Line 120... |
Line 120... |
120 |
if (mdr_dos_resizeblock((sizeof(struct line) + newsiz + 15) / 16, FP_SEG(db->cursor)) == 0) return(0);
|
120 |
if (mdr_dos_resizeblock((sizeof(struct line) + newsiz + 15) / 16, FP_SEG(db->cursor)) == 0) return(0);
|
121 |
|
121 |
|
122 |
/* create a new block and copy data over */
|
122 |
/* create a new block and copy data over */
|
123 |
newptr = line_calloc(newsiz);
|
123 |
newptr = line_calloc(newsiz);
|
124 |
if (newptr == NULL) return(-1);
|
124 |
if (newptr == NULL) return(-1);
|
125 |
_fmemmove(newptr, db->cursor, sizeof(struct line) + db->cursor->len);
|
125 |
fmemmove(newptr, db->cursor, sizeof(struct line) + db->cursor->len);
|
126 |
|
126 |
|
127 |
/* rewire the linked list */
|
127 |
/* rewire the linked list */
|
128 |
db->cursor = newptr;
|
128 |
db->cursor = newptr;
|
129 |
if (newptr->next) newptr->next->prev = newptr;
|
129 |
if (newptr->next) newptr->next->prev = newptr;
|
130 |
if (newptr->prev) newptr->prev->next = newptr;
|
130 |
if (newptr->prev) newptr->prev->next = newptr;
|
Line 147... |
Line 147... |
147 |
db->cursor->next = l;
|
147 |
db->cursor->next = l;
|
148 |
l->next->prev = l;
|
148 |
l->next->prev = l;
|
149 |
}
|
149 |
}
|
150 |
db->cursor = l;
|
150 |
db->cursor = l;
|
151 |
if (slen > 0) {
|
151 |
if (slen > 0) {
|
152 |
_fmemmove(l->payload, line, slen);
|
152 |
fmemmove(l->payload, line, slen);
|
153 |
l->len = slen;
|
153 |
l->len = slen;
|
154 |
}
|
154 |
}
|
155 |
|
155 |
|
156 |
db->totlines += 1;
|
156 |
db->totlines += 1;
|
157 |
db->curline += 1;
|
157 |
db->curline += 1;
|
Line 203... |
Line 203... |
203 |
/* append a nul-terminated string to line at cursor position */
|
203 |
/* append a nul-terminated string to line at cursor position */
|
204 |
static int line_append(struct file *f, const char *buf, unsigned short len) {
|
204 |
static int line_append(struct file *f, const char *buf, unsigned short len) {
|
205 |
if (sizeof(struct line) + f->cursor->len + len < len) goto ERR; /* overflow check */
|
205 |
if (sizeof(struct line) + f->cursor->len + len < len) goto ERR; /* overflow check */
|
206 |
if (curline_resize(f, f->cursor->len + len) != 0) goto ERR;
|
206 |
if (curline_resize(f, f->cursor->len + len) != 0) goto ERR;
|
207 |
|
207 |
|
208 |
_fmemmove(f->cursor->payload + f->cursor->len, buf, len);
|
208 |
fmemmove(f->cursor->payload + f->cursor->len, buf, len);
|
209 |
f->cursor->len += len;
|
209 |
f->cursor->len += len;
|
210 |
|
210 |
|
211 |
return(0);
|
211 |
return(0);
|
212 |
ERR:
|
212 |
ERR:
|
213 |
return(-1);
|
213 |
return(-1);
|
Line 595... |
Line 595... |
595 |
}
|
595 |
}
|
596 |
|
596 |
|
597 |
|
597 |
|
598 |
static void del(struct file *db) {
|
598 |
static void del(struct file *db) {
|
599 |
if (db->cursorposx + db->xoffset < db->cursor->len) {
|
599 |
if (db->cursorposx + db->xoffset < db->cursor->len) {
|
600 |
_fmemmove(db->cursor->payload + db->cursorposx + db->xoffset, db->cursor->payload + db->cursorposx + db->xoffset + 1, db->cursor->len - db->cursorposx - db->xoffset);
|
600 |
fmemmove(db->cursor->payload + db->cursorposx + db->xoffset, db->cursor->payload + db->cursorposx + db->xoffset + 1, db->cursor->len - db->cursorposx - db->xoffset);
|
601 |
db->cursor->len -= 1; /* do this AFTER memmove so the copy includes the nul terminator */
|
601 |
db->cursor->len -= 1; /* do this AFTER memmove so the copy includes the nul terminator */
|
602 |
uidirty.from = db->cursorposy;
|
602 |
uidirty.from = db->cursorposy;
|
603 |
uidirty.to = db->cursorposy;
|
603 |
uidirty.to = db->cursorposy;
|
604 |
db->modflag = 1;
|
604 |
db->modflag = 1;
|
605 |
} else if (db->cursor->next != NULL) { /* cursor is at end of line: merge current line with next one (if there is a next one) */
|
605 |
} else if (db->cursor->next != NULL) { /* cursor is at end of line: merge current line with next one (if there is a next one) */
|
606 |
struct line far *nextline = db->cursor->next;
|
606 |
struct line far *nextline = db->cursor->next;
|
607 |
if (db->cursor->next->len > 0) {
|
607 |
if (db->cursor->next->len > 0) {
|
608 |
if (curline_resize(db, db->cursor->len + db->cursor->next->len + 1) == 0) {
|
608 |
if (curline_resize(db, db->cursor->len + db->cursor->next->len + 1) == 0) {
|
609 |
_fmemmove(db->cursor->payload + db->cursor->len, db->cursor->next->payload, db->cursor->next->len + 1);
|
609 |
fmemmove(db->cursor->payload + db->cursor->len, db->cursor->next->payload, db->cursor->next->len + 1);
|
610 |
db->cursor->len += db->cursor->next->len;
|
610 |
db->cursor->len += db->cursor->next->len;
|
611 |
}
|
611 |
}
|
612 |
}
|
612 |
}
|
613 |
|
613 |
|
614 |
db->cursor->next = db->cursor->next->next;
|
614 |
db->cursor->next = db->cursor->next->next;
|
Line 864... |
Line 864... |
864 |
|
864 |
|
865 |
static void insert_in_line(struct file *db, const char *databuf, unsigned short len) {
|
865 |
static void insert_in_line(struct file *db, const char *databuf, unsigned short len) {
|
866 |
if (curline_resize(db, db->cursor->len + len) == 0) {
|
866 |
if (curline_resize(db, db->cursor->len + len) == 0) {
|
867 |
unsigned short off = db->xoffset + db->cursorposx;
|
867 |
unsigned short off = db->xoffset + db->cursorposx;
|
868 |
db->modflag = 1;
|
868 |
db->modflag = 1;
|
869 |
_fmemmove(db->cursor->payload + off + len, db->cursor->payload + off, db->cursor->len - off + 1);
|
869 |
fmemmove(db->cursor->payload + off + len, db->cursor->payload + off, db->cursor->len - off + 1);
|
870 |
db->cursor->len += len;
|
870 |
db->cursor->len += len;
|
871 |
uidirty.from = db->cursorposy;
|
871 |
uidirty.from = db->cursorposy;
|
872 |
uidirty.to = db->cursorposy;
|
872 |
uidirty.to = db->cursorposy;
|
873 |
while (len--) {
|
873 |
while (len--) {
|
874 |
db->cursor->payload[off++] = *databuf;
|
874 |
db->cursor->payload[off++] = *databuf;
|
Line 1304... |
Line 1304... |
1304 |
} else {
|
1304 |
} else {
|
1305 |
mdr_cout_char_rep(db->cursorposy, 0, ' ', ((SCHEME_TEXT >> 4) | (SCHEME_TEXT << 4)) & 0xff, screenlastcol);
|
1305 |
mdr_cout_char_rep(db->cursorposy, 0, ' ', ((SCHEME_TEXT >> 4) | (SCHEME_TEXT << 4)) & 0xff, screenlastcol);
|
1306 |
uidirty.from = db->cursorposy;
|
1306 |
uidirty.from = db->cursorposy;
|
1307 |
uidirty.to = db->cursorposy;
|
1307 |
uidirty.to = db->cursorposy;
|
1308 |
if (db->cursor->len != 0) {
|
1308 |
if (db->cursor->len != 0) {
|
1309 |
_fmemmove(clipboard->payload, db->cursor->payload, db->cursor->len);
|
1309 |
fmemmove(clipboard->payload, db->cursor->payload, db->cursor->len);
|
1310 |
clipboard->len = db->cursor->len;
|
1310 |
clipboard->len = db->cursor->len;
|
1311 |
}
|
1311 |
}
|
1312 |
mdr_bios_tickswait(2); /* ca 100ms */
|
1312 |
mdr_bios_tickswait(2); /* ca 100ms */
|
1313 |
|
1313 |
|
1314 |
/* if this is about cutting the line (CTRL+X) then delete cur line */
|
1314 |
/* if this is about cutting the line (CTRL+X) then delete cur line */
|