Subversion Repositories SvarDOS

Rev

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

Rev 1347 Rev 1348
Line 64... Line 64...
64
  unsigned short len;
64
  unsigned short len;
65
  char payload[1];
65
  char payload[1];
66
};
66
};
67
 
67
 
68
struct file {
68
struct file {
69
  int fd;
-
 
70
  struct line far *cursor;
69
  struct line far *cursor;
71
  unsigned short xoffset;
70
  unsigned short xoffset;
72
  unsigned char cursorposx;
71
  unsigned short cursorposx;
73
  unsigned char cursorposy;
72
  unsigned short cursorposy;
74
  unsigned short totlines;
73
  unsigned short totlines;
75
  unsigned short curline;
74
  unsigned short curline;
76
  char lfonly;   /* set if line endings are LF (CR/LF otherwise) */
75
  char lfonly;   /* set if line endings are LF (CR/LF otherwise) */
77
  char modflag;  /* non-zero if file has been modified since last save */
76
  char modflag;  /* non-zero if file has been modified since last save */
78
  char fname[128];
77
  char fname[128];
Line 96... Line 95...
96
static void line_free(struct line far *ptr) {
95
static void line_free(struct line far *ptr) {
97
  _dos_freemem(FP_SEG(ptr));
96
  _dos_freemem(FP_SEG(ptr));
98
}
97
}
99
 
98
 
100
 
99
 
101
static signed char curline_resize(struct file far *db, unsigned short newsiz) {
100
static int curline_resize(struct file far *db, unsigned short newsiz) {
102
  unsigned int maxavail;
101
  unsigned int maxavail;
103
  struct line far *newptr;
102
  struct line far *newptr;
104
 
103
 
105
  /* try resizing the block (much faster) */
104
  /* try resizing the block (much faster) */
106
  if (_dos_setblock((sizeof(struct line) + newsiz + 15) / 16, FP_SEG(db->cursor), &maxavail) == 0) return(0);
105
  if (_dos_setblock((sizeof(struct line) + newsiz + 15) / 16, FP_SEG(db->cursor), &maxavail) == 0) return(0);
Line 144... Line 143...
144
 
143
 
145
  return(0);
144
  return(0);
146
}
145
}
147
 
146
 
148
 
147
 
149
static void ui_getstring(const char *query, char *s, unsigned char maxlen) {
148
static void ui_getstring(const char *query, char *s, unsigned short maxlen) {
150
  unsigned char len = 0, y, x;
149
  unsigned short len = 0;
-
 
150
  unsigned char y, x;
151
  int k;
151
  int k;
152
 
152
 
153
  if (maxlen == 0) return;
153
  if (maxlen == 0) return;
154
  maxlen--; /* make room for the nul terminator */
154
  maxlen--; /* make room for the nul terminator */
155
 
155
 
Line 205... Line 205...
205
}
205
}
206
 
206
 
207
 
207
 
208
static void ui_basic(const struct file *db) {
208
static void ui_basic(const struct file *db) {
209
  const char *s = svarlang_strid(0); /* HELP */
209
  const char *s = svarlang_strid(0); /* HELP */
210
  unsigned char helpcol = screenw - strlen(s);
210
  unsigned short helpcol = screenw - strlen(s);
211
 
211
 
212
  /* fill status bar with background (without modflag as it is refreshed by ui_refresh) */
212
  /* fill status bar with background (without modflag as it is refreshed by ui_refresh) */
213
  mdr_cout_char_rep(screenh - 1, 1, ' ', SCHEME_STBAR1, screenw - 1);
213
  mdr_cout_char_rep(screenh - 1, 1, ' ', SCHEME_STBAR1, screenw - 1);
214
 
214
 
215
  /* filename */
215
  /* filename */
Line 263... Line 263...
263
 
263
 
264
  return(1);
264
  return(1);
265
}
265
}
266
 
266
 
267
 
267
 
268
static void ui_help(void) { /* 8706 -> 6277 */
268
static void ui_help(void) {
269
#define MAXLINLEN 39
269
#define MAXLINLEN 39
270
  unsigned short i, offset;
270
  unsigned short i, offset;
271
  offset = (screenw - MAXLINLEN) >> 1;
271
  offset = (screenw - MAXLINLEN) >> 1;
272
 
272
 
273
  for (i = 3; i < 25; i++) {
273
  for (i = 3; i < 25; i++) {
Line 499... Line 499...
499
 
499
 
500
/* a custom argv-parsing routine that looks directly inside the PSP, avoids the need
500
/* a custom argv-parsing routine that looks directly inside the PSP, avoids the need
501
 * of argc and argv, saves some 330 bytes of binary size */
501
 * of argc and argv, saves some 330 bytes of binary size */
502
static char *parseargv(void) {
502
static char *parseargv(void) {
503
  char *tail = (void *)0x81; /* THIS WORKS ONLY IN SMALL MEMORY MODEL */
503
  char *tail = (void *)0x81; /* THIS WORKS ONLY IN SMALL MEMORY MODEL */
504
  unsigned char count = 0;
504
  unsigned short count = 0;
505
  char *argv[4];
505
  char *argv[4];
506
 
506
 
507
  while (count < 4) {
507
  while (count < 4) {
508
    /* jump to nearest arg */
508
    /* jump to nearest arg */
509
    while (*tail == ' ') {
509
    while (*tail == ' ') {
Line 695... Line 695...
695
    line_free(victim);
695
    line_free(victim);
696
  }
696
  }
697
 
697
 
698
  /* zero out the struct */
698
  /* zero out the struct */
699
  bzero(db, sizeof(struct file));
699
  bzero(db, sizeof(struct file));
700
 
-
 
701
  /* add a single empty line and rewind */
-
 
702
  line_add(db, NULL, 0);
-
 
703
  db_rewind(db);
-
 
704
}
700
}
705
 
701
 
706
 
702
 
707
/* recompute db->curline by counting nodes in linked list */
703
/* recompute db->curline by counting nodes in linked list */
708
static void recompute_curline(struct file *db) {
704
static void recompute_curline(struct file *db) {
Line 874... Line 870...
874
    } else if ((k >= 0x20) && (k <= 0xff)) { /* "normal" character */
870
    } else if ((k >= 0x20) && (k <= 0xff)) { /* "normal" character */
875
      char c = k;
871
      char c = k;
876
      insert_in_line(db, &c, 1);
872
      insert_in_line(db, &c, 1);
877
 
873
 
878
    } else if (k == 0x009) { /* TAB */
874
    } else if (k == 0x009) { /* TAB */
879
      const char *tab = "        ";
-
 
880
      insert_in_line(db, tab, 8);
875
      insert_in_line(db, "        ", 8);
881
 
876
 
882
    } else if (k == 0x13b) { /* F1 */
877
    } else if (k == 0x13b) { /* F1 */
883
      ui_help();
878
      ui_help();
884
      uidirty.from = 0;
879
      uidirty.from = 0;
885
      uidirty.to = 0xff;
880
      uidirty.to = 0xff;
886
 
881
 
887
    } else if (k == 0x13c) { /* F2 (new file) */
882
    } else if (k == 0x13c) { /* F2 (new file) */
888
      if (ui_confirm_if_unsaved(db) == 0) clear_file(db);
883
      if (ui_confirm_if_unsaved(db) == 0) {
-
 
884
        clear_file(db);
-
 
885
        /* add a single empty line */
-
 
886
        line_add(db, NULL, 0);
-
 
887
      }
889
      uidirty.from = 0;
888
      uidirty.from = 0;
890
      uidirty.to = 0xff;
889
      uidirty.to = 0xff;
891
      uidirty.statusbar = 1;
890
      uidirty.statusbar = 1;
892
 
891
 
893
    } else if (k == 0x13d) { /* F3 (load file) */
892
    } else if (k == 0x13d) { /* F3 (load file) */