Пример #1
0
bool TokenName( unsigned token, char **start, unsigned *len )
{
    switch( token ) {
    case T_LINE_SEPARATOR:
        *start = LIT( End_Of_Line );
        *len = strlen( LIT( End_Of_Line ) ) + 1;
        return( TRUE );
    case T_INT_NUM:
    case T_REAL_NUM:
        *start = LIT( Num_Name );
        *len = strlen( LIT( Num_Name ) ) + 1;
        return( TRUE );
    case T_NAME:
        *start = LIT( Sym_Name_Name );
        *len = strlen( LIT( Sym_Name_Name ) ) + 1;
        return( TRUE );
    }
    if( token < LAST_CMDLN_DELIM ) {
        *start = &CmdLnDelimTab[ token - FIRST_CMDLN_DELIM ];
        *len = sizeof( char );
        return( TRUE );
    }
    if( ExprTokens != NULL ) {
        if( FindToken( ExprTokens->delims, token, start, len ) ) return(TRUE);
        if( FindToken( ExprTokens->keywords, token, start, len ) ) return(TRUE);
    }
    return( FALSE );
}
Пример #2
0
void Parser::SearchForEpisodeTitle() {
  auto token_begin = tokens_.begin();
  auto token_end = tokens_.begin();

  do {
    // Find the first non-enclosed unknown token
    token_begin = FindToken(token_end, tokens_.end(),
                            kFlagNotEnclosed | kFlagUnknown);
    if (token_begin == tokens_.end())
      return;

    // Continue until a bracket or identifier is found
    token_end = FindToken(token_begin, tokens_.end(),
                          kFlagBracket | kFlagIdentifier);

    // Ignore if it's only a dash
    if (std::distance(token_begin, token_end) <= 2 &&
        IsDashCharacter(token_begin->content)) {
      continue;
    }

    // Build episode title
    BuildElement(kElementEpisodeTitle, false, token_begin, token_end);
    return;
  } while (token_begin != tokens_.end());
}
Пример #3
0
void Parser::SearchForReleaseGroup() {
  token_container_t::iterator token_begin = tokens_.begin();
  token_container_t::iterator token_end = tokens_.begin();

  do {
    // Find the first enclosed unknown token
    token_begin = FindToken(token_end, tokens_.end(),
                            kFlagEnclosed | kFlagUnknown);
    if (token_begin == tokens_.end())
      return;

    // Continue until a bracket or identifier is found
    token_end = FindToken(token_begin, tokens_.end(),
                          kFlagBracket | kFlagIdentifier);
    if (token_end->category != kBracket)
      continue;

    // Ignore if it's not the first non-delimiter token in group
    token_container_t::iterator previous_token = FindPreviousToken(tokens_, token_begin,
                                            kFlagNotDelimiter);
    if (previous_token != tokens_.end() &&
        previous_token->category != kBracket) {
      continue;
    }

    // Build release group
    BuildElement(kElementReleaseGroup, true, token_begin, token_end);
    return;
  } while (token_begin != tokens_.end());
}
Пример #4
0
void TLexer::Read() {
    char c;
    std::string value = "";
    while (true) {
        c = GetChar();
        if (FileEOF()) {
            break;
        }
        value += c;
        switch (c) {
            case 34: {
                ReadString(value);
                break;
            }

            case 39: {
                ReadSymbol(value);
                break;
            }

            case '.' : {
                FindToken(State_Point, value);
                break;
            }

            case '(': {
                FindToken(State_Lbkt,value);
                break;
            }

            case ')': {
                FindToken(State_Rbkt,value);
                break;
            }
            case '#': {
                ReadSharp(value);
                break;
            }
            default: {
                if (isspecial(c) || isalpha(c)) {
                    ReadIdent(value);
                } else if (isdigit(c)) {
                    ReadNumber(value);
                } else if (IsEndToken(c)) {
                    value.erase(value.size() - 1, value.size());
                }
                break;
            }
        }
    }
    value = "EOF";
    FindToken(State_EOF, value);
}
Пример #5
0
void Parser::SearchForAnimeTitle() {
  bool enclosed_title = false;

  // Find the first non-enclosed unknown token
  token_container_t::iterator token_begin = FindToken(tokens_.begin(), tokens_.end(),
                               kFlagNotEnclosed | kFlagUnknown);

  // If that doesn't work, find the first unknown token in the second enclosed
  // group, assuming that the first one is the release group
  if (token_begin == tokens_.end()) {
    enclosed_title = true;
    token_begin = tokens_.begin();
    bool skipped_previous_group = false;
    do {
      token_begin = FindToken(token_begin, tokens_.end(), kFlagUnknown);
      if (token_begin == tokens_.end())
        break;
      // Ignore groups that are composed of non-Latin characters
      if (IsMostlyLatinString(token_begin->content))
        if (skipped_previous_group)
          break;  // Found it
      // Get the first unknown token of the next group
      token_begin = FindToken(token_begin, tokens_.end(), kFlagBracket);
      token_begin = FindToken(token_begin, tokens_.end(), kFlagUnknown);
      skipped_previous_group = true;
    } while (token_begin != tokens_.end());
  }
  if (token_begin == tokens_.end())
    return;

  // Continue until an identifier (or a bracket, if the title is enclosed)
  // is found
  token_container_t::iterator token_end = FindToken(token_begin, tokens_.end(),
      kFlagIdentifier | (enclosed_title ? kFlagBracket : kFlagNone));

  // If within the interval there's an open bracket without its matching pair,
  // move the upper endpoint back to the bracket
  if (!enclosed_title) {
    token_container_t::iterator last_bracket = token_end;
    bool bracket_open = false;
    for (token_container_t::iterator token = token_begin; token != token_end; ++token) {
      if (token->category == kBracket) {
        last_bracket = token;
        bracket_open = !bracket_open;
      }
    }
    if (bracket_open)
      token_end = last_bracket;
  }

  // Build anime title
  BuildElement(kElementAnimeTitle, false, token_begin, token_end);
}
Пример #6
0
void MenuManager::ParsePageInfo(char* plinePtr, int* menuNumber, int* pageNumber, int* itemNumber)
{	
	(*pageNumber)++;
	*itemNumber = -1;

	char	pdrawColor[20];
	ULONG color;
	char	pseparators[] = {0x20, 0x2c, 0x3d, 0x3b, 0x0d, 0x0a, 0x09, 0x23, 0x00};
	char	*ptoken;

	PageStruct* pPage = &(mpMenus[*menuNumber].mpPages[*pageNumber]);

	#ifdef USE_SH_POOLS
	pPage->mpTitle = (char *)MemAllocPtr(gCockMemPool,sizeof(char)*mMaxTextLen,FALSE);
	#else
	pPage->mpTitle		= new char[mMaxTextLen];
	#endif

	*(pPage->mpTitle)	= '\0';

	ptoken = FindToken(&plinePtr, pseparators);	
	sscanf(ptoken, "%d",  &(pPage->mNumItems));
	ptoken = FindToken(&plinePtr, pseparators);	
	sscanf(ptoken, "%d",  &(pPage->mCondition));
	ptoken = FindToken(&plinePtr, pseparators);	
	sscanf(ptoken, "%s",  pdrawColor);

	*(pPage->mpTitle) = NULL;
	ptoken = FindToken(&plinePtr, pseparators);	
	while(ptoken) {
		strcat(pPage->mpTitle, ptoken);
		ptoken = FindToken(&plinePtr, pseparators);
		if(ptoken) {
			strcat(pPage->mpTitle, " ");
		}
	}

	if(FindMenuColorValue(pdrawColor, &color)) {
		pPage->mDrawColor = color;
	}
	else {
		pPage->mDrawColor = gMenuColorTable[MENU_WHITE].mValue;
	}


	#ifdef USE_SH_POOLS
	pPage->mpItems = (ItemStruct *)MemAllocPtr(gCockMemPool,sizeof(ItemStruct)*pPage->mNumItems,FALSE);
	#else
	pPage->mpItems = new ItemStruct[pPage->mNumItems];
	#endif
}
Пример #7
0
void Parser::SearchForEpisodeTitle() {
  // Find the first non-enclosed unknown token
  token_container_t::iterator token_begin = FindToken(tokens_.begin(), tokens_.end(),
                               kFlagNotEnclosed | kFlagUnknown);
  if (token_begin == tokens_.end())
    return;

  // Continue until a bracket or identifier is found
  token_container_t::iterator token_end = FindToken(token_begin, tokens_.end(),
                             kFlagBracket | kFlagIdentifier);

  // Build episode title
  BuildElement(kElementEpisodeTitle, false, token_begin, token_end);
}
Пример #8
0
L_TOKEN* IDENTIFIER(char*          source,
                    int            start,
                    int            end,
                    int            line,
                    GRAMMAR_TABLE  grammar)
{
    int token;
    L_TOKEN* block = (L_TOKEN*)malloc(sizeof(L_TOKEN));

    token = FindToken(&source[start], end - start, grammar);
    if (token) {
        // token
        block->token = token;
        block->string = source + start;
        block->length = end - start;
        block->line = line;
        block->next = 0;
    } else {
        // identifier
        block->token = gSymbolIdentifier;
        block->string = source + start;
        block->length = end - start;
        block->line = line;
        block->next = 0;
    }

    return block;
}
Пример #9
0
L_TOKEN* TOKEN(char*          source,
               int            start,
               int            end,
               int            line,
               GRAMMAR_TABLE  grammar)
{
    int token;
    L_TOKEN* block = (L_TOKEN*)malloc(sizeof(L_TOKEN));

    token = FindToken(&source[start], end - start, grammar);
    if (token) {
        // token
        block->token = token;
        block->string = source + start;
        block->length = end - start;
        block->line = line;
        block->next = 0;
    } else {
        // identifier
        free(block);
        block = NULL;
        printf("Syntax error on line %i, ", line+1);
        printf("Error, illegal identifier: ");
        while (start < end)
            printf("0x%X", source[start++]);
        printf("\n");
    }

    return block;
}
Пример #10
0
token_iterator_t FindPreviousToken(token_container_t& tokens,
                                   token_iterator_t first,
                                   unsigned int flags) {
  auto it = FindToken(std::reverse_iterator<token_iterator_t>(first),
                       tokens.rend(), flags);
  return it == tokens.rend() ? tokens.end() : (++it).base();
}
Пример #11
0
int StyleSheetParser::Parse(StyleSheetNode* node, Stream* _stream)
{
	int rule_count = 0;
	line_number = 0;
	stream = _stream;
	stream_file_name = stream->GetSourceURL().GetURL().Replace("|", ":");

	// Look for more styles while data is available
	while (FillBuffer())
	{
		String style_names;
		
		while (FindToken(style_names, "{", true))
		{
			// Read the attributes
			PropertyDictionary properties;
			if (!ReadProperties(properties))
			{
				continue;
			}

			StringList style_name_list;
			StringUtilities::ExpandString(style_name_list, style_names);

			// Add style nodes to the root of the tree
			for (size_t i = 0; i < style_name_list.size(); i++)
				ImportProperties(node, style_name_list[i], properties, rule_count);

			rule_count++;
		}
	}	

	return rule_count;
}
Пример #12
0
void pgSettingItem::SetType(const wxString &str)
{
	int index = FindToken(str, pgConfigTypeStrings);
	if (index < 0)
		type = PGC_STRING;
	else
		type = (pgConfigType)index;
}
Пример #13
0
void pgSettingItem::SetContext(const wxString &str)
{
	int index = FindToken(str, pgConfigContextStrings);
	if (index < 0)
		context = PGC_INTERNAL;
	else
		context = (pgConfigContext)index;
}
Пример #14
0
void pgSettingItem::SetSource(const wxString &str)
{
	int index = FindToken(str, pgConfigSourceStrings);
	if (index < 0)
		source = PGC_UNKNOWNSOURCE;
	else
		source = (pgConfigSource)index;
}
Пример #15
0
void TLexer::IsCorrectToken(char c, std::string& value, States state) {
    if (IsEndToken(c)) {
        FindToken(state, value);
    } else {
        value += c;
        throw new ExceptionLexerIncorrectChar(value, PosLine, PosColumn);
    }
}
Пример #16
0
void MenuManager::ParseItemInfo(char* plinePtr, int* menuNumber, int* pageNumber, int* itemNumber)
{
	(*itemNumber)++;

	char	pdrawColor[20];
	ULONG color;
	char	pseparators[] = {0x20, 0x2c, 0x3d, 0x3b, 0x0d, 0x0a, 0x09, 0x23, 0x00};
	char	*ptoken;

	ItemStruct* pItem = &(mpMenus[*menuNumber].mpPages[*pageNumber].mpItems[*itemNumber]);

	#ifdef USE_SH_POOLS
	pItem->mpText = (char *)MemAllocPtr(gCockMemPool,sizeof(char)*mMaxTextLen,FALSE);
	#else
	pItem->mpText		= new char[mMaxTextLen];
	#endif

	*(pItem->mpText)	= '\0';

	ptoken = FindToken(&plinePtr, pseparators);	
	sscanf(ptoken, "%d",  &(pItem->mCondition));
	ptoken = FindToken(&plinePtr, pseparators);	
	sscanf(ptoken, "%d",  &(pItem->mPoll));
	ptoken = FindToken(&plinePtr, pseparators);	
	sscanf(ptoken, "%s",  pdrawColor);
	ptoken = FindToken(&plinePtr, pseparators);	
	sscanf(ptoken, "%f",  &(pItem->mSpacing));
	ptoken = FindToken(&plinePtr, pseparators);	
	sscanf(ptoken, "%d",  &(pItem->mMessage));

	int i = 0;
	while(*plinePtr != '\n' && *plinePtr != NULL) {
		pItem->mpText[i++] = *(plinePtr++);
	}

	pItem->mpText[i] = '\0';

	if(FindMenuColorValue(pdrawColor, &color)) {
		pItem->mNormColor = color;
	}
	else {
		pItem->mNormColor = gMenuColorTable[MENU_WHITE].mValue;
	}
}
Пример #17
0
struct TokenStruct NextToken (char *c) {
	*c = FindToken (*c);
	struct TokenStruct ret;// = malloc (sizeof (struct TokenStruct));
	ret.Token = malloc (sizeof (char) * 2);
	ret.Token[0] = *c;
	ret.type = TokenType (*c);
	ret.priority = OpPriority (*c);
	ret.index = line_index;
	
