home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
useful
/
dev
/
c
/
cmanual
/
devices
/
narratordevice
/
example1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-12
|
5KB
|
141 lines
/***********************************************************/
/* */
/* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
/* ------------------------------- ------------------ */
/* */
/* Book: ACM Devices Amiga C Club */
/* Chapter: Narrator Device Tulevagen 22 */
/* File: Example1.c 181 41 LIDINGO */
/* Author: Anders Bjerin SWEDEN */
/* Date: 92-04-26 */
/* Version: 1.00 */
/* */
/* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
/* */
/* Registered members may use this program freely in their */
/* own commercial/noncommercial programs/articles. */
/* */
/***********************************************************/
/* This very simple example demonstrates how to */
/* open the translator library, translate a string, */
/* and finally close the library before the program */
/* terminates. */
/* Declares the datatypes like STRPTR etc: */
#include <exec/types.h>
/* Size of the phonetic string buffer. (Remember */
/* that a phonetic string needs more space than */
/* the original string.) */
#define PHONETIC_BUFFER_SIZE 100
/* Pointer to the translator library: */
struct Library *TranslatorBase;
/* Declare our functions: */
void main();
void clean_up( STRPTR text );
void main()
{
/* If all characters could be translated and stored */
/* in the phonetic string this variable will be set */
/* to zero. On the other hand, if some words could */
/* not be translated since they did not fit in the */
/* phonetic string this variable will contain a */
/* negative value on how many characters actually */
/* were translated. */
int char_translated;
/* The original string: */
char *original_string = "Hello world";
/* The phonetic string: */
char phonetic_string[ PHONETIC_BUFFER_SIZE ];
/* Open the translator library: */
TranslatorBase = (struct Library *)
OpenLibrary( "translator.library", 0 );
/* Have we successfully opened the library? */
if( !TranslatorBase )
clean_up( "Could not open the translator library!" );
/* The translator library has now been opened, so */
/* we may now start to use the Translate() function. */
/* Translate our string into phonetics: (The Translate() */
/* functipon can sadly only translate English text, but */
/* with small modifications of the phonetic string it */
/* can be used with most languages.) */
char_translated =
Translate( original_string, strlen( original_string ),
phonetic_string, PHONETIC_BUFFER_SIZE );
/* If all characters could successfully be translated */
/* and stored in the phonetic string Translate() */
/* returns zero, else a negativa value is returned */
/* which tells us how many characters were actually */
/* translated: (Note that we put a minus sign infront */
/* of the variable to make it positive.) */
if( char_translated )
printf( "Translated only %d characters!\n", -char_translated );
else
printf( "All characters successfully translated!\n" );
/* Show the user what we got: */
printf( "Original string: %s\n", original_string );
printf( "Phonetic string: %s\n", phonetic_string );
/* Clean up and quit: */
clean_up( "The End!" );
}
/* Close and return everything that has been */
/* opened and allocated before we quit: */
void clean_up( STRPTR text )
{
/* Close the translator library: */
if( TranslatorBase )
CloseLibrary( TranslatorBase );
/* Remember that you must ALWAYS close the libraries you have */
/* opened. This is especially important when you are using the */
/* translator library since it is rather large and is loaded */
/* into memory when opened. If you forget to close this library */
/* you will waste a lot of memory which only can be recovered */
/* when the user turns off the computer. */
/* Print the last message: */
printf( "%s\n", text );
/* Quit: */
exit( 0 );
}