[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

A question about Charsets

Eric-Roger Bruecklmeier

11/20/2003 3:56:00 PM

Hello Rubyists,

in a new application i have to read dBase III Files which were generated
in a DOS enviroment. How can i convert the Data into Windows codepages
from ruby?

Thanks for any hints.

Eric.

6 Answers

Josef 'Jupp' Schugt

11/21/2003 1:06:00 AM

0

Hi!

* Eric-Roger Bruecklmeier; 2003-11-20, 20:30 UTC:
> in a new application i have to read dBase III Files which were generated
> in a DOS enviroment. How can i convert the Data into Windows codepages
> from ruby?

Map each Byte to the corresponding one using a hash. You need the
codepages.

DOS codepages are listed here:

http://dwd.da.ru/charsets/index.html#do...

Windows codepages are listed here:

http://dwd.da.ru/charsets/index.html#window...

The mapping is troublesome because of two reasons: First of all all
DOS characters have Windows standard codepage counterparts (greek
letters for example) and 0..31 can be either control chars or
pictograms.

So the best you can do is use the above tables and create Arrays or
hashes that do the mapping.

For cp850 and cp866 you can use iconv, otherwise you can use recode.
This can be done from Ruby but it requires the appropriate software
being in place. Bad if you want software to be portable.

Josef 'Jupp' Schugt
--
.-------.
message > 100 kB? / | |
sender = spammer? / | R.I.P.|
text = spam? / ___| |___


Eric-Roger Bruecklmeier

11/21/2003 9:56:00 AM

0

Josef 'Jupp' SCHUGT schrieb:

>
>>in a new application i have to read dBase III Files which were generated
>>in a DOS enviroment. How can i convert the Data into Windows codepages
>>from ruby?
>
>
> Map each Byte to the corresponding one using a hash. You need the
> codepages.

That's the way i do it now, but it's slow :-(

>
> For cp850 and cp866 you can use iconv, otherwise you can use recode.
> This can be done from Ruby but it requires the appropriate software
> being in place. Bad if you want software to be portable.

Exactly that's the problem, the software has to be portable :-(

Thanks anyhow!

C YA

Eric.

Josef 'Jupp' Schugt

11/21/2003 8:45:00 PM

0

Hi!

* Eric-Roger Bruecklmeier; 2003-11-21, 13:01 UTC:
> Josef 'Jupp' SCHUGT schrieb:
>>> in a new application i have to read dBase III Files which were
>>> generated in a DOS enviroment. How can i convert the Data into
>>> Windows codepages from ruby?
>>
>> Map each Byte to the corresponding one using a hash. You need the
>> codepages.
>
> That's the way i do it now, but it's slow :-(

When I find my code in tons of trouble, friends and collegues come to
me, speaking words of wisdom: write in C. (Sung to: 'Let it be' by
the Beatles).

Speedup calls for a C extension. I'll skip the 'intro to C
extensions' stuff (Thomas and Hunt have that) and directly go to the
implementation of the mapping algorithm.

Suppose s points to array of char to be converted. Suppose you simply
need to map code 0 to 1 and vice versa. In that case use this:

for (p = s; *p; p++) {
switch (*p) {
case 0: *p = 1; break;
case 1: *p = 0; break;
}
}

You don't need to map any char in the ASCII printable range which
saves a lot of coding. The resulting code is extremely fast.

> Exactly that's the problem, the software has to be portable :-(

The above code is extremely portable. An additional advantage: You
can give the codes in decimal or hexadecimal values.

For 16 Bit codes things are more complicated. You then need

for (p = s; *p; p+=2) {
switch (*p << 8 + *(p+1)) { /* or the other way round, depends */
case 0: *p = 1; break;
case 1: *p = 0; break;
}
}

and lots of additional cases.

Viel Erfolg,

Josef 'Jupp' Schugt
--
.-------.
message > 100 kB? / | |
sender = spammer? / | R.I.P.|
text = spam? / ___| |___


better than tomorrow worse than yesterday

11/17/2011 10:30:00 PM

0

On Nov 17, 3:27 pm, Stew <Stew_mem...@newsguy.com> wrote:
> In article <724696bc-9588-47ed-978d-f20b9b996...@y7g2000vbe.googlegroups.com>,
> peliku says...
>
>
>
> >On Nov 17, 1:38=A0pm, Mulligan <yos...@hotmail.com> wrote:
> >> On Nov 17, 2:34=A0pm, peliku <guaireaid...@hotmail.com> wrote:
>
> >> > Take a look:
>
> >> What is wrong with you sir is incurable.
>
> >I have an incurable dislike of mobs, especially unsanitary mobs.
>
> You would have been useless during the American Revolution.

If you read a history book you'll find out that the American
revolution was over two-hundred years ago. There is a difference
between revolutionaries and revolting people.

better than tomorrow worse than yesterday

11/17/2011 10:33:00 PM

0

On Nov 17, 2:40 pm, Mulligan <t2judgm...@gmail.com> wrote:
> On Nov 17, 3:37 pm, Lower Taxes <johnnaishwer...@yahoo.com> wrote:
>
>
>
>
>
> > On Nov 17, 2:16 pm, Mulligan <t2judgm...@gmail.com> wrote:
>
> > > On Nov 17, 3:09 pm, Common sense <guaireaid...@hotmail.com> wrote:
>
> > > > On Nov 17, 2:01 pm, Mulligan <t2judgm...@gmail.com> wrote:
>
> > > > > On Nov 17, 2:50 pm, peliku <guaireaid...@hotmail.com> wrote:
>
> > > > > > On Nov 17, 1:38 pm, Mulligan <yos...@hotmail.com> wrote:
>
> > > > > > > On Nov 17, 2:34 pm, peliku <guaireaid...@hotmail.com> wrote:
>
> > > > > > > > Take a look:
>
> > > > > > > What is wrong with you sir is incurable.
>
> > > > > > I have an incurable dislike of mobs, especially unsanitary mobs.
>
> > > > > Are you worried about being mobbed?
>
> > > > No, but I would be worried about my health if I got too near one of
> > > > the OWS crowd.
>
> > > What does this have to do with you do not have to be watching me?- Hide quoted text -
>
> > > - Show quoted text -
>
> > If you get sick don't let the doctor give you a transfusion from a
> > member of the "Occupiers."- Hide quoted text -
>
> > - Show quoted text -
>
> So it is irrelevant.- Hide quoted text -
>
> - Show quoted text -

You are irrelevant.

Just Wondering

11/18/2011 12:23:00 AM

0

On 11/17/2011 3:30 PM, Lower Taxes wrote:
> On Nov 17, 3:27 pm, Stew<Stew_mem...@newsguy.com> wrote:
>> In article<724696bc-9588-47ed-978d-f20b9b996...@y7g2000vbe.googlegroups.com>,
>> peliku says...
>>
>>
>>
>>> On Nov 17, 1:38=A0pm, Mulligan<yos...@hotmail.com> wrote:
>>>> On Nov 17, 2:34=A0pm, peliku<guaireaid...@hotmail.com> wrote:
>>
>>>>> Take a look:
>>
>>>> What is wrong with you sir is incurable.
>>
>>> I have an incurable dislike of mobs, especially unsanitary mobs.
>>
>> You would have been useless during the American Revolution.
>
> If you read a history book you'll find out that the American
> revolution was over two-hundred years ago. There is a difference
> between revolutionaries and revolting people.

http://www.youtube.com/watch?v=T...