Subversion Repositories SvarDOS

Rev

Rev 571 | Rev 965 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 571 Rev 959
Line 1... Line 1...
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,
Line 22... Line 22...
22
 * DEALINGS IN THE SOFTWARE.
22
 * DEALINGS IN THE SOFTWARE.
23
 */
23
 */
24
 
24
 
25
/*
25
/*
26
 * a variety of helper functions
26
 * a variety of helper functions
27
 * Copyright (C) 2021 Mateusz Viste
-
 
28
 */
27
 */
29
 
28
 
30
#include <i86.h>    /* MK_FP() */
29
#include <i86.h>    /* MK_FP() */
31
#include <stdio.h>  /* sprintf() */
30
#include <stdio.h>  /* sprintf() */
32
#include <string.h> /* memcpy() */
31
#include <string.h> /* memcpy() */
Line 128... Line 127...
128
  if (ptr == NULL) ptr = NOTFOUND;
127
  if (ptr == NULL) ptr = NOTFOUND;
129
  output_internal(ptr, nl, handle);
128
  output_internal(ptr, nl, handle);
130
}
129
}
131
 
130
 
132
 
131
 
-
 
132
/* output DOS error e to stdout, if stdout is redirected then *additionally*
133
/* output DOS error e to stderr */
133
 * also to stderr */
134
void nls_outputnl_doserr(unsigned short e) {
134
void nls_outputnl_doserr(unsigned short e) {
135
  static char errstr[16];
135
  static char errstr[16];
136
  const char *ptr = NULL;
136
  const char *ptr = NULL;
-
 
137
  unsigned char redirflag = 0;
137
  /* find string in nls block */
138
  /* find string in nls block */
138
  if (e < 0xff) ptr = nlsblock_findstr(0xff00 | e);
139
  if (e < 0xff) ptr = nlsblock_findstr(0xff00 | e);
139
  /* if not found, use a fallback */
140
  /* if not found, use a fallback */
140
  if (ptr == NULL) {
141
  if (ptr == NULL) {
141
    sprintf(errstr, "DOS ERR %u", e);
142
    sprintf(errstr, "DOS ERR %u", e);
142
    ptr = errstr;
143
    ptr = errstr;
143
  }
144
  }
-
 
145
 
144
  /* display */
146
  /* display to stdout */
145
  output_internal(ptr, 1, hSTDERR);
147
  output_internal(ptr, 1, hSTDOUT);
-
 
148
 
-
 
149
  /* is stdout redirected? */
-
 
150
  _asm {
-
 
151
    push bx
-
 
152
    push dx
-
 
153
 
-
 
154
    mov ax, 0x4400   /* query device flags */
-
 
155
    mov bx, 1        /* stdout */
-
 
156
    int 0x21
-
 
157
    /* CF set on error and AX filled with DOS error,
-
 
158
     * returns flags in DX on succes:
-
 
159
     *  bit 7 reset if handle points to a file, set if handle points to a device  */
-
 
160
    jc FAIL
-
 
161
    mov redirflag, dl
-
 
162
    and redirflag, 128
-
 
163
 
-
 
164
    FAIL:
-
 
165
    pop dx
-
 
166
    pop bx
-
 
167
  }
-
 
168
 
-
 
169
  if (redirflag == 0) output_internal(ptr, 1, hSTDERR);
146
}
170
}
147
 
171
 
148
 
172
 
149
/* find first matching files using a FindFirst DOS call
173
/* find first matching files using a FindFirst DOS call
150
 * returns 0 on success or a DOS err code on failure */
174
 * returns 0 on success or a DOS err code on failure */