Subversion Repositories planix.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
/* Copyright (C) 1989, 1995, 1996, 1999 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: gs.c,v 1.14 2004/09/15 19:41:01 ray Exp $ */
18
/* 'main' program for Ghostscript */
19
#include "ghost.h"
20
#include "imain.h"
21
#include "imainarg.h"
22
#include "iapi.h"
23
#include "iminst.h"
24
#include "ierrors.h"
25
#include "gsmalloc.h"
26
 
27
/* Define an optional array of strings for testing. */
28
/*#define RUN_STRINGS */
29
#ifdef RUN_STRINGS
30
private const char *run_strings[] =
31
{
32
    "2 vmreclaim /SAVE save def 2 vmreclaim",
33
    "(saved\n) print flush",
34
    "SAVE restore (restored\n) print flush 2 vmreclaim",
35
    "(done\n) print flush quit",
36
 
37
};
38
 
39
#endif
40
 
41
int
42
main(int argc, char *argv[])
43
{
44
    int exit_status = 0;
45
    gs_main_instance *minst = gs_main_alloc_instance(gs_malloc_init(NULL));
46
 
47
    int code = gs_main_init_with_args(minst, argc, argv);
48
 
49
#ifdef RUN_STRINGS
50
    {				/* Run a list of strings (for testing). */
51
	const char **pstr = run_strings;
52
 
53
	for (; *pstr; ++pstr) {
54
	    int exit_code;
55
	    ref error_object;
56
	    int code;
57
 
58
	    fprintf(stdout, "{%s} =>\n", *pstr);
59
	    fflush(stdout);
60
	    code = gs_main_run_string(minst, *pstr, 0,
61
				      &exit_code, &error_object);
62
	    zflush(osp);
63
	    fprintf(stdout, " => code = %d\n", code);
64
	    fflush(stdout);
65
	    if (code < 0) {
66
		gs_to_exit(1);
67
		return 1;
68
	    }
69
	}
70
    }
71
#endif
72
 
73
    if (code >= 0)
74
	code = gs_main_run_start(minst);
75
 
76
    exit_status = 0;
77
    switch (code) {
78
	case 0:
79
	case e_Info:
80
	case e_Quit:
81
	    break;
82
	case e_Fatal:
83
	    exit_status = 1;
84
	    break;
85
	default:
86
	    exit_status = 255;
87
    }
88
 
89
    gs_to_exit_with_code(minst->heap, exit_status, code);
90
 
91
    switch (exit_status) {
92
	case 0:
93
	    exit_status =  exit_OK;
94
	    break;
95
	case 1:
96
	    exit_status =  exit_FAILED;
97
	    break;
98
    }
99
    return exit_status;
100
}