/*! \note Still very unsafe, but I need to redo everything later anyway. */ void grs_run(GritShared *grs, GritRec *gr_base) { // Make sure we have shared data. if( grs->dib==NULL && grs->palRec.data==NULL) { lprintf(LOG_WARNING, "No shared data to run with!\n"); return; } // Make copy of gr_base for flags, etc GritRec *gr= grit_alloc(); grs_free(gr->shared); grit_copy_options(gr, gr_base); grit_copy_strings(gr, gr_base); // Attach shared data gr->shared= grs; strrepl(&gr->symName, grs->symName); strrepl(&gr->dstPath, grs->dstPath); if(grs->dib == NULL) { // Palette only. Create new dib. gr->srcDib= dib_alloc(16, 16, 8, NULL); memset(dib_get_pal(gr->srcDib), 0, PAL_MAX*RGB_SIZE); memcpy(dib_get_pal(gr->srcDib), grs->palRec.data, rec_size(&grs->palRec)); } else gr->srcDib= dib_clone(grs->dib); // NOTE: aliasing screws up deletion later; detach manually. gr->_dib= gr->srcDib; // Run for shared gr do { if(!grit_validate(gr)) break; bool grit_prep_gfx(GritRec *gr); bool grit_prep_shared_pal(GritRec *gr); if(gr->gfxProcMode != GRIT_EXCLUDE) grit_prep_gfx(gr); if(gr->palProcMode != GRIT_EXCLUDE) grit_prep_shared_pal(gr); if(gr->bExport) grit_export(gr); } while(0); gr->_dib= NULL; // Detach shared data and delete gr gr->shared= NULL; grit_free(gr); }
/*! After filling in a grit-rec, pass it to this function and you're pretty much done. \param gr A filled (but not necessarily validated) grit-rec. \return \c true for success, \c false for failure \todo Create a set of individual error messages for the various stages. */ bool grit_run(GritRec *gr) { time_t aclock; struct tm *newtime; char str[96]; time( &aclock ); newtime = localtime( &aclock ); strftime(str, 96, "Started run at: %Y-%m-%d, %H:%M:%S\n", newtime); lprintf(LOG_STATUS, str); if(grit_validate(gr) == false) return false; if(grit_prep(gr) == false) return false; if(gr->bExport) if(grit_export(gr) == false) return false; lprintf(LOG_STATUS, "Run completed :).\n"); return true; }