cosmetic fix in -configure-pkg-config-var-
[k8jam.git] / src / jbunpack.c
blobddf7970a0274c73d3f5d2a6be7f325292568b306
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, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #include <stdint.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <unistd.h>
22 #include "jambase.h"
24 #include "lzunpack.c"
27 void jambase_unpack (void) {
28 if (jambase == NULL) {
29 char *txt;
30 size_t len = 0, pos;
31 int linecount = 1, linenum = 0;
32 if (lzUncompress((void *)jambasepk, &txt, &len) != 0) {
33 fprintf(stderr, "FATAL: decompression error!\n");
34 exit(1);
36 //fprintf(stderr, "len=%u\n", len);
37 //fprintf(stderr, "%s\n", txt);
38 for (size_t f = 0; f < len; ++f) if (txt[f] == '\n') ++linecount;
39 //fprintf(stderr, "lc=%d\n", linecount);
40 jambase = (char **)calloc(linecount, sizeof(char *));
41 pos = 0;
42 while (pos < len) {
43 char *e = txt+len, ec;
44 size_t epos = len;
45 for (size_t f = pos; f < len; ++f) {
46 if (txt[f] == '\n') { e = txt+f+1; epos = f+1; break; }
48 ec = *e;
49 *e = 0;
50 //fprintf(stderr, "%d: %s", linenum, txt+pos);
51 jambase[linenum++] = strdup(txt+pos);
52 *e = ec;
53 pos = epos;
55 free(txt);
56 //fprintf(stderr, "lc=%d; ln=%d\n", linecount, linenum);
57 //fprintf(stderr, "::%s", jambase[0]);