[Scummvm-cvs-logs] CVS: residual/tools util.c,NONE,1.1 util.h,NONE,1.1 util.o,NONE,1.1 Makefile,1.5,1.6 unlab.c,1.3,1.4
Max Horn
fingolfin at users.sourceforge.net
Thu Jan 13 15:11:19 CET 2005
Update of /cvsroot/scummvm/residual/tools
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28797
Modified Files:
Makefile unlab.c
Added Files:
util.c util.h util.o
Log Message:
Import util code from regular tools directory; make unlab work on BE systems
--- NEW FILE: util.c ---
/* Scumm Tools
* Copyright (C) 2003-2005 The ScummVM Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header: /cvsroot/scummvm/residual/tools/util.c,v 1.1 2005/01/13 23:10:47 fingolfin Exp $
*
*/
#include "util.h"
#include <stdarg.h>
void error(const char *s, ...) {
char buf[1024];
va_list va;
va_start(va, s);
vsprintf(buf, s, va);
va_end(va);
fprintf(stderr, "ERROR: %s!\n", buf);
exit(1);
}
void warning(const char *s, ...) {
char buf[1024];
va_list va;
va_start(va, s);
vsprintf(buf, s, va);
va_end(va);
fprintf(stderr, "WARNING: %s!\n", buf);
}
uint8 readByte(FILE *fp) {
return fgetc(fp);
}
uint16 readUint16BE(FILE *fp) {
uint16 ret = 0;
ret |= fgetc(fp) << 8;
ret |= fgetc(fp);
return ret;
}
uint16 readUint16LE(FILE *fp) {
uint16 ret = 0;
ret |= fgetc(fp);
ret |= fgetc(fp) << 8;
return ret;
}
uint32 readUint32BE(FILE *fp) {
uint32 ret = 0;
ret |= fgetc(fp) << 24;
ret |= fgetc(fp) << 16;
ret |= fgetc(fp) << 8;
ret |= fgetc(fp);
return ret;
}
uint32 readUint32LE(FILE *fp) {
uint32 ret = 0;
ret |= fgetc(fp);
ret |= fgetc(fp) << 8;
ret |= fgetc(fp) << 16;
ret |= fgetc(fp) << 24;
return ret;
}
void writeByte(FILE *fp, uint8 b) {
fwrite(&b, 1, 1, fp);
}
void writeUint16BE(FILE *fp, uint16 value) {
writeByte(fp, (uint8)(value >> 8));
writeByte(fp, (uint8)(value));
}
void writeUint16LE(FILE *fp, uint16 value) {
writeByte(fp, (uint8)(value));
writeByte(fp, (uint8)(value >> 8));
}
void writeUint32BE(FILE *fp, uint32 value) {
writeByte(fp, (uint8)(value >> 24));
writeByte(fp, (uint8)(value >> 16));
writeByte(fp, (uint8)(value >> 8));
writeByte(fp, (uint8)(value));
}
void writeUint32LE(FILE *fp, uint32 value) {
writeByte(fp, (uint8)(value));
writeByte(fp, (uint8)(value >> 8));
writeByte(fp, (uint8)(value >> 16));
writeByte(fp, (uint8)(value >> 24));
}
uint32 fileSize(FILE *fp) {
uint32 sz;
uint32 pos = ftell(fp);
fseek(fp, 0, SEEK_END);
sz = ftell(fp);
fseek(fp, pos, SEEK_SET);
return sz;
}
--- NEW FILE: util.h ---
/* Scumm Tools
* Copyright (C) 2002-2005 The ScummVM project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header: /cvsroot/scummvm/residual/tools/util.h,v 1.1 2005/01/13 23:10:47 fingolfin Exp $
*
*/
#ifndef UTIL_H
#define UTIL_H
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#if !defined(_MSC_VER)
#include <unistd.h>
#endif
#ifdef WIN32
#include <io.h>
#include <process.h>
#endif
/*
* Some useful types
*/
typedef unsigned char byte;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
#if !defined(__cplusplus)
typedef enum { false = 0, true = 1 } bool;
/* If your C compiler doesn't support 'inline', please add a check for it. */
#if defined(_MSC_VER)
#define inline __inline
#endif
#endif
/*
* Various utility macros
*/
#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
static inline uint32 SWAP_32(uint32 a) {
return ((a >> 24) & 0xFF) | ((a >> 8) & 0xFF00) | ((a << 8) & 0xFF0000) |
((a << 24) & 0xFF000000);
}
static inline uint16 SWAP_16(uint16 a) {
return ((a >> 8) & 0xFF) | ((a << 8) & 0xFF00);
}
#if defined(SCUMM_BIG_ENDIAN)
#define TO_BE_32(a) (a)
#define TO_BE_16(a) (a)
#define TO_LE_32(a) SWAP_32(a)
#define TO_LE_16(a) SWAP_16(a)
#else
#define TO_BE_32(a) SWAP_32(a)
#define TO_BE_16(a) SWAP_16(a)
#define TO_LE_32(a) (a)
#define TO_LE_16(a) (a)
#endif
#define MKID(a) (((a&0xff) << 8) | ((a >> 8)&0xff))
#if defined(__GNUC__)
#define NORETURN_PRE
#define NORETURN_POST __attribute__((__noreturn__))
#elif defined(_MSC_VER)
#define NORETURN_PRE _declspec(noreturn)
#define NORETURN_POST
#else
#define NORETURN_PRE
#define NORETURN_POST
#endif
#if defined(__cplusplus)
extern "C" {
#endif
/* File I/O */
uint8 readByte(FILE *fp);
uint16 readUint16BE(FILE *fp);
uint16 readUint16LE(FILE *fp);
uint32 readUint32BE(FILE *fp);
uint32 readUint32LE(FILE *fp);
void writeByte(FILE *fp, uint8 b);
void writeUint16BE(FILE *fp, uint16 value);
void writeUint16LE(FILE *fp, uint16 value);
void writeUint32BE(FILE *fp, uint32 value);
void writeUint32LE(FILE *fp, uint32 value);
uint32 fileSize(FILE *fp);
/* Misc stuff */
void NORETURN_PRE error(const char *s, ...) NORETURN_POST;
void warning(const char *s, ...);
#if defined(__cplusplus)
}
#endif
#endif
--- NEW FILE: util.o ---
þíúÎ
L
Index: Makefile
===================================================================
RCS file: /cvsroot/scummvm/residual/tools/Makefile,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Makefile 7 Oct 2004 20:35:29 -0000 1.5
+++ Makefile 13 Jan 2005 23:10:46 -0000 1.6
@@ -1,13 +1,13 @@
CXX = g++
-CXXFLAGS = -g -O2 -Wall -I../lua -I.. -DLUA_NUM_TYPE=float
-CFLAGS = -g -O2 -Wall
-LDFLAGS =
+CXXFLAGS = $(CPPFLAGS) -g -O2 -Wall -I../lua -I.. -DLUA_NUM_TYPE=float
+CFLAGS = $(CPPFLAGS) -g -O2 -Wall
+#LDFLAGS =
LIBS =
all: bmtoppm delua imc2wav int2flt mat2ppm set2fig unlab vima
bmtoppm: bmtoppm.c
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ bmtoppm.c -lppm
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ bmtoppm.c -lppm -lpbm
mat2ppm: mat2ppm.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ mat2ppm.c -lppm
@@ -15,5 +15,9 @@
delua: delua.o ../localize.o ../registry.o ../debug.o
$(CXX) $(LDFLAGS) -o $@ delua.o ../localize.o ../registry.o $(LIBS)
+unlab: unlab.o util.o
+ $(CC) $(LDFLAGS) -o $@ $+
+
+
.c.o:
- $(CXX) $(CXXFLAGS) -c $<
+ $(CC) $(CXXFLAGS) -c $<
Index: unlab.c
===================================================================
RCS file: /cvsroot/scummvm/residual/tools/unlab.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- unlab.c 1 Jan 2005 10:23:18 -0000 1.3
+++ unlab.c 13 Jan 2005 23:10:46 -0000 1.4
@@ -15,44 +15,52 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
+#include "util.h"
struct lab_header {
- long magic;
- long magic2;
- long num_entries;
- long string_table_size;
+ uint32 magic;
+ uint32 magic2;
+ uint32 num_entries;
+ uint32 string_table_size;
};
struct lab_entry {
- long fname_offset;
- long start;
- long size;
- long reserved;
+ uint32 fname_offset;
+ uint32 start;
+ uint32 size;
+ uint32 reserved;
};
+uint16 READ_LE_UINT16(const void *ptr) {
+ const byte *b = (const byte *)ptr;
+ return (b[1] << 8) + b[0];
+}
+uint32 READ_LE_UINT32(const void *ptr) {
+ const byte *b = (const byte *)ptr;
+ return (b[3] << 24) + (b[2] << 16) + (b[1] << 8) + (b[0]);
+}
+
int main(int argc, char **argv) {
FILE *infile, *outfile;
struct lab_header head;
struct lab_entry *entries;
char *str_table;
- int i;
+ uint i;
off_t offset;
infile = fopen(argv[1], "rb");
if (infile == 0)
{
- printf("can't open source file: %s\n", argv[1]);
- exit(1);
+ error("can't open source file: %s", argv[1]);
}
- fread(&head, 1, sizeof(head), infile);
- if (head.magic != 'NBAL')
+ fread(&head.magic, 1, 4, infile);
+ fread(&head.magic2, 1, 4, infile);
+ head.num_entries = readUint32LE(infile);
+ head.string_table_size = readUint32LE(infile);
+ if (0 != memcmp(&head.magic, "LABN", 4))
{
- printf("its not LABN header in source file");
- exit(1);
+ error("There is no LABN header in source file");
}
entries = (struct lab_entry *)malloc(head.num_entries * sizeof(struct lab_entry));
@@ -62,12 +70,12 @@
fread(str_table, 1, head.string_table_size, infile);
for (i = 0; i < head.num_entries; i++) {
- outfile = fopen(str_table + entries[i].fname_offset, "wb");
- offset = entries[i].start;
- char *buf = (char *)malloc(entries[i].size);
+ outfile = fopen(str_table + READ_LE_UINT32(&entries[i].fname_offset), "wb");
+ offset = READ_LE_UINT32(&entries[i].start);
+ char *buf = (char *)malloc(READ_LE_UINT32(&entries[i].size));
fseek(infile, offset, SEEK_SET);
- fread(buf, 1, entries[i].size, infile);
- fwrite(buf, 1, entries[i].size, outfile);
+ fread(buf, 1, READ_LE_UINT32(&entries[i].size), infile);
+ fwrite(buf, 1, READ_LE_UINT32(&entries[i].size), outfile);
fclose(outfile);
}
More information about the Scummvm-git-logs
mailing list