Subversion Repositories SvarDOS

Rev

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

Rev 1355 Rev 1356
Line 33... Line 33...
33
#include "mdr\keyb.h"
33
#include "mdr\keyb.h"
34
 
34
 
35
#include "svarlang\svarlang.h"
35
#include "svarlang\svarlang.h"
36
 
36
 
37
 
37
 
-
 
38
#define PVER "2023.0"
-
 
39
#define PDATE "2023"
-
 
40
 
38
/*****************************************************************************
41
/*****************************************************************************
39
 * global variables and definitions                                          *
42
 * global variables and definitions                                          *
40
 *****************************************************************************/
43
 *****************************************************************************/
41
 
44
 
42
/* preload the mono scheme (to be overloaded at runtime if color adapter present) */
45
/* preload the mono scheme (to be overloaded at runtime if color adapter present) */
Line 208... Line 211...
208
  db->curline = 0;
211
  db->curline = 0;
209
}
212
}
210
 
213
 
211
 
214
 
212
static void ui_basic(const struct file *db, unsigned short slotnum) {
215
static void ui_basic(const struct file *db, unsigned short slotnum) {
213
  const char *s = svarlang_strid(0); /* HELP */
216
  const char *s = svarlang_strid(0); /* ESC=MENU */
214
  unsigned short helpcol = screenw - strlen(s);
217
  unsigned short helpcol = screenw - strlen(s);
215
 
218
 
216
  /* slot number */
219
  /* slot number */
217
  {
220
  {
218
    char slot[4] = "#00";
221
    char slot[4] = "#00";
Line 490... Line 493...
490
  cursor_left(db);
493
  cursor_left(db);
491
  del(db);
494
  del(db);
492
}
495
}
493
 
496
 
494
 
497
 
495
/* a custom argv-parsing routine that looks directly inside the PSP, avoids the need
-
 
496
 * of argc and argv, saves some 330 bytes of binary size */
-
 
497
static const char *parseargv(void) {
-
 
498
  char *tail = (void *)0x81; /* THIS WORKS ONLY IN SMALL MEMORY MODEL */
-
 
499
  unsigned short count = 0;
-
 
500
  char *argv[2];
-
 
501
 
-
 
502
  while (count < 2) {
-
 
503
    /* jump to nearest arg */
-
 
504
    while (*tail == ' ') {
-
 
505
      *tail = 0;
-
 
506
      tail++;
-
 
507
    }
-
 
508
 
-
 
509
    if (*tail == '\r') {
-
 
510
      *tail = 0;
-
 
511
      break;
-
 
512
    }
-
 
513
 
-
 
514
    argv[count++] = tail;
-
 
515
 
-
 
516
    /* jump to next delimiter */
-
 
517
    while ((*tail != ' ') && (*tail != '\r')) tail++;
-
 
518
  }
-
 
519
 
-
 
520
  /* check args now */
-
 
521
  if (count == 0) return("");
-
 
522
  if (count == 1) return(argv[0]);
-
 
523
 
-
 
524
  return(NULL);
-
 
525
}
-
 
526
 
-
 
527
 
-
 
528
/* returns 0 on success, 1 on file not found, 2 on other error */
498
/* returns 0 on success, 1 on file not found, 2 on other error */
529
static unsigned char loadfile(struct file *db, const char *fname) {
499
static unsigned char loadfile(struct file *db, const char *fname) {
530
  char buff[512]; /* read one entire sector at a time (faster) */
500
  char buff[512]; /* read one entire sector at a time (faster) */
531
  char *buffptr;
501
  char *buffptr;
532
  unsigned int len, llen;
502
  unsigned int len, llen;
Line 627... Line 597...
627
  _dos_close(fd);
597
  _dos_close(fd);
628
  return(2);
598
  return(2);
629
}
599
}
630
 
600
 
631
 
601
 
-
 
602
/* a custom argv-parsing routine that looks directly inside the PSP, avoids the need
-
 
603
 * of argc and argv, saves some 330 bytes of binary size
-
 
604
 * returns non-zero on error */
-
 
605
static int parseargv(struct file *dbarr) {
-
 
606
  char *tail = (void *)0x81; /* THIS WORKS ONLY IN SMALL MEMORY MODEL */
-
 
607
  unsigned short count = 0;
-
 
608
  char *arg;
-
 
609
  unsigned short lastarg = 0;
-
 
610
  unsigned short err;
-
 
611
 
-
 
612
  while (!lastarg) {
-
 
613
    /* jump to nearest arg */
-
 
614
    while (*tail == ' ') {
-
 
615
      *tail = 0;
-
 
616
      tail++;
-
 
617
    }
-
 
618
 
-
 
619
    if (*tail == '\r') {
-
 
620
      *tail = 0;
-
 
621
      break;
-
 
622
    }
-
 
623
 
-
 
624
    arg = tail;
-
 
625
 
-
 
626
    /* jump to next delimiter */
-
 
627
    while ((*tail != ' ') && (*tail != '\r')) tail++;
-
 
628
 
-
 
629
    /* if \r then remember this is the last arg */
-
 
630
    if (*tail == '\r') lastarg = 1;
-
 
631
 
-
 
632
    *tail = 0;
-
 
633
    tail++;
-
 
634
 
-
 
635
    /* look at the arg now */
-
 
636
    if (*arg == '/') {
-
 
637
      mdr_coutraw_puts("Sved ver " PVER " Copyright (C) " PDATE " Mateusz Viste");
-
 
638
      mdr_coutraw_puts("");
-
 
639
      mdr_coutraw_puts(svarlang_str(1,0)); /* usage: sved file.txt */
-
 
640
      return(-1);
-
 
641
    }
-
 
642
 
-
 
643
    /* looks to be a filename */
-
 
644
    if (count == 10) {
-
 
645
      mdr_coutraw_puts(svarlang_str(0,12));
-
 
646
      return(-1); /* too many files */
-
 
647
    }
-
 
648
 
-
 
649
    /* try loading it */
-
 
650
    mdr_coutraw_puts(arg);
-
 
651
    err = loadfile(&(dbarr[count]), arg);
-
 
652
    if (err) {
-
 
653
      if (err == 1) { /* file not found */
-
 
654
        err = 11;
-
 
655
      } else { /* general error */
-
 
656
        err = 10;
-
 
657
      }
-
 
658
      mdr_coutraw_puts(svarlang_str(0,err));
-
 
659
      return(-1);
-
 
660
    }
-
 
661
    count++;
-
 
662
  }
-
 
663
 
-
 
664
  return(0);
-
 
665
}
-
 
666
 
-
 
667
 
632
static int savefile(const struct file *db, const char *newfname) {
668
static int savefile(const struct file *db, const char *newfname) {
633
  int fd;
669
  int fd;
634
  const struct line far *l;
670
  const struct line far *l;
635
  unsigned bytes;
671
  unsigned bytes;
636
  unsigned char eollen;
672
  unsigned char eollen;
Line 780... Line 816...
780
 
816
 
781
/* main returns nothing, ie. sved always exits with a zero exit code
817
/* main returns nothing, ie. sved always exits with a zero exit code
782
 * (this saves 20 bytes of executable footprint) */
818
 * (this saves 20 bytes of executable footprint) */
783
void main(void) {
819
void main(void) {
784
  static struct file dbarr[10];
820
  static struct file dbarr[10];
785
  const char *fname;
-
 
786
  unsigned short curfile;
821
  unsigned short curfile;
787
  struct file *db = dbarr; /* visible file is the first slot by default */
822
  struct file *db = dbarr; /* visible file is the first slot by default */
788
 
823
 
789
  {
824
  {
790
    char nlspath[128], lang[8];
825
    char nlspath[128], lang[8];
791
    svarlang_autoload_pathlist("sved", mdr_dos_getenv(nlspath, "NLSPATH", sizeof(nlspath)), mdr_dos_getenv(lang, "LANG", sizeof(lang)));
826
    svarlang_autoload_pathlist("sved", mdr_dos_getenv(nlspath, "NLSPATH", sizeof(nlspath)), mdr_dos_getenv(lang, "LANG", sizeof(lang)));
792
  }
827
  }
793
 
828
 
794
  fname = parseargv();
-
 
795
 
-
 
796
  if ((fname == NULL) || (*fname == '/')) {
-
 
797
    mdr_coutraw_puts(svarlang_str(1,0)); /* usage: sved file.txt */
-
 
798
    return;
-
 
799
  }
-
 
800
 
-
 
801
  /* preload all slots with empty files */
829
  /* preload all slots with empty files */
802
  for (curfile = 9;; curfile--) {
830
  for (curfile = 9;; curfile--) {
803
    loadfile(&(dbarr[curfile]), "");
831
    loadfile(&(dbarr[curfile]), "");
804
    if (curfile == 0) break;
832
    if (curfile == 0) break;
805
  }
833
  }
806
 
834
 
807
  /* load file, if any given */
835
  /* parse argv (and load files, if any passed on) */
808
  if (*fname != 0) {
-
 
809
    unsigned char err = loadfile(db, fname);
-
 
810
    if (err == 1) {
-
 
811
      mdr_coutraw_puts(svarlang_str(0,11)); /* file not found */
-
 
812
      return;
-
 
813
    } else if (err != 0) {
836
  if (parseargv(dbarr) != 0) return;
814
      mdr_coutraw_puts(svarlang_str(0,10)); /* ERROR */
-
 
815
      return;
-
 
816
    }
-
 
817
  }
-
 
818
 
837
 
819
  if (mdr_cout_init(&screenw, &screenh)) {
838
  if (mdr_cout_init(&screenw, &screenh)) {
820
    /* load color scheme if mdr_cout_init returns a color flag */
839
    /* load color scheme if mdr_cout_init returns a color flag */
821
    SCHEME_TEXT = 0x17;
840
    SCHEME_TEXT = 0x17;
822
    SCHEME_MENU = 0x70;
841
    SCHEME_MENU = 0x70;