At Thu, 29 Jan 2009 00:00:08 +0100, Pavel Hofman wrote: > > Takashi Iwai wrote: > > At Mon, 19 Jan 2009 23:20:49 +0100, > > Pavel Hofman wrote: > >> @@ -84,6 +106,211 @@ typedef struct { > >> #define TO_LE16(x) bswap_16(x) > >> #endif > >> > >> +/* old_string MUST contain the key! */ > >> +int snd_pcm_file_replace_key(char *old_string, char *key, char *value, > >> + char **newstring_p) > > > > Make this static. > > > >> +{ > >> + int str_index, newstr_index, key_index, end, new_len, old_len, cpy_len, > >> + first_key_index; > >> + char *c, *first_c, *newstring; > >> + int keys_count; > >> + > >> + first_c = c = (char *) strstr(old_string, key); > > > > I guess this parser doesn't handle '%%' properly like printf()? > > > >> +int snd_pcm_file_replace_fname(snd_pcm_file_t *file, char **new_fname_p) > > > > Make it static. > > > >> +int snd_pcm_file_has_keys(char *string) > > > > Ditto. > > > >> +int snd_pcm_file_open_output_file(snd_pcm_file_t *file) > > > > Ditto. > > > >> + if (file->final_fname[0] == '|') { > >> + /* pipe mode */ > >> + FILE *pipe; > >> + /* clearing */ > >> + file->final_fname[0] = ' '; > >> + pipe = popen(file->final_fname, "w"); > > > > Pass "file->final_fname + 1", and you don't have to replace the pipe > > with a space. > > > > > > thanks, > > > > Takashi > > Hi Takashi, > > Thanks a lot for your comments. > > Please find enclosed a reworked patch which reflects your requests > including the %% functionality. Thanks, it gets better now. > +static int snd_pcm_file_replace_key(char format, const void *value_p, > + char **string_p, char **index_ch_p, int *len_p) I think it could be easier to make value_str in the caller side. That is, static int snd_pcm_file_replace_key(char **string_p, char **index_ch_p, int *len_p, const char *value_str) { char *value_str, *string, *index_ch; int index, len, value_len; /* input pointer values */ len = *(len_p); string = *(string_p); index_ch = *(index_ch_p); /* reallocation to accommodate the value */ index = index_ch - string; value_len = strlen(value_str); len += value_len; string = realloc(string, len + 1); if (!string) return -ENOMEM; index_ch = string + index; /* concatenating the new value */ strcpy(index_ch, value_str); index_ch += value_len; /* return values */ *(len_p) = len; *(string_p) = string; *(index_ch_p) = index_ch; return 0; } static int snd_pcm_file_replace_fname(snd_pcm_file_t *file, char **new_fname_p) { char value[64]; ... while (old_index_ch <= old_last_ch) { ... /* is %, skipping and checking next letter */ switch (*(++old_index_ch)) { case RATE_KEY: snprintf(value, sizeof(value), "%d', pcm->rate); err = snd_pcm_file_replace_key(&new_fname, &new_index_ch, &new_len, value); if (err < 0) return err; break; case CHANNELS_KEY: snprintf(value, sizeof(value), "%d', pcm->channels); err = snd_pcm_file_replace_key(&new_fname, &new_index_ch, &new_len, value); if (err < 0) return err; break; .... case FORMAT_KEY: err = snd_pcm_file_replace_key(&new_fname, &new_index_ch, &new_len, snd_pcm_format_name(pcm->format)); if (err < 0) return err; break; ... Takashi _______________________________________________ Alsa-devel mailing list Alsa-devel@xxxxxxxxxxxxxxxx http://mailman.alsa-project.org/mailman/listinfo/alsa-devel