BRL-CAD
cmd.h
Go to the documentation of this file.
1 /* C M D . H
2  * BRL-CAD
3  *
4  * Copyright (c) 1993-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 
21 /** @addtogroup cmd */
22 /** @{ */
23 
24 #ifndef CMD_H
25 #define CMD_H
26 
27 #include "common.h"
28 
29 #ifdef HAVE_SYS_TIME_H
30 # include <sys/time.h>
31 #endif
32 #include <time.h>
33 
34 #include "bsocket.h" /* for timeval */
35 #include "bio.h"
36 
37 #define BU_CMD_NULL (int (*)(void *, int, const char **))NULL
38 
39 #include "bu/defines.h"
40 #include "bu/list.h"
41 #include "bu/log.h"
42 #include "bu/vls.h"
43 
44 /**
45  * Generic keyword-to-command callback interface intended for use with
46  * bu_cmd().
47  */
48 struct bu_cmdtab {
49  const char *ct_name;
50  int (*ct_func)(void *data, int argc, const char *argv[]);
51 };
52 
53 struct bu_cmdhist {
54  struct bu_list l;
55  struct bu_vls h_command;
56  struct timeval h_start;
57  struct timeval h_finish;
58  int h_status;
59 };
60 #define BU_CMDHIST_NULL (struct bu_cmdhist *)NULL
61 
63  struct bu_list l;
64  struct bu_vls cho_name;
67 };
68 #define BU_CMDHIST_OBJ_NULL (struct bu_cmdhist_obj *)NULL
69 
71 
72 /** @file libbu/cmd.c
73  *
74  * @brief
75  * Routine(s) for processing subcommands
76  *
77  */
78 /**
79  * This function is intended to be used for parsing subcommands. If
80  * the command is found in the array of commands, the associated
81  * function is called. Otherwise, an error message is created and
82  * added to interp.
83  *
84  * @param cmds - commands and related function pointers
85  * @param argc - number of arguments in argv
86  * @param argv - command to execute and its arguments
87  * @param cmd_index - indicates which argv element holds the subcommand
88  * @param data - data/state associated with the command
89  * @param result - if non-NULL, return value from the command
90  *
91  * @return BRLCAD_OK if command was found, otherwise, BRLCAD_ERROR.
92  */
93 BU_EXPORT extern int bu_cmd(const struct bu_cmdtab *cmds, int argc, const char *argv[], int cmd_index, void *data, int *result);
94 
95 /** @file cmdhist.c
96  *
97  * @brief
98  * Routines for maintaining a command history
99  *
100  */
101 /**
102  * @brief
103  * Prints out the command history.
104  *
105  * USAGE:
106  * history [-delays] [-outfile filename]
107  */
108 BU_EXPORT extern int bu_cmdhist_history(void *data, int argc, const char **argv);
109 
110 /**
111  * @brief
112  * Add a command to the history list.
113  *
114  * USAGE:
115  * procname add cmd
116  */
117 BU_EXPORT extern int bu_cmdhist_add(void *data, int argc, const char **argv);
118 
119 /**
120  * Return the current command.
121  *
122  * USAGE:
123  * procname curr
124  */
125 BU_EXPORT extern int bu_cmdhist_curr(void *data, int argc, const char **argv);
126 
127 /**
128  * Set the current command to the next command.
129  *
130  * USAGE:
131  * procname next
132  */
133 BU_EXPORT extern int bu_cmdhist_next(void *data, int argc, const char **argv);
134 
135 /**
136  * Set the current command to the previous command.
137  *
138  * USAGE:
139  * procname prev
140  */
141 BU_EXPORT extern int bu_cmdhist_prev(void *data, int argc, const char **argv);
142 
144 
145 #endif /* CMD_H */
146 
147 /** @} */
148 /*
149  * Local Variables:
150  * mode: C
151  * tab-width: 8
152  * indent-tabs-mode: t
153  * c-file-style: "stroustrup"
154  * End:
155  * ex: shiftwidth=4 tabstop=8
156  */
Definition: cmd.h:48
Definition: list.h:118
struct bu_list l
Definition: cmd.h:54
struct bu_cmdhist * cho_curr
Definition: cmd.h:66
struct timeval h_start
Definition: cmd.h:56
Header file for the BRL-CAD common definitions.
struct timeval h_finish
Definition: cmd.h:57
int bu_cmdhist_curr(void *data, int argc, const char **argv)
Definition: cmdhist.c:196
int bu_cmdhist_prev(void *data, int argc, const char **argv)
Definition: cmdhist.c:176
struct bu_vls cho_name
Definition: cmd.h:64
COMPLEX data[64]
Definition: fftest.c:34
struct bu_cmdhist cho_head
Definition: cmd.h:65
int bu_cmdhist_add(void *data, int argc, const char **argv)
Add a command to the history list.
Definition: cmdhist.c:147
#define __BEGIN_DECLS
Definition: common.h:73
const char * ct_name
Definition: cmd.h:49
struct bu_list l
Definition: cmd.h:63
int h_status
Definition: cmd.h:58
struct bu_vls h_command
Definition: cmd.h:55
Definition: cmd.h:53
#define __END_DECLS
Definition: common.h:74
int(* ct_func)(void *data, int argc, const char *argv[])
Definition: cmd.h:50
Definition: vls.h:56
int bu_cmdhist_next(void *data, int argc, const char **argv)
Definition: cmdhist.c:216
int bu_cmdhist_history(void *data, int argc, const char **argv)
Prints out the command history.
int bu_cmd(const struct bu_cmdtab *cmds, int argc, const char *argv[], int cmd_index, void *data, int *result)