Subversion Repositories SvarDOS

Rev

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

Rev 965 Rev 968
Line 28... Line 28...
28
 
28
 
29
#include <i86.h>    /* MK_FP() */
29
#include <i86.h>    /* MK_FP() */
30
#include <stdio.h>  /* sprintf() */
30
#include <stdio.h>  /* sprintf() */
31
#include <string.h> /* memcpy() */
31
#include <string.h> /* memcpy() */
32
 
32
 
-
 
33
#include "svarlang.lib\svarlang.h"
-
 
34
 
33
#include "env.h"
35
#include "env.h"
34
 
36
 
35
#include "helpers.h"
37
#include "helpers.h"
36
 
38
 
37
 
39
 
38
/* supplied through DEFLANG.C */
-
 
39
extern char svarlang_mem[];
-
 
40
extern const unsigned short svarlang_memsz;
-
 
41
 
-
 
42
 
40
 
43
/* case-insensitive comparison of strings, compares up to maxlen characters.
41
/* case-insensitive comparison of strings, compares up to maxlen characters.
44
 * returns non-zero on equality. */
42
 * returns non-zero on equality. */
45
int imatchlim(const char *s1, const char *s2, unsigned short maxlen) {
43
int imatchlim(const char *s1, const char *s2, unsigned short maxlen) {
46
  while (maxlen--) {
44
  while (maxlen--) {
Line 108... Line 106...
108
    FINITO:
106
    FINITO:
109
  }
107
  }
110
}
108
}
111
 
109
 
112
 
110
 
113
static const char *nlsblock_findstr(unsigned short id) {
-
 
114
  const char *ptr = svarlang_mem;
-
 
115
  /* find the string id in langblock memory */
-
 
116
  for (;;) {
-
 
117
    if (((unsigned short *)ptr)[0] == id) {
-
 
118
      return(ptr + 4);
-
 
119
    }
-
 
120
    if (ptr[2] == 0) return(NULL);
-
 
121
    ptr += ((unsigned short *)ptr)[1] + 4;
-
 
122
  }
-
 
123
}
-
 
124
 
-
 
125
 
-
 
126
void nls_output_internal(unsigned short id, unsigned char nl, unsigned char handle) {
111
void nls_output_internal(unsigned short id, unsigned char nl, unsigned char handle) {
127
  const char *NOTFOUND = "NLS_STRING_NOT_FOUND";
112
  const char *NOTFOUND = "NLS_STRING_NOT_FOUND";
128
  const char *ptr = nlsblock_findstr(id);
113
  const char *ptr = svarlang_strid(id);
129
  if (ptr == NULL) ptr = NOTFOUND;
114
  if (ptr == NULL) ptr = NOTFOUND;
130
  output_internal(ptr, nl, handle);
115
  output_internal(ptr, nl, handle);
131
}
116
}
132
 
117
 
133
 
118
 
Line 136... Line 121...
136
void nls_outputnl_doserr(unsigned short e) {
121
void nls_outputnl_doserr(unsigned short e) {
137
  static char errstr[16];
122
  static char errstr[16];
138
  const char *ptr = NULL;
123
  const char *ptr = NULL;
139
  unsigned char redirflag = 0;
124
  unsigned char redirflag = 0;
140
  /* find string in nls block */
125
  /* find string in nls block */
141
  if (e < 0xff) ptr = nlsblock_findstr(0xff00 | e);
126
  if (e < 0xff) ptr = svarlang_strid(0xff00 | e);
142
  /* if not found, use a fallback */
127
  /* if not found, use a fallback */
143
  if (ptr == NULL) {
128
  if (ptr == NULL) {
144
    sprintf(errstr, "DOS ERR %u", e);
129
    sprintf(errstr, "DOS ERR %u", e);
145
    ptr = errstr;
130
    ptr = errstr;
146
  }
131
  }
Line 628... Line 613...
628
}
613
}
629
 
614
 
630
 
615
 
