예제 #1
0
파일: Substitu.cpp 프로젝트: konelav/jmc
void do_one_sub(wchar_t *line)
{
  struct listnode *ln;
  ln=common_subs;

    while((ln=ln->next)) 
        if(check_one_action(line,ln->left)) {
            // check its gag 
            if ( !wcscmp(ln->right, L".") ) {
				wcscpy(line, L".");
                return;
            }
            BOOL bAnchored = FALSE;
            wchar_t pattern[BUFFER_SIZE],SubStr[BUFFER_SIZE],result[BUFFER_SIZE];
            prepare_actionalias(ln->left , pattern, sizeof(pattern)/sizeof(wchar_t));
            prepare_actionalias(ln->right , SubStr, sizeof(SubStr)/sizeof(wchar_t));
            int pattern_len = wcslen(pattern);
			int sublen = wcslen(SubStr);
            if ( pattern_len == 0 ) 
                continue;

            result[0] = 0;
            wchar_t* line1 = line;
            wchar_t* ptr, *res = result;
			int rest = sizeof(result)/sizeof(wchar_t) - 1;
            while ( (ptr = wcsstr(line1, pattern)) != NULL ) {
				int to_copy = ptr - line1;
				if (to_copy > rest)
					to_copy = rest;
                wcsncpy(res, line1, to_copy );
				res[to_copy] = L'\0';
                res += to_copy;
				rest -= to_copy;

				to_copy = sublen;
				if (to_copy > rest)
					to_copy = rest;
                wcsncpy(res, SubStr, to_copy);
				res[to_copy] = L'\0';
                res += to_copy;
				rest -= to_copy;

                line1 += pattern_len + (ptr-line1);
            
            }
            if ( *line1 ) {
                wcscat(result, line1);
            }
            wcscpy(line, result);
            if(!bMultiSub)
			 return;
        
        }
}
예제 #2
0
파일: ttcoreex.cpp 프로젝트: konelav/jmc
void output_command(wchar_t* arg)
{ 
    wchar_t left[BUFFER_SIZE], right[BUFFER_SIZE];
    wchar_t result[BUFFER_SIZE], strng[BUFFER_SIZE];
    
    arg=get_arg_in_braces(arg,left,WITH_SPACES,sizeof(left)/sizeof(wchar_t)-1);
    arg=get_arg_in_braces(arg,right,WITH_SPACES,sizeof(right)/sizeof(wchar_t)-1);

    if ( !right[0] ) {  // no colors
        prepare_actionalias(left,strng, sizeof(strng)/sizeof(wchar_t)); 
    } else {
		prepare_actionalias(right,result, sizeof(result)/sizeof(wchar_t)); 
        add_codes(result, strng, left);
    }

    tintin_puts3(strng, 0);
}
예제 #3
0
파일: Substitu.cpp 프로젝트: Liscar/jmc
void do_one_sub(char *line)
{
  struct listnode *ln;
  ln=common_subs;

    while((ln=ln->next)) 
        if(check_one_action(line,ln->left)) {
            // check its gag 
            if ( *ln->right == '.' && *(ln->right+1) == 0 ) {
                line[0] = '.';
                line[1] = 0;
                return;
            }
            BOOL bAnchored = FALSE;
            char pattern[BUFFER_SIZE],SubStr[BUFFER_SIZE],result[BUFFER_SIZE];
            prepare_actionalias(ln->left , pattern);
            prepare_actionalias(ln->right , SubStr);
            int pattern_len = strlen(pattern);
            if ( pattern_len == 0 ) 
                continue;

            result[0] = 0;
            char* line1 = line;
            char* ptr, *res = result;
            while ( (ptr = strstr(line1, pattern)) != NULL ) {
                strncpy(res, line1, ptr-line1 );
                res += ptr-line1;
                strcpy(res, SubStr);
                res += strlen(res);
                line1 += pattern_len + (ptr-line1);
            
            }
            if ( *line1 ) {
                strcat(result, line1);
            }
            strcpy(line, result);
            if(!bMultiSub)
			 return;
        
        }
}
예제 #4
0
파일: Ivars.cpp 프로젝트: konelav/jmc
void match_command(wchar_t *arg) 
{
	wchar_t pattern[BUFFER_SIZE], 
		 strng[BUFFER_SIZE], 
		 if_then[BUFFER_SIZE], 
		 if_else[BUFFER_SIZE],
		 temp[BUFFER_SIZE];
	
	CPCRE re;

	arg = get_arg_in_braces(arg,temp,STOP_SPACES,sizeof(temp)/sizeof(wchar_t)-1);
	prepare_actionalias(temp, pattern, sizeof(pattern)/sizeof(wchar_t)-1);

    BOOL i_flag = FALSE, m_flag = FALSE, g_flag = FALSE;
	std::wstring regexp = pattern;

    if ( *pattern == L'/' ) {
		regexp = (wchar_t*)pattern + 1;
        
        int size = regexp.size();
		
		for (int i = size - 1; i >= 0; i--) {
			if (regexp[i] == L'i') {
				size--;
				i_flag = TRUE;
			} else if (regexp[i] == L'm') {
				size--;
				m_flag = TRUE;
			} else if (regexp[i] == L'g') {
				size--;
				g_flag = TRUE;
			} else if (regexp[i] == L'/') {
				size--;
				break;
			} else {
				size = regexp.size();
				i_flag = m_flag = g_flag = FALSE;
				break;
			}
		}
		regexp.resize(size);
    }

	if (!re.SetSource(regexp, m_flag, i_flag)) {
		return;
	}

	arg = get_arg_in_braces(arg,temp,STOP_SPACES,sizeof(temp)/sizeof(wchar_t)-1);
	prepare_actionalias(temp, strng, sizeof(strng)/sizeof(wchar_t)-1);
 
	arg = get_arg_in_braces(arg,if_then,WITH_SPACES,sizeof(if_then)/sizeof(wchar_t)-1);

	arg = get_arg_in_braces(arg,if_else,WITH_SPACES,sizeof(if_else)/sizeof(wchar_t)-1);

	int offset = 0;
    int offsets[33];

	bool no_match = true;
	wchar_t *test = (wchar_t*)strng;
	int test_len = wcslen(test);

	for (;;) {
		int captured = pcre16_exec(re.m_pPcre, re.m_pExtra, test, test_len, offset, 0, offsets, 33);
		if (captured <= 0)
			break;

		no_match = false;
		
		int i;
		for (i = 0; i < 10; i++) 
			vars[i][0] = 0;
		for (i = 1; i < captured; i++) {
			if (offsets[i*2] >= 0) {
				int size = offsets[i*2 + 1] - offsets[i*2];
				wcsncpy(vars[i-1], test + offsets[i*2], size);
				*(vars[i-1]+size) = L'\0'; 
			}
		}
		prepare_actionalias(if_then, temp, sizeof(temp)/sizeof(wchar_t)-1);
		parse_input(temp, g_flag);

		offset = offsets[1];

		if (!g_flag)
			break;
	}

	if (no_match)
		parse_input(if_else);
}
예제 #5
0
파일: Parse.cpp 프로젝트: Liscar/jmc
void parse_input(char *input)
{
    char command[BUFFER_SIZE], arg[BUFFER_SIZE], result[BUFFER_SIZE];
    char *input2;

    bPasswordEcho = TRUE;

    if(*input=='\0') {
        write_line_mud("");
        return ; 
    }

    if ( verbatim  && *input == cCommandChar && *(input+1) == 'v' ) {// check verbatim command
        char command[BUFFER_SIZE];
        char* input2=get_arg_stop_spaces(input+1, command);
        if(command[0] == 'v' && is_abrev(command, "verbatim")){
            char arg[BUFFER_SIZE];
            get_arg_all(input2, arg);
            verbatim_command(arg);
            return;
        }
    }
    
    if (verbatim ) {
        write_line_mud(input);
        return ;
    }
  
    if (*input==verbatim_char) {
        input++;
        write_line_mud(input);
        return ;
    }
    substitute_myvars(input, result);
    input2=result;
    while(*input2) {
//* en:colon
        // if(*input2==';')
        if(*input2==cCommandDelimiter||(bColon && *input2==';')&&*(input2-1)!='\\')
            input2++;
//*/en
        input2=get_arg_stop_spaces(input2, command);
        input2=get_arg_all(input2, arg);

//* en:prefix
		if(s_prefix[0] && command[0] != cCommandChar)
		{
			char p_command[BUFFER_SIZE];
			strcpy(p_command,command);
			strcat(p_command," ");
			strcat(p_command,arg);
			strcpy(command,s_prefix);
			strcpy(arg,p_command);
		}
//*/en
        if(*command==cCommandChar) 
		{
			if (bDisplayCommands) {
				// output command in square brackets
				char strInputCommand[BUFFER_SIZE], strOutputBuffer[BUFFER_SIZE];
				strcpy(strInputCommand, "\n[");
				strcat(strInputCommand, command);
				if (*arg != '\0') {
					strcat(strInputCommand, " ");
					strcat(strInputCommand, arg);
				}
				strcat(strInputCommand, "]");

				add_codes(strInputCommand, strOutputBuffer, "brown", TRUE);

				tintin_puts2(strOutputBuffer);

				if (hLogFile.is_open()) {
					log(strInputCommand);
				}
			}

            parse_tintin_command(command+1, arg);
		}
//* en:comments
        else if(*command==cCommentChar);
//*/en
        else
		{
//* en:waits
          if(iWaitState>0)
		  {
		   char *ptr1,*ptr2;
     	   for(ptr1=mQueue;*ptr1&&*ptr1!='\0';ptr1++);
	       *ptr1++=cCommandDelimiter;
           for(ptr2=command;*ptr2&&*ptr2!='\0';ptr2++,ptr1++)
             *ptr1=*ptr2;
		   if(*arg)
			   *ptr1++=' ';
           for(ptr2=arg;*ptr2&&*ptr2!='\0';ptr2++,ptr1++)
             *ptr1=*ptr2;
		   *ptr1++='\0';
		   continue;
		  }
//* en

          ALIAS_INDEX ind;
			
		  if( (ind=AliasList.find(command)) != AliasList.end() && ind->second->m_pGroup->m_bEnabled ) 
		  {
            
            int i;
            char *cpsource, *cpsource2, newcommand[BUFFER_SIZE], end;

            strcpy(vars[0], arg);

            for(i=1, cpsource=arg; i<10; i++) 
			{
                /* Next lines CHANGED to allow argument grouping with aliases */
                while (*cpsource == ' ')
                    cpsource++;
                end = (*cpsource == '{') ? '}' : ' ';
                cpsource = (*cpsource == '{') ? cpsource+1 : cpsource;
                for(cpsource2=cpsource; *cpsource2 && *cpsource2!=end; cpsource2++);
                strncpy(vars[i], cpsource, cpsource2-cpsource);
                *(vars[i]+(cpsource2-cpsource))='\0';
                cpsource=(*cpsource2) ? cpsource2+1 : cpsource2;
            }
            ALIAS* pal = ind->second;
            prepare_actionalias((char*)pal->m_strRight.data(), newcommand); 
            if(!strcmp(pal->m_strRight.data(), newcommand) && *arg) 
			{
                strcat(newcommand, " "); 
                strcat(newcommand, arg);
            }

            parse_input(newcommand);
		  }
          else 
		   if(speedwalk && !*arg && is_speedwalk_dirs(command))
            do_speedwalk(command);
           else 
		   {
                get_arg_with_spaces(arg,arg);
                write_com_arg_mud(command, arg);
           }
		}
    }
    return;
}