BRL-CAD
regdef.c
Go to the documentation of this file.
1 /* R E G D E F . 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/regdef.c
21  *
22  * The regdef command.
23  *
24  */
25 
26 #include "common.h"
27 #include <stdlib.h>
28 #include "ged.h"
29 
30 int
31 ged_regdef(struct ged *gedp, int argc, const char *argv[])
32 {
33  int item, air, los, mat;
34  static const char *usage = "item air los mat";
35 
38  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
39 
40  /* initialize result */
41  bu_vls_trunc(gedp->ged_result_str, 0);
42 
43  /* Get region defaults */
44  if (argc == 1) {
45  bu_vls_printf(gedp->ged_result_str, "ident %d air %d los %d material %d",
49  gedp->ged_wdbp->wdb_mat_default);
50  return GED_OK;
51  }
52 
53  if (argc < 2 || 5 < argc) {
54  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
55  return GED_ERROR;
56  }
57 
58  if (sscanf(argv[1], "%d", &item) != 1) {
59  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
60  return GED_ERROR;
61  }
62  gedp->ged_wdbp->wdb_item_default = item;
63 
64  if (argc == 2)
65  return GED_OK;
66 
67  if (sscanf(argv[2], "%d", &air) != 1) {
68  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
69  return GED_ERROR;
70  }
71  gedp->ged_wdbp->wdb_air_default = air;
72  if (air) {
73  item = 0;
74  gedp->ged_wdbp->wdb_item_default = 0;
75  }
76 
77  if (argc == 3)
78  return GED_OK;
79 
80  if (sscanf(argv[3], "%d", &los) != 1) {
81  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
82  return GED_ERROR;
83  }
84  gedp->ged_wdbp->wdb_los_default = los;
85 
86  if (argc == 4)
87  return GED_OK;
88 
89  if (sscanf(argv[4], "%d", &mat) != 1) {
90  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
91  return GED_ERROR;
92  }
93  gedp->ged_wdbp->wdb_mat_default = mat;
94 
95  return GED_OK;
96 }
97 
98 
99 /*
100  * Local Variables:
101  * tab-width: 8
102  * mode: C
103  * indent-tabs-mode: t
104  * c-file-style: "stroustrup"
105  * End:
106  * ex: shiftwidth=4 tabstop=8
107  */
int wdb_item_default
GIFT region ID.
Definition: raytrace.h:1278
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
int ged_regdef(struct ged *gedp, int argc, const char *argv[])
Definition: regdef.c:31
int wdb_mat_default
GIFT material code.
Definition: raytrace.h:1280
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
struct rt_wdb * ged_wdbp
Definition: ged.h:340
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
int wdb_los_default
Line-of-sight estimate.
Definition: raytrace.h:1281
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
int wdb_air_default
Definition: raytrace.h:1279
#define GED_CHECK_READ_ONLY(_gedp, _flags)
Definition: ged.h:181