gp_dvx.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* Copyright (C) 1989, 1995, 1998 Aladdin Enterprises. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  4. distributor accepts any responsibility for the consequences of using it, or
  5. for whether it serves any particular purpose or works at all, unless he or
  6. she says so in writing. Refer to the Aladdin Free Public License (the
  7. "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. in a plain ASCII text file named PUBLIC. The License grants you the right
  10. to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. conditions described in the License. Among other things, the License
  12. requires that the copyright notice and this notice be preserved on all
  13. copies.
  14. */
  15. /*$Id: gp_dvx.c,v 1.4 2001/04/08 08:43:24 ghostgum Exp $ */
  16. /* Desqview/X-specific routines for Ghostscript */
  17. #include "string_.h"
  18. #include "gx.h"
  19. #include "gsexit.h"
  20. #include "gp.h"
  21. #include "time_.h"
  22. /* Do platform-dependent initialization. */
  23. void
  24. gp_init(void)
  25. {
  26. }
  27. /* Do platform-dependent cleanup. */
  28. void
  29. gp_exit(int exit_status, int code)
  30. {
  31. }
  32. /* Exit the program. */
  33. void
  34. gp_do_exit(int exit_status)
  35. {
  36. }
  37. /* ------ Miscellaneous ------ */
  38. /* Get the string corresponding to an OS error number. */
  39. /* All reasonable compilers support it. */
  40. const char *
  41. gp_strerror(int errnum)
  42. {
  43. return strerror(errnum);
  44. }
  45. /* ------ Date and time ------ */
  46. /* Read the current time (in seconds since Jan. 1, 1970) */
  47. /* and fraction (in nanoseconds). */
  48. void
  49. gp_get_realtime(long *pdt)
  50. {
  51. struct timeval tp;
  52. struct timezone tzp;
  53. if (gettimeofday(&tp, &tzp) == -1) {
  54. lprintf("Ghostscript: gettimeofday failed!\n");
  55. tp.tv_sec = tp.tv_usec = 0;
  56. }
  57. /* tp.tv_sec is #secs since Jan 1, 1970 */
  58. pdt[0] = tp.tv_sec;
  59. pdt[1] = tp.tv_usec * 1000;
  60. #ifdef DEBUG_CLOCK
  61. printf("tp.tv_sec = %d tp.tv_usec = %d pdt[0] = %ld pdt[1] = %ld\n",
  62. tp.tv_sec, tp.tv_usec, pdt[0], pdt[1]);
  63. #endif
  64. }
  65. /* Read the current user CPU time (in seconds) */
  66. /* and fraction (in nanoseconds). */
  67. void
  68. gp_get_usertime(long *pdt)
  69. {
  70. gp_get_realtime(pdt); /* Use an approximation for now. */
  71. }
  72. /* ------ Printer accessing ------ */
  73. /* Open a connection to a printer. A null file name means use the */
  74. /* standard printer connected to the machine, if any. */
  75. /* Return NULL if the connection could not be opened. */
  76. extern void gp_set_file_binary(P2(int, int));
  77. FILE *
  78. gp_open_printer(char fname[gp_file_name_sizeof], int binary_mode)
  79. {
  80. if (strlen(fname) == 0 || !strcmp(fname, "PRN")) {
  81. if (binary_mode)
  82. gp_set_file_binary(fileno(stdprn), 1);
  83. stdprn->_flag = _IOWRT; /* Make stdprn buffered to improve performance */
  84. return stdprn;
  85. } else
  86. return fopen(fname, (binary_mode ? "wb" : "w"));
  87. }
  88. /* Close the connection to the printer. */
  89. void
  90. gp_close_printer(FILE * pfile, const char *fname)
  91. {
  92. if (pfile == stdprn)
  93. fflush(pfile);
  94. else
  95. fclose(pfile);
  96. }