int main( int argc, char **argv ) 
{
    FILE *fin;

    char str[1024], command, key;
    node *word;
    int i;

    // iterate through multiple input files at the command line
    for(i = 1; i < argc; i++) 
    {
        //open the input file
        fin = fopen( argv[i], "r" );
        if(fin == NULL) 
        {
            fprintf(stderr, "ERROR: Unable to open %s\n", argv[i]);
            exit(1);
        }

        // scan in the String to be manipulated and store as a LinkedList
        fscanf(fin, "%s", str);
        word = stringToList( str );

        // scan in commands until EOF
        while(fscanf(fin, "%c", &command) != EOF) 
        {
            switch( command ) 
            {
                case( '@' ): 
                {
                    fscanf( fin, " %c %s", &key, str );
                    word = replaceChar( word, key, str );
                    break;
                }
                case( '-' ): 
                {
                    fscanf( fin, " %c", &key );
                    word = replaceChar( word, key, NULL );
                    break;
                }
                case( '~' ): 
                {
                    word = reverseList( word );
                    break;
                }
                case( '!' ): 
                {
                    printList( word );
                    break;
                }

            }   // end switch

        }   // end while

    }   // end for

    return 0;
}
Ejemplo n.º 2
0
void Predictor::setupFile ( )
{
	char _outFile[100];
	char _dateStr[9];
	char _timeStr[9];

	_strdate( _dateStr);
    _strtime( _timeStr );

	//replaces invalid character for file names
	replaceChar( _dateStr, '/', '-' );
	replaceChar( _timeStr, ':', ' ' );

	//creates the filename for decoded data
	strcpy(_outFile, "Predicted PreLaunch Data for Launch Date ");
	strcat(_outFile, _dateStr);
	strcat(_outFile, " Time ");
	strcat(_outFile, _timeStr);
	strcat(_outFile, ".txt");
	_fpOutPredicted.open ( _outFile, ios::app );

	_fpOutPredicted <<"Callsign: "
					<< _balloon->getCallSign() <<'\n'
					<<"Area of Parachute: "
					<< _balloon->getArea() <<'\n'
					<<"CD of Balloon: "
					<< _balloon->getDragBalloon() <<'\n'
					<<"CD of Parachute: "
					<< _balloon->getDragPara() <<'\n'
					<<"Mass of Balloon: "
					<< _balloon->getMassBalloon() <<'\n'
					<<"Mass of Payload: "
					<< _balloon->getMassPayload() <<'\n'
					<<"Mass of Helium: "
					<< _balloon->getMassHelium() <<'\n'
					<<"Lift in lbs: "
					<< _balloon->getLift() <<'\n'
					<<"Burst Diameter: "
					<< _balloon->getBurst() <<'\n'
					<<"---------------------" <<'\n';

	_fpOutPredicted <<"Air Density Intercept (b): "
					<< _bAir <<'\n'
					<<"Air Density Slope (m): "
					<< _mAir <<'\n'
					<<"Air Density at Launch: "
					<< air( _balloon->getLatestPoint().getAlt() ) <<'\n'
					<<"---------------------" <<'\n';
	_fpOutPredicted <<"Volume Intercept (b): "
					<< _bVol <<'\n'
					<<"Volume Slope (m): "
					<< _mVol <<'\n'
					<<"Volume at Launch: "
					<< volume ( _balloon->getLatestPoint().getAlt() ) <<'\n'
					<<"---------------------" <<'\n';
	_fpOutPredicted <<"\n*********************"
					<<"\nPrelaunch Prediction"
					<<"\n*********************" <<"\n\n";
}
Ejemplo n.º 3
0
void fixLabel(Node* n){
	if(!checkNode(n))return;
	if(n->name==0)return;// HOW? checkNames=false :(
	if(n->name[0]=='"')n->name=n->name+1;

	if(n->name[strlen(n->name)-1]=='"'&&n->name[strlen(n->name)-2]!='"')
		n->name[strlen(n->name)-1]=0;
	if(n->name[strlen(n->name)-1]=='\\')
		n->name[strlen(n->name)-1]=0;
	replaceChar(n->name,'"',' ');
	replaceChar(n->name,'\'',' ');
	replaceChar(n->name,'\\',' ');
	// todo: "'","%27" etc
	//#include <curl/curl.h>
	//char *curl_easy_escape( CURL * curl , char * url , int length );
}
Ejemplo n.º 4
0
string CCUtils::appendPathComponent(const string& path, const string& component) {
	// change slash to windows format
	if(CC_PATH_SEPARATOR != '/')
		replaceChar((string&)path, '/', CC_PATH_SEPARATOR);
    
	// validating
	if(path.empty()) {
		if(component.empty())
			return "";
		else
			return component;
	} else if(component.empty()) {
		return path;
    }
    
	// allocate a big enough buffer
	// plus 2 because one for slash, one for null terminator
	size_t len = path.length();
	int cLen = component.length();
    char* buf = new char[len + cLen + 2];
    memset(buf, 0, len + cLen + 2);
    
	// copy path
	memcpy(buf, path.c_str(), len);
    
	// take care of slash
	int start = len;
	if(start > 0) {
		if(buf[start - 1] != CC_PATH_SEPARATOR) {
			buf[start++] = CC_PATH_SEPARATOR;
		} else {
			while(start >= 2 && buf[start - 2] == CC_PATH_SEPARATOR)
				start--;
		}
	}
    
	// copy component
	int cStart = 0;
	while(cStart < cLen && component[cStart] == CC_PATH_SEPARATOR)
		cStart++;
	if(cStart > 0 && start == 0)
		cStart--;
	memcpy(buf + start, component.c_str() + cStart, cLen - cStart);
    
    // remove end slash
    int end = start + cLen - cStart - 1;
    while(buf[end] == CC_PATH_SEPARATOR)
        buf[end--] = 0;
    
    string ret = buf;
    delete buf;
	return ret;
}
Ejemplo n.º 5
0
ParserABC::ParserABC( ) : _wrong(0)
{
	char _outFile[100];
	char _dateStr[9];
	char _timeStr[9];

	_strdate( _dateStr);
    _strtime( _timeStr );

	//replaces invalid character for file names
	replaceChar( _dateStr, '/', '-' );
	replaceChar( _timeStr, ':', ' ' );

	//creates the filename for decoded data
	strcpy(_outFile, "Decoded Data for Launch Date ");
	strcat(_outFile, _dateStr);
	strcat(_outFile, " Time ");
	strcat(_outFile, _timeStr);
	strcat(_outFile, ".txt");
	_fpOutDec.open ( _outFile, ios::app );
}
Ejemplo n.º 6
0
int RappScanner::RunSequence()
{
   if (sequence_.size() > 0)
   {
      std::string sequence2 = replaceChar(sequence_, ':', ',');
      tStringList sequenceList = split(sequence2, ' ');
   
      return SafeStoreSequence(sequenceList);
   }
   
   return UGA_->RunSequence(false) ? DEVICE_OK : DEVICE_ERR; 
}
Ejemplo n.º 7
0
	std::string abbreviateFile(const std::string& filePath)
	{
		std::string f = filePath;
#if LL_WINDOWS
		replaceChar(f, '\\', '/');
#endif
		static std::string indra_prefix = "indra/";
		f = removePrefix(f, indra_prefix);

#if LL_DARWIN
		static std::string newview_prefix = "newview/../";
		f = removePrefix(f, newview_prefix);
#endif

		return f;
	}
