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