diff options
author | iphydf <iphydf@users.noreply.github.com> | 2020-03-23 00:46:02 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2020-04-04 21:18:05 +0000 |
commit | 09649615575b7a3286892a433479512df2a7eb40 (patch) | |
tree | 4baab7a37f834c1483a96c70081d5b6dbf287c7b /other | |
parent | 40dd88596eda0eea5df67e747e93baf65cab2cbf (diff) |
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).
Diffstat (limited to 'other')
-rwxr-xr-x | other/astyle/format-source | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/other/astyle/format-source b/other/astyle/format-source index c2238841..7fa8b677 100755 --- a/other/astyle/format-source +++ b/other/astyle/format-source | |||
@@ -1,4 +1,4 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/bash |
2 | 2 | ||
3 | set -ex | 3 | set -ex |
4 | 4 | ||
@@ -30,8 +30,28 @@ if ! which "$APIDSL"; then | |||
30 | fi | 30 | fi |
31 | fi | 31 | fi |
32 | 32 | ||
33 | TO_JSON='s/\\/\\\\/g;s/\n/\\n/g;s/"/\\"/g;s/^(.*)$/"$1"/' | ||
34 | FROM_JSON='s/\\"/"/g;s/^"(.*)"$/$1/;s/\\\\/\\/g;s/\\n/\n/g' | ||
35 | |||
36 | apidsl_request() { | ||
37 | TMPFILE=$(mktemp /tmp/apidsl.XXXXXX) | ||
38 | curl -o "$TMPFILE" -X POST --data @<( | ||
39 | echo '["Request",'; | ||
40 | cat $2; | ||
41 | echo ']') https://apidsl2.herokuapp.com/$1 | ||
42 | if grep '\[1,"' "$TMPFILE" > /dev/null; then | ||
43 | echo "Error: $(grep -o '".*"' /tmp/apidsl-$$ | perl -0777 -pe "$FROM_JSON")" >&2 | ||
44 | rm "$TMPFILE" | ||
45 | exit 1 | ||
46 | fi | ||
47 | perl -0777 -pe 's/^\[0,(.*)\]$/$1/' "$TMPFILE" | ||
48 | rm "$TMPFILE" | ||
49 | } | ||
50 | |||
33 | apidsl_curl() { | 51 | apidsl_curl() { |
34 | curl -X POST --data-binary @"$1" https://apidsl.herokuapp.com/apidsl | 52 | apidsl_request "c" <( |
53 | apidsl_request "parse" <( | ||
54 | perl -0777 -pe "$TO_JSON" $1)) | perl -0777 -pe "$FROM_JSON" | ||
35 | } | 55 | } |
36 | 56 | ||
37 | # Check if apidsl generated sources are up to date. | 57 | # Check if apidsl generated sources are up to date. |