Ejemplo n.º 1
0
const char *racename(const struct locale *loc, const unit * u, const race * rc)
{
  const char *prefix = raceprefix(u);

  if (prefix != NULL) {
    static char lbuf[80];
    char *bufp = lbuf;
    size_t size = sizeof(lbuf) - 1;
    int ch, bytes;

    bytes = (int)strlcpy(bufp, LOC(loc, mkname("prefix", prefix)), size);
    if (wrptr(&bufp, &size, bytes) != 0)
      WARN_STATIC_BUFFER();

    bytes = (int)strlcpy(bufp, LOC(loc, rc_name(rc, u->number != 1)), size);
    assert(~bufp[0] & 0x80 || !"unicode/not implemented");
    ch = tolower(*(unsigned char *)bufp);
    bufp[0] = (char)ch;
    if (wrptr(&bufp, &size, bytes) != 0)
      WARN_STATIC_BUFFER();
    *bufp = 0;

    return lbuf;
  }
  return LOC(loc, rc_name(rc, u->number != 1));
}
Ejemplo n.º 2
0
unsigned torcompress(unsigned char method, unsigned char* in, unsigned char* out, unsigned size)
{
  struct bufio bufio; bufioini(&bufio, in, size, out, size);
  PackMethod m = std_Tornado_method[method];
  int rc = tor_compress (m, ReadWriteMem, &bufio, NULL, -1);
  return rc?0:wrptr(&bufio) - out;
}
Ejemplo n.º 3
0
int torhenc(unsigned char *in, int inlen, unsigned char *out, int outsize) {
  struct bufio bufio; bufioini(&bufio, in, inlen, out, outsize);
  HuffmanEncoder<EOB_CODE> huff(ReadWriteMem, &bufio, CHUNK_SIZE, 4*CHUNK_SIZE, EOB_CODE+1);
  unsigned char *p,*iep = in+inlen;
  for(p = in; p < iep; ) { unsigned char *ep = p + CHUNK_SIZE; if(ep>iep) ep = iep;
    for(; p < ep; p++) huff.encode(*p); 
    huff.flush();
  } huff.finish();
  return wrptr(&bufio) - out;
}
Ejemplo n.º 4
0
static order *make_movement_order(unit * u, const region * target, int moves,
    bool(*allowed) (const region *, const region *))
{
    region *r = u->region;
    region **plan;
    int bytes, position = 0;
    char zOrder[128], *bufp = zOrder;
    size_t size = sizeof(zOrder) - 1;

    if (monster_is_waiting(u))
        return NULL;

    plan = path_find(r, target, DRAGON_RANGE * 5, allowed);
    if (plan == NULL)
        return NULL;

    bytes =
        (int)strlcpy(bufp,
        (const char *)LOC(u->faction->locale, keyword(K_MOVE)), size);
    if (wrptr(&bufp, &size, bytes) != 0)
        WARN_STATIC_BUFFER();

    while (position != moves && plan[position + 1]) {
        region *prev = plan[position];
        region *next = plan[++position];
        direction_t dir = reldirection(prev, next);
        assert(dir != NODIRECTION && dir != D_SPECIAL);
        if (size > 1) {
            *bufp++ = ' ';
            --size;
        }
        bytes =
            (int)strlcpy(bufp,
            (const char *)LOC(u->faction->locale, directions[dir]), size);
        if (wrptr(&bufp, &size, bytes) != 0)
            WARN_STATIC_BUFFER();
    }

    *bufp = 0;
    return parse_order(zOrder, u->faction->locale);
}
Ejemplo n.º 5
0
int torhdec(unsigned char *in, int inlen, unsigned char *out, int outlen ) {
  struct bufio bufio; bufioini(&bufio, in, inlen, out, outlen);
  HuffmanDecoder<EOB_CODE> huff(ReadWriteMem, &bufio, CHUNK_SIZE, EOB_CODE+1);
  for(int i=0; i<outlen; i++) out[i] = huff.decode();
  return wrptr(&bufio) - out;
}
Ejemplo n.º 6
0
unsigned tordecompress(unsigned char* in, unsigned char* out, unsigned inlen, unsigned outsize)
{
  struct bufio bufio; bufioini(&bufio, in, inlen, out, outsize);
  int rc = tor_decompress(ReadWriteMem, &bufio, NULL, -1);
  return rc?0:wrptr(&bufio) - out;
}