Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

dutree.h

Go to the documentation of this file.
00001 /* dutree  -- Graphical display of disk useage
00002    Copyright (C) 1992, 1996, 2000 Free Software Foundation, Inc.
00003    Copyright (C) 2002 Aaron Bentley
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 2, or (at your option)
00008    any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software Foundation,
00017    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00018 
00019 #if HAVE_DIRENT_H
00020 # include <dirent.h>
00021 #else
00022 # define dirent direct
00023 # if HAVE_SYS_NDIR_H
00024 #  include <sys/ndir.h>
00025 # endif
00026 # if HAVE_SYS_DIR_H
00027 #  include <sys/dir.h>
00028 # endif
00029 # if HAVE_NDIR_H
00030 #  include <ndir.h>
00031 # endif
00032 #endif
00033 
00034 
00035 #define DOT_OR_DOTDOT(Basename) \
00036   (Basename[0] == '.' && (Basename[1] == '\0' \
00037            || (Basename[1] == '.' && Basename[2] == '\0')))
00038 
00039 #define xstrdup strdup
00040 #define xrealloc realloc
00041 /* Extract or fake data from a `struct stat'.
00042    ST_BLKSIZE: Preferred I/O blocksize for the file, in bytes.
00043    ST_NBLOCKS: Number of blocks in the file, including indirect blocks.
00044    ST_NBLOCKSIZE: Size of blocks used when calculating ST_NBLOCKS.  */
00045 #ifndef HAVE_STRUCT_STAT_ST_BLOCKS
00046 # define ST_BLKSIZE(statbuf) DEV_BSIZE
00047 # if defined(_POSIX_SOURCE) || !defined(BSIZE) /* fileblocks.c uses BSIZE.  */
00048 #  define ST_NBLOCKS(statbuf) \
00049   (S_ISREG ((statbuf).st_mode) \
00050    || S_ISDIR ((statbuf).st_mode) \
00051    ? (statbuf).st_size / ST_NBLOCKSIZE + ((statbuf).st_size % ST_NBLOCKSIZE != 0) : 0)
00052 # else /* !_POSIX_SOURCE && BSIZE */
00053 #  define ST_NBLOCKS(statbuf) \
00054   (S_ISREG ((statbuf).st_mode) \
00055    || S_ISDIR ((statbuf).st_mode) \
00056    ? st_blocks ((statbuf).st_size) : 0)
00057 # endif /* !_POSIX_SOURCE && BSIZE */
00058 #else /* HAVE_STRUCT_STAT_ST_BLOCKS */
00059 /* Some systems, like Sequents, return st_blksize of 0 on pipes. */
00060 # define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
00061                 ? (statbuf).st_blksize : DEV_BSIZE)
00062 # if defined(hpux) || defined(__hpux__) || defined(__hpux)
00063 /* HP-UX counts st_blocks in 1024-byte units.
00064    This loses when mixing HP-UX and BSD filesystems with NFS.  */
00065 #  define ST_NBLOCKSIZE 1024
00066 # else /* !hpux */
00067 #  if defined(_AIX) && defined(_I386)
00068 /* AIX PS/2 counts st_blocks in 4K units.  */
00069 #   define ST_NBLOCKSIZE (4 * 1024)
00070 #  else /* not AIX PS/2 */
00071 #   if defined(_CRAY)
00072 #    define ST_NBLOCKS(statbuf) \
00073   (S_ISREG ((statbuf).st_mode) \
00074    || S_ISDIR ((statbuf).st_mode) \
00075    ? (statbuf).st_blocks * ST_BLKSIZE(statbuf)/ST_NBLOCKSIZE : 0)
00076 #   endif /* _CRAY */
00077 #  endif /* not AIX PS/2 */
00078 # endif /* !hpux */
00079 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
00080 
00081 #ifndef ST_NBLOCKS
00082 # define ST_NBLOCKS(statbuf) \
00083   (S_ISREG ((statbuf).st_mode) \
00084    || S_ISDIR ((statbuf).st_mode) \
00085    ? (statbuf).st_blocks : 0)
00086 #endif
00087 
00088 #ifndef ST_NBLOCKSIZE
00089 # define ST_NBLOCKSIZE 512
00090 #endif
00091 
00092 #ifndef O_DIRECTORY
00093 # define O_DIRECTORY 0
00094 #endif
00095 
00096 #if CLOSEDIR_VOID
00097 /* Fake a return value. */
00098 # define CLOSEDIR(d) (closedir (d), 0)
00099 #else
00100 # define CLOSEDIR(d) closedir (d)
00101 #endif
00102 
00103 #if STDC_HEADERS || (!defined (isascii) && !HAVE_ISASCII)
00104 # define IN_CTYPE_DOMAIN(c) 1
00105 #else
00106 # define IN_CTYPE_DOMAIN(c) isascii(c)
00107 #endif
00108 
00109 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
00110 
00111 using std::cout;
00112 using std::endl;
00113 
00114 using SigC::slot;
00115 
00119 struct String
00120 {
00121   unsigned alloc;    /* Size of allocation for the text.  */
00122   unsigned length;      /* Length of the text currently.  */
00123   char *text;        /* Pointer to the text.  */
00124 };
00125 typedef struct String String;
00126 
00132 class DirTree
00133 {
00134 private:
00135    struct exclude_st *exclude;
00136    String *path;
00137    int (*xstat) (const char *, struct stat *buf);
00138    int exit_status;
00139    uintmax_t tot_size;
00140    struct htab *htab;
00141 
00142    /* Allocate space for the hash structures, and set the global
00143     variable `htab' to point to it.  The initial hash module is specified in
00144     MODULUS, and the number of entries are specified in ENTRY_TAB_SIZE.  (The
00145     hash structure will be rebuilt when ENTRY_TAB_SIZE entries have been
00146     inserted, and MODULUS and ENTRY_TAB_SIZE in the global `htab' will be
00147     doubled.)  */
00148 
00149    void hash_init (unsigned int modulus, unsigned int entry_tab_size);
00150    int hash_insert2 (struct htab *ht, ino_t ino, dev_t dev);
00151    int hash_insert (ino_t ino, dev_t dev);
00152    void hash_reset (void);
00153 
00154    uintmax_t count_entry (const char *ent, int top, dev_t last_dev, int depth, 
00155    EnTree *target);
00156    uintmax_t propogate_up(uintmax_t size, EnTree *target);
00157 
00158    void init();
00159    Watcher<DirTree> *my_watch;
00160 public:
00162    bool opt_count_all;
00163    bool opt_dereference_arguments;
00165    bool opt_one_file_system;
00166    bool opt_separate_dirs;
00168    bool opt_all;
00170    bool up_immediate;
00172    int max_depth;
00173 
00174    DirTree();
00175    void calc_EnTree(const char *target, EnTree *my_tree);
00176    void set_watcher(Watcher<DirTree> &my_watch);
00177 };
00178 
00179 
00183 class TreeView: public ImageMap, public Watcher<DirTree>, 
00184    public RegionWatcher<EntryRect>
00185 {
00186 private:
00187    std::auto_ptr<EnTree> my_tree;
00188    EnTree const *cur_tree;
00189    bool firsttime;
00190    uintmax_t oldsize;
00191    DirTree treeGen;
00192    std::auto_ptr<Drawer> dwr;
00193    std::auto_ptr<ColorPicker> cpick;
00194    bool drawing;
00195 
00196 public:
00197    RecTransform rt;
00198    TreeView(gint x_size = 0, gint y_size = 0);
00199 
00200    EnTree const &get_EnTree() const;
00201 
00202    void set_EnTree(EnTree const &newcur);
00203 
00204    EnTree const &get_top_EnTree() const;
00205 
00206    void modified(DirTree const &moddir);
00207 
00208    void EnTree_rect(EnTree const *curent, bool vertical, gint x, gint y, 
00209       gint width, gint height);
00210 
00211    void draw_rect();
00212    
00213    bool isReady();
00214 
00215    void test_tree();
00216 
00217    void setDrawer(Drawer *d)
00218    {
00219       dwr.reset(d);
00220    }
00221 
00222    void set_cpick(ColorPicker *cp)
00223    {
00224       cpick.reset(cp);
00225    }
00226 
00227    Drawer *getDrawer()
00228    {
00229       return dwr.get();
00230    }
00231 
00232    gint expose_event_impl(GdkEventExpose*);
00233 
00234    gint delayed_calc();
00235 
00236    bool clicked(EntryRect const *, int button);
00237    virtual bool region_hover(EntryRect &region)
00238    {
00239       me_modified();
00240       //set_EnTree(region.get_EnTree());
00241       return true;
00242    }
00243 };
00244 
00245 /* Initial number of entries in each hash table entry's table of inodes.  */
00246 #define INITIAL_HASH_MODULE 100
00247 
00248 /* Initial number of entries in the inode hash table.  */
00249 #define INITIAL_ENTRY_TAB_SIZE 70
00250 
00251 /* Initial size to allocate for `path'.  */
00252 #define INITIAL_PATH_SIZE 100
00253 
00254 #include "commandbutton.h"
00258 class MainWindow: public Gtk::Window, public Watcher<ImageMap>
00259 {
00260 private:
00261    Gtk::Button child_button;
00262    Gtk::Button next_button;
00263    Gtk::Button prev_button;
00264    Gtk::Button parent_button;
00265    Gtk::Label curdir;
00266    Gtk::VBox packer;
00267    Gtk::HBox buttons;
00268    Gtk::HBox hbox;
00269    Gtk::HBox buttonslabel;
00270    TreeView tview;
00271    CommandButton rbutton;
00272    CommandButton colorbutton;
00273    void nav(EnTree &en_new)
00274    {
00275       //setInfo(&en_new, tview.get_top_EnTree());
00276       tview.set_EnTree(en_new);
00277    }
00278    void nav_child()
00279    {
00280       EnTree *child=tview.get_EnTree().child;
00281       if (child!=NULL) nav(*child);
00282    }
00283    void nav_next()
00284    {
00285       EnTree *next=tview.get_EnTree().next;
00286       if (next!=NULL) nav(*next);
00287    }
00288    void nav_prev()
00289    {
00290       EnTree *prev=tview.get_EnTree().prev;
00291       if (prev!=NULL) nav(*prev);
00292    }
00293    void nav_parent()
00294    {
00295       if (! tview.isReady()) return;
00296 
00297       EnTree *parent=tview.get_EnTree().parent;
00298       if (parent!=NULL) nav(*parent);
00299    }
00300    void setInfo(EnTree const &cur, EnTree const &top);
00301 
00302    public:
00303    MainWindow();
00304    virtual int delete_event_impl(GdkEventAny *event);
00305    void modified(const ImageMap &);
00306    gint delayed_calc()
00307    {
00308       return false;
00309    }
00310 };
00311 
00312 struct entry
00313 {
00314   ino_t ino;
00315   dev_t dev;
00316   struct entry *coll_link;
00317 };
00318 
00319 struct htab
00320 {
00321   unsigned modulus;     /* Size of the `hash' pointer vector.  */
00322   struct entry *entry_tab; /* Pointer to dynamically growing vector.  */
00323   unsigned entry_tab_size; /* Size of current `entry_tab' allocation.  */
00324   unsigned first_free_entry;  /* Index in `entry_tab'.  */
00325   struct entry *hash[1];   /* Vector of pointers in `entry_tab'.  */
00326 };
00327 
00328 

Generated on Mon Apr 7 19:41:44 2003 for DuTree by doxygen1.2.18