Advertisement
Guest User

Untitled

a guest
Oct 1st, 2011
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <stdint.h>
  6.  
  7. int main()
  8. {
  9.     char buf[16 * 1024];
  10.     int tot_sz = 0;
  11.     FILE *f = fopen("map.bin", "w");
  12.    
  13.     do
  14.     {
  15.         if(fgets(buf, sizeof(buf), stdin) == NULL)
  16.             break;
  17.         int len = strlen(buf);
  18.         if(len == 0)
  19.             continue;
  20.        
  21.         if(buf[len - 1] == '\n')
  22.             buf[--len] = 0;
  23.            
  24.         int i = 0;
  25.         while(i < len && isspace(buf[i]))
  26.             i++;
  27.         char *next;
  28.         unsigned long addr = strtol(&buf[i], &next, 0);
  29.  
  30.         while(*next && isspace(*next))
  31.             next++;
  32.         len = strlen(next);
  33.         if(len == 0)
  34.             continue;
  35.         for(int i = 0; i < len; i++)
  36.             if(!isalnum(next[i]) && next[i] != '_')
  37.                 goto Lnext;
  38.         printf("%#lx: %s\n", addr, next);
  39.         uint32_t addr32 = addr;
  40.         fwrite(&addr32, sizeof(addr32), 1, f);
  41.         fwrite(next, strlen(next) + 1, 1, f);
  42.         tot_sz += 4 + strlen(next) + 1;
  43.         Lnext:
  44.         continue;
  45.     }while(!feof(stdin));
  46.     fclose(f);
  47.     printf("Total size: %d bytes\n", tot_sz);
  48.     return 0;
  49. }
  50.  
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement