示例#1
0
bool ieJpegDecoder::GetSOS()
//
// Process SOS (Start of Scan)
//
{
	int length = GetWord() - 3;
	int n = *pbStream++;				//  Number of components
	if ((length != (n * 2 + 3)) || (n < 1) || (n > IE_JPEG_MAX_COMPS)) 
		return false;
    nCompsInScan = n;

    // Collect color component id's and Huffman table indexes
	for (int i = 0; i < n; i++) {

		int cCompId = *pbStream++;
		int cTables = *pbStream++;
		length -= 2;

		PjdCompInfo pComp = nullptr;
		for (int ci = 0; ci < nComps; ci++) {
			if (cCompId == aComps[ci].iId) {
				pComp = &aComps[ci];
				break;
			}
        }
		if (!pComp) return false;

		apCompInfos[i] = pComp;

		pComp->iDCTable = cTables >> 4;
		pComp->iACTable = cTables & 0xF;
	}

    // Collect the additional scan parameters Ss, Se, Ah/Al.
  	Progressive.Ss = *pbStream++;				// Start of spectral selection, 0 for baseline
	Progressive.Se = *pbStream++;				// End of spectral selection, DCTSIZE2-1 for baseline
	BYTE c = *pbStream++;						// 0 for baseline
	Progressive.Ah = (c >> 4) & 0xF;			// Successive approximation high bit
	Progressive.Al = (c     ) & 0xF;    		// Successive approximation low bit
    length -= 3;
    iScanNumber++;

	pbStream += length;

	return true;
}
示例#2
0
bool ieJpegDecoder::GetAPP14()
//
// Process APP14 (Application data 14)
//
{
	int	length = GetWord() - 2;
	
	// See if an Adobe APP14 marker is present
	#define ADOBE_LEN 12
	if (length >= ADOBE_LEN) {
		if (memcmp(pbStream, "Adobe", 5) == 0) {
			// Found Adobe APP14 marker
			//version = (cd.pbStream[5] << 8) + cd.pbStream[6];
			//flags0 = (cd.pbStream[7] << 8) + cd.pbStream[8];
			//flags1 = (cd.pbStream[9] << 8) + cd.pbStream[10];
			//transform = cd.pbStream[11];
			switch (pbStream[11]) {	// Describes the colortransform used by the Adobe compressor
			case 0:							// 0: No transform => default Adobe colorspace
				switch (nComps) {
				case 1:
					eColorSpace = ieColorSpace::L;
					break;
				case 3:
					eColorSpace = ieColorSpace::RGB;
					break;
				case 4:
					eColorSpace = ieColorSpace::CMYL;
					break;
				}
				break;
			case 1:
				if (nComps == 3)
					eColorSpace = ieColorSpace::YCbCr;
				break;
			case 2:
				if (nComps == 4)
					eColorSpace = ieColorSpace::YCCK;
				break;
			}
		}
	}

	pbStream += length;

	return true;
}
示例#3
0
unsigned long 
NALUnit::GetUE()
{
    // Exp-Golomb entropy coding: leading zeros, then a one, then
    // the data bits. The number of leading zeros is the number of
    // data bits, counting up from that number of 1s as the base.
    // That is, if you see
    //      0001010
    // You have three leading zeros, so there are three data bits (010)
    // counting up from a base of 111: thus 111 + 010 = 1001 = 9
    int cZeros = 0;
    while (GetBit() == 0)
    {
        cZeros++;
    }
    return GetWord(cZeros) + ((1 << cZeros)-1);
}
示例#4
0
void ClientAgent::CTCPAction(BString theTarget, BString theMsg)
{
	BString theCTCP(GetWord(theMsg.String(), 1).ToUpper()),
		theRest(RestOfString(theMsg.String(), 2)), tempString("[CTCP->");

	tempString += theTarget;
	tempString += "] ";
	tempString += theCTCP;

	if (theRest != "-9z99") {
		tempString += " ";
		tempString += theRest;
		tempString += '\n';
	} else
		tempString += '\n';

	Display(tempString.String(), C_CTCP_REQ, C_BACKGROUND, F_SERVER);
}
示例#5
0
文件: omf.cpp 项目: DinrusGroup/DRC
uint32 SOMFRecordPointer::UnpackLIDATABlock(int8 * destination, uint32 MaxSize) {
   // Unpack Data block in LIDATA record recursively and store data at destination
   uint32 RepeatCount = GetNumeric();            // Outer repeat count
   uint32 BlockCount  = GetWord();               // Inner repeat count
   uint32 Size = 0;                              // Size of data expanded so far
   uint32 RSize;                                 // Size of recursively expanded data
   uint32 SaveIndex;                             // Save Index for repetition
   uint32 i, j;                                  // Loop counters
   if (BlockCount == 0) {
      // Contains one repeated block
      Size = GetByte();                          // Size of repeated block
      if (RepeatCount * Size > MaxSize) {
         // Data outside allowed area
         err.submit(2310);                       // Error message
         Index += Size;                          // Point to after block
         return 0;                               // No data stored
      }

      // Loop RepeatCount times
      for (i = 0; i < RepeatCount; i++) {
         // copy data block into destination
         memcpy(destination, buffer + FileOffset + Index, Size);
         destination += Size;
      }
      Index += Size;                             // Point to after block
      return RepeatCount * Size;                 // Size of expanded data
   }
   // Nested repeat blocks
   SaveIndex = Index;
   // Loop RepeatCount times
   for (i = 0; i < RepeatCount; i++) {
      // Go back and repeat unpacking
      Index = SaveIndex;
      // Loop BlockCount times
      for (j = 0; j < BlockCount; j++) {
         // Recursion
         RSize = UnpackLIDATABlock(destination, MaxSize);
         destination += RSize;
         MaxSize -= RSize;
         Size += RSize;
      }
   }
   return Size;
}
int CheckIfGuidance(char *line,int isLabel)
{
	int i;
	char *word;

	i = isLabel ? isLabel + 2 : 0;
	/* Ignore spaces */
	while(isspace(line[i]))
		i++;

	if (line[i++]=='.')
	{
		word=GetWord(&line[i],' ');
		if(strcmp(word,"extern")==0)
		{
			/* Step over .extern word in line */
			i+=7;
			/* Ignore spaces */
			while(isspace(line[i]))
				i++;

			HandleExtern(&line[i]);
			return 1;
		}
		else if(strcmp(word,"entry")==0)
		{
			i+=6;
			while(isspace(line[i]))
				i++;
			HandleEntry(&line[i],&constInstructionArr[MAX_INSTRUCTION-1]);
			return 1;
		}
		else
		{
			printf("Error! in Line %d  :%s  , illegal command \n", countLine, line);
			SeconnedPhaseSucess=0;
		}
	}
	else
	{
		return 0;
	}
	return 0;
}
示例#7
0
int __cdecl CYahooProto::SendMsg( HANDLE hContact, int flags, const char* pszSrc )
{
	DBVARIANT dbv;
	char *msg;
	int  bANSI;

	bANSI = 0;/*GetByte( "DisableUTF8", 0 );*/

	if (!m_bLoggedIn) {/* don't send message if we not connected! */
		YForkThread( &CYahooProto::im_sendackfail, hContact );
		return 1;
	}

	if (bANSI) 
		/* convert to ANSI */
		msg = ( char* )pszSrc;
	else if ( flags & PREF_UNICODE )
		/* convert to utf8 */
		msg = mir_utf8encodeW(( wchar_t* )&pszSrc[ strlen(pszSrc)+1 ] );
	else if ( flags & PREF_UTF )
		msg = mir_strdup(( char* )pszSrc );
	else
		msg = mir_utf8encode(( char* )pszSrc );

	if (lstrlenA(msg) > 800) {
		YForkThread( &CYahooProto::im_sendackfail_longmsg, hContact );
		return 1;
	}

	if (!DBGetContactSettingString( hContact, m_szModuleName, YAHOO_LOGINID, &dbv)) {
		send_msg(dbv.pszVal, GetWord( hContact, "yprotoid", 0), msg, (!bANSI) ? 1 : 0);

		if (!bANSI)
			mir_free(msg);

		YForkThread( &CYahooProto::im_sendacksuccess, hContact );

		DBFreeVariant(&dbv);
		return 1;
	}

	return 0;
}
示例#8
0
文件: omf.cpp 项目: DinrusGroup/DRC
uint8 SOMFRecordPointer::GetNext(uint32 align) {
   // Get next record. Returns record type, made even. Returns 0 if finished
   // align = alignment after MODEND records = page size. Applies to lib files only
   FileOffset += End + 1;

   // Check if alignment needed
   if (align > 1 && Type2 == OMF_MODEND) {
      // Align after MODEND record in library
      FileOffset = (FileOffset + align - 1) & - (int32)align;
   }
   if (FileOffset >= FileEnd) return 0;          // End of file
   Index = 0;                                    // Start reading record
   Type = GetByte();                             // Get record type
   Type2 = Type;  if (Type2 < OMF_LIBHEAD) Type2 &= ~1; // Make even
   uint16 RecordSize = GetWord();                // Get record size
   End = Index + RecordSize - 1;                 // Point to checksum byte
   if (FileOffset + RecordSize + 3 > FileEnd) err.submit(2301); // Extends beyond end of file
   return Type2;
}
示例#9
0
static  void    BldErrMsg( unsigned int err, char *buffer, va_list args ) {
// Build error message.
    const char          __FAR *char_ptr;
    const unsigned char __FAR *phrase_ptr;
    char                *buff_start;
    unsigned int        word_count;
    unsigned int        index;
    char                chr;
    int                 len;

    phrase_ptr = GetMsg( err );
    word_count = *phrase_ptr & LENGTH_MASK;
    phrase_ptr++;
    buff_start = buffer;
    *buffer = ' ';
    buffer++;
    for( ;; ) {
        index = 0;
        do {
            len = *phrase_ptr;
            index += len;
            ++phrase_ptr;
            --word_count;
        } while( len == 255 );
        char_ptr = GetWord( index );
        len = *(const char __FAR *)char_ptr;
        char_ptr++;
        for( ;; ) {
            chr = *char_ptr;
            char_ptr++;
            if( --len < 0 ) break;
            *buffer = chr;
            buffer++;
        }
        if( word_count == 0 ) break;
#if _CSET != _KANJI
        *buffer = ' ';
        buffer++;
#endif
    }
    *buffer = '\0';
    Substitute( buff_start, buff_start, args );
}
示例#10
0
文件: SCPI.c 项目: Sasha7b9/Osci
//---------------------------------------------------------------------------------------------------------------------------------------------------
bool SCPI_FirstIsInt(uint8 *buffer, int *value, int min, int max)
{
    Word param;
    if (GetWord(buffer, &param, 0))
    {
#ifdef WIN32
        char n[10];
#else
        char n[param.numSymbols + 1];
#endif
        memcpy(n, param.address, param.numSymbols);
        n[param.numSymbols] = '\0';
        if (String2Int(n, value) && *value >= min && *value <= max)
        {
            return true;
        }
    }
    return false;
}
示例#11
0
bool Phrase::operator== (const Phrase &other) const
{
  size_t thisSize = GetSize()
                    ,compareSize = other.GetSize();
  if (thisSize != compareSize) {
    return false;
  }

  for (size_t pos = 0 ; pos < thisSize ; pos++) {
    const Word &thisWord	= GetWord(pos)
                            ,&otherWord	= other.GetWord(pos);
    bool ret = thisWord == otherWord;
    if (!ret) {
      return false;
    }
  }

  return true;
}
示例#12
0
文件: resread.c 项目: mingpen/OpenNT
/*
 *
 * Function GetName,
 *  Copies a name from the OBJ file into the ObjInfo Structure.
 *
 */
