On Tue, Apr 25, 2006 at 01:32:39AM +0200, Enrico Forestieri wrote:

> On Mon, Apr 24, 2006 at 10:42:39PM +0100, Angus Leeming wrote:
> 
> > Hmmm. All of the .ini files have dos line endings, but io_ui_language.ini 
> > has one line (line 14) that cygwin's unix2dos.exe changes. I attach the 
> > "repaired" file. I say "repaired" because not even notepad can display the 
> > "repaired" file intelligibly. That said, if unix2dos is changing the file 
> > then presumably their is something "wrong" with it.
> 
> Angus, you have nulls embedded in that line. If you load the file
> in vim you will notice them as they get displayed as "^@".
> 
> However I see that development/Win32/packaging/installer/io_ui_language.ini
> is correct and I was unable to mangle it even after several unix2dos
> and dos2unix cycles, so I think that you cannot blame cygwin for that.

I think that you used the attached or similar program for the
conversion. Please, don't do that because this one also converts
between char sets and it is not what you want.

Instead, install the cygwin cygutils package. It contains both
unix2dos.exe and dos2unix.exe doing the right thing.

-- 
Enrico
/*
 *  A utility to convert text files from/to MSDOS
 *
 *  If named dos2iso will convert from MSDOS char set to iso8859-1 char set
 *  If named iso2dos will convert from iso8859-1 char set to MSDOS char set
 *
 *  $Revision: 1.2 $
 *
 *  $Log: dos2iso.c,v $
 * Revision 1.2  2004/03/16  23:59:19  enrico
 * If output filename missing, convert in place.
 *
 * Revision 1.1  1996/11/03  22:29:19  enrico
 * Now converts between MSDOS and ISO Latin 1 char sets.
 *
 * Revision 1.0  1996/11/03  19:14:46  enrico
 * Initial revision
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

unsigned char dos2iso[] =
{   0,  1,  2,  3,  4,  5,  6,  7,  8,  9,    /*   0 */
   10, 11, 12, 13, 14, 15, 16, 17, 18, 19,    /*  10 */
   20,167, 22, 23, 24, 25, 26, 27, 28, 29,    /*  20 */
   30, 31, 32, 33, 34, 35, 36, 37, 38, 39,    /*  30 */
   40, 41, 42, 43, 44, 45, 46, 47, 48, 49,    /*  40 */
   50, 51, 52, 53, 54, 55, 56, 57, 58, 59,    /*  50 */
   60, 61, 62, 63, 64, 65, 66, 67, 68, 69,    /*  60 */
   70, 71, 72, 73, 74, 75, 76, 77, 78, 79,    /*  70 */
   80, 81, 82, 83, 84, 85, 86, 87, 88, 89,    /*  80 */
   90, 91, 92, 93, 94, 95, 96, 97, 98, 99,    /*  90 */
  100,101,102,103,104,105,106,107,108,109,    /* 100 */
  110,111,112,113,114,115,116,117,118,119,    /* 110 */
  120,121,122,123,124,125,126,127,199,252,    /* 120 */
  233,226,228,224,229,231,234,235,232,239,    /* 130 */
  238,236,196,197,200,230,198,244,246,242,    /* 140 */
  251,249,255,214,220,162,163,165,223,102,    /* 150 */
  225,237,243,218,241,209,170,186,191,225,    /* 160 */
  172,189,188,161,171,187, 35, 35, 35,124,    /* 170 */
   43, 43, 43, 43, 43, 43,124, 43, 43, 43,    /* 180 */
   43, 43, 43, 43, 43, 43,196, 43, 43, 43,    /* 190 */
   43, 43, 43, 43, 43,173, 43, 43, 43, 43,    /* 200 */
   43, 43, 43, 43,214, 43, 43, 43, 43, 35,    /* 210 */
  220, 35, 35,223, 97,223, 71,182,228,115,    /* 220 */
  181,116, 70,216, 79,240, 56,248,101,110,    /* 230 */
   61,177, 62, 60, 83,228,246, 61,176,183,    /* 240 */
  183, 86,252,178, 35, 32                     /* 250 */
};

