int main(){
    int choice;
    
    do{
        choice = interfaceMenu();
        
        switch(choice){
            case 1:
                hammingDistance();
                break;
            case 2:
                subPattern();
                break;
            case 3:
                validString();
                break;
            case 4:
                gcSkew();
                break;
            case 5:
                maxSkew();
                break;
            case 6:
                minSkew();
                break;
            case 0:
                return 0;
            default:
                printf("\n Wrong input!");
        }
    }while(choice!= 0);
}
Ejemplo n.º 2
0
int verifyTokens(struct tokenList* tokens)
{
	int i, flag = 0;
	struct tokenElement* node = tokens->first;

	for (i = 0; i < tokens->qnt; i++)
	{
		if (node->token->text[0] == '\'')
		{
			if (validChar(node->token))
				node->token->code = tokenToCode(node->token->text,'c');
			else
				flag = 1;
		}
		else if (node->token->text[0] == '\"')
		{
			if (validString(node->token))
				node->token->code = tokenToCode(node->token->text,'s');
			else
				flag = 1;
		}
		else if (isalpha(node->token->text[0]))
			node->token->code = tokenToCode(node->token->text,'i');
		else if (isdigit(node->token->text[0]))
		{
			if (validNumber(node->token))
				node->token->code = tokenToCode(node->token->text,'n');
			else
				flag = 1;
		}
		else if (validSeparator(node->token))
			node->token->code = tokenToCode(node->token->text,'t');
		else
			flag = 1;

		node = node->next;
	}

	if (!flag)
		return 1;
	else
		return 0;
}
Ejemplo n.º 3
0
void ShaderDefinitions::readShaderDefinitions()
{

	ShadingNode sn;
	std::vector<ShadingNode> snodes;
	snodes.push_back(sn);
	this->shadingNodes.push_back(sn);

	logger.feature(MString("home dir: ") + getRendererHome());
	logger.feature(MString("shader defs file: ") + getRendererHome() + "ressources/shaderDefinitions.txt");
	
	std::string shaderDefFile = (getRendererHome() + "ressources/shaderDefinitions.txt").asChar();

	std::ifstream shaderFile(shaderDefFile.c_str());
	if( !shaderFile.good())
	{
		logger.error(MString("Unable to open shaderInfoFile ") + MString(shaderDefFile.c_str()));
		shaderFile.close();
		return;
	}
	std::string line;

	ShadingNode node;

	do{
		std::getline(shaderFile, line);
		//logger.debug(line.c_str());
		if(validString(line))
		{
			std::vector<std::string> stringArray;
			pystring::split(line, stringArray, ":");

			if(pystring::startswith(line, "shader_end"))
			{
				// these nodes are automatically valid because they are supported
				node.nodeState = ShadingNode::VALID;

				this->shadingNodes.push_back(node);
				// clean up old node
				node = ShadingNode();
			}

			if(pystring::startswith(line, "shader_start"))
			{
				node.typeName = stringArray[1].c_str();
			}
			//inatt:blender:float
			if(pystring::startswith(line, "inatt"))
			{
				if( stringArray.size() > 2 )
				{
					ShaderAttribute att;
					att.name = stringArray[1];
					att.type = stringArray[2];
					node.inputAttributes.push_back(att);
				}
			}
			if(pystring::startswith(line, "outatt"))
			{
				if( stringArray.size() > 2 )
				{
					ShaderAttribute att;
					att.name = stringArray[1];
					att.type = stringArray[2];
					node.outputAttributes.push_back(att);
				}
			}
		}

	}while(!shaderFile.eof());

	//logger.debug("Reading of shader def file done.");
	shaderFile.close();
	readDone = true;
}
Ejemplo n.º 4
0
// returns TRUE if it is legal for the current
// player to make the specified action, FALSE otherwise->
//
// "legal" means everything is legal:
//   * that the action code is a valid action code which is legal to
//     be made at this time
//   * that any path is well formed and legal ie consisting only of
//     the legal direction characters and of a legal length,
//     and which does not leave the island into the sea at any stage->
//   * that disciplines mentioned in any retraining actions are valid
//     discipline numbers, and that the university has sufficient
//     students of the correct type to perform the retraining
//
// eg when placing a campus consider such things as:
//   * is the path a well formed legal path
//   * does it lead to a vacent vertex?
//   * under the rules of the game are they allowed to place a
//     campus at that vertex?  (eg is it adjacent to one of their ARCs?)
//   * does the player have the 4 specific students required to pay for
//     that campus?
// It is not legal to make any action during Terra Nullis ie
// before the game has started->
// It is not legal for a player to make the moves OBTAIN_PUBLICATION
// or OBTAIN_IP_PATENT (they can make the move START_SPINOFF)
// you can assume that any pths passed in are NULL terminated strings->
int isLegalAction(Game g, action a) {
    int isLegal = TRUE;
    printf("Checking if an action is legal\n");
    int player = getWhoseTurn(g);
    int flag = 1;
    // Protect from stupid shit
    if ((a.actionCode < PASS) || (a.actionCode > RETRAIN_STUDENTS)) {
        printf("Invalid Action Code\n");
        flag = 0;
    } else if (a.actionCode == RETRAIN_STUDENTS) {
        printf("You've Called a retrain, checking if discipline");
        printf("within the bounds\n");
        // If it's a retrain action make sure the to
        // and from are in a nice range.
        if ((a.disciplineTo < STUDENT_THD)
            || (a.disciplineTo > STUDENT_MMONEY)) {
            printf("Invalid Discpline Code\n");
            flag = 0;
        }
        if ((a.disciplineFrom < STUDENT_THD)
            || (a.disciplineFrom > STUDENT_MMONEY)) {
            printf("Invalid Discpline Code\n");
            flag = 0;
        }
    }

    printf("The Flag when testing is %d\n", flag);

    if (flag == 1) {
        // Check all the basic stuff
        if (getTurnNumber(g) == TERRA_NULLIS) {
            isLegal = FALSE;
        } else if ((a.actionCode < 0) || (a.actionCode > MAX_ACTION)) {
            isLegal = FALSE;
        } else if ((getWhoseTurn(g) < 0) || (getWhoseTurn(g) > NUM_UNIS)) {
            isLegal = FALSE;
        } else if (a.actionCode == OBTAIN_IP_PATENT ||
            a.actionCode == OBTAIN_PUBLICATION) {
            isLegal = FALSE;
        }
        if (a.actionCode <= 3 && a.actionCode > 0 && isLegal) {
            if (validString(a.destination) == FALSE) {
                isLegal = FALSE;
            } else if (validPoint(pathToPoint(a.destination).x,
                pathToPoint(a.destination).y) == FALSE) {
                isLegal = FALSE;
            }
        }

        // edge actionEdge = pathToEdgeF (a.destination);

        // Check that someone can get an arc
        if (a.actionCode == OBTAIN_ARC && isLegal) {
            printf("Checking if the arc is legal. Arc:%s\n", a.destination);
            if (validNewEdge(g, pathToEdgeF(a.destination), player) == FALSE) {
                printf("Geographically Valid Edge\n");
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_BQN) < 1) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_BPS) < 1) {
                isLegal = FALSE;
            }
        }

        // Check that someone can get a Campus
        if (a.actionCode == BUILD_CAMPUS && isLegal) {
            if (validNewContents(g, a.destination, player) == FALSE) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_BQN) < 1) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_BPS) < 1) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_MJ) < 1) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_MTV) < 1) {
                isLegal = FALSE;
            }
        }

        if (a.actionCode == BUILD_GO8 && isLegal) {
            point actionPoint =  pathToPoint(a.destination);
            if (g->gameBoard->points[actionPoint.x][actionPoint.y]->contents !=
                player) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_MJ) < 2) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_MMONEY) < 3) {
                isLegal = FALSE;
            } else if (getTotalGO8s(g) == 8) {
                isLegal = FALSE;
            }
        }

        if (a.actionCode == START_SPINOFF && isLegal) {
            if (getStudents(g, player, STUDENT_MJ) < 1) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_MTV) < 1) {
                isLegal = FALSE;
            } else if (getStudents(g, player, STUDENT_MMONEY) < 1) {
                isLegal = FALSE;
            }
        }

        if (a.actionCode == RETRAIN_STUDENTS && isLegal) {
            int exchange = getExchangeRate(g, player, a.disciplineFrom,
                a.disciplineTo);
            if (getStudents(g, player, a.disciplineFrom) < exchange) {
                isLegal = FALSE;
            } else if (a.disciplineFrom == STUDENT_THD) {
                isLegal = FALSE;
            }
        }
    } else if (flag == 0) {
        isLegal = FALSE;
    }
    return isLegal;
}
Ejemplo n.º 5
0
int main(int argc, char** argv){
    // check if enough arguments are passed
    if (argc < 2){
	printf("Not enough arguments\n");
	exit(EXIT_FAILURE);
    }
	
    // check if valid file path
    if (fileExists(argv[1]) == EXIT_FAILURE){
	printf("Not valid file path %s\n", argv[1]);
	exit(EXIT_FAILURE);
    }
	
    // Establish a handler for signals
    signal(SIGINT | SIGKILL, catchSignal);
	
    // The structure for two events
    struct pollfd fds[1] = {{0}};
	 
    int fd = open(argv[1], O_RDONLY | O_NONBLOCK);
	
    if (fd < 0 ){
	printf("Error opening file %s\n", argv[1]);
	exit(EXIT_FAILURE);
    }
	
    printf("Polling device %s\n", argv[1]);
	
    // Monitor file for input
    fds[0].fd = fd;
    fds[0].events = POLLIN;
    fds[0].revents = 0;
		
    barcodeContext context = initializeBarcodeContext();
    barcodeOutput output = {0};

    // stop polling only when flag is set to 0	
    while (continuePolling){
	int ret = poll(fds, 1, POLL_TIME_MS);

	if (ret > 0 && (fds[0].revents & POLLIN)){
	    // If we detect the event, 
	    // zero it out so we can reuse the structure
	    int readBytes = 0;
	    char buffer[MAX_BUFFER_SIZE] = {0};
				
	    if ((readBytes = read(fds[0].fd, buffer, sizeof(buffer))) > 0){
		if (validString(buffer, readBytes) == SUCCESS){
		    barcodeInput inputLine = convertStringToLineInput(buffer, readBytes);
		    addInputLineToContext(&context, inputLine);
		    bzero(buffer, sizeof(buffer));
		}
	    }
				
	    if (parseBarcodeContext(context, &output) == SUCCESS){
	        printf("BARCODE RESULT : %s\n", output.line);
		context = initializeBarcodeContext();
		bzero(&output,sizeof(output)) ;
	    }
	}
		
	// zero it out so we can reuse the structure
	fds[0].revents = 0;
    }

    exit(EXIT_SUCCESS);
}