forked from bonsai/harakit
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 <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,32 +35,30 @@ int main(int argc, char *argv[]){
|
||||
showend = 0;
|
||||
showtab = 0;
|
||||
|
||||
if(argc > 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 > 0) { usage(argv[0]); }
|
||||
|
||||
if(argc > optind){
|
||||
usage: fprintf(stderr, "Usage: %s [-et]\n", argv[0]);
|
||||
return EX_USAGE;
|
||||
while ((c = getopt(argc, argv, "et")) != -1) {
|
||||
switch(c){
|
||||
case 'e': showend = 1; break;
|
||||
case 't': showtab = 1; break;
|
||||
default: 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);
|
||||
default:
|
||||
if(c >= ' ' || c == '\n' || (!showtab && c == '\t'))
|
||||
putc(c, stdout);
|
||||
else
|
||||
fprintf(stdout, "^%c", c + '@');
|
||||
if(argc > optind) { return usage(argv[0]); }
|
||||
|
||||
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')) {
|
||||
putc(c, stdout);
|
||||
} else {
|
||||
fprintf(stdout, "^%c", c + '@');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user