Subversion Repositories SvarDOS

Rev

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

Rev 1426 Rev 1427
Line 51... Line 51...
51
                     SCHEME_STBAR3 = 0x70, /* query */
51
                     SCHEME_STBAR3 = 0x70, /* query */
52
                     SCHEME_SCROLL = 0x70,
52
                     SCHEME_SCROLL = 0x70,
53
                     SCHEME_MSG    = 0x70,
53
                     SCHEME_MSG    = 0x70,
54
                     SCHEME_ERR    = 0x70;
54
                     SCHEME_ERR    = 0x70;
55
 
55
 
56
static unsigned char screenw, screenh;
56
static unsigned char screenw, screenh, screenlastrow, screenlastcol;
57
static unsigned char glob_monomode, glob_tablessmode;
57
static unsigned char glob_monomode, glob_tablessmode;
58
 
58
 
59
static struct {
59
static struct {
60
    unsigned char from;
60
    unsigned char from;
61
    unsigned char to;
61
    unsigned char to;
Line 158... Line 158...
158
  int k;
158
  int k;
159
 
159
 
160
  if (maxlen == 0) return;
160
  if (maxlen == 0) return;
161
  maxlen--; /* make room for the nul terminator */
161
  maxlen--; /* make room for the nul terminator */
162
 
162
 
163
  y = screenh - 1;
163
  y = screenlastrow;
164
 
164
 
165
  /* print query string */
165
  /* print query string */
166
  x = mdr_cout_str(y, 0, query, SCHEME_STBAR3, 40);
166
  x = mdr_cout_str(y, 0, query, SCHEME_STBAR3, 40);
167
  mdr_cout_char_rep(y, x++, ' ', SCHEME_STBAR3, screenw - x);
167
  mdr_cout_char_rep(y, x++, ' ', SCHEME_STBAR3, screenw - x);
168
 
168
 
Line 194... Line 194...
194
}
194
}
195
 
195
 
196
 
196
 
197
/* append a nul-terminated string to line at cursor position */
197
/* append a nul-terminated string to line at cursor position */
198
static int line_append(struct file *f, const char far *buf, unsigned short len) {
198
static int line_append(struct file *f, const char far *buf, unsigned short len) {
199
  if (sizeof(struct line) + f->cursor->len + len < len) return(-1); /* overflow check */
199
  if (sizeof(struct line) + f->cursor->len + len < len) goto ERR; /* overflow check */
200
  if (curline_resize(f, f->cursor->len + len) != 0) return(-1);
200
  if (curline_resize(f, f->cursor->len + len) != 0) goto ERR;
-
 
201
 
201
  _fmemmove(f->cursor->payload + f->cursor->len, buf, len);
202
  _fmemmove(f->cursor->payload + f->cursor->len, buf, len);
202
  f->cursor->len += len;
203
  f->cursor->len += len;
203
 
204
 
204
  return(0);
205
  return(0);
-
 
206
  ERR:
-
 
207
  return(-1);
205
}
208
}
206
 
209
 
207
 
210
 
208
static void db_rewind(struct file *db) {
211
static void db_rewind(struct file *db) {
209
  if (db->cursor == NULL) return;
212
  if (db->cursor == NULL) return;
Line 224... Line 227...
224
      slot[1] = '1';
227
      slot[1] = '1';
225
    } else {
228
    } else {
226
      slotnum++;
229
      slotnum++;
227
      slot[2] += slotnum;
230
      slot[2] += slotnum;
228
    }
231
    }
229
    mdr_cout_str(screenh - 1, 0, slot, SCHEME_STBAR2, 3);
232
    mdr_cout_str(screenlastrow, 0, slot, SCHEME_STBAR2, 3);
230
  }
233
  }
231
 
234
 
232
  /* fill rest of status bar with background */
235
  /* fill rest of status bar with background */
233
  mdr_cout_char_rep(screenh - 1, 3, ' ', SCHEME_STBAR1, helpcol - 3);
236
  mdr_cout_char_rep(screenlastrow, 3, ' ', SCHEME_STBAR1, helpcol - 3);
234
 
237
 
235
  /* filename and modflag */
238
  /* filename and modflag */
236
  {
239
  {
237
    const char *fn;
240
    const char *fn;
238
    unsigned short x;
241
    unsigned short x;
Line 242... Line 245...
242
      /* display filename up to maxfnlen chars */
245
      /* display filename up to maxfnlen chars */
243
      fn = db->fname;
246
      fn = db->fname;
244
      x = strlen(fn);
247
      x = strlen(fn);
245
      if (x > maxfnlen) fn += x - maxfnlen;
248
      if (x > maxfnlen) fn += x - maxfnlen;
246
    }
249
    }
247
    x = mdr_cout_str(screenh - 1, 4, fn, SCHEME_STBAR1, maxfnlen);
250
    x = mdr_cout_str(screenlastrow, 4, fn, SCHEME_STBAR1, maxfnlen);
248
    if (db->modflag) mdr_cout_char(screenh - 1, 5 + x, '!', SCHEME_STBAR2);
251
    if (db->modflag) mdr_cout_char(screenlastrow, 5 + x, '!', SCHEME_STBAR2);
