Subversion Repositories SvarDOS

Rev

Rev 410 | Go to most recent revision | Details | 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) {
6
  short nnn = 0;
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) {
28
    nnn = atoi(p->argv[0]);
29
    if (nnn < 1) {
30
      outputnl("Invalid code page number");
31
      return(-1);
32
    }
33
    /* set code page to nnn */
34
    _asm {
35
      push ax
36
      push bx
37
 
38
      mov ax, 0x6602    /* DOS 3.3+ -- Activate Code Page */
39
      mov bx, [nnn]
40
      int 0x21          /* CF set on error and err code in AX */
41
      jnc DONE
42
      mov [errcode], ax /* store err code in nnn on failure */
43
      DONE:
44
 
45
      pop bx
46
      pop ax
47
    }
48
    if (errcode == 1) {   /* DOS ERR 1 means "Function number invalid" (ie. no NLS) */
49
      outputnl("NLSFUNC not installed");
50
    } else if (errcode != 0) {
51
      outputnl("Failed to change code page");
52
    }
53
 
54
  } else { /* no parameter given: display active code page */
55
 
56
    _asm {
57
      push ax
58
      push bx
59
      push dx
60
 
61
      mov ax, 0x6601      /* DOS 3.3+ -- Query Active Code Page */
62
      int 0x21            /* CF set on error, current CP in BX */
63
      mov [nnn], bx
64
      jnc DONE
65
      mov [errcode], ax
66
      DONE:
67
 
68
      pop dx
69
      pop bx
70
      pop ax
71
    }
72
    if (errcode == 0) {
73
      sprintf(p->BUFFER, "Active code page: %d", nnn);
74
      outputnl(p->BUFFER);
75
    } else {
76
      outputnl(doserr(errcode));
77
    }
78
  }
79
 
80
  return(-1);
81
}