static gboolean process_image(gpointer parent) { gboolean success = TRUE; image_output imageout = (image_output)g_malloc(sizeof(struct imageout_str)); char* orig_filename = NULL; char* orig_basename = NULL; char* orig_file_ext = NULL; char* output_file_comp = NULL; // store original file path and name orig_filename = g_slist_nth (bimp_input_filenames, processed_count)->data; orig_basename = g_strdup(comp_get_filename(orig_filename)); // store original extension and check error cases orig_file_ext = g_strdup(strrchr(orig_basename, '.')); if (orig_file_ext == NULL) { /* under Linux, GtkFileChooser lets to pick an image file without extension, but GIMP cannot * save it back if its format remains unchanged. Operation can continue only if a MANIP_CHANGEFORMAT * is present */ if (list_contains_changeformat) { orig_file_ext = g_malloc0(sizeof(char)); } else { bimp_show_error_dialog(g_strdup_printf(_("Can't save image \"%s\": input file has no extension.\nYou can solve this error by adding a \"Change format or compression\" step"), orig_basename), bimp_window_main); success = FALSE; goto process_end; } } else if (g_ascii_strcasecmp(orig_file_ext, ".svg") == 0 && !list_contains_changeformat) { bimp_show_error_dialog(g_strdup_printf(_("GIMP can't save %s back to its original SVG format.\nYou can solve this error by adding a \"Change format or compression\" step"), orig_basename), bimp_window_main); success = FALSE; goto process_end; } g_print("\nWorking on file %d of %d (%s)\n", processed_count + 1, total_images, orig_filename); bimp_progress_bar_set(((double)processed_count)/total_images, g_strdup_printf(_("Working on file \"%s\"..."), orig_basename)); // rename and save process... orig_basename[strlen(orig_basename) - strlen(orig_file_ext)] = '\0'; // remove extension from basename // check if a rename pattern is defined if(list_contains_rename) { g_print("Applying RENAME...\n"); apply_rename((rename_settings)(bimp_list_get_manip(MANIP_RENAME))->settings, imageout, orig_basename); } else { imageout->filename = orig_basename; } // To keep the folder hierarchy if (common_folder_path == NULL) { // Not selected or required, everything goes into the same destination folder output_file_comp = g_malloc0(sizeof(char)); } else { // keep folders to add to output path output_file_comp = g_strndup(&orig_filename[strlen(common_folder_path)+1], strlen(orig_filename)-(strlen(common_folder_path)+1) -strlen(orig_basename)-strlen(orig_file_ext)); } if (strlen(output_file_comp) > 0) { #ifdef _WIN32 // Clean output_file_comp // Should only be concerned for ':' in Drive letter int i; for (i = 0; i < strlen(output_file_comp); ++i) if ( output_file_comp[i] == ':' ) output_file_comp[i] = '_'; #endif // Create path if needed g_mkdir_with_parents( g_strconcat(bimp_output_folder, FILE_SEPARATOR_STR, output_file_comp, NULL), 0777 ); } // save the final image in output dir with proper format and params format_type final_format = -1; format_params params = NULL; if(list_contains_changeformat) { changeformat_settings settings = (changeformat_settings)(bimp_list_get_manip(MANIP_CHANGEFORMAT))->settings; final_format = settings->format; params = settings->params; g_print("Changing FORMAT to %s\n", format_type_string[final_format][0]); imageout->filename = g_strconcat(imageout->filename, ".", format_type_string[final_format][0], NULL); // append new file extension imageout->filepath = g_strconcat(bimp_output_folder, FILE_SEPARATOR_STR, output_file_comp, imageout->filename, NULL); // build new path } // TO CHECK what apply_userdef does once coded else if (list_contains_savingplugin) { // leave filename without extension and proceed calling each saving plugin imageout->filename = g_strconcat(imageout->filename, ".dds", NULL); imageout->filepath = g_strconcat(bimp_output_folder, FILE_SEPARATOR_STR, output_file_comp, imageout->filename, NULL); // build new path GSList *iterator = NULL; manipulation man; for (iterator = bimp_selected_manipulations; iterator; iterator = iterator->next) { man = (manipulation)(iterator->data); if (man->type == MANIP_USERDEF && strstr(((userdef_settings)(man->settings))->procedure, "-save") != NULL) { /* found a saving plugin, execute it // TODO!!!! This won't work yet, we need a way to extract the file extension managed by the selected saving plugin * e.g. "file-dds-save" -> "dds" (don't do it with regexp on plugin's name... too easy...) */ apply_userdef((userdef_settings)(man->settings), imageout); } } } else { // if not specified, save in original format imageout->filename = g_strconcat(imageout->filename, orig_file_ext, NULL); // append old file extension imageout->filepath = g_strconcat(bimp_output_folder, FILE_SEPARATOR_STR, output_file_comp, imageout->filename, NULL); // build new path final_format = -1; } // check if writing possible gboolean will_overwrite = FALSE; if (bimp_opt_alertoverwrite != BIMP_OVERWRITE_SKIP_ASK) { // file already exists ? will_overwrite = g_file_test(imageout->filepath, G_FILE_TEST_IS_REGULAR); if (will_overwrite) { // "Don't overwrite" without confirmation if (bimp_opt_alertoverwrite == BIMP_DONT_OVERWRITE_SKIP_ASK) { g_print("Destination file already exists and won't be overwritten\n"); goto process_end; } else { // Ask what to do int ow_res = overwrite_result(imageout->filepath, parent); if (ow_res == 0) { g_print("Destination file already exists and user select to don't overwrite\n"); goto process_end; } } } } // apply all the main manipulations bimp_apply_drawable_manipulations(imageout, (gchar*)orig_filename, (gchar*)orig_basename); time_t mod_time = -1; if (will_overwrite && bimp_opt_keepdates) { // I must keep the dates even if the file has been overwritten mod_time = get_modification_time(imageout->filepath); if (mod_time == -1) g_print("An error occurred when retrieving the modification date of file.\n"); } // Save g_print("Saving file %s in %s\n", imageout->filename, imageout->filepath); image_save(final_format, imageout, params); if (will_overwrite && bimp_opt_keepdates && mod_time > -1) { // replace with the old dates int res = set_modification_time(imageout->filepath, mod_time); if (res == -1) g_print("An error occurred when replacing the modification date of file.\n"); } gimp_image_delete(imageout->image_id); // is it useful? process_end: g_free(orig_basename); g_free(orig_file_ext); g_free(output_file_comp); g_free(imageout->filename); g_free(imageout->filepath); g_free(imageout); processed_count++; if (success) success_count++; // TODO: errors check here if (!bimp_is_busy) { bimp_progress_bar_set(0.0, _("Operations stopped")); g_print("\nStopped, %d files processed.\n", processed_count); return FALSE; } else { if (processed_count == total_images) { int errors_count = processed_count - success_count; bimp_progress_bar_set(1.0, g_strdup_printf(_("End, all files have been processed with %d errors"), errors_count)); g_print("\nEnd, %d files have been processed with %d errors.\n", processed_count, errors_count); bimp_set_busy(FALSE); return FALSE; } else { return TRUE; } } }
String *Swig_name_make(Node *n, String *prefix, const_String_or_char_ptr cname, SwigType *decl, String *oldname) { String *nname = 0; String *result = 0; String *name = NewString(cname); Hash *wrn = 0; String *rdecl = 0; String *rname = 0; /* very specific hack for template constructors/destructors */ #ifdef SWIG_DEBUG Printf(stdout, "Swig_name_make: looking for %s %s %s %s\n", prefix, name, decl, oldname); #endif if (name && n && SwigType_istemplate(name)) { String *nodetype = nodeType(n); if (nodetype && (Equal(nodetype, "constructor") || Equal(nodetype, "destructor"))) { String *nprefix = NewStringEmpty(); String *nlast = NewStringEmpty(); String *tprefix; Swig_scopename_split(name, &nprefix, &nlast); tprefix = SwigType_templateprefix(nlast); Delete(nlast); if (Len(nprefix)) { Append(nprefix, "::"); Append(nprefix, tprefix); Delete(tprefix); rname = nprefix; } else { rname = tprefix; Delete(nprefix); } rdecl = Copy(decl); Replaceall(rdecl, name, rname); #ifdef SWIG_DEBUG Printf(stdout, "SWIG_name_make: use new name %s %s : %s %s\n", name, decl, rname, rdecl); #endif decl = rdecl; Delete(name); name = rname; } } if (rename_hash || rename_list || namewarn_hash || namewarn_list) { Hash *rn = Swig_name_object_get(Swig_name_rename_hash(), prefix, name, decl); if (!rn || !Swig_name_match_nameobj(rn, n)) { rn = Swig_name_nameobj_lget(Swig_name_rename_list(), n, prefix, name, decl); if (rn) { String *sfmt = Getattr(rn, "sourcefmt"); int fullname = GetFlag(rn, "fullname"); if (fullname && prefix) { String *sname = NewStringf("%s::%s", prefix, name); Delete(name); name = sname; prefix = 0; } if (sfmt) { String *sname = NewStringf(sfmt, name); Delete(name); name = sname; } } } if (rn) { String *newname = Getattr(rn, "name"); int fullname = GetFlag(rn, "fullname"); result = apply_rename(newname, fullname, prefix, name); } if (result && !Equal(result, name)) { /* operators in C++ allow aliases, we look for them */ char *cresult = Char(result); if (cresult && (strncmp(cresult, "operator ", 9) == 0)) { String *nresult = Swig_name_make(n, prefix, result, decl, oldname); if (!Equal(nresult, result)) { Delete(result); result = nresult; } else { Delete(nresult); } } } nname = result ? result : name; wrn = Swig_name_namewarn_get(n, prefix, nname, decl); if (wrn) { String *rename = Getattr(wrn, "rename"); if (rename) { String *msg = Getattr(wrn, "name"); int fullname = GetFlag(wrn, "fullname"); if (result) Delete(result); result = apply_rename(rename, fullname, prefix, name); if ((msg) && (Len(msg))) { if (!Getmeta(nname, "already_warned")) { if (n) { SWIG_WARN_NODE_BEGIN(n); Swig_warning(0, Getfile(n), Getline(n), "%s\n", msg); SWIG_WARN_NODE_END(n); } else { Swig_warning(0, Getfile(name), Getline(name), "%s\n", msg); } Setmeta(nname, "already_warned", "1"); } } } } } if (!result || !Len(result)) { if (result) Delete(result); if (oldname) { result = NewString(oldname); } else { result = NewString(cname); } } Delete(name); #ifdef SWIG_DEBUG Printf(stdout, "Swig_name_make: result '%s' '%s'\n", cname, result); #endif return result; }