BRL-CAD
adjust.c
Go to the documentation of this file.
1 /* A D J U 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/adjust.c
21  *
22  * The adjust 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_adjust(struct ged *gedp, int argc, const char *argv[])
37 {
38  int status;
39  struct directory *dp;
40  char *name;
41  struct rt_db_internal intern;
42  static const char *usage = "object attr value ?attr value?";
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  /* must be wanting help */
52  if (argc == 1) {
53  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
54  return GED_HELP;
55  }
56 
57  if (argc < 4) {
58  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
59  return GED_ERROR;
60  }
61 
62  name = (char *)argv[1];
63 
64  GED_DB_LOOKUP(gedp, dp, name, LOOKUP_QUIET, GED_ERROR);
65 
66  GED_DB_GET_INTERNAL(gedp, &intern, dp, (matp_t)NULL, &rt_uniresource, GED_ERROR);
67  RT_CK_DB_INTERNAL(&intern);
68 
69  /* Find out what type of object we are dealing with and tweak it. */
70  RT_CK_FUNCTAB(intern.idb_meth);
71 
72  if (!intern.idb_meth->ft_adjust) {
73  bu_vls_printf(gedp->ged_result_str, "wdb_export(%s) adjust failure", name);
74  return GED_ERROR;
75  }
76 
77  status = intern.idb_meth->ft_adjust(gedp->ged_result_str, &intern, argc-2, argv+2);
78  if (status == GED_OK && wdb_put_internal(gedp->ged_wdbp, name, &intern, 1.0) < 0) {
79  bu_vls_printf(gedp->ged_result_str, "wdb_export(%s) failure", name);
80  rt_db_free_internal(&intern);
81  return GED_ERROR;
82  }
83 
84  return GED_OK;
85 }
86 
87 
88 /*
89  * Local Variables:
90  * tab-width: 8
91  * mode: C
92  * indent-tabs-mode: t
93  * c-file-style: "stroustrup"
94  * End:
95  * ex: shiftwidth=4 tabstop=8
96  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
#define RT_CK_FUNCTAB(_p)
Definition: raytrace.h:2242
Definition: ged.h:338
Definition: clone.c:90
#define GED_DB_LOOKUP(_gedp, _dp, _name, _noisy, _flags)
Definition: ged.h:223
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 wdb_put_internal(struct rt_wdb *wdbp, const char *name, struct rt_db_internal *ip, double local2mm)
Definition: wdb.c:218
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
#define RT_CK_DB_INTERNAL(_p)
Definition: raytrace.h:207
#define LOOKUP_QUIET
Definition: raytrace.h:893
const struct rt_functab * idb_meth
for ft_ifree(), etc.
Definition: raytrace.h:194
struct bu_vls * ged_result_str
Definition: ged.h:357
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
#define GED_DB_GET_INTERNAL(_gedp, _intern, _dp, _mat, _resource, _flags)
Definition: ged.h:233
int ged_adjust(struct ged *gedp, int argc, const char *argv[])
Definition: adjust.c:36
#define GED_CHECK_READ_ONLY(_gedp, _flags)
Definition: ged.h:181
int(* ft_adjust)(struct bu_vls *, struct rt_db_internal *, int, const char **)
Definition: raytrace.h:2183
void rt_db_free_internal(struct rt_db_internal *ip)
Definition: dir.c:216