void GetName( FILE *infile, TCHAR *szName , DWORD *lSize)
{
    WORD i = 0;

    do
    {

#ifdef RLRES16

        szName[ i ] = GetByte( infile, lSize);

#else

        szName[ i ] = GetWord( infile, lSize);

#endif
    
    } while ( szName[ i++ ] != TEXT('\0') );
}
示例#13
0
// this function looks for portions of the text that can be skipped because it
// begins with a word to ignore or one of its synonyms.
// note that more than one item could match, all should be tried
vector<size_t> CWord_substitution :: GetMatchLens(const string& text, const string& pattern, char prev_char) const
{
    vector<size_t> match_lens;
    size_t len;

    if (!IsSetWord()) {
        // doesn't make sense
    } else if (!NStr::StartsWith(pattern, GetWord(), GetCase_sensitive() ? NStr::eCase : NStr::eNocase)) {
        // no match
    } else if (IsSetSynonyms()) {
        ITERATE(CWord_substitution::TSynonyms, syn, GetSynonyms()) {
            len = (*syn).length();
            if (NStr::StartsWith(text, *syn, GetCase_sensitive() ? NStr::eCase : NStr::eNocase)
                && (!IsSetWhole_word()
                        || (IsWordBoundary(prev_char) && IsWordBoundary(text.c_str()[len])))) {
                // text matches synonym
                match_lens.push_back(len);            
            }
        }
    } else {
//"因子"语法分析
bool KH::GrammarPL0::FactorParsing()
{
	bool result = true;

	switch( GetWord(false).GetSign())
	{
		case KH::_IDENTIFIER://因子可以是一个常量或变量
			Sa.ExistVariable(GetLine(),GetWord(false).GetValue());

			//Gen  ident
			GenPush(GetWord(false).GetValue());
			 skip(1);
			break;

		case KH::_INT:	//因子可以是一个数
		case KH::_FLOAT:
			//Gen  ident
			GenPush(GetWord(false).GetValue());
			 skip(1);
			break;

		case KH::_LPAREN :	//如果看到左括号'('
			//Gen (
			GenPush(" ( ");
			 skip(1);

			if(!ExpressionParsing())
			{
				Error( result," Factor Error , There should be a Expression .");
			}

			if( GetWord(false).GetSign() == KH::_RPAREN)//"表达式"后面应是右括号')'
			{
				//Gen )
				GenPush(" ) ");
				 skip(1);
			}
			else{
				Error( result," Factor Error , There should be a Right Paren : " + GetWord(false).GetValue());
			}

			break;

		default:	
			Error( result," Factor Error , There should be a Factor .");
			break;
	}//End of switch
	return result;
}
示例#15
0
文件: Parser.c 项目: facet42/AberMUD
void SkipPrep(void)		/* Skip any preposition which is next word */
{
	char *a=WordPtr;
	WLIST *b=GetWord();
	if(b==(WLIST *)-1)
	{
		WordPtr=a;
		return;
	}
	if(b==NULL)
	{
		WordPtr=a;
		return;
	}
	if(b->wd_Type!=WD_PREP)
	{
		WordPtr=a;
		return;
	}
}
示例#16
0
/* EXPORT->ReadDict: read and store a dictionary definition */
ReturnStatus ReadDict(char *dictFn, Vocab *voc)
{
   LabId labels[MAXPHONES+4];
   Source src;
   Word word;
   float prob;
   int nphones;
   ReturnStatus ret;

   if(InitSource(dictFn,&src,DictFilter)<SUCCESS){
      HRError(8010,"ReadDict: Can't open file %s", dictFn);
      return(FAIL);
   }
   if (trace&T_TOP)
      printf("\nLoading Dictionary from %s\n",dictFn);
   if((ret=ReadDictWord(&src,labels,&prob, &nphones))<SUCCESS){
      CloseSource(&src);
      HRError(8013,"ReadDict: Dict format error in first entry");
      return(FAIL);
   }
   while(nphones>=0){
      word = GetWord(voc,labels[0],TRUE);
      if (labels[1]==NULL) labels[1]=labels[0];
      if (labels[1]->name[0]==0) labels[1]=NULL;
      if (voc->nullWord->wordName == word->wordName)
         HRError(-8013,"ReadDict: !NULL entry contains pronunciation");
      NewPron(voc,word,nphones,labels+2,labels[1],prob);
      if((ret=ReadDictWord(&src,labels,&prob, &nphones))<SUCCESS){
         HRError(8013,"ReadDict: Dict format error");
         return(FAIL);
      }
   }
   CloseSource(&src);

   if (trace&T_DIC)
      ShowDict(voc);
   if (trace&T_TOP)
      printf("Dictionary loaded from %s with %d words and %d prons\n\n",
             dictFn,voc->nwords,voc->nprons);
   return(SUCCESS);
}
示例#17
0
// This method writes text to the screen in "paragraph" mode, staying within
// the bounds of the window and scrolling the window upward if necessary
void CursWin::WriteText(char* txt, bool ref) {
    char nextWord[100], *temp = txt;
    char blankWord[2] = "";
    if (((strlen(txt)-1) + curColPos) > maxColPos) {
        temp = GetWord(temp,nextWord);
        if (strlen(nextWord) + curColPos > maxColPos) {
            char* t2 = &(nextWord[0]);
            Writes(blankWord,false);
            while ((*t2 == ' ') || (*t2 == '\n') || (*t2 == '\t')) {
                t2++;
            }
            Write(t2,false);
        }
        else Write(nextWord,false);
        WriteText(temp, false);
    }
    else {
        Write(txt, false);
    }
    if (ref) refresh();
}
示例#18
0
文件: Parser.c 项目: facet42/AberMUD
int GetOrd(void)
{
	char *WRem=WordPtr;
	WLIST *a=GetWord();
	if(a==NULL)
	{
		WordPtr=WRem;
		return(1);
	}
	if(a==(WLIST *)-1)
	{
		WordPtr=WRem;
		return(1);
	}
	if(a->wd_Type!=WD_ORDIN)
	{
		WordPtr=WRem;
		return(1);
	}
	return(a->wd_Code);
}
const char* CRichEditSpellCheck::GetNextWord() const
{
	CHARRANGE cr;

	cr.cpMin = m_re.SendMessage(EM_FINDWORDBREAK, WB_RIGHT, m_crCurrentWord.cpMax);
	cr.cpMax = m_re.SendMessage(EM_FINDWORDBREAK, WB_RIGHTBREAK, cr.cpMin + 1);

	GetWord(cr, m_sCurrentWord);
	int nLength = m_sCurrentWord.GetLength();

	if (nLength)
	{
		m_crCurrentWord = cr;

		// if there's any trailing whitespace then trim it off
		m_sCurrentWord.TrimRight(DELIMS);

		// and update char range
		m_crCurrentWord.cpMax -= nLength - m_sCurrentWord.GetLength();
		nLength = m_sCurrentWord.GetLength();

		// if there's any leading whitespace then trim it off
		m_sCurrentWord.TrimLeft(DELIMS);

		// and update char range
		m_crCurrentWord.cpMin += nLength - m_sCurrentWord.GetLength();
		nLength = m_sCurrentWord.GetLength();

		// if there was some text but it was all whitespace, return
		// a non-empty string so that searching is not terminated
		// and move the selection to the end of the whitespace
		if (m_sCurrentWord.IsEmpty())
		{
			m_crCurrentWord.cpMin = m_crCurrentWord.cpMax = cr.cpMax;
			m_sCurrentWord = " ";
		}
	}

	return m_sCurrentWord;
}
示例#20
0
void
GetLogPage::SetNUMD(uint16_t numDW)
{
    uint64_t errLogPgEntries;
    uint64_t numDWAvail;

    LOG_NRM("Setting NUMD 0x%04X", numDW);
    ConstSharedIdentifyPtr idCmdCtrlr = gInformative->GetIdentifyCmdCtrlr();
    errLogPgEntries = idCmdCtrlr->GetValue(IDCTRLRCAP_ELPE);
    numDWAvail = ((errLogPgEntries * ERRINFO_DATA_SIZE) / sizeof(uint32_t));
    if (numDWAvail > numDW) {
        // per the spec this action is undef'd, so don't allow it
        LOG_ERR("Request %d DWORDS > %lld available yields undef'd results",
            numDW, (unsigned long long)numDWAvail);
        throw  exception();
    }

    uint16_t curVal = GetWord(10, 1);
    curVal &= ~NUMD_BITMASK;
    curVal |= (numDW & NUMD_BITMASK);
    SetWord(curVal, 10, 1);
}
示例#21
0
文件: niall.c 项目: Farthen/OTFBot
/* Add the next word on to the end of the buffer
*/
static void StringWord(char *Buffer,int BufSize,WORD *ThisWord)
{
	int nProbs,iProb,total;
	WORD *NextWord;
	ASCN *Assoc;

	/* Randomly select an index for the next word.
	*/
	nProbs = CountProbs(ThisWord);
	if(nProbs<1)
	{
		Niall_Warning("Corrupted brain (Unlinked word).");
		return;
	}

	/* Taken from the rand(3) manual page...
	*/
	iProb = (int)( (float)nProbs*(float)rand() / ((float)RAND_MAX+1.0) );

	/* Find the next word.
	*/
	for(total=0,Assoc=ThisWord->Associations;Assoc;Assoc=Assoc->Next)
	{
		total+=Assoc->Probability;
		if(total>iProb)
		{
			NextWord = GetWord(Assoc->Word);
			if(NextWord != END_SENTENCE)
			{
				if(strlen(Buffer)) safeStrcat(Buffer,BufSize," ");
				safeStrcat(Buffer,BufSize,NextWord->Data);
				StringWord(Buffer,BufSize,NextWord);
				return;
			}
			else return;
		}
	}
	Niall_Warning("Corrupted brain (Loop Overflow).");
}
示例#22
0
bool DTextParser::GetBool( int iCount, bool *pOut1, bool *pOut2, bool *pOut3 )
{
	if( iCount<1 )		return false;
	if( iCount>3 )		iCount=3;

	GetWord( m_TemporaryBuffer, iCount );

	int array[3];
	switch( iCount )
	{
		case 1:
			sscanf( m_TemporaryBuffer, "%d", &array[0] );
			break;
		case 2:
			sscanf( m_TemporaryBuffer, "%d %d", &array[0], &array[1] );
			break;
		case 3:
			sscanf( m_TemporaryBuffer, "%d %d %d", &array[0], &array[1], &array[2] );
			break;
	}

	if( pOut1 )
	{
		if(array[0])	*pOut1 = true;
		else			*pOut1 = false;
	}
	if( pOut2 )
	{
		if(array[1])	*pOut2 = true;
		else			*pOut2 = false;
	}
	if( pOut3 ) 
	{
		if(array[2])	*pOut3 = true;
		else			*pOut3 = false;
	}

	return true;
}
示例#23
0
int Phrase::Compare(const Phrase &other) const
{
#ifdef min
#undef min
#endif
  size_t thisSize			= GetSize()
                        ,compareSize	= other.GetSize();
  if (thisSize != compareSize) {
    return (thisSize < compareSize) ? -1 : 1;
  }

  for (size_t pos = 0 ; pos < thisSize ; pos++) {
    const Word &thisWord	= GetWord(pos)
                            ,&otherWord	= other.GetWord(pos);
    int ret = Word::Compare(thisWord, otherWord);

    if (ret != 0)
      return ret;
  }

  return 0;
}
FX_BOOL CPDF_SimpleParser::FindTagPair(const CFX_ByteStringC& start_token,
                                       const CFX_ByteStringC& end_token,
                                       FX_DWORD& start_pos,
                                       FX_DWORD& end_pos) {
  if (!start_token.IsEmpty()) {
    if (!SkipWord(start_token)) {
      return FALSE;
    }
    start_pos = m_dwCurPos;
  }
  while (1) {
    end_pos = m_dwCurPos;
    CFX_ByteStringC word = GetWord();
    if (word.IsEmpty()) {
      return FALSE;
    }
    if (word == end_token) {
      return TRUE;
    }
  }
  return FALSE;
}
示例#25
0
INT_PTR __cdecl CYahooProto::SendNudge(WPARAM wParam, LPARAM lParam)
{
	HANDLE hContact = (HANDLE) wParam;

	DebugLog("[YAHOO_SENDNUDGE]");

	if (!m_bLoggedIn) {/* don't send nudge if we not connected! */
		YForkThread( &CYahooProto::im_sendackfail, hContact );
		return 1;
	}

	DBVARIANT dbv;
	if (!DBGetContactSettingString(hContact, m_szModuleName, YAHOO_LOGINID, &dbv)) {
		send_msg(dbv.pszVal, GetWord(hContact, "yprotoid", 0), "<ding>", 0);
		DBFreeVariant(&dbv);

		YForkThread( &CYahooProto::im_sendacksuccess, hContact );
		return 1;
	}

	return 0;
}
示例#26
0
文件: Parser.c 项目: facet42/AberMUD
int GetPrep(void)
{
	char *a=WordPtr;
	register WLIST *b;
l1:	b=GetWord();
	if(b==(WLIST *)-1)
	{
		WordPtr=a;
		return(-1);
	}
	if(b==NULL)
		goto l1;	/* Dud word */
	if(b->wd_Type!=WD_PREP)
	{
		b=FindInList(WordList,WordBuffer,WD_PREP);
		if(!b)
		{
			WordPtr=a;
			return(-1);
		}
	}
	return(b->wd_Code);
}
示例#27
0
文件: niall.c 项目: Farthen/OTFBot
/* Add one word to the dictionary.
*/
static int IndexWord(char *Word,int Follows)
{
	WORD *thisWord,*lastWord;
	int wordIndex;

	if(Word != END_SENTENCE)
	{
		thisWord = FindWord(Word);
		if(!thisWord)
		{
			thisWord = AddWord(Word);
			if(!thisWord) Niall_Error("Out of memory.");
		}
		wordIndex = WordIndex(thisWord);	
	}
	else wordIndex = -1;

	lastWord = GetWord(Follows);
	if(!lastWord) Niall_Error("Corrupted brain (Can't find last word).");
	Associate(lastWord,wordIndex);

	return(wordIndex);
}
示例#28
0
int32 ClientAgent::FirstKnownAs(const BString& data, BString& result, bool* me) const
{
	BString myAKA(vision_app->GetString("alsoKnownAs"));

	int32 hit(data.Length()), i, place;
	BString target;

	if ((place = FirstSingleKnownAs(data, fMyNick)) != B_ERROR) {
		result = fMyNick;
		hit = place;
		*me = true;
	}

	for (i = 1; (target = GetWord(myAKA.String(), i)) != "-9z99"; ++i) {
		if ((place = FirstSingleKnownAs(data, target)) != B_ERROR && place < hit) {
			result = target;
			hit = place;
			*me = true;
		}
	}

	return hit < data.Length() ? hit : B_ERROR;
}
示例#29
0
文件: omf.cpp 项目: DinrusGroup/DRC
uint32 SOMFRecordPointer::InterpretLIDATABlock() {
   // Interpret Data block in LIDATA record recursively
   // Prints repeat count and returns total size
   uint32 RepeatCount = GetNumeric();
   uint32 BlockCount  = GetWord();
   uint32 Size = 0;
   printf("%i * ", RepeatCount);
   if (BlockCount == 0) {
      Size = GetByte();
      Index += Size;
      printf("%i", Size);
      return RepeatCount * Size;
   }
   // Nested repeat blocks
   printf("(");
   for (uint32 i = 0; i < BlockCount; i++) {
      // Recursion
      Size += InterpretLIDATABlock();
      if (i+1 < BlockCount) printf(" + ");
   }
   printf(")");
   return RepeatCount * Size;
}
示例#30
0
/**
 * 解包鉴权客户端请求
 */
int ParsePkg(const uint8_t *pPkg, int iPkgLen, tASecMsgHead &stHead, tASecVcClientReq &stReq)
{
	if (iPkgLen <= (int)sizeof(tASecMsgHead)+2)
	{
		return -1;
	}

	if (pPkg[0] != 0x02 ||
		pPkg[iPkgLen-1] != 0x03)
	{
		return -2;
	}

	memcpy(&stHead, pPkg+1, sizeof(stHead));
	Ntoh(&stHead);

	if (stHead.usLength != iPkgLen ||
			MSG_TYPE_VC_CLIENT_REQ != stHead.usMsgType)
	{
		return -3;
	}

	char *pCur = (char*)pPkg+1/*STX*/+sizeof(tASecMsgHead);
	int iLeftLen = iPkgLen-1-sizeof(tASecMsgHead);

	CK_RET(GetWord(&pCur, &iLeftLen, &stReq.usENLen), -4);


	CK_RET(GetFixData(&pCur, &iLeftLen, (char*)stReq.aucEN, stReq.usENLen), -5);

	if (iLeftLen != 1)
	{
		return -6;
	}

	return 0;
}