home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / minix / 5082 < prev    next >
Encoding:
Text File  |  1993-01-07  |  13.2 KB  |  627 lines

  1. Newsgroups: comp.os.minix
  2. Path: sparky!uunet!mcsun!sun4nl!star.cs.vu.nl!ast
  3. From: ast@cs.vu.nl (Andy Tanenbaum)
  4. Subject: some 1.6.24b files
  5. Message-ID: <C0I8yw.HIp@cs.vu.nl>
  6. Sender: news@cs.vu.nl
  7. Organization: Fac. Wiskunde & Informatica, VU, Amsterdam
  8. Date: Thu, 7 Jan 1993 22:25:44 GMT
  9. Lines: 616
  10.  
  11. There were apparently some problems with the following 1.6.24b files.
  12. Here are the files in full.
  13.  
  14. Andy Tanenbaum (ast@cs.vu.nl)
  15.  
  16. echo x - lib/ansi/malloc.c
  17. sed '/^X/s///' > lib/ansi/malloc.c << '/'
  18. X/* $Header$ */
  19. X
  20. X/* replace undef by define */
  21. X#undef     DEBUG        /* check assertions */
  22. X#undef     SLOWDEBUG    /* some extra test loops (requires DEBUG) */
  23. X
  24. X#include    <stdlib.h>
  25. X#include    <string.h>
  26. X
  27. X#ifdef DEBUG
  28. X#define    ASSERT(b)    if (!(b)) assert_failed();
  29. X#else
  30. X#define    ASSERT(b)    /* empty */
  31. X#endif
  32. X
  33. X#if _EM_WSIZE == _EM_PSIZE
  34. X#define    ptrint        int
  35. X#else
  36. X#define    ptrint        long
  37. X#endif
  38. X
  39. X#if    _EM_PSIZE == 2
  40. X#define BRKSIZE        1024
  41. X#else
  42. X#define BRKSIZE        4096
  43. X#endif
  44. X#define    PTRSIZE        ((int) sizeof(void *))
  45. X#define Align(x,a)    (((x) + (a - 1)) & ~(a - 1))
  46. X#define NextSlot(p)    (* (void **) ((p) - PTRSIZE))
  47. X#define NextFree(p)    (* (void **) (p))
  48. X
  49. X/*
  50. X * A short explanation of the data structure and algorithms.
  51. X * An area returned by malloc() is called a slot. Each slot
  52. X * contains the number of bytes requested, but preceeded by
  53. X * an extra pointer to the next the slot in memory.
  54. X * '_bottom' and '_top' point to the first/last slot.
  55. X * More memory is asked for using brk() and appended to top.
  56. X * The list of free slots is maintained to keep malloc() fast.
  57. X * '_empty' points the the first free slot. Free slots are
  58. X * linked together by a pointer at the start of the
  59. X * user visable part, so just after the next-slot pointer.
  60. X * Free slots are merged together by free().
  61. X */
  62. X
  63. Xextern void *_sbrk(size_t);
  64. Xextern int _brk(void *);
  65. Xstatic void *_bottom, *_top, *_empty;
  66. X
  67. Xstatic grow(size_t len)
  68. X{
  69. X  register char *p;
  70. X
  71. X  ASSERT(NextSlot((char *)_top) == 0);
  72. X  p = (char *) Align((ptrint)_top + len, BRKSIZE);
  73. X  if (p < (char *) _top || _brk(p) != 0)
  74. X    return 0;
  75. X  NextSlot((char *)_top) = p;
  76. X  NextSlot(p) = 0;
  77. X  free(_top);
  78. X  _top = p;
  79. X  return 1;
  80. X}
  81. X
  82. Xvoid *
  83. Xmalloc(size_t size)
  84. X{
  85. X  register char *prev, *p, *next, *new;
  86. X  register unsigned len, ntries;
  87. X
  88. X  if (size == 0) return NULL;
  89. X  for (ntries = 0; ntries < 2; ntries++) {
  90. X    if ((len = Align(size, PTRSIZE) + PTRSIZE) < 2 * PTRSIZE)
  91. X        return NULL;
  92. X    if (_bottom == 0) {
  93. X        if ((p = _sbrk(2 * PTRSIZE)) == (char *) -1)
  94. X            return NULL;
  95. X        p = (char *) Align((ptrint)p, PTRSIZE);
  96. X        p += PTRSIZE;
  97. X        _top = _bottom = p;
  98. X        NextSlot(p) = 0;
  99. X    }
  100. X#ifdef SLOWDEBUG
  101. X    for (p = _bottom; (next = NextSlot(p)) != 0; p = next)
  102. X        ASSERT(next > p);
  103. X    ASSERT(p == _top);
  104. X#endif
  105. X    for (prev = 0, p = _empty; p != 0; prev = p, p = NextFree(p)) {
  106. X        next = NextSlot(p);
  107. X        new = p + len;    /* easily overflows!! */
  108. X        if (new > next || new <= p)
  109. X            continue;        /* too small */
  110. X        if (new + PTRSIZE < next) {    /* too big, so split */
  111. X            /* + PTRSIZE avoids tiny slots on free list */
  112. X            NextSlot(new) = next;
  113. X            NextSlot(p) = new;
  114. X            NextFree(new) = NextFree(p);
  115. X            NextFree(p) = new;
  116. X        }
  117. X        if (prev)
  118. X            NextFree(prev) = NextFree(p);
  119. X        else
  120. X            _empty = NextFree(p);
  121. X        return p;
  122. X    }
  123. X    if (grow(len) == 0)
  124. X        break;
  125. X  }
  126. X  ASSERT(ntries != 2);
  127. X  return NULL;
  128. X}
  129. X
  130. Xvoid *
  131. Xrealloc(void *oldp, size_t size)
  132. X{
  133. X  register char *prev, *p, *next, *new;
  134. X  char *old = oldp;
  135. X  register size_t len, n;
  136. X
  137. X  if (!old) return malloc(size);
  138. X  else if (!size) {
  139. X    free(oldp);
  140. X    return NULL;
  141. X  }
  142. X  len = Align(size, PTRSIZE) + PTRSIZE;
  143. X  next = NextSlot(old);
  144. X  n = (int)(next - old);            /* old length */
  145. X  /*
  146. X   * extend old if there is any free space just behind it
  147. X   */
  148. X  for (prev = 0, p = _empty; p != 0; prev = p, p = NextFree(p)) {
  149. X    if (p > next)
  150. X        break;
  151. X    if (p == next) {    /* 'next' is a free slot: merge */
  152. X        NextSlot(old) = NextSlot(p);
  153. X        if (prev)
  154. X            NextFree(prev) = NextFree(p);
  155. X        else
  156. X            _empty = NextFree(p);
  157. X        next = NextSlot(old);
  158. X        break;
  159. X    }
  160. X  }
  161. X  new = old + len;
  162. X  /*
  163. X   * Can we use the old, possibly extended slot?
  164. X   */
  165. X  if (new <= next && new >= old) {        /* it does fit */
  166. X    if (new + PTRSIZE < next) {        /* too big, so split */
  167. X        /* + PTRSIZE avoids tiny slots on free list */
  168. X        NextSlot(new) = next;
  169. X        NextSlot(old) = new;
  170. X        free(new);
  171. X    }
  172. X    return old;
  173. X  }
  174. X  if ((new = malloc(size)) == NULL)        /* it didn't fit */
  175. X    return NULL;
  176. X  memcpy(new, old, n);                /* n < size */
  177. X  free(old);
  178. X  return new;
  179. X}
  180. X
  181. Xvoid
  182. Xfree(void *ptr)
  183. X{
  184. X  register char *prev, *next;
  185. X  char *p = ptr;
  186. X
  187. X  if (!p) return;
  188. X
  189. X  ASSERT(NextSlot(p) > p);
  190. X  for (prev = 0, next = _empty; next != 0; prev = next, next = NextFree(next))
  191. X    if (p < next)
  192. X        break;
  193. X  NextFree(p) = next;
  194. X  if (prev)
  195. X    NextFree(prev) = p;
  196. X  else
  197. X    _empty = p;
  198. X  if (next) {
  199. X    ASSERT(NextSlot(p) <= next);
  200. X    if (NextSlot(p) == next) {        /* merge p and next */
  201. X        NextSlot(p) = NextSlot(next);
  202. X        NextFree(p) = NextFree(next);
  203. X    }
  204. X  }
  205. X  if (prev) {
  206. X    ASSERT(NextSlot(prev) <= p);
  207. X    if (NextSlot(prev) == p) {        /* merge prev and p */
  208. X        NextSlot(prev) = NextSlot(p);
  209. X        NextFree(prev) = NextFree(p);
  210. X    }
  211. X  }
  212. X}
  213. X
  214. X#ifdef DEBUG
  215. Xstatic assert_failed()
  216. X{
  217. X    write(2, "assert failed in lib/malloc.c\n", 30);
  218. X    abort();
  219. X}
  220. X#endif
  221. /
  222. echo x - lib/ansi/wctomb.c
  223. sed '/^X/s///' > lib/ansi/wctomb.c << '/'
  224. X/*
  225. X * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  226. X * See the copyright notice in the ACK home directory, in the file "Copyright".
  227. X */
  228. X/* $Header: wctomb.c,v 1.4 91/01/15 11:55:33 ceriel Exp $ */
  229. X
  230. X#include    <stdlib.h>
  231. X#include    <limits.h>
  232. X
  233. Xint
  234. X/* was: wctomb(char *s, wchar_t wchar) 
  235. X * This conflicts with prototype, so it was changed to:
  236. X */
  237. Xwctomb(char *s, wchar_t wchar)
  238. X{
  239. X    if (!s) return 0;        /* no state dependent codings */
  240. X
  241. X    *s = wchar;
  242. X    return 1;
  243. X}
  244. /
  245. echo x - lib/em/Makefile
  246. sed '/^X/s///' > lib/em/Makefile << '/'
  247. X.s.o:
  248. X    $(CC) $(CFLAGS) $<
  249. X
  250. XCC=exec cc
  251. XCFLAGS= -c -O -D_MINIX -D_POSIX_SOURCE
  252. X
  253. X
  254. Xall:    
  255. X    @$(CC) $(CFLAGS) *.c *.s
  256. X
  257. X
  258. Xclean:    
  259. X    @rm -rf *.o *.bak stb.s
  260. X
  261. /
  262. echo x - lib/em/adi.s
  263. sed '/^X/s///' > lib/em/adi.s << '/'
  264. X.define .adi
  265. X
  266. X    .text
  267. X.adi:
  268. X    pop     bx 
  269. X    cmp     cx,#2
  270. X    jne     1f
  271. X    pop     cx
  272. X    add     ax,cx
  273. X    jmp     (bx)
  274. X1:
  275. X    cmp     cx,#4
  276. X    jne     9f
  277. X    pop     dx
  278. X    pop     cx
  279. X    add     ax,cx
  280. X    pop     cx
  281. X    adc     dx,cx
  282. X    push    dx
  283. X    jmp     (bx)
  284. X9:
  285. X.extern .trpilin
  286. X    push    bx
  287. X    jmp     .trpilin
  288. /
  289. echo x - lib/em/stb.c
  290. sed '/^X/s///' > lib/em/stb.c << '/'
  291. X/*
  292. X * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  293. X * See the copyright notice in the ACK home directory, in the file "Copyright".
  294. X */
  295. X/* $Header: stb.c,v 1.1 89/02/07 11:01:46 ceriel Exp $ */
  296. X/* library routine for copying structs */
  297. X
  298. X#include <ansi.h>
  299. X
  300. X_PROTOTYPE(int __stb, (int n, char *f, char *t ));
  301. X__stb(n, f, t)
  302. Xregister int n;
  303. Xregister char *f, *t;
  304. X{
  305. X    if (n > 0)
  306. X        do
  307. X            *t++ = *f++;
  308. X        while (--n);
  309. X}
  310. /
  311. echo x - lib/float/Makefile
  312. sed '/^X/s///' > lib/float/Makefile << '/'
  313. XCC=exec cc
  314. XCFLAGS=-O -I. -D_MINIX -D_POSIX_SOURCE -wo
  315. X
  316. XOBJ=add_ext.o adder.o adf4.o adf8.o cff4.o cff8.o cfi.o cfu.o cif4.o cif8.o \
  317. X    cmf4.o cmf8.o compact.o cuf4.o cuf8.o div_ext.o dvf4.o dvf8.o extend.o \
  318. X    fef4.o fef8.o fif4.o fif8.o mlf4.o mlf8.o mul_ext.o ngf4.o \
  319. X    ngf8.o nrm_ext.o sbf4.o sbf8.o sft_ext.o shifter.o sub_ext.o zrf4.o \
  320. X    zrf8.o zrf_ext.o
  321. X
  322. X
  323. X.SUFFIXES: .o .c .s
  324. X.c.o:
  325. X    $(CC) $(CFLAGS) -S $<
  326. X    @mv $*.s $*.s.tmp
  327. X    @sed -f FP.script < $*.s.tmp > $*.s;   rm $*.s.tmp
  328. X    @$(CC) $(CFLAGS) -c $*.s
  329. X    @rm $*.s
  330. X.s.o:
  331. X    $(CC) $(CFLAGS) -c $<
  332. X
  333. Xall: $(OBJ)
  334. X
  335. Xclean:    
  336. X    @rm -f *.s *.o *.bak
  337. X
  338. /
  339. echo x - lib/math/Makefile
  340. sed '/^X/s///' > lib/math/Makefile << '/'
  341. X.s.o:
  342. X    $(CC) $(CFLAGS) -c $<
  343. X
  344. XCC=exec cc
  345. XCFLAGS= -c -O -D_MINIX -D_POSIX_SOURCE
  346. XS=asin.s atan.s atan2.s ceil.s exp.s fabs.s floor.s fmod.s hugeval.s isnan.s \
  347. X  ldexp.s log.s log10.s pow.s sin.s sinh.s sqrt.s tan.s tanh.s 
  348. X
  349. Xall:    
  350. X    @$(CC) $(CFLAGS) *.c *s
  351. X
  352. X
  353. Xclean:    
  354. X    @rm -rf *.o *.bak $S
  355. X
  356. /
  357. echo x - lib/rts/Makefile.ansi
  358. sed '/^X/s///' > lib/rts/Makefile.ansi << '/'
  359. XCC=exec cc
  360. XCFLAGS= -c -O -D_MINIX -D_POSIX_SOURCE
  361. XSRC=fphook.c
  362. Xall:
  363. X    $(CC) $(CFLAGS) $(SRC)
  364. X
  365. Xclean:    
  366. X    @rm -rf *.o *.bak
  367. X
  368. /
  369. echo x - lib/rts/Makefile.kr
  370. sed '/^X/s///' > lib/rts/Makefile.kr << '/'
  371. XCC=exec cc
  372. XCFLAGS= -c -O -D_MINIX -D_POSIX_SOURCE -LIB
  373. XSRC=fphook.c head.s crtso.s
  374. Xall:
  375. X    $(CC) $(CFLAGS) $(SRC)
  376. X
  377. Xclean:    
  378. X    @rm -rf *.o *.bak
  379. X
  380. /
  381. echo x - lib/rts/fphook.c
  382. sed '/^X/s///' > lib/rts/fphook.c << '/'
  383. X/*
  384. X * fltpr.c - print floating point numbers
  385. X */
  386. X/* $Header: fltpr.c,v 1.4 90/02/27 16:47:40 eck Exp $ */
  387. X
  388. X#ifndef    NOFLOAT
  389. X#include    <string.h>
  390. X#include    <stdarg.h>
  391. X#include    "../stdio/loc_incl.h"
  392. Xint _fp_hook = 1;
  393. X
  394. Xstatic char *
  395. X_pfloat(long double r, register char *s, int n, int flags)
  396. X{
  397. X    register char *s1;
  398. X    int sign, dp;
  399. X    register int i;
  400. X
  401. X    s1 = _fcvt(r, n, &dp, &sign);
  402. X    if (sign)
  403. X        *s++ = '-';
  404. X    else if (flags & FL_SIGN)
  405. X        *s++ = '+';
  406. X    else if (flags & FL_SPACE)
  407. X        *s++ = ' ';
  408. X
  409. X    if (dp<=0)
  410. X        *s++ = '0';
  411. X    for (i=dp; i>0; i--)
  412. X        if (*s1) *s++ = *s1++;
  413. X        else *s++ = '0';
  414. X    if (((i=n) > 0) || (flags & FL_ALT))
  415. X        *s++ = '.';
  416. X    while (++dp <= 0) {
  417. X        if (--i<0)
  418. X            break;
  419. X        *s++ = '0';
  420. X    }
  421. X    while (--i >= 0)
  422. X        if (*s1) *s++ = *s1++;
  423. X        else *s++ = '0';
  424. X    return s;
  425. X}
  426. X
  427. Xstatic char *
  428. X_pscien(long double r, register char *s, int n, int flags)
  429. X{
  430. X    int sign, dp; 
  431. X    register char *s1;
  432. X
  433. X    s1 = _ecvt(r, n + 1, &dp, &sign);
  434. X    if (sign)
  435. X        *s++ = '-';
  436. X    else if (flags & FL_SIGN)
  437. X        *s++ = '+';
  438. X    else if (flags & FL_SPACE)
  439. X        *s++ = ' ';
  440. X
  441. X    *s++ = *s1++;
  442. X    if ((n > 0) || (flags & FL_ALT))
  443. X        *s++ = '.';
  444. X    while (--n >= 0)
  445. X        if (*s1) *s++ = *s1++;
  446. X        else *s++ = '0';
  447. X    *s++ = 'e';
  448. X    if ( r != 0 ) --dp ;
  449. X    if ( dp<0 ) {
  450. X        *s++ = '-' ; dp= -dp ;
  451. X    } else {
  452. X        *s++ = '+' ;
  453. X    }
  454. X    if (dp >= 100) {
  455. X        *s++ = '0' + (dp / 100);
  456. X        dp %= 100;
  457. X    }
  458. X    *s++ = '0' + (dp/10);
  459. X    *s++ = '0' + (dp%10);
  460. X    return s;
  461. X}
  462. X
  463. X#define    NDIGINEXP(exp)        (((exp) >= 100 || (exp) <= -100) ? 3 : 2)
  464. X#define    LOW_EXP            -4
  465. X#define    USE_EXP(exp, ndigits)    (((exp) < LOW_EXP + 1) || (exp >= ndigits + 1))
  466. X
  467. Xstatic char *
  468. X_gcvt(long double value, int ndigit, char *s, int flags)
  469. X{
  470. X    int sign, dp;
  471. X    register char *s1, *s2;
  472. X    register int i;
  473. X    register int nndigit = ndigit;
  474. X
  475. X    s1 = _ecvt(value, ndigit, &dp, &sign);
  476. X    s2 = s;
  477. X    if (sign) *s2++ = '-';
  478. X    else if (flags & FL_SIGN)
  479. X        *s2++ = '+';
  480. X    else if (flags & FL_SPACE)
  481. X        *s2++ = ' ';
  482. X
  483. X    if (!(flags & FL_ALT))
  484. X        for (i = nndigit - 1; i > 0 && s1[i] == '0'; i--)
  485. X            nndigit--;
  486. X
  487. X    if (USE_EXP(dp,ndigit))    {
  488. X        /* Use E format */
  489. X        dp--;
  490. X        *s2++ = *s1++;
  491. X        if ((nndigit > 1) || (flags & FL_ALT)) *s2++ = '.';
  492. X        while (--nndigit > 0) *s2++ = *s1++;
  493. X        *s2++ = 'e';
  494. X        if (dp < 0) {
  495. X            *s2++ = '-';
  496. X            dp = -dp;
  497. X        }
  498. X        else     *s2++ = '+';
  499. X        s2 += NDIGINEXP(dp);
  500. X        *s2 = 0;
  501. X        for (i = NDIGINEXP(dp); i > 0; i--) {
  502. X            *--s2 = dp % 10 + '0';
  503. X            dp /= 10;
  504. X        }
  505. X        return s;
  506. X    }
  507. X    /* Use f format */
  508. X    if (dp <= 0) {
  509. X        if (*s1 != '0')    {
  510. X            /* otherwise the whole number is 0 */
  511. X            *s2++ = '0';
  512. X            *s2++ = '.';
  513. X        }
  514. X        while (dp < 0) {
  515. X            dp++;
  516. X            *s2++ = '0';
  517. X        }
  518. X    }
  519. X    for (i = 1; i <= nndigit; i++) {
  520. X        *s2++ = *s1++;
  521. X        if (i == dp) *s2++ = '.';
  522. X    }
  523. X    if (i <= dp) {
  524. X        while (i++ <= dp) *s2++ = '0';
  525. X        *s2++ = '.';
  526. X    }
  527. X    if ((s2[-1]=='.') && !(flags & FL_ALT)) s2--;
  528. X    *s2 = '\0';
  529. X    return s;
  530. X}
  531. X
  532. Xchar *
  533. X_f_print(va_list *ap, int flags, char *s, char c, int precision)
  534. X{
  535. X    register char *old_s = s;
  536. X    long double ld_val;
  537. X
  538. X    if (flags & FL_LONGDOUBLE) ld_val = va_arg(*ap, long double);
  539. X    else ld_val = (long double) va_arg(*ap, double);
  540. X
  541. X    switch(c) {
  542. X    case 'f':
  543. X        s = _pfloat(ld_val, s, precision, flags);
  544. X        break;
  545. X    case 'e':
  546. X    case 'E':
  547. X        s = _pscien(ld_val, s, precision , flags);
  548. X        break;
  549. X    case 'g':
  550. X    case 'G':
  551. X        s = _gcvt(ld_val, precision, s, flags);
  552. X        s += strlen(s);
  553. X        break;
  554. X    }
  555. X    if ( c == 'E' || c == 'G') {
  556. X        while (*old_s && *old_s != 'e') old_s++;
  557. X        if (*old_s == 'e') *old_s = 'E';
  558. X    }
  559. X    return s;
  560. X}
  561. X#endif    /* NOFLOAT */
  562. X/* $Header: strtod.c,v 1.3 90/09/07 11:00:24 eck Exp $ */
  563. X
  564. X#include <stdlib.h>
  565. X#include "../ansi/ext_fmt.h"
  566. X
  567. Xvoid _str_ext_cvt(const char *s, char **ss, struct EXTEND *e);
  568. Xdouble _ext_dbl_cvt(struct EXTEND *e);
  569. X
  570. Xdouble
  571. Xstrtod(const char *p, char **pp)
  572. X{
  573. X    struct EXTEND e;
  574. X
  575. X    _str_ext_cvt(p, pp, &e);
  576. X    return _ext_dbl_cvt(&e);
  577. X}
  578. /
  579. echo x - lib/stdio/Makefile
  580. sed '/^X/s///' > lib/stdio/Makefile << '/'
  581. XCC=exec cc
  582. XCFLAGS= -c -O -D_MINIX -D_POSIX_SOURCE
  583. X
  584. X
  585. Xall:    
  586. X    @$(CC) $(CFLAGS) *.c
  587. X
  588. X
  589. Xclean:    
  590. X    @rm -rf *.o *.s *.bak
  591. X
  592. /
  593. echo x - lib/stdio/ecvt.c
  594. sed '/^X/s///' > lib/stdio/ecvt.c << '/'
  595. X/* $Header: ecvt.c,v 1.4 90/02/27 16:47:28 eck Exp $ */
  596. X
  597. X#ifndef NOFLOAT
  598. X
  599. X#include    "../ansi/ext_fmt.h"
  600. Xvoid _dbl_ext_cvt(double value, struct EXTEND *e);
  601. Xchar *_ext_str_cvt(struct EXTEND *e, int ndigit, int *decpt, int * sign, int ecvtflag);
  602. X
  603. Xstatic char *
  604. Xcvt(long double value, int ndigit, int *decpt, int *sign, int ecvtflag)
  605. X{
  606. X    struct EXTEND e;
  607. X
  608. X    _dbl_ext_cvt(value, &e);
  609. X    return _ext_str_cvt(&e, ndigit, decpt, sign, ecvtflag);
  610. X}
  611. X
  612. Xchar *
  613. X_ecvt(long double value, int ndigit, int *decpt, int *sign)
  614. X{
  615. X
  616. X    return cvt(value, ndigit, decpt, sign, 1);
  617. X}
  618. X
  619. Xchar *
  620. X_fcvt(long double value, int ndigit, int *decpt, int *sign)
  621. X{
  622. X    return cvt(value, ndigit, decpt, sign, 0);
  623. X}
  624. X
  625. X#endif    /* NOFLOAT */
  626. /
  627.