BRL-CAD
get.c
Go to the documentation of this file.
1 /* G E 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/get.c
21  *
22  * The get 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.h"
33 
34 
35 int
36 ged_get(struct ged *gedp, int argc, const char *argv[])
37 {
38  int status;
39  struct rt_db_internal intern;
40  static const char *usage = "object ?attr?";
41 
43  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
44 
45  /* initialize result */
46  bu_vls_trunc(gedp->ged_result_str, 0);
47 
48  /* must be wanting help */
49  if (argc == 1) {
50  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
51  return GED_HELP;
52  }
53 
54  if (argc > 3) {
55  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
56  return GED_ERROR;
57  }
58 
59  /* Verify that this wdb supports lookup operations
60  (non-null dbip) */
61  if (gedp->ged_wdbp->dbip == 0) {
62  bu_vls_printf(gedp->ged_result_str, "dbip does not support lookup operations");
63  return GED_ERROR;
64  }
65 
66  if (wdb_import_from_path(gedp->ged_result_str, &intern, argv[1], gedp->ged_wdbp) == GED_ERROR)
67  return GED_ERROR;
68 
69  if (!intern.idb_meth->ft_get) {
70  return GED_ERROR;
71  }
72 
73  status = intern.idb_meth->ft_get(gedp->ged_result_str, &intern, argv[2]);
74  rt_db_free_internal(&intern);
75 
76  return status;
77 }
78 
79 
80 /*
81  * Local Variables:
82  * tab-width: 8
83  * mode: C
84  * indent-tabs-mode: t
85  * c-file-style: "stroustrup"
86  * End:
87  * ex: shiftwidth=4 tabstop=8
88  */
void usage(struct ged *gedp)
Definition: coil.c:315
Definition: ged.h:338
struct db_i * dbip
Definition: raytrace.h:1266
int wdb_import_from_path(struct bu_vls *logstr, struct rt_db_internal *ip, const char *path, struct rt_wdb *wdb)
Definition: wdb.c:431
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.
#define GED_ERROR
Definition: ged.h:61
int ged_get(struct ged *gedp, int argc, const char *argv[])
Definition: get.c:36
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
const struct rt_functab * idb_meth
for ft_ifree(), etc.
Definition: raytrace.h:194
struct bu_vls * ged_result_str
Definition: ged.h:357
int(* ft_get)(struct bu_vls *, const struct rt_db_internal *, const char *item)
Definition: raytrace.h:2180
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 rt_db_free_internal(struct rt_db_internal *ip)
Definition: dir.c:216