home *** CD-ROM | disk | FTP | other *** search
- /*
- * Teach © Dirk Holtwick, 1996
- *
- * Small teaching tool to demonstrates, how
- * it works.
- *
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
-
- #include <proto/exec.h>
- #include <proto/dito.h>
-
- #define SUMKNOWN(data) (data->KnownWeight[0]+data->KnownWeight[1]+data->KnownWeight[2])
- #define SUMASKED(data) (data->AskedWeight[0]+data->AskedWeight[1]+data->AskedWeight[2])
-
- struct Library *DitoBase;
-
- struct DITO_Database *data;
- struct DITO_Entry *entry;
-
- /*
- ** Easy routine for error handling
- */
-
- void HandleDITOError(int error)
- {
- switch(error)
- {
- case DITO_Error_FileNotFound:
- puts("File not found!");
- break;
- case DITO_Error_NoDitoDatabase:
- puts("No DITO Database!");
- break;
- case DITO_Error_WrongLanguage:
- puts("Wrong Language!");
- break;
- case DITO_Error_Memory:
- puts("Not enough memory!");
- break;
- }
- }
-
- /*
- ** Teach(), return quote of answers
- */
-
- LONG Teach(void){
- struct DITO_Entry *entry;
- char answ[2];
-
- /*
- ** Lets start from the beginning, but this is not
- ** obligatory.
- */
-
- DITO_TeachInit(data);
-
- /*
- ** The "question loop"
- */
-
- do
- {
- /*
- ** Get pointer to question
- */
-
- entry = DITO_TeachRandom(data, 0);
-
- /*
- ** Ask.
- */
-
- printf("\fKNOWN WORDS: %d%\n\n", (SUMKNOWN(data) * 100 / data->sum));
-
- printf("What means '%s'? Say it loud!\n", DITO_GetStr(entry, DITO_Str_Word));
-
- gets(answ);
-
- /*
- ** Show answer
- */
-
- printf("It means '%s'. Did you know that (y/n)? ", DITO_GetStr(entry, DITO_Str_Translation));
-
- gets(answ);
-
- /*
- ** Set Known-Flag and get information, if we reached the end.
- */
- }
- while(!DITO_TeachKnown(data, (tolower(answ[0]) == 'y')));
-
- /*
- ** Calculate quote.
- */
-
- return(SUMKNOWN(data) * 100 / SUMASKED(data));
- }
-
-
- /*
- ** Main program
- */
-
-
- main(int argc, char *argv[])
- {
-
- if(argc==2)
- {
- if(DitoBase = OpenLibrary(DITO_NAME, DITO_VMIN))
- {
-
- /*
- ** You have to create a database before adding or
- ** loading entries to the structure. Do not try to
- ** init the structure by yourself!
- */
-
- if(data = DITO_CreateDatabase())
- {
-
- /*
- ** You may now add entries to the database, e.g.
- ** with DITO_LoadDatabase()
- */
-
- HandleDITOError(DITO_LoadDatabase(data,argv[1]));
-
- /*
- ** Jump to Teach();
- */
-
- printf("\fYou have reached a quote of %d%.\n", Teach());
-
- /*
- ** Do not forget to dispose the DITO_Database!
- */
-
- DITO_DisposeDatabase(data);
- }
-
- CloseLibrary(DitoBase);
-
- }else puts("Couldn't open actual version of dito.library.");
-
- }else puts("USAGE: Teach [file.voc]");
- }
-
-