-
Notifications
You must be signed in to change notification settings - Fork 10
/
unescoct
executable file
·85 lines (74 loc) · 3.49 KB
/
unescoct
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
######################################################################
#
# UNESCOCT - A Filter of Unescaping Escaped 3-Digit-Octal Numbers
#
# USAGE: unescoct [file...]
#
# Written by Shell-Shoccar Japan (@shellshoccarjpn) on 2020-05-06
#
# This is a public-domain software (CC0). It means that all of the
# people can use this for any purposes with no restrictions at all.
# By the way, We are fed up with the side effects which are brought
# about by the major licenses.
#
# The latest version is distributed at the following page.
# https://github.com/ShellShoccar-jpn/misc-tools
#
######################################################################
######################################################################
# Initial Configuration
######################################################################
# === Initialize shell environment ===================================
set -u
umask 0022
export LC_ALL=C
export PATH="$(command -p getconf PATH 2>/dev/null)${PATH+:}${PATH-}"
case $PATH in :*) PATH=${PATH#?};; esac
export UNIX_STD=2003 # to make HP-UX conform to POSIX
# === Define the functions for printing usage ========================
print_usage_and_exit () {
cat <<-USAGE 1>&2
Usage : ${0##*/} <file> [file...]
Version : 2020-05-06 22:42:19 JST
USAGE
exit 1
}
######################################################################
# Argument Parsing
######################################################################
# === Print usage and exit if one of the help options is set =========
case "$# ${1:-}" in
'1 -h'|'1 --help'|'1 --version') print_usage_and_exit;;
esac
######################################################################
# Main
######################################################################
(cat ${1+"$@"}; echo '') |
awk 'BEGIN { #
OFS=""; ORS=""; #
while (getline line) { #
while (1) { #
if (line=="") {print "\n"; break;} #
if (match(line,/\\[0-9][0-9][0-9]/)) { #
print substr(line, 1, RSTART-1); #
o=substr(line,RSTART+1,3); #
n=substr(o,1,1)*64+substr(o,2,1)*8+substr(o,3,1); #
printf("%c",n); #
line=substr(line,RSTART+4); #
} else { #
print line #
line=""; #
} #
} #
} #
}' |
awk 'BEGIN{ #
ORS=""; OFS=""; #
getline line; #
print line; #
dlm=sprintf("\n"); #
while (getline line) { #
print dlm,line; #
} #
}'