Subversion Repositories SvarDOS

Rev

Rev 1326 | Rev 1328 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1326 Rev 1327
Line 47... Line 47...
47
#define COL_MSG        4
47
#define COL_MSG        4
48
#define COL_ERR        5
48
#define COL_ERR        5
49
 
49
 
50
/* preload the mono scheme (to be overloaded at runtime if color adapter present) */
50
/* preload the mono scheme (to be overloaded at runtime if color adapter present) */
51
static unsigned char scheme[] = {0x07, 0x70, 0x70, 0x70, 0x70, 0xf0};
51
static unsigned char scheme[] = {0x07, 0x70, 0x70, 0x70, 0x70, 0xf0};
-
 
52
 
52
static unsigned char screenw, screenh;
53
static unsigned char screenw, screenh;
53
 
54
 
-
 
55
//static union {
-
 
56
static struct {
-
 
57
    unsigned char from;
-
 
58
    unsigned char to;
-
 
59
//  };
-
 
60
//  unsigned short fromto;
-
 
61
} uidirty = {0, 0xff}; /* make sure to redraw entire UI at first run */
-
 
62
//} uidirty = {0xff, 0};
-
 
63
 
54
#define SCROLL_CURSOR 0xB1
64
#define SCROLL_CURSOR 0xB1
55
 
65
 
56
struct line {
66
struct line {
57
  struct line far *prev;
67
  struct line far *prev;
58
  struct line far *next;
68
  struct line far *next;
Line 172... Line 182...
172
    mdr_cout_char(i, screenw - 1, SCROLL_CURSOR, scheme[COL_SCROLLBAR]);
182
    mdr_cout_char(i, screenw - 1, SCROLL_CURSOR, scheme[COL_SCROLLBAR]);
173
  }
183
  }
174
}
184
}
175
 
185
 
176
 
186
 
177
static void ui_msg(const char *msg, unsigned char *uidirtyfrom, unsigned char *uidirtyto, unsigned char attr) {
187
static void ui_msg(const char *msg, unsigned char attr) {
178
  unsigned short x, y, msglen, i;
188
  unsigned short x, y, msglen, i;
179
  msglen = strlen(msg);
189
  msglen = strlen(msg);
180
  y = (screenh - 4) >> 1;
190
  y = (screenh - 4) >> 1;
181
  x = (screenw - msglen - 4) >> 1;
191
  x = (screenw - msglen - 4) >> 1;
182
  for (i = y+2; i >= y; i--) mdr_cout_char_rep(i, x, ' ', attr, msglen + 2);
192
  for (i = y+2; i >= y; i--) mdr_cout_char_rep(i, x, ' ', attr, msglen + 2);
183
  mdr_cout_str(y+1, x+1, msg, attr, msglen);
193
  mdr_cout_str(y+1, x+1, msg, attr, msglen);
184
 
194
 
185
  if (*uidirtyfrom > y) *uidirtyfrom = y;
195
  if (uidirty.from > y) uidirty.from = y;
186
  if (*uidirtyto < y+2) *uidirtyto = y+2;
196
  if (uidirty.to < y+2) uidirty.to = y+2;
187
}
197
}
188
 
198
 
189
 
199
 
190
static void ui_help(void) {
200
static void ui_help(void) {
191
#define MAXLINLEN 35
201
#define MAXLINLEN 35
Line 209... Line 219...
209
  mdr_cout_cursor_show();
219
  mdr_cout_cursor_show();
210
#undef MAXLINLEN
220
#undef MAXLINLEN
211
}
221
}
212
 
222
 
213
 
223
 
