--- xv-3.10a_jp_org/xvbrowse.c Mon Sep 1 18:51:23 1997 +++ xv-3.10a_jp_work/xvbrowse.c Fri Mar 20 14:21:31 1998 @@ -17,6 +17,28 @@ #include "copyright.h" +/* If you enable DIRTHUMB, the visual schnauzer will search a image in + * some directories to make thumb nail file of them. If AUTO_EXPAND, + * i.e. virtual directory, is enabled, it also searches in the + * archive file. + * these functions are added by Masaaki Kumagai + * kumagai@emura.mech.tohoku.ac.jp + */ +#define DIRTHUMB +/* If you enable DIRTHUMB_NOPARENT, the DIRTHUMB function won't apply + * for parent directory */ +#define DIRTHUMB_NOPARENT +/* If you enable DIRTHUMB_DUMMY_ICON, the xv create and uses dummy + * bitmap file temporarily for speed up of next 'update' */ +#define DIRTHUMB_DUMMY_ICON + +/* If (dirthumb_check_directory), xv searches diretory to obtain thumb-nail, + * otherwise it uses already-updated-icons but do not create new one + */ +#ifdef DIRTHUMB +int dirthumb_check_directory=1; +#endif + #define NEEDSDIR #include "xv.h" @@ -1550,17 +1572,32 @@ ix = x + ISPACE_WIDE/2 - bf->w/2; /* center align */ iy = y + ISPACE_TOP + ISIZE_HIGH - bf->h; /* bottom align */ - +#ifdef DIRTHUMB + if (((bf->ftype >= 0 && bf->ftype ftype!=BF_DIR))|| + ((bf->ftype==BF_DIR)&&(bf->ximage==NULL))){ /* built-in icon */ +#else if (bf->ftype >= 0 && bf->ftype ftype], br->iconW, theGC, 0, 0, (u_int) bf->w, (u_int) bf->h, ix, iy, 1L); } - else if (bf->ftype == BF_HAVEIMG && bf->ximage) { XPutImage(theDisp, br->iconW, theGC, bf->ximage, 0,0, ix,iy, (u_int) bf->w, (u_int) bf->h); } - +#ifdef DIRTHUMB + else if((bf->ftype == BF_DIR)&&(bf->ximage!=NULL)) + { + XCopyPlane(theDisp, bfIcons[BF_DIR], br->iconW, theGC, + 0, 0, (u_int) br_dir_width, (u_int) br_dir_height, + x + ISPACE_WIDE/2-br_dir_width/2, + y + ISPACE_TOP + ISIZE_HIGH-br_dir_height, 1L); + XPutImage(theDisp, br->iconW, theGC, bf->ximage, 0,0, + x + ISPACE_WIDE/2- bf->w/2 -1, + y + ISPACE_TOP + ISIZE_HIGH-bf->h/2-16, + (u_int) bf->w, (u_int) bf->h); + } +#endif else { /* shouldn't happen */ XDrawRectangle(theDisp, br->iconW, theGC, ix, iy, (u_int) bf->w, (u_int) bf->h); @@ -2355,13 +2392,21 @@ x = (i%br->numWide) * ISPACE_WIDE; /* x,y=top-left of icon region */ y = (i/br->numWide) * ISPACE_HIGH; +#ifdef DIRTHUMB + if(bf->ftype==BF_DIR) + { + ix = x + ISPACE_WIDE/2 - br_dir_width/2; /* center align */ + iy = y + ISPACE_TOP + ISIZE_HIGH - br_dir_height;/* bottom align */ + + if (PTINRECT(mx,my, ix, iy, 48, 48)) break; + } +#endif ix = x + ISPACE_WIDE/2 - bf->w/2; /* center align */ iy = y + ISPACE_TOP + ISIZE_HIGH - bf->h; /* bottom align */ if (PTINRECT(mx,my, ix, iy, bf->w, bf->h)) break; } } - if (i==num) return -1; return sel; } @@ -3581,6 +3626,111 @@ SetCursors(-1); } +#ifdef DIRTHUMB +/***************************************************************/ +static char _dirimagefile[512]; +static char *searchGFile(dir) + char *dir; +{ + char wd[512]; + char **dirs; + char *select=NULL,*select_COMPRESS=NULL; + int dirsize,i,ftype; + struct stat st; + +#ifdef DIRTHUMB_NOPARENT + if(strcmp(dir,"..")==0) + return NULL; +#endif + + xv_getwd(wd,512); +#ifdef AUTO_EXPAND + Chvdir(dir); +#else + chdir(dir); +#endif + xv_getwd(_dirimagefile,512); + /* obtain all files in the directory */ + dirs=getDirEntries(".",&dirsize,1); + /* first, I'd like to use uncompressed files */ + for(i=0;iname || bf->name[0] == '\0') return; /* shouldn't happen */ str[0] = '\0'; @@ -3619,21 +3771,61 @@ bf->pimage = (byte *) NULL; bf->ximage = (XImage *) NULL; + bfname=bf->name; +#ifdef DIRTHUMB + bfftype=bf->ftype; + if((bf->ftype==BF_DIR)&&(dirthumb_check_directory)) + { + bfname=searchGFile(bf->name); + if(bfname==NULL) + { +#ifdef AUTO_EXPAND /* remove if directory is VD */ + if(strcmp(bf->name,"..")) + { + char bfrm1[512],bfrm2[512]; + xv_getwd(bfrm1,512); + strcat(bfrm1,"/"); strcat(bfrm1,bf->name); + strcpy(bfrm2,bfrm1); + Dirtovd(bfrm2); + if(strcmp(bfrm1,bfrm2)!=0) + { Rmvdir(bfrm1); } + } + else + { + bf->w=br_dir_width; + bf->h=br_dir_height; /* reset size of parent icon */ + } + return; +#endif + } + +/* printf("directory image: %s\n",bfname);*/ + strcpy(readname, bfname); + } /* skip all 'special' files */ + if((bf->ftype!=BF_DIR)&&(!ISLOADABLE(bf->ftype))) return; + if((bf->ftype==BF_DIR)&&(!dirthumb_check_directory)) + { + bf->w=br_dir_width; + bf->h=br_dir_height; + return; + } +#else + /* skip all 'special' files */ if (!ISLOADABLE(bf->ftype)) return; +#endif - filetype = ReadFileType(bf->name); - + filetype = ReadFileType(bfname); if (filetype == RFT_COMPRESS) { #if (defined(VMS) && !defined(GUNZIP)) /* VMS decompress doesn't like the file to have a trailing .Z in fname however, GUnZip is OK with it, which we are calling UnCompress */ - strcpy (basefname, bf->name); + strcpy (basefname, bfname); *rindex (basefname, '.') = '\0'; uncName = basefname; #else - uncName = bf->name; + uncName = bfname; #endif if (UncompressFile(uncName, uncompname)) { @@ -3641,7 +3833,7 @@ strcpy(readname, uncompname); } else { - sprintf(str, "Couldn't uncompress file '%s'", bf->name); + sprintf(str, "Couldn't uncompress file '%s'", bfname); setBrowStr(br, str); bf->ftype = BF_ERROR; } @@ -3650,11 +3842,11 @@ #ifdef MACBINARY if (handlemacb && macb_file == True && bf->ftype != BF_ERROR) { if (RemoveMacbinary(readname, uncompname)) { - if (strcmp(readname, bf->name)!=0) unlink(readname); + if (strcmp(readname, bfname)!=0) unlink(readname); strcpy(readname, uncompname); } else { - sprintf(str, "Unable to remove a InfoFile header form '%s'.", bf->name); + sprintf(str, "Unable to remove a InfoFile header form '%s'.", bfname); setBrowStr(br, str); bf->ftype = BF_ERROR; } @@ -3667,7 +3859,7 @@ char tmpname[128]; char *icom; - if((icom = mgcsfx_auto_input_com(bf->name)) != NULL){ + if((icom = mgcsfx_auto_input_com(bfname)) != NULL){ sprintf(tmpname, "%s/xvmsautoXXXXXX", tmpdir); mktemp(tmpname); SetISTR(ISTR_INFO, "Converting to known format by MgcSfx auto..."); @@ -3679,12 +3871,12 @@ #else if (!system(str)) { #endif - sprintf(str, "Unable to convert '%s' by MgcSfx auto.", bf->name); + sprintf(str, "Unable to convert '%s' by MgcSfx auto.", bfname); setBrowStr(br, str); bf->ftype = BF_ERROR; } else { filetype = ReadFileType(tmpname); - if (strcmp(readname, bf->name)!=0) unlink(readname); + if (strcmp(readname, bfname)!=0) unlink(readname); strcpy(readname, tmpname); } } @@ -3696,7 +3888,7 @@ if (pinfo.comment) free(pinfo.comment); pinfo.comment = (char *) NULL; if (filetype == RFT_ERROR) { - sprintf(str,"Couldn't open file '%s'", bf->name); + sprintf(str,"Couldn't open file '%s'", bfname); setBrowStr(br, str); bf->ftype = BF_ERROR; } @@ -3731,10 +3923,28 @@ } /* if we made an uncompressed file, we can rm it now */ - if (strcmp(readname, bf->name)!=0) unlink(readname); + if (strcmp(readname, bfname)!=0) unlink(readname); /* at this point either BF_ERROR, BF_UNKNOWN, BF_EXE or pic */ +#ifdef DIRTHUMB + if((bfftype==BF_DIR)&& + ((bf->ftype==BF_ERROR)||(bf->ftype==BF_UNKNOWN)||(bf->ftype==BF_EXE)|| + (!pinfo.pic))) + { + char bfrm[512]; + bf->ftype=BF_DIR; +#ifdef AUTO_EXPAND + if(strrchr(bfname,'/')!=NULL) /* remove if directory is VD */ + *(strrchr(bfname,'/'))='\0'; + strcpy(bfrm,bfname); + Vdtodir(bfrm); + if(strcmp(bfrm,bfname)!=0) + { Rmvdir(bfrm);} + return; +#endif + } +#endif if (!pinfo.pic) { if (bf->ftype == BF_EXE) return; /* don't write thumbfiles for exe's */ @@ -3758,6 +3968,20 @@ #endif /* VS_ADJUST */ hexpand = (double) pinfo.h / (double) ISIZE_HIGH; +#ifdef DIRTHUMB /* Create Picture that can be included in bits/br_dir */ + if(bfftype==BF_DIR) + { +#ifdef VS_ADJUST + if (!vsadjust) normaspect = 1; + + wexpand = (double) (pinfo.w * normaspect) / 45.0; +#else + wexpand = (double) pinfo.w / (double) 45.0; +#endif /* VS_ADJUST */ + hexpand = (double) pinfo.h / (double) 29.0; + } +#endif + if (wexpand >= 1.0 || hexpand >= 1.0) { /* don't expand small icons */ if (wexpand>hexpand) { #ifdef VS_ADJUST @@ -3842,7 +4066,7 @@ long filesize; char buf[64]; - fp = fopen(bf->name, "r"); + fp = fopen(bfname, "r"); if (fp) { fseek(fp, 0L, 2); filesize = ftell(fp); @@ -3875,7 +4099,21 @@ bf->w = iwide; bf->h = ihigh; bf->ftype = BF_HAVEIMG; - +#ifdef DIRTHUMB + if(bfftype==BF_DIR) + { + char bfrm[512]; + bf->ftype=BF_DIR; +#ifdef AUTO_EXPAND + if(strrchr(bfname,'/')!=NULL) /* remove if directory is VD */ + *(strrchr(bfname,'/'))='\0'; + strcpy(bfrm,bfname); + Vdtodir(bfrm); + if(strcmp(bfrm,bfname)!=0) + { Rmvdir(bfrm); } +#endif + } +#endif bf->ximage = Pic8ToXImage(icon8, (u_int) iwide, (u_int) ihigh, browcols, browR, browG, browB); @@ -3934,6 +4172,11 @@ info = NULL; icon8 = NULL; builtin = 0; +#ifdef DIRTHUMB + if(bf->ftype==BF_DIR) + sprintf(thFname, "%s%s/%s__DIR", br->path, THUMBDIR, bf->name); + else +#endif sprintf(thFname, "%s%s/%s", br->path, THUMBDIR, bf->name); #ifdef AUTO_EXPAND @@ -4015,6 +4258,16 @@ else { if (info) free(info); } +#ifdef DIRTHUMB + { + struct stat st; + int f=0; + sprintf(thFname, "%s%s", br->path, bf->name); + if((stat(thFname, &st)==0)&& + ((f=stat2bf((u_int) st.st_mode , thFname)) == BF_DIR)) + { /*printf("faked dir %s\n",thFname);*/ bf->ftype=BF_DIR;} + } +#endif fclose(fp); return; @@ -4051,14 +4304,18 @@ if (!i) perm = st.st_mode & 07777; else perm = 0755; - - +#ifdef DIRTHUMB + if(bf->ftype==BF_DIR) + sprintf(thFname, "%s%s/%s__DIR", br->path, THUMBDIR, bf->name); + else +#endif sprintf(thFname, "%s%s/%s", br->path, THUMBDIR, bf->name); #ifdef AUTO_EXPAND Dirtovd(thFname); #endif +/* printf("%s\n",thFname);*/ fp = fopen(thFname, "w"); if (!fp) { sprintf(buf, "Can't create thumbnail file '%s': %s", thFname, @@ -4096,6 +4353,7 @@ } if (ferror(fp)) { /* error occurred */ + printf("error\n"); fclose(fp); unlink(thFname); /* delete it */ sprintf(buf, "Can't write thumbnail file '%s': %s", thFname, @@ -4186,8 +4444,12 @@ WaitCursor(); for (i=0, bf=br->bfList; ibfLen; i++, bf++) { +#ifdef DIRTHUMB + if (bf->ftype <= BF_FILE || bf->ftype >= BF_ERROR || bf->ftype==BF_EXE || + bf->ftype==BF_DIR) { +#else if (bf->ftype <= BF_FILE || bf->ftype >= BF_ERROR || bf->ftype==BF_EXE) { - +#endif /* ie, not a 'special' file */ int s1, s2; @@ -4199,6 +4461,11 @@ s1 = stat(bf->name, &filest); /* see if this file has an associated thumbnail file */ +#ifdef DIRTHUMB + if(bf->ftype==BF_DIR) + sprintf(thfname, "%s%s/%s__DIR", br->path, THUMBDIR, bf->name); + else +#endif sprintf(thfname, "%s/%s", THUMBDIR, bf->name); s2 = stat(thfname, &thumbst); @@ -4235,6 +4502,13 @@ clearTemp(br); +#if defined(DIRTHUMB) && defined(DIRTHUMB_DUMMY_ICON) + { + char tmp[256]; + sprintf(tmp,"%s/__xvdummy",tmpdir); + unlink(tmp); + } +#endif /* search the THUMBDIR directory, looking for thumbfiles that don't have @@ -4247,10 +4521,30 @@ if (dirp) { while ( (dp = readdir(dirp)) != NULL) { char thfname[256]; + char *d_name; +#ifdef DIRTHUMB + char d_name_file[256]; +#endif struct stat filest, thumbst; /* stat this directory entry to make sure it's a plain file */ sprintf(thfname, "%s/%s", THUMBDIR, dp->d_name); + d_name=dp->d_name; +#ifdef DIRTHUMB +#ifdef DIRTHUMB_NOPARENT + if(strcmp(d_name,"..__DIR")==0) /* remove if not need parent icon */ + d_name="..parent_remove"; /* set original filename to non-exist */ + else +#endif + if((strstr(d_name,"__DIR")!=NULL)&& + (*(strstr(d_name,"__DIR")+5)=='\0')) + { + strcpy(d_name_file,d_name); + *(strstr(d_name_file,"__DIR"))='\0'; /* cut option */ + d_name=d_name_file; + } +#endif + if (stat(thfname, &thumbst)==0) { /* success */ int tmp; #ifdef AUTO_EXPAND @@ -4261,7 +4555,7 @@ if (tmp == BF_FILE) { /* a plain file */ /* see if this thumbfile has an associated pic file */ - if (stat(dp->d_name, &filest)) { /* failed!: guess it doesn't */ + if (stat(d_name, &filest)) { /* failed!: guess it doesn't */ if (unlink(thfname)==0) iconsKilled++; } }