import java.io.*;

/***************************************************************************

    Dirs -- Perform Tree Search of Directories and Print Graph of Sizes

 ***************************************************************************/   

    class Dirs
      {
      String sBasePath;
      int iMaxLevels;
      long lMaxGraphSize;


      Dirs (String s, int iMaxLevelsIn, long lMaxGraphSizeIn)
        {
        sBasePath = s;
        iMaxLevels = iMaxLevelsIn;
        lMaxGraphSize = lMaxGraphSizeIn;
        }


      void walkTree ()
        {
        File f;

        f = new File (sBasePath);
        System.out.println ("");
        processNode (f, 0);
        System.out.println ("");
        }


      long processNode (File fIn, int iLevel)
        {
        File f;
        String[] as;
        int i;
        long l = 0;

        if (fIn.isDirectory ())                  // If it is a directory..
          {
          as = fIn.list ();                      // ....Get its file names

          for (i = 0; i < as.length; i++)
            {                                    // ......For every file name
            f = new File (fIn, as[i]);           // ........Create file obj
            l += processNode (f, iLevel + 1);    // ..........and process it.
            }

          if (iLevel <= iMaxLevels)
            {
            System.out.println ("Dir: " + fIn.getPath () + "  Size = " + l);
            printGraph (l, lMaxGraphSize);
            }
          return (l);
          }

        return (fIn.length ());
        }


      void printGraph (long lSize, long lMax)
        {
        long i;
        long lNumChars;

        if (lSize > lMax) lSize = lMax;
        lNumChars = (79 * lSize) / lMax;

        for (i = 0; i < 79; i++)
          {
          if (i == lNumChars - 1)
            {
            System.out.print (">");
            }
          else if (i < lNumChars - 1)
            {
            System.out.print ("=");
            }
          else 
            {
            System.out.print ("-");
            }
          }
        System.out.println ();
        System.out.println ();
        }


      public static void main (String[] args)
        {
        Dirs x;
        long lMaxGraphSize;
        int iNumLevels;

        if (args.length < 1)
          {
          System.out.println ("Format: java Dirs BasePath [NumLevels "
           + "[MaxGraphSize]]");
          System.exit (1);
          }
        if (args.length > 1)
          {
          iNumLevels = (new Integer (args[1])).intValue ();
          }
        else
          {
          iNumLevels = 100;
          }
        if (args.length > 2)
          {
          lMaxGraphSize = (new Long (args[2])).longValue ();
          }
        else
          {
          lMaxGraphSize = 1000000;
          }

        x = new Dirs (args[0], iNumLevels, lMaxGraphSize);
        x.walkTree ();
        } 
      } 

