]>
cloudbase.mooo.com Git - ddt180.git/blob - prl2offz.c
2 * (C) Copyright 2019 Leo C. <erbl259-lmu@yahoo.de>
4 * SPDX-License-Identifier: GPL-2.0+
22 void die(int status
, const char *format
, ...)
27 va_start(arg
, format
);
28 fprintf(stderr
, "%s: ", progname
);
29 vfprintf(stderr
, format
, arg
);
38 static unsigned bitpos
;
42 if (bitpos
== progsize
) {
46 bytebuf
= fgetc(prlfile
);
51 retval
= (bytebuf
& 0x80) !=0;
59 int get_nr_of_bits(void)
66 } while ((bit
= get_bit()) == 0);
78 void put_bits(int width
, unsigned val
)
80 static unsigned bytebuf
;
81 static int bitcount
= 8;
85 if (val
& (1 << width
))
89 if (fputc(bytebuf
, outfile
) == EOF
)
90 die(1,"Error writing output file %s: %s\n",
91 outfilename
, strerror(errno
));
98 void fill_sector(void)
102 if ((curpos
= ftell(outfile
)) == -1)
103 die(1,"File error %s: %s\n", outfilename
, strerror(errno
));
105 for (int i
= 0; i
< 128 - curpos
% 128; i
++)
106 if (fputc(0, outfile
) == EOF
)
107 die(1,"Error writing output file %s: %s\n",
108 outfilename
, strerror(errno
));
115 int process_prlfile(void)
118 progsize
= fgetc(prlfile
) + (fgetc(prlfile
) << 8);
121 fseek(prlfile
, 0x100, SEEK_SET
);
123 for (unsigned i
= 0; i
< progsize
; i
++) {
124 int c
= fgetc(prlfile
);
126 die(1,"Unexpected end of prl file %s\n", prlfilename
);
127 if (fputc(c
, outfile
) == EOF
)
128 die(1,"Error writing output file %s: %s\n",
129 outfilename
, strerror(errno
));
134 while ((bits
= get_nr_of_bits()) >= 2) {
135 unsigned off
= bits
- 2;
137 put_bits(0 + 2 + 1, off
);
138 } else if (off
< (1<<4) + (1<<2)) {
141 put_bits(1 + 4 + 1, off
);
142 } else if (off
< (1<<8) + (1<<4) + (1<<2)) {
143 off
-= (1<<4) + (1<<2);
146 put_bits(2 + 8 + 1, off
);
148 off
-= (1<<8) + (1<<4) + (1<<2);
152 put_bits(3 + 16 + 1, off
);
157 die(1,"Bitmap error");
160 die(1,"Error while reading bitmap from prl file %s\n", prlfilename
);
165 /* flush output bit buffer */
178 "%s prlfile outfile\n", progname
);
182 int main(int argc
, char **argv
)
191 prlfilename
= argv
[1];
192 prlfile
=fopen(prlfilename
,"rb");
194 die(1,"Cannot open prl file %s: %s\n",
195 prlfilename
, strerror(errno
));
197 outfilename
= argv
[2];
198 outfile
=fopen(outfilename
,"wb");
200 die(1,"Cannot open output file %s: %s\n",
201 outfilename
, strerror(errno
));