Subversion Repositories SvarDOS

Rev

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

Rev 1316 Rev 1317
Line 454... Line 454...
454
  _dos_close(fd);
454
  _dos_close(fd);
455
  return(0);
455
  return(0);
456
}
456
}
457
 
457
 
458
 
458
 
-
 
459
static void insert_in_line(struct file *db, const char *databuf, unsigned short len, unsigned char screenw, unsigned char screenh, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
-
 
460
  struct line far *n;
-
 
461
  n = _frealloc(db->cursor, sizeof(struct line) + db->cursor->len + len);
-
 
462
  if (n != NULL) {
-
 
463
    unsigned short off = db->xoffset + db->cursorposx;
-
 
464
    if (n->prev) n->prev->next = n;
-
 
465
    if (n->next) n->next->prev = n;
-
 
466
    db->cursor = n;
-
 
467
    _fmemmove(db->cursor->payload + off + len, db->cursor->payload + off, db->cursor->len - off + 1);
-
 
468
    db->cursor->len += len;
-
 
469
    *uidirtyfrom = db->cursorposy;
-
 
470
    *uidirtyto = db->cursorposy;
-
 
471
    while (len--) {
-
 
472
      db->cursor->payload[off++] = *databuf;
-
 
473
      databuf++;
-
 
474
      cursor_right(db, screenw, screenh, uidirtyfrom, uidirtyto);
-
 
475
    }
-
 
476
  }
-
 
477
}
-
 
478
 
-
 
479
 
459
int main(void) {
480
int main(void) {
460
  const char *fname;
481
  const char *fname;
461
  struct file db;
482
  struct file db;
462
  unsigned char screenw = 0, screenh = 0;
483
  unsigned char screenw = 0, screenh = 0;
463
  unsigned char uidirtyfrom = 0, uidirtyto = 0xff; /* make sure to redraw entire UI at first run */
484
  unsigned char uidirtyfrom = 0, uidirtyto = 0xff; /* make sure to redraw entire UI at first run */
Line 551... Line 572...
551
 
572
 
552
    } else if (k == 0x008) { /* BKSPC */
573
    } else if (k == 0x008) { /* BKSPC */
553
      bkspc(&db, screenw, &uidirtyfrom, &uidirtyto);
574
      bkspc(&db, screenw, &uidirtyfrom, &uidirtyto);
554
 
575
 
555
    } else if ((k >= 0x20) && (k <= 0xff)) { /* "normal" character */
576
    } else if ((k >= 0x20) && (k <= 0xff)) { /* "normal" character */
556
      struct line far *n;
577
      char c = k;
557
      n = _frealloc(db.cursor, sizeof(struct line) + db.cursor->len);
578
      insert_in_line(&db, &c, 1, screenw, screenh, &uidirtyfrom, &uidirtyto);
-
 
579
 
558
      if (n != NULL) {
580
    } else if (k == 0x009) { /* TAB */
559
        unsigned short off = db.xoffset + db.cursorposx;
-
 
560
        if (n->prev) n->prev->next = n;
-
 
561
        if (n->next) n->next->prev = n;
-
 
562
        db.cursor = n;
-
 
563
        _fmemmove(db.cursor->payload + off + 1, db.cursor->payload + off, db.cursor->len - off + 1);
-
 
564
        db.cursor->len += 1;
-
 
565
        uidirtyfrom = db.cursorposy;
-
 
566
        uidirtyto = db.cursorposy;
-
 
567
        db.cursor->payload[off] = k;
581
      const char *tab = "        ";
568
        cursor_right(&db, screenw, screenh, &uidirtyfrom, &uidirtyto);
582
      insert_in_line(&db, tab, 8, screenw, screenh, &uidirtyfrom, &uidirtyto);
569
      }
-
 
570
 
583
 
571
    } else if (k == 0x13b) { /* F1 */
584
    } else if (k == 0x13b) { /* F1 */
572
      ui_help(screenw);
585
      ui_help(screenw);
573
      uidirtyfrom = 0;
586
      uidirtyfrom = 0;
574
      uidirtyto = 0xff;
587
      uidirtyto = 0xff;