Mercurial > hg > early-roguelike
comparison urogue/dictutil.c @ 257:c4b12d2d1dcd
UltraRogue: fix various build failures.
author | John "Elwin" Edwards |
---|---|
date | Tue, 31 Jan 2017 20:33:49 -0500 |
parents | c495a4f288c6 |
children | 13b482bd9e66 |
comparison
equal
deleted
inserted
replaced
256:c495a4f288c6 | 257:c4b12d2d1dcd |
---|---|
26 | 26 |
27 #include "dict.h" | 27 #include "dict.h" |
28 #include "dictutil.h" | 28 #include "dictutil.h" |
29 #include "rogue.h" | 29 #include "rogue.h" |
30 | 30 |
31 int trace; | 31 int dict_trace; |
32 FILE *ft; | 32 FILE *ft; |
33 | 33 |
34 | 34 |
35 /*********** | 35 /*********** |
36 ** Read 'count' characters into 'buffer' at 'offset' in a binary file | 36 ** Read 'count' characters into 'buffer' at 'offset' in a binary file |
81 return( NULL ); | 81 return( NULL ); |
82 } /* endif */ | 82 } /* endif */ |
83 | 83 |
84 if ( block == NULL ) { | 84 if ( block == NULL ) { |
85 ptr = malloc( dt_entry->size ); | 85 ptr = malloc( dt_entry->size ); |
86 if ( trace > 3 ) { | 86 if ( dict_trace > 3 ) { |
87 fprintf( ft , "\ndict_load_block allocates %lx bytes at location %p\n" , | 87 fprintf( ft , "\ndict_load_block allocates %lx bytes at location %p\n" , |
88 dt_entry->size , ptr ); | 88 dt_entry->size , ptr ); |
89 } /* endif */ | 89 } /* endif */ |
90 } else { | 90 } else { |
91 ptr = block; | 91 ptr = block; |
92 if ( trace > 3 ) { | 92 if ( dict_trace > 3 ) { |
93 fprintf( ft , "\ndict_load_block uses memory at location %p\n" , ptr ); | 93 fprintf( ft , "\ndict_load_block uses memory at location %p\n" , ptr ); |
94 } /* endif */ | 94 } /* endif */ |
95 } /* endif */ | 95 } /* endif */ |
96 if ( ptr == NULL ) { | 96 if ( ptr == NULL ) { |
97 signal_error( "dict_load_block: alloc failed " , toc_id , 1 ); | 97 signal_error( "dict_load_block: alloc failed " , toc_id , 1 ); |
111 return( NULL ); | 111 return( NULL ); |
112 } /* endif */ | 112 } /* endif */ |
113 | 113 |
114 dt_entry->ptr = ptr; | 114 dt_entry->ptr = ptr; |
115 | 115 |
116 if ( trace > 3 ) { | 116 if ( dict_trace > 3 ) { |
117 fprintf( ft , "\nLoaded block\nTOC entry: id:%s offset:%lx size:%lx ptr:%p checksum:%lx type:%d\n" , | 117 fprintf( ft , "\nLoaded block\nTOC entry: id:%s offset:%lx size:%lx ptr:%p checksum:%lx type:%d\n" , |
118 dict->toc[index].id , dict->toc[index].offset , | 118 dict->toc[index].id , dict->toc[index].offset , |
119 dict->toc[index].size , dict->toc[index].ptr , | 119 dict->toc[index].size , dict->toc[index].ptr , |
120 dict->toc[index].checksum , dict->toc[index].type ); | 120 dict->toc[index].checksum , dict->toc[index].type ); |
121 } /* endif */ | 121 } /* endif */ |
158 if ( ret_code == -1 ) { | 158 if ( ret_code == -1 ) { |
159 signal_error( "dict_save_block: block_write failed " , toc_id , 1 ); | 159 signal_error( "dict_save_block: block_write failed " , toc_id , 1 ); |
160 return( FALSE ); | 160 return( FALSE ); |
161 } /* endif */ | 161 } /* endif */ |
162 | 162 |
163 if ( trace > 3 ) { | 163 if ( dict_trace > 3 ) { |
164 fprintf( ft , "\nStored block\nTOC entry: id:%s offset:%lx size:%lx ptr:%p checksum:%lx type:%d\n" , | 164 fprintf( ft , "\nStored block\nTOC entry: id:%s offset:%lx size:%lx ptr:%p checksum:%lx type:%d\n" , |
165 dict->toc[index].id , dict->toc[index].offset , | 165 dict->toc[index].id , dict->toc[index].offset , |
166 dict->toc[index].size , dict->toc[index].ptr , | 166 dict->toc[index].size , dict->toc[index].ptr , |
167 dict->toc[index].checksum , dict->toc[index].type ); | 167 dict->toc[index].checksum , dict->toc[index].type ); |
168 } /* endif */ | 168 } /* endif */ |
416 | 416 |
417 return( TRUE ); | 417 return( TRUE ); |
418 } | 418 } |
419 | 419 |
420 /*********** | 420 /*********** |
421 ** If trace (global) > 0 , signal an error | 421 ** If dict_trace (global) > 0 , signal an error |
422 ** If severity > 0 , abort | 422 ** If severity > 0 , abort |
423 ***********/ | 423 ***********/ |
424 | 424 |
425 void signal_error( char *header , char *message , int severity ) | 425 void signal_error( char *header , char *message , int severity ) |
426 { | 426 { |
427 FILE *fpe; | 427 FILE *fpe; |
428 | 428 |
429 if ( trace > 0 ) { | 429 if ( dict_trace > 0 ) { |
430 printf( "%s: %s\n" , header , message ); | 430 printf( "%s: %s\n" , header , message ); |
431 fpe = fopen( "ERROR.FIL" , "a" ); | 431 fpe = fopen( "ERROR.FIL" , "a" ); |
432 fprintf( fpe , "\n%s: %s\n" , header , message ); | 432 fprintf( fpe , "\n%s: %s\n" , header , message ); |
433 fclose( fpe ); | 433 fclose( fpe ); |
434 } /* endif */ | 434 } /* endif */ |