Subversion Repositories SvarDOS

Rev

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