Subversion Repositories SvarDOS

Rev

Rev 421 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
405 mateuszvis 1
/*
2
 * echo
3
 */
4
 
5
static int cmd_echo(struct cmd_funcparam *p) {
6
  unsigned short offs = FP_OFF(p->cmdline) + 5;
7
  unsigned short segm = FP_SEG(p->cmdline);
8
  unsigned char far *echostatus = MK_FP(p->rmod_seg, RMOD_OFFSET_ECHOFLAG);
9
 
10
  /* display help only if /? is the only argument */
11
  if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
12
    outputnl("Displays messages, or turns command-echoing on or off");
13
    outputnl("");
14
    outputnl("ECHO [ON | OFF]");
15
    outputnl("ECHO [message]");
16
    outputnl("");
17
    outputnl("Type ECHO without parameters to display the current echo setting.");
18
    return(-1);
19
  }
20
 
21
  /* ECHO without any parameter: display current state */
22
  if (p->argc == 0) {
23
    if (*echostatus) {
24
      outputnl("ECHO is on");
25
    } else {
26
      outputnl("ECHO is off");
27
    }
28
    return(-1);
29
  }
30
 
31
  /* ECHO ON */
32
  if ((p->argc == 1) && (imatch(p->argv[0], "on"))) {
33
    *echostatus = 1;
34
    return(-1);
35
  }
36
 
37
  /* ECHO OFF */
38
  if ((p->argc == 1) && (imatch(p->argv[0], "off"))) {
39
    *echostatus = 0;
40
    return(-1);
41
  }
42
 
43
  /* ECHO MSG (start at cmdline+5 since first 5 are "ECHO" + separator) */
44
  _asm {
45
    push ax
46
    push dx
47
    push ds
48
    push si
49
 
50
    mov si, [offs]
51
    cld           /* clear direction flag (DF) so lodsb increments SI */
52
    mov ah, 0x02  /* display char from DL */
53
    mov ds, [segm]
54
    NEXTYBTE:
55
    lodsb         /* load byte at DS:[SI] into AL and inc SI (if DF clear) */
56
    or al, al     /* is AL == 0? then end of string reached */
57
    jz DONE
58
    mov dl, al
59
    int 0x21
60
    jmp NEXTYBTE
61
 
62
    /* output a final CR/LF */
63
    DONE:
64
    mov dl, 0x0D
65
    int 0x21
66
    mov dl, 0x0A
67
    int 0x21
68
 
69
    pop si
70
    pop ds
71
    pop dx
72
    pop ax
73
  }
74
 
75
  return(-1);
76
}