home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 11 / AUCD11B.iso / LANGUAGES / WraithSet / AwkStuff / MawkSrc / c / missing < prev    next >
Encoding:
Text File  |  1995-06-03  |  2.7 KB  |  193 lines

  1.  
  2. /* missing.c */
  3.  
  4. /*$Log: missing.c,v $
  5.  * Revision 1.2  1995/06/03  09:31:11  mike
  6.  * handle strchr(s,0) correctly
  7.  *
  8.  **/
  9.  
  10. #include "nstd.h"
  11.  
  12.  
  13. #ifdef    NO_STRCHR
  14. char *
  15. strchr(s, c)
  16.    char *s ;
  17.    int c ;
  18. {
  19.    if( c == 0 ) return s + strlen(s) ;
  20.  
  21.    while (*s)
  22.    {
  23.       if (*s == c)  return s ;
  24.       s++ ;
  25.    }
  26.    return (char *) 0 ;
  27. }
  28.  
  29. char *
  30. strrchr(s, c)
  31.    char *s ;
  32.    int c ;
  33. {
  34.    char *ret = (char *) 0 ;
  35.  
  36.    if ( c == 0 ) return s + strlen(s) ;
  37.  
  38.    while (*s)
  39.    {
  40.       if (*s == c)  ret = s ;
  41.       s++ ;
  42.    }
  43.    return ret ;
  44. }
  45. #endif /* NO_STRCHR */
  46.  
  47. #ifdef     NO_STRERROR
  48. extern int sys_nerr ;
  49. extern char *sys_errlist[] ;
  50. char *
  51. strerror(n)
  52.    int n ;
  53. {
  54.    return n > 0 & n < sys_nerr ? sys_errlist[n] : "" ;
  55. }
  56. #endif
  57.  
  58.  
  59. #ifdef    NO_MEMCPY
  60. PTR
  61. memcpy(t, s, n)
  62.    PTR t, s ;
  63.    size_t n ;
  64. {
  65.    char *tt = t ;
  66.    char *ss = s ;
  67.  
  68.    while (n > 0)
  69.    {
  70.       n-- ;
  71.       *tt++ = *ss++ ;
  72.    }
  73.    return t ;
  74. }
  75.  
  76. int
  77. memcmp(t, s, n)
  78.    PTR t, s ;
  79.    size_t n ;
  80. {
  81.    char *tt = t ;
  82.    char *ss = s ;
  83.  
  84.    while (n > 0)
  85.    {
  86.       if (*tt < *ss)  return -1 ;
  87.       if (*tt > *ss)  return 1 ;
  88.       tt++ ; ss++ ; n-- ;
  89.    }
  90.    return 0 ;
  91. }
  92.  
  93. PTR
  94. memset(t, c, n)
  95.    PTR t ;
  96.    int c ;
  97.    size_t n ;
  98. {
  99.    char *tt = (char *) t ;
  100.  
  101.    while (n > 0)
  102.    {
  103.       n-- ;
  104.       *tt++ = c ;
  105.    }
  106.    return t ;
  107. }
  108. #endif /* NO_MEMCPY */
  109.  
  110. #ifdef    NO_STRTOD
  111.  
  112. /* don't use this unless you really don't have strtod() because
  113.    (1) its probably slower than your real strtod()
  114.    (2) atof() may call the real strtod()
  115. */
  116.  
  117. double
  118. strtod(s, endptr)
  119.    const char *s ;
  120.    char **endptr ;
  121. {
  122.    register unsigned char *p ;
  123.    int flag ;
  124.    double atof();
  125.  
  126.    if (endptr)
  127.    {
  128.       p = (unsigned char *) s ;
  129.  
  130.       flag = 0 ;
  131.       while (*p == ' ' || *p == '\t')  p++ ;
  132.       if (*p == '-' || *p == '+')  p++ ;
  133.       while ( scan_code[*p] == SC_DIGIT ) { flag++ ; p++ ; }
  134.       if (*p == '.')
  135.       {
  136.      p++ ;
  137.      while ( scan_code[*p] == SC_DIGIT ) { flag++ ; p++ ; }
  138.       }
  139.       /* done with number part */
  140.       if (flag == 0)
  141.       {                /* no number part */
  142.      *endptr = s ; return 0.0 ; 
  143.       }
  144.       else  *endptr = (char *) p ;
  145.  
  146.       /* now look for exponent */
  147.       if (*p == 'e' || *p == 'E')
  148.       {
  149.      flag = 0 ;
  150.      p++ ;
  151.      if (*p == '-' || *p == '+')  p++ ;
  152.      while ( scan_code[*p] == SC_DIGIT ) { flag++ ; p++ ; }
  153.      if (flag)  *endptr = (char *) p ;
  154.       }
  155.    }
  156.    return atof(s) ;
  157. }
  158. #endif /* no strtod() */
  159.  
  160. #ifdef     NO_FMOD
  161.  
  162. #ifdef SW_FP_CHECK    /* this is V7 and XNX23A specific */
  163.  
  164. double
  165. fmod(x, y)
  166.    double x, y;
  167. {
  168.    double modf();
  169.    double dtmp, ipart;
  170.  
  171.    clrerr() ;
  172.    dtmp = x / y ;
  173.    fpcheck() ;
  174.    modf(dtmp, &ipart) ;
  175.    return x - ipart * y ;
  176. }
  177.  
  178. #else
  179.  
  180. double
  181. fmod(x, y)
  182.    double x, y;
  183. {
  184.    double modf();
  185.    double ipart;
  186.  
  187.    modf(x / y, &ipart) ;
  188.    return x - ipart * y ;
  189. }
  190.  
  191. #endif
  192. #endif /* NO_FMOD */
  193.