This repository was archived by the owner on May 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathmodp_b85_gen.c
65 lines (58 loc) · 1.44 KB
/
modp_b85_gen.c
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "arraytoc.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/**
* raw data to base85 char map
*/
static char gsIntToChar[85];
/**
* base 85 char to int
*/
static uint32_t gsCharToInt[256];
/*
* Set up the above arrays
*/
static void initTables(void)
{
int i = 0;
int j = 0;
for (i = 0; i < 256; i++) {
gsCharToInt[i] = 99;
}
/* i < 33 or '!' is unprintable
* 127 is an unprintable character
*/
for (i = '!', j = 0; j < 85 && i < 127; ++i) {
/* You can have 8 restrictions in the following line.
* Traditional postscript removes: ';', '&', '\', '"'
* so that 'last' character is 'y' ('z' is special)
* For web/cookie applications, I recommend those plus ','
*/
if (i == ';' || i == '&' || i == '\\' || i == '"' || i == ',') {
continue;
}
gsIntToChar[j] = (char)i;
gsCharToInt[i] = (uint32_t)j;
++j;
}
if (j != 85) {
fprintf(stderr, "Error in base85 table. You probably had too many restrictions\n");
exit(1);
}
}
/**
* beginning headers
*/
static void printStart(void)
{
printf("/* do not edit -- autogenerated from b85gen */\n");
}
int main(void)
{
initTables();
printStart();
uint32_array_to_c(gsCharToInt, sizeof(gsCharToInt) / sizeof(uint32_t), "gsCharToInt");
char_array_to_c(gsIntToChar, sizeof(gsIntToChar), "gsIntToChar");
return 0;
}