42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
#include <iostream>
|
|
#include <fstream>
|
|
|
|
int main( int argc, char **argv ){
|
|
if( argc <= 1 ){
|
|
std::cerr << "Usage: "<<argv[0]<<" [infile]" << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
std::ifstream input(argv[1]);
|
|
if(!input.good()){
|
|
std::cerr << "Error opening '"<<argv[1]<<"'. Bailing out." << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
std::string line, name, content;
|
|
while( std::getline( input, line ).good() ){
|
|
if( line.empty() || line[0] == '>' ){ // Identifier marker
|
|
if( !name.empty() ){ // Print out what we read from the last entry
|
|
std::cout << name << " : " << content << std::endl;
|
|
name.clear();
|
|
}
|
|
if( !line.empty() ){
|
|
name = line.substr(1);
|
|
}
|
|
content.clear();
|
|
} else if( !name.empty() ){
|
|
if( line.find(' ') != std::string::npos ){ // Invalid sequence--no spaces allowed
|
|
name.clear();
|
|
content.clear();
|
|
} else {
|
|
content += line;
|
|
}
|
|
}
|
|
}
|
|
if( !name.empty() ){ // Print out what we read from the last entry
|
|
std::cout << name << " : " << content << std::endl;
|
|
}
|
|
|
|
return 0;
|
|
}
|