This is zyxel.c in view mode; [Download] [Up]
/*********************************************************************/
/* */
/* Programmer: */
/* Olaf Mueller <olaf@orest.escape.de> */
/* */
/* Purpose: */
/* Answering Machine */
/* read and convert a zyxel voice file */
/* */
/* History: */
/* 29-08-96 Initial Release Olaf Mueller */
/* */
/* Notes: */
/* */
/*********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "zyxel.h"
#include "const.h"
int ZSNDread (char *filename,ZyxelSND *zsnd)
{
FILE *fpzsnd ;
if ((fpzsnd = fopen(filename,"r")) == NULL)
return -1 ;
fseek (fpzsnd,0L,SEEK_END) ;
if ((zsnd->voicelen = ftell (fpzsnd) - sizeof (ZyxelHeader)) < 0)
{
fclose (fpzsnd) ;
return -1 ;
}
if ((zsnd->voice = (char*)malloc (zsnd->voicelen)) == NULL)
{
fclose (fpzsnd) ;
return -1 ;
}
rewind (fpzsnd) ;
if (fread(&zsnd->zyxel,sizeof(ZyxelHeader),1,fpzsnd) != 1 ||
fread(zsnd->voice,zsnd->voicelen,1,fpzsnd) != 1)
{
fclose (fpzsnd) ;
free (zsnd->voice) ;
return ZYX_NOZYXELSTRUCT ;
}
fclose (fpzsnd) ;
if (memcmp(zsnd->zyxel.title,ZYX_TITLE,strlen(ZYX_TITLE)))
{
free (zsnd->voice) ;
return ZYX_NOZYXELSTRUCT ;
}
if (zsnd->zyxel.mode != ZYX_VOC)
{
free (zsnd->voice) ;
return ZYX_NOMODE ;
}
if (zsnd->zyxel.voice > 2)
{
free (zsnd->voice) ;
return ZYX_NOVOICE ;
}
zsnd->play = NULL ;
return 0 ;
}
int ZSNDmakePlayable (ZyxelSND *zsnd)
{
int ii ;
char *vp , *pp ;
if (zsnd->play)
return 1 ;
zsnd->playlen = zsnd->voicelen ;
for (ii = 0 , vp = zsnd->voice ; ii < zsnd->voicelen ; ii++)
if (*vp++ == DLE)
zsnd->playlen++ ;
if ((zsnd->play = (char*)malloc (zsnd->playlen)) == NULL)
return -1 ;
for (ii = 0 , vp = zsnd->voice , pp = zsnd->play ; ii < zsnd->voicelen ; ii++)
if ((*pp++ = *vp++) == DLE)
*pp++ = DLE ;
return 0 ;
}
void ZSNDfree (ZyxelSND *zsnd)
{
if (zsnd->voice)
free (zsnd->voice) ;
if (zsnd->play)
free (zsnd->play) ;
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.