Welcome, Guest. Please login or register.

Author Topic: AFAOS and encodings  (Read 4385 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline unusedunused

  • Sr. Member
  • ****
  • Join Date: Nov 2005
  • Posts: 479
    • Show only replies by unusedunused
Re: AFAOS and encodings
« Reply #14 from previous page: August 19, 2007, 12:33:19 PM »
I am sure they add the feature that hex is support and change the autodoc when they not went down 1994 ;-)

I think it is usefull for coding that strtolong support also other input formats.

So in parser can use hex and decimal values.

there is a ansi command strtol.
but when i look on this, i see it is not so easy to get the number of the character in the value.
 
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: AFAOS and encodings
« Reply #15 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 Georg

  • Jr. Member
  • **
  • Join Date: Feb 2002
  • Posts: 90
    • Show only replies by Georg
Re: AFAOS and encodings
« Reply #16 on: August 19, 2007, 02:22:30 PM »
Quote

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.


Backwards compatibility. If you have a function which takes an input string and splits it into int_number and string_remainder then a input string "0x10Hello" would give

0 x10Hello

in the old AOS style implementation (not accepting hex), but
would give

16 Hello in the new MOS style implementation (accepting hex).


Okay, I would probably (have) to think much harder for an example which makes some more (any) sense, but OTOH how likely do you think it is that a similiar enhancement is ever done for clib/atoi() and why.



 

Offline unusedunused

  • Sr. Member
  • ****
  • Join Date: Nov 2005
  • Posts: 479
    • Show only replies by unusedunused
Re: AFAOS and encodings
« Reply #17 on: August 19, 2007, 03:20:08 PM »
When i read this then maybe it is safer to let stringtolong as it is and change fontmanager.

but i am lazy and cant test if codepages work, because default font support german correct.

@Georg,

Do you have MOS source with stringtolong ?
I do it in a separate command.

 
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: AFAOS and encodings
« Reply #18 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 Georg

  • Jr. Member
  • **
  • Join Date: Feb 2002
  • Posts: 90
    • Show only replies by Georg
Re: AFAOS and encodings
« Reply #19 on: August 19, 2007, 07:57:33 PM »
Quote

Piru wrote:

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


Well, if so (which is very likely after a quick look at the source: for example the space/tab check should be in a loop I guess), it's because of buggy implementation not intended implementation.

Quote
Never.


And why?
 

Offline Georg

  • Jr. Member
  • **
  • Join Date: Feb 2002
  • Posts: 90
    • Show only replies by Georg
Re: AFAOS and encodings
« Reply #20 on: August 19, 2007, 08:01:55 PM »
Quote

bernd_afa wrote:

Do you have MOS source with stringtolong ?
I do it in a separate command.


No, we only have DOS sources from 2001 or 2002 which did not yet have hex support in. It's not something hard to implement but I would rather change ftmanager to use strtol() instead. Because for running ftmanager under AOS using StrToLong() would only work if you patch it to work like MOS.


 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: AFAOS and encodings
« Reply #21 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 unusedunused

  • Sr. Member
  • ****
  • Join Date: Nov 2005
  • Posts: 479
    • Show only replies by unusedunused
Re: AFAOS and encodings
« Reply #22 on: August 20, 2007, 08:15:07 AM »
Ok on MOS this is less risc, because it is not 100% compatible so all 68k programs work and Coders must port their programs if they notice a bug when they test all functions.

AFA should be 100% compatible.

I think too there cant be a 100% garantie that there is none of the 10000 and more programs out that fail in some cases, maybe read bad load file only when option x and y is set and program do wired things.

As Georg told, AROS Team have no source of the new strtolong.

Can you please send it ?
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: AFAOS and encodings
« Reply #23 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 */
 

Offline Georg

  • Jr. Member
  • **
  • Join Date: Feb 2002
  • Posts: 90
    • Show only replies by Georg
Re: AFAOS and encodings
« Reply #24 on: August 20, 2007, 06:37:58 PM »
Quote

Piru wrote:

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


cvs access I had did not include dos sources. DOS sources from 2001 or 2002 were sent as archive by Emm (initial plan was to have final thing compilable for both AROS and MOS from same source (reason for added AROS_DOS_COMPATIBLE) but at end Emm/MOS coders did not have enough time and/or possibility to test)).



 

Offline unusedunused

  • Sr. Member
  • ****
  • Join Date: Nov 2005
  • Posts: 479
    • Show only replies by unusedunused
Re: AFAOS and encodings
« Reply #25 on: August 21, 2007, 08:43:19 AM »
@Piru

Many thanks for the source
 

Offline unusedunused

  • Sr. Member
  • ****
  • Join Date: Nov 2005
  • Posts: 479
    • Show only replies by unusedunused
Re: AFAOS and encodings
« Reply #26 on: August 23, 2007, 10:19:01 AM »
On AFA Page is new fontmanager, i add the code Piru send and rename it as MosStrToLong.source is included in that archive

please look if that work.if so, then the fontmanager is datet as non beta
 
The link to codepage files is too on AFA page or look here