Subversion Repositories SvarDOS

Rev

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

Rev 1538 Rev 1539
Line 220... Line 220...
220
  while (db->cursor->prev) db->cursor = db->cursor->prev;
220
  while (db->cursor->prev) db->cursor = db->cursor->prev;
221
  db->curline = 0;
221
  db->curline = 0;
222
}
222
}
223
 
223
 
224
 
224
 
-
 
225
static int savefile(const struct file *db, const char *saveas) {
-
 
226
  int fd = 0;
-
 
227
  const struct line far *l;
-
 
228
  unsigned int bytes;
-
 
229
  unsigned char eollen = 2;
-
 
230
  const unsigned char *eolbuf = "\r\n";
-
 
231
  int errflag = 0;
-
 
232
 
-
 
233
  /* if filename not overloaded then use the fname in db */
-
 
234
  if (saveas == NULL) saveas = db->fname;
-
 
235
 
-
 
236
  _asm {
-
 
237
    push ax
-
 
238
    push cx
-
 
239
    push dx
-
 
240
 
-
 
241
    mov ah, 0x3C    /* create or truncate file */
-
 
242
    xor cx, cx      /* file attributes */
-
 
243
    mov dx, saveas  /* works only in SMALL/TINY mode */
-
 
244
    int 0x21
-
 
245
    jnc DONE
-
 
246
    mov errflag, ax
-
 
247
    DONE:
-
 
248
    mov fd, ax
-
 
249
 
-
 
250
    pop dx
-
 
251
    pop cx
-
 
252
    pop ax
-
 
253
  }
-
 
254
 
-
 
255
  if (errflag != 0) return(-1);
-
 
256
 
-
 
257
  l = db->cursor;
-
 
258
  while (l->prev) l = l->prev;
-
 
259
 
-
 
260
  /* preset line terminators */
-
 
261
  if (db->lfonly) {
-
 
262
    eolbuf++;
-
 
263
    eollen--;
-
 
264
  }
-
 
265
 
-
 
266
  while (l) {
-
 
267
    /* do not write the last empty line, it is only useful for edition */
-
 
268
    if (l->len != 0) {
-
 
269
      errflag |= _dos_write(fd, l->payload, l->len, &bytes);
-
 
270
    } else if (l->next == NULL) {
-
 
271
      break;
-
 
272
    }
-
 
273
    errflag |= _dos_write(fd, eolbuf, eollen, &bytes);
-
 
274
    l = l->next;
-
 
275
  }
-
 
276
 
-
 
277
  errflag |= _dos_close(fd);
-
 
278
 
-
 
279
  return(errflag);
-
 
280
}
-
 
281
 
-
 
282
 
225
static void ui_statusbar(const struct file *db, unsigned char slotnum) {
283
static void ui_statusbar(const struct file *db, unsigned char slotnum) {
226
  const char *s = svarlang_strid(0); /* ESC=MENU */
284
  const char *s = svarlang_strid(0); /* ESC=MENU */
227
  unsigned short helpcol = screenw - strlen(s);
285
  unsigned short helpcol = screenw - strlen(s);
228
  unsigned short col;
286
  unsigned short col;
229
 
287
 
Line 301... Line 359...
301
    i = strlen(msg2);
359
    i = strlen(msg2);
302
    if (i > msglen) msglen = i;
360
    if (i > msglen) msglen = i;
303
  }
361
  }
304
 
362
 
305
  y = (screenh - 6) >> 1;
363
  y = (screenh - 6) >> 1;
306
  x = (screenw - msglen - 4) >> 1;
364
  x = (screenw - msglen - 3) >> 1;
307
  for (i = y+2+msg2flag; i >= y; i--) mdr_cout_char_rep(i, x, ' ', attr, msglen + 2);
365
  for (i = y+2+msg2flag; i >= y; i--) mdr_cout_char_rep(i, x, ' ', attr, msglen + 2);
308
  x++;
366
  x++;
309
 
367
 
310
  mdr_cout_str(y+1, x, msg1, attr, msglen);
368
  mdr_cout_str(y+1, x, msg1, attr, msglen);
311
  if (msg2) mdr_cout_str(y+2, x, msg2, attr, msglen);
369
  if (msg2) mdr_cout_str(y+2, x, msg2, attr, msglen);
Line 313... Line 371...
313
  if (uidirty.from > y) uidirty.from = y;
371
  if (uidirty.from > y) uidirty.from = y;
314
  if (uidirty.to < y+4) uidirty.to = y+4;
372
  if (uidirty.to < y+4) uidirty.to = y+4;
315
}
373
}
316
 
374
 
317
 
375
 
-
 
