See the archives on discussions of rtl_printf, scanf, atof, and similar
functions.  A number of people have ported portions of c library functions
and made them work under rtlinux.  One of the reasons the regular functions
don't work under rtlinux is internal usage of malloc and other dynamic
allocation that is not too helpful in real time.

Here are some functions I created that might be of some help to you.

// ---------------------------------------------------------------
// isdigit -- returns true if character is a digit
// ---------------------------------------------------------------
int isdigit(char c){ return 47< (int)c && (int)c < 58 ? 1 : 0;   }

// ----------------------------------------------------------------
// atoi  -- converts character string to an integer
// ----------------------------------------------------------------
int atoi(char *s) {
   int i, n, m, t, sign=1;

    // Search for a digit saving plus or minus sign if one is found.
    for(i=0; !isdigit(s[i]); i++) {
        if( s[i]==0 ) return 0;
        if( s[i]=='-' )  sign = -1;
        if( s[i]=='+' ) sign = 1;
    }

    // Count the digits
    for(t=0; isdigit(s[i]); i++, t++) {}

    // t -- total number of digits counted
   n=0;
    m=1;
    while (t--) {
       n = n + m * ( (int)s[--i]-48 );  // 48 = ascii code offset
      m = m * 10;
     }
    return sign*n;
}

// ----------------------------------------------------------------
// atof  -- converts fixed point character string to a double
// ----------------------------------------------------------------
double atof(char *s) {
    int i, j, n, m, t, sign=1;
    double leftside;

    // Search for a digit saving plus or minus sign if one is found.
    for(i=0; !isdigit(s[i]); i++) {
        if( s[i]==0 ) return 0;
        if( s[i]=='-' )  sign = -1;
        if( s[i]=='+' ) sign = 1;
   }

    // Count the digits
    for(t=0; isdigit(s[i]); i++, t++) {}

    // t -- total number of digits counted
    n=0;
    m=1;
    for (j=0;j<t;j++){
       n = n + m * ( (int)s[--i]-48 );  // 48 = ascii code offset
        m = m * 10;
    }
    leftside=(double)n;

     //Advance the index again ..
     i = i + t;

     //Now work on the right side of decimal point (if any)
     if ( s[i]=='.' && isdigit(s[i+1]) ) {
          i++;
          // Count the digits
     for(t=0; isdigit(s[i]); i++, t++) {}

     // t -- total number of digits counted
          n=0;
     m=1;
          while (t--) {
               n = n + m * ( (int)s[--i]-48 );  // 48 = ascii code offset
               m = m * 10;
     }
         // Glue together right side with left side ...
         return sign*(leftside+ (double)n/m);
     }
     else {
          //We are done
          return leftside;
     }
}


// ------------------------------------------------------------------
// skipfield -- counts characters in an integer or fixed point field.
// ------------------------------------------------------------------
int skipfield (char *s) {
     int i, j, n, m, t, sign=1;

     // Search for a digit saving plus or minus sign if one is found.
    for(i=0; !isdigit(s[i]); i++) {
          if( s[i]==0 ) return 0;
          if( s[i]=='-' )     sign = -1;
        if( s[i]=='+' ) sign = 1;
     }

     // Count the digits
    for(t=0; isdigit(s[i]); i++, t++) {}

    // t -- total number of digits counted
     n=0;
    m=1;
    for (j=0;j<t;j++){
       n = n + m * ( (int)s[--i]-48 );  // 48 = ascii code offset
        m = m * 10;
    }

     //Advance the index again ..
     i = i + t;

     //Now work on the right side of decimal point (if any)
     if ( s[i]=='.' && isdigit(s[i+1]) ) {
          i++;
          // Count the digits
     for(t=0; isdigit(s[i]); i++, t++) {}
         return i;
     }
     else {
         // no right side was encountered

          if (s[i]=='.') return i+1;
          return i;
     }
}




[EMAIL PROTECTED] (Thomas Frasher)@fsmlabs.com on 05/30/2001 03:21:07
PM

Please respond to [EMAIL PROTECTED]

Sent by:  [EMAIL PROTECTED]


To:   <[EMAIL PROTECTED]>
cc:
Subject:  [rtl] atof not working


     I'm trying to use atof to do.... what atof does actually.  I'm trying
this
in of all places a real-time (rtl2.2) module. The module cannot be
inserted,
when trying to insert, the message something like " undefined symbol
__strtod_internal".  If the same call is used in a program (exectuable< non
module) it works just fine.  Anybody have any ideas?

-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/



-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/

Reply via email to