Esempio n. 1
0
// the index is the point, from which the next num_lines entries are shown
void kdebug_dump_trace() {

    printf("Dump Trace: [Exception/Ipc/Pf]\n");///All] ");
    char type;
    type = getc();

    trace_element *tmp;

#if defined(CONFIG_DEBUGGER_IO_OUTSCRN)

    // the last element in the buffer
    tmp = current_trace_pos->prev;

    while (i<NUM_LINES) {
	if (tmp->type == type) {
	    i++;
	}
	tmp = tmp->prev;
    }

//navigation in the buffer is still mising. (Next/Prev)
    for (int i=0; i<NUM_LINES; i++) {
	if (tmp->type == type) {
	    if ( is_restricted(tmp->raw[0], tmp->raw[3], tmp->type)) {
		dump_trace_element(tmp);
	    }
	    tmp = tmp->next;
	}
    }

#else /* CONFIG_DEBUGGER_OUT_IO_OUTCOM */

    tmp = start_trace_pos;

    if (tmp->type != 'u') {
	// there is somthing in the buffer
	do {
	    if (tmp->type == type) {
		if ( is_restricted(tmp->raw[0], tmp->raw[3], tmp->type)) {
		    dump_trace_element(tmp);
		}
	    }
	    tmp = tmp->next;
	} while (tmp != current_trace_pos);
    }
    else {
	printf("The buffer is empty.\n");
    }
#endif    
}
Esempio n. 2
0
int main(void)
{
	char car_num_str[8] = "A23456";
	int tail_num = 0;	// "A23456" -> 6
	enum day today;	// 1-7
	char last_char;
	int ret;
	
	printf("Please input your car number:\n");
	scanf("%s", car_num_str);	

	printf("car num is %s\n", car_num_str);
	
	/* get the last char of car number string */
	last_char = get_last_char(car_num_str);
	printf("last char is %c\n", last_char);

	tail_num = last_char - '0';
	//today = MONDAY;
	//today = FRIDAY;
	today = get_week_day(2013, 12, 31);
	printf("today is day %d\n", today);

	ret = is_restricted(tail_num, today);
	if (ret == 1)
		printf("restricted!\n");
	else
		printf("NOT restricted!\n");
		

	return 0;
}
Esempio n. 3
0
static VALUE protected_tidy_bytes(VALUE arg) {
  struct protected_tidy_bytes_arg* args = (struct protected_tidy_bytes_arg *)arg;
  VALUE string = args->string;
  uint8_t *arr = args->arr;

  int conts_expected = 0;
  int i, j;
  uint8_t byte;

  uint8_t *curr = arr;
  uint8_t *last_lead = curr;

  int did_write = 0;

  for (i = 0; i < RSTRING_LEN(string) ; i++) {
    byte = RSTRING_PTR(string)[i];
    curr[0] = byte;
    did_write = 0;

    if (is_unused(byte) || is_restricted(byte)) {
      curr = tidy_byte2(byte, curr);
      did_write = 1;
    } else if (is_cont(byte)) {
      if (conts_expected == 0) {
        curr = tidy_byte2(byte, curr);
        did_write = 1;
      } else {
        conts_expected--;
      }
    } else {
      if (conts_expected > 0) {
        int start_index = last_lead-arr;
        int end_index = curr-arr;
        int len = end_index - start_index;

        uint8_t temp[len];
        for (j = 0; j < len; j++) {
          temp[j] = arr[start_index + j];
        }

        curr = arr + start_index;
        for (j = 0; j < len; j++) {
          curr = tidy_byte2(temp[j], curr);
        }

        conts_expected = 0;
      }
      if (is_lead(byte)) {
        if (i == RSTRING_LEN(string) - 1) {
          curr = tidy_byte2(byte, curr);
          did_write = 1;
        } else {
          if (byte < 224) {
            conts_expected = 1;
          } else if (byte < 240) {
            conts_expected = 2;
          } else {
            conts_expected = 3;
          }
          last_lead = curr;
        }
      }
    }
    if (!did_write) {
      *curr++ = byte;
    }
  }
  VALUE str = rb_str_new((const char *)arr, curr-arr);
  return rb_funcall(str, idForceEncoding, 1, rb_str_new2("UTF-8"));
}
   void release_escrow_operation::evaluate( transaction_evaluation_state& eval_state )
   { try {
      FC_ASSERT( !"This operation is not enabled yet!" );

      auto escrow_balance_record = eval_state._current_state->get_balance_record( this->escrow_id );
      FC_ASSERT( escrow_balance_record.valid() );

      if( !eval_state.check_signature( this->released_by ) )
         FC_ASSERT( !"transaction not signed by releasor" );

      auto escrow_condition = escrow_balance_record->condition.as<withdraw_with_escrow>();
      auto total_released = amount_to_sender + amount_to_receiver;

      FC_ASSERT( total_released <= escrow_balance_record->balance );
      FC_ASSERT( total_released >= amount_to_sender ); // check for addition overflow

      escrow_balance_record->balance -= total_released;
      auto asset_rec = eval_state._current_state->get_asset_record( escrow_balance_record->condition.asset_id );
      if( asset_rec->is_restricted() )
      {
         FC_ASSERT( eval_state._current_state->get_authorization( escrow_balance_record->condition.asset_id, escrow_condition.receiver ) );
      }
      if( asset_rec->is_retractable() )
      {
         if( eval_state.verify_authority( asset_rec->authority ) )
         {
            //
         }
      }

      if( escrow_condition.sender == this->released_by )
      {
         FC_ASSERT( amount_to_sender == 0 );
         FC_ASSERT( amount_to_receiver <= escrow_balance_record->balance );

         if( !eval_state.check_signature( escrow_condition.sender ) )
             FC_CAPTURE_AND_THROW( missing_signature, (escrow_condition.sender) );

         balance_record new_balance_record( escrow_condition.receiver,
                                            asset( amount_to_receiver, escrow_balance_record->asset_id() ),
                                            escrow_balance_record->slate_id() );
         auto current_receiver_balance = eval_state._current_state->get_balance_record( new_balance_record.id());

         if( current_receiver_balance )
            current_receiver_balance->balance += amount_to_receiver;
         else
            current_receiver_balance = new_balance_record;

          eval_state._current_state->store_balance_record( *current_receiver_balance );
      }
      else if( escrow_condition.receiver == this->released_by )
      {
         FC_ASSERT( amount_to_receiver == 0 );
         FC_ASSERT( amount_to_sender <= escrow_balance_record->balance );

         if( !eval_state.check_signature( escrow_condition.receiver ) )
             FC_CAPTURE_AND_THROW( missing_signature, (escrow_condition.receiver) );

         balance_record new_balance_record( escrow_condition.sender,
                                            asset( amount_to_sender, escrow_balance_record->asset_id() ),
                                            escrow_balance_record->slate_id() );
         auto current_sender_balance = eval_state._current_state->get_balance_record( new_balance_record.id());

         if( current_sender_balance )
            current_sender_balance->balance += amount_to_sender;
         else
            current_sender_balance = new_balance_record;

         eval_state._current_state->store_balance_record( *current_sender_balance );
      }
      else if( escrow_condition.escrow == this->released_by )
      {
         if( !eval_state.check_signature( escrow_condition.escrow ) )
             FC_CAPTURE_AND_THROW( missing_signature, (escrow_condition.escrow) );
         // get a balance record for the receiver, create it if necessary and deposit funds
         {
            balance_record new_balance_record( escrow_condition.receiver,
                                               asset( amount_to_receiver, escrow_balance_record->asset_id() ),
                                               escrow_balance_record->slate_id() );
            auto current_receiver_balance = eval_state._current_state->get_balance_record( new_balance_record.id());

            if( current_receiver_balance )
               current_receiver_balance->balance += amount_to_receiver;
            else
               current_receiver_balance = new_balance_record;
            eval_state._current_state->store_balance_record( *current_receiver_balance );
         }
         //  get a balance record for the sender, create it if necessary and deposit funds
         {
            balance_record new_balance_record( escrow_condition.sender,
                                               asset( amount_to_sender, escrow_balance_record->asset_id() ),
                                               escrow_balance_record->slate_id() );
            auto current_sender_balance = eval_state._current_state->get_balance_record( new_balance_record.id());

            if( current_sender_balance )
               current_sender_balance->balance += amount_to_sender;
            else
               current_sender_balance = new_balance_record;
            eval_state._current_state->store_balance_record( *current_sender_balance );
         }
      }
      else if( address() == this->released_by )
      {
         if( !eval_state.check_signature( escrow_condition.sender ) )
             FC_CAPTURE_AND_THROW( missing_signature, (escrow_condition.sender) );
         if( !eval_state.check_signature( escrow_condition.receiver ) )
             FC_CAPTURE_AND_THROW( missing_signature, (escrow_condition.receiver) );
         // get a balance record for the receiver, create it if necessary and deposit funds
         {
            balance_record new_balance_record( escrow_condition.receiver,
                                               asset( amount_to_receiver, escrow_balance_record->asset_id() ),
                                               escrow_balance_record->slate_id() );
            auto current_receiver_balance = eval_state._current_state->get_balance_record( new_balance_record.id());

            if( current_receiver_balance )
               current_receiver_balance->balance += amount_to_receiver;
            else
               current_receiver_balance = new_balance_record;
            eval_state._current_state->store_balance_record( *current_receiver_balance );
         }
         //  get a balance record for the sender, create it if necessary and deposit funds
         {
            balance_record new_balance_record( escrow_condition.sender,
                                               asset( amount_to_sender, escrow_balance_record->asset_id() ),
                                               escrow_balance_record->slate_id() );
            auto current_sender_balance = eval_state._current_state->get_balance_record( new_balance_record.id());

            if( current_sender_balance )
               current_sender_balance->balance += amount_to_sender;
            else
               current_sender_balance = new_balance_record;
            eval_state._current_state->store_balance_record( *current_sender_balance );
         }
      }
      else
      {
          FC_ASSERT( !"not released by a party to the escrow transaction" );
      }

      eval_state._current_state->store_balance_record( *escrow_balance_record );
   } FC_CAPTURE_AND_RETHROW( (*this) ) }