unsigned char iso2dos[] =
{   0,  1,  2,  3,  4,  5,  6,  7,  8,  9,    /*   0 */
   10, 11, 12, 13, 14, 15, 16, 17, 18, 19,    /*  10 */
   20, 21, 22, 23, 24, 25, 26, 27, 28, 29,    /*  20 */
   30, 31, 32, 33, 34, 35, 36, 37, 38, 39,    /*  30 */
   40, 41, 42, 43, 44, 45, 46, 47, 48, 49,    /*  40 */
   50, 51, 52, 53, 54, 55, 56, 57, 58, 59,    /*  50 */
   60, 61, 62, 63, 64, 65, 66, 67, 68, 69,    /*  60 */
   70, 71, 72, 73, 74, 75, 76, 77, 78, 79,    /*  70 */
   80, 81, 82, 83, 84, 85, 86, 87, 88, 89,    /*  80 */
   90, 91, 92, 93, 94, 95, 96, 97, 98, 99,    /*  90 */
  100,101,102,103,104,105,106,107,108,109,    /* 100 */
  110,111,112,113,114,115,116,117,118,119,    /* 110 */
  120,121,122,123,124,125,126,127,128,129,    /* 120 */
  130,131,132,133,134,135,136,137,138,139,    /* 130 */
  140,141,142,143,144,145,146,147,148,149,    /* 140 */
  150,151,152,153,154,155,156,157,158,159,    /* 150 */
  160,173,155,156,248,157,124, 21, 34, 99,    /* 160 */
  166,174,170, 45, 82,126,248,241,253, 51,    /* 170 */
   96,230,227,249, 44, 49,167,175,172,171,    /* 180 */
  190,168, 65, 65, 65, 65,142,143,146,128,    /* 190 */
  144,144,144, 73, 73, 73, 73, 73, 68,165,    /* 200 */
   79, 79, 79, 79,153,120,233,163,163,150,    /* 210 */
  154, 89, 98,225,133,160,131,160,132,134,    /* 220 */
  145,135,138,130,136,137,141,161,140,139,    /* 230 */
  235,164,149,162,149,149,148,246,237,151,    /* 240 */
  163,150,129,121, 98,152                     /* 250 */
};


#define MAXLEN 256

FILE *infile;
FILE *outfile;
#ifndef WIN32
char *progname;
#else
char progname[MAXLEN] = { 0 };
#endif
char buf[MAXLEN] = { 0 };

void Fputc(int, FILE *);
void Fputs(char *, FILE *);
void toDOS(void);
void toUnix(void);

int main(int ac, char *av[])
{
    char *s, *outname;
#ifdef WIN32
    for (s = av[0]+strlen(av[0]); s >= av[0] && *s != '\\' && *s != ':'; --s);

    strncpy(progname, ++s, MAXLEN-1);
    if ((s = strstr(progname, ".exe")) != NULL) {
       *s = 0;
    }
#else
    for (s = av[0]+strlen(av[0]); s >= av[0] && *s != '/' && *s != ':'; --s);

    ++s;
    progname = s;
#endif

    if (ac == 2) {
       strncpy(buf, av[1], MAXLEN-5);
       strcat(buf, ".tmp");
       outname = buf;
    } else if (ac == 3) {
       outname = av[2];
    } else {
       fprintf(stderr, "Usage: %s infile [outfile]\n", progname);
       exit(EXIT_FAILURE);
    }

    if (NULL == (infile = fopen(av[1], "rb"))) {
       fprintf(stderr, "%s: can't open input file %s\n", progname, av[1]);
       return EXIT_FAILURE;
    }

    if (NULL == (outfile = fopen(outname, "wb"))) {
       fprintf(stderr, "%s: can't open output file %s\n", progname, outname);
       return EXIT_FAILURE;
    }

    if (strcmp(progname, "dos2iso") == 0)
       toUnix();
    else
       toDOS();

    fclose(infile);
    fclose(outfile);

    if (ac == 2) {
       if (remove(av[1]) != 0) {
          sprintf(buf, "%s: Cannot remove `%s'", progname, av[1]);
          perror(buf);
          return EXIT_FAILURE;
       }
       if (rename(outname, av[1]) != 0) {
          sprintf(buf, "%s: Cannot rename `%s'", progname, av[1]);
          perror(buf);
          return EXIT_FAILURE;
       }
    }

    return EXIT_SUCCESS;
}

void Fputc(int ch, FILE *outfile)
{
    if (EOF == fputc(ch, outfile)) {
        perror(progname);
        exit(EXIT_FAILURE);
    }
}

void Fputs(char *str, FILE *outfile)
{
    if (EOF == fputs(str, outfile)) {
        perror(progname);
        exit(EXIT_FAILURE);
    }
}

void toDOS(void)
{
    int ch, lastch = 0;

    while (EOF != (ch = fgetc(infile))) {
       if ('\n' == ch && '\r' != lastch)
           Fputc('\r', outfile);
       lastch = ch;
       Fputc(iso2dos[ch], outfile);
    }
    if ('\n' != lastch)
       Fputs("\r\n", outfile);
}

void toUnix(void)
{
    int ch, lastch = 0;

    while (EOF != (ch = fgetc(infile)) && '\x1a' != ch) {
       if ('\r' != ch) {
           lastch = ch;
           Fputc(dos2iso[ch], outfile);
       }
    }
    if ('\n' != lastch)
       Fputc('\n', outfile);
}

Reply via email to