~ubuntu-branches/ubuntu/oneiric/gmerlin/oneiric

« back to all changes in this revision

Viewing changes to lib/cfg_section.c

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2011-02-08 00:38:27 UTC
  • mfrom: (3.2.5 experimental)
  • Revision ID: james.westby@ubuntu.com-20110208003827-0q94ml0vrwryr8fb
Tags: 1.0.0~dfsg-4
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************
2
2
 * gmerlin - a general purpose multimedia framework and applications
3
3
 *
4
 
 * Copyright (c) 2001 - 2010 Members of the Gmerlin project
 
4
 * Copyright (c) 2001 - 2011 Members of the Gmerlin project
5
5
 * gmerlin-general@lists.sourceforge.net
6
6
 * http://gmerlin.sourceforge.net
7
7
 *
207
207
  return 0;
208
208
  }
209
209
 
210
 
 
211
 
/*
212
 
 *  Get/Set values
213
 
 */
214
 
 
215
210
bg_cfg_item_t * bg_cfg_section_find_item(bg_cfg_section_t * section,
216
211
                                         const bg_parameter_info_t * info)
217
212
  {
237
232
  return prev->next;
238
233
  }
239
234
 
240
 
 
241
 
void bg_cfg_section_set_parameter(bg_cfg_section_t * section,
242
 
                                  const bg_parameter_info_t * info,
243
 
                                  const bg_parameter_value_t * value)
