At 7:54 pm +0200 30/9/02, Adriano Allora wrote:

>On the one hand I didn't express myself very well, but for the other
>hand I found other aspects of the problem.
>
>Actual situation: I work with mac osx.2, vi editor, a pack of dos
>files to work on.
>When I open my files with vi I see some strings instead of stressed
>letters and signs.
>For instance:
>carriage return = ^M
>u grave = \xf9
>e grave = \xe8
>a grave = \xe0
>o grave = \xf2
>euro sign = \x80
>i grave = \xec
>BUT, if I write the same letters and signs on the editor, they appears as:
>carriage return =
>a grave = \xc3\xa0
>e grave = \xc3\xa8
>e acute = \xc3\xa9
>u grave = \xc3\xb9
>i grave = \xc3\xac
>o grave = \xc3\xb2
>euro: \xe2\x82\xac
>
>so, I don't know I can face the problem: to create an array of
>strings to substitute is a non-sense, because of I haven't got two
>lists in one-to-one correspondence... er, I suppose (I'm not sure).


I can't imagine using vi to do this sort of thing -- or anything
else, for that matter.  All you need to do is run the file through a
converter such as this, which converts from Latin-1 to Mac.  The Euro
sign does not exist in Latin-1, so you will have to discover which
charset (eg. windows-1252, iso-8859-15) is used in the original files
and change the table accordingly.  You can add your line-endings
conversion to the table as well.

Here I have used a string for the example.  You would normally take
input from a file and output to another file


#!/usr/bin/perl
#####
@_ = split /$\//, "�����
�����" ; #  =  "\xf9\xe8\xe0\xf2\x80$/\xf9\xe8\xe0\xf2\x80"
table();
for (@_) {
   s~([\x80-\xFF])~$latin2mac{$1}~g;
   print "$_$/";
}
## --> Mac output:
##   �����
##   �����
###########
sub table {%latin2mac = (
"\xFC" => "\x9F", "\xFB" => "\x9E", "\xFA" => "\x9C", "\xF9" => "\x9D",
"\xE8" => "\x8F", "\xCB" => "\xE8", "\xC0" => "\xCB", "\xBF" => "\xC0",
"\xF8" => "\xBF", "\xF6" => "\x9A", "\xF5" => "\x9B", "\xF4" => "\x99",
"\xF3" => "\x97", "\xF2" => "\x98", "\xF1" => "\x96", "\xEF" => "\x95",
"\xEE" => "\x94", "\xED" => "\x92", "\xEC" => "\x93", "\xEB" => "\x91",
"\xEA" => "\x90", "\xE9" => "\x8E", "\xE7" => "\x8D", "\xE6" => "\xBE",
"\xE5" => "\x8C", "\xE4" => "\x8A", "\xE3" => "\x8B", "\xE2" => "\x89",
"\xE1" => "\x87", "\xE0" => "\x88", "\xA7" => "\xA4", "\xDF" => "\xA7",
"\xDC" => "\x86", "\xDB" => "\xF3", "\xDA" => "\xF2", "\xD9" => "\xF4",
"\xAF" => "\xF8", "\xD8" => "\xAF", "\xFF" => "\xD8", "\xD6" => "\x85",
"\xF7" => "\xD6", "\xD4" => "\xEF", "\xD3" => "\xEE", "\xD2" => "\xF1",
"\xD1" => "\x84", "\xCF" => "\xEC", "\xCE" => "\xEB", "\xCD" => "\xEA",
"\xD5" => "\xCD", "\xCC" => "\xED", "\xCA" => "\xE6", "\xC9" => "\x83",
"\xC8" => "\xE9", "\xC7" => "\x82", "\xC2" => "\xE5", "\xAC" => "\xC2",
"\xA8" => "\xAC", "\xAE" => "\xA8", "\xC6" => "\xAE", "\xC5" => "\x81",
"\xC4" => "\x80", "\xC3" => "\xCC", "\xC1" => "\xE7", "\xAB" => "\xC7",
"\xBA" => "\xBC", "\xB8" => "\xFC", "\xB7" => "\xFA", "\xB6" => "\xA6",
"\xB4" => "\xAB", "\xA1" => "\xC1", "\xB0" => "\xA1", "\xBB" => "\xC8",
"\xAA" => "\xBB", "\xA5" => "\xB4", "\xA0" => "\xCA");}



Reply via email to