Example #1
0
void repair(int argc, char *argv[]) {
    if (argc != 2) {
        printf("Please enter a filename.\n");
        return;
    }
    char capture_filename[128];
    char japanese_filename[128];
    char temp_filename[128];
    sprintf(capture_filename, "%s_capture.dat", argv[1]);
    sprintf(japanese_filename, "%s_japanese.dat", argv[1]);
    sprintf(temp_filename, "%s_temp.dat", argv[1]);


    solution sol_;
    solution *sol = &sol_;
    char *buffer = file_to_buffer(capture_filename);
    buffer = load_solution(sol, buffer, 1);
    print_state(sol->base_state);
    calculate_leaves(sol);

    solution solj_;
    solution *solj = &solj_;
    buffer = file_to_buffer(japanese_filename);
    buffer = load_solution(solj, buffer, 1);
    print_state(solj->base_state);
    solj->leaf_nodes = sol->leaf_nodes;

    FILE *f = fopen(temp_filename, "wb");
    save_solution(solj, f);
    fclose(f);
    printf("Done!\n");
}
Example #2
0
void
cat_eat(unsigned int bowlnumber, int eat_time)
{

  /* check the argument */
  if ((bowlnumber == 0) || ((int)bowlnumber > num_bowls)) {
    panic("cat_eat: invalid bowl number %d\n",bowlnumber);
  }

  /* check and update the simulation state to indicate that
   * the cat is now eating at the specified bowl */
  P(mutex);   // start critical section

  /* first check whether allowing this cat to eat will
   * violate any simulation requirements */
  if (bowls[bowlnumber-1] == 'c') {
    /* there is already a cat eating at the specified bowl */
    panic("cat_eat: attempt to make two cats eat from bowl %d!\n",bowlnumber);
  }
  if (eating_mice_count > 0) {
    /* there is already a mouse eating at some bowl */
    panic("cat_eat: attempt to make a cat eat while mice are eating!\n");
  }
  KASSERT(bowls[bowlnumber-1]=='-');
  KASSERT(eating_mice_count == 0);

  /* now update the state to indicate that the cat is eating */
  eating_cats_count += 1;
  bowls[bowlnumber-1] = 'c';

  /* print a summary of the current state */
  kprintf("cat_eat   (bowl %3d) start:  ",bowlnumber);
  print_state();
  kprintf("\n");

  V(mutex);  // end critical section

  /* simulate eating by introducing a delay
   * note that eating is not part of the critical section */
  clocksleep(eat_time);

  /* update the simulation state to indicate that
   * the cat is finished eating */
  P(mutex);  // start critical section

  KASSERT(eating_cats_count > 0);
  KASSERT(bowls[bowlnumber-1]=='c');
  eating_cats_count -= 1;
  bowls[bowlnumber-1]='-';

  /* print a summary of the current state */
  kprintf("cat_eat   (bowl %3d) finish: ",bowlnumber);
  print_state();
  kprintf("\n");
  
  V(mutex);  // end critical section

  return;
}
Example #3
0
void
mouse_eat(unsigned int bowlnumber, int eat_time, unsigned int mouse_num)
{
  /* check the bowl number */
  KASSERT(bowlnumber > 0);
  KASSERT((int)bowlnumber <= NumBowls);

  /* check and updated the simulation state to indicate that
   * the mouse is now eating at the specified bowl. */
  P(mutex);  // start critical section

  /* first check whether allowing this mouse to eat will
   * violate any simulation requirements */
  if (bowls[bowlnumber-1].animal == 'm') {
    /* there is already a mouse eating at the specified bowl */
    panic("mouse_eat: attempt to make mouse %d eat from bowl %d while mouse %d is there!\n",
           mouse_num, bowlnumber, bowls[bowlnumber-1].which);
  }
  if (eating_cats_count > 0) {
    /* there is already a cat eating at some bowl */
    panic("mouse_eat: attempt to make mouse %d eat while cats are eating!\n", mouse_num);
  }
  KASSERT(bowls[bowlnumber-1].animal=='-');
  KASSERT(bowls[bowlnumber-1].which==INVALID_ANIMAL_NUM);
  KASSERT(eating_cats_count == 0);

  /* now update the state to indicate that the mouse is eating */
  eating_mice_count += 1;
  bowls[bowlnumber-1].animal = 'm';
  bowls[bowlnumber-1].which = mouse_num;
  print_state();

  DEBUG(DB_SYNCPROB,"mouse %d starts to eat at bowl %d [%d:%d]\n",
	mouse_num,bowlnumber,eating_cats_count,eating_mice_count);
  V(mutex);  // end critical section

  /* simulate eating by introducing a delay
   * note that eating is not part of the critical section */
  clocksleep(eat_time);

  /* update the simulation state to indicate that
   * the mouse is finished eating */
  P(mutex); // start critical section

  KASSERT(eating_mice_count > 0);
  eating_mice_count -= 1;
  KASSERT(bowls[bowlnumber-1].animal=='m');
  KASSERT(bowls[bowlnumber-1].which==mouse_num);
  bowls[bowlnumber-1].animal='-';
  bowls[bowlnumber-1].which=INVALID_ANIMAL_NUM;
  print_state();

  DEBUG(DB_SYNCPROB,"mouse %d finishes eating at bowl %d [%d:%d]\n",
	mouse_num,bowlnumber,eating_cats_count,eating_mice_count);
  V(mutex);  // end critical section
  return;
}
Example #4
0
bool test_spiral_8()
{
    /* State:
     *
     * |LSB       MSB|
     * 1 1 1 1 1 1 1 1
     * 1 0 0 0 0 0 0 1
     * 1 1 1 1 1 1 0 1
     * 1 0 0 0 0 1 0 1
     * 1 0 1 1 0 1 0 1
     * 1 0 1 0 0 1 0 1
     * 1 0 1 1 1 1 0 1
     * 1 0 0 0 0 0 0 1
     * 1 1 1 1 1 1 1 1
     */
    
    /* Easier to put into hex
     *LSB                                       MSB
     * 1111 1111 1000 0001 1111 1101 1000 0101
     * 1011 0101 1010 0101 1011 1101 1000 0001
     * 1111 1111
     */

    uint32_t * state;

    const uint32_t expected_state[] = {
        0xa1bf81ff,
        0x81bda5ad,
        0xff
    };

    read_pbm("tests/pbm/spiral_8_start.pbm", &state, &state_width, &state_height, NULL);

    ints_per_state = ((state_width * state_height) / 32) + ((state_width * state_height)%32) > 0 ? 1 : 0;
    state_size = ints_per_state * 4;

    if (state_width != 8 && state_height != 9)
    {
        printf("width: %u, expected_width: %u\n", state_width, 8);
        printf("height: %u, expected_height: %u\n", state_height, 9);

        return false;
    }
    else if (!states_equal(state, expected_state))
    {
        puts("state read:");
        print_state(state);

        puts("state expected:");
        print_state(expected_state);

        return false;
    }

    return true;
}
Example #5
0
char finished_one_jump_all_ode(struct_all_ode *s, double t1) {
    int i;
    char ok;
    ok = s->time_second < t1;
    if (ok) {
        //    printf("simulating from t0=%.5e to t1=%.5e\n", s->time_second, t1);
    }
    while (s->time_second < t1) {
        s->status = gsl_odeiv_evolve_apply(s->e, s->c, s->s,
                &s->sys,
                &s->time_second, t1,
                &s->h, s->x);
        if (s->h > s->hmax) s->h = s->hmax;
        if (s->status == GSL_FAILURE) {
            s->x[s->NX - 1] = 0;
            if (s->mode == MODE_FLY_TO_SOL) {
                if (s->print_values_fly_to_sol) {
                    printf("passing from fly to sol at time t=%.5e\n", s->time_second);
                    print_state(s->x, NULL);
                    print_energies(s, s->x);

                }
                compute_fly_to_sol_percussion(s);
                if (s->print_values_fly_to_sol) {
                    printf("passed from fly to sol at time t=%.5e\n", s->time_second);
                    print_state(s->x, NULL);
                    print_energies(s, s->x);

                }
                s->mode = MODE_SOL;
            }
            if (s->mode == MODE_SOL_TO_FLY) {
                if (s->print_values_sol_to_fly) {
                    printf("passing from sol to fly at time t=%.5e\n", s->time_second);
                    print_state(s->x, NULL);
                    print_energies(s, s->x);

                }
                s->x[INDX_VX] = -sin(s->x[INDX_TH]) * s->x[INDX_VR];
                s->x[INDX_VZ] = cos(s->x[INDX_TH]) * s->x[INDX_VR];
                s->x[INDX_VR] = 0;
                s->x[INDX_R] = s->r0;
                if (s->print_values_sol_to_fly) {
                    printf("passed from sol to fly at time t=%.5e\n", s->time_second);
                    print_state(s->x, NULL);
                    print_energies(s, s->x);

                }
                return 1;
            }
        }
    }
    return 0;

}
int main (void) {
        state_t vec1, vec2, vec3;
        binding_t b;
        int i;
       
        srand(time(NULL));
        fprintf(stdout, "--- Debut\n");
       
        /* Creation du vecteur */
        vec1 = create_state();
        vec2 = create_state();
        vec3 = create_state();
       
        /* Remplissage */
        for (i=0; i<15; i++) {
                b.id = i;
                b.place = (int) rand() % 40;
                add_binding(&vec1, b);
                add_binding(&vec3, b);
        }
       
        /* Remplissage */
        for (i=0; i<15; i++) {
                b.id = i;
                b.place = (int) rand() % 40;
                add_binding(&vec2, b);
        }
       
        print_state(vec1);
        print_state(vec2);

        /* Suppression */
        for (i=0; i<10; i++) {
                int r = (int) rand() % 15;
                fprintf(stdout,"Suppression du %d\n",r);
                erase_binding(&vec1, find_binding(vec1,r));
                erase_binding(&vec3, find_binding(vec3,r));
        }

        /* Suppression */
        for (i=0; i<10; i++) {
                int r = (int) rand() % 15;
                fprintf(stdout,"Suppression du %d\n",r);
                erase_binding(&vec2, find_binding(vec2,r));
        }

        print_state(vec1);
        print_state(vec2);
       
        /* Comparaison */
        if (compare_states(&vec1, &vec2)) { fprintf(stdout, "VEC1 = VEC2\n"); } else { fprintf(stdout, "VEC1 != VEC2\n"); }
        if (compare_states(&vec1, &vec3)) { fprintf(stdout, "VEC1 = VEC3\n"); } else { fprintf(stdout, "VEC1 != VEC3\n"); }

        return 1;
}
Example #7
0
int main()
{
    state prev = to_state("00000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000");
    std::size_t steps = 25;

    print_state(prev);
    for (std::size_t i = 0; i < steps; ++i) {
        state curr = next_state(prev);
        print_state(curr);
        prev.swap(curr);
    }
    return 0;
}
Example #8
0
/** %jp{サンプルタスク} */
void Sample_Task(VP_INT exinf)
{
	int num;
	
	num = (int)exinf;
	
	/* %jp{いわゆる哲学者の食事の問題} */
	for ( ; ; )
	{
		/* %jp{適当な時間考える} */
		print_state(num, "thinking");
		rand_wait();
		
		/* %jp{左右のフォークを取るまでループ} */
		for ( ; ; )
		{
			/* %jp{左から順に取る} */
			wai_sem(LEFT(num));
			if ( pol_sem(RIGHT(num)) == E_OK )
			{
				break;	/* %jp{両方取れた} */
			}
			sig_sem(LEFT(num));	/* %jp{取れなければ離す} */
			
			/* %jp{適当な時間待つ} */
			print_state(num, "hungry");
			rand_wait();

			/* %jp{右から順に取る} */
			wai_sem(RIGHT(num));
			if ( pol_sem(LEFT(num)) == E_OK )
			{
				break;	/* %jp{両方取れた} */
			}
			sig_sem(RIGHT(num));	/* %jp{取れなければ離す} */

			/* %jp{適当な時間待つ} */
			print_state(num, "hungry");
			rand_wait();
		}
		
		/* %jp{適当な時間、食べる} */
		print_state(num, "eating");
		rand_wait();
		
		/* %jp{フォークを置く} */
		sig_sem(LEFT(num));
		sig_sem(RIGHT(num));
	}
}
int main(int argc, char** argv)
{
    srand(time(NULL));

    initialize_state();

    initialize_timer();

    print_state(stdout, 1.0f);
    printf("Score: %d\n", game_state.score);

    char input;

    double dTime = 0;
    while (1)
    {
        dTime += get_elapsed_time();
        if (dTime > 1)
        {
            printf("Tick.\n");
            dTime -= 1;
        }
    }

    while (input = getchar())
    {
        switch (input)
        {
        case 'D':
            if (move_down()) return 0;
            break;
        case 'G':
            if (gravity_tick()) return 0;
            break;
        case 'L':
            move_left();
            break;
        case 'R':
            move_right();
            break;
        case 'U':
            rotate();
            break;
        }
        print_state(stdout, 1.0f);
        printf("Score: %d\n", game_state.score);
    }

    return 0;
}
/**
 * Computer vs computer
 *
 * The computer plays itself
 * @param string for filename
 * @param agent_color
 * @return 1 if black wins, else return 0
 */
