コード例 #1
0
ファイル: dictiter.c プロジェクト: heocon8319/Wordryo
XP_Bool
dict_firstWord( DictIter* iter )
{
    ASSERT_INITED( iter );
    XP_Bool success = firstWord( iter );
    if ( success ) {
        initWord( iter );
        iter->position = 0;
    }

    return success;
}
コード例 #2
0
ファイル: dictiter.c プロジェクト: heocon8319/Wordryo
void
dict_makeIndex( const DictIter* iter, XP_U16 depth, IndexData* data )
{
    ASSERT_INITED( iter );
    const DictionaryCtxt* dict = iter->dict;
    XP_ASSERT( depth < MAX_COLS_DICT );
    XP_U16 ii, needCount;
    const XP_U16 nFaces = dict_numTileFaces( dict );
    XP_U16 nNonBlankFaces = nFaces;
    XP_Bool hasBlank = dict_hasBlankTile( dict );
    if ( hasBlank ) {
        --nNonBlankFaces;
    }
    for ( ii = 1, needCount = nNonBlankFaces; ii < depth; ++ii ) {
        needCount *= nNonBlankFaces;
    }
    XP_ASSERT( needCount <= data->count );

    Tile allTiles[nNonBlankFaces];
    XP_U16 nTiles = 0;
    for ( ii = 0; ii < nFaces; ++ii ) {
        if ( hasBlank && ii == dict_getBlankTile( dict ) ) {
            continue;
        }
        allTiles[nTiles++] = (Tile)ii;
    }

    /* For each tile string implied by depth (A if depth == 1, AAA if == 3 ),
     * find the first word starting with that IF EXISTS.  If it does, find its
     * index.  As an optimization, find index starting with the previous word.
     */
    data->count = 0;
    DictIter prevIter;
    dict_initIterFrom( &prevIter, iter );
    if ( firstWord( &prevIter ) ) {
        DictPosition prevIndex = 0;
        Tile prefix[depth];
        doOneDepth( allTiles, nNonBlankFaces, prefix, 0, depth, 
                    data, &prevIter, &prevIndex );
    }

#ifdef DEBUG
    DictPosition pos;
    for ( pos = 1; pos < data->count; ++pos ) {
        XP_ASSERT( data->indices[pos-1] < data->indices[pos] );
    }
#endif
} /* dict_makeIndex */
コード例 #3
0
ファイル: dictiter.c プロジェクト: heocon8319/Wordryo
static DictPosition 
figurePosition( DictIter* iter )
{
    DictPosition result = 0;
    DictIter iterZero;
    dict_initIterFrom( &iterZero, iter );
    if ( !firstWord( &iterZero ) ) {
        XP_ASSERT( 0 );
    }

    while ( ! wordsEqual( &iterZero, iter ) ) {
        ++result;
        if ( !nextWord( &iterZero ) ) {
            XP_ASSERT( 0 );
        }
    }
    copyIter( iter, &iterZero );
    return result;
}
コード例 #4
0
ファイル: dictiter.c プロジェクト: heocon8319/Wordryo
XP_S16
dict_findStartsWith( DictIter* iter, const XP_UCHAR* prefix )
{
    ASSERT_INITED( iter );
    array_edge* edge = dict_getTopEdge( iter->dict );
    XP_S16 offset = findStartsWithChars( iter, prefix, 0, edge, 0 );
    if ( 0 > offset ) {
        /* not found; do nothing */
    } else if ( 0 == offset ) {
        if ( !firstWord( iter ) ) {
            offset = -1;
        }
    } else {
        if ( ACCEPT_ITER( iter, iter->nEdges ) || nextWord( iter ) ) {
            DictPosition result = figurePosition( iter );
            iter->position = result;
        } else {
            offset = -1;
        }
    }
    return offset;
}
コード例 #5
0
ファイル: dictiter.c プロジェクト: heocon8319/Wordryo
XP_U32
dict_countWords( const DictIter* iter, LengthsArray* lens )
{
    DictIter counter;
    dict_initIterFrom( &counter, iter );

    if ( NULL != lens ) {
        XP_MEMSET( lens, 0, sizeof(*lens) );
    }

    XP_U32 count;
    XP_Bool ok;
    for ( count = 0, ok = firstWord( &counter ); 
          ok; ok = nextWord( &counter) ) {
        ++count;

        if ( NULL != lens ) {
            ++lens->lens[counter.nEdges];
        }
    }
    return count;
}
コード例 #6
0
void CBatchCounter::LSLOC(results* result, string line, size_t lineNumber, string lineBak, string &strLSLOC, string &strLSLOCBak,
						 bool &data_continue, unsigned int &temp_lines, unsigned int &phys_exec_lines,
						 unsigned int &phys_data_lines/*, StringVector &loopLevel*/)// warning fix
{
	size_t start, end;
	size_t strSize;
	bool trunc_flag = false;
	string exclude = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$";
	string str, spc;
	unsigned int cnt = 0;

	string tmp    = CUtil::TrimString(line);
	string tmpBak = CUtil::TrimString(lineBak);
	start = 0;
	end = tmp.length();

	// skip whole line '(' or ')'
	if (tmp == "(" || tmp == ")")
	{
		strLSLOC = strLSLOCBak = "";
		phys_exec_lines++;
		temp_lines = 0;
		return;
	}

	// there may be more than 1 logical SLOC in this line
#ifdef	_MSC_VER
	char * context = NULL;		// used for strtok_s( )  below
#else
	//
#endif

	bool has_for = false;
	bool has_for_in = false;
	while (start < tmp.length())
	{
        	end = tmp.length();
        	if (start == 0) {
            		has_for = false;
            		has_for_in = false;
        	}
        	//std::cout << start <<"start\n";

        	// check if is a label
        	bool isLabel = false;
        	for (unsigned int i = 0; tmp[i] != '\0'; i++) {
			if (tmp[i] == ' ') {
                		continue;
            		} else if (tmp[i] == ':') {
                	isLabel = true;
                	break;
            		} else {
                		break;
            		}
		}
		if(isLabel) {
			strLSLOC = strLSLOCBak = "";
			phys_exec_lines++;
			temp_lines = 0;
			return;
		} 


		char * token = NULL;

		// Allocate a char array that must be deleted later.
		char* line = new char[end - start + 1];

	#ifdef _MSC_VER
		// Use more Secure C library API
		strcpy_s( line, (end - start + 1) * sizeof(char), tmp.substr(start).c_str() );
	#else
		// Use older less Secure C library API
		strcpy( line, tmp.substr(start).c_str() );
	#endif

		// check |, &
		bool hasPipe = false;
		size_t pipePos = 0;
		bool hasAmp = false;
		size_t ampPos = 0;

		for (int i = 0; line[i] != '\0'; i++) {
			if (line[i] == '|') {
		        	if (!hasPipe) {
		            		pipePos = (size_t)i;
		       		}
		        	hasPipe = true;
		        	line[i] = ' ';
		    	}
		    	if (line[i] == '&') {
		        	if (!hasAmp) {
		            		ampPos = (size_t)i;
		        	}
		        	hasAmp = true;
		        	line[i] = ' ';
		    	}
		}
		
	#ifdef _MSC_VER
		// Use more Secure C library API
		token = strtok_s( line,  " .@:", &context );
	#else
		// Use older less Secure C library API
		token = strtok( line, " .@:" );
	#endif

		for (int i = 0; token[i] != '\0'; i++) {
			token[i] = (char)lowerChars[ TL_ARR( token[i] ) ];
		}
		if (strcmp(token, "else") == 0) 
		{
		#ifdef _MSC_VER
			// Use more Secure C library API
			token = strtok_s( NULL,  " .@:", &context );
		#else
			// Use older less Secure C library API
			token = strtok( NULL, " .@:" );
		#endif
		}

		if (token == NULL) {
			strLSLOC = strLSLOCBak = "";
			phys_exec_lines++;
			temp_lines = 0;
			delete line;
			return;
		}
		
		//first keyword
		//std::cout << token << "TOKEN\n";
		string firstWord(token);    
		firstWord = CUtil::ToLower(firstWord);
		bool checkFirstWord = false;
		for(std::vector<string>::iterator it = exec_name_list.begin(); it != exec_name_list.end(); ++it) {
			if (*it == firstWord) {
				checkFirstWord = true;
				break;
			}
		}
		if(!checkFirstWord) {
			strLSLOC = strLSLOCBak = "";
			phys_exec_lines++;
			temp_lines = 0;
			delete line;
			return;
		}

		

		//if, for, choice as first word
		bool isComplexWord = false;
		bool isCall = false;
		size_t nextKeyWordStart = (size_t)(-1);
		bool isKeyWord = false;
		bool hasElse = false;
		char * nextToken = NULL;
		size_t tmpNextKeyWordStart = (size_t)(-1);
		size_t tmpEnd = (size_t)(-1);

		for(std::vector<string>::iterator it = cmplx_cond_list.begin(); it != cmplx_cond_list.end(); ++it) {
			if (*it == firstWord) {
				isComplexWord = true;
				break;
			}
		}

		//for as first word
		if (firstWord.compare("for") == 0) {
			has_for = true;
		}
		
		
		//call as first word
		if (firstWord.compare("call") == 0) {
			isCall = true;
		}


		// go through the rest of words
	#ifdef _MSC_VER
		// Use more Secure C library API
		nextToken = strtok_s( NULL,  " .@:", &context );
	#else
		// Use older less Secure C library API
		nextToken = strtok( NULL, " .@:" );
	#endif

		while (nextToken != NULL) 
		{
			string nextWord(nextToken);
			nextWord = CUtil::ToLower(nextWord);

			if (has_for && nextWord.compare("in") == 0) 
		        	has_for_in = true;

			if (nextWord.compare("else") == 0)
				hasElse = true;

			if (!isKeyWord) 
			{
				for(std::vector<string>::iterator it2 = exec_name_list.begin(); it2 != exec_name_list.end(); ++it2) 
				{
					if (*it2 == nextWord) 
					{
						isKeyWord = true;
						tmpNextKeyWordStart = CUtil::FindKeyword(CUtil::ToLower(tmp), nextWord, start + firstWord.length(), end);
						//std::cout << tmpNextKeyWordStart << "NEXT_START\n";
						tmpEnd = tmpNextKeyWordStart; // !!!!!
						//std::cout << tmpEnd << "CURR_END\n";

						break;
					}
				}
			}
		#ifdef _MSC_VER
			// Use more Secure C library API
			nextToken = strtok_s( NULL,  " .@:", &context );
		#else
			// Use older less Secure C library API
			nextToken = strtok( NULL, " .@:" );
		#endif
		}

		if (isKeyWord) 
		{
			//std::cout << pipePos << "pipePos\n";
			if (hasPipe && pipePos >= tmpEnd) 
				hasPipe = false;

			//std::cout << ampPos << "ampPos\n";
			if (hasAmp && ampPos >= tmpEnd)
				hasAmp = false;
		} 
		else 
		{
			hasPipe = false;
			hasAmp = false;
		}

		if ((isComplexWord || isCall || hasElse || has_for_in || hasPipe || hasAmp) && isKeyWord) {  // REMEMBER TO CHANGE THE SAME CODE BELOW
		    	nextKeyWordStart = tmpNextKeyWordStart;
		    	end = tmpEnd;
		}
		

		if (tmp[0] != '^') {
		    	//std::cout << "2\n";
			strSize = CUtil::TruncateLine(end - start + 1, strLSLOC.length(), this->lsloc_truncate, trunc_flag);
			if (strSize > 0) {
				strLSLOC += CUtil::TrimString(tmp.substr(start, strSize));
				strLSLOCBak += CUtil::TrimString(tmpBak.substr(start, strSize));
			}
			start = end + 1;
		    	if ((isComplexWord || isCall || hasElse || has_for_in || hasPipe || hasAmp) && isKeyWord) { // REMEMBER TO CHANGE THE SAME CODE ABOVE
		        	start = nextKeyWordStart;
		    	}
			if (strLSLOCBak.length() > 0) { //add physical SLOC
				if (result->addSLOC(strLSLOCBak, lineNumber, trunc_flag)) { //add a logical SLOC
					cnt = 0;
					CUtil::CountTally(strLSLOC, data_name_list, cnt, 1, exclude, "", "", &result->data_name_count);

		            		temp_lines++;
					if (data_continue == true || cnt > 0) {
						result->data_lines[LOG]++;
						phys_data_lines = temp_lines;
					}
					else {
						result->exec_lines[LOG]++;
						phys_exec_lines = temp_lines;
					}
				}
				else if (data_continue == true)
					phys_data_lines = temp_lines;
				else
					phys_exec_lines = temp_lines;
			}
			data_continue = false;
			temp_lines = 0;
			strLSLOC = strLSLOCBak = "";
		}

		delete line;
		line = NULL;
	}
}
コード例 #7
0
ファイル: FZFont.cpp プロジェクト: manucorporat/FORZE2D
 void Font::loadFNTData(char* data)
 {
     if(data == NULL)
         FZ_RAISE("Font:FNT: Imposible to load FNT data. Pointer is NULL.");
     
     int line = 1;
     char word[30];
     bool parsedCommon = false;
     bool parsedPage = false;
     
     while(*data != '\0') {
     
         firstWord(data, word);
         
         switch(fzHash(word)) {
             case "common"_hash:
             {
                 int nuPages = 0;
                 int nu_arg = sscanf(data, "common lineHeight=%f base=%*d scaleW=%*d scaleH=%*d pages=%d", &m_lineHeight, &nuPages);
                 
                 if(nu_arg != 2)
                     FZ_RAISE_STOP("Font:FNT: Line 2. Sintax error. Error parsing FNT common data.");
                 
                 if(nuPages != 1)
                     FZ_RAISE_STOP("Font:FNT: Line 2. Number of pages must be 1.");
                 
                 if(m_lineHeight == 0)
                     FZ_RAISE_STOP("Font:FNT: Line 2. Line height parsing error.");
                 
                 m_lineHeight /= m_factor;
                 parsedCommon = true;
                 
                 break;
             }
             case "page"_hash:
             {
                 char filename[256];
                 int nu_arg = sscanf(data, "page id=%*d file=\"%s\"", filename);
                 
                 if(nu_arg != 1)
                     FZ_RAISE_STOP("Font:FNT: Line 3. Sintax erro. Error parsing FNT page data.");
                 
                 if(filename[0] == '\0')
                     FZ_RAISE_STOP("Font:FNT: Line 3. texture's path is missing.");
                 
                 filename[strlen(filename)-1] = '\0'; // remove last "
                 p_texture = TextureCache::Instance().addImage(filename);
                 if(p_texture == NULL)
                     FZ_RAISE("Font:FNT: Font's texture is missing.");
                 
                 p_texture->retain();
                 parsedPage = true;
                 
                 break;
             }
             case "char"_hash:
             {
                 // CHAR DATA PARSING
                 int charID = 0;
                 fzCharDef temp_char;
                 
                 int nu_arg = sscanf(data, "char id=%d x=%f y=%f width=%f height=%f xoffset=%f yoffset=%f xadvance=%f",
                                 &charID,
                                 &temp_char.x, &temp_char.y,
                                 &temp_char.width, &temp_char.height,
                                 &temp_char.xOffset, &temp_char.yOffset,
                                 &temp_char.xAdvance);
                 
                 temp_char.x         /= m_factor;
                 temp_char.y         /= m_factor;
                 temp_char.width     /= m_factor;
                 temp_char.height    /= m_factor;
                 temp_char.xOffset   /= m_factor;
                 temp_char.yOffset   /= m_factor;
                 temp_char.xAdvance  /= m_factor;
                 
                 if(nu_arg != 8) {
                     FZLOGERROR("Font:FNT: Line %d. Error parsing FNT char data, syntax is not correct.", line);
                     break;
                 }
                 
                 if(charID >= 256) {
                     FZLOGERROR("Font:FNT: Line %d. CharID is out of bounds [0, 255].", line);
                     break;
                 }
                 
                 m_chars[charID] = temp_char;
                 break;
             }
             case "kerning"_hash:
             {
                 // KERNING DATA PARSING
                 int first = 0;
                 int second = 0;
                 fzFloat amount = 0;
                 
                 int nu_arg = sscanf(data, "kerning first=%d second=%d amount=%f",
                                 &first, &second, &amount);
                 
                 if(first < 0 || second < 0 || first > 255 || second > 255) {
                     FZLOGERROR("Font:FNT: Line %d. Invalid indexes.", line);
                     break;
                 }
                 if(nu_arg != 3) {
                     FZLOGERROR("Font:FNT: Line %d. Error parsing FNT kerning data.", line);
                     break;
                 }
                 
                 uint16_t key = generateKey((uint8_t)first, (uint8_t)second);
                 m_kerning.insert(pair<uint16_t, fzFloat>(key, amount));
                 
                 break;
             }
         }
         
         
         while(true) {
             if(*data != '\0') {
                 if(*(data++) == '\n'){
                     ++line;
                     break;
                 }
             }
         }
     }
     if(!parsedCommon)
         FZ_RAISE_STOP("Font:FNT: FNT common data not found.");
     
     if(!parsedPage)
         FZ_RAISE_STOP("Font:FNT: FNT page data not found.");
 }