home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / dos / strtolong.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  2.0 KB  |  107 lines

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