| 1 |
#ifndef BOOSTERSKEL_H |
| 2 |
#define BOOSTERSKEL_H |
| 3 |
|
| 4 |
#define _XOPEN_SOURCE |
| 5 |
#include <time.h> |
| 6 |
#include <stdint.h> /* for typedefs */ |
| 7 |
#include <setjmp.h> |
| 8 |
|
| 9 |
#define DEGTORAD(x) ((x)/360.*2*M_PI) |
| 10 |
#define F(x) (vals+x) |
| 11 |
|
| 12 |
typedef enum valType_e { |
| 13 |
VAL_NULL, |
| 14 |
VAL_BOOL, |
| 15 |
VAL_CHAR, |
| 16 |
VAL_SHORT, |
| 17 |
VAL_INT, |
| 18 |
VAL_BIGINT, |
| 19 |
VAL_FLOAT, |
| 20 |
VAL_DOUBLE, |
| 21 |
VAL_TEXT, |
| 22 |
VAL_JDATE, /* a julian year ("J2000.0"); this is stored as a simple double */ |
| 23 |
VAL_DATE, /* date expressed as a time_t */ |
| 24 |
VAL_DATETIME, /* date and time expressed as a time_t */ |
| 25 |
VAL_ARRAY, /* pre-serialised by pack*Array, length is # of *bytes* */ |
| 26 |
} valType; |
| 27 |
|
| 28 |
#define STRINGIFY(x) #x |
| 29 |
#define STRINGIFY_VAL(arg) STRINGIFY(arg) |
| 30 |
|
| 31 |
typedef struct Field_s { |
| 32 |
valType type; |
| 33 |
int length; /* ignored for anything but VAL_TEXT and VAL_ARRAY */ |
| 34 |
union { |
| 35 |
char *c_ptr; |
| 36 |
unsigned char *arr_ptr; |
| 37 |
double c_double; |
| 38 |
float c_float; |
| 39 |
int64_t c_int64; |
| 40 |
int32_t c_int32; |
| 41 |
int16_t c_int16; |
| 42 |
int8_t c_int8; |
| 43 |
time_t time; |
| 44 |
} val; |
| 45 |
} Field; |
| 46 |
|
| 47 |
|
| 48 |
#define MAKE_NULL(fi) F(fi)->type=VAL_NULL |
| 49 |
#define MAKE_DOUBLE(fi, value) {\ |
| 50 |
F(fi)->type=VAL_DOUBLE; F(fi)->val.c_double = value;} |
| 51 |
#define MAKE_FLOAT(fi, value) {\ |
| 52 |
F(fi)->type=VAL_FLOAT; F(fi)->val.c_float = value;} |
| 53 |
#define MAKE_SHORT(fi, value) {\ |
| 54 |
F(fi)->type=VAL_SHORT; F(fi)->val.c_int16 = value;} |
| 55 |
#define MAKE_INT(fi, value) {\ |
| 56 |
F(fi)->type=VAL_INT; F(fi)->val.c_int32 = value;} |
| 57 |
#define MAKE_BIGINT(fi, value) {\ |
| 58 |
F(fi)->type=VAL_BIGINT; F(fi)->val.c_int64 = value;} |
| 59 |
#define MAKE_CHAR(fi, value) {\ |
| 60 |
F(fi)->type=VAL_CHAR; F(fi)->val.c_int8 = value;} |
| 61 |
#define MAKE_BYTE(fi, value) {\ |
| 62 |
F(fi)->type=VAL_CHAR; F(fi)->val.c_int8 = value;} |
| 63 |
#define MAKE_CHAR_NULL(fi, value, nullvalue) {\ |
| 64 |
if ((value)==(nullvalue)) { MAKE_NULL(fi); } else {MAKE_CHAR(fi, value);}} |
| 65 |
#define MAKE_JDATE(fi, value) {\ |
| 66 |
F(fi)->type=VAL_JDATE; F(fi)->val.c_double = value;} |
| 67 |
#define MAKE_TEXT(fi, value) {\ |
| 68 |
F(fi)->type=VAL_TEXT; F(fi)->val.c_ptr = value;} |
| 69 |
#define MAKE_ARRAY(fi, value, nbytes) {\ |
| 70 |
F(fi)->type=VAL_ARRAY; F(fi)->val.arr_ptr = value; F(fi)->length = nbytes;} |
| 71 |
|
| 72 |
#define MAKE_WITH_NULL(type, fi, value, nullvalue) {\ |
| 73 |
if ((value)==(nullvalue)) { MAKE_NULL(fi); } else {\ |
| 74 |
MAKE_##type(fi, value);}} |
| 75 |
|
| 76 |
#define AS2DEG(field) linearTransform(F(field), 0, 1/3600.) |
| 77 |
#define MAS2DEG(field) linearTransform(F(field), 0, 1/3600./1000.) |
| 78 |
|
| 79 |
#define fieldscanf(str, fieldName, type, ...) \ |
| 80 |
real_fieldscanf((str), vals+(fieldName), type, STRINGIFY(fieldName),\ |
| 81 |
## __VA_ARGS__) |
| 82 |
|
| 83 |
void die(char *format, ...); |
| 84 |
void linearTransform(Field *field, double offset, double factor); |
| 85 |
int julian2unixtime(double julian, time_t *result); |
| 86 |
double mjdToJYear(double mjd); |
| 87 |
void makeTimeFromJd(Field *field); |
| 88 |
void stripWhitespace(char *str); |
| 89 |
char* copyString(char *src, char *dest, int start, int len); |
| 90 |
int isWhitespaceOnly(char *str); |
| 91 |
void parseFloat(char *src, Field *field, int start, int len); |
| 92 |
void parseFloatWithMagicNULL(char *src, Field *field, int start, int len, |
| 93 |
char *magicVal); |
| 94 |
void parseDoubleWithMagicNULL(char *src, Field *field, int start, int len, |
| 95 |
char *magicVal); |
| 96 |
void parseDouble(char *src, Field *field, int start, int len); |
| 97 |
void parseInt(char *src, Field *field, int start, int len); |
| 98 |
void parseBigint(char *src, Field *field, int start, int len); |
| 99 |
void parseShort(char *src, Field *field, int start, int len); |
| 100 |
void parseBlankBoolean(char *src, Field *field, int srcInd); |
| 101 |
void parseString(char *src, Field *field, int start, int len, char *space); |
| 102 |
void parseStringWithMagicNull(char *src, Field *field, int start, int len, |
| 103 |
char *space, char *magic); |
| 104 |
void parseChar(char *src, Field *field, int srcInd); |
| 105 |
void real_fieldscanf(char *str, Field *f, valType type, char *fieldName, ...); |
| 106 |
size_t packArray(unsigned char *buf, unsigned char *vals, int nVals, |
| 107 |
int itemoid, size_t itemsize, int littleEndian); |
| 108 |
|
| 109 |
int degToDms(double deg, char *sign_out, |
| 110 |
int *degs_out, int *minutes_out, double *seconds_out); |
| 111 |
int degToHms(double deg, |
| 112 |
int *hours_out, int *minutes_out, double *seconds_out); |
| 113 |
double jYearToJDN(double jYear); |
| 114 |
|
| 115 |
char *strtok_u(char *arg, char *separator); |
| 116 |
|
| 117 |
// functions for creating dump files |
| 118 |
void writeHeader(void *destination); |
| 119 |
void handleBadRecord(char *format, ...); |
| 120 |
void createDumpfile(int argc, char **argv); |
| 121 |
void writeTuple(Field *fields, int numFields, void *destination); |
| 122 |
void writeEndMarker(void *destination); |
| 123 |
|
| 124 |
extern char *context; // handleInvalidRecord() looks here to give |
| 125 |
// more informative error messages |
| 126 |
|
| 127 |
extern jmp_buf ignoreRecord; // longjmp target for non-letal bad records |
| 128 |
|
| 129 |
#endif |