244
 
  {
245
 
  bg_cfg_item_t * item;
246
 
 
247
 
  if(!value)
248
 
    return;
249
 
 
250
 
  item = bg_cfg_section_find_item(section, info);
251
 
 
252
 
  if(!item)
253
 
    return;
254
 
  
 
235
static bg_cfg_item_t * find_item_nocreate(bg_cfg_section_t * section,
 
236
                                          const bg_parameter_info_t * info)
 
237
  {
 
238
  bg_cfg_item_t * ret;
 
239
  ret = section->items;
 
240
  while(ret)
 
241
    {
 
242
    if(!strcmp(ret->name, info->name))
 
243
      return ret;
 
244
    ret = ret->next;
 
245
    }
 
246
  return NULL;
 
247
  }
 
248
 
 
249
 
 
250
/*
 
251
 *  Get/Set values
 
252
 */
 
253
 
 
254
static void value_2_item(const bg_parameter_value_t * value,
 
255
                         bg_cfg_item_t * item)
 
256
  {
255
257
  switch(item->type)
256
258
    {
257
259
    case BG_CFG_INT:
280
282
      break;
281
283
      
282
284
    }
283
 
  
 
285
  }
 
286
  
 
287
void bg_cfg_section_set_parameter(bg_cfg_section_t * section,
 
288
                                  const bg_parameter_info_t * info,
 
289
                                  const bg_parameter_value_t * value)
 
290
  {
 
291
  bg_cfg_item_t * item;
 
292
 
 
293
  if(!value)
 
294
    return;
 
295
 
 
296
  item = bg_cfg_section_find_item(section, info);
 
297
 
 
298
  if(!item)
 
299
    return;
 
300
  
 
301
  value_2_item(value, item);
284
302
  }
285
303
 
286
304
static char * parse_string(const char * str, int * len_ret)
438
456
        end_c = str;
439
457
        if(*end_c == '{')
440
458
          end_c++;
441
 
        end_c += gavl_time_parse(end_c, &(item->value.val_time));
 
459
        end_c += gavl_time_parse(end_c, &item->value.val_time);
442
460
        if(*end_c == '}')
443
461
          end_c++;
444
462
        str = end_c;
751
769
 
752
770
  while(infos[num].name)
753
771
    {
754
 
    item = bg_cfg_section_find_item(section, &(infos[num]));
 
772
    item = bg_cfg_section_find_item(section, &infos[num]);
755
773
 
756
774
    if(!item)
757
775
      {
761
779
    if(prefix)
762
780
      {
763
781
      tmp_string = bg_sprintf("%s.%s", prefix, item->name);
764
 
      func(callback_data, tmp_string, &(item->value));
 
782
      func(callback_data, tmp_string, &item->value);
765
783
      free(tmp_string);
766
784
      }
767
785
    else
768
 
      func(callback_data, item->name, &(item->value));
 
786
      func(callback_data, item->name, &item->value);
769
787
 
770
788
    /* If this was a menu, apply children */ 
771
789
 
901
919
 
902
920
  while(infos[num].name)
903
921
    {
904
 
    item = bg_cfg_section_find_item(section, &(infos[num]));
 
922
    item = bg_cfg_section_find_item(section, &infos[num]);
905
923
    if(item)
906
 
      func(callback_data, item->name, &(item->value));
 
924
      func(callback_data, item->name, &item->value);
907
925
    num++;
908
926
    }
909
927
  }
1117
1135
  return ret;
1118
1136
  }
1119
1137
 
 
1138
void bg_cfg_section_transfer_children(bg_cfg_section_t * src, bg_cfg_section_t * dst)
 
1139
  {
 
1140
  bg_cfg_section_t * src_child;
 
1141
  bg_cfg_section_t * dst_child;
 
1142
  src_child = src->children;
 
1143
  
 
1144
  while(src_child)
 
1145
    {
 
1146
    dst_child = bg_cfg_section_find_subsection(dst, src_child->name);
 
1147
    bg_cfg_section_transfer(src_child, dst_child);
 
1148
    src_child = src_child->next;
 
1149
    }
 
1150
  
 
1151
  }
 
1152
 
1120
1153
void bg_cfg_section_transfer(bg_cfg_section_t * src, bg_cfg_section_t * dst)
1121
1154
  {
1122
1155
  bg_cfg_item_t * src_item;
1123
 
  
1124
 
  bg_cfg_section_t * src_child;
1125
 
  bg_cfg_section_t * dst_child;
1126
1156
  bg_parameter_info_t  info;
1127
1157
  /* Copy items */
1128
1158
  
1131
1161
  while(src_item)
1132
1162
    {
1133
1163
    bg_cfg_item_to_parameter(src_item, &info);
1134
 
    bg_cfg_section_set_parameter(dst, &info, &(src_item->value));
 
1164
    bg_cfg_section_set_parameter(dst, &info, &src_item->value);
1135
1165
    src_item = src_item->next;
1136
1166
    }
1137
1167
  
1138
1168
  /* Copy children */
1139
1169
  
1140
 
  src_child = src->children;
1141
 
  
1142
 
  while(src_child)
1143
 
    {
1144
 
    dst_child = bg_cfg_section_find_subsection(dst, src_child->name);
1145
 
    bg_cfg_section_transfer(src_child, dst_child);
1146
 
    src_child = src_child->next;
1147
 
    }
 
1170
  bg_cfg_section_transfer_children(src, dst);
1148
1171
  }
1149
1172
 
1150
1173
 
1200
1223
 
1201
1224
  i = 0;
1202
1225
 
 
1226
  //  if(section->name && !strcmp(section->name, "e_mpeg"))
 
1227
  //    fprintf(stderr, "e_mpeg\n");
 
1228
  
1203
1229
  while(info[i].name)
1204
1230
    {
1205
1231
    if((info[i].type == BG_PARAMETER_SECTION) &&
1227
1253
      //      fprintf(stderr, "Section: %s, parameter: %s\n",
1228
1254
      //            section->name, info[i].name);
1229
1255
      
1230
 
      bg_cfg_section_find_item(section, &(info[i]));
 
1256
      bg_cfg_section_find_item(section, &info[i]);
1231
1257
    
1232
1258
      if(info[i].multi_parameters)
1233
1259
        {
1306
1332
  s->refs[s->num_refs] = ref;
1307
1333
  s->num_refs++;
1308
1334
  }
 
1335
 
 
1336
void bg_cfg_section_restore_defaults(bg_cfg_section_t * s,
 
1337
                                     const bg_parameter_info_t * info)
 
1338
  {
 
1339
  bg_cfg_item_t * item;
 
1340
  int i;
 
1341
  bg_cfg_section_t * subsection;
 
1342
  bg_cfg_section_t * subsubsection;
 
1343
  
 
1344
  while(info->name)
 
1345
    {
 
1346
    if(info->flags & BG_PARAMETER_HIDE_DIALOG)
 
1347
      {
 
1348
      info++;
 
1349
      continue;
 
1350
      }
 
1351
    item = find_item_nocreate(s, info);
 
1352
 
 
1353
    if(!item)
 
1354
      {
 
1355
      info++;
 
1356
      continue;
 
1357
      }
 
1358
    
 
1359
    value_2_item(&info->val_default, item);
 
1360
    
 
1361
    if(info->multi_parameters && bg_cfg_section_has_subsection(s, info->name))
 
1362
      {
 
1363
      subsection = bg_cfg_section_find_subsection(s, info->name);
 
1364
      i = 0;
 
1365
      
 
1366
      while(info->multi_names[i])
 
1367
        {
 
1368
        if(info->multi_parameters[i] &&
 
1369
           bg_cfg_section_has_subsection(subsection, info->multi_names[i]))
 
1370
          {
 
1371
          subsubsection =
 
1372
            bg_cfg_section_find_subsection(subsection, info->multi_names[i]);
 
1373
          bg_cfg_section_restore_defaults(subsubsection,
 
1374
                                          info->multi_parameters[i]);
 
1375
          }
 
1376
        i++;
 
1377
        }
 
1378
      }
 
1379
    
 
1380
    info++;
 
1381
    }
 
1382
  
 
1383
  }