swab(1): formatting, remove gotos
This commit is contained in:
parent
1ad4114882
commit
acc3cf3e90
51
src/npc.c
51
src/npc.c
@ -22,7 +22,12 @@
|
|||||||
#include <unistd.h> /* getopt(3) */
|
#include <unistd.h> /* getopt(3) */
|
||||||
#include <sysexits.h>
|
#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;
|
int c;
|
||||||
char showend;
|
char showend;
|
||||||
char showtab;
|
char showtab;
|
||||||
@ -30,32 +35,30 @@ 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)
|
|
||||||
switch(c){
|
|
||||||
case 'e': showend = 1; break;
|
|
||||||
case 't': showtab = 1; break;
|
|
||||||
default: goto usage;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(argc > optind){
|
while ((c = getopt(argc, argv, "et")) != -1) {
|
||||||
usage: fprintf(stderr, "Usage: %s [-et]\n", argv[0]);
|
switch(c){
|
||||||
return EX_USAGE;
|
case 'e': showend = 1; break;
|
||||||
|
case 't': showtab = 1; break;
|
||||||
|
default: return usage(argv[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while((c = getc(stdin)) != EOF){
|
if(argc > optind) { return usage(argv[0]); }
|
||||||
if((c & 0x80) != 0)
|
|
||||||
fputs("M-", stdout);
|
while ((c = getc(stdin)) != EOF) {
|
||||||
switch(c ^ 0x80 /* 0b 1000 0000 */){
|
if ((c & 0x80) != 0) { fputs("M-", stdout); }
|
||||||
case 0x7f: fputs("^?", stdout);
|
|
||||||
break;
|
switch (c ^ 0b10000000) {
|
||||||
case '\n': if(showend)
|
case 0x7f: fputs("^?", stdout); break;
|
||||||
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 + '@');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user