AI-MegaHAL
view release on metacpan or search on metacpan
libmegahal.c view on Meta::CPAN
*/
void listvoices(void)
{
#ifdef __mac_os
VoiceSpec voiceSpec;
VoiceDescription info;
short count, voiceCount;
unsigned char* temp;
OSErr err;
if(gSpeechExists) {
err = CountVoices(&voiceCount);
if (!err && voiceCount) {
for (count = 1; count <= voiceCount; count++) {
err = GetIndVoice(count, &voiceSpec);
if (err) continue;
err = GetVoiceDescription(&voiceSpec, &info,
sizeof(VoiceDescription));
if (err) continue;
p2cstr(info.name);
for (temp= info.name; *temp; temp++)
if (*temp == ' ')
*temp = '_';
printf("%s\n",info.name);
}
}
}
#endif
}
/*---------------------------------------------------------------------------*/
/*
* Function: Speak
*/
void speak(char *output)
{
if(speech==FALSE) return;
#ifdef __mac_os
if(gSpeechExists) {
OSErr err;
if (gSpeechChannel)
err = SpeakText(gSpeechChannel, output, strlen(output));
else {
c2pstr(output);
SpeakString((StringPtr)output);
p2cstr((StringPtr)output);
}
}
#endif
}
/*---------------------------------------------------------------------------*/
/*
* Function: Progress
*
* Purpose: Display a progress indicator as a percentage.
*/
bool progress(char *message, int done, int total)
{
static int last=0;
static bool first=FALSE;
/*
* We have already hit 100%, and a newline has been printed, so nothing
* needs to be done.
*/
if((done*100/total==100)&&(first==FALSE)) return(TRUE);
/*
* Nothing has changed since the last time this function was called,
* so do nothing, unless it's the first time!
*/
if(done*100/total==last) {
if((done==0)&&(first==FALSE)) {
// fprintf(stderr, "%s: %3d%%", message, done*100/total);
first=TRUE;
}
return(TRUE);
}
/*
* Erase what we printed last time, and print the new percentage.
*/
last=done*100/total;
//if(done>0) fprintf(stderr, "%c%c%c%c", 8, 8, 8, 8);
//fprintf(stderr, "%3d%%", done*100/total);
/*
* We have hit 100%, so reset static variables and print a newline.
*/
if(last==100) {
first=FALSE;
last=0;
//fprintf(stderr, "\n");
}
return(TRUE);
}
/*---------------------------------------------------------------------------*/
void help(void)
{
int j;
for(j=0; j<COMMAND_SIZE; ++j) {
printf("#%-7s: %s\n", command[j].word.word, command[j].helpstring);
}
}
/*---------------------------------------------------------------------------*/
void load_personality(MODEL **model)
{
FILE *file;
static char *filename=NULL;
if(filename==NULL) filename=(char *)malloc(sizeof(char)*1);
/*
* Allocate memory for the filename
*/
filename=(char *)realloc(filename,
sizeof(char)*(strlen(directory)+strlen(SEP)+12));
if(filename==NULL) error("load_personality","Unable to allocate filename");
/*
* Check to see if the brain exists
*/
if(strcmp(directory, DEFAULT)!=0) {
sprintf(filename, "%s%smegahal.brn", directory, SEP);
file=fopen(filename, "r");
if(file==NULL) {
sprintf(filename, "%s%smegahal.trn", directory, SEP);
file=fopen(filename, "r");
if(file==NULL) {
fprintf(stdout, "Unable to change MegaHAL personality to \"%s\".\n"
"Reverting to MegaHAL personality \"%s\".\n", directory, last);
free(directory);
directory=strdup(last);
( run in 1.057 second using v1.01-cache-2.11-cpan-98e64b0badf )