コード例 #1
0
ファイル: fts_matcher.cpp プロジェクト: Cassie90/mongo
        /*
         * Checks if any of the negTerms is in the tokenized string
         * @param raw, the raw string to be tokenized
         */
        bool FTSMatcher::_hasNegativeTerm_string( const string& raw ) const {

            Tokenizer i( _query.getLanguage(), raw );
            while ( i.more() ) {
                Token t = i.next();
                if ( t.type != Token::TEXT )
                    continue;
                string word = tolowerString( _stemmer.stem( t.data ) );
                if ( _query.getNegatedTerms().count( word ) > 0 )
                    return true;
            }
            return false;
        }
コード例 #2
0
ファイル: klicknmenu.c プロジェクト: seokbeomKim/klicknmenu
/* Read configuration file and init menu entries. */
extern void 
initConfig(FILE* fp)
{
	char   buf[BUFSIZE];
	char*  pch;
	bool   init_menu = false; /* flag for representing to read entry nodes( name, command, xpm path ) */
	
	/* initialize global value as minus, NULL */
	menu_width   = -1;
	menu_height  = -1;
	menu_padding = -1;
	border_width = -1;
	entry_height = -1;
	border_color = NULL;
	bgColor      = NULL;
	fgColor      = NULL;
	fontname     = NULL;
	focus_bgColor= NULL;
	focus_fgColor= NULL;
	
	/* setting global variation from configuration file */
	while( fgets(buf, BUFSIZE, fp) > 0 ) {
                /* start to tokenize the string */
                pch = strtok( buf, TOKEN_VALUES );

		while ( pch != NULL ) {
			/* make string from configuration file be lower */
			tolowerString(pch);


			if( ISOPTION(OPTION_MENUWIDTH) ) {
				pch = strtok( NULL, TOKEN_VALUES );
				COPY_INTVALUE(menu_width)
			}
			else if( ISOPTION(OPTION_MENUHEIGHT)) {
				pch = strtok( NULL, TOKEN_VALUES );
				COPY_INTVALUE(menu_height)
			}
			else if( ISOPTION(OPTION_MENUPADDING)) {
				pch = strtok( NULL, TOKEN_VALUES );
				COPY_INTVALUE(menu_padding)
			}
			else if( ISOPTION(OPTION_BORDERWIDTH)) {
コード例 #3
0
void
userInputTask(void* userData)
{
    char inputBuffer[100];
    char cmdBuffer[CMD_BUFFER_SIZE];
    command_t* command = (command_t*)xme_hal_mem_alloc(sizeof(command_t));

    XME_UNUSED_PARAMETER(userData);

    XME_LOG
    (
        XME_LOG_ALWAYS,
        "\nEnter command (to print help type \"help\" without quotes):\n>"
    );
    XME_CHECK
    (
        inputBuffer == fgets(inputBuffer, sizeof(inputBuffer), stdin),
        XME_CHECK_RVAL_VOID
    );

#ifdef _MSC_VER
    (void)sscanf_s(inputBuffer, "%" CMD_STRLEN_STRING "s", cmdBuffer, CMD_BUFFER_SIZE);
#else
    (void)sscanf(inputBuffer, "%" CMD_STRLEN_STRING "s", cmdBuffer);
#endif

    tolowerString(cmdBuffer, cmdBuffer, CMD_BUFFER_SIZE);

    // TODO:
    // - Allow nodeName instead of nodeID (add "subscriberNode" 4099)
    // - Allow componentTypeName instead of componentType (add 2 "subscriber")

    if (0 == strcmp(cmdBuffer, BUILD_STRING))
    {
        xme_core_node_nodeId_t nodeID;
        xme_core_componentType_t componentType;

#ifdef _MSC_VER
        (void)sscanf_s(inputBuffer, BUILD_STRING " %d %d", &nodeID, &componentType);
#else
        (void)sscanf(inputBuffer, BUILD_STRING " %d %d", (int*)&nodeID, (int*)&componentType);
#endif
        xme_core_nodeMgr_compRep_cancelBuild(builder);

        builder = xme_core_nodeMgr_compRep_createBuilder(nodeID, componentType);

        return;
    }
    else if (0 == strcmp(cmdBuffer, SET_QUEUE_SIZE_STRING))
    {
        uint32_t portTypeID;
        uint32_t queueSize;

#ifdef _MSC_VER
        (void)sscanf_s(inputBuffer, SET_QUEUE_SIZE_STRING " %" PRIu32 " %" PRIu32, &portTypeID, &queueSize);
#else
        (void)sscanf(inputBuffer, SET_QUEUE_SIZE_STRING " %" PRIu32 " %" PRIu32, &portTypeID, &queueSize);
#endif

        XME_CHECK_MSG(queueSize <= UCHAR_MAX, XME_CHECK_RVAL_VOID, XME_LOG_ERROR, "Maximum queue size is 255.\n");

        xme_core_nodeMgr_compRep_builderSetQueueSize(builder, portTypeID, (uint8_t)queueSize);

        return;
    }
    else if (0 == strcmp(cmdBuffer, SET_EXECUTION_PERIOD_STRING))
    {
        uint32_t functionTypeID;
        xme_hal_time_timeInterval_t execPeriod;

#ifdef _MSC_VER
        (void)sscanf_s(inputBuffer, SET_EXECUTION_PERIOD_STRING " %" PRIu32 " %" PRIu64, &functionTypeID, (uint64_t*)&execPeriod);
#else
        (void)sscanf(inputBuffer, SET_EXECUTION_PERIOD_STRING " %" PRIu32 " %" PRIu64, &functionTypeID, (uint64_t*)&execPeriod);
#endif
        xme_core_nodeMgr_compRep_builderSetExecutionPeriod(builder, functionTypeID, execPeriod);

        return;
    }
    else if (0 == strcmp(cmdBuffer, SET_INITIALIZATION_STRING_STRING))
    {
        char* initializationString;
        size_t len = xme_hal_safeString_strnlen(inputBuffer, sizeof(inputBuffer));
        if (inputBuffer[len-1] == '\n')
        {
            inputBuffer[len-1] = 0;
        }
        initializationString = &inputBuffer[strlen(SET_INITIALIZATION_STRING_STRING)+1];
        xme_core_nodeMgr_compRep_builderSetInitializationString(builder, initializationString);

        return;
    }
    else if (0 == strcmp(cmdBuffer, COMMIT_STRING))
    {
        xme_status_t status;
        xme_core_nodeMgr_compRep_componentHandle_t componentHandle;

        status = xme_core_nodeMgr_compRep_build(builder, &componentHandle);
        builder = NULL;
        XME_CHECK_MSG(XME_STATUS_SUCCESS == status, XME_CHECK_RVAL_VOID, XME_LOG_ERROR, "Command could not be executed.\n");

        command->commandType = ADD;
        command->commandData.addComponent.componentHandle = componentHandle;
    }
    else if (0 == strcmp(cmdBuffer, ADD_STRING))
    {
        xme_status_t status;
        xme_core_node_nodeId_t nodeID;
        xme_core_componentType_t componentType;
        xme_core_nodeMgr_compRep_componentBuilder_t* addBuilder = NULL;
        xme_core_nodeMgr_compRep_componentHandle_t componentHandle;

#ifdef _MSC_VER
        (void)sscanf_s(inputBuffer, ADD_STRING " %d %d", &nodeID, &componentType);
#else
        (void)sscanf(inputBuffer, ADD_STRING " %d %d", (int*)&nodeID, (int*)&componentType);
#endif

        addBuilder = xme_core_nodeMgr_compRep_createBuilder(nodeID, componentType);
        XME_CHECK(NULL != addBuilder, XME_CHECK_RVAL_VOID);
        status = xme_core_nodeMgr_compRep_build(addBuilder, &componentHandle);
        XME_CHECK_MSG(XME_STATUS_SUCCESS == status, XME_CHECK_RVAL_VOID, XME_LOG_ERROR, "Command could not be executed.\n");

        command->commandType = ADD;
        command->commandData.addComponent.componentHandle = componentHandle;
    }
    else if (0 == strcmp(cmdBuffer, REMOVE_STRING))
    {
        command->commandType = REMOVE;

#ifdef _MSC_VER
        (void)sscanf_s(inputBuffer, REMOVE_STRING " %d %d", (int*)&command->commandData.removeComponent.nodeID, &command->commandData.removeComponent.componentID);
#else
        (void)sscanf(inputBuffer, REMOVE_STRING " %d %d", (int*)&command->commandData.removeComponent.nodeID, &command->commandData.removeComponent.componentID);
#endif
    }
    else if (0 == strcmp(cmdBuffer, REMOVE2_STRING)) // equivalent alternative for REMOVE_STRING
    {
        command->commandType = REMOVE;
#ifdef _MSC_VER
        (void)sscanf_s(inputBuffer, REMOVE2_STRING " %d %d", (int*)&command->commandData.removeComponent.nodeID, &command->commandData.removeComponent.componentID);
#else
        (void)sscanf(inputBuffer, REMOVE2_STRING " %d %d", (int*)&command->commandData.removeComponent.nodeID, &command->commandData.removeComponent.componentID);
#endif
    }
    else if (0 == strcmp(cmdBuffer, LOGOUT_STRING))
    {
        command->commandType = LOGOUT;
#ifdef _MSC_VER
        (void)sscanf_s(inputBuffer, LOGOUT_STRING " %d", (int*)&command->commandData.logout.nodeID);
#else
        (void)sscanf(inputBuffer, LOGOUT_STRING " %d", (int*)&command->commandData.logout.nodeID);
#endif
    }
    else if (0 == strcmp(cmdBuffer, LIST_STRING))
    {
        // TODO: Upper case LIST will not work here. More robust parsing needed.
#ifdef _MSC_VER
        (void)sscanf_s(inputBuffer, LIST_STRING " %" CMD_STRLEN_STRING "s", cmdBuffer, CMD_BUFFER_SIZE);
#else
        (void)sscanf(inputBuffer, LIST_STRING " %" CMD_STRLEN_STRING "s", cmdBuffer);
#endif

        tolowerString(cmdBuffer, cmdBuffer, CMD_BUFFER_SIZE);

        if (0 == strcmp(cmdBuffer, LIST_TYPES_STRING))
        {
            xme_core_manifestRepository_iterator_t iter;
            xme_core_componentManifest_t* compManifest;

            iter = xme_core_manifestRepository_initIterator();

            XME_LOG(XME_LOG_ALWAYS, "\nContent of manifest repository of this node:\n");
            XME_LOG(XME_LOG_ALWAYS, "             component type name | component type ID\n");
            XME_LOG(XME_LOG_ALWAYS, "---------------------------------|------------------\n");

            while (xme_core_manifestRepository_hasNext(iter))
            {
                compManifest = xme_core_manifestRepository_next(&iter);
                
                XME_LOG(XME_LOG_NOTE, "%32s | %5d\n", compManifest->name, compManifest->componentType);
            }

            xme_core_manifestRepository_finiIterator(iter);

            return;
        }
        else if (0 == strcmp(cmdBuffer, LIST_NODES_STRING))
        {
            // Print list of all nodes in the system

            char nodeNameBuffer[20];

            xme_core_directory_nodeRegistryController_nodeIDIterator_t nodeIDIterator;
                
            XME_LOG(XME_LOG_ALWAYS, "\nThe following nodes are registered in the system:\n");
            XME_LOG(XME_LOG_ALWAYS, "           node name | node ID\n");
            XME_LOG(XME_LOG_ALWAYS, "---------------------|--------\n");
        
            xme_core_directory_nodeRegistryController_initNodeIDIterator(&nodeIDIterator);
            while (xme_core_directory_nodeRegistryController_hasNextNodeID(&nodeIDIterator))
            {
                xme_core_node_nodeId_t nodeID;

                nodeID = xme_core_directory_nodeRegistryController_nextNodeID(&nodeIDIterator);

                xme_core_directory_nodeRegistryController_getNodeName(nodeID, nodeNameBuffer, sizeof(nodeNameBuffer));

                XME_LOG(XME_LOG_NOTE, "%20s | %2d\n", nodeNameBuffer, nodeID);
            }
            xme_core_directory_nodeRegistryController_finiNodeIDIterator(&nodeIDIterator);

            return;
        }
        else if (0 == strcmp(cmdBuffer, LIST_COMPONENTS_STRING))
        {
            // Print list of all components in the system

            bool verbose = false;
            char nodeNameBuffer[20];
            char portBuffer[6];
            char functionBuffer[30];

#ifdef _MSC_VER
            (void)sscanf_s(inputBuffer, LIST_STRING " " LIST_COMPONENTS_STRING " %" CMD_STRLEN_STRING "s", cmdBuffer, CMD_BUFFER_SIZE);
#else
            (void)sscanf(inputBuffer, LIST_STRING " " LIST_COMPONENTS_STRING " %" CMD_STRLEN_STRING "s", cmdBuffer);
#endif
            if (0 == strcmp(cmdBuffer, LIST_COMPONENTS_VERBOSE_STRING))
            {
                verbose = true;
            }

            XME_LOG(XME_LOG_ALWAYS, "\nThe following components are registered in the system:\n");
            if (verbose)
            {
                XME_LOG(XME_LOG_ALWAYS, "                      | comp. |                           | port: | function:\n");
                XME_LOG(XME_LOG_ALWAYS, "       node name (ID) | ID    |      comp. type name (ID) | queue | exec.period\n");
                XME_LOG(XME_LOG_ALWAYS, "----------------------|-------|---------------------------|-------|------------\n");
            }
            else
            {
                XME_LOG(XME_LOG_ALWAYS, "                      | comp. |\n");
                XME_LOG(XME_LOG_ALWAYS, "       node name (ID) | ID    |      comp. type name (ID)\n");
                XME_LOG(XME_LOG_ALWAYS, "----------------------|-------|--------------------------\n");
            }

            xme_core_nodeMgr_compRep_componentIteratorInit();
            while (xme_core_nodeMgr_compRep_componentIteratorHasNext())
            {
                xme_core_node_nodeId_t nodeID;
                xme_core_component_t componentID;
                xme_core_componentType_t componentType;
                xme_core_componentManifest_t manifest;
                xme_core_nodeMgr_compRep_componentHandle_t componentHandle;
                xme_core_nodeMgr_compRep_portHandle_t portHandle;
                xme_core_nodeMgr_compRep_functionHandle_t functionHandle;
                uint16_t i = 0u;

                componentHandle = xme_core_nodeMgr_compRep_componentIteratorNext();
                nodeID = xme_core_nodeMgr_compRep_getNodeID(componentHandle);
                componentID = xme_core_nodeMgr_compRep_getComponentID(componentHandle);
                componentType = xme_core_nodeMgr_compRep_getComponentType(componentHandle);
                xme_core_manifestRepository_findComponentManifest(componentType, &manifest);
                xme_core_directory_nodeRegistryController_getNodeName(nodeID, nodeNameBuffer, sizeof(nodeNameBuffer));

                if (verbose)
                {
                    XME_LOG(XME_LOG_NOTE, "%16s (%2d) | %5d | %17s (%5d) |       |\n", nodeNameBuffer, nodeID, componentID, manifest.name, componentType);
                }
                else
                {
                    XME_LOG(XME_LOG_NOTE, "%16s (%2d) | %5d | %17s (%5d)\n", nodeNameBuffer, nodeID, componentID, manifest.name, componentType);
                }

                if (verbose)
                {
                    i = 0u;
                    do
                    {
                        uint16_t queueSize;
                        xme_hal_time_timeInterval_t execPeriod;
                    
                        portHandle = xme_core_nodeMgr_compRep_getPort(componentHandle, i);
                        if (XME_CORE_NODEMGR_COMPREP_INVALID_HANDLE != portHandle)
                        {
                            queueSize = xme_core_nodeMgr_compRep_getQueueSize(portHandle);
                            xme_hal_safeString_snprintf(portBuffer, sizeof(portBuffer), "%2d:%2" PRIu16, i, queueSize);
                        }
                        else
                        {
                            xme_hal_safeString_snprintf(portBuffer, sizeof(portBuffer), "       ");
                        }
                    
                        functionHandle = xme_core_nodeMgr_compRep_getFunction(componentHandle, i);
                        if (XME_CORE_NODEMGR_COMPREP_INVALID_HANDLE != functionHandle)
                        {
                            execPeriod = xme_core_nodeMgr_compRep_getExecutionPeriod(portHandle);

                            if (0ull == execPeriod || 1000000ull < execPeriod)
                            {
                                execPeriod = execPeriod / 1000000ull;
                                xme_hal_safeString_snprintf(functionBuffer, sizeof(functionBuffer), "%2d:%2" PRIu64 "ms", i, execPeriod);
                            }
                            else 
                            {
                                xme_hal_safeString_snprintf(functionBuffer, sizeof(functionBuffer), "%2d:%2" PRIu64 "ns", i, execPeriod);
                            }
                        }
                        else
                        {
                            xme_hal_safeString_snprintf(functionBuffer, sizeof(functionBuffer), "       ");
                        }

                        XME_LOG(XME_LOG_NOTE, "                      |       |                           | %s | %s\n", portBuffer, functionBuffer);

                        i++;

                    } while (XME_CORE_NODEMGR_COMPREP_INVALID_HANDLE != portHandle && XME_CORE_NODEMGR_COMPREP_INVALID_HANDLE != functionHandle);
                }
            }
            xme_core_nodeMgr_compRep_componentIteratorFini();

            return;
        }
        else
        {
            XME_LOG(XME_LOG_ERROR, "Unknown command. Enter help to print available commands.");
            return;
        }
    }
    else if (0 == strcmp(cmdBuffer, HELP_STRING))
    {
        XME_LOG
        (
            XME_LOG_ALWAYS,
            "Enter one of the following commands:\n"
            "COMMAND [PARAMS...]            DESCRIPTION\n"
            "add <nodeID> <componentType>   Adds a new component of the given component type\n"
            "                               to the given node.\n"
            "rem <nodeID> <componentID>     Removes the given component instance from the\n"
            "                               given node.\n"
            "logout <nodeID>                Trigger logout of the given node.\n"
            "list nodes                     Prints list of all nodes.\n"
            "list components                Prints list of all components.\n"
            "list components verbose        Prints list of all components with verbose\n"
            "                               information.\n"
            "list types                     Prints list of all component types.\n"
            "\n"
            "Advanced options for building a component:\n"
            "build <nodeID> <componentType> Like \"add\", but the component is not immediately\n"
            "                               added. Use the following functions to further\n"
            "                               refine the component definition.\n"
            "setqs <portTypeID> <queueSize> Set queue size of the given port to the given\n"
            "                               value.\n"
            "setep <functTypeID> <timeInNs> Set execution period of the given function to\n"
            "                               the given time value in nanoseconds.\n"
            "setis <initializationString>   Set the initialization string for the new\n"
            "commit                         component. Finally add the constructed component.\n"
        );
        return;
    }
    else
    {
        XME_LOG(XME_LOG_ERROR, "Unknown command. Enter help to print available commands.");
        return;
    }

    xme_hal_sync_enterCriticalSection(commandQueueMutex);

    xme_hal_singlyLinkedList_addItem(&commandQueue, command);

    xme_hal_sync_leaveCriticalSection(commandQueueMutex);
}