Lines 850-855
char *firsttok(char **s, const char *delim)
Link Here
|
850 |
} |
850 |
} |
851 |
|
851 |
|
852 |
/* |
852 |
/* |
|
|
853 |
* This is a simple trim function that only trim the space on the left of the string. |
854 |
* It will not duplicate the original string. It returns a pointer of the original string which is not a space |
855 |
* Args: |
856 |
* char *str: |
857 |
* Address of the pointer to the string we are going to trim. |
858 |
* Return value: |
859 |
* The pointer to the first none space character in the original string. |
860 |
* You do not need to free this pointer. |
861 |
*/ |
862 |
char *trimleft(char *str) { |
863 |
if(str == (char *)NULL) |
864 |
return NULL; |
865 |
|
866 |
while(str != (char *)NULL) { |
867 |
if(isspace(*str)) { |
868 |
str++; |
869 |
continue; |
870 |
} |
871 |
|
872 |
break; |
873 |
} |
874 |
|
875 |
return str; |
876 |
} |
877 |
|
878 |
/* |
853 |
read_config() -- Open and parse config file and extract values of variables |
879 |
read_config() -- Open and parse config file and extract values of variables |
854 |
*/ |
880 |
*/ |
855 |
bool_t read_config() |
881 |
bool_t read_config() |
Lines 869-883
bool_t read_config()
Link Here
|
869 |
} |
895 |
} |
870 |
|
896 |
|
871 |
while(fgets(buf, sizeof(buf), fp)) { |
897 |
while(fgets(buf, sizeof(buf), fp)) { |
872 |
char *begin=buf; |
898 |
char *begin=trimleft(buf); |
873 |
char *rightside; |
899 |
char *rightside; |
874 |
/* Make comments invisible */ |
|
|
875 |
if((p = strchr(buf, '#'))) { |
876 |
*p = (char)NULL; |
877 |
} |
878 |
|
900 |
|
879 |
/* Ignore malformed lines and comments */ |
901 |
/* Ignore malformed lines and comments */ |
880 |
if(strchr(buf, '=') == (char *)NULL) continue; |
902 |
if(*begin == '#' || strchr(buf, '=') == (char *)NULL) continue; |
881 |
|
903 |
|
882 |
/* Parse out keywords */ |
904 |
/* Parse out keywords */ |
883 |
p=firsttok(&begin, "= \t\n"); |
905 |
p=firsttok(&begin, "= \t\n"); |
884 |
- |
|
|