214
static void ui_refresh(const struct file *db, unsigned char uidirtyfrom, unsigned char uidirtyto) {
224
static void ui_refresh(const struct file *db) {
215
  unsigned char x;
225
  unsigned char x;
216
  const struct line far *l;
226
  const struct line far *l;
217
  unsigned char y = db->cursorposy;
227
  unsigned char y = db->cursorposy;
218
 
228
 
219
#ifdef DBG_REFRESH
229
#ifdef DBG_REFRESH
Line 221... Line 231...
221
  m++;
231
  m++;
222
  if (m > 'z') m = 'a';
232
  if (m > 'z') m = 'a';
223
#endif
233
#endif
224
 
234
 
225
  /* rewind cursor line to first line that needs redrawing */
235
  /* rewind cursor line to first line that needs redrawing */
226
  for (l = db->cursor; y > uidirtyfrom; y--) l = l->prev;
236
  for (l = db->cursor; y > uidirty.from; y--) l = l->prev;
227
 
237
 
228
  /* iterate over lines and redraw whatever needs to be redrawn */
238
  /* iterate over lines and redraw whatever needs to be redrawn */
229
  for (; l != NULL; l = l->next, y++) {
239
  for (; l != NULL; l = l->next, y++) {
230
 
240
 
231
    /* skip lines that do not need to be refreshed */
241
    /* skip lines that do not need to be refreshed */
232
    if (y < uidirtyfrom) continue;
242
    if (y < uidirty.from) continue;
233
    if (y > uidirtyto) break;
243
    if (y > uidirty.to) break;
234
 
244
 
235
    x = 0;
245
    x = 0;
236
    if (db->xoffset < l->len) {
246
    if (db->xoffset < l->len) {
237
      unsigned char i, limit;
247
      unsigned char i, limit;
238
      if (l->len - db->xoffset < screenw) {
248
      if (l->len - db->xoffset < screenw) {
Line 253... Line 263...
253
    if (y == screenh - 2) break;
263
    if (y == screenh - 2) break;
254
  }
264
  }
255
 
265
 
256
  /* fill all lines below if empty (and they need to be redrawn) */
266
  /* fill all lines below if empty (and they need to be redrawn) */
257
  if (l == NULL) {
267
  if (l == NULL) {
258
    while ((y < screenh - 1) && (y < uidirtyto)) {
268
    while ((y < screenh - 1) && (y < uidirty.to)) {
259
      mdr_cout_char_rep(y++, 0, ' ', scheme[COL_TXT], screenw - 1);
269
      mdr_cout_char_rep(y++, 0, ' ', scheme[COL_TXT], screenw - 1);
260
    }
270
    }
261
  }
271
  }
262
}
272
}
263
 
273
 
264
 
274
 
265
static void check_cursor_not_after_eol(struct file *db, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
275
static void check_cursor_not_after_eol(struct file *db) {
266
  if (db->xoffset + db->cursorposx <= db->cursor->len) return;
276
  if (db->xoffset + db->cursorposx <= db->cursor->len) return;
267
 
277
 
268
  if (db->cursor->len < db->xoffset) {
278
  if (db->cursor->len < db->xoffset) {
269
    db->cursorposx = 0;
279
    db->cursorposx = 0;
270
    db->xoffset = db->cursor->len;
280
    db->xoffset = db->cursor->len;
271
    *uidirtyfrom = 0;
281
    uidirty.from = 0;
272
    *uidirtyto = 0xff;
282
    uidirty.to = 0xff;
273
  } else {
283
  } else {
274
    db->cursorposx = db->cursor->len - db->xoffset;
284
    db->cursorposx = db->cursor->len - db->xoffset;
275
  }
285
  }
276
}
286
}
277
 
287
 
278
 
288
 
279
static void cursor_up(struct file *db, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
289
static void cursor_up(struct file *db) {
280
  if (db->cursor->prev != NULL) {
290
  if (db->cursor->prev != NULL) {
281
    db->cursor = db->cursor->prev;
291
    db->cursor = db->cursor->prev;
282
    if (db->cursorposy == 0) {
292
    if (db->cursorposy == 0) {
283
      *uidirtyfrom = 0;
293
      uidirty.from = 0;
284
      *uidirtyto = 0xff;
294
      uidirty.to = 0xff;
285
    } else {
295
    } else {
286
      db->cursorposy -= 1;
296
      db->cursorposy -= 1;
287
    }
297
    }
288
  }
298
  }
289
}
299
}
290
 
300
 
291
 
301
 
292
static void cursor_eol(struct file *db, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
302
static void cursor_eol(struct file *db) {
293
  /* adjust xoffset to make sure eol is visible on screen */
303
  /* adjust xoffset to make sure eol is visible on screen */
294
  if (db->xoffset > db->cursor->len) {
304
  if (db->xoffset > db->cursor->len) {
295
    db->xoffset = db->cursor->len - 1;
305
    db->xoffset = db->cursor->len - 1;
296
    *uidirtyfrom = 0;
306
    uidirty.from = 0;
297
    *uidirtyto = 0xff;
307
    uidirty.to = 0xff;
298
  }
308
  }
299
 
309
 
300
  if (db->xoffset + screenw - 1 <= db->cursor->len) {
310
  if (db->xoffset + screenw - 1 <= db->cursor->len) {
301
    db->xoffset = db->cursor->len - screenw + 2;
311
    db->xoffset = db->cursor->len - screenw + 2;
302
    *uidirtyfrom = 0;
312
    uidirty.from = 0;
303
    *uidirtyto = 0xff;
313
    uidirty.to = 0xff;
304
  }
314
  }
305
  db->cursorposx = db->cursor->len - db->xoffset;
315
  db->cursorposx = db->cursor->len - db->xoffset;
306
}
316
}
307
 
317
 
308
 
318
 
309
static void cursor_down(struct file *db, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
319
static void cursor_down(struct file *db) {
310
  if (db->cursor->next != NULL) {
320
  if (db->cursor->next != NULL) {
311
    db->cursor = db->cursor->next;
321
    db->cursor = db->cursor->next;
312
    if (db->cursorposy < screenh - 2) {
322
    if (db->cursorposy < screenh - 2) {
313
      db->cursorposy += 1;
323
      db->cursorposy += 1;
314
    } else {
324
    } else {
315
      *uidirtyfrom = 0;
325
      uidirty.from = 0;
316
      *uidirtyto = 0xff;
326
      uidirty.to = 0xff;
317
    }
327
    }
318
  }
328
  }
319
}
329
}
320
 
330
 
321
 
331
 
322
static void cursor_left(struct file *db, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
332
static void cursor_left(struct file *db) {
323
  if (db->cursorposx > 0) {
333
  if (db->cursorposx > 0) {
324
    db->cursorposx -= 1;
334
    db->cursorposx -= 1;
325
  } else if (db->xoffset > 0) {
335
  } else if (db->xoffset > 0) {
326
    db->xoffset -= 1;
336
    db->xoffset -= 1;
327
    *uidirtyfrom = 0;
337
    uidirty.from = 0;
328
    *uidirtyto = 0xff;
338
    uidirty.to = 0xff;
329
  } else if (db->cursor->prev != NULL) { /* jump to end of line above */
339
  } else if (db->cursor->prev != NULL) { /* jump to end of line above */
330
    cursor_up(db, uidirtyfrom, uidirtyto);
340
    cursor_up(db);
331
    cursor_eol(db, uidirtyfrom, uidirtyto);
341
    cursor_eol(db);
332
  }
342
  }
333
}
343
}
334
 
344
 
335
 
345
 
336
static void cursor_home(struct file *db, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
346
static void cursor_home(struct file *db) {
337
  db->cursorposx = 0;
347
  db->cursorposx = 0;
338
  if (db->xoffset != 0) {
348
  if (db->xoffset != 0) {
339
    db->xoffset = 0;
349
    db->xoffset = 0;
340
    *uidirtyfrom = 0;
350
    uidirty.from = 0;
341
    *uidirtyto = 0xff;
351
    uidirty.to = 0xff;
342
  }
352
  }
343
}
353
}
344
 
354
 
345
 
355
 
346
static void cursor_right(struct file *db, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
356
static void cursor_right(struct file *db) {
347
  if (db->cursor->len > db->xoffset + db->cursorposx) {
357
  if (db->cursor->len > db->xoffset + db->cursorposx) {
348
    if (db->cursorposx < screenw - 2) {
358
    if (db->cursorposx < screenw - 2) {
349
      db->cursorposx += 1;
359
      db->cursorposx += 1;
350
    } else {
360
    } else {
351
      db->xoffset += 1;
361
      db->xoffset += 1;
352
      *uidirtyfrom = 0;
362
      uidirty.from = 0;
353
      *uidirtyto = 0xff;
363
      uidirty.to = 0xff;
354
    }
364
    }
355
  } else {
365
  } else {
356
    cursor_down(db, uidirtyfrom, uidirtyto);
366
    cursor_down(db);
357
    cursor_home(db, uidirtyfrom, uidirtyto);
367
    cursor_home(db);
358
  }
368
  }
359
}
369
}
360
 
370
 
361
 
371
 
362
static void del(struct file *db, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
372
static void del(struct file *db) {
363
  if (db->cursorposx + db->xoffset < db->cursor->len) {
373
  if (db->cursorposx + db->xoffset < db->cursor->len) {
364
    _fmemmove(db->cursor->payload + db->cursorposx + db->xoffset, db->cursor->payload + db->cursorposx + db->xoffset + 1, db->cursor->len - db->cursorposx - db->xoffset);
374
    _fmemmove(db->cursor->payload + db->cursorposx + db->xoffset, db->cursor->payload + db->cursorposx + db->xoffset + 1, db->cursor->len - db->cursorposx - db->xoffset);
365
    db->cursor->len -= 1; /* do this AFTER memmove so the copy includes the nul terminator */
375
    db->cursor->len -= 1; /* do this AFTER memmove so the copy includes the nul terminator */
366
    *uidirtyfrom = db->cursorposy;
376
    uidirty.from = db->cursorposy;
367
    *uidirtyto = db->cursorposy;
377
    uidirty.to = db->cursorposy;
368
  } else if (db->cursor->next != NULL) { /* cursor is at end of line: merge current line with next one (if there is a next one) */
378
  } else if (db->cursor->next != NULL) { /* cursor is at end of line: merge current line with next one (if there is a next one) */
369
    struct line far *nextline = db->cursor->next;
379
    struct line far *nextline = db->cursor->next;
370
    if (db->cursor->next->len > 0) {
380
    if (db->cursor->next->len > 0) {
371
      void far *newptr = _frealloc(db->cursor, sizeof(struct line) + db->cursor->len + db->cursor->next->len + 1);
381
      void far *newptr = _frealloc(db->cursor, sizeof(struct line) + db->cursor->len + db->cursor->next->len + 1);
372
      if (newptr != NULL) {
382
      if (newptr != NULL) {
Line 377... Line 387...
377
    }
387
    }
378
    db->cursor->next = db->cursor->next->next;
388
    db->cursor->next = db->cursor->next->next;
379
    db->cursor->next->prev = db->cursor;
389
    db->cursor->next->prev = db->cursor;
380
    if (db->cursor->prev != NULL) db->cursor->prev->next = db->cursor; /* in case realloc changed my pointer */
390
    if (db->cursor->prev != NULL) db->cursor->prev->next = db->cursor; /* in case realloc changed my pointer */
381
    _ffree(nextline);
391
    _ffree(nextline);
382
    *uidirtyfrom = db->cursorposy;
392
    uidirty.from = db->cursorposy;
383
    *uidirtyto = 0xff;
393
    uidirty.to = 0xff;
384
  }
394
  }
385
}
395
}
386
 
396
 
387
 
397
 
388
static void bkspc(struct file *db, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
398
static void bkspc(struct file *db) {
389
 
399
 
390
  /* backspace is basically "left + del", not applicable only if cursor is on 1st byte of the file */
400
  /* backspace is basically "left + del", not applicable only if cursor is on 1st byte of the file */
391
  if ((db->cursorposx == 0) && (db->xoffset == 0) && (db->cursor->prev == NULL)) return;
401
  if ((db->cursorposx == 0) && (db->xoffset == 0) && (db->cursor->prev == NULL)) return;
392
 
402
 
393
  cursor_left(db, uidirtyfrom, uidirtyto);
403
  cursor_left(db);
394
  del(db, uidirtyfrom, uidirtyto);
404
  del(db);
395
}
405
}
396
 
406
 
397
 
407
 
398
/* a custom argv-parsing routine that looks directly inside the PSP, avoids the need
408
/* a custom argv-parsing routine that looks directly inside the PSP, avoids the need
399
 * of argc and argv, saves some 330 bytes of binary size */
409
 * of argc and argv, saves some 330 bytes of binary size */
Line 568... Line 578...
568
  _dos_close(fd);
578
  _dos_close(fd);
569
  return(0);
579
  return(0);
570
}
580
}
571
 
581
 
572
 
582
 
573
static void insert_in_line(struct file *db, const char *databuf, unsigned short len, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
583
static void insert_in_line(struct file *db, const char *databuf, unsigned short len) {
574
  struct line far *n;
584
  struct line far *n;
575
  n = _frealloc(db->cursor, sizeof(struct line) + db->cursor->len + len);
585
  n = _frealloc(db->cursor, sizeof(struct line) + db->cursor->len + len);
576
  if (n != NULL) {
586
  if (n != NULL) {
577
    unsigned short off = db->xoffset + db->cursorposx;
587
    unsigned short off = db->xoffset + db->cursorposx;
578
    if (n->prev) n->prev->next = n;
588
    if (n->prev) n->prev->next = n;
579
    if (n->next) n->next->prev = n;
589
    if (n->next) n->next->prev = n;
580
    db->cursor = n;
590
    db->cursor = n;
581
    _fmemmove(db->cursor->payload + off + len, db->cursor->payload + off, db->cursor->len - off + 1);
591
    _fmemmove(db->cursor->payload + off + len, db->cursor->payload + off, db->cursor->len - off + 1);
582
    db->cursor->len += len;
592
    db->cursor->len += len;
583
    *uidirtyfrom = db->cursorposy;
593
    uidirty.from = db->cursorposy;
584
    *uidirtyto = db->cursorposy;
594
    uidirty.to = db->cursorposy;
585
    while (len--) {
595
    while (len--) {
586
      db->cursor->payload[off++] = *databuf;
596
      db->cursor->payload[off++] = *databuf;
587
      databuf++;
597
      databuf++;
588
      cursor_right(db, uidirtyfrom, uidirtyto);
598
      cursor_right(db);
589
    }
599
    }
590
  }
600
  }
591
}
601
}
592
 
602
 
593
 
603
 
594
int main(void) {
604
int main(void) {
595
  const char *fname;
605
  const char *fname;
596
  struct file *db;
606
  struct file *db;
597
  unsigned char uidirtyfrom = 0, uidirtyto = 0xff; /* make sure to redraw entire UI at first run */
-
 
598
 
607
 
599
  {
608
  {
600
    char nlspath[128], lang[8];
609
    char nlspath[128], lang[8];
601
    svarlang_autoload_pathlist("sved", mdr_dos_getenv(nlspath, "NLSPATH", sizeof(nlspath)), mdr_dos_getenv(lang, "LANG", sizeof(lang)));
610
    svarlang_autoload_pathlist("sved", mdr_dos_getenv(nlspath, "NLSPATH", sizeof(nlspath)), mdr_dos_getenv(lang, "LANG", sizeof(lang)));
602
  }
611
  }
Line 616... Line 625...
616
  ui_basic(db);
625
  ui_basic(db);
617
 
626
 
618
  for (;;) {
627
  for (;;) {
619
    int k;
628
    int k;
620
 
629
 
621
    check_cursor_not_after_eol(db, &uidirtyfrom, &uidirtyto);
630
    check_cursor_not_after_eol(db);
622
    mdr_cout_locate(db->cursorposy, db->cursorposx);
631
    mdr_cout_locate(db->cursorposy, db->cursorposx);
623
 
632
 
624
    if (uidirtyfrom != 0xff) {
633
    if (uidirty.from != 0xff) {
625
      ui_refresh(db, uidirtyfrom, uidirtyto);
634
      ui_refresh(db);
626
      uidirtyfrom = 0xff;
635
      uidirty.from = 0xff;
627
    }
636
    }
628
 
637
 
629
    k = keyb_getkey();
638
    k = keyb_getkey();
630
 
639
 
631
    if (k == 0x150) { /* down */
640
    if (k == 0x150) { /* down */
632
      cursor_down(db, &uidirtyfrom, &uidirtyto);
641
      cursor_down(db);
633
 
642
 
634
    } else if (k == 0x148) { /* up */
643
    } else if (k == 0x148) { /* up */
635
      cursor_up(db, &uidirtyfrom, &uidirtyto);
644
      cursor_up(db);
636
 
645
 
637
    } else if (k == 0x14D) { /* right */
646
    } else if (k == 0x14D) { /* right */
638
      cursor_right(db, &uidirtyfrom, &uidirtyto);
647
      cursor_right(db);
639
 
648
 
640
    } else if (k == 0x14B) { /* left */
649
    } else if (k == 0x14B) { /* left */
641
      cursor_left(db, &uidirtyfrom, &uidirtyto);
650
      cursor_left(db);
642
 
651
 
643
    } else if (k == 0x149) { /* pgup */
652
    } else if (k == 0x149) { /* pgup */
644
      // TODO
653
      // TODO
645
 
654
 
646
    } else if (k == 0x151) { /* pgdown */
655
    } else if (k == 0x151) { /* pgdown */
647
      // TODO
656
      // TODO
648
 
657
 
649
    } else if (k == 0x147) { /* home */
658
    } else if (k == 0x147) { /* home */
650
       cursor_home(db, &uidirtyfrom, &uidirtyto);
659
       cursor_home(db);
651
 
660
 
652
    } else if (k == 0x14F) { /* end */
661
    } else if (k == 0x14F) { /* end */
653
       cursor_eol(db, &uidirtyfrom, &uidirtyto);
662
       cursor_eol(db);
654
 
663
 
655
    } else if (k == 0x1B) { /* ESC */
664
    } else if (k == 0x1B) { /* ESC */
656
      break;
665
      break;
657
 
666
 
658
    } else if (k == 0x0D) { /* ENTER */
667
    } else if (k == 0x0D) { /* ENTER */
Line 662... Line 671...
662
        db->cursor->prev->len = db->xoffset + db->cursorposx;
671
        db->cursor->prev->len = db->xoffset + db->cursorposx;
663
        db->cursor->prev->payload[db->cursor->prev->len] = 0;
672
        db->cursor->prev->payload[db->cursor->prev->len] = 0;
664
        /* move cursor to the (new) line below */
673
        /* move cursor to the (new) line below */
665
        db->cursorposx = 0;
674
        db->cursorposx = 0;
666
        if (db->cursorposy < screenh - 2) {
675
        if (db->cursorposy < screenh - 2) {
667
          uidirtyfrom = db->cursorposy;
676
          uidirty.from = db->cursorposy;
668
          db->cursorposy++;
677
          db->cursorposy++;
669
        } else {
678
        } else {
670
          uidirtyfrom = 0;
679
          uidirty.from = 0;
671
        }
680
        }
672
        uidirtyto = 0xff;
681
        uidirty.to = 0xff;
673
      } else {
682
      } else {
674
        /* ERROR: OUT OF MEMORY */
683
        /* ERROR: OUT OF MEMORY */
675
      }
684
      }
676
 
685
 
677
    } else if (k == 0x153) {  /* DEL */
686
    } else if (k == 0x153) {  /* DEL */
678
      del(db, &uidirtyfrom, &uidirtyto);
687
      del(db);
679
 
688
 
680
    } else if (k == 0x008) { /* BKSPC */
689
    } else if (k == 0x008) { /* BKSPC */
681
      bkspc(db, &uidirtyfrom, &uidirtyto);
690
      bkspc(db);
682
 
691
 
683
    } else if ((k >= 0x20) && (k <= 0xff)) { /* "normal" character */
692
    } else if ((k >= 0x20) && (k <= 0xff)) { /* "normal" character */
684
      char c = k;
693
      char c = k;
685
      insert_in_line(db, &c, 1, &uidirtyfrom, &uidirtyto);
694
      insert_in_line(db, &c, 1);
686
 
695
 
687
    } else if (k == 0x009) { /* TAB */
696
    } else if (k == 0x009) { /* TAB */
688
      const char *tab = "        ";
697
      const char *tab = "        ";
689
      insert_in_line(db, tab, 8, &uidirtyfrom, &uidirtyto);
698
      insert_in_line(db, tab, 8);
690
 
699
 
691
    } else if (k == 0x13b) { /* F1 */
700
    } else if (k == 0x13b) { /* F1 */
692
      ui_help();
701
      ui_help();
693
      uidirtyfrom = 0;
702
      uidirty.from = 0;
694
      uidirtyto = 0xff;
703
      uidirty.to = 0xff;
695
 
704
 
696
    } else if (k == 0x13f) { /* F5 */
705
    } else if (k == 0x13f) { /* F5 */
697
      if (savefile(db) == 0) {
706
      if (savefile(db) == 0) {
698
        ui_msg(svarlang_str(0, 2), &uidirtyfrom, &uidirtyto, scheme[COL_MSG]);
707
        ui_msg(svarlang_str(0, 2), scheme[COL_MSG]);
699
        mdr_bios_tickswait(11); /* 11 ticks is about 600 ms */
708
        mdr_bios_tickswait(11); /* 11 ticks is about 600 ms */
700
      } else {
709
      } else {
701
        ui_msg(svarlang_str(0, 3), &uidirtyfrom, &uidirtyto, scheme[COL_ERR]);
710
        ui_msg(svarlang_str(0, 3), scheme[COL_ERR]);
702
        mdr_bios_tickswait(36); /* 2s */
711
        mdr_bios_tickswait(36); /* 2s */
703
      }
712
      }
704
 
713
 
705
    } else if (k == 0x144) { /* F10 */
714
    } else if (k == 0x144) { /* F10 */
706
      db->lfonly ^= 1;
715
      db->lfonly ^= 1;
Line 709... Line 718...
709
    } else if (k == 0x174) { /* CTRL+ArrRight - jump to next word */
718
    } else if (k == 0x174) { /* CTRL+ArrRight - jump to next word */
710
      /* if currently cursor is on a non-space, then fast-forward to nearest space or EOL */
719
      /* if currently cursor is on a non-space, then fast-forward to nearest space or EOL */
711
      for (;;) {
720
      for (;;) {
712
        if (db->xoffset + db->cursorposx == db->cursor->len) break;
721
        if (db->xoffset + db->cursorposx == db->cursor->len) break;
713
        if (db->cursor->payload[db->xoffset + db->cursorposx] == ' ') break;
722
        if (db->cursor->payload[db->xoffset + db->cursorposx] == ' ') break;
714
        cursor_right(db, &uidirtyfrom, &uidirtyto);
723
        cursor_right(db);
715
      }
724
      }
716
      /* now skip to next non-space or end of file */
725
      /* now skip to next non-space or end of file */
717
      for (;;) {
726
      for (;;) {
718
        cursor_right(db, &uidirtyfrom, &uidirtyto);
727
        cursor_right(db);
719
        if (db->cursor->payload[db->xoffset + db->cursorposx] != ' ') break;
728
        if (db->cursor->payload[db->xoffset + db->cursorposx] != ' ') break;
720
        if ((db->cursor->next == NULL) && (db->cursorposx + db->xoffset == db->cursor->len)) break;
729
        if ((db->cursor->next == NULL) && (db->cursorposx + db->xoffset == db->cursor->len)) break;
721
      }
730
      }
722
 
731
 
723
    } else if (k == 0x173) { /* CTRL+ArrLeft - jump to prev word */
732
    } else if (k == 0x173) { /* CTRL+ArrLeft - jump to prev word */
724
      cursor_left(db, &uidirtyfrom, &uidirtyto);
733
      cursor_left(db);
725
      /* if currently cursor is on a space, then fast-forward to nearest non-space or start of line */
734
      /* if currently cursor is on a space, then fast-forward to nearest non-space or start of line */
726
      for (;;) {
735
      for (;;) {
727
        if ((db->xoffset == 0) && (db->cursorposx == 0)) break;
736
        if ((db->xoffset == 0) && (db->cursorposx == 0)) break;
728
        if (db->cursor->payload[db->xoffset + db->cursorposx] != ' ') break;
737
        if (db->cursor->payload[db->xoffset + db->cursorposx] != ' ') break;
729
        cursor_left(db, &uidirtyfrom, &uidirtyto);
738
        cursor_left(db);
730
      }
739
      }
731
      /* now skip to next space or start of file */
740
      /* now skip to next space or start of file */
732
      for (;;) {
741
      for (;;) {
733
        cursor_left(db, &uidirtyfrom, &uidirtyto);
742
        cursor_left(db);
734
        if (db->cursor->payload[db->xoffset + db->cursorposx] == ' ') {
743
        if (db->cursor->payload[db->xoffset + db->cursorposx] == ' ') {
735
          cursor_right(db, &uidirtyfrom, &uidirtyto);
744
          cursor_right(db);
736
          break;
745
          break;
737
        }
746
        }
738
        if ((db->cursorposx == 0) && (db->xoffset == 0)) break;
747
        if ((db->cursorposx == 0) && (db->xoffset == 0)) break;
739
      }
748
      }
740
 
749