#! /bin/sh
# Copyright © 2015 Rémi Denis-Courmont

cd "$(dirname "$0")" || exit $?
test -f libvlccore.sym || exit 1

# DO NOT add new entries here.
# Do make existing ones more specific.
# Do remove existing ones (especially near the end).

echo "Looking for unprefixed exported symbols..."
cat libvlccore.sym | grep -v \
	-e '^vlc_' -e '^vlm_' -e '^libvlc_[A-Z]' -e '^VLC_' \
	-e '^input_' -e '^access_' -e '^demux_' -e '^decoder_' \
	-e '^image_' -e '^block_' -e '^picture_' -e '^subpicture_' \
	-e '^es_format' -e '^[asv]out_' -e '^spu_' -e '^filter_' \
	-e '^video_format_' \
	-e '^intf_' \
	-e '^update_' -e '^addons\?_' -e '^fingerprinter_' \
	-e '^text_style_' -e '^text_segment_' \
	-e '^net_' -e '^httpd_' \
	-e '^config_' -e '^module_' -e '^var_' \
	-e '^date_' -e '^plane_' \
	-e '^utf8_' -e '^xml_' \
	-e '^[A-Z][a-z]*Charset$' \
		&& exit 1

echo "None found."

echo "Looking for VLC_API symbols missing from libvlccore.sym..."
# Drop preprocessor lines, then put each VLC_API declaration on one line
sed -n -e '/^[[:space:]]*#/d' -e '/VLC_API/!d' \
	-e ':a' -e '/[([;]/!{' -e 'N' -e 'ba' -e '}' -e 's/\n/ /g' -e 's/^/ /p' \
	../include/*.h |
# Keep what follows VLC_API, up to the parameter list or array size
sed -n 's/.*[^A-Za-z0-9_]VLC_API[^A-Za-z0-9_]\([^([;]*\).*/\1/p' |
# The symbol is the last identifier left
sed 's/[[:space:]]*$//; s/.*[^A-Za-z0-9_]//' |
sort -u | grep -vxF -f libvlccore.sym && exit 1

echo "None found."
