home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume13 / deltac / part01 / deltau.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-15  |  1.8 KB  |  96 lines

  1. /* 
  2.  * Delta modulation uncompress
  3.  *
  4.  * (C) Copyright 1989, 1990 Diomidis Spinellis.  All rights reserved.
  5.  * 
  6.  * $Header: deltau.c,v 1.1 90/06/08 22:13:50 dds Rel $
  7.  *
  8.  * Permission to use, copy, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted,
  10.  * provided that the above copyright notice appear in all copies and that
  11.  * both that copyright notice and this permission notice appear in
  12.  * supporting documentation.
  13.  * 
  14.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  15.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  16.  * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  17.  *
  18.  */
  19.  
  20. #include <stdio.h>
  21.  
  22. #ifndef lint
  23. static char RCSid[] = "$Header: deltau.c,v 1.1 90/06/08 22:13:50 dds Rel $";
  24. #endif
  25.  
  26. static prev, stored;
  27.  
  28. #ifdef SLOW
  29. int
  30. getnib()
  31. {
  32.     if (stored) {
  33.         stored = 0;
  34.         return prev & 0xf;
  35.     } else {
  36.         if ((prev = getchar()) == EOF)
  37.             exit(0);
  38.         else {
  39.             stored = 1;
  40.             return prev >> 4;
  41.         }
  42.     }
  43. }
  44. #else
  45. #define getnib() \
  46. ( \
  47.     (stored) ? ( \
  48.         stored = 0, \
  49.         prev & 0xf \
  50.     ) : ( \
  51.         ((prev = getchar()) == EOF) ? \
  52.             exit(0) \
  53.         : ( \
  54.             stored = 1, \
  55.             prev >> 4 \
  56.         ) \
  57.     ) \
  58. )
  59. #endif
  60.  
  61. main(argc, argv)
  62.     int argc;
  63.     char *argv[];
  64. {
  65.     register c, cn;
  66.  
  67.     if (argc != 1) {
  68.         fprintf(stderr, "%s: usage %s\n", argv[1]);
  69.         exit(1);
  70.     }
  71.     for(;;) {
  72.         switch (c = getnib()) {
  73.         case 8:
  74.             /* Change code */
  75.             cn = getnib() << 4;
  76.             cn |= getnib();
  77.             break;
  78.         case 0:
  79.             /* No change */
  80.             break;
  81.         case 1: case 2: case 3: case 4: case 5: case 6: case 7:
  82.             /* Delta is +ve */
  83.             cn += c;
  84.             break;
  85.         case 9: case 10: case 11: case 12: case 13: case 14: case 15:
  86.             /* Delta is -ve */
  87.             cn -= c & 7;
  88.             break;
  89.         }
  90.         if (putchar(cn) == EOF) {
  91.             perror("<stdout>");
  92.             exit(1);
  93.         }
  94.     }
  95. }
  96.