diff options
| author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-01-29 21:31:41 +0100 | 
|---|---|---|
| committer | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-01-29 21:31:41 +0100 | 
| commit | ea99528bdefdeb6ab0b0b8bc2a87ab52f2b5169c (patch) | |
| tree | f3a1eb47390df7e6449643c5b8f30514fa1810a5 /src/cli | |
| parent | 1a831356eee562451c8ce85654ec3b650658e7f9 (diff) | |
further attempts on making the main program work. Had to add a method for handling absolute paths in FileLocator for that.
Diffstat (limited to 'src/cli')
| -rw-r--r-- | src/cli/Main.cpp | 31 | 
1 files changed, 19 insertions, 12 deletions
| diff --git a/src/cli/Main.cpp b/src/cli/Main.cpp index 92c8caa..2dbeda8 100644 --- a/src/cli/Main.cpp +++ b/src/cli/Main.cpp @@ -136,21 +136,24 @@ int main(int argc, char **argv)  	}  	// To comply with standard UNIX conventions the following should be changed: -	// TODO: Always write to the working directory (not to the input directory!)  	// TODO: Allow "-" for input and output files for reading from stdin and  	//       writing to stdout -	// TODO: Best use boost::filesystem for path operations +	if (inputPath == "-") { +		logger.error("Currently no reading from std::in is supported!"); +		return ERROR_IN_COMMAND_LINE; +	} else{ +		inputPath = fs::canonical(inputPath).string(); +	}  	// prepare output path  	if (!vm.count("output")) { -		outputPath = inputPath; -		auto pos = outputPath.find_last_of('.'); -		if (pos != std::string::npos) { -			outputPath.erase(outputPath.begin() + pos + 1, outputPath.end()); -			outputPath += format; -			std::cout << "Using " << outputPath << " as output path." -			          << std::endl; -		} +		// get the input filename. +		fs::path in{inputPath}; +		// construct a working directory output path. +		fs::path outP = fs::canonical("."); +		outP /= (in.stem().string() + "." + format); +		outputPath = outP.string(); +		std::cout << "Using " << outputPath << " as output path." << std::endl;  	}  	// TODO: REMOVE diagnostic code. @@ -212,8 +215,12 @@ int main(int argc, char **argv)  	// write output.  	html::DemoHTMLTransformer outTransformer; -	std::fstream out{outputPath}; -	outTransformer.writeHTML(doc.cast<Document>(), out); +	if (outputPath == "-") { +		outTransformer.writeHTML(doc.cast<Document>(), std::cout); +	} else { +		std::fstream out {outputPath}; +		outTransformer.writeHTML(doc.cast<Document>(), out); +	}  	return SUCCESS;  } | 
