Subversion Repositories SvarDOS

Rev

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

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