home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / GP_DVX.C < prev    next >
C/C++ Source or Header  |  1994-07-27  |  4KB  |  118 lines

  1. /* Copyright (C) 1989, 1992, 1993, 1994 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gp_dvx.c */
  20. /* Desqview/X-specific routines for Ghostscript */
  21. #include "string_.h"
  22. #include "gx.h"
  23. #include "gsexit.h"
  24. #include "gp.h"
  25. #include "time_.h"
  26.  
  27. /* Do platform-dependent initialization. */
  28. void
  29. gp_init(void)
  30. {
  31. }
  32.  
  33. /* Do platform-dependent cleanup. */
  34. void
  35. gp_exit(int exit_status, int code)
  36. {
  37. }
  38.  
  39. /* ------ Miscellaneous ------ */
  40.  
  41. /* Get the string corresponding to an OS error number. */
  42. /* All reasonable compilers support it. */
  43. const char *
  44. gp_strerror(int errnum)
  45. {    return strerror(errnum);
  46. }
  47.  
  48. /* ------ Date and time ------ */
  49.  
  50. /* Read the current date (in days since Jan. 1, 1980) */
  51. /* and time (in milliseconds since midnight). */
  52. void
  53. gp_get_clock(long *pdt)
  54. {    long secs_since_1980;
  55.     struct timeval tp;
  56.     struct timezone tzp;
  57.     time_t tsec;
  58.     struct tm *tm, *localtime();
  59.  
  60.     if ( gettimeofday(&tp, &tzp) == -1 )
  61.        {    lprintf("Ghostscript: gettimeofday failed!\n");
  62.         gs_exit(1);
  63.        }
  64.  
  65.     /* tp.tv_sec is #secs since Jan 1, 1970 */
  66.  
  67.     /* subtract off number of seconds in 10 years */
  68.     /* leap seconds are not accounted for */
  69.     secs_since_1980 = tp.tv_sec - (long)(60 * 60 * 24 * 365.25 * 10);
  70.  
  71.     /* adjust for timezone */
  72.     secs_since_1980 -= (tzp.tz_minuteswest * 60);
  73.  
  74.     /* adjust for daylight savings time - assume dst offset is 1 hour */
  75.     tsec = tp.tv_sec;
  76.     tm = localtime(&tsec);
  77.     if ( tm->tm_isdst )
  78.         secs_since_1980 += (60 * 60);
  79.  
  80.     /* divide secs by #secs/day to get #days (integer division truncates) */
  81.     pdt[0] = secs_since_1980 / (60 * 60 * 24);
  82.     /* modulo + microsecs/1000 gives number of millisecs since midnight */
  83.     pdt[1] = (secs_since_1980 % (60 * 60 * 24)) * 1000;
  84.     /* Some Unix systems (e.g., Interactive 3.2 r3.0) return garbage */
  85.     /* in tp.tv_usec.  Try to filter out the worst of it here. */
  86.     if ( tp.tv_usec >= 0 && tp.tv_usec < 1000000 )
  87.         pdt[1] += tp.tv_usec / 1000;
  88.  
  89. #ifdef DEBUG_CLOCK
  90.     printf("tp.tv_sec = %d  tp.tv_usec = %d  pdt[0] = %ld  pdt[1] = %ld\n",
  91.         tp.tv_sec, tp.tv_usec, pdt[0], pdt[1]);
  92. #endif
  93. }
  94.  
  95. /* ------ Printer accessing ------ */
  96.  
  97. /* Open a connection to a printer.  A null file name means use the */
  98. /* standard printer connected to the machine, if any. */
  99. /* Return NULL if the connection could not be opened. */
  100. extern void gp_set_printer_binary(P2(int, int));
  101. FILE *
  102. gp_open_printer(char *fname, int binary_mode)
  103. {       if ( strlen(fname) == 0 || !strcmp(fname, "PRN") )
  104.         {       if ( binary_mode )
  105.                         gp_set_printer_binary(fileno(stdprn), 1);
  106.                 return stdprn;
  107.         }
  108.         else
  109.                 return fopen(fname, (binary_mode ? "wb" : "w"));
  110. }
  111.  
  112. /* Close the connection to the printer. */
  113. void
  114. gp_close_printer(FILE *pfile, const char *fname)
  115. {       if ( pfile != stdprn )
  116.                 fclose(pfile);
  117. }
  118.