Subversion Repositories SvarDOS

Rev

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

Rev 430 Rev 437
Line 27... Line 27...
27
 * Copyright (C) 2021 Mateusz Viste
27
 * Copyright (C) 2021 Mateusz Viste
28
 */
28
 */
29
 
29
 
30
#include <i86.h>    /* MK_FP() */
30
#include <i86.h>    /* MK_FP() */
31
#include <stdio.h>  /* sprintf() */
31
#include <stdio.h>  /* sprintf() */
-
 
32
#include <string.h> /* memcpy() */
-
 
33
 
-
 
34
#include "deflang.h"
-
 
35
 
-
 
36
#include "env.h"
32
 
37
 
33
#include "helpers.h"
38
#include "helpers.h"
34
 
39
 
35
 
40
 
36
/* case-insensitive comparison of strings, returns non-zero on equality */
41
/* case-insensitive comparison of strings, returns non-zero on equality */
Line 85... Line 90...
85
    FINITO:
90
    FINITO:
86
  }
91
  }
87
}
92
}
88
 
93
 
89
 
94
 
-
 
95
void nls_output_internal(unsigned short id, unsigned short nl) {
-
 
96
  const char *ptr = langblock + 4; /* first 4 bytes are lang id and lang len */
-
 
97
  const char *NOTFOUND = "NLS_STRING_NOT_FOUND";
-
 
98
  /* find the string id in langblock memory */
-
 
99
  for (;;) {
-
 
100
    if (((unsigned short *)ptr)[0] == id) {
-
 
101
      ptr += 3;
-
 
102
      break;
-
 
103
    }
-
 
104
    if (ptr[2] == 0) {
-
 
105
      ptr = NOTFOUND;
-
 
106
      break;
-
 
107
    }
-
 
108
    ptr += ptr[2] + 3;
-
 
109
  }
-
 
110
  output_internal(ptr, nl);
-
 
111
}
-
 
112
 
-
 
113
 
90
/* find first matching files using a FindFirst DOS call
114
/* find first matching files using a FindFirst DOS call
91
 * returns 0 on success or a DOS err code on failure */
115
 * returns 0 on success or a DOS err code on failure */
