7 */ |
7 */ |
8 /*--------------------------------------------------------------------------*/ |
8 /*--------------------------------------------------------------------------*/ |
9 /*---------------------------- Includes ------------------------------------*/ |
9 /*---------------------------- Includes ------------------------------------*/ |
10 #include <ctype.h> |
10 #include <ctype.h> |
11 #include "iniparser.h" |
11 #include "iniparser.h" |
|
12 #include "physfs.h" |
|
13 #include "physfsfgets.h" |
12 |
14 |
13 /*---------------------------- Defines -------------------------------------*/ |
15 /*---------------------------- Defines -------------------------------------*/ |
14 #define ASCIILINESZ (1024) |
16 #define ASCIILINESZ (1024) |
15 #define INI_INVALID_KEY ((char*)-1) |
17 #define INI_INVALID_KEY ((char*)-1) |
16 |
18 |
626 The returned dictionary must be freed using iniparser_freedict(). |
628 The returned dictionary must be freed using iniparser_freedict(). |
627 */ |
629 */ |
628 /*--------------------------------------------------------------------------*/ |
630 /*--------------------------------------------------------------------------*/ |
629 dictionary * iniparser_load(const char * ininame) |
631 dictionary * iniparser_load(const char * ininame) |
630 { |
632 { |
631 FILE * in ; |
633 PHYSFS_File * in ; |
632 |
634 |
633 char line [ASCIILINESZ+1] ; |
635 char line [ASCIILINESZ+1] ; |
634 char section [ASCIILINESZ+1] ; |
636 char section [ASCIILINESZ+1] ; |
635 char key [ASCIILINESZ+1] ; |
637 char key [ASCIILINESZ+1] ; |
636 char tmp [ASCIILINESZ+1] ; |
638 char tmp [ASCIILINESZ+1] ; |
641 int lineno=0 ; |
643 int lineno=0 ; |
642 int errs=0; |
644 int errs=0; |
643 |
645 |
644 dictionary * dict ; |
646 dictionary * dict ; |
645 |
647 |
646 if ((in=fopen(ininame, "r"))==NULL) { |
648 if ((in = PHYSFS_openRead(ininame))==NULL) { |
647 fprintf(stderr, "iniparser: cannot open %s\n", ininame); |
649 fprintf(stderr, "iniparser: cannot open %s\n", ininame); |
648 return NULL ; |
650 return NULL ; |
649 } |
651 } |
650 |
652 |
651 dict = dictionary_new(0) ; |
653 dict = dictionary_new(0) ; |
652 if (!dict) { |
654 if (!dict) { |
653 fclose(in); |
655 PHYSFS_close(in); |
654 return NULL ; |
656 return NULL ; |
655 } |
657 } |
656 |
658 |
657 memset(line, 0, ASCIILINESZ); |
659 memset(line, 0, ASCIILINESZ); |
658 memset(section, 0, ASCIILINESZ); |
660 memset(section, 0, ASCIILINESZ); |
659 memset(key, 0, ASCIILINESZ); |
661 memset(key, 0, ASCIILINESZ); |
660 memset(val, 0, ASCIILINESZ); |
662 memset(val, 0, ASCIILINESZ); |
661 last=0 ; |
663 last=0 ; |
662 |
664 |
663 while (fgets(line+last, ASCIILINESZ-last, in)!=NULL) { |
665 while (PHYSFS_fgets(line+last, ASCIILINESZ-last, in)!=NULL) { |
664 lineno++ ; |
666 lineno++ ; |
665 len = (int)strlen(line)-1; |
667 len = (int)strlen(line)-1; |
666 if (len==0) |
668 if (len==0) |
667 continue; |
669 continue; |
668 /* Safety check against buffer overflows */ |
670 /* Safety check against buffer overflows */ |