bool ConfigurationSection::ReadValue(const char* name, bool& value) const { // try string format std::string key(name); std::map<std::string,std::string>::const_iterator it = container_.find(key); if (it != container_.end()) { const std::string str(it->second); if (str=="y" || str=="Y" || str=="yes" || str == "Yes" || str=="true" || str == "True" || str == "1") { value = true; return true; } else if (str=="n" || str=="N" || str=="no" || str == "No" || str=="false" || str == "False" || str == "0") { value = false; return true; } else { BadFormat(name, str.c_str()); } } return false; }
static MEMO_EL * ReadAMemo( FILE * fid ) /**************************************/ /* Read one memo, creating the memo structure and filling it * in. Return a pointer to the memo (NULL if none read). */ { MEMO_EL * el; int len; TEXT_LINE * line; char buffer[MAXLEN]; len = ReadLine( buffer, MAXLEN, fid ); if( len == EOF ) { return( NULL ); } /* First line must be of the form "Date:" or "Date:YY/MM/DD": */ if( (len != 5 && len != 13) || strncmp( buffer, "Date:", 5 ) != 0 ) { BadFormat(); } buffer[len] = NULLCHAR; el = MemoMAlloc( sizeof( MEMO_EL ) ); el->text = NULL; strcpy( el->date, buffer + 5 ); line = NULL; for( ;; ) { len = ReadLine( buffer, MAXLEN, fid ); if( len == EOF ) { BadFormat(); } buffer[len] = NULLCHAR; if( strcmp( buffer, "====" ) == 0 ) { return( el ); } line = AddLine( buffer, el, line ); } }
/////////////////////////////////////////////////////////////////////////////// // validatePixelSizeInBytes - compute pixel size, measured in bytes /////////////////////////////////////////////////////////////////////////////// GLsizei Image::validatePixelSizeInBytes() { switch (format()) { case GL_LUMINANCE: _pixelSizeInBytes = 1; break; case GL_LUMINANCE_ALPHA: _pixelSizeInBytes = 2; break; case GL_RGB: _pixelSizeInBytes = 3; break; case GL_RGBA: _pixelSizeInBytes = 4; break; default: throw BadFormat(format()); } switch (type()) { case GL_BYTE: case GL_UNSIGNED_BYTE: break; case GL_SHORT: case GL_UNSIGNED_SHORT: _pixelSizeInBytes <<= 1; break; case GL_INT: case GL_UNSIGNED_INT: case GL_FLOAT: _pixelSizeInBytes <<= 2; break; default: throw BadType(type()); } validate(vbPixelSizeInBytes); return _pixelSizeInBytes; }
bool ReadIntegralValue(const char* name, T& value) const { // try string format std::string key(name); std::map<std::string,std::string>::const_iterator it = container_.find(key); if (it != container_.end()) { std::string str(it->second); char* endpos; if (str.length() > 2 && str[0]=='0' && (str[1]=='x' || str[1]=='X')) { strtoint(str.c_str()+2, &endpos, 16, value); } else { strtoint(str.c_str(), &endpos, 10, value); } if (*endpos) BadFormat(name, str.c_str()); return true; } return false; }
BOOL ParseDirLine(Connection *Connect,BOOL AllFiles,FTPFileInfo* p) { PROC(("ParseDirLine", "%p,%d", Connect, AllFiles)) String Line, Line1; FTPDirList dl; FTPServerInfo si; while(true) { Connect->GetOutput(Line); if(!Line.Length()) break; if(strstr(Line.c_str(),": Permission denied")) { WINPORT(SetLastError)(ERROR_ACCESS_DENIED); return FALSE; } if(Line.Length() < 20) continue; //Check contains skipped text static LPCSTR FTPMsg[] = { "data connection", "transfer complete", "bytes received", "DEVICE:[", "Total of " }; BOOL Found = FALSE; for(size_t n = 0; n < ARRAYSIZE(FTPMsg); n++) if(strstr(Line.c_str(),FTPMsg[n])) { Found = TRUE; break; } if(Found) continue; //Check special skip strings if(StrCmp(Line.c_str(), "Directory ", 10) == 0 && strchr(Line.c_str()+10,'[') != NULL) continue; //Set start detect info memset(p, 0, sizeof(*p)); si.ServerType = Connect->Host.ServerType; StrCpy(si.ServerInfo, Connect->SystemInfo, ARRAYSIZE(si.ServerInfo)); //Use temp buffer Line1 = Line; //Detect WORD idx; FTPType* tp = dl.GetType(Connect->Host.ServerType); if(Connect->Host.ServerType == FTP_TYPE_DETECT || Connect->Host.ServerType == FTP_TYPE_INVALID || tp == NULL) { idx = dl.DetectStringType(&si, Line.c_str(), Line.Length()); if(idx == FTP_TYPE_INVALID || (tp=dl.GetType(idx)) == NULL) { LogCmd(Message("ParserDETECT: %s->%s [%s]", Parser2Str(Connect->Host.ServerType,&dl), Parser2Str(idx,&dl), Line1.c_str()), ldInt); if(Connect->Host.ServerType != FTP_TYPE_DETECT && Connect->Host.ServerType != FTP_TYPE_INVALID) { LogCmd(Message("ParserIGNORE: [%s]", Line1.c_str()), ldInt); Connect->AddCmdLine(Message("ParserIGNORE: [%s]", Line1.c_str())); continue; } BadFormat(Connect,Line1.c_str(),FALSE); break; } else { Log(("ParserDETECTED: %s->%s [%s]",Parser2Str(Connect->Host.ServerType,&dl),Parser2Str(idx,&dl),Line1.c_str())); Connect->Host.ServerType = idx; } } else idx = Connect->Host.ServerType; //Use temp buffer Line = Line1; Log(("toParse: %d,[%s], %d",Line.Length(),Line.c_str())); //Parse if(!tp->Parser(&si,p,Line.c_str(),Line.Length())) { LogCmd(Message("ParserFAIL: %s->%s [%s]", Parser2Str(Connect->Host.ServerType,&dl), Parser2Str(idx,&dl), Line1.c_str()), ldInt); Connect->AddCmdLine(Message("ParserFAIL: (%s) [%s]", Parser2Str(idx,&dl), Line1.c_str())); continue; } //Skip entryes char *CurName = FTP_FILENAME(p); if(p->FileType == NET_SKIP || !CurName[0] || StrCmp(CurName,".") == 0 || (!AllFiles && StrCmp(CurName,"..") == 0)) continue; //Correct attrs if(p->FileType == NET_DIRECTORY || p->FileType == NET_SYM_LINK_TO_DIR) SET_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY); if(p->FileType == NET_SYM_LINK_TO_DIR || p->FileType == NET_SYM_LINK) SET_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_REPARSE_POINT); //Convert name text // Connect->ToOEM(CurName); //OK return TRUE; } WINPORT(SetLastError)(ERROR_NO_MORE_FILES); return FALSE; }