当前位置: 首页>>代码示例>>C++>>正文


C++ split函数代码示例

本文整理汇总了C++中split函数的典型用法代码示例。如果您正苦于以下问题:C++ split函数的具体用法?C++ split怎么用?C++ split使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了split函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........
		default:
			if (apropos)
				usage_whatapro();
			else if (catman)
				usage_catman();
			else if (makewhatishere)
				usage_makewhatis();
			else
				usage_man();
		}
	}
	argc -= optind;
	argv += optind;

	if (argc == 0) {
		if (apropos) {
			(void) fprintf(stderr, gettext("%s what?\n"),
			    __progname);
			exit(1);
		} else if (!printmp && !makewhatis) {
			(void) fprintf(stderr,
			    gettext("What manual page do you want?\n"));
			exit(1);
		}
	}

	init_bintoman();
	if (manpath == NULL && (manpath = getenv("MANPATH")) == NULL) {
		if ((manpath = getenv("PATH")) != NULL)
			bmp_flags = BMP_ISPATH | BMP_APPEND_DEFMANDIR;
		else
			manpath = DEFMANDIR;
	}
	pathv = split(manpath, ':');
	mandirs = build_manpath(pathv, bmp_flags);
	freev(pathv);
	fullpaths(&mandirs);

	if (makewhatis) {
		do_makewhatis(mandirs);
		exit(0);
	}

	if (printmp) {
		print_manpath(mandirs);
		exit(0);
	}

	/* Collect environment information */
	if (isatty(STDOUT_FILENO) && (mwstr = getenv("MANWIDTH")) != NULL &&
	    *mwstr != '\0') {
		if (strcasecmp(mwstr, "tty") == 0) {
			struct winsize	ws;

			if (ioctl(0, TIOCGWINSZ, &ws) != 0)
				warn("TIOCGWINSZ");
			else
				manwidth = ws.ws_col;
		} else {
			manwidth = (int)strtol(mwstr, (char **)NULL, 10);
			if (manwidth < 0)
				manwidth = 0;
		}
	}
	if (manwidth != 0) {
		DPRINTF("-- Using non-standard page width: %d\n", manwidth);
开发者ID:bahamas10,项目名称:openzfs,代码行数:67,代码来源:man.c

示例2: split

 /**
  * This method will be invoked second, the argument data is what exactly
  * you serialized at method "serialize", that means the data is not given by
  * system, it's given by your own serialize method. So the format of data is
  * designed by yourself, and deserialize it here as you serialize it in 
  * "serialize" method.
  */
 TreeNode *deserialize(string data) {
     vector<string> strs = split(data, ',');
     return _deserialize(strs);
 }
开发者ID:ericshape,项目名称:Lintcode-US-Giants,代码行数:11,代码来源:binary-tree-serialization.cpp

示例3: split

void cv::split(const Mat& src, vector<Mat>& mv)
{
    split(_InputArray(src), _OutputArray(mv));
}
开发者ID:jguinet,项目名称:s2p,代码行数:4,代码来源:convert.cpp

示例4: condition

list<PropTerm> PropTerm::ontic_prog(const OnticAction& ontic_action)
{
    list<PropTerm> progression; //Maybe need to make current PropTerm split into some PropTerms

    vector<int> missing_atom;
    vector<PropTerm> conditions; //convert each con in effect triple to PropTerm 
    for (size_t eff_i = 0; eff_i < ontic_action.con_eff.size(); eff_i++) {
        ConEffect cur_con_eff = ontic_action.con_eff[eff_i];  //current effect triple         
        //convert vector<int> to PropTerm
        PropTerm condition(length);
        for (size_t i = 0; i < cur_con_eff.condition.size(); i++) {
            condition.literals.set(cur_con_eff.condition[i], true);
        }
        conditions.push_back(condition);
        //check current PropTerm. Mostly, splitting is necessary 
        if (!(this->entails(condition) || this->entails(condition.negation()))) {            
            // 把condition里面出现,但this里面没有出现过的原子加入missing_atom里面
            for (int l = 1; l <= length/2; ++ l) {
                int pos = (l - 1) * 2;
                int neg = (l - 1) * 2 + 1;
                if (! this->literals[pos] && ! this->literals[neg] && 
                        (condition.literals[pos] || condition.literals[neg])) {
                    missing_atom.push_back(l);
                }
            }
        }
    }

    if (missing_atom.empty())
        progression.push_back(*this);
    else {
        list<PropTerm> splitting_result;
        PropTerm cur_propTerm = *this;
        split(missing_atom, 0, cur_propTerm, splitting_result);
        progression.insert(progression.end(), splitting_result.begin(), 
                splitting_result.end());
    }

    //begin ontic progression for each PropTerm (many PropTerms are split by current PropTerm)
    for (list<PropTerm>::iterator it = progression.begin(); it != progression.end(); ++it) {
        PropTerm origin = *it;//保存没做之前的状态,用作判断条件
        for (size_t eff_i = 0; eff_i < ontic_action.con_eff.size(); ++eff_i) {
            if (origin.entails(conditions[eff_i])) {
                // deal with the elements in the lit set
                for (size_t lit_i = 0; lit_i < ontic_action.con_eff[eff_i].lits.size(); ++lit_i) {
                    size_t pos = ontic_action.con_eff[eff_i].lits[lit_i];
                    if (pos % 2 == 0) {
                        // positive literal
                        it->literals.set(pos, true);
                        it->literals.set(pos+1, false);
                    } else {
                        // negative literal
                        it->literals.set(pos, true);
                        it->literals.set(pos-1, false);
                    }
                }
            }
        }
    }
    
    return progression;
}
开发者ID:fangbq,项目名称:SingleAgentPlanner,代码行数:62,代码来源:EpisDNF.cpp

示例5: split

/**
 * Creates and returns a PropertyMap type from a string formatted as a Java properties file.
 *
 * @param propertyString A string formatted as a Java properties file containing name/value pairs.
 * @return A PropertyMap comprised of the name/value pairs in the propertyString.
 */
PropertyMap Updater::getPropertyMap(std::string propertyString)
{
  // Create an empty map associating a PropertyType with a string value
  PropertyMap propertyMap;

  // Create a vector to hold the lines in the properties string
  std::vector<std::string> lines;

  // Split propertyString into lines and store in a vector
  lines = split(propertyString, '\n');

  // Loop over all tokens
  for (unsigned int i = 0; i < lines.size(); i++)
  {
    std::string line = lines[i];

    // Create a new vector to hold the name and value
    std::vector<std::string> pair;

    // If the "=" character is found in this line
    if (line.find("=") != std::string::npos)
    {
      // Split the line into a property/value pair
      pair = split(line, '=');

      // Get the property name
      std::string property = pair[0];

      // Get the property value
      std::string value = pair[1];

      // FIXME! This switch can be removed with a map. ~JJB 20140404 15:06

      // If the property is "item_id"
      if (property == "item_id")
      {
        // Insert PropertyType ITEM_ID and the value
        propertyMap.insert(PropertyMap::value_type(ITEM_ID, value));
        // If the property is "url"
      }
      else if (property == "url")
      {
        // Insert PropertyType URL and the value
        propertyMap.insert(PropertyMap::value_type(URL, value));
        // If the property is "client_key"
      }
      else if (property == "client_key")
      {
        // Insert PropertyType CLIENT_KEY and the value
        propertyMap.insert(PropertyMap::value_type(CLIENT_KEY, value));
      }
      else if (property == "username")
      {
        // Insert the username into the map
        propertyMap.insert(PropertyMap::value_type(USERNAME, value));
      }
      else if (property == "password")
      {
        // Insert the password into the map
        propertyMap.insert(PropertyMap::value_type(PASSWORD, value));
      }
    }
  }

  // Return the property map
  return propertyMap;
}
开发者ID:laizy,项目名称:moose,代码行数:73,代码来源:Updater.cpp

示例6: s

ObjModel::ObjModel(std::string fileName, Singleton* s): s(s) {
    xpos = ypos = zpos = xrot = yrot = zrot = 0;
    this->obj = this;

    if(fileName == ""){
        return;
    }

    std::string dirName = fileName;
    if (dirName.rfind("/") != std::string::npos)
        dirName = dirName.substr(0, dirName.rfind("/"));
    if (dirName.rfind("\\") != std::string::npos)
        dirName = dirName.substr(0, dirName.rfind("\\"));
    if (fileName == dirName)
        dirName = "";


    std::ifstream pFile(fileName.c_str());

    if (!pFile.is_open()) {
        //std::cout << "Could not open file " << fileName << std::endl;
        return;
    }


    ObjGroup *currentGroup = new ObjGroup();
    currentGroup->materialIndex = -1;


    while (!pFile.eof()) {
        std::string line;
        std::getline(pFile, line);

        line = replace(line, "\t", " ");
        while (line.find("  ") != std::string::npos)
            line = replace(line, "  ", " ");
        if (line == "")
            continue;
        if (line[0] == ' ')
            line = line.substr(1);
        if (line == "")
            continue;
        if (line[line.length() - 1] == ' ')
            line = line.substr(0, line.length() - 1);
        if (line == "")
            continue;
        if (line[0] == '#')
            continue;

        std::vector<std::string> params = split(line, " ");
        params[0] = toLower(params[0]);

        if (params[0] == "v")
            vertices.push_back(new Vec3f((float) atof(params[1].c_str()), (float) atof(params[2].c_str()),
                                         (float) atof(params[3].c_str())));
        else if (params[0] == "vn")
            normals.push_back(new Vec3f((float) atof(params[1].c_str()), (float) atof(params[2].c_str()),
                                        (float) atof(params[3].c_str())));
        else if (params[0] == "vt")
            texcoords.push_back(new Vec2f((float) atof(params[1].c_str()), (float) atof(params[2].c_str())));
        else if (params[0] == "f") {
            for (size_t ii = 4; ii <= params.size(); ii++) {
                Face face;

                for (size_t i = ii - 3; i < ii; i++)    //magische forlus om van quads triangles te maken ;)
                {
                    Vertex vertex;
                    std::vector<std::string> indices = split(params[i == (ii - 3) ? 1 : i], "/");
                    if (indices.size() >= 1)    //er is een positie
                        vertex.position = atoi(indices[0].c_str()) - 1;
                    if (indices.size() == 2)        //alleen texture
                        vertex.texcoord = atoi(indices[1].c_str()) - 1;
                    if (indices.size() == 3)        //v/t/n of v//n
                    {
                        if (indices[1] != "")
                            vertex.texcoord = atoi(indices[1].c_str()) - 1;
                        vertex.normal = atoi(indices[2].c_str()) - 1;
                    }
                    face.vertices.push_back(vertex);
                }
                currentGroup->faces.push_back(face);
            }
        }
        else if (params[0] == "s") {//smoothing
        }
        else if (params[0] == "mtllib") {
            loadMaterialFile(dirName + "/" + params[1], dirName);
        }
        else if (params[0] == "usemtl") {
            if (currentGroup->faces.size() != 0)
                groups.push_back(currentGroup);
            currentGroup = new ObjGroup();
            currentGroup->materialIndex = -1;

            for (size_t i = 0; i < materials.size(); i++) {
                MaterialInfo *info = materials[i];
                if (info->name == params[1]) {
                    currentGroup->materialIndex = i;
                    break;
                }
//.........这里部分代码省略.........
开发者ID:yorickr,项目名称:CV-solo,代码行数:101,代码来源:ObjModel.cpp

示例7: split

		static std::vector<std::string> split(const std::string &input, const std::string &delimiter)
		{
			std::vector<std::string> output;
			split(output, input, delimiter);
			return output;
		}
开发者ID:ThirdPartyNinjas,项目名称:NinjaParty,代码行数:6,代码来源:Path.cpp

示例8: MyProcessDatFileIII

int MyProcessDatFileIII(char* DatFileBuffer, int procid, vector<int> AllColumnIDList, vector<vector<int> > ColKeyToAllAlleleByPopList, vector<vector<vector<int> > >& AllAlleleByPopList, vector<std::string>& FullAccessionNameList, vector<std::string>& IndivPerPop, vector<int>& AllAlleles, std::string Rarify)
{
	//declare variables
	std::string foo;
	vector<std::string> foovector;
	std::string OldLocusName;
	std::string CurrLocusName;
	vector<std::string> LocusNames;
	vector<vector<std::string> > ActiveAlleleList;
	vector<std::string> OldAlleles;
	vector<vector<std::string> > TempList2d;
	vector<std::string> FilteredData;
	vector<std::string> ListToFilter;
	std::string IsNewPop = "no";
	vector<std::string>::iterator it;
	
	//initialize important data structures, unsized
	vector<vector<set<int> > > AllAlleleByPopListSet; //structure of this 3D vector is:
	// { { {pop1,loc1 alleles},{pop1,loc2 alleles},...}, { {pop2,loc1 alleles},{pop2,loc2 alleles},...} } }
	// this is the same structure as the vector<vector<vector<int> > > AllAlleleByPopList
	// if Rarify == "yes", AllAlleleByPopList just becomes ByPop3d.  if Rarify == "no", ByPop3d is reduced
	// to unique alleles at each locus using AllAlleleByPopListSet, then converted back into the vector
	// AllAlleleByPopList, which is updated as a reference


	unsigned int i,j,k,l;
	vector<std::string> bufvec;
	std::string NewPopID;
	std::string OldPopID = "init*@#rt4"; //use an unlikely population name for the initialization value

	if (procid == 0) cout << "  Reading data matrix...\n";
	//start the clock
	time_t startm,endm;
	time (&startm);

	//put giant char array buffer into a stream, then delete the buffer to save memory 
	stringstream s(DatFileBuffer);
	strcpy(DatFileBuffer,""); //clear char* 
	
	
	//read buffer into a vector, one line per item
	while (getline(s, foo))//get line from s, put in foo, consecutively
	{
		bufvec.push_back(foo);  
	}
	
	s.str(""); //clear stringstream
	int row = bufvec.size();
		
	//sort vector so that individuals from the same population form consecutive elements
	std::sort(bufvec.begin(), bufvec.end()); //no need to use fancy sort, lexicographic should be fine
		
	//split lines of bufvec into 2d vector
	vector<vector<std::string> > bufvec2d(bufvec.size()); 
	for (i=0;i<bufvec.size();++i) bufvec2d[i] = split(bufvec[i]);
	vector<std::string>().swap(bufvec); //clear bufvec
	
	//stop the clock
	time (&endm);
	double dif = difftime (endm,startm);
	if (procid == 0) 
	{
		if (dif==1) cout << "    " << dif << " second.\n";	
		else cout << "    " << dif << " seconds.\n";
	}
	
	//convert alleles to integer coding to save memory, vector access order 2
	if (procid == 0) 
	{
		cout << "  Recoding data...\n";
		time (&startm);
	}

	vector<vector<int> > bufvec2dint(bufvec2d.size(), vector<int>(bufvec2d[0].size())); //declare and size vector to hold new integer coded alleles
	unsigned int iz = ColKeyToAllAlleleByPopList.size();
	for (unsigned int i=0;i<iz;++i) //go thru each locus
	{
		//get all alleles at the locus
		vector<std::string> AllelesEncountered; //will contain the unique set of alleles at the locus
		unsigned int kz = bufvec2d.size();
		for (unsigned int k=0;k<kz;++k) //go thru all individuals
		{
			unsigned int jz = ColKeyToAllAlleleByPopList[i].size();
			for (unsigned int j=0;j<jz;++j) //get all alleles for an individual at this locus, then move to next indiv
			{
				int ColIndex = ColKeyToAllAlleleByPopList[i][j];
				std::string a = bufvec2d[k][ColIndex];  
				if (a == "9999") bufvec2dint[k][ColIndex] = -9999; //add the missing data value
				else
				{
					int AlleleInt; //the new, integerized, name of the allele
					std::vector<std::string>::iterator itr = std::find(AllelesEncountered.begin(), AllelesEncountered.end(), a);
					if (itr != AllelesEncountered.end()) //the allele has been found before
					{
						AlleleInt = itr - AllelesEncountered.begin(); //convert itr to index, the index is the integerized allele name
						bufvec2dint[k][ColIndex] = AlleleInt; //add the new name
					}
					else // you have a new allele
					{
						AllelesEncountered.push_back(a); //add new allele to list of those encountered
//.........这里部分代码省略.........
开发者ID:NCGRP,项目名称:MplusMPI,代码行数:101,代码来源:m+.cpp

示例9: MyProcessVarFile

int MyProcessVarFile(char* VarFileBuffer, vector<int>& AllColumnIDList, vector<std::string>& AllLociNameList, vector<int>& ActiveColumnIDList, vector<std::string>& ActiveLociNameList, vector<int>& TargetColumnIDList, vector<std::string>& TargetLociNameList, vector<vector<int> >& ColKeyToAllAlleleByPopList, vector<int>& ReferenceOrTargetKey, vector<int>& PloidyList, vector<std::string>& UniqLociNameList)
{
    //declare variables
    std::string foo;
    vector<std::string> foovector;
    unsigned int k;

    int i=0; // i is the row number

	std::string vfb(VarFileBuffer); //convert char* to string
    std::istringstream iss(vfb); //open string as a stream
    while (std::getline(iss, foo)) //cycle line by line, placing line in foo
    {
	    //split foo on whitespace
		foovector = split(foo);
		
		if (foovector.size() != 0) //omit the hanging last line, which has no information
		{
		
			//identify active columns with qualitative data, classify those as reference or target
			if (foovector[1] == "2") //column holds qualitative data
			{
				AllColumnIDList.push_back(i);
				AllLociNameList.push_back(foovector[0]);
				
				if ((foovector[2] == "1") && (foovector[3] == "0")) //reference variable
				{
					ActiveColumnIDList.push_back(i);
					ActiveLociNameList.push_back(foovector[0]);
				}
				else if ((foovector[2] == "0") && (foovector[3] == "1"))  //target variable
				{
					TargetColumnIDList.push_back(i);
					TargetLociNameList.push_back(foovector[0]);
				}
			}
		 
			i++;
			foovector.clear();  //zero vector foovector
		}
    }
	
	//make a key showing which loci are target and which are reference
	//this will be used later to sort out the AllAlleleByPopList
	std::string uniqloc;
	std::string currloc;
	
	//find unique locus names, retains sort order
	UniqLociNameList = unsortedRemoveDuplicates(AllLociNameList);

	//tabulate the ploidy for each locus
	PloidyList = GetPloidy(AllLociNameList, UniqLociNameList);
	
	//define 2d vector that is key to columns, size to number of unique loci
	ColKeyToAllAlleleByPopList.resize( UniqLociNameList.size() ); //size to number of loci
	int b;
	for (unsigned int i=0;i<UniqLociNameList.size();++i)
	{
		uniqloc = UniqLociNameList[i];
		for (k=0;k<AllLociNameList.size();++k)
		{
			currloc = AllLociNameList[k];
			if (currloc == uniqloc)
			{
				b = AllColumnIDList[k]; //get the corresponding value in the columnID list
				ColKeyToAllAlleleByPopList[i].push_back(b);	
			}	
		}		
	}
	
	//define a 1d vector that describes whether the loci in the ColKey are reference(0) or target(1)
	double rt;
	ReferenceOrTargetKey.resize( ColKeyToAllAlleleByPopList.size() ); //sized to same length as key
	for (unsigned int i=0;i<ColKeyToAllAlleleByPopList.size();++i)
	{
		rt=0;
		//test whether all elements are categorized as reference or as target, if not, raise error
		for (k=0;k<ColKeyToAllAlleleByPopList[i].size();++k)
		{
			b=ColKeyToAllAlleleByPopList[i][k];
			if(std::find(ActiveColumnIDList.begin(), ActiveColumnIDList.end(), b) != ActiveColumnIDList.end())
			{
   			 	//column is reference
   			 	rt=rt+0;
			} 
			else if(std::find(TargetColumnIDList.begin(), TargetColumnIDList.end(), b) != TargetColumnIDList.end())
			{
    			//column is target
    			rt=rt+1;
			}
		}
		
		//test whether columns in key represent reference or target loci
		if (rt == 0) ReferenceOrTargetKey[i] = 0; //it is a reference
		else if (  rt/ColKeyToAllAlleleByPopList[i].size() == 1 ) ReferenceOrTargetKey[i] = 1; //it is a target
		else 
		{
			cout << "ERROR:  Some loci are described as both reference and target.  Please check your var file. Quitting...\n\n";
			exit (EXIT_FAILURE);
		}
//.........这里部分代码省略.........
开发者ID:NCGRP,项目名称:MplusMPI,代码行数:101,代码来源:m+.cpp

示例10: readnewline

static const string * readnewline(FormatState * fs){
	return split(fs, Newline);
}
开发者ID:dansen,项目名称:luacode,代码行数:3,代码来源:luaformat.c

示例11: split

Polygon* Polygon_Reader::Parse_Polygon(string line)
{
	size_t start, end, pos;
	std::string head_str, gml_str;
	std::vector<std::string> temp_str_array;
	std::vector<std::string> coord_array;

	pos = line.find_first_of("<");
	head_str = line.substr(0, pos);
	split(head_str,':',temp_str_array);
	gml_str = line.substr(pos);

	start = gml_str.find_first_of("<");
	end= gml_str.find_first_of(">");
	std::string tag = gml_str.substr(start, end - start);
	std::string tag_name = "";

	start = tag.find_first_of("<"); 
	tag_name = tag_name + tag.substr(start, tag.find_first_of(" ") - start);
	tag_name = tag_name + ">";
	tag_name.insert(1, "/");

	start = end + 1;
	end = gml_str.find(tag_name);
	gml_str = gml_str.substr(start, end - start);    //get rid of polygon tag

	start = gml_str.find_first_of("<");
	end = gml_str.find_first_of(">");
	tag = gml_str.substr(start, end - start + 1);

	tag_name = tag;
	tag_name.insert(1, "/");

	//remove the tags of the outerBoundary
	start = end + 1;
	end = gml_str.find(tag_name);
	std::string tag_value = gml_str.substr(start, end - start);
	gml_str = gml_str.substr(gml_str.find(tag_name) + tag_name.length());   //rest of the string after remove the outer Boundary part

	start = tag_value.find("<gml:coordinates");
	end = tag_value.find("</gml:coordinates");
	std::string tmp_str = tag_value.substr(start, end - start);
	std::string Coord = tmp_str.substr(tmp_str.find_first_of(">") + 1);
		
	split(Coord, ' ', coord_array);
	std::vector<std::string> xy_array;
	LinearRing* lr_OB = new LinearRing();
	for (std::string xy : coord_array){
		split(xy, ',', xy_array);
		lr_OB->Add_Point(new Point(stod(xy_array[0]), stod(xy_array[1])));
		xy_array.clear();
	}

	OuterBoundary* OB = new OuterBoundary(lr_OB);
	Polygon* poly = new Polygon(stoi(temp_str_array[1]), stoi(temp_str_array[2]), OB);

	xy_array.clear();
	coord_array.clear();

	while (gml_str != "")
	{
		start = gml_str.find_first_of("<");
		end = gml_str.find_first_of(">");
		tag = gml_str.substr(start, end - start + 1);
		if (tag.find("innerBoundaryIs")!= 0){
			tag_name = tag;
			tag_name.insert(1, "/");

			start = end + 1;
			end = gml_str.find(tag_name);
			std::string tag_value = gml_str.substr(start, end - start);
			gml_str = gml_str.substr(gml_str.find(tag_name) + tag_name.length());
			
			start = tag_value.find("<gml:coordinates");
			end = tag_value.find("</gml:coordinates");
			tmp_str = tag_value.substr(start, end - start);
			Coord = tmp_str.substr(tmp_str.find_first_of(">") + 1);
			split(Coord, ' ', coord_array);

			LinearRing* lr_IB = new LinearRing();
			for (std::string xy: coord_array){
				split(xy, ',', xy_array);
				lr_IB->Add_Point(new Point(stod(xy_array[0]), stod(xy_array[1])));
				xy_array.clear();
			}
			poly->Add_Inner_Boundary(new InnerBoundary(lr_IB));
			xy_array.clear();
	        coord_array.clear();
		}
	}

	return poly;
}
开发者ID:kangpingsi,项目名称:Geofence,代码行数:93,代码来源:Polygon_Reader.cpp

示例12: main

int main(int argc, char const *argv[]) {

      FILE *fp;
      FILE* stream;
      char buf[MAXBUF];
      char buf2[MAXBUF];
      int i=0;
      int j=0;
      char *lines[MAXBUF];
      int status;
      int wpid;

      fp=fopen(argv[1], "r");
      if (fp == NULL)
            exit(EXIT_FAILURE);

      while(fgets(buf, MAXBUF, fp)){
                  lines[i]=strdup(buf);
                  i++;
      }

      pid_t *pids = malloc(i * sizeof(pid_t));
      buffer *text = malloc (i * sizeof(buffer));
      char *cmd[MAX_ARGS];

      for (int n  = 0 ; n < i ; n++) { // Start i at 0, not at 1

            if( pipe(text[n].mypipe) == -1){
                perror("Pipe failed");
                exit(1);
              }

            pid_t pid = fork();
            if (pid == -1) {                                                  //sono nel padre, errore della fork
                  fprintf(stderr, "forking error\n");
                  exit(1);
            } else if (pid == 0){
                  printf("Sono l'%d figlio\n", n );
                  close(STDOUT_FILENO);  //closing stdout
          		close(text[n].mypipe[0]);	   //closing pipe read
                  dup2(text[n].mypipe[1], 1);                                           //sono nel figlio quindi eseguo
                  split( cmd , lines[n]);
                  execvp(cmd[0], cmd);

          		exit(EXIT_FAILURE);
            } else {
            pids[n] = pid;
            text[n].pid=pid;                                                     //sono di nuovo nel padre ma è andato a buon fine quindi mi salvo il pid del figlio
            }

      }
      for (int k=0; k<i; k++){
            printf("%d\n", pids[k] );
      }
      wpid=wait(&status);
      printf("Child with PID %ld exited with status 0x%x.\n", (long)wpid, status);
      while (j<i) {
            if (wpid == text[j].pid) {
                  close(STDIN_FILENO);  //closing stdout
          		close(text[j].mypipe[1]);	   //closing pipe read
                  stream = fdopen(text[j].mypipe[0], "r");
                  while(fgets(buf2, MAXBUF, stream)){
                              printf("%s\n", buf2 );
                  }



            }
            else if(wpid != pids[j]) {
                  printf("%d\n", pids[j] );
                  if ( kill(pids[j], SIGKILL))
                        { printf("Failur\n" );}
                  }
            j++;
      }

      fclose(fp);
  return 0;
}
开发者ID:ob2410,项目名称:Esercizi_SO,代码行数:79,代码来源:es2.c

示例13: split

void DiscName::test() {
	DiscData d;
	d = split( "vcd://1//dev/dvd/" );
	d = split( "vcd://1/E:/" );
	d = split( "vcd://5" );
	d = split( "vcd://" );
	d = split( "vcd:////dev/dvdrecorder" );

	d = split( "dvd://1//dev/dvd" );
	d = split( "dvd://1/E:" );
	d = split( "dvd://5" );
	d = split( "dvd://" );
	d = split( "dvd:" );
	d = split( "dvd:////dev/dvdrecorder" );

	d = split( "cdda://1//dev/dvd" );
	d = split( "cdda://1/E:" );
	d = split( "cdda://5" );
	d = split( "cdda://" );
	d = split( "cdda:////dev/dvdrecorder" );

	d = split( "dvdnav://1//dev/dvd" );
	d = split( "dvdnav://1/D:/" );
	d = split( "dvdnav://5" );
	d = split( "dvdnav://" );
	d = split( "dvdnav:////dev/dvdrecorder/" );

	d = split( "br://1//dev/dvd" );
	d = split( "br://1/D:/" );
	d = split( "br://5" );
	d = split( "br://" );
	d = split( "br:////dev/dvdrecorder/" );

	QString s;
	s = join( DVD, 4, "/dev/dvd/" );
	s = join( DVD, 2, "E:" );
	s = join( DVD, 3, "E:/" );
	s = join( DVDNAV, 5, "/dev/dvdrecorder" );
	s = join( VCD, 1, "/dev/cdrom" );
	s = join( CDDA, 10, "/dev/cdrom" );
	s = joinDVD( 1, "/dev/cdrom", false );
	s = joinDVD( 2, "/dev/cdrom/", true );
	s = joinDVD( 3, "", true );
	s = join( VCD, 3, "" );
	s = join( BLURAY, 2, "/dev/cdrom");
}
开发者ID:corossig,项目名称:smplayer-mpv,代码行数:46,代码来源:discname.cpp

示例14: build_manpath

/*
 * This routine builds the manpage structure from MANPATH or PATH,
 * depending on flags.  See BMP_* definitions above for valid
 * flags.
 */
static struct man_node *
build_manpath(char **pathv, int flags)
{
	struct man_node *manpage = NULL;
	struct man_node *currp = NULL;
	struct man_node *lastp = NULL;
	char		**p;
	char		**q;
	char		*mand = NULL;
	char		*mandir = DEFMANDIR;
	int		s;
	struct dupnode	*didup = NULL;
	struct stat	sb;

	s = sizeof (struct man_node);
	for (p = pathv; *p != NULL; ) {
		if (flags & BMP_ISPATH) {
			if ((mand = path_to_manpath(*p)) == NULL)
				goto next;
			free(*p);
			*p = mand;
		}
		q = split(*p, ',');
		if (stat(q[0], &sb) != 0 || (sb.st_mode & S_IFDIR) == 0) {
			freev(q);
			goto next;
		}

		if (access(q[0], R_OK | X_OK) == 0) {
			/*
			 * Some element exists.  Do not append DEFMANDIR as a
			 * fallback.
			 */
			flags &= ~BMP_FALLBACK_DEFMANDIR;

			if ((currp = (struct man_node *)calloc(1, s)) == NULL)
				err(1, "calloc");

			currp->frompath = (flags & BMP_ISPATH);

			if (manpage == NULL)
				lastp = manpage = currp;

			getpath(currp, p);
			getsect(currp, p);

			/*
			 * If there are no new elements in this path,
			 * do not add it to the manpage list.
			 */
			if (dupcheck(currp, &didup) != 0) {
				freev(currp->secv);
				free(currp);
			} else {
				currp->next = NULL;
				if (currp != manpage)
					lastp->next = currp;
				lastp = currp;
			}
		}
		freev(q);
next:
		/*
		 * Special handling of appending DEFMANDIR. After all pathv
		 * elements have been processed, append DEFMANDIR if needed.
		 */
		if (p == &mandir)
			break;
		p++;
		if (*p != NULL)
			continue;
		if (flags & (BMP_APPEND_DEFMANDIR | BMP_FALLBACK_DEFMANDIR)) {
			p = &mandir;
			flags &= ~BMP_ISPATH;
		}
	}

	free_dupnode(didup);

	return (manpage);
}
开发者ID:bahamas10,项目名称:openzfs,代码行数:86,代码来源:man.c

示例15: fa

//******************************************************************************
// Mask the Fasta file based on the coordinates in the BED file.
//******************************************************************************
void MaskFastaFromBed::MaskFasta() {

    /* Make sure that we can open all of the files successfully*/

    // open the fasta database for reading
    ifstream fa(_fastaInFile.c_str(), ios::in);
    if ( !fa ) {
        cerr << "Error: The requested fasta file (" << _fastaInFile << ") could not be opened. Exiting!" << endl;
        exit (1);
    }

    // open the fasta database for reading
    ofstream faOut(_fastaOutFile.c_str(), ios::out);
    if ( !faOut ) {
        cerr << "Error: The requested fasta output file (" << _fastaOutFile << ") could not be opened. Exiting!" << endl;
        exit (1);
    }


    /* Read the fastaDb chromosome by chromosome*/
    string fastaInLine;
    string currChromFull;
    string currChrom;
    string currDNA = "";
    currDNA.reserve(500000000);
    int fastaWidth = -1;
    bool widthSet  = false;
    int start, end, length;
    string replacement;

    while (getline(fa,fastaInLine)) {

        if (fastaInLine.find(">",0) != 0 ) {
            if (widthSet == false) {
                fastaWidth = fastaInLine.size();
                widthSet = true;
            }
            currDNA += fastaInLine;
        }
        else {
            if (currDNA.size() > 0) {

                vector<BED> bedList = _bed->bedMapNoBin[currChrom];

                /*
                    loop through each BED entry for this chrom and
                    mask the requested sequence in the FASTA file.
                */
                for (unsigned int i = 0; i < bedList.size(); i++) {
                    start = bedList[i].start;
                    end = bedList[i].end;
                    length = end - start;

                    /*
                       (1) if soft masking, extract the sequence, lowercase it,
                           then put it back
                       (2) otherwise replace with Ns
                    */
                    if (_softMask) {
                        replacement = currDNA.substr(start, length);
                        toLowerCase(replacement);
                        currDNA.replace(start, length, replacement);
                    }
                    else {
                        string hardmask(length, _maskChar);
                        currDNA.replace(start, length, hardmask);
                    }
                }
                // write the masked chrom to the output file
                PrettyPrintChrom(faOut, _useFullHeader ? currChromFull : currChrom, currDNA, fastaWidth);
            }

            // reset for the next chromosome.
            currChromFull = fastaInLine.substr(1);
            currChrom = split(currChromFull, " \t").at(0);
            currDNA = "";
        }
    }

    // process the last chromosome.
    // exact same logic as in the main loop.
    if (currDNA.size() > 0) {

        vector<BED> bedList = _bed->bedMapNoBin[currChrom];

        for (unsigned int i = 0; i < bedList.size(); i++) {
            start = bedList[i].start;
            end = bedList[i].end;
            length = end - start;

            if (_softMask) {
                replacement = currDNA.substr(start, length);
                toLowerCase(replacement);
                currDNA.replace(start, length, replacement);
            }
            else {
                string hardmask(length, _maskChar);
//.........这里部分代码省略.........
开发者ID:ablab,项目名称:quast,代码行数:101,代码来源:maskFastaFromBed.cpp


注:本文中的split函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。