Ejemplo n.º 8
0
ssize_t CCUtils::lastSlashIndex(string path) {
	if(path.empty())
		return -1;
    
	// change slash to windows format
    if(CC_PATH_SEPARATOR != '/')
        replaceChar(path, '/', CC_PATH_SEPARATOR);
    
	// find slash index
	size_t len = path.length();
	int end = len;
	int slash = -1;
	for(int i = len - 1; i >= 0; i--) {
		if(path[i] == CC_PATH_SEPARATOR) {
			if(i == end - 1) {
				end--;
				if(i == 0) {
					slash = 0;
					break;
				}
			} else {
				slash = i;
				break;
			}
		}
	}
    
	// skip extra slash
	if(slash != -1) {
		while(slash >= 1 && path[slash - 1] == CC_PATH_SEPARATOR)
			slash--;
	}
    
	// assign to end
	end = slash;
	if(end == 0)
		end = 1;
    
	return end;
}
Ejemplo n.º 9
0
string CCUtils::lastPathComponent(const string& path) {
	// change slash to windows format
	if(CC_PATH_SEPARATOR != '/')
		replaceChar((string&)path, '/', CC_PATH_SEPARATOR);
    
	size_t len = path.length();
	int start = 0;
	int end = len;
	for(int i = len - 1; i >= 0; i--) {
		if(path[i] == CC_PATH_SEPARATOR) {
			if(i == end - 1)
				end--;
			else {
				start = i + 1;
				break;
			}
		}
	}
    
	if(end < start)
		return path;
	else
		return path.substr(start, end);
}
Ejemplo n.º 10
0
void Predictor::writeFileDesc ( )
{
	char _outFile[100];
	char _dateStr[9];
	char _timeStr[9];

	_strdate( _dateStr);
    _strtime( _timeStr );

	//replaces invalid character for file names
	replaceChar( _dateStr, '/', '-' );
	replaceChar( _timeStr, ':', ' ' );

	//creates the filename for decoded data
	strcpy(_outFile, "Predicted Descent Data for Launch Date ");
	strcat(_outFile, _dateStr);
	strcat(_outFile, " Time ");
	strcat(_outFile, _timeStr);
	strcat(_outFile, ".txt");
	_fpOutPredicted.open ( _outFile, ios::app );

	_fpOutPredicted <<"Callsign: "
					<< _balloon->getCallSign() <<'\n'
					<<"Area of Parachute: "
					<< _balloon->getArea() <<'\n'
					<<"CD of Balloon: "
					<< _balloon->getDragBalloon() <<'\n'
					<<"CD of Parachute: "
					<< _balloon->getDragPara() <<'\n'
					<<"Mass of Balloon: "
					<< _balloon->getMassBalloon() <<'\n'
					<<"Mass of Payload: "
					<< _balloon->getMassPayload() <<'\n'
					<<"Mass of Helium: "
					<< _balloon->getMassHelium() <<'\n'
					<<"Lift in lbs: "
					<< _balloon->getLift() <<'\n'
					<<"Burst Diameter: "
					<< _balloon->getBurst() <<'\n'
					<<"---------------------" <<'\n';

	_fpOutPredicted <<"Air Density Intercept (b): "
					<< _bAir <<'\n'
					<<"Air Density Slope (m): "
					<< _mAir <<'\n'
					<<"Air Density at Launch: "
					<< air( _balloon->getLatestPoint().getAlt() ) <<'\n'
					<<"---------------------" <<'\n';
	_fpOutPredicted <<"Volume Intercept (b): "
					<< _bVol <<'\n'
					<<"Volume Slope (m): "
					<< _mVol <<'\n'
					<<"Volume at Launch: "
					<< volume ( _balloon->getLatestPoint().getAlt() ) <<'\n'
					<<"---------------------" <<'\n';
	_fpOutPredicted <<"\n*********************"
					<<"\nBurst Prediction"
					<<"\n*********************" <<"\n\n";

	double altHold(0), timeHold(0);
	list<PredictedNode>::iterator move = _balloon->getPrePointDescent().begin();

	if ( _balloon->getPrePointDescent().size() > 1 )
	{
		while ( move != _balloon->getPrePointDescent().end() )
		{
			_fpOutPredicted <<"Predicted Altitude: "
							<<(*move).getAltPre() <<'\n'
							<<"Predicted Latitude: "
							<<(*move).getLatPre() <<'\n'
							<<"Predicted Longitude: "
							<<(*move).getLonPre() <<'\n'
							<<"Predicted Time: "
							<<(*move).getTimePre() <<'\n';
			altHold = (*move).getAltPre();
			timeHold = (*move).getTimePre();
			++move;
			if ( move != _balloon->getPrePointDescent().end() )
			{
				_fpOutPredicted <<"Ascent Rate: "
					<<getAscentRate() <<'\n';
			}
			_fpOutPredicted <<"---------------------" <<'\n';
		}
	}
}
const char* WebModelUnified::website_search(const char* req){
    JSONObject root;
    JSONArray jsarray;
    Connection* conn = connect();
    Query query = conn->query();

    string reqstr(req);
    string reqstr_spaced = replaceChar(reqstr, '+', ' ');
    vector<string> splittedstr;
    split(splittedstr, reqstr_spaced, boost::algorithm::is_any_of(" "));

    int titleForce = 10;
    int descriptionForce = 1;
    int urlForce = 3;

    query << "SELECT * , ";
    //Occurences total
    for(size_t i1 = 0; i1 < splittedstr.size(); i1++)
    {
        string s = splittedstr[i1];
        if(i1 != 0){
            query << " + ";
        }

        query << "((" <<
          titleForce << " * (char_length(title) - char_length(replace(title,'" << s << "',''))) + " <<
          descriptionForce << " * (char_length(description) - char_length(replace(description,'" << s << "',''))) + " <<
          urlForce << " * (char_length(url) - char_length(replace(url,'" << s << "','')))" <<
        ") / char_length('" << s << "'))";
    }
    query << " as Occurances " << " FROM website ";

    //Where clause
    for(size_t i1 = 0; i1 < splittedstr.size(); i1++)
    {
        string s = splittedstr[i1];
        if(i1 == 0) {
            query << "WHERE ";
        } else {
            query << "OR ";
        }
        query << "(url LIKE '%" << s << "%' or title LIKE '%" << s << "%' or description LIKE '%" << s << "%') ";
    }

    query << " ORDER BY " << "Occurances desc, title ASC ";

    StoreQueryResult ares = query.store();
    unsigned int numrow = ares.num_rows();

    for(unsigned int i = 0; i < numrow; i++)
    {
        JSONObject result;

        result[L"title"] = new JSONValue(wchartFromChar(ares[i]["title"]));
        result[L"description"] = new JSONValue(wchartFromChar(ares[i]["description"]));
        result[L"url"] = new JSONValue(wchartFromChar(ares[i]["url"]));
        JSONValue* resultVal = new JSONValue(result);

        jsarray.push_back(resultVal);
    }

    root[L"results"] = new JSONValue(jsarray);

    JSONValue* jvalue = new JSONValue(root);

    const char* returnStr = fromWString(jvalue->Stringify());
    delete jvalue;
    return returnStr;
}
Ejemplo n.º 12
0
int main(void) {
	int exitVal = EXIT_SUCCESS;

	// Filenames
	const char readfile[] = "source.txt";
	const char write1[] = "destination1.txt";
	const char write2[] = "destination2.txt";
	
	const size_t firstReadSize = 100;
	const size_t secondReadSize = 50;
	// Will hold file data
	char buffer[BUFFSIZE];
	// 0 init array
	int i;
	for(i = 0; i < BUFFSIZE; ++i) buffer[i] = 0;
	
	// Open files while checking for errors
	int src = open(readfile, O_RDONLY);
	if(src == -1) {
		perror("Error opening source file");
		return EXIT_FAILURE;
	}
	int d1 = open(write1, O_WRONLY);
	if(d1 == -1) {
		perror("Error opening destionation1 file");
		// Manually close previously opened files
		if(close(src) == -1) perror(NULL);
		return EXIT_FAILURE;
	}
	int d2 = open(write2, O_WRONLY);
	if(d2 == -1) {
		perror("Error opening destination2 file");
		// Manually close previously opened files
		if(close(src) == -1) perror(NULL);
		if(close(d1) == -1) perror(NULL);
		return EXIT_FAILURE;
	}
	
	// Read and write files accordingly
	ssize_t readSize;
	do {
		// Read next <=100 bytes from source
		readSize = read(src, buffer, firstReadSize);
		if(readSize == -1) goto exit_error;
		// Replace 1's with A's in buffer
		replaceChar('1', 'A', buffer, readSize);
		// Terminate program if issue writing
		if(write(d1, buffer, readSize) == -1) goto exit_error;

		// Read next <=50 bytes from source
		readSize = read(src, buffer, secondReadSize);
		if(readSize == -1) goto exit_error;
		// Replace 2's with B's in buffer
		replaceChar('2', 'B', buffer, readSize);
		if(write(d2, buffer, readSize) == -1) goto exit_error;
	} while(readSize > 0);
	
	// Program was successful
	goto exit_close;
exit_error:
	// print last error and modify return value
	perror(NULL);
	exitVal = EXIT_FAILURE;
exit_close:
	// attempt to close all files
	if(close(src) == -1) perror("Unable to close source file");
	if(close(d1) == -1) perror("Unable to close destination1 file");
	if(close(d2) == -1) perror("Unable to close destination2 file");

	return exitVal;
}
Ejemplo n.º 13
0
TEST_F(ReplaceStringTest, PositiveExample) {

	for(auto& example : testStrings) {
		ASSERT_EQ(replaceChar(example.first, toReplace, rep), example.second);
	}
}