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

dutree.cpp File Reference

#include <gtk--/main.h>
#include <gtk--/window.h>
#include <gtk--/button.h>
#include <gtk--/box.h>
#include <gtk--/drawingarea.h>
#include <gtk--/style.h>
#include <gtk--/label.h>
#include <gtk--/widget.h>
#include <sigc++-1.0/sigc++/slot.h>
#include <sigc++-1.0/sigc++/signal_system.h>
#include "errno.h"
#include <sys/stat.h>
#include "save-cwd.h"
#include <unistd.h>
#include "savedir.h"
#include "config.h"
#include <fcntl.h>
#include <sstream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include "context.h"
#include "drawerdep.h"
#include "drawervisitordep.h"
#include "colorpickerdep.h"
#include "dutree.h"
#include "rotatedrawer.h"
#include <stdio.h>
#include <sys/types.h>
#include "pathmax.h"

Include dependency graph for dutree.cpp:

Include dependency graph

Compounds

struct  exclude_st
class  RotateDrawerCmd
class  RotateColorCmd

Defines

#define NAME_SIZE_DEFAULT   512
#define FNM_PATHNAME   (1 << 0)
#define FNM_NOESCAPE   (1 << 1)
#define FNM_PERIOD   (1 << 2)
#define FNM_FILE_NAME   FNM_PATHNAME
#define FNM_LEADING_DIR   (1 << 3)
#define FNM_CASEFOLD   (1 << 4)
#define FNM_NOMATCH   1
#define FOLD(c)
#define S_ISLNK(s)   0

Functions

std::ostream & operator<< (std::ostream &output, Exception &err)
 Writes an exception to an ostream.

void destroy_handler ()
char * getcwd ()
char * xgetcwd ()
void free_cwd (struct saved_cwd *cwd)
void xalloc_fail_func PARAMS ((void))=0
void xalloc_die (void)
char * savedir (const char *dir, off_t name_size)
int restore_cwd (const struct saved_cwd *cwd, const char *dest, const char *from)
int save_cwd (struct saved_cwd *cwd)
int fnmatch (const char *pattern, const char *string, int flags)
exclude_stnew_exclude (void)
int excluded_filename (struct exclude_st const *ex, char const *f, int options)
int main (int argc, char *argv[])

Variables

int errno

Define Documentation

#define NAME_SIZE_DEFAULT   512
 

#define FNM_PATHNAME   (1 << 0)
 

#define FNM_NOESCAPE   (1 << 1)
 

#define FNM_PERIOD   (1 << 2)
 

#define FNM_FILE_NAME   FNM_PATHNAME
 

#define FNM_LEADING_DIR   (1 << 3)
 

#define FNM_CASEFOLD   (1 << 4)
 

#define FNM_NOMATCH   1
 

#define FOLD  
 

Value:

((flags & FNM_CASEFOLD) && ISUPPER ((unsigned char) (c)) \
                 ? tolower ((unsigned char) (c)) \
                 : (c))

#define S_ISLNK      0
 


Function Documentation

std::ostream& operator<< std::ostream &    output,
Exception   err
 

Writes an exception to an ostream.

Note:
a wrapper on Exception::write so normal syntax can be used

00056 {
00057    err.write(output);
00058    return output;
00059 }

void destroy_handler  
 

00062 {
00063    Gtk::Main::quit();
00064 }

char* getcwd  
 

char* xgetcwd  
 

00490 {
00491   char *ret;
00492   unsigned path_max;
00493   char buf[1024];
00494 
00495   errno = 0;
00496   ret = getcwd (buf, sizeof (buf));
00497   if (ret != NULL)
00498     return xstrdup (buf);
00499   if (errno != ERANGE)
00500     return NULL;
00501 
00502   path_max = (unsigned) PATH_MAX;
00503   path_max += 2;     /* The getcwd docs say to do this. */
00504 
00505   for (;;)
00506     {
00507       char *cwd = (char *) xmalloc (path_max);
00508 
00509       errno = 0;
00510       ret = getcwd (cwd, path_max);
00511       if (ret != NULL)
00512    return ret;
00513       if (errno != ERANGE)
00514    {
00515      int save_errno = errno;
00516      free (cwd);
00517      errno = save_errno;
00518      return NULL;
00519    }
00520 
00521       free (cwd);
00522 
00523       path_max += path_max / 16;
00524       path_max += 32;
00525     }
00526 }

