BRL-CAD
match.c
Go to the documentation of this file.
1 /* M A T C H . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2008-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file libged/match.c
21  *
22  * The match command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <string.h>
29 
30 #include "bu/cmd.h"
31 
32 #include "./ged_private.h"
33 
34 
35 int
36 ged_match(struct ged *gedp, int argc, const char *argv[])
37 {
38  static const char *usage = "expression";
39 
41  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
42 
43  /* initialize result */
44  bu_vls_trunc(gedp->ged_result_str, 0);
45 
46  /* must be wanting help */
47  if (argc == 1) {
48  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
49  return GED_HELP;
50  }
51 
52  for (++argv; *argv != NULL; ++argv) {
53  register int i, num;
54  register struct directory *dp;
55  for (i = num = 0; i < RT_DBNHASH; i++) {
56  for (dp = gedp->ged_wdbp->dbip->dbi_Head[i]; dp != RT_DIR_NULL; dp = dp->d_forw) {
57  if (bu_fnmatch(*argv, dp->d_namep, 0) != 0)
58  continue;
59  if (num == 0)
61  else {
62  bu_vls_strcat(gedp->ged_result_str, " ");
64  }
65  ++num;
66  }
67  }
68 
69  if (num > 0)
70  bu_vls_strcat(gedp->ged_result_str, " ");
71  }
73 
74  return GED_OK;
75 }
76 
77 
78 /*
79  * Local Variables:
80  * tab-width: 8
81  * mode: C
82  * indent-tabs-mode: t
83  * c-file-style: "stroustrup"
84  * End:
85  * ex: shiftwidth=4 tabstop=8
86  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
char * d_namep
pointer to name string
Definition: raytrace.h:859
#define RT_DBNHASH
hash table is an array of linked lists with this many array pointer elements (Memory use for 32-bit: ...
Definition: raytrace.h:755
Definition: ged.h:338
struct db_i * dbip
Definition: raytrace.h:1266
void bu_vls_strcat(struct bu_vls *vp, const char *s)
Definition: vls.c:368
void bu_vls_trunc(struct bu_vls *vp, int len)
Definition: vls.c:198
#define GED_CHECK_ARGC_GT_0(_gedp, _argc, _flags)
Definition: ged.h:202
int ged_match(struct ged *gedp, int argc, const char *argv[])
Definition: match.c:36
struct rt_wdb * ged_wdbp
Definition: ged.h:340
Header file for the BRL-CAD common definitions.
struct directory * d_forw
link to next dir entry
Definition: raytrace.h:864
#define GED_ERROR
Definition: ged.h:61
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
int bu_fnmatch(const char *pattern, const char *pathname, int flags)
Definition: fnmatch.c:311
struct bu_vls * ged_result_str
Definition: ged.h:357
struct directory * dbi_Head[RT_DBNHASH]
Definition: raytrace.h:814
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
#define RT_DIR_NULL
Definition: raytrace.h:875
#define GED_HELP
Definition: ged.h:62
void bu_vls_trimspace(struct bu_vls *vp)
Definition: vls.c:678