Migrate format-source script to new apidsl web app.

This one is unfortunately a little more complicated to use. I may add a
simpler API later, but for now, it's JSON-based (because I couldn't get
binary data to work without it getting mangled somewhere along the way -
JSON is at least text-transport-safe).
This commit is contained in:
iphydf 2020-03-23 00:46:02 +00:00
parent 40dd88596e
commit 0964961557
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
2 changed files with 27 additions and 7 deletions

View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
set -ex
@ -30,8 +30,28 @@ if ! which "$APIDSL"; then
fi
fi
TO_JSON='s/\\/\\\\/g;s/\n/\\n/g;s/"/\\"/g;s/^(.*)$/"$1"/'
FROM_JSON='s/\\"/"/g;s/^"(.*)"$/$1/;s/\\\\/\\/g;s/\\n/\n/g'
apidsl_request() {
TMPFILE=$(mktemp /tmp/apidsl.XXXXXX)
curl -o "$TMPFILE" -X POST --data @<(
echo '["Request",';
cat $2;
echo ']') https://apidsl2.herokuapp.com/$1
if grep '\[1,"' "$TMPFILE" > /dev/null; then
echo "Error: $(grep -o '".*"' /tmp/apidsl-$$ | perl -0777 -pe "$FROM_JSON")" >&2
rm "$TMPFILE"
exit 1
fi
perl -0777 -pe 's/^\[0,(.*)\]$/$1/' "$TMPFILE"
rm "$TMPFILE"
}
apidsl_curl() {
curl -X POST --data-binary @"$1" https://apidsl.herokuapp.com/apidsl
apidsl_request "c" <(
apidsl_request "parse" <(
perl -0777 -pe "$TO_JSON" $1)) | perl -0777 -pe "$FROM_JSON"
}
# Check if apidsl generated sources are up to date.