static void poddraw_save( void ) { char buf[64]; int x; int choice; FILE * fp; time_t t; struct tm * current_time; choice = pz_dialog( _("Save?"), _("Save this image?"), 2, 0, _("Yes"), _("No")); if( choice == 1 ) return; if( !poddraw_buffer ) return; t = time( NULL ); current_time = localtime( &t ); strftime( buf, 64, "%Y-%m-%d_%H%M.ppm", current_time ); fp = fopen( buf, "w" ); if( !fp ) return; fprintf( fp, "P3\n" ); fprintf( fp, "#generated by poddraw/podzilla\n" ); fprintf( fp, "%d %d 255\n", screen_info.cols, screen_info.rows - HEADER_TOPLINE ); for( x=0 ; x< (screen_info.cols * (screen_info.rows - HEADER_TOPLINE)) ; x++ ) { fprintf( fp, "%d %d %d\n", (int)poddraw_buffer[x] & 0x000000ff, (int)(poddraw_buffer[x]>>8) & 0x000000ff, (int)(poddraw_buffer[x]>>16) & 0x000000ff ); } fclose( fp ); pz_message_title (_("Save"), _("Saved.")); }
void pz_modules_init(char *path) { #ifdef IPOD #define MODULEDIR "/opt/Base:/opt/Emulators:/opt/Media:/opt/Tools:/opt/Zillae" #else #define MODULEDIR "modules" #endif /* Used for the progress bar */ TWindow * sliderwin; TWidget * slider; int sliderVal=0; int verbosity = pz_get_int_setting( pz_global_config, VERBOSITY ); #define MAXSLIDERVAL (100) #define SETUPSECTIONS (6) PzModule *last, *cur; int i; int modCount=0; if (module_head) { pz_error (_("modules_init called more than once")); return; } /* set up the screen to show a pretty progress bar */ sliderwin = ttk_new_window(); ttk_window_hide_header(sliderwin); sliderwin->x = sliderwin->y = 0; slider = ttk_new_slider_widget(2, ttk_screen->h/3, ttk_screen->w - 8, 0, MAXSLIDERVAL, &sliderVal, 0); slider->x = (sliderwin->w - slider->w)/2; ttk_add_widget(sliderwin, slider); sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 1; updateprogress(sliderwin, slider, sliderVal, _("Scanning For Modules"), NULL); if (!path) path = MODULEDIR; path = strtok(strdupa(path), ":"); while (path) { find_modules (path); path = strtok(NULL, ":"); } sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 2; updateprogress(sliderwin, slider, sliderVal, _("Reading Modules"), NULL); for (i = 0; i < __pz_builtin_number_of_init_functions; i++) { int found = 0; const char *name = __pz_builtin_names[i]; cur = module_head; while (cur) { char *p = strrchr (cur->podpath, '/'); if (!p) p = cur->podpath; else p++; if (!strncmp (p, name, strlen (name)) && !isalpha (p[strlen (name)])) { found = 1; break; } cur = cur->next; } if (!found) { if (module_head) { cur = module_head; while (cur->next) cur = cur->next; cur->next = calloc (1, sizeof(PzModule)); cur = cur->next; } else { cur = module_head = calloc (1, sizeof(PzModule)); } cur->podpath = 0; cur->name = strdup (__pz_builtin_names[i]); cur->init = __pz_builtin_init_functions[i]; cur->to_load = -1; cur->ordered = 0; cur->next = 0; } } if (!module_head) { pz_message_title (_("Warning"), _("No modules. podzilla will probably be very boring.")); return; } /* Used to initialize the window + progressbar used in loading the modules*/ cur = module_head; while (cur) { modCount++; cur = cur->next; } sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 3; updateprogress(sliderwin, slider, sliderVal, _("Mounting Modules"), NULL); // Mount 'em cur = module_head; last = 0; while (cur) { if (cur->podpath && cur->extracted) { cur->mountpt = strdup (cur->podpath); last = cur; cur = cur->next; } else if (cur->podpath && mount_pod (cur) == -1) { if (last) last->next = cur->next; else module_head = cur->next; free (cur->podpath); free (cur); cur = last? last->next : module_head; } else { last = cur; cur = cur->next; } } sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 4; updateprogress(sliderwin, slider, sliderVal, _("Scanning Module Info"), NULL); // Load the module.inf's cur = module_head; while (cur) { load_modinf (cur); cur = cur->next; } sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 5; updateprogress(sliderwin, slider, sliderVal, _("Module Dependencies"), NULL); // Figure out the dependencies cur = module_head; last = 0; while (cur) { if (fix_dependencies (cur, 1, SOFTDEP) == -1 || fix_dependencies(cur, 1, HARDDEP) == -1) { if (last) last->next = cur->next; else module_head = cur->next; free_module (cur); cur = last? last->next : module_head; } else { last = cur; cur = cur->next; } } // Check which ones are linked in cur = module_head; last = 0; while (cur) { for (i = 0; i < __pz_builtin_number_of_init_functions; i++) { if (!strcmp (__pz_builtin_names[i], cur->name)) { cur->init = __pz_builtin_init_functions[i]; cur->to_load = -1; cur->ordered = 0; } } cur = cur->next; } // XXX. For now, we use a slow method for deps, and it'll crash // for circular deps. davidc__ is working on a // better solution. cur = module_head; while (cur) { add_deps (cur); cur = cur->next; } sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 6; updateprogress(sliderwin, slider, sliderVal, _("Loading Modules"), NULL); struct dep *c = load_order; while (c) { if (c->mod->to_load > 0) { do_load (c->mod); } if( verbosity < VERBOSITY_ERRORS && c->mod->longname ) { updateprogress(sliderwin, slider, sliderVal, _("Loading Modules"), c->mod->longname ); } c = c->next; } c = load_order; sliderVal = 0; updateprogress(sliderwin, slider, sliderVal, _("Initializing Modules"), NULL); /* trigger the sliders to switch to init mode, restting the slider */ sliderVal = 0; /* initialize the modules */ while (c) { sliderVal += MAXSLIDERVAL / modCount; current_module = c->mod; updateprogress(sliderwin, slider, sliderVal, _("Initializing Modules"), (verbosity < 2)? c->mod->longname : NULL ); do_init (c->mod); c = c->next; } sliderVal = MAXSLIDERVAL; updateprogress(sliderwin, slider, sliderVal, _("Finishing Up..."), NULL); // Any modules with unrecoverable errors on loading set mod->to_free. // Oblige them. cur = module_head; last = 0; while (cur) { if (cur->to_free) { if (last) last->next = cur->next; else module_head = cur->next; free_module (cur); cur = last? last->next : module_head; } else { last = cur; cur = cur->next; } } ttk_free_window (sliderwin); }