	int length = 1;
	if (!ret.type) {
		if (*c == '+' || *c == '-' || *c == '*' || *c == '/' || *c == '%' || *c == '^' || *c == '=' || *c == ')' || *c == '(' || *c == ',') {	// Grab next character if we have a valid token
			*c = FindToken (0);
		}
		ret.Token[1] = '\0';
#ifdef DEBUG
		if (ret.Token[0] != '\n') { printf ("	Op/Invalid Token %i: '%s';\n", ret.index, ret.Token); }
		else { printf ("	Op/Invalid Token %i: '\\n';\n", ret.index); }
		sleep (1);
#endif
		return ret;
	}
	
	*c = getchar ();
	AddSpace (*c);
	while (TokenType (*c) == ret.type) {
		ret.Token[length++] = *c;
		if (ECHO) { putchar (*c); }
		ret.Token = realloc (ret.Token, sizeof (char) * (length+1));
		*c = getchar ();
		AddSpace (*c);
	}
	if (ECHO) { putchar (*c); }
	//line_index += length;
	ret.Token[length] = '\0';
	*c = FindToken (*c);
#ifdef DEBUG
	printf ("	Var/Num Token %i: %s;\n", ret.index, ret.Token);
	sleep (1);
#endif
	return ret;
}
Пример #18
0
void MenuManager::ReadDataFile(char* pfileName)
{
	FILE*				pFile;
	BOOL				quitFlag  = FALSE;
	char*				presult = "";
	char*				plinePtr;
	const int		lineLen = MAX_LINE_BUFFER - 1;
	char				plineBuffer[MAX_LINE_BUFFER] = "";
	char				*ptoken;
	char				pseparators[] = {0x20, 0x2c, 0x3d, 0x3b, 0x0d, 0x0a, 0x09, 0x23, 0x00};
	int				menuNumber = -1;
	int				pageNumber = -1;
	int				itemNumber = -1;

	pFile = CP_OPEN(pfileName, "r");
	F4Assert(pFile);

	presult	= fgets(plineBuffer, lineLen, pFile);
	quitFlag	= (presult == NULL);
	plinePtr = plineBuffer;

	while(!quitFlag) {

		if(*plineBuffer == '#') {

			ptoken = FindToken(&plinePtr, pseparators);	

			if(!strcmpi(ptoken, TYPE_MENUMANGER_STR)) {
				ParseManagerInfo(plinePtr);
			}
			else if(!strcmpi(ptoken, TYPE_MENU_STR)) {
				ParseMenuInfo(plinePtr, &menuNumber, &pageNumber);
			}
			else if(!strcmpi(ptoken, TYPE_PAGE_STR)) {
				ParsePageInfo(plinePtr, &menuNumber, &pageNumber, &itemNumber);
			}
			else if(!strcmpi(ptoken, TYPE_ITEM_STR)) {
				ParseItemInfo(plinePtr, &menuNumber, &pageNumber, &itemNumber);
			}
			else if(!strcmpi(ptoken, TYPE_RES_STR)) {
				ParseResInfo(plinePtr, --mResCount);
			}
			else {
				ShiWarning ("Bad String in menu file");
			}
		}
		presult	= fgets(plineBuffer, lineLen, pFile);
		plinePtr = plineBuffer;
		quitFlag	= (presult == NULL);
	}

	CP_CLOSE(pFile);
	ShiAssert(mResCount == 0);	// Bad data in the manager information line!
}
Пример #19
0
void PdfParser::ReadXRef( pdf_long* pXRefOffset )
{
    FindToken( "startxref", PDF_XREF_BUF );

    if( !this->IsNextToken( "startxref" ) )
    {
        PODOFO_RAISE_ERROR( ePdfError_NoXRef );
    }

    *pXRefOffset = this->GetNextNumber();
}
void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
  const CXXConstructorDecl *Ctor =
      Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor");
  // Do not be confused: isExplicit means 'explicit' keyword is present,
  // isImplicit means that it's a compiler-generated constructor.
  if (Ctor->isOutOfLine() || Ctor->isImplicit() || Ctor->isDeleted() ||
      Ctor->getNumParams() == 0 || Ctor->getMinRequiredArguments() > 1)
    return;

  bool takesInitializerList = isStdInitializerList(
      Ctor->getParamDecl(0)->getType().getNonReferenceType());
  if (Ctor->isExplicit() &&
      (Ctor->isCopyOrMoveConstructor() || takesInitializerList)) {
    auto isKWExplicit = [](const Token &Tok) {
      return Tok.is(tok::raw_identifier) &&
             Tok.getRawIdentifier() == "explicit";
    };
    SourceRange ExplicitTokenRange =
        FindToken(*Result.SourceManager, Result.Context->getLangOpts(),
                  Ctor->getOuterLocStart(), Ctor->getLocEnd(), isKWExplicit);
    StringRef ConstructorDescription;
    if (Ctor->isMoveConstructor())
      ConstructorDescription = "move";
    else if (Ctor->isCopyConstructor())
      ConstructorDescription = "copy";
    else
      ConstructorDescription = "initializer-list";

    DiagnosticBuilder Diag =
        diag(Ctor->getLocation(),
             "%0 constructor should not be declared explicit")
        << ConstructorDescription;
    if (ExplicitTokenRange.isValid()) {
      Diag << FixItHint::CreateRemoval(
          CharSourceRange::getCharRange(ExplicitTokenRange));
    }
    return;
  }

  if (Ctor->isExplicit() || Ctor->isCopyOrMoveConstructor() ||
      takesInitializerList)
    return;

  bool SingleArgument =
      Ctor->getNumParams() == 1 && !Ctor->getParamDecl(0)->isParameterPack();
  SourceLocation Loc = Ctor->getLocation();
  diag(Loc,
       "%0 must be marked explicit to avoid unintentional implicit conversions")
      << (SingleArgument
              ? "single-argument constructors"
              : "constructors that are callable with a single argument")
      << FixItHint::CreateInsertion(Loc, "explicit ");
}
Пример #21
0
char const *FindInitialToken(Token *tok, char const *s)
{
    DynamicBuffer buf;
    DBufInit(&buf);

    tok->type = T_Illegal;

    while (isempty(*s)) s++;

    while (*s && !isempty(*s)) {
	if (DBufPutc(&buf, *s++) != OK) return s;
    }

    FindToken(DBufValue(&buf), tok);
    DBufFree(&buf);

    return s;
}
ULONG tScriptState::ReadCommand(CString& s)
{
    char buf[256];
    if (!fgets(buf, sizeof(buf) - 1, f))
    {
        if (feof(f)) s = FindToken(cmdEnd);
        else s = "<Error reading from file>";
    }
    else
    {
        s = buf;
    }
    while (isspace(s[0])) s.Delete(0, 1);
    s.Remove('\n');
    s.Remove('\r');
    currentLine++;
    currentDot = 0;
    strcpy(buf, s);
    return currentCommandIndex++;
}
Пример #23
0
/*
 * Routine: ProcessTypes
 * Purpose: Parse the type vector
 * Algorithm:
 * Data Structures:
 *
 * Params:
 * Returns:
 * Called By:
 * Calls:
 * Assumptions:
 * Side Effects:
 * TODO: None
 */
