Exemplo n.º 1
0
// Handles tokens that start with a letter: reserved words and identifiers
int alpha(char* program, int save){
	// Character after the initial alpha character
	currentpos++;
	// Keep looking forward until a character is not alphanumeric
	while(isalnum(program[currentpos])){
		currentpos++;
	}
	// Get the length of the string by subtracting the first character
	// position from the last character position in the program array
	int strlength = currentpos - save;
	// String is too long - this is an error!
	if(strlength > CHARMAX)
		return 0;
	// Copy the string from the program array into a new char array
	// so that it can be compared to the reserved words
	char str[strlength+1];
	strncpy(str, &program[save], strlength);
	str[strlength] = '\0';
	int reserved = isReserved(str);
	if(reserved != -1){
		printf("%s is reserved\n", str);
	}
	else
		printf("%s is an ident\n", str);
	return 1;
}
Exemplo n.º 2
0
int NameManager::validateGuildName(const String& name, int type) {
	if (name.isEmpty())
		return NameManagerResult::DECLINED_EMPTY;

	if ((type == NameManagerType::GUILD_NAME || type == NameManagerType::GUILD_TITLE) && name.length() > 25)
		return NameManagerResult::DECLINED_GUILD_LENGTH;

	if (type == NameManagerType::GUILD_ABBREV && name.length() > 5)
		return NameManagerResult::DECLINED_GUILD_LENGTH;

	if (isProfane(name))
		return NameManagerResult::DECLINED_PROFANE;

	if (isDeveloper(name))
		return NameManagerResult::DECLINED_DEVELOPER;

	if (isFiction(name))
		return NameManagerResult::DECLINED_FICT_RESERVED;

	if (isReserved(name))
		return NameManagerResult::DECLINED_RESERVED;

	// Guilds allowed multiple spaces
	if (strspn(name.toCharArray(), "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'- ") != name.length())
		return NameManagerResult::DECLINED_SYNTAX;

	// Multiple consecutive spaces not allowed
	if (name.indexOf("  ") != -1)
		return NameManagerResult::DECLINED_SYNTAX;

	if (name.contains("\\") || name.contains("\n") || name.contains("\r") || name.contains("#"))
		return NameManagerResult::DECLINED_SYNTAX;

	return NameManagerResult::ACCEPTED;
}
Exemplo n.º 3
0
int NameManager::validateVendorName(const String& name) {
	if (name.isEmpty())
		return NameManagerResult::DECLINED_EMPTY;

	if (name.length() > 40)
		return NameManagerResult::DECLINED_SYNTAX;

	if (isProfane(name))
		return NameManagerResult::DECLINED_PROFANE;

	if (isDeveloper(name))
		return NameManagerResult::DECLINED_DEVELOPER;

	if (isFiction(name))
		return NameManagerResult::DECLINED_FICT_RESERVED;

	if (isReserved(name))
		return NameManagerResult::DECLINED_RESERVED;

	// Vendors allowed to have spaces
	if (strspn(name.toCharArray(), "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'- ") != name.length())
		return NameManagerResult::DECLINED_SYNTAX;

	// Multiple consecutive spaces not allowed
	if (name.indexOf("  ") != -1)
		return NameManagerResult::DECLINED_SYNTAX;

	return NameManagerResult::ACCEPTED;
}
Exemplo n.º 4
0
static ParseResult<std::string> parseScheme(char const* str) {
    auto result = parseWhile(str, [](char ch) {
        return ch != ':' && !isReserved(ch);
    });
    result.ch = (result.ch[0] == ':') ? (result.ch+1) : (result.ch);
    return result;
}
Exemplo n.º 5
0
void titleformat_text_filter_nontext_chars::write(const GUID & p_inputtype,pfc::string_receiver & p_out,const char * p_data,t_size p_data_length) {
	for(t_size walk = 0;;) {
		t_size base = walk;
		while(walk < p_data_length && !isReserved(p_data[walk]) && p_data[walk] != 0) walk++;
		p_out.add_string(p_data+base,walk-base);
		if (walk >= p_data_length || p_data[walk] == 0) break;
		p_out.add_byte('_'); walk++;
	}
}
Exemplo n.º 6
0
Token DnLexer::Id() {
  std::string buf;
  int resv = -1;
  do { buf.append(1, c); consume(); } while(isDecimal() || isLetter() || isSym());
  if((resv = isReserved(buf)) != -1){
    /* Is this id reserved word? */
    return Token(2 + resv, buf);
  }
  return Token(ID, buf);
}
Exemplo n.º 7
0
static ParseResult<std::string> parseUser(char const* str) {
    auto result = parseWhile(str, [](char ch) {
        return ch != '@' && !isReserved(ch);
    });
    if (result.ch[0] == '@') {
        result.ch = result.ch+1;
    } else {
        result.ch = str;
        result.value = "";
    }
    return result;
}
Exemplo n.º 8
0
Arquivo: edge.cpp Projeto: KDE/kwin
void WindowBasedEdge::doUpdateBlocking()
{
    if (!isReserved()) {
        return;
    }
    if (isBlocked()) {
        m_window.unmap();
        m_approachWindow.unmap();
    } else {
        m_window.map();
        m_approachWindow.map();
    }
}
Exemplo n.º 9
0
static ParseResult<uint16_t> parsePort(char const* str) {
    ParseResult<uint16_t> result;
    if (str[0] != ':') {
        result.value = 0;
        result.ch = str;
        return result;
    }
    auto tmp = parseWhile(str+1, [](char ch) {
        return !isReserved(ch);
    });
    result.value = uint16_t(strtol(tmp.value.c_str(), 0, 10));
    result.ch = tmp.ch; 
    return result; 
}
Exemplo n.º 10
0
// return a node that conflicts with this request; NULL if there's no conflict
// does automatic sensorization so you don't have to later! isn't that nice? :-)
Node *resConflict(int numNodes, Node **nodes, int myTid) {
	// scan through the request and see if any of the nodes are already reserved
	int i;
	for (i=0; i<numNodes; i++) {
		if (isReserved(nodes[i], myTid)) {
			Node *retNode = nodes[i];
			// sensorize
			if (retNode->type == NODE_SENSOR) {
				retNode = (Node *)getSensor( ((Sensor *)retNode)->forward_num );
			}
			return retNode;
		}
	}
	// otherwise, there were no error conditions, so return true
	return NULL;
}
int NameManager::validateLastName(const String& name, int species) {
	if (name.isEmpty())
		return NameManagerResult::ACCEPTED;

	//Wookiees are not allowed to have last names.
	if (species == CreatureObject::WOOKIE)
		return NameManagerResult::DECLINED_RACE_INAPP;

	if (name.length() > 20)
		return NameManagerResult::DECLINED_RACE_INAPP;

	if (isProfane(name))
		return NameManagerResult::DECLINED_PROFANE;

	if (isDeveloper(name))
		return NameManagerResult::DECLINED_DEVELOPER;

	if (isFiction(name))
		return NameManagerResult::DECLINED_FICT_RESERVED;

	if (isReserved(name))
		return NameManagerResult::DECLINED_RESERVED;

	//Make sure that only valid characters are allowed in the name.
	if (strspn(name.toCharArray(), "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'-") != name.length())
		return NameManagerResult::DECLINED_SYNTAX;

	//If the name has a hyphen or apostrophe, make sure they are the proper species.
	if (name.indexOf("'") != -1 || name.indexOf("-") != -1) {
		//Must be a human, twilek, moncal, or zabrak to have a hyphen or apostrophe.
		if (species != CreatureObjectImplementation::HUMAN && species != CreatureObjectImplementation::TWILEK && species != CreatureObjectImplementation::MONCAL && species != CreatureObjectImplementation::ZABRAK)
			return NameManagerResult::DECLINED_RACE_INAPP;

		//Moncal's aren't allowed to have apostrophes.
		if (species == CreatureObjectImplementation::MONCAL && name.indexOf("'") != -1)
			return NameManagerResult::DECLINED_RACE_INAPP;

		//Make sure they only have one hyphen and apostrophe in lastname.
		if (name.indexOf('\'') != name.lastIndexOf('\'') || name.indexOf('-') != name.lastIndexOf('-'))
			return NameManagerResult::DECLINED_RACE_INAPP;
	}

	return NameManagerResult::ACCEPTED;
}
Exemplo n.º 12
0
void logRelease(int numNodes, Node **nodes, int trainNum) {
	// scan through the request and set all of the specified nodes to unavailable
	// also, die with an error upon discovering an inconsistency
	int i;
	for (i=0; i<numNodes; i++) {
		if ( isReserved(nodes[i], -1) ) { // if it was previously locked, we're ok
			if (nodes[i]->type == NODE_SWITCH) { // if it's a switch node
				((Switch *)nodes[i])->available = 1;
			} else if (nodes[i]->type == NODE_SENSOR) { // if it's a switch node
				(getSensor( ((Sensor *)nodes[i])->forward_num) )->available = 1;
			} else {
				aprintf(COM2, "ERROR: res. serv.::logRel. got unrecognized node type %d! Halt!!!", nodes[i]->type);
				Halt();
			}
		} else { // else if it was not previously available, die with an error
			aprintf(COM2, "ResServ: Train %d unres free node: ", trainNum);
			printNode(nodes[i]);
			Halt();
		}
	}
}
Exemplo n.º 13
0
int isName( u8 c ){
  if( !isReserved( c ) && !isWhitespace( c ) )
    return 1;
  return 0;
}
Exemplo n.º 14
0
// This method will read the input file char by char
//   and will clean the input and build the lexTable
int execute( ){
  // open input.txt and cleaninput.txt
	FILE *input = fopen( "input.txt","r" );
	FILE *clean = fopen( "cleaninput.txt","w+" );

  // begin grabbing char by char
	char c = getc( input );
  buffer = (char *)malloc(13);

  // while there are characters left parse the file
	while( c != EOF ){    
		// makes sure the buffer is clean
    for( temp = 0; temp < 13; temp++ )
      buffer[temp] = '\0';
		
    // start building a word
    buffer[bufferLen] = c;

		if( isLetter(c) ){	// word starts with a letter

      // keep adding letters or digits to the word
      while( isLetter(c) || isDigit(c) ){
				buffer[bufferLen++] = c;
        // if the buffer word is too large give error
        if( bufferLen > 11 ) return error( input, clean, c, buffer, 2 );

				c = getc( input );
			}
      // now check if the found word is a reserved word
      if( !isReserved( clean, buffer ) )
        // add to lexTable as an identsym
        addToTable( clean, buffer, identsym );

      // unget one char
			ungetc( c, input );

		}else if( isDigit(c) ){ // word start with a digit 
      
      // keep adding digits to the word (number)
			while( isDigit(c) ){
				buffer[bufferLen++] = c;
        // if the buffer word (number) is no large give error
        if( bufferLen > 5 ) return error( input, clean, c, buffer, 1 );

				c = getc( input );
        // if the word starts with a digit and has a letter give error
        if( isLetter(c) ) return error( input, clean, c, buffer, 0 );

			}
      // add to lexTable as an numbersym
      addToTable( clean, buffer, numbersym );
 
      // unget one char and add buffer to cleaninput.txt
			ungetc( c, input );
			
		}else if( isSymbol(c) ){ // word is a symbol
			// use a switch to add the corresponding symbol to the lexTable	
      //   also add the symbol to cleaninput.txt
			switch(c){
      case '+':
        addToTable( clean, "+", plussym );
        break;
      case '-':
        addToTable( clean, "-", minussym );
        break;
      case '*':
        addToTable( clean, "*", multsym );
        break;   
      case '/': // two comment formatts that are left out of cleaninput.txt
				c = getc( input );
        switch(c){
        case '*': // '/*' multiline comment
          do{ // waits for another '/' after a '*'
						do{ // waits for another '*'
							c = getc( input ); 
						}while( c != '*' );
						c = getc( input );
					}while( c != '/' );
          break;

        case '/': // '//' singleline comment
          do{ // waits for a newline character
            c = getc( input );
          }while( c != NEWLINE );
          break;

        default: // '/' as in 'divides' add this one to the table
          addToTable( clean, "/", slashsym );
          ungetc( c, input );
        }
				break;
      case '(':
        addToTable( clean, "(", lparentsym );
        break;
      case ')':
        addToTable( clean, ")", rparentsym );
        break;
      case '=':
        addToTable( clean, "=", eqlsym );
        break;
      case ',':
        addToTable( clean, ",", commasym );
        break;
	    case '.':
        addToTable( clean, ".", periodsym );
        break;
	    case '<': 
        c = buffer[++bufferLen] = getc( input );
        switch( c ){
        case '=': // less than or equal to
          addToTable( clean, "<=", leqsym );
          break;
        case '>': // '<>' neqsym
          addToTable( clean, "<>", neqsym );
          break;
        default: // just less than
          addToTable( clean, "<", lessym );
        } 
//        ungetc( c, input );
        break;
	    case '>': 
        c = buffer[++bufferLen] = getc( input );
        switch( c ){
        case '=': // greater than or equal to
          addToTable( clean, ">=", leqsym );
          break;
        default: // just greater than
          addToTable( clean, ">", lessym );
        } 
        ungetc( c, input );
        break;
      case ';':
        addToTable( clean, ";", semicolonsym );
        break;
	    case ':': // a colon is found check for an '=' 
        // if not bleed into the default case to send an error
        buffer[++bufferLen] = getc( input );
        if( !strncmp( buffer, ":=", 2 ) ){
          addToTable( clean, ":=", becomessym );
          break;
        }
			default:
       return error( input, clean, c, buffer, 3 );
			}
		}else if( isInvis(c) ){ // word is a white space
			// add the char to the buffer
      while( isInvis(c) ){
        buffer[0] = c;
        c = getc( input ); 
      }
      ungetc( c, input );
			fprintf( clean, "%s", buffer );
		}else
      return error( input, clean, c, buffer, 3 );

    // reset bufferLen and continue building char by char
		bufferLen = 0;
		c = getc( input );
	}
	fclose( input );
  fclose( clean );
  return 1;
}
Exemplo n.º 15
0
int NameManager::validateName(const String& name, int species) {
	NameData* data = getSpeciesData(species);
	NameRules* firstNameRules = data->getFirstNameRules();
	NameRules* lastNameRules = data->getLastNameRules();

	if (name.isEmpty())
		return NameManagerResult::DECLINED_EMPTY;

	int fullMaxLength = firstNameRules->getMaxChars() + lastNameRules->getMaxChars() + 1;

	if (name.length() > fullMaxLength)
		return NameManagerResult::DECLINED_RACE_INAPP;

	String firstName, lastName;

	//Split the name into first and last
	int spc = name.indexOf(" ");
	if (spc != -1) {
		firstName = name.subString(0, spc);
		lastName = name.subString(spc + 1, name.length());
	} else {
		firstName = name;
		lastName = "";
	}

	if (isProfane(name))
		return NameManagerResult::DECLINED_PROFANE;

	if (isDeveloper(name))
		return NameManagerResult::DECLINED_DEVELOPER;

	if (isFiction(name))
		return NameManagerResult::DECLINED_FICT_RESERVED;

	if (isReserved(name) || isReserved(firstName) )
		return NameManagerResult::DECLINED_RESERVED;

	if (firstName.length() < firstNameRules->getMinChars() || firstName.length() > firstNameRules->getMaxChars())
		return NameManagerResult::DECLINED_RACE_INAPP;

	// This will handle species not allowed surnames (Wookiees) if the rules have min/max set to 0
	if (lastName != "" && (lastName.length() < lastNameRules->getMinChars() || lastName.length() > lastNameRules->getMaxChars()))
		return NameManagerResult::DECLINED_RACE_INAPP;

	// Iterates through the name, looking for non alphabetic characters and comparing it to the allowed
	// special characters in the rules, also counting total characters and comparing to the max
	int specialCount = 0;
	for (int i = 0; i < firstName.length(); i++) {
		String singleChar = firstName.subString(i, i + 1);
		if (isalpha(firstName.charAt(i)) == 0) {
			if (!firstNameRules->getSpecialChars().contains(singleChar))
				return NameManagerResult::DECLINED_RACE_INAPP;
			else
				specialCount++;
		}
	}

	if (specialCount > firstNameRules->getMaxSpecialChars())
		return NameManagerResult::DECLINED_RACE_INAPP;

	if (lastName != "") {
		specialCount = 0;
		for (int i = 0; i < lastName.length(); i++) {
			String singleChar = lastName.subString(i, i + 1);
			if (isalpha(lastName.charAt(i)) == 0) {
				if (!lastNameRules->getSpecialChars().contains(singleChar))
					return NameManagerResult::DECLINED_RACE_INAPP;
				else
					specialCount++;
			}
		}

		if (specialCount > lastNameRules->getMaxSpecialChars())
			return NameManagerResult::DECLINED_RACE_INAPP;
	}

	return NameManagerResult::ACCEPTED;
}
Exemplo n.º 16
0
static ParseResult<std::string> parseHost(char const* str) {
    return parseWhile(str, [](char ch) {
        return ch != ':' && !isReserved(ch);
    });
}