Esempio n. 1
0
static uint32_t parse_monster_color(std::ifstream &f,
                                    std::string *lookahead,
                                    std::vector<uint32_t> *color)
{
  uint32_t i;
  uint32_t c;

  c = UINT_MAX;

  eat_blankspace(f);

  if (f.peek() == '\n') {
    return 1;
  }

  do {
    f >> *lookahead;

    color->push_back(0);

    eat_blankspace(f);
  } while (f.peek() != '\n');

  f >> *lookahead;

  return 0;
}
Esempio n. 2
0
static uint32_t parse_color(std::ifstream &f,
                            std::string *lookahead,
                            uint32_t *color)
{
  uint32_t i;

  *color = UINT_MAX;

  eat_blankspace(f);

  if (f.peek() == '\n') {
    return 1;
  }

  f >> *lookahead;




  eat_blankspace(f);
  if (f.peek() != '\n') {
    return 1;
  }

  f >> *lookahead;

  return 0;
}
static uint32_t parse_dice(std::ifstream &f,
                           std::string *lookahead,
                           dice *d)
{
  int32_t base;
  uint32_t number, sides;

  eat_blankspace(f);

  if (f.peek() == '\n') {
    return 1;
  }

  f >> *lookahead;

  if (sscanf(lookahead->c_str(), "%d+%ud%u", &base, &number, &sides) != 3) {
    return 1;
  }

  d->set(base, number, sides);

  f >> *lookahead;

  return 0;
}
Esempio n. 4
0
static uint32_t parse_monster_symb(std::ifstream &f,
                                   std::string *lookahead,
                                   char *symb)
{
  eat_blankspace(f);

  if (f.peek() == '\n') {
    return 1;
  }

  *symb = f.get();

  eat_blankspace(f);
  if (f.peek() != '\n') {
    return 1;
  }

  f >> *lookahead;

  return 0;
}
Esempio n. 5
0
static uint32_t parse_monster_color(std::ifstream &f,
                                    std::string *lookahead,
                                    std::vector<uint32_t> *color)
{
  uint32_t i;
  uint32_t c;

  c = UINT_MAX;

  eat_blankspace(f);

  if (f.peek() == '\n') {
    return 1;
  }

  do {
    f >> *lookahead;

    for (i = 0; colors_lookup[i].name; i++) {
      if (*lookahead == colors_lookup[i].name) {
        c = colors_lookup[i].value;
        break;
      }
    }

    if (!colors_lookup[i].name) {
      return 1;
    }

    color->push_back(c);

    eat_blankspace(f);
  } while (f.peek() != '\n');

  f >> *lookahead;

  return 0;
}
static uint32_t parse_object_type(std::ifstream &f,
                                   std::string *lookahead,
                                   uint32_t *type)
{
  uint32_t i;

  *type = 0;

  eat_blankspace(f);

  if (f.peek() == '\n') {
    return 1;
  }

  /* Will not lead to error if an ability is listed multiple times. */
  while (f.peek() != '\n') {
    f >> *lookahead;

    for (i = 0; type_lookup[i].name; i++) {
      if (*lookahead == type_lookup[i].name) {
        *type |= type_lookup[i].value;
        break;
      }
    }

    if (!type_lookup[i].name) {
      return 1;
    }

    eat_blankspace(f);
  }

  f >> *lookahead;

  return 0;
}
static uint32_t parse_object_color(std::ifstream &f,
                                    std::string *lookahead,
                                    uint32_t *color)
{
  uint32_t i;

  *color = UINT_MAX;

  eat_blankspace(f);

  if (f.peek() == '\n') {
    return 1;
  }

  f >> *lookahead;

  for (i = 0; colors_lookup[i].name; i++) {
    if (*lookahead == colors_lookup[i].name) {
      *color = colors_lookup[i].value;
      break;
    }
  }

  if (!colors_lookup[i].name) {
    return 1;
  }

  eat_blankspace(f);
  if (f.peek() != '\n') {
    return 1;
  }

  f >> *lookahead;

  return 0;
}
Esempio n. 8
0
static uint32_t parse_monster_abil(std::ifstream &f,
                                   std::string *lookahead,
                                   uint32_t *abil)
{
  uint32_t i;

  *abil = 0;

  eat_blankspace(f);

  if (f.peek() == '\n') {
    return 1;
  }

  /* Will not lead to error if an ability is listed multiple times. */
  while (f.peek() != '\n') {
    f >> *lookahead;

    for (i = 0; abilities_lookup[i].name; i++) {
      if (*lookahead == abilities_lookup[i].name) {
        *abil |= abilities_lookup[i].value;
        break;
      }
    }

    if (!abilities_lookup[i].name) {
      return 1;
    }

    eat_blankspace(f);
  }

  f >> *lookahead;

  return 0;
}
static uint32_t parse_object_desc(std::ifstream &f,
                                   std::string *lookahead,
                                   std::string *desc)
{
  /* DESC is special.  Data doesn't follow on the same line *
   * as the keyword, so we want to eat the newline, too.    */
  eat_blankspace(f);

  if (f.peek() != '\n') {
    return 1;
  }

  f.get();

  while (f.peek() != EOF) {
    getline(f, *lookahead);
    if (lookahead->length() > 77) {
      return 1;
    }

    lookahead->push_back('\n');

    if (*lookahead == ".\n") {
      break;
    }

    *desc += *lookahead;
  }

  /* Strip off the trailing newline */
  desc->erase(desc->length() - 1);

  if (*lookahead != ".\n") {
    return 1;
  }

  f >> *lookahead;

  return 0;
}
static uint32_t parse_object_name(std::ifstream &f,
                                   std::string *lookahead,
                                   std::string *name)
{
  /* Always start by eating the blanks.  If we then find a newline, we *
   * know there's an error in the file.  If we eat all whitespace,     *
   * we'd consume newlines and perhaps miss a restart on the next      *
   * line.                                                             */

  eat_blankspace(f);

  if (f.peek() == '\n') {
    return 1;
  }

  getline(f, *name);

  /* We enter this function with the semantic in the lookahead, so we  *
   * read a new one so that we're in the same state for the next call. */
  f >> *lookahead;

  return 0;
}