int
ProcessTypes (char *stmt, token_t * tokens)
{
    char *cp,
         *cp1;
    int nTypeCount = 1,
        nToken,
        i;

    /* get a type count */
    for (cp1 = stmt; (cp1 = strchr (cp1, ',')) != NULL; cp1++)
        nTypeCount += 1;
    pCurrentIndexEntry->dist->type_vector =
        (int *) MALLOC (sizeof (int) * nTypeCount);
    if (pCurrentIndexEntry->dist->type_vector == NULL)
        return (QERR_NO_MEMORY);
    memset(pCurrentIndexEntry->dist->type_vector, 0, sizeof(int) * nTypeCount);

    /* get the type names */
    i = 0;
    while ((cp = strtok (NULL, "=( ,);")) != NULL)
    {
        switch (nToken = FindToken (cp))
        {
        /*
         * NOTE NOTE NOTE NOTE NOTE
         * this is manually sync'd with expr.h values
         * NOTE NOTE NOTE NOTE NOTE
         */
        case TKN_INT:
        case TKN_VARCHAR:
            pCurrentIndexEntry->dist->type_vector[i++] = nToken;
            break;
        default:
            return (QERR_SYNTAX);
        }
    }

    return (nTypeCount);
}
Пример #24
0
void PdfParser::ReadTrailer()
{
    FindToken( "trailer", PDF_XREF_BUF );

    if( !this->IsNextToken( "trailer" ) )
    {
        if( m_ePdfVersion < ePdfVersion_1_5 )
        {
            PODOFO_RAISE_ERROR( ePdfError_NoTrailer );
        }
        else
        {
            // Since PDF 1.5 trailer information can also be found
            // in the crossreference stream object
            // and a trailer dictionary is not required
            m_device.Device()->Seek( m_nXRefOffset );

            m_pTrailer = new PdfParserObject( m_vecObjects, m_device, m_buffer );
            static_cast<PdfParserObject*>(m_pTrailer)->ParseFile( false );
            return;
        }
    }
    else
    {
        m_pTrailer = new PdfParserObject( m_vecObjects, m_device, m_buffer );
        try {
            // Ignore the encryption in the trailer as the trailer may not be encrypted
            static_cast<PdfParserObject*>(m_pTrailer)->ParseFile( NULL, true );
        } catch( PdfError & e ) {
            e.AddToCallstack( __FILE__, __LINE__, "The trailer was found in the file, but contains errors." );
            throw e;
        }
#ifdef PODOFO_VERBOSE_DEBUG
//         PdfError::DebugMessage("Size=%li\n", m_pTrailer->GetDictionary().GetKeyAsLong( PdfName::KeySize, 0 ) );
#endif // PODOFO_VERBOSE_DEBUG
    }
}
Пример #25
0
bool cStrings::UnderstandToken(int token, char *data)
{
	sFlagPair		*FlagPair;

	switch(token)
	{
		case TK_FLAGS:
			while(token != TK_INVALID)
			{
				token = FindToken(data, false);
				for(FlagPair = FlagPairs; FlagPair->Name != TK_INVALID; FlagPair++)
				{
					if (FlagPair->Name == token)
					{
						Flags |= FlagPair->Value;
						break;
					}
				}
			}
			return true;

		case TK_REFERENCE:
			SetReference(data);
			return true;

		case TK_RIGHT_BRACE:
			return false;
	}

	if (token == TK_INVALID)
	{
		return false;
	}

	return true;
}
Пример #26
0
/* handle .model directive
 * syntax: .MODEL <FLAT|TINY|SMALL...> [,<C|PASCAL|STDCALL...>][,<NEARSTACK|FARSTACK>][,<OS_DOS|OS_OS2>]
 * sets fields
 * - ModuleInfo.model
 * - ModuleInfo.language
 * - ModuleInfo.distance
 * - ModuleInfo.ostype
 * if model is FLAT, defines FLAT pseudo-group
 * set default segment names for code and data
 */
