void createOutputFile(FILE* input, FILE* output, MacroTable* table ){ char* instruc = (char*)calloc(100,sizeof(char)); char* prev= (char*)calloc(100,sizeof(char)); char* parameter= (char*)calloc(100,sizeof(char)); char* oper = (char*)calloc(100,sizeof(char)); int index=-1; while(fscanf(input,"%s",instruc) > 0){ // If the operation with its operand is found, its mnemonic and operand is printed if(IsKeyword(instruc)==2){ fscanf(input,"%s",oper); strcat(instruc," "); strcat(instruc,oper); fprintf(output,"%s\n",instruc); } // If the operation without any operand is found, its mnemonic is printed if(IsKeyword(instruc)==1){ fprintf(output,"%s\n",instruc); } // finds a macro definition, and ignores its definition if(IsLabel(instruc)==1){ remove2P(instruc); if(isMacro(table,instruc)==1||isMacro(table,instruc)==2){//find a macro definition while(strcmp(instruc,"ENDMACRO")!=0){ fscanf(input,"%s",instruc);//ignores its definition } } else{ //if is label: strcat(instruc,":"); fprintf(output,"%s ",instruc); } } // prints macro whithout parameter in the output file if(isMacro(table,instruc)==1){ PrintMacroTableInFile(output,table, findLabelName(table,instruc)); } // prints macro with parameter if(isMacro(table,instruc)==2){ fscanf(input,"%s",parameter); PrintMacroTableInFileParameter(output,table, findLabelName(table,instruc),parameter); } } }
static void getText( ss_block *ss_new, char *start ) { char *text = start + 1; char save_char; bool isKeyword; while( isalnum( *text ) || (*text == '_') ) { text++; } save_char = *text; *text = '\0'; isKeyword = IsKeyword( start, false ); *text = save_char; // Expect a double regular expression after s, tr, and y. if( text - start == 1 && (*start == 's' || *start == 'y') ) { flags.doubleRegExp = true; } else if( text - start == 2 && *start == 't' && *(start + 1) == 'r' ) { flags.doubleRegExp = true; } else { flags.doubleRegExp = false; } flags.beforeRegExp = isKeyword; ss_new->type = SE_IDENTIFIER; if( isKeyword ) { ss_new->type = SE_KEYWORD; } else if( *text == ':' && firstNonWS == start && *(text + 1) != ':' && *(text + 1) != '>' ) { // : and > checked as it may be :: (CPP) operator or :> (base op.) text++; ss_new->type = SE_JUMPLABEL; } ss_new->len = text - start; }
static void getText( ss_block *ss_new, char *start ) { char *text = start + 1; char save_char; // gather up symbol while( isalnum( *text ) || (*text == '_') ) { text++; } ss_new->type = SE_IDENTIFIER; // see if symbol is a keyword if( flags.inGMLKeyword ) { save_char = *text; *text = '\0'; if( IsKeyword( start, TRUE ) ) { ss_new->type = SE_KEYWORD; } *text = save_char; // only check first word after a ":" (should check all tokens?) flags.inGMLKeyword = FALSE; } ss_new->len = text - start; }
static void getPreproc( ss_block *ss_new, char *start ) { char *text = start + 1; char *keyword; char save_char; // whitespace is allowed after '!' while( isspace( *text ) ) { text++; } keyword = text; // gather up symbol while( isalpha( *text ) ) { text++; } ss_new->type = SE_IDENTIFIER; // see if symbol is a keyword save_char = *text; *text = '\0'; if( IsKeyword( keyword, true ) ) { ss_new->type = SE_PREPROCESSOR; flags.inPreproc = false; } *text = save_char; ss_new->len = text - start; }
const char* cTokenizer::ParseLabel(const char* strLine) { std::string strBuffer; const char* strCrsr = strLine+1; while(char c = *strCrsr++) { if(!isalpha(c) && !isdigit(c) && c != '_') break; } int iLen = strCrsr - strLine - 1; strBuffer.assign(strLine, iLen); int kw = IsKeyword(strBuffer.c_str()); if (kw != m_nUnkownKeyword) { PushKeyword(kw); } else { PushToken(TOKEN_LABEL, strLine, iLen); } return strCrsr-1; }
void RCFile::NeedBegin() { if (!IsKeyword() || (GetToken()->GetKeyword() != Lexer::openbr && GetToken()->GetKeyword() != Lexer::BEGIN)) { throw new std::runtime_error("Begin expected"); } NextToken(); }
unsigned RCFile::GetTokenId() { unsigned rv = 0; if (IsKeyword()) { rv = GetToken()->GetKeyword(); NextToken(); } return rv; }
void ReadFromFile(FILE* input,MacroTable* table){ char* instruc = (char*)calloc(100,sizeof(char)); char* prev= (char*)calloc(100,sizeof(char)); char* oper = (char*)calloc(100,sizeof(char)); MacroSymbols* macro; //READING MACROS AND CREATING TABLES while(fscanf(input,"%s",instruc) > 0){ if(strcmp(instruc,"BEGINMACRO")!=0){ strcpy(prev,instruc); } else { //creates macro with its name (prev) //remove ":" from the macro name remove2P(prev); macro = createMacroSymbols(prev); while(strcmp(instruc,"ENDMACRO")!=0){ fscanf(input,"%s",instruc); //macro with parameter if(IsKeyword(instruc)==0){ strcpy(macro->parameter_,instruc); macro->has_parameter_=1; } else { //check if theres an operand to insert in table if(IsKeyword(instruc)==2 &&(strcmp(instruc,"ENDMACRO")!=0)){ fscanf(input,"%s",oper); insertInstrucInTable(macro,instruc,oper); } else if(strcmp(instruc,"ENDMACRO")!=0) { strcpy(oper,"\0"); macro->has_parameter_=0; insertInstrucInTable(macro,instruc,oper); } } } insertInMacroTable(table,macro); } } PrintTable(table); }
/** * Function name IsIdentifier * Description checks whether String is an st identifier * @param CString String * @return BOOL * @exception - * @see - */ BOOL IsIdentifier(CString String) { if (String.IsEmpty()) // 1 { return FALSE; } if (IsKeyword(String)) { return FALSE; } if (String.Find(_T("__")) != -1) // 2 { // "__" is not allowed within an identifier. return FALSE; } int StringLength = String.GetLength(); ASSERT(StringLength > 0); // owing to 1 const int StartIndex = 0; _TCHAR c = String.GetAt(StartIndex); if (!_istalpha(c) && !((c == _T('_')) && (StringLength > 1))) { // First char is not a-z or A-Z and // first char is not '_'-and-followed-by-an-other-char. // ('_' is no valid identifier. // String.GetAt(StartIndex + 1) does not equal '_' due to 2.) return FALSE; } for (int i = StartIndex + 1; i < StringLength; i++) { c = String.GetAt(i); if ((!_istalnum(c)) && (c != _T('_'))) { // String contains a char which is not a-z, A-Z, 0-9, or '_', return FALSE; } } return TRUE; }
DDSString be_CppName::ConvertToCpp (const DDSString & idlName) { DDSString result = idlName; // This next bit of code initializes the string for // iostreams that require it. if (result.length() == 0) { result = ""; } if (IsKeyword(idlName)) { result = "_cxx_" + idlName; } return result; }
static void getDirective( ss_block *ss_new, char *start ) { char *text = start + 1; char save_char; // gather up symbol while( isalpha( *text ) ) { text++; } ss_new->type = SE_IDENTIFIER; // see if symbol is a keyword save_char = *text; *text = '\0'; if( IsKeyword( start + 1, true ) ) { ss_new->type = SE_KEYWORD; } *text = save_char; ss_new->len = text - start; }
static void getText( ss_block *ss_new, char *start ) { char keyword[MAX_INPUT_LINE + 1]; char *text = start; int index = 0; // eliminate leading spaces while( isspace( *text ) ) { text++; } // take copy string up to first white space while( isalnum( *text ) || (*text == '_') || (*text == '$') ) { keyword[index++] = toupper( *text ); text++; } keyword[index] = '\0'; // test if string is keyword if( IsKeyword( keyword, true ) ) { char *end = text; ss_new->type = SE_KEYWORD; // attempt to find a "*" associated with type while( isspace( *text ) ) { text++; } if( *text == '*' ) { text++; } else { text = end; } } else { ss_new->type = SE_IDENTIFIER; } ss_new->len = text - start; }
static void getText( ss_block *ss_new, char *start ) { char *text = start + 1; char save_char; bool isKeyword; while( isalnum( *text ) || *text == '_' || *text == '.' ) { text++; } save_char = *text; *text = '\0'; isKeyword = IsKeyword( start, false ); *text = save_char; ss_new->type = SE_IDENTIFIER; if( isKeyword ) { ss_new->type = SE_KEYWORD; } else if( text[0] == ':' && firstNonWS == start && text[1] != ':' && text[1] != '>' ) { // : and > checked as it may be :: (CPP) operator or :> (base op.) text++; ss_new->type = SE_JUMPLABEL; } ss_new->len = text - start; }
void RCFile::NeedEnd() { if (!IsKeyword() || (GetToken()->GetKeyword() != Lexer::closebr && GetToken()->GetKeyword() != Lexer::END)) throw new std::runtime_error("End expected"); NextToken(); }
static int _object_get_callback(Jsi_Tree *tree, Jsi_TreeEntry *hPtr, void *data) { Jsi_Value *v; objwalker *ow = data; Jsi_DString *dStr = ow->dStr; int len; char *str; if ((hPtr->f.bits.dontenum)) return JSI_OK; v = Jsi_TreeValueGet(hPtr); if ((ow->quote&JSI_OUTPUT_JSON) && v && v->vt == JSI_VT_UNDEF) return JSI_OK; str = Jsi_TreeKeyGet(hPtr); char *cp = Jsi_DSValue(dStr); len = Jsi_DSLength(dStr); if (len>=2 && cp[len-2] != '{') Jsi_DSAppend(dStr, ", ", NULL); if (((ow->quote&JSI_OUTPUT_JSON) == 0 || (ow->quote&JSI_JSON_STRICT) == 0) && IsAlnum(str) && !IsKeyword(tree->interp, str)) Jsi_DSAppend(dStr, str, NULL); else /* JSON/spaces, etc requires quoting the name. */ Jsi_DSAppend(dStr, "\"", str, "\"", NULL); Jsi_DSAppend(dStr, ":", NULL); ow->depth++; jsiValueGetString(tree->interp, v, dStr, ow); ow->depth--; return JSI_OK; }
void PythonSyntax::Highlight(const wchar *start, const wchar *end, HighlightOutput& hls, CodeEditor *editor, int line, int pos) { InitKeywords(); bool isComment = false; bool isStr = false; char strOpening; const wchar* p = start; while(p < end) { if((*p == '#' || isComment) && !isStr) { isComment = true; hls.Put(hl_style[INK_COMMENT]); } else if(*p == '\'' || *p == '\"' || isStr) { hls.Put(hl_style[INK_CONST_STRING]); if((*p == '\'' || *p == '\"') && p - 1 != start && *(p - 1) != '\\') if (!isStr || strOpening == *p) { isStr = !isStr; strOpening = (char)*p; } } else if(IsSeparator(p) || p == start) { WString w; bool isW = false; const wchar* bp = (p == start && !IsSeparator(p)) ? p : p + 1; while (bp != end && !IsSeparator(bp)) w += *bp++; bool isPutted = false; if(IsSeparator(p)) { hls.Put(hl_style[INK_NORMAL]); isPutted = true; } if(IsKeyword(w)) { hls.Put(w.GetLength(), hl_style[INK_KEYWORD]); isW = true; } else if(IsSpecialVar(w)) { hls.Put(w.GetLength(), hl_style[INK_UPP]); isW = true; } else if(IsNumber(w)) { hls.Put(w.GetLength(), hl_style[INK_CONST_INT]); isW = true; } if(isW) { p += w.GetLength() - (isPutted ? 0 : 1); } } else hls.Put(hl_style[INK_NORMAL]); p++; } }
int ParseLine( LPCLASSDATA lpcd, int nInBlock, TCHAR *pcText, int nLength, SYNTAX_COLOR *scColors, int *lpnBlocks, int nNumBlocks, int nLine ) { LPPARSER lpp = Parser; LPKEYHASH lpHash; LPBLOCK lpBlock; COLORREF crText = Parser->crColors[ CARR_TEXT ]; int nIndex = 0, nBlock = 0, nSize, i, nMatchX1 = 0, nMatchX2 = 0; BOOL bContinue = FALSE, bStartOfLine = TRUE, bHasInit = FALSE; int nHyperLength; // Modified by Stephan (2005-06-12) // To allow unquoted paths with space like c:\program files /* * Compute match columns. */ if ( lpcd->ptBracket1.y >= 0 ) nMatchX1 = CaretOffsetLine( lpcd, lpcd->ptBracket1.y, lpcd->ptBracket1.x ); if ( lpcd->ptBracket2.y >= 0 ) nMatchX2 = CaretOffsetLine( lpcd, lpcd->ptBracket2.y, lpcd->ptBracket2.x ); /* * Any text to parse? */ if ( nLength == 0 ) /* * Return the block we are in. */ return nInBlock; /* * Start with a normal text * color block... */ if ( scColors ) { /* * Enough text blocks? */ CHECK_BLOCKS; scColors[ nBlock ].nColumn = nLength; scColors[ nBlock ].crColor = crText; scColors[ nBlock ].crBgColor = CLR_DEFAULT; scColors[ nBlock ].pHash = NULL; scColors[ nBlock ].wFlags = 0; } /* * Parser active? */ if ( lpp == NULL ) { /* * A single text color block. */ *lpnBlocks = 1; return -1; } /* * Are we in a block? */ if ( nInBlock != -1 ) { /* * Get the block. */ lpBlock = ArrayGetAt( lpp->lpaBlocks, nInBlock ); /* * Setup the color. */ if ( scColors ) { /* * Enough text blocks? */ CHECK_BLOCKS; scColors[ nBlock ].nColumn = nLength; scColors[ nBlock ].crColor = lpBlock->crColor; scColors[ nBlock ].crBgColor = lpBlock->crBgColor; scColors[ nBlock ].pHash = NULL; scColors[ nBlock ].wFlags = 0; } /* * End the block with a string? */ if ( lpBlock->nEnd ) { /* * See if the terminator string occures * on the line. */ LPCTSTR pszStr = ( lpp->bCaseOn ? StrStr : StrStrI )( pcText, lpBlock->pszEnd ); /* * Terminator found? */ if( pszStr == NULL ) { /* * Are we parsing hyperlinks? */ if ( Parser->bParseHyperLinks && scColors && lpnBlocks ) { /* * Find all hyperlinks in the line starting * at offset 'nIndex'. */ *lpnBlocks = FindHyperlinksInBlock( lpcd, pcText, nIndex, nLength, 0, nNumBlocks, lpnBlocks, scColors ) + 1; scColors[ *lpnBlocks - 1 ].nColumn = nLength; } else if ( lpnBlocks ) /* * Uses a single block. */ *lpnBlocks = 1; /* * Remain in the text block. */ return nInBlock; } else if ( Parser->bParseHyperLinks && scColors && lpnBlocks ) /* * Find all hyperlinks from offset 'nIndex' * up to the block end marker. */ nBlock = FindHyperlinksInBlock( lpcd, pcText, nIndex, ( int )( pszStr - pcText ), 0, nNumBlocks, lpnBlocks, scColors ); /* * Skip to the index at which * the terminator was found. */ nIndex = ( int )( pszStr - pcText ); } } else { /* * If we are not yet inside a block we determine * if any of the block initiators occure in this * line and, if so, at which offset. */ for ( i = 0; ; i++ ) { /* * Get the block. */ lpBlock = ArrayGetAt( lpp->lpaBlocks, i ); /* * Done? */ if ( lpBlock == NULL ) break; /* * By default this block initiator is not on * this line. */ lpBlock->bInLine = FALSE; /* * Will the initiator fit at all? */ if ( lpBlock->nStart && lpBlock->nStart <= nLength ) { /* * Look up the block initiator on the line. */ LPCTSTR pszStr = ( lpp->bCaseOn ? StrStr : StrStrI )( pcText, lpBlock->pszStart ); /* * Found? */ if ( pszStr != NULL ) { /* * We have a block initializer. */ bHasInit = TRUE; /* * This block initiator is located * on this line. */ lpBlock->bInLine = TRUE; } } } } /* * First we skip the leading blanks... */ while ( _istspace( pcText[ nIndex ] ) && nIndex <= nLength ) nIndex++; /* * Iterate text. */ for ( /*nIndex = 0*/; nIndex <= nLength; nIndex++ ) { /* * Clear continue flag. */ bContinue = FALSE; /* * In a block? */ if ( nInBlock != -1 ) { /* * Get block. */ lpBlock = ArrayGetAt( lpp->lpaBlocks, nInBlock ); /* * Does the block terminate with a string? */ if ( lpBlock->nEnd ) { /* * Does the terminator occure in the text? */ LPCTSTR pszStr = ( lpp->bCaseOn ? StrStr : StrStrI )( &pcText[ nIndex ], lpBlock->pszEnd ); /* * No. Return the block number. */ if ( pszStr == NULL ) { /* * Are we parsing hyperlinks? */ if ( Parser->bParseHyperLinks && scColors && lpnBlocks ) { /* * Find the hyperlinks starting at offset 'nIndex'. */ *lpnBlocks = FindHyperlinksInBlock( lpcd, pcText, nIndex, nLength, nBlock, nNumBlocks, lpnBlocks, scColors ) + 1; scColors[ *lpnBlocks - 1 ].nColumn = nLength; } else if ( lpnBlocks ) /* * Store the block number. */ *lpnBlocks = nBlock + 1; return nInBlock; } else if ( Parser->bParseHyperLinks && scColors && lpnBlocks ) /* * Find all hyperlinks from offset 'nIndex' * up to the block end marker. */ nBlock = FindHyperlinksInBlock( lpcd, pcText, nIndex, ( int )( pszStr - pcText ), nBlock, nNumBlocks, lpnBlocks, scColors ); /* * Skip through to the index at which the * terminator was found. */ nIndex = ( int )( pszStr - pcText ); } /* * Will the terminator fit? */ if ( nLength - nIndex >= lpBlock->nEnd || lpBlock->pszEnd == END_OF_LINE ) { /* * End a block? */ if ( BlockEnd( lpcd, lpBlock, pcText, nIndex, nLength )) { /* * Color array present? */ if ( scColors ) { /* * Enough room? */ CHECK_BLOCKS; /* * Yes. Terminate current color. */ scColors[ nBlock++ ].nColumn = nIndex + lpBlock->nEnd; /* * Start a new color. */ scColors[ nBlock ].nColumn = nLength; scColors[ nBlock ].crColor = crText; scColors[ nBlock ].crBgColor = CLR_DEFAULT; scColors[ nBlock ].pHash = NULL; scColors[ nBlock ].wFlags = 0; } /* * Skip the block terminator. */ if ( lpBlock->pszEnd != END_OF_LINE ) nIndex += lpBlock->nEnd - 1; else nIndex = nLength; /* * No longer in the block. */ nInBlock = -1; /* * Continue parse... */ continue; } } } /* * Keep looking for the terminator if * we are still inside a block. */ if ( nInBlock != -1 ) { if ( scColors && nIndex >= nLength ) scColors[ nBlock ].nColumn = nIndex; continue; } /* * Do we have an initiator? */ if ( bHasInit ) { /* * Look up the block * initiators. */ for ( i = 0; ; i++ ) { /* * Valid block? */ if (( lpBlock = ArrayGetAt( lpp->lpaBlocks, i )) == NULL ) break; /* * Block initiator in this * line? */ if ( ! lpBlock->bInLine ) continue; /* * Block found? */ if ( ! BlockStart( lpcd, lpBlock, pcText, nIndex, nLength, bStartOfLine )) continue; /* * Colors present? */ if ( scColors ) { /* * Enough room? */ CHECK_BLOCKS; /* * Yes. Terminate current color. */ scColors[ nBlock++ ].nColumn = nIndex; /* * Start a new color. */ scColors[ nBlock ].nColumn = nLength; scColors[ nBlock ].crColor = lpBlock->crColor; scColors[ nBlock ].crBgColor = lpBlock->crBgColor; scColors[ nBlock ].pHash = NULL; scColors[ nBlock ].wFlags = 0; } /* * Mark us as being in the block. */ nInBlock = i; /* * Does this block terminate at eol? */ if ( lpBlock->pszEnd == END_OF_LINE ) { /* * Look at the rest of the line * for hyperlinks. */ if ( Parser->bParseHyperLinks && scColors && lpnBlocks ) nBlock = FindHyperlinksInBlock( lpcd, pcText, nIndex, nLength, nBlock, nNumBlocks, lpnBlocks, scColors ); /* * Skip everything except * the last terminator length * plus the escape character. */ nIndex = max( 0, nLength - 2 ); } else /* * Skip the block initiator. */ nIndex += lpBlock->nStart - 1; /* * Break the loop and * continue parsing. */ bContinue = TRUE; break; } } /* * No longer at the start * of the line... */ bStartOfLine = FALSE; /* * Continue? */ if ( bContinue || scColors == NULL ) continue; /* * Skip spaces. */ if ( _istspace( pcText[ nIndex ] )) { /* * Make a new block. */ if ( scColors[ nBlock ].crBgColor != CLR_DEFAULT || scColors[ nBlock ].crColor != crText || scColors[ nBlock ].wFlags ) { /* * Enough room? */ CHECK_BLOCKS; /* * Terminate current color. */ scColors[ nBlock++ ].nColumn = nIndex; /* * Setup new color. */ scColors[ nBlock ].crColor = crText; scColors[ nBlock ].crBgColor = CLR_DEFAULT; scColors[ nBlock ].nColumn = nLength; scColors[ nBlock ].pHash = NULL; scColors[ nBlock ].wFlags = 0; } continue; } if ( Parser->bParseHyperLinks && scColors ) { nHyperLength = IsHyperlink( pcText, nIndex, nLength ); // Modified by Stephan (2005-06-12) if (nHyperLength) { /* * Enough room? */ CHECK_BLOCKS; /* * Yes. Terminate current color. */ scColors[ nBlock++ ].nColumn = nIndex; /* * Start a new color. */ scColors[ nBlock ].nColumn = nLength; scColors[ nBlock ].crColor = Parser->crColors[ CARR_HYPERLINK ]; scColors[ nBlock ].crBgColor = Parser->crColors[ CARR_BACKGROUND_HYPERLINK ]; scColors[ nBlock ].pHash = NULL; scColors[ nBlock ].wFlags = SCF_HYPERLINK; /* * Is it a quoted hyperlink? */ if ( nIndex && (pcText[ nIndex - 1 ] == _T( '"' ) || pcText[ nIndex - 1 ] == _T( '\'' ))) // Modified by Stephan (2005-05-30) { /* * Look up the next quote. */ while ( nIndex < nLength && pcText[ nIndex ] != _T( '"' ) && pcText[ nIndex ] != _T( '\'' )) // Modified by Stephan (2005-05-30) nIndex++; if ( pcText[ nIndex ] == _T( '"' ) || pcText[ nIndex ] == _T( '\'' )) // Modified by Stephan (2005-05-30) nIndex--; } else { /* * Look up the next white space. */ nIndex += nHyperLength; // Modified by Stephan while ( nIndex < nLength && ! _istspace( pcText[ nIndex ] ) && pcText[ nIndex ] != _T('(') && pcText[ nIndex ] != _T(',') && pcText[ nIndex ] != _T(';') && pcText[ nIndex ] != _T(')') && pcText[ nIndex ] != _T('\'')) // Modified by Stephan (2005-05-28) nIndex++; if ( _istspace( pcText[ nIndex ] ) || pcText[ nIndex ] == _T('(') || pcText[ nIndex ] == _T(',') || pcText[ nIndex ] == _T(';') || pcText[ nIndex ] == _T(')') || pcText[ nIndex ] == _T('\'')) // Modified by Stephan (2005-05-28) nIndex--; } continue; } } /* * Delimiter? */ if ( IsDelimiter( lpcd, pcText[ nIndex ] )) { /* * Any change in color? */ if (( scColors[ nBlock ].crColor != Parser->crColors[ CARR_DELIMITER ] ) || ( scColors[ nBlock ].crBgColor != Parser->crColors[ CARR_BACKGROUND_DELIMITER ] ) || ( scColors[ nBlock ].wFlags )) { /* * Enough room? */ CHECK_BLOCKS; /* * Terminate current color. */ scColors[ nBlock++ ].nColumn = nIndex; /* * Setup delimiter color. */ scColors[ nBlock ].crColor = Parser->crColors[ CARR_DELIMITER ]; scColors[ nBlock ].crBgColor = Parser->crColors[ CARR_BACKGROUND_DELIMITER ]; scColors[ nBlock ].nColumn = nLength; scColors[ nBlock ].pHash = NULL; scColors[ nBlock ].wFlags = 0; } /* * Do we have matched brackets? */ if (( nLine == lpcd->ptBracket1.y && nIndex == nMatchX1 ) || ( nLine == lpcd->ptBracket2.y && nIndex == nMatchX2 )) { /* * Enough room? */ CHECK_BLOCKS; /* * Terminate current color. */ scColors[ nBlock++ ].nColumn = nIndex; /* * Setup match color. */ scColors[ nBlock ].crColor = scColors[ nBlock - 1 ].crColor; scColors[ nBlock ].crBgColor = lpp->crColors[ CARR_BRACKET_MATCH ]; scColors[ nBlock ].nColumn = nLength; scColors[ nBlock ].pHash = NULL; scColors[ nBlock ].wFlags = 0; } /* * Continue parsing. */ continue; } else /* * Is it a number? This check is a bit * to simple but it should not pose * any problems... */ if ( _istdigit( pcText[ nIndex ] )) { /* * Color changes? */ if (( scColors[ nBlock ].crColor != Parser->crColors[ CARR_NUMBER ] ) || ( scColors[ nBlock ].crBgColor != Parser->crColors[ CARR_BACKGROUND_NUMBER ] ) || ( scColors[ nBlock ].wFlags )) { /* * Enough room? */ CHECK_BLOCKS; /* * Terminate the current color. */ scColors[ nBlock++ ].nColumn = nIndex; /* * Setup the number colors. */ scColors[ nBlock ].nColumn = nLength; scColors[ nBlock ].crColor = Parser->crColors[ CARR_NUMBER ]; scColors[ nBlock ].crBgColor = Parser->crColors[ CARR_BACKGROUND_NUMBER ]; scColors[ nBlock ].pHash = NULL; scColors[ nBlock ].wFlags = 0; } } else { /* * Do we have bracket matches? */ if (( nLine == lpcd->ptBracket1.y && nIndex == nMatchX1 ) || ( nLine == lpcd->ptBracket2.y && nIndex == nMatchX2 )) { /* * Enough room? */ CHECK_BLOCKS; /* * Terminate current color. */ scColors[ nBlock++ ].nColumn = nIndex; /* * Setup match color. */ scColors[ nBlock ].crColor = crText; scColors[ nBlock ].crBgColor = lpp->crColors[ CARR_BRACKET_MATCH ]; scColors[ nBlock ].nColumn = nLength; scColors[ nBlock ].pHash = NULL; scColors[ nBlock ].wFlags = 0; /* * Continue parsing. */ continue; } else if ( scColors[ nBlock ].crColor != crText || scColors[ nBlock ].crBgColor != CLR_DEFAULT || scColors[ nBlock ].wFlags ) { /* * Enough room? */ CHECK_BLOCKS; /* * Terminate current color. */ scColors[ nBlock++ ].nColumn = nIndex; /* * Setup text color. */ scColors[ nBlock ].crColor = crText; scColors[ nBlock ].crBgColor = CLR_DEFAULT; scColors[ nBlock ].nColumn = nLength; scColors[ nBlock ].pHash = NULL; scColors[ nBlock ].wFlags = 0; } } /* * Count the characters up until * the next space or delimiter. */ nSize = nIndex; while ( nSize < nLength && ! _istspace( pcText[ nSize ] ) && ! IsDelimiter( lpcd, pcText[ nSize ] )) { /* * Do we have bracket matches? */ if (( nLine == lpcd->ptBracket1.y && nSize == nMatchX1 ) || ( nLine == lpcd->ptBracket2.y && nSize == nMatchX2 )) { /* * Enough room? */ CHECK_BLOCKS; /* * Terminate current color. */ scColors[ nBlock++ ].nColumn = nSize; /* * Setup match colors. */ scColors[ nBlock ].crColor = crText; scColors[ nBlock ].crBgColor = lpp->crColors[ CARR_BRACKET_MATCH ]; scColors[ nBlock ].nColumn = nLength; scColors[ nBlock ].pHash = NULL; scColors[ nBlock ].wFlags = 0; /* * Continue parsing. */ break; } nSize++; } /* * Is the previous character a space/delimiter or are * we at the start of the line? */ if ( nIndex == 0 || _istspace( pcText[ nIndex - 1 ] ) || IsDelimiter( lpcd, pcText[ nIndex - 1 ] )) { /* * Is it a keyword */ if (( lpHash = IsKeyword( lpcd, &pcText[ nIndex ], nSize - nIndex )) != NULL ) { /* * Color changes? * NOTE: Removed to accomodate case-fixing. */ /*if ( scColors[ nBlock ].crColor != lpHash->crColor )*/ { /* * Enough room? */ CHECK_BLOCKS; /* * Terminate the current color. */ scColors[ nBlock++ ].nColumn = nIndex; /* * Setup the keyword color and the hash. We use the hash * when a text line is edited to fix the casing when * case-fixing is turned on. */ scColors[ nBlock ].nColumn = nLength; scColors[ nBlock ].crColor = lpHash->crColor; scColors[ nBlock ].crBgColor = lpHash->crBkColor; scColors[ nBlock ].pHash = lpHash; scColors[ nBlock ].wFlags = 0; } } } /* * Are we at the end? */ if ( nSize >= nLength ) break; /* * Adjust the index. */ nIndex = nSize - 1; } /* * Store the number of syntax * color block that are valid. */ if ( lpnBlocks ) *lpnBlocks = nBlock + 1; return nInBlock; }
void Scanner() { int word_pos, num_value, max_word_len; char word[100], word_temp[100], input[MAXLEN]; char *p; InitList(); while( fgets(input,100,fpIn) ) { readRow++; strcpy( word, input ); p = word; while( *p != '\n' ) { word_pos = 0; while( *p == ' ' || *p == 9 ) p++; if( *p == '\n' )// bug test file : while( a < 10 { break; if( isalpha(*p) || *p == '_' ) { CLR(word_temp); max_word_len = 0; while( isalpha(*p) || is_digtial(*p) || *p == '_' ) { word_temp[word_pos++] = *p; p++ , max_word_len++; } if( max_word_len >= 20 ) { fprintf( fpOut, "word's max len error"); exit(0); } word_temp[word_pos] = '\0'; if( *(p) == '[' ) { InsertList( SYN_ARRAY, word_temp ); } else InsertList( IsKeyword(word_temp), word_temp ); } else if( *p >= '0' && *p <= '9' ) { CLR(word_temp); num_value = 0; while( (*p>='0' && *p<='9') ) { num_value = num_value * 10 + *p-'0'; p++; } if( isalpha(*p) ) { fprintf( fpOut, "word wrong can't not begin with number" ); exit(0); return ; } if( num_value >= 32767 ) { fprintf( fpOut, "int too big" ); exit(0); return ; } else { itoa(num_value,word_temp,10); InsertList( SYN_NUM, word_temp ); } } else { switch( *p ) { case '=': if( *(p+1) == '=' ) { InsertList( SYN_EQ, "==" ); p++; } else InsertList( SYN_ASSIGN, "=" ); break; case '+': InsertList( SYN_PLUS, "+" ); break; case '-': InsertList( SYN_MINUS, "-" ); break; case '*': InsertList( SYN_MUL, "*" ); break; case '/': InsertList( SYN_DIV, "/" ); break; case '<': if( *(p+1) == '=' ) { InsertList( SYN_LE, "<=" ); p++; } else InsertList( SYN_LT, "<" ); break; case '>': if( *(p+1) == '=' ) { InsertList( SYN_ME, ">=" ); p++; } else InsertList( SYN_LG, ">" ); break; case '!': InsertList( SYN_NE, "!=" ); break; case ',': InsertList( SYN_COMMA, "," ); break; case ':': InsertList( SYN_COLON, ":" ); break; case ';': InsertList( SYN_SEMICOLON, ";" ); break; case '(': InsertList( SYN_LPAREN, "(" ); break; case ')': InsertList( SYN_RPAREN, ")" ); break; case '{': InsertList( SYN_LEFTBRACKET2, "{" ); break; case '}': InsertList( SYN_RIGHTBRACKET2, "}" ); break; case '[': InsertList( SYN_LEFTBRACKET1, "[" ); break; case ']': InsertList( SYN_RIGHTBRACKET1, "]" ); break; default: return ; break; } p++; } } } }
void CTWScriptEdit::FormatTextRange(int nStart, int nEnd) { if (nStart >= nEnd) return; m_bInForcedChange = TRUE; CHARRANGE crOldSel; GetSel(crOldSel); LockWindowUpdate(); HideSelection(TRUE, FALSE); WCHAR *pBuffer = NULL; try { SetSel(nStart, nEnd); //pBuffer = new WCHAR[nEnd - nStart + 1]; CHAR* pBuffer2 = new CHAR[nEnd - nStart + 1]; long nLen = GetSelText(pBuffer2); pBuffer = GetUnicode(pBuffer2); ASSERT(nLen <= nEnd - nStart); pBuffer[nLen] = 0; WCHAR *pStart, *pPtr; pStart = pPtr = pBuffer; WCHAR* pSymbolStart = NULL; SymbolColor ic; while (*pPtr != 0) { WCHAR ch = *pPtr; if (ch == m_chComment && (m_chComment2 == 0 || pPtr[1] == m_chComment2)) { pSymbolStart = pPtr; do { ch = *(++pPtr); } while (ch != 0 && ch != '\r'); ic = m_icComment; } else if (IsStringQuote(ch)) { // Process strings pSymbolStart = pPtr; WCHAR ch1 = ch; do { ch = *(++pPtr); } while (ch != 0 && ch != ch1 && ch != '\r'); if (ch == ch1) pPtr++; ic = m_icString; } else if (_istdigit(ch)) { // Process numbers pSymbolStart = pPtr; wcstod(pSymbolStart, &pPtr); ic = m_icNumber; } else if (_istalpha(ch) || ch == '_') { // Process keywords pSymbolStart = pPtr; do { ch = *(++pPtr); } while (_istalnum(ch) || ch == '_'); *pPtr = 0; int nPos = IsKeyword(pSymbolStart); if (nPos >= 0) { ChangeCase(nStart + pSymbolStart - pBuffer, nStart + pPtr - pBuffer, m_strKeywords.Mid(nPos+1, pPtr - pSymbolStart)); if (wcsicmp(m_strComment, pSymbolStart) == 0) { *pPtr = ch; *pSymbolStart = m_chComment; if (pSymbolStart[1] != 0 && m_chComment2 != 0) pSymbolStart[1] = m_chComment2; pPtr = pSymbolStart; pSymbolStart = NULL; continue; } ic = m_icKeyword; } else { nPos = IsConstant(pSymbolStart); if (nPos >= 0) { ChangeCase(nStart + pSymbolStart - pBuffer, nStart + pPtr - pBuffer, m_strConstants.Mid(nPos+1, pPtr - pSymbolStart)); ic = m_icConstant; } else { pSymbolStart = NULL; } } *pPtr = ch; } else { pPtr++; } if (pSymbolStart != NULL) { ASSERT(pSymbolStart < pPtr); SetFormatRange(nStart + pStart - pBuffer, nStart + pSymbolStart - pBuffer, FALSE, RGB(0,0,0)); SetFormatRange(nStart + pSymbolStart - pBuffer, nStart + pPtr - pBuffer, ic.bBold, ic.clrColor); pStart = pPtr; pSymbolStart = 0; } else if (*pPtr == 0) SetFormatRange(nStart + pStart - pBuffer, nStart + pPtr - pBuffer, FALSE, RGB(0,0,0)); } } catch(...){} //delete [] pBuffer; SetSel(crOldSel); HideSelection(FALSE, FALSE); UnlockWindowUpdate(); m_bInForcedChange = FALSE; }
void RCFile::SkipComma() { if (IsKeyword() && GetToken()->GetKeyword() == Lexer::comma) NextToken(); }