Mercurial > projects > dwt-addons
comparison packageimport.d @ 132:77bd3bb3d7b8
tool for package imports
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 01:13:39 +0200 |
parents | |
children | 07f3bab17e54 |
comparison
equal
deleted
inserted
replaced
131:c4fb132a086c | 132:77bd3bb3d7b8 |
---|---|
1 module packageimport; | |
2 | |
3 import tango.io.FilePath; | |
4 import tango.io.File; | |
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 ); | |
32 auto cont = cast(char[])File( filename ).read; | |
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); | |
46 if( line.locatePattern( "module " ) is 0 ){ | |
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 |