Subversion Repositories SvarDOS

Rev

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

Rev 1341 Rev 1342
Line 52... Line 52...
52
static unsigned char screenw, screenh;
52
static unsigned char screenw, screenh;
53
 
53
 
54
static struct {
54
static struct {
55
    unsigned char from;
55
    unsigned char from;
56
    unsigned char to;
56
    unsigned char to;
-
 
57
    unsigned char statusbar;
57
} uidirty = {0, 0xff}; /* make sure to redraw entire UI at first run */
58
} uidirty = {0, 0xff, 1}; /* make sure to redraw entire UI at first run */
58
 
59
 
59
#define SCROLL_CURSOR 0xB1
60
#define SCROLL_CURSOR 0xB1
60
 
61
 
61
struct line {
62
struct line {
62
  struct line far *prev;
63
  struct line far *prev;
Line 82... Line 83...
82
/*****************************************************************************
83
/*****************************************************************************
83
 * functions                                                                 *
84
 * functions                                                                 *
84
 *****************************************************************************/
85
 *****************************************************************************/
85
 
86
 
86
static struct line far *line_calloc(unsigned short siz) {
87
static struct line far *line_calloc(unsigned short siz) {
-
 
88
  struct line far *res;
87
  unsigned int seg;
89
  unsigned int seg;
88
  if (_dos_allocmem((sizeof(struct line) + siz + 15) / 16, &seg) != 0) return(NULL);
90
  if (_dos_allocmem((sizeof(struct line) + siz + 15) / 16, &seg) != 0) return(NULL);
89
  _fmemset(MK_FP(seg, 0), 0, siz);
91
  res = MK_FP(seg, 0);
-
 
92
  _fmemset(res, 0, sizeof(struct line) + siz);
90
  return(MK_FP(seg, 0));
93
  return(MK_FP(seg, 0));
91
}
94
}
92
 
95
 
93
 
96
 
94
static void line_free(struct line far *ptr) {
97
static void line_free(struct line far *ptr) {
Line 130... Line 133...
130
    l->next = db->cursor->next;
133
    l->next = db->cursor->next;
131
    db->cursor->next = l;
134
    db->cursor->next = l;
132
    l->next->prev = l;
135
    l->next->prev = l;
133
  }
136
  }
134
  db->cursor = l;
137
  db->cursor = l;
-
 
138
  if (slen > 0) {
135
  _fmemmove(l->payload, line, slen);
139
    _fmemmove(l->payload, line, slen);
136
  l->len = slen;
140
    l->len = slen;
-
 
141
  }
137
 
142
 
138
  db->totlines += 1;
143
  db->totlines += 1;
139
  db->curline += 1;
144
  db->curline += 1;
140
 
145
 
141
  return(0);
146
  return(0);
Line 245... Line 250...
245
  if (uidirty.from > y) uidirty.from = y;
250
  if (uidirty.from > y) uidirty.from = y;
246
  if (uidirty.to < y+4) uidirty.to = y+4;
251
  if (uidirty.to < y+4) uidirty.to = y+4;
247
}
252
}
248
 
253
 
249
 
254
 
-
 
255
static unsigned char ui_confirm_if_unsaved(struct file *db) {
-
 
256
  if (db->modflag == 0) return(0);
-
 
257
 
-
 
258
  /* if file has been modified then ask for confirmation */
-
 
259
  ui_msg(svarlang_str(0,4), svarlang_str(0,5), SCHEME_MSG);
-
 
260
  if (keyb_getkey() == '\r') return(0);
-
 
261
 
-
 
262
  return(1);
-
 
263
}
-
 
264
 
-
 
265
 
250
static void ui_help(void) {
266
static void ui_help(void) {
251
#define MAXLINLEN 35
267
#define MAXLINLEN 35
252
  unsigned char i, offset;
268
  unsigned char i, offset;
253
  offset = (screenw - MAXLINLEN + 2) >> 1;
269
  offset = (screenw - MAXLINLEN + 2) >> 1;
254
 
270
 
Line 672... Line 688...
672
    }
688
    }
673
  }
689
  }
674
}
690
}
675
 
691
 
676
 
692
 
-
 
693
static void clear_file(struct file *db) {
-
 
694
 
-
 
695
  /* free the entire linked list of lines */
-
 
696
  db_rewind(db);
-
 
697
  while (db->cursor) {
-
 
698
    struct line far *victim;
-
 
699
    victim = db->cursor;
-
 
700
    db->cursor = db->cursor->next;
-
 
701
    line_free(victim);
-
 
702
  }
-
 
703
 
-
 
704
  /* zero out the struct */
-
 
705
  bzero(db, sizeof(struct file));
-
 
706
 
-
 
707
  /* add a single empty line and rewind */
-
 
708
  line_add(db, NULL, 0);
-
 
709
  db_rewind(db);
-
 
710
}
-
 
711
 
-
 
712
 