ret_code ModelDirective( int i, struct asm_tok tokenarray[] )
/***********************************************************/
{
    enum model_type model;
    enum lang_type language;
    enum dist_type distance;
    enum os_type ostype;
    int index;
    uint_8 init;
    uint_8 initv;

    DebugMsg1(("ModelDirective enter\n"));
    /* v2.03: it may occur that "code" is defined BEFORE the MODEL
     * directive (i.e. DB directives in AT-segments). For FASTPASS,
     * this may have caused errors because contents of the ModuleInfo
     * structure was saved before the .MODEL directive.
     */
    //if( Parse_Pass != PASS_1 ) {
    if( Parse_Pass != PASS_1 && ModuleInfo.model != MODEL_NONE ) {
        /* just set the model with SetModel() if pass is != 1.
         * This won't set the language ( which can be modified by
         * OPTION LANGUAGE directive ), but the language in ModuleInfo
         * isn't needed anymore once pass one is done.
         */
        SetModel();
        return( NOT_ERROR );
    }

    i++;
    if ( tokenarray[i].token == T_FINAL ) {
        EmitError( EXPECTED_MEMORY_MODEL );
        return( ERROR );
    }
    /* get the model argument */
    index = FindToken( tokenarray[i].string_ptr, ModelToken, sizeof( ModelToken )/sizeof( ModelToken[0] ) );
    if( index >= 0 ) {
        if( ModuleInfo.model != MODEL_NONE ) {
            EmitWarn( 2, MODEL_DECLARED_ALREADY );
            return( NOT_ERROR );
        }
        model = index + 1;
        i++;
    } else {
        EmitErr( SYNTAX_ERROR_EX, tokenarray[i].string_ptr );
        return( ERROR );
    }

    /* get the optional arguments: language, stack distance, os */
    init = 0;
    while ( i < ( Token_Count - 1 ) && tokenarray[i].token == T_COMMA ) {
        i++;
        if ( tokenarray[i].token != T_COMMA ) {
            if ( GetLangType( &i, tokenarray, &language ) == NOT_ERROR ) {
                initv = INIT_LANG;
            } else {
                index = FindToken( tokenarray[i].string_ptr, ModelAttr, sizeof( ModelAttr )/sizeof( ModelAttr[0] ) );
                if ( index < 0 )
                    break;
                initv = ModelAttrValue[index].init;
                switch ( initv ) {
                case INIT_STACK:
                    if ( model == MODEL_FLAT ) {
                        EmitError( INVALID_MODEL_PARAM_FOR_FLAT );
                        return( ERROR );
                    }
                    distance = ModelAttrValue[index].value;
                    break;
                case INIT_OS:
                    ostype = ModelAttrValue[index].value;
                    break;
                }
                i++;
            }
            /* attribute set already? */
            if ( initv & init ) {
                i--;
                break;
            }
            init |= initv;
        }
    }
    /* everything parsed successfully? */
    if ( tokenarray[i].token != T_FINAL ) {
        EmitErr( SYNTAX_ERROR_EX, tokenarray[i].tokpos );
        return( ERROR );
    }

    if ( model == MODEL_FLAT ) {
        if ( ( ModuleInfo.curr_cpu & P_CPU_MASK) < P_386 ) {
            EmitError( INSTRUCTION_OR_REGISTER_NOT_ACCEPTED_IN_CURRENT_CPU_MODE );
            return( ERROR );
        }
        DefineFlatGroup();
    }

    ModuleInfo.model = model;
    if ( init & INIT_LANG ) {
        ModuleInfo.langtype = language;
#if AMD64_SUPPORT
        /* v2.03: set header and fastcall type to win64 if x64 is active.
         * This is rather hackish, but currently there's no other possibility
         * to enable the win64 ABI from the source.
         */
        if ( ( ModuleInfo.curr_cpu & P_CPU_MASK ) == P_64 )
            if ( language == LANG_FASTCALL &&
                model == MODEL_FLAT &&
                Options.output_format != OFORMAT_ELF ) {
                DebugMsg(("ModelDirective: FASTCALL type set to WIN64\n"));
                ModuleInfo.header_format = HFORMAT_WIN64;
                ModuleInfo.fctype = FCT_WIN64;
            }
#endif
    }
    if ( init & INIT_STACK )
        ModuleInfo.distance = distance;
    if ( init & INIT_OS )
        ModuleInfo.ostype = ostype;

    SetModelDefaultSegNames();
    SetModel();

    return( NOT_ERROR );
}
Пример #27
0
// GetNext
bool COpcTextReader::GetNext(COpcText& cToken)
{
    // no more data to get - give up
    if (m_uEndOfData == 0)
    {
        return false;
    }

    // find the token
    if (!FindToken(cToken))
    {
        return false;
    }     

    // all done if token is not being extracted.
    if (cToken.GetNoExtract())
    {
        return true;
    }

    UINT uEndOfToken = cToken.GetEnd() + 1;
    UINT uDataLeft   = m_uEndOfData - uEndOfToken;
  
    // extract the delimiter if extracting token.

    // new line delimiter found.
    if (cToken.GetNewLine())
    {
        if (cToken.GetDelimChar() == _T('\r'))
        {
            uEndOfToken += 2;
            uDataLeft   -= 2;
        }

        else
        {
            uEndOfToken += 1;
            uDataLeft   -= 1;
        }
    }

    // specific delimiter found.
    else if (cToken.GetDelimChar() > 0 && !cToken.GetEof())
    {
        uEndOfToken++;
        uDataLeft--;
    }

    // move leftover data to the start of the buffer
    for (UINT ii = 0; ii < uDataLeft; ii++)
    {
        m_szBuf[ii] = m_szBuf[uEndOfToken+ii];
    }

    m_szBuf[ii]  = L'\0';
    m_uEndOfData = uDataLeft;

	// set EOF flag if no data left in buffer.
	if (m_uEndOfData == 0)
	{
		cToken.SetEof();
	}
    
    return true;
}
Пример #28
0
/************************************************************************************************
 * GetLine
 *
 * inputs:
 *
 * return:
 *
 ************************************************************************************************/
