
ai="
WAV
AIFF
AU
RAW
PAF
SVX
NIST
VOC
IRCAM
W64
MAT4
MAT5
PVF
XI
HTK
SDS
AVR
WAVEX
SD2
FLAC
CAF
OGG
MP3
MP2
SPEEX
WMA
AAC
VQF
RA
"

echo "static int setformat_base(char *soundfile_format){"
echo "  return("

for a in $ai;do
    echo "#include <sndfile.h>" >temp.c
    echo "main(){return SF_FORMAT_"$a";}" >>temp.c
    echo >>temp.c
    if gcc temp.c 2>/dev/null; then
	echo "    (!strcasecmp(\""$a"\",soundfile_format)) ? SF_FORMAT_"$a":"
    fi
done
echo "    -1);"
echo "}"
echo
echo "void setformat(SF_INFO *sf_info,char *soundfile_format){"
echo "    int format=setformat_base(soundfile_format);"
echo "    if(format==-1){"
echo '      fprintf(stderr,"Warning, the format \"%s\" is not supported. Using wav instead.\n",soundfile_format);'
echo "      sf_info->format=SF_FORMAT_WAV;"
echo "    }else"
echo "      sf_info->format=format;"
echo "}"
echo
echo "void print_all_formats(void){"
#echo "  printf(\"Supported formats: \\n\");"
echo
for a in $ai;do
    echo "  if(setformat_base(\""$a"\")!=-1)"
    echo "    printf(\""`echo $a|tr '[:upper:]' '[:lower:]'`" \");"
done
echo '   printf("\n");'
echo "}"
