Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 538 → Rev 537

/svarcom/trunk/cmd/cd.c
97,7 → 97,7
}
}
if (err != 0) {
nls_outputnl_doserr(err);
outputnl(doserr(err));
return(CMD_FAIL);
}
}
/svarcom/trunk/cmd/chcp.c
106,7 → 106,7
sprintf(p->BUFFER, "Active code page: %d", nnn);
outputnl(p->BUFFER);
} else {
nls_outputnl_doserr(errcode);
outputnl(doserr(errcode));
return(CMD_FAIL);
}
}
/svarcom/trunk/cmd/copy.c
283,7 → 283,7
if (t != 0) {
output(setup->src[i]);
output(" - ");
nls_outputnl_doserr(t);
outputnl(doserr(t));
continue;
}
cursrclen = strlen(setup->cursrc); /* remember cursrc length */
347,7 → 347,7
 
t = cmd_copy_internal(setup->dst, 0, setup->cursrc, 0, appendflag, setup->databuf, setup->databufsz);
if (t != 0) {
nls_outputnl_doserr(t);
outputnl(doserr(t));
return(CMD_FAIL);
}
 
/svarcom/trunk/cmd/date.c
149,7 → 149,7
 
i = nls_getpatterns(nls);
if (i != 0) {
nls_outputnl_doserr(i);
outputnl(doserr(i));
return(CMD_FAIL);
}
 
/svarcom/trunk/cmd/del.c
97,7 → 97,7
err = findfirst(dta, buff, DOS_ATTR_RO | DOS_ATTR_SYS | DOS_ATTR_HID);
if (err != 0) { /* report the error only if query had no wildcards */
for (i = 0; buff[i] != 0; i++) if (buff[i] == '?') break;
if (buff[i] == 0) nls_outputnl_doserr(err);
if (buff[i] == 0) outputnl(doserr(err));
break;
}
} else {
133,7 → 133,7
if (err != 0) {
output(fname);
output(": ");
nls_outputnl_doserr(err);
outputnl(doserr(err));
break;
}
}
/svarcom/trunk/cmd/dir.c
154,7 → 154,7
}
 
i = nls_getpatterns(nls);
if (i != 0) nls_outputnl_doserr(i);
if (i != 0) outputnl(doserr(i));
 
/* parse command line */
for (i = 0; i < p->argc; i++) {
230,7 → 230,7
i = file_truename(filespecptr, p->BUFFER);
}
if (i != 0) {
nls_outputnl_doserr(i);
outputnl(doserr(i));
return(CMD_FAIL);
}
 
258,7 → 258,7
 
i = findfirst(dta, p->BUFFER, DOS_ATTR_RO | DOS_ATTR_HID | DOS_ATTR_SYS | DOS_ATTR_DIR | DOS_ATTR_ARC);
if (i != 0) {
nls_outputnl_doserr(i);
outputnl(doserr(i));
return(CMD_FAIL);
}
 
352,7 → 352,7
if (flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
/* xxxx bytes free */
i = cmd_dir_df(&summary_totsz, drv);
if (i != 0) nls_outputnl_doserr(i);
if (i != 0) outputnl(doserr(i));
alignpos += 13 + 13;
memset(buff2, ' ', alignpos); /* align the freebytes value to same column as totbytes */
i = nls_format_number(buff2 + alignpos, summary_totsz, nls);
/svarcom/trunk/cmd/mkdir.c
69,7 → 69,7
}
 
if (err != 0) {
nls_outputnl_doserr(err);
outputnl(doserr(err));
return(CMD_FAIL);
}
 
/svarcom/trunk/cmd/rename.c
54,7 → 54,7
/* convert src to truename format */
i = file_truename(p->argv[0], src);
if (i != 0) {
nls_outputnl_doserr(i);
outputnl(doserr(i));
return(CMD_FAIL);
}
 
83,7 → 83,7
/* apply truename to dest to normalize wildcards into ? chars */
i = file_truename(buff1, dst);
if (i != 0) {
nls_outputnl_doserr(i);
outputnl(doserr(i));
return(CMD_FAIL);
}
 
