int main(void) {
	int isRunning = 1;
	char buffer[MAX_LINE_LENGTH];
	char command[MAX_LINE_LENGTH];
	while(isRunning){	
		//int i;
		printf("> ");
		fgets(buffer, MAX_LINE_LENGTH, stdin);
		/*for( i = 0; i < MAX_LINE_LENGTH; i++ ){
		  buffer[i] = tolower(buffer[i]);
		}*/
		sscanf(buffer, " %s ", (char*)&command);
		//Switch for commands
		if(strcmp(command, "BYE") == 0){					/*BYE*/
			deleteAllEntry(entry_head);
			deleteAllSnapshot(snapshot_head);
			printf("bye");
			isRunning = 0;
		}else if(strcmp(command, "HELP") == 0){				/*HELP*/
			cmd_help();
		}else if(strcmp(command, "LIST") == 0){
			sscanf(buffer + strlen(command), "%s", (char*)&command);
			if(strcmp(command, "KEYS") == 0){				/*LIST KEYS*/
				cmd_list_keys();
			}else if(strcmp(command, "ENTRIES") == 0){		/*LIST ENTRIES*/
				cmd_list_entries();
			}else if(strcmp(command, "SNAPSHOTS") == 0){	/*LIST SNAPSHOTS*/
				cmd_list_snapshots();
			}
		}else if(strcmp(command, "GET") == 0){				/*GET*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_get(key);
		}else if(strcmp(command, "DEL") == 0){				/*DEL*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_del(key);
		}else if(strcmp(command, "PURGE") == 0){			/*PURGE*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_purge(key);
		}else if(strcmp(command, "SET") == 0){				/*SET*/
			int i = 0;
			char key[MAX_KEY_LENGTH];
			char *endptr;
			int *values = (int*)malloc(MAX_LINE_LENGTH/2*sizeof(int));
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			endptr = buffer + strlen(command) + strlen(key) + 2;
			while(1){
				values[i] = strtol(endptr, &endptr, 10);
				if(*endptr == '\n'){
					cmd_set(key, values, i+1);
					break;
				}
				i++;
			}
			free(values);
		}else if(strcmp(command, "PUSH") == 0){				/*PUSH*/
			int i = 0;
			char key[MAX_KEY_LENGTH];
			char *endptr;
			int *values = (int*)malloc(MAX_LINE_LENGTH/2*sizeof(int));
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			endptr = buffer + strlen(command) + strlen(key) + 2;
			while(1){
				values[i] = strtol(endptr, &endptr, 10);
				if(*endptr == '\n'){
					cmd_push(key, values, i+1);
					break;
				}
				i++;
			}
			free(values);
		}else if(strcmp(command, "APPEND") == 0){			/*APPEND*/ 
			int i = 0;
			char key[MAX_KEY_LENGTH];
			char *endptr;
			int *values = (int*)malloc(MAX_LINE_LENGTH/2*sizeof(int));
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			endptr = buffer + strlen(command) + strlen(key) + 2;
			while(1){
				values[i] = strtol(endptr, &endptr, 10);
				if(*endptr == '\n'){
					cmd_append(key, values, i+1);
					break;
				}
				i++;
			}
			free(values);
		}else if(strcmp(command, "PICK") == 0){				/*PICK*/
			char key[MAX_KEY_LENGTH];
			int index;
			sscanf(buffer + strlen(command)+1, "%s", (char*)&key);
			index = strtol(buffer + strlen(command) + strlen(key)+2, (char**)&command, 0);
			cmd_pick(key, index);
		}else if(strcmp(command, "PLUCK") == 0){			/*PLUCK*/
			char key[MAX_KEY_LENGTH];
			int index;
			sscanf(buffer + strlen(command)+1, "%s", (char*)&key);
			index = strtol(buffer + strlen(command) + strlen(key)+2, (char**)&command, 0);
			cmd_pluck(key, index);
		}else if(strcmp(command, "POP") == 0){				/*POP*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_pop(key);
		}else if(strcmp(command, "DROP") == 0){				/*DROP*/
			int id = strtol(buffer + strlen(command) +1 , (char**)&command, 10);
			cmd_drop(id);
		}else if(strcmp(command, "ROLLBACK") == 0){			/*ROLLBACK*/
			int id = strtol(buffer + strlen(command) +1 , (char**)&command, 10);
			cmd_rollback(id);
		}else if(strcmp(command, "CHECKOUT") == 0){			/*CHECKOUT*/
			int id = strtol(buffer + strlen(command) +1 , (char**)&command, 10);
			cmd_checkout(id);
		}else if(strcmp(command, "SNAPSHOT") == 0){			/*SNAPSHOT*/
			cmd_snapshot();
		}else if(strcmp(command, "MIN") == 0){				/*MIN*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_min(key);
		}else if(strcmp(command, "MAX") == 0){				/*MAX*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_max(key);
		}else if(strcmp(command, "SUM") == 0){				/*SUM*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_sum(key);
		}else if(strcmp(command, "LEN") == 0){				/*LEN*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_len(key);
		}else if(strcmp(command, "REV") == 0){				/*REV*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_rev(key);
		}else if(strcmp(command, "UNIQ") == 0){				/*UNIQ*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_uniq(key);
		}else if(strcmp(command, "SORT") == 0){				/*SORT*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_sort(key);
		}else{
			printf("\n");
		}
	}
	return 0;
}
Exemple #2
0
//переход на обработчик команды
bool Vm1::exec_command()
{
	if(!parse_command()) return false;

	switch (cmd.id)
	{
	case halt:
		cmd_halt();
		return false;
	case push_reg:
		cmd_push(cmd.operand);
		break;
	case pop_reg:
		cmd_pop(cmd.operand);
		break;
	case cmp_reg_reg:
		cmd_cmp_reg_reg(cmd.operand,cmd.operand2);
		break;
	case mov_reg_reg:
		cmd_mov_reg_reg(cmd.operand,cmd.operand2);
		break;
	case mov_reg_mem:
		cmd_mov_reg_mem(cmd.operand,cmd.operand2);
		break;

	case jmp:
		cmd_jmp(cmd.operand2,cmd.operand);
		break;

	case add_reg_reg:
		cmd_add_reg_reg(cmd.operand,cmd.operand2);
		break;

	case mod_reg_imm:
		cmd_mod_reg_imm(cmd.operand,cmd.operand2);
		break;

	case shl_reg_reg:
		cmd_shl_reg_reg(cmd.operand,cmd.operand2);
		break;
		
	case mov_reg_byte:
		cmd_mov_reg_byte(cmd.operand,cmd.operand2);
		break;

	case mov_reg_imm:
		cmd_mov_reg_imm(cmd.operand,cmd.operand2);
		break;
		
	case mov_reg_ptr_reg:
		cmd_mov_reg_ptr_reg(cmd.operand,cmd.operand2);
		break;
		
	case add_reg_imm:
		cmd_add_reg_imm(cmd.operand,cmd.operand2);
		break;	

	case xor_byte_ptr_reg:
		cmd_xor_byte_ptr_reg(cmd.operand,cmd.operand2);
		break;	

	case antidebug_1:
		cmd_antidebug_1(cmd.operand,cmd.operand2);
		break;	

	default:
		return false;
	}
	//след команда..
	reg.eip+=cmd.len;
	return true;
}
Exemple #3
0
int main(int argc, char *argv[])
{
	errorCode_t	ec;
	char		**adpArray = NULL;
	int		adpLen;
	neardal_adapter	*adapter;
	static int	power = 1;

	g_argc=argc;
	g_argv=argv;

	printf("\n");

	/* Look for available adapter */
	ec = neardal_get_adapters(&adpArray, &adpLen);
	if (ec == NEARDAL_SUCCESS)
	{
		memcpy(AdpName, adpArray[0], sizeof(AdpName));
		neardal_free_array(&adpArray);
	} else
	{
		printf("---- No adapter found\n");
		return 1;
	}

	/* Power on first adapter found */
	ec = neardal_get_adapter_properties(AdpName,&adapter);	
	if (ec == NEARDAL_SUCCESS)
	{
		power=adapter->powered;
		neardal_free_adapter(adapter);			
		if (!power)
		{
			power = 1;
			ec = neardal_set_adapter_property(AdpName, NEARD_ADP_PROP_POWERED, GINT_TO_POINTER(power));
			if (ec != NEARDAL_SUCCESS) {
				printf("---- Error setting adapter properties\n");
				return 1;
			}
		}
	} else
	{
		printf("---- Error getting adapter properties\n");
		return 1;
	}

	/* Register callbacks */
	neardal_set_cb_tag_found(cb_tag_found, NULL);
	neardal_set_cb_tag_lost(cb_tag_lost, NULL);
	neardal_set_cb_dev_found(cb_dev_found, NULL);
	neardal_set_cb_dev_lost(cb_dev_lost, NULL);

	if (argc<2)
	{
		printf("Missing argument\n");
		help();
	}
	else if (strcmp(argv[1],"poll") == 0)
	{
		neardal_agent_set_NDEF_cb("urn:nfc:wkt:U", cb_ndef_agent, NULL, NULL);
		neardal_set_cb_record_found(cb_record_found, NULL);
		cmd_poll();
	}
	else if(strcmp(argv[1],"write") == 0)
	{
		cmd_write(g_argc,g_argv);
	}
	else if(strcmp(argv[1],"push") == 0)
	{
		cmd_push(g_argc,g_argv);
	}
	else
	{
		help();
	}

	printf("\n");
	return 0;
}
Exemple #4
0
void LedController::process_command() {
  current_instruction_pc = pc;
  uint8_t cmd = program[pc++]; 
  switch(cmd) {

    case CMD_GROUP_SET:
      cmd_group_set();
      break;
      
    case CMD_GROUP_CLEAR:
      cmd_group_clear();
      break;

    case CMD_CLEAR_GROUPS:
      cmd_clear_groups();
      break;

    case CMD_DISABLE_ACTIONS:
      cmd_disable_actions();
      break;
          
    case CMD_LOAD_REG_CONST:
      cmd_load_reg_const();
      break;

    case CMD_LDAA8:
      cmd_load_reg_8(0);
      break;
    
    case CMD_LDAB8:
      cmd_load_reg_8(1);
      break;
    
    case CMD_LDAC8:
      cmd_load_reg_8(2);
      break;
    
    case CMD_LDAD8:
      cmd_load_reg_8(3);
      break;
    
    case CMD_LDAE8:
      cmd_load_reg_8(4);
      break;
    
    case CMD_LDAA16:
      cmd_load_reg_16(0);
      break;
    
    case CMD_LDAB16:
      cmd_load_reg_16(1);
      break;
    
    case CMD_LDAC16:
      cmd_load_reg_16(2);
      break;
    
    case CMD_LDAD16:
      cmd_load_reg_16(3);
      break;
        
    case CMD_LDAE16:
      cmd_load_reg_16(4);
      break;
        
    case CMD_LOAD_REG_MAV:
      cmd_load_reg_mav();
      break;
      
    case CMD_PAUSE:
      cmd_pause();
      break;
          
    case CMD_YIELD:
      cmd_yield();
      break;
      
    case CMD_JUMP_ABS:
      cmd_jump_absolute();
      break;

    case CMD_JUMP_REL:
      cmd_jump_relative();
      break;

    case CMD_BZ_REL:
      cmd_bz_relative();
      break;
      
    case CMD_BNZ_REL:
      cmd_bnz_relative();
      break;
      
    case CMD_MOVE_REG:
      cmd_move_register();
      break;
               
    case CMD_SETCOLOR:
      cmd_set_color();
      break;    
      
    case CMD_SETFLASH:
      cmd_set_flash();
      break;
      
    case CMD_SETWAVE:
      cmd_set_wave();
      break;
      
    case CMD_SETBOUNCE:
      cmd_set_bounce();
      break;
      
    case CMD_SETRANDOM:
      cmd_set_random();
      break;
      
    case CMD_SETBAR:
      cmd_set_bar();
      break;     
       
    case CMD_SETOFF:
      cmd_set_off();
      break;

    case CMD_SETFILL:
      cmd_set_fill();
      break;
    case CMD_0EQ1:
      cmd_0eq1();
      break;

    case CMD_0NE1:
      cmd_0ne1();
      break;

    case CMD_0LT1:
      cmd_0lt1();
      break;
    
    case CMD_0LE1:
      cmd_0le1();
      break;
    
    case CMD_0GT1:
      cmd_0gt1();
      break;
    
    case CMD_0GE1:
      cmd_0ge1();
      break;

    case CMD_PUSH:
      cmd_push();
      break;
      
    case CMD_POP:
      cmd_pop();
      break;
      
    case CMD_AND:
      cmd_and();
      break;

    case CMD_OR:
      cmd_or();
      break;
      
    default:
      if(console != NULL)
      {
        console->console_print("Invalid program instruction %d at pc:%d\r\n", cmd, pc);
      }    
  }
}