forked from JnyJny/meowmeow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmmencode.c
More file actions
41 lines (31 loc) · 698 Bytes
/
mmencode.c
File metadata and controls
41 lines (31 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* mmencode.c - MeowMeow, a stream encoder/decoder */
#include <errno.h>
#include <string.h>
#include "mmencode.h"
#include "table.h"
#define LO_MASK 0x000f
#define HI_MASK 0x00f0
#define BITS_IN_NIBBLE 4
int mm_encode(FILE *src, FILE *dst)
{
char buf[BUFSIZ];
unsigned char hi;
unsigned char lo;
int i;
char * tbl[] = ENCODER_INIT;
if (!src || !dst) {
errno = EINVAL;
return -1;
}
while (!feof(src)) {
if (!fgets(buf, sizeof(buf), src))
break;
for(i=0; i<strlen(buf); i++) {
lo = (buf[i] & LO_MASK);
hi = (buf[i] & HI_MASK) >> BITS_IN_NIBBLE;
fputs(tbl[hi], dst);
fputs(tbl[lo], dst);
}
}
return 0;
}