Subversion Repositories SvarDOS

Rev

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

Rev 1328 Rev 1330
Line 72... Line 72...
72
  unsigned short xoffset;
72
  unsigned short xoffset;
73
  unsigned char cursorposx;
73
  unsigned char cursorposx;
74
  unsigned char cursorposy;
74
  unsigned char cursorposy;
75
  unsigned short totlines;
75
  unsigned short totlines;
76
  unsigned short curline;
76
  unsigned short curline;
77
  char lfonly; /* set if line endings are LF (CR/LF otherwise) */
77
  char lfonly;   /* set if line endings are LF (CR/LF otherwise) */
-
 
78
  char modflag;  /* non-zero if file has been modified since last save */
78
  char fname[1]; /* dynamically sized */
79
  char fname[1]; /* dynamically sized */
79
};
80
};
80
 
81
 
81
 
82
 
82
/*****************************************************************************
83
/*****************************************************************************
Line 145... Line 146...
145
 
146
 
146
static void ui_basic(const struct file *db) {
147
static void ui_basic(const struct file *db) {
147
  const char *s = svarlang_strid(0); /* HELP */
148
  const char *s = svarlang_strid(0); /* HELP */
148
  unsigned char helpcol = screenw - (strlen(s) + 4);
149
  unsigned char helpcol = screenw - (strlen(s) + 4);
149
 
150
 
150
  /* fill status bar with background */
151
  /* fill status bar with background (without modflag as it is refreshed by ui_refresh) */
151
  mdr_cout_char_rep(screenh - 1, 0, ' ', scheme[COL_STATUSBAR1], screenw);
152
  mdr_cout_char_rep(screenh - 1, 1, ' ', scheme[COL_STATUSBAR1], screenw - 1);
152
 
153
 
153
  /* filename */
154
  /* filename */
-
 
155
  {
154
  if (db->fname[0] == 0) {
156
    const char *fn = db->fname;
155
    mdr_cout_str(screenh - 1, 0, svarlang_str(0, 1), scheme[COL_STATUSBAR1], screenw);
157
    if (*fn == 0) fn = svarlang_str(0, 1);
156
  } else {
-
 
157
    mdr_cout_str(screenh - 1, 0, db->fname, scheme[COL_STATUSBAR1], screenw);
158
    mdr_cout_str(screenh - 1, 1, fn, scheme[COL_STATUSBAR1], screenw);
158
  }
159
  }
159
 
160
 
160
  /* eol type */
161
  /* eol type */
161
  if (db->lfonly) {
162
  {
162
    mdr_cout_str(screenh - 1, helpcol - 3, "LF", scheme[COL_STATUSBAR1], 5);
163
    const char *eoltype = "CRLF";
163
  } else {
164
    if (db->lfonly) eoltype = "LF";
164
    mdr_cout_str(screenh - 1, helpcol - 5, "CRLF", scheme[COL_STATUSBAR1], 5);
165
    mdr_cout_str(screenh - 1, helpcol - 5, eoltype, scheme[COL_STATUSBAR1], 5);
165
  }
166
  }
166
 
167
 
167
  mdr_cout_str(screenh - 1, helpcol, " F1=", scheme[COL_STATUSBAR2], 40);
168
  mdr_cout_str(screenh - 1, helpcol, " F1=", scheme[COL_STATUSBAR2], 40);
168
  mdr_cout_str(screenh - 1, helpcol + 4, s, scheme[COL_STATUSBAR2], 40);
169
  mdr_cout_str(screenh - 1, helpcol + 4, s, scheme[COL_STATUSBAR2], 40);
169
}
170
}
Line 176... Line 177...
176
  x = (screenw - msglen - 4) >> 1;
177
  x = (screenw - msglen - 4) >> 1;
177
  for (i = y+2; i >= y; i--) mdr_cout_char_rep(i, x, ' ', attr, msglen + 2);
178
  for (i = y+2; i >= y; i--) mdr_cout_char_rep(i, x, ' ', attr, msglen + 2);
178
  mdr_cout_str(y+1, x+1, msg, attr, msglen);
179
  mdr_cout_str(y+1, x+1, msg, attr, msglen);
179
 
180
 
180
  if (uidirty.from > y) uidirty.from = y;
181
  if (uidirty.from > y) uidirty.from = y;
181
  if (uidirty.to < y+2) uidirty.to = y+2;
