BRL-CAD
debuglib.c
Go to the documentation of this file.
1 /* D E B U G L I B . 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/debuglib.c
21  *
22  * The debuglib command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <stdlib.h>
29 #include <ctype.h>
30 #include <string.h>
31 
32 #include "bu/debug.h"
33 #include "./ged_private.h"
34 
35 
36 int
37 ged_debuglib(struct ged *gedp, int argc, const char *argv[])
38 {
39  static const char *usage = "[hex_code]";
40 
42  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
43 
44  /* initialize result */
45  bu_vls_trunc(gedp->ged_result_str, 0);
46 
47  if (argc > 2) {
48  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
49  return GED_ERROR;
50  }
51 
52  /* get librt's debug bit vector */
53  if (argc == 1) {
54  bu_vls_printb(gedp->ged_result_str, "Possible flags", 0xffffffffL, DEBUG_FORMAT);
55  bu_vls_printf(gedp->ged_result_str, "\n");
56  } else {
57  /* set librt's debug bit vector */
58  if (sscanf(argv[1], "%x", (unsigned int *)&RTG.debug) != 1) {
59  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
60  return GED_ERROR;
61  }
62 
64  }
65 
66  bu_vls_printb(gedp->ged_result_str, "librt RT_G_DEBUG", RT_G_DEBUG, DEBUG_FORMAT);
67  bu_vls_printf(gedp->ged_result_str, "\n");
68 
69  return GED_OK;
70 }
71 
72 
73 /*
74  * Local Variables:
75  * tab-width: 8
76  * mode: C
77  * indent-tabs-mode: t
78  * c-file-style: "stroustrup"
79  * End:
80  * ex: shiftwidth=4 tabstop=8
81  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
Definition: ged.h:338
#define DEBUG_FORMAT
Definition: raytrace.h:125
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
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
void bu_vls_printb(struct bu_vls *vls, const char *s, unsigned long v, const char *bits)
int ged_debuglib(struct ged *gedp, int argc, const char *argv[])
Definition: debuglib.c:37
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
#define RT_G_DEBUG
Definition: raytrace.h:1718
struct bu_vls * ged_result_str
Definition: ged.h:357
#define BU_DEBUG_COREDUMP
Definition: debug.h:53
int bu_debug
Definition: globals.c:87
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
uint32_t debug
!0 for debug, see librt/debug.h
Definition: raytrace.h:1695
struct rt_g RTG
Definition: globals.c:39