MBED port of https://github.com/ys1382/filagree . The only change is adding #define MBED

Dependents:   filagree_test

Committer:
yusufx
Date:
Wed May 30 21:13:01 2012 +0000
Revision:
0:1a89e28dea91

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yusufx 0:1a89e28dea91 1 #ifndef UTIL_H
yusufx 0:1a89e28dea91 2 #define UTIL_H
yusufx 0:1a89e28dea91 3
yusufx 0:1a89e28dea91 4 #include <stdbool.h>
yusufx 0:1a89e28dea91 5 #include <setjmp.h>
yusufx 0:1a89e28dea91 6 #include <stdint.h>
yusufx 0:1a89e28dea91 7 #include <inttypes.h>
yusufx 0:1a89e28dea91 8 #include <stdarg.h>
yusufx 0:1a89e28dea91 9 #include <stdio.h>
yusufx 0:1a89e28dea91 10
yusufx 0:1a89e28dea91 11 #ifdef __LP64__
yusufx 0:1a89e28dea91 12 #define VOID_INT int64_t
yusufx 0:1a89e28dea91 13 #define VOID_FLT long double
yusufx 0:1a89e28dea91 14 #else
yusufx 0:1a89e28dea91 15 #define VOID_INT int32_t
yusufx 0:1a89e28dea91 16 #define VOID_FLT double)(int32_t
yusufx 0:1a89e28dea91 17 #endif
yusufx 0:1a89e28dea91 18
yusufx 0:1a89e28dea91 19 #define MBED
yusufx 0:1a89e28dea91 20 #ifdef MBED
yusufx 0:1a89e28dea91 21 #pragma diag_suppress 1293 // suppress squeamish warning of "assignment in condition"
yusufx 0:1a89e28dea91 22 #endif
yusufx 0:1a89e28dea91 23
yusufx 0:1a89e28dea91 24 #define ARRAY_LEN(x) (sizeof x / sizeof *x)
yusufx 0:1a89e28dea91 25 #define ITOA_LEN 19 // enough for 64-bit integer
yusufx 0:1a89e28dea91 26
yusufx 0:1a89e28dea91 27 extern jmp_buf trying;
yusufx 0:1a89e28dea91 28 const char *make_message(const char *fmt, va_list ap);
yusufx 0:1a89e28dea91 29 void assert_message(bool assertion, const char *format, ...);
yusufx 0:1a89e28dea91 30 void *exit_message(const char *format, ...);
yusufx 0:1a89e28dea91 31 void null_check(const void* p);
yusufx 0:1a89e28dea91 32 void log_print(const char *format, ...);
yusufx 0:1a89e28dea91 33
yusufx 0:1a89e28dea91 34 #ifdef DEBUG
yusufx 0:1a89e28dea91 35 #define DEBUGPRINT(...) log_print( __VA_ARGS__ );
yusufx 0:1a89e28dea91 36 #else
yusufx 0:1a89e28dea91 37 #define DEBUGPRINT(...) {};
yusufx 0:1a89e28dea91 38 #endif // #ifdef DEBUG
yusufx 0:1a89e28dea91 39
yusufx 0:1a89e28dea91 40 // file
yusufx 0:1a89e28dea91 41
yusufx 0:1a89e28dea91 42 #define ERROR_FSIZE "Could not get length of file"
yusufx 0:1a89e28dea91 43 #define ERROR_FOPEN "Could not open file"
yusufx 0:1a89e28dea91 44 #define ERROR_FREAD "Could not read file"
yusufx 0:1a89e28dea91 45 #define ERROR_FCLOSE "Could not close file"
yusufx 0:1a89e28dea91 46
yusufx 0:1a89e28dea91 47 struct byte_array *read_file(const struct byte_array *filename);
yusufx 0:1a89e28dea91 48 int write_file(const struct byte_array* filename, struct byte_array* bytes);
yusufx 0:1a89e28dea91 49 long fsize(FILE* file);
yusufx 0:1a89e28dea91 50
yusufx 0:1a89e28dea91 51 struct number_string {
yusufx 0:1a89e28dea91 52 uint8_t number;
yusufx 0:1a89e28dea91 53 char* chars;
yusufx 0:1a89e28dea91 54 };
yusufx 0:1a89e28dea91 55
yusufx 0:1a89e28dea91 56 const char* num_to_string(const struct number_string *ns, int num_items, int num);
yusufx 0:1a89e28dea91 57 #define NUM_TO_STRING(ns, num) num_to_string(ns, ARRAY_LEN(ns), num)
yusufx 0:1a89e28dea91 58
yusufx 0:1a89e28dea91 59 // error messages
yusufx 0:1a89e28dea91 60
yusufx 0:1a89e28dea91 61 #define ERROR_ALLOC "Could not allocate memory"
yusufx 0:1a89e28dea91 62
yusufx 0:1a89e28dea91 63
yusufx 0:1a89e28dea91 64
yusufx 0:1a89e28dea91 65 #endif // UTIL_H