Subversion Repositories SvarDOS

Rev

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

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