101,7 → 101,7
*/
 
i = findfirst(dta, src, 0);
if (i != 0) nls_outputnl_doserr(i);
if (i != 0) outputnl(doserr(i));
 
while (i == 0) {
/* write found fname into buff1 and dst fname into buff2 - both in FCB
153,7 → 153,7
output(" -> ");
output(buff2 + fnameoffset);
output(" ");
nls_outputnl_doserr(i);
outputnl(doserr(i));
}
/* next please */
i = findnext(dta);
/svarcom/trunk/cmd/rmdir.c
69,7 → 69,7
}
 
if (err != 0) {
nls_outputnl_doserr(err);
outputnl(doserr(err));
return(CMD_FAIL);
}
 
/svarcom/trunk/cmd/time.c
152,7 → 152,7
 
i = nls_getpatterns(nls);
if (i != 0) {
nls_outputnl_doserr(i);
outputnl(doserr(i));
return(CMD_FAIL);
}
 
/svarcom/trunk/cmd/type.c
105,7 → 105,7
}
 
if (err != 0) {
nls_outputnl_doserr(err);
outputnl(doserr(err));
return(CMD_FAIL);
}
 
/svarcom/trunk/cmd.c
33,6 → 33,7
#include <stdlib.h>
#include <string.h>
 
#include "doserr.h"
#include "env.h"
#include "helpers.h"
#include "redir.h"
230,7 → 231,7
pop ax
}
if (curdrive == drive) return(CMD_OK);
nls_outputnl_doserr(0x0f);
outputnl(doserr(0x0f));
return(CMD_FAIL);
}
}
/svarcom/trunk/command.c
31,6 → 31,7
#include <process.h>
 
#include "cmd.h"
#include "doserr.h"
#include "env.h"
#include "helpers.h"
#include "redir.h"
623,7 → 624,7
 
/* printf("blen=%u filepos_cx=%u filepos_dx=%u\r\n", blen, filepos_cx, filepos_dx); */
 
if (errv != 0) nls_outputnl_doserr(errv);
if (errv != 0) outputnl(doserr(errv));
 
/* on EOF - abort processing the bat file */
if (blen == 0) goto OOPS;
/svarcom/trunk/doserr.c
0,0 → 1,80
/* This file is part of the SvarCOM project and is published under the terms
* of the MIT license.
*
* Copyright (C) 2021 Mateusz Viste
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
 
/*
* translates a DOS extended error into a human string
* (as defined by INT 21/AH=59h/BX=0000h)
*/
 
#include <stdio.h>
 
#include "doserr.h"
 
const char *doserr(unsigned short err) {
static char buf[18] = "DOS ERROR 0x";
switch (err) {
case 0x00: return("Success");
case 0x01: return("Function number invalid");
case 0x02: return("File not found");
case 0x03: return("Path not found");
case 0x04: return("Too many open files (no handles available)");
case 0x05: return("Access denied");
case 0x06: return("Invalid handle");
case 0x07: return("Memory control block destroyed");
case 0x08: return("Insufficient memory");
case 0x09: return("Memory block address invalid");
case 0x0A: return("Environment invalid");
case 0x0B: return("Format invalid");
case 0x0C: return("Access code invalid");
case 0x0D: return("Data invalid");
case 0x0F: return("Invalid drive");
case 0x10: return("Attemted to remove current directory");
case 0x11: return("Not same device");
case 0x12: return("No more files");
case 0x13: return("Disk write-protected");
case 0x14: return("Unknown unit");
case 0x15: return("Drive not ready");
case 0x16: return("Unknown command");
case 0x17: return("Data error (CRC)");
case 0x18: return("Bad request structure length");
case 0x19: return("Seek error");
case 0x1A: return("Unknown media type (non-DOS disk)");
case 0x1B: return("Sector not found");
case 0x1C: return("Printer out of paper");
case 0x1D: return("Write fault");
case 0x1E: return("Read fault");
case 0x1F: return("General failure");
case 0x20: return("Sharing violation");
case 0x21: return("Lock violation");
case 0x22: return("Disk change invalid");
case 0x23: return("FCB unavailable");
case 0x24: return("Sharing buffer overflow");
case 0x25: return("Code page mismatch");
case 0x26: return("Cannot complete file operations (EOF / out of input)");
case 0x27: return("Insufficient disk space");
default:
sprintf(buf + 12, "%02X", err);
return(buf);
}
}
/svarcom/trunk/doserr.h
0,0 → 1,35
/* This file is part of the SvarCOM project and is published under the terms
* of the MIT license.
*
* Copyright (C) 2021 Mateusz Viste
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
 
/*
* translates a DOS extended error into a human string
* (as defined by INT 21/AH=59h/BX=0000h)
*/
 
