home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / edu / DITOdev.lha / DITOdev / Library / Examples / FindDict.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-23  |  2.2 KB  |  117 lines

  1. /*
  2.  *   ShellDict © Dirk Holtwick, 1996
  3.  *
  4.  *   Small example to demonstrate how to write a program
  5.  *   wich uses the DICT files.
  6.  */
  7.  
  8. /// INCLUDE & DEFS
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12. #include <proto/exec.h>
  13. #include <proto/dito.h>
  14.  
  15. struct Library *DitoBase;
  16. ///
  17.  
  18. /// HandleDITOError()
  19.  
  20. // Easy routine for error handling
  21. int HandleDITOError(int error)
  22. {
  23.     switch(error)
  24.     {
  25.         case DITO_Error_FileNotFound:
  26.             puts("File not found!");
  27.             break;
  28.         case DITO_Error_NoDitoDatabase:
  29.             puts("No DITO Database!");
  30.             break;
  31.         case DITO_Error_WrongLanguage:
  32.             puts("Wrong Language!");
  33.             break;
  34.         case DITO_Error_Memory:
  35.             puts("Not enough memory!");
  36.             break;
  37.     }
  38.     return(error);
  39. }
  40. ///
  41. /// Main()
  42.  
  43. // Main program
  44. main(int argc, char *argv[])
  45. {
  46.     struct DITO_UserInfo    ui;
  47.     struct DITO_Dict        *dt;
  48.     struct DITO_Database    *data;
  49.     struct DITO_Entry       *entry;
  50.     ULONG  n;
  51.  
  52.     if(argc==3)
  53.     {
  54.         if(DitoBase = OpenLibrary(DITO_NAME, DITO_VMIN))
  55.         {
  56.  
  57.             // You have to create a database before adding or
  58.             // loading entries to the structure. Do not try to
  59.             // init the structure by yourself!
  60.  
  61.             DITO_GetUserInfo(&ui);
  62.  
  63.             if(ui.nr) printf("You are the registred user: %s, #%d\n\n",ui.name,ui.nr);
  64.             else puts("You are not registred. Please do it!\n");
  65.  
  66.             if(data = DITO_CreateDatabase())
  67.             {
  68.                 // You may now add entries to the database, e.g.
  69.                 // with DITO_LoadDatabase()
  70.  
  71.                 printf("Loading Dictionary ...\n");
  72.  
  73.                 if(dt = DITO_OpenDict (argv[1]))
  74.                 {
  75.                     // Delete all entries
  76.  
  77.                     DITO_InitDatabase(data);
  78.  
  79.                     // Load entries that fit the pattern
  80.  
  81.                     DITO_LoadDictData(data, dt, argv[2], 1);
  82.  
  83.                     // Show all found entries
  84.  
  85.                     printf("\n");
  86.  
  87.                     for (n=0; n<data->sum; n++)
  88.                     {
  89.                         entry = DITO_GetPtr(data, n);
  90.  
  91.                         printf(
  92.                             "%3d. \033[1m%s,\033[0m %s\n",
  93.                             n + 1,
  94.                             DITO_GetStr (entry, DITO_Str_Word),
  95.                             DITO_GetStr (entry, DITO_Str_Translation)
  96.                         );
  97.                     }
  98.  
  99.                     // Don't forget to close the DICT
  100.  
  101.                     DITO_CloseDict(dt);
  102.  
  103.                 }
  104.  
  105.                 // Do not forget to dispose the DITO_Database!
  106.  
  107.                 DITO_DisposeDatabase(data);
  108.             }
  109.  
  110.             CloseLibrary(DitoBase);
  111.         }
  112.         else puts("Couldn't open actual version of dito.library.");
  113.     }
  114.     else puts("USAGE: FindDict [file.dict] [pattern]");
  115. }
  116. ///
  117.