|
Revision 432, 1.4 kB
(checked in by BCS, 2 years ago)
|
moved a #line
|
| Line | |
|---|
| 1 |
module lines; |
|---|
| 2 |
import std.conv; |
|---|
| 3 |
import std.stdio; |
|---|
| 4 |
import std.stream; |
|---|
| 5 |
import std.regexp; |
|---|
| 6 |
|
|---|
| 7 |
enum Act |
|---|
| 8 |
{ |
|---|
| 9 |
Print, |
|---|
| 10 |
Line, |
|---|
| 11 |
} |
|---|
| 12 |
|
|---|
| 13 |
void main(char[][] args) |
|---|
| 14 |
{ |
|---|
| 15 |
Act act = Act.Print; |
|---|
| 16 |
if(args.length < 4) |
|---|
| 17 |
{ |
|---|
| 18 |
writef("Usage: %s infile trapName trapLine [ -Print | -Line | ]\n",args[0]); |
|---|
| 19 |
return; |
|---|
| 20 |
} |
|---|
| 21 |
foreach(arg;args[4..$]) |
|---|
| 22 |
{ |
|---|
| 23 |
switch(arg) |
|---|
| 24 |
{ |
|---|
| 25 |
case "-print": act = Act.Print; break; |
|---|
| 26 |
case "-line": act = Act.Line; break; |
|---|
| 27 |
} |
|---|
| 28 |
} |
|---|
| 29 |
|
|---|
| 30 |
char[] trapName = args[2]; |
|---|
| 31 |
int trapLine = toInt(args[3]); |
|---|
| 32 |
|
|---|
| 33 |
char[] name = args[1]; |
|---|
| 34 |
int lineNum = 1; |
|---|
| 35 |
|
|---|
| 36 |
char[] realName = args[1]; |
|---|
| 37 |
int realLine = 1; |
|---|
| 38 |
|
|---|
| 39 |
static const char[] prefix = "#line"; |
|---|
| 40 |
|
|---|
| 41 |
foreach(char[] line; new File(name)) |
|---|
| 42 |
{ |
|---|
| 43 |
if(line.length > prefix.length && line[0..prefix.length] == prefix) |
|---|
| 44 |
{ |
|---|
| 45 |
auto rex = search(line, `#line\s+([0-9]+)\s+"([\w.]+)"`); |
|---|
| 46 |
if(rex is null) |
|---|
| 47 |
{ |
|---|
| 48 |
writef("Error %s(%d)", args[1],realLine); |
|---|
| 49 |
return; |
|---|
| 50 |
} |
|---|
| 51 |
//writef("wow %s %s\n",rex.match(1), rex.match(2)); |
|---|
| 52 |
lineNum = toInt(rex.match(1)); |
|---|
| 53 |
name = rex.match(2).dup; |
|---|
| 54 |
} |
|---|
| 55 |
else |
|---|
| 56 |
{ |
|---|
| 57 |
//writef("%s / %s %s / %s\n", name,trapName, lineNum,trapLine); |
|---|
| 58 |
if(lineNum == trapLine && name == trapName) |
|---|
| 59 |
switch(act) |
|---|
| 60 |
{ |
|---|
| 61 |
case Act.Print: writef("%s\n", line); break; |
|---|
| 62 |
case Act.Line: writef("%s(%d)\n",realName,realLine); |
|---|
| 63 |
} |
|---|
| 64 |
lineNum++; |
|---|
| 65 |
} |
|---|
| 66 |
realLine++; |
|---|
| 67 |
} |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
#line 2 "bob.d" |
|---|
| 71 |
/* |
|---|
| 72 |
|
|---|
| 73 |
line 4 |
|---|
| 74 |
line 5 |
|---|
| 75 |
*/ |
|---|