[Te11g3 26] Пример разбора ключей

Sergey Maslennikov tmp110306 на rplab.ru
Ср Дек 11 12:19:32 MSK 2013


  char *str_t=NULL, *str_i=NULL, *str_o=NULL;
  int win_output = 0;

	int nOption, nOptCnt = 0;
	const char *short_options = "ht:i:o:wr:m:";
	const struct option long_options[] = {
		{"help", 0 /*0 = no arguments*/, NULL, 'h'},
		{"thickness", 1, NULL, 't'},
		{"input-file", 1, NULL, 'i'},
		{"output-file", 1, NULL, 'o'},
		{"windows-output", 0, NULL, 'w'},
		{"initial-nre", 1, NULL, 'r'},
		{"initial-nim", 1, NULL, 'm'},
		{NULL, 0, NULL, 0}
	};
	do {
		nOption = getopt_long(argc, argv,
			short_options, long_options, NULL);
		if(nOption == 'h') { print_usage(argv); return 0; }
		else if(nOption == 't') str_t = optarg;
    else if(nOption == 'i') str_i = optarg;
		else if(nOption == 'o') str_o = optarg;
		else if(nOption == 'w') win_output = -1;
		else if(nOption == 'r') initial_nre = strtod(optarg, NULL);
		else if(nOption == 'm') initial_nim = strtod(optarg, NULL);
		else if(nOption == '?') { print_usage(argv); return 0; }
		else if(nOptCnt == 0) { print_usage(argv); return -1; }
		nOptCnt++;
	} while(nOption != -1);




Подробная информация о списке рассылки tech11g3