Subversion Repositories SvarDOS

Rev

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

Rev 538 Rev 989
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 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
 * type
26
 * type
27
 */
27
 */
28
 
28
 
29
static enum cmd_result cmd_type(struct cmd_funcparam *p) {
29
static enum cmd_result cmd_type(struct cmd_funcparam *p) {
30
  char *buff = p->BUFFER;
30
  char *buff = p->BUFFER;
31
  const char *fname = p->argv[0];
31
  const char *fname = p->argv[0];
32
  unsigned short err = 0;
32
  unsigned short err = 0;
33
 
33
 
34
  if (cmd_ishlp(p)) {
34
  if (cmd_ishlp(p)) {
35
    outputnl("Displays the contents of a text file.");
35
    nls_outputnl(21,0); /* "Displays the contents of a text file." */
36
    outputnl("");
36
    outputnl("");
37
    outputnl("TYPE [drive:][path]filename");
37
    nls_outputnl(21,1); /* "TYPE [drive:][path]filename" */
38
    return(CMD_OK);
38
    return(CMD_OK);
39
  }
39
  }
40
 
40
 
41
  if (p->argc == 0) {
41
  if (p->argc == 0) {
42
    outputnl("Required parameter missing");
42
    nls_outputnl(0,7); /* "Required parameter missing" */
43
    return(CMD_FAIL);
43
    return(CMD_FAIL);
44
  }
44
  }
45
 
45
 
46
  if (p->argc > 1) {
46
  if (p->argc > 1) {
47
    outputnl("Too many parameters");
47
    nls_outputnl(0,4); /* "Too many parameters" */
48
    return(CMD_FAIL);
48
    return(CMD_FAIL);
49
  }
49
  }
50
 
50
 
51
  /* if here then display the file */
51
  /* if here then display the file */
52
  _asm {
52
  _asm {
53
    push ax
53
    push ax
54
    push bx
54
    push bx
55
    push cx
55
    push cx
56
    push dx
56
    push dx
57
    push si
57
    push si
58
 
58
 
59
    mov ax, 0x3d00 /* open file via handle, access mode in AL (0 = read) */
59
    mov ax, 0x3d00 /* open file via handle, access mode in AL (0 = read) */
60
    mov dx, fname
60
    mov dx, fname
61
    int 0x21       /* file handle in ax on success (CF clear) */
61
    int 0x21       /* file handle in ax on success (CF clear) */
62
    jnc FILE_OPEN_OK
62
    jnc FILE_OPEN_OK
63
    mov [err], ax  /* on error AX contains the DOS err code */
63
    mov [err], ax  /* on error AX contains the DOS err code */
64
    jmp FOPENFAIL
64
    jmp FOPENFAIL
65
    FILE_OPEN_OK:
65
    FILE_OPEN_OK:
66
    /* copy obtained file handle to BX */
66
    /* copy obtained file handle to BX */
67
    mov bx, ax
67
    mov bx, ax
68
 
68
 
69
    READNEXTBLOCK:
69
    READNEXTBLOCK:
70
    /* read file block by block */
70
    /* read file block by block */
71
    mov cx, 1024   /* read 1K at a time */
71
    mov cx, 1024   /* read 1K at a time */
72
    mov dx, buff
72
    mov dx, buff
73
    mov ah, 0x3f   /* read CX bytes from file handle in BX and write to DS:DX */
73
    mov ah, 0x3f   /* read CX bytes from file handle in BX and write to DS:DX */
74
    int 0x21       /* CF set on error, AX=errno or AX=number of bytes read */
74
    int 0x21       /* CF set on error, AX=errno or AX=number of bytes read */
75
    jc GOTERROR    /* abort on error */
75
    jc GOTERROR    /* abort on error */
76
    test ax, ax    /* EOF? */
76
    test ax, ax    /* EOF? */
77
    jz ENDFILE
77
    jz ENDFILE
78
    /* display read block (AX=len) */
78
    /* display read block (AX=len) */
79
    mov si, dx     /* preset DS:SI to DS:DX (DL will be reused soon) */
79
    mov si, dx     /* preset DS:SI to DS:DX (DL will be reused soon) */
80
    mov cx, ax     /* set loop count to CX */
80
    mov cx, ax     /* set loop count to CX */
81
    mov ah, 0x02   /* write character in DL to stdout */
81
    mov ah, 0x02   /* write character in DL to stdout */
82
    NEXTCHAR:
82
    NEXTCHAR:
83
    mov dl, [si]
83
    mov dl, [si]
84
    inc si
84
    inc si
85
    int 0x21
85
    int 0x21
86
    loopnz NEXTCHAR /* CX-- ; jnz NEXTCHAR (display CX characters) */
86
    loopnz NEXTCHAR /* CX-- ; jnz NEXTCHAR (display CX characters) */
87
    /* read (and display) next block */
87
    /* read (and display) next block */
88
    jmp READNEXTBLOCK
88
    jmp READNEXTBLOCK
89
 
89
 
90
    GOTERROR:
90
    GOTERROR:
91
    mov [err], ax
91
    mov [err], ax
92
 
92
 
93
    ENDFILE:
93
    ENDFILE:
94
    /* close file */
94
    /* close file */
95
    mov ah, 0x3e   /* close file handle (file handle already in BX) */
95
    mov ah, 0x3e   /* close file handle (file handle already in BX) */
96
    int 0x21
96
    int 0x21
97
 
97
 
98
    FOPENFAIL:
98
    FOPENFAIL:
99
 
99
 
100
    pop si
100
    pop si
101
    pop dx
101
    pop dx
102
    pop cx
102
    pop cx
103
    pop bx
103
    pop bx
104
    pop ax
104
    pop ax
105
  }
105
  }
106
 
106
 
107
  if (err != 0) {
107
  if (err != 0) {
108
    nls_outputnl_doserr(err);
108
    nls_outputnl_doserr(err);
109
    return(CMD_FAIL);
109
    return(CMD_FAIL);
110
  }
110
  }
111
 
111
 
112
  return(CMD_OK);
112
  return(CMD_OK);
113
}
113
}
114
 
114