Cyrus Hackford

Tag: Objective-C

아희 해석기 on Mac OS X 제작중……

by Cyrus H. on Mar.22, 2010, under Mac, Made by myself, Objective-C

아희는 한글로 된 난해한 프로그래밍 언어이다.
자세한 사항은 아희 소개 페이지를 참고하기 바란다.

아래는 아직 미완성인 Aheui.m 파일…….

#import <Foundation/Foundation.h>

void printHelp(const char *appPath) {
	printf("%s",[@"아희 해석기 on Mac OS X, 판 0.1.0\n만든이: 키루스 해크포트, 2010년 제작\n\n" UTF8String]);
	printf("%s",[[NSString stringWithFormat:@"사용법: %s [선택지들] <파일 이름>\n\t주어진 아희 스크립트(<파일 이름>)를 해석하고 실행합니다.\n\n선택지들:\n",appPath] UTF8String]);
	printf("%s",[@"\t-h 또는 --help\n\t\t이 도움말을 출력하고 종료합니다.\n" UTF8String]);
	printf("%s",[@"\t-d <파일 이름> 또는 --dump <파일 이름>\n\t\t해석기의 전체 실행 단계를 주어진 <filename>에 덤프합니다.\n" UTF8String]);
}

int main(int argc,const char *argv[]) {
	NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
	BOOL isDumpMode=NO;
	NSString *dumpPath=nil,*scriptPath=nil;
	NSUInteger interpretationResult=0;
	NSFileHandle *dumpFile=nil,*scriptFile=nil;

	if(argc==1) { // 아무 인수도 없으면 걍 종료한다.
		printf("%s",[[NSString stringWithFormat:@"도움말을 보시려면 %s --help를 실행하세요.\n",argv[0]] UTF8String]);

		[pool drain];
		return 0;
	} else {
		// 모든 인수를 NSString化한다. 만약 -help나 -h가 보이면 그 즉시 멈추고 도움말을 출력한 후 종료한다.
		BOOL endApp=NO,helpShowed=NO;
		for(int loopy=1;loopy<argc;) {
			NSString *tmpArg=[NSString stringWithUTF8String:argv[loopy]];
			if([tmpArg isEqualToString:@"-h"]==YES || [tmpArg isEqualToString:@"--help"]==YES) { // 도움말 선택지
				printHelp(argv[0]);
				endApp=helpShowed=YES;
				break;
			} else if([tmpArg isEqualToString:@"-d"]==YES || [tmpArg isEqualToString:@"--dump"]==YES) { // 덤프 선택지
				isDumpMode=YES;
				if(argc==loopy+1) {
					printf("%s",[@"오류: 생성할 덤프 파일의 위치가 주어지지 않았습니다.\n" UTF8String]);
					endApp=YES;
				} else
					dumpPath=[[NSString stringWithUTF8String:argv[loopy+1]] stringByExpandingTildeInPath];
				loopy+=2;
			} else { // 현재(2010년 3월 21일 기준), 아희 표준안에 딱히 인수를 받아들이는 방법이 없으므로 구현하지 않는다. 따라서 이것은 바로 아희 스크립트 파일의 위치! :D
				scriptPath=[[NSString stringWithUTF8String:argv[loopy]] stringByExpandingTildeInPath];
				loopy++;
			}
		}

		if(scriptPath==nil && helpShowed==NO) { // 만약 모든 인수를 점검했는데도 아무 작업이 계획되지 않았다면(==스크립트 파일이 주어지지 않았다면) 에러를 출력한 후 종료한다.
			printf("%s",[@"오류: 아희 스크립트 파일이 주어지지 않았습니다.\n" UTF8String]);
			endApp=YES;
		}

		if(endApp==YES) {
			[pool drain];

			return 0;
		}
	}

	// 미완성.......

	[pool drain];

	return interpretationResult;
}

명령행에서 주어진 인수를 처리하는 NSUserDefaults라는 클래스가 있지만, 어째 내가 원하는 것과는 살짝 다른 것 같아서 인수를 직접 처리하기로 했다.

아……. 초보티 물씬 풍기는 코드여…….

Leave a Comment :, , , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

나는 세벌식을 씁니다!

Hosted by AQUZ