void free_cwd struct saved_cwd   cwd
 

00530 {
00531   if (cwd->desc >= 0)
00532     close (cwd->desc);
00533   if (cwd->name)
00534     free (cwd->name);
00535 }

void xalloc_fail_func PARAMS (void)    [pure virtual]
 

void xalloc_die void   
 

00541 {
00542   if (xalloc_fail_func)
00543     (*xalloc_fail_func) ();
00544   //error (xalloc_exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted));
00545   /* The `noreturn' cannot be given to error, since it may return if
00546      its first argument is 0.  To help compilers understand the
00547      xalloc_die does terminate, call exit. */
00548   exit (EXIT_FAILURE);
00549 }

char* savedir const char *    dir,
off_t    name_size
 

00567 {
00568   DIR *dirp;
00569   struct dirent *dp;
00570   char *name_space;
00571   size_t allocated = name_size; /* Overflow is checked indirectly below.  */
00572   size_t used = 0;
00573   int save_errno;
00574 
00575   dirp = opendir (dir);
00576   if (dirp == NULL)
00577     return NULL;
00578 
00579   /* Use the default if the size is not known.  Be sure "allocated"
00580      is at least `1' so there's room for the final NUL byte.
00581      Do not simply test name_size <= 0, because the initialization
00582      of "allocated" might have overflowed.  */
00583   if (name_size < 0 || allocated == 0)
00584     allocated = NAME_SIZE_DEFAULT;
00585 
00586   name_space = static_cast<char *>(xmalloc (allocated));
00587 
00588   errno = 0;
00589   while ((dp = readdir (dirp)) != NULL)
00590     {
00591       /* Skip "", ".", and "..".  "" is returned by at least one buggy
00592          implementation: Solaris 2.4 readdir on NFS filesystems.  */
00593       char const *entry = dp->d_name;
00594       if (entry[entry[0] != '.' ? 0 : entry[1] != '.' ? 1 : 2] != '\0')
00595    {
00596      size_t entry_size = strlen (entry) + 1;
00597      if (used + entry_size < used)
00598        xalloc_die ();
00599      if (allocated <= used + entry_size)
00600        {
00601          do
00602       {
00603         if (2 * allocated < allocated)
00604           xalloc_die ();
00605         allocated *= 2;
00606       }
00607          while (allocated <= used + entry_size);
00608 
00609          name_space = static_cast<char *>(xrealloc (name_space, allocated));
00610        }
00611      memcpy (name_space + used, entry, entry_size);
00612      used += entry_size;
00613    }
00614     }
00615   name_space[used] = '\0';
00616   save_errno = errno;
00617   if (CLOSEDIR (dirp) != 0)
00618     save_errno = errno;
00619   if (save_errno != 0)
00620     {
00621       free (name_space);
00622       errno = save_errno;
00623       return NULL;
00624     }
00625   return name_space;
00626 }

int restore_cwd const struct saved_cwd   cwd,
const char *    dest,
const char *    from
 

00634 {
00635   int fail = 0;
00636   if (cwd->desc >= 0)
00637     {
00638       if (fchdir (cwd->desc))
00639    {
00640      /*error (0, errno, "cannot return to %s%s%s",
00641        (dest ? dest : "saved working directory"),
00642        (from ? " from " : ""),
00643        (from ? from : ""));*/
00644      fail = 1;
00645    }
00646     }
00647   else if (chdir (cwd->name) < 0)
00648     {
00649 //      error (0, errno, "%s", cwd->name);
00650       fail = 1;
00651     }
00652   return fail;
00653 }

int save_cwd struct saved_cwd   cwd
 

