-
Notifications
You must be signed in to change notification settings - Fork 11
/
modp_b85_gen.c
69 lines (60 loc) · 1.49 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
66
67
68
69
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
/* vi: set expandtab shiftwidth=4 tabstop=4: */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "arraytoc.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
*/
void initTables()
{
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
*/
void printStart()
{
printf("/* do not edit -- autogenerated from b85gen */\n");
}
int main()
{
initTables();
printStart();
uint32_array_to_c(gsCharToInt, 256, "gsCharToInt");
char_array_to_c(gsIntToChar, 85, "gsIntToChar");
return 0;
}