376
/* returns 0 if operation may proceed, non-zero to cancel */
318
static unsigned char ui_confirm_if_unsaved(const struct file *db) {
377
static unsigned char ui_confirm_if_unsaved(const struct file *db) {
319
  unsigned char r = 0;
378
  int k;
-
 
379
 
320
  if (db->modflag == 0) return(0);
380
  if (db->modflag == 0) return(0);
321
 
381
 
322
  mdr_cout_cursor_hide();
382
  mdr_cout_cursor_hide();
323
 
383
 
324
  /* if file has been modified then ask for confirmation */
384
  /* if file has been modified then ask for confirmation:
-
 
385
   * ENTER        : agree to data loss
-
 
386
   * SPACE        : SAVE file before quit (only if valid filename present)
-
 
387
   * anything else: ABORT */
325
  ui_msg(svarlang_str(0,4), svarlang_str(0,5), SCHEME_MSG);
388
  ui_msg(svarlang_str(0,4), svarlang_str(0,5), SCHEME_MSG);
326
  if (mdr_dos_getkey2() != '\r') r = 1;
-
 
327
 
389
 
-
 
390
  k = mdr_dos_getkey2();
328
  mdr_cout_cursor_show();
391
  mdr_cout_cursor_show();
329
 
392
 
-
 
393
  /* ENTER = agree to loose unsaved data */
-
 
394
  if (k == '\r') return(0);
-
 
395
 
-
 
396
  /* SPACE = save file and continue */
-
 
397
  if ((k == ' ') && (db->fname[0] != 0) && (savefile(db, NULL) == 0)) return(0);
-
 
398
 
-
 
399
  /* any other key = cancel operation */
330
  return(r);
400
  return(1);
331
}
401
}
332
 
402
 
333
 
403
 
334
static void ui_refresh(const struct file *db) {
404
static void ui_refresh(const struct file *db) {
335
  unsigned char x;
405
  unsigned char x;
Line 757... Line 827...
757
 
827
 
758
  return(0);
828
  return(0);
759
}
829
}
760
 
830
 
761
 
831
 
762
static int savefile(const struct file *db, const char *saveas) {
-
 
763
  int fd = 0;
-
 
764
  const struct line far *l;
-
 
765
  unsigned int bytes;
-
 
766
  unsigned char eollen = 2;
-
 
767
  const unsigned char *eolbuf = "\r\n";
-
 
768
  int errflag = 0;
-
 
769
 
-
 
770
  /* if filename not overloaded then use the fname in db */
-
 
771
  if (saveas == NULL) saveas = db->fname;
-
 
772
 
-
 
773
  _asm {
-
 
774
    push ax
-
 
775
    push cx
-
 
776
    push dx
-
 
777
 
-
 
778
    mov ah, 0x3C    /* create or truncate file */
-
 
779
    xor cx, cx      /* file attributes */
-
 
780
    mov dx, saveas  /* works only in SMALL/TINY mode */
-
 
781
    int 0x21
-
 
782
    jnc DONE
-
 
783
    mov errflag, ax
-
 
784
    DONE:
-
 
785
    mov fd, ax
-
 
786
 
-
 
787
    pop dx
-
 
788
    pop cx
-
 
789
    pop ax
-
 
790
  }
-
 
791
 
-
 
792
  if (errflag != 0) return(-1);
-
 
793
 
-
 
794
  l = db->cursor;
-
 
795
  while (l->prev) l = l->prev;
-
 
796
 
-
 
797
  /* preset line terminators */
-
 
798
  if (db->lfonly) {
-
 
799
    eolbuf++;
-
 
800
    eollen--;
-
 
801
  }
-
 
802
 
-
 
803
  while (l) {
-
 
804
    /* do not write the last empty line, it is only useful for edition */
-
 
805
    if (l->len != 0) {
-
 
806
      errflag |= _dos_write(fd, l->payload, l->len, &bytes);
-
 
807
    } else if (l->next == NULL) {
-
 
808
      break;
-
 
809
    }
-
 
810
    errflag |= _dos_write(fd, eolbuf, eollen, &bytes);
-
 
811
    l = l->next;
-
 
812
  }
-
 
813
 
-
 
814
  errflag |= _dos_close(fd);
-
 
815
 
-
 
816
  return(errflag);
-
 
817
}
-
 
818
 
-
 
819
 
-
 
820
static void insert_in_line(struct file *db, const char *databuf, unsigned short len) {
832
static void insert_in_line(struct file *db, const char *databuf, unsigned short len) {
821
  if (curline_resize(db, db->cursor->len + len) == 0) {
833
  if (curline_resize(db, db->cursor->len + len) == 0) {
822
    unsigned short off = db->xoffset + db->cursorposx;
834
    unsigned short off = db->xoffset + db->cursorposx;
823
    db->modflag = 1;
835
    db->modflag = 1;
824
    _fmemmove(db->cursor->payload + off + len, db->cursor->payload + off, db->cursor->len - off + 1);
836
    _fmemmove(db->cursor->payload + off + len, db->cursor->payload + off, db->cursor->len - off + 1);