Beispiel #1
0
static int
enc_check_encoding(VALUE obj)
{
    if (SPECIAL_CONST_P(obj) || !rb_typeddata_is_kind_of(obj, &encoding_data_type)) {
	return -1;
    }
    return check_encoding(RDATA(obj)->data);
}
Beispiel #2
0
static int
enc_check_encoding(mrb_state *mrb, mrb_value obj)
{
  if (SPECIAL_CONST_P(obj) || !is_data_encoding(obj)) {
    return -1;
  }
  return check_encoding(mrb, RDATA(obj)->data);
}
Beispiel #3
0
static int
enc_check_encoding(VALUE obj)
{
    if (!is_obj_encoding(obj)) {
	return -1;
    }
    return check_encoding(RDATA(obj)->data);
}
Beispiel #4
0
string
xml_html_parser::transcode (string s2) {
  s= parse_string (s2);

  string encoding;
  if (test (s, "<?")) {
    s += 2;
    string target= parse_name ();
    skip_space ();
    if (target == "xml") {
      // since html==true implies we can accept horribly broken HTML, the
      // presence of an XML prolog is not enough to clear the flag.
      /* html= false; */
      while (s && !test (s, "?>")) {
	string attname= parse_name ();
	skip_space ();
	if (!test (s, "=")) break;
	s += 1;
	skip_space ();
	string val;
	if (test (s, "\"")) {
	  s += 1;
	  val= parse_until ("\"");
	  skip_space ();	  
	}
	else if (test (s, "'")) {
	  s += 1;
	  val= parse_until ("'");
	  skip_space ();
	}
	if (attname == "encoding") {
	  encoding= upcase_all (val);
	  break;
	}
      }
    }
  }

  if (N(encoding) != 0) {
    // cout << "encoding was specified\n" ;
    string s3= convert (s2, encoding, "UTF-8");
    if (N(s3) == 0)
      /* conversion from specified charset failed, do nothing (and pray) */ ;
    else return s3;
  }
  else {
    // cout << "guess encoding\n" ;
    if (check_encoding (s2, "UTF-8"))
      /* input encoding seems to be utf-8, do nothing */ ;
    else {
      string s3= convert (s2, "ISO-8859-1", "UTF-8");
      if (N(s3) != 0) return s3;
    }
  }

  return s2;
}
Beispiel #5
0
int
main(int argc, char **argv)
{
	audio_info_t ainfo;
	char *fname = NULL;
	int fd, i, c;
	int rate = 8000;

	while ((c = getopt(argc, argv, "f:r:t:")) != -1) {
		switch (c) {
		case 'f':
			fname = optarg;
			break;
		case 'r':
			if (get_int(optarg, &rate) || rate <= 0) {
				fprintf(stderr, "%s bad rate %s\n",
				    argv[0], optarg);
				return (1);
			}
			break;
		case 't':
			if (get_double(optarg, &playfreq) || playfreq <= 0.0) {
				fprintf(stderr, "%s bad freq %s\n",
				    argv[0], optarg);
				return (1);
			}
			break;
		case '?':
		default:
			fprintf(stderr, "%s [-f device]\n", argv[0]);
			return (1);
		}
	}

	if (fname == NULL)
		fname = DEFAULT_DEV;

	fd = open(fname, O_RDWR, 0);
	if (fd == -1)
		err(1, "open");


	if (ioctl(fd, AUDIO_GETINFO, &ainfo) == -1)
		err(1, "%s: audio_getinfo", fname);

	for (i = 0; ; i++) {
		audio_encoding_t enc;

		enc.index = i;
		if (ioctl(fd, AUDIO_GETENC, &enc) == -1)
			break;
		check_encoding(fd, &enc, rate);
	}
	close(fd);

	return (0);
}