1#!/bin/bash
2# This Linux-only script creates a sorted list of our API from several
3# independent locations within our source tree and finds all the
4# inconsistencies between them.
5
6# This script should be run from the top-level source tree.
7
8# Prepare API list from include/plplot.h to be compared with all others.
9
10# First add functions which are known to be part of our public API but without
11# the usual "c_" prefix folderol.  N.B. All functions will be added this
12# way if/when we drop that folderol.
13echo "plGetCursor" >| /tmp/plplot_api.txt
14# Be sure to remove officially deprecated functions later, but
15# there are none now.
16grep '^#define.*pl.*c_pl' include/plplot.h |\
17    tr '\t' " " |\
18    tr -s " " |\
19    cut --delimiter=" " --fields=2 \
20	>> /tmp/plplot_api.txt
21sort -o /tmp/plplot_api.txt /tmp/plplot_api.txt
22
23
24case $1 in
25    docbook)
26	# Prepare API list from doc/docbook/src/api.xml
27	# and compare with previous
28	echo "documentation API differences (if any)"
29	grep '<sect1.*id="pl.*".*renderas="sect.*">$' doc/docbook/src/api.xml |\
30	    cut --delimiter='"' --fields=2 |\
31	    sort |\
32	    diff -au /tmp/plplot_api.txt -
33	;;
34
35    swig)
36	# Prepare API list from bindings/swig-support/plplotcapi.i
37	# and compare with previous
38	echo "swig API differences (if any)"
39	# The grep -v stanzas get rid of some of the non-public API that
40	# is exposed for the swig-generated bindings.
41
42	grep '^pl.*(' bindings/swig-support/plplotcapi.i |\
43	    cut --delimiter='(' --fields=1 |\
44	    grep -v plAlloc2dGrid |\
45	    grep -v plClearOpts |\
46	    grep -v plFindCommand |\
47	    grep -v plFindName |\
48	    grep -v plFree2dGrid |\
49	    grep -v plGetFlt |\
50	    grep -v plGetInt |\
51	    grep -v plGetName |\
52	    grep -v plMergeOpts |\
53	    grep -v plMinMax2dGrid |\
54	    grep -v plOptUsage |\
55	    grep -v plResetOpts |\
56	    grep -v plSetUsage |\
57	    grep -v plTranslateCursor |\
58	    grep -v plgDevs |\
59	    grep -v plgFileDevs |\
60	    grep -v plsButtonEH |\
61	    grep -v plsError |\
62	    grep -v plsKeyEH |\
63	    grep -v pl_cmd |\
64	    grep -v pldid2pc |\
65	    grep -v pldip2dc |\
66	    grep -v plf2eval |\
67	    grep -v plf2eval2 |\
68	    grep -v plf2evalr |\
69	    grep -v plfcont |\
70	    grep -v plfshade |\
71	    grep -v plgesc |\
72	    grep -v plgfile |\
73	    grep -v plsexit |\
74	    grep -v plsfile |\
75	    grep -v plsxwin |\
76	    grep -v pltr0f |\
77	    grep -v pltr2f |\
78	    grep -v pltr2p |\
79	    sort |\
80	    diff -au /tmp/plplot_api.txt -
81	;;
82
83    java)
84	# Prepare API list from bindings/java/PLStream.java
85	# and compare with previous.
86	echo "java API differences (if any)"
87	# The grep -v '[A-Z]' stanza gets rid of some of the non-public API that
88	# is exposed.
89	grep 'plplotjavac.pl.*(' bindings/java/PLStream.java |\
90	    cut --delimiter='(' --fields=1 |\
91	    cut --delimiter='.' --fields=2 |\
92	    sort -u |\
93	    grep -v '[A-Z]' |\
94	    diff -au /tmp/plplot_api.txt -
95	;;
96
97    fortran)
98	# Prepare API list from the fortran binding and compare with previous.
99	echo "fortran API differences (if any)"
100	# We search for all occurrences of 'bind(c,name=' (with arbitrary blanks) to determine
101	# C names that are interfaced by our Fortran binding and parse that result with
102	# cut and sed to obtain the C name (without "c_" prefix if that occurs).
103	# We then do a unique
104	# sort to get rid of duplicates, and specifically exclude some added special
105	# fortran functions.
106	grep -h 'bind( *c *, *name *=' bindings/fortran/*.f90 |\
107	    cut --delimiter="'" --field=2 |\
108	    sed -e 's?c_??' |\
109	    sort -u |\
110	    grep -v _private |\
111	    grep -v _null |\
112	    grep -v '^plf2evalr' |\
113	    grep -v '^plfcont' |\
114	    grep -v '^plfvect' |\
115	    grep -v '^pltr' |\
116	    diff -au /tmp/plplot_api.txt -
117	;;
118
119    c++)
120	# Prepare API list from bindings/c++/plstream.h
121	# and compare with previous.
122	echo "c++ API differences (if any)"
123	grep 'plstream::' bindings/c++/plstream.cc |\
124	    grep -v '//' |\
125	    grep '(' |\
126	    cut --delimiter='(' --fields=1 |\
127	    cut --delimiter=':' --fields=3 |\
128	    sed 's/[^ ]*/pl&/' |\
129	    sort -u |\
130	    grep -v '[A-Z]' |\
131	    diff -au /tmp/plplot_api.txt -
132	;;
133
134    tcl)
135	# Prepare API list from bindings/tcl/plapi.tpl
136	echo "tcl API differences (if any)"
137	( grep '^pltclcmd' bindings/tcl/plapi.tpl |\
138		cut --delimiter=' ' --fields=2  && \
139		grep '{"pl' bindings/tcl/tclAPI.c | \
140		    cut --delimiter='"' --fields=2 \
141	) | \
142	    sort -u | \
143	    diff -au /tmp/plplot_api.txt -
144	;;
145
146    all)
147	$0 docbook
148	$0 swig
149	$0 java
150	$0 fortran
151	$0 c++
152	$0 tcl
153	;;
154
155    *)
156	echo "First argument was $1"
157	echo "Instead, it must be one of the following:"
158	echo "docbook, swig, java, fortran, c++, tcl or all"
159	;;
160esac
161#rm /tmp/plplot_api.txt
162