File: tkinfo.c

package info (click to toggle)
mc 4.1.35-1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 6,924 kB
  • ctags: 9,665
  • sloc: ansic: 84,273; tcl: 1,779; makefile: 1,266; sh: 864; perl: 262; awk: 148; sed: 93; csh: 1
file content (117 lines) | stat: -rw-r--r-- 3,719 bytes parent folder | download | duplicates (2)
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
/* Midnight Commander Tk Information display
   Copyright (C) 1995 Miguel de Icaza
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   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 <config.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include "fs.h"
#include "dlg.h"
#include "widget.h"
#include "info.h"
#include "win.h"
#include "tkmain.h"

/* The following three include files are needed for cpanel */
#include "main.h"
#include "dir.h"
#include "panel.h"

/* Create the Tk widget */
void
x_create_info (Dlg_head *h, widget_data parent, WInfo *info)
{
    char *cmd;
    widget_data container = info->widget.wcontainer;

    cmd = tk_new_command  (container, info, 0, 'o');
    tk_evalf ("newinfo %s %s " VERSION, (char *)container,
	      wtk_win (info->widget));
}

/* Updates the information on the Tk widgets */
void
x_show_info (WInfo *info, struct my_statfs *s, struct stat *b)
{
    char bsize [17];
    char avail_buf [17], total_buf [17];
    char *mod, *acc, *cre;
    char *fname;
    int  have_space, have_nodes;
    int  space_percent;
    int  ispace_percent;

    fname = cpanel->dir.list [cpanel->selected].fname;
    sprint_bytesize (bsize, b->st_size, 0);
    mod = strdup (file_date (b->st_mtime));
    acc = strdup (file_date (b->st_atime));
    cre = strdup (file_date (b->st_ctime));

    /* Do we have information on space/inodes? */
    have_space = s->avail > 0 || s->total > 0;
    have_nodes = s->nfree > 0 || s->nodes > 0;

    /* Compute file system usage */
    sprint_bytesize (avail_buf, s->avail, 1);
    sprint_bytesize (total_buf, s->total, 1);
    space_percent = s->total
	? 100 * s->avail / s->total : 0;

    /* inode percentage use */
    ispace_percent = s->total ? 100 * s->nfree / s->nodes : 0;
    
    tk_evalf ("info_update %s.b {%s} %X %X " /* window fname dev ino */
	      "{%s} %o "	        /* mode mode_oct */
	      "%d %s %s "               /* links owner group */
#ifdef HAVE_ST_BLOCKS
#define BLOCKS b->st_blocks
	      "1 %d "	                /* have_blocks blocks */
#else
#define BLOCKS 0
	      "0 %d "                   /* have_blocks blocks */
#endif
              "{%s} "                     /* size */
#ifdef HAVE_RDEV
#define RDEV b->st_rdev
	      "1 %d %d "                /* have_rdev rdev rdev2 */
#else
#define RDEV 0
	      "0 %d %d "                /* have_rdev rdev rdev2 */
#endif
	      "{%s} {%s} {%s} "         /* create modify access */
	      "{%s} {%s} {%s} "         /* fsys dev type */
	      "%d {%s} %d {%s} "        /* have_space avail percent total */
	      "%d %d %d %d",            /* have_ino nfree inoperc inotot */

	      wtk_win (info->widget), fname,
	      b->st_dev, b->st_ino,
	      string_perm (b->st_mode), b->st_mode & 07777,
	      b->st_nlink, get_owner (b->st_uid), get_group (b->st_gid),
	      BLOCKS,
	      bsize,
	      RDEV >> 8, RDEV & 0xff,
	      cre, mod, acc,
	      s->mpoint, s->device, s->typename,
	      have_space, avail_buf, space_percent, total_buf,
	      have_nodes, s->nfree, ispace_percent, s->nodes);

    free (mod);
    free (acc);
    free (cre);
}