Subversion Repositories SvarDOS

Rev

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

Rev 959 Rev 965
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 "deflang.h"
-
 
34
 
-
 
35
#include "env.h"
33
#include "env.h"
36
 
34
 
37
#include "helpers.h"
35
#include "helpers.h"
38
 
36
 
39
 
37
 
-
 
38
/* supplied through DEFLANG.C */
-
 
39
extern char svarlang_mem[];
-
 
40
extern const unsigned short svarlang_memsz;
-
 
41
 
-
 
42
 
40
/* case-insensitive comparison of strings, compares up to maxlen characters.
43
/* case-insensitive comparison of strings, compares up to maxlen characters.
41
 * returns non-zero on equality. */
44
 * returns non-zero on equality. */
42
int imatchlim(const char *s1, const char *s2, unsigned short maxlen) {
45
int imatchlim(const char *s1, const char *s2, unsigned short maxlen) {
43
  while (maxlen--) {
46
  while (maxlen--) {
44
    char c1, c2;
47
    char c1, c2;
Line 106... Line 109...
106
  }
109
  }
107
}
110
}
108
 
111
 
109
 
112
 
110
static const char *nlsblock_findstr(unsigned short id) {
113
static const char *nlsblock_findstr(unsigned short id) {
111
  const char *ptr = langblock + 4; /* first 4 bytes are lang id and lang len */
114
  const char *ptr = svarlang_mem;
112
  /* find the string id in langblock memory */
115
  /* find the string id in langblock memory */
113
  for (;;) {
116
  for (;;) {
114
    if (((unsigned short *)ptr)[0] == id) {
117
    if (((unsigned short *)ptr)[0] == id) {
115
      ptr += 3;
-
 
116
      return(ptr);
118
      return(ptr + 4);
117
    }
119
    }
118
    if (ptr[2] == 0) return(NULL);
120
    if (ptr[2] == 0) return(NULL);
119
    ptr += ptr[2] + 3;
121
    ptr += ((unsigned short *)ptr)[1] + 4;
120
  }
122
  }
121
}
123
}
122
 
124
 
123
 
125
 
124
void nls_output_internal(unsigned short id, unsigned char nl, unsigned char handle) {
126
void nls_output_internal(unsigned short id, unsigned char nl, unsigned char handle) {
Line 624... Line 626...
624
 
626
 
625
  return(sl);
627
  return(sl);
626
}
628
}
627
 
629
 
628
 
630
 
629
/* reload nls ressources from svarcom.lng into langblock */
631
/* reload nls ressources from svarcom.lng into svarlang_mem */
630
void nls_langreload(char *buff, unsigned short env) {
632
void nls_langreload(char *buff, unsigned short env) {
631
  unsigned short i;
633
  unsigned short i;
632
  const char far *nlspath;
634
  const char far *nlspath;
633
  char *langblockptr = langblock;
635
  char *langblockptr = svarlang_mem;
634
  unsigned short lang;
636
  unsigned short lang;
635
  unsigned short errcode = 0;
637
  unsigned short errcode = 0;
-
 
638
  static unsigned short lastlang;
636
 
639
 
637
  /* look up the LANG env variable, upcase it and copy to lang */
640
  /* look up the LANG env variable, upcase it and copy to lang */
638
  nlspath = env_lookup_val(env, "LANG");
641
  nlspath = env_lookup_val(env, "LANG");
639
  if ((nlspath == NULL) || (nlspath[0] == 0)) return;
642
  if ((nlspath == NULL) || (nlspath[0] == 0)) return;
640
  buff[0] = nlspath[0];
643
  buff[0] = nlspath[0] & 0xDF;
641
  buff[1] = nlspath[1];
644
  buff[1] = nlspath[1] & 0xDF;
642
  buff[2] = 0;
645
  buff[2] = 0;
643
 
646
 
644
  if (buff[0] >= 'a') buff[0] -= 'a' - 'A';
-
 
645
  if (buff[1] >= 'a') buff[1] -= 'a' - 'A';
-
 
646
  memcpy(&lang, buff, 2);
647
  memcpy(&lang, buff, 2);
647
 
648
 
648
  /* check if there is need to reload at all */
649
  /* check if there is need to reload at all */
649
  if (((unsigned short *)langblock)[0] == lang) return;
650
  if (lastlang == lang) return;
650
 
651
 
651
  /* printf("NLS RELOAD (curlang=%04X ; toload=%04X\r\n", ((unsigned short *)langblock)[0], lang); */
652
  /* printf("NLS RELOAD (curlang=%04X ; toload=%04X\r\n", lastlang, lang); */
652
 
653
 
653
  nlspath = env_lookup_val(env, "NLSPATH");
654
  nlspath = env_lookup_val(env, "NLSPATH");
654
  if ((nlspath == NULL) || (nlspath[0] == 0)) return;
655
  if ((nlspath == NULL) || (nlspath[0] == 0)) return;
655
 
656
 
656
  /* copy NLSPATH(far) to buff */
657
  /* copy NLSPATH(far) to buff */
Line 660... Line 661...
660
  if (buff[i - 1] != '\\') buff[i++] = '\\';
661
  if (buff[i - 1] != '\\') buff[i++] = '\\';
661
 
662
 
662
  /* append "svarcom.lng" */
663
  /* append "svarcom.lng" */
663
  strcpy(buff + i, "SVARCOM.LNG");
664
  strcpy(buff + i, "SVARCOM.LNG");
664
 
665
 
665
  /* copy file content to langblock */
666
  /* copy file content to svarlang_mem */
666
  _asm {
667
  _asm {
667
    push ax
668
    push ax
668
    push bx
669
    push bx
669
    push cx
670
    push cx
670
    push dx
671
    push dx
Line 735... Line 736...
735
    jc FAIL
736
    jc FAIL
736
    jmp READLANGID
737
    jmp READLANGID
737
 
738
 
738
    LOADSTRINGS:
739
    LOADSTRINGS:
739
 
740
 
740
    /* copy langid and langlen to langblockptr */
-
 
741
    mov di, langblockptr
-
 
742
    mov ax, [si]
-
 
743
    stosw   /* mov [di], ax and di += 2 */
-
 
744
    mov ax, [si+2]
-
 
745
    stosw
-
 
746
    /* read strings (buff+2 bytes) into langblock */
741
    /* read strings (buff+2 bytes) into langblock */
-
 
742
    mov di, langblockptr
747
    mov ah, 0x3f   /* Read from File via Handle in BX */
743
    mov ah, 0x3f   /* Read from File via Handle in BX */
748
    mov cx, [si+2]
744
    mov cx, [si+2]
749
    mov dx, di
745
    mov dx, di
750
    int 0x21
746
    int 0x21
751
    jnc DONE
747
    jnc DONE
Line 774... Line 770...
774
    pop cx
770
    pop cx
775
    pop bx
771
    pop bx
776
    pop ax
772
    pop ax
777
  }
773
  }
778
 
774
 
779
  if (errcode != 0) printf("AX=%04x\r\n", errcode);
775
  if (errcode == 0) lastlang = lang;
780
}
776
}
781
 
777
 
782
 
778
 
783
/* locates executable fname in path and fill res with result. returns 0 on success,
779
/* locates executable fname in path and fill res with result. returns 0 on success,
784
 * -1 on failed match and -2 on failed match + "don't even try with other paths"
780
 * -1 on failed match and -2 on failed match + "don't even try with other paths"