Beispiel #1
0
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_IWDG_Init();
  MX_USB_DEVICE_Init();

  /* USER CODE BEGIN 2 */
	cfg_init();
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
    cli_run();

  }
  /* USER CODE END 3 */

}
Beispiel #2
0
int main(int argc, char *argv[])
{
	int result;
	int opt;
	int arg = 1;
	static char *exit_cmd[] = { "exit", NULL };
	char *hist_size;

	strcpy(server, "localhost");

	cli_init("ippool");
	result = cli_add_commands(&cmds[0]);
	if (result < 0) {
		fprintf(stderr, "Application initialization error.\n");
		return result;
	}

	cl = clnt_create(server, IPPOOL_PROG, IPPOOL_VERSION, "udp");
	if (cl == NULL) {
		clnt_pcreateerror(server);
		exit(1);
	}
	atexit(cleanup);

	opterr = 0;		/* no error messages please */

	opt = getopt(argc, argv, "qR:");
	switch (opt) {
	case 'q':
		opt_quiet = 1;
		arg++;
		break;
	case 'R':
		strncpy(server, optarg, sizeof(server));
		arg += 2;
		ippool_set_prompt(server);
		break;
	default:
		break;
	}

	/* If user supplied arguments, send them to the CLI now and immediately exit.
	 */
	if (argc > arg) {
		(void) cli_execute(argc - arg, &argv[arg]);
		(void) cli_execute(1, exit_cmd);
	} else {
		/* interactive mode */
		interactive = 1;
		ippool_histfile = getenv("IPPOOL_HISTFILE");
		if (ippool_histfile == NULL) {
			ippool_histfile = "~/.ippool_history";
		}
		hist_size = getenv("IPPOOL_HISTFILESIZE");
		if (hist_size != NULL) {
			ippool_histfile_maxsize = strtoul(hist_size, NULL, 0);
		}

		cli_read_history_file(ippool_histfile);
		cli_run();
	}

	return 0;
}
Beispiel #3
0
int main(int argc, char *argv[])
{
	int result;
	struct cli_node *node;
	struct cli_node *matches[30];
	int num_matches = 30;
	int match;

	cli_init("test");
	result = cli_add_commands(&cmds[0]);
	cli_dump_commands();
	printf("dump: result = %d\n", result);
	if (argc > 1) {
		node = cli_find_command(argc - 1, &argv[1], &matches[0], &num_matches);
		if (node != NULL) {
			for (match = 0; match < num_matches; match++) {
				node = matches[match];
				printf("node[%d] = %p (%s:%s)\n", match, node, 
				       node->type == CLI_NODE_TYPE_KEYWORD ? "KEYWORD" : "COMMAND",
				       node->keyword);
			}
		} else {
			printf("find: invalid command sequence\n");
		}
	} else {
		char *argv[10];

		banner("test");
		argv[0] = "test";
		argv[1] = NULL;
		node = cli_find_command(1, &argv[0], &matches[0], &num_matches);
		if (node != NULL) {
			dump_buddies(node, 0);
			dump_kids(node);
		} else {
			printf("UNMATCHED\n");
		}

		banner("tunnel");
		argv[0] = "tunnel";
		argv[1] = NULL;
		node = cli_find_command(1, &argv[0], &matches[0], &num_matches);
		if (node != NULL) {
			dump_buddies(node, 0);
			dump_kids(node);
		} else {
			printf("UNMATCHED\n");
		}

		banner("system");
		argv[0] = "system";
		argv[1] = NULL;
		node = cli_find_command(1, &argv[0], &matches[0], &num_matches);
		if (node != NULL) {
			dump_buddies(node, 0);
			dump_kids(node);
		} else {
			printf("UNMATCHED\n");
		}

		banner("system modify");
		argv[0] = "system";
		argv[1] = "modify";
		argv[2] = NULL;
		node = cli_find_command(2, &argv[0], &matches[0], &num_matches);
		if (node != NULL) {
			dump_buddies(node, 0);
			dump_kids(node);
		} else {
			printf("UNMATCHED\n");
		}

		banner("test one");
		argv[0] = "test";
		argv[1] = "one";
		argv[2] = NULL;
		node = cli_find_command(2, &argv[0], &matches[0], &num_matches);	
		if (node != NULL) {
			printf("matches node '%s', level %d\n", node->keyword, node->level);
		} else {
			printf("UNMATCHED\n");
		}

		banner("test one two run");
		argv[0] = "test";
		argv[1] = "one";
		argv[2] = "two";
		argv[3] = "run";
		argv[4] = NULL;
		node = cli_find_command(4, &argv[0], &matches[0], &num_matches);	
		printf("test one two run");
		if (node != NULL) {
			printf("matches node '%s', level %d\n", node->keyword, node->level);
		} else {
			printf("UNMATCHED\n");
		}

		banner("tunnel profile create");
		argv[0] = "tunnel";
		argv[1] = "profile";
		argv[2] = "create";
		argv[3] = NULL;
		node = cli_find_command(3, &argv[0], &matches[0], &num_matches);	
		printf("tunnel profile create ");
		if (node != NULL) {
			printf("matches node '%s', level %d\n", node->keyword, node->level);
		} else {
			printf("UNMATCHED\n");
		}

		banner("system modify trace_flags=1 more_flags=2 debug");
		argv[0] = "system";
		argv[1] = "modify";
		argv[2] = "trace_flags";
		argv[3] = "1";
		argv[4] = "more_flags";
		argv[5] = "2";
		argv[6] = "debug";
		argv[7] = NULL;
		node = cli_find_command(7, &argv[0], &matches[0], &num_matches);
		if (node != NULL) {
			printf("matches node '%s', level %d\n", node->keyword, node->level);
		} else {
			printf("UNMATCHED\n");
		}

		// exit(0);
		cli_run();
	}

	return 0;
}