BRL-CAD
cmd.h
Go to the documentation of this file.
1/* C M D . H
2 * BRL-CAD
3 *
4 * Copyright (c) 1993-2023 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 rt/cmd.h
21 *
22 */
23
24#ifndef RT_CMD_H
25#define RT_CMD_H
26
27#include "common.h"
28
29/* system headers */
30#include <stdio.h> /* for FILE */
31
32/* interface headers */
33#include "vmath.h"
34#include "rt/defines.h"
35#include "rt/rt_instance.h"
36
37__BEGIN_DECLS
38
39/**
40 * Table for driving generic command-parsing routines
41 */
43 const char *ct_cmd;
44 const char *ct_parms;
45 const char *ct_comment;
46 int (*ct_func)(const int, const char **);
47 int ct_min; /**< @brief min number of words in cmd */
48 int ct_max; /**< @brief max number of words in cmd */
49};
50
51/* cmd.c */
52/* Read semi-colon terminated line */
53
54/*
55 * Read one semi-colon terminated string of arbitrary length from the
56 * given file into a dynamically allocated buffer. Various commenting
57 * and escaping conventions are implemented here.
58 *
59 * Returns:
60 * NULL on EOF
61 * char * on good read
62 */
63RT_EXPORT extern char *rt_read_cmd(FILE *fp);
64/* do cmd from string via cmd table */
65
66/*
67 * Slice up input buffer into whitespace separated "words", look up
68 * the first word as a command, and if it has the correct number of
69 * args, call that function. Negative min/max values in the tp
70 * command table effectively mean that they're not bounded.
71 *
72 * Expected to return -1 to halt command processing loop.
73 *
74 * Based heavily on mged/cmd.c by Chuck Kennedy.
75 *
76 * DEPRECATED: needs to migrate to libbu
77 */
78RT_EXPORT extern int rt_do_cmd(struct rt_i *rtip,
79 const char *ilp,
80 const struct command_tab *tp);
81
82
83
84
85/* TODO - libged's commands should be using the below functions in lieu of
86 * their own implementation, but even temporarily swapping gedp->ged_wdbp into
87 * dbip->dbi_wdbp before calling the librt versions (apparently a functional
88 * necessity) we're still seeing some sort of problem with Archer - the GUI is
89 * not properly interactive. Until that's resolved, we have duplicate logic in
90 * the librt implementation of these and the libged commands. Adding even
91 * though we've not resolved libged's use of these functions because they do
92 * allow the v5 ASCII import plugin in libgcv to succeed.
93 */
94
95/**
96 * @brief Convert an ASCII v5 "attr" command into a .g attribute
97 *
98 * Given an array of strings formatted as a BRL-CAD v5 ASCII "attr" command,
99 * translate the information in that command into an attribute setting for the
100 * dbip.
101 *
102 * The msg parameter is optional - if present, rt_cmd_attr will output
103 * diagnostic messages to the vls in the event of an error.
104 *
105 * Returns BRLCAD_OK on success, BRLCAD_ERROR on failure.
106 */
107RT_EXPORT extern int rt_cmd_attr(struct bu_vls *msg, struct db_i *dbip, int argc, const char **argv);
108
109/**
110 * @brief Convert an ASCII v5 "color" command into a .g coloribute
111 *
112 * Given an array of strings formatted as a BRL-CAD v5 ASCII "color" command,
113 * translate the information in that command into an coloribute setting for the
114 * dbip.
115 *
116 * The msg parameter is optional - if present, rt_cmd_color will output
117 * diagnostic messages to the vls in the event of an error.
118 *
119 * Returns BRLCAD_OK on success, BRLCAD_ERROR on failure.
120 */
121RT_EXPORT extern int rt_cmd_color(struct bu_vls *msg, struct db_i *dbip, int argc, const char **argv);
122
123/**
124 * @brief Convert an ASCII v5 "put" command into a .g object
125 *
126 * Given an array of strings formatted as a BRL-CAD v5 ASCII "put" command,
127 * translate the information in that command into an object in the dbip.
128 *
129 * The msg parameter is optional - if present, rt_cmd_put will output
130 * diagnostic messages to the vls in the event of an error.
131 *
132 * Returns BRLCAD_OK on success, BRLCAD_ERROR on failure.
133 */
134RT_EXPORT extern int rt_cmd_put(struct bu_vls *msg, struct rt_wdb *wdbp, int argc, const char **argv);
135
136/**
137 * @brief Convert an ASCII v5 "title" command into a .g title
138 *
139 * Given an array of strings formatted as a BRL-CAD v5 ASCII "title" command,
140 * translate the information in that command into a new title for the dbip.
141 *
142 * The msg parameter is optional - if present, rt_cmd_title will output
143 * diagnostic messages to the vls in the event of an error.
144 *
145 * Returns BRLCAD_OK on success, BRLCAD_ERROR on failure.
146 */
147RT_EXPORT extern int rt_cmd_title(struct bu_vls *msg, struct db_i *dbip, int argc, const char **argv);
148
149/**
150 * @brief Convert an ASCII v5 "units" command into a .g units
151 *
152 * Given an array of strings formatted as a BRL-CAD v5 ASCII "units" command,
153 * translate the information in that command into a new units for the dbip.
154 *
155 * The msg parameter is optional - if present, rt_cmd_units will output
156 * diagnostic messages to the vls in the event of an error.
157 *
158 * Returns BRLCAD_OK on success, BRLCAD_ERROR on failure.
159 */
160RT_EXPORT extern int rt_cmd_units(struct bu_vls *msg, struct db_i *dbip, int argc, const char **argv);
161
162
163__END_DECLS
164
165#endif /* RT_CMD_H */
166
167/*
168 * Local Variables:
169 * tab-width: 8
170 * mode: C
171 * indent-tabs-mode: t
172 * c-file-style: "stroustrup"
173 * End:
174 * ex: shiftwidth=4 tabstop=8
175 */
Header file for the BRL-CAD common definitions.
int rt_cmd_put(struct bu_vls *msg, struct rt_wdb *wdbp, int argc, const char **argv)
Convert an ASCII v5 "put" command into a .g object.
int rt_cmd_units(struct bu_vls *msg, struct db_i *dbip, int argc, const char **argv)
Convert an ASCII v5 "units" command into a .g units.
int rt_cmd_title(struct bu_vls *msg, struct db_i *dbip, int argc, const char **argv)
Convert an ASCII v5 "title" command into a .g title.
int rt_cmd_attr(struct bu_vls *msg, struct db_i *dbip, int argc, const char **argv)
Convert an ASCII v5 "attr" command into a .g attribute.
int rt_cmd_color(struct bu_vls *msg, struct db_i *dbip, int argc, const char **argv)
Convert an ASCII v5 "color" command into a .g coloribute.
int rt_do_cmd(struct rt_i *rtip, const char *ilp, const struct command_tab *tp)
char * rt_read_cmd(FILE *fp)
Definition: vls.h:53
const char * ct_cmd
Definition: cmd.h:43
int ct_max
max number of words in cmd
Definition: cmd.h:48
int ct_min
min number of words in cmd
Definition: cmd.h:47
int(* ct_func)(const int, const char **)
Definition: cmd.h:46
const char * ct_comment
Definition: cmd.h:45
const char * ct_parms
Definition: cmd.h:44
Definition: wdb.h:62
fundamental vector, matrix, quaternion math macros