home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / edu / DITOdev.lha / DITOdev / Library / Examples / MakeDict.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-09  |  1.9 KB  |  93 lines

  1. /*
  2.  *   MakeDict © Dirk Holtwick, 1996
  3.  *
  4.  *   Creates DICT files from VOC files that allow
  5.  *   a faster and less memory using access to a
  6.  *   vocabulary database
  7.  */
  8.  
  9. /// INCLUDES & DEFS
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12.  
  13. #include <proto/exec.h>
  14. #include <proto/dito.h>
  15.  
  16. struct Library *DitoBase;
  17. ///
  18.  
  19. /// HandleDITOError()
  20.  
  21. // Easy routine for error handling
  22. int HandleDITOError(int error){
  23.     switch(error){
  24.         case DITO_Error_FileNotFound:
  25.             puts("File not found!");
  26.             break;
  27.         case DITO_Error_NoDitoDatabase:
  28.             puts("No DITO Database!");
  29.             break;
  30.         case DITO_Error_WrongLanguage:
  31.             puts("Wrong Language!");
  32.             break;
  33.         case DITO_Error_Memory:
  34.             puts("Not enough memory!");
  35.             break;
  36.     }
  37.     return(error);
  38. }
  39. ///
  40. /// Main()
  41.  
  42. // Main program
  43. main(int argc, char *argv[]){
  44.     struct DITO_UserInfo    ui;
  45.     struct DITO_Database    *data;
  46.  
  47.     if(argc==3)
  48.     {
  49.         if(DitoBase = OpenLibrary(DITO_NAME, DITO_VMIN))
  50.         {
  51.             // You have to create a database before adding or
  52.             // loading entries to the structure. Do not try to
  53.             // init the structure by yourself!
  54.  
  55.             DITO_GetUserInfo(&ui);
  56.  
  57.             if(ui.nr) printf("You are the registred user: %s, #%d\n\n",ui.name,ui.nr);
  58.             else puts("You are not registred. Please do it!\n");
  59.  
  60.             if(data = DITO_CreateDatabase())
  61.             {
  62.  
  63.                 // You may now add entries to the database, e.g.
  64.                 // with DITO_LoadDatabase()
  65.  
  66.                 printf("Loading '%s' ...\n",argv[1]);
  67.  
  68.                 if(!HandleDITOError(DITO_LoadDatabase(data,argv[1])))
  69.                 {
  70.  
  71.                     // Save as DITO Dictionary for faster data access and
  72.                     // less memory use
  73.  
  74.                     printf("Saving as '%s' ...\n", argv[2]);
  75.  
  76.                     DITO_SaveDatabase (data, argv[2], DITO_Save_Dict);
  77.  
  78.                     puts("Finished.");
  79.                 }
  80.  
  81.                 // Do not forget to dispose the DITO_Database!
  82.  
  83.                 DITO_DisposeDatabase(data);
  84.             }
  85.  
  86.             CloseLibrary(DitoBase);
  87.         }
  88.         else puts("Couldn't open actual version of dito.library.");
  89.     }
  90.     else puts("USAGE: MakeDict [input.voc] [output.dict]");
  91. }
  92. ///
  93.