View Full Version : porting this script help

Nov 10, 2004, 06:50 PM
I am not a real programmer but have dinked around a bit.

when I paste the code into PB and try to compile with gcc 2.95 or 3.1 I get the following errors oh project as a standard tool:

main.c:154: field `pointer' has incomplete type
main.c:169: field `data' has incomplete type
main.c:186: field `data' has incomplete type

these fields I know are Flexible arrays or think I know but I dont know how to correct the problem.

#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#ifndef byte
typedef unsigned char byte;
#ifndef false
#define false 0
#ifndef true
#define true 1
char temp[2048];
int myargc;
char **myargv;
void Error (char *error, ...)
va_list argptr;
printf ("\n************ ERROR ************\n");
va_start (argptr,error);
vprintf (error,argptr);
va_end (argptr);
printf ("\n");
#ifdef WIN32
#define PATH_DELIMITER '\\'
#define PATH_DELIMITER '/'
int CheckParm (char *check)
int i;
for (i = 1;i<myargc;i++)
#ifdef WIN32
if ( !_stricmp(check, myargv[i]) )
return i;
if ( !strcasecmp(check, myargv[i]) )
return i;
return 0;
void StripExtension (char *path)
int length;
length = strlen(path)-1;
while (length > 0 && path[length] != '.')
if (path[length] == PATH_DELIMITER)
return; // no extension
if (length)
path[length] = 0;
long term[3];
void *mem;
long blockcount;
long version; // in case there is another version difference?!
long animated; // this is a guess
long width, height;
void *dc6data;
long dc6datasize;
int transparent;
int transcol = 0;

byte default_palette[768] =
0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x08, 0x18, 0x1C, 0x10, 0x24, 0x2C, 0x18, 0x34, 0x3C, 0x00,
0x00, 0x5C, 0x20, 0x40, 0x48, 0x28, 0x48, 0x54, 0x00, 0x00, 0x90, 0x10, 0x48, 0x8C, 0x00, 0x00,
0xBC, 0x20, 0x84, 0xD0, 0x6C, 0xC4, 0xF4, 0x50, 0x7C, 0x8C, 0x64, 0x9C, 0xAC, 0x08, 0x0C, 0x0C,
0x10, 0x10, 0x14, 0x1C, 0x1C, 0x1C, 0x1C, 0x24, 0x28, 0x2C, 0x2C, 0x2C, 0x30, 0x38, 0x3C, 0x38,
0x38, 0x38, 0x48, 0x48, 0x48, 0x48, 0x50, 0x58, 0x34, 0x58, 0x64, 0x58, 0x58, 0x58, 0x3C, 0x64,
0x74, 0x64, 0x64, 0x64, 0x70, 0x74, 0x7C, 0x84, 0x84, 0x84, 0x94, 0x98, 0x9C, 0xC4, 0xC4, 0xC4,
0xF4, 0xF4, 0xF4, 0x04, 0x04, 0x08, 0x00, 0x04, 0x10, 0x04, 0x08, 0x18, 0x08, 0x10, 0x18, 0x10,
0x14, 0x1C, 0x04, 0x0C, 0x24, 0x0C, 0x18, 0x20, 0x14, 0x18, 0x20, 0x08, 0x10, 0x2C, 0x10, 0x1C,
0x24, 0x0C, 0x20, 0x28, 0x04, 0x08, 0x38, 0x10, 0x1C, 0x30, 0x14, 0x28, 0x30, 0x0C, 0x14, 0x40,
0x10, 0x28, 0x38, 0x04, 0x0C, 0x48, 0x1C, 0x28, 0x38, 0x0C, 0x20, 0x4C, 0x14, 0x2C, 0x44, 0x20,
0x2C, 0x40, 0x08, 0x10, 0x58, 0x20, 0x34, 0x48, 0x28, 0x34, 0x44, 0x1C, 0x28, 0x54, 0x14, 0x1C,
0x5C, 0x08, 0x24, 0x5C, 0x18, 0x38, 0x54, 0x24, 0x38, 0x54, 0x10, 0x18, 0x6C, 0x10, 0x2C, 0x68,
0x24, 0x44, 0x5C, 0x18, 0x24, 0x70, 0x24, 0x3C, 0x68, 0x0C, 0x2C, 0x7C, 0x2C, 0x4C, 0x64, 0x08,
0x48, 0x70, 0x18, 0x28, 0x80, 0x28, 0x50, 0x74, 0x24, 0x30, 0x88, 0x40, 0x50, 0x6C, 0x0C, 0x34,
0x8C, 0x68, 0x20, 0x70, 0x44, 0x58, 0x78, 0x40, 0x40, 0x8C, 0x30, 0x5C, 0x84, 0x24, 0x34, 0x9C,
0x18, 0x28, 0xA4, 0x14, 0x48, 0xA4, 0x40, 0x64, 0x8C, 0x38, 0x70, 0x8C, 0x50, 0x68, 0x8C, 0x34,
0x44, 0xB0, 0x20, 0x4C, 0xB4, 0x58, 0x70, 0x98, 0x40, 0x78, 0xA0, 0x1C, 0x60, 0xBC, 0x48, 0x84,
0x9C, 0x54, 0x54, 0xC4, 0x20, 0x6C, 0xC8, 0x58, 0x7C, 0xAC, 0x48, 0x88, 0xB0, 0x54, 0x7C, 0xC8,
0x20, 0x70, 0xE0, 0x54, 0x9C, 0xB8, 0x00, 0x2C, 0xFC, 0x70, 0x8C, 0xC0, 0x50, 0x98, 0xCC, 0x30,
0x84, 0xE4, 0x70, 0x70, 0xE0, 0x78, 0x98, 0xD0, 0x3C, 0x88, 0xF8, 0x38, 0xA0, 0xEC, 0x64, 0xB8,
0xD8, 0x84, 0xA4, 0xE0, 0x44, 0xB4, 0xF0, 0x4C, 0xC0, 0xF4, 0x8C, 0xB0, 0xF0, 0x5C, 0xD4, 0xFC,
0xB0, 0xB0, 0xFC, 0x10, 0x24, 0x04, 0x18, 0x24, 0x14, 0x18, 0x3C, 0x20, 0x0C, 0x48, 0x18, 0x30,
0x44, 0x00, 0x08, 0x64, 0x18, 0x24, 0x5C, 0x24, 0x24, 0x5C, 0x38, 0x44, 0x6C, 0x08, 0x14, 0x7C,
0x28, 0x34, 0x74, 0x40, 0x30, 0x78, 0x58, 0x1C, 0x9C, 0x34, 0x38, 0x84, 0x70, 0x34, 0xA0, 0x48,
0x4C, 0x90, 0x58, 0x28, 0xBC, 0x44, 0x48, 0x98, 0x84, 0x4C, 0xB8, 0x60, 0x00, 0xFC, 0x18, 0x5C,
0xDC, 0x74, 0x7C, 0xD0, 0x8C, 0x88, 0xFC, 0xA0, 0x28, 0x0C, 0x0C, 0x48, 0x18, 0x18, 0x58, 0x00,
0x00, 0x44, 0x14, 0x38, 0x68, 0x24, 0x10, 0x64, 0x3C, 0x28, 0x78, 0x28, 0x28, 0x80, 0x10, 0x4C,
0x84, 0x4C, 0x38, 0x94, 0x30, 0x30, 0x8C, 0x60, 0x48, 0xA0, 0x5C, 0x38, 0xAC, 0x50, 0x50, 0xAC,
0x6C, 0x4C, 0xBC, 0x78, 0x54, 0xD8, 0x60, 0x24, 0xD0, 0x78, 0x64, 0xE0, 0x90, 0x64, 0xDC, 0xA0,
0x80, 0xFC, 0x20, 0xA4, 0xF0, 0x84, 0x84, 0xFC, 0xA0, 0xA0, 0xFC, 0xB8, 0x90, 0x90, 0x8C, 0x58,
0xA4, 0xA0, 0x68, 0xC4, 0xC0, 0x84, 0xD4, 0xD0, 0x98, 0xFC, 0xCC, 0xA8, 0xF4, 0xF4, 0xCC, 0x80,
0xA0, 0xC0, 0xA8, 0xC0, 0xC4, 0x94, 0xC4, 0xE0, 0x74, 0xE8, 0xFC, 0xB0, 0xFC, 0xC4, 0xA4, 0xE4,
0xFC, 0xC4, 0xFC, 0xFC, 0x04, 0x04, 0x04, 0x08, 0x08, 0x08, 0x0C, 0x0C, 0x0C, 0x10, 0x10, 0x10,
0x14, 0x14, 0x14, 0x18, 0x18, 0x18, 0x18, 0x1C, 0x24, 0x20, 0x20, 0x20, 0x24, 0x24, 0x24, 0x28,
0x28, 0x28, 0x20, 0x28, 0x30, 0x30, 0x30, 0x30, 0x28, 0x30, 0x38, 0x34, 0x34, 0x34, 0x3C, 0x38,
0x34, 0x34, 0x38, 0x44, 0x3C, 0x3C, 0x3C, 0x30, 0x3C, 0x4C, 0x40, 0x40, 0x40, 0x3C, 0x40, 0x44,
0x44, 0x44, 0x44, 0x3C, 0x48, 0x50, 0x38, 0x44, 0x58, 0x4C, 0x4C, 0x4C, 0x3C, 0x4C, 0x60, 0x5C,
0x58, 0x34, 0x50, 0x50, 0x50, 0x54, 0x54, 0x54, 0x5C, 0x5C, 0x5C, 0x50, 0x5C, 0x68, 0x60, 0x60,
0x60, 0x74, 0x70, 0x44, 0x50, 0x64, 0x7C, 0x68, 0x68, 0x68, 0x6C, 0x6C, 0x6C, 0x60, 0x6C, 0x78,
0x70, 0x70, 0x70, 0x74, 0x74, 0x74, 0x7C, 0x7C, 0x7C, 0x64, 0x80, 0x94, 0x74, 0x84, 0x90, 0x70,
0x88, 0xAC, 0x90, 0x90, 0x90, 0x84, 0x94, 0x9C, 0xB8, 0x94, 0x80, 0xA0, 0xA0, 0xA0, 0x98, 0xAC,
0xB0, 0xAC, 0xAC, 0xAC, 0xB8, 0xB8, 0xB8, 0xCC, 0xCC, 0xCC, 0xD8, 0xD8, 0xD8, 0xFC, 0xCC, 0xCC,
0xE4, 0xE4, 0xE4, 0x80, 0x00, 0xFC, 0x08, 0x14, 0x10, 0x08, 0x1C, 0x14, 0x08, 0x20, 0x14, 0x0C,
0x24, 0x18, 0x0C, 0x2C, 0x20, 0x18, 0x34, 0x20, 0x1C, 0x38, 0x30, 0x44, 0x20, 0x00, 0x68, 0x00,
0x18, 0x04, 0x08, 0x08, 0x10, 0x14, 0x14, 0x14, 0x18, 0x18, 0x14, 0x1C, 0x1C, 0x10, 0x20, 0x1C,
0x18, 0x20, 0x24, 0x14, 0x28, 0x24, 0x20, 0x28, 0x28, 0x24, 0x28, 0x2C, 0x30, 0x2C, 0x20, 0x24,
0x2C, 0x30, 0x28, 0x30, 0x34, 0x2C, 0x34, 0x38, 0x40, 0x3C, 0x30, 0x34, 0x3C, 0x40, 0x38, 0x44,
0x48, 0x44, 0x4C, 0x50, 0x4C, 0x58, 0x5C, 0x54, 0x5C, 0x60, 0x58, 0x64, 0x68, 0xFF, 0xFF, 0xFF,
byte *palette;

typedef struct dc6header_s
long version; // 06000000
long unknown01; // 01000000
long unknown02; // 00000000
byte termination[4];// EEEEEEEE or CDCDCDCD
long unknown03; // 10000000
long blockcount; // 10000000
// after this, are pointers
long pointer[]; //<------------------------here
} dc6header;
void *pointer_block[12]; //800x600 image has 12
long ofs_x[12];
long ofs_y[12];
typedef struct dc6blockheader_s
long unknown01; // 000000000
long width;
long height;
long unknown02;
long unknown03;
long unknown04;
long next_block;
long length;
byte data[]; //<------------------------here
} dc6blockheader;

typedef struct
char manufacturer;
char version;
char encoding;
char bits_per_pixel;
unsigned short xmin,ymin,xmax,ymax;
unsigned short hres,vres;
unsigned char palette[48];
char reserved;
char color_planes;
unsigned short bytes_per_line;
unsigned short palette_type;
char filler[58];
byte data[]; //<------------------------here
} pcx_t;

#define LittleLong(n) (n)
long BigLong(long n)
byte *a, *b;
long out;
a = (void *) &n;
b = (void *) &out;
b[0] = a[3];
b[1] = a[2];
b[2] = a[1];
b[3] = a[0];
return out;
.... more code

Nov 10, 2004, 10:24 PM
I recall that you can't do that in C/C++. Is there such a thing as flexible arrays? it is either defined as byte data[100], or a pointer.

That is what I remember :D

Nov 11, 2004, 12:52 PM
I concluded the same thing... I changed all the structs to this....

typedef struct dc6blockheader_s
long unknown01 __attribute__((packed)); // 000000000
long width __attribute__((packed));
long height __attribute__((packed));
long unknown02 __attribute__((packed));
long unknown03 __attribute__((packed));
long unknown04 __attribute__((packed));
long next_block __attribute__((packed));
long length __attribute__((packed));
byte data[65000] __attribute__((packed));
} dc6blockheader;

and it compiles ok now

what I need now is to find a way to convert from little endian to big endian hopefully without having to change everything ....again