65 static const char* expression =
66 "^[ \t]*cache_dir([ \t]+([[:alpha:]]+))?[ \t]+([[:graph:]]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)";
69 if (
debug ) fprintf(
debug,
"# trying to open %s\n", fn ? fn :
"(null)" );
70 std::ifstream cfgin(fn);
72 fprintf( stderr,
"fopen %s: %s\n", fn,
strerror(errno) );
77 if (
debug ) fprintf(
debug,
"# trying to compile \"%s\"\n", expression );
79 int result = regcomp( &rexp, expression, REG_EXTENDED );
82 regerror( result, &rexp, buffer,
sizeof(buffer) );
83 fprintf( stderr,
"regular expression \"%s\": %s\n", expression, buffer );
88 if (
debug ) fputs(
"# trying to read lines\n",
debug );
93 while ( cfgin.getline( line,
sizeof(line)) ) {
97 if ( (s = (
char*) memchr( line,
'#',
sizeof(line) )) ) *s =
'\0';
100 if ( *line ==
'\0' || *line ==
'\n' )
continue;
103 if ( (result=regexec( &rexp, line, 7, subs, 0 )) != 0 ) {
105 if ( result != REG_NOMATCH ) {
107 regerror( result, &rexp, buffer,
sizeof(buffer) );
108 fprintf( stderr,
"while matching \"%s\" against %s%s\n",
109 expression, line, buffer );
116 memset( &cd, 0,
sizeof(cd) );
117 if (
debug ) fprintf(
debug,
"# match from %d-%d on line %s",
118 (
int)subs[0].rm_so, (
int)subs[0].rm_eo,
122 line[ subs[0].rm_eo ] =
'\0';
127 if ( subs[6].rm_so == -1 ) {
129 cd.type = CacheDir::CDT_UFS;
132 line[ subs[offset].rm_eo ] =
'\0';
133 if (
debug ) fprintf(
debug,
"# match from %d-%d on \"%s\"\n",
134 (
int)subs[offset].rm_so,
135 (
int)subs[offset].rm_eo,
136 line+subs[offset].rm_so );
137 if ( strcmp( line + subs[offset].rm_so,
"ufs" ) == 0 )
138 cd.type = CacheDir::CDT_UFS;
139 else if ( strcmp( line + subs[offset].rm_so,
"asyncufs" ) == 0 )
140 cd.type = CacheDir::CDT_AUFS;
141 else if ( strcmp( line + subs[offset].rm_so,
"diskd" ) == 0 )
142 cd.type = CacheDir::CDT_DISKD;
144 cd.type = CacheDir::CDT_OTHER;
149 line[ subs[offset].rm_eo ] =
'\0';
150 if (
debug ) fprintf(
debug,
"# match from %d-%d on \"%s\"\n",
151 (
int)subs[offset].rm_so,
152 (
int)subs[offset].rm_eo,
153 line+subs[offset].rm_so );
154 cd.base =
xstrdup( line+subs[offset].rm_so );
158 line[ subs[offset].rm_eo ] =
'\0';
159 if (
debug ) fprintf(
debug,
"# match from %d-%d on \"%s\"\n",
160 (
int)subs[offset].rm_so,
161 (
int)subs[offset].rm_eo,
162 line+subs[offset].rm_so );
163 cd.size = strtoul( line+subs[offset].rm_so,
nullptr, 10 );
167 line[ subs[offset].rm_eo ] =
'\0';
168 if (
debug ) fprintf(
debug,
"# match from %d-%d on \"%s\"\n",
169 (
int)subs[offset].rm_so,
170 (
int)subs[offset].rm_eo,
171 line+subs[offset].rm_so );
172 cd.level[0] = strtoul( line+subs[offset].rm_so,
nullptr, 10 );
176 line[ subs[offset].rm_eo ] =
'\0';
177 if (
debug ) fprintf(
debug,
"# match from %d-%d on \"%s\"\n",
178 (
int)subs[offset].rm_so,
179 (
int)subs[offset].rm_eo,
180 line+subs[offset].rm_so );
181 cd.level[1] = strtoul( line+subs[offset].rm_so,
nullptr, 10 );
184 cachedir.push_back( cd );
190 return cachedir.size();
void debug(const char *format,...)
int readConfigFile(CacheDirVector &cachedir, const char *fn, FILE *debug)