2023-12-24 17:13:17 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2023 DTB <trinity@trinity.moe>
|
2024-07-12 15:55:36 -06:00
|
|
|
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
2023-12-24 17:13:17 -07:00
|
|
|
* 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 */
|
2023-12-25 15:57:58 -07:00
|
|
|
#include <stdlib.h> /* EXIT_FAILURE, EXIT_SUCCESS */
|
2023-12-24 17:13:17 -07:00
|
|
|
#include <unistd.h> /* getopt(3) */
|
2023-12-25 20:49:29 -07:00
|
|
|
#include <sysexits.h>
|
2023-12-24 17:13:17 -07:00
|
|
|
|
2024-07-12 15:43:00 -06:00
|
|
|
int usage(char *s) {
|
|
|
|
fprintf(stderr, "Usage: %s [-et]\n", s);
|
|
|
|
return EX_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2023-12-24 17:13:17 -07:00
|
|
|
int c;
|
|
|
|
char showend;
|
|
|
|
char showtab;
|
|
|
|
|
|
|
|
showend = 0;
|
|
|
|
showtab = 0;
|
|
|
|
|
2024-07-12 15:43:00 -06:00
|
|
|
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: return usage(argv[0]);
|
|
|
|
}
|
2023-12-24 17:13:17 -07:00
|
|
|
}
|
|
|
|
|
2024-07-12 15:43:00 -06:00
|
|
|
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 + '@');
|
|
|
|
}
|
2023-12-24 17:13:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EX_OK;
|
|
|
|
}
|