1 // ===========================================================================
2 // Copyright (c) 2002 DAgora Team. All rights reserved.
3 // ---------------------------------------------------------------------------
4 package nmp.util;
5
6 import java.io.*;
7
8 public class AddCopyright
9 {
10 private static String []newCopyright = {
11 "// ===========================================================================",
12 "// Copyright (c) 2002 DAgora Team. All rights reserved.",
13 "// ---------------------------------------------------------------------------"
14 };
15
16 private static String []oldCopyright = {
17 "// ===========================================================================",
18 "// Copyright (c) 2002 DAgora Team. All rights reserved.",
19 "// ---------------------------------------------------------------------------"
20 };
21
22 private static void processOne( BufferedReader reader, PrintWriter writer) throws IOException {
23 for( int i = 0; i < newCopyright.length; i++)
24 writer.println( newCopyright[i]);
25
26 String line = null;
27
28 // process old copyright
29 String []l = new String[oldCopyright.length];
30 int pos = 0;
31 boolean isoldcopyright = true;
32 boolean endoffile = false;
33 for( ; isoldcopyright && pos < oldCopyright.length; pos++) {
34 l[pos] = reader.readLine();
35 if( l[pos] == null) {
36 isoldcopyright = false;
37 endoffile = true;
38 break;
39 }
40 if( ! l[pos].equals( oldCopyright[pos])) {
41 isoldcopyright = false;
42 }
43 }
44 if( ! isoldcopyright)
45 for( int i = 0; i < pos; i++)
46 writer.println( l[i]);
47 if( ! endoffile)
48 for( ; ; ) {
49 String str = reader.readLine();
50 if( str == null)
51 break;
52 writer.println( str);
53 }
54 }
55
56 private static void addOne( String filename) throws IOException {
57 String auxfilename = filename + "._old";
58 File f = new File( filename);
59 File faux = new File( auxfilename);
60 BufferedReader reader = new BufferedReader( new FileReader( f));
61 PrintWriter writer = new PrintWriter( new FileWriter( faux));
62
63 processOne( reader, writer);
64
65 writer.flush();
66 writer.close();
67 reader.close();
68
69 if( f.delete() == false)
70 throw new IOException( "Could not delete :" + f.getPath());
71 if( faux.renameTo( f) == false)
72 throw new IOException( "Could not rename :" + faux.getPath());
73 }
74
75
76 public static void main(String[] args)
77 {
78 try {
79 if( args.length != 1) {
80 System.out.println( "Usages:\nnmp.util.AddCopyright [filename|@filename]");
81 System.exit( 0);
82 }
83 if( args[0].startsWith("@")) {
84 BufferedReader reader = new BufferedReader( new FileReader( args[0].substring(1)));
85 for( ; ;) {
86 String line = reader.readLine();
87 if( line == null)
88 break;
89 addOne( line);
90 }
91 reader.close();
92 } else
93 addOne( args[0]);
94 } catch( Throwable th) {
95 th.printStackTrace();
96 }
97
98 }
99 }
This page was automatically generated by Maven