1 #!/usr/bin/env rdmd 2 3 /* Distributed under the Boost Software License, Version 1.0. 4 * (See accompanying file LICENSE_1_0.txt or copy at 5 * http://www.boost.org/LICENSE_1_0.txt) 6 */ 7 8 module catdoc; 9 10 import std.file; 11 import std.getopt; 12 import std.stdio; 13 import std.string; 14 15 int main(string[] args) 16 { 17 if (args.length < 2) 18 { 19 writeln("catdoc: Concatenate Ddoc files 20 Usage: 21 catdoc -o=outputfile sourcefiles... 22 "); 23 return 1; 24 } 25 26 string ofile; 27 getopt(args, "o", &ofile); 28 if (!ofile.ptr) 29 { 30 writeln("catdoc: set output file with -o=filename"); 31 return 1; 32 } 33 if (args.length < 2) 34 { 35 writeln("catdoc: no input files"); 36 return 1; 37 } 38 39 string comment = "Ddoc\n"; 40 string macros; 41 foreach (arg; args[1..$]) 42 { 43 //writeln(arg); 44 string input = cast(string)std.file.read(arg); 45 if (input.length < 4 || input[0..4] != "Ddoc") 46 { writefln("catdoc: %s is not a Ddoc file", arg); 47 return 1; 48 } 49 foreach (i, c; input) 50 { 51 if (c == '\n') 52 { 53 if (i + 8 < input.length && std..string.icmp(input[i + 1 .. i + 8], "Macros:") == 0) 54 { 55 comment ~= input[4 .. i + 1]; 56 if (!macros.ptr) 57 macros = "Macros:\n"; 58 macros ~= input[i + 8 .. $]; 59 goto L1; 60 } 61 } 62 } 63 comment ~= input[4 .. $]; 64 L1: ; 65 } 66 67 std.file.write(ofile, comment ~ macros); 68 69 return 0; 70 }