119 |
} |
} |
120 |
} |
} |
121 |
|
|
|
//-------------------------------------------------------------------------------- |
|
|
// M E M O R Y A L L O C A T I O N F U N C T I O N S |
|
|
//-------------------------------------------------------------------------------- |
|
|
//These functions form a layer over the standard library so that conditions of |
|
|
//concern can be more easily trapped. |
|
|
//-------------------------------------------------------------------------------- |
|
|
void *CCMALLOC_malloc(size_t size) |
|
|
{ |
|
|
void *rv; |
|
|
|
|
|
rv = malloc(size); |
|
|
|
|
|
if (!rv) |
|
|
{ |
|
|
CCMFATAL_fatal("NULL pointer from malloc()--probable out of memory.", |
|
|
__FILE__, |
|
|
__LINE__); |
|
|
} |
|
|
|
|
|
memset(rv, 0, size); |
|
|
|
|
|
return(rv); |
|
|
} |
|
|
|
|
|
void *CCMALLOC_calloc(size_t num, size_t size) |
|
|
{ |
|
|
void *rv; |
|
|
|
|
|
rv = calloc(num, size); |
|
|
|
|
|
if (!rv) |
|
|
{ |
|
|
CCMFATAL_fatal("NULL pointer from calloc()--probable out of memory.", |
|
|
__FILE__, |
|
|
__LINE__); |
|
|
} |
|
|
|
|
|
memset(rv, 0, size); |
|
|
|
|
|
return(rv); |
|
|
} |
|
|
|
|
|
void *CCMALLOC_realloc(void *memblock, size_t size) |
|
|
{ |
|
|
void *rv; |
|
|
|
|
|
rv = realloc(memblock, size); |
|
|
|
|
|
if ((!rv) && (size)) |
|
|
{ |
|
|
CCMFATAL_fatal("NULL pointer from realloc()--probable out of memory.", |
|
|
__FILE__, |
|
|
__LINE__); |
|
|
} |
|
|
|
|
|
return(rv); |
|
|
} |
|
|
|
|
|
void CCMALLOC_free(void *memblock) |
|
|
{ |
|
|
free(memblock); |
|
|
} |
|
|
|
|
|
//-------------------------------------------------------------------------------- |
|
|
// C H A R A C T E R F U N C T I O N S |
|
|
//-------------------------------------------------------------------------------- |
|
|
int CHARFUNC_digit_to_val(char digit) |
|
|
{ |
|
|
switch (digit) |
|
|
{ |
|
|
case '0': return(0); |
|
|
break; |
|
|
case '1': return(1); |
|
|
break; |
|
|
case '2': return(2); |
|
|
break; |
|
|
case '3': return(3); |
|
|
break; |
|
|
case '4': return(4); |
|
|
break; |
|
|
case '5': return(5); |
|
|
break; |
|
|
case '6': return(6); |
|
|
break; |
|
|
case '7': return(7); |
|
|
break; |
|
|
case '8': return(8); |
|
|
break; |
|
|
case '9': return(9); |
|
|
break; |
|
|
default: return(-1); |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
char CHARFUNC_nibble_to_lc_hex_digit(int nibble) |
|
|
{ |
|
|
switch (nibble & 0x0F) |
|
|
{ |
|
|
case 0: |
|
|
return('0'); |
|
|
break; |
|
|
case 1: |
|
|
return('1'); |
|
|
break; |
|
|
case 2: |
|
|
return('2'); |
|
|
break; |
|
|
case 3: |
|
|
return('3'); |
|
|
break; |
|
|
case 4: |
|
|
return('4'); |
|
|
break; |
|
|
case 5: |
|
|
return('5'); |
|
|
break; |
|
|
case 6: |
|
|
return('6'); |
|
|
break; |
|
|
case 7: |
|
|
return('7'); |
|
|
break; |
|
|
case 8: |
|
|
return('8'); |
|
|
break; |
|
|
case 9: |
|
|
return('9'); |
|
|
break; |
|
|
case 10: |
|
|
return('a'); |
|
|
break; |
|
|
case 11: |
|
|
return('b'); |
|
|
break; |
|
|
case 12: |
|
|
return('c'); |
|
|
break; |
|
|
case 13: |
|
|
return('d'); |
|
|
break; |
|
|
case 14: |
|
|
return('e'); |
|
|
break; |
|
|
case 15: |
|
|
return('f'); |
|
|
break; |
|
|
default: |
|
|
USERASSERT_assert(0, __FILE__, __LINE__); |
|
|
return('?'); |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
void CHARFUNC_int_to_lc_hex_rev(int arg, char *s) |
|
|
{ |
|
|
int i; |
|
|
|
|
|
USERASSERT_assert(s != NULL, __FILE__, __LINE__); |
|
|
|
|
|
for (i = 0; i<8; i++) |
|
|
{ |
|
|
s[i] = CHARFUNC_nibble_to_lc_hex_digit(arg); |
|
|
arg >>= 4; |
|
|
} |
|
|
} |
|
122 |
|
|
123 |
//-------------------------------------------------------------------------------- |
//-------------------------------------------------------------------------------- |
124 |
// S T R I N G A N D C H A R A C T E R A R R A Y F U N C T I O N S |
// S T R I N G A N D C H A R A C T E R A R R A Y F U N C T I O N S |
222 |
fprintf(s, "\n"); |
fprintf(s, "\n"); |
223 |
} |
} |
224 |
|
|
|
void FCMIOF_stream_bannerheading(FILE *f, |
|
|
char *s, |
|
|
int n_extra_lines) |
|
|
{ |
|
|
const int lr_padding = 3; |
|
|
/* The number of spaces on each side of what is printed. |
|
|
*/ |
|
|
int i; |
|
|
/* General iteration variable. |
|
|
*/ |
|
|
|
|
|
int n_asterisks; |
|
|
int input_arg_len; |
|
|
int n_left_spaces; |
|
|
int n_right_spaces; |
|
|
|
|
|
/* Check the file pointer, string pointer, and other par. |
|
|
*/ |
|
|
USERASSERT_assert(f != NULL, __FILE__, __LINE__); |
|
|
USERASSERT_assert(s != NULL, __FILE__, __LINE__); |
|
|
USERASSERT_assert(n_extra_lines >= 0, __FILE__, __LINE__); |
|
|
|
|
|
/* Print the right number of solid lines of asterisks to the |
|
|
** standard output. |
|
|
*/ |
|
|
for (i = 0; i<n_extra_lines; i++) |
|
|
{ |
|
|
FCMIOF_stream_repchar(f, '*', FCMIOF_LINE_LEN); |
|
|
fprintf(f, "\n"); |
|
|
} |
|
|
|
|
|
/* Figure out how many asterisks to print on each side of the |
|
|
** argument, and how many spaces. We also need to figure out |
|
|
** how many characters of the input argument to print--if there |
|
|
** are too many characters, we need to truncate. |
|
|
*/ |
|
|
input_arg_len = strlen(s); |
|
|
if (input_arg_len > (FCMIOF_LINE_LEN - 2 * lr_padding - 2)) |
|
|
input_arg_len = FCMIOF_LINE_LEN - 2 * lr_padding - 2; |
|
|
|
|
|
n_asterisks = (FCMIOF_LINE_LEN - 2 * lr_padding - input_arg_len) / 2; |
|
|
|
|
|
n_left_spaces = lr_padding; |
|
|
|
|
|
if ((FCMIOF_LINE_LEN - 2 * lr_padding - input_arg_len) % 2) |
|
|
{ |
|
|
/* Odd, need to pad the right by one. */ |
|
|
n_right_spaces = lr_padding + 1; |
|
|
} |
|
|
else |
|
|
{ |
|
|
n_right_spaces = lr_padding; |
|
|
} |
|
|
|
|
|
/* Print the text. */ |
|
|
FCMIOF_stream_repchar(f, '*', n_asterisks); |
|
|
FCMIOF_stream_repchar(f, ' ', n_left_spaces); |
|
|
for (i = 0; i<input_arg_len; i++) |
|
|
fprintf(f, "%c", s[i]); |
|
|
FCMIOF_stream_repchar(f, ' ', n_right_spaces); |
|
|
FCMIOF_stream_repchar(f, '*', n_asterisks); |
|
|
fprintf(f, "\n"); |
|
|
|
|
|
/* Print the right number of solid lines of asterisks to the |
|
|
** standard output. |
|
|
*/ |
|
|
for (i = 0; i<n_extra_lines; i++) |
|
|
{ |
|
|
FCMIOF_stream_repchar(f, '*', FCMIOF_LINE_LEN); |
|
|
fprintf(f, "\n"); |
|
|
} |
|
|
} |
|
|
|
|
|
void FCMIOF_bannerheading(char *s, int n_extra_lines) |
|
|
{ |
|
|
USERASSERT_assert(s != NULL, __FILE__, __LINE__); |
|
|
USERASSERT_assert(n_extra_lines >= 0, __FILE__, __LINE__); |
|
|
|
|
|
FCMIOF_stream_bannerheading(stdout, s, n_extra_lines); |
|
|
} |
|
|
|
|
|
void FCMIOF_time_stream(FILE *s, time_t ltime) |
|
|
{ |
|
|
char *p; |
|
|
|
|
|
USERASSERT_assert(s != NULL, __FILE__, __LINE__); |
|
|
|
|
|
time(<ime); |
|
|
|
|
|
p = ctime(<ime); |
|
|
|
|
|
if (p) |
|
|
{ |
|
|
int i; |
|
|
|
|
|
for (i = 11; i<19; i++) |
|
|
fprintf(s, "%c", p[i]); |
|
|
fprintf(s, " "); |
|
|
for (i = 0; i<10; i++) |
|
|
fprintf(s, "%c", p[i]); |
|
|
fprintf(s, " "); |
|
|
for (i = 20; i<24; i++) |
|
|
fprintf(s, "%c", p[i]); |
|
|
} |
|
|
else |
|
|
{ |
|
|
fprintf(s, "??? ??? ?? ??:??:?? ????"); |
|
|
} |
|
|
} |
|
|
|
|
225 |
int is_legal_non_eol_character(char c) |
int is_legal_non_eol_character(char c) |
226 |
{ |
{ |
227 |
if ((c >= 32) && (c <= 126)) |
if ((c >= 32) && (c <= 126)) |
267 |
size_t i, len; |
size_t i, len; |
268 |
char buffer[100]; |
char buffer[100]; |
269 |
|
|
270 |
sprintf(buffer, "%llu", arg); |
sprintf_s(buffer, sizeof(buffer)/sizeof(buffer[0]), "%llu", arg); |
271 |
len = strlen(buffer); |
len = strlen(buffer); |
272 |
|
|
273 |
for (i = 0; i < len; i++) |
for (i = 0; i < len; i++) |