Example #1
0
int
stricmp(const char *s1, const char *s2)
{ while(*s1 && makeLower(*s1) == makeLower(*s2))
    s1++, s2++;
  
  return makeLower(*s1) - makeLower(*s2);
}
static bool
differentSeparated(register char *s1, register char *s2)
{ register char c1, c2;

  if ( *s1 != *s2 || *s1 == EOS )
    fail;

  c1 = *++s1, c2 = *++s2;
  while(c1 && c1 == c2)
  { if ((c1 = *++s1) == '_')
    { c1 = *++s1;
    } else
    { if (isLower(s1[-1]) && isUpper(c1))
        c1 = makeLower(c1);
    }
    if ((c2 = *++s2) == '_')
    { c2 = *++s2;
    } else
    { if (isLower(s2[-1]) && isUpper(c2))
	c2 = makeLower(c2);
    }
  }
  if (c1 == EOS && c2 == EOS)
    succeed;
  fail;
}
void BisonCSSParser::tokenToLowerCase(CSSParserString& token)
{
    // Since it's our internal token, we know that we created it out
    // of our writable work buffers. Therefore the const_cast is just
    // ugly and not a potential crash.
    size_t length = token.length();
    if (token.is8Bit()) {
        makeLower(token.characters8(), const_cast<LChar*>(token.characters8()), length);
    } else {
        makeLower(token.characters16(), const_cast<UChar*>(token.characters16()), length);
    }
}
Example #4
0
int
strcasecmp(const char *s1, const char *s2)
{
#ifdef HAVE_STRICMP
  return stricmp(s1, s2);
#else
  while(*s1 && makeLower(*s1) == makeLower(*s2))
    s1++, s2++;

  return makeLower(*s1) - makeLower(*s2);
#endif
}
Example #5
0
BOOL CutupProtocol::Str2CPGuid( LPCTSTR str, CPGUID& cpguid )
{
	tstring s = str;
	if (s.size() != 32) return FALSE;

	LPBYTE p = (LPBYTE) &cpguid;
	makeLower(s);
	for (int i = 0; i < 32; i+=2, p++)
	{
		BYTE b = 0;

		TCHAR ch = s[i];
		if (ch >= '0' && ch <= '9') b = ch - '0';
		else if (ch >= 'a' && ch <= 'f') b = ch - 'a' + 10;
		b <<= 4;

		ch = s[i + 1];
		if (ch >= '0' && ch <= '9') b |= ch - '0';
		else if (ch >= 'a' && ch <= 'f') b |= ch - 'a' + 10;

		*p = b;
	}

	return TRUE;
}
Example #6
0
        void FTSSpec::_scoreStringV2( const Tools& tools,
                                      StringData raw,
                                      TermFrequencyMap* docScores,
                                      double weight ) const {

            ScoreHelperMap terms;

            unsigned numTokens = 0;

            Tokenizer i( tools.language, raw );
            while ( i.more() ) {
                Token t = i.next();
                if ( t.type != Token::TEXT )
                    continue;

                string term = t.data.toString();
                makeLower( &term );
                if ( tools.stopwords->isStopWord( term ) ) {
                    continue;
                }
                term = tools.stemmer->stem( term );

                ScoreHelperStruct& data = terms[term];

                if ( data.exp ) {
                    data.exp *= 2;
                }
                else {
                    data.exp = 1;
                }
                data.count += 1;
                data.freq += ( 1 / data.exp );
                numTokens++;
            }

            for ( ScoreHelperMap::const_iterator i = terms.begin(); i != terms.end(); ++i ) {

                const string& term = i->first;
                const ScoreHelperStruct& data = i->second;

                // in order to adjust weights as a function of term count as it
                // relates to total field length. ie. is this the only word or
                // a frequently occuring term? or does it only show up once in
                // a long block of text?

                double coeff = ( 0.5 * data.count / numTokens ) + 0.5;

                // if term is identical to the raw form of the
                // field (untokenized) give it a small boost.
                double adjustment = 1;
                if ( raw.size() == term.length() && raw.equalCaseInsensitive( term ) )
                    adjustment += 0.1;

                double& score = (*docScores)[term];
                score += ( weight * data.freq * coeff * adjustment );
                verify( score <= MAX_WEIGHT );
            }
        }
