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