Subversion Repositories SvarDOS

Rev

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

Rev 1555 Rev 1556
Line 21... Line 21...
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23
 * IN THE SOFTWARE.
23
 * IN THE SOFTWARE.
24
 */
24
 */
25
 
25
 
26
#include <dos.h>      /* _dos_open(), _dos_read(), _dos_close(), ... */
-
 
27
#include <fcntl.h>    /* O_RDONLY, O_WRONLY */
26
#include <i86.h> /* MK_FP() */
-
 
27
 
28
#include <string.h>
28
#include "libc.h"
29
#include <strings.h>
-
 
30
 
29
 
31
#include "mdr\bios.h"
30
#include "mdr\bios.h"
32
#include "mdr\cout.h"
31
#include "mdr\cout.h"
33
#include "mdr\dos.h"
32
#include "mdr\dos.h"
34
 
33
 
Line 94... Line 93...
94
 * functions                                                                 *
93
 * functions                                                                 *
95
 *****************************************************************************/
94
 *****************************************************************************/
96
 
95
 
97
static struct line far *line_calloc(unsigned short siz) {
96
static struct line far *line_calloc(unsigned short siz) {
98
  struct line far *res;
97
  struct line far *res;
99
  unsigned int seg;
98
  unsigned short seg;
100
 
-
 
101
  if (_dos_allocmem((sizeof(struct line) + siz + 15) / 16, &seg) != 0) return(NULL);
-
 
102
 
99
 
-
 
100
  seg = mdr_dos_allocmem((sizeof(struct line) + siz + 15) / 16);
-
 
101
  if (seg == 0) return(NULL);
103
  res = MK_FP(seg, 0);
102
  res = MK_FP(seg, 0);
104
  res->len = 0;
103
  res->len = 0;
105
  res->next = NULL;
104
  res->next = NULL;
106
  res->prev = NULL;
105
  res->prev = NULL;
107
 
106
 
Line 113... Line 112...
113
  _dos_freemem(FP_SEG(ptr));
112
  _dos_freemem(FP_SEG(ptr));
114
}
113
}
115
 
114
 
116
 
115
 
