comparison fixmodule.d @ 152:07f3bab17e54

fixmodules
author Frank Benoit <benoit@tionex.de>
date Sun, 24 Aug 2008 23:57:08 +0200
parents
children 0ea0c9f9008f
comparison
equal deleted inserted replaced
151:eb21d3dfc767 152:07f3bab17e54
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 auto cont = cast(char[])File( filename ).read;
32 char[][] lines = cont.splitLines();
33 int modLine = -1;
34 foreach( uint idx, char[] line; lines ){
35 if( line.length && line.locatePattern( "module dwtx" ) is 0 ){
36 //Trace.formatln( "mod: {} {}", idx, line );
37 modLine = idx;
38 break;
39 }
40 }
41 int impLine = -1;
42 foreach( uint idx, char[] line; lines ){
43 if( line.length && line.locatePattern( "import dwtx" ) is 0 ){
44 //Trace.formatln( "imp: {} {}", idx, line );
45 impLine = idx;
46 break;
47 }
48 }
49 assert( modLine !is -1 );
50 assert( impLine !is -1 );
51 if( modLine > impLine ){
52 Trace.formatln( "{} {} {} {}", filename, modLine, impLine, lines.length );
53 auto moddecl = lines[ modLine .. modLine + 2 ].dup;
54 for( int i = modLine; i >= impLine+1; i-- ){
55 lines[i+1] = lines[i-1];
56 }
57 lines[ impLine .. impLine+2 ] = moddecl;
58 auto output = new TextFileOutput( filename );
59 bool first = true;
60 foreach( line; lines ){
61 if( !first ){
62 output.write( \n );
63 }
64 first = false;
65 output.write( line );
66 }
67 output.flush();
68 output.close();
69 }
70 }
71 // read content into buffer
72 // search module statement and print to outfile
73 // write package imports
74 // write all remaining lines
75 }
76
77 void main(){
78 processDir( "dwtx/text" );
79 processDir( "dwtx/jface/text" );
80 processDir( "dwtx/jface/internal/text" );
81 }
82
83
84
85
86
87