677
int main(void) {
713
int main(void) {
678
  const char *fname;
714
  const char *fname;
679
  struct file *db;
715
  struct file *db;
680
 
716
 
681
  {
717
  {
Line 702... Line 738...
702
    SCHEME_STBAR3 = 0xf0;
738
    SCHEME_STBAR3 = 0xf0;
703
    SCHEME_SCROLL = 0x70;
739
    SCHEME_SCROLL = 0x70;
704
    SCHEME_MSG = 0xf0;
740
    SCHEME_MSG = 0xf0;
705
    SCHEME_ERR = 0x4f;
741
    SCHEME_ERR = 0x4f;
706
  }
742
  }
707
  ui_basic(db);
-
 
708
 
743
 
709
  for (;;) {
744
  for (;;) {
710
    int k;
745
    int k;
711
 
746
 
712
    check_cursor_not_after_eol(db);
747
    check_cursor_not_after_eol(db);
Line 714... Line 749...
714
 
749
 
715
    if (uidirty.from != 0xff) {
750
    if (uidirty.from != 0xff) {
716
      ui_refresh(db);
751
      ui_refresh(db);
717
      uidirty.from = 0xff;
752
      uidirty.from = 0xff;
718
    }
753
    }
-
 
754
    if (uidirty.statusbar) {
-
 
755
      ui_basic(db);
-
 
756
      uidirty.statusbar = 0;
-
 
757
    }
719
#ifdef DBG_LINENUM
758
#ifdef DBG_LINENUM
720
      {
759
      {
721
        char ddd[10];
760
        char ddd[10];
722
        db->curline += 1;
761
        db->curline += 1;
723
        ddd[0] = '0' + db->curline / 100;
762
        ddd[0] = '0' + db->curline / 100;
Line 785... Line 824...
785
 
824
 
786
    } else if (k == 0x14F) { /* end */
825
    } else if (k == 0x14F) { /* end */
787
       cursor_eol(db);
826
       cursor_eol(db);
788
 
827
 
789
    } else if (k == 0x1B) { /* ESC */
828
    } else if (k == 0x1B) { /* ESC */
790
      if (db->modflag == 0) break;
829
      if (ui_confirm_if_unsaved(db) == 0) break;
791
      /* if file has been modified then ask for confirmation */
-
 
792
      ui_msg(svarlang_str(0,4), svarlang_str(0,5), SCHEME_MSG);
-
 
793
      if (keyb_getkey() == '\r') break;
-
 
794
 
830
 
795
    } else if (k == 0x0D) { /* ENTER */
831
    } else if (k == 0x0D) { /* ENTER */
796
      unsigned short off = db->xoffset + db->cursorposx;
832
      unsigned short off = db->xoffset + db->cursorposx;
797
      /* add a new line */
833
      /* add a new line */
798
      if (line_add(db, db->cursor->payload + off, db->cursor->len - off) == 0) {
834
      if (line_add(db, db->cursor->payload + off, db->cursor->len - off) == 0) {
Line 827... Line 863...
827
    } else if (k == 0x13b) { /* F1 */
863
    } else if (k == 0x13b) { /* F1 */
828
      ui_help();
864
      ui_help();
829
      uidirty.from = 0;
865
      uidirty.from = 0;
830
      uidirty.to = 0xff;
866
      uidirty.to = 0xff;
831
 
867
 
-
 
868
    } else if (k == 0x13c) { /* F2 (new file) */
-
 
869
      if (ui_confirm_if_unsaved(db) == 0) clear_file(db);
-
 
870
      uidirty.from = 0;
-
 
871
      uidirty.to = 0xff;
-
 
872
      uidirty.statusbar = 1;
-
 
873
 
832
    } else if ((k == 0x13f) || (k == 0x140)) { /* F5 or F6 */
874
    } else if ((k == 0x13f) || (k == 0x140)) { /* F5 or F6 */
833
      int saveres;
875
      int saveres;
834
 
876
 
835
      if ((k == 0x140) || (db->fname[0] == 0)) { /* save as... */
877
      if ((k == 0x140) || (db->fname[0] == 0)) { /* save as... */
836
        char fname[25];
878
        char fname[25];
Line 849... Line 891...
849
      } else {
891
      } else {
850
        ui_msg(svarlang_str(0, 3), NULL, SCHEME_ERR);
892
        ui_msg(svarlang_str(0, 3), NULL, SCHEME_ERR);
851
        mdr_bios_tickswait(36); /* 2s */
893
        mdr_bios_tickswait(36); /* 2s */
852
      }
894
      }
853
 
895
 
854
      ui_basic(db);
-
 
855
      ui_refresh(db);
896
      ui_refresh(db);
-
 
897
      uidirty.statusbar = 1;
856
 
898
 
857
    } else if (k == 0x144) { /* F10 */
899
    } else if (k == 0x144) { /* F10 */
858
      db->modflag = 1;
900
      db->modflag = 1;
859
      db->lfonly ^= 1;
901
      db->lfonly ^= 1;
860
      ui_basic(db);
902
      uidirty.statusbar = 1;
861
 
903
 
862
    } else if (k == 0x174) { /* CTRL+ArrRight - jump to next word */
904
    } else if (k == 0x174) { /* CTRL+ArrRight - jump to next word */
863
      /* if currently cursor is on a non-space, then fast-forward to nearest space or EOL */
905
      /* if currently cursor is on a non-space, then fast-forward to nearest space or EOL */
864
      for (;;) {
906
      for (;;) {
865
        if (db->xoffset + db->cursorposx == db->cursor->len) break;
907
        if (db->xoffset + db->cursorposx == db->cursor->len) break;