#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "tree.h"
#include "transl.h"
void TSW(void);
char* GetSouceWord(FILE* sourceFile);
/////////////////////////////////////////////////////////////////////////////////////////////
char* sourceName = NULL;
char* destinName = NULL;
char* filterName = NULL;
char* translName = NULL;
FILE* sourceFile = stdin;
FILE* destinFile = stdout;
FILE* filterFile = NULL;
FILE* translFile = NULL;
/////////////////////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
// Schritt 0: Startparameter bearbeiten
if (argc > 5)
{ // (Eckige Klammner mag der Wiki hier nicht)
fprintf(stderr, "Utility to generate a table of translations for an ASCII text\n");
fprintf(stderr, "Usage : %s (<sourceName> (<destinationName> (<filterName> (<translateName>)))))\n", argv[0]);
fprintf(stderr, "Parameter: <sourceName> : file with the ASCII-text\n");
fprintf(stderr, " If no filename is given, 'stdin'\n");
fprintf(stderr, " will be read\n");
fprintf(stderr, " <destinationName>: Name of the table of translations.\n");
fprintf(stderr, " Is no name given, the table will\n");
fprintf(stderr, " written to 'stdout'\n");
fprintf(stderr, " <filterName>: Name of a list of words not to be translated.\n");
fprintf(stderr, " Is no name given, all words are translated\n");
fprintf(stderr, " <translateName>: Name of a list of translations (e d d d).\n");
fprintf(stderr, " Is no name given, nothing is translated\n");
exit(1);
}
if (argc != 1) sourceName = argv[1];
if (argc > 2) destinName = argv[2];
if (argc > 3) filterName = argv[3];
if (argc > 4) translName = argv[4];
if (sourceName != NULL) sourceFile = fopen(sourceName, "r");
if (destinName != NULL) destinFile = fopen(destinName, "w");
if (filterName != NULL) filterFile = fopen(filterName, "r");
if (translName != NULL) translFile = fopen(translName, "r");
if (sourceFile == 0)
{
fprintf(stderr, "%s: Can't open %s to read => error %d\n", argv[0], sourceName, errno);
exit(1);
}
if (destinFile == 0)
{
fprintf(stderr, "%s: Can't open %s to write => error %d\n", argv[0], destinName, errno);
exit(1);
}
if ( (filterName != NULL) && (filterFile == 0) )
{
fprintf(stderr, "%s: Can't open %s to filter => error %d\n", argv[0], filterName, errno);
exit(1);
}
if ( (translName != NULL) && (translFile == 0) )
{
fprintf(stderr, "%s: Can't open %s to translate => error %d\n", argv[0], translName, errno);
exit(1);
}
TSW(); /////// main funtion
if (sourceName != NULL) fclose(sourceFile);
if (destinName != NULL) fclose(destinFile);
if (filterName != NULL) fclose(filterFile);
if (translName != NULL) fclose(translFile);
exit (0);
}
/////////////////////////////////////////////////////////////////////////////////////////////
void TSW(void)
{
char* Word;
long Count, Left;
//---------- IN ------------------
// Schritt 1: Worte aus Quelltext herausfiltern
// Schritt 2: Wortliste alphabetisch sortieren
// Schritt 3: Doppelte Worte entfernen
Count = 0;
do
{
Word = GetSouceWord(sourceFile);
if(Word) { PutTreeWord(Word); Count++; }
}
while ( Word );
Left = Elements(),
printf("%i of %i Words were different.\n" ,Left ,Count );
//---------- FILTER --------------
// Schritt 4: Die "leichten" Worte entfernen
Count = 0;
do
{
if(filterFile) Word = GetSouceWord(filterFile);
if(Word) { DelTreeWord(Word); Count++; }
}
while ( Word );
printf("%i left after %i of %i knowen Words were found.\n" ,Elements(), Left-Elements() ,Count );
Left = Elements(),
//---------- OUT -----------------
// Schritt 5: Übersetzung zu den "schwierigen" Worten suchen
// Schritt 6: Wortpaare im Druckformat ausgeben
InitTranslate(translFile);
do
{
Word = GetTreeWord();
if(Word)
{
fputs(Word, destinFile);
fputs(" = ", destinFile);
fputs(Translate(Word), destinFile);
}
}
while ( Word );
printf("%i Words were translated, %i not.\n" ,Translated(), Left-Translated() );
} |