Subversion Repositories SvarDOS

Rev

Rev 426 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
421 mateuszvis 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
 
407 mateuszvis 25
/*
26
 * chcp
27
 */
28
 
29
static int cmd_chcp(struct cmd_funcparam *p) {
410 mateuszvis 30
  unsigned short nnn = 0;
407 mateuszvis 31
  unsigned short errcode = 0;
32
 
33
  if (cmd_ishlp(p)) {
34
    outputnl("Displays or sets the active code page number");
35
    outputnl("");
36
    outputnl("CHCP [nnn]");
37
    outputnl("");
38
    outputnl("nnn  Specifies a code page number");
39
    outputnl("");
40
    outputnl("Type CHCP without a parameter to display the active code page number.");
41
    return(-1);
42
  }
43
 
44
  /* too many parameters */
45
  if (p->argc > 1) {
46
    outputnl("Too many parameters");
47
    return(-1);
48
  }
49
 
50
  /* one param? must be numeric in range 1+ */
51
  if (p->argc == 1) {
414 mateuszvis 52
    unsigned char nlsfuncflag = 0;
426 mateuszvis 53
    if (atous(&nnn, p->argv[0]) != 0) {
407 mateuszvis 54
      outputnl("Invalid code page number");
55
      return(-1);
56
    }
57
    _asm {
414 mateuszvis 58
      /* verify that NLSFUNC is installed */
407 mateuszvis 59
      push ax
60
      push bx
61
 
414 mateuszvis 62
      mov ax, 0x1400    /* DOS 3+ -- is NLSFUNC.EXE installed? */
63
      int 0x2f          /* AL = 0xff -> installed */
64
      cmp al, 0xff
65
      jne DONE
66
      mov [nlsfuncflag], 1
67
 
68
      /* set code page to nnn */
69
 
407 mateuszvis 70
      mov ax, 0x6602    /* DOS 3.3+ -- Activate Code Page */
71
      mov bx, [nnn]
72
      int 0x21          /* CF set on error and err code in AX */
73
      jnc DONE
74
      mov [errcode], ax /* store err code in nnn on failure */
75
      DONE:
76
 
77
      pop bx
78
      pop ax
79
    }
414 mateuszvis 80
    if (nlsfuncflag == 0) {
407 mateuszvis 81
      outputnl("NLSFUNC not installed");
82
    } else if (errcode != 0) {
83
      outputnl("Failed to change code page");
84
    }
85
 
86
  } else { /* no parameter given: display active code page */
87
 
88
    _asm {
89
      push ax
90
      push bx
91
      push dx
92
 
93
      mov ax, 0x6601      /* DOS 3.3+ -- Query Active Code Page */
94
      int 0x21            /* CF set on error, current CP in BX */
95
      mov [nnn], bx
96
      jnc DONE
97
      mov [errcode], ax
98
      DONE:
99
 
100
      pop dx
101
      pop bx
102
      pop ax
103
    }
104
    if (errcode == 0) {
105
      sprintf(p->BUFFER, "Active code page: %d", nnn);
106
      outputnl(p->BUFFER);
107
    } else {
108
      outputnl(doserr(errcode));
109
    }
110
  }
111
 
112
  return(-1);
113
}