182
  if (uidirty.to < y+3) uidirty.to = y+3;
182
}
183
}
183
 
184
 
184
 
185
 
185
static void ui_help(void) {
186
static void ui_help(void) {
186
#define MAXLINLEN 35
187
#define MAXLINLEN 35
Line 253... Line 254...
253
    while ((y < screenh - 1) && (y < uidirty.to)) {
254
    while ((y < screenh - 1) && (y < uidirty.to)) {
254
      mdr_cout_char_rep(y++, 0, ' ', scheme[COL_TXT], screenw - 1);
255
      mdr_cout_char_rep(y++, 0, ' ', scheme[COL_TXT], screenw - 1);
255
    }
256
    }
256
  }
257
  }
257
 
258
 
-
 
259
  /* "file changed" flag */
-
 
260
  {
-
 
261
    char flg = ' ';
-
 
262
    if (db->modflag) flg = '*';
-
 
263
    mdr_cout_char(screenh - 1, 0, flg, scheme[COL_STATUSBAR1]);
-
 
264
  }
-
 
265
 
258
  /* scroll bar */
266
  /* scroll bar */
259
  for (y = 0; y < (screenh - 1); y++) {
267
  for (y = 0; y < (screenh - 1); y++) {
260
    mdr_cout_char(y, screenw - 1, SCROLL_CURSOR, scheme[COL_SCROLLBAR]);
268
    mdr_cout_char(y, screenw - 1, SCROLL_CURSOR, scheme[COL_SCROLLBAR]);
261
  }
269
  }
262
 
270
 
Line 379... Line 387...
379
  if (db->cursorposx + db->xoffset < db->cursor->len) {
387
  if (db->cursorposx + db->xoffset < db->cursor->len) {
380
    _fmemmove(db->cursor->payload + db->cursorposx + db->xoffset, db->cursor->payload + db->cursorposx + db->xoffset + 1, db->cursor->len - db->cursorposx - db->xoffset);
388
    _fmemmove(db->cursor->payload + db->cursorposx + db->xoffset, db->cursor->payload + db->cursorposx + db->xoffset + 1, db->cursor->len - db->cursorposx - db->xoffset);
381
    db->cursor->len -= 1; /* do this AFTER memmove so the copy includes the nul terminator */
389
    db->cursor->len -= 1; /* do this AFTER memmove so the copy includes the nul terminator */
382
    uidirty.from = db->cursorposy;
390
    uidirty.from = db->cursorposy;
383
    uidirty.to = db->cursorposy;
391
    uidirty.to = db->cursorposy;
-
 
392
    db->modflag = 1;
384
  } else if (db->cursor->next != NULL) { /* cursor is at end of line: merge current line with next one (if there is a next one) */
393
  } else if (db->cursor->next != NULL) { /* cursor is at end of line: merge current line with next one (if there is a next one) */
385
    struct line far *nextline = db->cursor->next;
394
    struct line far *nextline = db->cursor->next;
386
    if (db->cursor->next->len > 0) {
395
    if (db->cursor->next->len > 0) {
387
      void far *newptr = _frealloc(db->cursor, sizeof(struct line) + db->cursor->len + db->cursor->next->len + 1);
396
      void far *newptr = _frealloc(db->cursor, sizeof(struct line) + db->cursor->len + db->cursor->next->len + 1);
388
      if (newptr != NULL) {
397
      if (newptr != NULL) {
Line 396... Line 405...
396
    if (db->cursor->prev != NULL) db->cursor->prev->next = db->cursor; /* in case realloc changed my pointer */
405
    if (db->cursor->prev != NULL) db->cursor->prev->next = db->cursor; /* in case realloc changed my pointer */
397
    _ffree(nextline);
406
    _ffree(nextline);
398
    uidirty.from = db->cursorposy;
407
    uidirty.from = db->cursorposy;
399
    uidirty.to = 0xff;
408
    uidirty.to = 0xff;
400
    db->totlines -= 1;
409
    db->totlines -= 1;
-
 
410
    db->modflag = 1;
401
  }
411
  }
402
}
412
}
403
 
413
 
404
 
414
 
405
static void bkspc(struct file *db) {
415
static void bkspc(struct file *db) {
Line 581... Line 591...
581
    _dos_write(fd, eolbuf, eollen, &bytes);
591
    _dos_write(fd, eolbuf, eollen, &bytes);
582
    l = l->next;
592
    l = l->next;
583
  }
593
  }
584
 
594
 
585
  _dos_close(fd);
595
  _dos_close(fd);
-
 
596
 
586
  return(0);
597
  return(0);
587
}
598
}
588
 