249
  }
252
  }
250
 
253
 
251
  /* eol type */
254
  /* eol type */
252
  {
255
  {
253
    const char *eoltype = "CRLF";
256
    const char *eoltype = "CRLF";
254
    if (db->lfonly) eoltype += 2;
257
    if (db->lfonly) eoltype += 2;
255
    mdr_cout_str(screenh - 1, helpcol - 6, eoltype, SCHEME_STBAR1, 5);
258
    mdr_cout_str(screenlastrow, helpcol - 6, eoltype, SCHEME_STBAR1, 5);
256
  }
259
  }
257
 
260
 
258
  mdr_cout_str(screenh - 1, helpcol, s, SCHEME_STBAR2, 40);
261
  mdr_cout_str(screenlastrow, helpcol, s, SCHEME_STBAR2, 40);
259
}
262
}
260
 
263
 
261
 
264
 
262
static void ui_msg(const char *msg1, const char *msg2, unsigned char attr) {
265
static void ui_msg(const char *msg1, const char *msg2, unsigned char attr) {
263
  unsigned short x, y, msglen, i;
266
  unsigned short x, y, msglen, i;
Line 327... Line 330...
327
    if (db->xoffset < l->len) {
330
    if (db->xoffset < l->len) {
328
      unsigned char i, limit;
331
      unsigned char i, limit;
329
      if (l->len - db->xoffset < screenw) {
332
      if (l->len - db->xoffset < screenw) {
330
        limit = l->len;
333
        limit = l->len;
331
      } else {
334
      } else {
332
        limit = db->xoffset + screenw - 1;
335
        limit = db->xoffset + screenlastcol;
333
      }
336
      }
334
      for (i = db->xoffset; i < limit; i++) mdr_cout_char(y, x++, l->payload[i], SCHEME_TEXT);
337
      for (i = db->xoffset; i < limit; i++) mdr_cout_char(y, x++, l->payload[i], SCHEME_TEXT);
335
    }
338
    }
336
 
339
 
337
    /* write empty spaces until end of line */
340
    /* write empty spaces until end of line */
338
    if (x < screenw - 1) mdr_cout_char_rep(y, x, ' ', SCHEME_TEXT, screenw - 1 - x);
341
    if (x < screenlastcol) mdr_cout_char_rep(y, x, ' ', SCHEME_TEXT, screenlastcol - x);
339
 
342
 
340
#ifdef DBG_REFRESH
343
#ifdef DBG_REFRESH
341
    mdr_cout_char(y, 0, m, SCHEME_STBAR1);
344
    mdr_cout_char(y, 0, m, SCHEME_STBAR1);
342
#endif
345
#endif
343
 
346
 
344
    if (y == screenh - 2) break;
347
    if (y == screenh - 2) break;
345
  }
348
  }
346
 
349
 
347
  /* fill all lines below if empty (and they need to be redrawn) */
350
  /* fill all lines below if empty (and they need to be redrawn) */
348
  if (l == NULL) {
351
  if (l == NULL) {
349
    while ((y < screenh - 1) && (y < uidirty.to)) {
352
    while ((y < screenlastrow) && (y < uidirty.to)) {
350
      mdr_cout_char_rep(y++, 0, ' ', SCHEME_TEXT, screenw - 1);
353
      mdr_cout_char_rep(y++, 0, ' ', SCHEME_TEXT, screenlastcol);
351
    }
354
    }
352
  }
355
  }
353
 
356
 
354
  /* scroll bar */
357
  /* scroll bar */
355
  for (y = 0; y < (screenh - 1); y++) {
358
  for (y = 0; y < screenlastrow; y++) {
356
    mdr_cout_char(y, screenw - 1, SCROLL_CURSOR, SCHEME_SCROLL);
359
    mdr_cout_char(y, screenlastcol, SCROLL_CURSOR, SCHEME_SCROLL);
357
  }
360
  }
358
 
361
 
359
  /* scroll cursor */
362
  /* scroll cursor */
360
  if (db->totlines >= screenh) {
363
  if (db->totlines >= screenh) {
361
    unsigned short topline = db->curline - db->cursorposy;
364
    unsigned short topline = db->curline - db->cursorposy;
362
    unsigned short col;
365
    unsigned short col;
363
    unsigned short totlines = db->totlines - screenh + 1;
366
    unsigned short totlines = db->totlines - screenh + 1;
364
    if (db->totlines - screenh > screenh) {
367
    if (db->totlines - screenh > screenh) {
365
      col = topline / (totlines / (screenh - 1));
368
      col = topline / (totlines / screenlastrow);
366
    } else {
369
    } else {
367
      col = topline * (screenh - 1) / totlines;
370
      col = topline * screenlastrow / totlines;
368
    }
371
    }
369
    if (col >= screenh - 1) col = screenh - 2;
372
    if (col >= screenlastrow) col = screenh - 2;
370
    mdr_cout_char(col, screenw - 1, ' ', SCHEME_SCROLL);
373
    mdr_cout_char(col, screenlastcol, ' ', SCHEME_SCROLL);
371
  }
374
  }
372
 
375
 