void GetLine(char *&Data, int &Size, int &token, char *&data)
{
	static char		save_data[8192];
	char			temp_data[8192];
	char			*test_token, *pos;

	save_data[0] = 0;
	token = TK_INVALID;
	data = save_data;

	if (!ReadData(Data, Size, temp_data, sizeof(temp_data)))
	{
		return;
	}

//	strcpy(temp_data, "   DATA \"test of the data\ntest test\ndfa dfd");
//	strcpy(temp_data, "   DATA");

	pos = temp_data;
	while((*pos) && strchr(" \n\r", *pos))
	{	// remove white space
		pos++;
	}
	test_token = pos;

	while((*pos) && !strchr(" \n\r", *pos))
	{	// scan until end of white space
		pos++;
	}

	if ((*pos))
	{
		*pos = 0;
		pos++;
	}
	token = FindToken(test_token, true);
	
	while((*pos) && strchr(" \n\r", *pos))
	{	// remove white space
		pos++;
	}

	if ((*pos) == '\"')
	{
		pos++;
		test_token = save_data;
		memset(save_data, 0, sizeof(save_data));
		
		while(((*pos) != '\"' || !strchr("\n\r", (*(pos+1)))) && (*pos))
		{
			if ((*pos) == '\\' && (*(pos+1)) == 'n')
			{
#ifdef _STRIPED_
				*test_token = '\r';
				test_token++;
#endif
				*test_token = '\n';
				test_token++;
				pos+=2;
				continue;
			}

			*test_token = *pos;
			test_token++;
			pos++;
		}

		if ((*pos) == '\"')
		{
			*pos = 0;
		}
	}
	else
	{
		test_token = pos;
		while((*pos) && !strchr("\n\r", *pos))
		{	// scan until end of white space
			pos++;
		}
		*pos = 0;

		strcpy(save_data, test_token);
	}
}
Пример #29
0
void pgHbaConfigLine::Init(const wxString &line)
{
	connectType = PGC_INVALIDCONF;
	changed = false;

	if (line.IsEmpty())
		return;

	text = line;

	const wxChar *p0 = line.c_str();

	if (*p0 == '#')
	{
		isComment = true;
		p0++;
		SkipSpace(p0);
	}
	else
		isComment = false;


	const wxChar *p1 = p0;
	SkipNonspace(p1);

	wxString str = line.Mid(p0 - line.c_str(), p1 - p0);

	int i = FindToken(str, pgHbaConnectTypeStrings);

	if (i >= 0)
		connectType = (pgHbaConnectType)i;
	else
	{
		connectType = PGC_INVALIDCONF;
		isComment = true;
		return;
	}

	SkipSpace(p1);

	const wxChar *p2 = p1;
	bool quoted = false;

	while (*p2)
	{
		if (!quoted && IsSpaceChar(*p2))
			break;
		if (*p2 == '"')
			quoted = !quoted;
		p2++;
	}

	database = line.Mid(p1 - line.c_str(), p2 - p1);

	SkipSpace(p2);

	const wxChar *p3 = p2;

	quoted = false;
	while (*p3)
	{
		if (!quoted && IsSpaceChar(*p3))
			break;
		if (*p3 == '"')
			quoted = !quoted;
		p3++;
	}

	user = line.Mid(p2 - line.c_str(), p3 - p2);

	SkipSpace(p3);

	const wxChar *p4 = p3;

	if (connectType == PGC_LOCAL)
	{
		// no ip address
	}
	else
	{
		bool hasCidr = false;
		while (*p4 && !IsSpaceChar(*p4))
		{
			if (*p4 == '/')
				hasCidr = true;
			p4++;
		}
		if (!hasCidr)
		{
			SkipSpace(p4);
			SkipNonspace(p4);
		}

		ipaddress = line.Mid(p3 - line.c_str(), p4 - p3);
		SkipSpace(p4);
	}

	const wxChar *p5 = p4;
	SkipNonspace(p5);

	str = line.Mid(p4 - line.c_str(), p5 - p4);

	i = FindToken(str, pgHbaMethodStrings);

	if (i >= 0)
		method = (pgHbaMethod)i;
	else
	{
		connectType = PGC_INVALIDCONF;
		isComment = true;
		return;
	}
	SkipSpace(p5);
	option = p5;
}
Пример #30
0
// nsIStreamListener implementation
NS_IMETHODIMP
nsMultiMixedConv::OnDataAvailable(nsIRequest *request, nsISupports *context,
                                  nsIInputStream *inStr, uint64_t sourceOffset,
                                  uint32_t count) {
    nsresult rv = NS_OK;
    AutoFree buffer(nullptr);
    uint32_t bufLen = 0, read = 0;

    NS_ASSERTION(request, "multimixed converter needs a request");

    nsCOMPtr<nsIChannel> channel = do_QueryInterface(request, &rv);
    if (NS_FAILED(rv)) return rv;

    // fill buffer
    {
        bufLen = count + mBufLen;
        NS_ENSURE_TRUE((bufLen >= count) && (bufLen >= mBufLen),
                       NS_ERROR_FAILURE);
        buffer = (char *) malloc(bufLen);
        if (!buffer)
            return NS_ERROR_OUT_OF_MEMORY;

        if (mBufLen) {
            // incorporate any buffered data into the parsing
            memcpy(buffer, mBuffer, mBufLen);
            free(mBuffer);
            mBuffer = 0;
            mBufLen = 0;
        }
        
        rv = inStr->Read(buffer + (bufLen - count), count, &read);

        if (NS_FAILED(rv) || read == 0) return rv;
        NS_ASSERTION(read == count, "poor data size assumption");
    }

    char *cursor = buffer;

    if (mFirstOnData) {
        // this is the first OnData() for this request. some servers
        // don't bother sending a token in the first "part." This is
        // illegal, but we'll handle the case anyway by shoving the
        // boundary token in for the server.
        mFirstOnData = false;
        NS_ASSERTION(!mBufLen, "this is our first time through, we can't have buffered data");
        const char * token = mToken.get();

        PushOverLine(cursor, bufLen);

        bool needMoreChars = bufLen < mTokenLen + 2;
        nsAutoCString firstBuffer(buffer, bufLen);
        int32_t posCR = firstBuffer.Find("\r");

        if (needMoreChars || (posCR == kNotFound)) {
            // we don't have enough data yet to make this comparison.
            // skip this check, and try again the next time OnData()
            // is called.
            mFirstOnData = true;
        } else if (mPackagedApp) {
            // We need to check the line starts with --
            if (!StringBeginsWith(firstBuffer, NS_LITERAL_CSTRING("--"))) {
                return NS_ERROR_FAILURE;
            }

            // If the boundary was set in the header,
            // we need to check it matches with the one in the file.
            if (mTokenLen &&
                !StringBeginsWith(Substring(firstBuffer, 2), mToken)) {
                return NS_ERROR_FAILURE;
            }

            // Save the token.
            if (!mTokenLen) {
                mToken = nsCString(Substring(firstBuffer, 2).BeginReading(),
                                   posCR - 2);
                mTokenLen = mToken.Length();
            }

            cursor = buffer;
        } else if (!PL_strnstr(cursor, token, mTokenLen + 2)) {
            char *newBuffer = (char *) realloc(buffer, bufLen + mTokenLen + 1);
            if (!newBuffer)
                return NS_ERROR_OUT_OF_MEMORY;
            buffer = newBuffer;

            memmove(buffer + mTokenLen + 1, buffer, bufLen);
            memcpy(buffer, token, mTokenLen);
            buffer[mTokenLen] = '\n';

            bufLen += (mTokenLen + 1);

            // need to reset cursor to the buffer again (bug 100595)
            cursor = buffer;
        }
    }

    char *token = nullptr;

    // This may get initialized by ParseHeaders and the resulting
    // HttpResponseHead will be passed to nsPartChannel by SendStart

    if (mProcessingHeaders) {
        // we were not able to process all the headers
        // for this "part" given the previous buffer given to 
        // us in the previous OnDataAvailable callback.
        bool done = false;
        rv = ParseHeaders(channel, cursor, bufLen, &done);
        if (NS_FAILED(rv)) return rv;

        if (done) {
            mProcessingHeaders = false;
            rv = SendStart(channel);
            if (NS_FAILED(rv)) return rv;
        }
    }

    int32_t tokenLinefeed = 1;
    while ( (token = FindToken(cursor, bufLen)) ) {

        if (((token + mTokenLen) < (cursor + bufLen)) &&
            (*(token + mTokenLen + 1) == '-')) {
            // This was the last delimiter so we can stop processing
            rv = SendData(cursor, LengthToToken(cursor, token));
            if (NS_FAILED(rv)) return rv;
            if (mPartChannel) {
                mPartChannel->SetIsLastPart();
            }
            return SendStop(NS_OK);
        }

        if (!mNewPart && token > cursor) {
            // headers are processed, we're pushing data now.
            NS_ASSERTION(!mProcessingHeaders, "we should be pushing raw data");
            rv = SendData(cursor, LengthToToken(cursor, token));
            bufLen -= token - cursor;
            if (NS_FAILED(rv)) return rv;
        }
        // XXX else NS_ASSERTION(token == cursor, "?");
        token += mTokenLen;
        bufLen -= mTokenLen;
        tokenLinefeed = PushOverLine(token, bufLen);

        if (mNewPart) {
            // parse headers
            mNewPart = false;
            cursor = token;
            bool done = false; 
            rv = ParseHeaders(channel, cursor, bufLen, &done);
            if (NS_FAILED(rv)) return rv;
            if (done) {
                rv = SendStart(channel);
                if (NS_FAILED(rv)) return rv;
            }
            else {
                // we haven't finished processing header info.
                // we'll break out and try to process later.
                mProcessingHeaders = true;
                break;
            }
        }
        else {
            mNewPart = true;
            // Reset state so we don't carry it over from part to part
            mContentType.Truncate();
            mContentLength = UINT64_MAX;
            mContentDisposition.Truncate();
            mIsByteRangeRequest = false;
            mByteRangeStart = 0;
            mByteRangeEnd = 0;
            
            rv = SendStop(NS_OK);
            if (NS_FAILED(rv)) return rv;
            // reset the token to front. this allows us to treat
            // the token as a starting token.
            token -= mTokenLen + tokenLinefeed;
            bufLen += mTokenLen + tokenLinefeed;
            cursor = token;
        }
    }

    // at this point, we want to buffer up whatever amount (bufLen)
    // we have leftover. However, we *always* want to ensure that
    // we buffer enough data to handle a broken token.

    // carry over
    uint32_t bufAmt = 0;
    if (mProcessingHeaders)
        bufAmt = bufLen;
    else if (bufLen) {
        // if the data ends in a linefeed, and we're in the middle
        // of a "part" (ie. mPartChannel exists) don't bother
        // buffering, go ahead and send the data we have. Otherwise
        // if we don't have a channel already, then we don't even
        // have enough info to start a part, go ahead and buffer
        // enough to collect a boundary token.
        if (!mPartChannel || !(cursor[bufLen-1] == nsCRT::LF) )
            bufAmt = std::min(mTokenLen - 1, bufLen);
    }

    if (bufAmt) {
        rv = BufferData(cursor + (bufLen - bufAmt), bufAmt);
        if (NS_FAILED(rv)) return rv;
        bufLen -= bufAmt;
    }

    if (bufLen) {
        rv = SendData(cursor, bufLen);
        if (NS_FAILED(rv)) return rv;
    }

    return rv;
}