finish npc
This commit is contained in:
parent
3e77b69e66
commit
546ad1d96d
1
wip/npc/Makefile
Normal file
1
wip/npc/Makefile
Normal file
@ -0,0 +1 @@
|
||||
npc: npc.c
|
47
wip/npc/npc.1
Normal file
47
wip/npc/npc.1
Normal file
@ -0,0 +1,47 @@
|
||||
.TH npc 1
|
||||
|
||||
.SH NAME
|
||||
|
||||
npc \(en show non-printing characters
|
||||
|
||||
.SH SYNOPSIS
|
||||
|
||||
npc
|
||||
.RB ( -eht )
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
||||
Npc reads from standard input and writes to standard output, replacing non-
|
||||
printing characters with printable equivalents. Control characters print as a
|
||||
carat ('^') followed by the character '@' through '_' corresponding to the
|
||||
character replaced (e.g. control-X becomes "^X"). The delete character (0x7F)
|
||||
becomes "^?". Characters with the high bit set (>127) are printed as "M-"
|
||||
followed by the graphical representation for the same character without the
|
||||
high bit set.
|
||||
.PP
|
||||
The
|
||||
.B -e
|
||||
option prints a currency sign ('$') before each line ending.
|
||||
.PP
|
||||
The
|
||||
.B -t
|
||||
option prints tab characters as "^I" rather than a literal horizontal tab.
|
||||
|
||||
.SH DIAGNOSTICS
|
||||
|
||||
Npc prints a debug message and exits with the appropriate sysexits(3) error
|
||||
code in the event of an error, otherwise it exits successfully.
|
||||
|
||||
.SH STANDARDS
|
||||
|
||||
None.
|
||||
|
||||
.SH COPYRIGHT
|
||||
|
||||
Public domain.
|
||||
|
||||
.SH SEE ALSO
|
||||
|
||||
cat(1), cat-v(1)
|
||||
.PP
|
||||
"UNIX Style, or cat -v Considered Harmful" by Rob Pike
|
52
wip/npc/npc.c
Normal file
52
wip/npc/npc.c
Normal file
@ -0,0 +1,52 @@
|
||||
#include <stdio.h> /* fprintf(3), fputs(3), getc(3), putc(3), stdin, stdout,
|
||||
* EOF */
|
||||
#include <unistd.h> /* getopt(3) */
|
||||
#if !defined EX_USAGE || !defined EX_OK
|
||||
# include <sysexits.h>
|
||||
#endif
|
||||
|
||||
static char *program_name = "npc";
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
int c;
|
||||
char showend;
|
||||
char showtab;
|
||||
|
||||
showend = 0;
|
||||
showtab = 0;
|
||||
|
||||
if(argc > 0)
|
||||
while((c = getopt(argc, argv, "et")) != -1)
|
||||
switch(c){
|
||||
case 'e': showend = 1; break;
|
||||
case 't': showend = 1; break;
|
||||
default: goto usage;
|
||||
}
|
||||
|
||||
if(optind > argc){
|
||||
usage: fprintf(stderr,
|
||||
"Usage: %s (-eht)\n",
|
||||
argv[0] == NULL ? program_name : argv[0]);
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
while((c = getc(stdin)) != EOF){
|
||||
if(c > 127){
|
||||
fputs("M-", stdout);
|
||||
c -= 128;
|
||||
}
|
||||
switch(c){
|
||||
case 127: 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 + '@');
|
||||
}
|
||||
}
|
||||
|
||||
return EX_OK;
|
||||
}
|
Loading…
Reference in New Issue
Block a user