root/trunk/utils/insitu.d

Revision 287, 4.1 kB (checked in by h3r3tic, 1 year ago)

updated to latest tango; added an assertion to Linker.register

Line 
1 /+
2     Copyright (c) 2005-2007 Eric Anderton
3             
4     Permission is hereby granted, free of charge, to any person
5     obtaining a copy of this software and associated documentation
6     files (the "Software"), to deal in the Software without
7     restriction, including without limitation the rights to use,
8     copy, modify, merge, publish, distribute, sublicense, and/or
9     sell copies of the Software, and to permit persons to whom the
10     Software is furnished to do so, subject to the following
11     conditions:
12
13     The above copyright notice and this permission notice shall be
14     included in all copies or substantial portions of the Software.
15
16     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23     OTHER DEALINGS IN THE SOFTWARE.
24 +/
25 module utils.insitu;
26
27 // DDL insitu utility
28
29 private import ddl.all;
30 private import ddl.DDLException;
31 private import ddl.FileBuffer;
32 private import ddl.insitu.all;
33
34 private import utils.insitu_bn;
35 private import utils.ArgParser;
36
37 private import tango.io.Stdout;
38 private import tango.io.FileConduit;
39 private import Text = tango.text.Util;
40
41 char[] helpText =
42 "InSitu - Optimized in situ module generator - V1.1 {0}
43 Copyright (C) 2005 Eric Anderton
44 Documentation: http://www.dsource.org/projects/ddl
45
46 Creates a .situ file that contains optmized .map file
47 data specifically for the DDL in situ module loader.
48
49 Usage:
50   insitu <map file>  {{ -switch }
51  
52   -f    Specify output file
53   -c    Compression level for data (1-9 where 9 is default)
54  
55   When the output file is not specified, a file in the
56   form of <filename>.situ will be used by instead.
57  
58   Map files are expected to be the same format as provided
59   by DMD.
60 ";
61
62 int main(char[][] args){
63     DefaultRegistry registry = new DefaultRegistry();
64    
65     if(args.length == 1 || args.length > 3){
66         Stdout.format(helpText,auto_build_number).newline;
67         Stdout.format("Supported Object Types:").newline;
68         foreach(char[] ext; registry.getSupportedTypes){
69             Stdout.format("{0} ",ext);
70         }
71         Stdout.newline;
72         return 0;
73     }
74            
75     // determine the output file
76     char[] outputFilename = "";
77     bool filenameOverride = false;
78     char[] filename = "";
79    
80     ubyte compressionLevel = 9;
81        
82     // Configure the parser and parse the command line 
83     ArgParser parser = new ArgParser(delegate uint(char[] value,uint ordinal){
84         if(ordinal > 0) throw new DDLException("Invalid argument {0}",value);
85         filename = value;
86         return value.length;
87     });
88    
89     parser.bind("-", "f",delegate uint(char[] value){
90         filenameOverride = true;
91         outputFilename = value;
92         return value.length;
93     });
94        
95     parser.bind("-", "c",delegate uint(char[] value){
96         char ch = value[0];
97         if(ch < '1' || ch > '9'){
98             throw new Exception("Unknown compression level '" ~ ch ~ "'");
99         }
100         compressionLevel = ch - '1';
101         return 1;
102     });
103    
104     parser.parse(args[1..$]);
105    
106     if(filename == ""){
107         throw new DDLException("No filename specified.");
108     }
109    
110     // get the file
111     FileBuffer inputFile = FileBuffer(filename);       
112        
113     if(outputFilename == ""){
114         outputFilename = inputFile.getPath.toString;       
115     }   
116    
117     // load the .map file and get what we need
118     InSituMapBinary inputBinary = new InSituMapBinary();
119     inputBinary.load(inputFile);
120    
121     debug debugLog("{0} bytes loaded",inputFile.buffer.length);
122     debug debugLog("{0} exports total",inputBinary.getAllSymbols().values.length);
123     if(!filenameOverride){
124         foreach_reverse(split,ch; outputFilename){
125             if(ch == '.'){
126                 outputFilename = outputFilename[0..split] ~ ".situ";
127                 goto filenameOverrideDone;
128             }
129         }
130         // just append by default
131         outputFilename ~= ".situ"; 
132         filenameOverrideDone: {}
133     }
134    
135     FileBuffer outputFile = FileBuffer(outputFilename,null);
136            
137     // commit the data to the lib-style binary
138     InSituLibBinary outputBinary = new InSituLibBinary();
139     outputBinary.setAllSymbols(inputBinary.getAllSymbols());
140     outputBinary.save(outputFile,compressionLevel);
141    
142     outputFile.save();
143
144     return 0;
145 }
Note: See TracBrowser for help on using the browser.