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
21/** @addtogroup bu_cmd
22 * @brief
23 * Routine(s) for processing subcommands
24 */
25/** @{ */
26/** @file bu/cmd.h */
27
28#ifndef BU_CMD_H
29#define BU_CMD_H
30
31#include "common.h"
32
33#include <time.h>
34
35#include "bsocket.h" /* for timeval */
36
37#define BU_CMD_NULL (int (*)(void *, int, const char **))NULL
38
39#include "bu/defines.h"
40#include "bu/log.h"
41#include "bu/vls.h"
42
43/**
44 * Generic keyword-to-command callback interface intended for use with
45 * bu_cmd().
46 */
47struct bu_cmdtab {
48 const char *ct_name;
49 int (*ct_func)(void *data, int argc, const char *argv[]);
50};
51
52__BEGIN_DECLS
53
54/** @brief Routine(s) for processing subcommands */
55
56/**
57 * This function is intended to be used for parsing subcommands. If
58 * the command is found in the array of commands, the associated
59 * function is called. Otherwise, an error message is printed along
60 * with a list of available commands. This behavior can be suppressed
61 * by registering a bu_log() callback.
62 *
63 * @code
64 * struct bu_hook_list saved_hooks = BU_HOOK_LIST_INIT_ZERO;
65 * bu_log_hook_save_all(&saved_hooks);
66 * bu_log_hook_delete_all();
67 * bu_log_add_hook(NULL, NULL); // disables logging
68 * bu_cmd(...);
69 * bu_log_hook_restore_all(&saved_hooks);
70 * @endcode
71 *
72 * @param cmds - commands and related function pointers
73 * @param argc - number of arguments in argv
74 * @param argv - command to execute and its arguments
75 * @param cmd_index - indicates which argv element holds the subcommand
76 * @param data - data/state associated with the command
77 * @param result - if non-NULL, return value from the command
78 *
79 * @return BRLCAD_OK if command was found, otherwise, BRLCAD_ERROR.
80 */
81BU_EXPORT extern int bu_cmd(const struct bu_cmdtab *cmds, int argc, const char *argv[], int cmd_index, void *data, int *result);
82
83/**
84 * Returns BRLCAD_OK if cmdname defines a command in the cmds table, and BRLCAD_ERROR otherwise */
85BU_EXPORT extern int bu_cmd_valid(const struct bu_cmdtab *cmds, const char *cmdname);
86
87/** @brief Routines for maintaining a command history */
88
89/**
90 * Prints out the command history.
91 *
92 * USAGE:
93 * history [-delays] [-outfile filename]
94 */
95DEPRECATED BU_EXPORT extern int bu_cmdhist_history(void *data, int argc, const char **argv);
96
97/**
98 * Add a command to the history list.
99 *
100 * USAGE:
101 * procname add cmd
102 */
103DEPRECATED BU_EXPORT extern int bu_cmdhist_add(void *data, int argc, const char **argv);
104
105/**
106 * Return the current command.
107 *
108 * USAGE:
109 * procname curr
110 */
111DEPRECATED BU_EXPORT extern int bu_cmdhist_curr(void *data, int argc, const char **argv);
112
113/**
114 * Set the current command to the next command.
115 *
116 * USAGE:
117 * procname next
118 */
119DEPRECATED BU_EXPORT extern int bu_cmdhist_next(void *data, int argc, const char **argv);
120
121/**
122 * Set the current command to the previous command.
123 *
124 * USAGE:
125 * procname prev
126 */
127DEPRECATED BU_EXPORT extern int bu_cmdhist_prev(void *data, int argc, const char **argv);
128
129__END_DECLS
130
131#endif /* BU_CMD_H */
132
133/** @} */
134/*
135 * Local Variables:
136 * mode: C
137 * tab-width: 8
138 * indent-tabs-mode: t
139 * c-file-style: "stroustrup"
140 * End:
141 * ex: shiftwidth=4 tabstop=8
142 */
Header file for the BRL-CAD common definitions.
DEPRECATED int bu_cmdhist_history(void *data, int argc, const char **argv)
Routines for maintaining a command history.
DEPRECATED int bu_cmdhist_next(void *data, int argc, const char **argv)
DEPRECATED int bu_cmdhist_curr(void *data, int argc, const char **argv)
int bu_cmd_valid(const struct bu_cmdtab *cmds, const char *cmdname)
int bu_cmd(const struct bu_cmdtab *cmds, int argc, const char *argv[], int cmd_index, void *data, int *result)
Routine(s) for processing subcommands.
DEPRECATED int bu_cmdhist_prev(void *data, int argc, const char **argv)
DEPRECATED int bu_cmdhist_add(void *data, int argc, const char **argv)
#define DEPRECATED
Definition: common.h:400
Definition: cmd.h:47
const char * ct_name
Definition: cmd.h:48
int(* ct_func)(void *data, int argc, const char *argv[])
Definition: cmd.h:49