#ifndef DOSERR_H
#define DOSERR_H
 
const char *doserr(unsigned short err);
 
#endif
/svarcom/trunk/helpers.c
68,9 → 68,9
}
 
 
/* outputs a NULL-terminated string to handle (1=stdout 2=stderr) */
void output_internal(const char *s, unsigned char nl, unsigned char handle) {
const static unsigned char *crlf = "\r\n";
/* outputs a NULL-terminated string to stdout */
void output_internal(const char *s, unsigned char nl) {
const static unsigned char *crlf = "\r\n$";
_asm {
push ds
pop es /* make sure es=ds (scasb uses es) */
88,8 → 88,7
 
/* output by writing to stdout */
/* mov ah, 0x40 */ /* DOS 2+ -- write to file via handle */
xor bh, bh
mov bl, handle /* set handle (1=stdout 2=stderr) */
mov bx, 1 /* handle 1 is always stdout */
/* mov cx, xxx */ /* write CX bytes */
/* mov dx, s */ /* DS:DX is the source of bytes to "write" */
int 0x21
96,11 → 95,9
WRITEDONE:
 
/* print out a CR/LF trailer if nl set */
test byte ptr [nl], 0xff
or byte ptr [nl], 0
jz FINITO
/* bx still contains handle */
mov ah, 0x40 /* "write to file" */
mov cx, 2
mov ah, 0x09
mov dx, crlf
int 0x21
FINITO:
108,44 → 105,25
}
 
 
static const char *nlsblock_findstr(unsigned short id) {
void nls_output_internal(unsigned short id, unsigned char nl) {
const char *ptr = langblock + 4; /* first 4 bytes are lang id and lang len */
const char *NOTFOUND = "NLS_STRING_NOT_FOUND";
/* find the string id in langblock memory */
for (;;) {
if (((unsigned short *)ptr)[0] == id) {
ptr += 3;
return(ptr);
break;
}
if (ptr[2] == 0) return(NULL);
if (ptr[2] == 0) {
ptr = NOTFOUND;
break;
}
ptr += ptr[2] + 3;
}
output_internal(ptr, nl);
}
 
 
void nls_output_internal(unsigned short id, unsigned char nl) {
const char *NOTFOUND = "NLS_STRING_NOT_FOUND";
const char *ptr = nlsblock_findstr(id);
if (ptr == NULL) ptr = NOTFOUND;
output_internal(ptr, nl, hSTDOUT);
}
 
 
/* output DOS error e to stderr */
void nls_outputnl_doserr(unsigned short e) {
static char errstr[16];
const char *ptr = NULL;
/* find string in nls block */
if (e < 0xff) ptr = nlsblock_findstr(0xff00 | e);
/* if not found, use a fallback */
if (ptr == NULL) {
sprintf(errstr, "DOS ERR %u", e);
ptr = errstr;
}
/* display */
output_internal(ptr, 1, hSTDERR);
}
 
 
/* find first matching files using a FindFirst DOS call
* returns 0 on success or a DOS err code on failure */
unsigned short findfirst(struct DTA *dta, const char *pattern, unsigned short attr) {
/svarcom/trunk/helpers.h
34,23 → 34,17
/* returns zero if s1 starts with s2 */
int strstartswith(const char *s1, const char *s2);
 
/* outputs a NULL-terminated string to handle (hSTDOUT or hSTDERR) */
void output_internal(const char *s, unsigned char nl, unsigned char handle);
/* outputs a NULL-terminated string to stdout */
void output_internal(const char *s, unsigned char nl);
 
/* outputs a NULL-terminated NLS string to stdout */
void nls_output_internal(unsigned short id, unsigned char nl);
 
#define hSTDOUT 1
#define hSTDERR 2
 
#define output(x) output_internal(x, 0, hSTDOUT)
#define outputnl(x) output_internal(x, 1, hSTDOUT)
#define output(x) output_internal(x, 0)
#define outputnl(x) output_internal(x, 1)
#define nls_output(x,y) nls_output_internal((x << 8) | y, 0)
#define nls_outputnl(x,y) nls_output_internal((x << 8) | y, 1)
 
/* output DOS error e to stderr */
void nls_outputnl_doserr(unsigned short e);
 
/*
* FileInfoRec (DTA) format:
* offset size desc
/svarcom/trunk/history.txt
9,7 → 9,6
- DIR: fixed /P pagination in wide mode
- implemented IF command (IF EXIST, IF ERRORLEVEL, IF str==str)
- added a break handler (running application can be aborted with CTRL+C)
- Error messages are output to stderr
 
 
=== ver 2021.0 (24.11.2021) ==================================================
/svarcom/trunk/makefile
26,8 → 26,8
 
all: command.com
 
command.com: rmodcore.h command.obj cmd.obj env.obj redir.obj rmodinit.obj sayonara.obj helpers.obj
*wcl $(LDFLAGS) command.obj cmd.obj env.obj redir.obj rmodinit.obj sayonara.obj helpers.obj
command.com: rmodcore.h command.obj cmd.obj doserr.obj env.obj redir.obj rmodinit.obj sayonara.obj helpers.obj
*wcl $(LDFLAGS) command.obj cmd.obj doserr.obj env.obj redir.obj rmodinit.obj sayonara.obj helpers.obj
 
cmd.obj: cmd.c cmd\*.c
wcc $(CFLAGS) cmd.c
/svarcom/trunk/redir.c
24,6 → 24,7
 
#include <string.h> /* memset() */
 
#include "doserr.h"
#include "helpers.h"
#include "rmodinit.h"
 
147,7 → 148,7
pop ax
}
if (errcode != 0) {
nls_outputnl_doserr(errcode);
outputnl(doserr(errcode));
return(-1);
}
}
/svarcom/trunk/tlumacz/lang/english.txt
12,43 → 12,3
# SHIFT
16.0:Changes the position of arguments in a batch file:
16.1:Argument %1 becomes %0, argument %2 becomes %1, etc.
 
# DOS ERRORS
255.1:Function number invalid
255.2:File not found
255.3:Path not found
255.4:Too many open files (no handles available)
255.5:Access denied
255.6:Invalid handle
255.7:Memory control block destroyed
255.8:Insufficient memory
255.9:Memory block address invalid
255.10:Environment invalid
255.11:Format invalid
255.12:Access code invalid
255.13:Data invalid
255.15:Invalid drive
255.16:Attemted to remove current directory
255.17:Not same device
255.18:No more files
255.19:Disk write-protected
255.20:Unknown unit
255.21:Drive not ready
255.22:Unknown command
255.23:Data error (CRC)
255.24:Bad request structure length
255.25:Seek error
255.26:Unknown media type (non-DOS disk)
255.27:Sector not found
255.28:Printer out of paper
255.29:Write fault
255.30:Read fault
255.31:General failure
255.32:Sharing violation
255.33:Lock violation
255.34:Disk change invalid
255.35:FCB unavailable
255.36:Sharing buffer overflow
255.37:Code page mismatch
255.38:Cannot complete file operations (EOF / out of input)
255.39:Insufficient disk space