84 lines
2.8 KiB
C
84 lines
2.8 KiB
C
#ifndef FUNC_H
|
|
#define FUNC_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define MAX_FUNC_NAME_LENGTH 20
|
|
|
|
typedef enum
|
|
/* The purpose of this enum is to enforce backward compatibility
|
|
of numeric function identifiers which may be recorded in old
|
|
save files. Hence, do NOT change the order of the items in this
|
|
enum, merely add new identifiers at the end, just before
|
|
N_FUNCTION_IDENTIFIERS.
|
|
*/
|
|
{
|
|
NOT_A_FUNCTION = -1,
|
|
FIRST_FUNCTION = 0,
|
|
FUNC_AT_SYMBOL = 0, FUNC_AMPERSAND, FUNC_X, FUNC_Y, FUNC_Z, FUNC_EVAL,
|
|
FUNC_ERROR, FUNC_STRING, FUNC_SUM, FUNC_N, FUNC_INT, FUNC_FRAC, FUNC_LEN,
|
|
FUNC_MIN, FUNC_MAX, FUNC_ABS, FUNC_DOLLAR_SIGN, FUNC_FLOAT, FUNC_STRFTIME,
|
|
FUNC_CLOCK, FUNC_POLY, FUNC_E, FUNC_LOG, FUNC_SIN, FUNC_COS, FUNC_TAN,
|
|
FUNC_SINH, FUNC_COSH, FUNC_TANH, FUNC_ASIN, FUNC_ACOS, FUNC_ATAN,
|
|
FUNC_ARSINH, FUNC_ARCOSH, FUNC_ARTANH, FUNC_DEG2RAD, FUNC_RAD2DEG,
|
|
FUNC_RND, FUNC_SUBSTR, FUNC_STRPTIME, FUNC_TIME, FUNC_BITAND, FUNC_BITOR,
|
|
FUNC_R, FUNC_D, FUNC_CAP_X, FUNC_X_AMPERSAND, FUNC_NEGATE, FUNC_PLUS_SYMBOL,
|
|
FUNC_MINUS_SYMBOL, FUNC_ASTERISK, FUNC_SLASH,
|
|
|
|
/* Note use of these in the macro below */
|
|
FUNC_LESS_EQUAL, FUNC_GREATER_EQUAL, FUNC_LESS_THAN, FUNC_GREATER_THAN,
|
|
FUNC_EQUAL_EQUAL, FUNC_TILDE_EQUAL, FUNC_BANG_EQUAL,
|
|
|
|
FUNC_CARET,
|
|
FUNC_PER_CENT, FUNC_CONCAT, FUNC_TAU, FUNC_SQRT, FUNC_FLOOR, FUNC_CEIL,
|
|
FUNC_TRUNC, FUNC_ROUND, FUNC_DECIMAL, FUNC_SCIENTIFIC, FUNC_COMPACT,
|
|
FUNC_HEXACT, FUNC_RIGHT, FUNC_LEFT, FUNC_DOWN, FUNC_UP, FUNC_BELOW, FUNC_ABOVE,
|
|
FUNC_TRUE, FUNC_FALSE, FUNC_AND, FUNC_OR,
|
|
|
|
/* Note use of these in the macro below */
|
|
FUNC_BOOL, FUNC_EMPTY, FUNC_FIDENT,
|
|
FUNC_FUNCALL, FUNC_LIDENT, FUNC_LOCATION, FUNC_NUMBER, FUNC_OPERATOR,
|
|
|
|
FUNC_IS, FUNC_FIND, FUNC_PRECISION, FUNC_FOREGROUND, FUNC_BACKGROUND,
|
|
FUNC_JUSTIFY, FUNC_FLOATFMT, FUNC_SHADOWED, FUNC_TRANSPARENT, FUNC_BOLD,
|
|
FUNC_UNDERLINE, FUNC_CENTER,
|
|
|
|
N_FUNCTION_IDS
|
|
} FunctionIdentifier;
|
|
|
|
#define IS_RELATION_FUNC(f) (((f) >= FUNC_LESS_EQUAL) && ((f) <= FUNC_BANG_EQUAL))
|
|
#define IS_TYPE_FUNC(f) (((f) >= FUNC_BOOL && ((f) <= FUNC_OPERATOR)) || (f)==FUNC_ERROR || (f)==FUNC_FLOAT || (f)==FUNC_INT || (f)==FUNC_STRING)
|
|
|
|
/* Forward declaration of Token, since this header is used in scanner.h */
|
|
typedef struct Token_struc Token;
|
|
|
|
typedef enum /* In increasing order of precedence */
|
|
{
|
|
NO_PRECEDENCE, INFIX_CONC, INFIX_BOOL, INFIX_REL, INFIX_PLUS, INFIX_MUL,
|
|
PREFIX_NEG, INFIX_POW, PREFIX_FUNC
|
|
} FunctionPrecedence;
|
|
|
|
typedef enum { FUNCT, MACRO } EvaluationStrategy;
|
|
|
|
typedef struct
|
|
{
|
|
const char name[MAX_FUNC_NAME_LENGTH + 1];
|
|
Token (*func)(FunctionIdentifier self, int, const Token*);
|
|
FunctionPrecedence precedence;
|
|
EvaluationStrategy eval_as;
|
|
const char* display_symbol;
|
|
} Tfunc;
|
|
|
|
FunctionIdentifier identcode(const char *s, size_t len);
|
|
extern Tfunc tfunc[];
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|