Exemple #1
0
bool parse_TRACE(char * line, solvedPlay * solvedp)
{
#ifdef DEBUG
  printf("parse_TRACE: Got line '%s'\n", line);
#endif

  int pos = 0;
  if (consume_tag(line, &pos, "TRACE") == false) return false;
#ifdef DEBUG
  printf("parse_TRACE: Got tag 'TRACE'\n");
#endif

  if (consume_int(line, &pos, &solvedp->number) == false) return false;
#ifdef DEBUG
  printf("parse_TRACE: Read number %d\n", solvedp->number);
#endif

  for (int i = 0; i < solvedp->number; i++)
  {
    if (consume_int(line, &pos, &solvedp->tricks[i]) == false)
      return false;
#ifdef DEBUG
    printf("parse_TRACE: Read tricks[%d] = %d\n", i, solvedp->tricks[i]);
#endif
  }
  return true;
}
Exemple #2
0
bool parse_FUT(char * line, futureTricks * fut)
{
#ifdef DEBUG
  printf("parse_FUT: Got line '%s'\n", line);
#endif
  int pos = 0;
  if (consume_tag(line, &pos, "FUT") == false) return false;
#ifdef DEBUG
  printf("parse_FUT: Got tag 'FUT'\n");
#endif

  if (consume_int(line, &pos, &fut->cards) == false) return false;
#ifdef DEBUG
  printf("parse_FUT: Read cards %d\n", fut->cards);
#endif

  for (int c = 0; c < fut->cards; c++)
  {
    if (consume_int(line, &pos, &fut->suit[c]) == false) return false;
#ifdef DEBUG
    printf("parse_FUT: Read suit[%d]: %d\n", c, fut->suit[c]);
#endif
  }

  for (int c = 0; c < fut->cards; c++)
  {
    if (consume_int(line, &pos, &fut->rank[c]) == false) return false;
#ifdef DEBUG
    printf("parse_FUT: Read rank[%d]: %d\n", c, fut->rank[c]);
#endif
  }

  for (int c = 0; c < fut->cards; c++)
  {
    if (consume_int(line, &pos, &fut->equals[c]) == false) return false;
#ifdef DEBUG
    printf("parse_FUT: Read equals[%d]: %d\n", c, fut->equals[c]);
#endif
  }

  for (int c = 0; c < fut->cards; c++)
  {
    if (consume_int(line, &pos, &fut->score[c]) == false) return false;
#ifdef DEBUG
    printf("parse_FUT: Read score[%d]: %d\n", c, fut->score[c]);
#endif
  }

  return true;
}
Exemple #3
0
bool parse_PLAY(char * line, playTracePBN * playp)
{
#ifdef DEBUG
  printf("parse_PLAY: Got line '%s'\n", line);
#endif

  int pos = 0;
  if (consume_tag(line, &pos, "PLAY") == false) return false;
#ifdef DEBUG
  printf("parse_PLAY: Got tag 'PLAY', pos now %d\n", pos);
#endif

  if (consume_int(line, &pos, &playp->number) == false) return false;
#ifdef DEBUG
  printf("parse_PLAY: Read number %d\n", playp->number);
#endif

  if (consume_string(line, &pos, playp->cards) == false)
    return false;
#ifdef DEBUG
  printf("parse_PLAY: Read cards '%s'\n", playp->cards);
#endif

  return true;
}
Exemple #4
0
bool parse_PBN(
  char * line,
  int * dealer,
  int * vul,
  dealPBN * dl)
{
#ifdef DEBUG
  printf("parse_PBN: Got line '%s'\n", line);
#endif
  int pos = 0;
  if (consume_tag(line, &pos, "PBN") == false) return false;
#ifdef DEBUG
  printf("parse_PBN: Got tag 'PBN'\n");
#endif

  if (consume_int(line, &pos, dealer) == false) return false;
#ifdef DEBUG
  printf("parse_PBN: Read dealer %d\n", * dealer);
#endif

  if (consume_int(line, &pos, vul) == false) return false;
#ifdef DEBUG
  printf("parse_PBN: Read vul %d\n", * dealer);
#endif

  if (consume_int(line, &pos, &dl->trump) == false) return false;
#ifdef DEBUG
  printf("parse_PBN: Read trump %d\n", dl->trump);
#endif

  if (consume_int(line, &pos, &dl->first) == false) return false;
#ifdef DEBUG
  printf("parse_PBN: Read first %d\n", dl->first);
#endif

  if (consume_string(line, &pos, dl->remainCards) == false)
    return false;
#ifdef DEBUG
  printf("parse_PBN: Read string '%s'\n", dl->remainCards);
#endif

  return true;
}
Exemple #5
0
bool parse_NUMBER(char * line, int * number)
{
#ifdef DEBUG
  printf("parse_NUMBER: Got line '%s'\n", line);
#endif
  int pos = 0;
  if (consume_tag(line, &pos, "NUMBER") == false) return false;
#ifdef DEBUG
  printf("parse_NUMBER: Got tag 'NUMBER'\n");
#endif

  if (consume_int(line, &pos, number) == false) return false;
#ifdef DEBUG
  printf("parse_NUMBER: Read number %d\n", * number);
#endif
  return true;
}
Exemple #6
0
bool parse_TABLE(char * line, ddTableResults * table)
{
  int pos = 0;
  if (consume_tag(line, &pos, "TABLE") == false) return false;
#ifdef DEBUG
  printf("parse_FUT: Got tag 'TABLE'\n");
#endif

  for (int suit = 0; suit <= 4; suit++)
  {
    for (int pl = 0; pl <= 3; pl++)
    {
      if (consume_int(line, &pos, &table->resTable[suit][pl]) == false)
        return false;
#ifdef DEBUG
      printf("parse_TABLE: Read table[%d][%d] = %d\n",
             suit, pl, table->resTable[suit][pl]);
#endif
    }
  }
  return true;
}
GAIAAUX_DECLARE int
gaiaParseDMS (const char *dms, double *longitude, double *latitude)
{
/* attempting to parse a DMS string */
    double lg;
    double lt;
    int lat_d;
    int lat_m;
    double lat_s;
    char lat_prefix = '\0';
    int long_d;
    int long_m;
    double long_s;
    char long_prefix = '\0';
    const char *p = dms;
    const char *p_end;
    if (dms == NULL)
	return 0;

/* attempting to parse the latitude */
    consume_blank (p, &p_end);
    p = p_end;
    if (*p == 'S' || *p == 'N')
      {
	  lat_prefix = *p;
	  p++;
	  consume_blank (p, &p_end);
	  p = p_end;
      }
    if (*p >= '0' && *p <= '9')
      {
	  consume_int (p, &p_end, &lat_d);
	  if (lat_d < 0 && lat_d > 90)
	      return 0;
	  p = p_end;
      }
    else
	return 0;
    consume_blank (p, &p_end);
    p = p_end;
    if (check_deg_delimiter (p, &p_end))
	p = p_end;
    else
	return 0;
    consume_blank (p, &p_end);
    p = p_end;
    if (*p >= '0' && *p <= '9')
      {
	  consume_int (p, &p_end, &lat_m);
	  if (lat_m < 0 && lat_m >= 60)
	      return 0;
	  p = p_end;
      }
    else
	return 0;
    consume_blank (p, &p_end);
    p = p_end;
    if (check_min_delimiter (p, &p_end))
	p = p_end;
    else
	return 0;
    consume_blank (p, &p_end);
    p = p_end;
    if (*p >= '0' && *p <= '9')
      {
	  consume_float (p, &p_end, &lat_s);
	  if (lat_s < 0.0 && lat_s >= 60.0)
	      return 0;
	  p = p_end;
      }
    else
	return 0;
    consume_blank (p, &p_end);
    p = p_end;
    if (check_sec_delimiter (p, &p_end))
	p = p_end;
    else
	return 0;
    consume_blank (p, &p_end);
    p = p_end;
    if (lat_prefix == '\0')
      {
	  /* attempting to retrieve the prefix */
	  if (*p == 'S' || *p == 'N')
	    {
		lat_prefix = *p;
		p++;
	    }
	  else
	      return 0;
      }
    lt = (double) lat_d + ((double) lat_m / 60.0) + (lat_s / 3600.0);
    if (lat_prefix == 'S')
	lt *= -1.0;
    if (lt < -90.0 || lt > 90.0)
	return 0;

/* attempting to parse the longitude */
    consume_blank (p, &p_end);
    p = p_end;
    if (*p == 'E' || *p == 'W')
      {
	  long_prefix = *p;
	  p++;
	  consume_blank (p, &p_end);
	  p = p_end;
      }
    if (*p >= '0' && *p <= '9')
      {
	  consume_int (p, &p_end, &long_d);
	  if (long_d < 0 && long_d > 90)
	      return 0;
	  p = p_end;
      }
    else
	return 0;
    consume_blank (p, &p_end);
    p = p_end;
    if (check_deg_delimiter (p, &p_end))
	p = p_end;
    else
	return 0;
    consume_blank (p, &p_end);
    p = p_end;
    if (*p >= '0' && *p <= '9')
      {
	  consume_int (p, &p_end, &long_m);
	  if (long_m < 0 && long_m >= 60)
	      return 0;
	  p = p_end;
      }
    else
	return 0;
    consume_blank (p, &p_end);
    p = p_end;
    if (check_min_delimiter (p, &p_end))
	p = p_end;
    else
	return 0;
    consume_blank (p, &p_end);
    p = p_end;
    if (*p >= '0' && *p <= '9')
      {
	  consume_float (p, &p_end, &long_s);
	  if (long_s < 0.0 && long_s >= 60.0)
	      return 0;
	  p = p_end;
      }
    else
	return 0;
    consume_blank (p, &p_end);
    p = p_end;
    if (check_sec_delimiter (p, &p_end))
	p = p_end;
    else
	return 0;
    consume_blank (p, &p_end);
    p = p_end;
    if (long_prefix == '\0')
      {
	  /* attempting to retrieve the prefix */
	  if (*p == 'E' || *p == 'W')
	    {
		long_prefix = *p;
		p++;
	    }
	  else
	      return 0;
      }
    lg = (double) long_d + ((double) long_m / 60.0) + (long_s / 3600.0);
    if (long_prefix == 'W')
	lg *= -1.0;
    if (lg < -180.0 || lg > 180.0)
	return 0;

    *longitude = lg;
    *latitude = lt;
    return 1;
}