1 /* coded by Ketmar // Vampire Avalon (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 static const uint8_t *jbpkdata
;
27 static int jbpkdatalen
;
30 static int bread (void *buf
, int buflen
, void *udata
) {
31 static int readpos
= 0;
33 uint8_t *ob
= (uint8_t *)buf
;
35 int left
= jbpkdatalen
-readpos
;
37 if (left
> buflen
) left
= buflen
;
38 memcpy(ob
, jbpkdata
+readpos
, left
);
48 void jambase_unpack (void) {
49 if (jambase
== NULL
) {
52 int linecount
= 1, linenum
= 0;
54 jbpkdata
= (const uint8_t *)jambasepk
;
55 jbpkdatalen
= jbpksize();
58 memcpy(&n
, jbpkdata
, 4);
62 hup
= haunp_open_io(bread
, NULL
);
63 txt
= calloc(len
+1, 1);
64 if (haunp_read(hup
, txt
, len
) != (int)len
) {
65 fprintf(stderr
, "FATAL: decompression error!\n");
69 //fprintf(stderr, "len=%u\n", len);
70 //fprintf(stderr, "%s\n", txt);
71 for (size_t f
= 0; f
< len
; ++f
) if (txt
[f
] == '\n') ++linecount
;
72 //fprintf(stderr, "lc=%d\n", linecount);
73 jambase
= (char **)calloc(linecount
, sizeof(char *));
76 char *e
= txt
+len
, ec
;
78 for (size_t f
= pos
; f
< len
; ++f
) {
79 if (txt
[f
] == '\n') { e
= txt
+f
+1; epos
= f
+1; break; }
83 //fprintf(stderr, "%d: %s", linenum, txt+pos);
84 jambase
[linenum
++] = strdup(txt
+pos
);
89 //fprintf(stderr, "lc=%d; ln=%d\n", linecount, linenum);
90 //fprintf(stderr, "::%s", jambase[0]);