1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/* Copyright (C) 1997, 1998, 1999 Aladdin Enterprises. All rights reserved.
This software is licensed to a single customer by Artifex Software Inc.
under the terms of a specific OEM agreement.
*/
/*$RCSfile$ $Revision$ */
/* Command line argument list management */
#ifndef gsargs_INCLUDED
# define gsargs_INCLUDED
/*
* We need to handle recursion into @-files.
* The following structures keep track of the state.
* Defining a maximum argument length and a maximum nesting depth
* decreases generality, but eliminates the need for dynamic allocation.
*/
#define arg_str_max 512
#define arg_depth_max 10
typedef struct arg_source_s {
bool is_file;
union _u {
struct _su {
char *chars; /* original string */
gs_memory_t *memory; /* if non-0, free chars when done with it */
const char *str; /* string being read */
} s;
FILE *file;
} u;
} arg_source;
typedef struct arg_list_s {
bool expand_ats; /* if true, expand @-files */
FILE *(*arg_fopen) (P2(const char *fname, void *fopen_data));
void *fopen_data;
const char **argp;
int argn;
int depth; /* depth of @-files */
char cstr[arg_str_max + 1];
arg_source sources[arg_depth_max];
} arg_list;
/* Initialize an arg list. */
void arg_init(P5(arg_list * pal, const char **argv, int argc,
FILE * (*arg_fopen) (P2(const char *fname, void *fopen_data)),
void *fopen_data));
/*
* Push a string onto an arg list.
* This may also be used (once) to "unread" the last argument.
* If mem != 0, it is used to free the string when we are done with it.
*/
void arg_push_memory_string(P3(arg_list * pal, char *str, gs_memory_t * mem));
#define arg_push_string(pal, str)\
arg_push_memory_string(pal, str, (gs_memory_t *)0);
/* Clean up an arg list before exiting. */
void arg_finit(P1(arg_list * pal));
/*
* Get the next arg from a list.
* Note that these are not copied to the heap.
*/
const char *arg_next(P1(arg_list * pal));
/* Copy an argument string to the heap. */
char *arg_copy(P2(const char *str, gs_memory_t * mem));
#endif /* gsargs_INCLUDED */
|