control: add hexadecimal parse
PATCH 1/2 control: add hexadecimal parse
From: "Lu, Han" <[email protected]>
src/control/ctlparse.c +8 -2
@@ -59,7 +59,10 @@ static long get_integer(const char **ptr, long min, long max) goto out; s = p; - val =strtol (s, &p,10 ); +if (*p =='0' && (*(p+1 ) =='x' || *(p+1 ) =='X' )) + val =strtol (s, &p,16 ); +else + val =strtol (s, &p,10 );if (*p =='.' ) { p++;strtol (p, &p,10 );
@@ -87,7 +90,10 @@ static long long get_integer64(const char **ptr, long long min, long long max) goto out; s = p; - val =strtol (s, &p,10 ); +if (*p =='0' && (*(p+1 ) =='x' || *(p+1 ) =='X' )) + val =strtol (s, &p,16 ); +else + val =strtol (s, &p,10 );if (*p =='.' ) { p++;strtol (p, &p,10 );
Signature · 1 line
1.9.1
PATCH 2/2 ucm: add binary file parse
From: "Lu, Han" <[email protected]>
src/ucm/main.c +41 -3
@@ -160,11 +160,45 @@ static int open_ctl(snd_use_case_mgr_t *uc_mgr,return 0 ; } +static int binary_file_parse (snd_ctl_elem_value_t *dst, +const char *filepath) +{ +int err =0 ; +FILE *in; +long len; +char *res; +unsigned int idx; + + in =fopen (filepath,"r" ); +if (!in) { + err = -errno; + goto __fail; + } +fseek (in,0L ,SEEK_END ); + len =ftell (in); +rewind (in); +if (len >512 ) + len =512 ; + res =calloc (1 , (size_t )len); +if (res ==NULL ) { + err = -ENOMEM ; + goto __fail_nomem; + } +fread (res, (size_t )len,1 , in); +for (idx =0 ; idx < len; idx++) +snd_ctl_elem_value_set_byte (dst, idx, *(res + idx)); +free (res); + __fail_nomem: +fclose (in); + __fail: +return err; +} +extern int __snd_ctl_ascii_elem_id_parse (snd_ctl_elem_id_t *dst,const char *str,const char **ret_ptr); -static int execute_cset (snd_ctl_t *ctl,const char *cset) +static int execute_cset (snd_ctl_t *ctl,const char *cset,int isbin) {const char *pos;int err;
@@ -194,7 +228,10 @@ static int execute_cset(snd_ctl_t *ctl, const char *cset) err =snd_ctl_elem_info (ctl, info);if (err <0 ) goto __fail; - err =snd_ctl_ascii_value_parse (ctl, value, info, pos); +if (isbin) + err =binary_file_parse (value, pos); +else + err =snd_ctl_ascii_value_parse (ctl, value, info, pos);if (err <0 ) goto __fail; err =snd_ctl_elem_write (ctl, value);
@@ -239,6 +276,7 @@ static int execute_sequence(snd_use_case_mgr_t *uc_mgr, goto __fail_nomem;break ;case SEQUENCE_ELEMENT_TYPE_CSET : +case SEQUENCE_ELEMENT_TYPE_BCSETF :if (cdev ==NULL ) {const char *cdev1 =NULL , *cdev2 =NULL ; err = get_value3(&cdev1, "PlaybackCTL",
@@ -274,7 +312,7 @@ static int execute_sequence(snd_use_case_mgr_t *uc_mgr, goto __fail; } } - err =execute_cset (ctl, s->data.cset); + err =execute_cset (ctl, s->data.cset, s->isbin);if (err <0 ) {uc_error ("unable to execute cset '%s'\n" , s->data.cset); goto __fail;
src/ucm/parser.c +11 -0
@@ -306,6 +306,17 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED,continue ; } +if (strcmp (cmd,"bcsetf" ) ==0 ) { + curr->type =SEQUENCE_ELEMENT_TYPE_BCSETF ; + curr->isbin =1 ; + err =parse_string (n, &curr->data.cset); +if (err <0 ) { +uc_error ("error: bcsetf requires a string!" ); +return err; + } +continue ; + } +if (strcmp (cmd,"usleep" ) ==0 ) { curr->type =SEQUENCE_ELEMENT_TYPE_SLEEP ; err =snd_config_get_integer (n, &curr->data.sleep);
src/ucm/ucm_local.h +2 -0
@@ -47,6 +47,7 @@#define SEQUENCE_ELEMENT_TYPE_CSET 2#define SEQUENCE_ELEMENT_TYPE_SLEEP 3#define SEQUENCE_ELEMENT_TYPE_EXEC 4 +#define SEQUENCE_ELEMENT_TYPE_BCSETF 5struct ucm_value {struct list_head list;
@@ -63,6 +64,7 @@ struct sequence_element {char *cset;char *exec; } data; +int isbin;/* Indicate cset is binary array or ascii array */ };/*
Signature · 1 line
1.9.1
Re: [PATCH - UCM 2/2] ucm: add binary file parse
At Mon, 12 Jan 2015 13:21:17 +0800,
Quoted 4 lines · [email protected] wrote:
From: "Lu, Han" <[email protected]>
Signed-off-by Lu, Han <[email protected]>
The most important part is missing -- the patch description. Please give a more detailed description, i.e. what this patch does, why this is needed and how it's implemented. (And what does BCSETF mean? Is another form of WTF? :)
thanks,
Takashi
Quoted 131 lines
src/ucm/main.c +41
-3@@ -160,11 +160,45 @@ static int open_ctl(snd_use_case_mgr_t *uc_mgr,return 0 ; } +static int binary_file_parse (snd_ctl_elem_value_t *dst, +const char *filepath) +{ +int err =0 ; +FILE *in; +long len; +char *res; +unsigned int idx; + + in =fopen (filepath,"r" ); +if (!in) { + err = -errno; + goto __fail; + } +fseek (in,0L ,SEEK_END ); + len =ftell (in); +rewind (in); +if (len >512 ) + len =512 ; + res =calloc (1 , (size_t )len); +if (res ==NULL ) { + err = -ENOMEM ; + goto __fail_nomem; + } +fread (res, (size_t )len,1 , in); +for (idx =0 ; idx < len; idx++) +snd_ctl_elem_value_set_byte (dst, idx, *(res + idx)); +free (res); + __fail_nomem: +fclose (in); + __fail: +return err; +} +extern int __snd_ctl_ascii_elem_id_parse (snd_ctl_elem_id_t *dst,const char *str,const char **ret_ptr); -static int execute_cset (snd_ctl_t *ctl,const char *cset) +static int execute_cset (snd_ctl_t *ctl,const char *cset,int isbin) {const char *pos;int err;@@ -194,7 +228,10 @@ static int execute_cset(snd_ctl_t *ctl, const char *cset) err =snd_ctl_elem_info (ctl, info);if (err <0 ) goto __fail; - err =snd_ctl_ascii_value_parse (ctl, value, info, pos); +if (isbin) + err =binary_file_parse (value, pos); +else + err =snd_ctl_ascii_value_parse (ctl, value, info, pos);if (err <0 ) goto __fail; err =snd_ctl_elem_write (ctl, value);@@ -239,6 +276,7 @@ static int execute_sequence(snd_use_case_mgr_t *uc_mgr, goto __fail_nomem;break ;case SEQUENCE_ELEMENT_TYPE_CSET : +case SEQUENCE_ELEMENT_TYPE_BCSETF :if (cdev ==NULL ) {const char *cdev1 =NULL , *cdev2 =NULL ; err = get_value3(&cdev1, "PlaybackCTL",@@ -274,7 +312,7 @@ static int execute_sequence(snd_use_case_mgr_t *uc_mgr, goto __fail; } } - err =execute_cset (ctl, s->data.cset); + err =execute_cset (ctl, s->data.cset, s->isbin);if (err <0 ) {uc_error ("unable to execute cset '%s'\n" , s->data.cset); goto __fail;src/ucm/parser.c +11
-0@@ -306,6 +306,17 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED,continue ; } +if (strcmp (cmd,"bcsetf" ) ==0 ) { + curr->type =SEQUENCE_ELEMENT_TYPE_BCSETF ; + curr->isbin =1 ; + err =parse_string (n, &curr->data.cset); +if (err <0 ) { +uc_error ("error: bcsetf requires a string!" ); +return err; + } +continue ; + } +if (strcmp (cmd,"usleep" ) ==0 ) { curr->type =SEQUENCE_ELEMENT_TYPE_SLEEP ; err =snd_config_get_integer (n, &curr->data.sleep);src/ucm/ucm_local.h +2
-0@@ -47,6 +47,7 @@#define SEQUENCE_ELEMENT_TYPE_CSET 2#define SEQUENCE_ELEMENT_TYPE_SLEEP 3#define SEQUENCE_ELEMENT_TYPE_EXEC 4 +#define SEQUENCE_ELEMENT_TYPE_BCSETF 5struct ucm_value {struct list_head list;@@ -63,6 +64,7 @@ struct sequence_element {char *cset;char *exec; } data; +int isbin;/* Indicate cset is binary array or ascii array */ };/* Signature · 6 lines
1.9.1 _______________________________________________ Alsa-devel mailing list [email protected] http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: [PATCH - UCM 2/2] ucm: add binary file parse
Hi Takashi,
BR,
Han Lu
Quoted 10 lines
-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Monday, January 12, 2015 10:50 PM
To: Lu, Han
Cc: [email protected]
Subject: Re: [alsa-devel] [PATCH - UCM 2/2] ucm: add binary file parseAt Mon, 12 Jan 2015 13:21:17 +0800,
Quoted 1 line · [email protected] wrote:
Quoted 9 lines
Quoted 3 lines
From: "Lu, Han" <[email protected]>
Signed-off-by Lu, Han <[email protected]>The most important part is missing -- the patch description. Please give a more detailed description, i.e. what this patch does, why this is needed and how it's implemented. (And what does BCSETF mean? Is another form of WTF? :)
Sorry, I have added description and resend the patch, please review. Thanks.
Quoted 141 lines
thanks,
Takashi
src/ucm/main.c static int execute_cset(snd_ctl_t *ctl, const char
Quoted 53 lines
src/ucm/main.c index 37ae4c8..1496b22 renamed from src/ucm/main.c +0
-0100644
src/ucm/main.c +35
-1@@ -160,11 +160,45 @@ static int open_ctl(snd_use_case_mgr_t *uc_mgr,return 0 ; } +static int binary_file_parse (snd_ctl_elem_value_t *dst, +const char *filepath) +{ +int err =0 ; +FILE *in; +long len; +char *res; +unsigned int idx; + + in =fopen (filepath,"r" ); +if (!in) { + err = -errno; + goto __fail; + } +fseek (in,0L ,SEEK_END ); + len =ftell (in); +rewind (in); +if (len >512 ) + len =512 ; + res =calloc (1 , (size_t )len); +if (res ==NULL ) { + err = -ENOMEM ; + goto __fail_nomem; + } +fread (res, (size_t )len,1 , in); +for (idx =0 ; idx < len; idx++) +snd_ctl_elem_value_set_byte (dst, idx, *(res + idx)); +free (res); + __fail_nomem: +fclose (in); + __fail: +return err; +} +extern int __snd_ctl_ascii_elem_id_parse (snd_ctl_elem_id_t *dst,const char *str,const char **ret_ptr); -static int execute_cset (snd_ctl_t *ctl,const char *cset) +static int execute_cset (snd_ctl_t *ctl,const char *cset,int isbin) {const char *pos;int err;@@ -194,7 +228,10 @@ static int execute_cset(snd_ctl_t *ctl, const char*cset)
Quoted 12 lines
src/ucm/main.c +4
-1err =snd_ctl_elem_info (ctl, info);if (err <0 ) goto __fail; - err =snd_ctl_ascii_value_parse (ctl, value, info, pos); +if (isbin) + err =binary_file_parse (value, pos); +else + err =snd_ctl_ascii_value_parse (ctl, value, info, pos);if (err <0 ) goto __fail; err = snd_ctl_elem_write(ctl, value); @@ -239,6 +276,7 @@ static intexecute_sequence(snd_use_case_mgr_t
*uc_mgr,src/ucm/main.c static int execute_sequence(snd_use_case_mgr_t *uc_mgr,
Quoted 7 lines
src/ucm/main.c +1
-0goto __fail_nomem;break ;case SEQUENCE_ELEMENT_TYPE_CSET : +case SEQUENCE_ELEMENT_TYPE_BCSETF :if (cdev ==NULL ) {const char *cdev1 =NULL , *cdev2 =NULL ; err = get_value3(&cdev1, "PlaybackCTL", @@-274,7 +312,7 @@
src/ucm/parser.c static int parse_sequence(snd_use_case_mgr_t
Quoted 15 lines
static int execute_sequence(snd_use_case_mgr_t
*uc_mgr,src/ucm/main.c +1
-1goto __fail; } } - err =execute_cset (ctl, s->data.cset); + err =execute_cset (ctl, s->data.cset, s->isbin);if (err <0 ) { uc_error("unable to execute cset '%s'\n", s-data.cset);
src/ucm/main.c +0
-0goto __fail;src/ucm/parser.c index renamed from src/ucm/parser.c +0
-0d7517f6..686c883 100644
src/ucm/parser.c +0
-0@@ -306,6 +306,17 @@ static int parse_sequence(snd_use_case_mgr_t
*uc_mgrATTRIBUTE_UNUSED,Quoted 7 lines
src/ucm/parser.c +4
-0continue ; } +if (strcmp (cmd,"bcsetf" ) ==0 ) { + curr->type =SEQUENCE_ELEMENT_TYPE_BCSETF ; + curr->isbin =1 ; + err =parse_string (n, &curr->data.cset);src/ucm/parser.c static int parse_sequence(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, · line 322
Quoted 10 lines
src/ucm/parser.c +7
-0+if (err <0 ) { +uc_error ("error: bcsetf requires a string!" ); +return err; + } +continue ; + } +if (strcmp (cmd,"usleep" ) ==0 ) { curr->type =SEQUENCE_ELEMENT_TYPE_SLEEP ; err =snd_config_get_integer (n, &curr->data.sleep);diff --git
Quoted 28 lines
a/src/ucm/ucm_local.hb/src/ucm/ucm_local.hindex 87f14a2..80d7335 100644src/ucm/ucm_local.h +2
-1@@ -47,6 +47,7 @@#define SEQUENCE_ELEMENT_TYPE_CSET 2#define SEQUENCE_ELEMENT_TYPE_SLEEP 3#define SEQUENCE_ELEMENT_TYPE_EXEC 4 +#define SEQUENCE_ELEMENT_TYPE_BCSETF 5struct ucm_value {struct list_head list;@@ -63,6 +64,7 @@ struct sequence_element {char *cset;char *exec; } data; +int isbin;/* Indicate cset is binary array or ascii array */ };/* -- 1.9.1
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
At Mon, 12 Jan 2015 13:21:16 +0800,
Quoted 10 lines · [email protected] wrote:
From: "Lu, Han" <[email protected]>
Signed-off-by Lu, Han <[email protected]>src/control/ctlparse.c +0
-0
src/control/ctlparse.c static long get_integer(const char **ptr, long min, long max) · line 65
Quoted 8 lines
src/control/ctlparse.c +4
-1@@ -59,7 +59,10 @@ static long get_integer(const char **ptr, long min, long max) goto out; s = p; - val =strtol (s, &p,10 ); +if (*p =='0' && (*(p+1 ) =='x' || *(p+1 ) =='X' )) + val =strtol (s, &p,16 ); +else + val =strtol (s, &p,10 );
Just pass 0 to the base of strtol() instead of 10. That'll do everything.
Takashi
Hi Takashi,
BR,
Han Lu
Quoted 22 lines
-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Monday, January 12, 2015 3:50 PM
To: Lu, Han
Cc: [email protected]
Subject: Re: [PATCH - UCM 1/2] control: add hexadecimal parseAt Mon, 12 Jan 2015 13:21:16 +0800,
src/control/ctlparse.c static long get_integer(const char **ptr, long min,
Quoted 10 lines · [email protected] wrote:
From: "Lu, Han" <[email protected]>
Signed-off-by Lu, Han <[email protected]>src/control/ctlparse.c index renamed from src/control/ctlparse.c +0
-0978977d..92e2f95 100644
src/control/ctlparse.c +0
-0@@ -59,7 +59,10 @@ static long get_integer(const char **ptr, long min,long max)
Quoted 2 lines
src/control/ctlparse.c +0
-0goto out;
Quoted 9 lines
src/control/ctlparse.c static long get_integer(const char **ptr, long min, long max) · line 65
Quoted 6 lines
src/control/ctlparse.c +4
-1s = p; - val =strtol (s, &p,10 ); +if (*p =='0' && (*(p+1 ) =='x' || *(p+1 ) =='X' )) + val =strtol (s, &p,16 ); +else + val =strtol (s, &p,10 );Just pass 0 to the base of
strtol()instead of 10. That'll do everything.
Thank you, I have validated it and resend the patch.
Quoted 2 lines
Takashi