예제 #1
0
path
edit_cursor_rep::make_cursor_accessible (path p, bool forwards) {
  //time_t t1= texmacs_time ();
  path start_p= p;
  bool inverse= false;
  int old_mode= get_access_mode ();
  if (get_init_string (MODE) == "src")
    set_access_mode (DRD_ACCESS_SOURCE);
  while (!is_accessible_cursor (et, p) && !in_source ()) {
    path pp;
    ASSERT (rp <= p, "path outside document");
    p= rp * closest_inside (subtree (et, rp), p / rp);
    if (forwards ^ inverse)
      pp= rp * next_valid (subtree (et, rp), p / rp);
    else
      pp= rp * previous_valid (subtree (et, rp), p / rp);
    if (pp == p) {
      if (inverse) break;
      else { p= start_p; inverse= true; }
    }
    else p= pp;
  }
  set_access_mode (old_mode);
  //time_t t2= texmacs_time ();
  //if (t2-t1 >= 1) cout << "made_cursor_accessible took " << t2-t1 << "ms\n";
  return p;
}
예제 #2
0
파일: 11.c 프로젝트: Nidjo123/AdventOfCode
int main(void) {
	int i;
	char password[LENGTH + 1];

	scanf("%s", password);
	
	for (i = 0; i < TIMES_EXPIRED; i++) {
		next_valid(password);
		printf("%s\n", password);
	}
	
	return 0;
}
예제 #3
0
파일: main.c 프로젝트: bolhoso/uva-problems
int main () {
  char buf[MAX];

  do {
    /* Read, strip \n and check for the end # */
    fgets (buf, 50, stdin);
    buf[strlen(buf)-1] = '\0';
    if (strcmp (buf, EOF_SEQUENCE) == 0) {
      return 0;
    }

    char *s = next_valid (buf);
    if (!s) {
      printf ("No Successor\n");
    } else {
      printf ("%s\n", s);
    }
  } while (1);

  return 0;
}
예제 #4
0
static void parse_number(struct context_t *ctx, struct lexem_t *lexem)
{
    locate_lexem(lexem, ctx);
    /* check base */
    int base = 10;
    if(cur_char(ctx) == '0' && next_valid(ctx, 1) && next_char(ctx, 1) == 'x')
    {
        advance(ctx, 2);
        base = 16;
    }

    lexem->type = LEX_NUMBER;
    lexem->num = 0;
    while(!eof(ctx) && isxdigit(cur_char(ctx)))
    {
        if(base == 10 && !isdigit(cur_char(ctx)))
            break;
        byte v;
        if(convxdigit(cur_char(ctx), &v))
            break;
        lexem->num = base * lexem->num + v;
        advance(ctx, 1);
    }
}
예제 #5
0
static void next_lexem(struct context_t *ctx, struct lexem_t *lexem)
{
    #define ret_simple(t, adv) \
        do {locate_lexem(lexem, ctx); \
            lexem->type = t; \
            advance(ctx, adv); \
            return;} while(0)
    while(!eof(ctx))
    {
        char c = cur_char(ctx);
        /* skip whitespace */
        if(c == ' ' || c == '\t' || c == '\n' || c == '\r')
        {
            advance(ctx, 1);
            continue;
        }
        /* skip C++ style comments */
        if(c == '/' && next_valid(ctx, 1) && next_char(ctx, 1) == '/')
        {
            while(!eof(ctx) && cur_char(ctx) != '\n')
                advance(ctx, 1);
            continue;
        }
        /* skip C-style comments */
        if(c == '/' && next_valid(ctx, 1) && next_char(ctx, 1) == '*')
        {
            advance(ctx, 2);
            while(true)
            {
                if(!next_valid(ctx, 1))
                    parse_error(ctx, "Unterminated comment");
                if(cur_char(ctx) == '*' && next_char(ctx, 1) == '/')
                {
                    advance(ctx, 2);
                    break;
                }
                advance(ctx, 1);
            }
            continue;
        }
        break;
    }
    if(eof(ctx)) ret_simple(LEX_EOF, 0);
    char c = cur_char(ctx);
    bool nv = next_valid(ctx, 1);
    char nc = nv  ? next_char(ctx, 1) : 0;
    if(c == '(') ret_simple(LEX_LPAREN, 1);
    if(c == ')') ret_simple(LEX_RPAREN, 1);
    if(c == '{') ret_simple(LEX_LBRACE, 1);
    if(c == '}') ret_simple(LEX_RBRACE, 1);
    if(c == '>') ret_simple(LEX_RANGLE, 1);
    if(c == '=') ret_simple(LEX_EQUAL, 1);
    if(c == ';') ret_simple(LEX_SEMICOLON, 1);
    if(c == ',') ret_simple(LEX_COLON, 1);
    if(c == '|') ret_simple(LEX_OR, 1);
    if(c == '<' && nv && nc == '<') ret_simple(LEX_LSHIFT, 2);
    if(c == '<' && nv && nc == '=') ret_simple(LEX_LE, 2);
    if(c == '"') return parse_string(ctx, lexem);
    if(c == '\'') return parse_ascii_number(ctx, lexem);
    if(isdigit(c)) return parse_number(ctx, lexem);
    if(isalpha(c) || c == '_') return parse_identifier(ctx, lexem);
    parse_error(ctx, "Unexpected character '%c'\n", c);
    #undef ret_simple
}