On 8 January 2014 00:29, Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx> wrote: > > You should pass a callback function instead, eg. > > static int nft_chain_json_parse(struct nft_chain *c, const char *json, > struct nft_parse_err *err, > json_t *(*jsonbuilder)(const void *input_data, > const char *treename, > struct nft_parse_err *e)) Ok. > But I don't understand yet what you save (in terms of lines of code) > by using this aproach. I avoid doing something like: nft_*_parse() { switch (type) if XML return xml_parse() if JSON return json_parse() } nft_*_parse_file() { switch (type) if XML return xml_parse_file() if JSON return json_parse_file() } We double the format switch, and also two functions per format are needed to do build and parsing. Total = 6 functions heavily duplicating code. With my approach, we have 1 function that decides which format to parse, and a one function per format to build and do parsing. Total = 3 functions, no duplicate code. -- Arturo Borrero González -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html