]> git.codecow.com Git - Monocypher.git/commitdiff
Rewrite example test script in shell
authorMichael Savage <mikejsavage@gmail.com>
Sat, 28 Dec 2019 11:53:34 +0000 (13:53 +0200)
committerMichael Savage <mikejsavage@gmail.com>
Sat, 28 Dec 2019 11:54:08 +0000 (13:54 +0200)
doc/man/man3/test_examples.lua [deleted file]
doc/man2c.sh [new file with mode: 0755]

diff --git a/doc/man/man3/test_examples.lua b/doc/man/man3/test_examples.lua
deleted file mode 100755 (executable)
index 37a1c49..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-#! /usr/bin/env lua
-
-local lfs = require( "lfs" )
-
-local all = {
-       "#include \"../../../src/monocypher.h\"",
-       "#include \"../../../src/optional/monocypher-ed25519.h\"",
-       "#include <stdlib.h>",
-       "int main() {",
-}
-
-local function AddExamples( man )
-       for code in man:gmatch( "%.Bd[^\n]*\n(.-)%.Ed" ) do
-               table.insert( all, "{" )
-               table.insert( all, code )
-               table.insert( all, "}" )
-       end
-end
-
-local function AddDir( path )
-       for file in lfs.dir( path ) do
-               local attr = lfs.symlinkattributes( path .. "/" .. file )
-               if file:match( "%.3monocypher$" ) and attr.mode == "file" then
-                       table.insert( all, "// " .. path .. "/" .. file )
-
-                       local f = assert( io.open( path .. "/" .. file, "r" ) )
-                       local contents = assert( f:read( "*all" ) )
-                       f:close()
-
-                       AddExamples( contents )
-
-                       table.insert( all, "" )
-               end
-       end
-end
-
-AddDir( "." )
-AddDir( "optional" )
-
-table.insert( all, "}" )
-
-print( table.concat( all, "\n" ) )
diff --git a/doc/man2c.sh b/doc/man2c.sh
new file mode 100755 (executable)
index 0000000..20d6d0d
--- /dev/null
@@ -0,0 +1,25 @@
+#! /bin/sh
+
+cat << END
+#include <stdio.h>
+#include <stdlib.h>
+#include "../src/monocypher.h"
+#include "../src/optional/monocypher-ed25519.h"
+
+typedef struct SHA2_CTX { } SHA2_CTX;
+void SHA512Init(SHA2_CTX*);
+void SHA512Update(SHA2_CTX*, void*, size_t);
+void SHA512Final(uint8_ *, SHA2_CTX*);
+void arc4random_buf(void *, size_t);
+
+int main() {
+END
+
+for f in man/man3/*.3monocypher man/man3/optional/*.3monocypher; do
+       if ! [ -L "$f" ]; then
+               echo "// $f"
+               sed -n "/^\.Bd/,/^\.Ed/p" < $f | sed "s/\.Bd.*/{/" | sed "s/\.Ed/}/"
+       fi
+done
+
+echo "}"