1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/*
* HT Editor
* htfinfo.cc
*
* Copyright (C) 1999-2002 Stefan Weyergraf
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "htfinfo.h"
#include "snprintf.h"
#include <sys/stat.h>
#include <string.h>
ht_view *htfinfo_init(Bounds *b, File *file, ht_format_group *group)
{
ht_finfo_text *v = new ht_finfo_text();
v->init(b, file);
return v;
}
format_viewer_if htfinfo_if = {
htfinfo_init,
0
};
/*
* ht_finfo_text
*/
void ht_finfo_text::init(Bounds *b, File *f)
{
ht_statictext::init(b, FINFO_DESC, align_left, 1);
options |= VO_BROWSABLE;
// olddesc = desc;
// desc =;
file = f;
}
void ht_finfo_text::done()
{
// desc = olddesc;
ht_statictext::done();
}
#define FINFO_IDENTIFIER_WIDTH 24
#define FINFO_IDENTIFIER_WIDTH_STR "24"
int print_time(char *f, int max_len, const char *prefix, time_t time)
{
tm tt;
memcpy(&tt, localtime(&time), sizeof tt);
return ht_snprintf(f, max_len, "%-"FINFO_IDENTIFIER_WIDTH_STR"s%s", prefix, asctime(&tt));
}
int ht_finfo_text::gettext(char *text, int max_len)
{
if (max_len <= 0) return 0;
char *t = text;
pstat_t s;
file->pstat(s);
if (s.caps & pstat_ctime) t += print_time(t, max_len-(t-text), "time of creation", s.ctime);
if (s.caps & pstat_mtime) t += print_time(t, max_len-(t-text), "time of modification", s.mtime);
if (s.caps & pstat_atime) t += print_time(t, max_len-(t-text), "time of last access", s.atime);
if (s.caps & pstat_uid) t += ht_snprintf(t, max_len-(t-text), "%-"FINFO_IDENTIFIER_WIDTH_STR"s%d\n", "user id", s.uid);
if (s.caps & pstat_gid) t += ht_snprintf(t, max_len-(t-text), "%-"FINFO_IDENTIFIER_WIDTH_STR"s%d\n", "group id", s.gid);
if (s.caps & pstat_size) {
t += ht_snprintf(t, max_len-(t-text), "%-"FINFO_IDENTIFIER_WIDTH_STR"s%qd (%.2f KiB, %.2f MiB)"
" / 0x%08qx\n", "size", s.size, ((float)s.size)/1024,
((float)s.size)/1024/1024, s.size);
}
if (s.caps & pstat_inode) t += ht_snprintf(t, max_len-(t-text), "%-"FINFO_IDENTIFIER_WIDTH_STR"s%d\n", "inode", s.fsid);
else if (s.caps & pstat_cluster) t += ht_snprintf(t, max_len-(t-text), "%-"FINFO_IDENTIFIER_WIDTH_STR"s%d\n", "cluster (?)", s.fsid);
else if (s.caps & pstat_fsid) t += ht_snprintf(t, max_len-(t-text), "%-"FINFO_IDENTIFIER_WIDTH_STR"s%d\n", "fsid", s.fsid);
if (s.caps & pstat_mode_all) {
uint32 am[3][3]={
{HT_S_IRUSR, HT_S_IWUSR, HT_S_IXUSR},
{HT_S_IRGRP, HT_S_IWGRP, HT_S_IXGRP},
{HT_S_IROTH, HT_S_IWOTH, HT_S_IXOTH}
};
uint32 ulm[3]={pstat_mode_usr, pstat_mode_grp, pstat_mode_oth};
const char *uls[3]={"user", "group", "world"};
uint32 alm[3]={pstat_mode_r, pstat_mode_w, pstat_mode_x};
const char *als[3]={"read", "write", "execute"};
if (max_len-(t-text) > 1) *t++ = '\n';
int cols=0;
t += ht_snprintf(t, max_len-(t-text), "%-"FINFO_IDENTIFIER_WIDTH_STR"s", "");
for (int u=0; u<3; u++) {
if (s.caps & ulm[u]) {
t += ht_snprintf(t, max_len-(t-text), " %-8s", uls[u]);
cols++;
}
}
if (max_len-(t-text) > 1) *t++ = '\n';
for (int q=0; q < FINFO_IDENTIFIER_WIDTH+cols*9; q++) if (max_len-(t-text) > 1) *t++ = '-';
if (max_len-(t-text) > 1) *t++ = '\n';
for (int a=0; a<3; a++) {
if (s.caps & alm[a]) {
t += ht_snprintf(t, max_len-(t-text), "%-"FINFO_IDENTIFIER_WIDTH_STR"s", als[a]);
for (int u=0; u<3; u++) {
if (s.caps & ulm[u]) {
t += ht_snprintf(t, max_len-(t-text), " %-8s", (s.mode & am[u][a]) ? "[x]" : "[ ]");
}
}
if (max_len-(t-text) > 1) *t++ = '\n';
}
}
*t = 0;
}
return t-text;
}
|