Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int ParseINI(FILE *File, void (*Handler)(const char *Group, const char *Item, const char *Value)) {
- if(File == NULL) return 0;
- char Group[512]="", *Item, *Value, Line[512]="", c, *Poke = NULL;
- int State = 0, i;
- while(!feof(File)) {
- for(i=0,c=1;;i++) {
- c = fgetc(File);
- if(c=='\r'||c=='\n') {
- Line[i]=0;
- break;
- }
- Line[i] = c;
- }
- while(c=='\r'||c=='\n')
- c = fgetc(File);
- fseek(File, -1 , SEEK_CUR);
- if(!*Line)
- break;
- else if(*Line == ';'); // comment
- else if(*Line == '[') { // group
- Poke = strchr(Line, ']');
- if(Poke) *Poke = 0;
- strcpy(Group, Line+1);
- } else { // item
- Poke = strchr(Line, '=');
- if(Poke) {
- *Poke = 0;
- Item = Line;
- Value = Poke+1;
- Handler(Group, Item, Value);
- }
- }
- }
- fclose(File);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement