2002-07-30 17:08:53 +00:00
|
|
|
/*
|
|
|
|
#FILENAME#
|
|
|
|
|
|
|
|
#DESCRIPTION#
|
|
|
|
|
|
|
|
Copyright (C) 2002 #AUTHOR#
|
|
|
|
|
|
|
|
Author: #AUTHOR#
|
|
|
|
Date: #DATE#
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __QF_cbuf_h
|
|
|
|
#define __QF_cbuf_h
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** \defgroup cbuf Command buffer management.
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup utils
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2002-08-02 04:07:25 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
#include "QF/qtypes.h"
|
|
|
|
|
2002-07-30 17:08:53 +00:00
|
|
|
typedef struct cbuf_args_s {
|
|
|
|
int argc;
|
|
|
|
struct dstring_s **argv;
|
2003-11-20 07:02:14 +00:00
|
|
|
void **argm; // Metadata (optional)
|
2002-07-30 17:08:53 +00:00
|
|
|
const char **args;
|
|
|
|
int argv_size;
|
|
|
|
} cbuf_args_t;
|
|
|
|
|
2002-08-03 06:04:00 +00:00
|
|
|
|
2002-07-30 17:08:53 +00:00
|
|
|
typedef struct cbuf_s {
|
|
|
|
cbuf_args_t *args;
|
2012-05-21 23:23:22 +00:00
|
|
|
struct cbuf_interpreter_s *interpreter;
|
2002-07-31 22:03:53 +00:00
|
|
|
|
2003-11-20 07:02:14 +00:00
|
|
|
struct cbuf_s *up, *down; // The stack
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2002-07-31 22:03:53 +00:00
|
|
|
enum {
|
2003-11-20 07:02:14 +00:00
|
|
|
CBUF_STATE_NORMAL = 0, // Normal condition
|
|
|
|
CBUF_STATE_WAIT, // Buffer is stalled until next frame
|
|
|
|
CBUF_STATE_BLOCKED, // Buffer is blocked until further notice
|
|
|
|
CBUF_STATE_ERROR, // An unrecoverable error occured
|
|
|
|
CBUF_STATE_STACK, // A buffer has been added to the stack
|
|
|
|
CBUF_STATE_JUNK // Buffer can be freed or reused
|
2003-01-29 04:34:23 +00:00
|
|
|
} state;
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2003-11-20 07:02:14 +00:00
|
|
|
int (*unknown_command)(void); // handle unkown commands. !0 = handled
|
2023-06-13 09:06:11 +00:00
|
|
|
bool strict; // Should we tolerate unknown commands?
|
2003-11-20 07:02:14 +00:00
|
|
|
double resumetime; // Time when stack can be executed again
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2003-11-20 07:02:14 +00:00
|
|
|
void *data; // Pointer to interpreter data
|
2002-07-30 17:08:53 +00:00
|
|
|
} cbuf_t;
|
|
|
|
|
2002-08-03 06:04:00 +00:00
|
|
|
typedef struct cbuf_interpreter_s {
|
|
|
|
void (*construct) (struct cbuf_s *cbuf);
|
|
|
|
void (*destruct) (struct cbuf_s *cbuf);
|
2003-02-14 08:06:01 +00:00
|
|
|
void (*reset) (struct cbuf_s *cbuf);
|
2003-01-28 21:16:21 +00:00
|
|
|
void (*add) (struct cbuf_s *cbuf, const char *str);
|
|
|
|
void (*insert) (struct cbuf_s *cbuf, const char *str);
|
|
|
|
void (*execute) (struct cbuf_s *cbuf);
|
|
|
|
void (*execute_sets) (struct cbuf_s *cbuf);
|
2007-03-20 21:31:07 +00:00
|
|
|
const char** (*complete) (struct cbuf_s *cbuf, const char *str);
|
2002-08-03 06:04:00 +00:00
|
|
|
} cbuf_interpreter_t;
|
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
extern cbuf_t *cbuf_active;
|
|
|
|
|
|
|
|
cbuf_args_t *Cbuf_ArgsNew (void);
|
|
|
|
void Cbuf_ArgsDelete (cbuf_args_t *);
|
|
|
|
void Cbuf_ArgsAdd (cbuf_args_t *args, const char *arg);
|
|
|
|
|
2002-08-03 06:04:00 +00:00
|
|
|
cbuf_t * Cbuf_New (cbuf_interpreter_t *interp);
|
2002-08-02 04:07:25 +00:00
|
|
|
|
2002-08-01 02:42:19 +00:00
|
|
|
void Cbuf_Delete (cbuf_t *cbuf);
|
2002-08-03 06:04:00 +00:00
|
|
|
void Cbuf_DeleteStack (cbuf_t *stack);
|
2023-03-05 08:23:11 +00:00
|
|
|
void Cbuf_DeleteStackReverse (cbuf_t *stack);
|
2003-02-14 08:06:01 +00:00
|
|
|
void Cbuf_Reset (cbuf_t *cbuf);
|
|
|
|
cbuf_t *Cbuf_PushStack (cbuf_interpreter_t *interp);
|
2002-07-30 17:08:53 +00:00
|
|
|
void Cbuf_AddText (cbuf_t *cbuf, const char *text);
|
|
|
|
void Cbuf_InsertText (cbuf_t *cbuf, const char *text);
|
|
|
|
void Cbuf_Execute (cbuf_t *cbuf);
|
2002-08-03 06:04:00 +00:00
|
|
|
void Cbuf_Execute_Stack (cbuf_t *cbuf);
|
2002-07-30 17:08:53 +00:00
|
|
|
void Cbuf_Execute_Sets (cbuf_t *cbuf);
|
|
|
|
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2002-07-30 17:08:53 +00:00
|
|
|
#endif//__QF_cbuf_h
|