~ubuntu-branches/ubuntu/saucy/blender/saucy-proposed

« back to all changes in this revision

Viewing changes to source/blender/blenlib/intern/BLI_args.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * A general argument parsing module
3
 
 *
4
 
 *
5
2
 * ***** BEGIN GPL LICENSE BLOCK *****
6
3
 *
7
4
 * This program is free software; you can redistribute it and/or
30
27
 
31
28
/** \file blender/blenlib/intern/BLI_args.c
32
29
 *  \ingroup bli
 
30
 *  \brief A general argument parsing module
33
31
 */
34
32
 
35
 
 
36
33
#include <ctype.h> /* for tolower */
37
34
#include <string.h>
38
35
 
52
49
        const char *short_arg;
53
50
        const char *long_arg;
54
51
        const char *documentation;
55
 
        int  done;
 
52
        int done;
56
53
} bArgDoc;
57
54
 
58
55
typedef struct bAKey {
71
68
struct bArgs {
72
69
        ListBase docs;
73
70
        GHash  *items;
74
 
        int     argc;
 
71
        int argc;
75
72
        const char  **argv;
76
 
        int       *passes;
 
73
        int *passes;
77
74
};
78
75
 
79
76
static unsigned int case_strhash(const void *ptr)
80
77
{
81
 
        const char *s= ptr;
82
 
        unsigned int i= 0;
 
78
        const char *s = ptr;
 
79
        unsigned int i = 0;
83
80
        unsigned char c;
84
81
 
85
 
        while ( (c= tolower(*s++)) )
86
 
                i= i*37 + c;
 
82
        while ( (c = tolower(*s++)) )
 
83
                i = i * 37 + c;
87
84
 
88
85
        return i;
89
86
}
90
87
 
91
 
static unsigned int     keyhash(const void *ptr)
 
88
static unsigned int keyhash(const void *ptr)
92
89
{
93
90
        const bAKey *k = ptr;
94
 
        return case_strhash(k->arg); // ^ BLI_ghashutil_inthash((void*)k->pass);
 
91
        return case_strhash(k->arg);  /* ^ BLI_ghashutil_inthash((void *)k->pass); */
95
92
}
96
93
 
97
94
static int keycmp(const void *a, const void *b)
105
102
                        return strcmp(ka->arg, kb->arg);
106
103
        }
107
104
        else {
108
 
                return BLI_ghashutil_intcmp((const void*)ka->pass, (const void*)kb->pass);
 
105
                return BLI_ghashutil_intcmp((const void *)ka->pass, (const void *)kb->pass);
109
106
        }
110
107
}
111
108
 
176
173
        return d;
177
174
}
178
175
 
179
 
static void internalAdd(struct bArgs *ba, const char *arg, int pass, int case_str, BA_ArgCallback cb, void *data, bArgDoc *d)
 
176
static void internalAdd(struct bArgs *ba, const char *arg, int pass,
 
177
                        int case_str, BA_ArgCallback cb, void *data, bArgDoc *d)
180
178
{
181
179
        bArgument *a;
182
180
        bAKey *key;
185
183
 
186
184
        if (a) {
187
185
                printf("WARNING: conflicting argument\n");
188
 
                printf("\ttrying to add '%s' on pass %i, %scase sensitive\n", arg, pass, case_str == 1? "not ": "");
189
 
                printf("\tconflict with '%s' on pass %i, %scase sensitive\n\n", a->key->arg, (int)a->key->pass, a->key->case_str == 1? "not ": "");
 
186
                printf("\ttrying to add '%s' on pass %i, %scase sensitive\n",
 
187
                       arg, pass, case_str == 1 ? "not " : "");
 
188
                printf("\tconflict with '%s' on pass %i, %scase sensitive\n\n",
 
189
                       a->key->arg, (int)a->key->pass, a->key->case_str == 1 ? "not " : "");
190
190
        }
191
191
 
192
192
        a = MEM_callocN(sizeof(bArgument), "bArgument");
204
204
        BLI_ghash_insert(ba->items, key, a);
205
205
}
206
206
 
207
 
void BLI_argsAddCase(struct bArgs *ba, int pass, const char *short_arg, int short_case, const char *long_arg, int long_case, const char *doc, BA_ArgCallback cb, void *data)
 
207
void BLI_argsAddCase(struct bArgs *ba, int pass,
 
208
                     const char *short_arg, int short_case,
 
209
                     const char *long_arg, int long_case,
 
210
                     const char *doc, BA_ArgCallback cb, void *data)
208
211
{
209
212
        bArgDoc *d = internalDocs(ba, short_arg, long_arg, doc);
210
213
 
217
220
 
218
221
}
219
222
 
220
 
void BLI_argsAdd(struct bArgs *ba, int pass, const char *short_arg, const char *long_arg, const char *doc, BA_ArgCallback cb, void *data)
 
223
void BLI_argsAdd(struct bArgs *ba, int pass,
 
224
                 const char *short_arg, const char *long_arg,
 
225
                 const char *doc, BA_ArgCallback cb, void *data)
221
226
{
222
227
        BLI_argsAddCase(ba, pass, short_arg, 0, long_arg, 0, doc, cb, data);
223
228
}
243
248
 
244
249
                internalDocPrint(d);
245
250
 
246
 
                d->done = 1;
 
251
                d->done = TRUE;
247
252
        }
248
253
}
249
254
 
262
267
{
263
268
        int i = 0;
264
269
 
265
 
        for ( i = 1; i < ba->argc; i++) { /* skip argv[0] */
 
270
        for (i = 1; i < ba->argc; i++) {  /* skip argv[0] */
266
271
                if (ba->passes[i] == 0) {
267
 
                         /* -1 signal what side of the comparison it is */
 
272
                        /* -1 signal what side of the comparison it is */
268
273
                        bArgument *a = lookUp(ba, ba->argv[i], pass, -1);
269
274
                        BA_ArgCallback func = NULL;
270
275
                        void *data = NULL;