README
1Libfind allows to be used for adding find(1) like command line features
2to other programs (e.g. star and mkisofs). It also allows to implement
3a find(1) command in 10 lines of code and it allows to be used as shell
4built in function.
5
6Example code for a complete find(1) program:
7/*--------------------------------------------------------------------------*/
8/* %Z%%M% %I% %E% Copyright 2004-2007 J. Schilling */
9#ifndef lint
10static char sccsid[] =
11 "%Z%%M% %I% %E% Copyright 2004-2007 J. Schilling";
12#endif
13/*
14 * Another find implementation...
15 *
16 * Copyright (c) 2004-2007 J. Schilling
17 */
18/*
19 * The contents of this file are subject to the terms of the
20 * Common Development and Distribution License, Version 1.0 only
21 * (the "License"). You may not use this file except in compliance
22 * with the License.
23 *
24 * See the file CDDL.Schily.txt in this distribution for details.
25 *
26 * When distributing Covered Code, include this CDDL HEADER in each
27 * file and include the License file CDDL.Schily.txt from this distribution.
28 */
29
30#include <schily/mconfig.h>
31#include <schily/unistd.h>
32#include <schily/standard.h>
33#include <schily/schily.h>
34
35#include "walk.h"
36#include "find.h"
37
38EXPORT int main __PR((int ac, char **av));
39
40EXPORT int
41main(ac, av)
42 int ac;
43 char **av;
44{
45 FILE *std[3];
46
47 std[0] = stdin;
48 std[1] = stdout;
49 std[2] = stderr;
50 return (find_main(ac, av, NULL, std, NULL));
51}
52/*--------------------------------------------------------------------------*/
53
54Example code for redirecting I/O and for catching/handling signals in "bsh":
55/*--------------------------------------------------------------------------*/
56#include "../libfind/walk.h"
57#include "../libfind/find.h"
58
59LOCAL int
60quitfun(void *arg)
61{
62 return (*((int *)arg) != 0); /* Return TRUE is a signal was catched */
63}
64
65/* ARGSUSED */
66EXPORT void
67bfind(vp, std, flag)
68 vector *vp;
69 FILE *std[];
70 int flag;
71{
72 squit_t quit;
73
74 quit.quitfun = quitfun; /* The function to evaluate "ctlc" */
75 quit.qfarg = &ctlc; /* The ^C catched counter */
76
77 ex_status = find_main(vp->v_ac, vp->v_av, evarray, std, &quit);
78}
79/*--------------------------------------------------------------------------*/
80
81Example code for how to redirect I/O in ksh93 and how to catch signals:
82NOTE: as th ksh93 does not use stdio but sfio, you need two wrapper
83functions in order to run a standard program inside ksh93.
84/*--------------------------------------------------------------------------*/
85a.c: (compiled against sfio)
86
87int
88quitfun(void *dummy)
89{
90 return (cmdquit() != 0);
91}
92
93int
94b_find(int ac, char **av, void* context))
95{
96 int i, o, e;
97
98 cmdinit(ac, av, context, ERROR_CATALOG, ERROR_NOTIFY);
99
100 i = fileno(stdin);
101 o = fileno(stdout);
102 e = fileno(stderr);
103
104 return xfind(ac, av, dup(i), dup(o), dup(e), quitfun);
105}
106
107------
108b.c: (compiled against stdio)
109
110int
111xfind(int ac, char **av, int i, int o, int e, int (*quitfun)(void *))
112{
113 int ret;
114 FILE *std[3];
115 squit_t quit;
116
117 quit.quitfun = quitfun; /* The function to evaluate "ctlc" */
118 quit.qfarg = NULL; /* Dummy */
119
120 std[0] = fdopen(i, "r+");
121 std[1] = fdopen(o, "w");
122 std[2] = fdopen(e, "w+");
123 ret = find_main(ac, av, NULL, std, &quit);
124 fclose(std[0]);
125 fclose(std[1]);
126 fclose(std[2]);
127 return (ret);
128}
129/*--------------------------------------------------------------------------*/
130