Subversion Repositories SvarDOS

Rev

Rev 414 | Rev 426 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 414 Rev 421
-
 
1
/* This file is part of the SvarCOM project and is published under the terms
-
 
2
 * of the MIT license.
-
 
3
 *
-
 
4
 * Copyright (C) 2021 Mateusz Viste
-
 
5
 *
-
 
6
 * Permission is hereby granted, free of charge, to any person obtaining a
-
 
7
 * copy of this software and associated documentation files (the "Software"),
-
 
8
 * to deal in the Software without restriction, including without limitation
-
 
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
-
 
10
 * and/or sell copies of the Software, and to permit persons to whom the
-
 
11
 * Software is furnished to do so, subject to the following conditions:
-
 
12
 *
-
 
13
 * The above copyright notice and this permission notice shall be included in
-
 
14
 * all copies or substantial portions of the Software.
-
 
15
 *
-
 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-
 
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-
 
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-
 
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-
 
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-
 
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-
 
22
 * DEALINGS IN THE SOFTWARE.
-
 
23
 */
-
 
24
 
1
/*
25
/*
2
 * chcp
26
 * chcp
3
 */
27
 */
4
 
28
 
5
static int cmd_chcp(struct cmd_funcparam *p) {
29
static int cmd_chcp(struct cmd_funcparam *p) {
6
  unsigned short nnn = 0;
30
  unsigned short nnn = 0;
7
  unsigned short errcode = 0;
31
  unsigned short errcode = 0;
8
 
32
 
9
  if (cmd_ishlp(p)) {
33
  if (cmd_ishlp(p)) {
10
    outputnl("Displays or sets the active code page number");
34
    outputnl("Displays or sets the active code page number");
11
    outputnl("");
35
    outputnl("");
12
    outputnl("CHCP [nnn]");
36
    outputnl("CHCP [nnn]");
13
    outputnl("");
37
    outputnl("");
14
    outputnl("nnn  Specifies a code page number");
38
    outputnl("nnn  Specifies a code page number");
15
    outputnl("");
39
    outputnl("");
16
    outputnl("Type CHCP without a parameter to display the active code page number.");
40
    outputnl("Type CHCP without a parameter to display the active code page number.");
17
    return(-1);
41
    return(-1);
18
  }
42
  }
19
 
43
 
20
  /* too many parameters */
44
  /* too many parameters */
21
  if (p->argc > 1) {
45
  if (p->argc > 1) {
22
    outputnl("Too many parameters");
46
    outputnl("Too many parameters");
23
    return(-1);
47
    return(-1);
24
  }
48
  }
25
 
49
 
26
  /* one param? must be numeric in range 1+ */
50
  /* one param? must be numeric in range 1+ */
27
  if (p->argc == 1) {
51
  if (p->argc == 1) {
28
    unsigned char nlsfuncflag = 0;
52
    unsigned char nlsfuncflag = 0;
29
    if (atouns(&nnn, p->argv[0]) != 0) {
53
    if (atouns(&nnn, p->argv[0]) != 0) {
30
      outputnl("Invalid code page number");
54
      outputnl("Invalid code page number");
31
      return(-1);
55
      return(-1);
32
    }
56
    }
33
    _asm {
57
    _asm {
34
      /* verify that NLSFUNC is installed */
58
      /* verify that NLSFUNC is installed */
35
      push ax
59
      push ax
36
      push bx
60
      push bx
37
 
61
 
38
      mov ax, 0x1400    /* DOS 3+ -- is NLSFUNC.EXE installed? */
62
      mov ax, 0x1400    /* DOS 3+ -- is NLSFUNC.EXE installed? */
39
      int 0x2f          /* AL = 0xff -> installed */
63
      int 0x2f          /* AL = 0xff -> installed */
40
      cmp al, 0xff
64
      cmp al, 0xff
41
      jne DONE
65
      jne DONE
42
      mov [nlsfuncflag], 1
66
      mov [nlsfuncflag], 1
43
 
67
 
44
      /* set code page to nnn */
68
      /* set code page to nnn */
45
 
69
 
46
      mov ax, 0x6602    /* DOS 3.3+ -- Activate Code Page */
70
      mov ax, 0x6602    /* DOS 3.3+ -- Activate Code Page */
47
      mov bx, [nnn]
71
      mov bx, [nnn]
48
      int 0x21          /* CF set on error and err code in AX */
72
      int 0x21          /* CF set on error and err code in AX */
49
      jnc DONE
73
      jnc DONE
50
      mov [errcode], ax /* store err code in nnn on failure */
74
      mov [errcode], ax /* store err code in nnn on failure */
51
      DONE:
75
      DONE:
52
 
76
 
53
      pop bx
77
      pop bx
54
      pop ax
78
      pop ax
55
    }
79
    }
56
    if (nlsfuncflag == 0) {
80
    if (nlsfuncflag == 0) {
57
      outputnl("NLSFUNC not installed");
81
      outputnl("NLSFUNC not installed");
58
    } else if (errcode != 0) {
82
    } else if (errcode != 0) {
59
      outputnl("Failed to change code page");
83
      outputnl("Failed to change code page");
60
    }
84
    }
61
 
85
 
62
  } else { /* no parameter given: display active code page */
86
  } else { /* no parameter given: display active code page */
63
 
87
 
64
    _asm {
88
    _asm {
65
      push ax
89
      push ax
66
      push bx
90
      push bx
67
      push dx
91
      push dx
68
 
92
 
69
      mov ax, 0x6601      /* DOS 3.3+ -- Query Active Code Page */
93
      mov ax, 0x6601      /* DOS 3.3+ -- Query Active Code Page */
70
      int 0x21            /* CF set on error, current CP in BX */
94
      int 0x21            /* CF set on error, current CP in BX */
71
      mov [nnn], bx
95
      mov [nnn], bx
72
      jnc DONE
96
      jnc DONE
73
      mov [errcode], ax
97
      mov [errcode], ax
74
      DONE:
98
      DONE:
75
 
99
 
76
      pop dx
100
      pop dx
77
      pop bx
101
      pop bx
78
      pop ax
102
      pop ax
79
    }
103
    }
80
    if (errcode == 0) {
104
    if (errcode == 0) {
81
      sprintf(p->BUFFER, "Active code page: %d", nnn);
105
      sprintf(p->BUFFER, "Active code page: %d", nnn);
82
      outputnl(p->BUFFER);
106
      outputnl(p->BUFFER);
83
    } else {
107
    } else {
84
      outputnl(doserr(errcode));
108
      outputnl(doserr(errcode));
85
    }
109
    }
86
  }
110
  }
87
 
111
 
88
  return(-1);
112
  return(-1);
89
}
113
}
90
 
114