1
0

npc incorporated into bonsai

This commit is contained in:
dtb 2023-12-25 16:56:58 -07:00
parent 7cc847d8f5
commit c0e548d323
3 changed files with 0 additions and 98 deletions

View File

@ -1 +0,0 @@
npc: npc.c

View File

@ -1,51 +0,0 @@
.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 BUGS
Npc operates in single-byte chunks regardless of intended encoding.
.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

View File

@ -1,46 +0,0 @@
#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
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': showtab = 1; break;
default: goto usage;
}
if(argc > optind){
usage: fprintf(stderr, "Usage: %s (-eht)\n", argv[0]);
return EX_USAGE;
}
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 + '@');
}
}
return EX_OK;
}