home *** CD-ROM | disk | FTP | other *** search
- /*
- * OW2DITO © Dirk Holtwick, 1996
- *
- * Converts OwnWords files to DITO databases
- */
-
- /// INCLUDES & DEFS
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #include <proto/exec.h>
- #include <proto/dito.h>
-
- struct Library *DitoBase;
- ///
-
- /// HandleDITOError()
-
- // Easy routine for error handling
- int 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;
- }
- return(error);
- }
- ///
- /// GetStr
- char *GetStr(char *str, FILE *f)
- {
- fgets(str, 255, f);
- str[strlen(str)-1] = 0;
- return(str);
- }
- ///
-
- /// Main()
- // Main program
- main(int argc, char *argv[]){
- struct DITO_UserInfo ui;
- struct DITO_Database *data;
- struct DITO_EntryInfo ei;
- static char str[2000],*s;
- FILE *f;
-
- if(argc==3)
- {
- 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!
-
- DITO_GetUserInfo(&ui);
-
- if(ui.nr) printf("You are the registred user: %s, #%d\n\n",ui.name,ui.nr);
- else puts("You are not registred. Please do it!\n");
-
- if(data = DITO_CreateDatabase())
- {
-
- // Open inputfile
-
- if(f = fopen(argv[1],"r"))
- {
- while(!feof(f))
- {
- // Add entry to database
-
- DITO_InitEntryInfo(&ei);
-
- GetStr(str, f);
-
- s = str;
- while(*s && (*s!=':')) s++;
-
- *s=0;
- s++;
-
- ei.word = str;
- ei.trans = s;
-
- // Replace '/' with ';' => Styleguide
- while(*s)
- {
- if(*s=='/') *s=';';
- s++;
- }
-
- DITO_InsertEntry(data, &ei);
- }
-
- fclose(f);
-
- // Save complete database
- DITO_SaveDatabase (data, argv[2], DITO_Save_All);
- }
- else puts("Couldn't open inputfile");
-
- // 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: OW2DITO [ow-file.dat] [output.voc]");
- }
- ///
-