2 |
- |
1 |
/* Copyright (C) 1997, 1998, 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: gsargs.h,v 1.7 2002/06/16 08:45:42 lpd Exp $ */
|
|
|
18 |
/* Command line argument list management */
|
|
|
19 |
|
|
|
20 |
#ifndef gsargs_INCLUDED
|
|
|
21 |
# define gsargs_INCLUDED
|
|
|
22 |
|
|
|
23 |
/*
|
|
|
24 |
* We need to handle recursion into @-files.
|
|
|
25 |
* The following structures keep track of the state.
|
|
|
26 |
* Defining a maximum argument length and a maximum nesting depth
|
|
|
27 |
* decreases generality, but eliminates the need for dynamic allocation.
|
|
|
28 |
*/
|
|
|
29 |
#define arg_str_max 2048
|
|
|
30 |
#define arg_depth_max 10
|
|
|
31 |
typedef struct arg_source_s {
|
|
|
32 |
bool is_file;
|
|
|
33 |
union _u {
|
|
|
34 |
struct _su {
|
|
|
35 |
char *chars; /* original string */
|
|
|
36 |
gs_memory_t *memory; /* if non-0, free chars when done with it */
|
|
|
37 |
const char *str; /* string being read */
|
|
|
38 |
} s;
|
|
|
39 |
FILE *file;
|
|
|
40 |
} u;
|
|
|
41 |
} arg_source;
|
|
|
42 |
typedef struct arg_list_s {
|
|
|
43 |
bool expand_ats; /* if true, expand @-files */
|
|
|
44 |
FILE *(*arg_fopen) (const char *fname, void *fopen_data);
|
|
|
45 |
void *fopen_data;
|
|
|
46 |
const char **argp;
|
|
|
47 |
int argn;
|
|
|
48 |
int depth; /* depth of @-files */
|
|
|
49 |
char cstr[arg_str_max + 1];
|
|
|
50 |
arg_source sources[arg_depth_max];
|
|
|
51 |
} arg_list;
|
|
|
52 |
|
|
|
53 |
/* Initialize an arg list. */
|
|
|
54 |
void arg_init(arg_list * pal, const char **argv, int argc,
|
|
|
55 |
FILE * (*arg_fopen) (const char *fname, void *fopen_data),
|
|
|
56 |
void *fopen_data);
|
|
|
57 |
|
|
|
58 |
/*
|
|
|
59 |
* Push a string onto an arg list.
|
|
|
60 |
* This may also be used (once) to "unread" the last argument.
|
|
|
61 |
* If mem != 0, it is used to free the string when we are done with it.
|
|
|
62 |
* Return 0 on success, non-zero on failure
|
|
|
63 |
*/
|
|
|
64 |
int arg_push_memory_string(arg_list * pal, char *str, gs_memory_t * mem);
|
|
|
65 |
|
|
|
66 |
#define arg_push_string(pal, str)\
|
|
|
67 |
arg_push_memory_string(pal, str, (gs_memory_t *)0);
|
|
|
68 |
|
|
|
69 |
/* Clean up an arg list before exiting. */
|
|
|
70 |
void arg_finit(arg_list * pal);
|
|
|
71 |
|
|
|
72 |
/*
|
|
|
73 |
* Get the next arg from a list.
|
|
|
74 |
* Note that these are not copied to the heap.
|
|
|
75 |
*/
|
|
|
76 |
const char *arg_next(arg_list * pal, int *code);
|
|
|
77 |
|
|
|
78 |
/* Copy an argument string to the heap. */
|
|
|
79 |
char *arg_copy(const char *str, gs_memory_t * mem);
|
|
|
80 |
|
|
|
81 |
#endif /* gsargs_INCLUDED */
|