Subversion Repositories SvarDOS

Rev

Rev 534 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
421 mateuszvis 1
/* This file is part of the SvarCOM project and is published under the terms
2
 * of the MIT license.
3
 *
989 mateusz.vi 4
 * Copyright (C) 2021-2022 Mateusz Viste
421 mateuszvis 5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
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
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
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,
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
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
22
 * DEALINGS IN THE SOFTWARE.
23
 */
24
 
405 mateuszvis 25
/*
26
 * echo
27
 */
28
 
533 mateuszvis 29
static enum cmd_result cmd_echo(struct cmd_funcparam *p) {
534 mateuszvis 30
  const char *arg = p->cmdline + 5;
405 mateuszvis 31
 
32
  /* display help only if /? is the only argument */
33
  if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
989 mateusz.vi 34
    nls_outputnl(31,0); /* "Displays messages, or turns command-echoing on or off" */
405 mateuszvis 35
    outputnl("");
36
    outputnl("ECHO [ON | OFF]");
989 mateusz.vi 37
    nls_outputnl(31,1); /* "ECHO [message]" */
405 mateuszvis 38
    outputnl("");
989 mateusz.vi 39
    nls_outputnl(31,2); /* "Type ECHO without parameters to display the current setting." */
533 mateuszvis 40
    return(CMD_OK);
405 mateuszvis 41
  }
42
 
43
  /* ECHO without any parameter: display current state */
44
  if (p->argc == 0) {
475 mateuszvis 45
    if (p->rmod->flags & FLAG_ECHOFLAG) {
989 mateusz.vi 46
      nls_outputnl(31,3); /* "ECHO is on" */
405 mateuszvis 47
    } else {
989 mateusz.vi 48
      nls_outputnl(31,4); /* "ECHO is off" */
405 mateuszvis 49
    }
533 mateuszvis 50
    return(CMD_OK);
405 mateuszvis 51
  }
52
 
53
  /* ECHO ON */
54
  if ((p->argc == 1) && (imatch(p->argv[0], "on"))) {
475 mateuszvis 55
    p->rmod->flags |= FLAG_ECHOFLAG;
533 mateuszvis 56
    return(CMD_OK);
405 mateuszvis 57
  }
58
 
59
  /* ECHO OFF */
60
  if ((p->argc == 1) && (imatch(p->argv[0], "off"))) {
475 mateuszvis 61
    p->rmod->flags &= ~FLAG_ECHOFLAG;
533 mateuszvis 62
    return(CMD_OK);
405 mateuszvis 63
  }
64
 
65
  /* ECHO MSG (start at cmdline+5 since first 5 are "ECHO" + separator) */
66
  _asm {
67
    push ax
68
    push dx
69
    push si
70
 
534 mateuszvis 71
    mov si, [arg]
405 mateuszvis 72
    cld           /* clear direction flag (DF) so lodsb increments SI */
73
    mov ah, 0x02  /* display char from DL */
74
    NEXTYBTE:
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 */
77
    jz DONE
78
    mov dl, al
79
    int 0x21
80
    jmp NEXTYBTE
81
 
82
    /* output a final CR/LF */
83
    DONE:
84
    mov dl, 0x0D
85
    int 0x21
86
    mov dl, 0x0A
87
    int 0x21
88
 
89
    pop si
90
    pop dx
91
    pop ax
92
  }
93
 
533 mateuszvis 94
  return(CMD_OK);
405 mateuszvis 95
}