Пример #1
0
/* Parse a structured stipulation (keyword sstipulation)
 * @param start index of entry into solving machinery
 * @return remainder of input token; 0 if parsing failed
 */
char *ParseStructuredStip(char *tok, slice_index start)
{
  slice_index const root_slice_hook = alloc_proxy_slice();
  Side starter;

  TraceFunctionEntry(__func__);
  TraceFunctionParam("%s",tok);
  TraceFunctionParam("%u",root_slice_hook);
  TraceFunctionParamListEnd();

  stipulation_reset();

  starter = ParseStructuredStip_starter(tok);
  if (starter!=no_side)
  {
    expression_type type;
    tok = ReadNextTokStr();
    tok = ParseStructuredStip_expression(tok,start,root_slice_hook,&type,0);
    if (tok==0)
      tok = ReadNextTokStr();
    else if (SLICE_NEXT1(root_slice_hook)!=no_slice)
    {
      solving_impose_starter(root_slice_hook,starter);
      move_effect_journal_do_insert_sstipulation(start,root_slice_hook);
    }
  }

  /* signal to our caller that the stipulation has changed */
  SLICE_STARTER(root_slice_hook) = no_side;

  TraceFunctionExit(__func__);
  TraceFunctionResult("%s",tok);
  TraceFunctionResultEnd();
  return tok;
}
Пример #2
0
char *ParseStip(char *tok, slice_index start)
{
    slice_index const root_slice_hook = alloc_proxy_slice();

    TraceFunctionEntry(__func__);
    TraceFunctionParam("%s",tok);
    TraceFunctionParam("%u",start);
    TraceFunctionParamListEnd();

    stipulation_reset();

    if (ParsePlay(tok,start,root_slice_hook,play_length_minimum))
    {
        move_effect_journal_do_insert_stipulation(start,root_slice_hook);
        tok = ReadNextTokStr();
    }
    else
        dealloc_slices(root_slice_hook);

    /* signal to our caller that the stipulation has changed */
    SLICE_STARTER(root_slice_hook) = no_side;

    TraceFunctionExit(__func__);
    TraceFunctionResult("%s",tok);
    TraceFunctionResultEnd();
    return tok;
}
Пример #3
0
static char *ParseLength(char *tok, stip_length_type *length)
{
    char *end;
    unsigned long tmp_length;

    TraceFunctionEntry(__func__);
    TraceFunctionParam("%s",tok);
    TraceFunctionParamListEnd();

    if (tok!=0 && *tok==0)
        /* allow white space before length, e.g. "dia 4" */
        tok = ReadNextTokStr();

    tmp_length = strtoul(tok,&end,10);
    TraceValue("%ld",tmp_length);
    TraceEOL();

    if (tok==end || tmp_length>UINT_MAX)
    {
        output_plaintext_input_error_message(WrongInt,0);
        tok = 0;
    }
    else
    {
        *length = tmp_length;
        tok = end;
    }

    TraceFunctionExit(__func__);
    TraceFunctionResult("%s",tok);
    TraceFunctionResultEnd();
    return tok;
}
Пример #4
0
/* Advance to next1 token while parsing a structured stipulation
 * @param tok current position in current token
 * @return tok, if we are within the current token; next1 token otherwise
 */
static char *ParseStructuredStip_skip_whitespace(char *tok)
{
  if (tok[0]==0)
  {
    tok = ReadNextTokStr();
    TraceValue("%s\n",tok);
  }

  return tok;
}
Пример #5
0
char *ParseSingleWalk(char *tok, piece_walk_type *result)
{
    switch (strlen(tok))
    {
    case 1:
        *result = GetPieNamIndex(tok[0],' ');
        return ReadNextTokStr();
        break;

    case 2:
        *result = GetPieNamIndex(tok[0],tok[1]);
        return ReadNextTokStr();
        break;

    default:
        *result = nr_piece_walks;
        return tok;
    }
}
Пример #6
0
void input_plaintext_detect_user_language(slice_index si)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  UserLanguage = detect_user_language(ReadNextTokStr());

  if (UserLanguage==LanguageCount)
    output_plaintext_input_error_message(NoBegOfProblem, 0);
  else
  {
    output_plaintext_select_language(UserLanguage);
    output_message_initialise_language(UserLanguage);

    pipe_solve_delegate(si);
  }

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Пример #7
0
char *ParsePieceFlags(Flags *flags)
{
    char *tok;

    while (true)
    {
        tok = ReadNextTokStr();

        {
            piece_flag_type const ps = GetUniqIndex(nr_piece_flags-nr_sides,PieSpTab,tok);
            if (ps==nr_piece_flags-nr_sides)
                break;
            else if (ps>nr_piece_flags-nr_sides)
                output_plaintext_input_error_message(PieSpecNotUniq,0);
            else
                SETFLAG(*flags,ps+nr_sides);
        }
    }

    return tok;
}
Пример #8
0
static char *ParsePieceWalkAndSquares(char *tok, Flags Spec, piece_addition_type type)
{
    unsigned int nr_walks_parsed = 0;

    TraceFunctionEntry(__func__);
    TraceFunctionParam("%s",tok);
    TraceFunctionParamListEnd();

    while (true)
    {
        piece_walk_type walk;
        char * const save_tok = tok;

        tok = ParsePieceWalk(tok,&walk);

        if (walk>=King)
        {
            piece_addition_settings settings = { walk, Spec, type};

            ++nr_walks_parsed;

            if (tok[0]==0)
            {
                /* the next token must be a valid square list, e.g. B a1b2
                 */
                char * const squares_tok = ReadNextTokStr();
                tok = ParseSquareList(squares_tok,&HandleAddedPiece,&settings);
                if (tok==squares_tok)
                    output_plaintext_input_error_message(MissngSquareList,0);
                else if (*tok!=0)
                    output_plaintext_error_message(WrongSquareList);
            }
            else
            {
                /* the remainder of the token may be
                 * * a valid square list, e.g. Ba1b2
                 * * the remainder of a different word e.g. Black
                 */
                if (*ParseSquareList(tok,&HandleAddedPiece,&settings)!=0)
                {
                    tok = save_tok;
                    break;
                }
            }

            tok = ReadNextTokStr();

            /* undocumented feature: "royal" only applies to the immediately next
             * piece indication because there can be at most 1 royal piece per side
             */
            CLRFLAG(Spec,Royal);
        }
        else
        {
            if (nr_walks_parsed==0)
            {
                output_plaintext_input_error_message(WrongPieceName,0);
                tok = ReadNextTokStr();
            }
            else
                tok = save_tok;

            break;
        }
    }

    TraceFunctionExit(__func__);
    TraceFunctionResult("%s",tok);
    TraceFunctionResultEnd();
    return tok;
}