npc(1): specifies sysexits imports, formatting

This commit is contained in:
Emma Tebibyte 2024-07-13 17:03:41 -06:00
parent 8421f8be87
commit 35a20dca79
Signed by untrusted user: emma
GPG Key ID: 06FA419A1698C270

View File

@ -19,9 +19,9 @@
#include <stdio.h> /* fprintf(3), fputs(3), getc(3), putc(3), stdin, stdout, #include <stdio.h> /* fprintf(3), fputs(3), getc(3), putc(3), stdin, stdout,
* EOF */ * EOF */
#include <stdlib.h> /* EXIT_FAILURE, EXIT_SUCCESS */ #include <stdlib.h> /* EXIT_FAILURE */
#include <unistd.h> /* getopt(3) */ #include <unistd.h> /* getopt(3) */
#include <sysexits.h> #include <sysexits.h> /* EX_OK, EX_USAGE */
int usage(char *s) { int usage(char *s) {
fprintf(stderr, "Usage: %s [-et]\n", s); fprintf(stderr, "Usage: %s [-et]\n", s);
@ -36,17 +36,17 @@ int main(int argc, char *argv[]) {
showend = 0; showend = 0;
showtab = 0; showtab = 0;
if(!argc > 0) { usage(argv[0]); } if (argc > 0) {
while ((c = getopt(argc, argv, "et")) != -1) {
while ((c = getopt(argc, argv, "et")) != -1) { switch (c){
switch(c){ case 'e': showend = 1; break;
case 'e': showend = 1; break; case 't': showtab = 1; break;
case 't': showtab = 1; break; default: return usage(argv[0]);
default: return usage(argv[0]); }
} }
} }
if(argc > optind) { return usage(argv[0]); } if (argc > optind) { return usage(argv[0]); }
while ((c = getc(stdin)) != EOF) { while ((c = getc(stdin)) != EOF) {
if ((c & 0x80) != 0) { fputs("M-", stdout); } if ((c & 0x80) != 0) { fputs("M-", stdout); }
@ -55,7 +55,7 @@ int main(int argc, char *argv[]) {
case 0x7f: fputs("^?", stdout); break; case 0x7f: fputs("^?", stdout); break;
case '\n': if (showend) { putc('$', stdout); } case '\n': if (showend) { putc('$', stdout); }
default: default:
if(c >= ' ' || c == '\n' || (!showtab && c == '\t')) { if (c >= ' ' || c == '\n' || (!showtab && c == '\t')) {
putc(c, stdout); putc(c, stdout);
} else { } else {
fprintf(stdout, "^%c", c + '@'); fprintf(stdout, "^%c", c + '@');