From d61066fcfe7f00843c4660182ea38ba3a5e41803 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 13 Apr 2010 16:14:14 +0200 Subject: test: add API test part1; Needs improvement: Think about a sensible way to map feature sets to the mandated syms. Our LEGACY stuff maps to OB, OBXSI for example. A "normal" config should satisfy the BASE (i.e. $foo.SUSv4.syms) Signed-off-by: Bernhard Reutner-Fischer --- test/API/html2input.sh | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100755 test/API/html2input.sh (limited to 'test/API/html2input.sh') diff --git a/test/API/html2input.sh b/test/API/html2input.sh new file mode 100755 index 000000000..9ea68fec1 --- /dev/null +++ b/test/API/html2input.sh @@ -0,0 +1,119 @@ +#!/bin/sh +# vi: ft=awk : +# +# Script to extract functions and external variables off SUS html docs +# +# Copyright (C) 2010 Bernhard Reutner-Fischer +# Public Domain + +# Usage: +# wget http://www.opengroup.org/onlinepubs/9699919799/download/susv4.tgz +# tar xzf susv4.tgz +# SUS=susv4 html2input.sh -vFULL_DECLARATIONS=1 +# or +# SUS=susv4 html2input.sh -vFULL_DECLARATIONS=0 -vSTDNAME=SUSv4 +# +# Bug in time.h.html of SUSv4: +# It inconsistently reads "as variables" instead of "external variables" that +# is used everywhere except in time.h.html + +test "x$SUS" = "x" && SUS="susv4" +test "x$AWK" = "x" && AWK="AWK" +test "x$GREP" = "x" && GREP="GREP" +for h in \ + $($GREP -l "shall be declared as functions" $SUS/basedefs/*.h.html) \ + $($GREP -l "shall declare the following as variables" $SUS/basedefs/*.h.html) \ + $($GREP -l "shall declare the following external variables" $SUS/basedefs/*.h.html) +do +$AWK $* ' +function get_filename () { + if (NR == 1) { + x=FILENAME + sub(".*/", "", x) + split(x, f , ".") + fname=f[1] + if (STDNAME) + fname=fname "." STDNAME + fname=fname ".in" + printf "" > fname + } +} +function unhtml (l) { + sub("", "", l) + sub("", "", l) + sub("", "", l) + sub("", "", l) + sub("]*>", "", l) + sub("", "", l) + if (l ~ /]*Option[[:space:]][[:space:]]*Start[^>]*>/) { + sub("]*>", "[Option Start]", l) + } else if (l ~ /]*Option[[:space:]][[:space:]]*End[^>]*>/) { + sub("]*>", "[Option End]", l) + } + sub("<.*>", "", l) + return l +} +function get_funcname (l) { + if (FULL_DECLARATIONS) + return l + if (l !~ /;$/) + return l + cnt = split(l, foo, " ") + if (cnt >= 2 && foo[2] ~ /^\(\*/) { + cnt = split(l, foo, "(") + # good enough for signal() and sigset() + if (cnt >= 2) + l=foo[2] + } else { + sub("\\(.*", "", l) + } + gsub("[[\\]\\*]", "", l) + i = split(l, a, " ") + if (i) + l = a[i] + return l +} +function get_varname (l) { + if (FULL_DECLARATIONS) + return l + if (l !~ /;$/) + return l + gsub(",[[:space:]][[:space:]]*", ",", l) + sub(";$", "", l) + i = split(l, a, " ") + if (i) + l = a[i] + gsub("[[\\]\\*]", "", l) + gsub(",", "\n", l) + return l +} +BEGIN{data=0;l=""} +get_filename() +/shall be declared as functions/{data=1;isvar=0;next;} +/shall declare the following as variables/{data=1;isvar=1;next;} +/shall declare the following external variables/{data=1;isvar=1;next;} +/
/{data++;next;}
+/<\/pre>/{data=0;next;}
+/.*/{
+	if (data == 2 && fname) {
+		tmp = $0
+		sub("^[[:space:]][[:space:]]*", " ", tmp)
+		l = l tmp
+		tmp = unhtml(l)
+		if (!tmp)
+			next
+		l = tmp
+		if (tmp !~ /;$/ && tmp !~ />$/ &&
+			tmp !~ /Option Start\]$/ && tmp !~ /Option End\]$/)
+			next
+		if (!isvar)
+			l = get_funcname(l)
+		else
+			l = get_varname(l)
+		if (l)
+			print l >> fname
+		l=""
+	}
+}
+' $h
+done
-- 
cgit v1.2.3