/* ================ GL_ResampleTexture ================ */ void GL_ResampleTexture (unsigned *indata, int inwidth, int inheight, unsigned *outdata, int outwidth, int outheight) { // _pixops_scale is too slow for large downsampling factors, so make use // of the fast GL_MipMap when possible if (inwidth >= outwidth*2 && inheight >= outheight*2) { int tw, th; byte *in, *buf; for (tw = outwidth, th = outheight; tw*2 <= inwidth && th*2 <= inheight; ) { tw *= 2; th *= 2; } if (inwidth > tw || inheight > th) { buf = Q_malloc (tw * th * 4); _pixops_scale ((guchar *)buf, 0, 0, tw, th, tw * 4, 4, 1, (const guchar *)indata, inwidth, inheight, inwidth * 4, 4, 1, (double)tw/inwidth, (double)th/inheight, PIXOPS_INTERP_BILINEAR); in = buf; } else { buf = Q_malloc ((tw/2) * (th/2) * 4); in = (byte *)indata; } while (tw > outwidth) { GL_MipMap (in, buf, tw, th); in = buf; tw >>= 1; th >>= 1; } memcpy (outdata, buf, outwidth*outheight*4); Q_free (buf); return; }
void Host_InitVCR (quakeparms_t *parms) { int i, len, n; char *p; if (COM_CheckParm("-playback")) { if (com_argc != 2) Sys_Error("No other parameters allowed with -playback\n"); Sys_FileOpenRead("quake.vcr", &vcrFile); if (vcrFile == -1) Sys_Error("playback file not found\n"); Sys_FileRead (vcrFile, &i, sizeof(int)); if (i != VCR_SIGNATURE) Sys_Error("Invalid signature in vcr file\n"); Sys_FileRead (vcrFile, &com_argc, sizeof(int)); com_argv = Q_malloc(com_argc * sizeof(char *)); com_argv[0] = parms->argv[0]; for (i = 0; i < com_argc; i++) { Sys_FileRead (vcrFile, &len, sizeof(int)); p = Q_malloc(len); Sys_FileRead (vcrFile, p, len); com_argv[i+1] = p; } com_argc++; /* add one for arg[0] */ parms->argc = com_argc; parms->argv = com_argv; } if ( (n = COM_CheckParm("-record")) != 0) { vcrFile = Sys_FileOpenWrite("quake.vcr"); i = VCR_SIGNATURE; Sys_FileWrite(vcrFile, &i, sizeof(int)); i = com_argc - 1; Sys_FileWrite(vcrFile, &i, sizeof(int)); for (i = 1; i < com_argc; i++) { if (i == n) { len = 10; Sys_FileWrite(vcrFile, &len, sizeof(int)); Sys_FileWrite(vcrFile, "-playback", len); continue; } len = strlen(com_argv[i]) + 1; Sys_FileWrite(vcrFile, &len, sizeof(int)); Sys_FileWrite(vcrFile, com_argv[i], len); } } }
// renders document into memory buffer, int XSD_RenderDocument(document_rendered_t *ret, xml_document_t *doc, int width) { int lines; memset(ret, 0, sizeof(document_rendered_t)); // render document title if (doc->title) { int lines; document_tag_text_t *text; document_tag_p_t *p; xml_document_t *tdoc; tdoc = XSD_Document_New(); // create p tag p = (document_tag_p_t *) Q_malloc(sizeof(document_tag_p_t)); memset(p, 0, sizeof(document_tag_p_t)); p->type = tag_p; p->align = align_center; tdoc->content = (document_tag_t *) p; // create text tag text = (document_tag_text_t *) Q_malloc(sizeof(document_tag_text_t)); memset(text, 0, sizeof(document_tag_text_t)); text->type = tag_text; text->text = Q_strdup(doc->title); p->tags = (document_tag_t *) text; lines = XSD_RenderDocumentOnce(tdoc, NULL, width, 0, NULL, NULL); if (lines > 0) { ret->title = (char *) Q_malloc(lines*width); ret->title_lines = XSD_RenderDocumentOnce(tdoc,(byte *) ret->title, width, lines, NULL, NULL); } XSD_Document_Free((xml_t *)tdoc); } // render document body lines = XSD_RenderDocumentOnce(doc, NULL, width, 0, NULL, NULL); if (lines <= 0) goto error; ret->text = (char *) Q_malloc(lines*width); ret->text_lines = XSD_RenderDocumentOnce(doc,(byte *) ret->text, width, lines, &ret->links, &ret->sections); return 1; error: XSD_RenderClear(ret); return 0; }
/* =============== Cmd_StuffCmds_f Adds command line parameters as script statements Commands lead with a +, and continue until a - or another + quake +prog jctest.qp +cmd amlev1 quake -nosound +cmd amlev1 =============== */ void Cmd_StuffCmds_f (void) { int i, j; int s; char *text, *build, c; // build the combined string to parse from s = 0; for (i = 1; i < com_argc; i++) s += strlen (com_argv[i]) + 1; if (!s) return; text = (char *) Q_malloc (s+1); text[0] = 0; for (i = 1; i < com_argc; i++) { strlcat (text, com_argv[i], s + 1); if (i != com_argc-1) strlcat (text, " ", s + 1); } // pull out the commands build = (char *) Q_malloc (s+1); build[0] = 0; for (i=0 ; i<s-1 ; i++) { if (text[i] == '+') { i++; for (j=i ; (text[j] != '+') && (text[j] != '-') && (text[j] != 0) ; j++) ; c = text[j]; text[j] = 0; strlcat (build, text + i, s + 1); strlcat (build, "\n", s + 1); text[j] = c; i = j-1; } } if (build[0]) Cbuf_AddText (build); Q_free (text); Q_free (build); }
static void Precache_Source(source_data *s) { int i; char name[1024]; server_data *servers[MAX_SERVERS]; int serversn = 0; if (s->type == type_url) { char *filename; size_t filename_size = SB_URL_To_Filename_Length(s->address.url); filename = Q_malloc(filename_size); SB_URL_to_FileName(s->address.url, filename, filename_size); snprintf(name, sizeof (name), "sb/cache/%s", filename); Q_free(filename); } else if (s->type == type_master) { snprintf(name, sizeof (name), "sb/cache/%d_%d_%d_%d_[%d].txt", s->address.address.ip[0], s->address.address.ip[1], s->address.address.ip[2], s->address.address.ip[3], ntohs(s->address.address.port)); } else { return; } Update_Source_From_File(s, name, servers, &serversn); if (serversn > 0) { SYSTEMTIME tm; char tmp_path[MAX_OSPATH] = {0}; snprintf(&tmp_path[0], sizeof(tmp_path), "%s/ezquake/%s", com_basedir, name); if (GetFileLocalTime(tmp_path, &tm)) { Reset_Source(s); s->servers = (server_data **) Q_malloc(serversn * sizeof(server_data *)); for (i=0; i < serversn; i++) s->servers[i] = servers[i]; s->serversn = serversn; s->servers_allocated = serversn; if (s->checked) rebuild_servers_list = 1; memcpy(&s->last_update, &tm, sizeof(SYSTEMTIME)); } } }
/* =========== Cvar_Get =========== */ cvar_t *Cvar_Get (const char *name, const char *string, int cvarflags) { cvar_t *var; int key; var = Cvar_Find(name); if (var) { var->flags &= ~CVAR_TEMP; var->flags |= cvarflags; return var; } // allocate a new cvar var = (cvar_t *) Q_malloc (sizeof(cvar_t)); // link it in var->next = cvar_vars; cvar_vars = var; key = Com_HashKey (name); var->hash_next = cvar_hash[key]; cvar_hash[key] = var; // Q_malloc returns unitialized memory, so make sure all fields // are initialized here var->name = Q_strdup (name); var->string = Q_strdup (string); var->flags = cvarflags | CVAR_DYNAMIC; var->value = Q_atof (var->string); var->OnChange = NULL; // FIXME, check userinfo/serverinfo return var; }
// allocate, may link it in, if requested svtcpstream_t *sv_tcp_connection_new(int sock, netadr_t from, char *buf, int buf_len, qbool link) { svtcpstream_t *st = NULL; st = Q_malloc(sizeof(svtcpstream_t)); st->waitingforprotocolconfirmation = true; st->socketnum = sock; st->remoteaddr = from; if (buf_len > 0 && buf_len < sizeof(st->inbuffer)) { memmove(st->inbuffer, buf, buf_len); st->inlen = buf_len; } else st->drop = true; // yeah, funny // link it in if requested if (link) { st->next = svs.tcpstreams; svs.tcpstreams = st; } return st; }
// adds text element char *Add_Inline_Text (document_rendering_context_t *cx, char *text, document_tag_text_t *tag) { char *s, *d; char *buf; size_t size; size = strlen (text) + strlen (tag->text) + 1; buf = (char *) Q_malloc (size); strlcpy (buf, text, size); Q_free (text); d = buf + strlen(buf); s = tag->text; while (*s) { char c = *s++; if (cx->do_color) c = ChangeColor(c); *d++ = c; } *d = 0; return buf; }
// strip spaces multiple spaces from in-between words char *XSD_StripSpaces (char *str) { char *buf, *ret; unsigned int p = 0, q = 0; if (str == NULL) return str; buf = (char *) Q_malloc(strlen(str)+1); for (p=0; p < strlen(str); p++) { if (XSD_IsSpace(str[p])) { if (q == 0 || XSD_IsSpace(buf[q-1])) ; else buf[q++] = ' '; } else buf[q++] = str[p]; } // strip spaces from the end while (q > 0 && XSD_IsSpace(buf[q-1])) q--; buf[q] = 0; ret = (char *) Q_strdup(buf); Q_free(buf); Q_free(str); return ret; }
cvar_t *Cvar_Create (char *name, char *string, int cvarflags) { cvar_t *v; int key; if ((v = Cvar_Find(name))) { v->flags &= ~CVAR_TEMP; v->flags |= cvarflags; return v; } v = (cvar_t *) Q_malloc(sizeof(cvar_t)); memset(v, 0, sizeof(cvar_t)); // Cvar doesn't exist, so we create it v->next = cvar_vars; cvar_vars = v; key = Com_HashKey (name) % VAR_HASHPOOL_SIZE; v->hash_next = cvar_hash[key]; cvar_hash[key] = v; v->name = Q_strdup(name); v->string = Q_strdup(string); v->defaultvalue = Q_strdup(string); v->flags = cvarflags | CVAR_USER_CREATED; v->value = Q_atof (v->string); v->integer = Q_atoi (v->string); StringToRGB_W(v->string, v->color); v->modified = true; #ifdef WITH_TCL TCL_RegisterVariable (v); #endif return v; }
int MP3_WINAMP_CachePlaylist(void) { char *playlist_buf; unsigned int length; int current; if ((length = WINAMP_GetPlaylist(&playlist_buf)) == -1) { Com_Printf("%s is not running\n", mp3_player->PlayerName_LeadingCaps); return -1; } MP3_WINAMP_GetPlaylistInfo(¤t, &WINAMP_Playlist_nelms); /* Free the list before we cache a new one */ if (WINAMP_Playlist) { MP3_WINAMP_CachePlaylistFlush(); } WINAMP_Playlist = (char **) Q_malloc(sizeof(*WINAMP_Playlist)*WINAMP_Playlist_nelms); WINAMP_Playlist_nelms = WINAMP_ParsePlaylist_EXTM3U(playlist_buf, length, WINAMP_Playlist, WINAMP_Playlist_nelms); Q_free(playlist_buf); return 0; }
CPageViewer_t * CPageViewer_New(void) { CPageViewer_t *viewer = (CPageViewer_t *) Q_malloc(sizeof(CPageViewer_t)); CPageViewer_Init(viewer); return viewer; }
void AddToFileSource(source_data *source, server_data *serv) { if (IsInSource(source, serv)) return; SB_ServerList_Lock(); // reallocate buffer if we've run out of space if (source->serversn >= source->servers_allocated) { int new_size = source->servers_allocated + 4; server_data** newlist = Q_malloc(new_size * sizeof(server_data*)); memcpy(newlist, source->servers, sizeof(server_data*) * source->servers_allocated); Q_free(source->servers); source->servers = newlist; source->servers_allocated = new_size; } source->servers[source->serversn++] = Clone_Server(serv); rebuild_servers_list = true; SB_ServerList_Unlock(); DumpSource(source); Mark_Source(sources[0]); }
// allocate data and set fields, perform linkage to qtvuserlist // Well, instead of QTV_NewUser(int id, char *name, ...) I pass params with single qtvuser_t *user struct, well its OK for current struct. static qtvuser_t *QTV_NewUser(qtvuser_t *user) { // check, may be user alredy exist, so reuse it qtvuser_t *newuser = QTV_UserById(user->id); if (!newuser) { // user does't exist, alloc data newuser = Q_malloc(sizeof(*newuser)); QTV_SetUser(newuser, user); // perform linkage newuser->next = qtvuserlist; qtvuserlist = newuser; } else { // we do not need linkage, just save current qtvuser_t *oldnext = newuser->next; // we need save this before assign all fields QTV_SetUser(newuser, user); newuser->next = oldnext; } return newuser; }
void MVD_ClockStart(int itemtype) { mvd_clock_t *newclock = (mvd_clock_t *) Q_malloc(sizeof (mvd_clock_t)); newclock->clockval = cls.demotime + MVD_RespawnTimeGet(itemtype); newclock->itemtype = itemtype; MVD_ClockList_Insert(newclock); }
void SaveConfig(const char *cfgname) { char filename[MAX_PATH] = {0}, *filename_ext, *backupname_ext; size_t len; FILE *f; snprintf(filename, sizeof(filename) - 4, "%s", cfgname[0] ? cfgname : MAIN_CONFIG_FILENAME); // use config.cfg if no params was specified COM_ForceExtensionEx (filename, ".cfg", sizeof (filename)); if (cfg_backup.integer) { if (cfg_use_home.integer) // homedir filename_ext = va("%s/%s/%s", com_homedir, (strcmp(com_gamedirfile, "qw") == 0 || !cfg_use_gamedir.integer) ? "" : com_gamedirfile, filename); else // basedir filename_ext = va("%s/%s/configs/%s", com_basedir, (strcmp(com_gamedirfile, "qw") == 0 || !cfg_use_gamedir.integer) ? "ezquake" : com_gamedirfile, filename); if ((f = fopen(filename_ext, "r"))) { fclose(f); len = strlen(filename_ext) + 5; backupname_ext = (char *) Q_malloc(len); snprintf (backupname_ext, len, "%s.bak", filename_ext); if ((f = fopen(backupname_ext, "r"))) { fclose(f); remove(backupname_ext); } rename(filename_ext, backupname_ext); Q_free(backupname_ext); } } DumpConfig(filename); filesystemchanged = true; // fix bug 2359900 }
static cvar_group_t *Cvar_AddGroup(char *name) { static qbool initialised = false; cvar_group_t *newgroup; char **s; if (!initialised) { initialised = true; for (s = cvar_groups_list; *s; s++) Cvar_AddGroup(*s); } for (newgroup = cvar_groups; newgroup; newgroup = newgroup->next) if (!strcasecmp(newgroup->name, name)) return newgroup; newgroup = (cvar_group_t *) Q_malloc(sizeof(cvar_group_t)); strlcpy(newgroup->name, name, sizeof(newgroup->name)); newgroup->count = 0; newgroup->head = NULL; newgroup->next = cvar_groups; cvar_groups = newgroup; return newgroup; }
static void RenderDocument(CPageViewer_t *viewer, int width) { // int lines; xml_document_t *doc; LeaveNavigationMode(viewer); FreePageRendered(viewer->page); viewer->page->current_line = 0; viewer->page->width = width; viewer->page->should_render = false; // load document if (!viewer->page->doc) viewer->page->doc = XSD_LoadDocumentWithXsl(viewer->page->url); if (!viewer->page->doc) goto error; doc = viewer->page->doc; if (!XSD_RenderDocument(&viewer->page->rendered, doc, width)) goto error; return; error: viewer->page->rendered.title = (char *) Q_malloc(viewer->page->width); memset(viewer->page->rendered.title, 0, width); memcpy(viewer->page->rendered.title, "Document loading error!", strlen("Document loading error!")); viewer->page->rendered.title_lines = 1; return; }
static void AddPage(CPageViewer_t *viewer) { CPageViewer_page_t *page = (CPageViewer_page_t *) Q_malloc(sizeof(CPageViewer_page_t)); memset(page, 0, sizeof(CPageViewer_page_t)); page->next = viewer->page; viewer->page = page; }
// returns Q_malloc'ed data wchar *decode_cp1251 (char *str) { wchar *buf, *out; buf = out = Q_malloc ((strlen(str) + 1)*sizeof(wchar)); while (*str) *out++ = cp1251towc(*str++); *out = 0; return buf; };
wchar *Q_wcsdup (const wchar *src) { wchar *out; size_t size = (qwcslen(src) + 1) * sizeof(wchar); out = Q_malloc (size); memcpy (out, src, size); return out; }
// returns Q_malloc'ed data wchar *decode_koi8q (char *str) { wchar *buf, *out; buf = out = Q_malloc ((strlen(str) + 1)*sizeof(wchar)); while (*str) *out++ = koi2wc(*str++); *out = 0; return buf; };
// adds string char *Add_Inline_String (char *text, char *string) { size_t size = strlen (text) + strlen (string) + 1; char *buf = (char *) Q_malloc (size); strlcpy (buf, text, size); Q_free(text); strlcat (buf, string, size); return buf; }
sb_qtvlist_parse_state_t *QTVList_Parse_Init(void) { sb_qtvlist_parse_state_t *ret = Q_malloc(sizeof (sb_qtvlist_parse_state_t)); ret->chardata_buffer[0] = '\0'; ret->list = NULL; ret->position = QTVLIST_INITIAL; return ret; }
static void SB_PingTree_ScanProxies(void) { int i; proxy_request_queue queue = { NULL, 0, false }; size_t request = 0; FILE *f = NULL; for (i = 0; i < ping_nodes_count; i++) { if (ping_nodes[i].proxport) { queue.items++; } } if (!queue.items) return; queue.data = (proxy_query_request_t *) Q_malloc(sizeof(proxy_query_request_t) * queue.items); for (i = 0; i < ping_nodes_count; i++) { if (ping_nodes[i].proxport) { queue.data[request].done = false; queue.data[request].nodeid = i; queue.data[request].sock = UDP_OpenSocket(NA_IPv4, PORT_ANY); request++; } } if (sb_listcache.value) { f = fopen(va("%s/%s", com_homedir, "proxies_data"), "wb"); if (f) SB_Proxylist_Serialize_Start(f); } for (i = 0; i < sb_proxretries.integer; i++) { queue.sending_done = false; Sys_CreateThread(SB_PingTree_SendQueryThread, (void *) &queue); SB_PingTree_RecvQuery(&queue, f); if (queue.allrecved) { break; } } if (f) { SB_Proxylist_Serialize_End(f); fclose(f); } while (!queue.sending_done) { // XXX: use semaphore instead Sys_MSleep(100); } for (i = 0; i < queue.items; i++) { closesocket(queue.data[i].sock); } Q_free(queue.data); }
void R_Bloom_InitTextures( void ) { unsigned char *data; int maxtexsize; size_t size; // Find closer power of 2 to screen size. for (screen_texture_width = 1; screen_texture_width < glwidth; screen_texture_width *= 2); for (screen_texture_height = 1; screen_texture_height < glheight; screen_texture_height *= 2); // Disable blooms if we can't handle a texture of that size. glGetIntegerv (GL_MAX_TEXTURE_SIZE, &maxtexsize); if (screen_texture_width > maxtexsize || screen_texture_height > maxtexsize) { screen_texture_width = screen_texture_height = 0; Cvar_SetValue (&r_bloom, 0); Com_Printf ("WARNING: 'R_InitBloomScreenTexture' too high resolution for Light Bloom. Effect disabled\n"); return; } // Init the screen texture. size = screen_texture_width * screen_texture_height * sizeof (int); data = Q_malloc (size); memset (data, 255, size); //r_bloomscreentexture = GL_LoadTexture ( "***r_screenbackuptexture***", screen_texture_width, screen_texture_height, data, 0, 4); // false, false, 4); if (!r_bloomscreentexture) r_bloomscreentexture = texture_extension_number++; GL_Bind (r_bloomscreentexture); glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, screen_texture_width, screen_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); Q_free (data); // Validate bloom size and init the bloom effect texture. R_Bloom_InitEffectTexture(); // If screensize is more than 2x the bloom effect texture, set up for stepped downsampling. r_bloomdownsamplingtexture = 0; r_screendownsamplingtexture_size = 0; if( glwidth > (BLOOM_SIZE * 2) && !r_bloom_fast_sample.value ) { r_screendownsamplingtexture_size = (int)(BLOOM_SIZE * 2); data = Q_calloc (r_screendownsamplingtexture_size * r_screendownsamplingtexture_size, sizeof (int)); r_bloomdownsamplingtexture = GL_LoadTexture ( "***r_bloomdownsamplingtexture***", r_screendownsamplingtexture_size, r_screendownsamplingtexture_size, data, 0, 4); Q_free (data); } // Init the screen backup texture. if (r_screendownsamplingtexture_size) R_Bloom_InitBackUpTexture (r_screendownsamplingtexture_size, r_screendownsamplingtexture_size); else R_Bloom_InitBackUpTexture (BLOOM_SIZE, BLOOM_SIZE); }
/* ================== CopyWinding ================== */ winding_t *CopyWinding (winding_t *w) { int size; winding_t *c; size = (int)((winding_t *)0)->p[w->numpoints]; c = Q_malloc (size); memcpy (c, w, size); return c; }
/* ============= AllocWinding ============= */ winding_t *AllocWinding (int points) { winding_t *w; int s; s = sizeof(vec_t)*3*points + sizeof(int); w = Q_malloc (s); memset (w, 0, s); return w; }
/* * Sys_Thread_Create */ int Sys_Thread_Create( qthread_t **pthread, void *(*routine) (void*), void *param ) { qthread_t *thread; thread = (qthread_t *)Q_malloc(sizeof(*thread)); thread->t = SDL_CreateThread((SDL_ThreadFunction)routine, NULL, param); *pthread = thread; return 0; }
/* * Sys_Mutex_Create */ int Sys_Mutex_Create( qmutex_t **pmutex ) { qmutex_t *mutex; mutex = (qmutex_t *)Q_malloc(sizeof(*mutex)); mutex->m = SDL_CreateMutex(); *pmutex = mutex; return 0; }