59 memcpy(&total, data,
sizeof (guchar));
60 return g_strdup_printf(
"%d", total);
82 memcpy(&total, data,
sizeof (guchar));
83 return g_strdup_printf(
"%u", total);
105 memcpy(&total, data, 2 *
sizeof (guchar));
106 return g_strdup_printf(
"%d", total);
128 memcpy(&total, data, 2 *
sizeof (guchar));
129 return g_strdup_printf(
"%u", total);
151 memcpy(&total, data, 4 *
sizeof (guchar));
152 return g_strdup_printf(
"%d", total);
174 memcpy(&total, data, 4 *
sizeof (guchar));
175 return g_strdup_printf(
"%u", total);
197 memcpy(&total, data, 8 *
sizeof (guchar));
198 return g_strdup_printf(
"%lld", (
long long int) total);
220 memcpy(&total, data, 8 *
sizeof (guchar));
221 return g_strdup_printf(
"%llu", (
long long unsigned int) total);
243 memcpy(&total, data, 4 *
sizeof (guchar));
244 return g_strdup_printf(
"%f", total);
266 memcpy(&total, data, 4 *
sizeof (guchar));
267 return g_strdup_printf(
"%g", total);
289 memcpy(&total, data, 8 *
sizeof (guchar));
290 return g_strdup_printf(
"%f", total);
312 memcpy(&total, data, 8 *
sizeof (guchar));
313 return g_strdup_printf(
"%g", total);
327 if ((year % 100) == 0)
329 if ((year % 400) == 0)
361 while (i<12 && day > tab_ns_months[i])
366 mydate->
month = i + 1;
370 mydate->
day = 1 + day;
374 mydate->
day = (1 + day) - tab_ns_months[i-1];
392 guint tab_ns_months[12] = { 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } ;
405 guint tab_ns_months[12] = { 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
427 guint tab_ns_months[11];
429 if (base_day > 0 && base_day < 32)
438 tab_ns_months[0] = 31;
441 tab_ns_months[1] = 60;
442 tab_ns_months[2] = 91;
443 tab_ns_months[3] = 121;
444 tab_ns_months[4] = 152;
445 tab_ns_months[5] = 182;
446 tab_ns_months[6] = 213;
447 tab_ns_months[7] = 244;
448 tab_ns_months[8] = 274;
449 tab_ns_months[9] = 305;
450 tab_ns_months[10] = 335;
454 tab_ns_months[1] = 59;
455 tab_ns_months[2] = 90;
456 tab_ns_months[3] = 120;
457 tab_ns_months[4] = 151;
458 tab_ns_months[5] = 181;
459 tab_ns_months[6] = 212;
460 tab_ns_months[7] = 243;
461 tab_ns_months[8] = 273;
462 tab_ns_months[9] = 304;
463 tab_ns_months[10] = 334;
466 if (base_month > 1 && base_month < 13)
468 return (tab_ns_months[base_month-2] + base_day);
470 else if (base_month == 1)
508 modulus = days / 146100;
509 mydate->
year = modulus * 400;
511 days = days % 146100;
514 modulus = days / 1461;
515 mydate->
year += modulus * 4;
516 reste += (modulus*4) / 100;
517 reste += days % 1461;
519 mydate->
year += base_year;
525 while (reste > nbdays)
551 return g_strdup_printf(
"%02u/%02u/%04u - %02u:%02u:%02u", mydate->
day, mydate->
month, mydate->
year, mydate->
hour, mydate->
minutes, mydate->
seconds);
566 gchar *interpreted_date = NULL;
576 mydate->
year = (data[3] >> 1) + 1980;
577 mydate->
month = ((data[3] & 0x01) << 3) + (data[2] >> 5);
578 mydate->
day = data[2] & 0x1F;
579 mydate->
hour = (data[1] & 0xF8) >> 3;
580 mydate->
minutes = ((data[1] & 0x07) << 3) + ((data[0] & 0xE0) >> 5);
581 mydate->
seconds = (data[0] & 0x1F) << 1;
586 return interpreted_date;
607 memcpy(&total, data, len *
sizeof (guchar));
609 total = (total / nbticks);
610 days = (guint32) (total / 86400); ;
614 mydate->
hour = ((total % 86400) / 3600);
615 mydate->
minutes = ((total % 3600) / 60);
616 mydate->
seconds = (total % 60);
631 gchar *interpreted_date = NULL;
646 return interpreted_date;
662 gchar *interpreted_date = NULL;
677 return interpreted_date;
693 gchar *interpreted_date = NULL;
708 return interpreted_date;
752 bits = (gchar *) g_malloc0(decode_parameters->
stream_size * 10 * (
sizeof(gchar)) + 1);
755 for (i = 0 ; i < decode_parameters->
stream_size ; i++)
810 bcd[part_number] =
'0';
813 bcd[part_number] =
'1';
816 bcd[part_number] =
'2';
819 bcd[part_number] =
'3';
822 bcd[part_number] =
'4';
825 bcd[part_number] =
'5';
828 bcd[part_number] =
'6';
831 bcd[part_number] =
'7';
834 bcd[part_number] =
'8';
837 bcd[part_number] =
'9';
840 bcd[part_number] =
'*';
843 bcd[part_number] =
'#';
846 bcd[part_number] =
'a';
849 bcd[part_number] =
'b';
852 bcd[part_number] =
'c';
855 bcd[part_number] =
' ';
858 bcd[part_number] =
'?';
888 bcd = (gchar *) g_malloc0((2 * decode_parameters->
stream_size + 1) *
sizeof(gchar));
889 while (i < decode_parameters->stream_size)
891 memcpy(&total, data + i,
sizeof(guchar));
913 gboolean
swap_bytes(guchar *to_swap, guint first, guint last)
923 aux = to_swap[first];
924 to_swap[first] = to_swap[last];
938 guint8 car = (guint8) to_reverse[0];
941 aux = ((car & 0x80) >> 7);
942 aux += ((car & 0x40) >> 5);
943 aux += ((car & 0x20) >> 3);
944 aux += ((car & 0x10) >> 1);
945 aux += ((car & 0x08) << 1);
946 aux += ((car & 0x04) << 3);
947 aux += ((car & 0x02) << 5);
948 aux += ((car & 0x01) << 7);
950 to_reverse[0] = (guchar) aux;
970 return decode_parameters;
987 if (decode_func != NULL && entry != NULL)
990 decode_struct->
func = decode_func;
991 decode_struct->
entry = entry;
992 decode_struct->
err_msg = g_strdup(err_msg);
994 return decode_struct;
1025 GtkWidget *entry = NULL;
1026 GPtrArray *decode_array;
1028 decode_array = g_ptr_array_new();
1032 va_start(args, nb_cols);
1033 for (i = 0 ; i < nb_cols ; i++)
1036 entry = gtk_entry_new();
1037 gtk_editable_set_editable(GTK_EDITABLE(entry), FALSE);
1039 g_ptr_array_add(decode_array, (gpointer) decode);
1044 my_struct->
label = gtk_label_new(label);
1045 gtk_misc_set_padding(GTK_MISC(my_struct->
label), 3, 3);
1046 gtk_misc_set_alignment(GTK_MISC(my_struct->
label), 0.5, 0.5);
static void which_year_month_day(date_and_time_t *mydate, guint32 days, guint32 base_year, guint base_month, guint8 base_day)
About date calculation : Leap years are periods of 4 years except the years that we can divide by 100...
static gchar * date_printf(date_and_time_t *mydate)
Return a gchar * that contains the date and time encoded from the values contained in the date_and_ti...
gchar * decode_16bits_unsigned(guchar *data, gpointer data_struct)
general purpose of this function is to take a 2 byte data stream and convert it as if it is a 16 bits...
gboolean fixed_size
says whether we can modify data_size or not
gchar * err_msg
error message if something went wrong when decoding expects a d somewhere in the message to represent...
gchar * decode_double_scientific(guchar *data, gpointer data_struct)
general purpose of this function is to take a 8 byte data stream and convert it as if it is a float n...
gchar * decode_32bits_unsigned(guchar *data, gpointer data_struct)
general purpose of this function is to take a 4 byte data stream and convert it as if it is a 32 bits...
guint data_size
size of what we may decode
DecodeFunc func
a function to decode into something
gchar * decode_float_scientific(guchar *data, gpointer data_struct)
general purpose of this function is to take a 4 byte data stream and convert it as if it is a float n...
void reverse_byte_order(guchar *to_reverse)
Reverse the byte order LSB -> MSB in MSB -> LSB 12345678 in 87654321.
static void which_month_day(date_and_time_t *mydate, guint32 day, gboolean bi)
Front end function for the calc_which_month_day function !
static gboolean bissextile_year(guint32 year)
Says whether a year is a leap one or not.
gchar * decode_dos_date(guchar *data, gpointer data_struct)
general purpose of this function is to take a 4 byte data stream and convert it as if it is a dos dat...
gchar * decode_filetime_date(guchar *data, gpointer data_struct)
general purpose of this function is to take a 8 byte data stream and convert it as if it is a filetim...
static void calc_which_month_day(date_and_time_t *mydate, guint32 day, guint tab_ns_months[12])
Says, from a number of days (eg 154), which month it is (eg may) and which day in the corresponding m...
static guint32 remove_days_from_first_january(guint32 base_year, guint8 base_month, guint8 base_day)
Returns the number of days since 01/01/base_year eg 15/02/base_year –> 31 + 15 = 46...
gchar * decode_8bits_unsigned(guchar *data, gpointer data_struct)
general purpose of this function is to take a 1 byte data stream and convert it as if it is an 8 bits...
gchar * decode_32bits_signed(guchar *data, gpointer data_struct)
general purpose of this function is to take a 4 byte data stream and convert it as if it is a 32 bits...
gchar * decode_to_bits(guchar *data, gpointer data_struct)
decodes the stream represented by *data (one byte) to a string containing eight 0 or 1 (Little Endian...
gchar * decode_8bits_signed(guchar *data, gpointer data_struct)
General purpose of this function is to take a 1 byte data stream and convert it as if it is an 8 bits...
A human struct to store a date with a time.
static void make_date_and_time(date_and_time_t *mydate, guchar *data, guint8 len, guint64 nbticks, guint32 base_year, guint base_month, guint8 base_day)
Reads the data from the stream (specified length !! <= 8 or 64 bits to decode)
static guchar data_to_one_bit(guchar data)
Returns a guchar that is 1 or 0 respectiveky if data is > 0 or not.
Basic way to associate a decode function and an entry that will receive the result.
decode_parameters_t * new_decode_parameters_t(guint endianness, guint stream_size)
Make an new decode_parameters_t in order to pass to the functions.
gchar * decode_double_normal(guchar *data, gpointer data_struct)
general purpose of this function is to take a 8 byte data stream and convert it as if it is a float n...
gchar *(* DecodeFunc)(guchar *, gpointer)
Templates for the decoding functions.
GPtrArray * decode_array
Pointer Array of decode_t functions and corresponding entries.
gchar * decode_64bits_signed(guchar *data, gpointer data_struct)
general purpose of this function is to take a 8 byte data stream and convert it as if it is a 64 bits...
gchar * decode_HFS_date(guchar *data, gpointer data_struct)
general purpose of this function is to take a 4 byte data stream and convert it as if it is a HFS dat...
gchar * decode_float_normal(guchar *data, gpointer data_struct)
general purpose of this function is to take a 4 byte data stream and convert it as if it is a float n...
gboolean swap_bytes(guchar *to_swap, guint first, guint last)
Swap bytes from the buffer to_swap.
GtkWidget * label
label for these decoding functions
This file contains all the definitions and includes all other .h files.
gchar * decode_packed_BCD(guchar *data, gpointer data_struct)
Decode one byte as a Packed BCD (Binary Coded Decimal) and return a gchar* that may be freed when no ...
static void transform_bcd_to_human(gchar *bcd, guint8 part, guint8 part_number)
transcribes the bcd number "part" into a
GtkWidget * entry
the widget that will receive the result
gchar * decode_64bits_unsigned(guchar *data, gpointer data_struct)
general purpose of this function is to take a 8 byte data stream and convert it as if it is a 64 bits...
guint stream_size
stream_size
gchar * decode_C_date(guchar *data, gpointer data_struct)
general purpose of this function is to take a 4 byte data stream and convert it as if it is a C date...
guint endianness
endianness
decode_generic_t * new_decode_generic_t(const gchar *label, guint data_size, gboolean fixed_size, const gchar *err_msg, guint nb_cols,...)
Make a new decode_generic_t structure and creates the associated widgets.
Basic way to have as many as we want decoding functions corresponding to one label.
decode_t * new_decode_t(DecodeFunc decode_func, GtkWidget *entry, const gchar *err_msg)
Make a new decode_t structure.
Used to pass decoding options to the functions.
gchar * decode_16bits_signed(guchar *data, gpointer data_struct)
general purpose of this function is to take a 2 byte data stream and convert it as if it is a 16 bits...