breakup string into literals
This commit is contained in:
13
tools/tostr
13
tools/tostr
@@ -1,10 +1,10 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
awk '
|
awk '
|
||||||
BEGIN {
|
|
||||||
printf "\""
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
|
# Start a new string literal
|
||||||
|
printf "\""
|
||||||
|
|
||||||
for (i = 1; i <= length($0); i++) {
|
for (i = 1; i <= length($0); i++) {
|
||||||
c = substr($0, i, 1)
|
c = substr($0, i, 1)
|
||||||
if (c == "\\") {
|
if (c == "\\") {
|
||||||
@@ -31,10 +31,9 @@ BEGIN {
|
|||||||
printf "%s", c
|
printf "%s", c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf "\\n"
|
|
||||||
}
|
# Always end each literal with \n inside, close quote, then newline
|
||||||
END {
|
printf "\\n\"\n"
|
||||||
printf "\"\n"
|
|
||||||
}
|
}
|
||||||
function ord(str, l, r) {
|
function ord(str, l, r) {
|
||||||
l = sprintf("%c", 255)
|
l = sprintf("%c", 255)
|
||||||
|
|||||||
Reference in New Issue
Block a user