117
static int curline_resize(struct file *db, unsigned short newsiz) {
116
static int curline_resize(struct file *db, unsigned short newsiz) {
118
  unsigned int maxavail;
117
  unsigned short maxavail;
119
  struct line far *newptr;
118
  struct line far *newptr;
120
 
119
 
121
  /* try resizing the block (much faster) */
120
  /* try resizing the block (much faster) */
122
  if (_dos_setblock((sizeof(struct line) + newsiz + 15) / 16, FP_SEG(db->cursor), &maxavail) == 0) return(0);
121
  if (mdr_dos_resizeblock((sizeof(struct line) + newsiz + 15) / 16, FP_SEG(db->cursor), &maxavail) == 0) return(0);
123
 
122
 
124
  /* create a new block and copy data over */
123
  /* create a new block and copy data over */
125
  newptr = line_calloc(newsiz);
124
  newptr = line_calloc(newsiz);
126
  if (newptr == NULL) return(-1);
125
  if (newptr == NULL) return(-1);
127
  _fmemmove(newptr, db->cursor, sizeof(struct line) + db->cursor->len);
126
  _fmemmove(newptr, db->cursor, sizeof(struct line) + db->cursor->len);
Line 226... Line 225...
226
/* saves db file, resets db->modflag on success and overwrites the filename
225
/* saves db file, resets db->modflag on success and overwrites the filename
227
 * field if saveas is not NULL */
226
 * field if saveas is not NULL */
228
static int savefile(struct file *db, const char *saveas) {
227
static int savefile(struct file *db, const char *saveas) {
229
  int fd = 0;
228
  int fd = 0;
230
  const struct line far *l;
229
  const struct line far *l;
231
  unsigned int bytes;
230
  unsigned short bytes;
232
  unsigned char eollen = 2;
231
  unsigned char eollen = 2;
233
  const unsigned char *eolbuf = "\r\n";
232
  const unsigned char *eolbuf = "\r\n";
234
  int errflag = 0;
233
  int errflag = 0;
235
 
234
 
236
  /* if filename not overloaded then use the fname in db */
235
  /* if filename not overloaded then use the fname in db */
Line 267... Line 266...
267
  }
266
  }
268
 
267
 
269
  while (l) {
268
  while (l) {
270
    /* do not write the last empty line, it is only useful for edition */
269
    /* do not write the last empty line, it is only useful for edition */
271
    if (l->len != 0) {
270
    if (l->len != 0) {
272
      errflag |= _dos_write(fd, l->payload, l->len, &bytes);
271
      errflag |= mdr_dos_write(fd, l->payload, l->len, &bytes);
273
    } else if (l->next == NULL) {
272
    } else if (l->next == NULL) {
274
      break;
273
      break;
275
    }
274
    }
276
    errflag |= _dos_write(fd, eolbuf, eollen, &bytes);
275
    errflag |= mdr_dos_write(fd, eolbuf, eollen, &bytes);
277
    l = l->next;
276
    l = l->next;
278
  }
277
  }
279
 
278
 
280
  errflag |= _dos_close(fd);
279
  errflag |= mdr_dos_fclose(fd);
281
 
280
 
282
  /* did it all work? */
281
  /* did it all work? */
283
  if (errflag == 0) {
282
  if (errflag == 0) {
284
    db->modflag = 0;
283
    db->modflag = 0;
285
    if (saveas != db->fname) mdr_dos_truename(db->fname, saveas);
284
    if (saveas != db->fname) mdr_dos_truename(db->fname, saveas);
Line 637... Line 636...
637
#define LOADFILE_FILENOTFOUND 2
636
#define LOADFILE_FILENOTFOUND 2
638
 
637
 
639
/* returns 0 on success, 1 on file not found, 2 on other error */
638
/* returns 0 on success, 1 on file not found, 2 on other error */
640
static unsigned char loadfile(struct file *db, const char *fname) {
639
static unsigned char loadfile(struct file *db, const char *fname) {
641
  char *buffptr;
640
  char *buffptr;
642
  unsigned int len, llen;
641
  unsigned short len, llen;
643
  int fd;
642
  unsigned short fd;
644
  unsigned char eolfound;
643
  unsigned char eolfound;
645
  unsigned char err = 0;
644
  unsigned char err = 0;
646
 
645
 
647
  /* free the entire linked list of lines */
646
  /* free the entire linked list of lines */
648
  db_rewind(db);
647
  db_rewind(db);
Line 666... Line 665...
666
  if (fname == NULL) goto SKIPLOADING;
665
  if (fname == NULL) goto SKIPLOADING;
667
 
666
 
668
  /* make the filename canonical (DOS 3+ only, on earlier versions it just copies the filename) */
667
  /* make the filename canonical (DOS 3+ only, on earlier versions it just copies the filename) */
669
  mdr_dos_truename(db->fname, fname);
668
  mdr_dos_truename(db->fname, fname);
670
 
669
 
671
  err = _dos_open(fname, O_RDONLY, &fd);
670
  err = mdr_dos_fopen(fname, &fd);
672
  if (err != 0) goto SKIPLOADING;
671
  if (err != 0) goto SKIPLOADING;
673
 
672
 
674
  db->lfonly = 1;
673
  db->lfonly = 1;
675
 
674
 
676
  for (eolfound = 0;;) {
675
  for (eolfound = 0;;) {
677
    unsigned short consumedbytes;
676
    unsigned short consumedbytes;
678
 
677
 
679
    if ((_dos_read(fd, buff, sizeof(buff), &len) != 0) || (len == 0)) break;
678
    if ((mdr_dos_read(fd, buff, sizeof(buff), &len) != 0) || (len == 0)) break;
680
    buffptr = buff;
679
    buffptr = buff;
681
 
680
 
682
    FINDLINE:
681
    FINDLINE:
683
 
682
 
684
    /* look for nearest \n (also expand tabs) */
683
    /* look for nearest \n (also expand tabs) */
Line 738... Line 737...
738
      goto FINDLINE;
737
      goto FINDLINE;
739
    }
738
    }
740
 
739
 
741
  }
740
  }
742
 
741
 
743
  _dos_close(fd);
742
  mdr_dos_fclose(fd);
744
 
743
 
745
  SKIPLOADING:
744
  SKIPLOADING:
746
 
745
 
747
  /* rewind cursor to top of file because it has been used by line_add() */
746
  /* rewind cursor to top of file because it has been used by line_add() */
748
  db_rewind(db);
747
  db_rewind(db);
749
 
748
 
750
  return(err);
749
  return(err);
751
 
750
 
752
  IOERR:
751
  IOERR:
753
  _dos_close(fd);
752
  mdr_dos_fclose(fd);
754
  return(1);
753
  return(1);
755
}
754
}
756
 
755
 
757
 
756
 
758
/* a custom argv-parsing routine that looks directly inside the PSP, avoids the need
757
/* a custom argv-parsing routine that looks directly inside the PSP, avoids the need
Line 969... Line 968...
969
  static struct file dbarr[10];
968
  static struct file dbarr[10];
970
  struct file *db = dbarr; /* visible file is the first slot by default */
969
  struct file *db = dbarr; /* visible file is the first slot by default */
971
  static struct line far *clipboard;
970
  static struct line far *clipboard;
972
  static unsigned char original_breakflag;
971
  static unsigned char original_breakflag;
973
 
972
 
-
 
973
  mdr_coutraw_puts("glob_monomode:");
-
 
974
  mdr_coutraw_char('0' + glob_monomode);
-
 
975
  mdr_coutraw_crlf();
-
 
976
 
-
 
977
  mdr_coutraw_puts("original_breakflag:");
-
 
978
  mdr_coutraw_char('0' + original_breakflag);
-
 
979
  mdr_coutraw_crlf();
-
 
980
 
974
  { /* load NLS resource */
981
  { /* load NLS resource */
975
    unsigned short i = 0;
982
    unsigned short i = 0;
976
    const char far *selfptr;
983
    const char far *selfptr;
977
    char lang[8];
984
    char lang[8];
978
    selfptr = mdr_dos_selfexe();
985
    selfptr = mdr_dos_selfexe();
Line 1006... Line 1013...
1006
    SCHEME_STBAR2 = 0x78;
1013
    SCHEME_STBAR2 = 0x78;
1007
    SCHEME_STBAR3 = 0x3f;
1014
    SCHEME_STBAR3 = 0x3f;
1008
    SCHEME_SCROLL = 0x70;
1015
    SCHEME_SCROLL = 0x70;
1009
    SCHEME_MSG = 0x6f;
1016
    SCHEME_MSG = 0x6f;
1010
    SCHEME_ERR = 0x4f;
1017
    SCHEME_ERR = 0x4f;
-
 
1018
  } else {
-
 
1019
    // FIXME
-
 
1020
    mdr_coutraw_char('0' + glob_monomode);
-
 
1021
    _asm int 0x20
1011
  }
1022
  }
1012
  screenlastrow = screenh - 1;
1023
  screenlastrow = screenh - 1;
1013
  screenlastcol = screenw - 1;
1024
  screenlastcol = screenw - 1;
1014
 
1025
 
1015
  /* instruct DOS to stop detecting CTRL+C because user needs it for
1026
  /* instruct DOS to stop detecting CTRL+C because user needs it for