Browse code

cmdutils: allow storing per-stream/chapter/.... options in a generic way

Anton Khirnov authored on 2011/08/29 14:54:56
Showing 2 changed files
... ...
@@ -207,6 +207,7 @@ int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef
207 207
 {
208 208
     const OptionDef *po;
209 209
     int bool_val = 1;
210
+    int *dstcount;
210 211
     void *dst;
211 212
 
212 213
     po = find_option(options, opt);
... ...
@@ -231,7 +232,17 @@ unknown_opt:
231 231
 
232 232
     /* new-style options contain an offset into optctx, old-style address of
233 233
      * a global var*/
234
-    dst = po->flags & (OPT_OFFSET) ? (uint8_t*)optctx + po->u.off : po->u.dst_ptr;
234
+    dst = po->flags & (OPT_OFFSET|OPT_SPEC) ? (uint8_t*)optctx + po->u.off : po->u.dst_ptr;
235
+
236
+    if (po->flags & OPT_SPEC) {
237
+        SpecifierOpt **so = dst;
238
+        char *p = strchr(opt, ':');
239
+
240
+        dstcount = (int*)(so + 1);
241
+        *so = grow_array(*so, sizeof(**so), dstcount, *dstcount + 1);
242
+        (*so)[*dstcount - 1].specifier = av_strdup(p ? p + 1 : "");
243
+        dst = &(*so)[*dstcount - 1].u;
244
+    }
235 245
 
236 246
     if (po->flags & OPT_STRING) {
237 247
         char *str;
... ...
@@ -108,6 +108,16 @@ double parse_number_or_die(const char *context, const char *numstr, int type, do
108 108
  */
109 109
 int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration);
110 110
 
111
+typedef struct SpecifierOpt {
112
+    char *specifier;    /**< stream/chapter/program/... specifier */
113
+    union {
114
+        uint8_t *str;
115
+        int        i;
116
+        int64_t  i64;
117
+        float      f;
118
+    } u;
119
+} SpecifierOpt;
120
+
111 121
 typedef struct {
112 122
     const char *name;
113 123
     int flags;
... ...
@@ -126,6 +136,9 @@ typedef struct {
126 126
 #define OPT_DATA   0x1000
127 127
 #define OPT_FUNC2  0x2000
128 128
 #define OPT_OFFSET 0x4000       /* option is specified as an offset in a passed optctx */
129
+#define OPT_SPEC   0x8000       /* option is to be stored in an array of SpecifierOpt.
130
+                                   Implies OPT_OFFSET. Next element after the offset is
131
+                                   an int containing element count in the array. */
129 132
      union {
130 133
         void *dst_ptr;
131 134
         int (*func_arg)(const char *, const char *);