home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley. The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
- /* modified from uuencode.c V 5.3 from Berkeley 1/22/85 for use with */
- /* T3DLIB by Rob Hounsell */
-
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include "t3dlib.h"
-
- /* ENC is the basic 1 character encoding function to make a char printing */
- #define ENC(c) ((c) ? ((c) & 077) + ' ': '`')
-
- encode_data (buffer, file, size)
- register char *buffer;
- FILE *file;
- ULONG size;
- {
- char buf[80];
- int i, n;
-
- for (;;) {
- /* 1 (up to) 45 character line */
- if (size <= 45)
- {
- n = fr(file, buf, size);
- }
- else {
- n = fr(file, buf, 45);
- }
- size -= n;
- *buffer++ = ENC(n);
-
- for (i=0; i<n; i += 3)
- {
- int c1, c2, c3, c4;
-
- c1 = buf[i] >> 2;
- c2 = (buf[i] << 4) & 060 | (buf[i+1] >> 4) & 017;
- c3 = (buf[i+1] << 2) & 074 | (buf[i+2] >> 6) & 03;
- c4 = buf[i+2] & 077;
- *buffer++ = ENC(c1);
- *buffer++ = ENC(c2);
- *buffer++ = ENC(c3);
- *buffer++ = ENC(c4);
- }
-
- /* *buffer++ = '\n'; */
- if (size <= 0)
- break;
- }
- *buffer = '\0';
- }
-
- /*
- * output one group of 3 bytes, pointed at by p, on file f.
- */
-
- /* fr: like read but stdio */
- int
- fr(fd, buf, cnt)
- FILE *fd;
- char *buf;
- int cnt;
- {
- int c, i;
-
- for (i=0; i<cnt; i++) {
- c = getc(fd);
- if (c == EOF)
- return(i);
- buf[i] = c;
- }
- return (cnt);
- }
-