From 09649615575b7a3286892a433479512df2a7eb40 Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 23 Mar 2020 00:46:02 +0000 Subject: 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). --- other/astyle/format-source | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'other') 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 @@ -#!/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. -- cgit v1.2.3