eclass_t *Eclass_ForName (const char *name, bool has_brushes) { eclass_t *e; char buff[1024]; if (!name) { return eclass_bad; } for ( e = eclass; e; e = e->next ) { if ( !strcmp( name, e->name ) ) { return e; } } e = EClass_Alloc(); if ( !e ) { return NULL; } e->name = Mem_CopyString( name ); sprintf(buff, "%s not found in def/*.def\n", name); e->comments = Mem_CopyString( buff ); e->color.x = 0.0f; e->color.y = 0.5f; e->color.z = 0.0f; e->fixedsize = !has_brushes; e->mins.x = e->mins.y = e->mins.z = -8.0f; e->maxs.x = e->maxs.y = e->maxs.z = 8.0f; Eclass_InsertAlphabetized( e ); return e; }
/* ============ idCmdSystemLocal::AddCommand ============ */ void idCmdSystemLocal::AddCommand( const char* cmdName, cmdFunction_t function, int flags, const char* description, argCompletion_t argCompletion ) { commandDef_t* cmd; // fail if the command already exists for( cmd = commands; cmd; cmd = cmd->next ) { if( idStr::Cmp( cmdName, cmd->name ) == 0 ) { if( function != cmd->function ) { common->Printf( "idCmdSystemLocal::AddCommand: %s already defined\n", cmdName ); } return; } } cmd = new( TAG_SYSTEM ) commandDef_t; cmd->name = Mem_CopyString( cmdName ); cmd->function = function; cmd->argCompletion = argCompletion; cmd->flags = flags; cmd->description = Mem_CopyString( description ); cmd->next = commands; commands = cmd; }
eclass_t* GetCachedModel(entity_t *pEntity, const char *pName, idVec3 &vMin, idVec3 &vMax) { eclass_t *e = NULL; if (pName == NULL || strlen(pName) == 0) { return NULL; } for (e = g_md3Cache; e ; e = e->next) { if (!strcmp (pName, e->name)) { pEntity->md3Class = e; VectorCopy(e->mins, vMin); VectorCopy(e->maxs, vMax); return e; } } e = (eclass_t*)Mem_ClearedAlloc(sizeof(*e)); memset (e, 0, sizeof(*e)); e->name = Mem_CopyString( pName ); e->color[0] = e->color[2] = 0.85f; if (LoadModel(pName, e, vMin, vMax, NULL)) { EClass_InsertSortedList(g_md3Cache, e); VectorCopy(vMin, e->mins); VectorCopy(vMax, e->maxs); pEntity->md3Class = e; return e; } return NULL; }
} END_TEST START_TEST(check_Mem_CopyString) { char *test = Mem_CopyString("test"); ck_assert(Mem_Size() == strlen(test) + 1); Mem_Free(test); ck_assert(Mem_Size() == 0); } END_TEST
void Eclass_InitForSourceDirectory( const char *path ) { int c = declManager->GetNumDecls( DECL_ENTITYDEF ); for( int i = 0; i < c; i++ ) { const idDeclEntityDef *def = static_cast<const idDeclEntityDef *>( declManager->DeclByIndex( DECL_ENTITYDEF, i ) ); if( def ) { eclass_t *e = EClass_InitFromDict( &def->dict, def->GetName() ); if( e ) { Eclass_InsertAlphabetized( e ); } } } eclass_bad = EClass_Alloc(); if( !eclass_bad ) { return; } eclass_bad->color.x = 0.0f; eclass_bad->color.y = 0.5f; eclass_bad->color.z = 0.0f; eclass_bad->fixedsize = false; eclass_bad->name = Mem_CopyString( "UKNOWN ENTITY CLASS" ); }
/* ================ CSyntaxRichEditCtrl::LoadKeyWordsFromFile ================ */ bool CSyntaxRichEditCtrl::LoadKeyWordsFromFile(const char *fileName) { idParser src; idToken token, name, description; byte red, green, blue; keyWord_t keyword; if (!src.LoadFile(fileName)) { return false; } FreeKeyWordsFromFile(); while (src.ReadToken(&token)) { if (token.Icmp("keywords") == 0) { src.ExpectTokenString("{"); while (src.ReadToken(&token)) { if (token == "}") { break; } if (token == "{") { // parse name src.ExpectTokenType(TT_STRING, 0, &name); src.ExpectTokenString(","); // parse color src.ExpectTokenString("("); src.ExpectTokenType(TT_NUMBER, TT_INTEGER, &token); red = token.GetIntValue(); src.ExpectTokenString(","); src.ExpectTokenType(TT_NUMBER, TT_INTEGER, &token); green = token.GetIntValue(); src.ExpectTokenString(","); src.ExpectTokenType(TT_NUMBER, TT_INTEGER, &token); blue = token.GetIntValue(); src.ExpectTokenString(")"); src.ExpectTokenString(","); // parse description src.ExpectTokenType(TT_STRING, 0, &description); src.ExpectTokenString("}"); keyword.keyWord = Mem_CopyString(name); keyword.color = RGB(red, green, blue); keyword.description = Mem_CopyString(description); keyWordsFromFile.Append(keyword); } } } else { src.SkipBracedSection(); } } keyword.keyWord = NULL; keyword.color = RGB(255, 255, 255); keyword.description = NULL; keyWordsFromFile.Append(keyword); SetKeyWords(keyWordsFromFile.Ptr()); return true; }
static LONG WINAPI ConWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { char *cmdString; static bool s_timePolarity; switch (uMsg) { case WM_ACTIVATE: if ( LOWORD( wParam ) != WA_INACTIVE ) { SetFocus( s_wcd.hwndInputLine ); } break; case WM_CLOSE: if ( cvarSystem->IsInitialized() && com_skipRenderer.GetBool() ) { cmdString = Mem_CopyString( "quit" ); Sys_QueEvent( 0, SE_CONSOLE, 0, 0, strlen( cmdString ) + 1, cmdString ); } else if ( s_wcd.quitOnClose ) { PostQuitMessage( 0 ); } else { Sys_ShowConsole( 0, false ); win32.win_viewlog.SetBool( false ); } return 0; case WM_CTLCOLORSTATIC: if ( ( HWND ) lParam == s_wcd.hwndBuffer ) { SetBkColor( ( HDC ) wParam, RGB( 0x00, 0x00, 0x80 ) ); SetTextColor( ( HDC ) wParam, RGB( 0xff, 0xff, 0x00 ) ); return ( long ) s_wcd.hbrEditBackground; } else if ( ( HWND ) lParam == s_wcd.hwndErrorBox ) { if ( s_timePolarity & 1 ) { SetBkColor( ( HDC ) wParam, RGB( 0x80, 0x80, 0x80 ) ); SetTextColor( ( HDC ) wParam, RGB( 0xff, 0x0, 0x00 ) ); } else { SetBkColor( ( HDC ) wParam, RGB( 0x80, 0x80, 0x80 ) ); SetTextColor( ( HDC ) wParam, RGB( 0x00, 0x0, 0x00 ) ); } return ( long ) s_wcd.hbrErrorBackground; } break; case WM_SYSCOMMAND: if ( wParam == SC_CLOSE ) { PostQuitMessage( 0 ); } break; case WM_COMMAND: if ( wParam == COPY_ID ) { SendMessage( s_wcd.hwndBuffer, EM_SETSEL, 0, -1 ); SendMessage( s_wcd.hwndBuffer, WM_COPY, 0, 0 ); } else if ( wParam == QUIT_ID ) { if ( s_wcd.quitOnClose ) { PostQuitMessage( 0 ); } else { cmdString = Mem_CopyString( "quit" ); Sys_QueEvent( 0, SE_CONSOLE, 0, 0, strlen( cmdString ) + 1, cmdString ); } } else if ( wParam == CLEAR_ID ) { SendMessage( s_wcd.hwndBuffer, EM_SETSEL, 0, -1 ); SendMessage( s_wcd.hwndBuffer, EM_REPLACESEL, FALSE, ( LPARAM ) "" ); UpdateWindow( s_wcd.hwndBuffer ); } break; case WM_CREATE: s_wcd.hbrEditBackground = CreateSolidBrush( RGB( 0x00, 0x00, 0x80 ) ); s_wcd.hbrErrorBackground = CreateSolidBrush( RGB( 0x80, 0x80, 0x80 ) ); SetTimer( hWnd, 1, 1000, NULL ); break; /* case WM_ERASEBKGND: HGDIOBJ oldObject; HDC hdcScaled; hdcScaled = CreateCompatibleDC( ( HDC ) wParam ); assert( hdcScaled != 0 ); if ( hdcScaled ) { oldObject = SelectObject( ( HDC ) hdcScaled, s_wcd.hbmLogo ); assert( oldObject != 0 ); if ( oldObject ) { StretchBlt( ( HDC ) wParam, 0, 0, s_wcd.windowWidth, s_wcd.windowHeight, hdcScaled, 0, 0, 512, 384, SRCCOPY ); } DeleteDC( hdcScaled ); hdcScaled = 0; } return 1; */ case WM_TIMER: if ( wParam == 1 ) { s_timePolarity = (bool)!s_timePolarity; if ( s_wcd.hwndErrorBox ) { InvalidateRect( s_wcd.hwndErrorBox, NULL, FALSE ); } } break; } return DefWindowProc( hWnd, uMsg, wParam, lParam ); }
/** * @brief */ static cvar_t *Cvar_Set_(const char *name, const char *value, int32_t flags, _Bool force) { cvar_t *var = Cvar_Get(name); if (!var) { // create it return Cvar_Add(name, value, flags, NULL); } if (var->flags & (CVAR_USER_INFO | CVAR_SERVER_INFO)) { if (!Cvar_InfoValidate(value)) { Com_Print("Invalid info value for %s: %s\n", var->name, value); return var; } } // if not forced, honor flags-based logic if (!force) { // command line variables retain their value through initialization if (var->flags & CVAR_CLI) { if (!Com_WasInit(QUETOO_CLIENT) && !Com_WasInit(QUETOO_SERVER)) { Com_Debug(DEBUG_CONSOLE, "%s: retaining value \"%s\" from command line.\n", name, var->string); return var; } } // developer variables can not be modified when in multiplayer mode if (var->flags & CVAR_DEVELOPER) { if (!Com_WasInit(QUETOO_SERVER)) { Com_Print("%s is only available offline.\n", name); return var; } } // write-protected variables can never be modified if (var->flags & CVAR_NO_SET) { Com_Print("%s is write protected.\n", name); return var; } // while latched variables can only be changed on map load if (var->flags & CVAR_LATCH) { if (var->latched_string) { if (!g_strcmp0(value, var->latched_string)) { return var; } Mem_Free(var->latched_string); } else { if (!g_strcmp0(value, var->string)) { return var; } } if (Com_WasInit(QUETOO_SERVER)) { Com_Print("%s will be changed for next game.\n", name); var->latched_string = Mem_Link(Mem_TagCopyString(value, MEM_TAG_CVAR), var); } else { if (var->string) { Mem_Free(var->string); } var->string = Mem_Link(Mem_TagCopyString(value, MEM_TAG_CVAR), var); var->value = strtof(var->string, NULL); var->integer = (int32_t) strtol(var->string, NULL, 0); var->modified = true; } return var; } } else { if (var->latched_string) { Mem_Free(var->latched_string); var->latched_string = NULL; } } if (!g_strcmp0(var->string, value)) { return var; // not changed } if (!force) { if (var->flags & CVAR_R_MASK) { Com_Print("%s will be changed on ^3r_restart^7.\n", name); } if (var->flags & CVAR_S_MASK) { Com_Print("%s will be changed on ^3s_restart^7.\n", name); } } if (var->flags & CVAR_USER_INFO) { cvar_user_info_modified = true; // transmit at next opportunity } Mem_Free(var->string); var->string = Mem_Link(Mem_CopyString(value), var); var->value = strtof(var->string, NULL); var->integer = (int32_t) strtol(var->string, NULL, 0); var->modified = true; return var; }