Exemplo n.º 1
0
const char *aulookup_syscall(llist *l, char *buf, size_t size)
{
	const char *sys;

	if (report_format <= RPT_DEFAULT) {
		snprintf(buf, size, "%d", l->s.syscall);
		return buf;
	}
	machine = audit_elf_to_machine(l->s.arch);
	if (machine < 0)
		return Q;
	sys = audit_syscall_to_name(l->s.syscall, machine);
	if (sys) {
		const char *func = NULL;
		if (strcmp(sys, "socketcall") == 0) {
			if (list_find_item(l, AUDIT_SYSCALL))
				func = aulookup_socketcall((long)l->cur->a0);
		} else if (strcmp(sys, "ipc") == 0) {
			if(list_find_item(l, AUDIT_SYSCALL))
				func = aulookup_ipccall((long)l->cur->a0);
		}
		if (func) {
			snprintf(buf, size, "%s(%s)", sys, func);
			return buf;
		}
		return sys;
	}
	snprintf(buf, size, "%d", l->s.syscall);
	return buf;
}
Exemplo n.º 2
0
/*
 * InventoryRemoveItem:  Remove the object with the given id from the
 *   inventory display.
 */
void InventoryRemoveItem(ID id)
{
    InvItem *item;

    WindowBeginUpdate(hwndInv);

    item = (InvItem *) list_find_item(items, (void *) id, InventoryCompareIdItem);
    if (item == NULL)
    {
        debug(("Tried to remove nonexistent object %ld from inventory list", id));
        return;
    }

    items = list_delete_item(items, (void *) id, InventoryCompareIdItem);
    // Object itself freed elsewhere
    SafeFree(item);

    num_items--;
    InventoryScrollRange();
    /* See if we should remove scroll bar */
    if (num_items == rows * cols)
    {
        InventoryDisplayScrollbar();
        top_row = 0;
    }

    WindowEndUpdate(hwndInv);

    InventoryRedraw();
}
Exemplo n.º 3
0
/*
 * add_parent_classvars: Add classvars of a class's superclasses to the
 *   class's classvars.  
 *   cv_list is a list used just for holding classvars; we need a separate list
 *   to handle classvars that are overridden with properties in a parent class.
 */
void add_parent_classvars(list_type cv_list, class_type base, class_type parent)
{
   list_type cv;

   if (parent == NULL)
   {
      list_delete(cv_list);
      return;
   }

   for (cv = parent->classvars; cv != NULL; cv = cv->next)
   {
      classvar_type classvar = (classvar_type) (cv->data);
      /* Parser error recovery may have made a NULL property */
      if (classvar != NULL)
      {
	 // Increment classvar count even for classvars that are overridden by properties.
	 // Only add non-overridden classvars to symbol table, though, so that references
	 // to the name will map to the property, not the classvar.

	 if (list_find_item(cv_list, classvar->id, id_compare) == NULL)
	 {
	    cv_list = list_add_item(cv_list, classvar->id);
	    st.maxclassvars++;
	 }

	 // Insert to table will fail if property with same name is already there
	 table_insert(st.classvars, (void *) classvar->id, id_hash, id_compare);
      }
   }

   add_parent_classvars(cv_list, base, parent->superclass);
}
Exemplo n.º 4
0
expr_type make_expr_from_id(id_type id)
{
   expr_type e = (expr_type) SafeMalloc(sizeof(expr_struct));
   
   /* Id must be a parameter, local, property, constant, or resource */
   lookup_id(id);		
   switch(id->type)
   {
   case I_LOCAL:
   case I_PROPERTY:
   case I_CLASSVAR:
      e->type = E_IDENTIFIER;
      e->value.idval = id;
      break;

   case I_RESOURCE:
   {
      const_type c = (const_type) SafeMalloc(sizeof(const_struct));

      /* Turn resource id reference into the resource # itself */
      c->type = C_RESOURCE;
      c->value.numval = id->idnum; 

      e->type = E_CONSTANT;
      e->value.constval = c;
      return e;
   }

   case I_CONSTANT:
   {
      const_type c = (const_type) SafeMalloc(sizeof(const_struct));
      id_type temp;

      /* Turn constant id reference into the constant itself */
      c->type = C_NUMBER;

      temp = (id_type) list_find_item(st.constants, id, id_compare);
      c->value.numval = temp->source; /* Value is stored in source field */

      e->type = E_CONSTANT;
      e->value.constval = c;
      break;
   }
   case I_UNDEFINED:
   case I_MISSING:
      action_error("Unknown identifier %s", id->name);
      /* Put in something so that compilation can continue */
      e = make_expr_from_constant(make_nil_constant());
      break;

   default:
      action_error("Identifier %s in expression has wrong type", id->name);
      /* Put in something so that compilation can continue */
      e = make_expr_from_constant(make_nil_constant());
      break;
   }
   e->lineno = lineno;
   return e;
}
Exemplo n.º 5
0
void UnuseObject(ID obj_id)
{
   if (list_find_item(use_list, (void *) obj_id, CompareId) == NULL)
      return;  /* Not an error, since we always try to unuse what we drop */

   use_list = list_delete_item(use_list, (void *) obj_id, CompareId);
   ModuleEvent(EVENT_INVENTORY, INVENTORY_UNUSE, obj_id);
}
Exemplo n.º 6
0
/*
 * InventoryChangeItem:  Change given object in inventory to reflect new
 *   icon, name, or amount.
 */
