unp.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. *
  5. * This product is part of the Amsterdam Compiler Kit.
  6. *
  7. * Permission to use, sell, duplicate or disclose this software must be
  8. * obtained in writing. Requests for such permissions may be sent to
  9. *
  10. * Dr. Andrew S. Tanenbaum
  11. * Wiskundig Seminarium
  12. * Vrije Universiteit
  13. * Postbox 7161
  14. * 1007 MC Amsterdam
  15. * The Netherlands
  16. *
  17. */
  18. /* Author: J.W. Stevenson */
  19. #include <pc_err.h>
  20. extern _trp();
  21. #define assert(x) /* nothing */
  22. #ifndef EM_WSIZE
  23. #define EM_WSIZE _EM_WSIZE
  24. #endif
  25. struct descr {
  26. int low;
  27. int diff;
  28. int size;
  29. };
  30. _unp(ad,zd,i,ap,zp,noext) int i; struct descr *ad,*zd; char *ap,*zp; int noext; {
  31. if (zd->diff > ad->diff ||
  32. (i -= ad->low) < 0 ||
  33. (i+zd->diff) > ad->diff)
  34. _trp(EUNPACK);
  35. ap += (i * ad->size);
  36. i = (zd->diff + 1) * zd->size;
  37. if (zd->size == 1) {
  38. int *aptmp = (int *) ap;
  39. assert(ad->size == EM_WSIZE);
  40. while (--i >= 0)
  41. if (noext) *aptmp++ = *zp++ & 0377;
  42. else *aptmp++ = *zp++;
  43. #if EM_WSIZE > 2
  44. } else if (zd->size == 2) {
  45. int *aptmp = (int *) ap;
  46. short *zptmp = (short *) zp;
  47. assert(ad->size == EM_WSIZE);
  48. while (--i >= 0)
  49. if (noext) *aptmp++ = *zptmp++ & 0177777;
  50. else *aptmp++ = *zptmp++;
  51. #endif
  52. } else {
  53. assert(ad->size == zd->size);
  54. while (--i >= 0)
  55. *ap++ = *zp++;
  56. }
  57. }