mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
methods & templates
This commit is contained in:
parent
efd58428a9
commit
75f4e0aee4
11 changed files with 197 additions and 92 deletions
|
@ -94,14 +94,6 @@ typedef enum {
|
|||
PSYC_LIST_BINARY = 2,
|
||||
} PsycListType;
|
||||
|
||||
typedef enum PsycMessageFlag {
|
||||
PSYC_MESSAGE_TEMPLATE = 1 << 0,
|
||||
PSYC_MESSAGE_REPLY = 1 << 1,
|
||||
PSYC_MESSAGE_VISIBLE = 1 << 2,
|
||||
PSYC_MESSAGE_LOGGABLE = 1 << 3,
|
||||
PSYC_MESSAGE_MANUAL = 1 << 4,
|
||||
} PsycMessageFlag;
|
||||
|
||||
/**
|
||||
* String struct.
|
||||
*
|
||||
|
|
65
include/psyc/method.h
Normal file
65
include/psyc/method.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
#ifndef PSYC_METHOD_H
|
||||
#define PSYC_METHOD_H
|
||||
|
||||
typedef enum PsycMethodFlag {
|
||||
PSYC_METHOD_TEMPLATE = 1 << 0,
|
||||
PSYC_METHOD_REPLY = 1 << 1,
|
||||
PSYC_METHOD_VISIBLE = 1 << 2,
|
||||
PSYC_METHOD_LOGGABLE = 1 << 3,
|
||||
PSYC_METHOD_MANUAL = 1 << 4,
|
||||
} PsycMethodFlag;
|
||||
|
||||
typedef enum PsycMethod {
|
||||
PSYC_MC_UNKNOWN,
|
||||
|
||||
PSYC_MC_DATA,
|
||||
PSYC_MC_ECHO,
|
||||
PSYC_MC_ECHO_CONTEXT_ENTER,
|
||||
PSYC_MC_ECHO_CONTEXT_LEAVE,
|
||||
PSYC_MC_ERROR,
|
||||
PSYC_MC_FAILURE,
|
||||
PSYC_MC_INFO,
|
||||
PSYC_MC_MESSAGE,
|
||||
PSYC_MC_MESSAGE_ACTION,
|
||||
PSYC_MC_MESSAGE_ECHO,
|
||||
PSYC_MC_MESSAGE_ECHO_ACTION,
|
||||
PSYC_MC_NOTICE,
|
||||
PSYC_MC_NOTICE_CONTEXT_ENTER,
|
||||
PSYC_MC_NOTICE_CONTEXT_LEAVE,
|
||||
PSYC_MC_REQUEST,
|
||||
PSYC_MC_REQUEST_CONTEXT_ENTER,
|
||||
PSYC_MC_REQUEST_CONTEXT_LEAVE,
|
||||
PSYC_MC_STATUS,
|
||||
PSYC_MC_STATUS_CONTEXTS_ENTERED,
|
||||
PSYC_MC_WARNING,
|
||||
|
||||
PSYC_METHODS_NUM,
|
||||
} PsycMethod;
|
||||
|
||||
typedef union PsycTemplates {
|
||||
PsycString a[PSYC_METHODS_NUM];
|
||||
struct {
|
||||
PsycString _;
|
||||
PsycString _data;
|
||||
PsycString _echo;
|
||||
PsycString _echo_context_enter;
|
||||
PsycString _echo_context_leave;
|
||||
PsycString _error;
|
||||
PsycString _failure;
|
||||
PsycString _info;
|
||||
PsycString _message;
|
||||
PsycString _message_action;
|
||||
PsycString _message_echo_action;
|
||||
PsycString _notice;
|
||||
PsycString _notice_context_enter;
|
||||
PsycString _notice_context_leave;
|
||||
PsycString _request;
|
||||
PsycString _request_context_enter;
|
||||
PsycString _request_context_leave;
|
||||
PsycString _status;
|
||||
PsycString _status_contexts_entered;
|
||||
PsycString _warning;
|
||||
} s;
|
||||
} PsycTemplates;
|
||||
|
||||
#endif
|
|
@ -16,10 +16,11 @@
|
|||
* @{
|
||||
*/
|
||||
|
||||
#include <psyc.h>
|
||||
#include <psyc/syntax.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "syntax.h"
|
||||
#include "method.h"
|
||||
|
||||
/** Modifier flags. */
|
||||
typedef enum {
|
||||
/// Modifier needs to be checked if it needs length.
|
||||
|
@ -67,21 +68,6 @@ typedef enum {
|
|||
PSYC_STATE_RESYNC = '?',
|
||||
} PsycStateOp;
|
||||
|
||||
typedef enum PsycMethod {
|
||||
PSYC_METHOD_UNKNOWN,
|
||||
PSYC_METHOD_DATA,
|
||||
PSYC_METHOD_ECHO,
|
||||
PSYC_METHOD_ERROR,
|
||||
PSYC_METHOD_FAILURE,
|
||||
PSYC_METHOD_INFO,
|
||||
PSYC_METHOD_MESSAGE,
|
||||
PSYC_METHOD_MESSAGE_ECHO,
|
||||
PSYC_METHOD_NOTICE,
|
||||
PSYC_METHOD_REQUEST,
|
||||
PSYC_METHOD_STATUS,
|
||||
PSYC_METHOD_WARNING,
|
||||
} PsycMethod;
|
||||
|
||||
/** Structure for a modifier. */
|
||||
typedef struct {
|
||||
char oper;
|
||||
|
|
|
@ -114,7 +114,8 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <psyc.h>
|
||||
|
||||
#include "../psyc.h"
|
||||
|
||||
typedef enum {
|
||||
/// Default Flag. Parse everything.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef PSYC_RENDER_H
|
||||
#define PSYC_RENDER_H
|
||||
|
||||
#include <psyc/packet.h>
|
||||
#include "packet.h"
|
||||
|
||||
/**
|
||||
* @file psyc/render.h
|
||||
|
|
|
@ -158,6 +158,16 @@ psyc_text_bytes_written (PsycTextState *state)
|
|||
PsycTextRC
|
||||
psyc_text (PsycTextState *state, PsycTextCB getValue, void *extra);
|
||||
|
||||
extern const PsycTemplates psyc_templates;
|
||||
|
||||
static inline const char *
|
||||
psyc_template (PsycMethod mc, size_t *len) {
|
||||
PsycString t = psyc_templates.a[mc];
|
||||
if (len)
|
||||
*len = t.length;
|
||||
return t.data;
|
||||
}
|
||||
|
||||
/** @} */ // end of text group
|
||||
|
||||
#endif
|
||||
|
|
|
@ -13,8 +13,12 @@ extern const PsycString psyc_routing_vars[];
|
|||
// Variable types in alphabetical order.
|
||||
extern const PsycDictInt psyc_var_types[];
|
||||
|
||||
/// Method names in alphabetical order.
|
||||
extern const PsycDictInt psyc_methods[];
|
||||
|
||||
extern const size_t psyc_routing_vars_num;
|
||||
extern const size_t psyc_var_types_num;
|
||||
extern const size_t psyc_methods_num;
|
||||
|
||||
/**
|
||||
* Is this a routing variable name?
|
||||
|
@ -39,6 +43,6 @@ psyc_var_is_list (const char *name, size_t len)
|
|||
}
|
||||
|
||||
PsycMethod
|
||||
psyc_method_family (char *method, size_t methodlen, unsigned int *flag);
|
||||
psyc_method (char *method, size_t methodlen, PsycMethod *family, unsigned int *flag);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue