/* Copyright (C) 1992 Aladdin Enterprises. All rights reserved.
Distributed by Free Software Foundation, Inc.
This file is part of Ghostscript.
Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing. Refer
to the Ghostscript General Public License for full details.
Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License. A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities. It should be in a file named COPYING. Among other
things, the copyright notice and this notice must be preserved on all
/* Common platform-specific routines for MS-DOS (any compiler) */
/* ------ Date and time ------ */
/* Read the current date (in days since Jan. 1, 1980) */
/* and time (in milliseconds since midnight). */
{ union REGS osdate
, ostime
;
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
osdate
.h
.ah
= 0x2a; /* get date */
intdos(&osdate
, &osdate
);
#define da_year rshort.cx
ostime
.h
.ah
= 0x2c; /* get time */
intdos(&ostime
, &ostime
);
idate
= (long)osdate
.da_year
* 365 +
(osdate
.da_year
/ 4 + 1 + /* account for leap years */
mstart
[osdate
.da_mon
- 1] + /* month is 1-origin */
osdate
.da_day
- 1); /* day of month is 1-origin */
if ( osdate
.da_mon
<= 2 && osdate
.da_year
% 4 == 0 ) /* Jan. or Feb. of leap year */
(ostime
.ti_hour
* 60 + ostime
.ti_min
) * 60000L +
(ostime
.ti_sec
* 100 + ostime
.ti_hund
) * 10L;
/* ------ Printer accessing ------ */
/* Put the printer into binary mode. This is not a standard gp procedure, */
/* but all MS-DOS configurations need it. */
gp_set_printer_binary(int prnfno
)
regs
.h
.ah
= 0x44; /* ioctl */
regs
.h
.al
= 0; /* get device info */
regs
.h
.dl
|= 0x20; /* binary (no ^Z intervention) */
regs
.h
.ah
= 0x44; /* ioctl */
regs
.h
.al
= 1; /* set device info */
/* ------ File names ------ */
/* Define the character used for separating file names in a list. */
const char gp_file_name_list_separator
= ';';
/* Define the default scratch file name prefix. */
const char gp_scratch_file_name_prefix
[] = "_temp_";
/* Define whether case is insignificant in file names. */
const int gp_file_names_ignore_case
= 1;
/* Answer whether a file name contains a directory/device specification, */
/* i.e. is absolute (not directory- or device-relative). */
gp_file_name_is_absolute(const char *fname
, uint len
)
{ /* A file name is absolute if it contains a drive specification */
/* (second character is a :) or if it start with / or \. */
return ( len
>= 1 && (*fname
== '/' || *fname
== '\\' ||
(len
>= 2 && fname
[1] == ':')) );
/* Answer the string to be used for combining a directory/device prefix */
/* with a base file name. The file name is known to not be absolute. */
gp_file_name_concat_string(const char *prefix
, uint plen
,
const char *fname
, uint len
)
switch ( prefix
[plen
- 1] )
{ case ':': case '/': case '\\': return "";
/* ------ File enumeration ------ */
int patlen
; /* allocated length of pattern */
int head_size
; /* pattern length through last */
/* Initialize an enumeration. Note that * and ? in a directory */
/* don't work, and \* and \? don't work. */
gp_enumerate_files_init(const char *pat
, uint patlen
,
proc_alloc_t palloc
, proc_free_t pfree
)
{ file_enum
*pfen
= (file_enum
*)(*palloc
)(1, sizeof(file_enum
), "gp_enumerate_files");
if ( pfen
== 0 ) return 0;
pattern
= (*palloc
)(patlen
+ 1, 1,
"gp_enumerate_files(pattern)");
if ( pattern
== 0 ) return 0;
for ( i
= 0; i
< patlen
; i
++ )
/* Skip to . or end of string so DOS can do it. */
while ( i
< patlen
&& pat
[i
] != '.' ) i
++;
if ( pat
[i
] != '\\' && pat
[i
] != '/' && pat
[i
] != ':' )
pfen
->mprocs
.alloc
= palloc
;
pfen
->mprocs
.free
= pfree
;
/* Enumerate the next file. */
gp_enumerate_files_next(file_enum
*pfen
, char *ptr
, uint maxlen
)
{ code
= dos_findfirst(pfen
->pattern
, &pfen
->ffblk
);
code
= dos_findnext(&pfen
->ffblk
);
{ /* All done, clean up. */
gp_enumerate_files_close(pfen
);
if ( maxlen
< 13 + pfen
->head_size
) return maxlen
+ 1; /* cop out! */
memcpy(ptr
, pfen
->pattern
, pfen
->head_size
);
for ( p
= &pfen
->ffblk
.ff_name
[0], q
= ptr
+ pfen
->head_size
; *p
; p
++ )
if ( *p
!= ' ' ) *q
++ = *p
;
/* Clean up the file enumeration. */
gp_enumerate_files_close(file_enum
*pfen
)
{ proc_free_t pfree
= pfen
->mprocs
.free
;
(*pfree
)(pfen
->pattern
, pfen
->patlen
+ 1, 1,
"gp_enumerate_files_close(pattern)");
(*pfree
)((char *)pfen
, 1, sizeof(file_enum
), "gp_enumerate_files_close");