[MPlayer-dev-eng] [PATCH] tv config in file (load/save)

Ötvös Attila oattila at chello.hu
Sat Sep 22 18:05:58 CEST 2007


2007. szeptember 20. 19.33 dátummal Vladimir Voroshilov ezt írta:
> Here is rewrited version.
>
> Changes:
> 1. Since implementation of "global" section support (replacing entire
> -tv option) is not yet clear enough, i'll decide to remove that code
> from patch. At this time config file can contain only "default" and
> channels sections.
>
> 2.if channels option is specified in config file or command line,
> loading of tv.conf will be disabled.
> I've also added apropriate note into man page about this behaviour.
>
> 3. config option can contain only file name (no more "yes" or "no" there).
> File is used only if above option is specified.
>
> 4. added doxygen comments to new routines.
>
> 5. parsing code is simplified, comments are added.
>
> 6. new parsing code does not load entire config file into memory
> buffer, it parses
> config line-by-line. Additional restrinction: line can not be larger
> than 1024 bytes.
>
> 7. several memory leaks fixed.

Hi Vladimir Voroshilov!

I corrected some fault and allow remark after option value.

@@ -468,7 +468,7 @@
             new_entry = 1;
             channel_tmp = m_struct_alloc(tv_config_section[i].mstruct);
             if(!channel_tmp) return 0;
-            *channel_tmp = tv_channels_defaults;
+            m_struct_reset(tv_config_section[i].mstruct, channel_tmp, NULL);
             channel_tmp->name=malloc(TV_CHANNELS_NAME_SIZE+1);
             av_strlcpy(channel_tmp->name,section,TV_CHANNELS_NAME_SIZE);
         }

If string option is copy string pointer instead of string value.

@@ -503,6 +503,24 @@
 }
 
 /**
+ * \brief convert string between " or ' to string
+ * \param txt string between " or '
+ * \return txt end after position
+ */
+static char* text2text(char *txt) {
+    char *next, sep=*txt;
+    int skip=0;
+
+    next=++txt;
+    while (*next && (*next!=sep || skip)) {
+        skip=(*next=='\\');
+        next++;
+        }
+    if (*next==sep) *next++=0;
+    return next;
+}
+
+/**
  * \brief tv config file parsing routine
  * \param tv_param tv parameters structure
  *
@@ -557,13 +575,14 @@
 
         //section name
         if (*name=='[') {
+            if(section)
+                free(section);
+            section=NULL;
             if(!(tmp=strchr(name,']'))){
                 mp_msg(MSGT_TV,MSGL_ERR, "Config file parsing error at 
line %d\n",line);
-                break;
+                continue;
             }
             *tmp='\0';
-            if(section)
-                free(section);
             section=strdup(name+1);
             if(!section)
                 break;
@@ -572,19 +591,19 @@
         //option outside any section
         if(!section){
             mp_msg(MSGT_TV,MSGL_ERR, "Config file parsing error at 
line %d\n",line);
-            break;
+            continue;
         }
 
         //empty name for option
         if(*name=='='){
             mp_msg(MSGT_TV,MSGL_ERR, "Config file parsing error at 
line %d\n",line);
-            break;
+            continue;
         }
 
         //option line must have '='
         if (!(value=strchr(name,'='))) {
             mp_msg(MSGT_TV,MSGL_ERR, "Config file parsing error at 
line %d\n",line);
-            break;
+            continue;
         }
 
         //trimming spaces from the end of option's name

loadtvconfig don't break parsing if error config line.

@@ -597,21 +616,23 @@
         //trimming spaces from beginning of option's value
         for(value++; *value && isspace(*value); value++) /* NOP */;
             
-
+        if(*value=='"' || *value=='\'') {
+            //convert string between " or ' to string
+            text2text(value);
+            value++;
+        } else {
+            //splitting remark if exist
+            if ((tmp=strchr(value,'#'))) 
+                *tmp='\0'; 
         //trimming spaces from end of option's value
         for(tmp=value+strlen(value)-1; tmp>value && isspace(*tmp); tmp--)
             *tmp='\0';

Allow remark after values and string between " or ':
channel=52	# BBC
channel="52"
channel='52'

-
-        //empty value for option
-        if(*value=='\n' || *value=='\0'){
-            mp_msg(MSGT_TV,MSGL_ERR, "Config file parsing error at 
line %d\n",line);
-            break;
         }
 
savetvconfig create empty value of option eg:
channel=

 	//name and value can contain spaces at end!!
         if(!tv_parse_config_item(section,name,value,&last_tv_channels)){
             mp_msg(MSGT_TV,MSGL_ERR, "Config file parsing error at 
line %d\n",line);
-            break;
+            continue;
         }
 
     }
@@ -782,8 +803,6 @@
         parse_channels(tvh);
     else if (tvh->tv_param->tvconfig)
         loadtvconfig(tvh);
-    else
-        tv_channel_last_real = malloc(5);
 
     if (tv_channel_list) {
 	int i;
@@ -822,6 +841,7 @@
 	tv_set_freq(tvh, (unsigned long)
(((float)tv_channel_current->freq/1000)*16));
 	tv_channel_last = tv_channel_current;
     } else {
+        tv_channel_last_real = malloc(5);
     /* we need to set frequency */
     if (tvh->tv_param->freq)
     {

mplayer crash if don't parsed channel (in tv channel step)

@@ -887,8 +907,8 @@
  * \param mstruct option struct
  * \param section section name
  * \param data data structure to save info from 
- * \param defaultdata data structure with default values (1-save all options, 
0-only changed)
- * \param saveall whether to save options with default values
+ * \param defaultdata data structure with default values
+ * \param saveall whether to save options with default values (1-save all 
options, 0-only changed)
  *
  * \note data and defaultdata must points to strucutre of the same type!
  *

Remark correction.

@@ -917,7 +937,7 @@
             ptr=(unsigned char*)defaultdata+(int)(opts->p);
             //empty string will cause m_option_print to fail
             if(opts->type==CONF_TYPE_STRING && (!ptr || *ptr=='\0'))
-                dp="";
+                dp=strdup("");
             else
                 dp=m_option_print(opts,ptr);
             if(!dp){

mplayer crash if free dp=""

Best regard.
Attila
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tvconfig20-new.patch
Type: text/x-diff
Size: 25117 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20070922/7f9b50ba/attachment.patch>


More information about the MPlayer-dev-eng mailing list