|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +if test $# -lt 2 |
| 4 | +then |
| 5 | + echo "USAGE: $0 <CLAR_DECLS_H> <OUTPUT>" 2>&1 |
| 6 | + exit 1 |
| 7 | +fi |
| 8 | + |
| 9 | +CLAR_DECLS_H="$1" |
| 10 | +OUTPUT="$2" |
| 11 | + |
| 12 | +awk ' |
| 13 | + function add_suite(suite, initialize, cleanup, count) { |
| 14 | + if (!suite) return |
| 15 | + suite_count++ |
| 16 | + callback_count += count |
| 17 | + suites = suites " {\n" |
| 18 | + suites = suites " \"" suite "\",\n" |
| 19 | + suites = suites " " initialize ",\n" |
| 20 | + suites = suites " " cleanup ",\n" |
| 21 | + suites = suites " _clar_cb_" suite ", " count ", 1\n" |
| 22 | + suites = suites " },\n" |
| 23 | + } |
| 24 | +
|
| 25 | + BEGIN { |
| 26 | + suites = "static struct clar_suite _clar_suites[] = {\n" |
| 27 | + } |
| 28 | +
|
| 29 | + { |
| 30 | + print |
| 31 | + name = $3; sub(/\(.*$/, "", name) |
| 32 | + suite = name; sub(/^test_/, "", suite); sub(/__.*$/, "", suite) |
| 33 | + short_name = name; sub(/^.*__/, "", short_name) |
| 34 | + cb = "{ \"" short_name "\", &" name " }" |
| 35 | + if (suite != prev_suite) { |
| 36 | + add_suite(prev_suite, initialize, cleanup, count) |
| 37 | + if (callbacks) callbacks = callbacks "};\n" |
| 38 | + callbacks = callbacks "static const struct clar_func _clar_cb_" suite "[] = {\n" |
| 39 | + initialize = "{ NULL, NULL }" |
| 40 | + cleanup = "{ NULL, NULL }" |
| 41 | + count = 0 |
| 42 | + prev_suite = suite |
| 43 | + } |
| 44 | + if (short_name == "initialize") { |
| 45 | + initialize = cb |
| 46 | + } else if (short_name == "cleanup") { |
| 47 | + cleanup = cb |
| 48 | + } else { |
| 49 | + callbacks = callbacks " " cb ",\n" |
| 50 | + count++ |
| 51 | + } |
| 52 | + } |
| 53 | +
|
| 54 | + END { |
| 55 | + add_suite(suite, initialize, cleanup, count) |
| 56 | + suites = suites "};" |
| 57 | + if (callbacks) callbacks = callbacks "};" |
| 58 | + print callbacks |
| 59 | + print suites |
| 60 | + print "static const size_t _clar_suite_count = " suite_count ";" |
| 61 | + print "static const size_t _clar_callback_count = " callback_count ";" |
| 62 | + } |
| 63 | +' "$CLAR_DECLS_H" >"$OUTPUT" |
0 commit comments