Professional Web Applications Themes

A question about Chts - Ruby

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....

  1. #1

    Default A question about Chts

    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.

    Eric-Roger Bruecklmeier Guest

  2. #2

    Default Re: A question about Chts

    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:

    [url]http://dwd.da.ru/chts/index.html#dos-specific[/url]

    Windows codepages are listed here:

    [url]http://dwd.da.ru/chts/index.html#windows-specific[/url]

    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? / ___| |___


    Josef 'Jupp' SCHUGT Guest

  3. #3

    Default Re: A question about Chts

    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.

    Eric-Roger Bruecklmeier Guest

  4. #4

    Default Re: A question about Chts

    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? / ___| |___


    Josef 'Jupp' SCHUGT Guest

Similar Threads

  1. multibyte chts?
    By yawnmoth in forum MySQL
    Replies: 1
    Last Post: June 22nd, 01:30 PM
  2. Replies: 9
    Last Post: April 27th, 04:44 AM
  3. Chts!
    By mrT in forum PHP Development
    Replies: 1
    Last Post: November 15th, 07:47 PM
  4. problems with chts
    By peter pilsl in forum PERL Miscellaneous
    Replies: 2
    Last Post: September 7th, 07:47 PM
  5. #9188 [Com]: it seems that mysql-module doesn't support any chts except latin1
    By makisfm at mailbox dot gr in forum PHP Development
    Replies: 0
    Last Post: September 2nd, 06:49 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139