/*
 * The MIT License
 * 
 * Copyright (C) 2013 Kiyofumi Kondoh
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package jp.ne.sakura.kkkon.StripElfSectionHeader;

import java.io.File;
import jp.ne.sakura.kkkon.StripElfSectionHeader.ElfFile.ElfFile;

/**
 *
 * @author Kiyofumi Kondoh
 */
public class App 
{

    public static void stripRecursive( final String path )
    {
        File file = new File( path );
        if ( file.isDirectory() )
        {
            final File[] files = file.listFiles();
            if ( null != files )
            {
                final int count = files.length;
                for ( int index = 0; index < count; ++index )
                {
                    if ( null == files[index] )
                    {
                        continue;
                    }
                    //System.err.println( files[index].getPath() );

                    if ( 0 == ".".compareTo(files[index].getPath()))
                    {
                        continue;
                    }
                    if ( 0 == "..".compareTo(files[index].getPath()))
                    {
                        continue;
                    }
                    stripRecursive( files[index].getAbsolutePath() );
                }
            }
        }
        else
        {
            final boolean isElfFile = ElfFile.stripElfSectionHeader( path );
            System.err.println( path + ": " + isElfFile );
        }
        
    }

    public static void main( String[] args )
    {
        AppOption appOpt = new AppOption();
        appOpt.createOptions();
        appOpt.parseOption( args );
        appOpt.applyOption();

        if ( null == args )
        {
            appOpt.showUsage();
            return;
        }
        if ( args.length < 1 )
        {
            appOpt.showUsage();
            return;
        }

        {
            final String[] remain_args = appOpt.getArgs();
            if ( null != remain_args )
            {
                final int count = remain_args.length;
                for ( int index = 0; index < count; ++index )
                {
                    final String arg = remain_args[index];
                    stripRecursive( arg );
                }
            }
        }
    }
}

@@ -1375,16 +1375,40 @@
 cursive(
+ final AppOption option,
  final S
@@ -1420,16 +1420,16 @@
  path )%0A
-
     %7B%0A  
@@ -2216,32 +2216,33 @@
               %7D%0A
+%0A
                 
@@ -2245,31 +2245,675 @@
         
-stripRecursive(
+%7B%0A                        boolean needCall = false;%0A                        final File f = new File( files%5Bindex%5D.getPath() );%0A                        if ( f.isDirectory() )%0A                        %7B%0A                            if ( option.isRecursive() )%0A                            %7B%0A                                needCall = true;%0A                            %7D%0A                        %7D%0A                        else%0A                        %7B%0A                            needCall = true;%0A                        %7D%0A                        %0A                        if ( needCall )%0A                        %7B%0A                            stripRecursive( option,
  files%5Bi
@@ -2925,16 +2925,8 @@
 .get
-Absolute
 Path
@@ -2923,32 +2923,80 @@
 x%5D.getPath() );%0A
+                        %7D%0A                    %7D%0A
                 
@@ -3919,16 +3919,16 @@
 index%5D;%0A
-
         
@@ -3954,16 +3954,24 @@
 cursive(
+ appOpt,
  arg );%0A

support option 'recursive'