Example #1
0
static const char *next_name(const char *names, unsigned *len)
{
	names += *len;
	if (names[0] == ' ' || names[0] == '=' || names[0] == '\0')
		return NULL;
	return first_name(names + 1, len);
}
Example #2
0
DataFrame human_parse::parse_vector(std::vector < std::string > names){
  
  // Measure and construct output
  unsigned int input_size = names.size();
  std::vector < std::string > salutation(input_size);
  std::vector < std::string > first_name(input_size);
  std::vector < std::string > middle_name(input_size);
  std::vector < std::string > last_name(input_size);
  std::vector < std::string > suffix(input_size);
  std::vector < std::string > holding(5);
  
  // For each element, go nuts
  for(unsigned int i = 0; i < input_size; i++){
    if((i % 10000) == 0){
      Rcpp::checkUserInterrupt();
    }
    
    holding = parse_single(names[i]);
    salutation[i] = holding[0];
    first_name[i] = holding[1];
    middle_name[i] = holding[2];
    last_name[i] = holding[3];
    suffix[i] = holding[4];

  }
  
  return DataFrame::create(_["salutation"] = salutation,
                           _["first_name"] = first_name,
                           _["middle_name"] = middle_name,
                           _["last_name"] = last_name,
                           _["suffix"] = suffix,
                           _["full_name"] = names,
                           _["stringsAsFactors"] = false);
}
Example #3
0
int find_path(xfs_mount_t *mp, const char *path, xfs_inode_t **result) {
    xfs_inode_t *current;
    xfs_ino_t inode;
    struct xfs_name xname;
    int error;
   
    error = libxfs_iget(mp, NULL, mp->m_sb.sb_rootino, 0, &current, 0);
    assert(error==0);
    
    xname = first_name(path);
    while (xname.len != 0) {
        if (!(current->i_d.di_mode & S_IFDIR)) {
            libxfs_iput(current, 0);
            return XFS_ERROR(ENOTDIR);
        }
        
        error = libxfs_dir_lookup(NULL, current, &xname, &inode, NULL);
        if (error != 0) {
            return error;
        }

        /* Done with current: make it available */
        libxfs_iput(current, 0);

        error = libxfs_iget(mp, NULL, inode, 0, &current, 0);
        if (error != 0) {
            printf("Failed to get inode for %s %d\n", xname.name, xname.len);
            return XFS_ERROR(EIO);
        }
        xname = next_name(xname);
    }
    *result = current;
    return 0;
}
Example #4
0
static const char *first_opt(unsigned *i, unsigned *len)
{
	for (*i = 0; *i < opt_count; (*i)++) {
		if (opt_table[*i].type == OPT_SUBTABLE)
			continue;
		return first_name(opt_table[*i].names, len);
	}
	return NULL;
}
Example #5
0
static const char *next_opt(const char *p, unsigned *i, unsigned *len)
{
	for (; *i < opt_count; (*i)++) {
		if (opt_table[*i].type == OPT_SUBTABLE)
			continue;
		if (!p)
			return first_name(opt_table[*i].names, len);
		p = next_name(p, len);
		if (p)
			return p;
	}
	return NULL;
}
Example #6
0
DataFrame human_parse::parse_vector(CharacterVector names){
  
  // Measure and construct output
  unsigned int input_size = names.size();
  CharacterVector salutation(input_size);
  CharacterVector first_name(input_size);
  CharacterVector middle_name(input_size);
  CharacterVector last_name(input_size);
  CharacterVector suffix(input_size);
  CharacterVector holding(5);
  
  // For each element, go nuts
  for(unsigned int i = 0; i < input_size; i++){
    if((i % 10000) == 0){
      Rcpp::checkUserInterrupt();
    }
    
    if(names[i] == NA_STRING){
      salutation[i] = NA_STRING;
      first_name[i] = NA_STRING;
      middle_name[i] = NA_STRING;
      last_name[i] = NA_STRING;
      suffix[i] = NA_STRING;
    } else {
      holding = parse_single(Rcpp::as<std::string>(names[i]));
      salutation[i] = holding[0];
      first_name[i] = holding[1];
      middle_name[i] = holding[2];
      last_name[i] = holding[3];
      suffix[i] = holding[4];
    }


  }
  
  return DataFrame::create(_["salutation"] = salutation,
                           _["first_name"] = first_name,
                           _["middle_name"] = middle_name,
                           _["last_name"] = last_name,
                           _["suffix"] = suffix,
                           _["full_name"] = names,
                           _["stringsAsFactors"] = false);
}
Example #7
0
static void check_opt(const struct opt_table *entry)
{
	const char *p;
	unsigned len;

	if (entry->type != OPT_HASARG && entry->type != OPT_NOARG
	    && entry->type != (OPT_EARLY|OPT_HASARG)
	    && entry->type != (OPT_EARLY|OPT_NOARG))
		failmsg("Option %s: unknown entry type %u",
			entry->names, entry->type);

	if (!entry->desc)
		failmsg("Option %s: description cannot be NULL", entry->names);


	if (entry->names[0] != '-')
		failmsg("Option %s: does not begin with '-'", entry->names);

	for (p = first_name(entry->names, &len); p; p = next_name(p, &len)) {
		if (*p == '-') {
			if (len == 1)
				failmsg("Option %s: invalid long option '--'",
					entry->names);
			opt_num_long++;
		} else {
			if (len != 1)
				failmsg("Option %s: invalid short option"
					" '%.*s'", entry->names, len+1, p-1);
			opt_num_short++;
			if (entry->type == OPT_HASARG)
				opt_num_short_arg++;
		}
		/* Don't document args unless there are some. */
		if (entry->type == OPT_NOARG) {
			if (p[len] == ' ' || p[len] == '=')
				failmsg("Option %s: does not take arguments"
					" '%s'", entry->names, p+len+1);
		}
	}
}