Example #1
0
static char *VX_RemovePrefix(int player)
{
	size_t skip;
	char *prefixes, *prefix, *name;

	if (amf_tracker_name_remove_prefixes.string[0] == 0)
		return cl.players[player].name;

	skip = 0;
	prefixes = Q_normalizetext(Q_strdup(amf_tracker_name_remove_prefixes.string));
	prefix = strtok(prefixes, " ");
	name = Q_normalizetext(Q_strdup(cl.players[player].name));

	while (prefix != NULL) {
		if (strlen(prefix) > skip && strlen(name) > strlen(prefix) && strncasecmp(prefix, name, strlen(prefix)) == 0) {
			skip = strlen(prefix);
			// remove spaces from the new start of the name
			while (name[skip] == ' ')
				skip++;
			// if it would skip the whole name, just use the whole name
			if (name[skip] == 0) {
				skip = 0;
				break;
			}
		}
		prefix = strtok(NULL, " ");
	}

	Q_free(prefixes);
	Q_free(name);

	return cl.players[player].name + skip;
}
Example #2
0
// compares two fun strings
int funcmp(const char *s1, const char *s2)
{
    char *t1, *t2;
    int ret;

    if (s1 == NULL  &&  s2 == NULL)
        return 0;

    if (s1 == NULL)
        return -1;

    if (s2 == NULL)
        return 1;

    t1 = Q_strdup(s1);
    t2 = Q_strdup(s2);

    FunToSort(t1);
    FunToSort(t2);

    ret = strcmp(t1, t2);

    Q_free(t1);
    Q_free(t2);

    return ret;
}
Example #3
0
File: cvar.cpp Project: luaman/zq
/*
===========
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;
}
Example #4
0
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;
}
Example #5
0
File: cvar.cpp Project: luaman/zq
/*
============
Cvar_Register

Adds a freestanding variable to the variable list.

If the variable already exists, the value will not be set
The flags will be or'ed in if the variable exists.
============
*/
EXTERNC void Cvar_Register (cvar_t *var)
{
	char	string[512];
	int		key;
	cvar_t	*old;

	// first check to see if it has already been defined
	old = Cvar_Find (var->name);

	if (old && !(old->flags & CVAR_DYNAMIC)) {
		if (old == var)
			return;
		Com_Printf ("Can't register variable %s, already defined\n", var->name);
		return;
	}

#if 0
	// check for overlap with a command
	if (Cmd_Exists (var->name)) {
		Com_Printf ("Cvar_Register: %s is a command\n", var->name);
		return;
	}
#endif

	if (old)
	{
		var->flags |= old->flags & ~(CVAR_DYNAMIC|CVAR_TEMP);
		strlcpy (string, old->string, sizeof(string));
		Cvar_Delete (old->name);
		if (!(var->flags & CVAR_ROM))
			var->string = Q_strdup (string);
		else
			var->string = Q_strdup (var->string);
	}
	else
	{
		// allocate the string on heap because future sets will Q_free it
		var->string = Q_strdup (var->string);
	}
	
	var->value = Q_atof (var->string);

	// link the variable in
	key = Com_HashKey (var->name);
	var->hash_next = cvar_hash[key];
	cvar_hash[key] = var;
	var->next = cvar_vars;
	cvar_vars = var;

#ifndef CLIENTONLY
	if (var->flags & CVAR_SERVERINFO)
		SV_ServerinfoChanged (var->name, var->string);
#endif

#ifndef SERVERONLY
	if (var->flags & CVAR_USERINFO)
		CL_UserinfoChanged (var->name, var->string);
#endif
}
Example #6
0
void SList_Set (int i, char *addr, char *desc) {
	if (i >= MAX_SERVER_LIST || i < 0)
		Sys_Error("SList_Switch: Bad index %d", i);

	if (slist[i].server)
		Q_free(slist[i].server);
	if (slist[i].description)
		Q_free(slist[i].description);

	slist[i].server = Q_strdup (addr);
	slist[i].description = Q_strdup (desc);
}
Example #7
0
static char *VX_SkipCommonPrefix(int player)
{
	size_t skip;
	char *prefixes, *prefix, *name;

	skip = 0;
	prefixes = Q_normalizetext(Q_strdup(amf_tracker_name_prefixes.string));
	prefix = strtok(prefixes, " ");
	name = Q_normalizetext(Q_strdup(cl.players[player].name));

	if (prefix == NULL)  {
		// no prefixes defined by the user, search all players and remove the commont prefix
		size_t i;
		int j;
		unsigned players_left;

		players_left = 0xFFFF;
		players_left &= ~(1 << player);

		for (i = 0; i < strlen(cl.players[player].name); i++) {
			for (j = 0; j < MAX_CLIENTS; j++) {
				if ((players_left & (1 << j)) == 0)
					continue;
				if (cl.players[j].spectator)
					players_left &= ~(1 << j);
				if (strlen(cl.players[j].name) < i + 1 || cl.players[j].name[i] != cl.players[player].name[i])
					players_left &= ~(1 << j);
			}
			if (players_left == 0)
				break;
		}

		skip = i;

		if (skip == strlen(cl.players[player].name))
			skip = 0;
	} else {
		while (prefix != NULL) {
			if (strlen(name) > strlen(prefix) && strncasecmp(prefix, name, strlen(prefix)) == 0) {
				if (strlen(prefix) > skip)
					skip = strlen(prefix);
			}
			prefix = strtok(NULL, " ");
		}
	}

	Q_free(prefixes);
	Q_free(name);

	return cl.players[player].name + skip;
}
Example #8
0
File: cmd.c Project: matatk/agrip
/*
===============
Cmd_Alias_f

Creates a new command that executes a command string (possibly ; separated)
===============
*/
void Cmd_Alias_f (void)
{
	cmd_alias_t	*a;
	int			key;
	char		*name;

	if (Cmd_Argc() == 1)
	{
		Com_Printf ("alias <name> <command> : create or modify an alias\n");
		Com_Printf ("aliaslist : list all aliases\n");
		return;
	}

	name = Cmd_Argv(1);

	// see if there's already an alias by that name
	a = Cmd_FindAlias(name);

	if (a) {
		// reuse it
		Q_free (a->name);
		Q_free (a->value);
	}
	else {
		// allocate a new one
		a = Q_malloc (sizeof(cmd_alias_t));
		a->flags = 0;

		// link it in
		a->next = cmd_alias;
		cmd_alias = a;
		key = Com_HashKey(name);
		a->hash_next = cmd_alias_hash[key];
		cmd_alias_hash[key] = a;
	}

	a->name = Q_strdup(name);
	a->value = Q_strdup(Cmd_MakeArgs(2));	// copy the rest of the command line

#ifndef SERVERONLY
	if (cbuf_current == &cbuf_svc)
		a->flags |= ALIAS_STUFFED;
	else
		a->flags &= ALIAS_STUFFED;
#endif

	if (!Q_stricmp(Cmd_Argv(0), "aliasa"))
		a->flags |= ALIAS_ARCHIVE;

}
Example #9
0
// load document by url
void CPageViewer_GoUrl(CPageViewer_t *viewer, char *url)
{
    AddPage(viewer);

    viewer->page->url = Q_strdup(url);
    viewer->page->should_render = true;
}
Example #10
0
void SYSINFO_Init(void)
{
	// TODO: disconnect --> f_system for MacOSX (man sysctl)
	// VVD: Look at code for FreeBSD: 30 lines down. :-)
#ifdef GLQUAKE
	{
		extern const char *gl_renderer;

		if (gl_renderer  &&  gl_renderer[0])
			SYSINFO_3D_description = Q_strdup(gl_renderer);
	}
#endif

	snprintf(f_system_string, sizeof(f_system_string), "%dMB", (int)(SYSINFO_memory / 1024. / 1024. + .5));

	if (SYSINFO_processor_description) {
		strlcat(f_system_string, ", ", sizeof(f_system_string));
		strlcat(f_system_string, SYSINFO_processor_description, sizeof(f_system_string));
	}
	if (SYSINFO_MHz) {
		strlcat(f_system_string, va(" %dMHz", SYSINFO_MHz), sizeof(f_system_string));
	}
	if (SYSINFO_3D_description) {
		strlcat(f_system_string, ", ", sizeof(f_system_string));
		strlcat(f_system_string, SYSINFO_3D_description, sizeof(f_system_string));
	}
}
Example #11
0
qbool Util_F_Match (const char *_msg, char *f_request) {
	int offset, i, status, flags;
	char *s, *msg;

	msg = Q_strdup(_msg);
	flags = TP_CategorizeMessage(msg, &offset);

	if (flags != 1 && flags != 4)
		return false;

	for (i = 0, s = msg + offset; i < strlen(s); i++)
		s[i] = s[i] & ~128;		

	if (strstr(s, f_request) != s) {
		Q_free(msg);
		return false;
	}
	status = 0;
	for (s += strlen(f_request); *s; s++) {
		if (isdigit(*s) && status <= 1) {
			status = 1;
		} else if (isspace(*s)) {
			status = (status == 1) ? 2 : status;
		} else {
			Q_free(msg);			
			return false;
		}
	}
	Q_free(msg);
	return true;
}
Example #12
0
// 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;
}
Example #13
0
// load document by xml_document_t
void CPageViewer_Go(CPageViewer_t *viewer, char *url, xml_document_t *doc)
{
    AddPage(viewer);

    viewer->page->url = Q_strdup(url);
    viewer->page->doc = doc;
    viewer->page->should_render = true;
}
Example #14
0
// 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;
}
Example #15
0
void COM_StoreOriginalCmdline (int argc, char **argv)
{
	char buf[4096]; // enough?
	int i;

	buf[0] = 0;
	strlcat (buf, " ", sizeof (buf));

	for (i=0; i < argc; i++)
		strlcat (buf, argv[i], sizeof (buf));

	com_args_original = Q_strdup (buf);
}
Example #16
0
void SYSINFO_Init(void)
{
	int mib[2];
	mib[0] = CTL_HW;
	mib[1] = HW_MEMSIZE;
	int64_t memsize_value;
	int cpu_frequency_value;
	size_t length = sizeof(memsize_value);
	char cpu_brand_string[100] = {0};
	size_t cpu_brand_string_len = sizeof(cpu_brand_string) - 1; /* Don't trust Apple, make sure its NULL terminated */

	extern const char *gl_renderer;

	if (sysctl(mib, 2, &memsize_value, &length, NULL, 0) != -1) {
		SYSINFO_memory = memsize_value;
	}

	if (sysctlbyname("machdep.cpu.brand_string", &cpu_brand_string, &cpu_brand_string_len, NULL, 0) != -1) {
		SYSINFO_processor_description = cpu_brand_string;
	}

	mib[0] = CTL_HW;
	mib[1] = HW_CPU_FREQ;
	length = sizeof(cpu_frequency_value);
	if (sysctl(mib, 2, &cpu_frequency_value, &length, NULL, 0) != -1) {
		SYSINFO_MHz = cpu_frequency_value / 1000. / 1000. + .5;
	}


	if (gl_renderer && gl_renderer[0]) {
		if (SYSINFO_3D_description != NULL) {
			free(SYSINFO_3D_description);
		}
		SYSINFO_3D_description = Q_strdup(gl_renderer);
	}

	snprintf(f_system_string, sizeof(f_system_string), "%dMB", (int)(SYSINFO_memory / 1024. / 1024. + .5));

	if (SYSINFO_processor_description) {
		strlcat(f_system_string, ", ", sizeof(f_system_string));
		strlcat(f_system_string, SYSINFO_processor_description, sizeof(f_system_string));
	}
	if (SYSINFO_MHz) {
		strlcat(f_system_string, va(" %dMHz", SYSINFO_MHz), sizeof(f_system_string));
	}
	if (SYSINFO_3D_description) {
		strlcat(f_system_string, ", ", sizeof(f_system_string));
		strlcat(f_system_string, SYSINFO_3D_description, sizeof(f_system_string));
	}
}
Example #17
0
// convert to xml_document_t
xml_document_t * XSD_Variable_Convert(xml_t *doc)
{
    xml_document_t *ret;
    xml_variable_t *var = (xml_variable_t *) doc;

    ret = XSD_Document_New();

    // make head
    ret->title = Q_strdup(var->name);

    // make body
    {
        document_tag_text_t *text;

        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(var->description);
        ret->content = (document_tag_t *) text;
    }

    return ret;
}
Example #18
0
void Cvar_SetDefault(cvar_t *var, float value)
{
	char val[128];
	int i;

	snprintf (val, sizeof(val), "%f", value);
	for (i = strlen(val) - 1; i > 0 && val[i] == '0'; i--)
		val[i] = 0;
	if (val[i] == '.')
		val[i] = 0;
	Q_free(var->defaultvalue);
	var->defaultvalue = Q_strdup(val);
	Cvar_Set(var, val);
}
Example #19
0
// strip spaces from inline text, making links working
char * StripInlineSpaces(char *str, document_rendered_link_t *links)
{
    int cut = 0;

    char *buf, *ret;
    int p=0, q=0;

    if (str == NULL)
        return str;

    buf = (char *) Q_malloc(strlen(str)+1);
    for (p=0; p < strlen(str); p++)
    {
        // offset links
        document_rendered_link_t *l = links;
        while (l)
        {
            if (l->start == p)
                l->start -= cut;
            if (l->end == p)
                l->end -= cut;

            l = l->next;
        }

        if (XSD_IsSpace(str[p]))
        {
            if (q == 0  ||  XSD_IsSpace(buf[q-1]))
                cut++;
            else
            {
                // add this char, but replace with pure space
                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;
}
Example #20
0
File: cvar.cpp Project: luaman/zq
/*
============
Cvar_Set
============
*/
void Cvar_Set (cvar_t *var, const char *string)
{
	static qbool changing = false;

	if (!var)
		return;

	if (var->flags & CVAR_ROM)
	{
		Com_Printf ("\"%s\" is write protected\n", var->name);
		return;
	}

	if ((var->flags & CVAR_INIT) && host_initialized)
	{
		//if (cl_warncmd.value)
		//	Com_Printf ("\"%s\" cannot be changed from the console\n", var->name);
		return;
	}

	if (var->OnChange && !changing) {
		qbool cancel = false;
		changing = true;
		var->OnChange(var, (char *)string, &cancel);
		changing = false;
		if (cancel)
			return;
	}

	// FIXME, avoid reallocation if the new string has same size?

	Q_free (var->string);
	var->string = Q_strdup (string);

	var->value = Q_atof (var->string);

#ifndef CLIENTONLY
	if (var->flags & CVAR_SERVERINFO)
		SV_ServerinfoChanged (var->name, var->string);
#endif

#ifndef SERVERONLY
	if (var->flags & CVAR_USERINFO)
		CL_UserinfoChanged (var->name, var->string);
#endif
}
Example #21
0
// renders inline chain, stops at first non-inline tag and returns this tag
static document_tag_t * RenderInlineChain(document_rendering_context_t *cx, document_tag_t *tag)
{
    char *text = Q_strdup("");

    while (tag && !IsBlockElement(tag))
    {
        text = Add_Inline_Tag(cx, text, tag);

        tag = tag->next;
    }

    text = StripInlineSpaces(text, cx->inline_links);
    Render_String(cx, text);
    LineFeed(cx);

    Q_free(text);

    return tag;
}
Example #22
0
static log_upload_job_t* Log_Upload_Job_Prepare(const char *filename, const char *hostname, const char* player_name,
                                                const char *token, const char *url, const char *mapname)
{
	log_upload_job_t *job = (log_upload_job_t *) Q_malloc(sizeof(log_upload_job_t));

	job->filename = Q_strdup(filename);
	job->hostname = Q_strdup(hostname);
	job->player_name = Q_strdup(player_name);
	job->token = Q_strdup(token);
	job->url = Q_strdup(url);
	job->mapname = Q_strdup(mapname);

	return job;
}
Example #23
0
static void OnStartElement(void *userData, const XML_Char *name, const XML_Char **atts)
{
    xml_parser_stack_t *stack = (xml_parser_stack_t *) userData;
    xml_variable_t *document = (xml_variable_t *) stack->document;

    if (stack->path[0] == 0)
        document->document_type = Q_strdup(name);

    if (!strcmp(stack->path, "/variable/value"))
    {
        if (!strcmp(name, "string"))
            document->value_type = t_string;
        if (!strcmp(name, "integer"))
            document->value_type = t_integer;
        if (!strcmp(name, "float"))
            document->value_type = t_float;
        if (!strcmp(name, "boolean"))
            document->value_type = t_boolean;
        if (!strcmp(name, "enum"))
            document->value_type = t_enum;
    }
    if (!strcmp(stack->path, "/variable/value/enum"))
    {
        // create new enum
        variable_enum_value_t *val = (variable_enum_value_t *) Q_malloc(sizeof(variable_enum_value_t));
        memset(val, 0, sizeof(variable_enum_value_t));

        if (document->value.enum_value == NULL)
            document->value.enum_value = val;
        else
        {
            variable_enum_value_t *prev = document->value.enum_value;
            while (prev->next)
                prev = prev->next;
            prev->next = val;
        }
    }

    XSD_OnStartElement(stack, name, atts);
}
Example #24
0
void Cvar_SetEx(cvar_t *var, char *value, qbool ignore_callback)
{
	extern cvar_t cl_warncmd;
	extern cvar_t re_subi[10];
	static qbool changing = false;
	float test;
	char *new_val;

	if (!var)
		return;

	// C code may wrongly use Cvar_Set on non registered variable, some 99.99% accurate check
	// variables for internal triggers are not registered intentionally
	if (var < re_subi || var > re_subi + 9) {
		if (!var->next /* this is fast, but a bit flawed logic */ && !Cvar_Find(var->name)) {
			Com_Printf("Cvar_Set: on non linked var %s\n", var->name);
			return;
		}
	}

	if (var->flags & CVAR_ROM) {
		Com_Printf ("\"%s\" is write protected\n", var->name);
		return;
	}

	if (var->flags & CVAR_RULESET_MIN) {
		test  = Q_atof (value);
		if (test < var->minrulesetvalue) {
			Com_Printf ("min \"%s\" is limited to %0.2f\n", var->name,var->minrulesetvalue);
			return;
		}
	}

	if (var->flags & CVAR_RULESET_MAX) {
		test  = Q_atof (value);
		if (test > var->maxrulesetvalue) {
			Com_Printf ("max \"%s\" is limited to %0.2f\n", var->name,var->maxrulesetvalue);
			return;
		}
	}

	if ((var->flags & CVAR_INIT) && host_initialized) {
		if (cl_warncmd.value || developer.value)
			Com_Printf ("\"%s\" can only be changed with \"+set %s %s\" on the command line.\n", var->name, var->name, value);
		return;
	}

	// We do this before OnChange check, which means no OnChange check for latched cvars.
	if (var->flags & CVAR_LATCH)
	{
		if (var->latchedString)
		{
			if (strcmp(value, var->latchedString) == 0)
				return; // latched string alredy has this value
			Q_free(var->latchedString); // switching latching string to other, so free it
		}
		else
		{
			if (strcmp(value, var->string) == 0)
				return; // we change string value to the same, do no create latched string then
		}

		// HACK: sometime I need somehow silently change latched cvars.
		//       So, flag CVAR_SILENT for latched cvars mean no this warning.
		//       However keep this flag always on latched variable is stupid imo.
		//       So, do not mix CVAR_LATCHED | CVAR_SILENT in cvar definition.
		if ( !(var->flags & CVAR_SILENT) ) {
			const char* restartcmd = "vid_restart (video/graphics)";
			if (strncmp(var->name, "in_", 3) == 0) {
				restartcmd = "in_restart (input)";
			}
			else if (strncmp(var->name, "s_", 2) == 0) {
				restartcmd = "s_restart (sound)";
			}
			Com_Printf ("%s needs %s to take effect.\n", var->name, restartcmd);
		}
		var->latchedString = Q_strdup(value);
		var->modified = true; // set to true even car->string is not changed yet, that how q3 does
		return;
	}

	if (!ignore_callback && var->OnChange && !changing) {
		qbool cancel = false;
		changing = true;
		var->OnChange(var, value, &cancel);
		changing = false;
		if (cancel)
			return;
	}

	// dup string first (before free) since 'value' and 'var->string' can point at the same memory area.
	new_val = Q_strdup(value);
	// free the old value string.
	Q_free(var->string);

	var->string = new_val;
	var->value = Q_atof (var->string);
	var->integer = Q_atoi (var->string);
	StringToRGB_W(var->string, var->color);
	Cvar_AutoReset(var);
	var->modified = true;

#ifndef CLIENTONLY
	if (var->flags & CVAR_SERVERINFO)
		SV_ServerinfoChanged (var->name, var->string);
#endif

	if (var->flags & CVAR_USERINFO)
		CL_UserinfoChanged (var->name, var->string);
}
Example #25
0
// ================
// WINAMP_ParsePlaylist_EXTM3U
// ================
// An M3U playlist format is below
//
// #EXTM3U
// 
// #EXTINF:123,Sample title
// C:\Documents and Settings\I\My Music\Sample.mp3
// 
// #EXTINF:321,Example title
// C:\Documents and Settings\I\My Music\Greatest Hits\Example.ogg
//
int WINAMP_ParsePlaylist_EXTM3U(char *playlist_buf, unsigned int length,
								char **playlist, int playlist_nelms) { 
	int skip = 0; 
	char *s, *t, *buf, *line;
	int playlist_size = 0;

	buf = playlist_buf;
	while (playlist_size < playlist_nelms) {
		// Find the first newline
		for (s = line = buf; s - playlist_buf < length && *s && *s != '\n' && *s != '\r'; s++)
			;
		// We have parsed the whole buffer
		if (s - playlist_buf >= length)
			break;

		// Change the line break to the end of the string
		*s = 0;

		// Buf now points to the next line
		// D-Kure: FIXME: 2 seems a little random, 1 for over the NULL
		//                the 2nd may be because windows gives "\r\n"
		buf = s + 2;

		// Ignore the intial #EXTM3U
		if (skip || !strncmp(line, "#EXTM3U", 7)) 
		{
			skip = 0;
			continue;
		}
		// Parse the line starting with #EXTINF
		else if (!strncmp(line, "#EXTINF:", 8)) 
		{
			if (!(s = strstr(line, ",")) || ++s - playlist_buf >= length) 
				break;

			skip = 1; // Skip the next line that contains the path to this song
		} 
		// No #EXTINF was given, instead parse the filename
		else
		{
			// Search from the end of string for the first directory marker
			for (s = line + strlen(line); s > line && *s != '\\' && *s != '/'; s--)
				;
			if (s != line) // If a directory marker was found skip it
				s++;

			// Ignore extensions
			if ((t = strrchr(s, '.')) && t - playlist_buf < length)
				*t = 0;		

			// Ignore trailing spaces
			for (t = s + strlen(s) - 1; t > s && *t == ' '; t--)
				*t = 0;
		}
		
		// D-Kure: There was a check here to limit the length of s, it seemed 
		//         unnessacary
		playlist[playlist_size++] = Q_strdup(s);
	}

	return playlist_size;
}
Example #26
0
void SYSINFO_Init(void)
{
	char cpu_model[256];

	int mib[2], val;
	unsigned long val_ul;
	size_t len;

#ifdef id386
	unsigned long long old_tsc, tsc_freq;
	struct timeval tp, old_tp;
#endif

	mib[0] = CTL_HW;
	mib[1] =
#if __FreeBSD_version >= 500000
		HW_REALMEM;
#else
		HW_PHYSMEM;
#endif
// VVD: We can use HW_REALMEM (hw.realmem) for RELENG_5/6/7 for getting exact result,
// but RELENG_4 have only HW_PHYSMEM (hw.physmem).
	len = sizeof(val);
	sysctl(mib, sizeof(mib) / sizeof(mib[0]), &val_ul, &len, NULL, 0);

	SYSINFO_memory = val_ul;

	mib[0] = CTL_HW;
	mib[1] = HW_MODEL;
	len = sizeof(cpu_model);
	sysctl(mib, sizeof(mib) / sizeof(mib[0]), cpu_model, &len, NULL, 0);
	cpu_model[sizeof(cpu_model) - 1] = '\0';

	SYSINFO_processor_description = cpu_model;

#ifdef id386
	gettimeofday(&old_tp, NULL);
	old_tsc = rdtsc();
	do {
		gettimeofday(&tp, NULL);
	} while ((tp.tv_sec - old_tp.tv_sec) * 1000000. + tp.tv_usec - old_tp.tv_usec < 1000000.);
	tsc_freq = rdtsc();
	SYSINFO_MHz = (int)((tsc_freq - old_tsc) /
						(tp.tv_sec - old_tp.tv_sec + (tp.tv_usec - old_tp.tv_usec) / 1000000.) /
						1000000. + .5);
// VVD: We can use sysctl hw.clockrate, but it don't work on i486 - always 0.
// Must work on Pentium 1/2/3; tested on Pentium 4. And RELENG_4 have no this sysctl.
#endif

#ifdef GLQUAKE
	{
		extern const char *gl_renderer;

		if (gl_renderer  &&  gl_renderer[0])
			SYSINFO_3D_description = Q_strdup(gl_renderer);
	}
#endif

	snprintf(f_system_string, sizeof(f_system_string), "%dMB", (int)(SYSINFO_memory / 1024. / 1024. + .5));

	if (SYSINFO_processor_description) {
		strlcat(f_system_string, ", ", sizeof(f_system_string));
		strlcat(f_system_string, SYSINFO_processor_description, sizeof(f_system_string));
	}
	if (SYSINFO_MHz) {
		strlcat(f_system_string, va(" (%dMHz)", SYSINFO_MHz), sizeof(f_system_string));
	}
	if (SYSINFO_3D_description) {
		strlcat(f_system_string, ", ", sizeof(f_system_string));
		strlcat(f_system_string, SYSINFO_3D_description, sizeof(f_system_string));
	}
}
Example #27
0
/*
Adds a freestanding variable to the variable list.

If the variable already exists, the value will not be set
The flags will be or'ed in if the variable exists.
*/
void Cvar_Register (cvar_t *var)
{
	char string[512];
	int key;
	cvar_t *old;

	// first check to see if it has already been defined
	old = Cvar_Find (var->name);

	// we alredy register cvar, warn about it
	if (old && !(old->flags & CVAR_USER_CREATED))
	{
		// allow re-register lacthed cvar
		if (old->flags & CVAR_LATCH)
		{
			// if we have a latched string, take that value now
			if ( old->latchedString )
			{
				// I did't want bother with all this CVAR_ROM and OnChange handler, just set value
				Q_free(old->string);
				old->string  = old->latchedString;
				old->latchedString = NULL;
				old->value   = Q_atof (old->string);
				old->integer = Q_atoi (old->string);
				StringToRGB_W(old->string, old->color);
				old->modified = true;
			}
			Cvar_AutoReset(old);

			return;
		}

		// warn if CVAR_SILENT is not set
		if (!(old->flags & CVAR_SILENT))
			Com_Printf ("Can't register variable %s, already defined\n", var->name);

		return;
	}

	if (old && old == var)
		Sys_Error("Cvar_Register: something wrong with %s", var->name);

/*	// check for overlap with a command
	if (Cmd_Exists (var->name)) {
		Com_Printf ("Cvar_Register: %s is a command\n", var->name);
		return;
	} */

	if (var->defaultvalue)
		Sys_Error("Cvar_Register: defaultvalue alredy set for %s", var->name);

	var->defaultvalue = Q_strdup(var->string);
	if (old)
	{
		var->flags |= old->flags & ~(CVAR_USER_CREATED|CVAR_TEMP);
		strlcpy (string, (var->flags & CVAR_ROM) ? var->string : old->string, sizeof(string));
		Cvar_Delete (old->name);
		var->string = Q_strdup(string);
	}
	else
	{
		// allocate the string on zone because future sets will Q_freeit
		var->string = Q_strdup(var->string);
	}
	var->value = Q_atof (var->string);
	var->integer = Q_atoi (var->string);
	StringToRGB_W(var->string, var->color);
	var->modified = true;

	// link the variable in
	key = Com_HashKey (var->name) % VAR_HASHPOOL_SIZE;
	var->hash_next = cvar_hash[key];
	cvar_hash[key] = var;
	var->next = cvar_vars;
	cvar_vars = var;

#ifdef WITH_TCL
	TCL_RegisterVariable (var);
#endif

	Cvar_AddCvarToGroup(var);

#ifndef CLIENTONLY
	if (var->flags & CVAR_SERVERINFO)
		SV_ServerinfoChanged (var->name, var->string);
#endif

	if (var->flags & CVAR_USERINFO)
		CL_UserinfoChanged (var->name, var->string);
}
Example #28
0
void SYSINFO_Init(void)
{
	LONG            ret;
	HKEY            hKey;
	PGMSE			pGMSE;

	// Get memory size.
	if ((pGMSE = (PGMSE)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GlobalMemoryStatusEx")) != NULL)
	{
		MEMORYSTATUSEX	memstat;
		memstat.dwLength = sizeof(memstat);
		pGMSE(&memstat);
		SYSINFO_memory = memstat.ullTotalPhys;
	}
	else
	{
		// Win9x doesn't have GlobalMemoryStatusEx.
		MEMORYSTATUS memstat;
		GlobalMemoryStatus(&memstat);
		SYSINFO_memory = memstat.dwTotalPhys;
	}

	// Get processor info.
	ret = RegOpenKey(
	          HKEY_LOCAL_MACHINE,
	          "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
	          &hKey);

	if (ret == ERROR_SUCCESS) 
	{
		DWORD type;
		byte  data[1024];
		DWORD datasize;

		datasize = 1024;
		ret = RegQueryValueEx(
		          hKey,
		          "~MHz",
		          NULL,
		          &type,
		          data,
		          &datasize);

		if (ret == ERROR_SUCCESS  &&  datasize > 0  &&  type == REG_DWORD)
			SYSINFO_MHz = *((DWORD *)data);

		datasize = 1024;
		ret = RegQueryValueEx(
		          hKey,
		          "ProcessorNameString",
		          NULL,
		          &type,
		          data,
		          &datasize);

		if (ret == ERROR_SUCCESS  &&  datasize > 0  &&  type == REG_SZ)
			SYSINFO_processor_description = Q_strdup((char *) data);

		RegCloseKey(hKey);
	}

	#ifdef GLQUAKE
	{
		extern const char *gl_renderer;

		if (gl_renderer  &&  gl_renderer[0])
			SYSINFO_3D_description = Q_strdup(gl_renderer);
	}
	#endif // GLQUAKE

	//
	// Create the f_system string.
	//
	
	snprintf(f_system_string, sizeof(f_system_string), "%uMiB", (unsigned)((SYSINFO_memory / (double) 1048576u)+0.5));

	if (SYSINFO_processor_description) 
	{
		strlcat(f_system_string, ", ", sizeof(f_system_string));
		strlcat(f_system_string, SYSINFO_processor_description, sizeof(f_system_string));
	}

	if (SYSINFO_MHz) 
	{
		strlcat(f_system_string, va(" %dMHz", SYSINFO_MHz), sizeof(f_system_string));
	}

	if (SYSINFO_3D_description) 
	{
		strlcat(f_system_string, ", ", sizeof(f_system_string));
		strlcat(f_system_string, SYSINFO_3D_description, sizeof(f_system_string));
	}
}
Example #29
0
void Cmd_Alias_f (void)
{
	cmd_alias_t	*a;
	char		cmd[1024];
	int			i, c;
	int			key;
	char		*s;
	//	cvar_t		*var;

	c = Cmd_Argc();
	if (c == 1)
	{
		Con_Printf ("Current alias commands:\n");
		for (a = cmd_alias ; a ; a=a->next)
			Con_Printf ("%s : %s\n\n", a->name, a->value);
		return;
	}

	s = Cmd_Argv(1);
	if (strlen(s) >= MAX_ALIAS_NAME)
	{
		Con_Printf ("Alias name is too long\n");
		return;
	}

#if 0
	if ( (var = Cvar_Find(s)) != NULL )
	{
		if (var->flags & CVAR_USER_CREATED)
			Cvar_Delete (var->name);
		else
		{
			//			Con_Printf ("%s is a variable\n");
			return;
		}
	}
#endif

	key = Com_HashKey (s);

	// if the alias already exists, reuse it
	for (a = cmd_alias_hash[key] ; a ; a=a->hash_next)
	{
		if (!strcasecmp(a->name, s))
		{
			Q_free (a->value);
			break;
		}
	}

	if (!a)
	{
		a = (cmd_alias_t*) Q_malloc (sizeof(cmd_alias_t));
		a->next = cmd_alias;
		cmd_alias = a;
		a->hash_next = cmd_alias_hash[key];
		cmd_alias_hash[key] = a;
	}
	strlcpy (a->name, s, MAX_ALIAS_NAME);

	// copy the rest of the command line
	cmd[0] = 0;		// start out with a null string
	for (i=2 ; i<c ; i++)
	{
		if (i > 2)
			strlcat (cmd, " ", sizeof(cmd));
		strlcat (cmd, Cmd_Argv(i), sizeof(cmd));
	}

	a->value = Q_strdup (cmd);
}
Example #30
0
void SYSINFO_Init(void)
{
	// disconnect: which way is best(MEM/CPU-MHZ/CPU-MODEL)?
	f_system_string[0] = 0;
	char buffer[1024];
	char cpu_model[255];
	char *match;
	FILE *f;

	// MEM
	f = fopen("/proc/meminfo", "r");
	if (f) {
		if (fscanf (f, "%*s %llu %*s\n", &SYSINFO_memory) != 1) {
			Com_Printf ("could not read /proc/meminfo!\n");
		} else {
			SYSINFO_memory /= 1024;
		}
		fclose (f);
	} else {
		Com_Printf ("could not open /proc/meminfo!\n");
		SYSINFO_memory = 0;
	}

	//CPU-MHZ
	f = fopen("/proc/cpuinfo", "r");
	if (f) {
		buffer[fread (buffer, 1, sizeof(buffer) - 1, f)] = '\0';
		fclose (f);
		match = strstr (buffer, "cpu MHz");
		sscanf (match, "cpu MHz : %i", &SYSINFO_MHz);
	} else {
		Com_Printf ("could not open /proc/cpuinfo!\n");
	}

	//CPU-MODEL
	f = fopen("/proc/cpuinfo", "r");
	if (f) {
		while (!feof(f)) {
			if (fgets (buffer, sizeof(buffer), f) == NULL && !feof(f)) {	// disconnect: sizeof(buffer) - 1 ?
				Com_Printf("Error reading /proc/cpuinfo\n");
				break;
			}
			if (!strncmp( buffer, "model name", 10)) {
				match = strchr( buffer, ':' );
				match++;
				while (isspace(*match)) match++;
				memcpy(cpu_model, match, sizeof(cpu_model));
				cpu_model[strlen(cpu_model) - 1] = '\0';
				SYSINFO_processor_description= Q_strdup (cpu_model);
				break;
			}
		}
		fclose(f);	
	} else {
		Com_Printf("could not open /proc/cpuinfo!\n");
	}

#ifdef GLQUAKE
	{
		extern const char *gl_renderer;

		if (gl_renderer  &&  gl_renderer[0])
			SYSINFO_3D_description = Q_strdup(gl_renderer);
	}
#endif

	snprintf(f_system_string, sizeof(f_system_string), "%dMB", (int)(SYSINFO_memory));

	if (SYSINFO_processor_description) {
		strlcat(f_system_string, ", ", sizeof(f_system_string));
		strlcat(f_system_string, SYSINFO_processor_description, sizeof(f_system_string));
	}
	if (SYSINFO_MHz) {
		strlcat(f_system_string, va(" %dMHz", SYSINFO_MHz), sizeof(f_system_string));
	}
	if (SYSINFO_3D_description) {
		strlcat(f_system_string, ", ", sizeof(f_system_string));
		strlcat(f_system_string, SYSINFO_3D_description, sizeof(f_system_string));
	}
}