1 /* Copyright (C) 1989, 1995, 1996, 1997 Aladdin Enterprises. All rights reserved.
2
3 This software is provided AS-IS with no warranty, either express or
4 implied.
5
6 This software is distributed under license and may not be copied,
7 modified or distributed except as expressly authorized under the terms
8 of the license contained in the file LICENSE in this distribution.
9
10 For more information about licensing, please refer to
11 http://www.ghostscript.com/licensing/. For information on
12 commercial licensing, go to http://www.artifex.com/licensing/ or
13 contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 San Rafael, CA 94903, U.S.A., +1(415)492-9861.
15 */
16
17 /* $Id: gsinit.c,v 1.7 2004/08/10 12:59:53 stefan Exp $ */
18 /* Initialization for the imager */
19 #include "stdio_.h"
20 #include "memory_.h"
21 #include "gdebug.h"
22 #include "gscdefs.h"
23 #include "gsmemory.h"
24 #include "gsmalloc.h"
25 #include "gp.h"
26 #include "gslib.h" /* interface definition */
27
28 /* Configuration information from gconfig.c. */
29 extern_gx_init_table();
30
31 /* Initialization to be done before anything else. */
32 int
gs_lib_init(FILE * debug_out)33 gs_lib_init(FILE * debug_out)
34 {
35 return gs_lib_init1(gs_lib_init0(debug_out));
36 }
37 gs_memory_t *
gs_lib_init0(FILE * debug_out)38 gs_lib_init0(FILE * debug_out)
39 {
40 gs_memory_t *mem;
41
42 mem = (gs_memory_t *) gs_malloc_init(NULL);
43
44 /* Reset debugging flags */
45 memset(gs_debug, 0, 128);
46 gs_log_errors = 0;
47 return mem;
48 }
49 int
gs_lib_init1(gs_memory_t * mem)50 gs_lib_init1(gs_memory_t * mem)
51 {
52 /* Run configuration-specific initialization procedures. */
53 init_proc((*const *ipp));
54 int code;
55
56 for (ipp = gx_init_table; *ipp != 0; ++ipp)
57 if ((code = (**ipp)(mem)) < 0)
58 return code;
59 return 0;
60 }
61
62 /* Clean up after execution. */
63 void
gs_lib_finit(int exit_status,int code,gs_memory_t * mem)64 gs_lib_finit(int exit_status, int code, gs_memory_t *mem)
65 {
66 /* Do platform-specific cleanup. */
67 gp_exit(exit_status, code);
68
69 /* NB: interface problem.
70 * if gs_lib_init0 was called the we should
71 * gs_malloc_release(mem);
72 * else
73 * someone else has control of mem so we can't free it.
74 * gs_view and iapi.h interface
75 */
76 }
77