示例#1
0
static void CL_RE_Trigger_Delete_f (void)
{
	pcre_trigger_t *trig, *next_trig;
	char *name;
	int i;
 
	for (i = 1; i < Cmd_Argc(); i++) {
		name = Cmd_Argv(i);
		if (IsRegexp(name)) {
			if(!ReSearchInit(name))
				return;
			prev = NULL;
			for (trig = re_triggers; trig; ) {
				if (ReSearchMatch (trig->name)) {
					next_trig = trig->next;
					RemoveReTrigger(trig);
					trig = next_trig;
				} else {
					prev = trig;
					trig = trig->next;
				}
			}
			ReSearchDone();
		} else {
			if ((trig = CL_FindReTrigger(name)))
				RemoveReTrigger(trig);
		}
	}
}
示例#2
0
static void Trig_ReSearch_do (ReTrigger_func f)
{
	pcre_trigger_t *trig;
 
	for( trig = re_triggers; trig; trig = trig->next) {
		if (ReSearchMatch (trig->name))
			f (trig);
	}
}
示例#3
0
// disconnect -->
void Cvar_UnSet (qbool use_regex)
{
	cvar_t	*var, *next;
	char	*name;
	int		i;
	qbool	re_search = false;


	if (Cmd_Argc() < 2) {
		Com_Printf ("unset <cvar> [<cvar2>..]: erase user-created variable\n");
		return;
	}

	for (i=1; i<Cmd_Argc(); i++) {
		name = Cmd_Argv(i);

		if (use_regex && (re_search = IsRegexp(name)))
			if(!ReSearchInit(name))
				continue;

		if (use_regex && re_search) {
			for (var = cvar_vars ; var ; var = next) {
				next = var->next;

				if (ReSearchMatch(var->name)) {
					if (var->flags & CVAR_USER_CREATED) {
						Cvar_Delete(var->name);
					} else {
						Com_Printf("Can't delete not user created cvars (\"%s\")\n", var->name);
					}
				}
			}
		} else {
			if (!(var = Cvar_Find(name))) {
				Com_Printf("Can't delete \"%s\": no such cvar\n", name);
				continue;
			}

			if (var->flags & CVAR_USER_CREATED) {
				Cvar_Delete(name);
			} else {
				Com_Printf("Can't delete not user created cvars (\"%s\")\n", name);
			}
		}
		if (use_regex && re_search)
			ReSearchDone();
	}
}
示例#4
0
void Cvar_CvarList (qbool use_regex)
{
	static cvar_t *sorted_cvars[4096];
	int i, c, m = 0, count;
	cvar_t *var;
	char *pattern;

#define MAX_SORTED_CVARS (sizeof (sorted_cvars) / sizeof (sorted_cvars[0]))

	for (var = cvar_vars, count = 0; var && count < MAX_SORTED_CVARS; var = var->next, count++)
		sorted_cvars[count] = var;
	qsort (sorted_cvars, count, sizeof (cvar_t *), Cvar_CvarCompare);

	if (count == MAX_SORTED_CVARS)
		assert(!"count == MAX_SORTED_CVARS");

	pattern = (Cmd_Argc() > 1) ? Cmd_Argv(1) : NULL;

	if (((c = Cmd_Argc()) > 1) && use_regex)
		if (!ReSearchInit(Cmd_Argv(1)))
			return;

	Com_Printf ("List of cvars:\n");
	for (i = 0; i < count; i++) {
		var = sorted_cvars[i];
		if (use_regex) {
			if (!(c == 1 || ReSearchMatch (var->name)))
				continue;
		} else {
			if (pattern && !Q_glob_match (pattern, var->name))
				continue;
		}

		Com_Printf ("%c%c %s\n",
			var->flags & CVAR_USERINFO ? 'u' : ' ',
			var->flags & CVAR_SERVERINFO ? 's' : ' ',
			var->name);
		m++;
	}
	
	if (use_regex && (c > 1))
		ReSearchDone ();

	Com_Printf ("------------\n%i/%i %svariables\n", m, count, (pattern) ? "matching " : "");
}
示例#5
0
static void Cvar_Toggle_f_base (qbool use_regex)
{
	qbool re_search = false;
	cvar_t *var;
	char *name;
	int i;


	if (Cmd_Argc() < 2) {
		Com_Printf("%s <cvar> [<cvar>..]: toggle a cvar on/off\n", Cmd_Argv(0));
		return;
	}

	for (i=1; i<Cmd_Argc(); i++) {
		name = Cmd_Argv(i);

		if (use_regex && (re_search = IsRegexp(name)))
			if(!ReSearchInit(name))
				continue;

		if (use_regex && re_search) {
			for (var = cvar_vars ; var ; var=var->next) {
				if (ReSearchMatch(var->name)) {
					Cvar_Set (var, var->value ? "0" : "1");
				}
			}
		} else {
			var = Cvar_Find (name);

			if (!(var)) {
				Com_Printf ("Unknown variable \"%s\"\n", Cmd_Argv(1));
				continue;
			}
			Cvar_Set (var, var->value ? "0" : "1");
		}
		if (use_regex && re_search)
			ReSearchDone();
	}
}
示例#6
0
void Cvar_Reset (qbool use_regex)
{
	qbool re_search = false;
	cvar_t *var;
	char *name;
	int i;


	if (Cmd_Argc() < 2) {
		Com_Printf("%s <cvar> [<cvar2>..]: reset variable to it default value\n", Cmd_Argv(0));
		return;
	}

	for (i=1; i<Cmd_Argc(); i++) {
		name = Cmd_Argv(i);

		if (use_regex && (re_search = IsRegexp(name)))
			if(!ReSearchInit(name))
				continue;

		if (use_regex && re_search) {
			for (var = cvar_vars ; var ; var=var->next) {
				if (ReSearchMatch(var->name)) {
					Cvar_ResetVar(var);
				}
			}
		} else {
			if ((var = Cvar_Find(name)))
				Cvar_ResetVar(var);
			else
				Com_Printf("%s : No variable with name %s\n", Cmd_Argv(0), name);
		}
		if (use_regex && re_search)
			ReSearchDone();
	}
}
示例#7
0
static void CL_RE_Trigger_f (void)
{
	int c,i,m;
	char *name;
	char *regexpstr;
	pcre_trigger_t *trig;
	pcre *re;
	pcre_extra *re_extra;
	const char *error;
	int error_offset;
	qbool newtrigger=false;
	qbool re_search = false;
 
	c = Cmd_Argc();
	if (c > 3) {
		Com_Printf ("re_trigger <trigger name> <regexp>\n");
		return;
	}
 
	if (c == 2 && IsRegexp(Cmd_Argv(1))) {
		re_search = true;
	}
 
	if (c == 1 || re_search) {
		if (!re_triggers) {
			Com_Printf ("no regexp_triggers defined\n");
		} else {
			if (re_search && !ReSearchInit(Cmd_Argv(1)))
				return;
 
			Com_Printf ("List of re_triggers:\n");
 
			for (trig=re_triggers, i=m=0; trig; trig=trig->next, i++) {
				if (!re_search || ReSearchMatch(trig->name)) {
					Com_Printf ("%s : \"%s\" : %d\n", trig->name, trig->regexpstr, trig->counter);
					m++;
				}
			}
 
			Com_Printf ("------------\n%i/%i re_triggers\n", m, i);
			if (re_search)
				ReSearchDone();
		}
		return;
	}
 
	name = Cmd_Argv(1);
	trig = CL_FindReTrigger (name);
 
	if (c == 2) {
		if (trig) {
			Com_Printf ("%s: \"%s\"\n", trig->name, trig->regexpstr);
			Com_Printf ("  options: mask=%d interval=%g%s%s%s%s%s\n", trig->flags & 0xFF,
			            trig->min_interval,
			            trig->flags & RE_FINAL ? " final" : "",
			            trig->flags & RE_REMOVESTR ? " remove" : "",
			            trig->flags & RE_NOLOG ? " nolog" : "",
			            trig->flags & RE_ENABLED ? "" : " disabled",
			            trig->flags & RE_NOACTION ? " noaction" : ""
			           );
			Com_Printf ("  matched %d times\n", trig->counter);
		} else {
			Com_Printf ("re_trigger \"%s\" not found\n", name);
		}
		return;
	}
 
	if (c == 3) {
		regexpstr = Cmd_Argv(2);
		if (!trig) {
			// allocate new trigger
			newtrigger = true;
			trig = (pcre_trigger_t *) Z_Malloc (sizeof(pcre_trigger_t));
			trig->next = re_triggers;
			re_triggers = trig;
			trig->name = Z_Strdup (name);
			trig->flags = RE_PRINT_ALL | RE_ENABLED; // catch all printed messages by default
		}
 
		error = NULL;
		if ((re = pcre_compile(regexpstr, 0, &error, &error_offset, NULL))) {
			error = NULL;
			re_extra = pcre_study(re, 0, &error);
			if (error) {
				Com_Printf ("Regexp study error: %s\n", &error);
			} else {
				if (!newtrigger) {
					(pcre_free)(trig->regexp);
					if (trig->regexp_extra)
						(pcre_free)(trig->regexp_extra);
					Z_Free(trig->regexpstr);
				}
				trig->regexpstr = Z_Strdup (regexpstr);
				trig->regexp = re;
				trig->regexp_extra = re_extra;
				return;
			}
		} else {
			Com_Printf ("Invalid regexp: %s\n", error);
		}
		prev = NULL;
		RemoveReTrigger(trig);
	}
}