Index: release/datafiles/datatoc.c =================================================================== --- release/datafiles/datatoc.c (revision 19711) +++ release/datafiles/datatoc.c (working copy) @@ -22,7 +22,7 @@ * * The Original Code is: all of this file. * - * Contributor(s): none yet. + * Contributor(s): Alex Feterman * * ***** END GPL LICENSE BLOCK ***** */ @@ -31,72 +31,163 @@ #include #include + int main(int argc, char**argv) { FILE *fpin, *fpout; - char cname[256]; + char cname[256] = "splash.jpg.c"; char sizest[256]; - size_t size; + size_t size[265]; int i; + int iparam, file_count; + short expect_output_param = 0; + short output_opened = 0; + char temp_name[256], *tmp_n; + char buffer[1024]; + size_t outsize; + size_t total_outsize; - if (argc<1) { - printf ("Usage: datatoc \n"); - exit(1); + if (argc<2) { + printf ("Usage: datatoc [...] [-o ]\n"); + printf ("If is not specified, '%s' is used by default.\n", &cname); + exit(0); } - - fpin= fopen(argv[1], "rb"); - if (!fpin) { - printf ("Unable to open input <%s>\n", argv[1]); + + tmp_n = tmpnam(temp_name); + if(!tmp_n) { + printf ("Error: could not get temporary filename"); exit(1); } - fseek (fpin, 0L, SEEK_END); - size= ftell(fpin); - fseek (fpin, 0L, SEEK_SET); - - if (argv[1][0]=='.') argv[1]++; - - sprintf(cname, "%s.c", argv[1]); - printf ("Making C file <%s>\n", cname); - - for (i=0; i < (int)strlen(argv[1]); i++) - if (argv[1][i]=='.') argv[1][i]='_'; - - sprintf(sizest, "%d", (int)size); - printf ("Input filesize is %ld, Output size should be %ld\n", size, ((int)size)*4 + strlen("/* DataToC output of file <> */\n\n") + strlen("char datatoc_[]= {\"") + strlen ("\"};\n") + (strlen(argv[1])*3) + strlen(sizest) + strlen("int datatoc__size= ;\n") +(((int)(size/256)+1)*5)); - - fpout= fopen(cname, "w"); + fpout= fopen(temp_name, "wb"); if (!fpout) { - printf ("Unable to open output <%s>\n", cname); + printf ("Unable to create temp file <%s>\n", temp_name); exit(1); } - fprintf (fpout, "/* DataToC output of file <%s> */\n\n",argv[1]); - fprintf (fpout, "int datatoc_%s_size= %s;\n", argv[1], sizest); - /* - fprintf (fpout, "char datatoc_%s[]= {\"", argv[1]); + strcpy(buffer, "/* DataToC output */\x0A\x0A"); + total_outsize = strlen(buffer); + fprintf(fpout, buffer); + + for (iparam = 1, file_count = 0; iparam < argc; ++iparam) + { + /* next parameter expected to be output filename? */ + if (!strcmp(argv[iparam], "-o")) { + if (expect_output_param) { + printf("Output filename expected after '-o'\n"); + exit(1); + } + else { + expect_output_param = 1; + continue; + } + } + + /* this is the output filename */ + if (expect_output_param) { + strcpy(cname, argv[iparam]); + printf ("Output file set to %s\n", cname); + continue; + } + + /* otherwise, open as input file */ + fpin= fopen(argv[iparam], "rb"); + if (!fpin) { + printf ("Unable to open input <%s>\n", argv[iparam]); + continue; + } + + /* sizes are later required; store them */ + fseek (fpin, 0L, SEEK_END); + size[file_count]= ftell(fpin); + fseek (fpin, 0L, SEEK_SET); - while (size--) { - if(size%256==0) - fprintf(fpout, "\" \\\n\""); + /* init per-file output text size stats */ + outsize = 0; - fprintf (fpout, "\\x%02x", getc(fpin)); - } + sprintf (buffer, "static char datatoc_splash_jpg_%d[] = {\x0A/* Contents of '%s' */\x0A", file_count, argv[iparam]); + outsize += strlen(buffer); + fprintf (fpout, buffer); - fprintf (fpout, "\"};\n"); - */ - - fprintf (fpout, "char datatoc_%s[]= {\n", argv[1]); - while (size--) { - if(size%32==31) - fprintf(fpout, "\n"); + i = size[file_count]; + outsize += i * 4; + while (i--) { + if(i%32==31) { + putc('\x0A', fpout); + outsize++; + } + fprintf (fpout, "%3d,", getc(fpin)); + } - /* fprintf (fpout, "\\x%02x", getc(fpin)); */ - fprintf (fpout, "%3d,", getc(fpin)); + /* null terminate for the case it is a string */ + strcpy (buffer, "0\x0A};\x0A\x0A"); + outsize += strlen (buffer); + fprintf (fpout, buffer); + + /* close input file and tally */ + fclose(fpin); + ++file_count; + printf("Processed: %s; added output should be %ld bytes long\n", argv[iparam], outsize); + total_outsize += outsize; } - /* null terminate for the case it is a string */ - fprintf (fpout, "\n 0};\n\n"); - fclose(fpin); + /* print pointer block, block sizes and close file */ + sprintf (buffer, " int datatoc_block_count = %d;\x0A\x0A int datatoc_splash_jpg_size[]={", file_count); + fprintf(fpout, buffer); + total_outsize += strlen (buffer); + for (i = 0; i < file_count; ++i) { + sprintf(buffer, "%s%ld", (i ? "," : ""), (int)size[i]); + total_outsize += strlen (buffer); + fprintf(fpout, buffer); + } + sprintf(buffer, "};\x0A\x0A char *datatoc_splash_jpg[] = {"); + total_outsize += strlen (buffer); + fprintf(fpout, buffer); + for (i = 0; i < file_count; ++i) { + sprintf(buffer, "%s&datatoc_splash_jpg_%d", (i ? "," : ""), i); + total_outsize += strlen (buffer); + fprintf(fpout, buffer); + } + sprintf(buffer, "};\x0A"); + total_outsize += strlen (buffer); + fprintf(fpout, buffer); fclose(fpout); + + printf("Done processing. Total output should be %ld bytes.\n", (int)total_outsize); + + /* what if a previous file with that name exists? let's ask the user */ + fpin = fopen(cname, "r"); + while (fpin) + { + printf("File '%s' exists: [o]verwrite, [a]bort, [d]ifferent name? ", cname); + gets(buffer); + switch(*buffer) + { + case 'o': + case 'O': + fclose(fpin); + printf("Overwriting\n"); + if (remove(cname)) + { + printf("Error: failed to remove existing '%s'\n", cname); + exit(1); + } + fpin = NULL; + break; + case 'd': + case 'D': + fclose(fpin); + printf("New name: "); + while(!gets(cname)); + fpin = fopen(cname, "r"); + break; + case 'a': + case 'A': + fclose(fpin); + printf("Aborting."); + exit(1); + } + } + rename(temp_name, cname); + return 0; } Index: source/blender/include/BIF_screen.h =================================================================== --- source/blender/include/BIF_screen.h (revision 19711) +++ source/blender/include/BIF_screen.h (working copy) @@ -93,6 +93,7 @@ void screen_swapbuffers(void); void set_debug_swapbuffers_ovveride(struct bScreen *sc, int mode); int is_allowed_to_change_screen(struct bScreen *newp); +void get_rotating_splash_data(void **ptr, int *size); void splash(void * data, int datasizei, char * string); void screen_delayed_undo_push(char *name); void screenmain(void); Index: source/blender/src/editscreen.c =================================================================== --- source/blender/src/editscreen.c (revision 19711) +++ source/blender/src/editscreen.c (working copy) @@ -1542,13 +1542,12 @@ mainqenter(PKEY, 1); } else { - extern char datatoc_splash_jpg[]; - extern int datatoc_splash_jpg_size; + void *splash_data; int *splash_size; + get_rotating_splash_data(&splash_data, &splash_size); //if (! ((G.main->versionfile >= G.version) // || G.save_over)) { - splash((void *)datatoc_splash_jpg, - datatoc_splash_jpg_size, NULL); + splash(splash_data, splash_size, NULL); //} } firsttime = 0; Index: source/blender/src/headerbuttons.c =================================================================== --- source/blender/src/headerbuttons.c (revision 19711) +++ source/blender/src/headerbuttons.c (working copy) @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -454,12 +455,29 @@ do_update_for_newframe(nosound, 0); } +static int rotating_splash = -1; +/* rotates the splash image, randomizing the first one to show */ +void get_rotating_splash_data(void **pptr, int *psize) +{ + extern char *datatoc_splash_jpg[]; + extern int datatoc_splash_jpg_size[]; + extern int datatoc_block_count; + + if (rotating_splash == -1) + rotating_splash = time(NULL) % datatoc_block_count; + else if (++rotating_splash >= datatoc_block_count) + rotating_splash = 0; + *pptr = (void*)datatoc_splash_jpg[rotating_splash]; + *psize = datatoc_splash_jpg_size[rotating_splash]; +} + static void show_splash(void) { - extern char datatoc_splash_jpg[]; - extern int datatoc_splash_jpg_size; + void *splash_data; int *splash_size; char *string = NULL; + + get_rotating_splash_data(&splash_data, &splash_size); #ifdef NAN_BUILDINFO char buffer[1024]; @@ -473,7 +491,7 @@ sprintf(string,"Built on %s %s, Rev-%s Version %s %s", build_date, build_time, build_rev, build_platform, build_type); #endif - splash((void *)datatoc_splash_jpg, datatoc_splash_jpg_size, string); + splash(splash_data, splash_size, string); } Index: source/blender/src/splash.jpg.c =================================================================== --- source/blender/src/splash.jpg.c (revision 19711) +++ source/blender/src/splash.jpg.c (working copy) @@ -1,7 +1,7 @@ -/* DataToC output of file */ +/* DataToC output */ -int datatoc_splash_jpg_size= 288981; -char datatoc_splash_jpg[]= { +static char datatoc_splash_jpg_0[] = { +/* Contents of 'splash.jpg' */ 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 1,245, 0, 0, 1, 26, 8, 6, 0, 0, 0, 8, 90,206, 70, 0, 0, 0, 1,115, 82, 71, 66, 0,174,206, 28,233, 0, 0, 0, 6, 98, 75, 71, 68, 0,255, 0,255, 0,255,160,189,167,147, 0, 0, 0, 9,112, 72, 89,115, 0, 0, 11, 19, 0, 0, 11, 19, 1, 0,154,156, 24, @@ -9032,5 +9032,11 @@ 235, 30, 39,112,203,184, 61,209,250,172,141,253, 58, 49, 95,139,172,184,233, 52, 17, 76, 37,194, 42,192,165, 14,231,196,145,201, 54, 93,253, 99, 57, 96, 91,247,115,110,176,195, 19,145,222,103, 93,138,158,190,124,242,172, 83,184,237,179,103, 69, 66,143,238, 218, 25, 82,206, 62,149,189,255,103, 76, 38,125,170,112, 18,135,219,106, 92,240, 89,246, 5,174,249,193,233,110, 21,225, 1,105, -202,143, 10,215, 4,158,114, 48,217,133,255, 31,241, 38, 60, 68,184, 86,227, 95, 0, 0, 0, 0, 73, 69, 78, 68,174, 66, 96,130, +202,143, 10,215, 4,158,114, 48,217,133,255, 31,241, 38, 60, 68,184, 86,227, 95, 0, 0, 0, 0, 73, 69, 78, 68,174, 66, 96,130,0 }; + + int datatoc_block_count = 1; + + int datatoc_splash_jpg_size[]={288981}; + + char *datatoc_splash_jpg[] = {&datatoc_splash_jpg_0};