extract.c

Fredrik Ekman d91fe at pt.hk-r.se
Thu Jun 3 16:11:25 CEST 1993


And here's the extract utility. I don't know if anyone has any real
use for it, but I just couldn't stop myself. :-)

I have successfully compiled it on a DOS machine with the Borland C++
3.0 compiler, but it should work with any ANSI C compiler. If you get
any problems, I should be able to supply you with a uuencoded
executable for either MS-DOS or SUN SPARCstations. Alternatively, if
you want only one or two extractions, I could simply send you the
extractions instead.

The program is very simple to use. As arguments, you use the language
codes from the International Disney Comic Names list. So if you, for
example want a translation of names from English to Swedish (the two
most complete languages, for obvious reasons) you type

extract en sv

The program in its current form requires that the International Names
list (any version 2.x) is in the current directory and has file name
"names". I have deliberately kept both file names short in order not
to cause problems for MS-DOS users (like myself). If you prefer to
have any other name on the file (I think Per uses "interlingual" in
the FTP archive) just change line three of the source.

Enjoy!

  /Fredrik Ekman


              ___________________________
       ______|                           |______
       \     |   In Donaldismo Veritas   |     /
        >    |___________________________|    <
       /______\|                       |/______\
                  

--------------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#define FILENAME "names"

		  /**************************
		   * Program: extract       *
		   * Version: 1.0           *
		   * Date   : 5/5 1993      *
		   * Source : extract.c     *
		   * Author : Fredrik Ekman *
		   **************************/

  /* This is a utility to extract two-language translations from the
     International Disney Comic Character Names list. This list is
     available from the author of this program or through anonymous
     FTP from ftp.lysator.liu.se under the file name
     /pub/comics/disney/characters/interlingual. To use the program,
     the file in question must be present in the current directory.
     The filename must be the same as that which is defined in line
     three of this source. If you should want to use any other name,
     just change line three to whatever you want. This program is in
     the public domain, so if you feel that anything is required
     except what is already featured; just add it. The only thing I
     ask for if you change it is a copy of the updated code. Please
     report any bugs.

     Fredrik Ekman      email: d91fe at ide.ide.hk-r.se                 */

char *readline(FILE *fp, char *ch);
char *before_colon(char *strn);
char *extract_name(char *strn);

void main(int argc, char *argv[])
{
    char ch='\0';
    char language1[80];
    char language2[80];
    char strn[80];
    FILE *fp;

    *language1 = *language2 = '\0';
    puts("Translation of Disney Comic Character Names");
    if(fp=fopen(FILENAME, "r"))
	if(argc == 3)
	{
	    while(ch != EOF && (*language1 == '\0' || *language2 == '\0'))
	    {
		strcpy(strn, readline(fp, &ch));
		if(strcmp(before_colon(strn), argv[1]) == 0)
		    strcpy(language1, extract_name(strn));
		if(strcmp(before_colon(strn), argv[2]) == 0)
		    strcpy(language2, extract_name(strn));
	    }
	    if(*language1 && *language2)
	    {
		while(strcmp(readline(fp, &ch), "") != 0);
		printf("%s to %s\n\n", language1, language2);
		*language1 = *language2 = '\0';
		while(ch != EOF)
		{
		    strcpy(strn, readline(fp, &ch));
		    if(strcmp(before_colon(strn), argv[1]) == 0)
			strcpy(language1, extract_name(strn));
		    if(strcmp(before_colon(strn), argv[2]) == 0)
			strcpy(language2, extract_name(strn));
		    if(strcmp(strn, "") == 0)
			*language1 = *language2 = '\0';
		    if(*language1 && *language2)
		    {
			printf("%s = %s\n", language1, language2);
			while(strcmp(readline(fp, &ch), "") != 0);
			*language1 = *language2 = '\0';
		    }
		}
	    }
	    else
		fputs("Error: Language code does not exist in file", stderr);
	    fclose(fp);
	}
	else
	{
	    puts("Extract utility ver 1.0 by Fredrik Ekman\n");
	    puts("Useage: extract {code 1} {code 2}");
	    printf("Where code x is a language code from the file %s", FILENAME);
	}
    else
	fprintf(stderr, "Error: The file %s is not in the current directory\n", FILENAME);
}

/* Function to return a line from file */

char *readline(FILE *fp, char *ch)
{
    char strn[80];
    int  i;

    for(i=0; (strn[i]=getc(fp)) != EOF && strn[i] != '\n'; i++);
    *ch = strn[i];
    strn[i] = '\0';
    return strn;
}

/* Function to return the characters before the colon in a string */

char *before_colon(char *strn)
{
    char output[80];
    int  colon=0;
    int  i;

    for(i=0; strn[i] != '\0' && strn[i] != ':'; i++)
	output[i] = strn[i];
    if(strn[i] == ':')
	colon = 1;
    output[i] = '\0';
    return colon ? output : NULL;
}

/* Function to extract name from a string */

char *extract_name(char *strn)
{
    int  i, j;
    char name[80];

    j = strlen(before_colon(strn))+1;
    for(i=0; (name[i]=strn[j]) != '\0' && strn[j] != '[' && strn[j] != '|'; i++, j++);
    if(name[i] != '\0')
	for(; name[i] == ' ' || name[i] == '[' || name[i] == '|'; i--)
	    name[i] = '\0';
    return name;
}



More information about the DCML mailing list