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