bool Primitive_Parse( brush_t *pBrush ){ char *token = Token(); GetToken( true ); if ( !strcmp( token, "patchDef2" ) ) { pBrush->patchBrush = true; pBrush->pPatch = Patch_Alloc(); pBrush->pPatch->pSymbiot = pBrush; Patch_Parse( pBrush->pPatch ); GetToken( true ); //} // A patchdef should never be loaded from a quake2 map file // so we just return false and the brush+patch gets freed // and the user gets told. if ( g_MapVersion != MAPVERSION_Q3 ) { // FIXME: Hydra - I wanted to write out a line number here, but I can't because there's no API to access the core's "scriptline" variable. Syn_Printf( "ERROR: patchDef2's are not supported in Quake%d format .map files!\n",g_MapVersion ); abortcode = MAP_WRONGVERSION; return false; } } else if ( !strcmp( token, "brushDef" ) ) { pBrush->bBrushDef = true; GetToken( true ); // { while ( 1 ) { face_t *f = pBrush->brush_faces; pBrush->brush_faces = Face_Alloc(); Face_Parse( pBrush->brush_faces, true ); pBrush->brush_faces->next = f; // check for end of brush GetToken( true ); if ( strcmp( token,"}" ) == 0 ) { break; } UnGetToken(); } GetToken( true ); // } } else { UnGetToken(); while ( 1 ) { face_t *f = pBrush->brush_faces; pBrush->brush_faces = Face_Alloc(); Face_Parse( pBrush->brush_faces ); pBrush->brush_faces->next = f; // check for end of brush GetToken( true ); if ( strcmp( token,"}" ) == 0 ) { break; } UnGetToken(); } } return true; }
/* ============== TokenAvailable Returns qtrue if there is another token on the line ============== */ qboolean TokenAvailable (void) { int oldLine; qboolean r; oldLine = script->line; r = GetToken( qtrue ); if ( !r ) { return qfalse; } UnGetToken(); if ( oldLine == script->line ) { return qtrue; } return qfalse; }
boolean CI2CShell::Write (void) { u8 Buffer[256]; CString Data; unsigned nCount; for (nCount = 0; nCount < sizeof Buffer && GetToken (&Data); nCount++) { unsigned nData = ConvertNumber (Data); if (nData == INVALID_NUMBER) { UnGetToken (Data); break; } if (nData > 255) { Print ("Data byte out of range: %s\n", (const char *) Data); return FALSE; } Buffer[nCount] = (u8) nData; } if (nCount == 0) { Print ("Data byte expected\n"); return FALSE; } if (m_ucSlaveAddress == INVALID_SLAVE) { Print ("Slave address not set\n"); return FALSE; } assert (m_pI2CMaster != 0); m_pI2CMaster->SetClock (m_nI2CClockHz); int nResult = m_pI2CMaster->Write (m_ucSlaveAddress, Buffer, nCount); if (nResult <= 0) { PrintI2CError (nResult); return FALSE; } return TRUE; }
/* ============== TokenAvailable Returns qtrue if there is another token on the line ============== */ qboolean TokenAvailable (void) { int oldLine; qboolean r; /* save */ oldLine = scriptline; /* test */ r = GetToken( qtrue ); if ( !r ) { return qfalse; } UnGetToken(); if ( oldLine == scriptline ) { return qtrue; } /* restore */ //% scriptline = oldLine; //% script->line = oldScriptLine; return qfalse; }
void Eclass_ScanFile( char *filename ){ int size; char *data; char temp[1024]; GSList *l_classes = NULL; char token_debug[1024]; //++Hydra FIXME: cleanup this. bool done = false; int len,classtype; char *token = Token(); QE_ConvertDOSToUnixName( temp, filename ); size = vfsLoadFullPathFile( filename, (void**)&data ); if ( size <= 0 ) { Sys_FPrintf( SYS_ERR, "Eclass_ScanFile: %s not found\n", filename ); return; } Sys_Printf( "ScanFile: %s\n", temp ); // start parsing the file StartTokenParsing( data ); // build a list of base classes first while ( !done ) { // find an @ sign. do { if ( !GetToken( true ) ) { done = true; break; } } while ( token[0] != '@' ); strcpy( temp,token + 1 ); // skip the @ classtype = CLASS_NOCLASS; if ( !stricmp( temp,"BaseClass" ) ) { classtype = CLASS_BASECLASS; } if ( !stricmp( temp,"PointClass" ) ) { classtype = CLASS_POINTCLASS; } if ( !stricmp( temp,"SolidClass" ) ) { classtype = CLASS_SOLIDCLASS; } if ( classtype ) { class_t *newclass = (class_t *) malloc( sizeof( class_s ) ); memset( newclass, 0, sizeof( class_s ) ); newclass->classtype = classtype; while ( 1 ) { GetTokenExtra( false,"(",false ); // option or = strcpy( token_debug,token ); if ( !strcmp( token,"=" ) ) { UnGetToken(); break; } else { strlower( token ); if ( !strcmp( token,"base" ) ) { GetTokenExtra( false,"(",true ); // ( if ( !strcmp( token,"(" ) ) { while ( GetTokenExtra( false,",)",false ) ) // option) or option, { newclass->l_baselist = g_slist_append( newclass->l_baselist, strdup( token ) ); GetTokenExtra( false,",)",true ); // , or ) if ( !strcmp( token,")" ) ) { break; } } } } else if ( !strcmp( token,"size" ) ) { // parse (w h d) or (x y z, x y z) GetTokenExtra( false,"(",true ); // ( if ( !strcmp( token,"(" ) ) { int sizedone = false; float w,h,d; GetToken( false ); w = atof( token ); GetToken( false ); h = atof( token ); GetToken( false ); // number) or number , strcpy( temp,token ); len = strlen( temp ); if ( temp[len - 1] == ')' ) { sizedone = true; } temp[len - 1] = 0; d = atof( temp ); if ( sizedone ) { // only one set of cordinates supplied, change the W,H,D to mins/maxs newclass->boundingbox[0][0] = 0 - ( w / 2 ); newclass->boundingbox[1][0] = w / 2; newclass->boundingbox[0][1] = 0 - ( h / 2 ); newclass->boundingbox[1][1] = h / 2; newclass->boundingbox[0][2] = 0 - ( d / 2 ); newclass->boundingbox[1][2] = d / 2; newclass->gotsize = true; } else { newclass->boundingbox[0][0] = w; newclass->boundingbox[0][1] = h; newclass->boundingbox[0][2] = d; GetToken( false ); newclass->boundingbox[1][0] = atof( token ); GetToken( false ); newclass->boundingbox[1][1] = atof( token ); /* GetToken(false); // "number)" or "number )" strcpy(temp,token); len = strlen(temp); if (temp[len-1] == ')') temp[len-1] = 0; else GetToken(false); // ) newclass->boundingbox[1][2] = atof(temp); */ GetTokenExtra( false,")",false ); // number newclass->boundingbox[1][2] = atof( token ); newclass->gotsize = true; GetTokenExtra( false,")",true ); // ) } } } else if ( !strcmp( token,"color" ) ) { GetTokenExtra( false,"(",true ); // ( if ( !strcmp( token,"(" ) ) { // get the color values (0-255) and normalize them if required. GetToken( false ); newclass->color[0] = atof( token ); if ( newclass->color[0] > 1 ) { newclass->color[0] /= 255; } GetToken( false ); newclass->color[1] = atof( token ); if ( newclass->color[1] > 1 ) { newclass->color[1] /= 255; } GetToken( false ); strcpy( temp,token ); len = strlen( temp ); if ( temp[len - 1] == ')' ) { temp[len - 1] = 0; } newclass->color[2] = atof( temp ); if ( newclass->color[2] > 1 ) { newclass->color[2] /= 255; } newclass->gotcolor = true; } } else if ( !strcmp( token,"iconsprite" ) ) { GetTokenExtra( false,"(",true ); // ( if ( !strcmp( token,"(" ) ) { GetTokenExtra( false,")",false ); // filename) // the model plugins will handle sprites too. // newclass->sprite = strdup(token); newclass->model = strdup( token ); GetTokenExtra( false,")",true ); // ) } } else if ( !strcmp( token,"model" ) ) { GetTokenExtra( false,"(",true ); // ( if ( !strcmp( token,"(" ) ) { GetTokenExtra( false,")",false ); // filename) newclass->model = strdup( token ); GetTokenExtra( false,")",true ); // ) } } else { // Unsupported GetToken( false ); // skip it. } } } GetToken( false ); // = strcpy( token_debug,token ); if ( !strcmp( token,"=" ) ) { GetToken( false ); newclass->classname = strdup( token ); } // Get the description if ( newclass->classtype != CLASS_BASECLASS ) { GetToken( false ); if ( !strcmp( token,":" ) ) { GetToken( false ); newclass->description = strdup( token ); } else{ UnGetToken(); // no description } } // now build the option list. GetToken( true ); // [ or [] if ( strcmp( token,"[]" ) ) { // got some options ? if ( !strcmp( token,"[" ) ) { // yup bool optioncomplete = false; option_t *newoption; while ( 1 ) { GetToken( true ); if ( !strcmp( token,"]" ) ) { break; // no more options } // parse the data and build the option_t strcpy( temp,token ); len = strlen( temp ); char *ptr = strchr( temp,'(' ); if ( !ptr ) { break; } newoption = (option_t *) malloc( sizeof( option_s ) ); memset( newoption, 0, sizeof( option_s ) ); *ptr++ = 0; newoption->epairname = strdup( temp ); len = strlen( ptr ); if ( ptr[len - 1] != ')' ) { break; } ptr[len - 1] = 0; strlower( ptr ); if ( !strcmp( ptr,"integer" ) ) { newoption->optiontype = OPTION_INTEGER; } else if ( !strcmp( ptr,"choices" ) ) { newoption->optiontype = OPTION_CHOICES; } else if ( !strcmp( ptr,"flags" ) ) { newoption->optiontype = OPTION_FLAGS; } else // string { newoption->optiontype = OPTION_STRING; } switch ( newoption->optiontype ) { case OPTION_STRING: case OPTION_INTEGER: if ( !TokenAvailable() ) { optioncomplete = true; break; } GetToken( false ); // : strcpy( token_debug,token ); if ( ( token[0] == ':' ) && ( strlen( token ) > 1 ) ) { newoption->optioninfo = strdup( token + 1 ); } else { GetToken( false ); newoption->optioninfo = strdup( token ); } if ( TokenAvailable() ) { // default value ? GetToken( false ); if ( !strcmp( token,":" ) ) { if ( GetToken( false ) ) { newoption->optiondefault = strdup( token ); optioncomplete = true; } } } else { optioncomplete = true; } break; case OPTION_CHOICES: GetTokenExtra( false,":",true ); // : or :"something like this" (bah!) strcpy( token_debug,token ); if ( ( token[0] == ':' ) && ( strlen( token ) > 1 ) ) { if ( token[1] == '\"' ) { strcpy( temp,token + 2 ); while ( 1 ) { if ( !GetToken( false ) ) { break; } strcat( temp," " ); strcat( temp,token ); len = strlen( temp ); if ( temp[len - 1] == '\"' ) { temp[len - 1] = 0; break; } } } newoption->optioninfo = strdup( temp ); } else { GetToken( false ); newoption->optioninfo = strdup( token ); } GetToken( false ); // : or = strcpy( token_debug,token ); if ( !strcmp( token,":" ) ) { GetToken( false ); newoption->optiondefault = strdup( token ); } else { UnGetToken(); } // And Follow on... case OPTION_FLAGS: GetToken( false ); // : or = strcpy( token_debug,token ); if ( strcmp( token,"=" ) ) { // missing ? break; } GetToken( true ); // [ strcpy( token_debug,token ); if ( strcmp( token,"[" ) ) { // missing ? break; } choice_t *newchoice; while ( 1 ) { GetTokenExtra( true,":",true ); // "]" or "number", or "number:" strcpy( token_debug,token ); if ( !strcmp( token,"]" ) ) { // no more ? optioncomplete = true; break; } strcpy( temp,token ); len = strlen( temp ); if ( temp[len - 1] == ':' ) { temp[len - 1] = 0; } else { GetToken( false ); // : if ( strcmp( token,":" ) ) { // missing ? break; } } if ( !TokenAvailable() ) { break; } GetToken( false ); // the name newchoice = (choice_t *) malloc( sizeof( choice_s ) ); memset( newchoice, 0, sizeof( choice_s ) ); newchoice->value = atoi( temp ); newchoice->name = strdup( token ); newoption->choices = g_slist_append( newoption->choices, newchoice ); // ignore any remaining tokens on the line while ( TokenAvailable() ) GetToken( false ); // and it we found a "]" on the end of the line, put it back in the queue. if ( !strcmp( token,"]" ) ) { UnGetToken(); } } break; } // add option to the newclass if ( optioncomplete ) { if ( newoption ) { // add it to the list. newclass->l_optionlist = g_slist_append( newclass->l_optionlist, newoption ); } } else { Sys_Printf( "%WARNING: Parse error occured in '%s - %s'\n",classnames[newclass->classtype],newclass->classname ); Free_Option( newoption ); } } } else { UnGetToken(); // shouldn't get here. } } // add it to our list. l_classes = g_slist_append( l_classes, newclass ); } } // finished with the file now. g_free( data ); Sys_Printf( "FGD scan complete, building entities...\n" ); // Once we get here we should have a few (!) lists in memory that we // can extract all the information required to build a the eclass_t structures. Create_EClasses( l_classes ); // Free everything GSList *p = l_classes; while ( p ) { class_t *tmpclass = (class_t *)p->data; #ifdef FGD_VERBOSE // DEBUG: dump the info... Sys_Printf( "%s: %s (", classnames[tmpclass->classtype],tmpclass->classname ); for ( GSList *tmp = tmpclass->l_baselist; tmp != NULL; tmp = tmp->next ) { if ( tmp != tmpclass->l_baselist ) { Sys_Printf( ", " ); } Sys_Printf( "%s", (char *)tmp->data ); } if ( tmpclass->gotsize ) { sprintf( temp,"(%.0f %.0f %.0f) - (%.0f %.0f %.0f)",tmpclass->boundingbox[0][0], tmpclass->boundingbox[0][1], tmpclass->boundingbox[0][2], tmpclass->boundingbox[1][0], tmpclass->boundingbox[1][1], tmpclass->boundingbox[1][2] ); } else{ strcpy( temp,"No Size" ); } Sys_Printf( ") '%s' Size: %s",tmpclass->description ? tmpclass->description : "No description",temp ); if ( tmpclass->gotcolor ) { sprintf( temp,"(%d %d %d)",tmpclass->color[0], tmpclass->color[1], tmpclass->color[2] ); } else{ strcpy( temp,"No Color" ); } Sys_Printf( " Color: %s Options:\n",temp ); if ( !tmpclass->l_optionlist ) { Sys_Printf( " No Options\n" ); } else { option_t *tmpoption; int count; GSList *olst; for ( olst = tmpclass->l_optionlist, count = 1; olst != NULL; olst = olst->next, count++ ) { tmpoption = (option_t *)olst->data; Sys_Printf( " %d, Type: %s, EPair: %s\n", count,optionnames[tmpoption->optiontype], tmpoption->epairname ); choice_t *tmpchoice; GSList *clst; int ccount; for ( clst = tmpoption->choices, ccount = 1; clst != NULL; clst = clst->next, ccount++ ) { tmpchoice = (choice_t *)clst->data; Sys_Printf( " %d, Value: %d, Name: %s\n", ccount, tmpchoice->value, tmpchoice->name ); } } } #endif // free the baselist. ClearGSList( tmpclass->l_baselist ); Free_Class( tmpclass ); p = g_slist_remove( p, p->data ); } }
void ParsePatch( qboolean onlyLights ) { vec_t info[ 5 ]; int i, j, k; parseMesh_t *pm; char texture[ MAX_QPATH ]; char shader[ MAX_QPATH ]; mesh_t m; bspDrawVert_t *verts; epair_t *ep; vec4_t delta, delta2, delta3; qboolean degenerate; float longestCurve; int maxIterations; MatchToken( "{" ); /* get texture */ GetToken( qtrue ); strcpy( texture, token ); Parse1DMatrix( 5, info ); m.width = info[0]; m.height = info[1]; m.verts = verts = (bspDrawVert_t *)safe_malloc( m.width * m.height * sizeof( m.verts[0] ) ); if( m.width < 0 || m.width > MAX_PATCH_SIZE || m.height < 0 || m.height > MAX_PATCH_SIZE ) Error( "ParsePatch: bad size" ); MatchToken( "(" ); for( j = 0; j < m.width ; j++ ) { MatchToken( "(" ); for( i = 0; i < m.height ; i++ ) { Parse1DMatrix( 5, verts[ i * m.width + j ].xyz ); /* ydnar: fix colors */ for( k = 0; k < MAX_LIGHTMAPS; k++ ) { verts[ i * m.width + j ].color[ k ][ 0 ] = 255; verts[ i * m.width + j ].color[ k ][ 1 ] = 255; verts[ i * m.width + j ].color[ k ][ 2 ] = 255; verts[ i * m.width + j ].color[ k ][ 3 ] = 255; } } MatchToken( ")" ); } MatchToken( ")" ); // if brush primitives format, we may have some epairs to ignore here GetToken(qtrue); if (g_bBrushPrimit!=BPRIMIT_OLDBRUSHES && strcmp(token,"}")) { // NOTE: we leak that! ep = ParseEPair(); } else UnGetToken(); MatchToken( "}" ); MatchToken( "}" ); /* short circuit */ if( noCurveBrushes || onlyLights ) return; /* ydnar: delete and warn about degenerate patches */ j = (m.width * m.height); VectorClear( delta ); delta[ 3 ] = 0; degenerate = qtrue; /* find first valid vector */ for( i = 1; i < j && delta[ 3 ] == 0; i++ ) { VectorSubtract( m.verts[ 0 ].xyz, m.verts[ i ].xyz, delta ); delta[ 3 ] = VectorNormalize( delta, delta ); } /* secondary degenerate test */ if( delta[ 3 ] == 0 ) degenerate = qtrue; else { /* if all vectors match this or are zero, then this is a degenerate patch */ for( i = 1; i < j && degenerate == qtrue; i++ ) { VectorSubtract( m.verts[ 0 ].xyz, m.verts[ i ].xyz, delta2 ); delta2[ 3 ] = VectorNormalize( delta2, delta2 ); if( delta2[ 3 ] != 0 ) { /* create inverse vector */ VectorCopy( delta2, delta3 ); delta3[ 3 ] = delta2[ 3 ]; VectorNegate( delta3, delta3 ); /* compare */ if( VectorCompare( delta, delta2 ) == qfalse && VectorCompare( delta, delta3 ) == qfalse ) degenerate = qfalse; } } } /* warn and select degenerate patch */ if( degenerate ) { Sys_Warning( mapEnt->mapEntityNum, entitySourceBrushes, "Degenerate patch" ); free( m.verts ); return; } /* find longest curve on the mesh */ longestCurve = 0.0f; maxIterations = 0; for( j = 0; j + 2 < m.width; j += 2 ) { for( i = 0; i + 2 < m.height; i += 2 ) { ExpandLongestCurve( &longestCurve, verts[ i * m.width + j ].xyz, verts[ i * m.width + (j + 1) ].xyz, verts[ i * m.width + (j + 2) ].xyz ); /* row */ ExpandLongestCurve( &longestCurve, verts[ i * m.width + j ].xyz, verts[ (i + 1) * m.width + j ].xyz, verts[ (i + 2) * m.width + j ].xyz ); /* col */ ExpandMaxIterations( &maxIterations, patchSubdivisions, verts[ i * m.width + j ].xyz, verts[ i * m.width + (j + 1) ].xyz, verts[ i * m.width + (j + 2) ].xyz ); /* row */ ExpandMaxIterations( &maxIterations, patchSubdivisions, verts[ i * m.width + j ].xyz, verts[ (i + 1) * m.width + j ].xyz, verts[ (i + 2) * m.width + j ].xyz ); /* col */ } } /* allocate patch mesh */ pm = (parseMesh_t *)safe_malloc( sizeof( *pm ) ); memset( pm, 0, sizeof( *pm ) ); /* ydnar: add entity/brush numbering */ pm->entityNum = mapEnt->mapEntityNum; pm->mapEntityNum = mapEnt->mapEntityNum; pm->brushNum = entitySourceBrushes; /* set shader */ sprintf( shader, "textures/%s", texture ); pm->shaderInfo = ShaderInfoForShader( shader ); /* set mesh */ pm->mesh = m; /* set longest curve */ pm->longestCurve = longestCurve; pm->maxIterations = maxIterations; /* link to the entity */ pm->next = mapEnt->patches; mapEnt->patches = pm; }
/* ================= ParsePatch Creates a mapDrawSurface_t from the patch text ================= */ void ParsePatch( void ) { vec_t info[5]; int i, j; parseMesh_t *pm; char texture[MAX_QPATH]; char shader[MAX_QPATH]; mesh_t m; drawVert_t *verts; epair_t *ep; MatchToken( "{" ); // get texture GetToken (qtrue); strcpy( texture, token ); // save the shader name for retexturing if ( numMapIndexedShaders == MAX_MAP_BRUSHSIDES ) { Error( "MAX_MAP_BRUSHSIDES" ); } strcpy( mapIndexedShaders[numMapIndexedShaders], texture ); numMapIndexedShaders++; Parse1DMatrix( 5, info ); m.width = info[0]; m.height = info[1]; m.verts = verts = malloc( m.width * m.height * sizeof( m.verts[0] ) ); if ( m.width < 0 || m.width > MAX_PATCH_SIZE || m.height < 0 || m.height > MAX_PATCH_SIZE ) { Error("ParsePatch: bad size"); } MatchToken( "(" ); for ( j = 0 ; j < m.width ; j++ ) { MatchToken( "(" ); for ( i = 0 ; i < m.height ; i++ ) { Parse1DMatrix( 5, verts[i*m.width+j].xyz ); } MatchToken( ")" ); } MatchToken( ")" ); // if brush primitives format, we may have some epairs to ignore here GetToken(qtrue); if (g_bBrushPrimit!=BPRIMIT_OLDBRUSHES && strcmp(token,"}")) { // NOTE: we leak that! ep = ParseEpair(); } else UnGetToken(); MatchToken( "}" ); MatchToken( "}" ); if ( noCurveBrushes ) { return; } // find default flags and values pm = malloc( sizeof( *pm ) ); memset( pm, 0, sizeof( *pm ) ); sprintf( shader, "textures/%s", texture ); pm->shaderInfo = ShaderInfoForShader( shader ); pm->mesh = m; // link to the entity pm->next = mapent->patches; mapent->patches = pm; }
globle struct expr *GetRHSPattern( char *readSource, struct token *tempToken, int *error, int constantsOnly, int readFirstParen, int checkFirstParen, int endType) { struct expr *lastOne = NULL; struct expr *nextOne, *firstOne, *argHead = NULL; int printError, count; struct deftemplate *theDeftemplate; struct symbolHashNode *templateName; /*=================================================*/ /* Get the opening parenthesis of the RHS pattern. */ /*=================================================*/ *error = FALSE; if (readFirstParen) GetToken(readSource,tempToken); if (checkFirstParen) { if (tempToken->type == endType) return(NULL); if (tempToken->type != LPAREN) { SyntaxErrorMessage("RHS patterns"); *error = TRUE; return(NULL); } } /*======================================================*/ /* The first field of an asserted fact must be a symbol */ /* (but not = or : which have special significance). */ /*======================================================*/ GetToken(readSource,tempToken); if (tempToken->type != SYMBOL) { SyntaxErrorMessage("first field of a RHS pattern"); *error = TRUE; return(NULL); } else if ((strcmp(ValueToString(tempToken->value),"=") == 0) || (strcmp(ValueToString(tempToken->value),":") == 0)) { SyntaxErrorMessage("first field of a RHS pattern"); *error = TRUE; return(NULL); } /*=========================================================*/ /* Check to see if the relation name is a reserved symbol. */ /*=========================================================*/ templateName = (struct symbolHashNode *) tempToken->value; if (ReservedPatternSymbol(ValueToString(templateName),NULL)) { ReservedPatternSymbolErrorMsg(ValueToString(templateName),"a relation name"); *error = TRUE; return(NULL); } /*============================================================*/ /* A module separator in the name is illegal in this context. */ /*============================================================*/ if (FindModuleSeparator(ValueToString(templateName))) { IllegalModuleSpecifierMessage(); *error = TRUE; return(NULL); } /*=============================================================*/ /* Determine if there is an associated deftemplate. If so, let */ /* the deftemplate parsing functions parse the RHS pattern and */ /* then return the fact pattern that was parsed. */ /*=============================================================*/ theDeftemplate = (struct deftemplate *) FindImportedConstruct("deftemplate",NULL,ValueToString(templateName), &count,TRUE,NULL); if (count > 1) { AmbiguousReferenceErrorMessage("deftemplate",ValueToString(templateName)); *error = TRUE; return(NULL); } /*======================================================*/ /* If no deftemplate exists with the specified relation */ /* name, then create an implied deftemplate. */ /*======================================================*/ if (theDeftemplate == NULL) #if (! BLOAD_ONLY) && (! RUN_TIME) { #if BLOAD || BLOAD_AND_BSAVE if ((Bloaded()) && (! CheckSyntaxMode)) { NoSuchTemplateError(ValueToString(templateName)); *error = TRUE; return(NULL); } #endif #if DEFMODULE_CONSTRUCT if (FindImportExportConflict("deftemplate",((struct defmodule *) GetCurrentModule()),ValueToString(templateName))) { ImportExportConflictMessage("implied deftemplate",ValueToString(templateName),NULL,NULL); *error = TRUE; return(NULL); } #endif if (! CheckSyntaxMode) { theDeftemplate = CreateImpliedDeftemplate((SYMBOL_HN *) templateName,TRUE); } } #else { NoSuchTemplateError(ValueToString(templateName)); *error = TRUE; return(NULL); } #endif /*=========================================*/ /* If an explicit deftemplate exists, then */ /* parse the fact as a deftemplate fact. */ /*=========================================*/ if ((theDeftemplate != NULL) && (theDeftemplate->implied == FALSE)) { firstOne = GenConstant(DEFTEMPLATE_PTR,theDeftemplate); #if FUZZY_DEFTEMPLATES if (theDeftemplate->fuzzyTemplate != NULL) firstOne->nextArg = ParseAssertFuzzyFact(readSource,tempToken, error,endType, constantsOnly,theDeftemplate, TRUE); else #endif firstOne->nextArg = ParseAssertTemplate(readSource,tempToken, error,endType, constantsOnly,theDeftemplate); if (*error) { ReturnExpression(firstOne); firstOne = NULL; } #if CERTAINTY_FACTORS else { /* if certaintly factors allowed then the next item after a fact specifier COULD be a certainty factor spec --- CF x.xxx */ SavePPBuffer(" "); GetToken(readSource,tempToken); if ((tempToken->type == SYMBOL) && ((strcmp(ValueToString(tempToken->value),"CF") == 0) || (strcmp(ValueToString(tempToken->value),"cf") == 0)) ) { struct expr *CFexpr; /* expecting a certainty factor (float) expression */ /* tokenToFloatExpression expect 1st token already read */ SavePPBuffer(" "); GetToken(readSource,tempToken); CFexpr = tokenToFloatExpression(readSource,tempToken,error,constantsOnly); if (*error) { ReturnExpression(firstOne); return( NULL ); } if (CFexpr->type == FLOAT) /* if constant -- check range */ { double cfval = ValueToDouble(CFexpr->value); if (cfval > 1.0 || cfval < 0.0) { *error = TRUE; ReturnExpression(CFexpr); cfRangeError(); ReturnExpression(firstOne); return( NULL ); } } /* store the CF expression in the argList of the DEFTEMPLATE_PTR expr */ firstOne->argList = CFexpr; } else { /* Do an 'UnGetToken' function here to undo the lookahead for a CF. Also need to PPBackup over the space added before reading the potential CF expression -- UnGetToken does one PPBackup over the token which was added to the PP Buffer */ UnGetToken(tempToken); PPBackup(); } } #endif return(firstOne); } /*========================================*/ /* Parse the fact as an ordered RHS fact. */ /*========================================*/ firstOne = GenConstant(DEFTEMPLATE_PTR,theDeftemplate); #if FUZZY_DEFTEMPLATES /*=============================================*/ /* Fuzzy facts parsed differently */ /*=============================================*/ if (theDeftemplate->fuzzyTemplate != NULL) { firstOne->nextArg = ParseAssertFuzzyFact(readSource,tempToken, error,endType, constantsOnly,theDeftemplate, TRUE); if (*error) { ReturnExpression(firstOne); return(NULL); } } else { /* --- matches } below with FUZZY_DEFTEMPLATES */ #endif /* FUZZY_DEFTEMPLATES */ #if (! RUN_TIME) && (! BLOAD_ONLY) SavePPBuffer(" "); #endif while ((nextOne = GetAssertArgument(readSource,tempToken, error,endType,constantsOnly,&printError)) != NULL) { if (argHead == NULL) argHead = nextOne; else lastOne->nextArg = nextOne; lastOne = nextOne; #if (! RUN_TIME) && (! BLOAD_ONLY) SavePPBuffer(" "); #endif } /*===========================================================*/ /* If an error occurred, set the error flag and return NULL. */ /*===========================================================*/ if (*error) { if (printError) SyntaxErrorMessage("RHS patterns"); ReturnExpression(firstOne); ReturnExpression(argHead); return(NULL); } /*=====================================*/ /* Fix the pretty print representation */ /* of the RHS ordered fact. */ /*=====================================*/ #if (! RUN_TIME) && (! BLOAD_ONLY) PPBackup(); PPBackup(); SavePPBuffer(tempToken->printForm); #endif /*==========================================================*/ /* Ordered fact assertions are processed by stuffing all of */ /* the fact's proposition (except the relation name) into a */ /* single multifield slot. */ /*==========================================================*/ firstOne->nextArg = GenConstant(FACT_STORE_MULTIFIELD,AddBitMap("\0",1)); firstOne->nextArg->argList = argHead; #if FUZZY_DEFTEMPLATES } /* --- matches else { above with FUZZY_DEFTEMPLATES */ #endif #if CERTAINTY_FACTORS /* if certaintly factors allowed then the next item after a fact specifier could be a certainty factor spec --- CF x.xxx */ #if (! RUN_TIME) && (! BLOAD_ONLY) SavePPBuffer(" "); #endif GetToken(readSource,tempToken); if ((tempToken->type == SYMBOL) && ((strcmp(ValueToString(tempToken->value),"CF") == 0) || (strcmp(ValueToString(tempToken->value),"cf") == 0)) ) { struct expr *CFexpr; /* expecting a certainty factor (float) expression */ /* tokenToFloatExpression expect 1st token already read */ #if (! RUN_TIME) && (! BLOAD_ONLY) SavePPBuffer(" "); #endif GetToken(readSource,tempToken); CFexpr = tokenToFloatExpression(readSource,tempToken,error,constantsOnly); if (*error) { ReturnExpression(firstOne); return( NULL ); } if (CFexpr->type == FLOAT) /* if constant -- check range */ { double cfval = ValueToDouble(CFexpr->value); if (cfval > 1.0 || cfval < 0.0) { *error = TRUE; ReturnExpression(CFexpr); cfRangeError(); ReturnExpression(firstOne); return( NULL ); } } /* store the CF expression in the argList of the DEFTEMPLATE_PTR expr */ firstOne->argList = CFexpr; } else { /* Do an 'UnGetToken' function here to undo the lookahead for a CF. Also need to PPBackup over the space added before reading the potential CF expression -- UnGetToken does one PPBackup over the token which was added to the PP Buffer */ UnGetToken(tempToken); #if (! RUN_TIME) && (! BLOAD_ONLY) PPBackup(); #endif } #endif /* CERTAINTY_FACTORS */ /*==============================*/ /* Return the RHS ordered fact. */ /*==============================*/ return(firstOne); }
void Face_Parse( face_t *face, bool bAlternateTexdef = false ){ int i, j; char *str; bool bworldcraft = false; char *token = Token(); // parse planepts str = NULL; for ( i = 0; i < 3; i++ ) { GetToken( true ); //( for ( j = 0; j < 3; j++ ) { GetToken( false ); face->planepts[i][j] = atof( token ); } GetToken( false ); //) } if ( bAlternateTexdef ) { // parse alternate texdef GetToken( false ); // ( GetToken( false ); // ( for ( i = 0; i < 3; i++ ) { GetToken( false ); face->brushprimit_texdef.coords[0][i] = atof( token ); } GetToken( false ); // ) GetToken( false ); // ( for ( i = 0; i < 3; i++ ) { GetToken( false ); face->brushprimit_texdef.coords[1][i] = atof( token ); } GetToken( false ); // ) GetToken( false ); // ) } // parse shader name GetToken( false ); // shader // if we're loading a halflife map then we don't have a relative texture name // we just get <texturename>. So we need to convert this to a relative name // like this: "textures/<wadname>/shader", so we use vfsFileFile to get the filename. // *** IMPORTANT *** // For Halflife we need to see if the texture is in wads listed in the // map's worldspawn "wad" e-pair. If we don't then the image used will be the // first image with this texture name that is found in any of the wads on the // user's system. this is not a huge problem, because the map compiler obeys // the "wad" epair when compiling the map, but the user might end up looking at // the wrong texture in the editor. (more of a problem if the texture we use // here has a different size from the one in the wad the map compiler uses...) // Hydra: - TTimo: I looked all over for other places to put this, but really it // is an issue with map loading (because of a limitation of halflife/q2 map format) // so it's gone in here, it also stops incorrect shader/texdef names getting used // in the radiant core and it's modules which we'd only have to change later on. // (either in map_importentities() or the shader module). so it's actually cleaner // in the long run, even if a little odd. And it keeps more game specific stuff // OUT of the core, which is a good thing. if ( g_MapVersion == MAPVERSION_HL ) { qboolean done = false; // FIXME: This bit is halflife specific. // look in the list of wads supplied in the worldspawn "wad" key/pair for the // texture first, if it's not in any then we carry on searching the vfs for it // as usual. // each time we find a texture, we add it to the a cache // so we don't have to hunt the vfs for it each time. // See SearchWadsForTextureName() and AddToCache() above for cache stuff char *wadname; wadname = SearchWadsForTextureName( token ); if ( wadname ) { face->texdef.SetName( wadname ); done = true; } else { // using the cache below means that this message is only ever printed out once! Sys_Printf( "WARNING: could not find \"%s\" in any listed wad files, searching all wad files instead!\n",token ); } // end of half-life specific bit. // check the cache! if ( !done ) { str = CheckCacheForTextureName( token ); if ( str ) { face->texdef.SetName( str ); done = true; } } if ( !done ) { char *fullpath; str = new char[strlen( token ) + 4 + 1]; // FIXME: halflife specific file extension, we'll have to support Q2/Q1 formats // and maybe tga texture format for HL here too.. sprintf( str,"%s.hlw",token ); fullpath = vfsGetFullPath( str,0,VFS_SEARCH_PAK | VFS_SEARCH_DIR ); // MIP support for quake if ( !fullpath ) { sprintf( str,"%s.mip",token ); fullpath = vfsGetFullPath( str, 0, 0 ); } // TGA support in halflife ? /* if (!fullpath) { sprintf(str,"%s.tga",token); fullpath = vfsGetFullPath(str); } */ delete [] str; if ( fullpath ) { // strip the extension. int len = strlen( fullpath ); if ( fullpath[len - 4] == '.' ) { fullpath[len - 4] = '\0'; } // and set the correct name! face->texdef.SetName( fullpath ); AddToCache( token,fullpath ); } else { Sys_Printf( "WARNING: could not find \"%s\" in the vfs search path\n",token ); str = new char[strlen( token ) + 10]; strcpy( str, "textures/" ); strcpy( str + 9, token ); face->texdef.SetName( str ); AddToCache( token,str ); delete [] str; } } } else // !MAPVERSION_HL { str = new char[strlen( token ) + 10]; strcpy( str, "textures/" ); strcpy( str + 9, token ); face->texdef.SetName( str ); delete [] str; } if ( !bAlternateTexdef ) { if ( g_MapVersion == MAPVERSION_HL ) { // Q1 as well ? GetToken( false ); if ( token[0] == '[' && token[1] == '\0' ) { bworldcraft = true; GetToken( false ); // UAxis[0] GetToken( false ); // UAxis[1] GetToken( false ); // UAxis[2] GetToken( false ); // shift face->texdef.shift[0] = atof( token ); GetToken( false ); // ] GetToken( false ); // [ GetToken( false ); // VAxis[0] GetToken( false ); // VAxis[1] GetToken( false ); // VAxis[2] GetToken( false ); // shift face->texdef.shift[1] = atof( token ); GetToken( false ); // ] // rotation is derived from the U and V axes. // ZHLT ignores this setting even if present in a .map file. GetToken( false ); face->texdef.rotate = atof( token ); // Scales GetToken( false ); face->texdef.scale[0] = atof( token ); GetToken( false ); face->texdef.scale[1] = atof( token ); } else { UnGetToken(); } } if ( !bworldcraft ) { // !MAPVERSION_HL // parse texdef GetToken( false ); face->texdef.shift[0] = atof( token ); GetToken( false ); face->texdef.shift[1] = atof( token ); GetToken( false ); face->texdef.rotate = atof( token ); GetToken( false ); face->texdef.scale[0] = atof( token ); GetToken( false ); face->texdef.scale[1] = atof( token ); } } // parse the optional contents/flags/value if ( !bworldcraft && TokenAvailable() ) { GetToken( true ); if ( isdigit( token[0] ) ) { face->texdef.contents = atoi( token ); GetToken( false ); face->texdef.flags = atoi( token ); GetToken( false ); face->texdef.value = atoi( token ); } else { UnGetToken(); } } }
boolean CI2CShell::Detect (void) { boolean bWriteMode = FALSE; CString Mode; if (GetToken (&Mode)) { if (Mode.Compare ("r") == 0) { // nothing to do } else if (Mode.Compare ("w") == 0) { bWriteMode = TRUE; } else { UnGetToken (Mode); } } assert (m_pI2CMaster != 0); m_pI2CMaster->SetClock (m_nI2CClockHz); u8 ucFirstSlaveAddress = INVALID_SLAVE; for (u8 ucAddress = SLAVE_ADDRESS_MIN; ucAddress <= SLAVE_ADDRESS_MAX; ucAddress++) { boolean bPresent = FALSE; if (bWriteMode) { if (m_pI2CMaster->Write (ucAddress, 0, 0) == 0) { bPresent = TRUE; } } else { u8 Buffer[1]; if (m_pI2CMaster->Read (ucAddress, Buffer, sizeof Buffer) >= 0) { bPresent = TRUE; } } if (bPresent) { if (ucFirstSlaveAddress == INVALID_SLAVE) { Print ("Slave(s) at address:"); ucFirstSlaveAddress = ucAddress; } Print (" 0x%02X", (unsigned) ucAddress); } } if (ucFirstSlaveAddress == INVALID_SLAVE) { Print ("No slave present\n"); m_ucSlaveAddress = INVALID_SLAVE; return FALSE; } Print ("\n"); m_ucSlaveAddress = ucFirstSlaveAddress; return TRUE; }