swab(1): formatting, remove gotos

This commit is contained in:
Emma Tebibyte 2024-07-12 15:43:00 -06:00
parent 1ad4114882
commit acc3cf3e90
Signed by untrusted user: emma
GPG Key ID: 06FA419A1698C270

View File

@ -22,6 +22,11 @@
#include <unistd.h> /* getopt(3) */ #include <unistd.h> /* getopt(3) */
#include <sysexits.h> #include <sysexits.h>
int usage(char *s) {
fprintf(stderr, "Usage: %s [-et]\n", s);
return EX_USAGE;
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
int c; int c;
char showend; char showend;
@ -30,34 +35,32 @@ int main(int argc, char *argv[]){
showend = 0; showend = 0;
showtab = 0; showtab = 0;
if(argc > 0) if(!argc > 0) { usage(argv[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: goto usage; default: return usage(argv[0]);
}
} }
if(argc > optind){ if(argc > optind) { return usage(argv[0]); }
usage: fprintf(stderr, "Usage: %s [-et]\n", argv[0]);
return EX_USAGE;
}
while ((c = getc(stdin)) != EOF) { while ((c = getc(stdin)) != EOF) {
if((c & 0x80) != 0) if ((c & 0x80) != 0) { fputs("M-", stdout); }
fputs("M-", stdout);
switch(c ^ 0x80 /* 0b 1000 0000 */){ switch (c ^ 0b10000000) {
case 0x7f: fputs("^?", stdout); case 0x7f: fputs("^?", stdout); break;
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 + '@');
} }
} }
}
return EX_OK; return EX_OK;
} }