Ejemplo n.º 1
0
/* @method String XmlReader.getAttributeNs(String ns, String name) */
METHOD XmlReader_getAttributeNs(Ctx *ctx, knh_sfp_t *sfp)
{
    xmlTextReaderPtr reader = (xmlTextReaderPtr) p_cptr(sfp[0]);
    xmlChar* ns   = (xmlChar*) p_char(sfp[1]);
    xmlChar* name = (xmlChar*) p_char(sfp[2]);
    char* ret = (char*) xmlTextReaderGetAttributeNs(reader,ns,name);
    KNH_RETURN(ctx,sfp,new_String(ctx,B(ret),NULL));
}
Ejemplo n.º 2
0
Archivo: xml.c Proyecto: matsuu/konoha
METHOD XmlNode_setAttr(Ctx *ctx, knh_sfp_t *sfp)
{
    xmlNodePtr node= (xmlNodePtr) p_cptr(sfp[0]);
    xmlChar *name = (xmlChar *) p_char(sfp[1]);
    xmlChar *val  = (xmlChar *) p_char(sfp[2]);
    xmlSetProp(node,name,val);
    KNH_RETURN_void(ctx,sfp);
}
Ejemplo n.º 3
0
Archivo: xml.c Proyecto: matsuu/konoha
/* XmlNode */
METHOD XmlNode_createNode(Ctx *ctx, knh_sfp_t *sfp)
{
    xmlNodePtr parent = (xmlNodePtr) p_cptr(sfp[0]);
    xmlChar *name = (xmlChar*) p_char(sfp[1]);
    xmlChar *val  = (xmlChar*) p_char(sfp[2]);

    xmlNodePtr node = xmlNewChild(parent, NULL, name, val);
    KNH_RETURN(ctx,sfp,new_Glue(ctx,(char*)"libxml2.XmlNode",node,NULL));
}
Ejemplo n.º 4
0
int
d_undead_lord(struct command *c)
{
  int where = subloc(c->who);
  int aura = c->a;
  int undead;
  int rating;

  if (!may_cookie_npc(c->who, where, item_undead_cookie))
    return FALSE;

  if (!charge_aura(c->who, aura))
    return FALSE;

  undead = do_cookie_npc(c->who, where, item_undead_cookie, c->who);

  if (undead == 0) {
    log_write(LOG_CODE, "d_undead_lord: why not?");
    wout(c->who, "Unable to summon a demon lord.");
    return FALSE;
  }

  switch (aura) {
  case 3:
    rating = 100;
    break;
  case 4:
    rating = 150;
    break;
  case 5:
    rating = 190;
    break;
  case 6:
    rating = 220;
    break;
  case 7:
    rating = 240;
    break;
  case 8:
    rating = 250;
    break;

  default:
    assert(FALSE);
  }

  p_char(undead)->attack = rating;
  p_char(undead)->defense = rating;

  set_loyal(undead, LOY_summon, 5);

  wout(c->who, "Summoned %s.", box_name(undead));
  wout(where, "%s has summoned %s.", box_name(c->who), liner_desc(undead));

  return TRUE;
}
Ejemplo n.º 5
0
Archivo: xml.c Proyecto: matsuu/konoha
METHOD Xml_createNode(Ctx *ctx, knh_sfp_t *sfp)
{
    xmlDocPtr doc = (xmlDocPtr) p_cptr(sfp[0]);
    xmlChar *name = (xmlChar*) p_char(sfp[1]);
    doc->children = xmlNewDocNode(doc, NULL, name , NULL);
    KNH_RETURN(ctx,sfp,new_Glue(ctx,(char*)"libxml2.XmlNode",doc->children,NULL));
}
Ejemplo n.º 6
0
Archivo: xml.c Proyecto: matsuu/konoha
METHOD Xml_new(Ctx *ctx, knh_sfp_t *sfp)
{
    xmlChar* version = (xmlChar*)p_char(sfp[1]);
    xmlDocPtr doc = xmlNewDoc(version);
    knh_Glue_init(ctx,sfp[0].glue,doc,knh_xml_gfree);
    KNH_RETURN(ctx,sfp,sfp[0].o);
}
Ejemplo n.º 7
0
/* @method String XmlReader.lookupNameSpace(String ns) */
METHOD XmlReader_lookupNameSpace(Ctx *ctx, knh_sfp_t *sfp)
{
    xmlTextReaderPtr reader = (xmlTextReaderPtr) p_cptr(sfp[0]);
    xmlChar* ns   = (xmlChar*) p_char(sfp[1]);
    char* ret = (char*) xmlTextReaderLookupNamespace(reader,ns);
    KNH_RETURN(ctx,sfp,new_String(ctx,B(ret),NULL));
}
Ejemplo n.º 8
0
Archivo: xml.c Proyecto: matsuu/konoha
METHOD XmlNode_getAttr(Ctx *ctx, knh_sfp_t *sfp)
{
    xmlNodePtr node= (xmlNodePtr) p_cptr(sfp[0]);
    xmlChar *name = (xmlChar *) p_char(sfp[1]);
    xmlChar *ret  = (xmlChar *)"";
    if(node->properties){
        ret  = xmlGetProp(node,name);
    }
    KNH_RETURN(ctx, sfp, new_String(ctx, B((char*)ret), NULL));
}
Ejemplo n.º 9
0
/* @method This! XmlReader.new(String filename) */
METHOD XmlReader_new(Ctx *ctx, knh_sfp_t *sfp)
{
    char* filename = (char*)p_char(sfp[1]);
    xmlTextReaderPtr reader = xmlNewTextReaderFilename(filename);
    if(reader == NULL) {
        KNH_THROWs(ctx, "XmlReader: cant load file");
    }
    knh_Glue_init(ctx,sfp[0].glue,reader,knh_xmlreader_gfree);
    KNH_RETURN(ctx,sfp,sfp[0].o);
}
Ejemplo n.º 10
0
/* @method String XmlReader.getAttribute() */
METHOD XmlReader_getAttribute(Ctx *ctx, knh_sfp_t *sfp)
{
    xmlTextReaderPtr reader = (xmlTextReaderPtr) p_cptr(sfp[0]);
    xmlChar * ns = (xmlChar *) p_char(sfp[1]);
    char* ret = (char*) xmlTextReaderGetAttribute(reader,ns);
    if(ret == NULL){
        ret = "";
    }
    KNH_RETURN(ctx,sfp,new_String(ctx,B(ret),NULL));
}
Ejemplo n.º 11
0
int
d_heal(struct command *c)
{
  int target = c->a;
  int aura = c->b;
  int chance;

  if (kind(target) != T_char) {
    wout(c->who, "%s is no longer a character.", box_code(target));
    return FALSE;
  }

  if (!char_sick(target)) {
    wout(c->who, "%s is not sick.", box_name(target));
    return FALSE;
  }

  if (!charge_aura(c->who, aura))
    return FALSE;

  switch (aura) {
  case 1:
    chance = 30;
    break;

  case 2:
    chance = 15;
    break;

  case 3:
    chance = 5;
    break;

  default:
    assert(FALSE);
  }

  vector_clear();
  vector_add(c->who);
  vector_add(target);

  wout(VECT, "%s casts Heal on %s:", box_name(c->who), box_name(target));

  if (rnd(1, 100) <= chance) {
    wout(VECT, "Spell fails.");
    return FALSE;
  }

  p_char(target)->sick = FALSE;

  wout(VECT, "%s has been cured, and should now recover.", box_name(target));

  return TRUE;
}
Ejemplo n.º 12
0
METHOD Kernel_insmod(Ctx* ctx, knh_sfp_t* sfp)
{
  char *cmd = alloca(sizeof(char*));
  char *str = "insmod";
  char *filename = p_char(sfp[1]);
  int len = strlen(str)+strlen(filename)+2;
  snprintf(cmd, len, "%s %s", str, filename);
  system(cmd);

  KNH_RETURN_void(ctx, sfp);
}
Ejemplo n.º 13
0
Archivo: xml.c Proyecto: matsuu/konoha
METHOD XPath_find(Ctx *ctx, knh_sfp_t *sfp)
{
    xmlXPathContextPtr xctx = (xmlXPathContextPtr) p_cptr(sfp[0]);
    xmlChar *xpath = (xmlChar *) p_char(sfp[1]);
    xmlNodePtr node = NULL;
    xmlXPathObjectPtr xpobj;
    if (!(xpobj = xmlXPathEvalExpression( xpath, xctx))) {
        fprintf(stderr,"xpath:%s",(char*)xpath);
        KNH_THROWs(ctx, "XPATH: cant execute xmlXPathEvalExpression");
    }
    if (!xmlXPathNodeSetIsEmpty(xpobj->nodesetval)) {
        node = xmlXPathNodeSetItem(xpobj->nodesetval, 0);
    }
    xmlXPathFreeObject(xpobj);
    KNH_RETURN(ctx,sfp,new_Glue(ctx,(char*)"libxml2.XmlNode",node,NULL));
}