File: missing.c

package info (click to toggle)
mawk 1.3.3-17
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 1,484 kB
  • ctags: 1,506
  • sloc: ansic: 13,008; yacc: 994; awk: 629; makefile: 113; sh: 107
file content (192 lines) | stat: -rw-r--r-- 2,812 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

/* missing.c */

/*$Log: missing.c,v $
 * Revision 1.2  1995/06/03  09:31:11  mike
 * handle strchr(s,0) correctly
 *
 **/

#include "nstd.h"


#ifdef	NO_STRCHR
char *
strchr(s, c)
   char *s ;
   int c ;
{
   if( c == 0 ) return s + strlen(s) ;

   while (*s)
   {
      if (*s == c)  return s ;
      s++ ;
   }
   return (char *) 0 ;
}

char *
strrchr(s, c)
   char *s ;
   int c ;
{
   char *ret = (char *) 0 ;

   if ( c == 0 ) return s + strlen(s) ;

   while (*s)
   {
      if (*s == c)  ret = s ;
      s++ ;
   }
   return ret ;
}
#endif /* NO_STRCHR */

#ifdef	 NO_STRERROR
extern int sys_nerr ;
extern char *sys_errlist[] ;
char *
strerror(n)
   int n ;
{
   return n > 0 & n < sys_nerr ? sys_errlist[n] : "" ;
}
#endif


#ifdef	NO_MEMCPY
PTR
memcpy(t, s, n)
   PTR t, s ;
   size_t n ;
{
   char *tt = t ;
   char *ss = s ;

   while (n > 0)
   {
      n-- ;
      *tt++ = *ss++ ;
   }
   return t ;
}

int
memcmp(t, s, n)
   PTR t, s ;
   size_t n ;
{
   char *tt = t ;
   char *ss = s ;

   while (n > 0)
   {
      if (*tt < *ss)  return -1 ;
      if (*tt > *ss)  return 1 ;
      tt++ ; ss++ ; n-- ;
   }
   return 0 ;
}

PTR
memset(t, c, n)
   PTR t ;
   int c ;
   size_t n ;
{
   char *tt = (char *) t ;

   while (n > 0)
   {
      n-- ;
      *tt++ = c ;
   }
   return t ;
}
#endif /* NO_MEMCPY */

#ifdef	NO_STRTOD

/* don't use this unless you really don't have strtod() because
   (1) its probably slower than your real strtod()
   (2) atof() may call the real strtod()
*/

double
strtod(s, endptr)
   const char *s ;
   char **endptr ;
{
   register unsigned char *p ;
   int flag ;
   double atof();

   if (endptr)
   {
      p = (unsigned char *) s ;

      flag = 0 ;
      while (*p == ' ' || *p == '\t')  p++ ;
      if (*p == '-' || *p == '+')  p++ ;
      while ( scan_code[*p] == SC_DIGIT ) { flag++ ; p++ ; }
      if (*p == '.')
      {
	 p++ ;
	 while ( scan_code[*p] == SC_DIGIT ) { flag++ ; p++ ; }
      }
      /* done with number part */
      if (flag == 0)
      {				/* no number part */
	 *endptr = s ; return 0.0 ; 
      }
      else  *endptr = (char *) p ;

      /* now look for exponent */
      if (*p == 'e' || *p == 'E')
      {
	 flag = 0 ;
	 p++ ;
	 if (*p == '-' || *p == '+')  p++ ;
	 while ( scan_code[*p] == SC_DIGIT ) { flag++ ; p++ ; }
	 if (flag)  *endptr = (char *) p ;
      }
   }
   return atof(s) ;
}
#endif /* no strtod() */

#ifdef	 NO_FMOD

#ifdef SW_FP_CHECK	/* this is V7 and XNX23A specific */

double
fmod(x, y)
   double x, y;
{
   double modf();
   double dtmp, ipart;

   clrerr() ;
   dtmp = x / y ;
   fpcheck() ;
   modf(dtmp, &ipart) ;
   return x - ipart * y ;
}

#else

double
fmod(x, y)
   double x, y;
{
   double modf();
   double ipart;

   modf(x / y, &ipart) ;
   return x - ipart * y ;
}

#endif
#endif /* NO_FMOD */