summaryrefslogtreecommitdiff
path: root/tools/tmxcopy/base64.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2008-02-11 19:07:36 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-02-11 19:07:36 +0000
commit7f2a504d7bcbc255616af97e050e59b0a2d99c12 (patch)
tree358df0d3f4606aa5386a1937f4d8127633e99a99 /tools/tmxcopy/base64.cpp
parent230c65a923aeaf456d61e5fbf4faec4c93313308 (diff)
downloadmana-7f2a504d7bcbc255616af97e050e59b0a2d99c12.tar.gz
mana-7f2a504d7bcbc255616af97e050e59b0a2d99c12.tar.bz2
mana-7f2a504d7bcbc255616af97e050e59b0a2d99c12.tar.xz
mana-7f2a504d7bcbc255616af97e050e59b0a2d99c12.zip
Merged revisions 3750-3751,3755-3759,3761,3766-3767,3773-3776,3779,3781,3783-3789,3791-3800,3807,3814-3815,3817,3819-3820,3822,3824-3825,3827,3829-3838,3840-3841,3843-3858,3860-3875 via svnmerge from
https://themanaworld.svn.sourceforge.net/svnroot/themanaworld/tmw/branches/0.0 ........ r3750 | crush_tmw | 2007-11-20 00:36:02 +0100 (Tue, 20 Nov 2007) | 1 line Updated desert maps with new tiles by Len. ........ r3755 | crush_tmw | 2007-11-20 17:47:44 +0100 (Tue, 20 Nov 2007) | 1 line fixed a collision layer error ........ r3773 | crush_tmw | 2007-12-12 16:45:25 +0100 (Wed, 12 Dec 2007) | 2 lines Added my tmxcopy tool for copying parts of maps to other maps. ........ r3774 | b_lindeijer | 2007-12-12 20:06:49 +0100 (Wed, 12 Dec 2007) | 2 lines Added two new cave tiles by yosuhara. ........ r3775 | crush_tmw | 2007-12-12 20:25:40 +0100 (Wed, 12 Dec 2007) | 1 line Fixed the blurred outlines of the new tiles. ........ r3791 | b_lindeijer | 2007-12-18 17:19:53 +0100 (Tue, 18 Dec 2007) | 2 lines Added initial version of the update analysis tool upalyzer. ........ r3792 | b_lindeijer | 2007-12-18 17:22:27 +0100 (Tue, 18 Dec 2007) | 2 lines Small fix to the displayed obsolete data percentage. ........ r3793 | b_lindeijer | 2007-12-18 17:31:52 +0100 (Tue, 18 Dec 2007) | 2 lines Calculate usage percentage correctly and display zip file overhead. ........ r3794 | b_lindeijer | 2007-12-18 19:44:12 +0100 (Tue, 18 Dec 2007) | 4 lines Optimized with single loop approach and nicer printing calls, inspired by doener's version. Also added list of update entries and their respective update. ........ r3795 | b_lindeijer | 2007-12-19 10:26:21 +0100 (Wed, 19 Dec 2007) | 4 lines Fixed association of entries to update, added no-cache headers, added a bit of error reporting in case of invalid zip files, kept original ordering of the update list and sorted the list of entries on their filename. ........ r3796 | b_lindeijer | 2007-12-19 11:32:28 +0100 (Wed, 19 Dec 2007) | 3 lines Added list of files in each update with indication on whether they are still used. ........ r3797 | b_lindeijer | 2007-12-19 12:16:24 +0100 (Wed, 19 Dec 2007) | 2 lines Fixed weird problem with zip_open failing with relative path. ........ r3798 | b_lindeijer | 2007-12-19 12:22:50 +0100 (Wed, 19 Dec 2007) | 2 lines Incorporated some more of doener's leet PHP skills. ;) ........ r3800 | crush_tmw | 2007-12-19 19:11:22 +0100 (Wed, 19 Dec 2007) | 1 line Fixed a map bug (monster trap) on map 18 (woodland village surrounding) ........ r3814 | b_lindeijer | 2007-12-24 17:23:56 +0100 (Mon, 24 Dec 2007) | 2 lines Updated debian subfolder. ........ r3817 | b_lindeijer | 2007-12-25 15:26:22 +0100 (Tue, 25 Dec 2007) | 2 lines Fixed missing backslash. ........ r3822 | crush_tmw | 2007-12-28 01:26:57 +0100 (Fri, 28 Dec 2007) | 1 line Some mapping errors fixed by Zipon. ........ r3824 | crush_tmw | 2007-12-29 03:25:16 +0100 (Sat, 29 Dec 2007) | 1 line Added new map by 5t3v3 (east desert cave) and enhanced version of eastern desert by Len. ........ r3827 | crush_tmw | 2007-12-30 01:28:00 +0100 (Sun, 30 Dec 2007) | 1 line switched layer compression on. ........ r3830 | crush_tmw | 2008-01-03 18:17:00 +0100 (Thu, 03 Jan 2008) | 1 line Some map bugs reported by Strump, fixed by Zipon. ........ r3840 | crush_tmw | 2008-01-14 11:22:14 +0100 (Mon, 14 Jan 2008) | 1 line Added new versions of snow maps by 5t3v3 (with minor fixes) ........ r3845 | crush_tmw | 2008-01-19 12:43:32 +0100 (Sat, 19 Jan 2008) | 1 line Fixes for the new snowland maps by 5t3v3. ........ r3846 | crush_tmw | 2008-01-19 14:00:37 +0100 (Sat, 19 Jan 2008) | 1 line Added hot spring particle effect to pond south of snow village. ........ r3873 | crush_tmw | 2008-02-08 23:07:21 +0100 (Fri, 08 Feb 2008) | 1 line Added Dimonds Cove Restaurant maps. ........ r3875 | crush_tmw | 2008-02-10 15:40:00 +0100 (Sun, 10 Feb 2008) | 1 line Added Dimonds Cove outdoor map. ........
Diffstat (limited to 'tools/tmxcopy/base64.cpp')
-rw-r--r--tools/tmxcopy/base64.cpp149
1 files changed, 149 insertions, 0 deletions
diff --git a/tools/tmxcopy/base64.cpp b/tools/tmxcopy/base64.cpp
new file mode 100644
index 00000000..9a8f6356
--- /dev/null
+++ b/tools/tmxcopy/base64.cpp
@@ -0,0 +1,149 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP HTML Embedded Scripting Language Version 3.0 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2000 PHP Development Team (See Credits file) |
+ +----------------------------------------------------------------------+
+ | This program is free software; you can redistribute it and/or modify |
+ | it under the terms of one of the following licenses: |
+ | |
+ | A) the GNU General Public License as published by the Free Software |
+ | Foundation; either version 2 of the License, or (at your option) |
+ | any later version. |
+ | |
+ | B) the PHP License as published by the PHP Development Team and |
+ | included in the distribution in the file: LICENSE |
+ | |
+ | This program is distributed in the hope that it will be useful, |
+ | but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ | GNU General Public License for more details. |
+ | |
+ | You should have received a copy of both licenses referred to here. |
+ | If you did not, or have any questions about PHP licensing, please |
+ | contact core@php.net. |
+ +----------------------------------------------------------------------+
+ | Author: Jim Winstead (jimw@php.net) |
+ +----------------------------------------------------------------------+
+ */
+/* $Id$ */
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "base64.h"
+
+static char base64_table[] =
+{
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
+ 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
+ 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0'
+};
+static char base64_pad = '=';
+
+unsigned char *php3_base64_encode(const unsigned char *string, int length, int *ret_length) {
+ const unsigned char *current = string;
+ int i = 0;
+ unsigned char *result = (unsigned char *)malloc(((length + 3 - length % 3) * 4 / 3 + 1) * sizeof(char));
+
+ while (length > 2) { /* keep going until we have less than 24 bits */
+ result[i++] = base64_table[current[0] >> 2];
+ result[i++] = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
+ result[i++] = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)];
+ result[i++] = base64_table[current[2] & 0x3f];
+
+ current += 3;
+ length -= 3; /* we just handle 3 octets of data */
+ }
+
+ /* now deal with the tail end of things */
+ if (length != 0) {
+ result[i++] = base64_table[current[0] >> 2];
+ if (length > 1) {
+ result[i++] = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
+ result[i++] = base64_table[(current[1] & 0x0f) << 2];
+ result[i++] = base64_pad;
+ }
+ else {
+ result[i++] = base64_table[(current[0] & 0x03) << 4];
+ result[i++] = base64_pad;
+ result[i++] = base64_pad;
+ }
+ }
+ if(ret_length) {
+ *ret_length = i;
+ }
+ result[i] = '\0';
+ return result;
+}
+
+/* as above, but backwards. :) */
+unsigned char *php3_base64_decode(const unsigned char *string, int length, int *ret_length) {
+ const unsigned char *current = string;
+ int ch, i = 0, j = 0, k;
+ char *chp;
+
+ unsigned char *result = (unsigned char *)malloc(length + 1);
+
+ if (result == NULL) {
+ return NULL;
+ }
+
+ /* run through the whole string, converting as we go */
+ while ((ch = *current++) != '\0') {
+ if (ch == base64_pad) break;
+
+ /* When Base64 gets POSTed, all pluses are interpreted as spaces.
+ This line changes them back. It's not exactly the Base64 spec,
+ but it is completely compatible with it (the spec says that
+ spaces are invalid). This will also save many people considerable
+ headache. - Turadg Aleahmad <turadg@wise.berkeley.edu>
+ */
+
+ if (ch == ' ') ch = '+';
+
+ chp = strchr(base64_table, ch);
+ if (chp == NULL) continue;
+ ch = chp - base64_table;
+
+ switch(i % 4) {
+ case 0:
+ result[j] = ch << 2;
+ break;
+ case 1:
+ result[j++] |= ch >> 4;
+ result[j] = (ch & 0x0f) << 4;
+ break;
+ case 2:
+ result[j++] |= ch >>2;
+ result[j] = (ch & 0x03) << 6;
+ break;
+ case 3:
+ result[j++] |= ch;
+ break;
+ }
+ i++;
+ }
+
+ k = j;
+ /* mop things up if we ended on a boundary */
+ if (ch == base64_pad) {
+ switch(i % 4) {
+ case 0:
+ case 1:
+ free(result);
+ return NULL;
+ case 2:
+ k++;
+ case 3:
+ result[k++] = 0;
+ }
+ }
+ if(ret_length) {
+ *ret_length = j;
+ }
+ result[k] = '\0';
+ return result;
+}