#! /usr/bin/env perl
use strict;
use warnings;
my $prev_return;
while (<>) {
# assume letter in first column introduces a function return type
if (my($return_type) = /^([^\W\d]\w*)/) {
if ($return_type eq "void" && defined $prev_return) {
print $prev_return;
}
undef $prev_return; # reset after each function definition
}
elsif (/\\return\b/) {
$prev_return = "$ARGV:$.: $_";
}
}
continue {
close ARGV if eof; # reset $. at the end of each named file
}
참고 : 패턴 [^\W\d]
사용 숫자가 아닌 "단어 문자"인 double-negative technique은 즉, 문자와 밑줄입니다.
샘플 출력 :
$ cat file.c
/*!
* \brief The foo function
* \return OK if successful, ERROR otherwise
*/
void foo(void)
{
...
}
\return fdsklj
void bar(void)
void baz
$ ./doxygen-return-void file.c
file.c:3: * \return OK if successful, ERROR otherwise
file.c:10: \return fdsklj
펄의 <>
, 또한 다이아몬드 연산자로 알려진, 쉽게 유닉스 스타일의 필터를 작성합니다. 즉, 원하는만큼 경로를 지정할 수 있습니다.
$ ./doxygen-return-void file.c file.c
file.c:3: * \return OK if successful, ERROR otherwise
file.c:10: \return fdsklj
file.c:3: * \return OK if successful, ERROR otherwise
file.c:10: \return fdsklj
위의 프로그램도 표준 입력을 사용하지만 출력은별로 유용하지 않습니다.
$ cat file.c | ./doxygen-return-void
-:3: * \return OK if successful, ERROR otherwise
-:10: \return fdsklj
내 질문에 잘못된 점을 자세히 설명해 주시겠습니까? – Jens