components/libtecla/files/pca_lookup_file.3tecla
author Mike Sullivan <Mike.Sullivan@Oracle.COM>
Wed, 29 Aug 2012 11:05:56 -0700
changeset 957 255465c5756f
parent 681 7c568e880861
child 5810 76203f2cf39d
permissions -rw-r--r--
Close of build 04.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
681
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     1
'\" te
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     2
.\" Copyright (c) 2000, 2001, 2002, 2003, 2004 by Martin C. Shepherd. All Rights Reserved.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     3
.\" Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, provided that the above copyright notice(s) and this permission notice appear in all copies of the Software and that both the above copyright notice(s) and this permission notice appear in supporting documentation.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.  Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization of the copyright holder.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     4
.\" Portions Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     5
.TH pca_lookup_file 3TECLA "13 Aug 2007" "SunOS 5.11" "Interactive Command-line Input Library Functions"
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     6
.SH NAME
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     7
pca_lookup_file, del_PathCache, del_PcaPathConf, new_PathCache, new_PcaPathConf, pca_last_error, pca_path_completions, pca_scan_path, pca_set_check_fn, ppc_file_start, ppc_literal_escapes \- lookup a file in a list of directories
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     8
.SH SYNOPSIS
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
     9
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    10
.nf
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    11
cc [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-ltecla\fR [ \fIlibrary\fR\&.\|.\|. ] 
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    12
#include <libtecla.h>
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    13
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    14
\fBchar *\fR\fBpca_lookup_file\fR(\fBPathCache *\fR\fIpc\fR, \fBconst char *\fR\fIname\fR,
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    15
     \fBint\fR \fIname_len\fR, \fBint\fR \fIliteral\fR);
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    16
.fi
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    17
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    18
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    19
.nf
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    20
\fBPathCache *\fR\fBdel_PathCache\fR(\fBPathCache *\fR\fIpc\fR);
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    21
.fi
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    22
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    23
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    24
.nf
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    25
\fBPcaPathConf *\fR\fBdel_PcaPathConf\fR(\fBPcaPathConf *\fR\fIppc\fR);
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    26
.fi
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    27
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    28
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    29
.nf
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    30
\fBPathCache *\fR\fBnew_PathCache\fR(\fBvoid\fR);
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    31
.fi
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    32
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    33
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    34
.nf
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    35
\fBPcaPathConf *\fR\fBnew_PcaPathConf\fR(\fBPathCache *\fR\fIpc\fR);
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    36
.fi
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    37
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    38
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    39
.nf
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    40
\fBconst char *\fR\fBpca_last_error\fR(\fBPathCache *\fR\fIpc\fR);
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    41
.fi
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    42
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    43
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    44
.nf
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    45
\fBCPL_MATCH_FN\fR(\fBpca_path_completions\fR);
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    46
.fi
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    47
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    48
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    49
.nf
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    50
\fBint\fR \fBpca_scan_path\fR(\fBPathCache *\fR\fIpc\fR, \fBconst char *\fR\fIpath\fR);
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    51
.fi
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    52
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    53
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    54
.nf
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    55
\fBvoid\fR \fBpca_set_check_fn\fR(\fBPathCache *\fR\fIpc\fR, \fBCplCheckFn *\fR\fIcheck_fn\fR,
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    56
     \fBvoid *\fR\fIdata\fR);
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    57
.fi
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    58
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    59
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    60
.nf
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    61
\fBvoid\fR \fBppc_file_start\fR(\fBPcaPathConf *\fR\fIppc\fR, \fBint\fR \fIstart_index\fR);
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    62
.fi
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    63
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    64
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    65
.nf
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    66
\fBvoid\fR \fBppc_literal_escapes\fR(\fBPcaPathConf *\fR\fIppc\fR, \fBint\fR \fIliteral\fR);
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    67
.fi
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    68
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    69
.SH DESCRIPTION
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    70
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    71
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    72
The \fBPathCache\fR object is part of the \fBlibtecla\fR(3LIB) library. \fBPathCache\fR objects allow an application to search for files in any colon separated list of directories, such as the UNIX execution \fBPATH\fR environment variable. Files in absolute directories are cached in a \fBPathCache\fR object, whereas relative directories are scanned as needed. Using a \fBPathCache\fR object, you can look up the full pathname of a simple filename, or you can obtain a list of the possible completions of a given filename prefix. By default all files in the list of directories are targets for lookup and completion, but a versatile mechanism is provided for only selecting specific types of files. The obvious application of this facility is to provide Tab-completion and lookup of executable commands in the UNIX \fBPATH\fR, so an optional callback which rejects all but executable files, is provided.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    73
.SS "An Example"
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    74
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    75
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    76
Under UNIX, the following example program looks up and displays the full pathnames of each of the command names on the command line.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    77
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    78
.in +2
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    79
.nf
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    80
#include <stdio.h>
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    81
#include <stdlib.h>
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    82
#include <libtecla.h>
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    83
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    84
int main(int argc, char *argv[])
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    85
{
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    86
        int i;
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    87
        /*
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    88
        * Create a cache for executable files.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    89
        */
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    90
        PathCache *pc = new_PathCache();
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    91
        if(!pc)
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    92
          exit(1);
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    93
        /*
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    94
        * Scan the user's PATH for executables.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    95
        */
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    96
        if(pca_scan_path(pc, getenv("PATH"))) {
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    97
          fprintf(stderr, "%s\en", pca_last_error(pc));
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    98
          exit(1);
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
    99
        }
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   100
        /*
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   101
        * Arrange to only report executable files.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   102
        */
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   103
        pca_set_check_fn(pc, cpl_check_exe, NULL);
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   104
        /*
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   105
        * Lookup and display the full pathname of each of the
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   106
        * commands listed on the command line.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   107
        */
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   108
        for(i=1; i<argc; i++) {
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   109
          char *cmd = pca_lookup_file(pc, argv[i], -1, 0);
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   110
          printf("The full pathname of '%s' is %s\e\en", argv[i],
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   111
                 cmd ? cmd : "unknown");
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   112
        }
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   113
        pc = del_PathCache(pc);  /* Clean up */
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   114
        return 0;
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   115
}
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   116
.fi
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   117
.in -2
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   118
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   119
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   120
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   121
The following is an example of what this does on a laptop under LINUX:
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   122
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   123
.in +2
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   124
.nf
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   125
$ ./example less more blob
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   126
The full pathname of 'less' is /usr/bin/less
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   127
The full pathname of 'more' is /bin/more
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   128
The full pathname of 'blob' is unknown
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   129
$
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   130
.fi
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   131
.in -2
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   132
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   133
.SS "Function Descriptions"
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   134
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   135
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   136
To use the facilities of this module, you must first allocate a \fBPathCache\fR object by calling the \fBnew_PathCache()\fR constructor function. This function creates the resources needed to cache and lookup files in a list of directories. It returns \fINULL\fR on error.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   137
.SS "Populating The Cache"
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   138
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   139
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   140
Once you have created a cache, it needs to be populated with files. To do this, call the \fBpca_scan_path()\fR function. Whenever this function is called, it discards the current contents of the cache, then scans the list of directories specified in its path argument for files. The path argument must be a string containing a colon-separated list of directories, such as "\fB/usr/bin\fR:\fB/home/mcs/bin\fR:". This can include directories specified by absolute pathnames such as "\fB/usr/bin\fR", as well as sub-directories specified by relative pathnames such as "." or "\fBbin\fR". Files in the absolute directories are immediately cached in the specified \fBPathCache\fR object, whereas subdirectories, whose identities obviously change whenever the current working directory is changed, are marked to be scanned on the fly whenever a file is looked up.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   141
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   142
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   143
On success this function return 0. On error it returns 1, and a description of the error can be obtained by calling \fBpca_last_error\fR(\fIpc\fR).
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   144
.SS "Looking Up Files"
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   145
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   146
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   147
Once the cache has been populated with files, you can look up the full pathname of a file, simply by specifying its filename to \fBpca_lookup_file()\fR.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   148
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   149
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   150
To make it possible to pass this function a filename which is actually part of a longer string, the \fIname_len\fR argument can be used to specify the length of the filename at the start of the \fIname\fR[] argument. If you pass -1 for this length, the length of the string will be determined with \fIstrlen\fR. If the \fIname\fR[] string might contain backslashes that escape the special meanings of spaces and tabs within the filename, give the \fIliteral\fR argument the value 0. Otherwise, if backslashes should be treated as normal characters, pass 1 for the value of the \fIliteral\fR argument.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   151
.SS "Filename Completion"
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   152
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   153
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   154
Looking up the potential completions of a filename-prefix in the filename cache is achieved by passing the provided \fBpca_path_completions()\fR callback function to the \fBcpl_complete_word\fR(3TECLA) function.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   155
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   156
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   157
This callback requires that its data argument be a pointer to a PcaPathConf object. Configuration objects of this type are allocated by calling \fBnew_PcaPathConf()\fR.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   158
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   159
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   160
This function returns an object initialized with default configuration parameters, which determine how the \fBcpl_path_completions()\fR callback function behaves. The functions which allow you to individually change these parameters are discussed below.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   161
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   162
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   163
By default, the \fBpca_path_completions()\fR callback function searches backwards for the start of the filename being completed, looking for the first un-escaped space or the start of the input line. If you wish to specify a different location, call \fBppc_file_start()\fR with the index at which the filename starts in the input line. Passing \fIstart_index\fR=-1 re-enables the default behavior.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   164
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   165
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   166
By default, when \fBpca_path_completions()\fR looks at a filename in the input line, each lone backslash in the input line is interpreted as being a special character which removes any special significance of the character which follows it, such as a space which should be taken as part of the filename rather than delimiting the start of the filename. These backslashes are thus ignored while looking for completions, and subsequently added before spaces, tabs and literal backslashes in the list of completions. To have unescaped backslashes treated as normal characters, call \fBppc_literal_escapes()\fR with a non-zero value in its literal argument.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   167
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   168
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   169
When you have finished with a \fBPcaPathConf\fR variable, you can pass it to the \fBdel_PcaPathConf()\fR destructor function to reclaim its memory.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   170
.SS "Being Selective"
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   171
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   172
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   173
If you are only interested in certain types or files, such as, for example, executable files, or files whose names end in a particular suffix, you can arrange for the file completion and lookup functions to be selective in the filenames that they return. This is done by registering a callback function with your \fBPathCache\fR object. Thereafter, whenever a filename is found which either matches a filename being looked up or matches a prefix which is being completed, your callback function will be called with the full pathname of the file, plus any application-specific data that you provide. If the callback returns 1 the filename will be reported as a match. If it returns 0, it will be ignored. Suitable callback functions and their prototypes should be declared with the following macro. The \fBCplCheckFn\fR typedef is also provided in case you wish to declare pointers to such functions
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   174
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   175
.in +2
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   176
.nf
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   177
#define CPL_CHECK_FN(fn) int (fn)(void *data, const char *pathname)
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   178
typedef CPL_CHECK_FN(CplCheckFn);
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   179
.fi
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   180
.in -2
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   181
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   182
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   183
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   184
Registering one of these functions involves calling the \fBpca_set_check_fn()\fR function. In addition to the callback function passed with the \fIcheck_fn\fR argument, you can pass a pointer to anything with the \fIdata\fR argument. This pointer will be passed on to your callback function by its own \fIdata\fR argument whenever it is called, providing a way to pass application-specific data to your callback. Note that these callbacks are passed the full pathname of each matching file, so the decision about whether a file is of interest can be based on any property of the file, not just its filename. As an example, the provided \fBcpl_check_exe()\fR callback function looks at the executable permissions of the file and the permissions of its parent directories, and only returns 1 if the user has execute permission to the file. This callback function can thus be used to lookup or complete command names found in the directories listed in the user's \fBPATH\fR environment variable. The example program above provides a demonstration of this.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   185
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   186
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   187
Beware that if somebody tries to complete an empty string, your callback will get called once for every file in the cache, which could number in the thousands. If your callback does anything time consuming, this could result in an unacceptable delay for the user, so callbacks should be kept short.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   188
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   189
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   190
To improve performance, whenever one of these callbacks is called, the choice that it makes is cached, and the next time the corresponding file is looked up, instead of calling the callback again, the cached record of whether it was accepted or rejected is used. Thus if somebody tries to complete an empty string, and hits tab a second time when nothing appears to happen, there will only be one long delay, since the second pass will operate entirely from the cached dispositions of the files. These cached dipositions are discarded whenever \fBpca_scan_path()\fR is called, and whenever \fBpca_set_check_fn()\fR is called with changed callback function or \fIdata\fR arguments.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   191
.SS "Error Handling"
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   192
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   193
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   194
If \fBpca_scan_path()\fR reports that an error occurred by returning 1, you can obtain a terse description of the error by calling \fBpca_last_error\fR(\fIpc\fR). This returns an internal string containing an error message.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   195
.SS "Cleaning Up"
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   196
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   197
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   198
Once you have finished using a \fBPathCache\fR object, you can reclaim its resources by passing it to the \fBdel_PathCache()\fR destructor function. This takes a pointer to one of these objects, and always returns \fINULL\fR.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   199
.SS "Thread Safety"
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   200
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   201
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   202
It is safe to use the facilities of this module in multiple threads, provided that each thread uses a separately allocated \fBPathCache\fR object. In other words, if two threads want to do path searching, they should each call \fBnew_PathCache()\fR to allocate their own caches.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   203
.SH ATTRIBUTES
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   204
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   205
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   206
See \fBattributes\fR(5) for descriptions of the following attributes:
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   207
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   208
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   209
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   210
.TS
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   211
tab() box;
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   212
cw(2.75i) |cw(2.75i) 
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   213
lw(2.75i) |lw(2.75i) 
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   214
.
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   215
ATTRIBUTE TYPEATTRIBUTE VALUE
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   216
_
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   217
Interface StabilityCommitted
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   218
_
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   219
MT-LevelMT-Safe
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   220
.TE
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   221
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   222
.SH SEE ALSO
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   223
.sp
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   224
.LP
7c568e880861 7143177 move libtecla from ON to Userland (Userland portion)
John Beck <John.Beck@Oracle.COM>
parents:
diff changeset
   225
\fBcpl_complete_word\fR(3TECLA), \fBef_expand_file\fR(3TECLA), \fBgl_get_line\fR(3TECLA), \fBlibtecla\fR(3LIB), \fBattributes\fR(5)