00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "htfinfo.h"
00022
00023 #include <sys/stat.h>
00024 #include <string.h>
00025
00026 ht_view *htfinfo_init(bounds *b, ht_streamfile *file, ht_format_group *group)
00027 {
00028 ht_finfo_text *v=new ht_finfo_text();
00029 v->init(b, file);
00030 return v;
00031 }
00032
00033 format_viewer_if htfinfo_if = {
00034 htfinfo_init,
00035 0
00036 };
00037
00038
00039
00040
00041
00042 void ht_finfo_text::init(bounds *b, ht_streamfile *f)
00043 {
00044 ht_statictext::init(b, 0, align_left, 1);
00045 options|=VO_BROWSABLE;
00046 olddesc=desc;
00047 desc=FINFO_DESC;
00048 file=f;
00049 }
00050
00051 void ht_finfo_text::done()
00052 {
00053 desc=olddesc;
00054 ht_statictext::done();
00055 }
00056
00057 #define FINFO_IDENTIFIER_WIDTH 24
00058 #define FINFO_IDENTIFIER_WIDTH_STR "24"
00059
00060 int print_time(char *f, char *prefix, time_t time)
00061 {
00062 tm tt;
00063 memcpy(&tt, localtime(&time), sizeof tt);
00064 return sprintf(f, "%-"FINFO_IDENTIFIER_WIDTH_STR"s%s", prefix, asctime(&tt));
00065 }
00066
00067 char *ht_finfo_text::gettext()
00068 {
00069 char *t=finfotext;
00070 pstat_t s;
00071 file->pstat(&s);
00072
00073 if (s.caps & pstat_ctime) t+=print_time(t, "time of creation", s.ctime);
00074 if (s.caps & pstat_mtime) t+=print_time(t, "time of modification", s.mtime);
00075 if (s.caps & pstat_atime) t+=print_time(t, "time of last access", s.atime);
00076 if (s.caps & pstat_uid) t+=sprintf(t, "%-"FINFO_IDENTIFIER_WIDTH_STR"s%d\n", "user id", s.uid);
00077 if (s.caps & pstat_gid) t+=sprintf(t, "%-"FINFO_IDENTIFIER_WIDTH_STR"s%d\n", "group id", s.gid);
00078
00079 if (s.caps & pstat_size) {
00080 t+=sprintf(t, "%-"FINFO_IDENTIFIER_WIDTH_STR"s%d (%.2f KiB, %.2f MiB)\n", "size", s.size, ((float)s.size)/1024, ((float)s.size)/1024/1024);
00081 }
00082
00083 if (s.caps & pstat_inode) t+=sprintf(t, "%-"FINFO_IDENTIFIER_WIDTH_STR"s%d\n", "inode", s.fsid); else
00084 if (s.caps & pstat_cluster) t+=sprintf(t, "%-"FINFO_IDENTIFIER_WIDTH_STR"s%d\n", "cluster (?)", s.fsid); else
00085 if (s.caps & pstat_fsid) t+=sprintf(t, "%-"FINFO_IDENTIFIER_WIDTH_STR"s%d\n", "fsid", s.fsid);
00086
00087 if (s.caps & pstat_mode_all) {
00088 dword am[3][3]={
00089 {HT_S_IRUSR, HT_S_IWUSR, HT_S_IXUSR},
00090 {HT_S_IRGRP, HT_S_IWGRP, HT_S_IXGRP},
00091 {HT_S_IROTH, HT_S_IWOTH, HT_S_IXOTH}
00092 };
00093
00094 dword ulm[3]={pstat_mode_usr, pstat_mode_grp, pstat_mode_oth};
00095 char *uls[3]={"user", "group", "world"};
00096
00097 dword alm[3]={pstat_mode_r, pstat_mode_w, pstat_mode_x};
00098 char *als[3]={"read", "write", "execute"};
00099
00100 *(t++)='\n';
00101
00102 int cols=0;
00103 t+=sprintf(t, "%-"FINFO_IDENTIFIER_WIDTH_STR"s", "");
00104 for (int u=0; u<3; u++) {
00105 if (s.caps & ulm[u]) {
00106 t+=sprintf(t, " %-8s", uls[u]);
00107 cols++;
00108 }
00109 }
00110 *(t++)='\n';
00111
00112 for (int q=0; q<FINFO_IDENTIFIER_WIDTH+cols*9; q++) *(t++)='-';
00113 *(t++)='\n';
00114
00115 for (int a=0; a<3; a++) {
00116 if (s.caps & alm[a]) {
00117 t+=sprintf(t, "%-"FINFO_IDENTIFIER_WIDTH_STR"s", als[a]);
00118 for (int u=0; u<3; u++) {
00119 if (s.caps & ulm[u]) {
00120 t+=sprintf(t, " %-8s", (s.mode & am[u][a]) ? "[x]" : "[ ]");
00121 }
00122 }
00123 *(t++)='\n';
00124 }
00125 }
00126 *t=0;
00127 }
00128
00129 return finfotext;
00130 }
00131