void InventoryChangeItem(object_node *obj)
{
    InvItem *item;

    item = (InvItem *) list_find_item(items, (void *) obj->id, InventoryCompareIdItem);
    if (item == NULL)
        return;  /* Not an error, since we try to unuse everything we drop */

    InventoryRedrawSingleItem(item);
}
Exemplo n.º 7
0
lnode *list_prev(llist *l)
{
	if (l->cur == NULL)
		return NULL;

	if (l->cur->item == 0)
		return NULL;

	list_find_item(l, l->cur->item-1);
	return l->cur;
}
Exemplo n.º 8
0
/*
 * DisplaySetUsing:  Change selections in inventory to reflect the fact that
 *   player is using (using = True) or not using (using = False) given item.
 */
void DisplaySetUsing(ID obj_id, Bool is_using)
{
    InvItem *item;

    item = (InvItem *) list_find_item(items, (void *) obj_id, InventoryCompareIdItem);
    if (item == NULL)
        return;  /* Not an error, since we try to unuse everything we drop */

    item->is_using = is_using;

    InventoryRedrawSingleItem(item);
}
Exemplo n.º 9
0
/*
 * ToggleUse: Ask server to toggle usage state of given object.
 */
void ToggleUse(ID obj_id)
{
    InvItem *item;

    if (num_items == 0)
        return;

    item = (InvItem *) list_find_item(items, (void *) obj_id, InventoryCompareIdItem);
    if (item == NULL)
        return;  /* Not an error, since we try to unuse everything we drop */

    if (item->is_using)
        RequestUnuse(obj_id);
    else RequestUse(obj_id);
}
Exemplo n.º 10
0
void RemoveSpell(ID id)
{
   spell *old_spell = (spell *) list_find_item(spells, (void *) id, CompareIdObject);

   if (old_spell == NULL)
   {
      debug(("Tried to remove nonexistent spell #%ld\n", id));
      return;
   }

   MenuRemoveSpell(old_spell);

   spells = list_delete_item(spells, (void *) id, CompareIdObject);
   SafeFree(old_spell);
}
Exemplo n.º 11
0
class_type make_class_signature(id_type class_id, id_type superclass_id)
{
   list_type l;
   id_type old_id;
   class_type c = (class_type) SafeMalloc(sizeof(class_struct));
   c->superclass = NULL;  /* Will be set for real below */

   c->class_id = class_id;

   /* Class name must not have appeared before */
   old_id = lookup_id(class_id);

   switch(class_id->type)
   {
   case I_MISSING:
      /* The class has been referenced in a function call, but not declared anywhere 
       * We should use the existent class # and remove the id from the missing list 
       */
      if (class_id->source != I_CLASS)
      {
	 action_error("Class %s was referenced elsewhere with different type", class_id->name);
	 break;
      }

      /* Insert directly into global table to preserve id # */
      class_id->type = I_CLASS;
      class_id->source = COMPILE;
      table_insert(st.globalvars, (void *) class_id, id_hash, id_compare);

      /* Remove from missing list */
      table_delete_item(st.missingvars, class_id, id_hash, id_compare);

      break;
      
   case I_UNDEFINED:
      /* New class name--continue normally */
      add_identifier(class_id, I_CLASS);
      break;

   case I_CLASS:
      /* We are recompiling a previously existing class.  This is rather ugly, since
       * we want to replace all the old class's data with our new data.  However, to give
       * previously compiled subclasses a chance of working with the new version, we
       * should try to match class numbers, message #s, etc. with the old class.
       *   At this point, all the old class's data have been inserted into our hash
       * tables.  The new class will be inserted into st.globalvars.  We must remove the old class 
       * from the class list.
       */

      /* If class is given twice in source files, that's an error */
      if (class_id->source == COMPILE)
	 action_error("Class %s is given twice", class_id->name);
      else 
	 /* Change the existent class id to reflect the fact that the class has now
	  * been recompiled. */
	 old_id->source = COMPILE;

      class_id->source = COMPILE;

      /* Delete self from list of existent classes.  Give warnings for subclasses. */
	 
      for (l = st.classes; l != NULL; l = l->next)
	 if (is_parent(c, (class_type) l->data))
	 {
	    if (((class_type) l->data)->class_id->idnum == c->class_id->idnum)
	       st.classes = list_delete_item(st.classes, l->data, class_compare);
	    else
	       /* Don't give warning if deleted self from list */
	    {
	       recompile_type recompile_info = 
		  (recompile_type) SafeMalloc(sizeof(recompile_struct));
	       recompile_info->class_id = ((class_type) (l->data))->class_id;
	       recompile_info->superclass = c->class_id;
	       
	       /* Only add to list if it isn't already there */
	       if (list_find_item(st.recompile_list, recompile_info->class_id, 
				  recompile_compare) == NULL)
		  st.recompile_list = list_add_item(st.recompile_list, (void *) recompile_info);
	    }
	    
	 }
      break;
      
   default:
      action_error("Duplicate identifier %s", class_id->name);
   }

   /* Delete this class from list of those that need to be recompiled */
   st.recompile_list = 
      list_delete_item(st.recompile_list, (void *) c->class_id, recompile_compare);

   c->resources  = NULL;
   c->properties = NULL;
   c->messages   = NULL;
   c->is_new = True; /* We should generate code for this class */

   /* Superclass must be defined, if one is given */
   if (superclass_id != NULL)
   {
      lookup_id(superclass_id);
      if (superclass_id->type != I_CLASS)
	 action_error("Can't find superclass %s", superclass_id->name);
      else if (class_id->idnum == superclass_id->idnum)
	 action_error("Can't subclass from self", superclass_id->name);	 
      else 
      {
	 /* Find superclass's data and store a pointer to it. */
	 for (l = st.classes; l != NULL; l = l->next)
	    if (superclass_id->idnum == ((class_type) (l->data))->class_id->idnum)
	    {
	       c->superclass = (class_type) l->data;
	       break;
	    }

	 if (c->superclass == NULL)
	    action_error("Unable to find superclass %s", superclass_id->name);
      }
      
   }
   else c->superclass = NULL;

   st.curclass = class_id->idnum;

   /* Now add superclasses' properties to our own property table, but delete
    * them from our property list.  This way the table will hold all properties 
    * that can be referenced in the class, but the property list will only 
    * hold those that were declared in this class (need to know this for code gen) */
   add_parent_properties(c, c->superclass);

   /* Similarly, add superclasses' classvars.  This must be done AFTER adding the properties,
    * since some properties in a superclass could be overriding classvars in a superclass */
   add_parent_classvars(NULL, c, c->superclass);

   /* Add to list of classes */
   st.classes = list_add_item(st.classes, (void *) c);

   return c;   
}
Exemplo n.º 12
0
/*
 * IsInUse:  Return True iff the object with the given id is in use.
 */
Bool IsInUse(ID obj_id)
{
   return (list_find_item(use_list, (void *) obj_id, CompareId) != NULL);
}