Labels and Relative Jumps - NSIS manual

프로그래밍/NSIS 2006/12/22 17:28 게으른 엔지니어
1. Label

Label의 경우 조건문에 의해서 실행되는 흐름을 바꿀때 Label이 붙어 있는 곳으로 보낼 수 있다. 주로 IfErrors, IfFileExists, StrCmp 등의 명령어를 사용할때 많이 사용한다. Label의 경우 지역적으로만 인식되므로 같은 function이나 section 내부에서만 사용할 수 있다. 또한 Label은 -, +, !, $ 또는 0-9 로 시작할 수는 없다. Label 을 사용하는 것은 다음과 같이 한다.

[code type=nsis]
MyLabel:
[/code]

Label의 이름으로 시작할때 만약 '.'으로 시작하면 전역적으로 볼 수 있는 Label이다. 즉 function/section 내부에서 외부로 흐름을 바꿀 수 있다.

2. Relative Jump

Relative Jump는 이름이 말하는 것처럼 현재 위치를 기준으로 몇번째 instruction으로 갈 건지를 결정하는 것이다. +1 은 바로 다음 instruction(일반적인 경우)을 실행하는 것이며, +2는 두 번째 instruction 즉 첫 번째 instruction은 건너 띄고 두 번째 instruction을 실행하는 것이다. 여기서 말하는 instruction 이라는 것은 인스톨러가 실제로 실행될때 실행되는 모든 명령어를 말하는 것이다. MessageBox, Goto, GetDLLVersion, FileRead, SetShellVarContext 등이 예이다. AddSize, Section, SectionGroup, Name, LangString 등은 인스톨러를 컴파일 할 때 실행되기 때문에 instruction이 아니다.

[code type=nsis]
Goto +2
MessageBox MB_OK "You will never ever see this message box"
MessageBox MB_OK "The last message was skipped, this one should be shown."
[/code]

위의 경우 두 번째 MessageBox만 실행이 된다. +2 이므로 첫 번째 instruction(첫 번째에 있는 MessageBox)이 skip되고 두 번째 instruction 인 두 번째에 있는 MessageBox 가 실행이 된다.


[code type=nsis]
# set the name of the installer
outfile "label_jump.exe"

# create a default section.
section

Goto +4
MessageBox MB_OK "The following message will be skipped"
Goto +3
MessageBox MB_OK "You will never ever see this message box"
Goto -3
MessageBox MB_OK "Done"

sectionEnd
[/code]

위의 예제를 실행하면 어떤 메시지가 들어 있는 MessageBox가 나올까...
사용자 삽입 이미지
왼쪽의 MessageBox가 제일 먼저 나온다. 왜 그런지 생각해 보자. section 내부에 제일 먼저 있는 Goto +4를 보면 네 번째 instruction을 실행하라는 명령이다. 현재 위치에서 네 번째 instruction은 Goto -3 이다. 위쪽 방향으로 세 번째 instruction 은 왼쪽에 보이는 메시지 박스이다. 그리고 그 다음 instruction을 보면 Goto +3 이므로 "Done" 이라는 문자열을 가지는 메시지 박스를 출력하게 된다.
사용자 삽입 이미지
NSIS에도 매크로라는게 있는데, 이 매크로는 relative jump가 실행되기 전에 확장되므로 매크로를 포함할 경우에는 주의해서 사용해야 한다. 아래의 예제를 보면 매크로 확장에 의해서 "second macro line" 이라는 문자열을 가지는 MessageBox가 나오게 된다.




[code type=nsis]
!macro relative_jump_test
  MessageBox MB_OK "first macro line"
  MessageBox MB_OK "second macro line"
!macroend

Goto +2
!insertmacro relative_jump_test
[/code]
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://www.cipher.pe.kr/tt/cipher/rss/response/103

댓글+트랙백 ATOM :: http://www.cipher.pe.kr/tt/cipher/atom/response/103

트랙백 주소 :: http://www.cipher.pe.kr/tt/cipher/trackback/103

트랙백 RSS :: http://www.cipher.pe.kr/tt/cipher/rss/trackback/103

트랙백 ATOM :: http://www.cipher.pe.kr/tt/cipher/atom/trackback/103

댓글을 달아 주세요

댓글 RSS 주소 : http://www.cipher.pe.kr/tt/cipher/rss/comment/103
댓글 ATOM 주소 : http://www.cipher.pe.kr/tt/cipher/atom/comment/103
[로그인][오픈아이디란?]