[17] | 1 | /* -*- mode: C; tab-width:8; c-basic-offset:8 -*- |
---|
| 2 | * vi:set ts=8: |
---|
| 3 | * |
---|
| 4 | * al_rcvar.h |
---|
| 5 | * |
---|
| 6 | * Stuff related to the Rcvar config interface |
---|
| 7 | * |
---|
| 8 | */ |
---|
| 9 | #ifndef AL_RCVAR_H_ |
---|
| 10 | #define AL_RCVAR_H_ |
---|
| 11 | |
---|
| 12 | #include <AL/al.h> |
---|
| 13 | #include <stdlib.h> |
---|
| 14 | |
---|
| 15 | /* |
---|
| 16 | * opaque pointer to a lisp-like var. Calling code shouldn't mess with it |
---|
| 17 | * directly. |
---|
| 18 | */ |
---|
| 19 | typedef void *Rcvar; |
---|
| 20 | |
---|
| 21 | /* |
---|
| 22 | * Each AL_rctree has a type, which reflects how its data should be |
---|
| 23 | * interpreted. There are those types. |
---|
| 24 | */ |
---|
| 25 | typedef enum { |
---|
| 26 | ALRC_INVALID, |
---|
| 27 | ALRC_PRIMITIVE, |
---|
| 28 | ALRC_CONSCELL, |
---|
| 29 | ALRC_SYMBOL, |
---|
| 30 | ALRC_INTEGER, |
---|
| 31 | ALRC_FLOAT, |
---|
| 32 | ALRC_STRING, |
---|
| 33 | ALRC_BOOL, |
---|
| 34 | ALRC_POINTER |
---|
| 35 | } ALRcEnum; |
---|
| 36 | |
---|
| 37 | /* |
---|
| 38 | * Returns the binding for the symbol named by name, if it exists, or NULL if |
---|
| 39 | * it doesn't. |
---|
| 40 | */ |
---|
| 41 | Rcvar rc_lookup( const char *name ); |
---|
| 42 | |
---|
| 43 | /* |
---|
| 44 | * Creates a binding between symname and the evaluation of val in the |
---|
| 45 | * global scope, returning val. |
---|
| 46 | */ |
---|
| 47 | Rcvar rc_define( const char *symname, Rcvar val ); |
---|
| 48 | |
---|
| 49 | /* |
---|
| 50 | * Creates a binding between car(ls) (symbol) the evaluation of cadr(ls) in the |
---|
| 51 | * global scope, returning cadr(ls). |
---|
| 52 | */ |
---|
| 53 | Rcvar rc_define_list( Rcvar ls ); |
---|
| 54 | |
---|
| 55 | /* |
---|
| 56 | * Evaluates str, returning result. |
---|
| 57 | */ |
---|
| 58 | Rcvar rc_eval( const char *str ); |
---|
| 59 | |
---|
| 60 | /* |
---|
| 61 | * Returns the type of sym. |
---|
| 62 | */ |
---|
| 63 | ALRcEnum rc_type( Rcvar sym ); |
---|
| 64 | |
---|
| 65 | /* |
---|
| 66 | * Returns the car portion of sym. If sym is not a cons cell, returns NULL. |
---|
| 67 | */ |
---|
| 68 | Rcvar rc_car( Rcvar sym ); |
---|
| 69 | |
---|
| 70 | /* |
---|
| 71 | * Returns the cdr portion of sym. If sym is not a cons cell, returns NULL. |
---|
| 72 | */ |
---|
| 73 | Rcvar rc_cdr( Rcvar sym ); |
---|
| 74 | |
---|
| 75 | /* |
---|
| 76 | * If sym has type ALRC_SYMBOL, this call populates retstr ( up to len bytes ) |
---|
| 77 | * with the name of the symbol. |
---|
| 78 | */ |
---|
| 79 | Rcvar rc_symtostr0( Rcvar sym, char *retstr, size_t len ); |
---|
| 80 | |
---|
| 81 | /* |
---|
| 82 | * If sym has type ALRC_STRING, this call populates retstr ( up to len bytes ) |
---|
| 83 | * with the value of the string. |
---|
| 84 | */ |
---|
| 85 | Rcvar rc_tostr0( Rcvar sym, char *retstr, size_t len ); |
---|
| 86 | |
---|
| 87 | /* |
---|
| 88 | * Returns AL_TRUE if sym is a boolean type and equal to #t, AL_FALSE |
---|
| 89 | * otherwise. |
---|
| 90 | */ |
---|
| 91 | ALboolean rc_tobool( Rcvar sym ); |
---|
| 92 | |
---|
| 93 | /* |
---|
| 94 | * If sym is a numerical type, returns the integer value of sym. Otherwise, |
---|
| 95 | * returns 0. |
---|
| 96 | */ |
---|
| 97 | ALint rc_toint( Rcvar sym ); |
---|
| 98 | |
---|
| 99 | /* |
---|
| 100 | * If sym is a numerical type, returns the float value of sym. Otherwise, |
---|
| 101 | * returns 0.0f. |
---|
| 102 | */ |
---|
| 103 | ALfloat rc_tofloat( Rcvar sym ); |
---|
| 104 | |
---|
| 105 | /* |
---|
| 106 | * If d1 and d2 both have type AL_STRING, returns AL_TRUE if there are |
---|
| 107 | * equivilant. Returns AL_FALSE otherwise. |
---|
| 108 | */ |
---|
| 109 | ALboolean rc_strequal( Rcvar d1, Rcvar d2 ); |
---|
| 110 | |
---|
| 111 | /* |
---|
| 112 | * Evaluates needle and sees if it is a member in haystack, returning a list |
---|
| 113 | * with the first conscell to have a matching car as its head. |
---|
| 114 | */ |
---|
| 115 | Rcvar rc_lookup_list( Rcvar haystack, const char *needle ); |
---|
| 116 | |
---|
| 117 | /* |
---|
| 118 | * Returns a list with the first conscell to have a matching car with sym as |
---|
| 119 | * its head, NULL otherwise. |
---|
| 120 | */ |
---|
| 121 | Rcvar rc_member( Rcvar ls, Rcvar sym ); |
---|
| 122 | |
---|
| 123 | /* |
---|
| 124 | * Returns AL_TRUE if r1 and r2 and equivilant, AL_FALSE otherwise. |
---|
| 125 | */ |
---|
| 126 | ALboolean rc_equal( Rcvar r1, Rcvar r2 ); |
---|
| 127 | |
---|
| 128 | struct _AL_rctree; |
---|
| 129 | struct _AL_rctree *(*rc_toprim( Rcvar sym ))( struct _AL_rctree *, |
---|
| 130 | struct _AL_rctree * ); |
---|
| 131 | |
---|
| 132 | /* |
---|
| 133 | * Returns a const char *representation of type. |
---|
| 134 | */ |
---|
| 135 | const char *rc_typestr( ALRcEnum type ); |
---|
| 136 | |
---|
| 137 | /* |
---|
| 138 | * For each member in ls, apply op to the member. |
---|
| 139 | */ |
---|
| 140 | void rc_foreach( Rcvar ls, Rcvar (*op)( Rcvar operand )); |
---|
| 141 | |
---|
| 142 | /* |
---|
| 143 | * Prints a stdout representation of sym to stdout. |
---|
| 144 | */ |
---|
| 145 | void rc_print( Rcvar sym ); |
---|
| 146 | |
---|
| 147 | /* |
---|
| 148 | * Quotes sym, returning that. |
---|
| 149 | */ |
---|
| 150 | Rcvar alrc_quote( Rcvar sym ); |
---|
| 151 | |
---|
| 152 | /* |
---|
| 153 | * car and cdr convienence macros. |
---|
| 154 | */ |
---|
| 155 | #define rc_cddr(s) rc_cdr(rc_cdr(s)) |
---|
| 156 | #define rc_cdddr(s) rc_cdr(rc_cddr(s)) |
---|
| 157 | #define rc_cddddr(s) rc_cdr(rc_cdddr(s)) |
---|
| 158 | #define rc_cddddddr(s) rc_cdr(rc_cdddddr(s)) |
---|
| 159 | |
---|
| 160 | #define rc_cadr(s) rc_car(rc_cdr(s)) |
---|
| 161 | #define rc_caddr(s) rc_car(rc_cddr(s)) |
---|
| 162 | #define rc_cadddr(s) rc_car(rc_cdddr(s)) |
---|
| 163 | #define rc_caddddr(s) rc_car(rc_cddddr(s)) |
---|
| 164 | #define rc_cadddddr(s) rc_car(rc_cdddddr(s)) |
---|
| 165 | |
---|
| 166 | #endif /* AL_RCVAR_H_ */ |
---|