Welcome, Guest. Please login or register.

Author Topic: AFAOS and encodings  (Read 4380 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: AFAOS and encodings
« on: August 18, 2007, 02:59:40 PM »
@bernd_afa
Quote
I thought MOS is same as AROS because MOS team should exchange files with AROS team.the diskfont stuff of MOS and AROS is same.

While AROS has accepted many of our contributions, it doesn't mean they'll just merge all our changes blindly. As a result there are differences between AROS and MorphOS, even for the components shared. That is why you can't share ft .otag files between AROS and MorphOS for example (AROS for some unknown reason renamed the freetype bullet engine from "ft2" to "freetype2").

Quote
But if MOS work with hex codepages, and they dont want exchange the files, seem i must add this feature, because there are no codepages here

maybe you can ask if somebody send you the actual MOS source of the truetype manager to save me time ?

As AROS ftmanager is directly based on the MorphOS ftmanager, you already have it.

BTW: The codepage files are available at Unicode, Inc ftp server.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: AFAOS and encodings
« Reply #1 on: August 18, 2007, 05:23:51 PM »
@bernd_afa
Quote
is MOS strtolong enhanced that strtolong support too hex values ?

Yes.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: AFAOS and encodings
« Reply #2 on: August 18, 2007, 06:54:16 PM »
@bernd_afa
Quote
and source is not available ?

To my knowledge AROS has the source-code for this function, along with other dos.library parts which were derived from AROS. Perhaps it wasn't merged for some reason?
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: AFAOS and encodings
« Reply #3 on: August 19, 2007, 12:43:18 PM »
@Georg
Quote
Was that a good idea considering that autodocs say "Converts decimal string into LONG value."?

It automagically gave hex support for ReadArgs /N, too, so yes I consider it a good move.

Also, to specify a hex number you need a identifier before such number, thus I can't possibly see any disadvantages in it either.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: AFAOS and encodings
« Reply #4 on: August 19, 2007, 03:36:21 PM »
@Georg
Quote
Backwards compatibility

Considering the AROS StrToLong() isn't AmigaOS compatible either, that is a bit silly argument IMO.

Quote
OTOH how likely do you think it is that a similiar enhancement is ever done for clib/atoi() and why.

Never.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: AFAOS and encodings
« Reply #5 on: August 19, 2007, 08:20:03 PM »
@Georg
Quote
And why?

Well, you know why, but lets go into details, just for fun.

Because atoi() is ANSI, C89, C99 etc. It's a standard function. In short: I don't feel like touching such standard function, which should be pretty obvious.

I consider StrToLong() to be less standard, and subject to change, as long as the original functionality isn't compromised. It obviously is a calculated risk to change the behaviour, but this is one of the smallest changes in MorphOS. There are many more fundamental ones. I have no problem changing functionality if it offers new and improved features. However, it should happen in a way that it breaks as little old behaviour as possible. Staying in the confines of the original AmigaOS 3.1 API doesn't just cut it for me (or us the MorphOS Team in general).

In this StrToLong()-case the positivies are: Having old applications automagically support hex numbers when reading numbers via StrToLong() and ReadArgs() /N. Negatives: Potentially breaking some applications that depend on the call stopping on hex identifier. So far I haven't seen myself, or heard of any reports that would indicate any software breaking due to this change.

As a funny remark, some seem to have had broken atoi at some point.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: AFAOS and encodings
« Reply #6 on: August 20, 2007, 05:47:54 PM »
@bernd_afa
Quote
As Georg told, AROS Team have no source of the new strtolong.

The particular change was made in 2002. Georg himself had access to the source code at that time.

Quote
Can you please send it ?

This code is licensed under AROS Public License v1.1.

Code: [Select]
/*
    (C) 1995-96 AROS - The Amiga Research OS
    (C) 2002 Sigbjørn "CISC" Skjæret and Harry "Piru" Sintonen
    $Id: strtolong.c,v 1.1.1.1 2005/03/15 15:54:40 laire Exp $

    Desc: Convert a string into a long
    Lang: english
*/

#include "dos_intern.h"

#define DEBUG_STRTOLONG(x) ;

/*****************************************************************************

    NAME */
#include <proto/dos.h>
#include &quot;dos_intern.h&quot;

        AROS_LH2I(LONG, StrToLong,

/*  SYNOPSIS */
        AROS_LHA(STRPTR, string, D1),
        AROS_LHA(LONG *, value,  D2),

/*  LOCATION */
        struct DosLibrary *, DOSBase, 136, Dos)

/*  FUNCTION
        Convert a string to a long number.

    INPUTS
        string - The value to convert
        value - The result is returned here

    RESULT
        How many characters in the string were considered when it was
        converted or -1 if no valid number could be found.

    NOTES
        The routine doesn't check if the number if too large.

    EXAMPLE
        // Valid number are: 5, -1, +3, +0007, $feed, -0xBEEF, etc.

    BUGS

    SEE ALSO

    INTERNALS

    HISTORY
        04-07-02    Added ability to read hex-strings.

*****************************************************************************/
{
    AROS_LIBFUNC_INIT
    AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)

    LONG old_v, v = 0;
    STRPTR s = string;
    BOOL negative = FALSE;

    DEBUG_STRTOLONG(dprintf(&quot;StrToLong: string \&quot;%s\&quot; value 0x%lx\n&quot;, string, (ULONG) value));

    /* Skip leading whitespace characters */
    while (*s == ' ' || *s == '\t')
        ++s;

    /* Swallow sign */
#ifdef AROS_DOS_COMPATIBLE
    if (*s == '-')
#else
    if (*s == '+' || *s == '-')
#endif
        negative = *s++ == '-';

    /* Is it a hex-string? */
    if (*s == '$' || (*s == '0' && (s[1] == 'x' || s[1] == 'X')))
    {
        LONG i = 0;

        /* Skip hex-identifier */
        if (*s++ != '$')
            ++s;

        /* If there is no number return an error. */
        if ((*s < '0' || *s > '9') && (*s < 'a' || *s > 'f') && (*s < 'A' || *s > 'F'))
        {
            *value = 0;

            DEBUG_STRTOLONG(dprintf(&quot;StrToLong: no number, return error\n&quot;));

            /* Compatability return */
            if (s[-1] == 'x' || s[-1] == 'X')
                return s - 1 - string;
            else
                return -1;
        }

        /* Calculate result */
        do
        {
            old_v = v;
            v <<= 4;
            if (negative && v < old_v)
                break;
            old_v = v;
            v += ((*s <= '9') ? (*s - '0') : ((*s <= 'F') ? (*s - 'A' + 10) : (*s - 'a' + 10)));

            if (negative && v == -2147483648L)
            {
                negative = FALSE;
                old_v = v;
                ++s;
                break;
            }
            else if (negative && v < old_v)
                break;

            ++s;

            if (++i == 8) break;
        } while ((*s >= '0' && *s <= '9') || (*s >= 'a' && *s <= 'f') || (*s >= 'A' && *s <= 'F'));
    }
    else
    {
        /* If there is no number return an error. */
        if (*s < '0' || *s > '9')
        {
            *value = 0;

            DEBUG_STRTOLONG(dprintf(&quot;StrToLong: no number, return error\n&quot;));

            return -1;
        }

        /* Calculate result */
        do
        {
            LONG x;
            x = v;
            old_v = v;
            v <<= 3;
            if (v < old_v)
                break;
            old_v = v;
            v += x;
            if (v < old_v)
                break;
            old_v = v;
            v += x;
            if (v < old_v)
                break;
            old_v = v;
            v = v + *s - '0';
            if (negative && v == -2147483648L)
            {
                negative = FALSE;
                old_v = v;
                ++s;
                break;
            }
            else if (v < old_v)
                break;
            ++s;
        } while (*s >= '0' && *s <= '9');
    }

    /* Overflow? */
    if (v < old_v)
        v = old_v;

    /* Negative? */
    if (negative)
        v = -v;

    /* All done. */
    *value = v;

    DEBUG_STRTOLONG(dprintf(&quot;StrToLong: *value = %ld return %ld\n&quot;, v, (LONG) (s - string)));

    return s - string;

    AROS_LIBFUNC_EXIT
} /* StrToLong */