Changeset 1517 for branches/reyalp-flt/tools/elf2flt/myio.c
- Timestamp:
- 12/30/11 13:39:02 (18 months ago)
- File:
-
- 1 edited
-
branches/reyalp-flt/tools/elf2flt/myio.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/reyalp-flt/tools/elf2flt/myio.c
r1510 r1517 199 199 } 200 200 201 202 //========================================== 203 204 struct StopListRecord { 205 char* symbol; 206 char* warning; 207 void* next; 208 }; 209 210 211 char *stoplist_buf=0; 212 struct StopListRecord* stoplisthead=0; 213 214 215 int load_stoplist(char* stopfile) 216 { 217 if ( !stopfile ) 218 return 0; 219 220 int fd=open(stopfile, O_RDONLY|O_BINARY, 0777); 221 222 if ( fd <=0 ) { 223 PRINTERR(stderr,"No stoplist file '%s' found\n",stopfile); 224 return 0; 225 } 226 int stoplistfilesize = lseek(fd,0,SEEK_END); 227 if ( FLAG_VERBOSE ) 228 printf("Stoplist file '%s' size=%d\n",stopfile, stoplistfilesize); 229 230 stoplist_buf=malloc(stoplistfilesize+1); 231 if (!stoplist_buf) return 0; 232 233 int now=0, loaded =0; 234 if (lseek(fd, 0, SEEK_SET) != 0) return 0; 235 do 236 { 237 now = read(fd, stoplist_buf+loaded, stoplistfilesize-loaded); 238 loaded+=now; 239 } while (loaded<stoplistfilesize && now); 240 241 stoplist_buf[loaded]=0; 242 close(fd); 243 244 if ( loaded != stoplistfilesize ) 245 return -loaded; 246 247 // Parse 248 struct StopListRecord record; 249 char* sym=0, *finsym=0; 250 char* cur=stoplist_buf; 251 252 for ( ; cur<(stoplist_buf+stoplistfilesize); ) { 253 for(;*cur==' '; cur++); // skip spaces 254 255 sym=cur; 256 for(;*cur && *cur!=9 && *cur!=' ' && *cur!=0x0a; cur++); 257 if ( cur==sym ) { 258 for(;*cur && *cur!=10; cur++); 259 if ( *cur==10) {cur++;} 260 continue; 261 } 262 263 record.symbol = sym; 264 record.warning = "Error: unsafe symbol used. Please check stoplist"; 265 finsym=cur; 266 for(;*cur && *cur!=9 && *cur!=0x0a; cur++); // find \t 267 268 if ( *cur==0 ) break; 269 if ( *cur==9 ) { 270 cur++; 271 record.warning=cur; 272 } 273 274 for(;*cur && *cur!=10; cur++); // find eol 275 if ( *cur==0x0a && cur>stoplist_buf && *(cur-1)==0x0d) 276 *(cur-1)=0; 277 278 if (cur==record.warning) 279 record.warning = "Error: unsafe symbol used. Please check stoplist"; 280 281 record.next=stoplisthead; 282 stoplisthead = malloc (sizeof(struct StopListRecord)); 283 memcpy( stoplisthead, &record, sizeof(struct StopListRecord)); 284 285 if ( *cur!=0 ) { *cur=0; cur++;} 286 *finsym = 0; 287 288 if ( FLAG_VERBOSE ) 289 printf("Stop record: %s => %s\n",record.symbol, record.warning); 290 } 291 292 return loaded; 293 } 294 295 //return: 1 - found in stoplist, 0 - not found 296 int stoplist_check(char *sym) 297 { 298 struct StopListRecord *cur; 299 300 for ( cur = stoplisthead; cur; cur = cur->next ) { 301 if ( !cur->symbol ) 302 continue; 303 if ( !strcmp( sym, cur->symbol) ) { 304 PRINTERR(stderr,"%s\n",cur->warning); 305 cur->symbol = 0; // mark that this symbol is already warned 306 return 1; 307 } 308 } 309 return 0; 310 } 311 312 201 313 //========================================== 202 314 void raise_error()
Note: See TracChangeset
for help on using the changeset viewer.