LIB.TXT
资源名称:os_source.zip [点击查看]
上传用户:datang2001
上传日期:2007-02-01
资源大小:53269k
文件大小:979k
源码类别:
操作系统开发
开发平台:
C/C++
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/ext_fmt.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 00000 struct mantissa {
- 00001 unsigned long h_32;
- 00002 unsigned long l_32;
- 00003 };
- 00004
- 00005 struct EXTEND {
- 00006 short sign;
- 00007 short exp;
- 00008 struct mantissa mantissa;
- 00009 #define m1 mantissa.h_32
- 00010 #define m2 mantissa.l_32
- 00011 };
- 00012
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/loc_time.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 00100 /*
- 00101 * loc_time.h - some local definitions
- 00102 */
- 00103 /* $Header: loc_time.h,v 1.1 91/04/22 13:19:51 ceriel Exp $ */
- 00104
- 00105 #define YEAR0 1900 /* the first year */
- 00106 #define EPOCH_YR 1970 /* EPOCH = Jan 1 1970 00:00:00 */
- 00107 #define SECS_DAY (24L * 60L * 60L)
- 00108 #define LEAPYEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400)))
- 00109 #define YEARSIZE(year) (LEAPYEAR(year) ? 366 : 365)
- 00110 #define FIRSTSUNDAY(timp) (((timp)->tm_yday - (timp)->tm_wday + 420) % 7)
- 00111 #define FIRSTDAYOF(timp) (((timp)->tm_wday - (timp)->tm_yday + 420) % 7)
- 00112 #define TIME_MAX ULONG_MAX
- 00113 #define ABB_LEN 3
- 00114
- 00115 extern const int _ytab[2][12];
- 00116 extern const char *_days[];
- 00117 extern const char *_months[];
- 00118
- 00119 void _tzset(void);
- 00120 unsigned _dstget(struct tm *timep);
- 00121
- 00122 extern long _timezone;
- 00123 extern long _dst_off;
- 00124 extern int _daylight;
- 00125 extern char *_tzname[2];
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/abort.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 00200 /*
- 00201 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 00202 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 00203 */
- 00204 /* $Header: abort.c,v 1.3 90/11/22 13:59:37 eck Exp $ */
- 00205
- 00206 #if defined(_POSIX_SOURCE)
- 00207 #include <sys/types.h>
- 00208 #endif
- 00209 #include <signal.h>
- 00210 #include <stdlib.h>
- 00211
- 00212 extern void (*_clean)(void);
- 00213
- 00214 void
- 00215 abort(void)
- 00216 {
- 00217 if (_clean) _clean(); /* flush all output files */
- 00218 raise(SIGABRT);
- 00219 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/abs.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 00300 /*
- 00301 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 00302 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 00303 */
- 00304 /* $Header: abs.c,v 1.1 89/05/16 13:06:59 eck Exp $ */
- 00305
- 00306 #include <stdlib.h>
- 00307
- 00308 int
- 00309 abs(register int i)
- 00310 {
- 00311 return i >= 0 ? i : -i;
- 00312 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/asctime.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 00400 /*
- 00401 * asctime - print a date
- 00402 */
- 00403 /* $Header: asctime.c,v 1.3 91/04/22 13:20:15 ceriel Exp $ */
- 00404
- 00405 #include <string.h>
- 00406 #include <time.h>
- 00407 #include "loc_time.h"
- 00408
- 00409 #define DATE_STR "??? ??? ?? ??:??:?? ????n"
- 00410
- 00411 static char *
- 00412 two_digits(register char *pb, int i, int nospace)
- 00413 {
- 00414 *pb = (i / 10) % 10 + '0';
- 00415 if (!nospace && *pb == '0') *pb = ' ';
- 00416 pb++;
- 00417 *pb++ = (i % 10) + '0';
- 00418 return ++pb;
- 00419 }
- 00421 static char *
- 00422 four_digits(register char *pb, int i)
- 00423 {
- 00424 i %= 10000;
- 00425 *pb++ = (i / 1000) + '0';
- 00426 i %= 1000;
- 00427 *pb++ = (i / 100) + '0';
- 00428 i %= 100;
- 00429 *pb++ = (i / 10) + '0';
- 00430 *pb++ = (i % 10) + '0';
- 00431 return ++pb;
- 00432 }
- 00434 char *asctime(const struct tm *timeptr)
- 00435 {
- 00436 static char buf[26];
- 00437 register char *pb = buf;
- 00438 register const char *ps;
- 00439 register int n;
- 00440
- 00441 strcpy(pb, DATE_STR);
- 00442 ps = _days[timeptr->tm_wday];
- 00443 n = ABB_LEN;
- 00444 while(--n >= 0) *pb++ = *ps++;
- 00445 pb++;
- 00446 ps = _months[timeptr->tm_mon];
- 00447 n = ABB_LEN;
- 00448 while(--n >= 0) *pb++ = *ps++;
- 00449 pb++;
- 00450 pb = two_digits(
- 00451 two_digits(
- 00452 two_digits(two_digits(pb, timeptr->tm_mday, 0)
- 00453 , timeptr->tm_hour, 1)
- 00454 , timeptr->tm_min, 1)
- 00455 , timeptr->tm_sec, 1);
- 00456
- 00457 four_digits(pb, timeptr->tm_year + 1900);
- 00458 return buf;
- 00459 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/assert.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 00500 /*
- 00501 * assert.c - diagnostics
- 00502 */
- 00503 /* $Header: assert.c,v 1.3 90/04/03 15:01:58 eck Exp $ */
- 00504
- 00505 #include <assert.h>
- 00506 #include <stdio.h>
- 00507 #include <stdlib.h>
- 00508
- 00509 void __bad_assertion(const char *mess) {
- 00510
- 00511 fputs(mess, stderr);
- 00512 abort();
- 00513 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/atexit.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 00600 /* $Header: atexit.c,v 1.1 89/12/18 15:11:09 eck Exp $ */
- 00601
- 00602 #include <stdlib.h>
- 00603
- 00604 #define NEXITS 32
- 00605
- 00606 extern void (*__functab[NEXITS])(void);
- 00607 extern int __funccnt;
- 00608
- 00609 int
- 00610 atexit(void (*func)(void))
- 00611 {
- 00612 if (__funccnt >= NEXITS)
- 00613 return 1;
- 00614 __functab[__funccnt++] = func;
- 00615 return 0;
- 00616 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/atof.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 00700 /*
- 00701 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 00702 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 00703 */
- 00704 /* $Header: atof.c,v 1.2 89/12/18 15:11:50 eck Exp $ */
- 00705
- 00706 #include <stdlib.h>
- 00707 #include <errno.h>
- 00708
- 00709 double
- 00710 atof(const char *nptr)
- 00711 {
- 00712 double d;
- 00713 int e = errno;
- 00714
- 00715 d = strtod(nptr, (char **) NULL);
- 00716 errno = e;
- 00717 return d;
- 00718 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/atoi.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 00800 /*
- 00801 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 00802 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 00803 */
- 00804 /* $Header: atoi.c,v 1.4 90/05/22 12:22:25 ceriel Exp $ */
- 00805
- 00806 #include <ctype.h>
- 00807 #include <stdlib.h>
- 00808
- 00809 /* We do not use strtol here for backwards compatibility in behaviour on
- 00810 overflow.
- 00811 */
- 00812 int
- 00813 atoi(register const char *nptr)
- 00814 {
- 00815 int total = 0;
- 00816 int minus = 0;
- 00817
- 00818 while (isspace(*nptr)) nptr++;
- 00819 if (*nptr == '+') nptr++;
- 00820 else if (*nptr == '-') {
- 00821 minus = 1;
- 00822 nptr++;
- 00823 }
- 00824 while (isdigit(*nptr)) {
- 00825 total *= 10;
- 00826 total += (*nptr++ - '0');
- 00827 }
- 00828 return minus ? -total : total;
- 00829 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/atol.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 00900 /*
- 00901 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 00902 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 00903 */
- 00904 /* $Header: atol.c,v 1.3 90/05/22 10:48:12 ceriel Exp $ */
- 00905
- 00906 #include <ctype.h>
- 00907 #include <stdlib.h>
- 00908
- 00909 /* We do not use strtol here for backwards compatibility in behaviour on
- 00910 overflow.
- 00911 */
- 00912 long
- 00913 atol(register const char *nptr)
- 00914 {
- 00915 long total = 0;
- 00916 int minus = 0;
- 00917
- 00918 while (isspace(*nptr)) nptr++;
- 00919 if (*nptr == '+') nptr++;
- 00920 else if (*nptr == '-') {
- 00921 minus = 1;
- 00922 nptr++;
- 00923 }
- 00924 while (isdigit(*nptr)) {
- 00925 total *= 10;
- 00926 total += (*nptr++ - '0');
- 00927 }
- 00928 return minus ? -total : total;
- 00929 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/bsearch.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 01000 /*
- 01001 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 01002 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 01003 */
- 01004 /* $Header: bsearch.c,v 1.2 89/12/18 15:12:21 eck Exp $ */
- 01005
- 01006 #include <stdlib.h>
- 01007
- 01008 void *
- 01009 bsearch(register const void *key, register const void *base,
- 01010 register size_t nmemb, register size_t size,
- 01011 int (*compar)(const void *, const void *))
- 01012 {
- 01013 register const void *mid_point;
- 01014 register int cmp;
- 01015
- 01016 while (nmemb > 0) {
- 01017 mid_point = (char *)base + size * (nmemb >> 1);
- 01018 if ((cmp = (*compar)(key, mid_point)) == 0)
- 01019 return (void *)mid_point;
- 01020 if (cmp >= 0) {
- 01021 base = (char *)mid_point + size;
- 01022 nmemb = (nmemb - 1) >> 1;
- 01023 } else
- 01024 nmemb >>= 1;
- 01025 }
- 01026 return (void *)NULL;
- 01027 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/calloc.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 01100 /* $Header$ */
- 01101 #include <stdlib.h>
- 01102
- 01103 #define ALIGN(x) (((x) + (sizeof(size_t) - 1)) & ~(sizeof(size_t) - 1))
- 01104
- 01105 void *
- 01106 calloc(size_t nelem, size_t elsize)
- 01107 {
- 01108 register char *p;
- 01109 register size_t *q;
- 01110 size_t size = ALIGN(nelem * elsize);
- 01111
- 01112 p = malloc(size);
- 01113 if (p == NULL) return NULL;
- 01114 q = (size_t *) (p + size);
- 01115 while ((char *) q > p) *--q = 0;
- 01116 return p;
- 01117 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/chartab.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 01200 #include <ctype.h>
- 01201
- 01202 char __ctype[] = {
- 01203 0,
- 01204 _C,
- 01205 _C,
- 01206 _C,
- 01207 _C,
- 01208 _C,
- 01209 _C,
- 01210 _C,
- 01211 _C,
- 01212 _C,
- 01213 _C|_S,
- 01214 _C|_S,
- 01215 _C|_S,
- 01216 _C|_S,
- 01217 _C|_S,
- 01218 _C,
- 01219 _C,
- 01220 _C,
- 01221 _C,
- 01222 _C,
- 01223 _C,
- 01224 _C,
- 01225 _C,
- 01226 _C,
- 01227 _C,
- 01228 _C,
- 01229 _C,
- 01230 _C,
- 01231 _C,
- 01232 _C,
- 01233 _C,
- 01234 _C,
- 01235 _C,
- 01236 _S,
- 01237 _P,
- 01238 _P,
- 01239 _P,
- 01240 _P,
- 01241 _P,
- 01242 _P,
- 01243 _P,
- 01244 _P,
- 01245 _P,
- 01246 _P,
- 01247 _P,
- 01248 _P,
- 01249 _P,
- 01250 _P,
- 01251 _P,
- 01252 _N,
- 01253 _N,
- 01254 _N,
- 01255 _N,
- 01256 _N,
- 01257 _N,
- 01258 _N,
- 01259 _N,
- 01260 _N,
- 01261 _N,
- 01262 _P,
- 01263 _P,
- 01264 _P,
- 01265 _P,
- 01266 _P,
- 01267 _P,
- 01268 _P,
- 01269 _U|_X,
- 01270 _U|_X,
- 01271 _U|_X,
- 01272 _U|_X,
- 01273 _U|_X,
- 01274 _U|_X,
- 01275 _U,
- 01276 _U,
- 01277 _U,
- 01278 _U,
- 01279 _U,
- 01280 _U,
- 01281 _U,
- 01282 _U,
- 01283 _U,
- 01284 _U,
- 01285 _U,
- 01286 _U,
- 01287 _U,
- 01288 _U,
- 01289 _U,
- 01290 _U,
- 01291 _U,
- 01292 _U,
- 01293 _U,
- 01294 _U,
- 01295 _P,
- 01296 _P,
- 01297 _P,
- 01298 _P,
- 01299 _P,
- 01300 _P,
- 01301 _L|_X,
- 01302 _L|_X,
- 01303 _L|_X,
- 01304 _L|_X,
- 01305 _L|_X,
- 01306 _L|_X,
- 01307 _L,
- 01308 _L,
- 01309 _L,
- 01310 _L,
- 01311 _L,
- 01312 _L,
- 01313 _L,
- 01314 _L,
- 01315 _L,
- 01316 _L,
- 01317 _L,
- 01318 _L,
- 01319 _L,
- 01320 _L,
- 01321 _L,
- 01322 _L,
- 01323 _L,
- 01324 _L,
- 01325 _L,
- 01326 _L,
- 01327 _P,
- 01328 _P,
- 01329 _P,
- 01330 _P,
- 01331 _C,
- 01332 0,
- 01333 0,
- 01334 0,
- 01335 0,
- 01336 0,
- 01337 0,
- 01338 0,
- 01339 0,
- 01340 0,
- 01341 0,
- 01342 0,
- 01343 0,
- 01344 0,
- 01345 0,
- 01346 0,
- 01347 0,
- 01348 0,
- 01349 0,
- 01350 0,
- 01351 0,
- 01352 0,
- 01353 0,
- 01354 0,
- 01355 0,
- 01356 0,
- 01357 0,
- 01358 0,
- 01359 0,
- 01360 0,
- 01361 0,
- 01362 0,
- 01363 0,
- 01364 0,
- 01365 0,
- 01366 0,
- 01367 0,
- 01368 0,
- 01369 0,
- 01370 0,
- 01371 0,
- 01372 0,
- 01373 0,
- 01374 0,
- 01375 0,
- 01376 0,
- 01377 0,
- 01378 0,
- 01379 0,
- 01380 0,
- 01381 0,
- 01382 0,
- 01383 0,
- 01384 0,
- 01385 0,
- 01386 0,
- 01387 0,
- 01388 0,
- 01389 0,
- 01390 0,
- 01391 0,
- 01392 0,
- 01393 0,
- 01394 0,
- 01395 0,
- 01396 0,
- 01397 0,
- 01398 0,
- 01399 0,
- 01400 0,
- 01401 0,
- 01402 0,
- 01403 0,
- 01404 0,
- 01405 0,
- 01406 0,
- 01407 0,
- 01408 0,
- 01409 0,
- 01410 0,
- 01411 0,
- 01412 0,
- 01413 0,
- 01414 0,
- 01415 0,
- 01416 0,
- 01417 0,
- 01418 0,
- 01419 0,
- 01420 0,
- 01421 0,
- 01422 0,
- 01423 0,
- 01424 0,
- 01425 0,
- 01426 0,
- 01427 0,
- 01428 0,
- 01429 0,
- 01430 0,
- 01431 0,
- 01432 0,
- 01433 0,
- 01434 0,
- 01435 0,
- 01436 0,
- 01437 0,
- 01438 0,
- 01439 0,
- 01440 0,
- 01441 0,
- 01442 0,
- 01443 0,
- 01444 0,
- 01445 0,
- 01446 0,
- 01447 0,
- 01448 0,
- 01449 0,
- 01450 0,
- 01451 0,
- 01452 0,
- 01453 0,
- 01454 0,
- 01455 0,
- 01456 0,
- 01457 0,
- 01458 0,
- 01459 0,
- 01460 };
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/clock.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 01500 /*
- 01501 * clock - determine the processor time used
- 01502 */
- 01503 /* $Header: clock.c,v 1.3 90/01/22 13:08:11 eck Exp $ */
- 01504
- 01505 #include <time.h>
- 01506
- 01507 #if defined(__BSD4_2)
- 01508
- 01509 struct timeval {
- 01510 long tv_sec; /* seconds */
- 01511 long tv_usec; /* and microseconds */
- 01512 };
- 01513
- 01514 #define RUSAGE_SELF 0
- 01515 #define RUSAGE_CHILDREN -1
- 01516
- 01517 struct rusage {
- 01518 struct timeval ru_utime; /* user time used */
- 01519 struct timeval ru_stime; /* system time used */
- 01520 long ru_maxrss;
- 01521 long ru_ixrss; /* integral shared memory size */
- 01522 long ru_idrss; /* integral unshared data size */
- 01523 long ru_isrss; /* integral unshared stack size */
- 01524 long ru_minflt; /* page reclaims */
- 01525 long ru_majflt; /* page faults */
- 01526 long ru_nswap; /* swaps */
- 01527 long ru_inblock; /* block input operations */
- 01528 long ru_oublock; /* block output operations */
- 01529 long ru_msgsnd; /* messages sent */
- 01530 long ru_msgrcv; /* messages received */
- 01531 long ru_nsignals; /* signals received */
- 01532 long ru_nvcsw; /* voluntary context switches */
- 01533 long ru_nivcsw; /* involuntary context switches */
- 01534 };
- 01535
- 01536 void _getrusage(int who, struct rusage *rusage);
- 01537
- 01538 #elif defined(_POSIX_SOURCE) || defined(__USG)
- 01539
- 01540 struct tms {
- 01541 time_t tms_utime; /* user time */
- 01542 time_t tms_stime; /* system time */
- 01543 time_t tms_cutime; /* user time, children */
- 01544 time_t tms_cstime; /* system time, children */
- 01545 };
- 01546
- 01547 clock_t _times(struct tms *buffer);
- 01548
- 01549 #else /* Version 7 UNIX */
- 01550
- 01551 struct tbuffer {
- 01552 long proc_user_time;
- 01553 long proc_system_time;
- 01554 long child_user_time;
- 01555 long child_system_time;
- 01556 };
- 01557
- 01558 clock_t _times(struct tbuffer *buffer);
- 01559
- 01560 #endif
- 01561
- 01562 clock_t
- 01563 clock(void)
- 01564 {
- 01565 #if defined(__BSD4_2)
- 01566 struct rusage rusage;
- 01567
- 01568 _getrusage(RUSAGE_SELF, &rusage);
- 01569
- 01570 return (((unsigned long)rusage.ru_utime.tv_sec * CLOCKS_PER_SEC)
- 01571 + rusage.ru_utime.tv_usec);
- 01572 #elif defined(_POSIX_SOURCE) || defined(__USG)
- 01573 struct tms tms;
- 01574
- 01575 _times(&tms);
- 01576 /* Assume that time_t can be converted to clock_t for Sys5 */
- 01577 return tms.tms_utime;
- 01578 #else
- 01579 struct tbuffer tbuffer;
- 01580
- 01581 _times(&tbuffer);
- 01582 return tbuffer.proc_user_time;
- 01583 #endif
- 01584 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/ctime.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 01600 /*
- 01601 * ctime - convers the calendar time to a string
- 01602 */
- 01603 /* $Header: ctime.c,v 1.1 89/06/12 15:21:16 eck Exp $ */
- 01604
- 01605 #include <time.h>
- 01606
- 01607 char *
- 01608 ctime(const time_t *timer)
- 01609 {
- 01610 return asctime(localtime(timer));
- 01611 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/difftime.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 01700 /*
- 01701 * difftime - compute the difference between two calendar times
- 01702 */
- 01703 /* $Header: difftime.c,v 1.4 90/09/11 10:18:44 eck Exp $ */
- 01704
- 01705 #include <time.h>
- 01706
- 01707 double
- 01708 difftime(time_t time1, time_t time0)
- 01709 {
- 01710 /* be careful: time_t may be unsigned */
- 01711 if ((time_t)-1 > 0 && time0 > time1) {
- 01712 return - (double) (time0 - time1);
- 01713 } else {
- 01714 return (double)(time1 - time0);
- 01715 }
- 01716 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/div.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 01800 /*
- 01801 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 01802 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 01803 */
- 01804 /* $Header: div.c,v 1.3 90/03/05 13:47:53 eck Exp $ */
- 01805
- 01806 #include <stdlib.h>
- 01807
- 01808 static int tmp = -1;
- 01809
- 01810 div_t
- 01811 div(register int numer, register int denom)
- 01812 {
- 01813 div_t r;
- 01814
- 01815 /* The assignment of tmp should not be optimized !! */
- 01816 if (tmp == -1) {
- 01817 tmp = (tmp / 2 == 0);
- 01818 }
- 01819 if (numer == 0) {
- 01820 r.quot = numer / denom; /* might trap if denom == 0 */
- 01821 r.rem = numer % denom;
- 01822 } else if ( !tmp && ((numer < 0) != (denom < 0))) {
- 01823 r.quot = (numer / denom) + 1;
- 01824 r.rem = numer - (numer / denom + 1) * denom;
- 01825 } else {
- 01826 r.quot = numer / denom;
- 01827 r.rem = numer % denom;
- 01828 }
- 01829 return r;
- 01830 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/errlist.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 01900 /*
- 01901 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 01902 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 01903 */
- 01904 /* $Header: errlist.c,v 1.1 89/05/10 16:22:20 eck Exp $ */
- 01905
- 01906 #include <errno.h>
- 01907
- 01908 static const char unknown[] = "Unknown error";
- 01909
- 01910 const char *_sys_errlist[] = {
- 01911 "Error 0", /* EGENERIC */
- 01912 "Not owner", /* EPERM */
- 01913 "No such file or directory", /* ENOENT */
- 01914 "No such process", /* ESRCH */
- 01915 "Interrupted system call", /* EINTR */
- 01916 "I/O error", /* EIO */
- 01917 "No such device or address", /* ENXIO */
- 01918 "Arg list too long", /* E2BIG */
- 01919 "Exec format error", /* ENOEXEC */
- 01920 "Bad file number", /* EBADF */
- 01921 "No children", /* ECHILD */
- 01922 "No more processes", /* EAGAIN */
- 01923 "Not enough core", /* ENOMEM */
- 01924 "Permission denied", /* EACCES */
- 01925 "Bad address", /* EFAULT */
- 01926 "Block device required", /* ENOTBLK */
- 01927 "Resource busy", /* EBUSY */
- 01928 "File exists", /* EEXIST */
- 01929 "Cross-device link", /* EXDEV */
- 01930 "No such device", /* ENODEV */
- 01931 "Not a directory", /* ENOTDIR */
- 01932 "Is a directory", /* EISDIR */
- 01933 "Invalid argument", /* EINVAL */
- 01934 "File table overflow", /* ENFILE */
- 01935 "Too many open files", /* EMFILE */
- 01936 "Not a typewriter", /* ENOTTY */
- 01937 "Text file busy", /* ETXTBSY */
- 01938 "File too large", /* EFBIG */
- 01939 "No space left on device", /* ENOSPC */
- 01940 "Illegal seek", /* ESPIPE */
- 01941 "Read-only file system", /* EROFS */
- 01942 "Too many links", /* EMLINK */
- 01943 "Broken pipe", /* EPIPE */
- 01944 "Math argument", /* EDOM */
- 01945 "Result too large", /* ERANGE */
- 01946 "Resource deadlock avoided", /* EDEADLK */
- 01947 "File name too long", /* ENAMETOOLONG */
- 01948 "No locks available", /* ENOLCK */
- 01949 "Function not implemented", /* ENOSYS */
- 01950 "Directory not empty", /* ENOTEMPTY */
- 01951 unknown, /* 40 */
- 01952 unknown, /* 41 */
- 01953 unknown, /* 42 */
- 01954 unknown, /* 43 */
- 01955 unknown, /* 44 */
- 01956 unknown, /* 45 */
- 01957 unknown, /* 46 */
- 01958 unknown, /* 47 */
- 01959 unknown, /* 48 */
- 01960 unknown, /* 49 */
- 01961 "Invalid packet size", /* EPACKSIZE */
- 01962 "Not enough buffers left", /* EOUTOFBUFS */
- 01963 "Illegal ioctl for device", /* EBADIOCTL */
- 01964 "Bad mode for ioctl", /* EBADMODE */
- 01965 "Would block", /* EWOULDBLOCK */
- 01966 "Bad destination address", /* EBADDEST */
- 01967 "Destination not reachable", /* EDSTNOTRCH */
- 01968 "Already connected", /* EISCONN */
- 01969 "Address in use", /* EADDRINUSE */
- 01970 "Connection refused", /* ECONNREFUSED */
- 01971 "Connection reset", /* ECONNRESET */
- 01972 "Connection timed out", /* ETIMEDOUT */
- 01973 "Urgent data present", /* EURG */
- 01974 "No urgent data present", /* ENOURG */
- 01975 "No connection", /* ENOTCONN */
- 01976 "Already shutdown", /* ESHUTDOWN */
- 01977 "No such connection", /* ENOCONN */
- 01978 };
- 01979
- 01980 const int _sys_nerr = sizeof(_sys_errlist) / sizeof(_sys_errlist[0]);
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/exit.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 02000 /*
- 02001 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 02002 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 02003 */
- 02004 /* $Header: exit.c,v 1.3 90/01/22 13:00:04 eck Exp $ */
- 02005
- 02006 #include <stdio.h>
- 02007 #include <stdlib.h>
- 02008
- 02009 #define NEXITS 32
- 02010
- 02011 void (*__functab[NEXITS])(void);
- 02012 int __funccnt = 0;
- 02013
- 02014 extern void _exit(int);
- 02015
- 02016 /* only flush output buffers when necessary */
- 02017 int (*_clean)(void) = NULL;
- 02018
- 02019 static void
- 02020 _calls(void)
- 02021 {
- 02022 register int i = __funccnt;
- 02023
- 02024 /* "Called in reversed order of their registration" */
- 02025 while (--i >= 0)
- 02026 (*__functab[i])();
- 02027 }
- 02029 void
- 02030 exit(int status)
- 02031 {
- 02032 _calls();
- 02033 if (_clean) _clean();
- 02034 _exit(status) ;
- 02035 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/ext_comp.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 02100 /*
- 02101 (c) copyright 1989 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 02102 See the copyright notice in the ACK home directory, in the file "Copyright".
- 02103 */
- 02104
- 02105 /* $Id: ext_comp.c,v 1.10 1994/06/24 11:53:36 ceriel Exp $ */
- 02106
- 02107 /* extended precision arithmetic for the strtod() and cvt() routines */
- 02108
- 02109 /* This may require some more work when long doubles get bigger than 8
- 02110 bytes. In this case, these routines may become obsolete. ???
- 02111 */
- 02112
- 02113 #include "ext_fmt.h"
- 02114 #include <float.h>
- 02115 #include <errno.h>
- 02116 #include <ctype.h>
- 02117
- 02118 static int b64_add(struct mantissa *e1, struct mantissa *e2);
- 02119 static b64_sft(struct mantissa *e1, int n);
- 02120
- 02121 static
- 02122 mul_ext(struct EXTEND *e1, struct EXTEND *e2, struct EXTEND *e3)
- 02123 {
- 02124 /* Multiply the extended numbers e1 and e2, and put the
- 02125 result in e3.
- 02126 */
- 02127 register int i,j; /* loop control */
- 02128 unsigned short mp[4];
- 02129 unsigned short mc[4];
- 02130 unsigned short result[8]; /* result */
- 02131
- 02132 register unsigned short *pres;
- 02133
- 02134 /* first save the sign (XOR) */
- 02135 e3->sign = e1->sign ^ e2->sign;
- 02136
- 02137 /* compute new exponent */
- 02138 e3->exp = e1->exp + e2->exp + 1;
- 02139
- 02140 /* check for overflow/underflow ??? */
- 02141
- 02142 /* 128 bit multiply of mantissas */
- 02143
- 02144 /* assign unknown long formats */
- 02145 /* to known unsigned word formats */
- 02146 mp[0] = e1->m1 >> 16;
- 02147 mp[1] = (unsigned short) e1->m1;
- 02148 mp[2] = e1->m2 >> 16;
- 02149 mp[3] = (unsigned short) e1->m2;
- 02150 mc[0] = e2->m1 >> 16;
- 02151 mc[1] = (unsigned short) e2->m1;
- 02152 mc[2] = e2->m2 >> 16;
- 02153 mc[3] = (unsigned short) e2->m2;
- 02154 for (i = 8; i--;) {
- 02155 result[i] = 0;
- 02156 }
- 02157 /*
- 02158 * fill registers with their components
- 02159 */
- 02160 for(i=4, pres = &result[4];i--;pres--) if (mp[i]) {
- 02161 unsigned short k = 0;
- 02162 unsigned long mpi = mp[i];
- 02163 for(j=4;j--;) {
- 02164 unsigned long tmp = (unsigned long)pres[j] + k;
- 02165 if (mc[j]) tmp += mpi * mc[j];
- 02166 pres[j] = tmp;
- 02167 k = tmp >> 16;
- 02168 }
- 02169 pres[-1] = k;
- 02170 }
- 02171
- 02172 if (! (result[0] & 0x8000)) {
- 02173 e3->exp--;
- 02174 for (i = 0; i <= 3; i++) {
- 02175 result[i] <<= 1;
- 02176 if (result[i+1]&0x8000) result[i] |= 1;
- 02177 }
- 02178 result[4] <<= 1;
- 02179 }
- 02180 /*
- 02181 * combine the registers to a total
- 02182 */
- 02183 e3->m1 = ((unsigned long)(result[0]) << 16) + result[1];
- 02184 e3->m2 = ((unsigned long)(result[2]) << 16) + result[3];
- 02185 if (result[4] & 0x8000) {
- 02186 if (++e3->m2 == 0) {
- 02187 if (++e3->m1 == 0) {
- 02188 e3->m1 = 0x80000000;
- 02189 e3->exp++;
- 02190 }
- 02191 }
- 02192 }
- 02193 }
- 02195 static
- 02196 add_ext(struct EXTEND *e1, struct EXTEND *e2, struct EXTEND *e3)
- 02197 {
- 02198 /* Add two extended numbers e1 and e2, and put the result
- 02199 in e3
- 02200 */
- 02201 struct EXTEND ce2;
- 02202 int diff;
- 02203
- 02204 if ((e2->m1 | e2->m2) == 0L) {
- 02205 *e3 = *e1;
- 02206 return;
- 02207 }
- 02208 if ((e1->m1 | e1->m2) == 0L) {
- 02209 *e3 = *e2;
- 02210 return;
- 02211 }
- 02212 ce2 = *e2;
- 02213 *e3 = *e1;
- 02214 e1 = &ce2;
- 02215
- 02216 /* adjust mantissas to equal power */
- 02217 diff = e3->exp - e1->exp;
- 02218 if (diff < 0) {
- 02219 diff = -diff;
- 02220 e3->exp += diff;
- 02221 b64_sft(&(e3->mantissa), diff);
- 02222 }
- 02223 else if (diff > 0) {
- 02224 e1->exp += diff;
- 02225 b64_sft(&(e1->mantissa), diff);
- 02226 }
- 02227 if (e1->sign != e3->sign) {
- 02228 /* e3 + e1 = e3 - (-e1) */
- 02229 if (e1->m1 > e3->m1 ||
- 02230 (e1->m1 == e3->m1 && e1->m2 > e3->m2)) {
- 02231 /* abs(e1) > abs(e3) */
- 02232 if (e3->m2 > e1->m2) {
- 02233 e1->m1 -= 1; /* carry in */
- 02234 }
- 02235 e1->m1 -= e3->m1;
- 02236 e1->m2 -= e3->m2;
- 02237 *e3 = *e1;
- 02238 }
- 02239 else {
- 02240 if (e1->m2 > e3->m2)
- 02241 e3->m1 -= 1; /* carry in */
- 02242 e3->m1 -= e1->m1;
- 02243 e3->m2 -= e1->m2;
- 02244 }
- 02245 }
- 02246 else {
- 02247 if (b64_add(&e3->mantissa,&e1->mantissa)) {/* addition carry */
- 02248 b64_sft(&e3->mantissa,1);/* shift mantissa one bit RIGHT */
- 02249 e3->m1 |= 0x80000000L; /* set max bit */
- 02250 e3->exp++; /* increase the exponent */
- 02251 }
- 02252 }
- 02253 if ((e3->m2 | e3->m1) != 0L) {
- 02254 /* normalize */
- 02255 if (e3->m1 == 0L) {
- 02256 e3->m1 = e3->m2; e3->m2 = 0L; e3->exp -= 32;
- 02257 }
- 02258 if (!(e3->m1 & 0x80000000)) {
- 02259 unsigned long l = 0x40000000;
- 02260 int cnt = -1;
- 02261
- 02262 while (! (l & e3->m1)) {
- 02263 l >>= 1; cnt--;
- 02264 }
- 02265 e3->exp += cnt;
- 02266 b64_sft(&(e3->mantissa), cnt);
- 02267 }
- 02268 }
- 02269 }
- 02271 static int
- 02272 cmp_ext(struct EXTEND *e1, struct EXTEND *e2)
- 02273 {
- 02274 struct EXTEND tmp;
- 02275
- 02276 e2->sign = ! e2->sign;
- 02277 add_ext(e1, e2, &tmp);
- 02278 e2->sign = ! e2->sign;
- 02279 if (tmp.m1 == 0 && tmp.m2 == 0) return 0;
- 02280 if (tmp.sign) return -1;
- 02281 return 1;
- 02282 }
- 02284 static
- 02285 b64_sft(struct mantissa *e1, int n)
- 02286 {
- 02287 if (n > 0) {
- 02288 if (n > 63) {
- 02289 e1->l_32 = 0;
- 02290 e1->h_32 = 0;
- 02291 return;
- 02292 }
- 02293 if (n >= 32) {
- 02294 e1->l_32 = e1->h_32;
- 02295 e1->h_32 = 0;
- 02296 n -= 32;
- 02297 }
- 02298 if (n > 0) {
- 02299 e1->l_32 >>= n;
- 02300 if (e1->h_32 != 0) {
- 02301 e1->l_32 |= (e1->h_32 << (32 - n));
- 02302 e1->h_32 >>= n;
- 02303 }
- 02304 }
- 02305 return;
- 02306 }
- 02307 n = -n;
- 02308 if (n > 0) {
- 02309 if (n > 63) {
- 02310 e1->l_32 = 0;
- 02311 e1->h_32 = 0;
- 02312 return;
- 02313 }
- 02314 if (n >= 32) {
- 02315 e1->h_32 = e1->l_32;
- 02316 e1->l_32 = 0;
- 02317 n -= 32;
- 02318 }
- 02319 if (n > 0) {
- 02320 e1->h_32 <<= n;
- 02321 if (e1->l_32 != 0) {
- 02322 e1->h_32 |= (e1->l_32 >> (32 - n));
- 02323 e1->l_32 <<= n;
- 02324 }
- 02325 }
- 02326 }
- 02327 }
- 02329 static int
- 02330 b64_add(struct mantissa *e1, struct mantissa *e2)
- 02331 /*
- 02332 * pointers to 64 bit 'registers'
- 02333 */
- 02334 {
- 02335 register int overflow;
- 02336 int carry;
- 02337
- 02338 /* add higher pair of 32 bits */
- 02339 overflow = ((unsigned long) 0xFFFFFFFF - e1->h_32 < e2->h_32);
- 02340 e1->h_32 += e2->h_32;
- 02341
- 02342 /* add lower pair of 32 bits */
- 02343 carry = ((unsigned long) 0xFFFFFFFF - e1->l_32 < e2->l_32);
- 02344 e1->l_32 += e2->l_32;
- 02345 if ((carry) && (++e1->h_32 == 0))
- 02346 return(1); /* had a 64 bit overflow */
- 02347 else
- 02348 return(overflow); /* return status from higher add */
- 02349 }
- 02351 /* The following tables can be computed with the following bc(1)
- 02352 program:
- 02353
- 02354 obase=16
- 02355 scale=0
- 02356 define t(x){
- 02357 auto a, b, c
- 02358 a=2;b=1;c=2^32;n=1
- 02359 while(a<x) {
- 02360 b=a;n+=n;a*=a
- 02361 }
- 02362 n/=2
- 02363 a=b
- 02364 while(b<x) {
- 02365 a=b;b*=c;n+=32
- 02366 }
- 02367 n-=32
- 02368 b=a
- 02369 while(a<x) {
- 02370 b=a;a+=a;n+=1
- 02371 }
- 02372 n-=1
- 02373 x*=16^16
- 02374 b=x%a
- 02375 x/=a
- 02376 if(a<=(2*b)) x+=1
- 02377 obase=10
- 02378 n
- 02379 obase=16
- 02380 return(x)
- 02381 }
- 02382 for (i=1;i<28;i++) {
- 02383 t(10^i)
- 02384 }
- 02385 0
- 02386 for (i=1;i<20;i++) {
- 02387 t(10^(28*i))
- 02388 }
- 02389 0
- 02390 define r(x){
- 02391 auto a, b, c
- 02392 a=2;b=1;c=2^32;n=1
- 02393 while(a<x) {
- 02394 b=a;n+=n;a*=a
- 02395 }
- 02396 n/=2
- 02397 a=b
- 02398 while(b<x) {
- 02399 a=b;b*=c;n+=32
- 02400 }
- 02401 n-=32
- 02402 b=a
- 02403 while(a<x) {
- 02404 b=a;a+=a;n+=1
- 02405 }
- 02406 a=b
- 02407 a*=16^16
- 02408 b=a%x
- 02409 a/=x
- 02410 if(x<=(2*b)) a+=1
- 02411 obase=10
- 02412 -n
- 02413 obase=16
- 02414 return(a)
- 02415 }
- 02416 for (i=1;i<28;i++) {
- 02417 r(10^i)
- 02418 }
- 02419 0
- 02420 for (i=1;i<20;i++) {
- 02421 r(10^(28*i))
- 02422 }
- 02423 0
- 02424
- 02425 */
- 02426 static struct EXTEND ten_powers[] = { /* representation of 10 ** i */
- 02427 { 0, 0, 0x80000000, 0 },
- 02428 { 0, 3, 0xA0000000, 0 },
- 02429 { 0, 6, 0xC8000000, 0 },
- 02430 { 0, 9, 0xFA000000, 0 },
- 02431 { 0, 13, 0x9C400000, 0 },
- 02432 { 0, 16, 0xC3500000, 0 },
- 02433 { 0, 19, 0xF4240000, 0 },
- 02434 { 0, 23, 0x98968000, 0 },
- 02435 { 0, 26, 0xBEBC2000, 0 },
- 02436 { 0, 29, 0xEE6B2800, 0 },
- 02437 { 0, 33, 0x9502F900, 0 },
- 02438 { 0, 36, 0xBA43B740, 0 },
- 02439 { 0, 39, 0xE8D4A510, 0 },
- 02440 { 0, 43, 0x9184E72A, 0 },
- 02441 { 0, 46, 0xB5E620F4, 0x80000000 },
- 02442 { 0, 49, 0xE35FA931, 0xA0000000 },
- 02443 { 0, 53, 0x8E1BC9BF, 0x04000000 },
- 02444 { 0, 56, 0xB1A2BC2E, 0xC5000000 },
- 02445 { 0, 59, 0xDE0B6B3A, 0x76400000 },
- 02446 { 0, 63, 0x8AC72304, 0x89E80000 },
- 02447 { 0, 66, 0xAD78EBC5, 0xAC620000 },
- 02448 { 0, 69, 0xD8D726B7, 0x177A8000 },
- 02449 { 0, 73, 0x87867832, 0x6EAC9000 },
- 02450 { 0, 76, 0xA968163F, 0x0A57B400 },
- 02451 { 0, 79, 0xD3C21BCE, 0xCCEDA100 },
- 02452 { 0, 83, 0x84595161, 0x401484A0 },
- 02453 { 0, 86, 0xA56FA5B9, 0x9019A5C8 },
- 02454 { 0, 89, 0xCECB8F27, 0xF4200F3A }
- 02455 };
- 02456 static struct EXTEND big_ten_powers[] = { /* representation of 10 ** (28*i) */
- 02457 { 0, 0, 0x80000000, 0 },
- 02458 { 0, 93, 0x813F3978, 0xF8940984 },
- 02459 { 0, 186, 0x82818F12, 0x81ED44A0 },
- 02460 { 0, 279, 0x83C7088E, 0x1AAB65DB },
- 02461 { 0, 372, 0x850FADC0, 0x9923329E },
- 02462 { 0, 465, 0x865B8692, 0x5B9BC5C2 },
- 02463 { 0, 558, 0x87AA9AFF, 0x79042287 },
- 02464 { 0, 651, 0x88FCF317, 0xF22241E2 },
- 02465 { 0, 744, 0x8A5296FF, 0xE33CC930 },
- 02466 { 0, 837, 0x8BAB8EEF, 0xB6409C1A },
- 02467 { 0, 930, 0x8D07E334, 0x55637EB3 },
- 02468 { 0, 1023, 0x8E679C2F, 0x5E44FF8F },
- 02469 { 0, 1116, 0x8FCAC257, 0x558EE4E6 },
- 02470 { 0, 1209, 0x91315E37, 0xDB165AA9 },
- 02471 { 0, 1302, 0x929B7871, 0xDE7F22B9 },
- 02472 { 0, 1395, 0x940919BB, 0xD4620B6D },
- 02473 { 0, 1488, 0x957A4AE1, 0xEBF7F3D4 },
- 02474 { 0, 1581, 0x96EF14C6, 0x454AA840 },
- 02475 { 0, 1674, 0x98678061, 0x27ECE4F5 },
- 02476 { 0, 1767, 0x99E396C1, 0x3A3ACFF2 }
- 02477 };
- 02478
- 02479 static struct EXTEND r_ten_powers[] = { /* representation of 10 ** -i */
- 02480 { 0, 0, 0x80000000, 0 },
- 02481 { 0, -4, 0xCCCCCCCC, 0xCCCCCCCD },
- 02482 { 0, -7, 0xA3D70A3D, 0x70A3D70A },
- 02483 { 0, -10, 0x83126E97, 0x8D4FDF3B },
- 02484 { 0, -14, 0xD1B71758, 0xE219652C },
- 02485 { 0, -17, 0xA7C5AC47, 0x1B478423 },
- 02486 { 0, -20, 0x8637BD05, 0xAF6C69B6 },
- 02487 { 0, -24, 0xD6BF94D5, 0xE57A42BC },
- 02488 { 0, -27, 0xABCC7711, 0x8461CEFD },
- 02489 { 0, -30, 0x89705F41, 0x36B4A597 },
- 02490 { 0, -34, 0xDBE6FECE, 0xBDEDD5BF },
- 02491 { 0, -37, 0xAFEBFF0B, 0xCB24AAFF },
- 02492 { 0, -40, 0x8CBCCC09, 0x6F5088CC },
- 02493 { 0, -44, 0xE12E1342, 0x4BB40E13 },
- 02494 { 0, -47, 0xB424DC35, 0x095CD80F },
- 02495 { 0, -50, 0x901D7CF7, 0x3AB0ACD9 },
- 02496 { 0, -54, 0xE69594BE, 0xC44DE15B },
- 02497 { 0, -57, 0xB877AA32, 0x36A4B449 },
- 02498 { 0, -60, 0x9392EE8E, 0x921D5D07 },
- 02499 { 0, -64, 0xEC1E4A7D, 0xB69561A5 },
- 02500 { 0, -67, 0xBCE50864, 0x92111AEB },
- 02501 { 0, -70, 0x971DA050, 0x74DA7BEF },
- 02502 { 0, -74, 0xF1C90080, 0xBAF72CB1 },
- 02503 { 0, -77, 0xC16D9A00, 0x95928A27 },
- 02504 { 0, -80, 0x9ABE14CD, 0x44753B53 },
- 02505 { 0, -84, 0xF79687AE, 0xD3EEC551 },
- 02506 { 0, -87, 0xC6120625, 0x76589DDB },
- 02507 { 0, -90, 0x9E74D1B7, 0x91E07E48 }
- 02508 };
- 02509
- 02510 static struct EXTEND r_big_ten_powers[] = { /* representation of 10 ** -(28*i) */
- 02511 { 0, 0, 0x80000000, 0 },
- 02512 { 0, -94, 0xFD87B5F2, 0x8300CA0E },
- 02513 { 0, -187, 0xFB158592, 0xBE068D2F },
- 02514 { 0, -280, 0xF8A95FCF, 0x88747D94 },
- 02515 { 0, -373, 0xF64335BC, 0xF065D37D },
- 02516 { 0, -466, 0xF3E2F893, 0xDEC3F126 },
- 02517 { 0, -559, 0xF18899B1, 0xBC3F8CA2 },
- 02518 { 0, -652, 0xEF340A98, 0x172AACE5 },
- 02519 { 0, -745, 0xECE53CEC, 0x4A314EBE },
- 02520 { 0, -838, 0xEA9C2277, 0x23EE8BCB },
- 02521 { 0, -931, 0xE858AD24, 0x8F5C22CA },
- 02522 { 0, -1024, 0xE61ACF03, 0x3D1A45DF },
- 02523 { 0, -1117, 0xE3E27A44, 0x4D8D98B8 },
- 02524 { 0, -1210, 0xE1AFA13A, 0xFBD14D6E },
- 02525 { 0, -1303, 0xDF82365C, 0x497B5454 },
- 02526 { 0, -1396, 0xDD5A2C3E, 0xAB3097CC },
- 02527 { 0, -1489, 0xDB377599, 0xB6074245 },
- 02528 { 0, -1582, 0xD91A0545, 0xCDB51186 },
- 02529 { 0, -1675, 0xD701CE3B, 0xD387BF48 },
- 02530 { 0, -1768, 0xD4EEC394, 0xD6258BF8 }
- 02531 };
- 02532
- 02533 #define TP (int)(sizeof(ten_powers)/sizeof(ten_powers[0]))
- 02534 #define BTP (int)(sizeof(big_ten_powers)/sizeof(big_ten_powers[0]))
- 02535 #define MAX_EXP (TP * BTP - 1)
- 02536
- 02537 static
- 02538 add_exponent(struct EXTEND *e, int exp)
- 02539 {
- 02540 int neg = exp < 0;
- 02541 int divsz, modsz;
- 02542 struct EXTEND x;
- 02543
- 02544 if (neg) exp = -exp;
- 02545 divsz = exp / TP;
- 02546 modsz = exp % TP;
- 02547 if (neg) {
- 02548 mul_ext(e, &r_ten_powers[modsz], &x);
- 02549 mul_ext(&x, &r_big_ten_powers[divsz], e);
- 02550 }
- 02551 else {
- 02552 mul_ext(e, &ten_powers[modsz], &x);
- 02553 mul_ext(&x, &big_ten_powers[divsz], e);
- 02554 }
- 02555 }
- 02557 _str_ext_cvt(const char *s, char **ss, struct EXTEND *e)
- 02558 {
- 02559 /* Like strtod, but for extended precision */
- 02560 register int c;
- 02561 int dotseen = 0;
- 02562 int digitseen = 0;
- 02563 int exp = 0;
- 02564
- 02565 if (ss) *ss = (char *)s;
- 02566 while (isspace(*s)) s++;
- 02567
- 02568 e->sign = 0;
- 02569 e->exp = 0;
- 02570 e->m1 = e->m2 = 0;
- 02571
- 02572 c = *s;
- 02573 switch(c) {
- 02574 case '-':
- 02575 e->sign = 1;
- 02576 case '+':
- 02577 s++;
- 02578 }
- 02579 while (c = *s++, isdigit(c) || (c == '.' && ! dotseen++)) {
- 02580 if (c == '.') continue;
- 02581 digitseen = 1;
- 02582 if (e->m1 <= (unsigned long)(0xFFFFFFFF)/10) {
- 02583 struct mantissa a1;
- 02584
- 02585 a1 = e->mantissa;
- 02586 b64_sft(&(e->mantissa), -3);
- 02587 b64_sft(&a1, -1);
- 02588 b64_add(&(e->mantissa), &a1);
- 02589 a1.h_32 = 0;
- 02590 a1.l_32 = c - '0';
- 02591 b64_add(&(e->mantissa), &a1);
- 02592 }
- 02593 else exp++;
- 02594 if (dotseen) exp--;
- 02595 }
- 02596 if (! digitseen) return;
- 02597
- 02598 if (ss) *ss = (char *)s - 1;
- 02599
- 02600 if (c == 'E' || c == 'e') {
- 02601 int exp1 = 0;
- 02602 int sign = 1;
- 02603 int exp_overflow = 0;
- 02604
- 02605 switch(*s) {
- 02606 case '-':
- 02607 sign = -1;
- 02608 case '+':
- 02609 s++;
- 02610 }
- 02611 if (c = *s, isdigit(c)) {
- 02612 do {
- 02613 int tmp;
- 02614
- 02615 exp1 = 10 * exp1 + (c - '0');
- 02616 if ((tmp = sign * exp1 + exp) > MAX_EXP ||
- 02617 tmp < -MAX_EXP) {
- 02618 exp_overflow = 1;
- 02619 }
- 02620 } while (c = *++s, isdigit(c));
- 02621 if (ss) *ss = (char *)s;
- 02622 }
- 02623 exp += sign * exp1;
- 02624 if (exp_overflow) {
- 02625 exp = sign * MAX_EXP;
- 02626 if (e->m1 != 0 || e->m2 != 0) errno = ERANGE;
- 02627 }
- 02628 }
- 02629 if (e->m1 == 0 && e->m2 == 0) return;
- 02630 e->exp = 63;
- 02631 while (! (e->m1 & 0x80000000)) {
- 02632 b64_sft(&(e->mantissa),-1);
- 02633 e->exp--;
- 02634 }
- 02635 add_exponent(e, exp);
- 02636 }
- 02638 #include <math.h>
- 02639
- 02640 static
- 02641 ten_mult(struct EXTEND *e)
- 02642 {
- 02643 struct EXTEND e1 = *e;
- 02644
- 02645 e1.exp++;
- 02646 e->exp += 3;
- 02647 add_ext(e, &e1, e);
- 02648 }
- 02650 #define NDIGITS 128
- 02651 #define NSIGNIFICANT 19
- 02652
- 02653 char *
- 02654 _ext_str_cvt(struct EXTEND *e, int ndigit, int *decpt, int *sign, int ecvtflag)
- 02655 {
- 02656 /* Like cvt(), but for extended precision */
- 02657
- 02658 static char buf[NDIGITS+1];
- 02659 struct EXTEND m;
- 02660 register char *p = buf;
- 02661 register char *pe;
- 02662 int findex = 0;
- 02663
- 02664 if (ndigit < 0) ndigit = 0;
- 02665 if (ndigit > NDIGITS) ndigit = NDIGITS;
- 02666 pe = &buf[ndigit];
- 02667 buf[0] = ' ';
- 02668
- 02669 *sign = 0;
- 02670 if (e->sign) {
- 02671 *sign = 1;
- 02672 e->sign = 0;
- 02673 }
- 02674
- 02675 *decpt = 0;
- 02676 if (e->m1 != 0) {
- 02677 register struct EXTEND *pp = &big_ten_powers[1];
- 02678
- 02679 while(cmp_ext(e,pp) >= 0) {
- 02680 pp++;
- 02681 findex = pp - big_ten_powers;
- 02682 if (findex >= BTP) break;
- 02683 }
- 02684 pp--;
- 02685 findex = pp - big_ten_powers;
- 02686 mul_ext(e,&r_big_ten_powers[findex],e);
- 02687 *decpt += findex * TP;
- 02688 pp = &ten_powers[1];
- 02689 while(pp < &ten_powers[TP] && cmp_ext(e, pp) >= 0) pp++;
- 02690 pp--;
- 02691 findex = pp - ten_powers;
- 02692 *decpt += findex;
- 02693
- 02694 if (cmp_ext(e, &ten_powers[0]) < 0) {
- 02695 pp = &r_big_ten_powers[1];
- 02696 while(cmp_ext(e,pp) < 0) pp++;
- 02697 pp--;
- 02698 findex = pp - r_big_ten_powers;
- 02699 mul_ext(e, &big_ten_powers[findex], e);
- 02700 *decpt -= findex * TP;
- 02701 /* here, value >= 10 ** -28 */
- 02702 ten_mult(e);
- 02703 (*decpt)--;
- 02704 pp = &r_ten_powers[0];
- 02705 while(cmp_ext(e, pp) < 0) pp++;
- 02706 findex = pp - r_ten_powers;
- 02707 mul_ext(e, &ten_powers[findex], e);
- 02708 *decpt -= findex;
- 02709 findex = 0;
- 02710 }
- 02711 (*decpt)++; /* because now value in [1.0, 10.0) */
- 02712 }
- 02713 if (! ecvtflag) {
- 02714 /* for fcvt() we need ndigit digits behind the dot */
- 02715 pe += *decpt;
- 02716 if (pe > &buf[NDIGITS]) pe = &buf[NDIGITS];
- 02717 }
- 02718 m.exp = -62;
- 02719 m.sign = 0;
- 02720 m.m1 = 0xA0000000;
- 02721 m.m2 = 0;
- 02722 while (p <= pe) {
- 02723 struct EXTEND oneminm;
- 02724
- 02725 if (p - pe > NSIGNIFICANT) {
- 02726 findex = 0;
- 02727 e->m1 = 0;
- 02728 }
- 02729 if (findex) {
- 02730 struct EXTEND tc, oldtc;
- 02731 int count = 0;
- 02732
- 02733 oldtc.exp = 0;
- 02734 oldtc.sign = 0;
- 02735 oldtc.m1 = 0;
- 02736 oldtc.m2 = 0;
- 02737 tc = ten_powers[findex];
- 02738 while (cmp_ext(e, &tc) >= 0) {
- 02739 oldtc = tc;
- 02740 add_ext(&tc, &ten_powers[findex], &tc);
- 02741 count++;
- 02742 }
- 02743 *p++ = count + '0';
- 02744 oldtc.sign = 1;
- 02745 add_ext(e, &oldtc, e);
- 02746 findex--;
- 02747 continue;
- 02748 }
- 02749 if (e->m1) {
- 02750 m.sign = 1;
- 02751 add_ext(&ten_powers[0], &m, &oneminm);
- 02752 m.sign = 0;
- 02753 if (e->exp >= 0) {
- 02754 struct EXTEND x;
- 02755
- 02756 x.m2 = 0; x.exp = e->exp;
- 02757 x.sign = 1;
- 02758 x.m1 = e->m1>>(31-e->exp);
- 02759 *p++ = (x.m1) + '0';
- 02760 x.m1 = x.m1 << (31-e->exp);
- 02761 add_ext(e, &x, e);
- 02762 }
- 02763 else *p++ = '0';
- 02764 /* Check that remainder is still significant */
- 02765 if (cmp_ext(&m, e) > 0 || cmp_ext(e, &oneminm) > 0) {
- 02766 if (e->m1 && e->exp >= -1) *(p-1) += 1;
- 02767 e->m1 = 0;
- 02768 continue;
- 02769 }
- 02770 ten_mult(&m);
- 02771 ten_mult(e);
- 02772 }
- 02773 else *p++ = '0';
- 02774 }
- 02775 if (pe >= buf) {
- 02776 p = pe;
- 02777 *p += 5; /* round of at the end */
- 02778 while (*p > '9') {
- 02779 *p = '0';
- 02780 if (p > buf) ++*--p;
- 02781 else {
- 02782 *p = '1';
- 02783 ++*decpt;
- 02784 if (! ecvtflag) {
- 02785 /* maybe add another digit at the end,
- 02786 because the point was shifted right
- 02787 */
- 02788 if (pe > buf) *pe = '0';
- 02789 pe++;
- 02790 }
- 02791 }
- 02792 }
- 02793 *pe = ' ';
- 02794 }
- 02795 return buf;
- 02796 }
- 02798 _dbl_ext_cvt(double value, struct EXTEND *e)
- 02799 {
- 02800 /* Convert double to extended
- 02801 */
- 02802 int exponent;
- 02803
- 02804 value = frexp(value, &exponent);
- 02805 e->sign = value < 0.0;
- 02806 if (e->sign) value = -value;
- 02807 e->exp = exponent - 1;
- 02808 value *= 4294967296.0;
- 02809 e->m1 = value;
- 02810 value -= e->m1;
- 02811 value *= 4294967296.0;
- 02812 e->m2 = value;
- 02813 }
- 02815 static struct EXTEND max_d;
- 02816
- 02817 double
- 02818 _ext_dbl_cvt(struct EXTEND *e)
- 02819 {
- 02820 /* Convert extended to double
- 02821 */
- 02822 double f;
- 02823 int sign = e->sign;
- 02824
- 02825 e->sign = 0;
- 02826 if (e->m1 == 0 && e->m2 == 0) {
- 02827 return 0.0;
- 02828 }
- 02829 if (max_d.exp == 0) {
- 02830 _dbl_ext_cvt(DBL_MAX, &max_d);
- 02831 }
- 02832 if (cmp_ext(&max_d, e) < 0) {
- 02833 f = HUGE_VAL;
- 02834 errno = ERANGE;
- 02835 }
- 02836 else f = ldexp((double)e->m1*4294967296.0 + (double)e->m2, e->exp-63);
- 02837 if (sign) f = -f;
- 02838 if (f == 0.0 && (e->m1 != 0 || e->m2 != 0)) {
- 02839 errno = ERANGE;
- 02840 }
- 02841 return f;
- 02842 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/getenv.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 02900 /*
- 02901 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 02902 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 02903 */
- 02904 /* $Header: getenv.c,v 1.4 91/04/24 12:18:03 ceriel Exp $ */
- 02905
- 02906 #include <stdlib.h>
- 02907
- 02908 extern const char **_penvp;
- 02909
- 02910 char *
- 02911 getenv(const char *name)
- 02912 {
- 02913 register const char **v = _penvp;
- 02914 register const char *p, *q;
- 02915
- 02916 if (v == NULL || name == NULL)
- 02917 return (char *)NULL;
- 02918 while ((p = *v++) != NULL) {
- 02919 q = name;
- 02920 while (*q && (*q == *p++))
- 02921 q++;
- 02922 if (*q || (*p != '='))
- 02923 continue;
- 02924 return (char *)p + 1;
- 02925 }
- 02926 return (char *)NULL;
- 02927 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/gmtime.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 03000 /*
- 03001 * gmtime - convert the calendar time into broken down time
- 03002 */
- 03003 /* $Header: gmtime.c,v 1.4 91/04/22 13:20:27 ceriel Exp $ */
- 03004
- 03005 #include <time.h>
- 03006 #include <limits.h>
- 03007 #include "loc_time.h"
- 03008
- 03009 struct tm *
- 03010 gmtime(register const time_t *timer)
- 03011 {
- 03012 static struct tm br_time;
- 03013 register struct tm *timep = &br_time;
- 03014 time_t time = *timer;
- 03015 register unsigned long dayclock, dayno;
- 03016 int year = EPOCH_YR;
- 03017
- 03018 dayclock = (unsigned long)time % SECS_DAY;
- 03019 dayno = (unsigned long)time / SECS_DAY;
- 03020
- 03021 timep->tm_sec = dayclock % 60;
- 03022 timep->tm_min = (dayclock % 3600) / 60;
- 03023 timep->tm_hour = dayclock / 3600;
- 03024 timep->tm_wday = (dayno + 4) % 7; /* day 0 was a thursday */
- 03025 while (dayno >= YEARSIZE(year)) {
- 03026 dayno -= YEARSIZE(year);
- 03027 year++;
- 03028 }
- 03029 timep->tm_year = year - YEAR0;
- 03030 timep->tm_yday = dayno;
- 03031 timep->tm_mon = 0;
- 03032 while (dayno >= _ytab[LEAPYEAR(year)][timep->tm_mon]) {
- 03033 dayno -= _ytab[LEAPYEAR(year)][timep->tm_mon];
- 03034 timep->tm_mon++;
- 03035 }
- 03036 timep->tm_mday = dayno + 1;
- 03037 timep->tm_isdst = 0;
- 03038
- 03039 return timep;
- 03040 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/isalnum.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 03100 #include <ctype.h>
- 03101
- 03102 int (isalnum)(int c) {
- 03103 return isalnum(c);
- 03104 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/isalpha.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 03200 #include <ctype.h>
- 03201
- 03202 int (isalpha)(int c) {
- 03203 return isalpha(c);
- 03204 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/isascii.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 03300 #include <ctype.h>
- 03301
- 03302 int (isascii)(int c) {
- 03303 return isascii(c);
- 03304 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/iscntrl.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 03400 #include <ctype.h>
- 03401
- 03402 int (iscntrl)(int c) {
- 03403 return iscntrl(c);
- 03404 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/isdigit.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 03500 #include <ctype.h>
- 03501
- 03502 int (isdigit)(int c) {
- 03503 return isdigit(c);
- 03504 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/isgraph.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 03600 #include <ctype.h>
- 03601
- 03602 int (isgraph)(int c) {
- 03603 return isgraph(c);
- 03604 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/islower.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 03700 #include <ctype.h>
- 03701
- 03702 int (islower)(int c) {
- 03703 return islower(c);
- 03704 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/isprint.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 03800 #include <ctype.h>
- 03801
- 03802 int (isprint)(int c) {
- 03803 return isprint(c);
- 03804 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/ispunct.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 03900 #include <ctype.h>
- 03901
- 03902 int (ispunct)(int c) {
- 03903 return ispunct(c);
- 03904 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/isspace.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 04000 #include <ctype.h>
- 04001
- 04002 int (isspace)(int c) {
- 04003 return isspace(c);
- 04004 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/isupper.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 04100 #include <ctype.h>
- 04101
- 04102 int (isupper)(int c) {
- 04103 return isupper(c);
- 04104 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/isxdigit.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 04200 #include <ctype.h>
- 04201
- 04202 int (isxdigit)(int c) {
- 04203 return isxdigit(c);
- 04204 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/labs.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 04300 /*
- 04301 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 04302 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 04303 */
- 04304 /* $Header: labs.c,v 1.1 89/05/16 13:08:11 eck Exp $ */
- 04305
- 04306 #include <stdlib.h>
- 04307
- 04308 long
- 04309 labs(register long l)
- 04310 {
- 04311 return l >= 0 ? l : -l;
- 04312 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/ldiv.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 04400 /*
- 04401 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 04402 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 04403 */
- 04404 /* $Header: ldiv.c,v 1.3 90/03/05 13:48:03 eck Exp $ */
- 04405
- 04406 #include <stdlib.h>
- 04407
- 04408 static long tmp = -1;
- 04409
- 04410 ldiv_t
- 04411 ldiv(register long numer, register long denom)
- 04412 {
- 04413 ldiv_t r;
- 04414
- 04415 /* The assignment of tmp should not be optimized !! */
- 04416 if (tmp == -1) {
- 04417 tmp = (tmp / 2 == 0);
- 04418 }
- 04419 if (numer == 0) {
- 04420 r.quot = numer / denom; /* might trap if denom == 0 */
- 04421 r.rem = numer % denom;
- 04422 } else if ( !tmp && ((numer < 0) != (denom < 0))) {
- 04423 r.quot = (numer / denom) + 1;
- 04424 r.rem = numer - (numer / denom + 1) * denom;
- 04425 } else {
- 04426 r.quot = numer / denom;
- 04427 r.rem = numer % denom;
- 04428 }
- 04429 return r;
- 04430 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/localeconv.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 04500 /*
- 04501 * localeconv - set components of a struct according to current locale
- 04502 */
- 04503 /* $Header: localeconv.c,v 1.2 89/12/18 15:48:58 eck Exp $ */
- 04504
- 04505 #include <limits.h>
- 04506 #include <locale.h>
- 04507
- 04508 extern struct lconv _lc;
- 04509
- 04510 struct lconv *
- 04511 localeconv(void)
- 04512 {
- 04513 register struct lconv *lcp = &_lc;
- 04514
- 04515 lcp->decimal_point = ".";
- 04516 lcp->thousands_sep = "";
- 04517 lcp->grouping = "";
- 04518 lcp->int_curr_symbol = "";
- 04519 lcp->currency_symbol = "";
- 04520 lcp->mon_decimal_point = "";
- 04521 lcp->mon_thousands_sep = "";
- 04522 lcp->mon_grouping = "";
- 04523 lcp->positive_sign = "";
- 04524 lcp->negative_sign = "";
- 04525 lcp->int_frac_digits = CHAR_MAX;
- 04526 lcp->frac_digits = CHAR_MAX;
- 04527 lcp->p_cs_precedes = CHAR_MAX;
- 04528 lcp->p_sep_by_space = CHAR_MAX;
- 04529 lcp->n_cs_precedes = CHAR_MAX;
- 04530 lcp->n_sep_by_space = CHAR_MAX;
- 04531 lcp->p_sign_posn = CHAR_MAX;
- 04532 lcp->n_sign_posn = CHAR_MAX;
- 04533
- 04534 return lcp;
- 04535 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/localtime.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 04600 /*
- 04601 * localtime - convert a calendar time into broken down time
- 04602 */
- 04603 /* $Header: localtime.c,v 1.3 91/04/22 13:20:36 ceriel Exp $ */
- 04604
- 04605 #include <time.h>
- 04606 #include "loc_time.h"
- 04607
- 04608 /* We must be careful, since an int can't represent all the seconds in a day.
- 04609 * Hence the adjustment of minutes when adding timezone and dst information.
- 04610 * This assumes that both must be expressable in multiples of a minute.
- 04611 * Furthermore, it is assumed that both fit into an integer when expressed as
- 04612 * minutes (this is about 22 days, so this should not cause any problems).
- 04613 */
- 04614 struct tm *
- 04615 localtime(const time_t *timer)
- 04616 {
- 04617 struct tm *timep;
- 04618 unsigned dst;
- 04619
- 04620 _tzset();
- 04621 timep = gmtime(timer); /* tm->tm_isdst == 0 */
- 04622 timep->tm_min -= _timezone / 60;
- 04623 timep->tm_sec -= _timezone % 60;
- 04624 mktime(timep);
- 04625
- 04626 dst = _dstget(timep);
- 04627 if (dst) {
- 04628 timep->tm_min += dst / 60;
- 04629 timep->tm_sec += dst % 60;
- 04630 mktime(timep);
- 04631 }
- 04632 return timep;
- 04633 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/malloc.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 04700 /* $Header$ */
- 04701
- 04702 /* replace undef by define */
- 04703 #undef DEBUG /* check assertions */
- 04704 #undef SLOWDEBUG /* some extra test loops (requires DEBUG) */
- 04705
- 04706 #include <stdlib.h>
- 04707 #include <string.h>
- 04708 #include <errno.h>
- 04709
- 04710 #ifdef DEBUG
- 04711 #define ASSERT(b) if (!(b)) assert_failed();
- 04712 #else
- 04713 #define ASSERT(b) /* empty */
- 04714 #endif
- 04715
- 04716 #if _EM_WSIZE == _EM_PSIZE
- 04717 #define ptrint int
- 04718 #else
- 04719 #define ptrint long
- 04720 #endif
- 04721
- 04722 #if _EM_PSIZE == 2
- 04723 #define BRKSIZE 1024
- 04724 #else
- 04725 #define BRKSIZE 4096
- 04726 #endif
- 04727 #define PTRSIZE ((int) sizeof(void *))
- 04728 #define Align(x,a) (((x) + (a - 1)) & ~(a - 1))
- 04729 #define NextSlot(p) (* (void **) ((p) - PTRSIZE))
- 04730 #define NextFree(p) (* (void **) (p))
- 04731
- 04732 /*
- 04733 * A short explanation of the data structure and algorithms.
- 04734 * An area returned by malloc() is called a slot. Each slot
- 04735 * contains the number of bytes requested, but preceeded by
- 04736 * an extra pointer to the next the slot in memory.
- 04737 * '_bottom' and '_top' point to the first/last slot.
- 04738 * More memory is asked for using brk() and appended to top.
- 04739 * The list of free slots is maintained to keep malloc() fast.
- 04740 * '_empty' points the the first free slot. Free slots are
- 04741 * linked together by a pointer at the start of the
- 04742 * user visable part, so just after the next-slot pointer.
- 04743 * Free slots are merged together by free().
- 04744 */
- 04745
- 04746 extern void *_sbrk(int);
- 04747 extern int _brk(void *);
- 04748 static void *_bottom, *_top, *_empty;
- 04749
- 04750 static int grow(size_t len)
- 04751 {
- 04752 register char *p;
- 04753
- 04754 ASSERT(NextSlot((char *)_top) == 0);
- 04755 errno = ENOMEM;
- 04756 if ((char *) _top + len < (char *) _top
- 04757 || (p = (char *)Align((ptrint)_top + len, BRKSIZE)) < (char *) _top
- 04758 || _brk(p) != 0)
- 04759 return(0);
- 04760 NextSlot((char *)_top) = p;
- 04761 NextSlot(p) = 0;
- 04762 free(_top);
- 04763 _top = p;
- 04764 return 1;
- 04765 }
- 04767 void *
- 04768 malloc(size_t size)
- 04769 {
- 04770 register char *prev, *p, *next, *new;
- 04771 register unsigned len, ntries;
- 04772
- 04773 if (size == 0) return NULL;
- 04774 errno = ENOMEM;
- 04775 for (ntries = 0; ntries < 2; ntries++) {
- 04776 if ((len = Align(size, PTRSIZE) + PTRSIZE) < 2 * PTRSIZE)
- 04777 return NULL;
- 04778 if (_bottom == 0) {
- 04779 if ((p = _sbrk(2 * PTRSIZE)) == (char *) -1)
- 04780 return NULL;
- 04781 p = (char *) Align((ptrint)p, PTRSIZE);
- 04782 p += PTRSIZE;
- 04783 _top = _bottom = p;
- 04784 NextSlot(p) = 0;
- 04785 }
- 04786 #ifdef SLOWDEBUG
- 04787 for (p = _bottom; (next = NextSlot(p)) != 0; p = next)
- 04788 ASSERT(next > p);
- 04789 ASSERT(p == _top);
- 04790 #endif
- 04791 for (prev = 0, p = _empty; p != 0; prev = p, p = NextFree(p)) {
- 04792 next = NextSlot(p);
- 04793 new = p + len; /* easily overflows!! */
- 04794 if (new > next || new <= p)
- 04795 continue; /* too small */
- 04796 if (new + PTRSIZE < next) { /* too big, so split */
- 04797 /* + PTRSIZE avoids tiny slots on free list */
- 04798 NextSlot(new) = next;
- 04799 NextSlot(p) = new;
- 04800 NextFree(new) = NextFree(p);
- 04801 NextFree(p) = new;
- 04802 }
- 04803 if (prev)
- 04804 NextFree(prev) = NextFree(p);
- 04805 else
- 04806 _empty = NextFree(p);
- 04807 return p;
- 04808 }
- 04809 if (grow(len) == 0)
- 04810 break;
- 04811 }
- 04812 ASSERT(ntries != 2);
- 04813 return NULL;
- 04814 }
- 04816 void *
- 04817 realloc(void *oldp, size_t size)
- 04818 {
- 04819 register char *prev, *p, *next, *new;
- 04820 char *old = oldp;
- 04821 register size_t len, n;
- 04822
- 04823 if (!old) return malloc(size);
- 04824 else if (!size) {
- 04825 free(oldp);
- 04826 return NULL;
- 04827 }
- 04828 len = Align(size, PTRSIZE) + PTRSIZE;
- 04829 next = NextSlot(old);
- 04830 n = (int)(next - old); /* old length */
- 04831 /*
- 04832 * extend old if there is any free space just behind it
- 04833 */
- 04834 for (prev = 0, p = _empty; p != 0; prev = p, p = NextFree(p)) {
- 04835 if (p > next)
- 04836 break;
- 04837 if (p == next) { /* 'next' is a free slot: merge */
- 04838 NextSlot(old) = NextSlot(p);
- 04839 if (prev)
- 04840 NextFree(prev) = NextFree(p);
- 04841 else
- 04842 _empty = NextFree(p);
- 04843 next = NextSlot(old);
- 04844 break;
- 04845 }
- 04846 }
- 04847 new = old + len;
- 04848 /*
- 04849 * Can we use the old, possibly extended slot?
- 04850 */
- 04851 if (new <= next && new >= old) { /* it does fit */
- 04852 if (new + PTRSIZE < next) { /* too big, so split */
- 04853 /* + PTRSIZE avoids tiny slots on free list */
- 04854 NextSlot(new) = next;
- 04855 NextSlot(old) = new;
- 04856 free(new);
- 04857 }
- 04858 return old;
- 04859 }
- 04860 if ((new = malloc(size)) == NULL) /* it didn't fit */
- 04861 return NULL;
- 04862 memcpy(new, old, n); /* n < size */
- 04863 free(old);
- 04864 return new;
- 04865 }
- 04867 void
- 04868 free(void *ptr)
- 04869 {
- 04870 register char *prev, *next;
- 04871 char *p = ptr;
- 04872
- 04873 if (!p) return;
- 04874
- 04875 ASSERT(NextSlot(p) > p);
- 04876 for (prev = 0, next = _empty; next != 0; prev = next, next = NextFree(next))
- 04877 if (p < next)
- 04878 break;
- 04879 NextFree(p) = next;
- 04880 if (prev)
- 04881 NextFree(prev) = p;
- 04882 else
- 04883 _empty = p;
- 04884 if (next) {
- 04885 ASSERT(NextSlot(p) <= next);
- 04886 if (NextSlot(p) == next) { /* merge p and next */
- 04887 NextSlot(p) = NextSlot(next);
- 04888 NextFree(p) = NextFree(next);
- 04889 }
- 04890 }
- 04891 if (prev) {
- 04892 ASSERT(NextSlot(prev) <= p);
- 04893 if (NextSlot(prev) == p) { /* merge prev and p */
- 04894 NextSlot(prev) = NextSlot(p);
- 04895 NextFree(prev) = NextFree(p);
- 04896 }
- 04897 }
- 04898 }
- 04900 #ifdef DEBUG
- 04901 static assert_failed()
- 04902 {
- 04903 write(2, "assert failed in lib/malloc.cn", 30);
- 04904 abort();
- 04905 }
- 04906 #endif
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/mblen.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 05000 /*
- 05001 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 05002 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 05003 */
- 05004 /* $Header: mblen.c,v 1.2 89/12/18 15:12:50 eck Exp $ */
- 05005
- 05006 #include <stdlib.h>
- 05007 #include <limits.h>
- 05008
- 05009 #define CHAR_SHIFT 8
- 05010
- 05011 int
- 05012 mblen(const char *s, size_t n)
- 05013 {
- 05014 if (s == (const char *)NULL) return 0; /* no state dependent codings */
- 05015 if (n <= 0) return 0;
- 05016 return (*s != 0);
- 05017 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/mbstowcs.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 05100 /*
- 05101 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 05102 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 05103 */
- 05104 /* $Header: mbstowcs.c,v 1.2 89/12/18 15:12:59 eck Exp $ */
- 05105
- 05106 #include <stdlib.h>
- 05107
- 05108 size_t
- 05109 mbstowcs(register wchar_t *pwcs, register const char *s, size_t n)
- 05110 {
- 05111 register int i = n;
- 05112
- 05113 while (--i >= 0) {
- 05114 if (!(*pwcs++ = *s++))
- 05115 return n - i - 1;
- 05116 }
- 05117 return n - i;
- 05118 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/mbtowc.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 05200 /*
- 05201 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 05202 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 05203 */
- 05204 /* $Header: mbtowc.c,v 1.3 90/03/28 16:36:45 eck Exp $ */
- 05205
- 05206 #include <stdlib.h>
- 05207 #include <limits.h>
- 05208
- 05209 int
- 05210 mbtowc(wchar_t *pwc, register const char *s, size_t n)
- 05211 {
- 05212 if (s == (const char *)NULL) return 0;
- 05213 if (n <= 0) return 0;
- 05214 if (pwc) *pwc = *s;
- 05215 return (*s != 0);
- 05216 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/memchr.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 05300 /*
- 05301 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 05302 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 05303 */
- 05304 /* $Header: memchr.c,v 1.3 90/08/28 13:52:11 eck Exp $ */
- 05305
- 05306 #include <string.h>
- 05307
- 05308 void *
- 05309 memchr(const void *s, register int c, register size_t n)
- 05310 {
- 05311 register const unsigned char *s1 = s;
- 05312
- 05313 c = (unsigned char) c;
- 05314 if (n) {
- 05315 n++;
- 05316 while (--n > 0) {
- 05317 if (*s1++ != c) continue;
- 05318 return (void *) --s1;
- 05319 }
- 05320 }
- 05321 return NULL;
- 05322 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/memcmp.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 05400 /*
- 05401 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 05402 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 05403 */
- 05404 /* $Id: memcmp.c,v 1.6 1994/06/24 11:56:26 ceriel Exp $ */
- 05405
- 05406 #include <string.h>
- 05407
- 05408 int
- 05409 memcmp(const void *s1, const void *s2, size_t n)
- 05410 {
- 05411 register const unsigned char *p1 = s1, *p2 = s2;
- 05412
- 05413 if (n) {
- 05414 n++;
- 05415 while (--n > 0) {
- 05416 if (*p1++ == *p2++) continue;
- 05417 return *--p1 - *--p2;
- 05418 }
- 05419 }
- 05420 return 0;
- 05421 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/memcpy.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 05500 /*
- 05501 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 05502 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 05503 */
- 05504 /* $Header: memcpy.c,v 1.4 90/08/28 13:52:31 eck Exp $ */
- 05505
- 05506 #include <string.h>
- 05507
- 05508 void *
- 05509 memcpy(void *s1, const void *s2, register size_t n)
- 05510 {
- 05511 register char *p1 = s1;
- 05512 register const char *p2 = s2;
- 05513
- 05514
- 05515 if (n) {
- 05516 n++;
- 05517 while (--n > 0) {
- 05518 *p1++ = *p2++;
- 05519 }
- 05520 }
- 05521 return s1;
- 05522 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/memmove.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 05600 /*
- 05601 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 05602 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 05603 */
- 05604 /* $Header: memmove.c,v 1.3 90/08/28 13:52:42 eck Exp $ */
- 05605
- 05606 #include <string.h>
- 05607
- 05608 void *
- 05609 memmove(void *s1, const void *s2, register size_t n)
- 05610 {
- 05611 register char *p1 = s1;
- 05612 register const char *p2 = s2;
- 05613
- 05614 if (n>0) {
- 05615 if (p2 <= p1 && p2 + n > p1) {
- 05616 /* overlap, copy backwards */
- 05617 p1 += n;
- 05618 p2 += n;
- 05619 n++;
- 05620 while (--n > 0) {
- 05621 *--p1 = *--p2;
- 05622 }
- 05623 } else {
- 05624 n++;
- 05625 while (--n > 0) {
- 05626 *p1++ = *p2++;
- 05627 }
- 05628 }
- 05629 }
- 05630 return s1;
- 05631 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/memset.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 05700 /*
- 05701 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 05702 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 05703 */
- 05704 /* $Header: memset.c,v 1.3 90/08/28 13:52:54 eck Exp $ */
- 05705
- 05706 #include <string.h>
- 05707
- 05708 void *
- 05709 memset(void *s, register int c, register size_t n)
- 05710 {
- 05711 register char *s1 = s;
- 05712
- 05713 if (n>0) {
- 05714 n++;
- 05715 while (--n > 0) {
- 05716 *s1++ = c;
- 05717 }
- 05718 }
- 05719 return s;
- 05720 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/misc.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 05800 /*
- 05801 * misc - data and miscellaneous routines
- 05802 */
- 05803 /* $Header: misc.c,v 1.11 91/04/22 13:20:45 ceriel Exp $ */
- 05804
- 05805 #include <ctype.h>
- 05806 #include <time.h>
- 05807 #include <stdlib.h>
- 05808 #include <string.h>
- 05809
- 05810 #if defined(__BSD4_2)
- 05811
- 05812 struct timeval {
- 05813 long tv_sec; /* seconds */
- 05814 long tv_usec; /* and microseconds */
- 05815 };
- 05816
- 05817 struct timezone {
- 05818 int tz_minuteswest; /* minutes west of Greenwich */
- 05819 int tz_dsttime; /* type of dst correction */
- 05820 };
- 05821
- 05822 int _gettimeofday(struct timeval *tp, struct timezone *tzp);
- 05823
- 05824 #elif !defined(_POSIX_SOURCE) && !defined(__USG)
- 05825 #if !defined(_MINIX) /* MINIX has no ftime() */
- 05826 struct timeb {
- 05827 long time;
- 05828 unsigned short millitm;
- 05829 short timezone;
- 05830 short dstflag;
- 05831 };
- 05832 void _ftime(struct timeb *bp);
- 05833 #endif
- 05834 #endif
- 05835
- 05836 #include "loc_time.h"
- 05837
- 05838 #define RULE_LEN 120
- 05839 #define TZ_LEN 10
- 05840
- 05841 /* Make sure that the strings do not end up in ROM.
- 05842 * These strings probably contain the wrong value, and we cannot obtain the
- 05843 * right value from the system. TZ is the only help.
- 05844 */
- 05845 static char ntstr[TZ_LEN + 1] = "GMT"; /* string for normal time */
- 05846 static char dststr[TZ_LEN + 1] = "GDT"; /* string for daylight saving */
- 05847
- 05848 long _timezone = 0;
- 05849 long _dst_off = 60 * 60;
- 05850 int _daylight = 0;
- 05851 char *_tzname[2] = {ntstr, dststr};
- 05852
- 05853 #if defined(__USG) || defined(_POSIX_SOURCE)
- 05854 char *tzname[2] = {ntstr, dststr};
- 05855
- 05856 #if defined(__USG)
- 05857 long timezone = 0;
- 05858 int daylight = 0;
- 05859 #endif
- 05860 #endif
- 05861
- 05862 static struct dsttype {
- 05863 char ds_type; /* Unknown, Julian, Zero-based or M */
- 05864 int ds_date[3]; /* months, weeks, days */
- 05865 long ds_sec; /* usually 02:00:00 */
- 05866 } dststart = { 'U', { 0, 0, 0 }, 2 * 60 * 60 }
- 05867 , dstend = { 'U', { 0, 0, 0 }, 2 * 60 * 60 };
- 05868
- 05869 const char *_days[] = {
- 05870 "Sunday", "Monday", "Tuesday", "Wednesday",
- 05871 "Thursday", "Friday", "Saturday"
- 05872 };
- 05873
- 05874 const char *_months[] = {
- 05875 "January", "February", "March",
- 05876 "April", "May", "June",
- 05877 "July", "August", "September",
- 05878 "October", "November", "December"
- 05879 };
- 05880
- 05881 const int _ytab[2][12] = {
- 05882 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
- 05883 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
- 05884 };
- 05885
- 05886 #if !defined(_POSIX_SOURCE) && !defined(__USG)
- 05887 #define USE_TABLE 1
- 05888 #endif
- 05889
- 05890 #if USE_TABLE
- 05891 static int usetable = 1;
- 05892
- 05893 typedef struct table {
- 05894 const char *tz_name;
- 05895 const int daylight;
- 05896 const long zoneoffset;
- 05897 } TABLE;
- 05898
- 05899 #define HOUR(x) ((x) * 60*60)
- 05900
- 05901 static TABLE TimezoneTable[] = {
- 05902 {"GMT", 0, HOUR(0) }, /* Greenwich Mean */
- 05903 {"BST", 60*60, HOUR(0) }, /* British Summer */
- 05904 {"WAT", 0, HOUR(1) }, /* West Africa */
- 05905 {"AT", 0, HOUR(2) }, /* Azores */
- 05906 {"BST", 0, HOUR(3) }, /* Brazil Standard */
- 05907 {"NFT", 0, HOUR(3.5) }, /* Newfoundland */
- 05908 {"NDT", 60*60, HOUR(3.5) }, /* Newfoundland Daylight */
- 05909 {"AST", 0, HOUR(4) }, /* Atlantic Standard */
- 05910 {"ADT", 60*60, HOUR(4) }, /* Atlantic Daylight */
- 05911 {"EST", 0, HOUR(5) }, /* Eastern Standard */
- 05912 {"EDT", 60*60, HOUR(5) }, /* Eastern Daylight */
- 05913 {"CST", 0, HOUR(6) }, /* Central Standard */
- 05914 {"CDT", 60*60, HOUR(6) }, /* Central Daylight */
- 05915 {"MST", 0, HOUR(7) }, /* Mountain Standard */
- 05916 {"MDT", 60*60, HOUR(7) }, /* Mountain Daylight */
- 05917 {"PST", 0, HOUR(8) }, /* Pacific Standard */
- 05918 {"PDT", 60*60, HOUR(8) }, /* Pacific Daylight */
- 05919 {"YST", 0, HOUR(9) }, /* Yukon Standard */
- 05920 {"YDT", 60*60, HOUR(9) }, /* Yukon Daylight */
- 05921 {"HST", 0, HOUR(10) }, /* Hawaii Standard */
- 05922 {"HDT", 60*60, HOUR(10) }, /* Hawaii Daylight */
- 05923 {"NT", 0, HOUR(11) }, /* Nome */
- 05924 {"IDLW", 0, HOUR(12) }, /* International Date Line West */
- 05925 {"MET", 0, -HOUR(1) }, /* Middle European */
- 05926 {"MDT", 60*60, -HOUR(1) }, /* Middle European Summer */
- 05927 {"EET", 0, -HOUR(2) }, /* Eastern Europe, USSR Zone 1 */
- 05928 {"BT", 0, -HOUR(3) }, /* Baghdad, USSR Zone 2 */
- 05929 {"IT", 0, -HOUR(3.5) }, /* Iran */
- 05930 {"ZP4", 0, -HOUR(4) }, /* USSR Zone 3 */
- 05931 {"ZP5", 0, -HOUR(5) }, /* USSR Zone 4 */
- 05932 {"IST", 0, -HOUR(5.5) }, /* Indian Standard */
- 05933 {"ZP6", 0, -HOUR(6) }, /* USSR Zone 5 */
- 05934 {"NST", 0, -HOUR(6.5) }, /* North Sumatra */
- 05935 {"SST", 0, -HOUR(7) }, /* South Sumatra, USSR Zone 6 */
- 05936 {"WAST", 0, -HOUR(7) }, /* West Australian Standard */
- 05937 {"WADT", 60*60, -HOUR(7) }, /* West Australian Daylight */
- 05938 {"JT", 0, -HOUR(7.5) }, /* Java (3pm in Cronusland!) */
- 05939 {"CCT", 0, -HOUR(8) }, /* China Coast, USSR Zone 7 */
- 05940 {"JST", 0, -HOUR(9) }, /* Japan Standard, USSR Zone 8 */
- 05941 {"CAST", 0, -HOUR(9.5) }, /* Central Australian Standard */
- 05942 {"CADT", 60*60, -HOUR(9.5) }, /* Central Australian Daylight */
- 05943 {"EAST", 0, -HOUR(10) }, /* Eastern Australian Standard */
- 05944 {"EADT", 60*60, -HOUR(10) }, /* Eastern Australian Daylight */
- 05945 {"NZT", 0, -HOUR(12) }, /* New Zealand */
- 05946 {"NZDT", 60*60, -HOUR(12) }, /* New Zealand Daylight */
- 05947 { NULL, 0, 0 }
- 05948 };
- 05949
- 05950 /*
- 05951 * The function ZoneFromTable() searches the table for the current
- 05952 * timezone. It saves the last one found in ntstr or dststr, depending on
- 05953 * wheter the name is for daylight-saving-time or not.
- 05954 * Both ntstr and dststr are TZ_LEN + 1 chars.
- 05955 */
- 05956 static void
- 05957 ZoneFromTable(long timezone)
- 05958 {
- 05959 register TABLE *tptr = TimezoneTable;
- 05960
- 05961 while (tptr->tz_name != NULL) {
- 05962 if (tptr->zoneoffset == timezone) {
- 05963 if (tptr->daylight == 0) {
- 05964 strncpy(ntstr,tptr->tz_name, TZ_LEN);
- 05965 ntstr[TZ_LEN] = ' ';
- 05966 } else {
- 05967 strncpy(dststr,tptr->tz_name, TZ_LEN);
- 05968 dststr[TZ_LEN] = ' ';
- 05969 }
- 05970 }
- 05971 tptr++;
- 05972 }
- 05973 }
- 05974 #endif /* USE_TABLE */
- 05975
- 05976 static const char *
- 05977 parseZoneName(register char *buf, register const char *p)
- 05978 {
- 05979 register int n = 0;
- 05980
- 05981 if (*p == ':') return NULL;
- 05982 while (*p && !isdigit(*p) && *p != ',' && *p != '-' && *p != '+') {
- 05983 if (n < TZ_LEN)
- 05984 *buf++ = *p;
- 05985 p++;
- 05986 n++;
- 05987 }
- 05988 if (n < 3) return NULL; /* error */
- 05989 *buf = ' ';
- 05990 return p;
- 05991 }
- 05993 static const char *
- 05994 parseTime(register long *tm, const char *p, register struct dsttype *dst)
- 05995 {
- 05996 register int n = 0;
- 05997 register const char *q = p;
- 05998 char ds_type = (dst ? dst->ds_type : ' ');
- 05999
- 06000 if (dst) dst->ds_type = 'U';
- 06001
- 06002 *tm = 0;
- 06003 while(*p >= '0' && *p <= '9') {
- 06004 n = 10 * n + (*p++ - '0');
- 06005 }
- 06006 if (q == p) return NULL; /* "The hour shall be required" */
- 06007 if (n < 0 || n >= 24) return NULL;
- 06008 *tm = n * 60 * 60;
- 06009 if (*p == ':') {
- 06010 p++;
- 06011 n = 0;
- 06012 while(*p >= '0' && *p <= '9') {
- 06013 n = 10 * n + (*p++ - '0');
- 06014 }
- 06015 if (q == p) return NULL; /* format error */
- 06016 if (n < 0 || n >= 60) return NULL;
- 06017 *tm += n * 60;
- 06018 if (*p == ':') {
- 06019 p++;
- 06020 n = 0;
- 06021 while(*p >= '0' && *p <= '9') {
- 06022 n = 10 * n + (*p++ - '0');
- 06023 }
- 06024 if (q == p) return NULL; /* format error */
- 06025 if (n < 0 || n >= 60) return NULL;
- 06026 *tm += n;
- 06027 }
- 06028 }
- 06029 if (dst) {
- 06030 dst->ds_type = ds_type;
- 06031 dst->ds_sec = *tm;
- 06032 }
- 06033 return p;
- 06034 }
- 06036 static const char *
- 06037 parseDate(register char *buf, register const char *p, struct dsttype *dstinfo)
- 06038 {
- 06039 register const char *q;
- 06040 register int n = 0;
- 06041 int cnt = 0;
- 06042 const int bnds[3][2] = { { 1, 12 },
- 06043 { 1, 5 },
- 06044 { 0, 6}
- 06045 };
- 06046 char ds_type;
- 06047
- 06048 if (*p != 'M') {
- 06049 if (*p == 'J') {
- 06050 *buf++ = *p++;
- 06051 ds_type = 'J';
- 06052 }
- 06053 else ds_type = 'Z';
- 06054 q = p;
- 06055 while(*p >= '0' && *p <= '9') {
- 06056 n = 10 * n + (*p - '0');
- 06057 *buf++ = *p++;
- 06058 }
- 06059 if (q == p) return NULL; /* format error */
- 06060 if (n < (ds_type == 'J') || n > 365) return NULL;
- 06061 dstinfo->ds_type = ds_type;
- 06062 dstinfo->ds_date[0] = n;
- 06063 return p;
- 06064 }
- 06065 ds_type = 'M';
- 06066 do {
- 06067 *buf++ = *p++;
- 06068 q = p;
- 06069 n = 0;
- 06070 while(*p >= '0' && *p <= '9') {
- 06071 n = 10 * n + (*p - '0');
- 06072 *buf++ = *p++;
- 06073 }
- 06074 if (q == p) return NULL; /* format error */
- 06075 if (n < bnds[cnt][0] || n > bnds[cnt][1]) return NULL;
- 06076 dstinfo->ds_date[cnt] = n;
- 06077 cnt++;
- 06078 } while (cnt < 3 && *p == '.');
- 06079 if (cnt != 3) return NULL;
- 06080 *buf = ' ';
- 06081 dstinfo->ds_type = ds_type;
- 06082 return p;
- 06083 }
- 06085 static const char *
- 06086 parseRule(register char *buf, register const char *p)
- 06087 {
- 06088 long time;
- 06089 register const char *q;
- 06090
- 06091 if (!(p = parseDate(buf, p, &dststart))) return NULL;
- 06092 buf += strlen(buf);
- 06093 if (*p == '/') {
- 06094 q = ++p;
- 06095 if (!(p = parseTime(&time, p, &dststart))) return NULL;
- 06096 while( p != q) *buf++ = *q++;
- 06097 }
- 06098 if (*p != ',') return NULL;
- 06099 p++;
- 06100 if (!(p = parseDate(buf, p, &dstend))) return NULL;
- 06101 buf += strlen(buf);
- 06102 if (*p == '/') {
- 06103 q = ++p;
- 06104 if (!(p = parseTime(&time, p, &dstend))) return NULL;
- 06105 while(*buf++ = *q++);
- 06106 }
- 06107 if (*p) return NULL;
- 06108 return p;
- 06109 }
- 06111 /* The following routine parses timezone information in POSIX-format. For
- 06112 * the requirements, see IEEE Std 1003.1-1988 section 8.1.1.
- 06113 * The function returns as soon as it spots an error.
- 06114 */
- 06115 static void
- 06116 parseTZ(const char *p)
- 06117 {
- 06118 long tz, dst = 60 * 60, sign = 1;
- 06119 static char lastTZ[2 * RULE_LEN];
- 06120 static char buffer[RULE_LEN];
- 06121
- 06122 if (!p) return;
- 06123
- 06124 #if USE_TABLE
- 06125 usetable = 0;
- 06126 #endif
- 06127 if (*p == ':') {
- 06128 /*
- 06129 * According to POSIX, this is implementation defined.
- 06130 * Since it depends on the particular operating system, we
- 06131 * can do nothing.
- 06132 */
- 06133 return;
- 06134 }
- 06135
- 06136 if (!strcmp(lastTZ, p)) return; /* nothing changed */
- 06137
- 06138 *_tzname[0] = ' ';
- 06139 *_tzname[1] = ' ';
- 06140 dststart.ds_type = 'U';
- 06141 dststart.ds_sec = 2 * 60 * 60;
- 06142 dstend.ds_type = 'U';
- 06143 dstend.ds_sec = 2 * 60 * 60;
- 06144
- 06145 if (strlen(p) > 2 * RULE_LEN) return;
- 06146 strcpy(lastTZ, p);
- 06147
- 06148 if (!(p = parseZoneName(buffer, p))) return;
- 06149
- 06150 if (*p == '-') {
- 06151 sign = -1;
- 06152 p++;
- 06153 } else if (*p == '+') p++;
- 06154
- 06155 if (!(p = parseTime(&tz, p, NULL))) return;
- 06156 tz *= sign;
- 06157 _timezone = tz;
- 06158 strncpy(_tzname[0], buffer, TZ_LEN);
- 06159
- 06160 if (!(_daylight = (*p != ' '))) return;
- 06161
- 06162 buffer[0] = ' ';
- 06163 if (!(p = parseZoneName(buffer, p))) return;
- 06164 strncpy(_tzname[1], buffer, TZ_LEN);
- 06165
- 06166 buffer[0] = ' ';
- 06167 if (*p && (*p != ','))
- 06168 if (!(p = parseTime(&dst, p, NULL))) return;
- 06169 _dst_off = dst; /* dst was initialized to 1 hour */
- 06170 if (*p) {
- 06171 if (*p != ',') return;
- 06172 p++;
- 06173 if (strlen(p) > RULE_LEN) return;
- 06174 if (!(p = parseRule(buffer, p))) return;
- 06175 }
- 06176 }
- 06178 void
- 06179 _tzset(void)
- 06180 {
- 06181 #if defined(__BSD4_2)
- 06182
- 06183 struct timeval tv;
- 06184 struct timezone tz;
- 06185
- 06186 _gettimeofday(&tv, &tz);
- 06187 _daylight = tz.tz_dsttime;
- 06188 _timezone = tz.tz_minuteswest * 60L;
- 06189
- 06190 #elif !defined(_POSIX_SOURCE) && !defined(__USG)
- 06191
- 06192 #if !defined(_MINIX) /* MINIX has no ftime() */
- 06193 struct timeb time;
- 06194
- 06195 _ftime(&time);
- 06196 _timezone = time.timezone * 60L;
- 06197 _daylight = time.dstflag;
- 06198 #endif
- 06199
- 06200 #endif /* !_POSIX_SOURCE && !__USG */
- 06201
- 06202 parseTZ(getenv("TZ")); /* should go inside #if */
- 06203
- 06204 #if defined(__USG) || defined(_POSIX_SOURCE)
- 06205 tzname[0] = _tzname[0];
- 06206 tzname[1] = _tzname[1];
- 06207 #if defined(__USG)
- 06208 timezone = _timezone;
- 06209 daylight = _daylight;
- 06210 #endif
- 06211 #endif /* __USG || _POSIX_SOURCE */
- 06212 }
- 06214 static int
- 06215 last_sunday(register int day, register struct tm *timep)
- 06216 {
- 06217 int first = FIRSTSUNDAY(timep);
- 06218
- 06219 if (day >= 58 && LEAPYEAR(YEAR0 + timep->tm_year)) day++;
- 06220 if (day < first) return first;
- 06221 return day - (day - first) % 7;
- 06222 }
- 06224 static int
- 06225 date_of(register struct dsttype *dst, struct tm *timep)
- 06226 {
- 06227 int leap = LEAPYEAR(YEAR0 + timep->tm_year);
- 06228 int firstday, tmpday;
- 06229 register int day, month;
- 06230
- 06231 if (dst->ds_type != 'M') {
- 06232 return dst->ds_date[0] -
- 06233 (dst->ds_type == 'J'
- 06234 && leap
- 06235 && dst->ds_date[0] < 58);
- 06236 }
- 06237 day = 0;
- 06238 month = 1;
- 06239 while (month < dst->ds_date[0]) {
- 06240 day += _ytab[leap][month - 1];
- 06241 month++;
- 06242 }
- 06243 firstday = (day + FIRSTDAYOF(timep)) % 7;
- 06244 tmpday = day;
- 06245 day += (dst->ds_date[2] - firstday + 7) % 7
- 06246 + 7 * (dst->ds_date[1] - 1);
- 06247 if (day >= tmpday + _ytab[leap][month]) day -= 7;
- 06248 return day;
- 06249 }
- 06251 /*
- 06252 * The default dst transitions are those for Western Europe (except Great
- 06253 * Britain).
- 06254 */
- 06255 unsigned
- 06256 _dstget(register struct tm *timep)
- 06257 {
- 06258 int begindst, enddst;
- 06259 register struct dsttype *dsts = &dststart, *dste = &dstend;
- 06260 int do_dst = 0;
- 06261
- 06262 if (_daylight == -1)
- 06263 _tzset();
- 06264
- 06265 timep->tm_isdst = _daylight;
- 06266 if (!_daylight) return 0;
- 06267
- 06268 if (dsts->ds_type != 'U')
- 06269 begindst = date_of(dsts, timep);
- 06270 else begindst = last_sunday(89, timep); /* last Sun before Apr */
- 06271 if (dste->ds_type != 'U')
- 06272 enddst = date_of(dste, timep);
- 06273 else enddst = last_sunday(272, timep); /* last Sun in Sep */
- 06274
- 06275 /* assume begindst != enddst (otherwise it would be no use) */
- 06276 if (begindst < enddst) { /* northern hemisphere */
- 06277 if (timep->tm_yday > begindst && timep->tm_yday < enddst)
- 06278 do_dst = 1;
- 06279 } else { /* southern hemisphere */
- 06280 if (timep->tm_yday > begindst || timep->tm_yday < enddst)
- 06281 do_dst = 1;
- 06282 }
- 06283
- 06284 if (!do_dst
- 06285 && (timep->tm_yday == begindst || timep->tm_yday == enddst)) {
- 06286 long dsttranssec; /* transition when day is this old */
- 06287 long cursec;
- 06288
- 06289 if (timep->tm_yday == begindst)
- 06290 dsttranssec = dsts->ds_sec;
- 06291 else dsttranssec = dste->ds_sec;
- 06292 cursec = ((timep->tm_hour * 60) + timep->tm_min) * 60L
- 06293 + timep->tm_sec;
- 06294
- 06295 if ((timep->tm_yday == begindst && cursec >= dsttranssec)
- 06296 || (timep->tm_yday == enddst && cursec < dsttranssec))
- 06297 do_dst = 1;
- 06298 }
- 06299 #if USE_TABLE
- 06300 if (usetable) ZoneFromTable(_timezone);
- 06301 #endif
- 06302 if (do_dst) return _dst_off;
- 06303 timep->tm_isdst = 0;
- 06304 return 0;
- 06305 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/mktime.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 06400 /*
- 06401 * mktime - convert local time into calendar time
- 06402 */
- 06403 /* $Header: mktime.c,v 1.5 91/04/22 13:20:54 ceriel Exp $ */
- 06404
- 06405 /* Michael A. Temari <temari@ix.netcom.com> 03/01/96 */
- 06406 /* - fixed bug is structure fixup code */
- 06407
- 06408 #include <time.h>
- 06409 #include <limits.h>
- 06410 #include "loc_time.h"
- 06411
- 06412 /* The code assumes that unsigned long can be converted to time_t.
- 06413 * A time_t should not be wider than unsigned long, since this would mean
- 06414 * that the check for overflow at the end could fail.
- 06415 */
- 06416 time_t
- 06417 mktime(register struct tm *timep)
- 06418 {
- 06419 register long day, year;
- 06420 register int tm_year;
- 06421 int yday, month;
- 06422 register unsigned long seconds;
- 06423 int overflow;
- 06424 unsigned dst;
- 06425
- 06426 timep->tm_min += timep->tm_sec / 60;
- 06427 timep->tm_sec %= 60;
- 06428 if (timep->tm_sec < 0) {
- 06429 timep->tm_sec += 60;
- 06430 timep->tm_min--;
- 06431 }
- 06432 timep->tm_hour += timep->tm_min / 60;
- 06433 timep->tm_min = timep->tm_min % 60;
- 06434 if (timep->tm_min < 0) {
- 06435 timep->tm_min += 60;
- 06436 timep->tm_hour--;
- 06437 }
- 06438 day = timep->tm_hour / 24;
- 06439 timep->tm_hour= timep->tm_hour % 24;
- 06440 if (timep->tm_hour < 0) {
- 06441 timep->tm_hour += 24;
- 06442 day--;
- 06443 }
- 06444 timep->tm_year += timep->tm_mon / 12;
- 06445 timep->tm_mon %= 12;
- 06446 if (timep->tm_mon < 0) {
- 06447 timep->tm_mon += 12;
- 06448 timep->tm_year--;
- 06449 }
- 06450 day += (timep->tm_mday - 1);
- 06451 while (day < 0) {
- 06452 if(--timep->tm_mon < 0) {
- 06453 timep->tm_year--;
- 06454 timep->tm_mon = 11;
- 06455 }
- 06456 day += _ytab[LEAPYEAR(YEAR0 + timep->tm_year)][timep->tm_mon];
- 06457 }
- 06458 while (day >= _ytab[LEAPYEAR(YEAR0 + timep->tm_year)][timep->tm_mon]) {
- 06459 day -= _ytab[LEAPYEAR(YEAR0 + timep->tm_year)][timep->tm_mon];
- 06460 if (++(timep->tm_mon) == 12) {
- 06461 timep->tm_mon = 0;
- 06462 timep->tm_year++;
- 06463 }
- 06464 }
- 06465 timep->tm_mday = day + 1;
- 06466 _tzset(); /* set timezone and dst info */
- 06467 year = EPOCH_YR;
- 06468 if (timep->tm_year < year - YEAR0) return (time_t)-1;
- 06469 seconds = 0;
- 06470 day = 0; /* means days since day 0 now */
- 06471 overflow = 0;
- 06472
- 06473 /* Assume that when day becomes negative, there will certainly
- 06474 * be overflow on seconds.
- 06475 * The check for overflow needs not to be done for leapyears
- 06476 * divisible by 400.
- 06477 * The code only works when year (1970) is not a leapyear.
- 06478 */
- 06479 #if EPOCH_YR != 1970
- 06480 #error EPOCH_YR != 1970
- 06481 #endif
- 06482 tm_year = timep->tm_year + YEAR0;
- 06483
- 06484 if (LONG_MAX / 365 < tm_year - year) overflow++;
- 06485 day = (tm_year - year) * 365;
- 06486 if (LONG_MAX - day < (tm_year - year) / 4 + 1) overflow++;
- 06487 day += (tm_year - year) / 4
- 06488 + ((tm_year % 4) && tm_year % 4 < year % 4);
- 06489 day -= (tm_year - year) / 100
- 06490 + ((tm_year % 100) && tm_year % 100 < year % 100);
- 06491 day += (tm_year - year) / 400
- 06492 + ((tm_year % 400) && tm_year % 400 < year % 400);
- 06493
- 06494 yday = month = 0;
- 06495 while (month < timep->tm_mon) {
- 06496 yday += _ytab[LEAPYEAR(tm_year)][month];
- 06497 month++;
- 06498 }
- 06499 yday += (timep->tm_mday - 1);
- 06500 if (day + yday < 0) overflow++;
- 06501 day += yday;
- 06502
- 06503 timep->tm_yday = yday;
- 06504 timep->tm_wday = (day + 4) % 7; /* day 0 was thursday (4) */
- 06505
- 06506 seconds = ((timep->tm_hour * 60L) + timep->tm_min) * 60L + timep->tm_sec;
- 06507
- 06508 if ((TIME_MAX - seconds) / SECS_DAY < day) overflow++;
- 06509 seconds += day * SECS_DAY;
- 06510
- 06511 /* Now adjust according to timezone and daylight saving time */
- 06512
- 06513 if (((_timezone > 0) && (TIME_MAX - _timezone < seconds))
- 06514 || ((_timezone < 0) && (seconds < -_timezone)))
- 06515 overflow++;
- 06516 seconds += _timezone;
- 06517
- 06518 if (timep->tm_isdst < 0)
- 06519 dst = _dstget(timep);
- 06520 else if (timep->tm_isdst)
- 06521 dst = _dst_off;
- 06522 else dst = 0;
- 06523
- 06524 if (dst > seconds) overflow++; /* dst is always non-negative */
- 06525 seconds -= dst;
- 06526
- 06527 if (overflow) return (time_t)-1;
- 06528
- 06529 if ((time_t)seconds != seconds) return (time_t)-1;
- 06530 return (time_t)seconds;
- 06531 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/qsort.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 06600 /*
- 06601 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 06602 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 06603 */
- 06604 /* $Header: qsort.c,v 1.3 90/08/28 14:03:24 eck Exp $ */
- 06605
- 06606 #include <stdlib.h>
- 06607
- 06608 static void qsort1(char *, char *, size_t);
- 06609 static int (*qcompar)(const char *, const char *);
- 06610 static void qexchange(char *, char *, size_t);
- 06611 static void q3exchange(char *, char *, char *, size_t);
- 06612
- 06613 void
- 06614 qsort(void *base, size_t nel, size_t width,
- 06615 int (*compar)(const void *, const void *))
- 06616 {
- 06617 /* when nel is 0, the expression '(nel - 1) * width' is wrong */
- 06618 if (!nel) return;
- 06619 qcompar = (int (*)(const char *, const char *)) compar;
- 06620 qsort1(base, (char *)base + (nel - 1) * width, width);
- 06621 }
- 06623 static void
- 06624 qsort1(char *a1, char *a2, register size_t width)
- 06625 {
- 06626 register char *left, *right;
- 06627 register char *lefteq, *righteq;
- 06628 int cmp;
- 06629
- 06630 for (;;) {
- 06631 if (a2 <= a1) return;
- 06632 left = a1;
- 06633 right = a2;
- 06634 lefteq = righteq = a1 + width * (((a2-a1)+width)/(2*width));
- 06635 /*
- 06636 Pick an element in the middle of the array.
- 06637 We will collect the equals around it.
- 06638 "lefteq" and "righteq" indicate the left and right
- 06639 bounds of the equals respectively.
- 06640 Smaller elements end up left of it, larger elements end
- 06641 up right of it.
- 06642 */
- 06643 again:
- 06644 while (left < lefteq && (cmp = (*qcompar)(left, lefteq)) <= 0) {
- 06645 if (cmp < 0) {
- 06646 /* leave it where it is */
- 06647 left += width;
- 06648 }
- 06649 else {
- 06650 /* equal, so exchange with the element to
- 06651 the left of the "equal"-interval.
- 06652 */
- 06653 lefteq -= width;
- 06654 qexchange(left, lefteq, width);
- 06655 }
- 06656 }
- 06657 while (right > righteq) {
- 06658 if ((cmp = (*qcompar)(right, righteq)) < 0) {
- 06659 /* smaller, should go to left part
- 06660 */
- 06661 if (left < lefteq) {
- 06662 /* yes, we had a larger one at the
- 06663 left, so we can just exchange
- 06664 */
- 06665 qexchange(left, right, width);
- 06666 left += width;
- 06667 right -= width;
- 06668 goto again;
- 06669 }
- 06670 /* no more room at the left part, so we
- 06671 move the "equal-interval" one place to the
- 06672 right, and the smaller element to the
- 06673 left of it.
- 06674 This is best expressed as a three-way
- 06675 exchange.
- 06676 */
- 06677 righteq += width;
- 06678 q3exchange(left, righteq, right, width);
- 06679 lefteq += width;
- 06680 left = lefteq;
- 06681 }
- 06682 else if (cmp == 0) {
- 06683 /* equal, so exchange with the element to
- 06684 the right of the "equal-interval"
- 06685 */
- 06686 righteq += width;
- 06687 qexchange(right, righteq, width);
- 06688 }
- 06689 else /* just leave it */ right -= width;
- 06690 }
- 06691 if (left < lefteq) {
- 06692 /* larger element to the left, but no more room,
- 06693 so move the "equal-interval" one place to the
- 06694 left, and the larger element to the right
- 06695 of it.
- 06696 */
- 06697 lefteq -= width;
- 06698 q3exchange(right, lefteq, left, width);
- 06699 righteq -= width;
- 06700 right = righteq;
- 06701 goto again;
- 06702 }
- 06703 /* now sort the "smaller" part */
- 06704 qsort1(a1, lefteq - width, width);
- 06705 /* and now the larger, saving a subroutine call
- 06706 because of the for(;;)
- 06707 */
- 06708 a1 = righteq + width;
- 06709 }
- 06710 /*NOTREACHED*/
- 06711 }
- 06713 static void
- 06714 qexchange(register char *p, register char *q,
- 06715 register size_t n)
- 06716 {
- 06717 register int c;
- 06718
- 06719 while (n-- > 0) {
- 06720 c = *p;
- 06721 *p++ = *q;
- 06722 *q++ = c;
- 06723 }
- 06724 }
- 06726 static void
- 06727 q3exchange(register char *p, register char *q, register char *r,
- 06728 register size_t n)
- 06729 {
- 06730 register int c;
- 06731
- 06732 while (n-- > 0) {
- 06733 c = *p;
- 06734 *p++ = *r;
- 06735 *r++ = *q;
- 06736 *q++ = c;
- 06737 }
- 06738 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/raise.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 06800 /*
- 06801 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 06802 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 06803 */
- 06804 /* $Header: raise.c,v 1.3 90/11/22 13:55:50 eck Exp $ */
- 06805
- 06806 #if defined(_POSIX_SOURCE)
- 06807 #include <sys/types.h>
- 06808 #endif
- 06809 #include <signal.h>
- 06810
- 06811 int _kill(int pid, int sig);
- 06812 pid_t _getpid(void);
- 06813
- 06814 int
- 06815 raise(int sig)
- 06816 {
- 06817 if (sig < 0 || sig > _NSIG)
- 06818 return -1;
- 06819 return _kill(_getpid(), sig);
- 06820 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/rand.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 06900 /*
- 06901 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 06902 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 06903 */
- 06904 /* $Header: rand.c,v 1.3 90/06/30 20:02:45 ceriel Exp $ */
- 06905
- 06906 #include <stdlib.h>
- 06907
- 06908 static unsigned long int next = 1;
- 06909
- 06910 int rand(void)
- 06911 {
- 06912 next = next * 1103515245 + 12345;
- 06913 return (unsigned int)(next/(2 * (RAND_MAX +1L)) % (RAND_MAX+1L));
- 06914 }
- 06916 void srand(unsigned int seed)
- 06917 {
- 06918 next = seed;
- 06919 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/setlocale.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 07000 /*
- 07001 * setlocale - set the programs locale
- 07002 */
- 07003 /* $Header: setlocale.c,v 1.2 89/12/18 15:49:11 eck Exp $ */
- 07004
- 07005 #include <locale.h>
- 07006 #include <string.h>
- 07007
- 07008 struct lconv _lc;
- 07009
- 07010 char *
- 07011 setlocale(int category, const char *locale)
- 07012 {
- 07013 if (!locale) return "C";
- 07014 if (*locale && strcmp(locale, "C")) return (char *)NULL;
- 07015
- 07016 switch(category) {
- 07017 case LC_ALL:
- 07018 case LC_CTYPE:
- 07019 case LC_COLLATE:
- 07020 case LC_TIME:
- 07021 case LC_NUMERIC:
- 07022 case LC_MONETARY:
- 07023 return *locale ? (char *)locale : "C";
- 07024 default:
- 07025 return (char *)NULL;
- 07026 }
- 07027 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/sigmisc.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 07100 /*
- 07101 * sigmisc.c - used to get a signal mask
- 07102 */
- 07103 /* $Header: sigmisc.c,v 1.2 90/10/15 11:23:08 eck Exp $ */
- 07104
- 07105 #if defined(_POSIX_SOURCE)
- 07106
- 07107 /* This can't be done in setjmp.e, since SIG_SETMASK is defined in
- 07108 * <signal.h>. This is a C-file, which can't be included.
- 07109 */
- 07110
- 07111 #include <sys/types.h>
- 07112 #include <signal.h>
- 07113 #include <stddef.h>
- 07114
- 07115 int _sigprocmask(int, sigset_t *, sigset_t *);
- 07116
- 07117 static void
- 07118 __testsigset(void) {
- 07119 /* This switch compiles when a sigset_t has the right size. */
- 07120 switch(0) {
- 07121 case 0:
- 07122 case sizeof(sigset_t) <= sizeof(long): break;
- 07123 }
- 07124 }
- 07126 void
- 07127 __newsigset(sigset_t *p)
- 07128 {
- 07129 /* The SIG_SETMASK is not significant */
- 07130 _sigprocmask(SIG_SETMASK, NULL, p);
- 07131 }
- 07133 void
- 07134 __oldsigset(sigset_t *p)
- 07135 {
- 07136 _sigprocmask(SIG_SETMASK, p, NULL);
- 07137 }
- 07138 #endif /* _POSIX_SOURCE */
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/signal.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 07200 /* SYSVR4 and ANSI compatible signal(2). */
- 07201
- 07202 #include <lib.h>
- 07203 #define sigaction _sigaction
- 07204 #define sigemptyset _sigemptyset
- 07205 #include <signal.h>
- 07206
- 07207 PUBLIC sighandler_t signal(sig, disp)
- 07208 int sig; /* signal number */
- 07209 sighandler_t disp; /* signal handler, or SIG_DFL, or SIG_IGN */
- 07210 {
- 07211 struct sigaction sa, osa;
- 07212
- 07213 if (sig <= 0 || sig > _NSIG || sig == SIGKILL) {
- 07214 errno = EINVAL;
- 07215 return(SIG_ERR);
- 07216 }
- 07217 sigemptyset(&sa.sa_mask);
- 07218
- 07219 #ifdef WANT_UNRELIABLE_SIGNALS
- 07220 /* Allow the signal being handled to interrupt the signal handler. */
- 07221 sa.sa_flags = SA_NODEFER;
- 07222
- 07223 /* When signal is caught, reset signal handler to SIG_DFL for all but
- 07224 * SIGILL and SIGTRAP.
- 07225 */
- 07226 if (sig != SIGILL && sig != SIGTRAP) sa.sa_flags |= SA_RESETHAND;
- 07227 #else
- 07228 sa.sa_flags = 0;
- 07229 #endif
- 07230
- 07231 sa.sa_handler = disp;
- 07232 if (sigaction(sig, &sa, &osa) < 0) return(SIG_ERR);
- 07233 return(osa.sa_handler);
- 07234 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strcat.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 07300 /*
- 07301 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 07302 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 07303 */
- 07304 /* $Header: strcat.c,v 1.2 90/05/31 18:33:06 ceriel Exp $ */
- 07305
- 07306 #include <string.h>
- 07307
- 07308 char *
- 07309 strcat(char *ret, register const char *s2)
- 07310 {
- 07311 register char *s1 = ret;
- 07312
- 07313 while (*s1++ != ' ')
- 07314 /* EMPTY */ ;
- 07315 s1--;
- 07316 while (*s1++ = *s2++)
- 07317 /* EMPTY */ ;
- 07318 return ret;
- 07319 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strchr.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 07400 /*
- 07401 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 07402 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 07403 */
- 07404 /* $Header: strchr.c,v 1.3 90/08/28 13:53:00 eck Exp $ */
- 07405
- 07406 #include <string.h>
- 07407
- 07408 char *
- 07409 strchr(register const char *s, register int c)
- 07410 {
- 07411 c = (char) c;
- 07412
- 07413 while (c != *s) {
- 07414 if (*s++ == ' ') return NULL;
- 07415 }
- 07416 return (char *)s;
- 07417 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strcmp.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 07500 /*
- 07501 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 07502 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 07503 */
- 07504 /* $Id: strcmp.c,v 1.4 1994/06/24 11:56:43 ceriel Exp $ */
- 07505
- 07506 #include <string.h>
- 07507
- 07508 int
- 07509 strcmp(register const char *s1, register const char *s2)
- 07510 {
- 07511 while (*s1 == *s2++) {
- 07512 if (*s1++ == ' ') {
- 07513 return 0;
- 07514 }
- 07515 }
- 07516 if (*s1 == ' ') return -1;
- 07517 if (*--s2 == ' ') return 1;
- 07518 return (unsigned char) *s1 - (unsigned char) *s2;
- 07519 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strcoll.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 07600 /*
- 07601 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 07602 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 07603 */
- 07604 /* $Header: strcoll.c,v 1.2 90/08/28 13:53:23 eck Exp $ */
- 07605
- 07606 #include <string.h>
- 07607 #include <locale.h>
- 07608
- 07609 int
- 07610 strcoll(register const char *s1, register const char *s2)
- 07611 {
- 07612 while (*s1 == *s2++) {
- 07613 if (*s1++ == ' ') {
- 07614 return 0;
- 07615 }
- 07616 }
- 07617 return *s1 - *--s2;
- 07618 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strcpy.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 07700 /*
- 07701 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 07702 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 07703 */
- 07704 /* $Header: strcpy.c,v 1.2 90/05/31 18:33:13 ceriel Exp $ */
- 07705
- 07706 #include <string.h>
- 07707
- 07708 char *
- 07709 strcpy(char *ret, register const char *s2)
- 07710 {
- 07711 register char *s1 = ret;
- 07712
- 07713 while (*s1++ = *s2++)
- 07714 /* EMPTY */ ;
- 07715
- 07716 return ret;
- 07717 }