BRL-CAD
pathlist.c
Go to the documentation of this file.
1 /* P A T H L I S T . 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/pathlist.c
21  *
22  * The pathlist 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 static int pathListNoLeaf = 0;
36 
37 
38 static union tree *
39 pathlist_leaf_func(struct db_tree_state *UNUSED(tsp), const struct db_full_path *pathp, struct rt_db_internal *ip, void *client_data)
40 {
41  struct ged *gedp = (struct ged *)client_data;
42  char *str;
43 
44  RT_CK_FULL_PATH(pathp);
46 
47  if (pathListNoLeaf) {
48  struct db_full_path pp;
49  db_full_path_init(&pp);
50  db_dup_full_path(&pp, pathp);
51  --pp.fp_len;
52  str = db_path_to_string(&pp);
53  bu_vls_printf(gedp->ged_result_str, " %s", str);
54  db_free_full_path(&pp);
55  } else {
56  str = db_path_to_string(pathp);
57  bu_vls_printf(gedp->ged_result_str, " %s", str);
58  }
59 
60  bu_free((void *)str, "path string");
61  return TREE_NULL;
62 }
63 
64 
65 int
66 ged_pathlist(struct ged *gedp, int argc, const char *argv[])
67 {
68  static const char *usage = "name";
69 
71  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
72 
73  /* initialize result */
74  bu_vls_trunc(gedp->ged_result_str, 0);
75 
76  /* must be wanting help */
77  if (argc == 1) {
78  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
79  return GED_HELP;
80  }
81 
82  if (3 < argc) {
83  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
84  return GED_ERROR;
85  }
86 
87  pathListNoLeaf = 0;
88 
89  if (argc == 3) {
90  if (BU_STR_EQUAL(argv[1], "-noleaf"))
91  pathListNoLeaf = 1;
92 
93  ++argv;
94  --argc;
95  }
96 
97  if (db_walk_tree(gedp->ged_wdbp->dbip, argc-1, (const char **)argv+1, 1,
99  0, 0, pathlist_leaf_func, (void *)gedp) < 0) {
100  bu_vls_printf(gedp->ged_result_str, "ged_pathlist: db_walk_tree() error");
101  return GED_ERROR;
102  }
103 
104  return GED_OK;
105 }
106 
107 
108 /*
109  * Local Variables:
110  * tab-width: 8
111  * mode: C
112  * indent-tabs-mode: t
113  * c-file-style: "stroustrup"
114  * End:
115  * ex: shiftwidth=4 tabstop=8
116  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
void db_dup_full_path(struct db_full_path *newp, const struct db_full_path *oldp)
Definition: db_fullpath.c:87
Definition: ged.h:338
struct db_i * dbip
Definition: raytrace.h:1266
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
struct rt_wdb * ged_wdbp
Definition: ged.h:340
Header file for the BRL-CAD common definitions.
void db_full_path_init(struct db_full_path *pathp)
Definition: db_fullpath.c:40
#define GED_ERROR
Definition: ged.h:61
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
#define RT_CK_DB_INTERNAL(_p)
Definition: raytrace.h:207
#define TREE_NULL
Definition: raytrace.h:1181
void db_free_full_path(struct db_full_path *pp)
Definition: db_fullpath.c:473
int ged_pathlist(struct ged *gedp, int argc, const char *argv[])
Definition: pathlist.c:66
#define UNUSED(parameter)
Definition: common.h:239
char * db_path_to_string(const struct db_full_path *pp)
Definition: db_fullpath.c:191
struct bu_vls * ged_result_str
Definition: ged.h:357
#define RT_CK_FULL_PATH(_p)
Definition: db_fullpath.h:59
struct db_tree_state wdb_initial_tree_state
Definition: raytrace.h:1267
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
#define GED_HELP
Definition: ged.h:62
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
int db_walk_tree(struct db_i *dbip, int argc, const char **argv, int ncpu, const struct db_tree_state *init_state, int(*reg_start_func)(struct db_tree_state *, const struct db_full_path *, const struct rt_comb_internal *, void *client_data), union tree *(*reg_end_func)(struct db_tree_state *, const struct db_full_path *, union tree *, void *client_data), union tree *(*leaf_func)(struct db_tree_state *, const struct db_full_path *, struct rt_db_internal *, void *client_data), void *client_data)
#define BU_STR_EQUAL(s1, s2)
Definition: str.h:126