コード例 #1
0
ファイル: magic_test.c プロジェクト: UweKopf/server
void test_getspell_unit(CuTest * tc)
{
  spell *sp;
  struct unit * u;
  struct faction * f;
  struct region * r;
  struct locale * lang;

  test_cleanup();
  test_create_world();
  r = findregion(0, 0);
  f = test_create_faction(0);
  u = test_create_unit(f, r);
  create_mage(u, M_GRAY);
  skill_enabled[SK_MAGIC] = 1;

  set_level(u, SK_MAGIC, 1);

  lang = find_locale("de");
  sp = create_spell("testspell", 0);
  locale_setstring(lang, mkname("spell", sp->sname), "Herp-a-derp");

  CuAssertPtrEquals(tc, 0, unit_getspell(u, "Herp-a-derp", lang));

  unit_add_spell(u, 0, sp, 1);
  CuAssertPtrNotNull(tc, unit_getspell(u, "Herp-a-derp", lang));
}
コード例 #2
0
ファイル: magic_test.c プロジェクト: UweKopf/server
void test_getspell_school(CuTest * tc)
{
  spell *sp;
  struct unit * u;
  struct faction * f;
  struct region * r;
  struct locale * lang;
  struct spellbook * book;

  test_cleanup();
  test_create_world();
  r = findregion(0, 0);
  f = test_create_faction(0);
  f->magiegebiet = M_TYBIED;
  u = test_create_unit(f, r);
  create_mage(u, f->magiegebiet);
  skill_enabled[SK_MAGIC] = 1;
  set_level(u, SK_MAGIC, 1);

  lang = find_locale("de");
  sp = create_spell("testspell", 0);
  locale_setstring(lang, mkname("spell", sp->sname), "Herp-a-derp");

  CuAssertPtrEquals(tc, 0, unit_getspell(u, "Herp-a-derp", lang));

  book = faction_get_spellbook(f);
  CuAssertPtrNotNull(tc, book);
  spellbook_add(book, sp, 1);
  CuAssertPtrEquals(tc, sp, unit_getspell(u, "Herp-a-derp", lang));
}
コード例 #3
0
ファイル: sym.c プロジェクト: EtchedPixels/FUZIX
/**
 * add new symbol to local table
 * @param sname
 * @param identity
 * @param type
 * @param offset size in bytes
 * @param storage_class
 * @return 
 */
