Subversion Repositories SvarDOS

Rev

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

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