Subversion Repositories SvarDOS

Rev

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

Rev 1450 Rev 1453
Line 32... Line 32...
32
#include "mdr\dos.h"
32
#include "mdr\dos.h"
33
 
33
 
34
#include "svarlang\svarlang.h"
34
#include "svarlang\svarlang.h"
35
 
35
 
36
 
36
 
37
#define PVER "2023.1"
37
#define PVER "2023.2"
38
#define PDATE "2023"
38
#define PDATE "2023"
39
 
39
 
40
/*****************************************************************************
40
/*****************************************************************************
41
 * global variables and definitions                                          *
41
 * global variables and definitions                                          *
42
 *****************************************************************************/
42
 *****************************************************************************/
Line 743... Line 743...
743
 
743
 
744
  return(0);
744
  return(0);
745
}
745
}
746
 
746
 
747
 
747
 
748
static int savefile(const struct file *db, const char *newfname) {
748
static int savefile(const struct file *db, const char *saveas) {
749
  int fd;
749
  int fd = 0;
750
  const struct line far *l;
750
  const struct line far *l;
751
  unsigned int bytes;
751
  unsigned int bytes;
752
  unsigned char eollen;
752
  unsigned char eollen;
753
  unsigned char eolbuf[2];
753
  unsigned char eolbuf[2];
754
  int errflag = 0;
754
  int errflag = 0;
755
 
755
 
756
  /* either create a new file if newfname provided, or... */
756
  /* if filename not overloaded then use the fname in db */
-
 
757
  if (saveas == NULL) saveas = db->fname;
-
 
758
 
-
 
759
  _asm {
757
  if (newfname) {
760
    push ax
-
 
761
    push cx
-
 
762
    push dx
-
 
763
 
758
    if (_dos_creatnew(newfname, _A_NORMAL, &fd) != 0) return(-1);
764
    mov ah, 0x3C    /* create or truncate file */
759
  } else { /* ...open db->fname */
765
    xor cx, cx      /* file attributes */
760
    if (_dos_open(db->fname, O_WRONLY, &fd) != 0) return(-1);
766
    mov dx, saveas  /* works only in SMALL/TINY mode */
-
 
767
    int 0x21
-
 
768
    jnc DONE
-
 
769
    mov errflag, ax
-
 
770
    DONE:
-
 
771
    mov fd, ax
-
 
772
 
-
 
773
    pop dx
-
 
774
    pop cx
-
 
775
    pop ax
761
  }
776
  }
762
 
777
 
-
 
778
  if (errflag != 0) return(-1);
-
 
779
 
763
  l = db->cursor;
780
  l = db->cursor;
764
  while (l->prev) l = l->prev;
781
  while (l->prev) l = l->prev;
765
 
782
 
766
  /* preset line terminators */
783
  /* preset line terminators */
767
  if (db->lfonly) {
784
  if (db->lfonly) {
Line 782... Line 799...
782
    }
799
    }
783
    errflag |= _dos_write(fd, eolbuf, eollen, &bytes);
800
    errflag |= _dos_write(fd, eolbuf, eollen, &bytes);
784
    l = l->next;
801
    l = l->next;
785
  }
802
  }
786
 
803
 
787
  /* emit a 0-bytes write - this means "truncate file at current position" */
-
 
788
  errflag |= _dos_write(fd, NULL, 0, &bytes);
-
 
789
 
-
 
790
  errflag |= _dos_close(fd);
804
  errflag |= _dos_close(fd);
791
 
805
 
792
  return(errflag);
806
  return(errflag);
793
}
807
}
794
 
808