int add_local (char *sname, int identity, int type, int offset, int storage_class) {
    int k;
    SYMBOL *symbol;
    char *buffer_ptr;

    if ((current_symbol_table_idx = find_locale (sname)) > -1) {
        return (current_symbol_table_idx);
    }
    if (local_table_index >= NUMBER_OF_GLOBALS + NUMBER_OF_LOCALS) {
        error ("local symbol table overflow");
        return (0);
    }
    current_symbol_table_idx = local_table_index;
    symbol = &symbol_table[current_symbol_table_idx];
    buffer_ptr = symbol->name;
    /* FIXME: only copy so many bytes */
    while (alphanumeric(*buffer_ptr++ = *sname++));
    symbol->identity = identity;
    symbol->type = type;
    symbol->storage = storage_class;
    if (storage_class == LSTATIC) {
        data_segment_gdata();
        print_label(k = getlabel());
        output_label_terminator();
        gen_def_storage();
        output_number(offset);
        newline();
        code_segment_gtext();
        offset = k;
    }
    symbol->offset = offset;
    local_table_index++;
    return (current_symbol_table_idx);
}
コード例 #4
0
ファイル: arena.c プロジェクト: UweKopf/server
static void guardian_faction(plane * pl, int id)
{
  region *r;
  faction *f = findfaction(id);

  if (!f) {
    f = calloc(1, sizeof(faction));
    f->banner = _strdup("Sie dienen dem großen Wyrm");
    f->passw = _strdup(itoa36(rng_int()));
    set_email(&f->email, "*****@*****.**");
    f->name = _strdup("Igjarjuks Kundschafter");
    f->race = new_race[RC_ILLUSION];
    f->age = turn;
    f->locale = find_locale("de");
    f->options =
      want(O_COMPRESS) | want(O_REPORT) | want(O_COMPUTER) | want(O_ADRESSEN) |
      want(O_DEBUG);

    f->no = id;
    addlist(&factions, f);
    fhash(f);
  }
  if (f->race != new_race[RC_ILLUSION]) {
    assert(!"guardian id vergeben");
    exit(0);
  }
  f->lastorders = turn;
  f->alive = true;
  for (r = regions; r; r = r->next)
    if (getplane(r) == pl && rterrain(r) != T_FIREWALL) {
      unit *u;
      freset(r, RF_ENCOUNTER);
      for (u = r->units; u; u = u->next) {
        if (u->faction == f)
          break;
      }
      if (u)
        continue;
      u = createunit(r, f, 1, new_race[RC_GOBLIN]);
      set_string(&u->name, "Igjarjuks Auge");
      set_item(u, I_RING_OF_INVISIBILITY, 1);
      set_order(&u->thisorder, NULL);
      fset(u, UFL_ANON_FACTION);
      set_money(u, 1000);
    }
}
コード例 #5
0
ファイル: function.c プロジェクト: EtchedPixels/FUZIX
void doLocalAnsiArgument(int type) {
    char symbol_name[NAMESIZE];
    int identity, address, argptr, ptr;

    if (match("*")) {
        identity = POINTER;
    } else {
        if (type == STRUCT) {
            error("cannot pass struct");
            return;
        }
        identity = VARIABLE;
        if (type == VOID)
            return;
    }
    if (symname(symbol_name)) {
        if (find_locale(symbol_name) > -1) {
            multidef(symbol_name);
        } else {
            argptr = add_local (symbol_name, identity, type, 0, AUTO);
            argstk = argstk + INTSIZE;
            ptr = local_table_index;
            while (ptr != NUMBER_OF_GLOBALS) { // modify stack offset as we push more params
                ptr = ptr - 1;
                address = symbol_table[ptr].offset;
                symbol_table[ptr].offset = address + INTSIZE;
                /* Struct etc FIXME */
            }
        }
    } else {
        error("illegal argument name");
        junk();
    }
    if (match("[")) {
        while (inbyte() != ']') {
            if (endst()) {
                break;
            }
        }
        identity = POINTER;
        symbol_table[argptr].identity = identity;
    }
}
コード例 #6
0
ファイル: ld-address.c プロジェクト: bminor/glibc
void
address_finish (struct localedef_t *locale, const struct charmap_t *charmap)
{
  struct locale_address_t *address = locale->categories[LC_ADDRESS].address;
  size_t cnt;
  int helper;
  int nothing = 0;

  /* Now resolve copying and also handle completely missing definitions.  */
  if (address == NULL)
    {
      /* First see whether we were supposed to copy.  If yes, find the
	 actual definition.  */
      if (locale->copy_name[LC_ADDRESS] != NULL)
	{
	  /* Find the copying locale.  This has to happen transitively since
	     the locale we are copying from might also copying another one.  */
	  struct localedef_t *from = locale;

	  do
	    from = find_locale (LC_ADDRESS, from->copy_name[LC_ADDRESS],
				from->repertoire_name, charmap);
	  while (from->categories[LC_ADDRESS].address == NULL
		 && from->copy_name[LC_ADDRESS] != NULL);

	  address = locale->categories[LC_ADDRESS].address
	    = from->categories[LC_ADDRESS].address;
	}

      /* If there is still no definition issue an warning and create an
	 empty one.  */
      if (address == NULL)
	{
	  record_warning (_("\
No definition for %s category found"), "LC_ADDRESS");
	  address_startup (NULL, locale, 0);
	  address = locale->categories[LC_ADDRESS].address;
	  nothing = 1;
	}
    }
コード例 #7
0
ファイル: function.c プロジェクト: JamesLinus/FUZIX
/**
 * declare argument types
 * called from "newfunc", this routine adds an entry in the local
 * symbol table for each named argument
 * completely rewritten version.  p.l. woods
 * @param t argument type (char, int)
 * @return 
 */
void getarg(int t) {
    int j, legalname, address, argptr;
    char n[NAMESIZE];

    FOREVER
    {
        if (argstk == 0)
            return;
        if (match("*"))
            j = POINTER;
        else
            j = VARIABLE;
        if (!(legalname = symname(n)))
            illname();
        if (match("[")) {
            while (inbyte() != ']')
                if (endst())
                    break;
            j = POINTER;
        }
        if (legalname) {
            if ((argptr = find_locale(n)) > -1) {
                symbol_table[argptr].identity = j;
                symbol_table[argptr].type = t;
                address = argtop - symbol_table[argptr].offset;
                symbol_table[argptr].offset = address;
            } else
                error("expecting argument name");
        }
        argstk = argstk - INTSIZE;
        if (endst())
            return;
        if (!match(","))
            error("expected comma");
    }
}
コード例 #8
0
ファイル: function.c プロジェクト: JamesLinus/FUZIX
void newfunc_typed(int storage, char *n, int type)
{
    int idx;
    SYMBOL *symbol;
    char an[NAMESIZE];

    fexitlab = getlabel();

    if ((idx = find_global(n)) > -1) {
        symbol = &symbol_table[idx];
        if (symbol->identity != FUNCTION)
            multidef(n);
    } else {
        /* extern implies global scope */
        idx = add_global(n, FUNCTION, CINT, 0, storage == EXTERN ? PUBLIC : storage);
        symbol = &symbol_table[idx];
    }
    local_table_index = NUMBER_OF_GLOBALS; //locptr = STARTLOC;
    argstk = 0;
    // ANSI style argument declaration
    if (doAnsiArguments()) {
        if (storage == EXTERN) {
            need_semicolon();
            return;
        }
        /* No body .. just a definition */
        if (match(";"))
            return;
    } else {
        // K&R style argument declaration
        while (!match(")")) {
            if (symname(an)) {
                if (find_locale(an) > -1)
                    multidef(an);
                else {
                    /* FIXME: struct */
                    add_local(an, 0, 0, argstk, AUTO);
                    argstk = argstk + INTSIZE;
                }
            } else {
                error("illegal argument name");
                junk();
            }
            blanks();
            if (!streq(line + lptr, ")")) {
                if (!match(","))
                    error("expected comma");
            }
            if (endst())
                break;
        }
        if (storage == EXTERN) {
            need_semicolon();
            return;
        }
        /* No body .. just a definition */
        if (match(";"))
            return;
        stkp = 0;
        argtop = argstk;
        while (argstk) {
            if ((type = get_type()) != -1) {
                notvoid(type);
                getarg(type);
                need_semicolon();
            } else {
                error("wrong number args");
                break;
            }
        }
    }
    if (symbol->offset == FUNCTION)
            multidef(n);
    symbol->offset = FUNCTION;
    output_string(n);
    output_label_terminator();
    newline();
    gen_prologue();
    statement(YES);
    print_label(fexitlab);
    output_label_terminator();
    newline();
    gen_epilogue();
    gen_modify_stack(0);
    gen_ret();
    stkp = 0;
    local_table_index = NUMBER_OF_GLOBALS; //locptr = STARTLOC;
}
コード例 #9
0
ファイル: sym.c プロジェクト: EtchedPixels/FUZIX
/**
 * declare local variables
 * works just like "declglb", but modifies machine stack and adds
 * symbol table entry with appropriate stack offset to find it again
 * @param typ
 * @param stclass
 * @param otag index of tag in tag_table
 */
void declare_local(int typ, int stclass, int otag) {
    int     k, j;
    char    sname[NAMESIZE];

    FOREVER {
        FOREVER {
            if (endst())
                return;
            if (match("*"))
                j = POINTER;
            else
                j = VARIABLE;
            if (!symname(sname))
                illname();
            if (-1 != find_locale(sname))
                multidef (sname);
            if (match("[")) {
                k = needsub();
                if (k) {
                    j = ARRAY;
                    if (typ & CINT) {
                        k = k * INTSIZE;
                    } else if (typ == STRUCT) {
                        k = k * tag_table[otag].size;
                    }
                } else {
                    j = POINTER;
                    k = INTSIZE;
                }
            } else {
                if (j == POINTER) {
                    k = INTSIZE;
                } else {
                    switch (typ) {
                        case CCHAR:
                        case UCHAR:
                            k = 1;
                            break;
                        case STRUCT:
                            k = tag_table[otag].size;
                            break;
                        default:
                            k = INTSIZE;
                    }
                }
            }
            if (stclass == LSTATIC) {
                add_local(sname, j, typ, k, LSTATIC);
                break;
            }
            if (stclass == REGISTER) {
                int r = gen_register(j, k, typ);
                if (r != -1) {
                    add_local(sname, j, typ, r, REGISTER);
                    break;
                }
            }
            if (match("=")) {
                gen_modify_stack(stkp);
                expression(0);
                gen_push(0);
            } else
                stkp = gen_defer_modify_stack(stkp - k);
            add_local(sname, j, typ, stkp, AUTO);
            break;
        }
        if (!match(","))
            return;
    }
}
コード例 #10
0
ファイル: primary.c プロジェクト: beretta42/FUZIX
int primary(LVALUE *lval) {
    char    sname[NAMESIZE];
    int     num[1], k, symbol_table_idx, offset, reg;
    SYMBOL *symbol;

    lval->ptr_type = 0;  // clear pointer/array type
    lval->tagsym = 0;
    if (match ("(")) {
        k = hier1 (lval);
        needbrack (")");
        return (k);
    }
    if (amatch("sizeof", 6)) {
        needbrack("(");
        gen_immediate();
        if (amatch("int", 3)) output_number(INTSIZE);
        else if (amatch("char", 4)) output_number(1);
        else if (symname(sname)) {
            if (((symbol_table_idx = find_locale(sname)) > -1) ||
                ((symbol_table_idx = find_global(sname)) > -1)) {
                symbol = &symbol_table[symbol_table_idx];
                if (symbol->storage == LSTATIC)
                    error("sizeof local static");
                offset = symbol->offset;
                if ((symbol->type & CINT) ||
                    (symbol->identity == POINTER))
                    offset *= INTSIZE;
                else if (symbol->type == STRUCT)
                    offset *= tag_table[symbol->tagidx].size;
                output_number(offset);
            } else {
                error("sizeof undeclared variable");
                output_number(0);
            }
        } else {
            error("sizeof only on type or variable");
        }
        needbrack(")");
        newline();
        lval->symbol = 0;
        lval->indirect = 0;
        return(0);
    }
    if (symname (sname)) {
        if ((symbol_table_idx = find_locale(sname)) > -1) {
            symbol = &symbol_table[symbol_table_idx];
            reg = gen_get_locale(symbol);
            lval->symbol = symbol;
            lval->indirect = symbol->type;
            if (symbol->type == STRUCT) {
                lval->tagsym = &tag_table[symbol->tagidx];
            }
            if (symbol->identity == ARRAY ||
                (symbol->identity == VARIABLE && symbol->type == STRUCT)) {
                lval->ptr_type = symbol->type;
                return reg;
            }
            if (symbol->identity == POINTER) {
                lval->indirect = CINT;
                lval->ptr_type = symbol->type;
            }
            return FETCH | reg;
        }
        if ((symbol_table_idx = find_global(sname)) > -1) {
            symbol = &symbol_table[symbol_table_idx];
            if (symbol->identity != FUNCTION) {
                lval->symbol = symbol;
                lval->indirect = 0;
                if (symbol->type == STRUCT) {
                    lval->tagsym = &tag_table[symbol->tagidx];
                }
                if (symbol->identity != ARRAY &&
                    (symbol->identity != VARIABLE || symbol->type != STRUCT)) {
                    if (symbol->identity == POINTER) {
                        lval->ptr_type = symbol->type;
                    }
                    return FETCH | HL_REG;
                }
                gen_immediate();
                output_string(symbol->name);
                newline();
                lval->indirect = symbol->type;
                lval->ptr_type = symbol->type;
                return 0;
            }
        }
        blanks();
        if (ch() != '(')
            error("undeclared variable");
        symbol_table_idx = add_global(sname, FUNCTION, CINT, 0, PUBLIC);
        symbol = &symbol_table[symbol_table_idx];
        lval->symbol = symbol;
        lval->indirect = 0;
        return 0;
    }
    lval->symbol = 0;
    lval->indirect = 0;
    if (constant(num))
        return 0;
    else {
        error("invalid expression");
        gen_immediate();
        output_number(0);
        newline();
        junk();
        return 0;
    }
}