# HG changeset patch # User Binki # Date 2009-02-19 23:05:33 # Node ID d643c8d1d8a8216ba930d2c60fd97f7e880030fd # Parent 63137fbb5790ac900c2c86ee62bf15e88b231557 some code rewriting diff --git a/src/client/distren.c b/src/client/distren.c --- a/src/client/distren.c +++ b/src/client/distren.c @@ -17,11 +17,36 @@ along with DistRen. If not, see . */ -#include +#include /* sprintf, printf */ +#include /* malloc, free */ +#include /* strlen */ + +/* this function should probably not exist. asprintf should be used instead of sprintf */ +size_t intstrlen(size_t theint) +{ + size_t len = 0; /* if the number is single digit, this will be incremented */ + do + { + theint /= 10; + len ++; + } + while(theint > 0); + + return len; +} + int main(int argc, char *argv[]) { + char *blendercmd; + char *filename = "file.blend"; /* declares a variable to hold the file name */ + char *format = "blender.exe -b \"%s\" -o //tmp/frame -f %d -F JPEG -x 1"; /* the format string to pass to sprintf */ + unsigned int frame_to_render; + size_t blenderstrlen; + + int toreturn; + //just prove that linking to the shared lib werkz genericfunc(); execlisten(); @@ -34,16 +59,19 @@ int main(int argc, char *argv[]) * url to dl .blend file */ - int frame_to_render; + frame_to_render = 10; // temporary, the number 10 will be replaced with a function call - char file_name[25]; // declares a variable to hold the file name - // file_name = job.file_name // retrieves file name from the blender structure + // file_name = job.file_name // retrieves file name from the blender structure ? - char string[100]; - sprintf(string, "blender.exe -b (filename).blend -o //tmp/frame -f %d -F JPEG -x 1", frame_to_render); + blenderstrlen = strlen(format) - 2 * 2 /* format string minus placeholders */ + strlen(filename) + intstrlen(frame_to_render) + 1 /* NULL terminator */; + blendercmd = malloc(blenderstrlen); + snprintf(blendercmd, blenderstrlen, format, filename, frame_to_render); + + fprintf(stderr, "will run ``%s''\n", blendercmd); - system(string); + toreturn = system(blendercmd); + free(blendercmd); - return 0; + return toreturn; }