table of contents
other versions
- wheezy 1.6.1-5
| ef_expand_file(3) | Library Functions Manual | ef_expand_file(3) |
NAME¶
ef_expand_file, del_ExpandFile, ef_last_error, ef_list_expansions, new_ExpandFile - expand filenames containing ~user/$envvar and wildcard expressionsSYNOPSIS¶
#include <libtecla.h>
ExpandFile *new_ExpandFile(void);
ExpandFile *del_ExpandFile(ExpandFile *ef);
FileExpansion *ef_expand_file(ExpandFile *ef,
const char *path,
int pathlen);
int ef_list_expansions(FileExpansion *result, FILE *fp,
int term_width);
const char *ef_last_error(ExpandFile *ef);
DESCRIPTION¶
The ef_expand_file() function is part of the tecla library (see the libtecla(3) man page). It expands a specified filename, converting ~user/ and ~/ expressions at the start of the filename to the corresponding home directories, replacing $envvar with the value of the corresponding environment variable, and then, if there are any wildcards, matching these against existing filenames. Backslashes in the input filename are interpreted as escaping any special meanings of the characters that follow them. Only backslahes that are themselves preceded by backslashes are preserved in the expanded filename. * - Match any sequence of zero or more characters.
? - Match any single character.
[chars] - Match any single character that appears in
'chars'. If 'chars' contains an expression of
the form a-b, then any character between a and
b, including a and b, matches. The '-'
character looses its special meaning as a
range specifier when it appears at the start
of the sequence of characters. The ']'
character also looses its significance as the
terminator of the range expression if it
appears immediately after the opening '[', at
which point it is treated one of the
characters of the range. If you want both '-'
and ']' to be part of the range, the '-'
should come first and the ']' second.
[^chars] - The same as [chars] except that it matches any
single character that doesn't appear in
'chars'.
#include <stdio.h>
#include <libtecla.h>
int main(int argc, char *argv[])
{
ExpandFile *ef; /* The expansion resource object */
char *filename; /* The filename being expanded */
FileExpansion *expn; /* The results of the expansion */
int i;
ef = new_ExpandFile();
if(!ef)
return 1;
for(arg = *(argv++); arg; arg = *(argv++)) {
if((expn = ef_expand_file(ef, arg, -1)) == NULL) {
fprintf(stderr, "Error expanding %s (%s).\n", arg,
ef_last_error(ef));
} else {
printf("%s matches the following files:\n", arg);
for(i=0; i<expn->nfile; i++)
printf(" %s\n", expn->files[i]);
}
}
ef = del_ExpandFile(ef);
return 0;
}
ExpandFile *new_ExpandFile(void)
ExpandFile *del_ExpandFile(ExpandFile *ef)
typedef struct {
int exists; /* True if the files in files[] exist */
int nfile; /* The number of files in files[] */
char **files; /* An array of 'nfile' filenames. */
} FileExpansion;
FileExpansion *ef_expand_file(ExpandFile *ef,
const char *path,
int pathlen)
const char *ef_last_error(ExpandFile *ef)
int ef_list_expansions(FileExpansion *result, FILE *fp,
int terminal_width);
THREAD SAFETY¶
In multi-threaded programs, you should use the libtecla_r.a version of the library. This uses POSIX reentrant functions where available (hence the _r suffix), and disables features that rely on non-reentrant system functions. Currently there are no features disabled in this module.FILES¶
libtecla.a - The tecla library libtecla.h - The tecla header file.
SEE ALSO¶
libtecla(3), gl_get_line(3), cpl_complete_word(3), pca_lookup_file(3)