00666 {
00667   static int have_working_fchdir = 1;
00668 
00669   cwd->desc = -1;
00670   cwd->name = NULL;
00671 
00672   if (have_working_fchdir)
00673     {
00674 #if HAVE_FCHDIR
00675       cwd->desc = open (".", O_RDONLY | O_DIRECTORY);
00676       if (cwd->desc < 0)
00677    {
00678      //error (0, errno, "cannot open current directory");
00679      return 1;
00680    }
00681 
00682 # if __sun__ || sun
00683       /* On SunOS 4, fchdir returns EINVAL if accounting is enabled,
00684     so we have to fall back to chdir.  */
00685       if (fchdir (cwd->desc))
00686    {
00687      if (errno == EINVAL)
00688        {
00689          close (cwd->desc);
00690          cwd->desc = -1;
00691          have_working_fchdir = 0;
00692        }
00693      else
00694        {
00695          error (0, errno, "current directory");
00696          close (cwd->desc);
00697          cwd->desc = -1;
00698          return 1;
00699        }
00700    }
00701 # endif /* __sun__ || sun */
00702 #else
00703 # define fchdir(x) (abort (), 0)
00704       have_working_fchdir = 0;
00705 #endif
00706     }
00707 
00708   if (!have_working_fchdir)
00709     {
00710       cwd->name = xgetcwd ();
00711       if (cwd->name == NULL)
00712    {
00713 //   error (0, errno, "cannot get current directory");
00714      return 1;
00715    }
00716     }
00717   return 0;
00718 }

int fnmatch const char *    pattern,
const char *    string,
int    flags
 

