home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / dos / strtolong.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  1.7 KB  |  90 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: strtolong.c,v 1.4 1996/10/24 15:50:37 aros Exp $
  4.     $Log: strtolong.c,v $
  5.     Revision 1.4  1996/10/24 15:50:37  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.3  1996/08/13 13:52:52  digulla
  9.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  10.     Replaced AROS_LA by AROS_LHA
  11.  
  12.     Revision 1.2  1996/08/01 17:40:58  digulla
  13.     Added standard header for all files
  14.  
  15.     Desc:
  16.     Lang: english
  17. */
  18.  
  19. /*****************************************************************************
  20.  
  21.     NAME */
  22.     #include <clib/dos_protos.h>
  23.  
  24.     AROS_LH2I(LONG, StrToLong,
  25.  
  26. /*  SYNOPSIS */
  27.     AROS_LHA(STRPTR, string, D1),
  28.     AROS_LHA(LONG *, value,  D2),
  29.  
  30. /*  LOCATION */
  31.     struct DosLibrary *, DOSBase, 136, Dos)
  32.  
  33. /*  FUNCTION
  34.  
  35.     INPUTS
  36.  
  37.     RESULT
  38.  
  39.     NOTES
  40.  
  41.     EXAMPLE
  42.  
  43.     BUGS
  44.  
  45.     SEE ALSO
  46.  
  47.     INTERNALS
  48.  
  49.     HISTORY
  50.     29-10-95    digulla automatically created from
  51.                 dos_lib.fd and clib/dos_protos.h
  52.  
  53. *****************************************************************************/
  54. {
  55.     AROS_LIBFUNC_INIT
  56.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  57.  
  58.     LONG sign=0, v=0;
  59.     STRPTR s=string;
  60.     
  61.     /* Skip leading whitespace characters */
  62.     if(*s==' '||*s=='\t')
  63.         s++;
  64.  
  65.     /* Swallow sign */
  66.     if(*s=='+'||*s=='-')
  67.         sign=*s++;
  68.     
  69.     /* If there is no number return an error. */
  70.     if(*s<'0'||*s>'9')
  71.     {
  72.         *value=0;
  73.         return -1;
  74.     }
  75.  
  76.     /* Calculate result */    
  77.     do
  78.         v=v*10+*s++-'0';
  79.     while(*s>='0'&&*s<='9');
  80.  
  81.     /* Negative? */
  82.     if(sign=='-')
  83.         v=-v;
  84.  
  85.     /* All done. */    
  86.     *value=v;
  87.     return s-string;
  88.     AROS_LIBFUNC_EXIT
  89. } /* StrToLong */
  90.