Skip to content

Commit 1285ff7

Browse files
committed
Made separator configurable.
1 parent 082fe73 commit 1285ff7

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/combinesummaries.1

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ output_file
4141
.br
4242
.Op Fl c Ar level | Fl Fl compress Ar level
4343
.br
44+
.Op Fl s Ar separator | Fl Fl separator Ar separator
45+
.br
4446
.Op Fl n | Fl Fl line-numbers
4547
.br
4648
.Op Fl q | Fl Fl quiet
@@ -73,6 +75,8 @@ The name of the output file to be created.
7375
A space-separated list of output variable names to be added to the output data tables.
7476
.It Fl c Ar level | Fl Fl compress Ar level
7577
Sets the BZip2 compression level; 1=none, 9=highest (default).
78+
.It Fl s Ar separator | Fl Fl separator Ar separator
79+
Sets the separator for the tables. Default: tabulator character (i.e. $'\t').
7680
.It Fl n | Fl Fl line-numbers
7781
Generate line numbers for output rows (GNU R: row names). In this case, the input files must contain line numbers (GNU R: row names) as well! The original line numbers are kept in column SubLineNo. Default: off.
7882
.It Fl quiet
@@ -85,10 +89,10 @@ v1.data.bz2 (created with ParameterY=Alpha) and
8589
v2.data.bz2 (created with ParameterY=Beta).
8690
The output data table should be written to output.data.bz2.
8791
.br
88-
( echo "\-\-values=\\"Alpha\\"" && \\
89-
echo "\-\-input=v1.data.bz2" && \\
90-
echo "\-\-values=\\"Beta\\"" && \\
91-
echo "\-\-input=v2.data.bz2" ) | combinesummaries output.data.bz2 "ParameterY"
92+
( echo -e "\-\-values=\\"Alpha\\"\\t\\"Test 1\\"" && \\
93+
echo "\-\-input=v1.data.bz2" && \\
94+
echo -e "\-\-values=\\"Beta\\"\\t\\"Test 2\\"" && \\
95+
echo "\-\-input=v2.data.bz2" ) | combinesummaries output.data.bz2 $'ParameterX\\tParameterY'
9296
.\" ###### Authors ##########################################################
9397
.Sh AUTHORS
9498
Thomas Dreibholz

src/combinesummaries.cc

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ void addDataFile(OutputFile& outputFile,
6666
unsigned long long& outputLineNumber,
6767
const std::string& varNames,
6868
const std::string& varValues,
69-
const std::string& inputFileName)
69+
const std::string& inputFileName,
70+
const char* separator = "\t")
7071
{
7172
// ====== Open input file ================================================
7273
InputFile inputFile;
@@ -93,15 +94,17 @@ void addDataFile(OutputFile& outputFile,
9394
if(withLineNumbers) {
9495
if(inputFile.getLine() == 1) {
9596
if(outputLineNumber == 0) {
96-
if(outputFile.printf("%s SubLineNo %s\n", varNames.c_str(), buffer) == false) {
97+
if(outputFile.printf("%s%sSubLineNo%s%s\n", varNames.c_str(), separator, separator, buffer) == false) {
9798
outputFile.finish();
9899
exit(1);
99100
}
100101
}
101102
}
102103
else {
103-
if(outputFile.printf("%06llu %s %s\n",
104-
outputLineNumber, varValues.c_str(), buffer) == false) {
104+
if(outputFile.printf("%06llu%s%s%s%s\n",
105+
outputLineNumber, separator,
106+
varValues.c_str(), separator,
107+
buffer) == false) {
105108
outputFile.finish();
106109
exit(1);
107110
}
@@ -110,14 +113,14 @@ void addDataFile(OutputFile& outputFile,
110113
else {
111114
if(inputFile.getLine() == 1) {
112115
if(outputLineNumber == 0) {
113-
if(outputFile.printf("%s %s\n", varNames.c_str(), buffer) == false) {
116+
if(outputFile.printf("%s%s%s\n", varNames.c_str(), separator, buffer) == false) {
114117
outputFile.finish();
115118
exit(1);
116119
}
117120
}
118121
}
119122
else {
120-
if(outputFile.printf("%s %s\n", varValues.c_str(), buffer) == false) {
123+
if(outputFile.printf("%s%s%s\n", varValues.c_str(), separator, buffer) == false) {
121124
outputFile.finish();
122125
exit(1);
123126
}
@@ -162,10 +165,12 @@ int main(int argc, char** argv)
162165
bool quietMode = false;
163166
bool withLineNumbers = false;
164167
unsigned int compressionLevel = 9;
168+
const char* separator = "\t";
165169

166170
// ====== Handle command-line arguments ==================================
167171
const static struct option long_options[] = {
168172
{ "compress", required_argument, 0, 'c' },
173+
{ "separator", required_argument, 0, 's' },
169174
{ "line-numbers", no_argument, 0, 'n' },
170175
{ "quiet", no_argument, 0, 'q' },
171176

@@ -176,7 +181,7 @@ int main(int argc, char** argv)
176181

177182
int option;
178183
int longIndex;
179-
while( (option = getopt_long_only(argc, argv, "c:nqhv", long_options, &longIndex)) != -1 ) {
184+
while( (option = getopt_long_only(argc, argv, "c:s:nqhv", long_options, &longIndex)) != -1 ) {
180185
switch(option) {
181186
case 'c':
182187
compressionLevel = atol(optarg);
@@ -187,6 +192,9 @@ int main(int argc, char** argv)
187192
compressionLevel = 9;
188193
}
189194
break;
195+
case 's':
196+
separator = optarg;
197+
break;
190198
case 'n':
191199
withLineNumbers = true;
192200
break;
@@ -278,7 +286,8 @@ int main(int argc, char** argv)
278286
exit(1);
279287
}
280288
addDataFile(outputFile, withLineNumbers, outputLineNumber,
281-
varNames, varValues, std::string((const char*)&command[8]));
289+
varNames, varValues, std::string((const char*)&command[8]),
290+
separator);
282291
varValues = "";
283292
}
284293
else if(!(strncmp(command, "--varnames=", 11))) {

0 commit comments

Comments
 (0)