home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / gnu / gs-2.6.1.4-src.lha / src / amiga / gs-2.6.1.4 / gp_amiga.c < prev    next >
C/C++ Source or Header  |  1994-01-29  |  8KB  |  347 lines

  1. /* Copyright (C) 1989, 1990, 1991 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_amiga.c */
  21. /* Amiga specific routines for Ghostscript */
  22.  
  23. #define timeval foo1
  24. #define ushort foo2
  25.  
  26. #include <intuition/intuitionbase.h>
  27. #include <graphics/gfxbase.h>
  28. #include <dos/dosextens.h>
  29.  
  30. #include <clib/exec_protos.h>
  31. #include <clib/dos_protos.h>
  32.  
  33. /*
  34. #include <inline/exec.h>
  35. #include <inline/dos.h>
  36. */
  37.  
  38. #include <signal.h>
  39.  
  40. #undef ushort
  41. #undef timeval
  42.  
  43. /* gp_amiga.c */
  44. /* Amiga-specific routines for Ghostscript */
  45.  
  46.  
  47. #include "memory_.h"
  48. #include "string_.h"
  49. #include "gx.h"
  50. #include "gp.h"
  51. #include "stat_.h"
  52. #include "time_.h"
  53.  
  54. struct IntuitionBase    *IntuitionBase;
  55. struct GfxBase        *GfxBase;
  56. struct Library        *LayersBase,
  57.             *IFFParseBase,
  58.             *AslBase,
  59.             *UtilityBase;
  60.  
  61. /* Nothing happens here */
  62. void
  63. gs_amiga_init()
  64. {
  65. }
  66.  
  67. void
  68. gp_exit(int exit_status, int code)
  69. {
  70. }
  71.  
  72. /* Cleanup routine, as called by atexit() trap */
  73. void
  74. cleanup()
  75. {
  76.     extern void devcleanup();
  77.  
  78.     devcleanup();
  79.  
  80.     if(IFFParseBase)
  81.     {
  82.         CloseLibrary(IFFParseBase);
  83.  
  84.         IFFParseBase = NULL;
  85.     }
  86.  
  87.     if(AslBase)
  88.     {
  89.         CloseLibrary(AslBase);
  90.  
  91.         AslBase = NULL;
  92.     }
  93.  
  94.     if(UtilityBase)
  95.     {
  96.         CloseLibrary(UtilityBase);
  97.  
  98.         UtilityBase = NULL;
  99.     }
  100.  
  101.     if(LayersBase)
  102.     {
  103.         CloseLibrary(LayersBase);
  104.  
  105.         LayersBase = NULL;
  106.     }
  107.  
  108.     if(GfxBase)
  109.     {
  110.         CloseLibrary((struct Library *)GfxBase);
  111.  
  112.         GfxBase = NULL;
  113.     }
  114.  
  115.     if(IntuitionBase)
  116.     {
  117.         CloseLibrary((struct Library *)IntuitionBase);
  118.  
  119.         IntuitionBase = NULL;
  120.     }
  121. }
  122.  
  123. void
  124. signal_handler(int signal)
  125. {
  126.     fprintf(stderr,"*** BREAK: Ghostscript\a\n");
  127.  
  128.     exit(1);
  129. }
  130.  
  131. /* Do platform-dependent initialization */
  132. void
  133. gp_init()
  134. {
  135.     atexit(cleanup);
  136.  
  137.     signal(SIGINT,signal_handler);
  138.  
  139.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37)))
  140.     {
  141.         perror("Ghostscript: cannot open intuition.library v37");
  142.  
  143.         exit(20);
  144.     }
  145.  
  146.     if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",37)))
  147.     {
  148.         perror("Ghostscript: cannot open graphics.library v37");
  149.  
  150.         exit(20);
  151.     }
  152.  
  153.     if(!(LayersBase = OpenLibrary("layers.library",37)))
  154.     {
  155.         perror("Ghostscript: cannot open layers.library v37");
  156.  
  157.         exit(20);
  158.     }
  159.  
  160.     if(!(UtilityBase = OpenLibrary("utility.library",37)))
  161.     {
  162.         perror("Ghostscript: cannot open utility.library v37");
  163.  
  164.         exit(20);
  165.     }
  166.  
  167.     if(!(IFFParseBase = OpenLibrary("iffparse.library",37)))
  168.     {
  169.         perror("Ghostscript: cannot open iffparse.library v37");
  170.  
  171.         exit(20);
  172.     }
  173.  
  174.     AslBase = OpenLibrary("asl.library",38);
  175. }
  176.  
  177. /* Read the current date (in days since Jan. 1, 1980) */
  178. /* and time (in milliseconds since midnight). */
  179. void
  180. gp_get_clock(long *pdt)
  181. {
  182.     struct DateStamp Date;
  183.  
  184.     DateStamp(&Date);
  185.  
  186.     pdt[0] = Date . ds_Days + 2 * 365;
  187.     pdt[1] = (Date . ds_Minute * 60 + Date . ds_Tick / TICKS_PER_SECOND) * 1000;
  188. }
  189.  
  190. /* ------ Printer accessing ------ */
  191.  
  192. /* Open a connection to a printer.  A null file name means use the */
  193. /* standard printer connected to the machine, if any. */
  194. /* "|command" opens an output pipe. */
  195. /* Return NULL if the connection could not be opened. */
  196. FILE *
  197. gp_open_printer(char *fname, int binary_mode)
  198. {    return
  199.       (strlen(fname) == 0 ?
  200.        gp_open_scratch_file(gp_scratch_file_name_prefix, fname, "w") :
  201.        fname[0] == '|' ?
  202.        popen(fname + 1, "w") :
  203.        fopen(fname, "w"));
  204. }
  205.  
  206. /* Close the connection to the printer. */
  207. void
  208. gp_close_printer(FILE *pfile, const char *fname)
  209. {    if ( fname[0] == '|' )
  210.         pclose(pfile);
  211.     else
  212.         fclose(pfile);
  213. }
  214.  
  215. /* ------ File name syntax ------ */
  216.  
  217. /* Define the character used for separating file names in a list. */
  218. const char gp_file_name_list_separator = ',';
  219.  
  220. /* Define the default scratch file name template. */
  221. const char gp_scratch_file_name_prefix[] = "T:gs_";
  222.  
  223. /* Define the string to be concatenated with the file mode */
  224. /* for opening files without end-of-line conversion. */
  225. const char gp_fmode_binary_suffix[] = "b";
  226. /* Define the file modes for binary reading or writing. */
  227. const char gp_fmode_rb[] = "r";
  228. const char gp_fmode_wb[] = "w";
  229.  
  230. /* Create and open a scratch file with a given name prefix. */
  231. /* Write the actual file name at fname. */
  232. FILE *
  233. gp_open_scratch_file(const char *prefix, char *fname, const char *mode)
  234. {
  235.     strcpy(fname,prefix);
  236.     /* Prevent trailing X's in path from being converted by mktemp. */
  237.     if ( *fname != 0 && fname[strlen(fname) - 1] == 'X' )
  238.         strcat(fname, "-");
  239.     strcat(fname, "XXXXXX");
  240.     mktemp(fname);
  241.     return fopen(fname, mode);
  242. }
  243.  
  244. /* Answer whether a file name contains a directory/device specification, */
  245. /* i.e. is absolute (not directory- or device-relative). */
  246. int
  247. gp_file_name_is_absolute(const char *fname, uint len)
  248. {
  249.     int i;
  250.  
  251.     for(i = 0 ; i < len ; i++)
  252.     {
  253.         if(fname[i] == ':')
  254.             return(1);
  255.     }
  256.  
  257.     return(0);
  258. }
  259.  
  260. /* Answer the string to be used for combining a directory/device prefix */
  261. /* with a base file name.  The file name is known to not be absolute. */
  262. const char *
  263. gp_file_name_concat_string(const char *prefix, uint plen, const char *fname, uint len)
  264. {
  265.     if(plen > 0 && (prefix[plen - 1] == '/' || prefix[plen - 1] == ':'))
  266.         return("");
  267.     else
  268.         return("/");
  269. }
  270.  
  271. /* ------ File operations ------ */
  272.  
  273. /* If the file given by fname exists, fill in its status and return 1; */
  274. /* otherwise return 0. */
  275. int
  276. gp_file_status(const char *fname, file_status *pstatus)
  277. {    struct stat sbuf;
  278.     /* The RS/6000 prototype for stat doesn't include const, */
  279.     /* so we have to explicitly remove the const modifier. */
  280.     if ( stat((char *)fname, &sbuf) < 0 ) return 0;
  281.     pstatus->size_pages = stat_blocks(&sbuf);    /* st_blocks is */
  282.                     /* missing on some systems, */
  283.                     /* see stat_.h */
  284.     pstatus->size_bytes = sbuf.st_size;
  285.     pstatus->time_referenced = sbuf.st_mtime;
  286.     pstatus->time_created = sbuf.st_ctime;
  287.     return 1;
  288. }
  289.  
  290.  
  291. /* ------ File enumeration ------ */
  292.  
  293. /****** THIS IS NOT SUPPORTED ON UNIX SYSTEMS. ******/
  294. /* Amazingly enough, there is no standard Unix library routine */
  295. /* for enumerating the files matching a pattern, */
  296. /* or even for enumerating (conveniently) the files in a directory. */
  297.  
  298. struct file_enum_s {
  299.     char *pattern;
  300.     int first_time;
  301.     const gs_memory_procs *mprocs;
  302. };
  303.  
  304. /* Initialize an enumeration.  NEEDS WORK ON HANDLING * ? \. */
  305. file_enum *
  306. gp_enumerate_files_init(const char *pat, uint patlen,
  307.   const gs_memory_procs *mprocs)
  308. {    file_enum *pfen = (file_enum *)(*mprocs->alloc)(1, sizeof(file_enum), "gp_enumerate_files");
  309.     char *pattern;
  310.     if ( pfen == 0 ) return 0;
  311.     pattern = (*mprocs->alloc)(patlen + 1, 1,
  312.                 "gp_enumerate_files(pattern)");
  313.     if ( pattern == 0 ) return 0;
  314.     memcpy(pattern, pat, patlen);
  315.     pattern[patlen] = 0;
  316.     pfen->pattern = pattern;
  317.     pfen->mprocs = mprocs;
  318.     pfen->first_time = 1;
  319.     return pfen;
  320. }
  321.  
  322. /* Enumerate the next file. */
  323. /* PUNT: JUST RETURN THE PATTERN. */
  324. uint
  325. gp_enumerate_files_next(file_enum *pfen, char *ptr, uint maxlen)
  326. {    if ( pfen->first_time )
  327.     {    char *pattern = pfen->pattern;
  328.         uint len = strlen(pattern);
  329.         pfen->first_time = 0;
  330.         if ( len > maxlen )
  331.             return maxlen + 1;
  332.         strcpy(ptr, pattern);
  333.         return len;
  334.     }
  335.     return -1;
  336. }
  337.  
  338. /* Clean up the file enumeration. */
  339. void
  340. gp_enumerate_files_close(file_enum *pfen)
  341. {    const gs_memory_procs *mprocs = pfen->mprocs;
  342.     (*mprocs->free)(pfen->pattern, strlen(pfen->pattern) + 1, 1,
  343.             "gp_enumerate_files_close(pattern)");
  344.     (*mprocs->free)((char *)pfen, 1, sizeof(file_enum),
  345.             "gp_enumerate_files_close");
  346. }
  347.