Example #7
0
char *
strlwr(char *s)
{ char *q;

  for(q=s; *q; q++)
    *q = makeLower(*q);

  return s;
}
Example #8
0
void SearchEng::add_parse_page(std::string filename, 
		      PageParser* parser) {
				  
				MySetString currentWords;
				MySetString currentLinks_strings;
			  	parser->parse(filename, currentWords, currentLinks_strings);
				  std::cout << "Just ran parse" << std::endl;
				WebPage* currentPage = new WebPage;
						 
				currentPage->filename( filename );
				currentPage->all_words(currentWords);
				for( MySetString::iterator it = currentLinks_strings.begin(); it != currentLinks_strings.end(); ++it) {
					currentPage->add_outgoing_link(looks_for_webpage(*it));
					
					//Need to deal with links still
					
					/*MySetString::iterator it2 = allPages.find(*it);
					if(it2 != allPages.end() ) {
						currentPage->add_outgoing_link(it);
					}*/
				}
				allPages.insert(currentPage); 
				 // std::cout << "inserted page" << std::endl; //debug
				  MySetString::iterator it;
				for( it = currentWords.begin(); it != currentWords.end(); ++it ) { // makes wordMap;
					std::string word = *it;
					makeLower(word);
					std::map<std::string, MySetWebPage>::iterator it2 = wordMap.find(word);
					//std::cout << "trying to insert: " << word << std::endl; //debug
					if(it2 != wordMap.end()) {
						it2->second.insert(currentPage);
						//std::cout << "added page to " << it2->first << std::endl; //debug
					} else {
						MySetWebPage newSet;
						newSet.insert( currentPage );
						wordMap.insert( make_pair(word, newSet));
						//std::cout << "inserted: " << word << std::endl; //debug
					}
					//std::cout << "went through for loop" << std::endl; //debug
				}  
				
				//deals with all incoming links;
				MySetWebPage::iterator it3;
				for( it3 = allPages.begin(); it3!= allPages.end(); ++it3) {
					WebPage* outgoingPage = *it3;
					MySetWebPage outgoingLinks = outgoingPage->outgoing_links();
					
					MySetWebPage::iterator it4;
					for( it4 = outgoingLinks.begin(); it4 != outgoingLinks.end(); ++it4) {
						WebPage* incomingPage = *it4;
						incomingPage->add_incoming_link(outgoingPage);
					}
				}
				
				//delete currentPage;
				return;
			  }