int computer_vs_computer( char *file, char agent_color )
{
    char board[ SIZE ][ SIZE ];

    /* set up board */
    setup_board(file,board);

    /* create a new state */
    struct State * state = new_state( board, 'B' );
    struct State * temp_state;

    /* start game */
    print_state( state );
    temp_state = computer_player_first( state );
    Free( state, sizeof( struct State ) );
    state = temp_state;

    /* second move */
    printf( "\n" );
    print_state( state );
    temp_state = computer_player_second( state );
    Free( state, sizeof( struct State ) );
    state = temp_state;

    /* regular game */
    for( ;; )
    {
        printf( "\n" );
        print_state( state );

        //printf( "\n>> Mem usage before: %lu\n", memory_usage() );
        temp_state = computer_player( state );
        Free( state, sizeof( struct State ) );
        state = temp_state;
        //printf( "\n>> Mem usage after: %lu\n", memory_usage() );

        if( terminal_test( state ) == 1 )
        {
            printf( "\n" );
            print_state( state );
            printf( "\nNo moves left!... \n" );
            printf( "\n%c wins!!!\n", opposite_player( state->player ) );
            Free( state, sizeof( struct State ) );
            break;
        }
    }

    return opposite_player( state->player ) == 'B';
}
Example #11
0
int main( int argc, char **argv )
{
// VARIABLES FOR INPUT
    char str[ MAX_LINE_LENGTH +1 ] ;
    ssize_t nchars; 
    state_t state; // state_t is defined by the PSVN API. It is the type used for individual states.

// VARIABLES FOR ITERATING THROUGH state's SUCCESSORS
    state_t child;
    ruleid_iterator_t iter; // ruleid_terator_t is the type defined by the PSVN API successor/predecessor iterators.
    int ruleid ; // an iterator returns a number identifying a rule
    int childCount;

// READ A LINE OF INPUT FROM stdin
    printf("Please enter a state followed by ENTER: ");
    if ( fgets(str, sizeof str, stdin) == NULL ) {
	printf("Error: empty input line.\n");
	return 0; 
    }

// CONVERT THE STRING TO A STATE
    nchars = read_state( str, &state );
    if (nchars <= 0) {
	printf("Error: invalid state entered.\n");
	return 0; 
    }

    printf("The state you entered is: ");
    print_state( stdout, &state );
    printf("\n");

// LOOP THOUGH THE CHILDREN ONE BY ONE
    childCount = 0;
    init_fwd_iter( &iter, &state );  // initialize the child iterator 
      while( ( ruleid = next_ruleid( &iter ) ) >= 0 ) {
//    while( -1 >= 0 ) {
	apply_fwd_rule( ruleid, &state, &child );
	++childCount;
    	printf("child %d. ",childCount);
	print_state( stdout, &child );
    	//printf("  %s (cost %d)\n",get_fwd_rule_label(ruleid),get_fwd_rule_cost(ruleid));
    	printf("  %s (cost %d), goal=%d\n",get_fwd_rule_label(ruleid),get_fwd_rule_cost(ruleid),is_goal(&child));
    } // end while... no more children
    if (childCount == 0) {
	printf("Your state has no children.\n");
    }

    return 0;
} // end main
Example #12
0
bool test_61c()
{
    /* State:
     *
     * |LSB                         MSB|
     * 1 1 1 0 1 1 1 0 1 0 0 0 1 0 1 1 1
     * 1 0 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0
     * 1 0 0 0 1 1 1 0 1 1 1 0 1 0 1 0 0
     * 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0
     * 1 1 1 0 1 1 1 0 1 1 1 0 1 0 1 1 1
     */
/* This is to make it easier to put into hex
1110 1110 1000 1011 1100 0100 0100 0101
0010 0011 1011 1010 1001 0000 0101 0101
0100 1110 1110 1110 1011 1
 */
    uint32_t * state;

    const uint32_t expected_state[] = {
        0xa223d177,
        0xaa095dc4,
        0x1d7772
    };

    read_pbm("tests/pbm/61c_end.pbm", &state, &state_width, &state_height, NULL);

    ints_per_state = ((state_width * state_height) / 32) + ((state_width * state_height)%32) > 0 ? 1 : 0;
    state_size = ints_per_state * 4;

    if (state_width != 17 && state_height != 5)
    {
        printf("width: %u, expected_width: %u\n", state_width, 17);
        printf("height: %u, expected_height: %u\n", state_height, 5);

        return false;
    }
    else if (!states_equal(state, expected_state))
    {
        puts("state read:");
        print_state(state);

        puts("state expected:");
        print_state(expected_state);

        return false;
    }

    return true;
}
Example #13
0
lexeme *st_one_two_sym_lex(lexer_info *linfo, buffer *buf)
{
    lexeme *lex = NULL;

#ifdef LEXER_DEBUG
    print_state("ST_ONE_TWO_SYM_LEX", linfo->c);
#endif

    if (buf->count_sym == 0) {
        add_to_buffer(buf, linfo->c);
        deferred_get_char(linfo);
    } else if (buf->count_sym == 1) {
        /* TODO: make it more pretty */
        char prev_c = get_last_from_buffer(buf);
        clear_buffer(buf);
        switch (prev_c) {
        case '>':
            lex = (prev_c == linfo->c) ?
                make_lex(LEX_APPEND) :
                make_lex(LEX_OUTPUT);
            break;
        case '|':
            lex = (prev_c == linfo->c) ?
                make_lex(LEX_OR) :
                make_lex(LEX_PIPE);
            break;
        case '&':
            lex = (prev_c == linfo->c) ?
                make_lex(LEX_AND) :
                make_lex(LEX_BACKGROUND);
            break;
        default:
            fprintf(stderr, "Lexer: error (type 1) in ST_ONE_TWO_SYM_LEX;");
            print_state("ST_ONE_TWO_SYM_LEX", linfo->c);
            exit(ES_LEXER_INCURABLE_ERROR);
        }
        if (prev_c == linfo->c)
            deferred_get_char(linfo);
        linfo->state = ST_START;
        return lex;
    } else {
        fprintf(stderr, "Lexer: error (type 2) in ST_ONE_TWO_SYM_LEX;");
        print_state("ST_ONE_TWO_SYM_LEX", linfo->c);
        exit(ES_LEXER_INCURABLE_ERROR);
    }

    return lex;
}
Example #14
0
void
print_results (void)
{
  state_number i;

  /* We used to use just .out if SPEC_NAME_PREFIX (-p) was used, but
     that conflicts with Posix.  */
  FILE *out = xfopen (spec_verbose_file, "w");

  reduce_output (out);
  grammar_rules_partial_print (out,
			       _("Rules never reduced"), rule_never_reduced_p);
  conflicts_output (out);

  print_grammar (out);

  /* If the whole state item sets, not only the kernels, are wanted,
     `closure' will be run, which needs memory allocation/deallocation.   */
  if (report_flag & report_itemsets)
    new_closure (nritems);
  /* Storage for print_reductions.  */
  shift_set =  bitset_create (ntokens, BITSET_FIXED);
  look_ahead_set = bitset_create (ntokens, BITSET_FIXED);
  for (i = 0; i < nstates; i++)
    print_state (out, states[i]);
  bitset_free (shift_set);
  bitset_free (look_ahead_set);
  if (report_flag & report_itemsets)
    free_closure ();

  xfclose (out);
}
Example #15
0
static void change_state(int *state, int new_state, int depth){
  *state = new_state;
  if(DEBUG == TRUE){
    print_state(*state, depth);
    fflush(stdout);
  }
}
Example #16
0
static MRS_INLINE void mrs_decrypt_lastblock(mrs_state_t state, unsigned char * out, const unsigned char * in, size_t inlen)
{
    size_t i;
    mrs_word_t * S = state->S;
    uint8_t lastblock[BYTES(MRS_R)];
    mrs_permute(state);
    for(i = 0; i < WORDS(MRS_R); ++i)
    {
        STORE(lastblock + i * BYTES(MRS_W), S[i]);
    }

    /* undo padding */
    memcpy(lastblock, in, inlen);
    /*lastblock[inlen] ^= 0x01;
    lastblock[BYTES(MRS_R) - 1] ^= 0x80;*/

    for (i = 0; i < WORDS(MRS_R); ++i)
    {
        const mrs_word_t c = LOAD(lastblock + i * BYTES(MRS_W));
        STORE(lastblock + i * BYTES(MRS_W), S[i] ^ c);
        S[i] = c;
    }
    memcpy(out, lastblock, inlen);

#if defined(MRS_DEBUG)
    printf("DECRYPTING LASTBLOCK:\n");
    print_bytes(lastblock, BYTES(MRS_R));
    printf("STATE:\n");
    print_state(state->S);
#endif

    burn(lastblock, 0, sizeof lastblock);
}
Example #17
0
void mrs_finalise(mrs_state_t state, size_t hlen, size_t mlen, unsigned char * tag)
{
    mrs_word_t * S = state->S;
    uint8_t lastblock[BYTES(MRS_R)];
    size_t i;

    /* finalise state */
    mrs_permute(state);

    S[0] ^= hlen;
    S[1] ^= mlen;

    mrs_permute(state);

    /* extract tag */
    for (i = 0; i < WORDS(MRS_R); ++i)
    {
        STORE(lastblock + i * BYTES(MRS_W), S[i]);
    }
    memcpy(tag, lastblock, BYTES(MRS_T));

#if defined(MRS_DEBUG)
    printf("FINALISED:\n");
    print_state(state->S);
#endif

    burn(lastblock, 0, BYTES(MRS_R));
}
Example #18
0
int main (int argc, char **argv)
{
    FILE * gcodeFile;
    char lineBuffer[1024];
    char * lineBufferPointer = &lineBuffer[0];
    GCODE_STATE previous_command; //stores the previous gcode command
    GCODE_STATE current_command; //stores the next gcode command
    init_gcode_state(&previous_command);
    init_gcode_state(&current_command);

    gcodeFile = fopen("test.gcode","r");
    if(gcodeFile == NULL){
        printf("Error: file dosen't exist");
        return -1;
    }

    printf ("GCode interpreter test\n");
    while(fgets(lineBuffer, 1024, gcodeFile) != NULL){
        //reset the line buffer pointer to the start of the line
        lineBufferPointer = &lineBuffer[0]; 
        previous_command = current_command;
        current_command = parse_gcode(lineBufferPointer);
        print_state(current_command);

    }

    fclose(gcodeFile);
    return 0;  // make sure your main returns int
}
Example #19
0
int serve_client(const int client) {
    state s_;
    state *s = &s_;
    int action = -1;
    if (read(client, (void*) &action, sizeof(int)) != sizeof(int)) {
        return READ_ERROR;
    }
    if (action == ACTION_LIST_SOLUTIONS) {
        WRITE(client, &num_solutions, sizeof(int));
        for (int i = 0; i < num_solutions; i++) {
            WRITE(client, sols[i]->base_state, SIZE_OF_STATE);
            int num_layers = (int)(sols[i]->num_layers);
            WRITE(client, &num_layers, sizeof(int));
            int name_len = strlen(solution_names[i]);
            WRITE(client, &name_len, sizeof(int));
            WRITE(client,solution_names[i], name_len * sizeof(char));
        }
        return SOLUTION_FOUND;
    }
    else if (action == ACTION_QUERY_STATE) {
        if (read(client, (void*) s, SIZE_OF_STATE) != SIZE_OF_STATE) {
            return READ_ERROR;
        }
        #ifdef DEBUG
            print_state(s);
            repr_state(s);
        #endif
        return query_state(client, s);
    }
    return ERROR_INVALID_ACTION;
}
Example #20
0
int main() {
  int rc = 0, cycle = 0;
  IAvoid_reset(&output);
  input.obstacle_detected = 0;
  input.latence1 = 2;
  input.latence2 = 3;
  input.latence3 = 4;
  input.latence4 = 5;
    
  while (1) {
    IAvoid(&input,&output);
    print_state(output);
    usleep(1000000);
    cycle++;
    if (cycle == 3) {
      input.obstacle_detected = 1;
    }

    if (output.stop && !output.up) {
      rc = 0;
    }

    if (output.up == 1) {
      rc = cycle;
      printf("rc %d\n",rc);
      input.obstacle_detected = 0;
    }
    
  }

  return 0;
}
Example #21
0
void verbose(void)
{
    register int i;

    if (!vflag)
	return xml_output();
    
	
	/* else */
    null_rules = (short *)MALLOC(nrules * sizeof(short));
    if (null_rules == 0)
	no_space();
    fprintf(verbose_file, "\f\n");
    for (i = 0; i < nstates; i++)
	print_state(i);
    FREE(null_rules);

    if (nunused)
	log_unused();
    if (SRtotal || RRtotal)
	log_conflicts();

    fprintf(verbose_file, "\n\n%d terminals, %d nonterminals\n", ntokens,
	    nvars);
    fprintf(verbose_file, "%d grammar rules, %d states\n", nrules - 2, nstates);
}
Example #22
0
void
verbose(void)
{
	int i;

	if (!vflag)
		return;

	null_rules = malloc(nrules * sizeof(short));
	if (null_rules == NULL)
		no_space();
	fprintf(verbose_file, "\f\n");
	for (i = 0; i < nstates; i++)
		print_state(i);
	free(null_rules);

	if (nunused)
		log_unused();
	if (SRtotal || RRtotal)
		log_conflicts();

	fprintf(verbose_file, "\n\n%d terminals, %d nonterminals\n", ntokens,
	    nvars);
	fprintf(verbose_file, "%d grammar rules, %d states\n", nrules - 2,
	    nstates);
}
Example #23
0
hcerr_t close_tag(int *i, simple_xml_parser *parser){
  char *tag = token_finish(&parser->buffer_list);

  if (parser->start_tag == TRUE){
    if (DEBUG == TRUE)
      fprintf(stdout, "End Start  element: %s\n", tag);
    require_ok((*parser->start_element_callback)(tag, 
						 parser->data,
						 parser->attribute_names,
						 parser->attribute_values,
						 parser->current_attribute));
    parser->current_attribute = 0;
    parser->depth++;
    change_state(&parser->state, OUTSIDE_ELEMENT, parser->depth);
    if (DEBUG == TRUE)	    
      print_state(parser->state, parser->depth);
  }
  else{
    if (DEBUG == TRUE)
      fprintf(stdout, "End Close element: %s\n", tag);
    require_ok((*parser->end_element_callback)(tag, parser->data));
    /* --> release string buffers */
    parser->depth--;
    change_state(&parser->state, OUTSIDE_ELEMENT, parser->depth);
  }
  return HCERR_OK;
}
Example #24
0
void test_vector_magnitudes() {
    printf("Testing vector magnitudes...\n");
    TestStats stats = test_stats();
    Vector test_vector;
    double computed;

    test_vector = zeroes(0);
    computed = vector_mag(&test_vector);
    assert_double(&stats, 0, computed,
            "Zero element vectors should have zero magnitude");

    int i;
    for (i = -1; i < 3; i++) {
        test_vector = linear(1, i, 0);
        computed = vector_mag(&test_vector);
        assert_double(&stats, abs(i), computed, 
                "One element vectors must have magnitude equal to their element.");
    }

    double quad_a[4] = {-.4, 0, .6, 1.2};
    Vector quad = { 4, &quad_a[0] };
    computed = vector_mag(&quad);
    assert_double(&stats, 1.4, computed,
            "Incorrectly computed vector magnitude");

    print_state(&stats);
}
/* Saves the matchinfo in parsable form to stdout. */
static void save(const struct ip6t_ip6 *ip, const struct ip6t_entry_match *match)
{
	struct ipt_state_info *sinfo = (struct ipt_state_info *)match->data;

	printf("--state ");
	print_state(sinfo->statemask);
}
Example #26
0
lexeme *st_in_quotes(lexer_info *linfo, buffer *buf)
{
#ifdef LEXER_DEBUG
    print_state("ST_IN_QUOTES", linfo->c);
#endif

    switch (linfo->c) {
    case EOF:
        linfo->state = ST_ERROR;
        return NULL;
    case '\\':
        deferred_get_char(linfo);
        linfo->state = ST_BACKSLASH_IN_QUOTES;
        break;
    case '\"':
        deferred_get_char(linfo);
        linfo->state = ST_WORD;
        break;
    case '\n':
        print_prompt2();
        /* fallthrough */
    default:
        add_to_buffer(buf, linfo->c);
        deferred_get_char(linfo);
        break;
    }

    return NULL;
}
Example #27
0
static void log_state(const char * message,
                      int num_joints,
                      STATE *state) {
  STRING segstate;
  print_state(state, num_joints, &segstate);
  tprintf("%20s [%40s]\n", message, segstate.string());
}
Example #28
0
void verbose(void)
{
    register int i;

    if (!vflag) return;

    null_rules = (Yshort *) NEW2(nrules, null_rules[0]);
    if (null_rules == 0) no_space();

    BtYacc_puts("\f\n", verbose_file);

    for (i = 0; i < nstates; ++i)
        print_state(i);
    FREE(null_rules);

    if (nunused)
        log_unused();
    if (SRtotal || RRtotal)
        log_conflicts();

    print_tokens();

    BtYacc_printf(verbose_file, "\n\n%d terminals, %d nonterminals\n%d grammar rules, %d states\n",
                  ntokens, nvars, nrules - 2, nstates);
}
Example #29
0
void
verbose(void)
{
    int i;

    if (!vflag)
	return;

    null_rules = (short *)MALLOC((unsigned)nrules * sizeof(short));
    NO_SPACE(null_rules);

    fprintf(verbose_file, "\f\n");
    for (i = 0; i < nstates; i++)
	print_state(i);
    FREE(null_rules);

    if (nunused)
	log_unused();
    if (SRtotal || RRtotal)
	log_conflicts();

    fprintf(verbose_file, "\n\n%d terminals, %d nonterminals\n", ntokens,
	    nvars);
    fprintf(verbose_file, "%d grammar rules, %d states\n", nrules - 2, nstates);
}
Example #30
0
        /* virtual */ void
        window::frame_render_one()
        {
          TRACE("platform::glx::window::test::window::frame_render_one");

          duration const now(timer_.lapse());

          if (duration_ < now) {
            close();
          } else {
            namespace sc = std::chrono;
        
            std::ostringstream ostr;

            ostr << title_orig_
                 << " ["
                 << std::fixed << std::right << std::setfill(' ') << sc::duration_fmt(sc::symbol)
                 << sc::duration_cast<sc::duration<double>>(duration_ - now)
                 << ']';

            title = ostr.str();
      
            print_state();
          }
        }