예제 #1
0
파일: rclex.c 프로젝트: ChrisG0x20/gdb
int
yylex (void)
{
  char *s;
  unichar *us;
  rc_uint_type length;
  int ch;

  /* Make sure that rclex_tok is initialized.  */
  if (! rclex_tok)
    rclex_tok_add_char (-1);

  do
    {
      do
	{
	  /* Clear token.  */
	  rclex_tok_pos = 0;
	  rclex_tok[0] = 0;

	  if ((ch = rclex_readch ()) == -1)
	    return -1;
	  if (ch == '\n')
	    ++rc_lineno;
	}
      while (ch <= 0x20);

      switch (ch)
	{
	case '#':
	  while ((ch = rclex_peekch ()) != -1 && ch != '\n')
	    rclex_readch ();
	  cpp_line ();
	  ch = IGNORED_TOKEN;
	  break;

	case '{':
	  ch = IGNORE_CPP (BEG);
	  break;

	case '}':
	  ch = IGNORE_CPP (END);
	  break;

	case '0': case '1': case '2': case '3': case '4':
	case '5': case '6': case '7': case '8': case '9':
	  yylval.i.val = read_digit (ch);
	  yylval.i.dword = 0;
	  switch (rclex_peekch ())
	    {
	    case 'l': case 'L':
	      rclex_readch ();
	      yylval.i.dword = 1;
	      break;
	    }
	  ch = IGNORE_CPP (NUMBER);
	  break;
	case '"':
	  rclex_string ();
	  ch = IGNORE_CPP ((! rcdata_mode ? QUOTEDSTRING : SIZEDSTRING));
	  if (ch == IGNORED_TOKEN)
	    break;
	  s = handle_quotes (&length);
	  if (! rcdata_mode)
	    yylval.s = s;
	  else
	    {
	      yylval.ss.length = length;
	      yylval.ss.s = s;
	  }
	  break;
	case 'L': case 'l':
	  if (rclex_peekch () == '"')
	    {
	      rclex_readch ();
	      rclex_string ();
	      ch = IGNORE_CPP ((! rcdata_mode ? QUOTEDUNISTRING : SIZEDUNISTRING));
	      if (ch == IGNORED_TOKEN)
		break;
	      us = handle_uniquotes (&length);
	      if (! rcdata_mode)
		yylval.uni = us;
	      else
	        {
		  yylval.suni.length = length;
		  yylval.suni.s = us;
	      }
	      break;
	    }
	  /* Fall through.  */
	default:
	  if (ISIDST (ch) || ch=='$')
	    {
	      while ((ch = rclex_peekch ()) != -1
		     && (ISIDNUM (ch) || ch == '$' || ch == '.'
		         || ch == ':' || ch == '\\' || ch == '/'
		         || ch == '_' || ch == '-')
		    )
		rclex_readch ();
	      ch = IGNORE_CPP (rclex_translatekeyword (rclex_tok));
	      if (ch == STRING)
		{
		  s = get_string (strlen (rclex_tok) + 1);
		  strcpy (s, rclex_tok);
		  yylval.s = s;
		}
	      else if (ch == BLOCK)
		{
		  const char *hs = NULL;

		  switch (yylex ())
		  {
		  case STRING:
		  case QUOTEDSTRING:
		    hs = yylval.s;
		    break;
		  case SIZEDSTRING:
		    hs = yylval.s = yylval.ss.s;
		    break;
		  }
		  if (! hs)
		    {
		      rcparse_warning ("BLOCK expects a string as argument.");
		      ch = IGNORED_TOKEN;
		    }
		  else if (! strcmp (hs, "StringFileInfo"))
		    ch = BLOCKSTRINGFILEINFO;
		  else if (! strcmp (hs, "VarFileInfo"))
		    ch = BLOCKVARFILEINFO;
		}
	      break;
	    }
	  ch = IGNORE_CPP (ch);
	  break;
	}
    }
  while (ch == IGNORED_TOKEN);

  return ch;
}
예제 #2
0
//
// overloaded version with no check and default
//
int read_digit(char *prompt) {
  return (read_digit(prompt, 0, 0, 9));
}
예제 #3
0
파일: ucci.c 프로젝트: StevenLOL/harmless
ucci_comm_enum idle_line(ucci_comm_struct *ucs_command)
{
    int i;
    char *line_str;
    ucci_comm_enum uce_return_value = UCCI_COMM_NONE;

    while (!line_input(command_line_str)) {
        idle();
    }

    line_str = command_line_str;

    if (strcmp(line_str, "isready") == 0) {
        /* isready */
        return UCCI_COMM_ISREADY;
    } else if (strncmp(line_str, "setoption ", 10) == 0) {
        /* setoption <option> [<arguments>] */
        line_str += 10;

        if (strncmp(line_str, "newgame", 7) == 0) {
            ucs_command->option.uo_type = UCCI_OPTION_NEWGAME;
        } else {
            ucs_command->option.uo_type = UCCI_OPTION_NONE;
        }

        return UCCI_COMM_SETOPTION;
    } else if (strncmp(line_str, "position ", 9) == 0) {
        /* position {<special_position> | fen <fen_string>} [moves <move_list>] */
        line_str += 9;

        if (strncmp(line_str, "fen ", 4) == 0) {
            ucs_command->position.fen_str = line_str + 4;
        } else {
            return UCCI_COMM_NONE;
        }

        line_str = strstr(line_str, " moves ");
        ucs_command->position.move_num = 0;

        if (line_str != NULL) {
            line_str += 7;
            ucs_command->position.move_num = ((strlen(line_str) + 1) / 5);

            for (i = 0; i < ucs_command->position.move_num; ++i) {
                coord_list[i] = *(long *) line_str;
                line_str += 5;
            }

            ucs_command->position.coord_list = coord_list;
        }

        return UCCI_COMM_POSITION;

    } else if(strncmp(line_str, "banmoves ", 9) == 0) {
        /* banmoves <move_list> */
        line_str += 9;
        ucs_command->ban_moves.move_num = ((strlen(line_str) + 1) / 5);

        for (i = 0; i < ucs_command->ban_moves.move_num; ++i) {
            coord_list[i] = *(long *) line_str;
            line_str += 5;
        }

        ucs_command->ban_moves.coord_list = coord_list;
        return UCCI_COMM_BANMOVES;

    } else if (strncmp(line_str, "go ", 3) == 0) {
        /* go [ponder] {infinite | depth <depth> | time <time> [movestogo <moves_to_go> | increment <inc_time>]} */
        line_str += 3;

        if (strncmp(line_str, "ponder ", 7) == 0) {
            line_str += 7;
            uce_return_value = UCCI_COMM_GOPONDER;
        } else if (strncmp(line_str, "draw ", 5) == 0) {
            line_str += 5;
        } else {
            uce_return_value = UCCI_COMM_GO;
        }

        if (strncmp(line_str, "time ", 5) == 0) {
            line_str += 5;
            ucs_command->search.depth_time.time = read_digit(line_str, 3600000);
        } else if (strncmp(line_str, "depth ", 6) == 0) {
            line_str += 6;
            ucs_command->search.ut_mode  = UCCI_TIME_DEPTH;
            ucs_command->search.depth_time.depth = read_digit(line_str, UCCI_MAX_DEPTH - 1);
        } else {
            ucs_command->search.ut_mode = UCCI_TIME_DEPTH;
            ucs_command->search.depth_time.depth = UCCI_MAX_DEPTH - 1;
        }

        return uce_return_value;

    } else if (strcmp(line_str, "stop") == 0) {
        /* stop */
        return UCCI_COMM_STOP;
    } else if (strcmp(line_str, "quit") == 0) {
        /* quit */
        return UCCI_COMM_QUIT;
    } else {
        return UCCI_COMM_NONE;
    }
}
예제 #4
0
//
// overloaded version with no check
//
int read_digit(char *prompt, int def) {
  return (read_digit(prompt, def, 0, 9));
}