Sat Jan 2 12:10:17 2021 UTC ()
trailing whitespace


(jmcneill)
diff -r1.1 -r1.2 src/games/testpat/testpat.c

cvs diff -r1.1 -r1.2 src/games/testpat/testpat.c (expand / switch to unified diff)

--- src/games/testpat/testpat.c 2021/01/02 03:21:39 1.1
+++ src/games/testpat/testpat.c 2021/01/02 12:10:17 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: testpat.c,v 1.1 2021/01/02 03:21:39 nat Exp $ */ 1/* $NetBSD: testpat.c,v 1.2 2021/01/02 12:10:17 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2016 Nathanial Sloss <nathanialsloss@yahoo.com.au> 4 * Copyright (c) 2016 Nathanial Sloss <nathanialsloss@yahoo.com.au>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -56,48 +56,48 @@ int main(int argc, char *argv[]) { @@ -56,48 +56,48 @@ int main(int argc, char *argv[]) {
56 }; 56 };
57 57
58 float coord_x, circle_int; 58 float coord_x, circle_int;
59 float a_axis, b_axis; 59 float a_axis, b_axis;
60 60
61 if (!(initscr())) { 61 if (!(initscr())) {
62 printf("\nUnknown terminal type."); 62 printf("\nUnknown terminal type.");
63 printf("\n"); 63 printf("\n");
64 return EXIT_FAILURE; 64 return EXIT_FAILURE;
65 } 65 }
66 66
67 if (argc > 2) { 67 if (argc > 2) {
68 endwin(); 68 endwin();
69 errx(EINVAL, "usage: testpat [title]");  69 errx(EINVAL, "usage: testpat [title]");
70 } 70 }
71  71
72 if (argc == 2 && strlen(argv[1]) < (size_t)COLS) 72 if (argc == 2 && strlen(argv[1]) < (size_t)COLS)
73 snprintf(title, sizeof(title), "%s", argv[1]); 73 snprintf(title, sizeof(title), "%s", argv[1]);
74 else if (argc == 2 && (int)strlen(argv[1]) > COLS) { 74 else if (argc == 2 && (int)strlen(argv[1]) > COLS) {
75 endwin(); 75 endwin();
76 errx(EINVAL, "title string must be less than display columns"); 76 errx(EINVAL, "title string must be less than display columns");
77 } 77 }
78 78
79 colourOK = has_colors(); 79 colourOK = has_colors();
80 80
81 if (COLS < 13 || LINES < 13) { 81 if (COLS < 13 || LINES < 13) {
82 endwin(); 82 endwin();
83 printf("\nTerminal size must be at least 72x25."); 83 printf("\nTerminal size must be at least 72x25.");
84 printf("\n"); 84 printf("\n");
85 return EXIT_FAILURE; 85 return EXIT_FAILURE;
86 } 86 }
87 87
88 if (colourOK) { 88 if (colourOK) {
89 start_color(); 89 start_color();
90  90
91 init_pair( 0, COLOR_WHITE, COLOR_BLACK ); 91 init_pair( 0, COLOR_WHITE, COLOR_BLACK );
92 init_pair( 1, COLOR_WHITE, COLOR_RED ); 92 init_pair( 1, COLOR_WHITE, COLOR_RED );
93 init_pair( 2, COLOR_WHITE, COLOR_GREEN ); 93 init_pair( 2, COLOR_WHITE, COLOR_GREEN );
94 init_pair( 3, COLOR_WHITE, COLOR_YELLOW ); 94 init_pair( 3, COLOR_WHITE, COLOR_YELLOW );
95 init_pair( 4, COLOR_WHITE, COLOR_BLUE ); 95 init_pair( 4, COLOR_WHITE, COLOR_BLUE );
96 init_pair( 5, COLOR_WHITE, COLOR_MAGENTA ); 96 init_pair( 5, COLOR_WHITE, COLOR_MAGENTA );
97 init_pair( 6, COLOR_WHITE, COLOR_CYAN ); 97 init_pair( 6, COLOR_WHITE, COLOR_CYAN );
98 init_pair( 7, COLOR_BLACK, COLOR_WHITE ); 98 init_pair( 7, COLOR_BLACK, COLOR_WHITE );
99 99
100 attrset(COLOR_PAIR(0)); 100 attrset(COLOR_PAIR(0));
101 } 101 }
102 102
103 x_limit = (COLS - 1) / 2; 103 x_limit = (COLS - 1) / 2;
@@ -182,56 +182,56 @@ int main(int argc, char *argv[]) { @@ -182,56 +182,56 @@ int main(int argc, char *argv[]) {
182 } 182 }
183 183
184 mvaddch(0, 0, 108 | A_ALTCHARSET); 184 mvaddch(0, 0, 108 | A_ALTCHARSET);
185 mvaddch(0, x_limit, 107 | A_ALTCHARSET); 185 mvaddch(0, x_limit, 107 | A_ALTCHARSET);
186 mvaddch(y_limit, 0, 109 | A_ALTCHARSET); 186 mvaddch(y_limit, 0, 109 | A_ALTCHARSET);
187 mvaddch(y_limit, x_limit, 106 | A_ALTCHARSET); 187 mvaddch(y_limit, x_limit, 106 | A_ALTCHARSET);
188 188
189 /* Draw a white circle. */ 189 /* Draw a white circle. */
190 for (i = 1; i < y_limit; i++) { 190 for (i = 1; i < y_limit; i++) {
191 for (col = circle_pos[i][0]; col <= circle_pos[i][1]; col++) { 191 for (col = circle_pos[i][0]; col <= circle_pos[i][1]; col++) {
192 mvaddch(i, col, 32 | A_REVERSE); 192 mvaddch(i, col, 32 | A_REVERSE);
193 } 193 }
194 } 194 }
195  195
196 /* Add title segment. */ 196 /* Add title segment. */
197 for (i = roundf(1 * grid_unit); i < roundf(2 * grid_unit); i++) { 197 for (i = roundf(1 * grid_unit); i < roundf(2 * grid_unit); i++) {
198 if (colourOK) 198 if (colourOK)
199 attrset(COLOR_PAIR(COLOR_BLACK)); 199 attrset(COLOR_PAIR(COLOR_BLACK));
200 200
201 for (col = roundf((4 * grid_unit * 2) + 201 for (col = roundf((4 * grid_unit * 2) +
202 circle_pos[y_limit /2][0]); col <= roundf((9 * grid_unit 202 circle_pos[y_limit /2][0]); col <= roundf((9 * grid_unit
203 * 2) + circle_pos[y_limit /2][0]); col++) 203 * 2) + circle_pos[y_limit /2][0]); col++)
204 mvaddch(i, col, ' '); 204 mvaddch(i, col, ' ');
205 } 205 }
206 206
207 i = roundf(1.4 * grid_unit);  207 i = roundf(1.4 * grid_unit);
208 208
209 col = y_limit - (strlen(title) / 2) + circle_pos[y_limit / 2][0]; 209 col = y_limit - (strlen(title) / 2) + circle_pos[y_limit / 2][0];
210 mvprintw(i, col, "%s", title); 210 mvprintw(i, col, "%s", title);
211 211
212 /* Add black segments at top. */ 212 /* Add black segments at top. */
213 for (line = roundf(2 * grid_unit); line < 4 * grid_unit; line++) { 213 for (line = roundf(2 * grid_unit); line < 4 * grid_unit; line++) {
214 if (colourOK) 214 if (colourOK)
215 attrset(COLOR_PAIR(COLOR_BLACK)); 215 attrset(COLOR_PAIR(COLOR_BLACK));
216 216
217 for (col = 0; col <= roundf((3.5 * grid_unit * 2)); col++) { 217 for (col = 0; col <= roundf((3.5 * grid_unit * 2)); col++) {
218 xpos = col + circle_pos[y_limit / 2][0]; 218 xpos = col + circle_pos[y_limit / 2][0];
219 if (xpos >= circle_pos[line][0] && 219 if (xpos >= circle_pos[line][0] &&
220 xpos <= circle_pos[line][1]) 220 xpos <= circle_pos[line][1])
221 mvaddch(line, xpos, ' '); 221 mvaddch(line, xpos, ' ');
222 } 222 }
223 223
224 for (col = roundf((9.5 * grid_unit * 2)); col <  224 for (col = roundf((9.5 * grid_unit * 2)); col <
225 roundf((13 * grid_unit * 2)); col++) { 225 roundf((13 * grid_unit * 2)); col++) {
226 xpos = col + circle_pos[y_limit / 2][0]; 226 xpos = col + circle_pos[y_limit / 2][0];
227 if (xpos >= circle_pos[line][0] && 227 if (xpos >= circle_pos[line][0] &&
228 xpos <= circle_pos[line][1]) 228 xpos <= circle_pos[line][1])
229 mvaddch(line, xpos, ' '); 229 mvaddch(line, xpos, ' ');
230 } 230 }
231 } 231 }
232 232
233 /* Add black and white squares close to top. */ 233 /* Add black and white squares close to top. */
234 int gap = (circle_pos[(int)(5 * grid_unit)][1] - 234 int gap = (circle_pos[(int)(5 * grid_unit)][1] -
235 circle_pos[(int)(5 * grid_unit)][0]) / 13; 235 circle_pos[(int)(5 * grid_unit)][0]) / 13;
236 236
237 for (i = roundf(3 * grid_unit); i < roundf(4 * grid_unit); i++) { 237 for (i = roundf(3 * grid_unit); i < roundf(4 * grid_unit); i++) {
@@ -253,27 +253,27 @@ int main(int argc, char *argv[]) { @@ -253,27 +253,27 @@ int main(int argc, char *argv[]) {
253 if (col >= circle_pos[i][0] && 253 if (col >= circle_pos[i][0] &&
254 col <= circle_pos[i][1]) 254 col <= circle_pos[i][1])
255 mvaddch(i, col, ' '); 255 mvaddch(i, col, ' ');
256 } 256 }
257 } 257 }
258 } 258 }
259 259
260 /* Add colour bars. */ 260 /* Add colour bars. */
261 for (i = 0; i < numcolours; i++) { 261 for (i = 0; i < numcolours; i++) {
262 colour = colour_list[i]; 262 colour = colour_list[i];
263 if (colourOK) 263 if (colourOK)
264 attrset(COLOR_PAIR(colour)); 264 attrset(COLOR_PAIR(colour));
265 265
266 if (i == 0)  266 if (i == 0)
267 spacing_start = 0; 267 spacing_start = 0;
268 else 268 else
269 spacing_start = (spacing * i) + spacing_residual; 269 spacing_start = (spacing * i) + spacing_residual;
270 270
271 if (i == numcolours - 1) 271 if (i == numcolours - 1)
272 spacing_end = circle_pos[y_limit / 2][1]; 272 spacing_end = circle_pos[y_limit / 2][1];
273 else 273 else
274 spacing_end = (spacing * (i + 1)) + spacing_residual; 274 spacing_end = (spacing * (i + 1)) + spacing_residual;
275 275
276 for (line = roundf(4 * grid_unit); line < (y_limit / 2); 276 for (line = roundf(4 * grid_unit); line < (y_limit / 2);
277 line++) { 277 line++) {
278 for (col = spacing_start; col < spacing_end; col++) { 278 for (col = spacing_start; col < spacing_end; col++) {
279 xpos = col + circle_pos[y_limit / 2][0]; 279 xpos = col + circle_pos[y_limit / 2][0];
@@ -283,85 +283,85 @@ int main(int argc, char *argv[]) { @@ -283,85 +283,85 @@ int main(int argc, char *argv[]) {
283 } 283 }
284 } 284 }
285 } 285 }
286 286
287 /* Add black segment under centre line. */ 287 /* Add black segment under centre line. */
288 for (line = y_limit / 2; line < (9.5 * grid_unit); line++) { 288 for (line = y_limit / 2; line < (9.5 * grid_unit); line++) {
289 if (colourOK) 289 if (colourOK)
290 attrset(COLOR_PAIR(COLOR_BLACK)); 290 attrset(COLOR_PAIR(COLOR_BLACK));
291 291
292 for (col = circle_pos[line][0]; col <= circle_pos[line][1]; 292 for (col = circle_pos[line][0]; col <= circle_pos[line][1];
293 col++) 293 col++)
294 mvaddch(line, col, ' '); 294 mvaddch(line, col, ' ');
295 295
296 for (col = roundf((1.5 * grid_unit * 2)); col <  296 for (col = roundf((1.5 * grid_unit * 2)); col <
297 roundf((4.3 * grid_unit * 2)); col++) { 297 roundf((4.3 * grid_unit * 2)); col++) {
298 xpos = col + circle_pos[y_limit / 2][0]; 298 xpos = col + circle_pos[y_limit / 2][0];
299 if (xpos >= circle_pos[line][0] && 299 if (xpos >= circle_pos[line][0] &&
300 xpos < circle_pos[line][1]) 300 xpos < circle_pos[line][1])
301 mvaddch(line, xpos, 120 | A_ALTCHARSET); 301 mvaddch(line, xpos, 120 | A_ALTCHARSET);
302 } 302 }
303 303
304 for (col = roundf((4.3 * grid_unit * 2)); col <  304 for (col = roundf((4.3 * grid_unit * 2)); col <
305 roundf((7.6 * grid_unit * 2)); col++) { 305 roundf((7.6 * grid_unit * 2)); col++) {
306 xpos = col + circle_pos[y_limit / 2][0]; 306 xpos = col + circle_pos[y_limit / 2][0];
307 if (xpos >= circle_pos[line][0] && 307 if (xpos >= circle_pos[line][0] &&
308 xpos < circle_pos[line][1]) 308 xpos < circle_pos[line][1])
309 mvaddch(line, xpos, '|'); 309 mvaddch(line, xpos, '|');
310 } 310 }
311 311
312 for (col = roundf((7.6 * grid_unit * 2)); col <  312 for (col = roundf((7.6 * grid_unit * 2)); col <
313 roundf((11.5 * grid_unit * 2)); col++) { 313 roundf((11.5 * grid_unit * 2)); col++) {
314 xpos = col + circle_pos[y_limit / 2][0]; 314 xpos = col + circle_pos[y_limit / 2][0];
315 if (xpos >= circle_pos[line][0] && 315 if (xpos >= circle_pos[line][0] &&
316 xpos < circle_pos[line][1]) 316 xpos < circle_pos[line][1])
317 mvaddch(line, xpos, 97 | A_ALTCHARSET); 317 mvaddch(line, xpos, 97 | A_ALTCHARSET);
318 } 318 }
319 } 319 }
320 320
321 /* Add black segment close to bottom. */ 321 /* Add black segment close to bottom. */
322 for (line = roundf(9.5 * grid_unit); line <= (10.5 * grid_unit); 322 for (line = roundf(9.5 * grid_unit); line <= (10.5 * grid_unit);
323 line++) { 323 line++) {
324 if (colourOK) 324 if (colourOK)
325 attrset(COLOR_PAIR(COLOR_BLACK)); 325 attrset(COLOR_PAIR(COLOR_BLACK));
326 326
327 for (col = roundf((0 * grid_unit * 2)); col <  327 for (col = roundf((0 * grid_unit * 2)); col <
328 roundf((4 * grid_unit * 2)); col++) { 328 roundf((4 * grid_unit * 2)); col++) {
329 xpos = col + circle_pos[y_limit / 2][0]; 329 xpos = col + circle_pos[y_limit / 2][0];
330 if (xpos >= circle_pos[line][0] && 330 if (xpos >= circle_pos[line][0] &&
331 xpos < circle_pos[line][1]) 331 xpos < circle_pos[line][1])
332 mvaddch(line, xpos, ' '); 332 mvaddch(line, xpos, ' ');
333 } 333 }
334 334
335 for (col = roundf((4 * grid_unit * 2)); col <  335 for (col = roundf((4 * grid_unit * 2)); col <
336 roundf((6.5 * grid_unit * 2)); col++) { 336 roundf((6.5 * grid_unit * 2)); col++) {
337 xpos = col + circle_pos[y_limit / 2][0]; 337 xpos = col + circle_pos[y_limit / 2][0];
338 if (xpos >= circle_pos[line][0] && 338 if (xpos >= circle_pos[line][0] &&
339 xpos < circle_pos[line][1]) 339 xpos < circle_pos[line][1])
340 mvaddch(line, xpos, 97 | A_ALTCHARSET); 340 mvaddch(line, xpos, 97 | A_ALTCHARSET);
341 } 341 }
342 342
343 if (colourOK) 343 if (colourOK)
344 attrset(COLOR_PAIR(COLOR_WHITE)); 344 attrset(COLOR_PAIR(COLOR_WHITE));
345 345
346 for (col = roundf((6.5 * grid_unit * 2)); col <  346 for (col = roundf((6.5 * grid_unit * 2)); col <
347 roundf((9 * grid_unit * 2)); col++) { 347 roundf((9 * grid_unit * 2)); col++) {
348 xpos = col + circle_pos[y_limit / 2][0]; 348 xpos = col + circle_pos[y_limit / 2][0];
349 if (xpos >= circle_pos[line][0] && 349 if (xpos >= circle_pos[line][0] &&
350 xpos < circle_pos[line][1]) 350 xpos < circle_pos[line][1])
351 mvaddch(line, xpos, 97 | A_ALTCHARSET); 351 mvaddch(line, xpos, 97 | A_ALTCHARSET);
352 } 352 }
353 353
354 for (col = roundf((9 * grid_unit * 2)); col <  354 for (col = roundf((9 * grid_unit * 2)); col <
355 roundf((13 * grid_unit * 2)); col++) { 355 roundf((13 * grid_unit * 2)); col++) {
356 xpos = col + circle_pos[y_limit / 2][0]; 356 xpos = col + circle_pos[y_limit / 2][0];
357 if (xpos >= circle_pos[line][0] && 357 if (xpos >= circle_pos[line][0] &&
358 xpos < circle_pos[line][1]) 358 xpos < circle_pos[line][1])
359 mvaddch(line, xpos, ' '); 359 mvaddch(line, xpos, ' ');
360 } 360 }
361 } 361 }
362 362
363 /* Add name segment close to bottom. */ 363 /* Add name segment close to bottom. */
364 for (line = roundf(10.5 * grid_unit); line < (12 * grid_unit); 364 for (line = roundf(10.5 * grid_unit); line < (12 * grid_unit);
365 line++) { 365 line++) {
366 if (colourOK) 366 if (colourOK)
367 attrset(COLOR_PAIR(COLOR_BLACK)); 367 attrset(COLOR_PAIR(COLOR_BLACK));
@@ -396,38 +396,38 @@ int main(int argc, char *argv[]) { @@ -396,38 +396,38 @@ int main(int argc, char *argv[]) {
396 396
397 /* Add yellow segment at bottom. */ 397 /* Add yellow segment at bottom. */
398 for (line = 12 * grid_unit; line < y_limit; line++) { 398 for (line = 12 * grid_unit; line < y_limit; line++) {
399 if (colourOK) 399 if (colourOK)
400 attrset(COLOR_PAIR(COLOR_YELLOW)); 400 attrset(COLOR_PAIR(COLOR_YELLOW));
401 401
402 for (col = circle_pos[line][0]; col <= circle_pos[line][1]; 402 for (col = circle_pos[line][0]; col <= circle_pos[line][1];
403 col++) 403 col++)
404 mvaddch(line, col, ' '); 404 mvaddch(line, col, ' ');
405 405
406 if (colourOK) 406 if (colourOK)
407 attrset(COLOR_PAIR(COLOR_RED)); 407 attrset(COLOR_PAIR(COLOR_RED));
408 408
409 for (col = roundf((6 * grid_unit * 2)); col <  409 for (col = roundf((6 * grid_unit * 2)); col <
410 roundf((7 * grid_unit * 2)); col++) { 410 roundf((7 * grid_unit * 2)); col++) {
411 xpos = col + circle_pos[y_limit / 2][0]; 411 xpos = col + circle_pos[y_limit / 2][0];
412 if (xpos >= circle_pos[line][0] && 412 if (xpos >= circle_pos[line][0] &&
413 xpos < circle_pos[line][1]) 413 xpos < circle_pos[line][1])
414 mvaddch(line, xpos, ' '); 414 mvaddch(line, xpos, ' ');
415 } 415 }
416 } 416 }
417 417
418 if (colourOK) 418 if (colourOK)
419 attrset(COLOR_PAIR(COLOR_BLACK)); 419 attrset(COLOR_PAIR(COLOR_BLACK));
420  420
421 for (line = 6 * grid_unit; line <= (7 * grid_unit) + 1; line++) { 421 for (line = 6 * grid_unit; line <= (7 * grid_unit) + 1; line++) {
422 if (colourOK) 422 if (colourOK)
423 attrset(COLOR_PAIR(COLOR_BLACK)); 423 attrset(COLOR_PAIR(COLOR_BLACK));
424 424
425 col = x_limit / 2; 425 col = x_limit / 2;
426 if (line != a_axis) { 426 if (line != a_axis) {
427 mvaddch(line, col - 1, ' '); 427 mvaddch(line, col - 1, ' ');
428 mvaddch(line, col, 120 | A_ALTCHARSET); 428 mvaddch(line, col, 120 | A_ALTCHARSET);
429 mvaddch(line, col + 1, ' '); 429 mvaddch(line, col + 1, ' ');
430 } 430 }
431 } 431 }
432 432
433 line = y_limit / 2; 433 line = y_limit / 2;