Skip to content

Commit e9b40d2

Browse files
committed
Add a version reporting feature to gsh
1 parent 9995d8f commit e9b40d2

File tree

6 files changed

+132
-7
lines changed

6 files changed

+132
-7
lines changed

include/ged.h

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "raytrace.h"
5151
#include "analyze.h"
5252
#include "ged/defines.h"
53+
#include "ged/version.h"
5354
#include "ged/database.h"
5455
#include "ged/commands.h"
5556
#include "ged/objects.h"

include/ged/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set(
1111
framebuffer.h
1212
objects.h
1313
rt.h
14+
version.h
1415
view.h
1516
)
1617
brlcad_manage_files(ged_headers ${INCLUDE_DIR}/brlcad/ged REQUIRED libged)

include/ged/version.h

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* V E R S I O N . H
2+
* BRL-CAD
3+
*
4+
* Copyright (c) 2004-2025 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+
21+
/*----------------------------------------------------------------------*/
22+
/** @addtogroup ged_version
23+
* @brief
24+
* report version information about LIBGED
25+
*/
26+
/** @{ */
27+
/* @file version.h */
28+
29+
#ifndef GED_VERSION_H
30+
#define GED_VERSION_H
31+
32+
#include "common.h"
33+
#include "ged/defines.h"
34+
35+
__BEGIN_DECLS
36+
37+
GED_EXPORT extern const char *ged_version(void);
38+
39+
__END_DECLS
40+
41+
#endif /* GED_VERSION_H */
42+
/** @} */
43+
/*
44+
* Local Variables:
45+
* mode: C
46+
* tab-width: 8
47+
* indent-tabs-mode: t
48+
* c-file-style: "stroustrup"
49+
* End:
50+
* ex: shiftwidth=4 tabstop=8
51+
*/

src/gtools/gsh/gsh.cpp

+29-7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include "linenoise.hpp"
3737

38+
#include "brlcad_ident.h"
3839
#include "bu.h"
3940
#include "bv.h"
4041

@@ -752,11 +753,14 @@ main(int argc, const char **argv)
752753

753754
/* Options */
754755
int print_help = 0;
756+
int report_versions = 0;
755757
int new_cmd_forms = 0;
756-
struct bu_opt_desc d[3];
757-
BU_OPT(d[0], "h", "help", "", NULL, &print_help, "print help and exit");
758-
BU_OPT(d[1], "", "new-cmds", "", NULL, &new_cmd_forms, "use new (qged style) commands");
759-
BU_OPT_NULL(d[2]);
758+
struct bu_opt_desc d[5];
759+
BU_OPT(d[0], "h", "help", "", NULL, &print_help, "print help and exit");
760+
BU_OPT(d[1], "?", "", "", NULL, &print_help, "");
761+
BU_OPT(d[2], "v", "version", "", NULL, &report_versions, "Report BRL-CAD and library versions, then exit");
762+
BU_OPT(d[3], "", "new-cmds", "", NULL, &new_cmd_forms, "use new (qged style) commands");
763+
BU_OPT_NULL(d[4]);
760764

761765
/* Parse options, fail if anything goes wrong */
762766
struct bu_vls opt_msg = BU_VLS_INIT_ZERO;
@@ -771,9 +775,27 @@ main(int argc, const char **argv)
771775
if (print_help) {
772776
struct bu_vls msg = BU_VLS_INIT_ZERO;
773777
const char *help = bu_opt_describe(d, NULL);
774-
bu_vls_sprintf(&msg, "Usage: 'gsh [options] model.g'\n\nOptions:\n%s\n", help);
778+
bu_vls_sprintf(&msg, "Usage: 'gsh [options] model.g' [args] \n\nOptions:\n%s\n", help);
775779
bu_free((char *)help, "done with help string");
776-
fputs(bu_vls_addr(&msg), stderr);
780+
fputs(bu_vls_cstr(&msg), stderr);
781+
bu_vls_free(&msg);
782+
bu_exit(EXIT_SUCCESS, NULL);
783+
}
784+
785+
/* If we're just reporting BRL-CAD and lib versions, do that */
786+
if (report_versions) {
787+
struct bu_vls msg = BU_VLS_INIT_ZERO;
788+
bu_vls_sprintf(&msg, "%s%s%s%s%s",
789+
brlcad_ident("Geometry Shell (gsh)"),
790+
bu_version(),
791+
bn_version(),
792+
rt_version(),
793+
ged_version());
794+
#ifdef USE_DM
795+
bu_vls_printf(&msg, "%s", dm_version());
796+
#endif
797+
bu_vls_printf(&msg, "\n");
798+
std::cout << bu_vls_cstr(&msg);
777799
bu_vls_free(&msg);
778800
bu_exit(EXIT_SUCCESS, NULL);
779801
}
@@ -874,7 +896,7 @@ main(int argc, const char **argv)
874896
}
875897
}
876898

877-
return BRLCAD_OK;
899+
return EXIT_SUCCESS;
878900
}
879901

880902
// Local Variables:

src/libged/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ set(
143143
tab_complete.cpp
144144
trace.c
145145
track.c
146+
vers.c
146147
vutil.c
147148
view/data_lines.c
148149
wdb_importFg4Section.c

src/libged/vers.c

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* V E R S . C
2+
* BRL-CAD
3+
*
4+
* Copyright (c) 2007-2025 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/vers.c
21+
*
22+
* version information about LIBGED
23+
*
24+
*/
25+
26+
#include "common.h"
27+
28+
#include "ged/version.h"
29+
#include "brlcad_ident.h"
30+
31+
32+
/**
33+
* returns the compile-time version of libged
34+
*/
35+
const char *
36+
ged_version(void)
37+
{
38+
return brlcad_ident("The BRL-CAD Geometry Editing Library (libged)");
39+
}
40+
41+
/*
42+
* Local Variables:
43+
* tab-width: 8
44+
* mode: C
45+
* indent-tabs-mode: t
46+
* c-file-style: "stroustrup"
47+
* End:
48+
* ex: shiftwidth=4 tabstop=8
49+
*/

0 commit comments

Comments
 (0)