home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / ghostscr / gp_dos.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-31  |  4.3 KB  |  126 lines

  1. /* Copyright (C) 1989, 1990 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* gp_dos.c */
  21. /* DOS-specific routines for Ghostscript */
  22. #define interrupt            /* non-ANSI! */
  23. #pragma inline                /* for assembly code, see below */
  24. #include <dos.h>
  25. #include <fcntl.h>
  26. #include "string_.h"
  27. #include "gx.h"
  28.  
  29. /* Define the size of the C stack. */
  30. unsigned _stklen = 8000;        /* default is 4096, we need more */
  31.  
  32. /* Do platform-dependent initialization */
  33. void
  34. gp_init()
  35. {    /*
  36.      * Detect the processor type using the following algorithms:
  37.      *    The 8088/8086 truncate shift counts mod 32,
  38.      *      the 80186 and up do not.
  39.      *    The 80186 and below fix FLAGS bits 15-12 to 1,
  40.      *      the 80286 and up do not.
  41.      *    The 80386 allows setting FLAGS bits 14-12,
  42.      *      the 80286 and below do not.
  43.      * Note that this algorithm will identify an 80386
  44.      *   running in Virtual 8086 mode as an 80386.
  45.      *   This is acceptable, because Ghostscript doesn't actually
  46.      *   use 80286 or 80386 addressing modes, only the additional
  47.      *   instructions available on these processors.
  48.      * (This algorithm is derived from the Intel manuals.)
  49.      */
  50. #if CPU_TYPE > 86
  51.     /* We have to be careful not to turn interrupts off! */
  52.     int result, type;
  53.        {    asm mov ax,202h; asm push ax; asm popf;
  54.         asm pushf; asm pop result;
  55.        }
  56.     if ( (result & 0xf000) == 0xf000 )
  57.        {    /* CPU is an 8088/8086/80186 */
  58.            {    asm mov cl,33; asm mov ax,0ffffh;
  59.             asm shl ax,cl; asm mov result,ax;
  60.            }
  61.         type = (result == 0 ? 186 : 86);
  62.        }
  63.     else
  64.        {    /* CPU is an 80286/80386/... */
  65.            {    asm mov ax,7202h; asm push ax; asm popf;
  66.             asm pushf; asm pop result;
  67.            }
  68.         type = ((result & 0x7000) == 0 ? 286 : 386);
  69.        }
  70.     if ( type < CPU_TYPE )
  71.        {    eprintf1("This executable requires an 80%d or higher.\n", CPU_TYPE);
  72.         exit(1);
  73.        }
  74. #endif
  75.     _fmode = O_BINARY;        /* Open files in 'binary' mode */
  76. }
  77.  
  78. /* Read the current date (in days since Jan. 1, 1980) */
  79. /* and time (in milliseconds since midnight). */
  80. void
  81. gs_get_clock(long *pdt)
  82. {    struct date osdate;
  83.     struct time ostime;
  84.     long idate;
  85.     static int mstart[12] =
  86.        { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
  87.     getdate(&osdate);
  88.     gettime(&ostime);
  89.     idate = (long)osdate.da_year * 365 +
  90.         (osdate.da_year / 4 + 1 +    /* account for leap years */
  91.          mstart[osdate.da_mon - 1] +    /* month is 1-origin */
  92.          osdate.da_day - 1);        /* day of month is 1-origin */
  93.     if ( osdate.da_mon <= 2 && osdate.da_year % 4 == 0 )        /* Jan. or Feb. of leap year */
  94.         idate--;
  95.     pdt[0] = idate;
  96.     pdt[1] =
  97.         (ostime.ti_hour * 60 + ostime.ti_min) * 60000L +
  98.         (ostime.ti_sec * 100 + ostime.ti_hund) * 10L;
  99. }
  100.  
  101. /* ------ File name syntax ------ */
  102.  
  103. /* Define the character used for separating file names in a list. */
  104. char gp_file_name_list_separator = '|';
  105.  
  106. /* Answer whether a file name contains a directory/device specification, */
  107. /* i.e. is absolute (not directory- or device-relative). */
  108. int
  109. gp_file_name_is_absolute(char *fname, uint len)
  110. {    /* A file name is absolute if it contains a drive specification */
  111.     /* (second character is a :) or if it start with / or \. */
  112.     return ( len >= 1 && (*fname == '/' || *fname == '\\' ||
  113.         (len >= 2 && fname[1] == ':')) );
  114. }
  115.  
  116. /* Answer the string to be used for combining a directory/device prefix */
  117. /* with a base file name.  The file name is known to not be absolute. */
  118. char *
  119. gp_file_name_concat_string(char *prefix, uint plen, char *fname, uint len)
  120. {    if ( plen > 0 )
  121.       switch ( prefix[plen - 1] )
  122.        {    case ':': case '/': case '\\': return "";
  123.        };
  124.     return "\\";
  125. }
  126.