~ubuntu-branches/ubuntu/trusty/haproxy/trusty

« back to all changes in this revision

Viewing changes to contrib/base64/base64rev-gen.c

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Cornet
  • Date: 2010-04-15 20:00:34 UTC
  • mfrom: (1.1.8 upstream) (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100415200034-is2r38tyvmtvi3ml
Tags: 1.4.4-1
* New upstream release
* Add splice and tproxy support
* Add regparm optimization on i386
* Switch to dpkg-source 3.0 (quilt) format

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * base64rev generator
 
3
 *
 
4
 * Copyright 2009-2010 Krzysztof Piotr Oledzki <ole@ans.pl>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU General Public License
 
8
 * as published by the Free Software Foundation; either version
 
9
 * 2 of the License, or (at your option) any later version.
 
10
 *
 
11
 */
 
12
 
 
13
#include <stdio.h>
 
14
 
 
15
const char base64tab[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
16
char base64rev[128];
 
17
 
 
18
#define base '#'        /* arbitrary chosen base value */
 
19
#define B64MAX  64
 
20
#define B64PADV B64MAX
 
21
 
 
22
int main() {
 
23
        char *p, c;
 
24
        int i, min = 255, max = 0;
 
25
 
 
26
        for (i = 0; i < sizeof(base64rev); i++)
 
27
                base64rev[i] = base;
 
28
 
 
29
        for (i = 0;  i < B64MAX; i++) {
 
30
                c = base64tab[i];
 
31
 
 
32
                if (min > c)
 
33
                        min = c;
 
34
 
 
35
                if (max < c)
 
36
                        max = c;
 
37
        }
 
38
 
 
39
        for (i = 0;  i < B64MAX; i++) {
 
40
                c = base64tab[i];
 
41
 
 
42
                if (base+i+1 > 127) {
 
43
                        printf("Wrong base value @%d\n", i);
 
44
                        return 1;
 
45
                }
 
46
 
 
47
                base64rev[c - min] = base+i+1;
 
48
        }
 
49
 
 
50
        base64rev['=' - min] = base + B64PADV;
 
51
 
 
52
        base64rev[max - min + 1] = '\0';
 
53
 
 
54
        printf("#define B64BASE '%c'\n", base);
 
55
        printf("#define B64CMIN '%c'\n", min);
 
56
        printf("#define B64CMAX '%c'\n", max);
 
57
        printf("#define B64PADV %u\n", B64PADV);
 
58
 
 
59
        p = base64rev;
 
60
        printf("const char base64rev[]=\"");
 
61
        for (p = base64rev; *p; p++) {
 
62
                if (*p == '\\')
 
63
                        printf("\\%c", *p);
 
64
                else
 
65
                        printf("%c", *p);
 
66
        }
 
67
        printf("\"\n");
 
68
 
 
69
        return 0;
 
70
}