Subversion Repositories SvarDOS

Rev

Rev 989 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 989 Rev 1203
1
/* This file is part of the SvarCOM project and is published under the terms
1
/* This file is part of the SvarCOM project and is published under the terms
2
 * of the MIT license.
2
 * of the MIT license.
3
 *
3
 *
4
 * Copyright (C) 2021-2022 Mateusz Viste
4
 * Copyright (C) 2021-2022 Mateusz Viste
5
 *
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
 * and/or sell copies of the Software, and to permit persons to whom the
10
 * and/or sell copies of the Software, and to permit persons to whom the
11
 * Software is furnished to do so, subject to the following conditions:
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
12
 *
13
 * The above copyright notice and this permission notice shall be included in
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
14
 * all copies or substantial portions of the Software.
15
 *
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
 * DEALINGS IN THE SOFTWARE.
22
 * DEALINGS IN THE SOFTWARE.
23
 */
23
 */
24
 
24
 
25
/*
25
/*
26
 * echo
26
 * echo
27
 */
27
 */
28
 
28
 
29
static enum cmd_result cmd_echo(struct cmd_funcparam *p) {
29
static enum cmd_result cmd_echo(struct cmd_funcparam *p) {
30
  const char *arg = p->cmdline + 5;
30
  const char *arg = p->cmdline + 5;
31
 
31
 
32
  /* display help only if /? is the only argument */
32
  /* display help only if /? is the only argument */
33
  if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
33
  if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
34
    nls_outputnl(31,0); /* "Displays messages, or turns command-echoing on or off" */
34
    nls_outputnl(31,0); /* "Displays messages, or turns command-echoing on or off" */
35
    outputnl("");
35
    outputnl("");
36
    outputnl("ECHO [ON | OFF]");
36
    outputnl("ECHO [ON | OFF]");
37
    nls_outputnl(31,1); /* "ECHO [message]" */
37
    nls_outputnl(31,1); /* "ECHO [message]" */
38
    outputnl("");
38
    outputnl("");
39
    nls_outputnl(31,2); /* "Type ECHO without parameters to display the current setting." */
39
    nls_outputnl(31,2); /* "Type ECHO without parameters to display the current setting." */
40
    return(CMD_OK);
40
    return(CMD_OK);
41
  }
41
  }
42
 
42
 
43
  /* ECHO without any parameter: display current state */
43
  /* ECHO without any parameter: display current state */
44
  if (p->argc == 0) {
44
  if (p->argc == 0) {
45
    if (p->rmod->flags & FLAG_ECHOFLAG) {
45
    if (p->rmod->flags & FLAG_ECHOFLAG) {
46
      nls_outputnl(31,3); /* "ECHO is on" */
46
      nls_outputnl(31,3); /* "ECHO is on" */
47
    } else {
47
    } else {
48
      nls_outputnl(31,4); /* "ECHO is off" */
48
      nls_outputnl(31,4); /* "ECHO is off" */
49
    }
49
    }
50
    return(CMD_OK);
50
    return(CMD_OK);
51
  }
51
  }
52
 
52
 
53
  /* ECHO ON */
53
  /* ECHO ON */
54
  if ((p->argc == 1) && (imatch(p->argv[0], "on"))) {
54
  if ((p->argc == 1) && (imatch(p->argv[0], "on"))) {
55
    p->rmod->flags |= FLAG_ECHOFLAG;
55
    p->rmod->flags |= FLAG_ECHOFLAG;
56
    return(CMD_OK);
56
    return(CMD_OK);
57
  }
57
  }
58
 
58
 
59
  /* ECHO OFF */
59
  /* ECHO OFF */
60
  if ((p->argc == 1) && (imatch(p->argv[0], "off"))) {
60
  if ((p->argc == 1) && (imatch(p->argv[0], "off"))) {
61
    p->rmod->flags &= ~FLAG_ECHOFLAG;
61
    p->rmod->flags &= ~FLAG_ECHOFLAG;
62
    return(CMD_OK);
62
    return(CMD_OK);
63
  }
63
  }
64
 
64
 
65
  /* ECHO MSG (start at cmdline+5 since first 5 are "ECHO" + separator) */
65
  /* ECHO MSG (start at cmdline+5 since first 5 are "ECHO" + separator) */
66
  _asm {
66
  _asm {
67
    push ax
67
    push ax
68
    push dx
68
    push dx
69
    push si
69
    push si
70
 
70
 
71
    mov si, [arg]
71
    mov si, [arg]
72
    cld           /* clear direction flag (DF) so lodsb increments SI */
72
    cld           /* clear direction flag (DF) so lodsb increments SI */
73
    mov ah, 0x02  /* display char from DL */
73
    mov ah, 0x02  /* display char from DL */
74
    NEXTYBTE:
74
    NEXTYBTE:
75
    lodsb         /* load byte at DS:[SI] into AL and inc SI (if DF clear) */
75
    lodsb         /* load byte at DS:[SI] into AL and inc SI (if DF clear) */
76
    or al, al     /* is AL == 0? then end of string reached */
76
    or al, al     /* is AL == 0? then end of string reached */
77
    jz DONE
77
    jz DONE
78
    mov dl, al
78
    mov dl, al
79
    int 0x21
79
    int 0x21
80
    jmp NEXTYBTE
80
    jmp NEXTYBTE
81
 
81
 
82
    /* output a final CR/LF */
82
    /* output a final CR/LF */
83
    DONE:
83
    DONE:
84
    mov dl, 0x0D
84
    mov dl, 0x0D
85
    int 0x21
85
    int 0x21
86
    mov dl, 0x0A
86
    mov dl, 0x0A
87
    int 0x21
87
    int 0x21
88
 
88
 
89
    pop si
89
    pop si
90
    pop dx
90
    pop dx
91
    pop ax
91
    pop ax
92
  }
92
  }
93
 
93
 
94
  return(CMD_OK);
94
  return(CMD_OK);
95
}
95
}
96
 
96