I'm hooking printf-like function that is defined like this:
int Con_Printf(const char *format, ...)
I want to check if a given string is within the arguments or in the final formatted string and if is there, then replace it with another string, but I have the following code to pass the arguments to the original function:
va_list args;
char *parg;
va_start(args, format);
vasprintf(&parg, format, args);
va_end(args);
(*conprint)("%s", parg);
free(parg);
being (*conprint) the original Con_Printf function.
How can I view the string with format applied (i.e arguments replaced into placeholders) to replace what I need and not just pass through all the arguments?
Example: The program calls Con_Printf("%s %s", "foo", "bar"), I want to know in my Con_Printf hook if "bar" is within the arguments, but I don't know how many arguments are there because of the ", ...)" definition of Con_Printf.
If "bar" is found within the arguments, then replace it for "baz" and forward a modified call (*conprint)("%s %s", "foo", "baz") (replaced bar with baz). (*conprint)("foo baz") would do the trick too.
Thanks!
parg=NULL;. BTW, your question is unclear, so edit it. Please give an example of expected behavior. - Basile Starynkevitchview the string after formatting? - Sourav Ghosh