📄 fv.info.c
字号:
#ifndef lintstatic char sccsid[] = "@(#)fv.info.c 1.1 92/07/30 Copyr 1988 Sun Micro";#endif/* Copyright (c) 1987, 1988, Sun Microsystems, Inc. All Rights Reserved. Sun considers its source code as an unpublished, proprietary trade secret, and it is available only under strict license provisions. This copyright notice is placed here only to protect Sun in the event the source is deemed a published work. Dissassembly, decompilation, or other means of reducing the object code to human readable form is prohibited by the license agreement under which this code is provided to the user or company in possession of this copy. RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the Government is subject to restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 52.227-7013 and in similar clauses in the FAR and NASA FAR Supplement. */#include <stdio.h>#include <string.h>#include <strings.h>#include <errno.h>#include <mntent.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/vfs.h> /* statfs */#include <sys/param.h> /* dbtob */#include <sys/file.h>#ifdef SV1#include <suntool/sunview.h>#include <suntool/panel.h>#include <suntool/canvas.h>#include <suntool/scrollbar.h>#else#include <view2/view2.h>#include <view2/panel.h>#include <view2/canvas.h>#include <view2/scrollbar.h>#endif#include "fv.port.h"#include "fv.h"#include "fv.extern.h"#include "fv.colormap.h"#ifdef SV1# ifndef PROTOstatic short pin_in_array[] = {#include "pin_in.icon"};mpr_static_static(Pin_in, 64, 13, 1, pin_in_array);static short pin_out_array[] = {#include "pin_out.icon"};mpr_static_static(Pin_out, 64, 13, 1, pin_out_array);static BOOLEAN Pinned;# endif#endif/* List of file types in case file(1) gives up... */static char *Typename[] = { "unknown type", "fifo", /* S_IFIFO */ "character special", /* S_IFCHR */ "unknown type", "directory", /* S_IFDIR */ "unknown type", "block special", /* S_IFBLK */ "unknown type", "regular file", /* S_IFREG */ "unknown type", "symbolic link", /* S_IFLNK */ "unknown type", "socket" /* S_IFSOCK */};static unsigned int Togglemask[] = { S_IREAD, S_IWRITE, S_IEXEC, S_IREAD>>3, S_IWRITE>>3, S_IEXEC>>3, S_IREAD>>6, S_IWRITE>>6, S_IEXEC>>6};static char *Label[] = { /* Panel item labels */ "Name:", "Owner:", "Group:", "Size:", "Last Modified:", "Last Accessed:", "Type:", "Permissions", "Owner:", "Group:", "World:", "Mount Point:", "Mounted From:", "Free Space:", "Color:"};#ifdef SV1# define JUSTIFY_COL 16# define EXTRA 0# define PERM_COL 6#else# define JUSTIFY_COL 10# define EXTRA 6# define PERM_COL 4#endif#define NAME 0#define OWNERNAME 1#define GROUPNAME 2#define BYTESIZE 3#define MODTIME 4#define ACCTIME 5#define TYPE 6#define PERM 7#define OWNERPERM 8#define GROUPPERM 9#define OTHERPERM 10#define MNTPT 11#define MNTFS 12#define FREE 13#define COLOR 14#define NUMITEMS 15#define MAXTOGGLES 9#define COLOR_WIDTH 26#define COLOR_HEIGHT 17static int Toggles[MAXTOGGLES]; /* Toggle values */static Panel_item Toggleitem[MAXTOGGLES];/* Toggles */static Panel_item Item[NUMITEMS]; /* Changeable items */static Panel_item Tag_item[NUMITEMS]; /* Label items */#ifdef SV1static Panel_item Ok_button; /* Automatically supplied in View2 */#endifstatic int Owner; /* We we own this file? */static Frame Fprops_frame;static Panel Fprops_panel;static struct stat Fstatus; /* Current file status */static char *Filename; /* Current file name */static char *Fname; /* File name without path */static Canvas Color_canvas;static PAINTWIN Color_pw;extern u_char Fv_red[], Fv_blue[], Fv_green[];static int Color; /* Original color */static int New_color; /* New color chosen */static int generic_toggle();static int props_proc();static char *addcommas();static char *docmd();fv_info_object() /* Show file properties */{ char *f_p; char buf[MAXPATH]; int i; New_color = 0; if (Fv_tselected) { fv_getpath(Fv_tselected, buf); f_p = buf; Color = BLACK; } else { if ((i = fv_getselectedfile()) == EMPTY) return; f_p = Fv_file[i]->name; Color = Fv_file[i]->color; (void)sprintf(buf, "%s%s%s", Fv_path, Fv_path[1]?"/":"", f_p); f_p = buf; } /* Store name here; (pointers may get changed if the directory is * changed or removed). */ if (Filename) free(Filename); if ((Filename = fv_malloc((unsigned)strlen(f_p)+1)) == NULL) return; (void)strcpy(Filename, f_p); /* Where does the name start? */ Fname = Filename[1] == 0 ? Filename : strrchr(Filename, '/')+1; makepopup(); if ((int)window_get(Fprops_frame, WIN_SHOW) == FALSE) fv_winright(Fprops_frame); window_set(Fprops_frame, WIN_SHOW, TRUE, 0);}staticmakepopup() /* Make panel items */{#ifndef SV1 static void apply(), reset();#endif if (Fprops_frame == NULL) { if ((Fprops_frame = window_create(Fv_frame, #ifdef SV1 FRAME,# ifdef PROTO FRAME_CLASS, FRAME_CLASS_COMMAND, FRAME_ADJUSTABLE, FALSE, FRAME_SHOW_FOOTER, FALSE,# endif FRAME_LABEL, "fileview: File Properties",#else FRAME_PROPS, FRAME_PROPS_APPLY_PROC, apply, FRAME_PROPS_RESET_PROC, reset, FRAME_LABEL, " File Properties", WIN_DYNAMIC_COLOR, TRUE,#endif FRAME_SHOW_LABEL, TRUE, FRAME_NO_CONFIRM, TRUE, 0)) == NULL ||#ifndef SV1 (Fprops_panel = vu_get(Fprops_frame, FRAME_PROPS_PANEL)) == NULL)#else (Fprops_panel = window_create(Fprops_frame, PANEL, 0)) == NULL)#endif { fv_putmsg(TRUE, Fv_message[MEWIN], 0, 0); return; }#ifdef SV1 make_ok_button();# ifdef PROTO frame_set_font_size(Fprops_frame, (int)window_get(Fv_frame, WIN_FONT_SIZE));# endif#endif makepanel(Fprops_panel); updatepanel(Filename); window_fit(Fprops_panel); window_fit(Fprops_frame); } else updatepanel(Filename);}staticmakepanel(panel) register Panel panel;{ register int i; register char *s_p; /* Create changable panel items, ie name, owner, and group... */ for (i = 0; i < BYTESIZE; i++) { s_p = Label[i]; Item[i] = panel_create_item(panel, PANEL_TEXT, PANEL_LABEL_BOLD, TRUE, PANEL_LABEL_STRING, s_p, PANEL_VALUE_STORED_LENGTH, i ? 80 : 255, PANEL_VALUE_DISPLAY_LENGTH, 22, PANEL_VALUE_Y, ATTR_ROW(i), PANEL_VALUE_X, ATTR_COL(JUSTIFY_COL), 0); } for (; i < NUMITEMS; i++) { s_p = Label[i]; /* Non editable items are not bolded */ Tag_item[i] = panel_create_item(panel, PANEL_MESSAGE, PANEL_LABEL_BOLD, #ifdef OPENLOOK TRUE,#else i>=PERM && i<=OTHERPERM || i==COLOR,#endif PANEL_LABEL_STRING, s_p, PANEL_VALUE_DISPLAY_LENGTH, 35, PANEL_VALUE_Y, ATTR_ROW(i), PANEL_VALUE_X, ATTR_COL(JUSTIFY_COL), 0); /* We'll want to update everything except the permissions... */ if (i < PERM || (i >= MNTPT && i < COLOR)) Item[i] = panel_create_item(panel, PANEL_MESSAGE, 0); } Item[PERM] = panel_create_item(panel, PANEL_MESSAGE, PANEL_LABEL_STRING, " Read Write Execute", PANEL_LABEL_BOLD, TRUE, PANEL_ITEM_Y, ATTR_ROW(PERM), PANEL_ITEM_X, ATTR_COL(JUSTIFY_COL), 0); if (Fv_color) create_color_canvas(); for (i = 0; i < MAXTOGGLES; i++) Toggleitem[i] = panel_create_item(panel, #ifdef SV1 PANEL_TOGGLE,#else PANEL_CHECK_BOX,#endif PANEL_CLIENT_DATA, i, PANEL_VALUE, Toggles[i], PANEL_NOTIFY_PROC, generic_toggle, PANEL_ITEM_X, ATTR_COL(JUSTIFY_COL+(i%3)*PERM_COL+2), PANEL_ITEM_Y, ATTR_ROW(OWNERPERM+(i/3))-CHECK_OFFSET, 0);}staticupdatepanel(name) /* Update panel items */ char *name; /* File name */{ char buf[100]; /* Generic buffer */ register char *str_p; /* Generic string pointer */ register int i; /* Index */ struct stat sbuf; /* File status */ struct statfs fsbuf; /* File system status */ struct mntent *mnt, *getmntpt();/* Mount point info */ int symlink; /* Does this file have a symlink? */ extern short Fv_wantdu; /* Do 'du -s' on directories */ char *getname(); char *getgroup(); panel_set(Item[NAME], PANEL_VALUE, Fname, 0); /* Get file status to determine symlink... */ symlink = ((i = lstat(name, &sbuf)) == 0 && (sbuf.st_mode & S_IFMT) == S_IFLNK); if (symlink) /* ...try to get real file */ i = stat(name, &sbuf); if (i == -1) { fv_putmsg(TRUE, Fv_message[MEREAD], (int)name, (int)sys_errlist[errno]); return; } Fstatus = sbuf; if ((str_p = getname(sbuf.st_uid)) == 0) { (void)sprintf(buf, "%d", sbuf.st_uid); str_p = buf; } panel_set(Item[OWNERNAME], PANEL_VALUE, str_p, 0); if ((str_p = getgroup(sbuf.st_gid)) == 0) { (void)sprintf(buf, "%d", sbuf.st_gid); str_p = buf; } panel_set(Item[GROUPNAME], PANEL_VALUE, str_p, 0); if (Fv_wantdu && ((sbuf.st_mode & S_IFMT) == S_IFDIR)) (void)sprintf(buf, "%s blocks", docmd("du -s ", name, (struct stat *)0)); else (void)sprintf(buf, "%s bytes", addcommas(sbuf.st_size)); panel_set(Item[BYTESIZE], PANEL_LABEL_STRING, buf, 0); panel_set(Item[MODTIME], PANEL_LABEL_STRING, ctime(&sbuf.st_mtime), 0); panel_set(Item[ACCTIME], PANEL_LABEL_STRING, ctime(&sbuf.st_atime), 0); /* If this is a symlink; get link's type... */ if (symlink) { if ((sbuf.st_mode & S_IFMT) == S_IFLNK) str_p = "symlink to nowhere"; else { (void)strcpy(buf, "symlink to "); i = readlink(name, &buf[11], sizeof(buf)); buf[11+i] = 0; str_p = buf; } } else { (void)strcpy(buf, docmd("file -L ", name, &sbuf)); str_p = buf; } panel_set(Item[TYPE], PANEL_LABEL_STRING, str_p, 0); for (i = 0; i < MAXTOGGLES; i++) { Toggles[i] = ((sbuf.st_mode & Togglemask[i]) != 0); panel_set(Toggleitem[i], PANEL_VALUE, Toggles[i], 0); } panel_set(Tag_item[COLOR], PANEL_SHOW_ITEM, Fv_color, 0); if (Fv_color) draw_box(Color); if ((statfs(Fv_path, &fsbuf)==0) && (mnt = getmntpt(Fv_path))) { panel_set(Item[MNTPT], PANEL_LABEL_STRING, mnt->mnt_dir, 0); panel_set(Item[MNTFS], PANEL_LABEL_STRING, mnt->mnt_fsname, 0); i = fsbuf.f_blocks - (fsbuf.f_bfree - fsbuf.f_bavail); (void)sprintf(buf, "%s kbytes (%d%%)", addcommas((fsbuf.f_bavail*fsbuf.f_bsize)/1024), 100-(100*(i - fsbuf.f_bavail))/i); panel_set(Item[FREE], PANEL_LABEL_STRING, buf, 0); freemnt(mnt); } /* If you don't own the file, you can't change most properties. * But if you can write on the folder, you can change the name. */ Owner = getuid(); Owner = Owner == sbuf.st_uid || Owner == 0;#ifdef OPENLOOK# ifdef SV1 panel_set(Ok_button, PANEL_INACTIVE, !Owner, 0);# endif for (i = 0; i < MAXTOGGLES; i++) panel_set(Toggleitem[i], PANEL_INACTIVE, !Owner, 0);#endif}static voidapply(){ props_proc(FRAME_PROPS_SET);}static voidreset(){ props_proc(FRAME_PROPS_RESET);}staticprops_proc(op) short op;{ int num; char *str1; char newname[MAXPATH]; int error = FALSE; /* Do we have an error? */ BOOLEAN changed = FALSE; /* Properties changed? */ BOOLEAN stay_up; /* Pinned window? */ if (op == FRAME_PROPS_RESET) { updatepanel(Filename); return; } if (access(Filename, F_OK) == -1) { fv_putmsg(TRUE, Fv_message[MEFIND], (int)Filename, 0); return; } num = toggletonum(); if ((Fstatus.st_mode & ~S_IFMT) != num) { /* Change permissions... */ if (chmod(Filename, num) == -1) { fv_putmsg(TRUE, sys_errlist[errno], 0, 0); error = TRUE; } else changed = TRUE; } str1 = (char *)panel_get_value(Item[NAME]); if (strcmp(str1, Fname)) { /* Change name... */ if (strchr(str1, '/')) { fv_putmsg(TRUE, Fv_message[MECHAR], '/', 0); return; } (void)strncpy(newname, Filename, Fname - Filename); newname[Fname-Filename] = NULL; (void)strcat(newname, str1); if (rename(Filename, newname) == -1) { fv_putmsg(TRUE, sys_errlist[errno], 0, 0); error = TRUE; } else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -