/* GEM-View 3.00 CONVERTATION Modul: !!!!! Primitives Beispiel !!!!! (c) 22.10.1993 by Dieter Fiebelkorn Grner Weg 29a D-45768 Marl (GERMANY) */ #include #include "imageopt.h" #include "moduls.h" extern int slct_morenames(int mode, int num, void *ptr); static CONV_Structure *g_convS; static char selectric[4096], newFileName[250]; static char loadPathname[4096], destinationPath[250]; char *dup_string(char *s) { char *d; if (!s) return(NULL); d= (char *)g_convS->memory.malloc(strlen(s) + 1); if (d) strcpy(d, s); else d = s; return(d); } char *get_Filename2(char *pathname, int first) { static char file[220]; static char *name; static char mode; char *str; if (first) { if (pathname == NULL) return(NULL); name = pathname; mode = ' '; } else { if (name == NULL) return(NULL); } if (*name == '\0' || (mode != ',' && mode != ' ')) return(NULL); if (mode == ',') { str = file + strlen(file); while (str != file && *str != '\\') str--; if (*str == '\\') *++str = '\0'; else *str = '\0'; goto skip; } if (mode == ' ') { file[0] = '\0'; skip: str = name; while(*str != ',' && *str != ' ' && *str != '\0') str++; mode = *str; *str = '\0'; strcat(file, name); *str++ = mode; name = str; } return(file); } char *get_Filename3(char *pathname, int first) { static char file[220]; static char *name; static char mode; char *str; if (first) { if (pathname == NULL) return(NULL); name = pathname; mode = ' '; } else { if (name == NULL) return(NULL); } if (*name == '\0' || (mode != ',' && mode != ' ')) return(NULL); if (mode == ',') { str = file + strlen(file); while (str != file && *str != '\\') str--; if (*str == '\\') *++str = '\0'; else *str = '\0'; goto skip; } if (mode == ' ') { file[0] = '\0'; skip: str = name; while(*str != ',' && *str != ' ' && *str != '\0') str++; mode = *str; *str = '\0'; strcat(file, name); *str++ = mode; name = str; } return(file); } char *get_Filename(char *pathname, int first) { DTA *dta, my_dta; static int my_first; static char *wildcards = NULL; int count; char *str, *tmp, path[220]; try_next: if (first || wildcards == NULL) { str = wildcards = get_Filename2(pathname, first); if (wildcards == NULL) return(NULL); my_first = 1; wind_update(BEG_UPDATE); wind_update(BEG_MCTRL); dta = Fgetdta(); Fsetdta(&my_dta); strcpy(path, str); strcpy(selectric, str); tmp = strrchr(path, '\\'); if (tmp == NULL) tmp = path; if (tmp[strcspn(tmp, "*?")] != 0) { if (*tmp == '\\') *tmp++ = 0; if (Fsfirst(str, 0x00) == 0) { count = 99; if (tmp != path) { strcpy(selectric, path); strcat(selectric, "\\"); strcat(selectric, my_dta.d_fname); } else strcpy(selectric, my_dta.d_fname); while (count > 0 && Fsnext() == 0) { strcat(selectric, ","); strcat(selectric, my_dta.d_fname); count--; } } } Fsetdta(dta); wind_update(END_MCTRL); wind_update(END_UPDATE); } str = wildcards = get_Filename3(selectric, my_first); if (wildcards == NULL) goto try_next; my_first = 0; return(str); } int TOS_Version(void) { SYSHDR **_sysbase = (SYSHDR **)0x04F2; long stack; int version; stack = Super(NULL); version = (*_sysbase)->os_base->os_version; Super((void *)stack); return(version); } int get_FileName(char *pathname, char *extention, char *newfilename, char *message, int file_need, int multiple) { char path[250], tmp_path[220]; int fsel_but, is_slct_da; long str_len, restorePath; char filename[20], *str; restorePath = FALSE; memset(path, '\0', 250L); path[0] = Dgetdrv() + 'A'; path[1] = ':'; Dgetpath(&path[2], 0); if (path[2] != '\\') { memmove(&path[3], &path[2], strlen(path) - 1); path[2] = '\\'; } if (path[strlen(path)-1] != '\\') strcat(path, "\\"); if (pathname[0] == '\0') { tmp_path[0] = '\0'; strcpy(pathname, path); } else { str = pathname; while(*str != ',' && *str != ' ' && *str != '\0') str++; *str = '\0'; strcpy(tmp_path, pathname); while(str != pathname && *str != '\\') str--; if (*str == '\\') *++str = '\0'; restorePath = TRUE; } filename[0] = '\0'; if (extention == NULL) strcat(pathname, "*.*"); else strcat(pathname, extention); if (newfilename == NULL) strcpy(filename, ""); else strcpy(filename, newfilename); g_convS->events.evntHandle(2); if (file_need) is_slct_da = slct_morenames(1, multiple ? 100 : 1, selectric); else is_slct_da = 0; selectric[0] = '\0'; wind_update(BEG_UPDATE); wind_update(BEG_MCTRL); g_convS->diawin.reset_dialogCol(TRUE); if (TOS_Version() >= 0x0104) fsel_exinput(pathname, filename, &fsel_but, message); else fsel_input(pathname, filename, &fsel_but); g_convS->diawin.reset_dialogCol(FALSE); wind_update(END_MCTRL); wind_update(END_UPDATE); g_convS->events.evntHandle(2); if (fsel_but == 0) goto exit; if (is_slct_da) { if (selectric[0] == '\0' && filename[0] != '\0') strcpy(selectric, filename); if (file_need && selectric[0] == '\0') goto exit; } else { if (file_need && filename[0] == '\0') { exit: strcpy(pathname, tmp_path); return(0); } } str_len = strlen(pathname); while ((str_len > 1) && (pathname[str_len-1] != '\\')) str_len--; pathname[str_len] = '\0'; if (pathname[1] != '\0') { if (restorePath) { Dsetdrv(path[0] - 'A'); Dsetpath(&path[2]); } else { pathname[str_len-1] = '\0'; Dsetdrv(pathname[0] - 'A'); Dsetpath(&pathname[2]); pathname[str_len-1] = '\\'; } } if (file_need) { if (is_slct_da) { strcpy(&pathname[str_len], selectric); str = &pathname[str_len]; while(*str != '\0') { if (*str == ' ') *str = ','; str++; } } else strcpy(&pathname[str_len], filename); } return(1); } ImageOptions *gvw_convert(CONV_Structure *convS) { OBJECT *tree; ImageOptions *list = NULL, *end, *new; char *filename, *file, *str; char destFormatFile[20], destFormatName[20], ext[8]; int xdial, ydial, wdial, hdial, exit_obj, borderx, bordery, destFormatType, newType; g_convS = convS; loadPathname[0] = 0; destinationPath[0] = 0; destFormatFile[0] = 0; destFormatName[0] = 0; destFormatType = 1; if (rsrc_load("CONVERT.RSC") == 0) return(NULL); if (rsrc_gaddr(R_TREE, CONVPATH, &tree) == 0) return(NULL); if (convS->versions.aes_version >= 0x0340) { if (convS->screen_depth > 1) { tree[0].ob_spec.obspec.fillpattern = 0; tree[0].ob_spec.obspec.interiorcol = 0; } tree[1].ob_state &= ~OUTLINED; } strcpy(tree[PTHSRC].ob_spec.tedinfo->te_ptext, loadPathname); strcpy(tree[PTHDST].ob_spec.tedinfo->te_ptext, destinationPath); strcpy(tree[PTHFORMA].ob_spec.tedinfo->te_ptext, destFormatName); wind_update(BEG_UPDATE); wind_update(BEG_MCTRL); convS->diawin.reset_dialogCol(TRUE); form_center(tree, &xdial, &ydial, &wdial, &hdial); objc_offset(tree, ROOT, &borderx, &bordery); borderx -= xdial; bordery -= ydial; form_dial(FMD_START, 0, 0, 0, 0, xdial, ydial, wdial, hdial); form_dial(FMD_GROW, 0, 0, 0, 0, xdial, ydial, wdial, hdial); objc_draw(tree, ROOT, MAX_DEPTH, xdial, ydial, wdial, hdial); do { exit_obj = form_do (tree, 0) & 0x7fff; objc_offset(tree, ROOT, &xdial, &ydial); xdial -= borderx; ydial -= bordery; tree[exit_obj].ob_state &= ~SELECTED; if (exit_obj == PTHOK) { if (loadPathname[0] == '\0') exit_obj = convS->events.alert(1, "[2][ | Please choose File(s)! | ][ OK ]"); if (destinationPath[0] == '\0') exit_obj = convS->events.alert(1, "[2][ | Please choose dest. path! | ][ OK ]"); if (destFormatName[0] == '\0') exit_obj = convS->events.alert(1, "[2][ | Please choose dest. format! | ][ OK ]"); objc_draw (tree, ROOT, MAX_DEPTH, xdial, ydial, wdial, hdial); } if (exit_obj == PTHMONO || exit_obj == PTHCOLOR || exit_obj == PTHTC) { tree[exit_obj].ob_state |= SELECTED; newType = exit_obj - PTHMONO; if (newType != destFormatType) { destFormatType = newType; destFormatName[0] = 0; strcpy(tree[PTHFORMA].ob_spec.tedinfo->te_ptext, destFormatName); objc_draw (tree, PTHFORMA, MAX_DEPTH, xdial, ydial, wdial, hdial); } } if (exit_obj == PTHSRC || exit_obj == PTHDST || exit_obj == PTHFORMA) { wind_update(END_MCTRL); wind_update(END_UPDATE); if (exit_obj == PTHSRC) { if (get_FileName(loadPathname, "*.*", "IMG's", ">> Select images to convert <<", TRUE, TRUE)) strncpy(tree[PTHSRC].ob_spec.tedinfo->te_ptext, loadPathname, tree[PTHSRC].ob_spec.tedinfo->te_txtlen-1); } if (exit_obj == PTHDST) { if (get_FileName(destinationPath, "*.*", "DestZiel", ">> Select destination path <<", FALSE, FALSE)) strncpy(tree[PTHDST].ob_spec.tedinfo->te_ptext, destinationPath, tree[PTHDST].ob_spec.tedinfo->te_txtlen-1); } if ( exit_obj == PTHFORMA) { switch (destFormatType) { case 0: if (convS->diawin.getMSaving("Destiantion format", ext, destFormatName, destFormatFile)) strcpy(tree[PTHFORMA].ob_spec.tedinfo->te_ptext, destFormatName); break; case 1: if (convS->diawin.getCSaving("Destiantion format", ext, destFormatName, destFormatFile)) strcpy(tree[PTHFORMA].ob_spec.tedinfo->te_ptext, destFormatName); break; case 2: if (convS->diawin.getTSaving("Destiantion format", ext, destFormatName, destFormatFile)) strcpy(tree[PTHFORMA].ob_spec.tedinfo->te_ptext, destFormatName); break; } } wind_update(BEG_UPDATE); wind_update(BEG_MCTRL); graf_mouse(0, NULL); objc_draw (tree, ROOT, MAX_DEPTH, xdial, ydial, wdial, hdial); } } while (exit_obj != PTHCAN && exit_obj != PTHOK); form_dial(FMD_SHRINK, 0, 0, 0, 0, xdial, ydial, wdial, hdial); form_dial(FMD_FINISH, 0, 0, 0, 0, xdial, ydial, wdial, hdial); convS->diawin.reset_dialogCol(FALSE); wind_update(END_MCTRL); wind_update(END_UPDATE); convS->events.evntHandle(2); rsrc_free(); if (exit_obj == PTHCAN) return(NULL); if ((filename = get_Filename(loadPathname, 1)) != NULL) { do { new = convS->memory.newImageOptions(); if (new == NULL) break; file = strrchr(filename, '\\'); file++; str = strchr(file, '.'); if (str != NULL) *str = '\0'; strcpy(newFileName, destinationPath); strcat(newFileName, file); strcat(newFileName, &ext[1]); if (str != NULL) *str = '.'; new->name = dup_string(filename); new->savename = dup_string(newFileName); new->save = 1 + destFormatType; if (destFormatType == 0) new->dither = Dither; strcpy(new->tc_saver, destFormatFile); strcpy(new->color_saver, destFormatFile); strcpy(new->mono_saver, destFormatFile); if (new->name == NULL || new->savename == NULL) { if (new->name) convS->memory.free(new->name); if (new->savename) convS->memory.free(new->savename); convS->memory.free(new); new = NULL; } if (new != NULL) { if (list == NULL) { list = end = new; } else { end->next = new; new->prev = end; end = new; } } } while ((filename = get_Filename(loadPathname, 0)) != NULL); } return(list); }