Subversion Repositories SvarDOS

Rev

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

Rev 1331 Rev 1332
Line 41... Line 41...
41
 * global variables and definitions                                          *
41
 * global variables and definitions                                          *
42
 *****************************************************************************/
42
 *****************************************************************************/
43
#define COL_TXT        0
43
#define COL_TXT        0
44
#define COL_STATUSBAR1 1
44
#define COL_STATUSBAR1 1
45
#define COL_STATUSBAR2 2
45
#define COL_STATUSBAR2 2
-
 
46
#define COL_STATUSBAR3 3
46
#define COL_SCROLLBAR  3
47
#define COL_SCROLLBAR  4
47
#define COL_MSG        4
48
#define COL_MSG        5
48
#define COL_ERR        5
49
#define COL_ERR        6
49
 
50
 
50
/* preload the mono scheme (to be overloaded at runtime if color adapter present) */
51
/* preload the mono scheme (to be overloaded at runtime if color adapter present) */
51
static unsigned char scheme[] = {0x07, 0x70, 0x70, 0x70, 0x70, 0xf0};
52
static unsigned char scheme[] = {0x07, 0x70, 0x70, 0xf0, 0x70, 0x70, 0xf0};
52
 
53
 
53
static unsigned char screenw, screenh;
54
static unsigned char screenw, screenh;
54
 
55
 
55
static struct {
56
static struct {
56
    unsigned char from;
57
    unsigned char from;
Line 74... Line 75...
74
  unsigned char cursorposy;
75
  unsigned char cursorposy;
75
  unsigned short totlines;
76
  unsigned short totlines;
76
  unsigned short curline;
77
  unsigned short curline;
77
  char lfonly;   /* set if line endings are LF (CR/LF otherwise) */
78
  char lfonly;   /* set if line endings are LF (CR/LF otherwise) */
78
  char modflag;  /* non-zero if file has been modified since last save */
79
  char modflag;  /* non-zero if file has been modified since last save */
79
  char fname[1]; /* dynamically sized */
80
  char fname[128];
80
};
81
};
81
 
82
 
82
 
83
 
83
/*****************************************************************************
84
/*****************************************************************************
84
 * functions                                                                 *
85
 * functions                                                                 *
Line 107... Line 108...
107
 
108
 
108
  return(0);
109
  return(0);
109
}
110
}
110
 
111
 
111
 
112
 
-
 
113
static void ui_getstring(const char *query, char *s, unsigned char maxlen) {
-
 
114
  unsigned char len = 0, y, x;
-
 
115
  int k;
-
 
116
 
-
 
117
  if (maxlen == 0) return;
-
 
118
  maxlen--; /* make room for the nul terminator */
-
 
119
 
-
 
120
  y = screenh - 1;
-
 
121
 
-
 
122
  /* print query string */
-
 
123
  x = mdr_cout_str(y, 0, query, scheme[COL_STATUSBAR3], 40);
-
 
124
  mdr_cout_char_rep(y, x++, ' ', scheme[COL_STATUSBAR3], screenw - x);
-
 
125
 
-
 
126
  for (;;) {
-
 
127
    mdr_cout_locate(y, x + len);
-
 
128
    k = keyb_getkey();
-
 
129
 
-
 
130
    if (k == 0x1b) return; /* ESC */
-
 
131
 
-
 
132
    if (k == '\r') {
-
 
133
      s[len] = 0;
-
 
134
      return;
-
 
135
    }
-
 
136
 
-
 
137
    if ((k == 0x08) && (len > 0)) { /* BKSPC */
-
 
138
      len--;
-
 
139
      mdr_cout_char(y, x + len, ' ', scheme[COL_STATUSBAR3]);
-
 
140
      continue;
-
 
141
    }
-
 
142
 
-
 
143
    if ((k <= 0xff) && (k >= ' ') && (len < maxlen)) {
-
 
144
      mdr_cout_char(y, x + len, k, scheme[COL_STATUSBAR3]);
-
 
145
      s[len++] = k;
-
 
146
    }
-
 
147
 
-
 
148
  }
-
 
149
}
-
 
150
 
-
 
151
 
112
/* append a nul-terminated string to line at cursor position */
152
/* append a nul-terminated string to line at cursor position */
113
static int line_append(struct file *f, const char far *buf, unsigned short len) {
153
static int line_append(struct file *f, const char far *buf, unsigned short len) {
114
  struct line far *n;
154
  struct line far *n;
115
  if (sizeof(struct line) + f->cursor->len + len < len) return(-1); /* overflow check */
155
  if (sizeof(struct line) + f->cursor->len + len < len) return(-1); /* overflow check */
116
  n = _frealloc(f->cursor, sizeof(struct line) + f->cursor->len + len);
156
  n = _frealloc(f->cursor, sizeof(struct line) + f->cursor->len + len);
Line 136... Line 176...
136
 
176
 
137
static void load_colorscheme(void) {
177
static void load_colorscheme(void) {
138
  scheme[COL_TXT] = 0x17;
178
  scheme[COL_TXT] = 0x17;
139
  scheme[COL_STATUSBAR1] = 0x70;
179
  scheme[COL_STATUSBAR1] = 0x70;
140
  scheme[COL_STATUSBAR2] = 0x78;
180
  scheme[COL_STATUSBAR2] = 0x78;
-
 
181
  scheme[COL_STATUSBAR3] = 0xf0;
141
  scheme[COL_SCROLLBAR] = 0x70;
182
  scheme[COL_SCROLLBAR] = 0x70;
142
  scheme[COL_MSG] = 0xf0;
183
  scheme[COL_MSG] = 0xf0;
143
  scheme[COL_ERR] = 0x4f;
184
  scheme[COL_ERR] = 0x4f;
144
}
185
}
145
 
186
 
Line 471... Line 512...
471
  int fd;
512
  int fd;
472
  unsigned char eolfound;
513
  unsigned char eolfound;
473
  struct file *db;
514
  struct file *db;
474
 
515
 
475
  len = strlen(fname) + 1;
516
  len = strlen(fname) + 1;
476
  db = calloc(1, sizeof(struct file) + len);
517
  db = calloc(1, sizeof(struct file));
477
  if (db == NULL) return(NULL);
518
  if (db == NULL) return(NULL);
478
  memcpy(db->fname, fname, len);
519
  memcpy(db->fname, fname, len);
479
 
520
 
480
  if (*fname == 0) goto SKIPLOADING;
521
  if (*fname == 0) goto SKIPLOADING;
481
 
522
 
Line 565... Line 606...
565
 
606
 
566
  return(db);
607
  return(db);
567
}
608
}
568
 
