BRL-CAD
eac.c
Go to the documentation of this file.
1 /* E A C . 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/eac.c
21  *
22  * The eac command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <stdlib.h>
29 #include <ctype.h>
30 #include <string.h>
31 
32 #include "./ged_private.h"
33 
34 
35 int
36 ged_eac(struct ged *gedp, int argc, const char *argv[])
37 {
38  int j;
39  int item;
40  struct directory *dp;
41  struct bu_vls v = BU_VLS_INIT_ZERO;
42  int new_argc;
43  int lim;
44  static const char *usage = "air_code(s)";
45 
48  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
49 
50  /* initialize result */
51  bu_vls_trunc(gedp->ged_result_str, 0);
52 
53  /* must be wanting help */
54  if (argc == 1) {
55  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
56  return GED_HELP;
57  }
58 
59  bu_vls_strcat(&v, "draw");
60  lim = 1;
61 
62  for (j = 1; j < argc; j++) {
63  item = atoi(argv[j]);
64  if (item < 1)
65  continue;
66 
68  struct rt_db_internal intern;
69  struct rt_comb_internal *comb;
70 
71  if (!(dp->d_flags & RT_DIR_REGION))
72  continue;
73 
74  bu_vls_printf(gedp->ged_result_str, "%s: looking at %s\n", argv[0], dp->d_namep);
75 
76  if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, (fastf_t *)NULL, &rt_uniresource) < 0) {
77  bu_vls_printf(gedp->ged_result_str, "%s: Database read error, aborting\n", argv[0]);
78  return GED_ERROR;
79  }
80  comb = (struct rt_comb_internal *)intern.idb_ptr;
81  if (comb->region_id != 0
82  || comb->aircode != item)
83  {
84  intern.idb_meth->ft_ifree(&intern);
85  continue;
86  }
87  intern.idb_meth->ft_ifree(&intern);
88 
89  bu_vls_strcat(&v, " ");
90  bu_vls_strcat(&v, dp->d_namep);
91  lim++;
93  }
94 
95  if (lim > 1) {
96  int retval;
97  char **new_argv;
98 
99  new_argv = (char **)bu_calloc(lim+1, sizeof(char *), "ged_eac: new_argv");
100  new_argc = bu_argv_from_string(new_argv, lim, bu_vls_addr(&v));
101  retval = ged_draw(gedp, new_argc, (const char **)new_argv);
102  bu_free((void *)new_argv, "ged_eac: new_argv");
103  bu_vls_free(&v);
104  return retval;
105  }
106 
107  bu_vls_free(&v);
108  return GED_OK;
109 }
110 
111 
112 /*
113  * Local Variables:
114  * tab-width: 8
115  * mode: C
116  * indent-tabs-mode: t
117  * c-file-style: "stroustrup"
118  * End:
119  * ex: shiftwidth=4 tabstop=8
120  */
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 FOR_ALL_DIRECTORY_START(_dp, _dbip)
Definition: raytrace.h:895
int rt_db_get_internal(struct rt_db_internal *ip, const struct directory *dp, const struct db_i *dbip, const mat_t mat, struct resource *resp)
Definition: dir.c:76
Definition: ged.h:338
void(* ft_ifree)(struct rt_db_internal *)
Definition: raytrace.h:2159
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_draw(struct ged *gedp, int argc, const char *argv[])
Definition: draw.c:1212
int ged_eac(struct ged *gedp, int argc, const char *argv[])
Definition: eac.c:36
#define FOR_ALL_DIRECTORY_END
Definition: raytrace.h:899
struct rt_wdb * ged_wdbp
Definition: ged.h:340
Header file for the BRL-CAD common definitions.
#define RT_DIR_REGION
region
Definition: raytrace.h:885
#define GED_ERROR
Definition: ged.h:61
if(share_geom)
Definition: nmg_mod.c:3829
void bu_vls_free(struct bu_vls *vp)
Definition: vls.c:248
struct resource rt_uniresource
default. Defined in librt/globals.c
Definition: globals.c:41
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
void * bu_calloc(size_t nelem, size_t elsize, const char *str)
Definition: malloc.c:321
const struct rt_functab * idb_meth
for ft_ifree(), etc.
Definition: raytrace.h:194
#define GED_CHECK_DRAWABLE(_gedp, _flags)
Definition: ged.h:129
char * bu_vls_addr(const struct bu_vls *vp)
Definition: vls.c:111
struct bu_vls * ged_result_str
Definition: ged.h:357
void * idb_ptr
Definition: raytrace.h:195
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
size_t bu_argv_from_string(char *argv[], size_t lim, char *lp)
Definition: argv.c:32
#define BU_VLS_INIT_ZERO
Definition: vls.h:84
int d_flags
flags
Definition: raytrace.h:869
Definition: vls.h:56
double fastf_t
Definition: defines.h:300