Exemplo n.º 1
0
svariable_t *new_variable(script_t *script, char *name, int vtype)
{
  int n;
  svariable_t *newvar;
  int tagtype =
    script==&global_script || script==&hub_script ? PU_STATIC : PU_LEVEL;
  
  // find an empty slot first

  newvar = Z_Malloc(sizeof(svariable_t), tagtype, 0);
  newvar->name = (char*)Z_Strdup(name, tagtype, 0);
  newvar->type = vtype;
  
  if(vtype == svt_string)
    {
      // 128 bytes for string
      newvar->value.s = Z_Malloc(128, tagtype, 0);
      newvar->value.s[0] = 0;
    }
  else
    newvar->value.i = 0;
  
  // now hook it into the hashchain
  
  n = variable_hash(name);
  newvar->next = script->variables[n];
  script->variables[n] = newvar;
  
  return script->variables[n];
}
Exemplo n.º 2
0
// create a new variable in a particular script.
// returns a pointer to the new variable.
svariable_t *script_t::new_variable(const char *name, int vtype)
{
  int tagtype = (this == &global_script || this == &hub_script) ? PU_STATIC : PU_LEVEL;
  
  // find an empty slot first
  svariable_t *newvar = (svariable_t *)Z_Malloc(sizeof(svariable_t), tagtype, 0);
  newvar->name = (char *)Z_Strdup(name, tagtype, 0);
  newvar->type = vtype;
  
  if (vtype == svt_string)
    {
      // 256 bytes for string
      newvar->value.s = (char *)Z_Malloc(256, tagtype, 0);
      newvar->value.s[0] = 0;
    }
  else
    newvar->value.i = 0;
  
  // now hook it into the hashchain  
  int n = variable_hash(name);
  newvar->next = variables[n];
  variables[n] = newvar;
  
  return newvar;
}
Exemplo n.º 3
0
/*
 * variable_add()
 *
 * dodaje zmienn± do listy zmiennych.
 *
 *  - plugin - opis wtyczki, która obs³uguje zmienn±,
 *  - name - nazwa,
 *  - type - typ zmiennej,
 *  - display - czy i jak ma wy¶wietlaæ,
 *  - ptr - wska¼nik do zmiennej,
 *  - notify - funkcja powiadomienia,
 *  - map - mapa warto¶ci,
 *  - dyndisplay - funkcja sprawdzaj±ca czy wy¶wietliæ zmienn±.
 *
 * zwraca 0 je¶li siê nie uda³o, w przeciwnym wypadku adres do strutury.
 */
variable_t *variable_add(plugin_t *plugin, const char *name, int type, int display, void *ptr, variable_notify_func_t *notify, variable_map_t *map, variable_display_func_t *dyndisplay) {
	variable_t *v;
	char *__name;

	if (!name)
		return NULL;

	if (plugin && !xstrchr(name, ':'))
		__name = saprintf("%s:%s", plugin->name, name);
	else
		__name = xstrdup(name);

	v = xmalloc(sizeof(variable_t));
	v->name		= __name;
	v->name_hash	= variable_hash(__name);
	v->type		= type;
	v->display	= display;
	v->ptr		= ptr;
	v->notify	= notify;
	v->map		= map;
	v->dyndisplay	= dyndisplay;
	v->plugin	= plugin;

	variables_add(v);
	return v;
}
Exemplo n.º 4
0
DFsVariable *DFsScript::NewVariable(const char *name, int vtype)
{
	DFsVariable *newvar = Create<DFsVariable>(name);
	newvar->type = vtype;
	
	int n = variable_hash(name);
	newvar->next = variables[n];
	variables[n] = newvar;
	GC::WriteBarrier(this, newvar);
	return newvar;
}
Exemplo n.º 5
0
// search a particular script for a variable, which
// is returned if it exists
svariable_t *script_t::variableforname(const char *name)
{
  svariable_t *current = variables[variable_hash(name)];
  
  while (current)
    {
      if (!strcmp(name, current->name)) // found it?
	return current;         
      current = current->next;        // check next in chain
    }
  
  return NULL;
}
Exemplo n.º 6
0
DFsVariable *DFsScript::VariableForName(const char *name)
{
	int n = variable_hash(name);
	DFsVariable *current = variables[n];
	
	while(current)
    {
		if(!strcmp(name, current->Name))        // found it?
			return current;         
		current = current->next;        // check next in chain
    }
	
	return NULL;
}
Exemplo n.º 7
0
/*
 * variable_find()
 *
 * znajduje strukturê variable_t opisuj±c± zmienn± o podanej nazwie.
 *
 * - name.
 */
variable_t *variable_find(const char *name) {
	GSList *vl;
	int hash;

	if (!name)
		return NULL;

	hash = variable_hash(name);

	for (vl = variables; vl; vl = vl->next) {
		variable_t *v = vl->data;
		if (v->name_hash == hash && !xstrcasecmp(v->name, name))
			return v;
	}

	return NULL;
}
Exemplo n.º 8
0
svariable_t *variableforname(script_t *script, char *name)
{
  int n;
  svariable_t *current;
  
  n = variable_hash(name);
  
  current = script->variables[n];
  
  while(current)
    {
      if(!strcmp(name, current->name))        // found it?
	return current;         
      current = current->next;        // check next in chain
    }
  
  return NULL;
}