annotate TaskManager/Test/test_render/base64_de.cpp @ 131:805d27efafd8

fix
author gongo@charles.cr.ie.u-ryukyu.ac.jp
date Tue, 25 Nov 2008 17:24:18 +0900
parents 5c194c71eca8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
1 #include <iostream>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
2 #include <fstream>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
3 using namespace std;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
4
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
5 class tagTT
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
6 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
7 public:
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
8 unsigned char buf;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
9 char *cont;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
10 int nlen;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
11 };
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
12
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
13
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
14 unsigned char CtoNum(int c)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
15 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
16 if (c >= 'A' && c <= 'Z') return c-'A';
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
17 if (c >= 'a' && c <= 'z') return (c - 'a')+26;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
18 if (c >= '0' && c <= '9') return (c - '0')+52;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
19 if (c == '+') return 62;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
20 if (c == '/') return 63;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
21 return 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
22 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
23
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
24
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
25 int GetNumB64(tagTT &pWork)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
26 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
27 char wr;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
28 unsigned char w;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
29 unsigned char r;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
30
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
31 wr = *pWork.cont;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
32 pWork.cont++;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
33 if (wr=='\0' || wr=='=')
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
34 return -1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
35
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
36 while(wr=='\n' || wr=='\t')
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
37 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
38 wr = *pWork.cont;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
39 pWork.cont++;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
40 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
41
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
42 w = CtoNum(wr);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
43 if (pWork.nlen == 0)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
44 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
45 unsigned char w2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
46
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
47 wr = *pWork.cont;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
48 pWork.cont++;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
49 if (wr!='\0' && wr!='=')
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
50 w2 = CtoNum(wr);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
51 else
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
52 w2 = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
53
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
54 pWork.buf = w << 2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
55 w = w2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
56 pWork.nlen = 6;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
57 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
58
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
59 pWork.nlen -= 2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
60
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
61 r = pWork.buf | (w >> pWork.nlen);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
62
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
63 pWork.buf = (w << (8 - pWork.nlen));
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
64 return r;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
65 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
66
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
67
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
68 //int decode(char *cont, char *file_name)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
69 int decode(char *cont, FILE *outfile)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
70 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
71 int rw;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
72 tagTT work;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
73
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
74 //ofstream outfile(file_name);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
75
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
76 work.buf = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
77 work.nlen = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
78 work.cont = cont;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
79
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
80 rw = GetNumB64(work);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
81 while ( rw != -1 )
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
82 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
83 //outfile << (char)rw;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
84 putc(rw, outfile);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
85 rw = GetNumB64(work);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
86 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
87
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
88 //outfile.close();
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
89
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
90 return 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
91 }