Skip to content

Commit c9cd391

Browse files
committed
got rid of endl
1 parent ad2fc8d commit c9cd391

6 files changed

Lines changed: 89 additions & 84 deletions

File tree

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
* faster char to int conversion in klets.cpp
44
* countlets is much faster when providing alphabet (using unordered_map)
55
* countlets version bumped to 1.3
6+
* replaced all instances of endl with \n
7+
* countfa version bumped to 1.2
8+
* countwin version bumped to 1.1
9+
* seqgen version bumped to 1.3
10+
* shuffler version bumped to 1.3
611

712
2019-05-04 Benjamin Jean-Marie Tremblay <benjmtremblay@gmail.com>
813

src/countfa.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ using namespace std;
2626

2727
void usage() {
2828
printf(
29-
"countfa v1.1 Copyright (C) 2019 Benjamin Jean-Marie Tremblay \n"
29+
"countfa v1.2 Copyright (C) 2019 Benjamin Jean-Marie Tremblay \n"
3030
" \n"
3131
"Usage: coutfa -i [filename] \n"
3232
" cat [filename] | coutfa \n"
@@ -46,22 +46,22 @@ void do_countfa(istream &input) {
4646
while (input.get(l)) {
4747

4848
if (l == '>') {
49-
if (counter > 0) cout << counter << endl;
49+
if (counter > 0) cout << counter << '\n';
5050
at_name = true;
5151
counter = 0;
5252
}
5353

5454
if (l == '\n' && at_name) {
5555
at_name = false;
56-
cout << endl;
56+
cout << '\n';
5757
}
5858

5959
if (at_name) cout << l;
6060
else if (l != ' ' && l != '\n') ++counter;
6161

6262
}
6363

64-
if (!at_name && counter > 0) cout << counter << endl;
64+
if (!at_name && counter > 0) cout << counter << '\n';
6565

6666
return;
6767

@@ -78,8 +78,8 @@ int main(int argc, char **argv) {
7878
case 'i': if (optarg) {
7979
seqfile.open(optarg);
8080
if (seqfile.bad()) {
81-
cerr << "Error: file not found" << endl;
82-
cerr << "Run countfa -h to see usage." << endl;
81+
cerr << "Error: file not found\n";
82+
cerr << "Run countfa -h to see usage.\n";
8383
exit(EXIT_FAILURE);
8484
}
8585
has_file = true;
@@ -92,8 +92,8 @@ int main(int argc, char **argv) {
9292

9393
if (!has_file) {
9494
if (isatty(STDIN_FILENO)) {
95-
cerr << "Error: missing input" << endl;
96-
cerr << "Run countfa -h to see usage." << endl;
95+
cerr << "Error: missing input\n";
96+
cerr << "Run countfa -h to see usage.\n";
9797
exit(EXIT_FAILURE);
9898
}
9999
do_countfa(cin);

src/countlets.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ int main(int argc, char **argv) {
101101
case 'i': if (optarg) {
102102
seqfile.open(optarg);
103103
if (seqfile.bad()) {
104-
cerr << "Error: file not found" << endl;
105-
cerr << "Run countlets -h to see usage." << endl;
104+
cerr << "Error: file not found\n";
105+
cerr << "Run countlets -h to see usage.\n";
106106
exit(EXIT_FAILURE);
107107
}
108108
has_file = true;
@@ -119,8 +119,8 @@ int main(int argc, char **argv) {
119119
case 'o': if (optarg) {
120120
outfile.open(optarg);
121121
if (outfile.bad()) {
122-
cerr << "Error: could not create outfile" << endl;
123-
cerr << "Run countlets -h to see usage." << endl;
122+
cerr << "Error: could not create outfile\n";
123+
cerr << "Run countlets -h to see usage.\n";
124124
exit(EXIT_FAILURE);
125125
}
126126
has_out = true;
@@ -137,15 +137,15 @@ int main(int argc, char **argv) {
137137
}
138138

139139
if (k < 1) {
140-
cerr << "Error: k must be greater than 0" << endl;
141-
cerr << "Run countlets -h to see usage." << endl;
140+
cerr << "Error: k must be greater than 0\n";
141+
cerr << "Run countlets -h to see usage.\n";
142142
exit(EXIT_FAILURE);
143143
}
144144

145145
if (!has_file) {
146146
if (isatty(STDIN_FILENO)) {
147-
cerr << "Error: missing input" << endl;
148-
cerr << "Run countlets -h to see usage." << endl;
147+
cerr << "Error: missing input\n";
148+
cerr << "Run countlets -h to see usage.\n";
149149
exit(EXIT_FAILURE);
150150
}
151151
}
@@ -186,12 +186,12 @@ int main(int argc, char **argv) {
186186
if (has_out) {
187187
for (size_t i = 0; i < klets.size(); ++i) {
188188
if (counts[i] > 0 || !nozero)
189-
outfile << klets[i] << " " << "\t" << counts[i] << endl;
189+
outfile << klets[i] << '\t' << counts[i] << '\n';
190190
}
191191
} else {
192192
for (size_t i = 0; i < klets.size(); ++i) {
193193
if (counts[i] > 0 || !nozero)
194-
cout << klets[i] << " " << "\t" << counts[i] << endl;
194+
cout << klets[i] << '\t' << counts[i] << '\n';
195195
}
196196
}
197197

@@ -202,8 +202,8 @@ int main(int argc, char **argv) {
202202
unordered_map<string, unsigned int> counts;
203203

204204
if (alph.length() < 1) {
205-
cerr << "Error: could not parse -a option" << endl;
206-
cerr << "Run countlets -h to see usage." << endl;
205+
cerr << "Error: could not parse -a option" << '\n';
206+
cerr << "Run countlets -h to see usage." << '\n';
207207
exit(EXIT_FAILURE);
208208
}
209209

@@ -225,18 +225,18 @@ int main(int argc, char **argv) {
225225
/* return */
226226

227227
if (counts.size() > klets.size()) {
228-
cerr << "Warning: foreign character(s) encountered" << endl;
228+
cerr << "Warning: foreign character(s) encountered" << '\n';
229229
}
230230

231231
if (has_out) {
232232
for (size_t i = 0; i < klets.size(); ++i) {
233233
if (counts[klets[i]] > 0 || !nozero)
234-
outfile << klets[i] << "\t" << counts[klets[i]] << "\t" << endl;
234+
outfile << klets[i] << '\t' << counts[klets[i]] << '\t' << '\n';
235235
}
236236
} else {
237237
for (size_t i = 0; i < klets.size(); ++i) {
238238
if (counts[klets[i]] > 0 || !nozero)
239-
cout << klets[i] << "\t" << counts[klets[i]] << "\t" << endl;
239+
cout << klets[i] << '\t' << counts[klets[i]] << '\t' << '\n';
240240
}
241241
}
242242

src/countwin.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using namespace std;
2929

3030
void usage() {
3131
printf(
32-
"countwin v1.0 Copyright (C) 2019 Benjamin Jean-Marie Tremblay \n"
32+
"countwin v1.1 Copyright (C) 2019 Benjamin Jean-Marie Tremblay \n"
3333
" \n"
3434
"Usage: countwin [options] -a [alphabet] -i [filename] -o [filename] \n"
3535
" echo [string] | countwin [options] -a [alphabet] > [filename] \n"
@@ -56,7 +56,7 @@ string make_row(string START, string STOP, vector<unsigned int> counts,
5656

5757
for (size_t i = 0; i < counts.size(); ++i) {
5858
if (counts[i] > 0 || !nozero)
59-
out += START + "\t" + STOP + "\t" + klets[i] + "\t" + to_string(counts[i]) + "\n";
59+
out += START + '\t' + STOP + '\t' + klets[i] + '\t' + to_string(counts[i]) + '\n';
6060
}
6161

6262
return out;
@@ -103,8 +103,8 @@ int main(int argc, char **argv) {
103103
case 'i': if (optarg) {
104104
infile.open(optarg);
105105
if (infile.bad()) {
106-
cerr << "Error: file not found" << endl;
107-
cerr << "Run countwin -h to see usage." << endl;
106+
cerr << "Error: file not found\n";
107+
cerr << "Run countwin -h to see usage.\n";
108108
exit(EXIT_FAILURE);
109109
}
110110
has_file = true;
@@ -114,8 +114,8 @@ int main(int argc, char **argv) {
114114
case 'o': if (optarg) {
115115
outfile.open(optarg);
116116
if (outfile.bad()) {
117-
cerr << "Error: could not create outfile" << endl;
118-
cerr << "Run countwin -h to see usage." << endl;
117+
cerr << "Error: could not create outfile\n";
118+
cerr << "Run countwin -h to see usage.\n";
119119
exit(EXIT_FAILURE);
120120
}
121121
has_out = true;
@@ -150,41 +150,41 @@ int main(int argc, char **argv) {
150150
}
151151

152152
if (ku < 1) {
153-
cerr << "Error: k must be greater than 0" << endl;
154-
cerr << "Run countwin -h to see usage." << endl;
153+
cerr << "Error: k must be greater than 0\n";
154+
cerr << "Run countwin -h to see usage.\n";
155155
exit(EXIT_FAILURE);
156156
}
157157

158158
k = ku;
159159

160160
if (!has_file) {
161161
if (isatty(STDIN_FILENO)) {
162-
cerr << "Error: missing input" << endl;
163-
cerr << "Run countwin -h to see usage." << endl;
162+
cerr << "Error: missing input\n";
163+
cerr << "Run countwin -h to see usage.\n";
164164
exit(EXIT_FAILURE);
165165
}
166166
}
167167

168168
if (alph.length() < 1) {
169-
cerr << "Error: missing alphabet" << endl;
169+
cerr << "Error: missing alphabet\n";
170170
exit(EXIT_FAILURE);
171171
}
172172

173173
if (!has_win) {
174174
window = k;
175175
} else {
176176
if (window < k) {
177-
cerr << "Error: window size must be equal to or greater than k" << endl;
178-
cerr << "Run countwin -h to see usage." << endl;
177+
cerr << "Error: window size must be equal to or greater than k\n";
178+
cerr << "Run countwin -h to see usage.\n";
179179
exit(EXIT_FAILURE);
180180
}
181181
}
182182

183183
if (!has_step) step = window;
184184

185185
if (step < 1 || step > window) {
186-
cerr << "Error: step size must be between 1 and window size" << endl;
187-
cerr << "Run countwin -h to see usage." << endl;
186+
cerr << "Error: step size must be between 1 and window size\n";
187+
cerr << "Run countwin -h to see usage.\n";
188188
exit(EXIT_FAILURE);
189189
}
190190

@@ -196,9 +196,9 @@ int main(int argc, char **argv) {
196196
klets = make_klets(lets_uniq, k);
197197

198198
if (has_file) {
199-
outfile << "START\tSTOP\tLET\tCOUNT" << endl;
199+
outfile << "START\tSTOP\tLET\tCOUNT\n";
200200
} else {
201-
cout << "START\tSTOP\tLET\tCOUNT" << endl;
201+
cout << "START\tSTOP\tLET\tCOUNT\n";
202202
}
203203

204204
/* initialise */
@@ -210,8 +210,8 @@ int main(int argc, char **argv) {
210210
}
211211
STOP = START + seq.length() - 1;
212212
if (seq.length() < k) {
213-
cerr << "Error: sequence cannot be smaller than k" << endl;
214-
cerr << "Run countwin -h to see usage." << endl;
213+
cerr << "Error: sequence cannot be smaller than k\n";
214+
cerr << "Run countwin -h to see usage.\n";
215215
exit(EXIT_FAILURE);
216216
}
217217
counts = count_klets(vector<char>(seq.begin(), seq.end()), lets_uniq, k, alphlen);

src/seqgen.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ using namespace std;
2828

2929
void usage() {
3030
printf(
31-
"seqgen v1.2 Copyright (C) 2019 Benjamin Jean-Marie Tremblay \n"
31+
"seqgen v1.3 Copyright (C) 2019 Benjamin Jean-Marie Tremblay \n"
3232
" \n"
3333
"Usage: seqgen [options] -a [letters] -l [length] -o [outfile] \n"
3434
" seqgen [options] -a [letters] -l [length] > [outfile] \n"
@@ -61,8 +61,8 @@ int main(int argc, char **argv) {
6161
size_t last, next;
6262

6363
if (argc == 1) {
64-
cerr << "Error: missing alphabet and sequence length" << endl;
65-
cerr << "Run seqgen -h to see usage." << endl;
64+
cerr << "Error: missing alphabet and sequence length\n";
65+
cerr << "Run seqgen -h to see usage.\n";
6666
return 0;
6767
}
6868

@@ -71,8 +71,8 @@ int main(int argc, char **argv) {
7171
case 'o': if (optarg) {
7272
outfile.open(optarg);
7373
if (outfile.bad()) {
74-
cerr << "Error: could not create outfile" << endl;
75-
cerr << "Run seqgen -h to see usage." << endl;
74+
cerr << "Error: could not create outfile\n";
75+
cerr << "Run seqgen -h to see usage.\n";
7676
exit(EXIT_FAILURE);
7777
}
7878
has_out = true;
@@ -95,8 +95,8 @@ int main(int argc, char **argv) {
9595
}
9696

9797
if (seqlen < 1) {
98-
cerr << "Error: please input a desired sequence length above 0" << endl;;
99-
cerr << "Run seqgen -h to see usage." << endl;
98+
cerr << "Error: please input a desired sequence length above 0\n";
99+
cerr << "Run seqgen -h to see usage.\n";
100100
exit(EXIT_FAILURE);
101101
}
102102

@@ -120,8 +120,8 @@ int main(int argc, char **argv) {
120120
alphlen = lets.size();
121121

122122
if (alphlen < 1) {
123-
cerr << "Error: could not parse sequence alphabet" << endl;
124-
cerr << "Run seqgen -h to see usage." << endl;
123+
cerr << "Error: could not parse sequence alphabet\n";
124+
cerr << "Run seqgen -h to see usage.\n";
125125
exit(EXIT_FAILURE);
126126
}
127127

@@ -140,7 +140,7 @@ int main(int argc, char **argv) {
140140

141141
if (lets.size() != freqs.size()) {
142142
cerr << "Error: mismatching number of letters [" << lets.size()
143-
<< "] and frequencies [" << freqs.size() << "]" << endl;
143+
<< "] and frequencies [" << freqs.size() << "]\n";
144144
exit(EXIT_FAILURE);
145145
}
146146

@@ -156,13 +156,13 @@ int main(int argc, char **argv) {
156156
for (unsigned int i = 0; i < seqlen; ++i) {
157157
outfile << lets[gen() % alphlen];
158158
}
159-
outfile << endl;
159+
outfile << '\n';
160160
outfile.close();
161161
} else {
162162
for (unsigned int i = 0; i < seqlen; ++i) {
163163
cout << lets[gen() % alphlen];
164164
}
165-
cout << endl;
165+
cout << '\n';
166166
}
167167

168168
} else {
@@ -173,13 +173,13 @@ int main(int argc, char **argv) {
173173
for (unsigned int i = 0; i < seqlen; ++i) {
174174
outfile << lets[next_let(gen)];
175175
}
176-
outfile << endl;
176+
outfile << '\n';
177177
outfile.close();
178178
} else {
179179
for (unsigned int i = 0; i < seqlen; ++i) {
180180
cout << lets[next_let(gen)];
181181
}
182-
cout << endl;
182+
cout << '\n';
183183
}
184184

185185
}

0 commit comments

Comments
 (0)