Esempio n. 1
0
vector<Item*> ItemBank::searchEvents(string keyword) {
	vector<Item*> allEvents;
	vector<Item*> eventsFound;

	allEvents = getAllEvents();

	for (vector<Item*>::iterator iter = allEvents.begin(); iter != allEvents.end(); iter++) {
		if (searchKeyword((*iter)->getTitle(), keyword)) {
			eventsFound.push_back(*iter);
		} else if (searchKeyword((*iter)->getDescription(), keyword)) {
			eventsFound.push_back(*iter);
		} else if (searchKeyword((*iter)->getStartDateInString(), keyword)) {
			eventsFound.push_back(*iter);
		} else if (searchKeyword((*iter)->getEndDateInString(), keyword)) {
			eventsFound.push_back(*iter);
		} else if (searchKeyword((*iter)->getVenue(), keyword)) {
			eventsFound.push_back(*iter);
		} else if (searchKeyword((*iter)->getCategory(), keyword)) {
			eventsFound.push_back(*iter);
		} else if (searchKeyword((*iter)->getPriorityInString(), keyword)) {
			eventsFound.push_back(*iter);
		}
	}

	return eventsFound;
}
Esempio n. 2
0
vector<Item*> ItemBank::searchTasks(string keyword) {
	vector<Item*> allTasks;
	vector<Item*> tasksFound;

	allTasks = getAllTasks();

	for (vector<Item*>::iterator iter = allTasks.begin(); iter != allTasks.end(); iter++) {
		if (searchKeyword((*iter)->getTitle(), keyword)) {
			tasksFound.push_back(*iter);
		} else if (searchKeyword((*iter)->getDescription(), keyword)) {
			tasksFound.push_back(*iter);
		} else if (searchKeyword((*iter)->getVenue(), keyword)) {
			tasksFound.push_back(*iter);
		} else if (searchKeyword((*iter)->getCategory(), keyword)) {
			tasksFound.push_back(*iter);
		} else if (searchKeyword((*iter)->getPriorityInString(), keyword)) {
			tasksFound.push_back(*iter);
		}
	}

	return tasksFound;
}
Esempio n. 3
0
int EBook::hitMultiWord(int maxcnt, const QStringList &words, SearchType stype)
{
    hits.clear();
    if ((stype == SearchKeyWord && !isHaveWordSearch()) ||
        (stype == SearchCrossWord && !isHaveCrossSearch()) )
        return 0;

    if ( maxcnt <= 0 )
        maxcnt = HitsBufferSize;
    int count = 0;
    for (;;) {
        EB_Error_Code ecode;
        if (stype == SearchKeyWord) {
            ecode = searchKeyword(words);
        } else {
            ecode = searchCross(words);
        }
        if (ecode != EB_SUCCESS) {
            break;
        }

        QList <EB_Hit> wrk = hitList(HitsBufferSize);
        if (wrk.count() == 0) {
            return 0;
        }

        foreach(EB_Hit w, wrk) {
            bool same_text = false;
            foreach(EB_Hit h, hits) {
                if (w.text.page == h.text.page &&
                    w.text.offset == h.text.offset) {
                    same_text = true;
                    break;
                }
            }
            if (same_text) continue;

            hits << w;
            count++;
            if (count >= maxcnt) break;
        }

        break;
    }
Esempio n. 4
0
int main(int argc, char* argv[])
{
	//read in file
	char str[100];
	FILE *fp;

	fp=fopen(argv[1],"r");
	if(fp==NULL)
	{
		fprintf(stderr,"Can't open input file!");
		exit(1);
	}

	//LEXICAL ANALYSIS
	int numLines = 0;
	while(fgets(str,MAX_LINE_LEN,fp)!=NULL)
	{
		char* curPos = str;
		while(*curPos != '\n')
		{
			//CASE 1: NUM
			if(isdigit(*curPos))
			{
				tokens[numTokens].type = 0;
				tokens[numTokens].lineNum = numLines;
				tokens[numTokens].lexeme = (char*)malloc(100);	
				extractNum(curPos, tokens[numTokens].lexeme);
				numTokens++;
				continue;
			}

			//CASE 2: KEYWORD / IDENTIFIER / operator AND-OR
			if(isalpha(*curPos))
			{
				//get alphanum token
				char* token = (char*)malloc(100);
				memset(token,'\0',100);
				getToken(curPos,token);

				//keyword case
				if(searchKeyword(token) != -1)
					tokens[numTokens].type = 1;
				else if(searchOperators(token) != -1)
					tokens[numTokens].type = 3;
				//identifier case
				else
					tokens[numTokens].type = 2;

				//add line num
				tokens[numTokens].lineNum = numLines;
			
				//add lexeme
				tokens[numTokens].lexeme = (char*)malloc(100);	
				memcpy(tokens[numTokens].lexeme,token,strlen(token));
			
				numTokens++;
			
				continue;
			}

			//CASE : WHITESPACE
			if(*curPos == ' ' || *curPos == '\t')
				curPos++;
		}
//		char* combined = (char*)malloc(100);
//		memcpy(combined,punctuation,strlen(punctuation));
//		strcat(combined,symbols);

//		char* test = strtok(str,combined);
//		while(test != NULL)
//		{
//			std::cout<<test<<std::endl;
//			test = strtok(NULL,combined);
//		}
	
//		continue;

//		std::cout<<"here\n\n\n"<<std::endl;

		//Examine line char by char
/*		char* curPos = str;
		char* token = (char*)malloc(100);//NULL;
		memset(token,'\0',100);

		getToken(curPos,token);
		while(token != NULL)
		{
			//CASE 1: NUM CASE
			if(isdigit(*token))
			{
				tokens[numTokens].type = 1;
				tokens[numTokens].lineNum = numLines;
				tokens[numTokens].lexeme = (char*)malloc(100);	
				extractNum(token, tokens[numTokens].lexeme);
				numTokens++;
			}

			//CASE 2: KEYWORD CASE
			
			getToken(curPos,token);
		}
*/
/*		
	//	int str_i = 0;
		while(str_i < strlen(str))
		{
			char c = str[str_i];

			//CASE 1: NUMBER
			if(isdigit(c))
			{
				//populate next element of tokens array
				tokens[numTokens].type = 1;
				tokens[numTokens].lineNum = numLines;

				//iterate through str until non-digit char encountered.
				//also iterate through lexeme to populate
				int lex_i = 0;
				while(isdigit(c) && str_i < strlen(str))
				{
					tokens[numTokens].lexeme[lex_i] = c;
				
					lex_i++;
					str_i++;

					c = str[str_i];
				}
			}
			
			//CASE 2: CHAR - always encapsulated by ' '
			if(c == '\'')
			{
				
				str_i++;
				c = str[str_i];
				
			}
			//CASE 3: 
		}
*/
		numLines++;
	}

	fclose(fp);

	printTokens();
	fflush(stdout);
	//END FILE READ	
}
Esempio n. 5
0
/*--------------------------------------------------------------------------*/
int sci_helpbrowser(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrhelpAdr      = NULL;
    int* piAddrkeywordAdr   = NULL;
    int* piAddrfullTextAdr  = NULL;
    int* fullTextAdr        = NULL;

    int nbRow = 0;
    int nbCol = 0;
    char** keywordAdr = NULL;

    int nbRowHelp       = 0;
    int nbColHelp       = 0;
    char** helpAdr      = NULL;
    char** languageAdr  = NULL;
    int ret = 1;

    CheckInputArgument(pvApiCtx, 2, 4);
    CheckOutputArgument(pvApiCtx, 0, 1);

    /* We load SciNotes when calling javahelp because we have no way to know
     * to load it when using Javahelp because it can call SciNotes directly */
    if (!loadedDep)
    {
        loadOnUseClassPath("SciNotes");
        loadedDep = TRUE;
    }

    if (checkInputArgumentType(pvApiCtx, 1, sci_strings))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrhelpAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 1.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddrhelpAdr, &nbRowHelp, &nbColHelp, &helpAdr))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 1);
            return 1;
        }
    }
    else if (checkInputArgumentType(pvApiCtx, 1, sci_matrix))
    {
        helpAdr = NULL; /* No toolboxes installed */
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: Matrix of strings expected.\n"), fname, 1);
        return FALSE;
    }

    if (nbInputArgument(pvApiCtx) == 2)
    {
        if ((checkInputArgumentType(pvApiCtx, 2, sci_strings)))
        {
            int* piAddrlanguageAdr = NULL;
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrlanguageAdr);
            if (sciErr.iErr)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 2.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrlanguageAdr, &nbRow, &nbCol, &languageAdr))
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 2);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedMatrixOfString(nbRow, nbCol, languageAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 2);
                return FALSE;
            }
        }
        else
        {
            if (helpAdr)
            {
                freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
            }
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2);
            return FALSE;
        }

        ret = launchHelpBrowser(helpAdr, nbRowHelp * nbColHelp, languageAdr[0]);

        if (helpAdr)
        {
            freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
        }
        freeAllocatedMatrixOfString(nbRow, nbCol, languageAdr);
    }
    else if (nbInputArgument(pvApiCtx) == 4)
    {
        if ((checkInputArgumentType(pvApiCtx, 2, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrkeywordAdr);
            if (sciErr.iErr)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }

                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 2.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrkeywordAdr, &nbRow, &nbCol, &keywordAdr))
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }

                Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 2);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedMatrixOfString(nbRow, nbCol, keywordAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 2);
                return FALSE;
            }
        }
        else
        {
            if (helpAdr)
            {
                freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
            }
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2);
            return FALSE;
        }

        if ((checkInputArgumentType(pvApiCtx, 3, sci_strings)))
        {
            int* piAddrlanguageAdr = NULL;
            sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrlanguageAdr);
            if (sciErr.iErr)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 3.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrlanguageAdr, &nbRow, &nbCol, &languageAdr))
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 3);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                freeAllocatedMatrixOfString(nbRow, nbCol, languageAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 3);
                return FALSE;
            }
        }
        else
        {
            if (helpAdr)
            {
                freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
            }
            freeAllocatedSingleString(*keywordAdr);
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 3);
            return FALSE;
        }

        if ((checkInputArgumentType(pvApiCtx, 4, sci_boolean)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddrfullTextAdr);
            if (sciErr.iErr)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                freeAllocatedSingleString(*languageAdr);
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of boolean at position 4.
            sciErr = getMatrixOfBoolean(pvApiCtx, piAddrfullTextAdr, &nbRow, &nbCol, &fullTextAdr);
            if (sciErr.iErr)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                freeAllocatedSingleString(*languageAdr);
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: Boolean matrix expected.\n"), fname, 4);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                freeAllocatedSingleString(*languageAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 4);
                return FALSE;
            }
        }
        else
        {
            if (helpAdr)
            {
                freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
            }
            freeAllocatedSingleString(*keywordAdr);
            freeAllocatedSingleString(*languageAdr);
            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 4);
            return FALSE;
        }

        ret = searchKeyword(helpAdr, nbRowHelp * nbColHelp, keywordAdr[0], languageAdr[0], *fullTextAdr == 1);

        if (helpAdr)
        {
            freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
        }

        freeAllocatedSingleString(*keywordAdr);
        freeAllocatedSingleString(*languageAdr);
    }
    else
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d or %d expected.\n"), fname, 2, 4);
        return FALSE;
    }

    if (ret == 0)
    {
        return FALSE;
    }

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);
    return TRUE;
}
Esempio n. 6
0
types::Function::ReturnValue sci_helpbrowser(types::typed_list &in, int _iRetCount, types::typed_list& out)
{
    int iHelpAdrSize    = 0;
    char **helpAdr      = NULL;
    char **languageAdr  = NULL;

    if (_iRetCount > 1)
    {
        Scierror(78, _("%s:  Wrong number of output argument(s): %d to %d expected."), "helpbrowser", 0, 1);
        return types::Function::Error;
    }
    switch (in.size())
    {
        case 4:
            if (!(in[3]->isBool() == true && in[3]->getAs<types::Bool>()->isScalar() == true))
            {
                Scierror(999, _("%s:  Wrong type for input argument #%d: A boolean expected."), "helpbrowser", 4);
                return types::Function::Error;
            }
            if (!(in[2]->isString() == true && in[2]->getAs<types::String>()->isScalar() == true))
            {
                Scierror(999, _("%s:  Wrong type for input argument #%d: string expected."), "helpbrowser", 3);
                return types::Function::Error;
            }
        case 2:
            // Second argument must be String or at least [].
            if (!(in[1]->isString() == true && in[1]->getAs<types::String>()->isScalar() == true))
            {
                Scierror(999, _("%s:  Wrong type for input argument #%d: string expected."), "helpbrowser", 2);
                return types::Function::Error;
            }
            // Matrix of String or [] allowed.
            if ( !( (in[0]->isString() == true)
                || (in[0]->isDouble() == true && in[0]->getAs<types::Double>()->isEmpty() == true)))
            {
                Scierror(999, _("%s:  Wrong type for input argument #%d: string expected."), "helpbrowser", 1);
                return types::Function::Error;
            }
            break;
        default:
            Scierror(77, _("%s:  Wrong number of input argument(s): %d to %d expected."), "helpbrowser", 2, 4);
            return types::Function::Error;
    }

    /* We load SciNotes when calling javahelp because we have no way to know
     * to load it when using Javahelp because it can call SciNotes directly */
    if (!loadedDep)
    {
        loadOnUseClassPath("SciNotes");
        loadedDep = TRUE;
    }

    if (in[0]->isString() == true)
    {
        types::String *pInHelpAdr = in[0]->getAs<types::String>();
        helpAdr = new char*[pInHelpAdr->getSize()];
        iHelpAdrSize = pInHelpAdr->getSize();

        for (int i = 0 ; i < pInHelpAdr->getSize() ; ++i)
        {
            helpAdr[i] = wide_string_to_UTF8(pInHelpAdr->get(i));
        }
    }

    char* pstLang   = NULL;
    char* pstKey    = NULL;
    if (in.size() == 2)
    {
        pstLang = wide_string_to_UTF8(in[1]->getAs<types::String>()->get(0));
        launchHelpBrowser(helpAdr, iHelpAdrSize, pstLang);
    }

    if (in.size() == 4)
    {
        pstLang = wide_string_to_UTF8(in[2]->getAs<types::String>()->get(0));
        pstKey = wide_string_to_UTF8(in[1]->getAs<types::String>()->get(0));
        int iFullText = in[3]->getAs<types::Bool>()->get(0);
        searchKeyword(helpAdr, iHelpAdrSize, pstKey, pstLang, (BOOL) iFullText);
    }

    if (pstLang != NULL)
    {
        FREE(pstLang);
    }

    if (pstKey != NULL)
    {
        FREE(pstKey);
    }

    if (helpAdr != NULL) /* No toolboxes loaded */
    {
        for (int i = 0 ; i < iHelpAdrSize ; i++)
        {
            FREE(helpAdr[i]);
        }
        delete[] helpAdr;
    }

    return types::Function::OK;
}