2014-12-24

[PD] searching source file of vanilla

Pd를 쓰다보면 소스를 고치고 싶을 때가 있다. 이 때 바닐라 소스를 보려는 방법이다.

방법은 grep을 사용한다. 리눅스와 맥에서 가능하다. 윈도우 지못미 ㅠㅠ

먼저 소스 디렉토리로 간다.

~$ cd ~/Downloads/pd-0.46-4/src

~/Downloads/pd-0.46-4/src$ grep '"metro"' *.c

설명:

grep:

grep은 파일 속의 텍스트 문구를 찾는 명령어다.

따옴표(' " metro " ')

작은 따옴표(')와 큰따옴표(")의 조합에 주의! metro와 정확히 일치하는 문자열을 찾는다. 따옴표 없이 검색하면 너무 많이 나온다.

*.c

소스코드는 c로 되어있다. c코드 안에서 찾는다는 의미다.

찾은화면

추가내용:

옵션을 -r 을 주면 하위폴더 검색(recursive)가능.

옵션을 -l을 주면 파일명만 표시.

.c가 아닌 .으로만 적으면 모든 확장자파일 검색

예제:

zmoelnig@XXX:~$ cd ~/src/pd/

zmoelnig@XXX:~/src/pd$  $ grep -r -l '"metro"' .

./doc/5.reference/timer-help.pd

./doc/1.manual/x5.htm

./src/x_time.c

zmoelnig@XXX:~/src/pd$

참고:

On 12/23/2014 08:12 PM, Jonghyun Kim wrote:

> thanks for the answer!
>
> I tried to find with grep, but it doesn't work...
>
> *akntk@umi:~/Downloads/pd-0.46-4$ grep '"metro"' *.c*
> *grep: *.c: No such file or directory*

all C-source files (that's all of Pd without the GUI), lives in the
"src" folder.

zmoelnig@XXX:~$ cd ~/src/pd/src/
zmoelnig@XXX:~/src/pd/src$ grep '"metro"' *.c
x_time.c:    metro_class = class_new(gensym("metro"),
(t_newmethod)metro_new,
zmoelnig@XXX:~/src/pd/src$

you could also use grep's "-r" flag to recursively search files in
subdirectories, and the "-l" flag to only show the filename (and not the
line containing the keyword).

zmoelnig@XXX:~$ cd ~/src/pd/
zmoelnig@XXX:~/src/pd$  $ grep -r -l '"metro"' .
./doc/5.reference/timer-help.pd
./doc/1.manual/x5.htm
./src/x_time.c
zmoelnig@XXX:~/src/pd$

obviously there are more files containing "metro" in quotes.
note that i now use '.' as the "file" to search (which means the current
directory; as i do a recursive search, this will search all files in all
subdirectories of the current dir).

you might also want to have a look at the manpage of "grep" to learn
more about it.

$ man grep

gfdsmr
IOhannes