Mercurial > projects > dwt-addons
annotate packageimport.d @ 197:0ea0c9f9008f
Remove tango deprecation warnings.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 18 Feb 2009 19:35:22 +0100 |
parents | 07f3bab17e54 |
children |
rev | line source |
---|---|
132 | 1 module packageimport; |
2 | |
3 import tango.io.FilePath; | |
197
0ea0c9f9008f
Remove tango deprecation warnings.
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
4 import tango.io.device.File; |
132 | 5 import tango.io.Buffer; |
6 import tango.io.stream.FileStream; | |
7 import tango.io.stream.TextFileStream; | |
8 import tango.util.log.Trace; | |
9 import tango.text.Regex; | |
10 import tango.text.Util; | |
11 import tango.text.stream.LineIterator; | |
12 import tango.text.convert.Format; | |
13 | |
14 void processDir( char[] dir ){ | |
15 auto pack = dir.dup.replace( '/', '.' ); | |
16 auto fp = FilePath(dir); | |
17 char[][] mods; | |
18 // read all module names | |
19 foreach( fileinfo; fp ){ | |
20 if( fileinfo.folder ){ | |
21 processDir( fileinfo.path ~ fileinfo.name ); | |
22 continue; | |
23 } | |
24 if( fileinfo.name.length > 2 && fileinfo.name[ $-2 .. $ ] == ".d" ){ | |
25 mods ~= fileinfo.name.dup; | |
26 } | |
27 } | |
28 // foreach module | |
29 foreach( mod; mods ){ | |
30 auto filename = Format("{}/{}", dir, mod ); | |
31 Trace.formatln( "{}", filename ); | |
197
0ea0c9f9008f
Remove tango deprecation warnings.
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
32 auto cont = cast(char[])File.get( filename ); |
132 | 33 auto output = new TextFileOutput( filename ); |
34 bool firstline = true; | |
35 void println( char[] l ){ | |
36 if( !firstline ){ | |
37 output.newline(); | |
38 } | |
39 output(l); | |
40 firstline = false; | |
41 } | |
42 bool found = false; | |
43 auto it = new LineIterator!(char)( new Buffer( cont )); | |
44 foreach( line; it ){ | |
45 println(line); | |
152 | 46 if( line.length && line.locatePattern( "module " ) is 0 ){ |
132 | 47 found = true; |
48 break; | |
49 } | |
50 } | |
51 assert( found ); | |
52 println( "" ); | |
53 foreach( impmod; mods ){ | |
54 if( impmod == mod ){ | |
55 continue; | |
56 } | |
57 println( Format( "import {}.{}; // packageimport", pack, impmod[ 0 .. $-2] )); | |
58 } | |
59 println( "" ); | |
60 foreach( line; it ){ | |
61 println(line); | |
62 } | |
63 output.flush(); | |
64 output.close(); | |
65 } | |
66 // read content into buffer | |
67 // search module statement and print to outfile | |
68 // write package imports | |
69 // write all remaining lines | |
70 } | |
71 | |
72 void main(){ | |
73 processDir( "dwtx/text" ); | |
74 processDir( "dwtx/jface/text" ); | |
75 processDir( "dwtx/jface/internal/text" ); | |
76 } | |
77 | |
78 | |
79 | |
80 | |
81 | |
82 |