| version 1.3, 2001/12/01 01:27:47 |
version 1.4, 2001/12/05 23:58:48 |
|
|
| |
#include "str/dynfgets.h" |
| |
|
| static int cfg_cfgfile_get_next_opt(const CFG_CONTEXT con); |
static int cfg_cfgfile_get_next_opt(const CFG_CONTEXT con); |
| |
static int cfgfile_set_currents(char *buf); |
| |
static char *get_multi_line(const CFG_CONTEXT con); |
| |
static void trim_spaces(char *buf); |
| |
|
| |
static int cfg_cfgfile_get_next_opt(const CFG_CONTEXT con) |
| |
{ |
| |
char *buf; |
| |
|
| |
if (con->fhandle == NULL) { |
| |
con->fhandle = fopen(con->filename, "r"); |
| |
if (con->fhandle == NULL) |
| |
return CFG_ERROR_FILE_NOT_FOUND; |
| |
|
| |
if (con->begin_pos > 0 && |
| |
fseek(con->fhandle, con->begin_pos, SEEK_SET) != 0) |
| |
return CFG_ERROR_SEEK_ERROR; |
| |
} |
| |
|
| |
while (1) { |
| |
|
| |
buf = get_multi_line(con); |
| |
|
| |
if (buf == NULL) |
| |
return CFG_ERROR_NOMEM; |
| |
|
| |
#if defined(DEBUG) && DEBUG |
| |
printf("read_multi_line<%s>\n", buf); |
| |
#endif |
| |
|
| |
if (cfgfile_set_currents(buf) == 0) |
| |
return CFG_ERROR_NOMEM; |
| |
|
| |
free(buf); |
| |
} |
| |
|
| static int cfg_cfgfile_get_next_opt(const CFG_CONTEXT con) { |
|
| return 0; |
return 0; |
| } |
} |
| |
|
| |
/* |
| |
* cfgfile_set_curents() |
| |
* |
| |
* Function allocate and initialize variables con->cur_opt and con->cur_arg |
| |
* according to input parameter buf. |
| |
* Returns 1 on success, 0 on error (not enough memory). |
| |
*/ |
| |
|
| |
static int cfgfile_set_currents(char *buf) |
| |
{ |
| |
|
| |
return 1; |
| |
} |
| |
|
| |
/* |
| |
* get_multi_line() |
| |
* |
| |
* Gets single line from file. If line continues on next line, |
| |
* returns the whole line concatenated. |
| |
*/ |
| |
|
| |
static char *get_multi_line(const CFG_CONTEXT con) |
| |
{ |
| |
register char **ar = NULL; |
| |
register char *buf = NULL; |
| |
|
| |
register int state = 0; |
| |
|
| |
if ((ar = strdyn_create()) == NULL) |
| |
return NULL; |
| |
|
| |
while (1) { |
| |
if (buf != NULL) |
| |
free(buf); |
| |
|
| |
buf = dynamic_fgets(con->fhandle); |
| |
if (buf == NULL) |
| |
return NULL; |
| |
|
| |
//trim_spaces(buf); |
| |
|
| |
if (strlen(buf) == 0 || strdyn_str(buf, con->comment_str) == buf) { |
| |
if (state == 0) |
| |
continue; |
| |
else |
| |
break; |
| |
} |
| |
|
| |
if (buf[strlen(buf) - 1] == '\\') { |
| |
buf[strlen(buf) - 1] = '\0'; |
| |
//trim_spaces(buf); |
| |
state = 1; |
| |
} |
| |
|
| |
ar = strdyn_add(ar, buf); |
| |
if (ar == NULL) |
| |
return NULL; |
| |
|
| |
if (state == 0) |
| |
break; |
| |
} |
| |
|
| |
if (buf != NULL) |
| |
free(buf); |
| |
|
| |
buf = strdyn_implode(ar, ""); |
| |
if (buf == NULL) |
| |
return NULL; |
| |
|
| |
return buf; |
| |
} |
| |
|
| |
/* |
| |
* trim_str() |
| |
* |
| |
* Removes white characters from beginning and end of string. |
| |
*/ |
| |
|
| |
static void trim_spaces(char *buf) |
| |
{ |
| |
|
| |
buf = buf; |
| |
|
| |
return; |
| |
} |
| |
|