373
  /* clear out the dirty flag */
376
  /* clear out the dirty flag */
374
  uidirty.from = 0xff;
377
  uidirty.from = 0xff;
375
}
378
}
Line 410... Line 413...
410
    db->xoffset = db->cursor->len - 1;
413
    db->xoffset = db->cursor->len - 1;
411
    uidirty.from = 0;
414
    uidirty.from = 0;
412
    uidirty.to = 0xff;
415
    uidirty.to = 0xff;
413
  }
416
  }
414
 
417
 
415
  if (db->xoffset + screenw - 1 <= db->cursor->len) {
418
  if (db->xoffset + screenlastcol <= db->cursor->len) {
416
    db->xoffset = db->cursor->len - screenw + 2;
419
    db->xoffset = db->cursor->len - screenw + 2;
417
    uidirty.from = 0;
420
    uidirty.from = 0;
418
    uidirty.to = 0xff;
421
    uidirty.to = 0xff;
419
  }
422
  }
420
  db->cursorposx = db->cursor->len - db->xoffset;
423
  db->cursorposx = db->cursor->len - db->xoffset;
Line 941... Line 944...
941
    SCHEME_STBAR3 = 0x3f;
944
    SCHEME_STBAR3 = 0x3f;
942
    SCHEME_SCROLL = 0x70;
945
    SCHEME_SCROLL = 0x70;
943
    SCHEME_MSG = 0x6f;
946
    SCHEME_MSG = 0x6f;
944
    SCHEME_ERR = 0x4f;
947
    SCHEME_ERR = 0x4f;
945
  }
948
  }
-
 
949
  screenlastrow = screenh - 1;
-
 
950
  screenlastcol = screenw - 1;
946
 
951
 
947
  /* instruct DOS to stop detecting CTRL+C because user needs it for
952
  /* instruct DOS to stop detecting CTRL+C because user needs it for
948
   * copy/paste operations. also remember the original status of the BREAK
953
   * copy/paste operations. also remember the original status of the BREAK
949
   * flag so I can restore it as it was before quitting. */
954
   * flag so I can restore it as it was before quitting. */
950
  original_breakflag = mdr_dos_ctrlc_disable();
955
  original_breakflag = mdr_dos_ctrlc_disable();
Line 1137... Line 1142...
1137
      unsigned short off = db->xoffset + db->cursorposx;
1142
      unsigned short off = db->xoffset + db->cursorposx;
1138
      /* add a new line */
1143
      /* add a new line */
1139
      if (line_add(db, db->cursor->payload + off, db->cursor->len - off) == 0) {
1144
      if (line_add(db, db->cursor->payload + off, db->cursor->len - off) == 0) {
1140
        db->modflag = 1;
1145
        db->modflag = 1;
1141
        db->cursor = db->cursor->prev; /* back to original line */
1146
        db->cursor = db->cursor->prev; /* back to original line */
-
 
1147
        db->curline -= 1;
1142
        /* trim the line above */
1148
        /* trim the line above */
1143
        db->cursor->len = off;
1149
        db->cursor->len = off;
1144
        /* move cursor to the (new) line below */
1150
        /* move cursor to the (new) line below */
1145
        db->curline -= 1;
-
 
1146
        uidirty.from = db->cursorposy;
1151
        uidirty.from = db->cursorposy;
1147
        uidirty.to = 0xff;
1152
        uidirty.to = 0xff;
1148
        cursor_down(db);
1153
        cursor_down(db);
1149
        cursor_home(db);
1154
        cursor_home(db);
1150
      } else {
1155
      } else {
Line 1212... Line 1217...
1212
      clipboard = line_calloc(db->cursor->len);
1217
      clipboard = line_calloc(db->cursor->len);
1213
      if (clipboard == NULL) {
1218
      if (clipboard == NULL) {
1214
        ui_msg(svarlang_str(0, 10), NULL, SCHEME_ERR); /* ERROR */
1219
        ui_msg(svarlang_str(0, 10), NULL, SCHEME_ERR); /* ERROR */
1215
        mdr_bios_tickswait(18); /* 1s */
1220
        mdr_bios_tickswait(18); /* 1s */
1216
      } else {
1221
      } else {
1217
        mdr_cout_char_rep(db->cursorposy, 0, ' ', ((SCHEME_TEXT >> 4) | (SCHEME_TEXT << 4)) & 0xff, screenw - 1);
1222
        mdr_cout_char_rep(db->cursorposy, 0, ' ', ((SCHEME_TEXT >> 4) | (SCHEME_TEXT << 4)) & 0xff, screenlastcol);
1218
        uidirty.from = db->cursorposy;
1223
        uidirty.from = db->cursorposy;
1219
        uidirty.to = db->cursorposy;
1224
        uidirty.to = db->cursorposy;
1220
        if (db->cursor->len != 0) {
1225
        if (db->cursor->len != 0) {
1221
          _fmemmove(clipboard->payload, db->cursor->payload, db->cursor->len);
1226
          _fmemmove(clipboard->payload, db->cursor->payload, db->cursor->len);
1222
          clipboard->len = db->cursor->len;
1227
          clipboard->len = db->cursor->len;