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

  1. /*
  2.  *   LSD2DITO © Dirk Holtwick, 1996
  3.  *
  4.  *   Converts LSD files to DITO databases
  5.  */
  6.  
  7. /// INCLUDES & DEFS
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.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.     switch(error){
  23.         case DITO_Error_FileNotFound:
  24.             puts("File not found!");
  25.             break;
  26.         case DITO_Error_NoDitoDatabase:
  27.             puts("No DITO Database!");
  28.             break;
  29.         case DITO_Error_WrongLanguage:
  30.             puts("Wrong Language!");
  31.             break;
  32.         case DITO_Error_Memory:
  33.             puts("Not enough memory!");
  34.             break;
  35.     }
  36.     return(error);
  37. }
  38. ///
  39. /// GetStr
  40. char *GetStr(char *str, FILE *f)
  41. {
  42.     fgets(str, 255, f);
  43.     str[strlen(str)-1] = 0;
  44.     return(str);
  45. }
  46. ///
  47.  
  48. /// Main()
  49. // Main program
  50. main(int argc, char *argv[]){
  51.     struct DITO_UserInfo    ui;
  52.     struct DITO_Database    *data;
  53.     struct DITO_EntryInfo   ei;
  54.     static char   word[256], str[256], trans[2000];
  55.     FILE   *f;
  56.     int    i;
  57.  
  58.     if(argc==3)
  59.     {
  60.         if(DitoBase = OpenLibrary(DITO_NAME, DITO_VMIN))
  61.         {
  62.             // You have to create a database before adding or
  63.             // loading entries to the structure. Do not try to
  64.             // init the structure by yourself!
  65.  
  66.             DITO_GetUserInfo(&ui);
  67.  
  68.             if(ui.nr) printf("You are the registred user: %s, #%d\n\n",ui.name,ui.nr);
  69.             else puts("You are not registred. Please do it!\n");
  70.  
  71.             if(data = DITO_CreateDatabase())
  72.             {
  73.  
  74.                 // Open inputfile
  75.  
  76.                 if(f = fopen(argv[1],"r"))
  77.                 {
  78.                     // First 6 Lines are not of  interest
  79.                     for(i=0;i<6;i++) GetStr(str,f);
  80.  
  81.                     while(!feof(f))
  82.                     {
  83.                         // Add entry to database
  84.  
  85.                         DITO_InitEntryInfo(&ei);
  86.  
  87.                         ei.word  = GetStr(word,  f);
  88.  
  89.                         trans[0] = 0;
  90.                         str[0] = 0;
  91.  
  92.                         do
  93.                         {
  94.                             if(trans[0]) strcat(trans, " ");
  95.                             strcat (trans, str);
  96.                             GetStr(str,f);
  97.                         }
  98.                         while(!feof(f) && (str[0] != '&'));
  99.  
  100.                         ei.trans = trans;
  101.  
  102.                         DITO_InsertEntry(data, &ei);
  103.                     }
  104.  
  105.                     fclose(f);
  106.  
  107.                     // Save complete database
  108.                     DITO_SaveDatabase (data, argv[2], DITO_Save_All);
  109.                 }
  110.                 else puts("Couldn't open inputfile");
  111.  
  112.                 // Do not forget to dispose the DITO_Database!
  113.  
  114.                 DITO_DisposeDatabase(data);
  115.             }
  116.  
  117.             CloseLibrary(DitoBase);
  118.         }
  119.         else puts("Couldn't open actual version of dito.library.");
  120.     }
  121.     else puts("USAGE: LSD2DITO [lsd-file.dat] [output.voc]");
  122. }
  123. ///
  124.