File: AddBom.cs

package info (click to toggle)
cadencii 3.3.9%2Bsvn20110818.r1732-5
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 35,880 kB
  • sloc: cs: 160,836; java: 42,449; cpp: 7,605; ansic: 1,728; perl: 1,087; makefile: 236; php: 142; xml: 117; sh: 21
file content (50 lines) | stat: -rw-r--r-- 1,581 bytes parent folder | download | duplicates (6)
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
using System;
using System.IO;
using System.Text;

class AddBom{
    private static string s_target_path = "";

    public static void Main( string[] args ){
        string current_parse = "";
        if( args.Length <= 0 ){
            Console.WriteLine( "AddBom" );
            Console.WriteLine( "Copyright (C) 2010 kbinani, All Rights Reserved" );
            Console.WriteLine( "Usage:" );
            Console.WriteLine( "    AddBom -t [search path]" );
            return;
        }

        for( int i = 0; i < args.Length; i++ ){
            if( args[i].StartsWith( "-" ) ){
                current_parse = args[i];
            }else{
                if( current_parse == "-t" ){
                    s_target_path = args[i];
                }else{
                }
                current_parse = "";
            }
        }

        if( s_target_path == "" ){
            return;
        }

        DirectoryInfo di = new DirectoryInfo( s_target_path );
        string tmp = Path.GetTempFileName();
        foreach( FileInfo fi in di.GetFiles( "*.cs" ) ){
            string file = fi.FullName;
            using( StreamReader sr = new StreamReader( file ) )
            using( StreamWriter sw = new StreamWriter( tmp, false, new UTF8Encoding( true ) ) ){
                string line = "";
                while( (line = sr.ReadLine()) != null ){
                    sw.WriteLine( line );
                }
            }
            
            File.Delete( file );
            File.Move( tmp, file );
        }
    }
}