From 159e76837a2582682d81943b3fa963d72141337f Mon Sep 17 00:00:00 2001 From: Wiimm Date: Sat, 27 Aug 2022 10:27:15 +0200 Subject: SZS v2.28a --- project/dclib/dclib-basics.h | 12 +++- project/dclib/dclib-debug.h | 6 +- project/dclib/dclib-file.c | 148 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 161 insertions(+), 5 deletions(-) (limited to 'project/dclib') diff --git a/project/dclib/dclib-basics.h b/project/dclib/dclib-basics.h index d15997c..9df963c 100644 --- a/project/dclib/dclib-basics.h +++ b/project/dclib/dclib-basics.h @@ -6085,9 +6085,13 @@ ccp * InsertStringFieldHelper ( StringField_t * sf, int idx ); // append at the end and do not sort void AppendStringField ( StringField_t * sf, ccp key, bool move_key ); -// append at the end if nor already exists, do not sort +// append at the end if not already exists, do not sort void AppendUniqueStringField ( StringField_t * sf, ccp key, bool move_key ); +// insert or append a path (path1+path2) with optional wildcards by SearchPaths() +uint InsertStringFieldExpand ( StringField_t * sf, ccp path1, ccp path2, bool allow_hidden ); +uint AppendStringFieldExpand ( StringField_t * sf, ccp path1, ccp path2, bool allow_hidden ); + // re-sort field using sf->func_cmp() void SortStringField ( StringField_t * sf ); @@ -6199,6 +6203,12 @@ bool RemoveParamField ( ParamField_t * pf, ccp key ); ParamFieldItem_t * AppendParamField ( ParamField_t * pf, ccp key, bool move_key, uint num, cvp data ); +// insert or append a path (path1+path2) with optional wildcards by SearchPaths() +uint InsertParamFieldExpand + ( ParamField_t * pf, ccp path1, ccp path2, bool allow_hidden, uint num, cvp data ); +uint AppendParamFieldExpand + ( ParamField_t * pf, ccp path1, ccp path2, bool allow_hidden, uint num, cvp data ); + // return the index of the (next) item uint FindParamFieldHelper ( const ParamField_t * pf, bool * found, ccp key ); diff --git a/project/dclib/dclib-debug.h b/project/dclib/dclib-debug.h index 1147646..639670d 100644 --- a/project/dclib/dclib-debug.h +++ b/project/dclib/dclib-debug.h @@ -484,9 +484,9 @@ void WAIT_ARG_FUNC ( ccp format, va_list arg ); // always disabled #define HAVE_PRINT0 0 -#define PRINT0 TRACE -#define PRINT_IF0 TRACE_IF -#define PRINT_SIZEOF0 TRACE_SIZEOF +#define PRINT0(...) +#define PRINT_IF0(...) +#define PRINT_SIZEOF0(...) #define BINGO0 TRACELINE // always enabled diff --git a/project/dclib/dclib-file.c b/project/dclib/dclib-file.c index 44bf5ec..94745e7 100644 --- a/project/dclib/dclib-file.c +++ b/project/dclib/dclib-file.c @@ -3725,7 +3725,7 @@ ccp GetBlockDeviceHolder ( ccp name, ccp sep, int *ret_level ) bool old_found; ParamFieldItem_t *item = FindInsertParamField(&db,name,false,0,&old_found); - DASSERT(item) + DASSERT(item); if (!old_found) { int level = 0; @@ -4055,6 +4055,152 @@ search_paths_stat_t SearchPaths return sp.status; } +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + +static enumError insert_string_field +( + mem_t path, // full path of existing file, never NULL + uint st_mode, // copy of struct stat.st_mode, see "man 2 stat" + void *param // user defined parameter +) +{ + StringField_t * sf = param; + DASSERT(sf); + InsertStringField(sf,path.ptr,false); + return ERR_OK; +} + +//----------------------------------------------------------------------------- + +uint InsertStringFieldExpand + ( StringField_t * sf, ccp path1, ccp path2, bool allow_hidden ) +{ + DASSERT(sf); + search_paths_stat_t stat = SearchPaths(path1,path2,allow_hidden,insert_string_field,sf); + PRINT0("%d %d %d\n",stat.dir_count,stat.func_count,stat.hit_count); + if (!stat.hit_count) + { + char srcbuf[PATH_MAX+2]; + ccp source = PathCatPP(srcbuf,sizeof(srcbuf),path1,path2); + InsertStringField(sf,source,false); + stat.hit_count++; + } + return stat.hit_count; +} + +/////////////////////////////////////////////////////////////////////////////// + +static enumError append_string_field +( + mem_t path, // full path of existing file, never NULL + uint st_mode, // copy of struct stat.st_mode, see "man 2 stat" + void *param // user defined parameter +) +{ + StringField_t * sf = param; + DASSERT(sf); + AppendStringField(sf,path.ptr,false); + return ERR_OK; +} + +//----------------------------------------------------------------------------- + +uint AppendStringFieldExpand + ( StringField_t * sf, ccp path1, ccp path2, bool allow_hidden ) +{ + DASSERT(sf); + search_paths_stat_t stat = SearchPaths(path1,path2,allow_hidden,append_string_field,sf); + PRINT0("%d %d %d\n",stat.dir_count,stat.func_count,stat.hit_count); + if (!stat.hit_count) + { + char srcbuf[PATH_MAX+2]; + ccp source = PathCatPP(srcbuf,sizeof(srcbuf),path1,path2); + AppendStringField(sf,source,false); + stat.hit_count++; + } + return stat.hit_count; +} + +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + +typedef struct search_param_field_t +{ + ParamField_t *pf; + uint num; + cvp data; +} +search_param_field_t; + +//----------------------------------------------------------------------------- + +static enumError insert_param_field +( + mem_t path, // full path of existing file, never NULL + uint st_mode, // copy of struct stat.st_mode, see "man 2 stat" + void *param // user defined parameter +) +{ + search_param_field_t *spf = param; + DASSERT(spf); + InsertParamField(spf->pf,path.ptr,false,spf->num,spf->data); + return ERR_OK; +} + +//----------------------------------------------------------------------------- + +uint InsertParamFieldExpand + ( ParamField_t * pf, ccp path1, ccp path2, bool allow_hidden, uint num, cvp data ) +{ + DASSERT(pf); + search_param_field_t spf = { .pf = pf, .num = num, .data = data }; + search_paths_stat_t stat = SearchPaths(path1,path2,allow_hidden,insert_param_field,&spf); + PRINT0("%d %d %d\n",stat.dir_count,stat.func_count,stat.hit_count); + if (!stat.hit_count) + { + char srcbuf[PATH_MAX+2]; + ccp source = PathCatPP(srcbuf,sizeof(srcbuf),path1,path2); + InsertParamField(pf,source,false,num,data); + stat.hit_count++; + } + return stat.hit_count; +} + +/////////////////////////////////////////////////////////////////////////////// + +static enumError append_param_field +( + mem_t path, // full path of existing file, never NULL + uint st_mode, // copy of struct stat.st_mode, see "man 2 stat" + void *param // user defined parameter +) +{ + search_param_field_t *spf = param; + DASSERT(spf); + AppendParamField(spf->pf,path.ptr,false,spf->num,spf->data); + return ERR_OK; +} + +//----------------------------------------------------------------------------- + +uint AppendParamFieldExpand + ( ParamField_t * pf, ccp path1, ccp path2, bool allow_hidden, uint num, cvp data ) +{ + DASSERT(pf); + search_param_field_t spf = { .pf = pf, .num = num, .data = data }; + search_paths_stat_t stat = SearchPaths(path1,path2,allow_hidden,append_param_field,&spf); + PRINT0("%d %d %d\n",stat.dir_count,stat.func_count,stat.hit_count); + if (!stat.hit_count) + { + char srcbuf[PATH_MAX+2]; + ccp source = PathCatPP(srcbuf,sizeof(srcbuf),path1,path2); + AppendParamField(pf,source,false,num,data); + stat.hit_count++; + } + return stat.hit_count; +} + // /////////////////////////////////////////////////////////////////////////////// /////////////// normalize filenames /////////////// -- cgit v1.3.1