Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdint.h>
- int main()
- {
- char buf[16 * 1024];
- int tot_sz = 0;
- FILE *f = fopen("map.bin", "w");
- do
- {
- if(fgets(buf, sizeof(buf), stdin) == NULL)
- break;
- int len = strlen(buf);
- if(len == 0)
- continue;
- if(buf[len - 1] == '\n')
- buf[--len] = 0;
- int i = 0;
- while(i < len && isspace(buf[i]))
- i++;
- char *next;
- unsigned long addr = strtol(&buf[i], &next, 0);
- while(*next && isspace(*next))
- next++;
- len = strlen(next);
- if(len == 0)
- continue;
- for(int i = 0; i < len; i++)
- if(!isalnum(next[i]) && next[i] != '_')
- goto Lnext;
- printf("%#lx: %s\n", addr, next);
- uint32_t addr32 = addr;
- fwrite(&addr32, sizeof(addr32), 1, f);
- fwrite(next, strlen(next) + 1, 1, f);
- tot_sz += 4 + strlen(next) + 1;
- Lnext:
- continue;
- }while(!feof(stdin));
- fclose(f);
- printf("Total size: %d bytes\n", tot_sz);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement