开发者

Using SED to transform the output from a TMS320C55x compiler for Visual Studio

I am trying to get SED to transform the output from a TMS320C55x compiler so that it is parsed correctly by Visual Studio (so that when you click an error/warning it jumps to the location in the source. I have done this successfully with other compilers, but do not use SED often enough for 开发者_高级运维this to be painless, and this time it has defeated me.

The compiler output is of the form:

"<file>", line <line>: <error|warning> <id>: <text>

for example:

"ImageBuffer.c", line 21: error #20: identifier "p" is undefined

And I need it transformed to:

<file>(<line>) : <error|warning> <id>: <text>

so for the example above:

ImageBuffer.c(2) : error #20: identifier "p" is undefined

The critical thing is the () part.

Thanks.


I can get that output by using:

c:\src>echo "ImageBuffer.c", line 21: error #20: identifier "p" is undefined
    | sed -e "s/\"//" -e "s/\", line /(/" -e "s/:/) :/"
ImageBuffer.c(21) : error #20: identifier "p" is undefined

I'm having to escape the " characters because I'm doing it from cmd.exe but you can use them unescaped in a more UNIXy environment if you just use single quotes to surround the sed commands.

The individual sed commands:

  • "s/\"//" gets rid of the starting quote from the file name.
  • "s/\", line /(/" gets rid of the ending quote from the file name and replaces the text between file name and line number with the opening parenthesis before the line number.
  • "s/:/) :/" puts the closing parenthesis after the line number after removing some other unnecessary text.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