| 1 |
sysadm |
1.1 |
/*
|
| 2 |
|
|
Copyright (C) 2000 Marco Ziech (mmz@gmx.net)
|
| 3 |
|
|
Copyright (C) 2000 Ross Combs (rocombs@cs.nmsu.edu)
|
| 4 |
|
|
|
| 5 |
|
|
This program is free software; you can redistribute it and/or modify
|
| 6 |
|
|
it under the terms of the GNU General Public License as published by
|
| 7 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
| 8 |
|
|
(at your option) any later version.
|
| 9 |
|
|
|
| 10 |
|
|
This program is distributed in the hope that it will be useful,
|
| 11 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
|
|
GNU General Public License for more details.
|
| 14 |
|
|
|
| 15 |
|
|
You should have received a copy of the GNU General Public License
|
| 16 |
|
|
along with this program; if not, write to the Free Software
|
| 17 |
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 18 |
|
|
*/
|
| 19 |
|
|
#include "common/setup_before.h"
|
| 20 |
|
|
#include <stdio.h>
|
| 21 |
|
|
#ifdef STDC_HEADERS
|
| 22 |
|
|
# include <stdlib.h>
|
| 23 |
|
|
#else
|
| 24 |
|
|
# ifdef HAVE_MALLOC_H
|
| 25 |
|
|
# include <malloc.h>
|
| 26 |
|
|
# endif
|
| 27 |
|
|
#endif
|
| 28 |
|
|
#include "fileio.h"
|
| 29 |
|
|
#include "bni.h"
|
| 30 |
|
|
#include "common/setup_after.h"
|
| 31 |
|
|
|
| 32 |
|
|
extern t_bnifile * load_bni(FILE *f) {
|
| 33 |
|
|
t_bnifile *b;
|
| 34 |
|
|
unsigned int i;
|
| 35 |
|
|
|
| 36 |
|
|
if (f == NULL) return NULL;
|
| 37 |
|
|
b = malloc(sizeof(t_bnifile));
|
| 38 |
|
|
file_rpush(f);
|
| 39 |
|
|
b->unknown1 = file_readd_le();
|
| 40 |
|
|
if (b->unknown1 != 0x00000010)
|
| 41 |
|
|
fprintf(stderr,"load_bni: field 1 is not 0x00000010. Data may be invalid!\n");
|
| 42 |
|
|
b->unknown2 = file_readd_le();
|
| 43 |
|
|
if (b->unknown2 != 0x00000001)
|
| 44 |
|
|
fprintf(stderr,"load_bni: field 2 is not 0x00000001. Data may be invalid!\n");
|
| 45 |
|
|
b->numicons = file_readd_le();
|
| 46 |
|
|
if (b->numicons > BNI_MAXICONS) {
|
| 47 |
|
|
fprintf(stderr,"load_bni: more than %d (BNI_MAXICONS) icons. Increase maximum number of icons in \"bni.h\".\n",BNI_MAXICONS);
|
| 48 |
|
|
b->numicons = BNI_MAXICONS;
|
| 49 |
|
|
}
|
| 50 |
|
|
b->dataoffset = file_readd_le();
|
| 51 |
|
|
if (b->numicons<1) {
|
| 52 |
|
|
fprintf(stderr,"load_bni: strange, no icons present in BNI file\n");
|
| 53 |
|
|
b->icons = NULL;
|
| 54 |
|
|
} else {
|
| 55 |
|
|
b->icons = malloc(b->numicons*sizeof(t_bniicon));
|
| 56 |
|
|
}
|
| 57 |
|
|
for (i = 0; i < b->numicons; i++) {
|
| 58 |
|
|
b->icons->icon[i].id = file_readd_le();
|
| 59 |
|
|
b->icons->icon[i].x = file_readd_le();
|
| 60 |
|
|
b->icons->icon[i].y = file_readd_le();
|
| 61 |
|
|
if (b->icons->icon[i].id == 0) {
|
| 62 |
|
|
b->icons->icon[i].tag = file_readd_le();
|
| 63 |
|
|
} else {
|
| 64 |
|
|
b->icons->icon[i].tag = 0;
|
| 65 |
|
|
}
|
| 66 |
|
|
b->icons->icon[i].unknown = file_readd_le();
|
| 67 |
|
|
}
|
| 68 |
|
|
if (ftell(f)!=(long)b->dataoffset)
|
| 69 |
|
|
fprintf(stderr,"load_bni: Warning, %lu bytes of garbage after BNI header\n",(unsigned long)(b->dataoffset-ftell(f)));
|
| 70 |
|
|
file_rpop();
|
| 71 |
|
|
return b;
|
| 72 |
|
|
}
|
| 73 |
|
|
|
| 74 |
|
|
extern int write_bni(FILE *f,t_bnifile *b) {
|
| 75 |
|
|
unsigned int i;
|
| 76 |
|
|
|
| 77 |
|
|
if (f == NULL) return -1;
|
| 78 |
|
|
if (b == NULL) return -1;
|
| 79 |
|
|
file_wpush(f);
|
| 80 |
|
|
file_writed_le(b->unknown1);
|
| 81 |
|
|
if (b->unknown1 != 0x00000010)
|
| 82 |
|
|
fprintf(stderr,"write_bni: field 1 is not 0x00000010. Data may be invalid!\n");
|
| 83 |
|
|
file_writed_le(b->unknown2);
|
| 84 |
|
|
if (b->unknown2 != 0x00000001)
|
| 85 |
|
|
fprintf(stderr,"write_bni: field 2 is not 0x00000001. Data may be invalid!\n");
|
| 86 |
|
|
file_writed_le(b->numicons);
|
| 87 |
|
|
file_writed_le(b->dataoffset);
|
| 88 |
|
|
for (i = 0; i < b->numicons; i++) {
|
| 89 |
|
|
file_writed_le(b->icons->icon[i].id);
|
| 90 |
|
|
file_writed_le(b->icons->icon[i].x);
|
| 91 |
|
|
file_writed_le(b->icons->icon[i].y);
|
| 92 |
|
|
if (b->icons->icon[i].id == 0) {
|
| 93 |
|
|
file_writed_le(b->icons->icon[i].tag);
|
| 94 |
|
|
}
|
| 95 |
|
|
file_writed_le(b->icons->icon[i].unknown);
|
| 96 |
|
|
}
|
| 97 |
|
|
if (ftell(f)!=(long)b->dataoffset)
|
| 98 |
|
|
fprintf(stderr,"Warning: dataoffset is incorrect! (=0x%lx should be 0x%lx)\n",(unsigned long)b->dataoffset,(unsigned long)ftell(f));
|
| 99 |
|
|
file_wpop();
|
| 100 |
|
|
return 0;
|
| 101 |
|
|
}
|
| 102 |
|
|
|