Subversion Repositories SvarDOS

Rev

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

Rev 2049 Rev 2050
Line 187... Line 187...
187
#define FILE_TYPE_DISK    0x01
187
#define FILE_TYPE_DISK    0x01
188
#define FILE_TYPE_CHAR    0x02
188
#define FILE_TYPE_CHAR    0x02
189
#define FILE_TYPE_PIPE    0x03
189
#define FILE_TYPE_PIPE    0x03
190
#define FILE_TYPE_REMOTE  0x80
190
#define FILE_TYPE_REMOTE  0x80
191
 
191
 
192
/* Returns file type of stdout.
-
 
193
 * Output, one of predefined values above indicating if
192
/* checks if stdout appears to be redirected. returns 0 if not, non-zero otherwise. */
194
 *         handle refers to file (FILE_TYPE_DISK), a
-
 
195
 *         device such as CON (FILE_TYPE_CHAR), a
-
 
196
 *         pipe (FILE_TYPE_PIPE), or unknown.
-
 
197
 * On errors or unspecified input, FILE_TYPE_UNKNOWN
-
 
198
 * is returned. */
-
 
199
static unsigned char GetStdoutType(void) {
193
static unsigned char is_stdout_redirected(void) {
200
  union REGS r;
194
  union REGS r;
201
 
195
 
202
  r.x.ax = 0x4400;                 /* DOS 2+, IOCTL Get Device Info */
196
  r.x.ax = 0x4400;                 /* DOS 2+, IOCTL Get Device Info */
203
  r.x.bx = 0x0001;                 /* file handle (stdout) */
197
  r.x.bx = 0x0001;                 /* file handle (stdout) */
204
 
198
 
205
  /* We assume hFile is an opened DOS handle, & if invalid call should fail. */
-
 
206
  intdos(&r, &r);     /* Clib function to invoke DOS int21h call   */
199
  intdos(&r, &r);     /* Clib function to invoke DOS int21h call   */
207
 
200
 
208
  /* error? */
201
  /* error? */
209
  if (r.x.cflag != 0) return(FILE_TYPE_UNKNOWN);
202
  if (r.x.cflag != 0) return(FILE_TYPE_UNKNOWN);
210
 
203
 
211
  /* if bit 7 is set it is a char dev */
204
  /* if bit 7 is set it is a char dev (not redirected to disk) */
212
  if (r.x.dx & 0x80) return(FILE_TYPE_CHAR);
205
  if (r.x.dx & 0x80) return(0);
213
 
-
 
214
  /* file is remote */
-
 
215
  if (r.x.dx & 0x8000) return(FILE_TYPE_REMOTE);
-
 
216
 
206
 
217
  /* assume valid file handle */
207
  /* assume valid file handle */
218
  return(FILE_TYPE_DISK);
208
  return(1);
219
}
209
}
220
 
210
 
221
 
211
 
222
/* sets rows & cols to size of actual console window
212
/* sets rows & cols to size of actual console window
223
 * force NOPAUSE if appears output redirected to a file or
213
 * force NOPAUSE if appears output redirected to a file or
Line 227... Line 217...
227
 */
217
 */
228
static void getConsoleSize(void) {
218
static void getConsoleSize(void) {
229
  unsigned short far *bios_cols = (unsigned short far *)MK_FP(0x40,0x4A);
219
  unsigned short far *bios_cols = (unsigned short far *)MK_FP(0x40,0x4A);
230
  unsigned short far *bios_size = (unsigned short far *)MK_FP(0x40,0x4C);
220
  unsigned short far *bios_size = (unsigned short far *)MK_FP(0x40,0x4C);
231
 
221
 
232
  switch (GetStdoutType()) {
222
  if (is_stdout_redirected() != 0) {
233
    case FILE_TYPE_DISK: /* e.g. redirected to a file, tree > filelist.txt */
223
    /* e.g. redirected to a file, tree > filelist.txt */
234
      /* Output to a file or program, so no screen to fill (no max cols or rows) */
224
    /* Output to a file or program, so no screen to fill (no max cols or rows) */
235
      pause = NOPAUSE;   /* so ignore request to pause */
225
      pause = NOPAUSE;   /* so ignore request to pause */
236
      break;
-
 
237
    case FILE_TYPE_CHAR:  /* e.g. the console */
226
  } else { /* e.g. the console */
238
    case FILE_TYPE_UNKNOWN:  /* else at least attempt to get proper limits */
-
 
239
    case FILE_TYPE_REMOTE:
-
 
240
    default:
-
 
241
      if ((*bios_cols == 0) || (*bios_size == 0)) { /* MDA does not report size */
227
    if ((*bios_cols == 0) || (*bios_size == 0)) { /* MDA does not report size */
242
        cols = 80;
228
      cols = 80;
243
        rows = 23;
229
      rows = 23;
244
      } else {
230
    } else {
245
        cols = *bios_cols;
231
      cols = *bios_cols;
246
        rows = *bios_size / cols / 2;
232
      rows = *bios_size / cols / 2;
247
        if (rows > 2) rows -= 2; /* necessary to keep screen from scrolling */
233
      if (rows > 2) rows -= 2; /* necessary to keep screen from scrolling */
248
      }
234
    }
249
      break;
-
 
250
  }
235
  }
251
}
236
}
252
 
237
 
253
 
238
 
254
/* when pause == NOPAUSE then identical to printf,
239
/* when pause == NOPAUSE then identical to printf,