YAZ  5.23.1
Data Structures | Functions
file_glob.c File Reference

File globbing (ala POSIX glob, but simpler) More...

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <yaz/wrbuf.h>
#include <yaz/tpath.h>
#include <yaz/log.h>
#include <yaz/dirent.h>
#include <yaz/nmem.h>
#include <yaz/file_glob.h>
#include <yaz/match_glob.h>

Go to the source code of this file.

Data Structures

struct  res_entry
 
struct  glob_res
 

Functions

static void add_entry (yaz_glob_res_t res, const char *str)
 
static void glob_r (yaz_glob_res_t res, const char *pattern, size_t off, char *prefix)
 
static int cmp_entry (const void *a, const void *b)
 
static void sort_them (yaz_glob_res_t res)
 
int yaz_file_glob (const char *pattern, yaz_glob_res_t *res)
 perform glob More...
 
int yaz_file_glob2 (const char *pattern, yaz_glob_res_t *res, unsigned flags)
 perform glob (with flags) More...
 
void yaz_file_globfree (yaz_glob_res_t *res)
 release glob result More...
 
const char * yaz_file_glob_get_file (yaz_glob_res_t res, size_t idx)
 return resulting matching file More...
 
size_t yaz_file_glob_get_num (yaz_glob_res_t res)
 return number of matching files More...
 

Detailed Description

File globbing (ala POSIX glob, but simpler)

Definition in file file_glob.c.

Function Documentation

static void add_entry ( yaz_glob_res_t  res,
const char *  str 
)
static
static int cmp_entry ( const void *  a,
const void *  b 
)
static

Definition at line 113 of file file_glob.c.

References res_entry::file.

Referenced by sort_them().

static void glob_r ( yaz_glob_res_t  res,
const char *  pattern,
size_t  off,
char *  prefix 
)
static

Definition at line 51 of file file_glob.c.

References add_entry(), glob_res::flags, YAZ_FILE_GLOB_FAIL_NOTEXIST, and yaz_match_glob().

Referenced by yaz_file_glob2().

static void sort_them ( yaz_glob_res_t  res)
static
int yaz_file_glob ( const char *  pattern,
yaz_glob_res_t res 
)

perform glob

Parameters
patternglob pattern file spec
resreturned glob result
Return values
0OK
-1ERROR

Definition at line 141 of file file_glob.c.

References yaz_file_glob2().

int yaz_file_glob2 ( const char *  pattern,
yaz_glob_res_t res,
unsigned  flags 
)

perform glob (with flags)

Parameters
patternglob pattern file spec
resreturned glob result
flagsYAZ_FILE_GLOB_.. flags
Return values
0OK
-1ERROR

Definition at line 146 of file file_glob.c.

References glob_r(), nmem_create(), nmem_malloc(), and sort_them().

Referenced by config_include_src(), and yaz_file_glob().

const char* yaz_file_glob_get_file ( yaz_glob_res_t  res,
size_t  idx 
)

return resulting matching file

Parameters
resglob result
idxindex 0=first, .. N-1 (where N is yaz_file_glob_get_num)
Returns
file name or NULL if idx is out-of-range

Definition at line 173 of file file_glob.c.

References glob_res::entries, res_entry::file, and res_entry::next.

Referenced by config_include_src().

size_t yaz_file_glob_get_num ( yaz_glob_res_t  res)

return number of matching files

Parameters
resglob result
Returns
number of files

Definition at line 186 of file file_glob.c.

References glob_res::number_of_entries.

void yaz_file_globfree ( yaz_glob_res_t res)

release glob result

Parameters
respointer to glob result

A value of *res == NULL is allowed. If *res != NULL, then res is set to NULL

Definition at line 163 of file file_glob.c.

References nmem_destroy().

Referenced by config_include_src().