BRL-CAD
wmater.c
Go to the documentation of this file.
1 /* W M A T E R . 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/wmater.c
21  *
22  * The wmater command.
23  *
24  */
25 
26 #include "ged.h"
27 
28 
29 int
30 ged_wmater(struct ged *gedp, int argc, const char *argv[])
31 {
32  int i;
33  int status = GED_OK;
34  FILE *fp;
35  struct directory *dp;
36  struct rt_db_internal intern;
37  struct rt_comb_internal *comb;
38 
39  static const char *usage = "filename comb1 [comb2 ...]";
40 
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  if ((fp = fopen(argv[1], "a")) == NULL) {
60  bu_vls_printf(gedp->ged_result_str, "%s: Failed to open file - %s", argv[0], argv[1]);
61  return GED_ERROR;
62  }
63 
64  for (i = 2; i < argc; ++i) {
65  if ((dp = db_lookup(gedp->ged_wdbp->dbip, argv[i], LOOKUP_NOISY)) == RT_DIR_NULL) {
66  bu_vls_printf(gedp->ged_result_str, "%s: Failed to find %s", argv[0], argv[i]);
67  status = GED_ERROR;
68  continue;
69  }
70  if ((dp->d_flags & RT_DIR_COMB) == 0) {
71  bu_vls_printf(gedp->ged_result_str, "%s: %s is not a combination", argv[0], dp->d_namep);
72  status = GED_ERROR;
73  continue;
74  }
75  if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, (fastf_t *)NULL, &rt_uniresource) < 0) {
76  bu_vls_printf(gedp->ged_result_str, "%s: Unable to read %s from database", argv[0], argv[i]);
77  status = GED_ERROR;
78  continue;
79  }
80  comb = (struct rt_comb_internal *)intern.idb_ptr;
81  RT_CK_COMB(comb);
82 
83  fprintf(fp, "\"%s\"\t\"%s\"\t%d\t%d\t%d\t%d\t%d\n", argv[i],
84  bu_vls_strlen(&comb->shader) > 0 ?
85  bu_vls_addr(&comb->shader) : "-",
86  comb->rgb[0], comb->rgb[1], comb->rgb[2],
87  comb->rgb_valid, comb->inherit);
88  rt_db_free_internal(&intern);
89  }
90 
91  (void)fclose(fp);
92  return status;
93 }
94 
95 
96 /*
97  * Local Variables:
98  * tab-width: 8
99  * mode: C
100  * indent-tabs-mode: t
101  * c-file-style: "stroustrup"
102  * End:
103  * ex: shiftwidth=4 tabstop=8
104  */
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
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
struct db_i * dbip
Definition: raytrace.h:1266
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 directory * db_lookup(const struct db_i *, const char *name, int noisy)
Definition: db_lookup.c:153
#define RT_CK_COMB(_p)
Definition: raytrace.h:955
struct rt_wdb * ged_wdbp
Definition: ged.h:340
unsigned char rgb[3]
Definition: raytrace.h:948
#define GED_ERROR
Definition: ged.h:61
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
struct bu_vls shader
Definition: raytrace.h:950
size_t bu_vls_strlen(const struct bu_vls *vp)
Definition: vls.c:189
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
#define RT_DIR_COMB
combination
Definition: raytrace.h:884
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
#define RT_DIR_NULL
Definition: raytrace.h:875
#define LOOKUP_NOISY
Definition: raytrace.h:892
#define GED_HELP
Definition: ged.h:62
int ged_wmater(struct ged *gedp, int argc, const char *argv[])
Definition: wmater.c:30
char rgb_valid
!0 ==> rgb[] has valid color
Definition: raytrace.h:947
#define GED_CHECK_READ_ONLY(_gedp, _flags)
Definition: ged.h:181
int d_flags
flags
Definition: raytrace.h:869
double fastf_t
Definition: defines.h:300
void rt_db_free_internal(struct rt_db_internal *ip)
Definition: dir.c:216