92
unsigned short findfirst(struct DTA *dta, const char *pattern, unsigned short attr) {
116
unsigned short findfirst(struct DTA *dta, const char *pattern, unsigned short attr) {
93
  unsigned short res = 0;
117
  unsigned short res = 0;
94
  _asm {
118
  _asm {
Line 224... Line 248...
224
}
248
}
225
 
249
 
226
 
250
 
227
/* displays the "Press any key to continue" msg and waits for a keypress */
251
/* displays the "Press any key to continue" msg and waits for a keypress */
228
void press_any_key(void) {
252
void press_any_key(void) {
229
  output("Press any key to continue...");
253
  nls_output(15, 1); /* Press any key to continue... */
230
  _asm {
254
  _asm {
231
    mov ah, 0x08  /* no echo console input */
255
    mov ah, 0x08  /* no echo console input */
232
    int 0x21      /* pressed key in AL now (0 for extended keys) */
256
    int 0x21      /* pressed key in AL now (0 for extended keys) */
233
    test al, al
257
    test al, al
234
    jnz DONE
258
    jnz DONE
Line 539... Line 563...
539
    s[sl - (i + 1)] = thcount;
563
    s[sl - (i + 1)] = thcount;
540
  }
564
  }
541
 
565
 
542
  return(sl);
566
  return(sl);
543
}
567
}
-
 
568
 
-
 
569
 
-
 
570
/* reload nls ressources from svarcom.lng into langblock */
-
 
571
void nls_langreload(char *buff, unsigned short env) {
-
 
572
  unsigned short i;
-
 
573
  const char far *nlspath;
-
 
574
  char *langblockptr = langblock;
-
 
575
  unsigned short lang;
-
 
576
  unsigned short errcode = 0;
-
 
577
 
-
 
578
  /* look up the LANG env variable, upcase it and copy to lang */
-
 
579
  nlspath = env_lookup_val(env, "LANG");
-
 
580
  if ((nlspath == NULL) || (nlspath[0] == 0)) return;
-
 
581
  buff[0] = nlspath[0];
-
 
582
  buff[1] = nlspath[1];
-
 
583
  buff[2] = 0;
-
 
584
 
-
 
585
  if (buff[0] >= 'a') buff[0] -= 'a' - 'A';
-
 
586
  if (buff[1] >= 'a') buff[1] -= 'a' - 'A';
-
 
587
  memcpy(&lang, buff, 2);
-
 
588
 
-
 
589
  /* check if there is need to reload at all */
-
 
590
  if (((unsigned short *)langblock)[0] == lang) return;
-
 
591
 
-
 
592
  /* printf("NLS RELOAD (curlang=%04X ; toload=%04X\r\n", ((unsigned short *)langblock)[0], lang); */
-
 
593
 
-
 
594
  nlspath = env_lookup_val(env, "NLSPATH");
-
 
595
  if ((nlspath == NULL) || (nlspath[0] == 0)) return;
-
 
596
 
-
 
597
  /* copy NLSPATH(far) to buff */
-
 
598
  for (i = 0; nlspath[i] != 0; i++) buff[i] = nlspath[i];
-
 
599
 
-
 
600
  /* terminate with a bkslash, if not already the case */
-
 
601
  if (buff[i - 1] != '\\') buff[i++] = '\\';
-
 
602
 
-
 
603
  /* append "svarcom.lng" */
-
 
604
  strcpy(buff + i, "SVARCOM.LNG");
-
 
605
 
-
 
606
  /* copy file content to langblock */
-
 
607
  _asm {
-
 
608
    push ax
-
 
609
    push bx
-
 
610
    push cx
-
 
611
    push dx
-
 
612
    push si
-
 
613
    push di
-
 
614
 
-
 
615
    /* make sure ES=DS and clear DF (will be useful for string matching) */
-
 
616
    push ds
-
 
617
    pop es
-
 
618
    cld
-
 
619
 
-
 
620
    /* preset SI to buff */
-
 
621
    mov si, buff
-
 
622
 
-
 
623
    /* Open File */
-
 
624
    mov bx, 0xffff /* bx holds the file handle (0xffff = not set) */
-
 
625
    mov ax, 0x3d00 /* DOS 2+ -- Open File for read */
-
 
626
    mov dx, si     /* fname */
-
 
627
    int 0x21       /* cf set on error, otherwise handle in AX */
-
 
628
    jnc OPENOK
-
 
629
    jmp FAIL
-
 
630
    OPENOK:
-
 
631
    mov bx, ax    /* save file handle to bx */
-
 
632
 
-
 
633
    /* read hdr */
-
 
634
    mov ah, 0x3f   /* DOS 2+ -- Read from File via Handle in BX */
-
 
635
    mov cx, 4      /* read 4 bytes */
-
 
636
    mov dx, si
-
 
637
    int 0x21
-
 
638
    jnc READHDROK
-
 
639
    jmp FAIL
-
 
640
 
-
 
641
    READHDROK:
-
 
642
 
-
 
643
    cmp ax, cx  /* hdr must be 4 bytes long (SvL\x1b) */
-
 
644
    jne FAIL
-
 
645
    /* check that sig is Svl\x1b */
-
 
646
    mov di, si
-
 
647
    cld         /* scasw must inc DI */
-
 
648
    mov ax, 'vS'
-
 
649
    scasw       /* cmp ax, ES:[DI] and DI += 2*/
-
 
650
    jne FAIL
-
 
651
    mov ax, 0x1B4C
-
 
652
    scasw       /* cmp ax, ES:[DI] and DI += 2*/
-
 
653
    jne FAIL
-
 
654
 
-
 
655
    READLANGID:
-
 
656
    /* read lang id */
-
 
657
    mov ah, 0x3f   /* Read from File via Handle in BX */
-
 
658
    /* mov bx, [i]  already set */
-
 
659
    mov cx, 4
-
 
660
    mov dx, si
-
 
661
    int 0x21
-
 
662
    jc FAIL
-
 
663
    cmp ax, cx
-
 
664
    jne FAIL
-
 
665
    /* is this the LANG I am looking for? */
-
 
666
    mov ax, [lang]
-
 
667
    mov di, si
-
 
668
    scasw       /* cmp ax, ES:[DI] and DI += 2*/
-
 
669
    je LOADSTRINGS
-
 
670
    /* skip to next lang */
-
 
671
    mov ax, 0x4201   /* move file pointer CX:DX bytes forward */
-
 
672
    /* mov bx, [i]  file handle */
-
 
673
    xor cx, cx
-
 
674
    mov dx, [di]
-
 
675
    int 0x21
-
 
676
    jc FAIL
-
 
677
    jmp READLANGID
-
 
678
 
-
 
679
    LOADSTRINGS:
-
 
680
 
-
 
681
    /* copy langid and langlen to langblockptr */
-
 
682
    mov di, langblockptr
-
 
683
    mov ax, [si]
-
 
684
    stosw   /* mov [di], ax and di += 2 */
-
 
685
    mov ax, [si+2]
-
 
686
    stosw
-
 
687
    /* read strings (buff+2 bytes) into langblock */
-
 
688
    mov ah, 0x3f   /* Read from File via Handle in BX */
-
 
689
    mov cx, [si+2]
-
 
690
    mov dx, di
-
 
691
    int 0x21
-
 
692
    jnc DONE
-
 
693
 
-
 
694
    /* on error make sure to zero out langblock's header */
-
 
695
    xor cx, cx
-
 
696
    mov [di], cx                 /* langblock id*/
-
 
697
    mov [di + 2], cx /* langblock len */
-
 
698
    mov [di + 4], cx /* 1st string id */
-
 
699
    mov [di + 6], cx /* 1st string len */
-
 
700
 
-
 
701
    /* cleanup and quit */
-
 
702
    FAIL:
-
 
703
    mov [errcode], ax
-
 
704
    DONE:
-
 
705
    /* close file handle if set */
-
 
706
    cmp bx, 0xffff
-
 
707
    je FNOTOPEN
-
 
708
    mov ah, 0x3e  /* DOS 2+ -- Close a File Handle (Handle in BX) */
-
 
709
    int 0x21
-
 
710
    FNOTOPEN:
-
 
711
 
-
 
712
    pop di
-
 
713
    pop si
-
 
714
    pop dx
-
 
715
    pop cx
-
 
716
    pop bx
-
 
717
    pop ax
-
 
718
  }
-
 
719
 
-
 
720
  if (errcode != 0) printf("AX=%04x\r\n", errcode);
-
 
721
}