int ReadEntityText( const char *pc, const char *pc1, CharBuf &cb ){ if( !pc ) return -1; if( !pc1 ) pc1=pc+strlen(pc); cb.Reset( ); cb.Resize( pc1-pc ); const char *ent; char ebuf[4]; while( pc<pc1 ){ ent = strchr(pc,'&'); if( !ent ) break; cb.Append( pc,ent-pc ); ent = SkipSpace(ent+1); if( !strncmp(ent,"lt",2) ) *ebuf='<', ent+=2; else if( !strncmp(ent,"gt",2) ) *ebuf='>', ent+=2; else if( !strncmp(ent,"amp",3) ) *ebuf='&', ent+=3; else if( !strncmp(ent,"quot",4) ) *ebuf='\"', ent+=4; else if( !strncmp(ent,"apos",4) ) *ebuf='\'', ent+=4; else return -2; ent = SkipSpace(ent); if( *ent!=';' ) return -3; if( ent>=pc1 ) return -4; cb.Append( ebuf, 1 ); pc = ent+1; } cb.Append( pc, pc1-pc ); return 0; }
int AcceptAttrib( const char *&xml, CharBuf& name, CharBuf& val, const char *expect ){ if( !xml ) return -1; const char *pc = SkipSpace(xml), *pc1; // Accept name if( expect && !keywordeq(pc,expect) ) return 1; for( pc1=pc; isalnum(*pc1); pc1++ ); if( pc1==pc ) return -1; name.Assign( pc,pc1 ); pc = SkipSpace(pc1); // Equals? if( *pc!='=' ) return -2; pc = SkipSpace(pc+1); // Quoted value, go past escaped quotes if( *pc!='\"' && *pc!='\'' ) return -3; pc1 = strchr(pc+1,*pc); if( !pc1 ) return -4; // Assign value if( ReadEntityText(pc+1,pc1,val) ) return -5; // Skip space xml = SkipSpace(pc1+1); return 0; }
/* ROOT 21147648 05/29/08 10:16:58 *FILE AMSAVF.SAVF ROOT 217088 04/14/08 11:41:28 *FILE CYN_COLLEC.FILE ROOT *MEM CYN_COLLEC.FILE/SH.MBR ROOT 16384 04/08/08 12:17:34 *FILE EVFEVENT.FILE ROOT 954368 04/08/08 11:48:21 *FILE LIBCCLOG.SAVF ROOT 163840 04/08/08 11:48:21 *FILE LIBCFFDC.SAVF ROOT 503808 04/08/08 11:48:21 *FILE LIBMSG23.SAVF QPGMR 143360 08/05/06 18:09:14 *FILE QAAPFILE.FILE QPGMR *MEM QAAPFILE.FILE/QAAPF1X1.MBR QPGMR *MEM QAAPFILE.FILE/QAAPF1X2.MBR QPGMR *MEM QAAPFILE.FILE/QAAPF2X2.MBR QSYS 131072 06/27/06 19:12:53 *DIR QOpenSys/ QDOC 69120 12/31/69 19:00:00 *FLR QDLS/ QSYS 13778944 07/10/06 16:21:25 *LIB QSYS.LIB/ QDFTOWN 4096 12/31/69 19:00:00 *DDIR QOPT/ QSYS 2272 07/05/06 06:08:14 *DDIR QFileSvr.400/ QDFTOWN 1200 07/05/06 06:08:14 *DDIR QNTC/ QSYS 40960 06/27/06 19:10:15 *DIR dev/ QSYS 8192 06/27/06 16:29:44 *DIR home/ QSYS 12288 07/07/06 23:24:53 *DIR tmp/ MUELLERJ 1282232 01/18/06 11:40:23 *STMF PARCELST.TXT MUELLERJ 58 01/03/06 11:29:17 *STMF UNTITLED.TXT */ BOOL net_parse_ls_line(char *line, NET_FileEntryInfo* entry_info) { char *e; int len; static Time_t savedate; //Owner e = SkipNSpace(line); CHECK((*e == 0), FALSE) len = Min((int)ARRAYSIZE(entry_info->FTPOwner)-1, (int)(e-line)); StrCpy(entry_info->FTPOwner, line, len+1); line = SkipSpace(e); if(line[0] != '*') { //Size e = SkipNSpace(line); CHECK((*e == 0), FALSE) *e = 0; entry_info->size = AtoI(line, (__int64)-1); *e = ' '; CHECK((entry_info->size == (__int64)-1), FALSE) //Date line = SkipSpace(e); CHECK((!parse_os400_date_time(line,entry_info->date)), FALSE) //save date of *FILE for *MEM members savedate = entry_info->date; line = SkipSpace(line); CHECK((*line == 0), FALSE) }
int xpGetType( const char *xml ){ if( !xml ) return -1; xml = SkipSpace(xml); if( *xml=='<' ){ xml = SkipSpace(xml+1); if( *xml=='!' ){ xml = SkipSpace(xml+1); if( !strncmp(xml,"--",2) ) return XP_COMMENT; if( *xml=='[' ) return XP_CDATA; return -2; } bool is_close = false; if( *xml=='/' ){ is_close=true; xml = SkipSpace(xml+1); } if( !xpIsLeadTagChar(*xml) ) return XP_NODE_BAD; const char *pc = strchr(xml,'>'); if( pc ) pc = SkipSpaceRev(pc-1); if( *pc=='/' ) return XP_NODE_BOTH; else return is_close ? XP_NODE_CLOSE : XP_NODE_OPEN; } // Default to text return XP_TEXT; }
const char *SkipAttrib( const char *xml ){ if( !xml ) return NULL; xml = SkipSpace(xml); // Accept name - not sure about this, accept numbers/digits/_ now for( char ch=*xml; ch!=' ' && ch!='='; xml++ ){ if( !ch ) return NULL; if( !isalnum(ch) && ch!='_' && ch!='-' ) return NULL; } xml = SkipSpace(xml); if( *xml!='=' ) return NULL; xml = SkipSpace(xml+1); // Quoted value, go past escaped quotes if( *xml!='"' ) return NULL; for( char ch=*xml; ch!='\"'; ch=*++xml ){ if( !ch ) return NULL; if( ch=='\\' ){ ch = *++xml; if( !ch ) return NULL; } } // Skip space xml = SkipSpace(xml+1); // Return new position return xml; }
/* windows NT DOS dir syntax. * looks like: * 1 2 3 4 5 * 012345678901234567890123456789012345678901234567890 * 06-29-95 03:05PM <DIR> muntemp * 05-02-95 10:03AM 961590 naxp11e.zip * 05-17-2007 07:58PM <DIR> muntemp * 09-09-2008 03:50AM 1506 naxp11e.zip * 04-06-1995 02:03 * 07-13-1995 11:39 * 05-27-11 09:31 <DIR> 3 * The date time directory indicator and FindData.cFileName * are always in a fixed position. The file * size always ends at position 37. */ BOOL WINAPI idPRParceDos(const FTPServerInfo* Server, FTPFileInfo* p, char *entry, int entry_len) { NET_FileEntryInfo entry_info; char *e, *m; int offset = 0; CHECK((entry_len < 11), FALSE); if(entry[10] == ' ') offset = 2; CHECK((entry_len < 38+offset || entry[17+offset]!=' '), FALSE) CHECK((!net_parse_dos_date_time(entry, entry_info.date)), FALSE) // <DIR> | digits e = SkipSpace(SkipNSpace(entry+15)); if(StrCmp(e, "<DIR> ",5,FALSE) == 0) { entry_info.FileType = NET_DIRECTORY; m = SkipSpace(e+5); } else { m = SkipNSpace(e); *m = 0; entry_info.size = AtoI(e,(__int64)-1); m = SkipSpace(m+1); CHECK((entry_info.size == -1), FALSE) } StrCpy(entry_info.FindData.cFileName, m, ARRAYSIZE(entry_info.FindData.cFileName)); return ConvertEntry(&entry_info,p); }
const char *GetAttrib( const char *xml, const char *name, CharBuf& val ){ if( !xml || !name ) return NULL; xml = SkipSpace(xml); // Accept name int nl = strlen(name); if( strncmp(xml,name,nl) ) return NULL; xml += nl; xml = SkipSpace(xml); // Equals? if( *xml!='=' ) return NULL; xml++; xml = SkipSpace(xml); // Quoted value, go past escaped quotes if( *xml!='"' ) return NULL; const char *pb = ++xml; for( char ch=*xml; ch!='\"'; ch=*++xml ){ if( !ch ) return NULL; if( ch=='\\' ){ ch = *++xml; if( !ch ) return NULL; } } // Assign value val.Assign( pb, xml-pb ); // Skip space xml = SkipSpace(xml+1); // Return new position return xml; }
bool XmlParser::ParseElement(const std::string &elemBuffer) { std::string::size_type i = 0; std::string elemName; std::map<std::string, std::string> attrPairs; if(elemBuffer[0] == '/') { i = 1; SkipSpace(elemBuffer, i); for(; i < elemBuffer.length() && !isspace(elemBuffer[i]); ++i) { elemName += elemBuffer[i]; } OnEndElement(elemName); } else { // 要素名 SkipSpace(elemBuffer, i); for(; i < elemBuffer.length() && !isspace(elemBuffer[i]); ++i) { elemName += elemBuffer[i]; } // 属性 Name S? '=' S? AttValue for(; i < elemBuffer.length(); ++i) { std::string attrName, attrValue; char delim; SkipSpace(elemBuffer, i); if(elemBuffer[i] == '/') { // 開始タグ中に '/' があったら空要素 break; } // 属性名 for(; i < elemBuffer.length() && !isspace(elemBuffer[i]) && elemBuffer[i] != '='; ++i) { attrName += elemBuffer[i]; } SkipSpace(elemBuffer, i); ++i; SkipSpace(elemBuffer, i); // 属性値 delim = elemBuffer[i]; ++i; if(delim == '\'' || delim == '\"') { for(; i < elemBuffer.length() && elemBuffer[i] != delim; ++i) { attrValue += elemBuffer[i]; } ++i; attrPairs[attrName] = attrValue; } else { // 属性値を区切るデリミタとして不当 return false; } } OnStartElement(elemName, attrPairs); } return true; }
static int SetRepeat( short *omin, short *omax, void *src, DString *ds, daoint i, daoint end ) { short min=0, max=0, offset=1; char *mbs = (char*) src; int chi, chi2=0; daoint pos, pos2; int j, k, start = i; j = SkipSpace( src, i, end ); i += j; offset += j; chi = mbs[i]; if( i+1<end ) chi2 = mbs[i+1]; if( chi == '?' ){ min = 0; max = 1; }else if( chi == '*' ){ min = 0; max = -1; }else if( chi == '+' ){ min = 1; max = -1; }else if( chi == '{' && chi2 != '{' ){ pos = DString_BalancedChar( ds, '}', 0, 0, 0, i+1, end, 0 ); pos2 = DString_BalancedChar( ds, '{', '{', '}', 0, i+1, pos, 0 ); if( pos != DAO_NULLPOS && pos2 == DAO_NULLPOS ){ j = SkipSpace( src, i+1, pos ); i += j+1; j = ScanInteger( & k, src, i, pos ); i += j; if( j ){ j = SkipSpace( src, i, pos ); i += j; min = max = k; chi = mbs[i]; if( chi == ',' ){ j = SkipSpace( src, i+1, pos ); i += j+1; j = ScanInteger( & k, src, i, pos ); max = j ? k : -1; } offset = pos - start + 1; }else{ offset = 0; } } }else{ offset = 0; } if( offset ){ *omin = min; *omax = max; } return offset; }
void __fastcall CCradio::SendCommand(LPCSTR p) { int c; int f; for(f = 0; *p; p++){ if( *p == '\\' ){ f = 0; p++; switch(*p){ case '$': f = 1; continue; case 'x': case 'X': p++; if( *p == 'x' ){ c = RADIO.Cmdxx; } else { c = htoin(p, 2); } p++; break; case 'r': c = CR; break; case 'n': c = LF; break; case 'w': p++; c = atoin(p, 2); if( (c < 0) || (c >= 100) ) c = 100; if( c ) ::Sleep(c * 10); p++; continue; case '\\': c = '\\'; break; case 'c': // comment return; } } else if( f ){ p = SkipSpace(p); if( *p == 'x' ){ c = RADIO.Cmdxx; } else { c = htoin(p, 2); } p++; } else { c = *p; } PutChar(BYTE(c)); } }
bool_t ParserIsAttrib(parser* p, tchar_t* Name, size_t NameLen) { SkipSpace(p); if (ParserIsToken(p,T(">")) || ParserIsToken(p,T("/>"))) return 0; return Read(p,Name,NameLen,"= \t\n/>",1)>0; }
int ParseFloats( const char *pText, float *pFloat, int count ) { const char *pTemp = pText; int index = 0; while ( pTemp && count > 0 ) { // Skip current token / float pTemp = SkipText( pTemp ); // Skip any whitespace in between pTemp = SkipSpace( pTemp ); if ( pTemp ) { // Parse a float pFloat[index] = (float)atof( pTemp ); count--; index++; } } if ( count == 0 ) return 1; return 0; }
bool ParseIndexTrio( IndexTrio& trio ) { SkipSpace(); if (!IsDigitOrSign(*m_line)) { return false; } trio.iPos = ParseInt(); if (*(m_line++) != '/') { return true; } // look for iTex if (*m_line != '/') { trio.iTex = ParseInt(); if (*(m_line++) != '/') { return true; } } // look for iNorm if (IsDigitOrSign(*m_line)) { trio.iNorm = ParseInt(); } return true; }
char *LookUpFiles( char *path, char *filename, int mode ) { char *find; if( !access( filename, mode ) ){ find = strdup( filename ); return find; } if( path==NULL ) return NULL; do{ path=SkipSpace( path ); find = calloc( strlen(path)+strlen(filename)+2, 1 ); if( strchr( path, ':' )==NULL ){ sprintf( find, "%s/%s", path, filename ); path += strlen( path ); } else{ strcpy( find, path ); sprintf( strchr( find, ':' ), "/%s", filename ); path = strchr( path, ':') + 1; } if( !access(find, mode ) ){ return find; } free( find ); } while( *path!='\0' && *path!='\n' ); return NULL; }
CBSString CBSString::SkipToken() { CBSString cs, ct; cs = SkipSpace(); ct = cs.SpanExcluding(separators); cs = cs.Right(cs.GetLength() - ct.GetLength()); return (cs); }
void Parser::ParseCamera() { Point position, focus; Vector up; double filedOfView; int xResolution, yResolution; while (HasNextTag()) { std::string tag = NextTag(); if (tag == "position") { SkipSpace(); ParseTripleDouble(&position.x, &position.y, &position.z); } else if (tag == "up") { SkipSpace(); ParseTripleDouble(&up.x, &up.y, &up.z); } else if (tag == "focus") { SkipSpace(); ParseTripleDouble(&focus.x, &focus.y, &focus.z); } else if (tag == "fov") { SkipSpace(); filedOfView = ParseDouble(); } else if (tag == "resolution") { SkipSpace(); xResolution = ParseInteger(); ++index; yResolution = ParseInteger(); } else if (tag == "/camera") { double aspect = static_cast<double>(xResolution) / static_cast<double>(yResolution); camera = new Camera(position, focus, up, filedOfView, aspect); image = new Image(xResolution,yResolution); break; } } }
int ParseInt() { SkipSpace(); int v = 0; int numConsumed = 0; sscanf_s(m_line, "%d%n", &v, &numConsumed); m_line += numConsumed; return v; }
float ParseFloat() { SkipSpace(); float v = 0.0; int numConsumed = 0; sscanf_s(m_line, "%f%n", &v, &numConsumed); m_line += numConsumed; return v; }
int AcceptCloseToken( const char *&xml ){ if( !xml ) return -1; const char *pc = SkipSpace(xml); bool node_close = false; if( *pc=='/' ) node_close=true, pc++; if( *pc!='>' ) return -2; xml = pc+1; return node_close ? 1 : 0; }
int AcceptOpenTag( const char *&xml, const char *expect ){ if( !xml || !xml ) return -1; const char *pc = SkipSpace(xml); if( *pc!='<' ) return -1; pc = SkipSpace(pc+1); bool is_close = false; if( *pc=='/' ){ is_close = true; pc = SkipSpace(xml); } if( !xpIsLeadTagChar(*pc) ) return -2; int sl = strlen(expect); if( strncmp(expect,pc,sl) || isalnum(pc[sl]) ) return -3; xml = SkipSpace( pc+sl ); return is_close ? 1 : 0; }
bool_t ParserAttribString(parser* p, tchar_t* Out, size_t OutLen) { if (!ParserIsToken(p,T("="))) return 0; SkipSpace(p); if (ParserIsToken(p,T("\""))) return Read(p,Out,OutLen,"\"",0)>=0; else return Read(p,Out,OutLen," \t\n/>",1)>=0; }
int AcceptOpenTag( const char *&xml, CharBuf& tag ){ if( !xml ) return -1; const char *pc = SkipSpace(xml); if( *pc!='<' ) return -1; pc = SkipSpace(pc+1); bool is_close = false; if( *pc=='/' ){ is_close = true; pc = SkipSpace(pc+1); } if( !xpIsLeadTagChar(*pc) ) return -2; xml = pc; while( isalnum(*pc) ) pc++; tag.Assign( xml, pc ); xml = SkipSpace( pc ); return is_close ? 1 : 0; }
///---------------------------------------------------------------- void __fastcall NumCopy(LPSTR t, LPCSTR p) { p = SkipSpace(p); for( ; *p; p++ ){ if( isdigit(*p) ){ *t++ = *p; } else { break; } } *t = 0; }
void Parser::ParseRenderer() { unsigned int bounce = 5; unsigned int samplesPerPixel = 4; while (HasNextTag()) { std::string tag = NextTag(); if (tag == "bounce") { SkipSpace(); bounce = ParseInteger(); } else if (tag == "sample") { SkipSpace(); samplesPerPixel = ParseInteger(); } else if (tag == "/renderer") { renderer = new Renderer(bounce, samplesPerPixel); break; } } }
int AcceptComment( const char *&xml, CharBuf *pcomment ){ if( !xml ) return -1; const char *pc = SkipSpace(xml); if( *pc!='<' ) return -1; pc = SkipSpace( pc+1 ); if( *pc!='!' ) return -2; pc = SkipSpace( pc+1 ); if( strncmp(pc,"--",2) ) return -3; pc += 2; // Comment starts here const char *pc1=pc, *pend; while( pc1=strstr(pc1,"--") ){ pend = SkipSpace(pc1+2); if( *pend=='>' ){ if( pcomment ) pcomment->Assign( pc, pc1 ); return 0; } pc1 = pend; } return -4; }
void CS_AddVLine (CodeSeg* S, LineInfo* LI, const char* Format, va_list ap) /* Add a line to the given code segment */ { const char* L; CodeEntry* E; char Token[IDENTSIZE+10]; /* Format the line */ StrBuf Buf = STATIC_STRBUF_INITIALIZER; SB_VPrintf (&Buf, Format, ap); /* Skip whitespace */ L = SkipSpace (SB_GetConstBuf (&Buf)); /* Check which type of instruction we have */ E = 0; /* Assume no insn created */ switch (*L) { case '\0': /* Empty line, just ignore it */ break; case ';': /* Comment or hint, ignore it for now */ break; case '.': /* Control instruction */ ReadToken (L, " \t", Token, sizeof (Token)); Error ("ASM code error: Pseudo instruction `%s' not supported", Token); break; default: E = ParseInsn (S, LI, L); break; } /* If we have a code entry, transfer the labels and insert it */ if (E) { CS_AddEntry (S, E); } /* Cleanup the string buffer */ SB_Done (&Buf); }
bool_t ParserIsToken(parser* p, const tchar_t* Token) { size_t n = tcslen(Token); tchar_t* Tmp = alloca(sizeof(tchar_t)*(n+1)); const char* i; SkipSpace(p); if ((i=(const char*)ParserPeek(p,n))!=NULL) { GetAsciiToken(Tmp,n+1,i,n); if (tcsicmp(Tmp,Token)==0) { p->Buffer.ReadPos += n; return 1; } } return 0; }
char *fgetline( char *str, int size, FILE *fp ) { int readlen; char strtmp[256]; if( fgets( str, size, fp )==NULL ) return NULL; readlen=strlen(str)-2; while( str[readlen]=='\\' && fgets( strtmp, sizeof(strtmp), fp)!=NULL ){ str[readlen]='\0'; snprintf( str, size, "%s%s", str, SkipSpace(strtmp) ); readlen=strlen(str)-2; } return str; }
void CFX_SAXReader::ParseText() { if (m_CurByte == '<') { if (m_iDataPos > 0) { m_iDataLength = m_iDataPos; m_iDataPos = 0; if (m_pHandler) { NotifyData(); } } Push(); m_dwNodePos = m_File.m_dwCur + m_File.m_dwBufIndex; m_eMode = FX_SAXMODE_NodeStart; return; } if (m_iDataPos < 1 && SkipSpace(m_CurByte)) { return; } ParseChar(m_CurByte); }
/* <c5400> ../engine/tmessage.c:177 */ NOXREF int ParseFloats(const char *pText, float *pFloat, int count) { const char *pTemp = pText; int index = 0; while (pTemp && count > 0) { pTemp = SkipText(pTemp); pTemp = SkipSpace(pTemp); if (pTemp) { pFloat[index] = (float)Q_atof(pTemp); count--; index++; } } if (count == 0) return 1; return 0; }