00739 {
00740   register const char *p = pattern, *n = string;
00741   register char c;
00742 
00743 /* Note that this evaluates C many times.  */
00744 #define FOLD(c) ((flags & FNM_CASEFOLD) && ISUPPER ((unsigned char) (c)) \
00745                  ? tolower ((unsigned char) (c)) \
00746                  : (c))
00747 
00748   while ((c = *p++) != '\0')
00749     {
00750       c = FOLD (c);
00751 
00752       switch (c)
00753    {
00754    case '?':
00755      if (*n == '\0')
00756        return FNM_NOMATCH;
00757      else if ((flags & FNM_FILE_NAME) && *n == '/')
00758        return FNM_NOMATCH;
00759      else if ((flags & FNM_PERIOD) && *n == '.' &&
00760          (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
00761        return FNM_NOMATCH;
00762      break;
00763 
00764    case '\\':
00765      if (!(flags & FNM_NOESCAPE))
00766        {
00767          c = *p++;
00768          if (c == '\0')
00769       /* Trailing \ loses.  */
00770       return FNM_NOMATCH;
00771          c = FOLD (c);
00772        }
00773      if (FOLD (*n) != c)
00774        return FNM_NOMATCH;
00775      break;
00776 
00777    case '*':
00778      if ((flags & FNM_PERIOD) && *n == '.' &&
00779          (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
00780        return FNM_NOMATCH;
00781 
00782      for (c = *p++; c == '?' || c == '*'; c = *p++)
00783        {
00784          if (c == '?')
00785       {
00786         /* A ? needs to match one character.  */
00787         if (*n == '\0' || (*n == '/' && (flags & FNM_FILE_NAME)))
00788           /* There isn't another character; no match.  */
00789           return FNM_NOMATCH;
00790         else
00791           /* One character of the string is consumed in matching
00792              this ? wildcard, so *??? won't match if there are
00793              less than three characters.  */
00794           ++n;
00795       }
00796        }
00797 
00798      if (c == '\0')
00799        {
00800          if ((flags & (FNM_FILE_NAME | FNM_LEADING_DIR)) == FNM_FILE_NAME)
00801       for (; *n != '\0'; n++)
00802         if (*n == '/')
00803           return FNM_NOMATCH;
00804          return 0;
00805        }
00806 
00807      {
00808        char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
00809        c1 = FOLD (c1);
00810        for (--p; *n != '\0'; ++n)
00811          if ((c == '[' || FOLD (*n) == c1) &&
00812         fnmatch (p, n, flags & ~FNM_PERIOD) == 0)
00813       return 0;
00814          else if (*n == '/' && (flags & FNM_FILE_NAME))
00815       break;
00816        return FNM_NOMATCH;
00817      }
00818 
00819    case '[':
00820      {
00821        /* Nonzero if the sense of the character class is inverted.  */
00822        register int noot;
00823 
00824        if (*n == '\0')
00825          return FNM_NOMATCH;
00826 
00827        if ((flags & FNM_PERIOD) && *n == '.' &&
00828       (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
00829          return FNM_NOMATCH;
00830 
00831        noot = (*p == '!' || *p == '^');
00832        if (noot)
00833          ++p;
00834 
00835        c = *p++;
00836        for (;;)
00837          {
00838       register char cstart = c, cend = c;
00839 
00840       if (!(flags & FNM_NOESCAPE) && c == '\\')
00841         {
00842           if (*p == '\0')
00843             return FNM_NOMATCH;
00844           cstart = cend = *p++;
00845         }
00846 
00847       cstart = cend = FOLD (cstart);
00848 
00849       if (c == '\0')
00850         /* [ (unterminated) loses.  */
00851         return FNM_NOMATCH;
00852 
00853       c = *p++;
00854       c = FOLD (c);
00855 
00856       if ((flags & FNM_FILE_NAME) && c == '/')
00857         /* [/] can never match.  */
00858         return FNM_NOMATCH;
00859 
00860       if (c == '-' && *p != ']')
00861         {
00862           cend = *p++;
00863           if (!(flags & FNM_NOESCAPE) && cend == '\\')
00864             cend = *p++;
00865           if (cend == '\0')
00866             return FNM_NOMATCH;
00867           cend = FOLD (cend);
00868 
00869           c = *p++;
00870         }
00871 
00872       if (FOLD (*n) >= cstart && FOLD (*n) <= cend)
00873         goto matched;
00874 
00875       if (c == ']')
00876         break;
00877          }
00878        if (!noot)
00879          return FNM_NOMATCH;
00880        break;
00881 
00882      matched:;
00883        /* Skip the rest of the [...] that already matched.  */
00884        while (c != ']')
00885          {
00886       if (c == '\0')
00887         /* [... (unterminated) loses.  */
00888         return FNM_NOMATCH;
00889 
00890       c = *p++;
00891       if (!(flags & FNM_NOESCAPE) && c == '\\')
00892         {
00893           if (*p == '\0')
00894             return FNM_NOMATCH;
00895           /* XXX 1003.2d11 is unclear if this is right.  */
00896           ++p;
00897         }
00898          }
00899        if (noot)
00900          return FNM_NOMATCH;
00901      }
00902      break;
00903 
00904    default:
00905      if (c != FOLD (*n))
00906        return FNM_NOMATCH;
00907    }
00908 
00909       ++n;
00910     }
00911 
00912   if (*n == '\0')
00913     return 0;
00914 
00915   if ((flags & FNM_LEADING_DIR) && *n == '/')
00916     /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz".  */
00917     return 0;
00918 
00919   return FNM_NOMATCH;
00920 
00921 #undef FOLD
00922 }

struct exclude_st* new_exclude void   
 

00934 {
00935   struct exclude_st *ex = (struct exclude_st *) xmalloc (sizeof (struct exclude_st));
00936   ex->exclude_count = 0;
00937   ex->exclude_alloc = 64;
00938   ex->exclude = (char const **) xmalloc (ex->exclude_alloc * sizeof (char *));
00939   return ex;
00940 }

int excluded_filename struct exclude_st const *    ex,
char const *    f,
int    options
 

00944 {
00945   char const * const *exclude = ex->exclude;
00946   int exclude_count = ex->exclude_count;
00947   int i;
00948 
00949   for (i = 0;  i < exclude_count;  i++)
00950     if (fnmatch (exclude[i], f, options) == 0)
00951       return 1;
00952 
00953   return 0;
00954 }

int main int    argc,
char *    argv[]
 

01437 {
01438    Context cx1("main()");
01439    try
01440    {
01441       // all GTK applications must have a gtk_main(). Control ends here
01442       // and waits for an event to occur (like a key press or mouse event).
01443       Gtk::Main kit(argc, argv);
01444 
01445       MainWindow dutree;
01446       {
01447     Context cx2("Update thread");
01448     kit.run();
01449       }
01450    }
01451    catch (Exception &err)
01452    {
01453       cout << err;
01454    }
01455    catch (ContException &cxe)
01456    {
01457       cxe.print();
01458    }
01459    return 0;
01460 }


Variable Documentation

int errno
 


Generated on Mon Apr 7 19:42:23 2003 for DuTree by doxygen1.2.18