1 /* coded by Ketmar // Invisible Vector (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/>.
27 static const uint8_t *jbpkdata
;
28 static int jbpkdatalen
;
31 static int bread (void *buf
, int buflen
, void *udata
) {
32 static int readpos
= 0;
34 uint8_t *ob
= (uint8_t *)buf
;
36 int left
= jbpkdatalen
-readpos
;
38 if (left
> buflen
) left
= buflen
;
39 memcpy(ob
, jbpkdata
+readpos
, left
);
49 void jambase_unpack (void) {
50 if (jambase
== NULL
) {
53 int linecount
= 1, linenum
= 0;
55 jbpkdata
= (const uint8_t *)jambasepk
;
56 jbpkdatalen
= jbpksize();
59 memcpy(&n
, jbpkdata
, 4);
63 hup
= haunp_open_io(bread
, NULL
);
64 txt
= calloc(len
+1, 1);
65 if (haunp_read(hup
, txt
, len
) != (int)len
) {
66 fprintf(stderr
, "FATAL: decompression error!\n");
70 //fprintf(stderr, "len=%u\n", len);
71 //fprintf(stderr, "%s\n", txt);
72 for (size_t f
= 0; f
< len
; ++f
) if (txt
[f
] == '\n') ++linecount
;
73 //fprintf(stderr, "lc=%d\n", linecount);
74 jambase
= (char **)calloc(linecount
, sizeof(char *));
77 char *e
= txt
+len
, ec
;
79 for (size_t f
= pos
; f
< len
; ++f
) {
80 if (txt
[f
] == '\n') { e
= txt
+f
+1; epos
= f
+1; break; }
84 //fprintf(stderr, "%d: %s", linenum, txt+pos);
85 jambase
[linenum
++] = strdup(txt
+pos
);
90 //fprintf(stderr, "lc=%d; ln=%d\n", linecount, linenum);
91 //fprintf(stderr, "::%s", jambase[0]);