コード例 #1
0
static int kor2chn_translator_analyze(index_word_extractor_t *extractor, index_word_t *index_word, int max)
{
	kor2chn_translator_handle_t *handle=NULL;
	token_t *token_array = NULL;
	int32_t index_word_idx = 0;
	int32_t num_of_tokens = 0;
	int i=0;

	if (extractor->id != 2) return MINUS_DECLINE;

	handle = extractor->handle;

	if (handle->done) return 0;

	memset(&(index_word[0]), 0x00, sizeof(index_word_t));

	token_array = handle->token_array;
	handle->token_array = sb_realloc(token_array, max * sizeof(token_t));

	token_array = handle->token_array;

	num_of_tokens = sb_run_get_tokens(handle->tokenizer, token_array, max);

	for(i=0; i < num_of_tokens && token_array[i].type != TOKEN_END_OF_DOCUMENT ; i++) { 

		switch(token_array[i].type)
		{ 
			case TOKEN_CHINESE: 
				/* TODO should be replaced by common/hanja.c:sb_hanja2hangul() */
				CDconvChn2Kor(token_array[i].string , token_array[i].string);

				// falls through
			case TOKEN_ALPHABET:
				strntoupper(token_array[i].string, MAX_WORD_LEN);

				// falls through
			case TOKEN_NUMBER:         
			case TOKEN_JAPANESE:
			case TOKEN_KOREAN: 
				append_index_word( &(index_word[index_word_idx]),
									&(token_array[i]), 1); 
				if (index_word[index_word_idx].len >= MAX_WORD_LEN-1)
					goto FINISH;
			
				break; 

		} // switch  

	} // loop 

FINISH:
	index_word_idx++;
	handle->done = 1;

	return index_word_idx;
}
コード例 #2
0
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
  int c;
  char *warning = NULL;
  char *critical = NULL;

  int opt_index = 0;
  static struct option long_opts[] = {
    {"help", no_argument, 0, 'h'},
    {"version", no_argument, 0, 'V'},
    {"verbose", no_argument, 0, 'v'},
    {"timeout", required_argument, 0, 't'},
    {"hostname", required_argument, 0, 'H'},
    {"server", required_argument, 0, 's'},
    {"reverse-server", required_argument, 0, 'r'},
    {"querytype", required_argument, 0, 'q'},
    {"expected-address", required_argument, 0, 'a'},
    {"expect-authority", no_argument, 0, 'A'},
    {"accept-cname", no_argument, 0, 'n'},
    {"warning", required_argument, 0, 'w'},
    {"critical", required_argument, 0, 'c'},
    {0, 0, 0, 0}
  };

  if (argc < 2)
    return ERROR;

  for (c = 1; c < argc; c++)
    if (strcmp ("-to", argv[c]) == 0)
      strcpy (argv[c], "-t");

  while (1) {
    c = getopt_long (argc, argv, "hVvAnt:H:s:r:a:q:w:c:", long_opts, &opt_index);

    if (c == -1 || c == EOF)
      break;

    switch (c) {
    case 'h': /* help */
      print_help ();
      exit (STATE_OK);
    case 'V': /* version */
      print_revision (progname, NP_VERSION);
      exit (STATE_OK);
    case 'v': /* version */
      verbose = TRUE;
      break;
    case 't': /* timeout period */
      timeout_interval = atoi (optarg);
      break;
    case 'H': /* hostname */
      if (strlen (optarg) >= ADDRESS_LENGTH)
        die (STATE_UNKNOWN, _("Input buffer overflow\n"));
      strcpy (query_address, optarg);
      break;
    case 's': /* server name */
      /* TODO: this host_or_die check is probably unnecessary.
       * Better to confirm nslookup response matches */
      host_or_die(optarg);
      if (strlen (optarg) >= ADDRESS_LENGTH)
        die (STATE_UNKNOWN, _("Input buffer overflow\n"));
      strcpy (dns_server, optarg);
      break;
    case 'r': /* reverse server name */
      /* TODO: Is this host_or_die necessary? */
      host_or_die(optarg);
      if (strlen (optarg) >= ADDRESS_LENGTH)
        die (STATE_UNKNOWN, _("Input buffer overflow\n"));
      strcpy (ptr_server, optarg);
      break;
    case 'a': /* expected address */
      if (strlen (optarg) >= ADDRESS_LENGTH)
        die (STATE_UNKNOWN, _("Input buffer overflow\n"));
      expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**));
      expected_address[expected_address_cnt] = strdup(optarg);
      expected_address_cnt++;
      break;
    case 'q': /* querytype -- A or AAAA or ANY or SRV or TXT, etc. */
      if (strlen (optarg) < 1 || strlen (optarg) > 5)
	die (STATE_UNKNOWN, _("Missing valid querytype parameter.  Try using 'A' or 'AAAA' or 'SRV'\n"));
      strntoupper(optarg, sizeof(optarg));
      strcpy(query_type, "-querytype=");
      strcat(query_type, optarg);
      break;
    case 'A': /* expect authority */
      expect_authority = TRUE;
      break;
    case 'n': /* accept cname responses as a result */
      accept_cname = TRUE;
      break;
    case 'w':
      warning = optarg;
      break;
    case 'c':
      critical = optarg;
      break;
    default: /* args not parsable */
      usage5();
    }
  }

  c = optind;
  if (strlen(query_address)==0 && c<argc) {
    if (strlen(argv[c])>=ADDRESS_LENGTH)
      die (STATE_UNKNOWN, _("Input buffer overflow\n"));
    strcpy (query_address, argv[c++]);
  }

  if (strlen(dns_server)==0 && c<argc) {
    /* TODO: See -s option */
    host_or_die(argv[c]);
    if (strlen(argv[c]) >= ADDRESS_LENGTH)
      die (STATE_UNKNOWN, _("Input buffer overflow\n"));
    strcpy (dns_server, argv[c++]);
  }

  set_thresholds(&time_thresholds, warning, critical);

  return validate_arguments ();
}