Subversion Repositories SvarDOS

Rev

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

Rev 2218 Rev 2220
Line 25... Line 25...
25
/*
25
/*
26
 * a variety of helper functions
26
 * a variety of helper functions
27
 */
27
 */
28
 
28
 
29
#include <i86.h>    /* MK_FP() */
29
#include <i86.h>    /* MK_FP() */
30
#include <stdio.h>  /* sprintf() */
-
 
31
 
30
 
32
#include "svarlang.lib\svarlang.h"
31
#include "svarlang.lib\svarlang.h"
33
 
32
 
34
#include "env.h"
33
#include "env.h"
35
#include "rmodinit.h"
34
#include "rmodinit.h"
Line 164... Line 163...
164
  unsigned char redirflag = 0;
163
  unsigned char redirflag = 0;
165
  /* find string in nls block */
164
  /* find string in nls block */
166
  if (e < 0xff) ptr = svarlang_strid(0xff00 | e);
165
  if (e < 0xff) ptr = svarlang_strid(0xff00 | e);
167
  /* if not found, use a fallback */
166
  /* if not found, use a fallback */
168
  if ((ptr == NULL) || (ptr[0] == 0)) {
167
  if ((ptr == NULL) || (ptr[0] == 0)) {
169
    sprintf(errstr, "DOS ERR %u", e);
168
    sv_strcpy(errstr, "DOS ERR ");
-
 
169
    ustoa(errstr + sv_strlen(errstr), e, 0, '0');
170
    ptr = errstr;
170
    ptr = errstr;
171
  }
171
  }
172
 
172
 
173
  /* display to stdout */
173
  /* display to stdout */
174
  output_internal(ptr, 1, hSTDOUT);
174
  output_internal(ptr, 1, hSTDOUT);
Line 447... Line 447...
447
    dst[end] = 0;
447
    dst[end] = 0;
448
  }
448
  }
449
}
449
}
450
 
450
 
451
 
451
 
-
 
452
/* convert an unsigned short to ASCIZ, output set to fixlen chars if fixlen
-
 
453
 * is non zero (prefixed with prefixchar if value too small, else truncated)
-
 
454
 * returns length of produced string */
-
 
455
unsigned short ustoa(char *dst, unsigned short n, unsigned char fixlen, char prefixchar) {
-
 
456
  unsigned short r;
-
 
457
  unsigned char i;
-
 
458
  unsigned char nonzerocharat = 5;
-
 
459
 
-
 
460
  for (i = 4; i != 0xff; i--) {
-
 
461
    r = n % 10;
-
 
462
    n /= 10;
-
 
463
    dst[i] = '0' + r;
-
 
464
    if (r != 0) nonzerocharat = i;
-
 
465
  }
-
 
466
 
-
 
467
  /* change prefix to prefixchar (eg. "00120" -> "  120") */
-
 
468
  for (i = 0; i < 4; i++) {
-
 
469
    if (dst[i] != '0') break;
-
 
470
    dst[i] = prefixchar;
-
 
471
  }
-
 
472
 
-
 
473
  /* apply fixlen, if set */
-
 
474
  if ((fixlen > 0) && (fixlen < 6)) {
-
 
475
    nonzerocharat = 5 - fixlen;
-
 
476
  }
-
 
477
 
-
 
478
  if (nonzerocharat != 0) {
-
 
479
    memcpy_ltr(dst, dst + nonzerocharat, 5 - nonzerocharat);
-
 
480
  }
-
 
481
 
-
 
482
  dst[5 - nonzerocharat] = 0;
-
 
483
 
-
 
484
  return(5 - nonzerocharat);
-
 
485
}
-
 
486
 
-
 
487
 
452
/* converts an ASCIIZ string into an unsigned short. returns 0 on success.
488
/* converts an ASCIIZ string into an unsigned short. returns 0 on success.
453
 * on error, result will contain all valid digits that were read until
489
 * on error, result will contain all valid digits that were read until
454
 * error occurred (0 on overflow or if parsing failed immediately) */
490
 * error occurred (0 on overflow or if parsing failed immediately) */
