Exemplo n.º 1
0
int main()
{
    CourseV course_vec = { {0, "Linux" }, {1, "C++"}, {2, "HTML"}, {4, "NodeJS"},
                         {5, "Shell"}, {6, "Python"} };
    show_help_info();
    
    unsigned cmd;
    while(cin >> cmd)
    {        
        bool exit_flag = false;
        try {
            switch (cmd)
            {
                case 0:
                    show_help_info();
                    break;
                case 1:
                    show_all_course(course_vec);
                    break;
                case 2:
                     show_course_num(course_vec);
                     break;
                case 3:
                    show_max_course(course_vec);
                    break;
                case 4:
                    delet_last_course(course_vec);
                    break;
                case 5:
                     exit_flag = true;
                     break;
                default:
                    throw out_of_range("invalid input!");
                    break;
            }
        } catch (out_of_range err) {
            cout << err.what() << "\12 check you input." << endl;
            show_help_info();
        }
        
        
        if (exit_flag)
           break;       
        cout << "======================" << endl;
        cout << "input the next number:" << endl;
    }
    
    cout << "loop is out, bye!" << endl;
    return 0;
}
Exemplo n.º 2
0
void interpret ( int argc, char* argv[] )
{
  init_with_options (argc, argv);

  //test_rec_write("test");

  char token[30];
	
  while (!feof(in_s))
    {
      fscanf (in_s, "%s", token);
      put_msg (DEBUG, "current token is \"%s\".\n", token);
      if (strcmp(token, t_quit) == 0)
	{ quit(); break;}
      if (token[0] == '#')
	{ skip_line (); continue; }
      if (strcmp(token, t_help) == 0)
	{ show_help_info (); continue; }
      if (strcmp(token, t_database) == 0)
	{ set_database(); continue; }
      if (strcmp(token, t_show) == 0)
	{ show_database(); continue; }
      if (strcmp(token, t_print) == 0)
	{ print_str(); continue; }
      if (strcmp(token, t_create) == 0)
	{ create_tbl(); continue; }
      if (strcmp(token, t_drop) == 0)
	{ drop_tbl(); continue; }
      if (strcmp(token, t_insert) == 0)
	{ insert_row(); continue; }
      if (strcmp(token, t_select) == 0)
	{ select_rows(); continue; }
      syntax_error (token);
    }
}
Exemplo n.º 3
0
static void uart_input_handler(const char *data, int len)
{
	int i;
	if (len < 1) {
		return;
	}

	if (data[0] == 0x7f || data[0] == 0x08) {
		if (rcvMsg.pWritePos != rcvMsg.pRcvMsgBuff) {
			const char back = 0x08, space = ' ';
			uart_write_bytes(UART_NUM_0, &back, 1);
			uart_write_bytes(UART_NUM_0, &space, 1);
			//uart_write_bytes(UART_NUM_0, &back, 1);
			rcvMsg.pWritePos[0] = 0;
			rcvMsg.pWritePos -= 1;
		} else {
			// nothing to delete
			return;
		}
	}

	if (data[0] == '\r' || data[0] == '\n') {
		// enter key press
		rcvMsg.pWritePos[0] = 0;

		if (rcvMsg.pWritePos == rcvMsg.pRcvMsgBuff) {
			uart_write_bytes(UART_NUM_0, PROMPT, PROMPT_LEN);
		} else {
				int length = rcvMsg.pWritePos - rcvMsg.pRcvMsgBuff;
				uart_write_bytes(UART_NUM_0, PROMPT, PROMPT_LEN);
				if (status == INPUT_SSID) {
					memset(wifi_ssid, 0, WIFI_SSID_MAX_LEN);
					memcpy(wifi_ssid, rcvMsg.pRcvMsgBuff, length);
					status = NONE;
					ESP_LOGI(TAG, "you set ssid: %s", wifi_ssid);
					esp_err_t er = save_string(CMD_SSID, (char *)wifi_ssid);
					if (er != ESP_OK)
						ESP_LOGE(TAG, "save ssid error");
					goto set_end;
				} else if (status == INPUT_PASS) {
					memset(wifi_pass, 0, WIFI_PASS_MAX_LEN);
					memcpy(wifi_pass, rcvMsg.pRcvMsgBuff, length);
					status = NONE;
					ESP_LOGI(TAG, "you set password: %s", wifi_pass);
					esp_err_t er = save_string(CMD_PASS, (char *)wifi_pass);
					if (er != ESP_OK)
						ESP_LOGE(TAG, "save pass error");
					goto set_end;
				} else if (status == INPUT_IP) {
					memset(srv_ip, 0, SRV_IP_MAX_LEN);
					memcpy(srv_ip, rcvMsg.pRcvMsgBuff, length);
					status = NONE;
					ESP_LOGI(TAG, "you set server ip: %s", srv_ip);
					esp_err_t er = save_string(CMD_IP, (char *)srv_ip);
					if (er != ESP_OK)
						ESP_LOGE(TAG, "save ip error");
					goto set_end;
				} else if (status == INPUT_PORT) {
					if (!is_valid_port((const char *)rcvMsg.pRcvMsgBuff, length)) {
						rcvMsg.pWritePos = rcvMsg.pRcvMsgBuff;
						ESP_LOGE(TAG, "invalid server port, please input again");
						return;
					}
					srv_port = str2num((const char *)rcvMsg.pRcvMsgBuff, length);
					status = NONE;
					ESP_LOGI(TAG, "you set server port: %d", srv_port);
					//esp_err_t er = save_int32(CMD_PORT, srv_port);
					esp_err_t er = save_string(CMD_PORT, (char *)rcvMsg.pRcvMsgBuff);
					if (er != ESP_OK)
						ESP_LOGE(TAG, "save port error");
					goto set_end;
				}

				if (strncmp((const char *)rcvMsg.pRcvMsgBuff, CMD_SSID, length) == 0) {
					ESP_LOGI(TAG, "input your ssid [less than 32byte]:");
					status = INPUT_SSID;
				} else if (strncmp((const char *)rcvMsg.pRcvMsgBuff, CMD_PASS, length) == 0) {
					ESP_LOGI(TAG, "input your password [less than 32byte]:");
					status = INPUT_PASS;
				} else if (strncmp((const char *)rcvMsg.pRcvMsgBuff, CMD_IP, length) == 0) {
					ESP_LOGI(TAG, "input server IP:");
					status = INPUT_IP;
				} else if (strncmp((const char *)rcvMsg.pRcvMsgBuff, CMD_PORT, length) == 0) {
					ESP_LOGI(TAG, "input server port:");
					status = INPUT_PORT;
				} else if (strncmp((const char *)rcvMsg.pRcvMsgBuff, CMD_HELP, length) == 0) {
					show_help_info();
				} else if (strncmp((const char *)rcvMsg.pRcvMsgBuff, CMD_WIFI, length) == 0) {
					ESP_LOGI(TAG, "BLE scanning ......");
					close_nvs();
					ble_client_app_register();
					//initialise_wifi();
				} else if (strncmp((const char *)rcvMsg.pRcvMsgBuff, CMD_QUIT, length) == 0) {
					ESP_LOGI(TAG, "reset wifi info:");
					clear_storage();
					close_nvs();
					system_restart();
				} else {
					ESP_LOGI(TAG, "invalid command %s", rcvMsg.pRcvMsgBuff);
					show_help_info();
				}
		}
set_end:
		rcvMsg.pWritePos = rcvMsg.pRcvMsgBuff;
		memset(rcvMsg.pRcvMsgBuff, 0, RECV_BUF_SIZE);
		return;
	}

	*(rcvMsg.pWritePos) = data[0];
	uart_write_bytes(UART_NUM_0, &data[0], 1);
	rcvMsg.pWritePos += 1;

	if (rcvMsg.pWritePos - rcvMsg.pRcvMsgBuff >= RECV_BUF_SIZE - 1) {
		rcvMsg.pWritePos = rcvMsg.pRcvMsgBuff;		// overflow, restart
		ESP_LOGI(TAG, "overflow");
	}
}
Exemplo n.º 4
0
int main(int argc, char *argv[])
{
    int nativeBlockNum = 0;
    int parityBlockNum = 0;
    int totalBlockNum = 0;
    int gridDimXSize = 0;
    int streamNum = 1;
    char *inFile = NULL;
    char *confFile = NULL;
    char *outFile = NULL;

    enum func
    {
        encode,
        decode
    };
    enum func op;
    int func_flag = 0;

    int option;
    while((option = getopt(argc, argv, "Ss:Pp:Kk:Nn:Ee:Ii:Cc:Oo:Ddh")) != -1) {
        switch (option) {
            case 'S':
            case 's':
                streamNum = (int) atoi(optarg);
                break;

            case 'P':
            case 'p':
                gridDimXSize = (int) atoi(optarg);
                break;

            case 'K':
            case 'k':
                nativeBlockNum = (int) atoi(optarg);
                break;

            case 'N':
            case 'n':
                totalBlockNum = (int) atoi(optarg);
                break;

            case 'E':
            case 'e':
                inFile = optarg;
                op = encode;
                func_flag = 1;
                break;

            case 'D':
            case 'd':
                op = decode;
                func_flag = 1;
                break;

            case 'I':
            case 'i':
                if (func_flag == 1 && op == decode)
                {
                    inFile = optarg;
                }
                else
                {
                    show_help_info();
                }
                break;

            case 'C':
            case 'c':
                if (func_flag == 1 && op == decode)
                {
                    confFile = optarg;
                }
                else
                {
                    show_help_info();
                }
                break;

            case 'O':
            case 'o':
                if (func_flag == 1 && op == decode)
                {
                    outFile = optarg;
                }
                else
                {
                    show_help_info();
                }
                break;

            case 'h':
                show_help_info();
                break;

            default:
                show_help_info();
                break;
        }	/* -----  end switch  ----- */
    }

    switch ( op ) {
        case encode:
            assert(nativeBlockNum != 0);
            assert(totalBlockNum != 0);
            parityBlockNum = totalBlockNum - nativeBlockNum;
            encode_file(inFile, nativeBlockNum, parityBlockNum, gridDimXSize, streamNum);
            break;

        case decode:
            assert(inFile != NULL);
            assert(confFile != NULL);
            decode_file(inFile, confFile, outFile, gridDimXSize, streamNum);
            break;

        default:
            break;
    }		/* -----  end switch  ----- */

    return 0;
}