00001
00002
00003
00004
00005
00006 #include "copyright.h"
00007 #include "autoconf.h"
00008 #include "config.h"
00009 #include "externs.h"
00010
00011
00012
00013 #define F_EXAMINE 1 // Normal
00014 #define F_QUIET 2 // Binary for db dumps
00015 #define F_DECOMPILE 3 // @decompile output
00016 #define F_FUNCTION 4 // [lock()] output
00017
00018
00019
00020
00021
00022
00023
00024 static char *unparse_object_quiet(dbref player, dbref loc)
00025 {
00026 UNUSED_PARAMETER(player);
00027
00028 static char buf[SBUF_SIZE];
00029
00030 switch (loc)
00031 {
00032 case NOTHING:
00033 return (char *)"-1";
00034 case HOME:
00035 return (char *)"-3";
00036 default:
00037 sprintf(buf, "(#%d)", loc);
00038 return buf;
00039 }
00040 }
00041
00042 static char boolexp_buf[LBUF_SIZE];
00043 static char *buftop;
00044
00045 static void unparse_boolexp1(dbref player, BOOLEXP *b, char outer_type, int format)
00046 {
00047 if ((b == TRUE_BOOLEXP))
00048 {
00049 if (format == F_EXAMINE)
00050 {
00051 safe_str("*UNLOCKED*", boolexp_buf, &buftop);
00052 }
00053 return;
00054 }
00055 switch (b->type)
00056 {
00057 case BOOLEXP_AND:
00058 if (outer_type == BOOLEXP_NOT)
00059 {
00060 safe_chr('(', boolexp_buf, &buftop);
00061 }
00062 unparse_boolexp1(player, b->sub1, b->type, format);
00063 safe_chr(AND_TOKEN, boolexp_buf, &buftop);
00064 unparse_boolexp1(player, b->sub2, b->type, format);
00065 if (outer_type == BOOLEXP_NOT)
00066 {
00067 safe_chr(')', boolexp_buf, &buftop);
00068 }
00069 break;
00070 case BOOLEXP_OR:
00071 if (outer_type == BOOLEXP_NOT || outer_type == BOOLEXP_AND)
00072 {
00073 safe_chr('(', boolexp_buf, &buftop);
00074 }
00075 unparse_boolexp1(player, b->sub1, b->type, format);
00076 safe_chr(OR_TOKEN, boolexp_buf, &buftop);
00077 unparse_boolexp1(player, b->sub2, b->type, format);
00078 if (outer_type == BOOLEXP_NOT || outer_type == BOOLEXP_AND)
00079 {
00080 safe_chr(')', boolexp_buf, &buftop);
00081 }
00082 break;
00083 case BOOLEXP_NOT:
00084 safe_chr('!', boolexp_buf, &buftop);
00085 unparse_boolexp1(player, b->sub1, b->type, format);
00086 break;
00087 case BOOLEXP_INDIR:
00088 safe_chr(INDIR_TOKEN, boolexp_buf, &buftop);
00089 unparse_boolexp1(player, b->sub1, b->type, format);
00090 break;
00091 case BOOLEXP_IS:
00092 safe_chr(IS_TOKEN, boolexp_buf, &buftop);
00093 unparse_boolexp1(player, b->sub1, b->type, format);
00094 break;
00095 case BOOLEXP_CARRY:
00096 safe_chr(CARRY_TOKEN, boolexp_buf, &buftop);
00097 unparse_boolexp1(player, b->sub1, b->type, format);
00098 break;
00099 case BOOLEXP_OWNER:
00100 safe_chr(OWNER_TOKEN, boolexp_buf, &buftop);
00101 unparse_boolexp1(player, b->sub1, b->type, format);
00102 break;
00103 case BOOLEXP_CONST:
00104
00105 if (mudstate.bStandAlone)
00106 {
00107 safe_str(unparse_object_quiet(player, b->thing),
00108 boolexp_buf, &buftop);
00109 }
00110 else
00111 {
00112 switch (format)
00113 {
00114 case F_QUIET:
00115
00116
00117
00118 safe_str(unparse_object_quiet(player, b->thing),
00119 boolexp_buf, &buftop);
00120 break;
00121
00122 case F_EXAMINE:
00123
00124
00125
00126 char *buff;
00127
00128 buff = unparse_object(player, b->thing, false);
00129 safe_str(buff, boolexp_buf, &buftop);
00130 free_lbuf(buff);
00131 break;
00132
00133 case F_DECOMPILE:
00134
00135
00136
00137
00138 switch (Typeof(b->thing))
00139 {
00140 case TYPE_PLAYER:
00141
00142 safe_chr('*', boolexp_buf, &buftop);
00143
00144 case TYPE_THING:
00145
00146 safe_str(Name(b->thing), boolexp_buf, &buftop);
00147 break;
00148
00149 default:
00150
00151 safe_tprintf_str(boolexp_buf, &buftop, "#%d", b->thing);
00152 break;
00153 }
00154 break;
00155
00156 case F_FUNCTION:
00157
00158
00159
00160
00161 switch (Typeof(b->thing))
00162 {
00163 case TYPE_PLAYER:
00164
00165 safe_chr('*', boolexp_buf, &buftop);
00166 safe_str(Name(b->thing), boolexp_buf, &buftop);
00167 break;
00168
00169 default:
00170
00171 safe_tprintf_str(boolexp_buf, &buftop, "#%d", b->thing);
00172 break;
00173 }
00174 }
00175 }
00176 break;
00177
00178 case BOOLEXP_ATR:
00179 case BOOLEXP_EVAL:
00180 ATTR *ap;
00181
00182 ap = atr_num(b->thing);
00183 if (ap && ap->number)
00184 {
00185
00186
00187 safe_str(ap->name, boolexp_buf, &buftop);
00188 }
00189 else
00190 {
00191
00192
00193
00194
00195
00196
00197 safe_ltoa(b->thing, boolexp_buf, &buftop);
00198 }
00199 if (b->type == BOOLEXP_EVAL)
00200 {
00201 safe_chr('/', boolexp_buf, &buftop);
00202 }
00203 else
00204 {
00205 safe_chr(':', boolexp_buf, &buftop);
00206 }
00207 safe_str((char *)b->sub1, boolexp_buf, &buftop);
00208 break;
00209
00210 default:
00211
00212
00213
00214 Log.WriteString("ABORT! unparse.cpp, fell off the end of switch in unparse_boolexp1()" ENDLINE);
00215 Log.Flush();
00216 abort();
00217 break;
00218 }
00219 }
00220
00221 char *unparse_boolexp_quiet(dbref player, BOOLEXP *b)
00222 {
00223 buftop = boolexp_buf;
00224 unparse_boolexp1(player, b, BOOLEXP_CONST, F_QUIET);
00225 *buftop = '\0';
00226 return boolexp_buf;
00227 }
00228
00229 char *unparse_boolexp(dbref player, BOOLEXP *b)
00230 {
00231 buftop = boolexp_buf;
00232 unparse_boolexp1(player, b, BOOLEXP_CONST, F_EXAMINE);
00233 *buftop = '\0';
00234 return boolexp_buf;
00235 }
00236
00237 char *unparse_boolexp_decompile(dbref player, BOOLEXP *b)
00238 {
00239 buftop = boolexp_buf;
00240 unparse_boolexp1(player, b, BOOLEXP_CONST, F_DECOMPILE);
00241 *buftop = '\0';
00242 return boolexp_buf;
00243 }
00244
00245 char *unparse_boolexp_function(dbref player, BOOLEXP *b)
00246 {
00247 buftop = boolexp_buf;
00248 unparse_boolexp1(player, b, BOOLEXP_CONST, F_FUNCTION);
00249 *buftop = '\0';
00250 return boolexp_buf;
00251 }