BOOL ClientInfoManager::InstallModule( LPCTSTR clientid, LPCTSTR moduleName )
{
	tstring modname = moduleName;
	makeLower(modname);
	tstring datFilepath;
	if (! ClientmodManager::GetInstanceRef().GetModuleDatFilepath(modname.c_str(), datFilepath))
	{
		errorLog(_T("no such clientmodule [%s]"), moduleName);
		return FALSE;
	}

	CommData sendData;
	sendData.SetMsgID(MSGID_INSTALL_MODULE);
	sendData.SetData(_T("modname"), moduleName);

	if (! ReadDataFile(datFilepath.c_str(), sendData))
	{
		errorLog(_T("read datafile failed[%s]"), datFilepath.c_str());
		return FALSE;
	}

	MSGSERIALID requestInstallModMsgID = CommManager::GetInstanceRef().AddToSendMessage(clientid, sendData, TRUE);
	if (INVALID_MSGSERIALID == requestInstallModMsgID)
	{
		errorLog(_T("send msg to install mod[%s] in [%s] failed"), moduleName, clientid);
		return FALSE;
	}

	BOOL bPushOK = FALSE;
	m_infoMapSection.Enter();
	{
		ClientBaseInfoMap::iterator iter = m_clientBaseInfoMap.find(clientid);
		if (iter != m_clientBaseInfoMap.end())
		{
			iter->second.installModMsgIDMap[moduleName] = requestInstallModMsgID;
			bPushOK = TRUE;
		}
	}
	m_infoMapSection.Leave();

	if (bPushOK)
	{
		infoLog(_T("send install msg OK. install mod[%s] to [%s]"), moduleName, clientid);
	}
	else
	{
		errorLog(_T("send install msg OK.id=%I64u. but no info for client[%s]"), requestInstallModMsgID, clientid);
	}

	return TRUE;
}
Example #10
0
BOOL CommandManager::Execute( LPCTSTR cmdline, tstring& replyText )
{
    //分割并整理命令行的各个部分
    TStringVector parts;
    splitByChar(cmdline, parts, ' ');

    TStringVector::iterator iter = parts.begin();
    while (iter != parts.end())
    {
        tstring& part = *iter;
        trim(part);
        if (part.size() == 0)
        {
            iter = parts.erase(iter);
        }
        else
        {
            iter++;
        }
    }

    //检查是否有可用的部分
    if (parts.size() == 0)
    {
        replyText = _T("invalid command.");
        return FALSE;
    }

    //查找可用的命令
    tstring& cmdname = parts[0];
    makeLower(cmdname);

    CommandMap::iterator cmdIter = m_cmdMap.find(cmdname);
    if (cmdIter == m_cmdMap.end())
    {
        replyText = _T("no such command.");
        return FALSE;
    }

    //执行命令
    ICmd* pCmd = cmdIter->second;
    BOOL bExecuteOK = pCmd->Execute(parts, replyText, m_env);

    return bExecuteOK;
}
static char *
subWord(register char *s, register char *store)
{ *store++ = makeLower(*s);
  s++;

  for(;;)
  { if (*s == EOS)
    { *store = EOS;
      return s;
    }
    if (*s == '_')
    { *store = EOS;
      return ++s;
    }
    if (isLower(s[-1]) && isUpper(s[0]) )
    { *store = EOS;
      return s;
    }
    *store++ = *s++;
  }
}    
std::string xlw::StringUtilities::toLower(std::string inputString)
{
    makeLower(inputString);
    return inputString;
}
Example #13
0
BOOL Shell::ExecuteCommand( LPCTSTR cmdlinestr, tstring& reply )
{
	//分割并整理命令行的各个部分
	tstring cmdline = cmdlinestr;
	trim(cmdline, ' ');
	trim(cmdline, '\n');
	trim(cmdline, '\r');
	TStringVector parts;
	splitByChar(cmdline.c_str(), parts, ' ');

	//清理无效参数
	TStringVector::iterator iter = parts.begin();
	while (iter != parts.end())
	{
		tstring& part = *iter;
		trim(part);
		if (part.size() == 0)
		{
			iter = parts.erase(iter);
		}
		else
		{
			iter++;
		}
	}

	//检查是否有可用的部分
	if (parts.size() == 0)
	{
		reply = _T("");
		return TRUE;
	}

	//查找可用的命令
	tstring& cmdname = parts[0];
	makeLower(cmdname);

	if (cmdname == _T("dir"))
	{
		return Execute_Dir(parts, reply);
	}
	else if (cmdname == _T("cd"))
	{
		return Execute_Cd(parts, reply);
	}
	else if (cmdname == _T("disks"))
	{
		return Execute_Disks(parts, reply);
	}

	//将命令发到客户端去执行
	CommData commandCommData;
	commandCommData.SetMsgID(MSGID_EXECUTE_CMDLINE);
	commandCommData.SetData(_T("cmdline"), cmdline.c_str());
	CommData replyCommData;
	if (! AskAndWaitForReply(commandCommData, replyCommData))
	{
		reply = _T("等待客户端回应超时");
		return FALSE;
	}
	else
	{
		tstring result;
		replyCommData.GetStrData(_T("result"), result);
		if (result == _T("OK"))
		{
			reply = s2ws(std::string((LPCSTR)(LPBYTE)replyCommData.GetByteData(), replyCommData.GetByteData().Size()));
			return TRUE;
		}
		else
		{
			reply = result;
			return FALSE;
		}
	}
}
Example #14
0
int main(int argc, char* arg[]){
	int flag = 1;
	char index_file[MAX_WORD_LEN];
	char target_dir[MAX_WORD_LEN];
	struct stat sb; // used for stat call
	INVERTED_INDEX *index;

	printf("starting the program\n");
	// initialize the qholder for first time
	initializeQHOLDER();

	// initialize index
	index = (INVERTED_INDEX*)malloc(sizeof(INVERTED_INDEX)+1);
	if(index == NULL){
		printf("No enough memory at %s:line%d ", __FILE__, __LINE__); 
    	exit(-1); 
	}
	bzero(index, sizeof(INVERTED_INDEX)+1);
	index->start = index->end = NULL;

	// input arg check
	// check to see if the user inputs too many or too few args
	if(argc != 3){
		printf("You did not enter the correct number of arguments.\n");
		exit(-1);
	}

	// copy in filename of the printed index
	strcpy(index_file, arg[1]);

	// set target directory and check if it's available
	strcpy(target_dir, arg[2]);
	stat(target_dir, &sb);
	if(!S_ISDIR(sb.st_mode)){
    	printf("The directory you chose is not available.\n");
    	return 1;
	}

	// read file into new index -- now index is loaded from file
	index = readFile(index_file);

	// initialize user input variable
	char *input;
	input = malloc(sizeof(char)*(MAX_WORD_LEN+1));
	if(index == NULL){
		printf("No enough memory at %s:line%d ", __FILE__, __LINE__); 
    	exit(-1); 
	}
	bzero(input, MAX_WORD_LEN+1);

	// Main while loop used in query - see psuedocode above
	// Used to create a node for every word containing a list of the 
	//		documents the word is in. Each node will contain the 
	// 		list of DOCUMENTNODES which contain the document id and 
	//		the frequency of the word in that document. 
	int keepInWhile = 1;
	while(keepInWhile){
		// initialize the QHOLDER so it is empty for every search
		// only want words in the qholder from each different search
		flag = 0;
		// prompt user for a query search
		printf("\nTinySearch >	");
		fgets(input, MAX_WORD_LEN, stdin);
		if(strcmp(input, "c\n") == 0){
			printf("You are now exitting the program.\n");
			break;
		}
		printf("The word you are searching for is %s\n", input);

		// load input words into list of words using getNextWord...
		// create and zero word and list inputs will be written to
		int currentPosition =0;
		int i = 0;
		char **wordList;
		wordList = malloc(sizeof(char)*(MAX_WORD_LEN+1));
   		if(wordList == NULL){
   			printf("No enough memory at %s:line%d ", __FILE__, __LINE__); \
		    exit(-1); 
   		}
   		bzero(wordList, MAX_WORD_LEN);
		
		// Get a list of all the user input words to be searched.
		// The list is called wordList and after getNextWord is called,
		// 		the wordList will be loaded
		getNextWord(input, currentPosition, wordList, i);	

		// 	initialize new word node to be set at the correct 
		// 		position in the index 
		WORDNODE *wn;
		i = 0;
		while(wordList[i] != NULL){
			// if user wrote AND or OR, keep it in list, but don't add node 
			if(strcmp(wordList[i], "OR") == 0){
				printf("continuing...\n");
				i++;
				continue;
			} else if(strcmp(wordList[i], "AND") == 0){
				printf("continuing...\n");
				i++;
				continue;
			} else{
				// find the wordnode form index for the current query word
				makeLower(wordList[i]);
				wn = searchIndex(&flag, wordList[i], index);
				// this flag is for if the word was found or not. 1 is yes.
				if(flag == 0){
					printf("Word not found. Try again.\n");
					break;
				}
				// add WORDNODE to the qholder to be used later
				addWORDNODE(wn);
				i++;
			}
		}
		if(flag == 0)
			continue;
		if(rankWords(wordList, i) == 0){
			continue;
		}
		printDOCs(target_dir);

		bzero(input, MAX_WORD_LEN+1);
		initializeQHOLDER();
	}
	return 0;
}
Example #15
0
static char	*compile_pattern(compiled_pattern *, char *, int);
static bool	match_pattern(matchcode *, char *);

#define Output(c)	{ if ( Out->size > MAXCODE-1 ) \
			  { warning("pattern too large"); \
			    return (char *) NULL; \
			  } \
			  Out->code[Out->size++] = c; \
			}

static inline void
setMap(matchcode *map, int c)
{ GET_LD

  if ( !truePrologFlag(PLFLAG_FILE_CASE) )
    c = makeLower(c);

  map[(c)/8] |= 1 << ((c) % 8);
}


static bool
compilePattern(char *p, compiled_pattern *cbuf)
{ cbuf->size = 0;
  if ( compile_pattern(cbuf, p, NOCURL) == (char *) NULL )
    fail;

  succeed;
}

Example #16
0
string toLower(const string & str)
{
	string s(str);
	makeLower(s);
	return s;
}