コード例 #1
0
ファイル: IRC.cpp プロジェクト: iamnilay3/openlierox
/////////////////////////
// Initializes the IRC client and connects to the server (specified in options)
bool InitializeIRC()
{
	// Already initialized?
	if (globalIRC)
		return true;

	if (!tLXOptions->bEnableChat)
		return false;

	// Allocate the IRC client
	try  {
		globalIRC = new IRCClient();
	} catch (...)  {
		return false;
	}

	// Get the server
	FILE *fp = OpenGameFile("cfg/chatserver.txt", "r");
	if (fp)  {
		std::string addr = ReadUntil(fp, '/');
		std::string chann = ReadUntil(fp, '\n');
		fclose(fp);
		return globalIRC->connect(addr, chann, tLXOptions->sLastSelectedPlayer);
	} else { // Defaults
		return globalIRC->connect("irc.quakenet.org", "#LieroX", tLXOptions->sLastSelectedPlayer);
	}
}
コード例 #2
0
ファイル: treefile.c プロジェクト: fredericlemoine/Seq-Gen
TNode *ReadBranch(FILE *fv, TTree *tree, int numNames, char **names)
{
	char ch;
	double len, param=0.0;
	TNode *node;
	
	ch=ReadToNextChar(fv);
	if (ch=='(') {	/* is a node */
		node=ReadNode(fv, tree, numNames, names, 1);
		ReadUntil(fv, ')', "Closing bracket");
		if (treeError)
			return NULL;
	} else {		/* is a tip */
		node=ReadTip(fv, ch, tree, numNames, names);
	}
	
	ch=ReadToNextChar(fv);
	if (ch==':') {
		if (tree->lengths==0) {
			sprintf(treeErrorMsg, "Some branches don't have branch lengths");
			return NULL;
		} else 
			tree->lengths=1;
			
		if (fscanf(fv, "%lf", &len)!=1) {
			sprintf(treeErrorMsg, "Unable to read branch length");
			return NULL;
		}

		ch=ReadToNextChar(fv);
		if (ch=='[') {
			if (fscanf(fv, "%lf", &param)!=1) {
				sprintf(treeErrorMsg, "Unable to read branch parameter");
				return NULL;
			}
			ReadUntil(fv, ']', "Close square bracket");
		} else
			ungetc(ch, fv);
	} else {
		if (tree->lengths==1) {
			sprintf(treeErrorMsg, "Some branches don't have branch lengths");
			return NULL;
		} else 
			tree->lengths=0;
	
		len=0.0;
		ungetc(ch, fv);
	}
	node->length0=len;
	node->param=param;
	
	return node;
}	
コード例 #3
0
ファイル: CWpnRest.cpp プロジェクト: iamnilay3/openlierox
///////////////////
// Load the weapons restrictions list
void CWpnRest::loadList(const std::string& szFilename, const std::string& moddir)
{
    // Shutdown the list first
    Shutdown();

    std::string fn = szFilename;
    if(!strCaseStartsWith(fn, "cfg/")) {
        if(fn.size() > 4 && !stringcaseequal(fn.substr(fn.size()-4), ".wps"))
            fn += ".wps";
        if(moddir != "" && IsFileAvailable("cfg/presets/" + moddir + "/" + fn))
            fn = "cfg/presets/" + moddir + "/" + fn;
        else
            fn = "cfg/presets/" + fn;
    }

    FILE *fp = OpenGameFile(fn, "rt");
    if( !fp )
        return;

    std::string line;

    while( !feof(fp) && !ferror(fp) ) {
        line = ReadUntil(fp, '\n');
        std::vector<std::string> exploded = explode(line,",");
        if (exploded.size() >= 2)
            addWeapon(exploded[0],from_string<int>(exploded[1]));
    }

    fclose(fp);

    // Sort the list
    sortList();
}
コード例 #4
0
ファイル: Tokenizer.cpp プロジェクト: MichaelKohler/gecko-dev
bool
Tokenizer::ReadUntil(Token const& aToken, nsACString& aResult, ClaimInclusion aInclude)
{
  nsDependentCSubstring substring;
  bool rv = ReadUntil(aToken, substring, aInclude);
  aResult.Assign(substring);
  return rv;
}
コード例 #5
0
ファイル: roomread.c プロジェクト: jcharr1/escape-from-limbo
boolean RoomReader(FILE * datFile)
{
    /*----local vars----*/
    int x = 0, y = 0,    // x,y coords
    i = 0,           // counter
    value = 0;       // generic input value
    
    char title[ROOM_MAX_TITLE_LEN] = {'\0'},
    descrip[MAX_DESCRIP_LEN] = {'\0'},
    delimiter,
    temp;        // used to check for eof
    
    //roomType rooms[UNI_MAX_X][UNI_MAX_Y]; //update 4/30 Michael Simpson
    
    
    if(!datFile)
    {
        //fprintf(stderr, "Invalid data file passed to RoomReader!\n");
        return(FALSE);
    }
    
    temp = fgetc(datFile);
    while(!feof(datFile))
    {
        ungetc(temp, datFile);
        fscanf(datFile, " %d %d", &x, &y);
        ReadLine(title, ROOM_MAX_TITLE_LEN, datFile);
        rmSetTitle(&(rooms[x][y]), title);
        delimiter = fgetc(datFile);
        ReadUntil(descrip, MAX_DESCRIP_LEN, delimiter, datFile);
        rmSetDescrip(&(rooms[x][y]), descrip);
        for(i = 0; i < MAX_DIRECTIONS; i++)
        {
            fscanf(datFile, " %d", &value);
            if(value == 1)
            {
                directionType dir = (directionType)i;
                rmSetValidExit(&(rooms[x][y]), dir);
            }
        }
        fscanf(datFile, " %d", &value);
        if(value == 0)
            rmUnlock(&(rooms[x][y]));
        
        rmSetWall(&(rooms[x][y]), FALSE);
        
        ClearStr(title, ROOM_MAX_TITLE_LEN);
        ClearStr(descrip, MAX_DESCRIP_LEN);
        value = 0;
        
        temp = fgetc(datFile);
    }
    
    return(TRUE);
}
コード例 #6
0
ファイル: treefile.c プロジェクト: fredericlemoine/Seq-Gen
TNode *ReadNode(FILE *fv, TTree *tree, int numNames, char **names, int detectPolytomies)
{
	TNode *node, *node2;
	char ch;
	
	if ((node=NewNode(tree))==NULL)
		return NULL;

	if ((node2=ReadBranch(fv, tree, numNames, names))==NULL)
		return NULL;
	node->branch1=node2;
	node2->branch0=node;
	node->length1=node2->length0;
	ReadUntil(fv, ',', "Comma");
	if (treeError)
		return NULL;
	
	if ((node2=ReadBranch(fv, tree, numNames, names))==NULL)
		return NULL;
	node->branch2=node2;
	node2->branch0=node;
	node->length2=node2->length0;
	
	ch=fgetc(fv);
	while (!feof(fv) && ch!=':' && ch!=',' && ch!=')' && ch!=';') 
		ch=fgetc(fv);
		
	if (detectPolytomies && ch==',') {
		fprintf(stderr, "This tree contains nodes which aren't bifurcations. Resolve the node\n");
		fprintf(stderr, "with zero branch lengths to obtain correct results. This can be done\n");
		fprintf(stderr, "with a program called TreeEdit: http://evolve.zoo.ox.ac.uk/software/TreeEdit\n");
		exit(4);
	}

	if (feof(fv)) {
		sprintf(treeErrorMsg, "Unexpected end of file");
		return NULL;
	}
	ungetc(ch, fv);
	
	return node;
}
コード例 #7
0
ファイル: ChatCommand.cpp プロジェクト: iamnilay3/openlierox
/////////////////////
// Main command parsing function
std::vector<std::string> ParseCommandMessage(const std::string& msg, bool ignore_blank_params)
{
	std::vector<std::string> result;

	// Checks
	if (msg == "")
		return result;

	if (*msg.begin() != '/')
		return result;

	std::string::const_iterator it = msg.begin();
	it++; // Skip /

	// Parse
	while (it != msg.end())  { // it++ - skip the space
		std::string p;

		if (*it == '\"')  {
			int skip;
			p = ReadQuotedParam(std::string(it, msg.end()), &skip);
			SafeAdvance(it, skip, msg.end());
		} else if (*it == ' ')  {
			it++;
			continue;
		}
		else  {
			p = ReadUntil(std::string(it, msg.end()), ' ');
			SafeAdvance(it, p.size(), msg.end());
		}

		// Add it
		if (result.size() == 0 && ignore_blank_params)
			continue;

		result.push_back(p);
	}

	return result;
}
コード例 #8
0
///////////////////
// Read a string
static bool GetString(const std::string& filename, const std::string& section, const std::string& key, std::string& string, bool abs_fn)
{
	FILE	*config = NULL;
	std::string	Line;
	std::string	tmpLine;
	std::string	curSection;
	std::string	temp;
	std::string	curKey;
	size_t	chardest = 0;
	int		Position;
	bool	found = false;
	
	if(filename == "")
		return false;
	
	if(abs_fn) {
		config = OpenGameFile(filename.c_str(), "rt");
	} else
		config = OpenGameFile(filename,"rt");
	if(!config)
		return false;
	
	//string="";
	curSection="";
	temp="";
	curKey="";
	
	// Check for UTF-8 encoded file and skip the UTF-8 mark if it is
	unsigned char utf8mark[3] = {0,0,0};
	if(fread(utf8mark, sizeof(utf8mark), 1, config) == 0) {
		fclose(config);
		return false;
	}
	if (utf8mark[0] != 0xEF || utf8mark[1] != 0xBB || utf8mark[2] != 0xBF)
		fseek(config, 0, SEEK_SET); // Not a UTF-8 file, jump back to the beginning
	
	
	while(!feof(config) && !ferror(config))
	{
		// Parse the lines
		Line = ReadUntil(config, '\n');
		TrimSpaces(Line);
		
		///////////////////
		// Comment, Ignore
		if(Line.size() == 0 || Line[0] == '#')
			continue;
		
		////////////
		// Sections
		if(Line[0] == '[' && Line[Line.size()-1] == ']')
		{
			curSection = Line.substr(1);
			curSection.erase(curSection.size()-1);
			continue;
		}
		
		////////
		// Keys
		chardest = Line.find('=');
		if(chardest != std::string::npos)
		{
			// Key
			Position = (int)chardest;
			tmpLine = Line;
			tmpLine.erase(Position);
			TrimSpaces(tmpLine);
			curKey = tmpLine;
			
			// Check if this is the key were looking for under the section were looking for
			if(stringcasecmp(curKey,key) == 0 && stringcasecmp(curSection,section) == 0)
			{
				// Get the value
				tmpLine = Line.substr(Position+1);
				TrimSpaces(tmpLine);
				string = tmpLine;
				found = true;
				break;
			}
			continue;
		}
	}
	
	fclose(config);
	
	return found;
}
コード例 #9
0
wxArrayString clEditorConfig::ProcessSection(wxString& strLine)
{
    eEditorConfigState state = kEC_STATE_NORMAL;

    clEditorConfigTreeNode* tree = new clEditorConfigTreeNode;
    std::vector<clEditorConfigTreeNode*> trees;
    trees.push_back(tree);

    wxString curpattern;
    while(!strLine.IsEmpty()) {
        switch(state) {
        case kEC_STATE_NORMAL: {
            wxChar ch = strLine.at(0);
            strLine.Remove(0, 1);
            switch(ch) {
            case '{':
                state = kEC_STATE_IN_CURLYGRP;
                break;
            case '[':
                state = kEC_STATE_IN_SQUAREGRP;
                break;
            case ',':
                // new pattern
                if(!curpattern.IsEmpty()) {
                    tree->Add(curpattern);

                    tree = new clEditorConfigTreeNode;
                    trees.push_back(tree);
                    curpattern.clear();
                }
                break;
            default:
                curpattern << ch;
                break;
            }
            break;
        }
        case kEC_STATE_IN_CURLYGRP: {
            // if we got something so far, add it before we continue
            if(!curpattern.IsEmpty()) {
                tree->Add(curpattern);
                curpattern.clear();
            }

            // read the buffer until we hit the closing brace
            wxString buffer;
            if(!ReadUntil('}', strLine, buffer)) {
                return wxArrayString();
            }
            state = kEC_STATE_NORMAL;
            wxArrayString groupPatterns = ProcessSection(buffer);
            tree->Add(groupPatterns);
            break;
        }
        case kEC_STATE_IN_SQUAREGRP: {
            wxString buffer;
            if(!ReadUntil(']', strLine, buffer)) {
                return wxArrayString();
            }
            state = kEC_STATE_NORMAL;
            break;
        }
        }
    }

    // Remainder
    if(!curpattern.IsEmpty()) {
        tree->Add(curpattern);
    }

    wxArrayString res;
    for(size_t i = 0; i < trees.size(); ++i) {
        wxArrayString patterns;
        trees.at(i)->GetPatterns(patterns);
        res.insert(res.end(), patterns.begin(), patterns.end());
        delete trees.at(i);
    }

    // Loop over the array and change "**" => "*"
    for(size_t i = 0; i < res.size(); ++i) {
        res.Item(i).Replace("**", "*");
    }
    return res;
}
コード例 #10
0
ファイル: utils.cpp プロジェクト: mockthebear/bear-engine
std::string utils::GetLine(std::string &str){
    return ReadUntil(str,'\n');
}