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

  1. /*
  2.  *   OW2DITO © Dirk Holtwick, 1996
  3.  *
  4.  *   Converts OwnWords 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  str[2000],*s;
  55.     FILE   *f;
  56.  
  57.     if(argc==3)
  58.     {
  59.         if(DitoBase = OpenLibrary(DITO_NAME, DITO_VMIN))
  60.         {
  61.             // You have to create a database before adding or
  62.             // loading entries to the structure. Do not try to
  63.             // init the structure by yourself!
  64.  
  65.             DITO_GetUserInfo(&ui);
  66.  
  67.             if(ui.nr) printf("You are the registred user: %s, #%d\n\n",ui.name,ui.nr);
  68.             else puts("You are not registred. Please do it!\n");
  69.  
  70.             if(data = DITO_CreateDatabase())
  71.             {
  72.  
  73.                 // Open inputfile
  74.  
  75.                 if(f = fopen(argv[1],"r"))
  76.                 {
  77.                     while(!feof(f))
  78.                     {
  79.                         // Add entry to database
  80.  
  81.                         DITO_InitEntryInfo(&ei);
  82.  
  83.                         GetStr(str,  f);
  84.  
  85.                         s = str;
  86.                         while(*s && (*s!=':')) s++;
  87.  
  88.                         *s=0;
  89.                         s++;
  90.  
  91.                         ei.word  = str;
  92.                         ei.trans = s;
  93.  
  94.                         // Replace '/' with ';' => Styleguide
  95.                         while(*s)
  96.                         {
  97.                             if(*s=='/') *s=';';
  98.                             s++;
  99.                         }
  100.  
  101.                         DITO_InsertEntry(data, &ei);
  102.                     }
  103.  
  104.                     fclose(f);
  105.  
  106.                     // Save complete database
  107.                     DITO_SaveDatabase (data, argv[2], DITO_Save_All);
  108.                 }
  109.                 else puts("Couldn't open inputfile");
  110.  
  111.                 // Do not forget to dispose the DITO_Database!
  112.  
  113.                 DITO_DisposeDatabase(data);
  114.             }
  115.  
  116.             CloseLibrary(DitoBase);
  117.         }
  118.         else puts("Couldn't open actual version of dito.library.");
  119.     }
  120.     else puts("USAGE: OW2DITO [ow-file.dat] [output.voc]");
  121. }
  122. ///
  123.