Subversion Repositories SvarDOS

Rev

Rev 538 | 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
 *
989 mateusz.vi 4
 * Copyright (C) 2021-2022 Mateusz Viste
421 mateuszvis 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
 
533 mateuszvis 29
static enum cmd_result 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)) {
989 mateusz.vi 34
    nls_outputnl(11,0); /* "Displays or sets the active code page number" */
407 mateuszvis 35
    outputnl("");
989 mateusz.vi 36
    nls_outputnl(11,1); /* "CHCP [nnn]" */
407 mateuszvis 37
    outputnl("");
989 mateusz.vi 38
    nls_outputnl(11,2); /* "nnn  Specifies a code page number" */
407 mateuszvis 39
    outputnl("");
989 mateusz.vi 40
    nls_outputnl(11,3); /* "Type CHCP without a parameter to display the active code page number." */
533 mateuszvis 41
    return(CMD_OK);
407 mateuszvis 42
  }
43
 
44
  /* too many parameters */
45
  if (p->argc > 1) {
989 mateusz.vi 46
    nls_outputnl(0,4); /* "Too many parameters" */
533 mateuszvis 47
    return(CMD_FAIL);
407 mateuszvis 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) {
989 mateusz.vi 54
      nls_outputnl(11,4); /* "Invalid code page number" */
533 mateuszvis 55
      return(CMD_FAIL);
407 mateuszvis 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) {
989 mateusz.vi 81
      nls_outputnl(11,5); /* "NLSFUNC not installed" */
407 mateuszvis 82
    } else if (errcode != 0) {
989 mateusz.vi 83
      nls_outputnl(11,6); /* "Failed to change code page" */
533 mateuszvis 84
      return(CMD_FAIL);
407 mateuszvis 85
    }
86
 
87
  } else { /* no parameter given: display active code page */
88
 
89
    _asm {
90
      push ax
91
      push bx
92
      push dx
93
 
94
      mov ax, 0x6601      /* DOS 3.3+ -- Query Active Code Page */
95
      int 0x21            /* CF set on error, current CP in BX */
96
      mov [nnn], bx
97
      jnc DONE
98
      mov [errcode], ax
99
      DONE:
100
 
101
      pop dx
102
      pop bx
103
      pop ax
104
    }
105
    if (errcode == 0) {
989 mateusz.vi 106
      nls_output(11,7); /* Active code page: */
107
      output(" ");
108
      sprintf(p->BUFFER, "%u", nnn);
407 mateuszvis 109
      outputnl(p->BUFFER);
110
    } else {
538 mateuszvis 111
      nls_outputnl_doserr(errcode);
533 mateuszvis 112
      return(CMD_FAIL);
407 mateuszvis 113
    }
114
  }
115
 
533 mateuszvis 116
  return(CMD_OK);
407 mateuszvis 117
}