609
 
569
 
610
 
570
static int savefile(const struct file *db) {
611
static int savefile(const struct file *db, const char *newfname) {
571
  int fd;
612
  int fd;
572
  const struct line far *l;
613
  const struct line far *l;
573
  unsigned bytes;
614
  unsigned bytes;
574
  unsigned char eollen;
615
  unsigned char eollen;
575
  unsigned char eolbuf[2];
616
  unsigned char eolbuf[2];
-
 
617
  int errflag = 0;
576
 
618
 
-
 
619
  /* either create a new file if newfname provided, or... */
-
 
620
  if (newfname) {
577
  if (_dos_open(db->fname, O_WRONLY, &fd) != 0) {
621
    if (_dos_creatnew(newfname, _A_NORMAL, &fd) != 0) return(-1);
578
    return(-1);
622
  } else { /* ...open db->fname */
-
 
623
    if (_dos_open(db->fname, O_WRONLY, &fd) != 0) return(-1);
579
  }
624
  }
580
 
625
 
581
  l = db->cursor;
626
  l = db->cursor;
582
  while (l->prev) l = l->prev;
627
  while (l->prev) l = l->prev;
583
 
628
 
Line 592... Line 637...
592
  }
637
  }
593
 
638
 
594
  while (l) {
639
  while (l) {
595
    /* do not write the last empty line, it is only useful for edition */
640
    /* do not write the last empty line, it is only useful for edition */
596
    if (l->len != 0) {
641
    if (l->len != 0) {
597
      _dos_write(fd, l->payload, l->len, &bytes);
642
      errflag |= _dos_write(fd, l->payload, l->len, &bytes);
598
    } else if (l->next == NULL) {
643
    } else if (l->next == NULL) {
599
      break;
644
      break;
600
    }
645
    }
601
    _dos_write(fd, eolbuf, eollen, &bytes);
646
    errflag |= _dos_write(fd, eolbuf, eollen, &bytes);
602
    l = l->next;
647
    l = l->next;
603
  }
648
  }
604
 
649
 
605
  _dos_close(fd);
650
  errflag |= _dos_close(fd);
606
 
651
 
607
  return(0);
652
  return(errflag);
608
}
653
}
609
 
654
 
610
 
655
 
611
static void insert_in_line(struct file *db, const char *databuf, unsigned short len) {
656
static void insert_in_line(struct file *db, const char *databuf, unsigned short len) {
612
  struct line far *n;
657
  struct line far *n;
Line 747... Line 792...
747
    } else if (k == 0x13b) { /* F1 */
792
    } else if (k == 0x13b) { /* F1 */
748
      ui_help();
793
      ui_help();
749
      uidirty.from = 0;
794
      uidirty.from = 0;
750
      uidirty.to = 0xff;
795
      uidirty.to = 0xff;
751
 
796
 
752
    } else if (k == 0x13f) { /* F5 */
797
    } else if ((k == 0x13f) || (k == 0x140)) { /* F5 or F6 */
-
 
798
      int saveres;
-
 
799
 
-
 
800
      if ((k == 0x140) || (db->fname[0] == 0)) { /* save as... */
-
 
801
        char fname[25];
-
 
802
        ui_getstring(svarlang_str(0,6), fname, sizeof(fname));
-
 
803
        if (*fname == 0) continue;
-
 
804
        saveres = savefile(db, fname);
-
 
805
        if (saveres == 0) memcpy(db->fname, fname, sizeof(fname));
-
 
806
      } else {
-
 
807
        saveres = savefile(db, NULL);
-
 
808
      }
-
 
809
 
753
      if (savefile(db) == 0) {
810
      if (saveres == 0) {
754
        db->modflag = 0;
811
        db->modflag = 0;
755
        ui_msg(svarlang_str(0, 2), NULL, scheme[COL_MSG]);
812
        ui_msg(svarlang_str(0, 2), NULL, scheme[COL_MSG]);
756
        mdr_bios_tickswait(11); /* 11 ticks is about 600 ms */
813
        mdr_bios_tickswait(11); /* 11 ticks is about 600 ms */
757
      } else {
814
      } else {
758
        ui_msg(svarlang_str(0, 3), NULL, scheme[COL_ERR]);
815
        ui_msg(svarlang_str(0, 3), NULL, scheme[COL_ERR]);
759
        mdr_bios_tickswait(36); /* 2s */
816
        mdr_bios_tickswait(36); /* 2s */
760
      }
817
      }
761
 
818
 
-
 
819
      ui_basic(db);
-
 
820
      ui_refresh(db);
-
 
821
 
762
    } else if (k == 0x144) { /* F10 */
822
    } else if (k == 0x144) { /* F10 */
763
      db->modflag = 1;
823
      db->modflag = 1;
764
      db->lfonly ^= 1;
824
      db->lfonly ^= 1;
765
      ui_basic(db);
825
      ui_basic(db);
766
 
826