gsinit.c 2.0 KB

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