void Main() { MatchString("BEGIN"); Prolog(); Block(); MatchString("END"); Epilog(); }
static BOOL ParseSurface(char **data, Mesh3D *mesh) { MeshSurfaceT *surface; WORD n; if (!(ReadShort(data, &n) && EndOfLine(data))) return FALSE; surface = &mesh->surface[n]; while (NextLine(data) && !MatchString(data, "@end")) { if (MatchString(data, "color")) { if (!(ReadByte(data, &surface->r) && ReadByte(data, &surface->g) && ReadByte(data, &surface->b) && EndOfLine(data))) return FALSE; } else if (MatchString(data, "side")) { if (!(ReadByte(data, &surface->sideness) && EndOfLine(data))) return FALSE; } else if (MatchString(data, "texture")) { if (!(ReadShort(data, &surface->texture) && EndOfLine(data))) return FALSE; } else { SkipLine(data); } } return TRUE; }
///////////////////////////////////////////////////////// // Parse the TIFF header. (Section 4.5.2, Table 1) ///////////////////////////////////////////////////////// bool EXIFParser::ParseTIFFHeader(uint32_t& aIFD0OffsetOut) { // Determine byte order. if (MatchString("MM\0*", 4)) { mByteOrder = ByteOrder::BigEndian; } else if (MatchString("II*\0", 4)) { mByteOrder = ByteOrder::LittleEndian; } else { return false; } // Determine offset of the 0th IFD. (It shouldn't be greater than 64k, which // is the maximum size of the entry APP1 segment.) uint32_t ifd0Offset; if (!ReadUInt32(ifd0Offset) || ifd0Offset > 64 * 1024) { return false; } // The IFD offset is relative to the beginning of the TIFF header, which // begins after the EXIF header, so we need to increase the offset // appropriately. aIFD0OffsetOut = ifd0Offset + EXIFHeaderLength; return true; }
void Greater(void) { MatchString(">"); if ( Token[0]=='=') { MatchString("="); Expression(); PopCompare(); SetGreaterOrEqual(); } else { Expression(); PopCompare(); SetGreater(); } }
BOOL WINAPI MatchString(LPCTSTR lpszPat, LPCTSTR lpszStr) { if (lpszPat == NULL || lpszStr == NULL) return FALSE; while(*lpszStr && *lpszPat) { if(*lpszPat == '?') { if(MatchString(lpszPat+1, lpszStr)) return TRUE; lpszStr++; lpszPat++; } else if(*lpszPat == '*') { while(*lpszPat == '*' || *lpszPat == '?') lpszPat++; if(!*lpszPat) return TRUE; while(*lpszStr) { if(MatchString(lpszPat, lpszStr)) return TRUE; lpszStr++; } return FALSE; } else { if(*lpszPat != *lpszStr) return FALSE; lpszStr++; lpszPat++; } } if(*lpszStr!=0) return FALSE; while(*lpszPat == '*' || *lpszPat == '?') lpszPat++; return !*lpszPat; }
int main() { Init(); MatchString("PROGRAM"); Semi(); Header(); TopDecls(); MatchString("BEGIN"); Prolog(); Block(); MatchString("END"); Epilog(); return 0; }
void DoIf() { Condition(); char L1[MAX_BUF]; char L2[MAX_BUF]; strcpy(L1, NewLabel()); strcpy(L2, L1); sprintf(tmp, "jz %s", L1); EmitLn(tmp); Block(); if (Token == 'l') { /* match *else* statement */ strcpy(L2, NewLabel()); sprintf(tmp, "jmp %s", L2); EmitLn(tmp); PostLabel(L1); Block(); } PostLabel(L2); MatchString("ENDIF"); }
void NotEquals(void) { MatchString(">"); Expression(); PopCompare(); SetNEqual(); }
void Prog() { MatchString("PROGRAM"); Header(); TopDecls(); Main(); Match('.'); }
void LessOrEqual(void) { MatchString("="); Expression(); PopCompare(); SetLessOrEqual(); }
__regargs Mesh3D *LoadMesh3D(char *filename, FLOAT scale) { char *file = LoadFile(filename, MEMF_PUBLIC); char *data = file; Mesh3D *mesh = MemAlloc(sizeof(Mesh3D), MEMF_PUBLIC|MEMF_CLEAR); Log("[3D] Parsing '%s' file\n", filename); mesh->scale = scale; while (NextLine(&data)) { ParserT *parser = TopLevelParser; for (; parser->name; parser++) { if (!MatchString(&data, parser->name)) continue; if (parser->func(&data, mesh)) break; Log("[3D] Syntax error at %ld position!\n", (LONG)(data - file)); DeleteMesh3D(mesh); return NULL; } } return mesh; }
static BOOL ParseVertices(char **data, Mesh3D *mesh) { FLOAT scale = SPMul(mesh->scale, SPFlt(16)); Point3D *vertex; WORD n; if (!(ReadShort(data, &n) && EndOfLine(data))) return FALSE; Log("[3D] Mesh has %ld points\n", (LONG)n); mesh->vertices = n; mesh->vertex = MemAlloc(sizeof(Point3D) * n, MEMF_PUBLIC); vertex = mesh->vertex; while (NextLine(data) && !MatchString(data, "@end") && n > 0) { FLOAT x, y, z; if (!(ReadFloat(data, &x) && ReadFloat(data, &y) && ReadFloat(data, &z) && EndOfLine(data))) return FALSE; vertex->x = SPFix(SPMul(x, scale)); vertex->y = SPFix(SPMul(y, scale)); vertex->z = SPFix(SPMul(z, scale)); vertex++; n--; } return n == 0; }
// operations void Equals(void) { MatchString("="); Expression(); PopCompare(); SetEqual(); }
static BOOL ParseVertexUVs(char **data, Mesh3D *mesh) { FLOAT scale_u = SPFlt(16); FLOAT scale_v = SPFlt(16); UVCoord *uv; WORD n; if (!(ReadShort(data, &n) && EndOfLine(data))) return FALSE; Log("[3D] Mesh has %ld uv coordinates\n", (LONG)n); mesh->uv = MemAlloc(sizeof(Point2D) * n, MEMF_PUBLIC); uv = mesh->uv ; while (NextLine(data) && !MatchString(data, "@end")) { FLOAT u, v; if (!(ReadFloat(data, &u) && ReadFloat(data, &v) && EndOfLine(data))) return FALSE; uv->u = SPFix(SPMul(u, scale_u)); uv->v = SPFix(SPMul(v, scale_v)); uv++; n--; } return n == 0; }
static BOOL ParseFaceUVs(char **data, Mesh3D *mesh) { IndexListT **faceUVs; WORD *index; WORD n, m; if (!(ReadShort(data, &n) && ReadShort(data, &m) && EndOfLine(data))) return FALSE; mesh->faceUV = MemAlloc(sizeof(IndexListT *) * (n + 1) + sizeof(WORD) * (m + n), MEMF_PUBLIC|MEMF_CLEAR); faceUVs = mesh->faceUV; index = (WORD *)&mesh->faceUV[n + 1]; while (NextLine(data) && !MatchString(data, "@end")) { IndexListT *faceUV = (IndexListT *)index++; while (!EndOfLine(data)) { if (!ReadShort(data, index++)) return FALSE; faceUV->count++, m--; } *faceUVs++ = faceUV, n--; } return (n == 0) && (m == 0); }
//----------------------------------------------------------------------------- // Purpose: // Input : pObject - // FindObject - // Output : Returns true if the object matches the search criteria, false if not. //----------------------------------------------------------------------------- bool FindCheck(CMapClass *pObject, FindObject_t &FindObject) { CMapEntity *pEntity = dynamic_cast <CMapEntity *>(pObject); if (!pEntity) { return false; } if (FindObject.bVisiblesOnly && !pObject->IsVisible()) { return false; } // // Search keyvalues. // int nKeyCount = pEntity->GetKeyValueCount(); for (int i = 0; i < nKeyCount; i++) { const char *pszValue = pEntity->GetKeyValue(i); if (pszValue && MatchString(pszValue, FindObject)) { return true; } } // // Search connections. // POSITION pos = pEntity->Connections_GetHeadPosition(); while (pos) { CEntityConnection *pConn = pEntity->Connections_GetNext(pos); if (pConn) { if (MatchString(pConn->GetTargetName(), FindObject) || MatchString(pConn->GetParam(), FindObject)) { return true; } } } return false; }
void Assignment() { char name[MAX_BUF]; sprintf(name, Value); Next(); MatchString("="); BoolExpression(); Store(name); }
void BoolTerm(void) { NotFactor(); while (Token[0]=='&') { Push(); MatchString("&"); NotFactor(); PopAnd(); } }
BOOL WINAPI SUITextOutW(HDC hdc,int x, int y,LPCWSTR lpstring,int c) { try { if(targetHandle != NULL) { if(c > 64 || c < 0) { return TrueTextOutW(hdc,x,y,lpstring,c); } else { if(IsFromPostMessage&&!hasGetPosition) { if(lstrcmp(text,lpstring) == 0) { startIndex++; if(startIndex == targetIndex) { hasGetPosition = TRUE; IsFromPostMessage = FALSE; targetHandle = NULL; xPos = x; yPos = y; } } else { if(MatchString(lpstring,text)) { startIndex++; if(startIndex == targetIndex) { hasGetPosition = TRUE; IsFromPostMessage = FALSE; targetHandle = NULL; xPos = x; yPos = y; } } } } return TrueTextOutW(hdc,x,y,lpstring,c); } } else { return TrueTextOutW(hdc,x,y,lpstring,c); } } catch(...) { return FALSE; } }
static void ParseActorProperty(FScanner &sc, Baggage &bag) { static const char *statenames[] = { "Spawn", "See", "Melee", "Missile", "Pain", "Death", "XDeath", "Burn", "Ice", "Raise", "Crash", "Crush", "Wound", "Disintegrate", "Heal", NULL }; strlwr (sc.String); FString propname = sc.String; if (sc.CheckString (".")) { sc.MustGetString (); propname += '.'; strlwr (sc.String); propname += sc.String; } else { sc.UnGet (); } FPropertyInfo *prop = FindProperty(propname); if (prop != NULL) { if (bag.Info->Class->IsDescendantOf(prop->cls)) { ParsePropertyParams(sc, prop, (AActor *)bag.Info->Class->Defaults, bag); } else { sc.ScriptMessage("\"%s\" requires an actor of type \"%s\"\n", propname.GetChars(), prop->cls->TypeName.GetChars()); FScriptPosition::ErrorCounter++; } } else if (!propname.CompareNoCase("States")) { if (bag.StateSet) { sc.ScriptMessage("'%s' contains multiple state declarations", bag.Info->Class->TypeName.GetChars()); FScriptPosition::ErrorCounter++; } ParseStates(sc, bag.Info, (AActor *)bag.Info->Class->Defaults, bag); bag.StateSet=true; } else if (MatchString(propname, statenames) != -1) { bag.statedef.SetStateLabel(propname, CheckState (sc, bag.Info->Class)); } else { sc.ScriptError("\"%s\" is an unknown actor property\n", propname.GetChars()); } }
int FScanner::MustMatchString (const char * const *strings, size_t stride) { int i; i = MatchString (strings, stride); if (i == -1) { ScriptError ("Unknown keyword '%s'", String); } return i; }
int FScanner::MustMatchString (const char * const *strings, size_t stride) { int i; i = MatchString (strings, stride); if (i == -1) { ScriptError (NULL); } return i; }
bool Security::CanConnect(const string& host,int port) { if(disabled) return true; list<pair<string,int> >::const_iterator i; for(i=net_connect.begin(); i!=net_connect.end(); i++) if(MatchString((*i).first,host) && MatchPort((*i).second,port)) return true; return false; }
void NotFactor(void) { message("NotFactor"); if (Token[0]=='!') { MatchString("!"); Relation(); NotIt(); } else { Relation(); } }
void adbusI_logmatch(const char* header, const adbus_Match* m) { if (!adbusI_log_enabled()) return; d_String str; ZERO(&str); MatchString(&str, m); adbusI_addheader(&str, "%-10s ", header); adbusI_klog(&str); ds_free(&str); }
BOOL MatchString(LPCWSTR source, LPCWSTR expression) { if(expression == NULL) { return (source == NULL); } if(*expression == L'\0') { return (*source == L'\0'); } if(*expression == L'*') { int sourceLen = lstrlen(source); for(int i=0; i<=sourceLen; i++) { if(MatchString(source + i,expression + 1)) return TRUE; } return FALSE; } /*else if(*expression == L'?') for extention { for(int i=0; i<2; i++) { if(MatchString(source + i,expression + 1)) return TRUE; } return FALSE; }*/ else { if(*source == *expression) { return MatchString(++source,++expression); } else { return FALSE; } } }
bool Glob(const string& pattern_, vector<string>& fileNames) { // Remove trailing slashes: string pattern = pattern_; while (pattern.size() > 0 && pattern[pattern.size()-1] == '/') { #ifdef OS_TRU64 pattern.remove(pattern.size() - 1); #else pattern.erase(pattern.end() - 1); #endif } // Split the pattern into directory name and base name: string dirname; string basename; _SplitPath(pattern, dirname, basename); if (!_contains_special_chars(basename)) fileNames.push_back(pattern_); else { // Find all files in the given directory MatchStringing the pattern: bool found = false; vector<string> filenames; if (!GetDirEntries(dirname, filenames)) return false; for (size_t i = 0; i < filenames.size(); i++) { if (MatchString(basename, filenames[i])) { found = true; if (dirname == ".") fileNames.push_back(filenames[i]); else fileNames.push_back(dirname + "/" + filenames[i]); } } if (!found) return false; } return true; }
//========================================================================== // //========================================================================== DEFINE_CLASS_PROPERTY(type, S, DynamicLight) { PROP_STRING_PARM(str, 0); static const char * ltype_names[]={ "Point","Pulse","Flicker","Sector","RandomFlicker", "ColorPulse", "ColorFlicker", "RandomColorFlicker", NULL}; static const int ltype_values[]={ PointLight, PulseLight, FlickerLight, SectorLight, RandomFlickerLight, ColorPulseLight, ColorFlickerLight, RandomColorFlickerLight }; int style = MatchString(str, ltype_names); if (style < 0) I_Error("Unknown light type '%s'", str); defaults->lighttype = ltype_values[style]; }
void Less(void) { MatchString("<"); switch (Token[0]) { case '=': LessOrEqual(); break; case '>': NotEquals(); break; default : Expression(); PopCompare(); SetLess(); break; } }
bool Security::CanExecute(const string& file) { if(disabled) return true; if(!ValidFilename(file)) return false; list<string>::const_iterator i; for(i=execute.begin(); i!=execute.end(); i++) if(MatchString(*i,file)) return true; return false; }