forked from bonsai/harakit
considering a different project directory struture
inspired by freebsd source tree
This commit is contained in:
68
bin/npc/npc.1
Normal file
68
bin/npc/npc.1
Normal file
@@ -0,0 +1,68 @@
|
||||
.\" Copyright (c) 2023–2024 DTB <trinity@trinity.moe>
|
||||
.\" Copyright (c) 2023 Emma Tebibyte <emma@tebibyte.media>
|
||||
.\"
|
||||
.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license,
|
||||
.\" visit <http://creativecommons.org/licenses/by-sa/4.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 RATIONALE
|
||||
|
||||
POSIX currently lacks a way to display non-printing characters in the terminal
|
||||
using a standard tool. A popular extension to cat(1p), the -v option, is the
|
||||
bandage solution GNU and other software suites use.
|
||||
|
||||
This functionality should be a separate tool because its usefulness extends
|
||||
beyond that of cat(1p).
|
||||
|
||||
.SH AUTHOR
|
||||
|
||||
Written by DTB <trinity@trinity.moe>.
|
||||
|
||||
.SH COPYRIGHT
|
||||
|
||||
Copyright © 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later
|
||||
<https://gnu.org/licenses/agpl.html>.
|
||||
|
||||
.SH SEE ALSO
|
||||
|
||||
cat(1p), cat-v(1)
|
||||
|
||||
.I UNIX Style, or cat -v Considered Harmful
|
||||
by Rob Pike
|
||||
63
bin/npc/npc.c
Normal file
63
bin/npc/npc.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2023 DTB <trinity@trinity.moe>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include <stdio.h> /* fprintf(3), fputs(3), getc(3), putc(3), stdin, stdout,
|
||||
* EOF */
|
||||
#include <stdlib.h> /* EXIT_FAILURE, EXIT_SUCCESS */
|
||||
#include <unistd.h> /* getopt(3) */
|
||||
#include <sysexits.h>
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user