#define ATTRTYPES_STR_MAX_LEN (1024-1)
-typedef int (*decode_callback_t)(const char* buffer, unsigned int buff_size,
- unsigned int* out_size);
+typedef int (*decode_callback_t) (const char *buffer, unsigned int buff_size,
+ unsigned int *out_size);
static int
-decode_smallint(const char* buffer, unsigned int buff_size, unsigned int* out_size);
+decode_smallint(const char *buffer, unsigned int buff_size, unsigned int *out_size);
static int
-decode_int(const char* buffer, unsigned int buff_size, unsigned int* out_size);
+decode_int(const char *buffer, unsigned int buff_size, unsigned int *out_size);
static int
-decode_bigint(const char* buffer, unsigned int buff_size, unsigned int* out_size);
+decode_bigint(const char *buffer, unsigned int buff_size, unsigned int *out_size);
static int
-decode_time(const char* buffer, unsigned int buff_size, unsigned int* out_size);
+decode_time(const char *buffer, unsigned int buff_size, unsigned int *out_size);
static int
-decode_timetz(const char* buffer, unsigned int buff_size, unsigned int* out_size);
+decode_timetz(const char *buffer, unsigned int buff_size, unsigned int *out_size);
static int
-decode_date(const char* buffer, unsigned int buff_size, unsigned int* out_size);
+decode_date(const char *buffer, unsigned int buff_size, unsigned int *out_size);
static int
-decode_timestamp(const char* buffer, unsigned int buff_size, unsigned int* out_size);
+decode_timestamp(const char *buffer, unsigned int buff_size, unsigned int *out_size);
static int
-decode_float4(const char* buffer, unsigned int buff_size, unsigned int* out_size);
+decode_float4(const char *buffer, unsigned int buff_size, unsigned int *out_size);
static int
-decode_float8(const char* buffer, unsigned int buff_size, unsigned int* out_size);
+decode_float8(const char *buffer, unsigned int buff_size, unsigned int *out_size);
static int
-decode_bool(const char* buffer, unsigned int buff_size, unsigned int* out_size);
+decode_bool(const char *buffer, unsigned int buff_size, unsigned int *out_size);
static int
-decode_uuid(const char* buffer, unsigned int buff_size, unsigned int* out_size);
+decode_uuid(const char *buffer, unsigned int buff_size, unsigned int *out_size);
static int
-decode_macaddr(const char* buffer, unsigned int buff_size, unsigned int* out_size);
+decode_macaddr(const char *buffer, unsigned int buff_size, unsigned int *out_size);
static int
-decode_string(const char* buffer, unsigned int buff_size, unsigned int* out_size);
+decode_string(const char *buffer, unsigned int buff_size, unsigned int *out_size);
static int
-decode_char(const char* buffer, unsigned int buff_size, unsigned int* out_size);
+decode_char(const char *buffer, unsigned int buff_size, unsigned int *out_size);
static int
-decode_name(const char* buffer, unsigned int buff_size, unsigned int* out_size);
+decode_name(const char *buffer, unsigned int buff_size, unsigned int *out_size);
static int
-decode_ignore(const char* buffer, unsigned int buff_size, unsigned int* out_size);
+decode_ignore(const char *buffer, unsigned int buff_size, unsigned int *out_size);
-static int ncallbacks = 0;
-static decode_callback_t callbacks[ATTRTYPES_STR_MAX_LEN / 2] = { NULL };
+static int ncallbacks = 0;
+static decode_callback_t callbacks[ATTRTYPES_STR_MAX_LEN / 2] =
+{
+ NULL
+};
-typedef struct {
- char* name;
+typedef struct
+{
+ char *name;
decode_callback_t callback;
-} ParseCallbackTableItem;
-
-static ParseCallbackTableItem callback_table[] = {
- { "smallserial", &decode_smallint },
- { "smallint", &decode_smallint },
- { "int", &decode_int },
- { "oid", &decode_int },
- { "xid", &decode_int },
- { "serial", &decode_int },
- { "bigint", &decode_bigint },
- { "bigserial", &decode_bigint },
- { "time", &decode_time },
- { "timetz", &decode_timetz },
- { "date", &decode_date },
- { "timestamp", &decode_timestamp },
- { "real", &decode_float4 },
- { "float4", &decode_float4 },
- { "float8", &decode_float8 },
- { "float", &decode_float8 },
- { "bool", &decode_bool },
- { "uuid", &decode_uuid },
- { "macaddr", &decode_macaddr },
- { "name", &decode_name },
- { "char", &decode_char },
- { "~", &decode_ignore },
+} ParseCallbackTableItem;
+
+static ParseCallbackTableItem callback_table[] =
+{
+ {
+ "smallserial", &decode_smallint
+ },
+ {
+ "smallint", &decode_smallint
+ },
+ {
+ "int", &decode_int
+ },
+ {
+ "oid", &decode_int
+ },
+ {
+ "xid", &decode_int
+ },
+ {
+ "serial", &decode_int
+ },
+ {
+ "bigint", &decode_bigint
+ },
+ {
+ "bigserial", &decode_bigint
+ },
+ {
+ "time", &decode_time
+ },
+ {
+ "timetz", &decode_timetz
+ },
+ {
+ "date", &decode_date
+ },
+ {
+ "timestamp", &decode_timestamp
+ },
+ {
+ "real", &decode_float4
+ },
+ {
+ "float4", &decode_float4
+ },
+ {
+ "float8", &decode_float8
+ },
+ {
+ "float", &decode_float8
+ },
+ {
+ "bool", &decode_bool
+ },
+ {
+ "uuid", &decode_uuid
+ },
+ {
+ "macaddr", &decode_macaddr
+ },
+ {
+ "name", &decode_name
+ },
+ {
+ "char", &decode_char
+ },
+ {
+ "~", &decode_ignore
+ },
/* internally all string types are stored the same way */
- { "charN", &decode_string },
- { "varchar", &decode_string },
- { "varcharN", &decode_string },
- { "text", &decode_string },
- { "json", &decode_string },
- { "xml", &decode_string },
- { NULL, NULL},
+ {
+ "charN", &decode_string
+ },
+ {
+ "varchar", &decode_string
+ },
+ {
+ "varcharN", &decode_string
+ },
+ {
+ "text", &decode_string
+ },
+ {
+ "json", &decode_string
+ },
+ {
+ "xml", &decode_string
+ },
+ {
+ NULL, NULL
+ },
};
static StringInfoData copyString;
* this limit. Unfortunately there is no way to know how much memory user
* is willing to allocate.
*/
-static char decompress_tmp_buff[64*1024];
+static char decompress_tmp_buff[64 * 1024];
/* Used by some PostgreSQL macro definitions */
void
int lineNumber)
{
printf("Exceptional condition: name = %s, type = %s, fname = %s, line = %d\n",
- conditionName ? conditionName : "(NULL)",
- errorType ? errorType : "(NULL)",
- fileName ? fileName : "(NULL)",
- lineNumber);
+ conditionName ? conditionName : "(NULL)",
+ errorType ? errorType : "(NULL)",
+ fileName ? fileName : "(NULL)",
+ lineNumber);
exit(1);
}
/* Append given string to current COPY line */
static void
-CopyAppend(const char* str)
+CopyAppend(const char *str)
{
- if(!copyStringInitDone)
+ if (!copyStringInitDone)
{
initStringInfo(©String);
copyStringInitDone = true;
}
/* Caller probably wanted just to init copyString */
- if(str == NULL)
+ if (str == NULL)
return;
- if(copyString.data[0] != '\0')
+ if (copyString.data[0] != '\0')
appendStringInfoString(©String, "\t");
appendStringInfoString(©String, str);
* like \r, \n, \t and \\.
*/
static void
-CopyAppendEncode(const char* str, int orig_len)
+CopyAppendEncode(const char *str, int orig_len)
{
/*
* Should be enough in most cases. If it's not user can manually change
* this limit. Unfortunately there is no way to know how much memory user
* is willing to allocate.
*/
- static char tmp_buff[64*1024];
+ static char tmp_buff[64 * 1024];
+
/* Reserve one byte for a trailing zero. */
- const int max_offset = sizeof(tmp_buff) - 2;
- int curr_offset = 0;
- int len = orig_len;
+ const int max_offset = sizeof(tmp_buff) - 2;
+ int curr_offset = 0;
+ int len = orig_len;
- while(len > 0)
+ while (len > 0)
{
/*
- * Make sure there is enough free space for at least one special symbol
- * and a trailing zero.
+ * Make sure there is enough free space for at least one special
+ * symbol and a trailing zero.
*/
- if(curr_offset > max_offset - 2)
+ if (curr_offset > max_offset - 2)
{
printf("ERROR: Unable to properly encode a string since it's too "
- "large (%d bytes). Try to increase tmp_buff size in CopyAppendEncode "
- "procedure.\n", orig_len);
+ "large (%d bytes). Try to increase tmp_buff size in CopyAppendEncode "
+ "procedure.\n", orig_len);
exit(1);
}
/*
- * Since we are working with potentially corrupted data we can encounter
- * \0 as well.
+ * Since we are working with potentially corrupted data we can
+ * encounter \0 as well.
*/
- if(*str == '\0')
+ if (*str == '\0')
{
tmp_buff[curr_offset] = '\\';
- tmp_buff[curr_offset+1] = '0';
+ tmp_buff[curr_offset + 1] = '0';
curr_offset += 2;
}
- else if(*str == '\r')
+ else if (*str == '\r')
{
tmp_buff[curr_offset] = '\\';
- tmp_buff[curr_offset+1] = 'r';
+ tmp_buff[curr_offset + 1] = 'r';
curr_offset += 2;
}
- else if(*str == '\n')
+ else if (*str == '\n')
{
tmp_buff[curr_offset] = '\\';
- tmp_buff[curr_offset+1] = 'n';
+ tmp_buff[curr_offset + 1] = 'n';
curr_offset += 2;
}
- else if(*str == '\t')
+ else if (*str == '\t')
{
tmp_buff[curr_offset] = '\\';
- tmp_buff[curr_offset+1] = 'r';
+ tmp_buff[curr_offset + 1] = 'r';
curr_offset += 2;
}
- else if(*str == '\\')
+ else if (*str == '\\')
{
tmp_buff[curr_offset] = '\\';
- tmp_buff[curr_offset+1] = '\\';
+ tmp_buff[curr_offset + 1] = '\\';
curr_offset += 2;
}
else
* < 0 - invalid type name
*/
static int
-AddTypeCallback(const char* type)
+AddTypeCallback(const char *type)
{
- int idx = 0;
+ int idx = 0;
- if(*type == '\0') /* ignore empty strings */
+ if (*type == '\0') /* ignore empty strings */
return 0;
- while(callback_table[idx].name != NULL)
+ while (callback_table[idx].name != NULL)
{
- if(strcmp(callback_table[idx].name, type) == 0)
+ if (strcmp(callback_table[idx].name, type) == 0)
{
callbacks[ncallbacks] = callback_table[idx].callback;
ncallbacks++;
printf("Error: type <%s> doesn't exist or is not currently supported\n", type);
printf("Full list of known types: ");
idx = 0;
- while(callback_table[idx].name != NULL)
+ while (callback_table[idx].name != NULL)
{
printf("%s ", callback_table[idx].name);
idx++;
* < 0 - if string is invalid
*/
int
-ParseAttributeTypesString(const char* str)
+ParseAttributeTypesString(const char *str)
{
- char *curr_type, *next_type;
- char attrtypes[ATTRTYPES_STR_MAX_LEN+1];
- int i, len = strlen(str);
+ char *curr_type,
+ *next_type;
+ char attrtypes[ATTRTYPES_STR_MAX_LEN + 1];
+ int i,
+ len = strlen(str);
- if(len > ATTRTYPES_STR_MAX_LEN)
+ if (len > ATTRTYPES_STR_MAX_LEN)
{
printf("Error: attribute types string is longer then %u characters!\n",
- ATTRTYPES_STR_MAX_LEN);
+ ATTRTYPES_STR_MAX_LEN);
return -1;
}
strcpy(attrtypes, str);
- for(i = 0; i < len; i++)
+ for (i = 0; i < len; i++)
attrtypes[i] = tolower(attrtypes[i]);
curr_type = attrtypes;
- while(curr_type)
+ while (curr_type)
{
next_type = strstr(curr_type, ",");
- if(next_type)
+ if (next_type)
{
*next_type = '\0';
next_type++;
}
- if(AddTypeCallback(curr_type) < 0)
+ if (AddTypeCallback(curr_type) < 0)
return -1;
curr_type = next_type;
unsigned int julian;
unsigned int quad;
unsigned int extra;
- int y;
+ int y;
julian = jd;
julian += 32044;
/* Decode a smallint type */
static int
-decode_smallint(const char* buffer, unsigned int buff_size, unsigned int* out_size)
+decode_smallint(const char *buffer, unsigned int buff_size, unsigned int *out_size)
{
- const char* new_buffer = (const char*)TYPEALIGN(sizeof(int16), (uintptr_t)buffer);
- unsigned int delta = (unsigned int)( (uintptr_t)new_buffer - (uintptr_t)buffer );
+ const char *new_buffer = (const char *) TYPEALIGN(sizeof(int16), (uintptr_t) buffer);
+ unsigned int delta = (unsigned int) ((uintptr_t) new_buffer - (uintptr_t) buffer);
- if(buff_size < delta)
+ if (buff_size < delta)
return -1;
buff_size -= delta;
buffer = new_buffer;
- if(buff_size < sizeof(int16))
+ if (buff_size < sizeof(int16))
return -2;
- CopyAppendFmt("%d", (int)(*(int16*)buffer));
+ CopyAppendFmt("%d", (int) (*(int16 *) buffer));
*out_size = sizeof(int16) + delta;
return 0;
}
/* Decode an int type */
static int
-decode_int(const char* buffer, unsigned int buff_size, unsigned int* out_size)
+decode_int(const char *buffer, unsigned int buff_size, unsigned int *out_size)
{
- const char* new_buffer = (const char*)TYPEALIGN(sizeof(int32), (uintptr_t)buffer);
- unsigned int delta = (unsigned int)( (uintptr_t)new_buffer - (uintptr_t)buffer );
+ const char *new_buffer = (const char *) TYPEALIGN(sizeof(int32), (uintptr_t) buffer);
+ unsigned int delta = (unsigned int) ((uintptr_t) new_buffer - (uintptr_t) buffer);
- if(buff_size < delta)
+ if (buff_size < delta)
return -1;
buff_size -= delta;
buffer = new_buffer;
- if(buff_size < sizeof(int32))
+ if (buff_size < sizeof(int32))
return -2;
- CopyAppendFmt("%d", *(int32*)buffer);
+ CopyAppendFmt("%d", *(int32 *) buffer);
*out_size = sizeof(int32) + delta;
return 0;
}
/* Decode a bigint type */
static int
-decode_bigint(const char* buffer, unsigned int buff_size, unsigned int* out_size)
+decode_bigint(const char *buffer, unsigned int buff_size, unsigned int *out_size)
{
- const char* new_buffer = (const char*)TYPEALIGN(sizeof(int64), (uintptr_t)buffer);
- unsigned int delta = (unsigned int)( (uintptr_t)new_buffer - (uintptr_t)buffer );
+ const char *new_buffer = (const char *) TYPEALIGN(sizeof(int64), (uintptr_t) buffer);
+ unsigned int delta = (unsigned int) ((uintptr_t) new_buffer - (uintptr_t) buffer);
- if(buff_size < delta)
+ if (buff_size < delta)
return -1;
buff_size -= delta;
buffer = new_buffer;
- if(buff_size < sizeof(int64))
+ if (buff_size < sizeof(int64))
return -2;
- CopyAppendFmt("%ld", *(int64*)buffer);
+ CopyAppendFmt("%ld", *(int64 *) buffer);
*out_size = sizeof(int64) + delta;
return 0;
}
/* Decode a time type */
static int
-decode_time(const char* buffer, unsigned int buff_size, unsigned int* out_size)
+decode_time(const char *buffer, unsigned int buff_size, unsigned int *out_size)
{
- const char* new_buffer = (const char*)TYPEALIGN(sizeof(int64), (uintptr_t)buffer);
- unsigned int delta = (unsigned int)( (uintptr_t)new_buffer - (uintptr_t)buffer );
- int64 timestamp, timestamp_sec;
+ const char *new_buffer = (const char *) TYPEALIGN(sizeof(int64), (uintptr_t) buffer);
+ unsigned int delta = (unsigned int) ((uintptr_t) new_buffer - (uintptr_t) buffer);
+ int64 timestamp,
+ timestamp_sec;
- if(buff_size < delta)
+ if (buff_size < delta)
return -1;
buff_size -= delta;
buffer = new_buffer;
- if(buff_size < sizeof(int64))
+ if (buff_size < sizeof(int64))
return -2;
- timestamp = *(int64*)buffer;
+ timestamp = *(int64 *) buffer;
timestamp_sec = timestamp / 1000000;
*out_size = sizeof(int64) + delta;
CopyAppendFmt("%02ld:%02ld:%02ld.%06ld",
- timestamp_sec / 60 / 60, (timestamp_sec / 60) % 60, timestamp_sec % 60,
- timestamp % 1000000);
+ timestamp_sec / 60 / 60, (timestamp_sec / 60) % 60, timestamp_sec % 60,
+ timestamp % 1000000);
return 0;
}
/* Decode a timetz type */
static int
-decode_timetz(const char* buffer, unsigned int buff_size, unsigned int* out_size)
+decode_timetz(const char *buffer, unsigned int buff_size, unsigned int *out_size)
{
- const char* new_buffer = (const char*)TYPEALIGN(sizeof(int64), (uintptr_t)buffer);
- unsigned int delta = (unsigned int)( (uintptr_t)new_buffer - (uintptr_t)buffer );
- int64 timestamp, timestamp_sec;
- int32 tz_sec, tz_min;
-
- if(buff_size < delta)
+ const char *new_buffer = (const char *) TYPEALIGN(sizeof(int64), (uintptr_t) buffer);
+ unsigned int delta = (unsigned int) ((uintptr_t) new_buffer - (uintptr_t) buffer);
+ int64 timestamp,
+ timestamp_sec;
+ int32 tz_sec,
+ tz_min;
+
+ if (buff_size < delta)
return -1;
buff_size -= delta;
buffer = new_buffer;
- if(buff_size < (sizeof(int64) + sizeof(int32)))
+ if (buff_size < (sizeof(int64) + sizeof(int32)))
return -2;
- timestamp = *(int64*)buffer;
- tz_sec = *(int32*)(buffer + sizeof(int64));
+ timestamp = *(int64 *) buffer;
+ tz_sec = *(int32 *) (buffer + sizeof(int64));
timestamp_sec = timestamp / 1000000;
- tz_min = - (tz_sec / 60);
+ tz_min = -(tz_sec / 60);
*out_size = sizeof(int64) + sizeof(int32) + delta;
CopyAppendFmt("%02ld:%02ld:%02ld.%06ld%c%02d:%02d",
- timestamp_sec / 60 / 60, (timestamp_sec / 60) % 60, timestamp_sec % 60,
- timestamp % 1000000, (tz_min > 0 ? '+' : '-'), abs(tz_min / 60), abs(tz_min % 60));
+ timestamp_sec / 60 / 60, (timestamp_sec / 60) % 60, timestamp_sec % 60,
+ timestamp % 1000000, (tz_min > 0 ? '+' : '-'), abs(tz_min / 60), abs(tz_min % 60));
return 0;
}
/* Decode a date type */
static int
-decode_date(const char* buffer, unsigned int buff_size, unsigned int* out_size)
+decode_date(const char *buffer, unsigned int buff_size, unsigned int *out_size)
{
- const char* new_buffer = (const char*)TYPEALIGN(sizeof(int32), (uintptr_t)buffer);
- unsigned int delta = (unsigned int)( (uintptr_t)new_buffer - (uintptr_t)buffer );
- int32 jd, year, month, day;
-
- if(buff_size < delta)
+ const char *new_buffer = (const char *) TYPEALIGN(sizeof(int32), (uintptr_t) buffer);
+ unsigned int delta = (unsigned int) ((uintptr_t) new_buffer - (uintptr_t) buffer);
+ int32 jd,
+ year,
+ month,
+ day;
+
+ if (buff_size < delta)
return -1;
buff_size -= delta;
buffer = new_buffer;
- if(buff_size < sizeof(int32))
+ if (buff_size < sizeof(int32))
return -2;
*out_size = sizeof(int32) + delta;
- jd = *(int32*)buffer + POSTGRES_EPOCH_JDATE;
+ jd = *(int32 *) buffer + POSTGRES_EPOCH_JDATE;
j2date(jd, &year, &month, &day);
CopyAppendFmt("%04d-%02d-%02d%s", (year <= 0) ? -year + 1 : year, month, day, (year <= 0) ? " BC" : "");
/* Decode a timestamp type */
static int
-decode_timestamp(const char* buffer, unsigned int buff_size, unsigned int* out_size)
+decode_timestamp(const char *buffer, unsigned int buff_size, unsigned int *out_size)
{
- const char* new_buffer = (const char*)TYPEALIGN(sizeof(int64), (uintptr_t)buffer);
- unsigned int delta = (unsigned int)( (uintptr_t)new_buffer - (uintptr_t)buffer );
- int64 timestamp, timestamp_sec;
- int32 jd, year, month, day;
-
- if(buff_size < delta)
+ const char *new_buffer = (const char *) TYPEALIGN(sizeof(int64), (uintptr_t) buffer);
+ unsigned int delta = (unsigned int) ((uintptr_t) new_buffer - (uintptr_t) buffer);
+ int64 timestamp,
+ timestamp_sec;
+ int32 jd,
+ year,
+ month,
+ day;
+
+ if (buff_size < delta)
return -1;
buff_size -= delta;
buffer = new_buffer;
- if(buff_size < sizeof(int64))
+ if (buff_size < sizeof(int64))
return -2;
*out_size = sizeof(int64) + delta;
- timestamp = *(int64*)buffer;
+ timestamp = *(int64 *) buffer;
jd = timestamp / USECS_PER_DAY;
if (jd != 0)
timestamp_sec = timestamp / 1000000;
CopyAppendFmt("%04d-%02d-%02d %02ld:%02ld:%02ld.%06ld%s",
- (year <= 0) ? -year + 1 : year, month, day,
- timestamp_sec / 60 / 60, (timestamp_sec / 60) % 60, timestamp_sec % 60,
- timestamp % 1000000,
- (year <= 0) ? " BC" : "");
+ (year <= 0) ? -year + 1 : year, month, day,
+ timestamp_sec / 60 / 60, (timestamp_sec / 60) % 60, timestamp_sec % 60,
+ timestamp % 1000000,
+ (year <= 0) ? " BC" : "");
return 0;
}
/* Decode a float4 type */
static int
-decode_float4(const char* buffer, unsigned int buff_size, unsigned int* out_size)
+decode_float4(const char *buffer, unsigned int buff_size, unsigned int *out_size)
{
- const char* new_buffer = (const char*)TYPEALIGN(sizeof(float), (uintptr_t)buffer);
- unsigned int delta = (unsigned int)( (uintptr_t)new_buffer - (uintptr_t)buffer );
+ const char *new_buffer = (const char *) TYPEALIGN(sizeof(float), (uintptr_t) buffer);
+ unsigned int delta = (unsigned int) ((uintptr_t) new_buffer - (uintptr_t) buffer);
- if(buff_size < delta)
+ if (buff_size < delta)
return -1;
buff_size -= delta;
buffer = new_buffer;
- if(buff_size < sizeof(float))
+ if (buff_size < sizeof(float))
return -2;
- CopyAppendFmt("%.12f", *(float*)buffer);
+ CopyAppendFmt("%.12f", *(float *) buffer);
*out_size = sizeof(float) + delta;
return 0;
}
/* Decode a float8 type */
static int
-decode_float8(const char* buffer, unsigned int buff_size, unsigned int* out_size)
+decode_float8(const char *buffer, unsigned int buff_size, unsigned int *out_size)
{
- const char* new_buffer = (const char*)TYPEALIGN(sizeof(double), (uintptr_t)buffer);
- unsigned int delta = (unsigned int)( (uintptr_t)new_buffer - (uintptr_t)buffer );
+ const char *new_buffer = (const char *) TYPEALIGN(sizeof(double), (uintptr_t) buffer);
+ unsigned int delta = (unsigned int) ((uintptr_t) new_buffer - (uintptr_t) buffer);
- if(buff_size < delta)
+ if (buff_size < delta)
return -1;
buff_size -= delta;
buffer = new_buffer;
- if(buff_size < sizeof(double))
+ if (buff_size < sizeof(double))
return -2;
- CopyAppendFmt("%.12lf", *(double*)buffer);
+ CopyAppendFmt("%.12lf", *(double *) buffer);
*out_size = sizeof(double) + delta;
return 0;
}
/* Decode an uuid type */
static int
-decode_uuid(const char* buffer, unsigned int buff_size, unsigned int* out_size)
+decode_uuid(const char *buffer, unsigned int buff_size, unsigned int *out_size)
{
unsigned char uuid[16];
- if(buff_size < sizeof(uuid))
+ if (buff_size < sizeof(uuid))
return -1;
memcpy(uuid, buffer, sizeof(uuid));
CopyAppendFmt("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
- uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7],
- uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]
+ uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7],
+ uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]
);
*out_size = sizeof(uuid);
return 0;
/* Decode a macaddr type */
static int
-decode_macaddr(const char* buffer, unsigned int buff_size, unsigned int* out_size)
+decode_macaddr(const char *buffer, unsigned int buff_size, unsigned int *out_size)
{
unsigned char macaddr[6];
- const char* new_buffer = (const char*)TYPEALIGN(sizeof(int32), (uintptr_t)buffer);
- unsigned int delta = (unsigned int)( (uintptr_t)new_buffer - (uintptr_t)buffer );
+ const char *new_buffer = (const char *) TYPEALIGN(sizeof(int32), (uintptr_t) buffer);
+ unsigned int delta = (unsigned int) ((uintptr_t) new_buffer - (uintptr_t) buffer);
- if(buff_size < delta)
+ if (buff_size < delta)
return -1;
buff_size -= delta;
buffer = new_buffer;
- if(buff_size < sizeof(macaddr))
+ if (buff_size < sizeof(macaddr))
return -2;
memcpy(macaddr, buffer, sizeof(macaddr));
CopyAppendFmt("%02x:%02x:%02x:%02x:%02x:%02x",
- macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]
+ macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]
);
*out_size = sizeof(macaddr) + delta;
return 0;
/* Decode a bool type */
static int
-decode_bool(const char* buffer, unsigned int buff_size, unsigned int* out_size)
+decode_bool(const char *buffer, unsigned int buff_size, unsigned int *out_size)
{
- if(buff_size < sizeof(bool))
+ if (buff_size < sizeof(bool))
return -1;
- CopyAppend(*(bool*)buffer ? "t" : "f");
+ CopyAppend(*(bool *) buffer ? "t" : "f");
*out_size = sizeof(bool);
return 0;
}
/* Decode a name type (used mostly in catalog tables) */
static int
-decode_name(const char* buffer, unsigned int buff_size, unsigned int* out_size)
+decode_name(const char *buffer, unsigned int buff_size, unsigned int *out_size)
{
- const char* new_buffer = (const char*)TYPEALIGN(sizeof(uint32), (uintptr_t)buffer);
- unsigned int delta = (unsigned int)( (uintptr_t)new_buffer - (uintptr_t)buffer );
+ const char *new_buffer = (const char *) TYPEALIGN(sizeof(uint32), (uintptr_t) buffer);
+ unsigned int delta = (unsigned int) ((uintptr_t) new_buffer - (uintptr_t) buffer);
- if(buff_size < delta)
+ if (buff_size < delta)
return -1;
buff_size -= delta;
buffer = new_buffer;
- if(buff_size < NAMEDATALEN)
+ if (buff_size < NAMEDATALEN)
return -2;
CopyAppendEncode(buffer, strnlen(buffer, NAMEDATALEN));
/* Decode a char type */
static int
-decode_char(const char* buffer, unsigned int buff_size, unsigned int* out_size)
+decode_char(const char *buffer, unsigned int buff_size, unsigned int *out_size)
{
- if(buff_size < sizeof(char))
+ if (buff_size < sizeof(char))
return -2;
CopyAppendEncode(buffer, 1);
/* Ignore all data left */
static int
-decode_ignore(const char* buffer, unsigned int buff_size, unsigned int* out_size)
+decode_ignore(const char *buffer, unsigned int buff_size, unsigned int *out_size)
{
*out_size = buff_size;
return 0;
/* Decode char(N), varchar(N), text, json or xml types */
static int
-decode_string(const char* buffer, unsigned int buff_size, unsigned int* out_size)
+decode_string(const char *buffer, unsigned int buff_size, unsigned int *out_size)
{
- int padding = 0;
+ int padding = 0;
/* Skip padding bytes. */
- while(*buffer == 0x00)
+ while (*buffer == 0x00)
{
- if(buff_size == 0)
+ if (buff_size == 0)
return -1;
buff_size--;
padding++;
}
- if(VARATT_IS_1B_E(buffer))
+ if (VARATT_IS_1B_E(buffer))
{
/*
* 00000001 1-byte length word, unaligned, TOAST pointer
*/
- uint8 tag = VARTAG_1B_E(buffer);
- uint32 len = VARTAG_SIZE(tag);
- if(len > buff_size)
+ uint8 tag = VARTAG_1B_E(buffer);
+ uint32 len = VARTAG_SIZE(tag);
+
+ if (len > buff_size)
return -1;
CopyAppend("(TOASTED)");
return 0;
}
- if(VARATT_IS_1B(buffer))
+ if (VARATT_IS_1B(buffer))
{
/*
- * xxxxxxx1 1-byte length word, unaligned, uncompressed data (up to 126b)
- * xxxxxxx is 1 + string length
+ * xxxxxxx1 1-byte length word, unaligned, uncompressed data (up to
+ * 126b) xxxxxxx is 1 + string length
*/
- uint8 len = VARSIZE_1B(buffer);
- if(len > buff_size)
+ uint8 len = VARSIZE_1B(buffer);
+
+ if (len > buff_size)
return -1;
CopyAppendEncode(buffer + 1, len - 1);
return 0;
}
- if(VARATT_IS_4B_U(buffer) && buff_size >= 4)
+ if (VARATT_IS_4B_U(buffer) && buff_size >= 4)
{
/*
* xxxxxx00 4-byte length word, aligned, uncompressed data (up to 1G)
*/
- uint32 len = VARSIZE_4B(buffer);
- if(len > buff_size)
+ uint32 len = VARSIZE_4B(buffer);
+
+ if (len > buff_size)
return -1;
CopyAppendEncode(buffer + 4, len - 4);
return 0;
}
- if(VARATT_IS_4B_C(buffer) && buff_size >= 8)
+ if (VARATT_IS_4B_C(buffer) && buff_size >= 8)
{
/*
* xxxxxx10 4-byte length word, aligned, *compressed* data (up to 1G)
*/
- int decompress_ret;
- uint32 len = VARSIZE_4B(buffer);
- uint32 decompressed_len = VARRAWSIZE_4B_C(buffer);
+ int decompress_ret;
+ uint32 len = VARSIZE_4B(buffer);
+ uint32 decompressed_len = VARRAWSIZE_4B_C(buffer);
- if(len > buff_size)
+ if (len > buff_size)
return -1;
- if(decompressed_len > sizeof(decompress_tmp_buff))
+ if (decompressed_len > sizeof(decompress_tmp_buff))
{
printf("WARNING: Unable to decompress a string since it's too "
- "large (%d bytes after decompressing). Consider increasing "
- "decompress_tmp_buff size.\n", decompressed_len);
+ "large (%d bytes after decompressing). Consider increasing "
+ "decompress_tmp_buff size.\n", decompressed_len);
CopyAppend("(COMPRESSED)");
*out_size = padding + len;
return 0;
}
- decompress_ret = pglz_decompress(VARDATA_4B_C(buffer), len - 2*sizeof(uint32),
- decompress_tmp_buff, decompressed_len);
- if((decompress_ret != decompressed_len) || (decompress_ret < 0))
+ decompress_ret = pglz_decompress(VARDATA_4B_C(buffer), len - 2 * sizeof(uint32),
+ decompress_tmp_buff, decompressed_len);
+ if ((decompress_ret != decompressed_len) || (decompress_ret < 0))
{
printf("WARNING: Unable to decompress a string. Data is corrupted.\n");
CopyAppend("(COMPRESSED)");
* tupleSize - tuple size in bytes
*/
void
-FormatDecode(const char* tupleData, unsigned int tupleSize)
+FormatDecode(const char *tupleData, unsigned int tupleSize)
{
- HeapTupleHeader header = (HeapTupleHeader)tupleData;
- const char* data = tupleData + header->t_hoff;
+ HeapTupleHeader header = (HeapTupleHeader) tupleData;
+ const char *data = tupleData + header->t_hoff;
unsigned int size = tupleSize - header->t_hoff;
- int curr_attr;
+ int curr_attr;
CopyClear();
- for(curr_attr = 0; curr_attr < ncallbacks; curr_attr++)
+ for (curr_attr = 0; curr_attr < ncallbacks; curr_attr++)
{
- int ret;
+ int ret;
unsigned int processed_size = 0;
- if( (header->t_infomask & HEAP_HASNULL) && att_isnull(curr_attr, header->t_bits) )
+ if ((header->t_infomask & HEAP_HASNULL) && att_isnull(curr_attr, header->t_bits))
{
CopyAppend("\\N");
continue;
}
- if(size <= 0)
+ if (size <= 0)
{
printf("Error: unable to decode a tuple, no more bytes left. Partial data: %s\n",
- copyString.data);
+ copyString.data);
return;
}
- ret = callbacks[curr_attr](data, size, &processed_size);
- if(ret < 0)
+ ret = callbacks[curr_attr] (data, size, &processed_size);
+ if (ret < 0)
{
printf("Error: unable to decode a tuple, callback #%d returned %d. Partial data: %s\n",
- curr_attr+1, ret, copyString.data);
+ curr_attr + 1, ret, copyString.data);
return;
}
data += processed_size;
}
- if(size != 0)
+ if (size != 0)
{
printf("Error: unable to decode a tuple, %d bytes left, 0 expected. Partial data: %s\n",
- size, copyString.data);
+ size, copyString.data);
return;
}
#include "storage/checksum_impl.h"
#include "decode.h"
-/***
+/*
* Global variables for ease of use mostly
*/
static unsigned int blockVersion = 0;
/* Program exit code */
-static int exitCode = 0;
+static int exitCode = 0;
-/***
+/*
* Function Prototypes
*/
static void DisplayOptions(unsigned int validOptions);
static void DumpFileContents();
-/* Send properly formed usage information to the user. */
+/* Send properly formed usage information to the user. */
static void
DisplayOptions(unsigned int validOptions)
{
* name is /path/to/xxxx.7 procedure returns 7. Default return value is 0.
*/
static unsigned int
-GetSegmentNumberFromFileName(const char* fileName)
+GetSegmentNumberFromFileName(const char *fileName)
{
- int segnumOffset = strlen(fileName) - 1;
+ int segnumOffset = strlen(fileName) - 1;
- if(segnumOffset < 0)
+ if (segnumOffset < 0)
return 0;
- while(isdigit(fileName[segnumOffset]))
+ while (isdigit(fileName[segnumOffset]))
{
segnumOffset--;
- if(segnumOffset < 0)
+ if (segnumOffset < 0)
return 0;
}
- if(fileName[segnumOffset] != '.')
+ if (fileName[segnumOffset] != '.')
return 0;
- return atoi(&fileName[segnumOffset+1]);
+ return atoi(&fileName[segnumOffset + 1]);
}
-/* Iterate through the provided options and set the option flags. */
-/* An error will result in a positive rc and will force a display */
-/* of the usage information. This routine returns enum */
-/* optionReturnCode values. */
+/* Iterate through the provided options and set the option flags.
+ * An error will result in a positive rc and will force a display
+ * of the usage information. This routine returns enum
+ * optionReturnCode values. */
static unsigned int
ConsumeOptions(int numOptions, char **options)
{
optionString = options[x];
optionStringLength = strlen(optionString);
- /* Range is a special case where we have to consume the next 1 or 2 */
- /* parameters to mark the range start and end */
+ /* Range is a special case where we have to consume the next 1 or 2
+ * parameters to mark the range start and end */
if ((optionStringLength == 2) && (strcmp(optionString, "-R") == 0))
{
int range = 0;
/*
* Mark that we have the range and advance the option to what
- * should
- */
- /* be the range start. Check the value of the next parameter */
+ * should be the range start. Check the value of the next
+ * parameter */
optionString = options[++x];
if ((range = GetOptionValue(optionString)) < 0)
{
/* The default is to dump only one block */
blockStart = blockEnd = (unsigned int) range;
- /* We have our range start marker, check if there is an end */
- /* marker on the option line. Assume that the last option */
- /* is the file we are dumping, so check if there are options */
- /* range start marker and the file */
+ /* We have our range start marker, check if there is an end
+ * marker on the option line. Assume that the last option
+ * is the file we are dumping, so check if there are options
+ * range start marker and the file */
if (x <= (numOptions - 3))
{
if ((range = GetOptionValue(options[x + 1])) >= 0)
}
}
}
- /* Check for the special case where the user forces a block size */
- /* instead of having the tool determine it. This is useful if */
- /* the header of block 0 is corrupt and gives a garbage block size */
+ /* Check for the special case where the user forces a block size
+ * instead of having the tool determine it. This is useful if
+ * the header of block 0 is corrupt and gives a garbage block size */
else if ((optionStringLength == 2)
&& (strcmp(optionString, "-S") == 0))
{
}
}
/* Check for the special case where the user forces tuples decoding. */
- else if((optionStringLength == 2)
- && (strcmp(optionString, "-D") == 0))
+ else if ((optionStringLength == 2)
+ && (strcmp(optionString, "-D") == 0))
{
SET_OPTION(blockOptions, BLOCK_DECODE, 'D');
/* Only accept the decode option once */
/* Next option encountered must be attribute types string */
optionString = options[++x];
- if(ParseAttributeTypesString(optionString) < 0)
+ if (ParseAttributeTypesString(optionString) < 0)
{
rc = OPT_RC_INVALID;
printf("Error: Invalid attribute types string <%s>.\n",
break;
}
}
- /* Check for the special case where the user forces a segment number */
- /* instead of having the tool determine it by file name. */
+ /* Check for the special case where the user forces a segment number
+ * instead of having the tool determine it by file name. */
else if ((optionStringLength == 2)
&& (strcmp(optionString, "-n") == 0))
{
if (fp)
{
fileName = options[x];
- if(!(segmentOptions & SEGMENT_NUMBER_FORCED))
+ if (!(segmentOptions & SEGMENT_NUMBER_FORCED))
segmentNumber = GetSegmentNumberFromFileName(fileName);
}
else
}
else
{
- /* Could be the case where the help flag is used without a */
- /* filename. Otherwise, the last option isn't a file */
+ /* Could be the case where the help flag is used without a
+ * filename. Otherwise, the last option isn't a file */
if (strcmp(optionString, "-h") == 0)
rc = OPT_RC_COPYRIGHT;
else
break;
}
- /* Iterate through the singular option string, throw out */
- /* garbage, duplicates and set flags to be used in formatting */
+ /* Iterate through the singular option string, throw out
+ * garbage, duplicates and set flags to be used in formatting */
for (y = 1; y < optionStringLength; y++)
{
switch (optionString[y])
/*
* Format the contents of the block with
- * interpretation
- */
- /* of the headers */
+ * interpretation of the headers */
case 'f':
SET_OPTION(blockOptions, BLOCK_FORMAT, 'f');
break;
exitCode = 1;
}
- /* If the user requested a control file dump, a pure binary */
- /* block dump or a non-interpreted formatted dump, mask off */
- /* all other block level options (with a few exceptions) */
+ /* If the user requested a control file dump, a pure binary
+ * block dump or a non-interpreted formatted dump, mask off
+ * all other block level options (with a few exceptions) */
if (rc == OPT_RC_VALID)
{
/* The user has requested a control file dump, only -f and */
blockOptions = itemOptions = 0;
}
}
- /* The user has requested a binary block dump... only -R and */
- /* -f are honoured */
+ /* The user has requested a binary block dump... only -R and -f
+ * are honoured */
else if (blockOptions & BLOCK_BINARY)
{
blockOptions &= (BLOCK_BINARY | BLOCK_RANGE | BLOCK_FORCED);
itemOptions = 0;
}
- /* The user has requested a non-interpreted dump... only -a, */
- /* -R and -f are honoured */
+ /* The user has requested a non-interpreted dump... only -a, -R
+ * and -f are honoured */
else if (blockOptions & BLOCK_NO_INTR)
{
blockOptions &=
return (rc);
}
-/* Given the index into the parameter list, convert and return the */
-/* current string to a number if possible */
+/* Given the index into the parameter list, convert and return the
+ * current string to a number if possible */
static int
GetOptionValue(char *optionString)
{
return (value);
}
-/* Read the page header off of block 0 to determine the block size */
-/* used in this file. Can be overridden using the -S option. The */
-/* returned value is the block size of block 0 on disk */
+/* Read the page header off of block 0 to determine the block size
+ * used in this file. Can be overridden using the -S option. The
+ * returned value is the block size of block 0 on disk */
static unsigned int
GetBlockSize()
{
return (localSize);
}
-/* Determine the contents of the special section on the block and */
-/* return this enum value */
+/* Determine the contents of the special section on the block and
+ * return this enum value */
static unsigned int
GetSpecialSectionType(Page page)
{
unsigned int specialValue;
PageHeader pageHeader = (PageHeader) page;
- /* If this is not a partial header, check the validity of the */
- /* special section offset and contents */
+ /* If this is not a partial header, check the validity of the
+ * special section offset and contents */
if (bytesToFormat > sizeof(PageHeaderData))
{
specialOffset = (unsigned int) pageHeader->pd_special;
- /* Check that the special offset can remain on the block or */
- /* the partial block */
+ /* Check that the special offset can remain on the block or
+ * the partial block */
if ((specialOffset == 0) ||
(specialOffset > blockSize) || (specialOffset > bytesToFormat))
rc = SPEC_SECT_ERROR_BOUNDARY;
specialSize = blockSize - specialOffset;
- /* If there is a special section, use its size to guess its */
- /* contents, checking the last 2 bytes of the page in cases */
- /* that are ambiguous. Note we don't attempt to dereference */
- /* the pointers without checking bytesToFormat == blockSize. */
+ /* If there is a special section, use its size to guess its
+ * contents, checking the last 2 bytes of the page in cases
+ * that are ambiguous. Note we don't attempt to dereference
+ * the pointers without checking bytesToFormat == blockSize. */
if (specialSize == 0)
rc = SPEC_SECT_NONE;
else if (specialSize == MAXALIGN(sizeof(uint32)))
{
- /* If MAXALIGN is 8, this could be either a sequence or */
- /* SP-GiST or GIN. */
+ /* If MAXALIGN is 8, this could be either a sequence or
+ * SP-GiST or GIN. */
if (bytesToFormat == blockSize)
{
specialValue = *((int *) (buffer + specialOffset));
else
rc = SPEC_SECT_ERROR_UNKNOWN;
}
- /* SP-GiST and GIN have same size special section, so check */
- /* the page ID bytes first. */
+ /* SP-GiST and GIN have same size special section, so check
+ * the page ID bytes first. */
else if (specialSize == MAXALIGN(sizeof(SpGistPageOpaqueData)) &&
bytesToFormat == blockSize &&
*ptype == SPGIST_PAGE_ID)
rc = SPEC_SECT_INDEX_GIN;
else if (specialSize > 2 && bytesToFormat == blockSize)
{
- /* As of 8.3, BTree, Hash, and GIST all have the same size */
- /* special section, but the last two bytes of the section */
- /* can be checked to determine what's what. */
+ /* As of 8.3, BTree, Hash, and GIST all have the same size
+ * special section, but the last two bytes of the section
+ * can be checked to determine what's what. */
if (*ptype <= MAX_BT_CYCLE_ID &&
specialSize == MAXALIGN(sizeof(BTPageOpaqueData)))
rc = SPEC_SECT_INDEX_BTREE;
return false;
}
-/* Display a header for the dump so we know the file name, the options */
-/* used and the time the dump was taken */
+/* Display a header for the dump so we know the file name, the options
+ * used and the time the dump was taken */
static void
CreateDumpFileHeader(int numOptions, char **options)
{
char optionBuffer[52] = "\0";
time_t rightNow = time(NULL);
- /* Iterate through the options and cache them. */
- /* The maximum we can display is 50 option characters + spaces. */
+ /* Iterate through the options and cache them.
+ * The maximum we can display is 50 option characters + spaces. */
for (x = 1; x < (numOptions - 1); x++)
{
if ((strlen(optionBuffer) + strlen(options[x])) > 50)
"* File: %s\n"
"* Options used: %s\n*\n"
"* Dump created on: %s"
- "*******************************************************************\n",
+ "*******************************************************************\n",
FD_VERSION, fileName, (strlen(optionBuffer)) ? optionBuffer : "None",
ctime(&rightNow));
}
printf("<Header> -----\n");
- /* Only attempt to format the header if the entire header (minus the item */
- /* array) is available */
+ /* Only attempt to format the header if the entire header (minus the item
+ * array) is available */
if (bytesToFormat < offsetof(PageHeaderData, pd_linp[0]))
{
headerBytes = bytesToFormat;
headerBytes = offsetof(PageHeaderData, pd_linp[0]);
blockVersion = (unsigned int) PageGetPageLayoutVersion(page);
- /* The full header exists but we have to check that the item array */
- /* is available or how far we can index into it */
+ /* The full header exists but we have to check that the item array
+ * is available or how far we can index into it */
if (maxOffset > 0)
{
unsigned int itemsLength = maxOffset * sizeof(ItemIdData);
/* Interpret the content of the header */
printf
(" Block Offset: 0x%08x Offsets: Lower %4u (0x%04hx)\n"
- " Block: Size %4d Version %4u Upper %4u (0x%04hx)\n"
+ " Block: Size %4d Version %4u Upper %4u (0x%04hx)\n"
" LSN: logid %6d recoff 0x%08x Special %4u (0x%04hx)\n"
" Items: %4d Free Space: %4u\n"
" Checksum: 0x%04x Prune XID: 0x%08x Flags: 0x%04x (%s)\n"
headerBytes += sizeof(BTMetaPageData);
}
- /* Eye the contents of the header and alert the user to possible */
- /* problems. */
+ /* Eye the contents of the header and alert the user to possible
+ * problems. */
if ((maxOffset < 0) ||
(maxOffset > blockSize) ||
(blockVersion != PG_PAGE_LAYOUT_VERSION) || /* only one we support */
if (blockOptions & BLOCK_CHECKSUMS)
{
- uint32 delta = (segmentSize/blockSize)*segmentNumber;
- uint16 calc_checksum = pg_checksum_page(page, delta + blkno);
+ uint32 delta = (segmentSize / blockSize) * segmentNumber;
+ uint16 calc_checksum = pg_checksum_page(page, delta + blkno);
if (calc_checksum != pageHeader->pd_checksum)
{
}
}
- /* If we have reached the end of file while interpreting the header, let */
- /* the user know about it */
+ /* If we have reached the end of file while interpreting the header, let
+ * the user know about it */
if (rc == EOF_ENCOUNTERED)
{
printf
exitCode = 1;
}
- /* A request to dump the formatted binary of the block (header, */
- /* items and special section). It's best to dump even on an error */
- /* so the user can see the raw image. */
+ /* A request to dump the formatted binary of the block (header,
+ * items and special section). It's best to dump even on an error
+ * so the user can see the raw image. */
if (blockOptions & BLOCK_FORMAT)
FormatBinary(headerBytes, 0);
ItemId itemId;
int maxOffset = PageGetMaxOffsetNumber(page);
- /* If it's a btree meta page, the meta block is where items would normally */
- /* be; don't print garbage. */
+ /* If it's a btree meta page, the meta block is where items would normally
+ * be; don't print garbage. */
if (IsBtreeMetaPage(page))
return;
printf("<Data> ------ \n");
- /* Loop through the items on the block. Check if the block is */
- /* empty and has a sensible item array listed before running */
- /* through each item */
+ /* Loop through the items on the block. Check if the block is
+ * empty and has a sensible item array listed before running
+ * through each item */
if (maxOffset == 0)
printf(" Empty block - no items listed \n\n");
else if ((maxOffset < 0) || (maxOffset > blockSize))
int formatAs;
char textFlags[16];
- /* First, honour requests to format items a special way, then */
- /* use the special section to determine the format style */
+ /* First, honour requests to format items a special way, then
+ * use the special section to determine the format style */
if (itemOptions & ITEM_INDEX)
formatAs = ITEM_INDEX;
else if (itemOptions & ITEM_HEAP)
" Flags: %s\n", x, itemSize, itemOffset, itemOffset,
textFlags);
- /* Make sure the item can physically fit on this block before */
- /* formatting */
+ /* Make sure the item can physically fit on this block before
+ * formatting */
if ((itemOffset + itemSize > blockSize) ||
(itemOffset + itemSize > bytesToFormat))
{
printf(" Error: Item contents extend beyond block.\n"
- " BlockSize<%d> Bytes Read<%d> Item Start<%d>.\n",
+ " BlockSize<%d> Bytes Read<%d> Item Start<%d>.\n",
blockSize, bytesToFormat, itemOffset + itemSize);
exitCode = 1;
}
else
{
- /* If the user requests that the items be interpreted as */
- /* heap or index items... */
+ /* If the user requests that the items be interpreted as
+ * heap or index items... */
if (itemOptions & ITEM_DETAIL)
FormatItem(itemSize, itemOffset, formatAs);
FormatBinary(itemSize, itemOffset);
/* Decode tuple data */
- if((blockOptions & BLOCK_DECODE) && (itemFlags == LP_NORMAL))
+ if ((blockOptions & BLOCK_DECODE) && (itemFlags == LP_NORMAL))
FormatDecode(&buffer[itemOffset], itemSize);
if (x == maxOffset)
}
}
-/* Interpret the contents of the item based on whether it has a special */
-/* section and/or the user has hinted */
+/* Interpret the contents of the item based on whether it has a special
+ * section and/or the user has hinted */
static void
FormatItem(unsigned int numBytes, unsigned int startIndex,
unsigned int formatAs)
if (numBytes != IndexTupleSize(itup))
{
printf(" Error: Item size difference. Given <%u>, "
- "Internal <%d>.\n", numBytes, (int) IndexTupleSize(itup));
+ "Internal <%d>.\n", numBytes, (int) IndexTupleSize(itup));
exitCode = 1;
}
}
HeapTupleHeaderGetOid(htup));
printf("\n"
- " Block Id: %u linp Index: %u Attributes: %d Size: %d\n",
+ " Block Id: %u linp Index: %u Attributes: %d Size: %d\n",
((uint32)
((htup->t_ctid.ip_blkid.bi_hi << 16) | (uint16) htup->
t_ctid.ip_blkid.bi_lo)), htup->t_ctid.ip_posid,
localNatts, htup->t_hoff);
- /* Place readable versions of the tuple info mask into a buffer. */
- /* Assume that the string can not expand beyond 256. */
+ /* Place readable versions of the tuple info mask into a buffer.
+ * Assume that the string can not expand beyond 256. */
flagString[0] = '\0';
if (infoMask & HEAP_HASNULL)
strcat(flagString, "HASNULL|");
printf(" infomask: 0x%04x (%s) \n", infoMask, flagString);
- /* As t_bits is a variable length array, determine the length of */
- /* the header proper */
+ /* As t_bits is a variable length array, determine the length of
+ * the header proper */
if (infoMask & HEAP_HASNULL)
bitmapLength = BITMAPLEN(localNatts);
else
computedLength =
MAXALIGN(localBitOffset + bitmapLength + oidLength);
- /*
- * Inform the user of a header size mismatch or dump the t_bits
- * array
- */
+ /* Inform the user of a header size mismatch or dump the t_bits
+ * array */
if (computedLength != localHoff)
{
printf
}
-/* On blocks that have special sections, print the contents */
-/* according to previously determined special section type */
+/* On blocks that have special sections, print the contents
+ * according to previously determined special section type */
static void
FormatSpecial()
{
" Blocks: Previous (%d) Next (%d)\n\n",
hashSection->hasho_flag, flagString,
hashSection->hasho_bucket,
- hashSection->hasho_prevblkno, hashSection->hasho_nextblkno);
+ hashSection->hasho_prevblkno, hashSection->hasho_nextblkno);
}
break;
(bytesToFormat ==
blockSize) ? "***************" : " PARTIAL BLOCK ");
- /* Either dump out the entire block in hex+acsii fashion or */
- /* interpret the data based on block structure */
+ /* Either dump out the entire block in hex+acsii fashion or
+ * interpret the data based on block structure */
if (blockOptions & BLOCK_NO_INTR)
FormatBinary(bytesToFormat, 0);
else
{
int rc;
- /* Every block contains a header, items and possibly a special */
- /* section. Beware of partial block reads though */
+ /* Every block contains a header, items and possibly a special
+ * section. Beware of partial block reads though */
rc = FormatHeader(page, blkno);
/* If we didn't encounter a partial read in the header, carry on... */
" System Identifier: " UINT64_FORMAT "\n"
" State: %s\n"
" Last Mod Time: %s"
- " Last Checkpoint Record: Log File (%u) Offset (0x%08x)\n"
- " Previous Checkpoint Record: Log File (%u) Offset (0x%08x)\n"
- " Last Checkpoint Record Redo: Log File (%u) Offset (0x%08x)\n"
+ " Last Checkpoint Record: Log File (%u) Offset (0x%08x)\n"
+ " Previous Checkpoint Record: Log File (%u) Offset (0x%08x)\n"
+ " Last Checkpoint Record Redo: Log File (%u) Offset (0x%08x)\n"
" |- TimeLineID: %u\n"
" |- Next XID: %u/%u\n"
" |- Next OID: %u\n"
" |- Next Multi: %u\n"
" |- Next MultiOff: %u\n"
" |- Time: %s"
- " Minimum Recovery Point: Log File (%u) Offset (0x%08x)\n"
+ " Minimum Recovery Point: Log File (%u) Offset (0x%08x)\n"
" Maximum Data Alignment: %u\n"
" Floating-Point Sample: %.7g%s\n"
" Database Block Size: %u\n"
" Maximum Index Keys: %u\n"
" TOAST Chunk Size: %u\n\n",
EQ_CRC32C(crcLocal,
- controlData->crc) ? "Correct" : "Not Correct",
+ controlData->crc) ? "Correct" : "Not Correct",
controlData->pg_control_version,
(controlData->pg_control_version == PG_CONTROL_VERSION ?
"" : " (Not Correct!)"),
" Size: Correct <%u> Received <%u>.\n\n",
controlFileSize, bytesToFormat);
- /* If we have an error, force a formatted dump so we can see */
- /* where things are going wrong */
+ /* If we have an error, force a formatted dump so we can see
+ * where things are going wrong */
controlOptions |= CONTROL_FORMAT;
exitCode = 1;
}
}
-/* Dump out the contents of the block in hex and ascii. */
-/* BYTES_PER_LINE bytes are formatted in each line. */
+/* Dump out the contents of the block in hex and ascii.
+ * BYTES_PER_LINE bytes are formatted in each line. */
static void
FormatBinary(unsigned int numBytes, unsigned int startIndex)
{
if (numBytes)
{
- /* Iterate through a printable row detailing the current */
- /* address, the hex and ascii values */
+ /* Iterate through a printable row detailing the current
+ * address, the hex and ascii values */
for (index = startIndex; index < lastByte; index += BYTES_PER_LINE)
{
stopIndex = index + BYTES_PER_LINE;
}
}
-/* Dump the binary image of the block */
+/* Dump the binary image of the block */
static void
DumpBinaryBlock()
{
putchar(buffer[x]);
}
-/* Control the dumping of the blocks within the file */
+/* Control the dumping of the blocks within the file */
static void
DumpFileContents()
{
unsigned int initialRead = 1;
unsigned int contentsToDump = 1;
- /* If the user requested a block range, seek to the correct position */
- /* within the file for the start block. */
+ /* If the user requested a block range, seek to the correct position
+ * within the file for the start block. */
if (blockOptions & BLOCK_RANGE)
{
unsigned int position = blockSize * blockStart;
currentBlock = blockStart;
}
- /* Iterate through the blocks in the file until you reach the end or */
- /* the requested range end */
+ /* Iterate through the blocks in the file until you reach the end or
+ * the requested range end */
while (contentsToDump)
{
bytesToFormat = fread(buffer, 1, blockSize, fp);
if (bytesToFormat == 0)
{
- /* fseek() won't pop an error if you seek passed eof. The next */
- /* subsequent read gets the error. */
+ /* fseek() won't pop an error if you seek passed eof. The next
+ * subsequent read gets the error. */
if (initialRead)
printf("Error: Premature end of file encountered.\n");
else if (!(blockOptions & BLOCK_BINARY))
}
}
-/* Consume the options and iterate through the given file, formatting as */
-/* requested. */
+/* Consume the options and iterate through the given file, formatting as
+ * requested. */
int
main(int argv, char **argc)
{
validOptions = (argv < 2) ? OPT_RC_COPYRIGHT : ConsumeOptions(argv, argc);
- /* Display valid options if no parameters are received or invalid options */
- /* where encountered */
+ /* Display valid options if no parameters are received or invalid options
+ * where encountered */
if (validOptions != OPT_RC_VALID)
DisplayOptions(validOptions);
else
if (!(blockOptions & BLOCK_BINARY))
CreateDumpFileHeader(argv, argc);
- /* If the user has not forced a block size, use the size of the */
- /* control file data or the information from the block 0 header */
+ /* If the user has not forced a block size, use the size of the
+ * control file data or the information from the block 0 header */
if (controlOptions)
{
if (!(controlOptions & CONTROL_FORCED))
else if (!(blockOptions & BLOCK_FORCED))
blockSize = GetBlockSize();
- /* On a positive block size, allocate a local buffer to store */
- /* the subsequent blocks */
+ /* On a positive block size, allocate a local buffer to store
+ * the subsequent blocks */
if (blockSize > 0)
{
buffer = (char *) malloc(blockSize);