ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/src/Inifile_Reader.c
(Generate patch)

Comparing Daodan/src/inifile_reader.c (file contents):
Revision 349 by rossy, Wed Jun 10 12:40:16 2009 UTC vs.
Revision 692 by alloc, Thu Mar 7 17:26:13 2013 UTC

# Line 1 | Line 1
1   #include <stdio.h>
2   #include <stdlib.h>
3 < #include <stdbool.h>
3 > #include "stdint.h"
4   #include <string.h>
5   #include <ctype.h>
6  
7 < #include "inifile.h"
8 < /*
7 > #include "Inifile_Reader.h"
8 >
9   char* inifile_cleanstr(char* str)
10   {
11 +        int i;
12 +        for (i = strlen(str) - 1; i >= 0; i --)
13 +                if (isspace(str[i]))
14 +                        str[i] = '\0';
15 +                else
16 +                        break;
17 +        
18          while (isspace(*str))
19                  str++;
20          
21 <        int i;
22 <        for (i = 0; str[i]; i ++)
21 >        return str;
22 > }
23 >
24 > int64_t inifile_parseint(const char* str, bool issigned)
25 > {
26 >        int64_t ret = 0;
27 >        bool neg = false;
28 >        if (str[0] == '0' && str[1] == 'x')
29 >        {
30 >                int i;
31 >                if (str[2] == '\0')
32 >                        return 0x100000000LL;
33 >                
34 >                for (i = 0, str += 2; *str; i++, str++)
35 >                {
36 >                        if (i == 8)
37 >                                return 0x100000000LL;
38 >                        
39 >                        ret <<= 4;
40 >                        if (*str >= '0' && *str <= '9')
41 >                                ret |= *str - '0';
42 >                        else if (*str >= 'a' && *str <= 'f')
43 >                                ret |= *str - 'a' + 10;
44 >                        else if (*str >= 'A' && *str <= 'F')
45 >                                ret |= *str - 'A' + 10;
46 >                        else
47 >                                return 0x100000000LL;
48 >                }
49 >                return ret;
50 >        }
51 >        else if ((*str >= '0' && *str <= '9') || (neg = (*str == '-')))
52          {
53 <                if
53 >                int i;
54 >                if (neg)
55 >                        str++;
56 >                for (i = 0; *str; i++, str++)
57 >                {
58 >                        if (i == 10)
59 >                                return 0x100000000LL;
60 >                        else if (i == 9 && !issigned && (ret > 429496729LL || (ret == 429496729LL && *str > '5')))
61 >                                return 0x100000000LL;
62 >                        else if (i == 9 && issigned && (ret > 214748364LL || (ret == 214748364LL && *str > (neg ? '8' : '7'))))
63 >                                return 0x100000000LL;
64 >                        
65 >                        ret *= 10;
66 >                        if (*str >= '0' && *str <= '9')
67 >                                ret += *str - '0';
68 >                        else
69 >                                return 0x100000000LL;
70 >                }
71 >                if (neg)
72 >                        ret *= -1;
73 >                return ret;
74          }
75 <        
76 <        return str;
75 >        else
76 >                return 0x100000000LL;
77   }
78 < */
79 < bool inifile_read(char* filename, inifile_callback callback)
78 >
79 > bool inifile_read(const char* filename, inifile_callback callback)
80   {
81          FILE* fp = fopen(filename, "r");
82          char* inisection = "";
# Line 56 | Line 112 | bool inifile_read(char* filename, inifil
112                          
113                          if (inisection[0])
114                                  free(inisection);
115 <                        inisection = strdup(readptr + 1); // Skip the first [
115 >                        inisection = _strdup(readptr + 1); // Skip the first [
116                          newsection = true;
117                  }
118                  else // It's a value.

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)