455
int atous(unsigned short *r, const char *s) {
491
int atous(unsigned short *r, const char *s) {
456
  int err = 0;
492
  int err = 0;
Line 615... Line 651...
615
 
651
 
616
/* computes a formatted date based on NLS patterns found in p
652
/* computes a formatted date based on NLS patterns found in p
617
 * returns length of result */
653
 * returns length of result */
618
unsigned short nls_format_date(char *s, unsigned short yr, unsigned char mo, unsigned char dy, const struct nls_patterns *p) {
654
unsigned short nls_format_date(char *s, unsigned short yr, unsigned char mo, unsigned char dy, const struct nls_patterns *p) {
619
  unsigned short items[3];
655
  unsigned short items[3];
-
 
656
  unsigned short slen;
-
 
657
 
620
  /* preset date/month/year in proper order depending on date format */
658
  /* preset date/month/year in proper order depending on date format */
621
  switch (p->dateformat) {
659
  switch (p->dateformat) {
622
    case 0:  /* USA style: m d y */
660
    case 0:  /* USA style: m d y */
623
      items[0] = mo;
661
      items[0] = mo;
624
      items[1] = dy;
662
      items[1] = dy;
Line 635... Line 673...
635
      items[1] = mo;
673
      items[1] = mo;
636
      items[2] = dy;
674
      items[2] = dy;
637
      break;
675
      break;
638
  }
676
  }
639
  /* compute the string */
677
  /* compute the string */
-
 
678
 
-
 
679
  slen = ustoa(s, items[0], 2, '0');
-
 
680
  slen += sv_strcpy(s + slen, p->datesep);
640
  return(sprintf(s, "%02u%s%02u%s%02u", items[0], p->datesep, items[1], p->datesep, items[2]));
681
  slen += ustoa(s + slen, items[1], 2, '0');
-
 
682
  slen += sv_strcpy(s + slen, p->datesep);
-
 
683
  slen += ustoa(s + slen, items[2], 2, '0');
-
 
684
 
-
 
685
  return(slen);
641
}
686
}
642
 
687
 
643
 
688
 
644
/* computes a formatted time based on NLS patterns found in p, sc are ignored if set 0xff
689
/* computes a formatted time based on NLS patterns found in p, sc are ignored if set 0xff
645
 * returns length of result */
690
 * returns length of result */
Line 655... Line 700...
655
      ampm = 'p';
700
      ampm = 'p';
656
    } else { /* ho < 12 */
701
    } else { /* ho < 12 */
657
      if (ho == 0) ho = 12;
702
      if (ho == 0) ho = 12;
658
      ampm = 'a';
703
      ampm = 'a';
659
    }
704
    }
660
    res = sprintf(s, "%2u", ho);
705
    res = ustoa(s, ho, 2, ' '); /* %2u */
661
  } else {
706
  } else {
662
    res = sprintf(s, "%02u", ho);
707
    res = ustoa(s, ho, 2, '0'); /* %02u */
663
  }
708
  }
664
 
709
 
665
  /* append separator and minutes */
710
  /* append separator and minutes */
666
  res += sprintf(s + res, "%s%02u", p->timesep, mn);
711
  res += sv_strcpy(s + res, p->timesep);
-
 
712
  res += ustoa(s + res, mn, 2, '0'); /* %02u */
667
 
713
 
668
  /* if seconds provided, append them, too */
714
  /* if seconds provided, append them, too */
-
 
715
  if (sc != 0xff) {
669
  if (sc != 0xff) res += sprintf(s + res, "%s%02u", p->timesep, sc);
716
    res += sv_strcpy(s + res, p->timesep);
-
 
717
    res += ustoa(s + res, sc, 2, '0'); /* %02u */
-
 
718
  }
670
 
719
 
671
  /* finally append AM/PM char */
720
  /* finally append the AM/PM char */
672
  if (ampm != 0) s[res++] = ampm;
721
  if (ampm != 0) s[res++] = ampm;
673
  s[res] = 0;
722
  s[res] = 0;
674
 
723
 
675
  return(res);
724
  return(res);
676
}
725
}
Line 890... Line 939...
890
  pathlen = env_lookup_valcopy(fname, 128, env_seg, "DOSDIR");
939
  pathlen = env_lookup_valcopy(fname, 128, env_seg, "DOSDIR");
891
  if (pathlen == 0) return(-1);
940
  if (pathlen == 0) return(-1);
892
 
941
 
893
  /* prep filename: %DOSDIR%\LINKS\PKG.LNK */
942
  /* prep filename: %DOSDIR%\LINKS\PKG.LNK */
894
  if (fname[pathlen - 1] == '\\') pathlen--;
943
  if (fname[pathlen - 1] == '\\') pathlen--;
895
  pathlen += sprintf(fname + pathlen, "\\LINKS");
944
  pathlen += sv_strcpy(fname + pathlen, "\\LINKS");
896
  /* create \LINKS if not exists */
945
  /* create \LINKS if not exists */
897
  if (file_getattr(fname) < 0) {
946
  if (file_getattr(fname) < 0) {
898
    _asm {
947
    _asm {
899
      push dx
948
      push dx
900
      mov ah, 0x39
949
      mov ah, 0x39
Line 917... Line 966...
917
    output(fname);
966
    output(fname);
918
    output(" - ");
967
    output(" - ");
919
    nls_outputnl(255,3); /* path not found */
968
    nls_outputnl(255,3); /* path not found */
920
    return(-1);
969
    return(-1);
921
  }
970
  }
-
 
971
  sv_strcat(fname + pathlen, "\\");
922
  sprintf(fname + pathlen, "\\%s.LNK", linkname);
972
  sv_strcat(fname + pathlen, linkname);
-
 
973
  sv_strcat(fname + pathlen, ".LNK");
923
 
974
 
924
  return(0);
975
  return(0);
925
}
976
}
926
 
977
 
927
 
978