[Mordor][Mordor] Mordor 6.66 한글화 #2
member photo 방울꽃 0 4,429 0 2004-02-27 12:31:36
근 2달여만에 글을 올리는것 같네요...

오늘 쓸글은 한글 명령어 처리에 대해 쓸 예정입니다.

command1.c 수정

void parse( str, cmnd )
char        *str;
cmd        *cmnd;
{

int        i, j, l, n, m;
char        token[MAX_TOKEN_SIZE];
int        isquote;

        l = n = m = 0;
        j = strlen(str);
        isquote = 0;

        if(j != 0) {
                if(str[j-1] == ' ' || str[j-1] == '.' || str[j-1] == '!' || str[j-1] == '?') {
                        strncpy(cmnd->str[n++], "말", MAX_TOKEN_SIZE-5);
                        cmnd->val[m] = 1L;
                }

                else {
                        i = j;

                        while(i >= 0 && str[i] != ' ')
                                i--;

                        if(i >= 0)
                                str[i] = 0;

                        j = i;
                        i++;

                        strncpy(cmnd->str[n++], &str[i], MAX_TOKEN_SIZE-5);
                        cmnd->val[m] = 1L;
                }
        }

        for(i = 0; i <= j; i++) {
                if (str[i] == ' '  || str[i] == '#' )
                        continue;

                if(str[i] == '\"') {
                        isquote = 1;
                        i++;
                }
                
                l = i;

                if(isquote) {
                        while(str[i] != '\0' && str[i] != '\"') {
                                i++;
                        }

                        if(str[i] == '\"') {
                                str[i] = '\0';
                        }
                }

                else {
                        while(str[i] != '\0' && str[i] != ' ' && str[i] != '#') {
                                i++;
                        }

                        str[i] = '\0';
                }

                strncpy(token, &str[l], MAX_TOKEN_SIZE-1);
                token[MAX_TOKEN_SIZE-1] = 0;

                if(!strlen(token)) {
                        isquote = 0;
                        continue;
                }

                if(isquote) {
                        strncpy(cmnd->str[n], token, MAX_TOKEN_SIZE-5);
                        cmnd->str[n][MAX_TOKEN_SIZE-4] = '\0';
                        cmnd->val[n] = 1L;
                        isquote = 0;
                        n++;
                }

                else {
                        if(n == 0) {
                                strncpy(cmnd->str[n], token, MAX_TOKEN_SIZE-5);
                                cmnd->str[n][MAX_TOKEN_SIZE-4] = '\0';
                                cmnd->val[n] = 1L;
                                n++;
                        }

                        else
                        if(is_number(token) || (token[0] == '-' && is_number(token + 1))) {
                                cmnd->val[MAX(0, n - 1)] = atol(token);
                        }

                        else {
                                strncpy(cmnd->str[n], token, MAX_TOKEN_SIZE-5);
                                cmnd->str[n][MAX_TOKEN_SIZE-4] = '\0';
                                cmnd->val[n] = 1L;
                                n++;
                        }
                }

                if(n >= COMMANDMAX) {
                        break;
                }
        }

        cmnd->num = n;

        return;

}


int process_cmd( fd, cmnd )
int        fd;
cmd        *cmnd;
{

int        match = 0, cmdno = 0, c = 0;
int        current_deep, match_deep = 0;

        if(strlen(cmnd->fullstr) > 200) {
                return(0);
        }

        do {
                if(!strcmp(cmnd->str[0], cmdlist[c].cmdstr)) {
                        match = 1;
                        cmdno = c;
                        break;
                }

                else
                if((current_deep = str_compare(cmnd->str[0], cmdlist[c].cmdstr)) != 0) {
                        match = 1;

                        if(match_deep == 0 || match_deep > current_deep) {
                                cmdno = c;
                                match_deep = current_deep;
                        }
                }

                c++;

        } while(cmdlist[c].cmdno);

        if(cmnd->str[0][0] == '*' && Ply[fd].ply->class != DM) {
                output(fd, "\n그런 명령어는 모르겟습니다.");
                printa(fd, "\n'{노도움말}'을 참고 하세요.");
                return(0);
        }

        else
        if(match == 0 || (cmnd->str[0][0] == '*' && Ply[fd].ply->class > DM)) {
                output(fd, "\n그런 명령어는 모르겟습니다.");
                printa(fd, "\n'{노도움말}'을 참고 하세요.");
                return(0);
        }

        if(cmdlist[cmdno].cmdno < 0)
                return(special_cmd(Ply[fd].ply, 0-cmdlist[cmdno].cmdno, cmnd));
        
        return((*cmdlist[cmdno].cmdfn)(Ply[fd].ply, cmnd));

}


char        cut_paste_chr;


int cut_command( str )
char        *str;
{

int        i;

        for(i = strlen(str)-1; i >= 0; i--) {
                if(str[i]==' ') {
                        break;
                }
        }

        if(i < 0)
                i=0;

        cut_paste_chr = str[i];
        str[i] = 0;

        return i;

}


void paste_command( str,index )
char        *str;
int        index;
{

        str[index] = cut_paste_chr;

}


int str_compare( str1, str2 )
unsigned char        *str1, *str2;
{

int        i = 0;

        while(str1[i] != 0 && str2[i] != 0) {
                if(str1[i] == str2[i] && str1[i+1] == str2[i+1])
                        i += 2;

                else
                if(str1[i] == str2[i] && str1[i] < 128)
                        i++;

                else
                        break;
        }

        if(str1[i] != 0)
                return 0;

        return i;

}

char *cut_space( str )
char        *str;
{

static char        buf[512];
int                i;

        strcpy(buf, str);

        for(i = strlen(buf)-1; i >= 0; i--) {
                if(buf[i] != ' ')
                        break;
        }

        buf[i+1] = 0;

        return buf;

}


int is_number( str )
unsigned char        *str;
{

int        i;

        for(i = 0; i < strlen(str); i++) {
                if(!isdigit(str[i]))
                        return 0;
        }

        return 1;

}


mtype.h 화일을 수정
#define MAX_TOKEN_SIZE  25
0
0Comments
-표시할 내용이 없습니다.-
코멘트를 삭제할 비밀번호를 입력하세요.
비밀번호:
정회원 이상만 코멘트 쓰기가 가능합니다.
총 게시물 11개 / 검색된 게시물: 11개

1

쪽지를 전송하고 있습니다. 잠시 기다려주세요.
쪽지보내기
받는이(ID/닉네임)
내용
쪽지가 도착하였습니다.
쪽지 내용을 읽어오고 있습니다. 잠시 기다려주세요.
--