home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / Puppeteer1.1 / Source / util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-23  |  1.2 KB  |  69 lines

  1. /*
  2.  * Puppeteer 1.1
  3.  *
  4.  * Copyright (c) 1994 Primitive Software Ltd.  All rights reserved.
  5.  *
  6.  * Author: Dave Griffiths <dave@prim.demon.co.uk>
  7.  */
  8.  
  9. #include <streams/streams.h>
  10. #include <sys/types.h>
  11. #include <sys/time.h>
  12. #include <stdio.h>
  13.  
  14. char chtbl[256];
  15.  
  16. void
  17. uuinit()
  18. {
  19.     int i, j;
  20.     
  21.     for (i = 0; i < ' '; i++)
  22.         chtbl[i] = 0;
  23.     for (i = ' ', j = 0; i < ' ' + 64; i++, j++)
  24.         chtbl[i] = j;
  25.     for (i = ' ' + 64; i < 128; i++)
  26.         chtbl[i] = 0;
  27.     chtbl['`'] = chtbl[' '];
  28.     chtbl['~'] = chtbl['^'];
  29. }
  30.     
  31. void
  32. uudecode(NXStream *in, NXStream *out)
  33. {
  34.     int count, b0, b1, b2, b3;
  35.     
  36.     while (count = chtbl[NXGetc(in)]) {
  37.         while (count > 0) {
  38.             b0 = NXGetc(in);
  39.             b1 = NXGetc(in);
  40.             b2 = NXGetc(in);
  41.             b3 = NXGetc(in);
  42.             NXPutc(out, (chtbl[b0] << 2 | chtbl[b1] >> 4));
  43.             count--;
  44.             if (count > 0) {
  45.                 NXPutc(out, (chtbl[b1] << 4 | chtbl[b2] >> 2));
  46.                 count--;
  47.             }
  48.             if (count > 0) {
  49.                 NXPutc(out, (chtbl[b2] << 6 | chtbl[b3]));
  50.                 count--;
  51.             }
  52.         }
  53.         NXGetc(in);
  54.     }
  55.     
  56.     NXFlush(out);
  57. }
  58.  
  59. void
  60. printTime(char *msg)
  61. {
  62.      struct timeval tp;
  63.      struct timezone tzp;
  64.      
  65.      gettimeofday(&tp, &tzp);
  66.      
  67.      printf("%s, SECS = %d, MSECS = %d\n", msg, tp.tv_sec, tp.tv_usec/1000);
  68. }
  69.