631
/* reload nls ressources from svarcom.lng into svarlang_mem */
616
/* reload nls ressources from svarcom.lng into svarlang_mem */
632
void nls_langreload(char *buff, unsigned short env) {
617
void nls_langreload(char *buff, unsigned short env) {
633
  unsigned short i;
-
 
634
  const char far *nlspath;
618
  const char far *nlspath;
635
  char *langblockptr = svarlang_mem;
-
 
636
  unsigned short lang;
619
  const char far *lang;
637
  unsigned short errcode = 0;
-
 
638
  static unsigned short lastlang;
620
  static unsigned short lastlang;
639
 
621
 
640
  /* look up the LANG env variable, upcase it and copy to lang */
622
  /* look up the LANG env variable, upcase it and copy to lang */
641
  nlspath = env_lookup_val(env, "LANG");
623
  lang = env_lookup_val(env, "LANG");
642
  if ((nlspath == NULL) || (nlspath[0] == 0)) return;
624
  if ((lang == NULL) || (lang[0] == 0)) return;
643
  buff[0] = nlspath[0] & 0xDF;
-
 
644
  buff[1] = nlspath[1] & 0xDF;
625
  _fmemcpy(buff, lang, 2);
645
  buff[2] = 0;
626
  buff[2] = 0;
646
 
627
 
647
  memcpy(&lang, buff, 2);
-
 
648
 
-
 
649
  /* check if there is need to reload at all */
628
  /* check if there is need to reload at all */
650
  if (lastlang == lang) return;
629
  if (memcmp(&lastlang, buff, 2) == 0) return;
651
 
-
 
652
  /* printf("NLS RELOAD (curlang=%04X ; toload=%04X\r\n", lastlang, lang); */
-
 
653
 
630
 
-
 
631
  buff[4] = 0;
654
  nlspath = env_lookup_val(env, "NLSPATH");
632
  nlspath = env_lookup_val(env, "NLSPATH");
655
  if ((nlspath == NULL) || (nlspath[0] == 0)) return;
633
  if (nlspath != NULL) _fstrcpy(buff + 4, nlspath);
656
 
-
 
657
  /* copy NLSPATH(far) to buff */
-
 
658
  for (i = 0; nlspath[i] != 0; i++) buff[i] = nlspath[i];
-
 
659
 
-
 
660
  /* terminate with a bkslash, if not already the case */
-
 
661
  if (buff[i - 1] != '\\') buff[i++] = '\\';
-
 
662
 
-
 
663
  /* append "svarcom.lng" */
-
 
664
  strcpy(buff + i, "SVARCOM.LNG");
-
 
665
 
-
 
666
  /* copy file content to svarlang_mem */
-
 
667
  _asm {
-
 
668
    push ax
-
 
669
    push bx
-
 
670
    push cx
-
 
671
    push dx
-
 
672
    push si
-
 
673
    push di
-
 
674
 
-
 
675
    /* make sure ES=DS and clear DF (will be useful for string matching) */
-
 
676
    push ds
-
 
677
    pop es
-
 
678
    cld
-
 
679
 
-
 
680
    /* preset SI to buff */
-
 
681
    mov si, buff
-
 
682
 
634
 
683
    /* Open File */
-
 
684
    mov bx, 0xffff /* bx holds the file handle (0xffff = not set) */
-
 
685
    mov ax, 0x3d00 /* DOS 2+ -- Open File for read */
635
  if (svarlang_load("SVARCOM", buff, buff + 4) != 0) return;
686
    mov dx, si     /* fname */
-
 
687
    int 0x21       /* cf set on error, otherwise handle in AX */
-
 
688
    jnc OPENOK
-
 
689
    jmp FAIL
-
 
690
    OPENOK:
-
 
691
    mov bx, ax    /* save file handle to bx */
-
 
692
 
-
 
693
    /* read hdr */
-
 
694
    mov ah, 0x3f   /* DOS 2+ -- Read from File via Handle in BX */
-
 
695
    mov cx, 4      /* read 4 bytes */
-
 
696
    mov dx, si
-
 
697
    int 0x21
-
 
698
    jnc READHDROK
-
 
699
    jmp FAIL
-
 
700
 
-
 
701
    READHDROK:
-
 
702
 
-
 
703
    cmp ax, cx  /* hdr must be 4 bytes long (SvL\x1b) */
-
 
704
    jne FAIL
-
 
705
    /* check that sig is Svl\x1b */
-
 
706
    mov di, si
-
 
707
    cld         /* scasw must inc DI */
-
 
708
    mov ax, 'vS'
-
 
709
    scasw       /* cmp ax, ES:[DI] and DI += 2*/
-
 
710
    jne FAIL
-
 
711
    mov ax, 0x1B4C
-
 
712
    scasw       /* cmp ax, ES:[DI] and DI += 2*/
-
 
713
    jne FAIL
-
 
714
 
-
 
715
    READLANGID:
-
 
716
    /* read lang id */
-
 
717
    mov ah, 0x3f   /* Read from File via Handle in BX */
-
 
718
    /* mov bx, [i]  already set */
-
 
719
    mov cx, 4
-
 
720
    mov dx, si
-
 
721
    int 0x21
-
 
722
    jc FAIL
-
 
723
    cmp ax, cx
-
 
724
    jne FAIL
-
 
725
    /* is this the LANG I am looking for? */
-
 
726
    mov ax, [lang]
-
 
727
    mov di, si
-
 
728
    scasw       /* cmp ax, ES:[DI] and DI += 2*/
-
 
729
    je LOADSTRINGS
-
 
730
    /* skip to next lang */
-
 
731
    mov ax, 0x4201   /* move file pointer CX:DX bytes forward */
-
 
732
    /* mov bx, [i]  file handle */
-
 
733
    xor cx, cx
-
 
734
    mov dx, [di]
-
 
735
    int 0x21
-
 
736
    jc FAIL
-
 
737
    jmp READLANGID
-
 
738
 
-
 
739
    LOADSTRINGS:
-
 
740
 
-
 
741
    /* read strings (buff+2 bytes) into langblock */
-
 
742
    mov di, langblockptr
-
 
743
    mov ah, 0x3f   /* Read from File via Handle in BX */
-
 
744
    mov cx, [si+2]
-
 
745
    mov dx, di
-
 
746
    int 0x21
-
 
747
    jnc DONE
-
 
748
 
-
 
749
    /* on error make sure to zero out langblock's header */
-
 
750
    xor cx, cx
-
 
751
    mov [di], cx                 /* langblock id*/
-
 
752
    mov [di + 2], cx /* langblock len */
-
 
753
    mov [di + 4], cx /* 1st string id */
-
 
754
    mov [di + 6], cx /* 1st string len */
-
 
755
 
-
 
756
    /* cleanup and quit */
-
 
757
    FAIL:
-
 
758
    mov [errcode], ax
-
 
759
    DONE:
-
 
760
    /* close file handle if set */
-
 
761
    cmp bx, 0xffff
-
 
762
    je FNOTOPEN
-
 
763
    mov ah, 0x3e  /* DOS 2+ -- Close a File Handle (Handle in BX) */
-
 
764
    int 0x21
-
 
765
    FNOTOPEN:
-
 
766
 
-
 
767
    pop di
-
 
768
    pop si
-
 
769
    pop dx
-
 
770
    pop cx
-
 
771
    pop bx
-
 
772
    pop ax
-
 
773
  }
-
 
774
 
636
 
775
  if (errcode == 0) lastlang = lang;
637
  _fmemcpy(&lastlang, lang, 2);
776
}
638
}
777
 
639
 
778
 
640
 
779
/* locates executable fname in path and fill res with result. returns 0 on success,
641
/* locates executable fname in path and fill res with result. returns 0 on success,
780
 * -1 on failed match and -2 on failed match + "don't even try with other paths"
642
 * -1 on failed match and -2 on failed match + "don't even try with other paths"