annotate lib/swig/swigwin-2.0.11/CCache/args.c @ 1933:5fcf6023f9c3

DamageMonsterFromParty some additional vars removed, changed the ordering part to something more readable
author Grumpy7
date Wed, 23 Oct 2013 21:13:28 -0700
parents b3009adc0e2f
children
rev   line source
1899
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2 convenient routines for argument list handling
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
3
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
4 Copyright (C) Andrew Tridgell 2002
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
5
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
6 This program is free software; you can redistribute it and/or modify
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
8 the Free Software Foundation; either version 2 of the License, or
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
9 (at your option) any later version.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
10
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
11 This program is distributed in the hope that it will be useful,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
14 GNU General Public License for more details.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
15
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
17 along with this program; if not, write to the Free Software
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
19 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
20
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
21 #include "ccache.h"
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
22
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
23 ARGS *args_init(int init_argc, char **init_args)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
24 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
25 ARGS *args;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
26 int i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
27 args = (ARGS *)x_malloc(sizeof(ARGS));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
28 args->argc = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
29 args->argv = (char **)x_malloc(sizeof(char *));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
30 args->argv[0] = NULL;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
31 for (i=0;i<init_argc;i++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
32 args_add(args, init_args[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
33 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
34 return args;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
35 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
36
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
37
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
38 void args_add(ARGS *args, const char *s)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
39 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
40 args->argv = (char**)x_realloc(args->argv, (args->argc + 2) * sizeof(char *));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
41 args->argv[args->argc] = x_strdup(s);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
42 args->argc++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
43 args->argv[args->argc] = NULL;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
44 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
45
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
46 /* pop the last element off the args list */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
47 void args_pop(ARGS *args, int n)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
48 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
49 while (n--) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
50 args->argc--;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
51 free(args->argv[args->argc]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
52 args->argv[args->argc] = NULL;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
53 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
54 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
55
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
56 /* remove the first element of the argument list */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
57 void args_remove_first(ARGS *args)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
58 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
59 free(args->argv[0]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
60 memmove(&args->argv[0],
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
61 &args->argv[1],
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
62 args->argc * sizeof(args->argv[0]));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
63 args->argc--;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
64 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
65
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
66 /* add an argument into the front of the argument list */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
67 void args_add_prefix(ARGS *args, const char *s)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
68 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
69 args->argv = (char**)x_realloc(args->argv, (args->argc + 2) * sizeof(char *));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
70 memmove(&args->argv[1], &args->argv[0],
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
71 (args->argc+1) * sizeof(args->argv[0]));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
72 args->argv[0] = x_strdup(s);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
73 args->argc++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
74 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
75
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
76 /* strip any arguments beginning with the specified prefix */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
77 void args_strip(ARGS *args, const char *prefix)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
78 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
79 int i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
80 for (i=0; i<args->argc; ) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
81 if (strncmp(args->argv[i], prefix, strlen(prefix)) == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
82 free(args->argv[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
83 memmove(&args->argv[i],
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
84 &args->argv[i+1],
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
85 args->argc * sizeof(args->argv[i]));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
86 args->argc--;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
87 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
88 i++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
89 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
90 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
91 }