BRL-CAD
who.c
Go to the documentation of this file.
1 /* W H O . 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/who.c
21  *
22  * The who command.
23  *
24  */
25 
26 #include "ged.h"
27 
28 
29 
30 /*
31  * List the objects currently prepped for drawing
32  *
33  * Usage:
34  * who [r(eal)|p(hony)|b(oth)]
35  *
36  */
37 int
38 ged_who(struct ged *gedp, int argc, const char *argv[])
39 {
40  struct display_list *gdlp;
41  int skip_real, skip_phony;
42  static const char *usage = "[r(eal)|p(hony)|b(oth)]";
43 
46  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
47 
48  /* initialize result */
49  bu_vls_trunc(gedp->ged_result_str, 0);
50 
51  if (2 < argc) {
52  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
53  return GED_ERROR;
54  }
55 
56  skip_real = 0;
57  skip_phony = 1;
58  if (argc == 2) {
59  switch (argv[1][0]) {
60  case 'b':
61  skip_real = 0;
62  skip_phony = 0;
63  break;
64  case 'p':
65  skip_real = 1;
66  skip_phony = 0;
67  break;
68  case 'r':
69  skip_real = 0;
70  skip_phony = 1;
71  break;
72  default:
73  bu_vls_printf(gedp->ged_result_str, "ged_who: argument not understood\n");
74  return GED_ERROR;
75  }
76  }
77 
78  for (BU_LIST_FOR(gdlp, display_list, gedp->ged_gdp->gd_headDisplay)) {
79  if (((struct directory *)gdlp->dl_dp)->d_addr == RT_DIR_PHONY_ADDR) {
80  if (skip_phony) continue;
81  } else {
82  if (skip_real) continue;
83  }
84 
85  bu_vls_printf(gedp->ged_result_str, "%s ", bu_vls_addr(&gdlp->dl_path));
86  }
87 
88  return GED_OK;
89 }
90 
91 
92 /*
93  * Local Variables:
94  * tab-width: 8
95  * mode: C
96  * indent-tabs-mode: t
97  * c-file-style: "stroustrup"
98  * End:
99  * ex: shiftwidth=4 tabstop=8
100  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
#define BU_LIST_FOR(p, structure, hp)
Definition: list.h:365
Definition: ged.h:338
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
void * dl_dp
Definition: bview.h:47
struct bu_list * gd_headDisplay
head of display list
Definition: ged.h:307
#define GED_ERROR
Definition: ged.h:61
int ged_who(struct ged *gedp, int argc, const char *argv[])
Definition: who.c:38
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
#define RT_DIR_PHONY_ADDR
Special marker for d_addr field.
Definition: raytrace.h:879
#define GED_CHECK_DRAWABLE(_gedp, _flags)
Definition: ged.h:129
struct bu_vls dl_path
Definition: bview.h:48
char * bu_vls_addr(const struct bu_vls *vp)
Definition: vls.c:111
struct bu_vls * ged_result_str
Definition: ged.h:357
struct ged_drawable * ged_gdp
Definition: ged.h:360
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694