599
 
589
 
600
 
590
static void insert_in_line(struct file *db, const char *databuf, unsigned short len) {
601
static void insert_in_line(struct file *db, const char *databuf, unsigned short len) {
591
  struct line far *n;
602
  struct line far *n;
592
  n = _frealloc(db->cursor, sizeof(struct line) + db->cursor->len + len);
603
  n = _frealloc(db->cursor, sizeof(struct line) + db->cursor->len + len);
593
  if (n != NULL) {
604
  if (n != NULL) {
594
    unsigned short off = db->xoffset + db->cursorposx;
605
    unsigned short off = db->xoffset + db->cursorposx;
-
 
606
    db->modflag = 1;
595
    if (n->prev) n->prev->next = n;
607
    if (n->prev) n->prev->next = n;
596
    if (n->next) n->next->prev = n;
608
    if (n->next) n->next->prev = n;
597
    db->cursor = n;
609
    db->cursor = n;
598
    _fmemmove(db->cursor->payload + off + len, db->cursor->payload + off, db->cursor->len - off + 1);
610
    _fmemmove(db->cursor->payload + off + len, db->cursor->payload + off, db->cursor->len - off + 1);
599
    db->cursor->len += len;
611
    db->cursor->len += len;
Line 689... Line 701...
689
 
701
 
690
    } else if (k == 0x0D) { /* ENTER */
702
    } else if (k == 0x0D) { /* ENTER */
691
      unsigned short off = db->xoffset + db->cursorposx;
703
      unsigned short off = db->xoffset + db->cursorposx;
692
      /* add a new line */
704
      /* add a new line */
693
      if (line_add(db, db->cursor->payload + off, db->cursor->len - off) == 0) {
705
      if (line_add(db, db->cursor->payload + off, db->cursor->len - off) == 0) {
-
 
706
        db->modflag = 1;
694
        db->cursor = db->cursor->prev; /* back to original line */
707
        db->cursor = db->cursor->prev; /* back to original line */
695
        db->curline -= 1;
708
        db->curline -= 1;
696
        /* trim the line above */
709
        /* trim the line above */
697
        db->cursor->len = off;
710
        db->cursor->len = off;
698
        /* move cursor to the (new) line below */
711
        /* move cursor to the (new) line below */
Line 723... Line 736...
723
      uidirty.from = 0;
736
      uidirty.from = 0;
724
      uidirty.to = 0xff;
737
      uidirty.to = 0xff;
725
 
738
 
726
    } else if (k == 0x13f) { /* F5 */
739
    } else if (k == 0x13f) { /* F5 */
727
      if (savefile(db) == 0) {
740
      if (savefile(db) == 0) {
-
 
741
        db->modflag = 0;
728
        ui_msg(svarlang_str(0, 2), scheme[COL_MSG]);
742
        ui_msg(svarlang_str(0, 2), scheme[COL_MSG]);
729
        mdr_bios_tickswait(11); /* 11 ticks is about 600 ms */
743
        mdr_bios_tickswait(11); /* 11 ticks is about 600 ms */
730
      } else {
744
      } else {
731
        ui_msg(svarlang_str(0, 3), scheme[COL_ERR]);
745
        ui_msg(svarlang_str(0, 3), scheme[COL_ERR]);
732
        mdr_bios_tickswait(36); /* 2s */
746
        mdr_bios_tickswait(36); /* 2s */
733
      }
747
      }
734
 
748
 
735
    } else if (k == 0x144) { /* F10 */
749
    } else if (k == 0x144) { /* F10 */
-
 
750
      db->modflag = 1;
736
      db->lfonly ^= 1;
751
      db->lfonly ^= 1;
737
      ui_basic(db);
752
      ui_basic(db);
738
 
753
 
739
    } else if (k == 0x174) { /* CTRL+ArrRight - jump to next word */
754
    } else if (k == 0x174) { /* CTRL+ArrRight - jump to next word */
740
      /* if currently cursor is on a non-space, then fast-forward to nearest space or EOL */
755
      /* if currently cursor is on a non-space, then fast-forward to nearest space or EOL */