Add function psl_suffix_wildcard_count()

This commit is contained in:
Tim Rühsen 2015-09-19 10:55:09 +02:00
parent e443d21b61
commit 34289fa59b
4 changed files with 31 additions and 1 deletions

View File

@ -95,6 +95,9 @@ int
/* just counts exceptions */
int
psl_suffix_exception_count(const psl_ctx_t *psl);
/* just counts wildcards */
int
psl_suffix_wildcard_count(const psl_ctx_t *psl);
/* returns compilation time */
time_t
psl_builtin_compile_time(void);

View File

@ -155,7 +155,8 @@ struct _psl_ctx_st {
*suffixes;
int
nsuffixes,
nexceptions;
nexceptions,
nwildcards;
};
/* include the PSL data compiled by 'psl2c' */
@ -168,6 +169,7 @@ struct _psl_ctx_st {
static time_t _psl_compile_time;
static int _psl_nsuffixes;
static int _psl_nexceptions;
static int _psl_nwildcards;
static const char _psl_sha1_checksum[] = "";
static const char _psl_filename[] = "";
#endif
@ -730,6 +732,7 @@ psl_ctx_t *psl_load_fp(FILE *fp)
p++;
/* wildcard *.foo.bar implicitely make foo.bar a public suffix */
suffix.flags = _PSL_FLAG_WILDCARD | _PSL_FLAG_PLAIN;
psl->nwildcards++;
psl->nsuffixes++;
} else {
if (!strchr(p, '.'))
@ -863,6 +866,26 @@ int psl_suffix_exception_count(const psl_ctx_t *psl)
return 0;
}
/**
* psl_suffix_wildcard_count:
* @psl: PSL context pointer
*
* This function returns number of public suffix wildcards maintained by @psl.
*
* Returns: Number of public suffix wildcards in PSL context.
*
* Since: 0.10.0
*/
int psl_suffix_wildcard_count(const psl_ctx_t *psl)
{
if (psl == &_builtin_psl)
return _psl_nwildcards;
else if (psl)
return psl->nwildcards;
else
return 0;
}
/**
* psl_builtin_compile_time:
*

View File

@ -262,6 +262,7 @@ int main(int argc, const char **argv)
fprintf(fpout, "static time_t _psl_compile_time = %lu;\n", time(NULL));
fprintf(fpout, "static int _psl_nsuffixes = %d;\n", psl->nsuffixes);
fprintf(fpout, "static int _psl_nexceptions = %d;\n", psl->nexceptions);
fprintf(fpout, "static int _psl_nwildcards = %d;\n", psl->nwildcards);
fprintf(fpout, "static const char _psl_sha1_checksum[] = \"%s\";\n", checksum);
fprintf(fpout, "static const char _psl_filename[] = \"%s\";\n", argv[1]);
@ -280,6 +281,7 @@ int main(int argc, const char **argv)
fprintf(fpout, "static time_t _psl_compile_time;\n");
fprintf(fpout, "static int _psl_nsuffixes = 0;\n");
fprintf(fpout, "static int _psl_nexceptions = 0;\n");
fprintf(fpout, "static int _psl_nwildcards = 0;\n");
fprintf(fpout, "static const char _psl_sha1_checksum[] = \"\";\n");
fprintf(fpout, "static const char _psl_filename[] = \"\";\n");

View File

@ -200,6 +200,7 @@ int main(int argc, const char *const *argv)
if (psl && psl != psl_builtin()) {
printf("suffixes: %d\n", psl_suffix_count(psl));
printf("exceptions: %d\n", psl_suffix_exception_count(psl));
printf("wildcards: %d\n", psl_suffix_wildcard_count(psl));
}
psl_free(psl);
@ -208,6 +209,7 @@ int main(int argc, const char *const *argv)
if (psl) {
printf("builtin suffixes: %d\n", psl_suffix_count(psl));
printf("builtin exceptions: %d\n", psl_suffix_exception_count(psl));
printf("builtin wildcards: %d\n", psl_suffix_wildcard_count(psl));
printf("builtin filename: %s\n", psl_builtin_filename());
printf("builtin compile time: %ld (%s)\n", psl_builtin_compile_time(), time2str(psl_builtin_compile_time()));
printf("builtin file time: %ld (%s)\n", psl_builtin_file_time(), time2str(psl_builtin_file_time()));