| 1 |
.TH pxfile 3 local |
| 2 |
.SH NAME |
| 3 |
pxfile \- Extended file opening with search path and optional extensions. |
| 4 |
.SH SYNOPSIS |
| 5 |
.nf |
| 6 |
.B #include "pxfile.h" |
| 7 |
|
| 8 |
.B FILE* px_fopen(filename,mode,pattern,path,show) |
| 9 |
.B char * filename; |
| 10 |
.B char * mode; |
| 11 |
.B char ** pattern; |
| 12 |
.B char ** path; |
| 13 |
.B int (*show)(); |
| 14 |
|
| 15 |
.B char **px_s2p(specification,seperator) |
| 16 |
.B char *specification; |
| 17 |
.B int seperator; |
| 18 |
.fi |
| 19 |
.SH DESCRIPTION |
| 20 |
The extended file opening routine allows to open a file like |
| 21 |
.B fopen(3) |
| 22 |
. |
| 23 |
The file is searched on a path and additional modifications of the |
| 24 |
file name are possible. E.g. the addion of an extension or prepending |
| 25 |
a fixed prefix is posible. |
| 26 |
|
| 27 |
.BR px_fopen () |
| 28 |
opens a file named |
| 29 |
.I filename |
| 30 |
with the mode |
| 31 |
.I mode |
| 32 |
which is the same as the mode used by |
| 33 |
.BR fopen (3). |
| 34 |
.I path |
| 35 |
is a NULL terminated array of strings indicating the possible directories to |
| 36 |
search for the file. A value of |
| 37 |
.I NULL |
| 38 |
indicates that only the current directory should be examined. |
| 39 |
.BR px_s2p () |
| 40 |
can be used to allocate and fill a path array form a simple string |
| 41 |
specification. |
| 42 |
|
| 43 |
.I pattern |
| 44 |
is a NULL terminated array of format specifications to be used with |
| 45 |
.BR fprintf (3). |
| 46 |
Two strings are indicated with the special '%s'. The first '%s' is replaced by |
| 47 |
the directory name. The second '%s' is replaced by the file name given. |
| 48 |
A value of |
| 49 |
.I NULL |
| 50 |
is the same as |
| 51 |
|
| 52 |
.nf |
| 53 |
{ "%s/%s", |
| 54 |
NULL |
| 55 |
} |
| 56 |
.fi |
| 57 |
|
| 58 |
The following example value of |
| 59 |
.I pattern |
| 60 |
shows how default extensions can be tried. First the pure file name |
| 61 |
is tried. Afterwards the extensions |
| 62 |
.B .tex |
| 63 |
and |
| 64 |
.B .TeX |
| 65 |
are tried. |
| 66 |
|
| 67 |
.nf |
| 68 |
{ "%s/%s", |
| 69 |
"%s/%s.tex", |
| 70 |
"%s/%s.TeX", |
| 71 |
NULL |
| 72 |
} |
| 73 |
.fi |
| 74 |
|
| 75 |
.I show |
| 76 |
is a pointer to a function. This function is called before an attempt |
| 77 |
is made to open a file. The argument of the function is the complete |
| 78 |
file name as string. The open is tried only if |
| 79 |
.I show |
| 80 |
returns an integer different from 0. |
| 81 |
This function can be used to display the file names before trying to open. |
| 82 |
A value of |
| 83 |
.I NULL |
| 84 |
can be used to indicate that no such function should be used. |
| 85 |
|
| 86 |
.BR px_s2p () |
| 87 |
constructs a |
| 88 |
.I pattern |
| 89 |
for |
| 90 |
.BR px_fopen () |
| 91 |
from a |
| 92 |
.I specification. |
| 93 |
Memory is allocated to store the array and the strings contained. |
| 94 |
.I specification |
| 95 |
is a strings where the different directories are separated by the character |
| 96 |
.I seperator. |
| 97 |
If not enough memory is available |
| 98 |
.I NULL |
| 99 |
is returned. The memory allocated consists of one block which can be |
| 100 |
freed with |
| 101 |
.BR free (3). |
| 102 |
|
| 103 |
.SH FILES |
| 104 |
pxfile.h |
| 105 |
.SH SEE ALSO |
| 106 |
.BR fopen (3), |
| 107 |
.BR fprintf (3), |
| 108 |
.BR free (3) |
| 109 |
|
| 110 |
.SH DIAGNOSTICS |
| 111 |
NULL is returned to indicate failure. |
| 112 |
.SH BUGS |
| 113 |
Mainly UN*X type file names are supported. |
| 114 |
|