mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 10:51:54 -04:00
Trims extra spaces in the configuration file.
This commit is contained in:
parent
2aa36a5df5
commit
09b8a3cd7c
4 changed files with 36 additions and 10 deletions
1
HISTORY
1
HISTORY
|
|
@ -3,6 +3,7 @@ SnapRAID HISTORY
|
|||
|
||||
1.5 2011/6
|
||||
==========
|
||||
* In the configuration file extra space are ignored.
|
||||
* Changed the output of check/fix to allow a more easily postprocessing
|
||||
with other tools like awk and sort.
|
||||
* Added the hidden option -G/--gui to enable the output of progress
|
||||
|
|
|
|||
20
state.c
20
state.c
|
|
@ -108,16 +108,24 @@ void state_config(struct snapraid_state* state, const char* path, int verbose, i
|
|||
/* start */
|
||||
s = buffer;
|
||||
|
||||
/* here we use strtoken_trim() to eat extra spaces inserted by the user */
|
||||
|
||||
/* skip ending spaces */
|
||||
while (ret>0 && isspace(s[ret-1])) {
|
||||
--ret;
|
||||
s[ret] = 0;
|
||||
}
|
||||
/* skip initial spaces */
|
||||
while (*s && isspace(*s))
|
||||
while (*s && isspace(*s)) {
|
||||
++s;
|
||||
}
|
||||
|
||||
/* ignore comments and empty lines */
|
||||
if (*s == '#' || *s == 0)
|
||||
continue;
|
||||
|
||||
tag = s;
|
||||
s = strtoken(s);
|
||||
s = strtoken_trim(s);
|
||||
|
||||
if (strcmp(tag, "block_size") == 0) {
|
||||
ret = stru32(s, &state->block_size);
|
||||
|
|
@ -158,7 +166,7 @@ void state_config(struct snapraid_state* state, const char* path, int verbose, i
|
|||
++content_count;
|
||||
} else if (strcmp(tag, "disk") == 0) {
|
||||
char* name = s;
|
||||
s = strtoken(s);
|
||||
s = strtoken_trim(s);
|
||||
tommy_array_insert(&state->diskarr, disk_alloc(name, s));
|
||||
} else if (strcmp(tag, "exclude") == 0) {
|
||||
struct snapraid_filter* filter = filter_alloc(-1, s);
|
||||
|
|
@ -294,9 +302,7 @@ void state_read(struct snapraid_state* state)
|
|||
/* start */
|
||||
s = buffer;
|
||||
|
||||
/* skip initial spaces */
|
||||
while (*s && isspace(*s))
|
||||
++s;
|
||||
/* here we use strtoken() to allow filenames starting and ending with spaces */
|
||||
|
||||
/* ignore comments and empty lines */
|
||||
if (*s == '#' || *s == 0)
|
||||
|
|
@ -304,7 +310,7 @@ void state_read(struct snapraid_state* state)
|
|||
|
||||
tag = s;
|
||||
s = strtoken(s);
|
||||
|
||||
|
||||
if (strcmp(tag, "blk") == 0 || strcmp(tag, "inv") == 0) {
|
||||
char* pos;
|
||||
char* hash;
|
||||
|
|
|
|||
4
util.c
4
util.c
|
|
@ -55,7 +55,7 @@ int strgets(char* s, unsigned size, FILE* f)
|
|||
return -1;
|
||||
}
|
||||
if (i == s)
|
||||
return 0;
|
||||
return 0; /* return EOF only if nothing was read */
|
||||
}
|
||||
|
||||
/* remove ending carrige return to support the Windows CR+LF format */
|
||||
|
|
@ -64,7 +64,7 @@ int strgets(char* s, unsigned size, FILE* f)
|
|||
|
||||
*i = 0;
|
||||
|
||||
return 1;
|
||||
return i - s;
|
||||
}
|
||||
|
||||
int stru32(const char* s, uint32_t* value)
|
||||
|
|
|
|||
21
util.h
21
util.h
|
|
@ -35,9 +35,28 @@ static inline char* strtoken(char* s)
|
|||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like strtoken() but trim spaces.
|
||||
*/
|
||||
static inline char* strtoken_trim(char* s)
|
||||
{
|
||||
while (*s && !isspace(*s))
|
||||
++s;
|
||||
if (*s) {
|
||||
*s = 0;
|
||||
++s;
|
||||
}
|
||||
|
||||
/* skip ending spaces */
|
||||
while (*s && isspace(*s))
|
||||
++s;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a text line from a file.
|
||||
* Returns -1 on error, 0 on oef, and 1 if more data is available.
|
||||
* Returns -1 on error, 0 on oef, or the number of chars read.
|
||||
*/
|
||||
int strgets(char* s, unsigned size, FILE* f);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue