Index: altium/Makefile =================================================================== --- altium/Makefile (revision 35505) +++ altium/Makefile (revision 35506) @@ -1,12 +1,18 @@ IOA=../../../trunk/src_plugins/io_altium CFLAGS = -Wall -g -I. -test: test.o pcbdoc_bin.o +test: test.o pcbdoc_bin.o altium_kw_sphash.o test.o: test.c pcbdoc_bin.o: pcbdoc_bin.c pcbdoc_bin.h +altium_kw_sphash.o: altium_kw_sphash.c altium_kw_sphash.h + pcbdoc_bin.c pcbdoc_bin.h: - -ln -s $(IOA)/pcbdoc_bin.c pcbdoc_bin.c - -ln -s $(IOA)/pcbdoc_bin.h pcbdoc_bin.h + ln -sf $(IOA)/pcbdoc_bin.c pcbdoc_bin.c + ln -sf $(IOA)/pcbdoc_bin.h pcbdoc_bin.h + +altium_kw_sphash.c altium_kw_sphash.h: + ln -sf $(IOA)/altium_kw_sphash.c altium_kw_sphash.c + ln -sf $(IOA)/altium_kw_sphash.h altium_kw_sphash.h Index: altium/config.h =================================================================== --- altium/config.h (revision 35505) +++ altium/config.h (revision 35506) @@ -1,4 +1,11 @@ /* librnd */ +#ifndef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE +#endif +#include +#include +#include + typedef struct rnd_hidlib_s { int dummy; } rnd_hidlib_t; @@ -5,8 +12,16 @@ #define RND_MSG_ERROR 0 -#define rnd_message(level, fmt, ...) fprintf(stderr, fmt, __VA_ARGS__) +static inline void rnd_message(int level, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); +} +static inline int rnd_strcasecmp(const char *a, const char *b) { return strcasecmp(a, b); } + #define DO_PRAGMA(arg) _Pragma(#arg) #define TODO(x) DO_PRAGMA(message("TODO: " #x)) Index: altium/libucdf/ucdf.h =================================================================== --- altium/libucdf/ucdf.h (revision 35505) +++ altium/libucdf/ucdf.h (revision 35506) @@ -2,6 +2,83 @@ #include #define ucdf_file_t FILE +typedef enum { + UCDF_SECT_FREE = -1, + UCDF_SECT_EOC = -2, /* end of chain */ + UCDF_SECT_SAT = -3, /* sector allocation table */ + UCDF_SECT_MSAT = -4 /* master sector allocation table */ +} ucdf_spec_sect_id_t; + +typedef enum { + UCDF_ERR_SUCCESS = 0, + UCDF_ERR_OPEN, + UCDF_ERR_READ, + UCDF_ERR_BAD_ID, + UCDF_ERR_BAD_HDR, + UCDF_ERR_BAD_MSAT, + UCDF_ERR_BAD_SAT, + UCDF_ERR_BAD_SSAT, + UCDF_ERR_BAD_DIRCHAIN, + UCDF_ERR_BAD_MALLOC +} ucdf_error_t; + +extern const char *ucdf_error_str[]; /* indexed by ucdf_error_t (typically ctx->error) */ + +typedef enum { + UCDF_DE_EMPTY = 0, + UCDF_DE_DIR = 1, + UCDF_DE_FILE = 2, /* "stream" */ + UCDF_DE_LOCK = 3, + UCDF_DE_PROP = 4, + UCDF_DE_ROOT = 5 +} ucdf_detype_t; + +typedef struct ucdf_ctx_s ucdf_ctx_t; +typedef struct ucdf_direntry_s ucdf_direntry_t; + +struct ucdf_direntry_s { + char name[32]; /* converted to ASCII */ + ucdf_detype_t type; + long size; + unsigned is_short:1; /* if set: file is short, using short sectors */ + long first; /* sector id (long or short) of the first sector */ + ucdf_direntry_t *parent; + ucdf_direntry_t *children; + ucdf_direntry_t *next; /* within children */ + + void *user_data; +}; + +struct ucdf_ctx_s { + ucdf_error_t error; /* last error experienced in parsing */ + int file_ver, file_rev, sect_size, short_sect_size; + + unsigned litend:1; /* set if file is little endian */ + + ucdf_direntry_t *root; + + void *user_data; + + /* cache/interanl */ + FILE *f; /* the file we are reading from */ + int ssz, sssz; + long sat_len; + long dir_first; /* first sector ID of the directory stream */ + long ssat_len, ssat_first; /* short allocation table */ + long msat_len, msat_first; /* master allocation table */ + long long_stream_min_size; + + long *msat; /* the master SAT read into memory */ + long *sat; /* the whole SAT assembled and read into memory; entries are indexed by sector ID and contain the next sector ID within the chain */ + long *ssat; /* the whole Short-SAT assembled and read into memory */ + + /* short sector data is really stored in a long stream; keep a file open on it */ + ucdf_direntry_t ssd_de; + ucdf_file_t ssd_f; +}; + + + static inline long ucdf_fread(ucdf_file_t *fp, char *dst, long len) { long res; @@ -17,3 +94,15 @@ { return 0; } + +static inline int ucdf_open(ucdf_ctx_t *ctx, const char *path) +{ + return -1; +} + +static inline void ucdf_close(ucdf_ctx_t *ctx) {} + +static inline int ucdf_fopen(ucdf_ctx_t *ctx, ucdf_file_t *fp, ucdf_direntry_t *de) +{ + return -1; +}