I have an application which is written in C and logs my function calls by writing them to a file.
Now I need to re-use these logged function calls in another C-application (which is also the reason for logging).
This application should do – next to other things – exactly the things which were logged.
example:
MYLOGFILE which was written by the first application
printf("Starting main process w/ pid %d\n", (int)getpid());
Display *dsp = XOpenDisplay( NULL );
Then the second application shall execute the function calls logged and taken from the file.
Any ideas how to realize that?
In essence, you want to generate C code and have that code executed, right? If this is is the case, you can check TCC that is available as a library and provides exactly this functionality.
Of course assuming your platform is among the supported ones.
That said I would rather avoid emitting C code and having another application reading it, compiling it and executing it. I would suggest you one of the following:
invent your own language and emit it in your logfile. Then write an interpreter for that language and make the other program read and interpret the log file.
Embed a scripting language (i.e. Lua) in your second program and emit your logfile in that language.
Which solution would work best depends on the complexity of the tasks you have to describe in your logfile.
As very last solution, assuming you want to emit C you can consider using
system()to invoke your compiler and than the compiled program. But I would really really discourage you to do so!