//----------------------------------------------------------------------------- // (For text buffers only) // Parse a token from the buffer: // Grab all text that lies between a starting delimiter + ending delimiter // (skipping whitespace that leads + trails both delimiters). // Note the delimiter checks are case-insensitive. // If successful, the get index is advanced and the function returns true, // otherwise the index is not advanced and the function returns false. //----------------------------------------------------------------------------- bool CUtlBuffer::ParseToken( const char *pStartingDelim, const char *pEndingDelim, char* pString, int nMaxLen ) { int nCharsToCopy = 0; int nCurrentGet = 0; size_t nEndingDelimLen; // Starting delimiter is optional char emptyBuf = '\0'; if ( !pStartingDelim ) { pStartingDelim = &emptyBuf; } // Ending delimiter is not Assert( pEndingDelim && pEndingDelim[0] ); nEndingDelimLen = Q_strlen( pEndingDelim ); int nStartGet = TellGet(); char nCurrChar; int nTokenStart = -1; EatWhiteSpace( ); while ( *pStartingDelim ) { nCurrChar = *pStartingDelim++; if ( !isspace((unsigned char)nCurrChar) ) { if ( tolower( GetChar() ) != tolower( nCurrChar ) ) goto parseFailed; } else { EatWhiteSpace(); } } EatWhiteSpace(); nTokenStart = TellGet(); if ( !GetToken( pEndingDelim ) ) goto parseFailed; nCurrentGet = TellGet(); nCharsToCopy = (nCurrentGet - nEndingDelimLen) - nTokenStart; if ( nCharsToCopy >= nMaxLen ) { nCharsToCopy = nMaxLen - 1; } if ( nCharsToCopy > 0 ) { SeekGet( CUtlBuffer::SEEK_HEAD, nTokenStart ); Get( pString, nCharsToCopy ); if ( !IsValid() ) goto parseFailed; // Eat trailing whitespace for ( ; nCharsToCopy > 0; --nCharsToCopy ) { if ( !isspace( (unsigned char)pString[ nCharsToCopy-1 ] ) ) break; } } pString[ nCharsToCopy ] = '\0'; // Advance the Get index SeekGet( CUtlBuffer::SEEK_HEAD, nCurrentGet ); return true; parseFailed: // Revert the get index SeekGet( SEEK_HEAD, nStartGet ); pString[0] = '\0'; return false; }
void CommHandler(void) //UART4 Interrupt handler implementation { int c = GetChar(); if (c >= 0) { //ConfigMode = 1; LEDon(); //print("got char %02X\r\n", c); switch (c) { case 'b': print("rebooting into boot loader ...\r\n"); Delay_ms(1000); bootloader(); break; case 'c': debugCnt ^= 1; print("counter messages %s\r\n", debugCnt ? "on" : "off"); break; case 'd': debugPrint ^= 1; print("debug messages %s\r\n", debugPrint ? "on" : "off"); break; case 'g': Delay_ms(100); PutChar('x'); for (int i = 0; i < CONFIGDATASIZE; i++) { uint8_t data = configData[i]; PutChar(data); } break; case 'G': printConfig(); break; #if 0 case 'H': if (CharAvailable() >= CONFIGDATASIZE) { for (int i = 0; i < CONFIGDATASIZE; i++) { uint8_t data = GetChar(); if (data <= LARGEST_CONFIGDATA) { configData[i] = data; } } configSave(); } else { UnGetChar(c); // try again in next loop } break; #endif case 'h': for (int i = 0; i < CONFIGDATASIZE; i++) { int data; while ((data = GetChar()) < 0) ; if (data <= LARGEST_CONFIGDATA) { configData[i] = data; } } configSave(); break; case 'i': ConfigMode = 1; break; case 'j': ConfigMode = 0; break; case 'o': debugOrient ^= 1; print("Orientation messages %s\r\n", debugOrient ? "on" : "off"); break; case 'p': debugPerf ^= 1; print("performance messages %s\r\n", debugPerf ? "on" : "off"); break; case 'r': debugRC ^= 1; print("RC messages %s\r\n", debugRC ? "on" : "off"); break; case 'R': print("rebooting...\r\n"); Delay_ms(1000); reboot(); break; case 's': debugSense ^= 1; print("Sensor messages %s\r\n", debugSense ? "on" : "off"); break; case 'u': { extern int bDeviceState; printUSART("\r\nYY bDeviceState %3d VCPConnectMode %d\r\n", bDeviceState, GetVCPConnectMode()); break; } case '+': testPhase += 0.1; print("test phase output %5.1f\r\n", testPhase); break; case '-': testPhase -= 0.1; print("test phase output %5.1f\r\n", testPhase); break; default: // TODO break; } } }
//------------------------------------------------------------------------------ bool FBasicTokenParser::GetToken(FBasicToken& Token, bool bNoConsts/* = false*/) { // if the parser is in a bad state, then don't continue parsing (who // knows what will happen!?) if (!IsValid()) { return false; } Token.TokenName = NAME_None; TCHAR c = GetLeadingChar(); TCHAR p = PeekChar(); if( c == 0 ) { UngetChar(); return 0; } Token.StartPos = PrevPos; Token.StartLine = PrevLine; if( (c>='A' && c<='Z') || (c>='a' && c<='z') || (c=='_') ) { // Alphanumeric token. int32 Length=0; do { Token.Identifier[Length++] = c; if( Length >= NAME_SIZE ) { Length = ((int32)NAME_SIZE) - 1; Token.Identifier[Length]=0; // need this for the error description FText ErrorDesc = FText::Format(LOCTEXT("IdTooLong", "Identifer ({0}...) exceeds maximum length of {1}"), FText::FromString(Token.Identifier), FText::AsNumber((int32)NAME_SIZE)); SetError(FErrorState::ParseError, ErrorDesc); break; } c = GetChar(); } while( ((c>='A')&&(c<='Z')) || ((c>='a')&&(c<='z')) || ((c>='0')&&(c<='9')) || (c=='_') ); UngetChar(); Token.Identifier[Length]=0; // Assume this is an identifier unless we find otherwise. Token.TokenType = FBasicToken::TOKEN_Identifier; // Lookup the token's global name. Token.TokenName = FName( Token.Identifier, FNAME_Find, true ); // If const values are allowed, determine whether the identifier represents a constant if ( !bNoConsts ) { // See if the identifier is part of a vector, rotation or other struct constant. // boolean true/false if( Token.Matches(TEXT("true")) ) { Token.SetConstBool(true); return true; } else if( Token.Matches(TEXT("false")) ) { Token.SetConstBool(false); return true; } } return IsValid(); } // if const values are allowed, determine whether the non-identifier token represents a const else if ( !bNoConsts && ((c>='0' && c<='9') || ((c=='+' || c=='-') && (p>='0' && p<='9'))) ) { // Integer or floating point constant. bool bIsFloat = 0; int32 Length = 0; bool bIsHex = 0; do { if( c==TEXT('.') ) { bIsFloat = true; } if( c==TEXT('X') || c == TEXT('x') ) { bIsHex = true; } Token.Identifier[Length++] = c; if( Length >= NAME_SIZE ) { Length = ((int32)NAME_SIZE) - 1; Token.Identifier[Length]=0; // need this for the error description FText ErrorDesc = FText::Format(LOCTEXT("IdTooLong", "Identifer ({0}...) exceeds maximum length of {1}"), FText::FromString(Token.Identifier), FText::AsNumber((int32)NAME_SIZE)); SetError(FErrorState::ParseError, ErrorDesc); break; } c = FChar::ToUpper(GetChar()); } while ((c >= TEXT('0') && c <= TEXT('9')) || (!bIsFloat && c == TEXT('.')) || (!bIsHex && c == TEXT('X')) || (bIsHex && c >= TEXT('A') && c <= TEXT('F'))); Token.Identifier[Length]=0; if (!bIsFloat || c != 'F') { UngetChar(); } if (bIsFloat) { Token.SetConstFloat( FCString::Atof(Token.Identifier) ); } else if (bIsHex) { TCHAR* End = Token.Identifier + FCString::Strlen(Token.Identifier); Token.SetConstInt( FCString::Strtoi(Token.Identifier,&End,0) ); } else { Token.SetConstInt( FCString::Atoi(Token.Identifier) ); } return IsValid(); } else if( c=='"' ) { // String constant. TCHAR Temp[MAX_STRING_CONST_SIZE]; int32 Length=0; c = GetChar(1); while( (c!='"') && !IsEOL(c) ) { if( c=='\\' ) { c = GetChar(1); if( IsEOL(c) ) { break; } else if(c == 'n') { // Newline escape sequence. c = '\n'; } } Temp[Length++] = c; if( Length >= MAX_STRING_CONST_SIZE ) { Length = ((int32)MAX_STRING_CONST_SIZE) - 1; Temp[Length]=0; // need this for the error description FText ErrorDesc = FText::Format(LOCTEXT("StringConstTooLong", "String constant ({0}...) exceeds maximum of {1} characters"), FText::FromString(Temp), FText::AsNumber((int32)MAX_STRING_CONST_SIZE)); SetError(FErrorState::ParseError, ErrorDesc); c = TEXT('\"'); break; } c = GetChar(1); } Temp[Length]=0; if( c != '"' ) { FText ErrorDesc = FText::Format(LOCTEXT("NoClosingQuote", "Unterminated quoted string ({0})"), FText::FromString(Temp)); SetError(FErrorState::ParseError, ErrorDesc); UngetChar(); } Token.SetConstString(Temp); return IsValid(); } else { // Symbol. int32 Length=0; Token.Identifier[Length++] = c; // Handle special 2-character symbols. #define PAIR(cc,dd) ((c==cc)&&(d==dd)) /* Comparison macro for convenience */ TCHAR d = GetChar(); if ( PAIR('<','<') || PAIR('>','>') || PAIR('!','=') || PAIR('<','=') || PAIR('>','=') || PAIR('+','+') || PAIR('-','-') || PAIR('+','=') || PAIR('-','=') || PAIR('*','=') || PAIR('/','=') || PAIR('&','&') || PAIR('|','|') || PAIR('^','^') || PAIR('=','=') || PAIR('*','*') || PAIR('~','=') || PAIR(':',':') ) { Token.Identifier[Length++] = d; if( c=='>' && d=='>' ) { if( GetChar()=='>' ) Token.Identifier[Length++] = '>'; else UngetChar(); } } else UngetChar(); #undef PAIR Token.Identifier[Length] = 0; Token.TokenType = FBasicToken::TOKEN_Symbol; // Lookup the token's global name. Token.TokenName = FName( Token.Identifier, FNAME_Find, true ); return true; } }
const Number FloatLiteralParser::Parse() { // Assert( NotAtEnd() && InClass(CharClass::NUMBER_HEAD) ) char c = GetChar(); NumberBuilder numberBuilder; if (c == '0') { Advance(); if (AtEnd()) { return Number::ZERO(); } switch (GetChar()) { case '.' : return ParseFractional(numberBuilder); case 'e' : case 'E' : return ParseExponent(numberBuilder); case 'b' : return config_.parse_binary ? ParseBinary() : Number::ZERO(); case 'x' : return config_.parse_hexadecimal ? ParseHexadecimal() : Number::ZERO(); } if (NotInClass(CharClass::DECIMAL)) { return Number::ZERO(); } if (config_.parse_octal) { return ParseOctal(); } } else if (c == '-') { numberBuilder.SetNegative(); Advance(); if (AtEnd() || NotInClass(CharClass::DECIMAL)) { ThrowError("Decimal digit expected"); } } // Assert( NotAtEnd() && InClass(CharClass::DECIMAL) ) do { numberBuilder.OnIntegerDigit(GetChar() - '0'); Advance(); if (AtEnd()) { return numberBuilder.Release(); } } while (InClass(CharClass::DECIMAL)); if (GetChar() == '.') { return ParseFractional(numberBuilder); } else if (GetChar() == 'e' || GetChar() == 'E') { return ParseExponent(numberBuilder); } return numberBuilder.Release(); }
void kGUIText::DrawSectionRot(int sstart,int slen,float x,float y,float angle,kGUIColor color,float alpha) { kGUIFace *face=kGUIFont::GetFace(GetFontID()); int glyph_index; int font_height,font_above,font_below; FT_Face ftface; int size; FT_Glyph glyph2; FT_Matrix matrix; FT_BitmapGlyph bit; float dx,dy,adv; float advsin,advcos; float fax,fay; /* rotated font above */ unsigned int ch; /* current character */ unsigned int nb; /* number of bytes for current character */ ftface=face->GetFace(); size=GetFontSize(); if(!size) return; assert(size>0,"Cannot print size 0\n"); font_height=face->GetPixHeight(size); font_above = face->GetPixAscHeight(size); font_below = face->GetPixDescHeight(size); kGUI::SelectFont(face,size); matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L ); matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L ); matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L ); matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L ); adv=0; advsin=sin(angle); advcos=cos(angle); fax=sin(angle-(2*PI)*0.025f)*font_above; fay=-(cos(angle-(2*PI)*0.025f)*font_above); /* todo, handle underline */ while(slen>0) { ch=GetChar(sstart,&nb); if(!ch) return; sstart+=nb; slen-=nb; /* todo, handle tabs, handle encoding */ glyph_index = FT_Get_Char_Index( ftface, ch ); if(glyph_index>0) { FT_Load_Glyph(ftface,glyph_index,FT_LOAD_DEFAULT); FT_Get_Glyph( ftface->glyph, &glyph2 ); FT_Glyph_Transform( glyph2, &matrix, 0 ); FT_Glyph_To_Bitmap( &glyph2, ft_render_mode_normal,0, 1); /* draw to screen using writepixel */ bit = (FT_BitmapGlyph)glyph2; dx=x+((advcos*adv)+fax); dy=y-((advsin*adv)+fay); DrawChar( (char *)bit->bitmap.buffer, dx + bit->left, dy -bit->top, bit->bitmap.width, bit->bitmap.rows, color,alpha); adv+=ftface->glyph->advance.x/64.0f; adv+=m_letterspacing; FT_Done_Glyph(glyph2); } } if(m_underline) kGUI::DrawLine(x+fax,y-fay,x+((advcos*adv)+fax),y-((advsin*adv)+fay),color,alpha); }
CFSVar CJSONReader::ReadVal(const CFSAString &szKeyPath) { OnValReadStart(szKeyPath); CFSVar Data; if (m_cCh=='[') { Data.Cast(CFSVar::VAR_ARRAY); GetChar(true); INTPTR ipPos=0; for (;;) { if (m_cCh==0) { throw CJSONException(FSTSTR("Unexpetcted EOF")); } else if (m_cCh==']') { GetChar(true); break; } else if (ipPos>0) { if (m_cCh==',') { GetChar(true); } else { throw CJSONException(FSTSTR("Missing ',' in array")); } } CFSAString szKey; szKey.Format("%zd", ipPos); CFSVar Data1=ReadVal(szKeyPath+"/"+szKey); if (m_iCollectData>0) { Data[ipPos]=Data1; } ipPos++; } } else if (m_cCh=='{') { Data.Cast(CFSVar::VAR_MAP); GetChar(true); INTPTR ipPos=0; for (;;) { if (m_cCh==0) { throw CJSONException(FSTSTR("Unexpetcted EOF")); } else if (m_cCh=='}') { GetChar(true); break; } else if (ipPos>0) { if (m_cCh==',') { GetChar(true); } else { throw CJSONException(FSTSTR("Missing ',' in map")); } } CFSAString szKey; if (m_cCh=='\"' || m_cCh=='\'') { szKey=ReadString(); } else if (FSIsLetter(m_cCh)) { szKey=ReadText(); } else { throw CJSONException(FSTSTR("Expected key")); } if (m_cCh==':') { GetChar(true); } else { throw CJSONException(FSTSTR("Expected ':'")); } CFSVar Data1=ReadVal(szKeyPath+"/"+szKey); if (m_iCollectData>0) { Data[szKey]=Data1; } ipPos++; } } else if (m_cCh=='\"' || m_cCh=='\'') { Data=ReadString(); } else if ((m_cCh>='0' && m_cCh<='9') || FSStrChr("-+.", m_cCh)) { Data=ReadNumber(); } else if (FSIsLetter(m_cCh)) { Data=ReadConst(); } else if (!m_cCh) { } else { throw CJSONException(FSTSTR("Unknown value type")); } OnValReadEnd(szKeyPath, Data); return Data; }
inline CField::operator tchar() const { return GetChar(); }
void TK_Device2PC(void) { int count=0,i=0; uint16_t len=0; uint8_t test; TK_CNANNEL_CONFIG tk_channel_config; TK_CNANNEL_CONFIG *tkchconfig; len=sizeof(TK_CNANNEL_CONFIG); //get magic id i=0; count=0; while(1) { if(kbhit()) { test=GetChar(); if(test!=MagicId[i++]) { return; } if(i==sizeof(MagicId)) break; } else { count++; } if(count > DELAY_TIME_OUT) return; } i=0; count=0; while(i<2) { if(kbhit()) { ((uint8_t *)&reclen)[i]=GetChar(); i++; } } i=0; count=0; while(i<reclen) { if(kbhit()) { ReceiveBuf[i]=GetChar(); i++; } } SendChars(MagicIdR,sizeof(MagicIdR)); count=0; switch(ReceiveBuf[0]) { case OP_AUTO_CHANNEL_CONFIG: /*Send : MagicidR | len(16) | "START" | progess (5 time) |len<NEXT> (16) */ len=5+sizeof(len); memcpy(SendBuf+count,&len,sizeof(len)); count+=sizeof(len); memcpy(SendBuf+count,(uint8_t *)"START",5); count+=5; len=sizeof(TK_CNANNEL_CONFIG)+5 /*Used by Progress */; memcpy(SendBuf+count,&len,2); count+=sizeof(len); SendChars((uint8_t *)SendBuf,count); AutoChannelConfig(ReceiveBuf[1],&final_result); tk_channel_config.channel=ReceiveBuf[1]; tk_channel_config.base=final_result.base; tk_channel_config.diff=final_result.diff; tk_channel_config.current=final_result.current; tk_channel_config.div=final_result.div; SendChars((uint8_t *)&tk_channel_config,sizeof(TK_CNANNEL_CONFIG)); break; case OP_GET_CONFIG: len=TK_CH_NUM*sizeof(TK_CNANNEL_CONFIG); memcpy( SendBuf+count,(uint8_t *)&len,sizeof(len)); count+=sizeof(len); for(i=0;i<TK_CH_NUM;i++) { tk_channel_config.channel=i; tk_channel_config.base=cfg[i].base; tk_channel_config.diff=cfg[i].diff; tk_channel_config.current=cfg[i].current; tk_channel_config.div=cfg[i].div; memcpy(SendBuf+count,(uint8_t *)(&tk_channel_config),sizeof(TK_CNANNEL_CONFIG)); count+=sizeof(TK_CNANNEL_CONFIG); } SendChars(SendBuf,count); break; case OP_SET_CHANNEL_CONFIG: tkchconfig=(TK_CNANNEL_CONFIG *)(ReceiveBuf+1); cfg[tkchconfig->channel].base=tkchconfig->base; cfg[tkchconfig->channel].diff=tkchconfig->diff; cfg[tkchconfig->channel].current=tkchconfig->current; cfg[tkchconfig->channel].div=tkchconfig->div; len=3; SendBuf[0]='A'; SendBuf[1]='C'; SendBuf[2]='K'; SendChars((uint8_t *)&len,sizeof(len)); SendChars(SendBuf,3); break; case OP_LISTEN_STATUS: /*Recive : magic_id(64) | len(16) | OP_LISTEN_STATUS(8) | Channel(16) */ /*Send : magic_id(32) | len(16) | struct LISTEN_STATUS(32) | ... | struct LISTEN_STATUS(32) */ RecordCount=0; memcpy((uint8_t *)&RecordChannel,(uint8_t *)(&ReceiveBuf[1]),2); Get_TK_Data(RecordChannel); for(i=0;i<MAX_CHANNEL;i++) { if(RecordChannel & 0x0001) RecordCount++; RecordChannel=RecordChannel>>1; } len=sizeof(LISTEN_STATUS)*RecordCount; SendChars((uint8_t *)&len,sizeof(len)); memcpy((uint8_t *)&RecordChannel,(uint8_t *)(&ReceiveBuf[1]),2); for(i=0;i<MAX_CHANNEL;i++) { if(RecordChannel & 0x0001) { Record.channel=i; Record.data=data[i]; SendChars((uint8_t *)&Record,sizeof(Record)); } RecordChannel=RecordChannel>>1; } break; default: break; } return ; }
bool NotInClass(const CharClass & charClass) const { return !charClass.Contains(GetChar()); }
/*! \brief Extract the data packet from QTouch Studio and set channel config. * \note Should only be called from the command handler. */ void Set_Channel_Config(void) { touch_ret_t touch_ret = TOUCH_SUCCESS; #if ((DEF_TOUCH_QDEBUG_ENABLE_QM == 1) ||\ (DEF_TOUCH_QDEBUG_ENABLE_QTA == 1) ||\ (DEF_TOUCH_QDEBUG_ENABLE_QTB == 1)) sensor_id_t sensor_id; uint8_t type_aks_pos_hyst; #if (DEF_TOUCH_QDEBUG_ENABLE_QM == 1) touch_qm_param_t touch_sensor_param; #endif #if ((DEF_TOUCH_QDEBUG_ENABLE_QTA == 1) || (DEF_TOUCH_QDEBUG_ENABLE_QTB == 1)) touch_qt_param_t touch_sensor_param; #endif sensor_id = GetChar(); /* Read back and initialize the touch_sensor_param structure. * This is because not all the touch_sensor_param members are * updated by this API. */ touch_ret = QDEBUG_GET_SENSOR_CONFIG_FUNC(sensor_id, &touch_sensor_param); if (touch_ret != TOUCH_SUCCESS) { while (1) { } } /* Update the necessary members of the touch_sensor_param structure * and write back. */ touch_sensor_param.detect_threshold = GetChar(); type_aks_pos_hyst = GetChar(); touch_sensor_param.aks_group = (aks_group_t)((uint8_t)((type_aks_pos_hyst & 0x38u) >> 3u)); touch_sensor_param.detect_hysteresis = (hysteresis_t)((uint8_t)(type_aks_pos_hyst & 0x03u)); touch_ret = QDEBUG_UPDATE_SENSOR_CONFIG_FUNC(sensor_id, &touch_sensor_param); if (touch_ret != TOUCH_SUCCESS) { while (1) { } } #endif #if DEF_TOUCH_QDEBUG_ENABLE_AT == 1 sensor_id_t sensor_id; touch_at_param_t touch_sensor_param; sensor_id = GetChar(); /* Dummy. To skip sensor_id. */ UNUSED(sensor_id); /* Dummy. To avoid warning. */ /* Read back and initialize the touch_sensor_param structure. * This is because not all the touch_sensor_param members are * updated by this API. */ touch_ret = QDEBUG_GET_SENSOR_CONFIG_FUNC(&touch_sensor_param); if (touch_ret != TOUCH_SUCCESS) { while (1) { } } /* Update the necessary members of the touch_sensor_param structure * and write back. */ touch_sensor_param.sense = GetChar(); /* Sense level (Detect *Threshold). */ touch_ret = QDEBUG_UPDATE_SENSOR_CONFIG_FUNC(&touch_sensor_param); if (touch_ret != TOUCH_SUCCESS) { while (1) { } } #endif }
void AutoChannelConfig(uint8_t ch,best_cfg* final_result) { uint16_t div, i; uint16_t current = 1; S_TK_CH_CFG ch_cfg = {1, 0, 0xFFFF, 0x0000}; uint8_t sen_level, sen_state,tmp_div; uint16_t sen_data; int8_t tmp_score; uint8_t tmp_cur; uint8_t progress=0; final_result->current = 1; final_result->div = 0; final_result->base = 0; final_result->diff = 0; base_rank[0].val = 0xFFFF; base_rank[0].div = 0; base_rank[0].current = 1; diff_rank[0].val = 0; diff_rank[0].div = 0; diff_rank[0].current = 1; progress=20; SendChars((uint8_t *)&progress,sizeof(progress)); for(div = 1; div < 12; div++) { for(current = 1; current <= 15; current++) { ch_cfg.u8Level = current; ch_cfg.u8Div = div; TK_ConfigChannel(ch, &ch_cfg); result[div][current - 1].level_off = 0; result[div][current - 1].data_off = 0; for(i = 0; i < 2; i++) { complete = 0; TK_Start(1 << ch); while(complete != 1); TK_ReadStatus(&sen_level, &sen_state, NULL); sen_data = TK_ReadData(ch); if(sen_state != 0 || sen_data == 0 || sen_data == 0xFFFF) { result[div][current - 1].level_off = 0; result[div][current - 1].data_off = 0; break; } else { result[div][current - 1].level_off += sen_level; result[div][current - 1].data_off += (sen_data >> 1); } } result[div][current - 1].level_off >>= 1; } } progress=40; SendChars((uint8_t *)&progress,sizeof(progress)); while(1) { if(kbhit()) if(GetChar()==progress) break; } for(div = 1; div < 12; div++) { for(current = 1; current <= 15; current++) { ch_cfg.u8Level = current; ch_cfg.u8Div = div; TK_ConfigChannel(ch, &ch_cfg); result[div][current - 1].level_on = 0; result[div][current - 1].data_on = 0; if(result[div][current - 1].level_off == 0) continue; for(i = 0; i < 2; i++) { complete = 0; TK_Start(1 << ch); while(complete != 1); TK_ReadStatus(&sen_level, &sen_state, NULL); sen_data = TK_ReadData(ch); if(sen_state != 0 || sen_data == 0 || sen_data == 0xFFFF) { result[div][current - 1].level_on = 0; result[div][current - 1].data_on = 0; break; } else { result[div][current - 1].level_on += sen_level; result[div][current - 1].data_on += (sen_data >> 1); } } result[div][current - 1].level_on >>= 1; } } // calculate sense level, timer divider, and change current score for(div = 1; div < 12; div++) { for(current = 1; current <= 15; current++) { result[div][current - 1].score = 0; if((result[div][current - 1].level_off != 0) && (result[div][current - 1].level_on != 0) && (result[div][current - 1].data_on > result[div][current - 1].data_off)) { result[div][current - 1].score += (div_score[div] + cur_score[current] + lvl_score[result[div][current - 1].level_off]); } } } // find out entry with highest diff for(div = 1; div < 12; div++) { for(current = 1; current <= 15; current++) { if(result[div][current - 1].score != 0) { if(((result[div][current - 1].data_on - result[div][current - 1].data_off) > diff_rank[0].val) && (result[div][current - 1].data_on > result[div][current - 1].data_off) && ((result[div][current - 1].data_on - result[div][current - 1].data_off) > 0x100)) { diff_rank[0].val = (result[div][current - 1].data_on - result[div][current - 1].data_off); diff_rank[0].current = current; diff_rank[0].div = div; break; } } } } progress=60; SendChars((uint8_t *)&progress,sizeof(progress)); // give score base on the differences for(div = 1; div < 12; div++) { for(current = 1; current <= 15; current++) { if(result[div][current - 1].score > 0) { if(result[div][current - 1].data_on < result[div][current - 1].data_off) result[div][current - 1].score -= 100; else if((result[div][current - 1].data_on - result[div][current - 1].data_off) < 0x50) result[div][current - 1].score -= 100; else result[div][current - 1].score += (8 - (diff_rank[0].val - (result[div][current - 1].data_on - result[div][current - 1].data_off)) / 0x800); } } } // find out lowest base for(div = 1; div < 12; div++) { for(current = 1; current <= 15; current++) { if(result[div][current - 1].score > 0) { if((result[div][current - 1].data_off < base_rank[0].val) && (result[div][current - 1].data_off < 0xF000)) { base_rank[0].val = result[div][current - 1].data_off; base_rank[0].current = current; base_rank[0].div = div; break; } } } } progress=80; SendChars((uint8_t *)&progress,sizeof(progress)); // give score base on the differences for(div = 1; div < 12; div++) { for(current = 1; current <= 15; current++) { if(result[div][current - 1].score > 0) { result[div][current - 1].score += (4 - (diff_rank[0].val - result[div][current - 1].data_off) / 0x1000); } } } // find the entry with highest score tmp_score = 0; tmp_cur = 1; // eliminate compilation warning tmp_div = 0; // eliminate compilation warning for(div = 1; div < 12; div++) { for(current = 1; current <= 15; current++) { if(result[div][current - 1].score > tmp_score) { tmp_score = result[div][current - 1].score; tmp_div = div; tmp_cur = current; } } } progress=100; SendChars((uint8_t *)&progress,sizeof(progress)); if(tmp_score == 0) { final_result->base=0; final_result->diff=0; final_result->current=0; final_result->div=0; } else { final_result->base = result[tmp_div][tmp_cur - 1].data_off; final_result->diff = result[tmp_div][tmp_cur - 1].data_on - result[tmp_div][tmp_cur - 1].data_off; final_result->current = tmp_cur; final_result->div = tmp_div; } }
/*! \brief Extract the data packet from QTouch Studio and set global config. * \note Should only be called from the command handler. */ void Set_Global_Config(void) { touch_ret_t touch_ret = TOUCH_SUCCESS; #if ((DEF_TOUCH_QDEBUG_ENABLE_QM == 1) ||\ (DEF_TOUCH_QDEBUG_ENABLE_QTA == 1) ||\ (DEF_TOUCH_QDEBUG_ENABLE_QTB == 1)) touch_global_param_t global_params; global_params.recal_threshold = (recal_threshold_t)GetChar(); global_params.di = GetChar(); global_params.drift_hold_time = GetChar(); global_params.max_on_duration = GetChar(); global_params.neg_drift_rate = GetChar(); global_params.pos_drift_rate = GetChar(); global_params.pos_recal_delay = GetChar(); /* update the global parameter value inside the uc3l library */ touch_ret = QDEBUG_UPDATE_GLOBAL_PARAM_FUNC(&global_params); if (touch_ret != TOUCH_SUCCESS) { while (1) { } } #endif #if DEF_TOUCH_QDEBUG_ENABLE_AT == 1 touch_at_param_t touch_sensor_param; uint8_t dummy_var; /* Fill touch_sensor_param structure with default values. * This is because QTouch Studio does not provide sense and outsense * values. So these values should not be overwritten by the update API. * */ touch_ret = QDEBUG_GET_GLOBAL_PARAM_FUNC(&touch_sensor_param); if (touch_ret != TOUCH_SUCCESS) { while (1) { } } /* Update data from QTouch Studio. */ touch_sensor_param.pthr = (recal_threshold_t)GetChar(); touch_sensor_param.filter = GetChar(); dummy_var = GetChar(); /* Skip drift_hold_time. */ dummy_var = GetChar(); /* Skip max_on_duration. */ touch_sensor_param.ndrift = GetChar(); touch_sensor_param.pdrift = GetChar(); UNUSED(dummy_var); /* Dummy. Avoid compiler warning. */ /* update the global parameter value inside the uc3l library */ touch_ret = QDEBUG_UPDATE_GLOBAL_PARAM_FUNC(&touch_sensor_param); if (touch_ret != TOUCH_SUCCESS) { while (1) { } } #endif }
char CUtlBuffer::GetDelimitedChar( CUtlCharConversion *pConv ) { if ( !IsText() || !pConv ) return GetChar( ); return GetDelimitedCharInternal( pConv ); }
//----------------------------------------------------------------------------- // Parses the next token, given a set of character breaks to stop at //----------------------------------------------------------------------------- int CUtlBuffer::ParseToken( characterset_t *pBreaks, char *pTokenBuf, int nMaxLen, bool bParseComments ) { Assert( nMaxLen > 0 ); pTokenBuf[0] = 0; // skip whitespace + comments while ( true ) { if ( !IsValid() ) return -1; EatWhiteSpace(); if ( bParseComments ) { if ( !EatCPPComment() ) break; } else { break; } } char c = GetChar(); // End of buffer if ( c == 0 ) return -1; // handle quoted strings specially if ( c == '\"' ) { int nLen = 0; while( IsValid() ) { c = GetChar(); if ( c == '\"' || !c ) { pTokenBuf[nLen] = 0; return nLen; } pTokenBuf[nLen] = c; if ( ++nLen == nMaxLen ) { pTokenBuf[nLen-1] = 0; return nMaxLen; } } // In this case, we hit the end of the buffer before hitting the end qoute pTokenBuf[nLen] = 0; return nLen; } // parse single characters if ( IN_CHARACTERSET( *pBreaks, c ) ) { pTokenBuf[0] = c; pTokenBuf[1] = 0; return 1; } // parse a regular word int nLen = 0; while ( true ) { pTokenBuf[nLen] = c; if ( ++nLen == nMaxLen ) { pTokenBuf[nLen-1] = 0; return nMaxLen; } c = GetChar(); if ( !IsValid() ) break; if ( IN_CHARACTERSET( *pBreaks, c ) || c == '\"' || c <= ' ' ) { SeekGet( SEEK_CURRENT, -1 ); break; } } pTokenBuf[nLen] = 0; return nLen; }
/*---------------------------------------------------------------------------------------------------------*/ void AutoFlow_FunctionRxTest() { uint32_t u32i; printf("\n"); printf("+-----------------------------------------------------------+\n"); printf("| Pin Configure |\n"); printf("+-----------------------------------------------------------+\n"); printf("| ______ _____ |\n"); printf("| | | | | |\n"); printf("| |Master|--UART1_TXD(PB.5) <==> UART1_RXD(PB.4)--|Slave| |\n"); printf("| | |--UART1_nCTS(PB.7) <==> UART1_nRTS(PB.6)--| | |\n"); printf("| |______| |_____| |\n"); printf("| |\n"); printf("+-----------------------------------------------------------+\n"); printf("\n"); printf("+-----------------------------------------------------------+\n"); printf("| AutoFlow Function Test (Slave) |\n"); printf("+-----------------------------------------------------------+\n"); printf("| Description : |\n"); printf("| The sample code needs two boards. One is Master and |\n"); printf("| the other is slave. Master will send 1k bytes data |\n"); printf("| to slave.Slave will check if received data is correct |\n"); printf("| after getting 1k bytes data. |\n"); printf("| Press any key to start... |\n"); printf("+-----------------------------------------------------------+\n"); GetChar(); /* Enable RTS and CTS autoflow control */ UART_EnableFlowCtrl(UART1); /* Set RTS Trigger Level as 8 bytes */ UART1->FCR &= ~UART_FCR_RTS_TRI_LEV_Msk; UART1->FCR |= UART_FCR_RTS_TRI_LEV_8BYTES; /* Set RX Trigger Level as 8 bytes */ UART1->FCR &= ~UART_FCR_RFITL_Msk; UART1->FCR |= UART_FCR_RFITL_8BYTES; /* Set Timeout time 0x3E bit-time and time-out counter enable */ UART_SetTimeoutCnt(UART1, 0x3E); /* Enable RDA\RLS\RTO Interrupt */ UART_EnableInt(UART1, (UART_IER_RDA_IEN_Msk | UART_IER_RLS_IEN_Msk | UART_IER_TOUT_IEN_Msk)); printf("\n Starting to receive data...\n"); /* Wait for receive 1k bytes data */ while(g_i32pointer < RXBUFSIZE); /* Compare Data */ for(u32i = 0; u32i < RXBUFSIZE; u32i++) { if(g_u8RecData[u32i] != (u32i & 0xFF)) { printf("Compare Data Failed\n"); while(1); } } printf("\n Receive OK & Check OK\n"); /* Disable RDA\RLS\RTO Interrupt */ UART_DisableInt(UART1, (UART_IER_RDA_IEN_Msk | UART_IER_RLS_IEN_Msk | UART_IER_TOUT_IEN_Msk)); }
bool wxSimpleHtmlParser::EatWhitespace() { while (!Eof() && IsWhitespace(GetChar(m_pos))) m_pos ++; return TRUE; }
int skapmot(void) { struct ShortUser *shortUser; int mad, setPermission, changed, ch, i, fidoDomainId, highestId; struct FidoDomain *fidoDomain; BPTR lock; struct User user; struct Mote tmpConf,*searchConf,*newConf; memset(&tmpConf, 0, sizeof(struct Mote)); if(argument[0] == '\0') { SendString("\r\n\nNamn på mötet: "); if(GetString(40,NULL)) { return 1; } strcpy(tmpConf.namn, inmat); } else { strcpy(tmpConf.namn, argument); } if(parsemot(tmpConf.namn) != -1) { SendString("\r\n\nFinns redan ett sådant möte!\r\n"); return 0; } tmpConf.skapat_tid = time(NULL);; tmpConf.skapat_av = inloggad; for(;;) { SendString("\r\nMötesAdministratör (MAD) : "); if(GetString(5,NULL)) { return 1; } if(inmat[0]) { if((mad = parsenamn(inmat)) == -1) { SendString("\r\nFinns ingen sådan användare!"); } else { tmpConf.mad = mad; break; } } } SendString("\n\rSorteringsvärde: "); tmpConf.sortpri = GetNumber(0, LONG_MAX, NULL); if(EditBitFlagShort("\r\nSka mötet vara slutet?", 'j', 'n', "Slutet", "Öppet", &tmpConf.status, SLUTET)) { return 1; } if(tmpConf.status & SLUTET) { SendString("\r\nVilka grupper ska ha tillgång till mötet? (? för lista)\r\n"); if(editgrupp((char *)&tmpConf.grupper)) { return 1; } } if(EditBitFlagShort("\r\nSka mötet vara skrivskyddat?", 'j', 'n', "Skyddat", "Oskyddat", &tmpConf.status, SKRIVSKYDD)) { return 1; } if(EditBitFlagShort("\r\nSka mötet vara kommentarsskyddat?", 'j', 'n', "Skyddat", "Oskyddat", &tmpConf.status, KOMSKYDD)) { return 1; } if(EditBitFlagShort("\r\nSka mötet vara hemligt?", 'j', 'n', "Hemligt", "Ej hemligt", &tmpConf.status, HEMLIGT)) { return 1; } if(!(tmpConf.status & SLUTET)) { if(EditBitFlagShort("\r\nSka alla användare bli medlemmar automagiskt?", 'j', 'n', "Ja", "Nej", &tmpConf.status, AUTOMEDLEM)) { return 1; } if(EditBitFlagShort("\r\nSka rättigheterna styra skrivmöjlighet?", 'j', 'n', "Ja", "Nej", &tmpConf.status, SKRIVSTYRT)) { return 1; } if(tmpConf.status & SKRIVSTYRT) { SendString("\r\nVilka grupper ska ha tillgång till mötet? (? för lista)\r\n"); if(editgrupp((char *)&tmpConf.grupper)) { return 1; } } } if(EditBitFlagShort("\r\nSka mötet enbart kommas åt från ARexx?", 'j', 'n', "Ja", "Nej", &tmpConf.status, SUPERHEMLIGT)) { return 1; } SendString("\n\n\rVilken typ av möte ska det vara?\n\r"); SendString("1: Lokalt möte\n\r"); SendString("2: Fido-möte\n\n\r"); SendString("Val: "); for(;;) { ch = GetChar(); if(ch == GETCHAR_LOGOUT) { return 1; } if(ch == '1' || ch == '2') { break; } } if(ch == '1') { SendString("Lokalt möte\n\n\r"); tmpConf.type = MOTE_ORGINAL; } else { SendString("Fido-möte\n\n\r"); tmpConf.type = MOTE_FIDO; if(EditString("Katalog for .msg-filerna", tmpConf.dir, 79, TRUE)) { return 1; } if(!(lock = Lock(tmpConf.dir, SHARED_LOCK))) { if(!(lock = CreateDir(tmpConf.dir))) SendString("\n\rKunde inte skapa katalogen\n\r"); } if(lock) { UnLock(lock); } if(EditString("FidoNet tag-namn", tmpConf.tagnamn, 49, TRUE)) { return 1; } strcpy(tmpConf.origin, Servermem->fidodata.defaultorigin); if(MaybeEditString("Origin-rad", tmpConf.origin, 69)) { return 1; } SendString("\n\n\rVilken teckenuppsättning ska användas för utgående texter?\n\r"); SendString("1: ISO Latin 1 (ISO 8859-1)\n\r"); SendString("2: SIS-7 (SF7, 'Måsvingar')\n\r"); SendString("3: IBM CodePage\n\r"); SendString("4: Mac\n\n\r"); SendString("Val: "); for(;;) { ch = GetChar(); if(ch == GETCHAR_LOGOUT) { return 1; } if(ch == '1' || ch == '2' || ch == '3' || ch == '4') { break; } } switch(ch) { case '1': SendString("ISO Latin 1\n\n\r"); tmpConf.charset = CHRS_LATIN1; break; case '2': SendString("SIS-7\n\n\r"); tmpConf.charset = CHRS_SIS7; break; case '3': SendString("IBM CodePage\n\n\r"); tmpConf.charset = CHRS_CP437; break; case '4': SendString("Mac\n\n\r"); tmpConf.charset = CHRS_MAC; break; } SendString("Vilken domän är mötet i?\n\r"); highestId = 0; for(i = 0; i < 10; i++) { if(!Servermem->fidodata.fd[i].domain[0]) { break; } highestId = max(highestId, Servermem->fidodata.fd[i].nummer); SendString("%3d: %s (%d:%d/%d.%d)\n\r", Servermem->fidodata.fd[i].nummer, Servermem->fidodata.fd[i].domain, Servermem->fidodata.fd[i].zone, Servermem->fidodata.fd[i].net, Servermem->fidodata.fd[i].node, Servermem->fidodata.fd[i].point); } if(i == 0) { SendString("\n\rDu måste definiera en domän i NiKomFido.cfg först!\n\r"); return 0; } for(;;) { SendString("\r\nDomän: "); if(GetString(5, NULL)) { return 1; } fidoDomainId = atoi(inmat); if(fidoDomain = getfidodomain(fidoDomainId, 0)) { break; } else { SendString("\n\rFinns ingen sådan domän.\n\r"); } } tmpConf.domain = fidoDomain->nummer; SendString("%s\n\n\r", fidoDomain->domain); } for(i = 0; i < MAXMOTE; i++) { if(getmotpek(i) == NULL) { break; } } if(i >= MAXMOTE) { SendString("\n\n\rDet finns inte plats för fler möten.\n\r"); return 0; } tmpConf.nummer = i; if(!(newConf = (struct Mote *)AllocMem(sizeof(struct Mote), MEMF_CLEAR | MEMF_PUBLIC))) { LogEvent(SYSTEM_LOG, ERROR, "Could not allocate %d bytes.", sizeof(struct Mote)); DisplayInternalError(); return 0; } memcpy(newConf, &tmpConf, sizeof(struct Mote)); ITER_EL(searchConf, Servermem->mot_list, mot_node, struct Mote *) { if(searchConf->sortpri > newConf->sortpri) { break; } } searchConf = (struct Mote *)searchConf->mot_node.mln_Pred; Insert((struct List *)&Servermem->mot_list, (struct Node *)newConf, (struct Node *)searchConf); writemeet(newConf); if((newConf->status & AUTOMEDLEM) && !(newConf->status & SKRIVSTYRT)) { return 0; } if(newConf->status & SUPERHEMLIGT) { return 0; } setPermission = (newConf->status & (SLUTET | SKRIVSTYRT)) ? FALSE : TRUE; for(i = 0; i < MAXNOD; i++) { BAMCLEAR(Servermem->inne[i].motmed, newConf->nummer); if(setPermission) { BAMSET(Servermem->inne[i].motratt, newConf->nummer); } else { BAMCLEAR(Servermem->inne[i].motratt, newConf->nummer); } } SendString("\r\nÄndrar i användardata..\r\n"); ITER_EL(shortUser, Servermem->user_list, user_node, struct ShortUser *) { if(!(shortUser->nummer % 10)) { SendString("\r%d", shortUser->nummer); } if(readuser(shortUser->nummer, &user)) { LogEvent(SYSTEM_LOG, ERROR, "Could not read user %d to set " "membership/permissions for new conference.", shortUser->nummer); DisplayInternalError(); return 0; } changed = FALSE; if(setPermission != BAMTEST(user.motratt, newConf->nummer)) { if(setPermission) { BAMSET(user.motratt, newConf->nummer); } else { BAMCLEAR(user.motratt, newConf->nummer); } changed = TRUE; } if(!(newConf->status & AUTOMEDLEM) && BAMTEST(user.motmed, newConf->nummer)) { BAMCLEAR(user.motmed, newConf->nummer); changed = TRUE; } if(changed && writeuser(shortUser->nummer, &user)) { LogEvent(SYSTEM_LOG, ERROR, "Could not write user %d to set " "membership/permissions for new conference.", shortUser->nummer); DisplayInternalError(); return 0; } } for(i = 0; i < MAXNOD; i++) { BAMCLEAR(Servermem->inne[i].motmed, newConf->nummer); if(setPermission) { BAMSET(Servermem->inne[i].motratt, newConf->nummer); } else { BAMCLEAR(Servermem->inne[i].motratt, newConf->nummer); } } BAMSET(Servermem->inne[nodnr].motratt, newConf->nummer); BAMSET(Servermem->inne[nodnr].motmed, newConf->nummer); if(newConf->type == MOTE_FIDO) { ReScanFidoConf(newConf, 0); } return 0; }
bool wxSimpleHtmlParser::EatWhitespace(int& pos) { while (!Eof(pos) && IsWhitespace(GetChar(pos))) pos ++; return TRUE; }
void MSA::ToAlnFile(TextFile &File) const { if (getMuscleContext()->params.g_bClwStrict) File.PutString("CLUSTAL W (1.81) multiple sequence alignment\n"); else { File.PutString("MUSCLE (" MUSCLE_MAJOR_VERSION "." MUSCLE_MINOR_VERSION ")" " multiple sequence alignment\n"); File.PutString("\n"); } int iLongestNameLength = 0; for (unsigned uSeqIndex = 0; uSeqIndex < GetSeqCount(); ++uSeqIndex) { const char *ptrName = GetSeqName(uSeqIndex); const char *ptrBlank = strchr(ptrName, ' '); int iLength; if (0 != ptrBlank) iLength = (int) (ptrBlank - ptrName); else iLength = (int) strlen(ptrName); if (iLength > iLongestNameLength) iLongestNameLength = iLength; } if (iLongestNameLength > MAX_NAME) iLongestNameLength = MAX_NAME; if (iLongestNameLength < MIN_NAME) iLongestNameLength = MIN_NAME; unsigned uLineCount = (GetColCount() - 1)/uCharsPerLine + 1; for (unsigned uLineIndex = 0; uLineIndex < uLineCount; ++uLineIndex) { File.PutString("\n"); unsigned uStartColIndex = uLineIndex*uCharsPerLine; unsigned uEndColIndex = uStartColIndex + uCharsPerLine - 1; if (uEndColIndex >= GetColCount()) uEndColIndex = GetColCount() - 1; char Name[MAX_NAME+1]; for (unsigned uSeqIndex = 0; uSeqIndex < GetSeqCount(); ++uSeqIndex) { const char *ptrName = GetSeqName(uSeqIndex); const char *ptrBlank = strchr(ptrName, ' '); int iLength; if (0 != ptrBlank) iLength = (int) (ptrBlank - ptrName); else iLength = (int) strlen(ptrName); if (iLength > MAX_NAME) iLength = MAX_NAME; memset(Name, ' ', MAX_NAME); memcpy(Name, ptrName, iLength); Name[iLongestNameLength] = 0; File.PutFormat("%s ", Name); for (unsigned uColIndex = uStartColIndex; uColIndex <= uEndColIndex; ++uColIndex) { const char c = GetChar(uSeqIndex, uColIndex); File.PutFormat("%c", toupper(c)); } File.PutString("\n"); } memset(Name, ' ', MAX_NAME); Name[iLongestNameLength] = 0; File.PutFormat("%s ", Name); for (unsigned uColIndex = uStartColIndex; uColIndex <= uEndColIndex; ++uColIndex) { const char c = GetAlnConsensusChar(*this, uColIndex); File.PutChar(c); } File.PutString("\n"); } }
bool wxSimpleHtmlParser::IsString() { return (GetChar(m_pos) == (int) '"') ; }
inline bool CField::operator!=(tchar cValue) const { return (cValue != GetChar()); }
bool wxSimpleHtmlParser::IsWord() { return (IsAlpha(GetChar(m_pos))); }
void GetLine( char * buffer, const unsigned int size, int EchoFlag ) { char ch = 0 ; int c; char* p = buffer ; unsigned int n = 0L ; int i ; while( n < size ) { c = GetChar() ; if( c == -1 ) { continue; } ch = c; //dprintf("%x ",ch); if( ch == KEYCODE_LF ) { #ifdef USE_LF *--p = 0 ; n-- ; #endif // USE_LF break ; } else if( ch == KEYCODE_CR ) { *p = 0 ; #ifndef CONFIG_HISTORY_KEYIN n-- ; #else //#ifdef CONFIG_HISTORY_KEYIN if(n!=0) { strcpy(history_cmd[hist_save_idx], buffer); (hist_save_idx >= HISTORY_CMD_ELN-1) ? hist_save_idx=0 : hist_save_idx++; hist_see_idx=hist_save_idx; } #endif break ; } else if( ch == KEYCODE_BS_7F ) { if( p != buffer ) { p-- ; n-- ; if(EchoFlag) { PutChar(KEYCODE_BS); PutChar(' '); PutChar(KEYCODE_BS); } } } else if( ch == KEYCODE_TAB ) { for( i=0 ; i < TAB ; i++ ) { *p++ = ' ' ; n++ ; if(EchoFlag) PutChar(' '); } } #ifdef CONFIG_HISTORY_KEYIN else if( ch == KEYCODE_ESC ) { if( GetChar()!= KEYCODE_BRACKET) continue; c=GetChar(); unsigned int vk= ( KEYCODE_ESC <<24) | (KEYCODE_BRACKET<<16) | (c<<8) | 0 ; if( vk==KEYCODE_VKUP) { (hist_see_idx==0) ? hist_see_idx= HISTORY_CMD_ELN-1 : hist_see_idx--; } else if(vk== KEYCODE_VKDOWN) { (hist_see_idx==HISTORY_CMD_ELN-1) ? hist_see_idx= 0 : hist_see_idx++; } else continue; //clear for(i=0;i<n;i++) { PutChar(KEYCODE_BS); PutChar(' '); PutChar(KEYCODE_BS); } strcpy(buffer, history_cmd[hist_see_idx]); n= strlen(buffer); p=buffer+n; dprintf("%s", buffer); } #endif else { *p++ = ch ; n++ ; if(EchoFlag) PutChar(ch); } } }
public void DecodeISO2022( state_t *state, byte codingSystem ) { int region; byte charset, ch, rch; byte c[ ICHAR_WIDTH ]; for( ; ; ){ GetChar( ch ); if( ch < SP ){ if( ESC == ch ){ if( FALSE == DecodeEscape( state ) ) break; } else if( HT == ch ) DecodeAddTab( state->attr ); else if( SO == ch ) /* LS1 for 8bit */ state->gset[ GL ] = G1; else if( SI == ch ) /* LS0 for 8bit */ state->gset[ GL ] = G0; else if( BS == ch ) DecodeAddBs(); else if( EM == ch ) state->sset = G2; else DecodeAddControl( ch ); } else { if( '~' == ch && TRUE == hz_detection ){ switch( STR[ SIDX ] ){ case '~': if( ASCII == state->cset[ G0 ] ) IncStringIndex(); break; /* break for '~' itself.*/ case '{': if( ASCII == state->cset[ G0 ] ){ IncStringIndex(); state->cset[ G0 ] = GB2312; continue; } break; case '}': if( GB2312 == state->cset[ G0 ] ){ IncStringIndex(); state->cset[ G0 ] = ASCII; continue; } break; } } rch = ch; if( 0 != state->sset ){ /* * single shifted character */ if( EUC_TAIWAN == codingSystem && G2 == state->sset ){ charset = CNS_1 + ( ch - 0xa1 ); if( charset < CNS_1 || charset > CNS_7 ){ state->sset = 0; continue; } GetChar( ch ); } else { charset = SSET; } state->sset = 0; ch &= 0x7f; /* for EUC */ if( !IsGraphicChar( charset, ch ) ){ if( SP == ch ){ DecodeAddSpace( state->attr ); } else { DecodeAddControl( rch ); } continue; } c[ 0 ] = ch; if( TRUE == iTable[ (int)charset ].multi ){ GetChar( ch ); if( !IsGraphicChar( charset, ch & 0x7f ) ){ DecodeAddControl( rch ); DecodeAddControl( ch ); continue; } c[ 1 ] = ch & 0x7f; /* for EUC */ } } else { if( 0x80 & ch ){ if( SS2 == ch ){ state->sset = G2; continue; } else if( SS3 == ch ){ state->sset = G3; continue; } region = GR; ch &= 0x7f; } else { region = GL; } charset = CSET( region ); if( !IsGraphicChar( charset, ch ) ){ if( SP == ch ){ DecodeAddSpace( state->attr ); } else { DecodeAddControl( rch ); } continue; } c[ 0 ] = ch; if( TRUE == iTable[ (int)charset ].multi ){ GetChar( ch ); ch &= 0x7f; if( !IsGraphicChar( charset, ch ) ) continue; c[ 1 ] = ch; } } DecodeAddChar( charset, c, state->attr ); } } }
void CObjectIStreamAsn::ReadAnyContent(string& value) { char buf[128]; size_t pos=0; const size_t maxpos=128; char to = GetChar(true); buf[pos++] = to; if (to == '{') { to = '}'; } else if (to == '\"') { } else { to = '\0'; } bool space = false; for (char c = m_Input.PeekChar(); ; c = m_Input.PeekChar()) { if (to != '\"') { if (to != '}' && c == '\n') { value.append(buf,pos); return; } if (isspace((unsigned char) c)) { if (space) { m_Input.SkipChar(); continue; } c = ' '; space = true; } else { space = false;; } if (to != '}' && (c == ',' || c == '}')) { value.append(buf,pos); return; } else if (c == '\"' || c == '{') { value.append(buf,pos); ReadAnyContent(value); pos = 0; continue; } } if (c == to) { if (pos >= maxpos) { value.append(buf,pos); pos = 0; } buf[pos++] = c; value.append(buf,pos); m_Input.SkipChar(); return; } if (c == '\"' || c == '{') { value.append(buf,pos); ReadAnyContent(value); pos = 0; continue; } if (pos >= maxpos) { value.append(buf,pos); pos = 0; } buf[pos++] = c; m_Input.SkipChar(); } }
char TOpt::GetCharOr0() const { if (Chars_.empty()) return 0; return GetChar(); }
const char* TiXmlBase::ReadText( const char* p, TIXML_STRING * text, bool trimWhiteSpace, const char* endTag, bool caseInsensitive, TiXmlEncoding encoding ) { *text = ""; if ( !trimWhiteSpace // certain tags always keep whitespace || !condenseWhiteSpace ) // if true, whitespace is always kept { // Keep all the white space. while ( p && *p && !StringEqual( p, endTag, caseInsensitive, encoding ) ) { int len; char cArr[4] = { 0, 0, 0, 0 }; p = GetChar( p, cArr, &len, encoding ); text->append( cArr, len ); } } else { bool whitespace = false; // Remove leading white space: p = SkipWhiteSpace( p, encoding ); while ( p && *p && !StringEqual( p, endTag, caseInsensitive, encoding ) ) { if ( *p == '\r' || *p == '\n' ) { whitespace = true; ++p; } else if ( IsWhiteSpace( *p ) ) { whitespace = true; ++p; } else { // If we've found whitespace, add it before the // new character. Any whitespace just becomes a space. if ( whitespace ) { (*text) += ' '; whitespace = false; } int len; char cArr[4] = { 0, 0, 0, 0 }; p = GetChar( p, cArr, &len, encoding ); if ( len == 1 ) (*text) += cArr[0]; // more efficient else text->append( cArr, len ); } } } if ( p ) p += strlen( endTag ); return p; }
WandExport MagickBooleanType GetScriptToken(ScriptTokenInfo *token_info) { int quote, c; int state; ssize_t offset; /* EOF - no more tokens! */ if (token_info->status != TokenStatusOK) { token_info->token[0]='\0'; return(MagickFalse); } state=IN_WHITE; quote='\0'; offset=0; while(1) { /* get character */ GetChar(c); /* hash comment handling */ if ( state == IN_COMMENT ) { if ( c == '\n' ) state=IN_WHITE; continue; } /* comment lines start with '#' anywhere, or ':' or '@' at start of line */ if ( state == IN_WHITE ) if ( ( c == '#' ) || ( token_info->curr_column==1 && (c == ':' || c == '@' ) ) ) state=IN_COMMENT; /* whitespace token seperator character */ if (strchr(" \n\r\t",c) != (char *)NULL) { switch (state) { case IN_TOKEN: token_info->token[offset]='\0'; return(MagickTrue); case IN_QUOTE: SaveChar(c); break; } continue; } /* quote character */ if ( c=='\'' || c =='"' ) { switch (state) { case IN_WHITE: token_info->token_line=token_info->curr_line; token_info->token_column=token_info->curr_column; case IN_TOKEN: state=IN_QUOTE; quote=c; break; case IN_QUOTE: if (c == quote) { state=IN_TOKEN; quote='\0'; } else SaveChar(c); break; } continue; } /* escape char (preserve in quotes - unless escaping the same quote) */ if (c == '\\') { if ( state==IN_QUOTE && quote == '\'' ) { SaveChar('\\'); continue; } GetChar(c); if (c == '\n') switch (state) { case IN_COMMENT: state=IN_WHITE; /* end comment */ case IN_QUOTE: if (quote != '"') break; /* in double quotes only */ case IN_WHITE: case IN_TOKEN: continue; /* line continuation - remove line feed */ } switch (state) { case IN_WHITE: token_info->token_line=token_info->curr_line; token_info->token_column=token_info->curr_column; state=IN_TOKEN; break; case IN_QUOTE: if (c != quote && c != '\\') SaveChar('\\'); break; } SaveChar(c); continue; } /* ordinary character */ switch (state) { case IN_WHITE: token_info->token_line=token_info->curr_line; token_info->token_column=token_info->curr_column; state=IN_TOKEN; case IN_TOKEN: case IN_QUOTE: SaveChar(c); break; case IN_COMMENT: break; } } /* input stream has EOF or produced a fatal error */ token_info->token[offset]='\0'; if ( token_info->status != TokenStatusOK ) return(MagickFalse); /* fatal condition - no valid token */ token_info->status = TokenStatusEOF; if ( state == IN_QUOTE) token_info->status = TokenStatusBadQuotes; if ( state == IN_TOKEN) return(MagickTrue); /* token with EOF at end - no problem */ return(MagickFalse); /* in white space or in quotes - invalid token */ }
//------------------------------------------------------------------------------ TCHAR FBasicTokenParser::GetLeadingChar() { // if the parser is in a bad state, then don't continue parsing (who // knows what will happen!?)... return a char signaling the end-of-stream if (!IsValid()) { return 0; } TCHAR TrailingCommentNewline = 0; for (;;) { bool MultipleNewlines = false; TCHAR c; // Skip blanks. do { c = GetChar(); // Check if we've encountered another newline since the last one if (c == TrailingCommentNewline) { MultipleNewlines = true; } } while (IsWhitespace(c)); if (c != TEXT('/') || PeekChar() != TEXT('/')) { return c; } // Clear the comment if we've encountered newlines since the last comment if (MultipleNewlines) { ClearCachedComment(); } // Record the first slash. The first iteration of the loop will get the second slash. PrevComment += c; do { c = GetChar(true); if (c == 0) return c; PrevComment += c; } while (!IsEOL(c)); TrailingCommentNewline = c; for (;;) { c = GetChar(); if (c == 0) return c; if (c == TrailingCommentNewline || !IsEOL(c)) { UngetChar(); break; } PrevComment += c; } } }
void TextFile::GetCharX(char &c) { bool bEof = GetChar(c); if (bEof) Quit("End-of-file in GetCharX"); }