/* Destroy the builtin parameter database. Generally, do this on projectm exit */ int destroy_builtin_param_db() { splay_traverse(free_param, builtin_param_tree); destroy_splaytree(builtin_param_tree); builtin_param_tree = NULL; return SUCCESS; }
/* Private function to close a preset file */ int close_preset(preset_t * preset) { if (preset == NULL) return FAILURE; splay_traverse(free_init_cond, preset->init_cond_tree); destroy_splaytree(preset->init_cond_tree); splay_traverse(free_init_cond, preset->per_frame_init_eqn_tree); destroy_splaytree(preset->per_frame_init_eqn_tree); splay_traverse(free_per_pixel_eqn, preset->per_pixel_eqn_tree); destroy_splaytree(preset->per_pixel_eqn_tree); splay_traverse(free_per_frame_eqn, preset->per_frame_eqn_tree); destroy_splaytree(preset->per_frame_eqn_tree); splay_traverse(free_param, preset->user_param_tree); destroy_splaytree(preset->user_param_tree); splay_traverse(free_custom_wave, preset->custom_wave_tree); destroy_splaytree(preset->custom_wave_tree); splay_traverse(free_custom_shape, preset->custom_shape_tree); destroy_splaytree(preset->custom_shape_tree); free(preset); return SUCCESS; }
void destroy_param_db_tree(splaytree_t * tree) { if (!tree) return; splay_traverse(free_param, tree); destroy_splaytree(tree); }
void destroy_init_cond_tree(splaytree_t * tree) { if (!tree) return; splay_traverse(free_init_cond, tree); destroy_splaytree(tree); }
void destroy_per_point_eqn_tree(splaytree_t * tree) { if (!tree) return; splay_traverse(free_per_point_eqn, tree); destroy_splaytree(tree); }
void reloadPerFrame(char * s, preset_t * preset) { FILE * fs; int slen; char c; int eqn_count = 1; per_frame_eqn_t * per_frame; if (s == NULL) return; if (preset == NULL) return; /* Clear previous per frame equations */ splay_traverse(free_per_frame_eqn, preset->per_frame_eqn_tree); destroy_splaytree(preset->per_frame_eqn_tree); preset->per_frame_eqn_tree = create_splaytree(compare_int, copy_int, free_int); /* Convert string to a stream */ fs = fmemopen (s, strlen(s), "r"); while ((c = fgetc(fs)) != EOF) { ungetc(c, fs); if ((per_frame = parse_per_frame_eqn(fs, eqn_count, preset)) != NULL) { splay_insert(per_frame, &eqn_count, preset->per_frame_eqn_tree); eqn_count++; } } fclose(fs); /* Clear string space */ memset(preset->per_frame_eqn_string_buffer, 0, STRING_BUFFER_SIZE); /* Compute length of string */ slen = strlen(s); /* Copy new string into buffer */ strncpy(preset->per_frame_eqn_string_buffer, s, slen); /* Yet again no bounds checking */ preset->per_frame_eqn_string_index = slen; /* Finished */ printf("reloadPerFrame: %d eqns parsed succesfully\n", eqn_count-1); return; }
void reloadPerPixel(char *s, preset_t * preset) { FILE * fs; int slen; char c; int i; if (s == NULL) return; if (preset == NULL) return; /* Clear previous per pixel equations */ splay_traverse(free_per_pixel_eqn, preset->per_pixel_eqn_tree); destroy_splaytree(preset->per_pixel_eqn_tree); preset->per_pixel_eqn_tree = create_splaytree(compare_int, copy_int, free_int); /* Convert string to a stream */ fs = fmemopen (s, strlen(s), "r"); while ((c = fgetc(fs)) != EOF) { ungetc(c, fs); parse_per_pixel_eqn(fs, preset); } fclose(fs); /* Clear string space */ memset(preset->per_pixel_eqn_string_buffer, 0, STRING_BUFFER_SIZE); /* Compute length of string */ slen = strlen(s); /* Copy new string into buffer */ strncpy(preset->per_pixel_eqn_string_buffer, s, slen); /* Yet again no bounds checking */ preset->per_pixel_eqn_string_index = slen; /* Finished */ return; }
int closePresetDir() { /* No preset director appears to be loaded */ if (chrono_order_preset_name_tree == NULL) return SUCCESS; if (PRESET_DEBUG) { printf("closePresetDir: freeing directory buffer..."); fflush(stdout); } /* Free each entry in the directory preset name tree */ splay_traverse(free_int, chrono_order_preset_name_tree); /* Destroy the chronological order splay tree */ destroy_splaytree(chrono_order_preset_name_tree); chrono_order_preset_name_tree = NULL; preset_name_buffer_size = 0; if (PRESET_DEBUG) printf("finished\n"); return SUCCESS; }
int loadPresetDir(char * dir) { struct dirent ** name_list; char * preset_name; int i, j, dir_size; if (dir == NULL) return ERROR; if (chrono_order_preset_name_tree != NULL) { if (PRESET_DEBUG) printf("loadPresetDir: previous directory doesn't appear to be closed!\n"); /* Let this slide for now */ } /* Scan the entire directory, storing each entry in a dirent struct array that needs to be freed later. For more information, consult scandir(3) in the man pages */ if ((dir_size = scandir(dir, &name_list, 0, alphasort)) < 0) { if (PRESET_DEBUG) printf("loadPresetDir: failed to open directory \"%s\"\n", dir); return ERROR; } chrono_order_preset_name_tree = create_splaytree(compare_int, copy_int, free_int); /* Iterate through entire dirent name list, adding to the preset name list if it is valid */ for (i = 0; ((i < dir_size) && (i < MAX_PRESETS_IN_DIR));i++) { /* Only perform the next set of operations if the preset name contains a valid extension */ if (is_valid_extension(name_list[i]->d_name)) { /* Handle the out of memory case. My guess is xmms would crash before this program would, but whatever...*/ if ((preset_name = (char*)malloc(MAX_PATH_SIZE)) == NULL) { if (PRESET_DEBUG) printf("loadPresetDir: out of memory! \n"); /* Free the rest of the dirent name list */ for (j = i; j < dir_size; j++) free(name_list[j]); destroy_splaytree(chrono_order_preset_name_tree); return OUTOFMEM_ERROR; } /* Now create the full path */ if (get_preset_path(&preset_name, dir, name_list[i]->d_name) < 0) { if (PRESET_DEBUG) printf("loadPresetDir: failed to generate full preset path name!\n"); /* Free the rest of the dirent name list */ for (j = i; j < dir_size; j++) free(name_list[j]); destroy_splaytree(chrono_order_preset_name_tree); return OUTOFMEM_ERROR; } /* Insert the character string into the splay tree, with the key being its sequence number */ splay_insert(preset_name, &preset_name_buffer_size, chrono_order_preset_name_tree); preset_name_buffer_size++; } /* Free the dirent struct */ free(name_list[i]); } free(name_list); /* No valid files in directory! */ if (chrono_order_preset_name_tree->root == NULL) { if (PRESET_DEBUG) printf("loadPresetDir: no valid files in directory \"%s\"\n", dir); destroy_splaytree(chrono_order_preset_name_tree); chrono_order_preset_name_tree = NULL; return FAILURE; } /* Start the prefix index right before the first entry, so next preset starts at the top of the list */ preset_index = -1; /* Start the first preset */ switchPreset(ALPHA_NEXT, HARD_CUT); return SUCCESS; }