Subversion Repositories SvarDOS

Rev

Rev 410 | Rev 421 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
407 mateuszvis 1
/*
2
 * chcp
3
 */
4
 
5
static int cmd_chcp(struct cmd_funcparam *p) {
410 mateuszvis 6
  unsigned short nnn = 0;
407 mateuszvis 7
  unsigned short errcode = 0;
8
 
9
  if (cmd_ishlp(p)) {
10
    outputnl("Displays or sets the active code page number");
11
    outputnl("");
12
    outputnl("CHCP [nnn]");
13
    outputnl("");
14
    outputnl("nnn  Specifies a code page number");
15
    outputnl("");
16
    outputnl("Type CHCP without a parameter to display the active code page number.");
17
    return(-1);
18
  }
19
 
20
  /* too many parameters */
21
  if (p->argc > 1) {
22
    outputnl("Too many parameters");
23
    return(-1);
24
  }
25
 
26
  /* one param? must be numeric in range 1+ */
27
  if (p->argc == 1) {
414 mateuszvis 28
    unsigned char nlsfuncflag = 0;
410 mateuszvis 29
    if (atouns(&nnn, p->argv[0]) != 0) {
407 mateuszvis 30
      outputnl("Invalid code page number");
31
      return(-1);
32
    }
33
    _asm {
414 mateuszvis 34
      /* verify that NLSFUNC is installed */
407 mateuszvis 35
      push ax
36
      push bx
37
 
414 mateuszvis 38
      mov ax, 0x1400    /* DOS 3+ -- is NLSFUNC.EXE installed? */
39
      int 0x2f          /* AL = 0xff -> installed */
40
      cmp al, 0xff
41
      jne DONE
42
      mov [nlsfuncflag], 1
43
 
44
      /* set code page to nnn */
45
 
407 mateuszvis 46
      mov ax, 0x6602    /* DOS 3.3+ -- Activate Code Page */
47
      mov bx, [nnn]
48
      int 0x21          /* CF set on error and err code in AX */
49
      jnc DONE
50
      mov [errcode], ax /* store err code in nnn on failure */
51
      DONE:
52
 
53
      pop bx
54
      pop ax
55
    }
414 mateuszvis 56
    if (nlsfuncflag == 0) {
407 mateuszvis 57
      outputnl("NLSFUNC not installed");
58
    } else if (errcode != 0) {
59
      outputnl("Failed to change code page");
60
    }
61
 
62
  } else { /* no parameter given: display active code page */
63
 
64
    _asm {
65
      push ax
66
      push bx
67
      push dx
68
 
69
      mov ax, 0x6601      /* DOS 3.3+ -- Query Active Code Page */
70
      int 0x21            /* CF set on error, current CP in BX */
71
      mov [nnn], bx
72
      jnc DONE
73
      mov [errcode], ax
74
      DONE:
75
 
76
      pop dx
77
      pop bx
78
      pop ax
79
    }
80
    if (errcode == 0) {
81
      sprintf(p->BUFFER, "Active code page: %d", nnn);
82
      outputnl(p->BUFFER);
83
    } else {
84
      outputnl(doserr(errcode));
85
    }
86
  }
87
 
88
  return(-1);
89
}