#include "copyright.h" #include "config.h" #include "db.h" #include "externs.h" #include "params.h" #include "interface.h" #include "mush.h" char *unparse_name(dbref thing) { static char buf[BUFFER_LEN], *first; strcpy(buf, DBFETCH(thing)->name); first = (char *)strchr(buf, ';'); if (first) *first = '\0'; return buf; } char *unparse_object_do(dbref player, dbref loc, int shortname) { static char buf[BUFFER_LEN]; switch(loc) { case NOTHING: return "*NOTHING*"; case HOME: return "*HOME*"; default: if ((can_link_to(player, NOTYPE, loc) #ifdef PLAYER_CHOWN || ((Typeof(loc) != TYPE_PLAYER) && (FLAGS(loc) & CHOWN_OK)) #endif /* PLAYER_CHOWN */ ) #ifdef SILENT_PLAYERS && !(FLAGS(player) & STICKY) #endif /* SILENT_PLAYERS */ ) { /* show everything */ #ifdef ABODE sprintf(buf, "%s(#%ld%s", shortname ? unparse_name(loc) : NAME(loc), loc, unparse_flags(loc)); if (FLAGS(player) & ABODE) { strcat(buf, " "); strcat(buf, unparse_name(OWNER(loc))); } strcat(buf, ")"); #else /* !ABODE */ sprintf(buf, "%s(#%ld%s)", shortname ? unparse_name(loc) : NAME(loc), loc, unparse_flags(loc)); #endif return buf; } else return unparse_name(loc); } } #ifndef MUSH #define OVERFLOW 512 static char boolexp_buf[BUFFER_LEN]; static char *buftop; static void unparse_boolexp1(dbref player, boolexp *b, boolexp_type outer_type) { if ((buftop - boolexp_buf) > (BUFFER_LEN - OVERFLOW)) { strcpy(buftop, "... (ovflw)"); buftop += strlen(buftop); } else if(b == TRUE_BOOLEXP) { strcpy(buftop, "*UNLOCKED*"); buftop += strlen(buftop); } else { switch(b->type) { case BOOLEXP_AND: if(outer_type == BOOLEXP_NOT) *buftop++ = '('; unparse_boolexp1(player, b->sub1, b->type); *buftop++ = AND_TOKEN; unparse_boolexp1(player, b->sub2, b->type); if(outer_type == BOOLEXP_NOT) *buftop++ = ')'; break; case BOOLEXP_OR: if(outer_type == BOOLEXP_NOT || outer_type == BOOLEXP_AND) *buftop++ = '('; unparse_boolexp1(player, b->sub1, b->type); *buftop++ = OR_TOKEN; unparse_boolexp1(player, b->sub2, b->type); if(outer_type == BOOLEXP_NOT || outer_type == BOOLEXP_AND) *buftop++ = ')'; break; case BOOLEXP_NOT: *buftop++ = '!'; unparse_boolexp1(player, b->sub1, b->type); break; case BOOLEXP_CONST: strcpy(buftop, unparse_object(player, b->thing)); buftop += strlen(buftop); break; case BOOLEXP_PROP: strcpy(buftop, b->prop_name); strcat(buftop, ":"); if (b->prop_data) strcat(buftop, b->prop_data); buftop += strlen(buftop); break; default: abort(); /* bad type */ break; } } } char *unparse_boolexp(dbref player, boolexp *b) { buftop = boolexp_buf; unparse_boolexp1(player, b, BOOLEXP_CONST); /* no outer type */ *buftop++ = '\0'; return boolexp_buf; } #else /* MUSH */ static char boolexp_buf[BUFFER_LEN]; static char *buftop; static void unparse_boolexp1(player, b, outer_type, flag) dbref player; struct boolexp *b; boolexp_type outer_type; int flag; /* 0 is full unparse, 1 is numbers-only */ { char tbuf1[BUFFER_LEN]; if (b == TRUE_BOOLEXP) { safe_str((char *)"*UNLOCKED*", boolexp_buf, &buftop); return; } else { switch (b->type) { case BOOLEXP_AND: if (outer_type == BOOLEXP_NOT) { safe_chr('(', boolexp_buf, &buftop); } unparse_boolexp1(player, b->sub1, b->type, flag); safe_chr(AND_TOKEN, boolexp_buf, &buftop); unparse_boolexp1(player, b->sub2, b->type, flag); if (outer_type == BOOLEXP_NOT) { safe_chr(')', boolexp_buf, &buftop); } break; case BOOLEXP_OR: if (outer_type == BOOLEXP_NOT || outer_type == BOOLEXP_AND) { safe_chr('(', boolexp_buf, &buftop); } unparse_boolexp1(player, b->sub1, b->type, flag); safe_chr(OR_TOKEN, boolexp_buf, &buftop); unparse_boolexp1(player, b->sub2, b->type, flag); if (outer_type == BOOLEXP_NOT || outer_type == BOOLEXP_AND) { safe_chr(')', boolexp_buf, &buftop); } break; case BOOLEXP_IND: safe_chr(AT_TOKEN, boolexp_buf, &buftop); unparse_boolexp1(player, b->sub1, b->type, flag); break; case BOOLEXP_IS: safe_chr(IS_TOKEN, boolexp_buf, &buftop); unparse_boolexp1(player, b->sub1, b->type, flag); break; case BOOLEXP_CARRY: safe_chr(IN_TOKEN, boolexp_buf, &buftop); unparse_boolexp1(player, b->sub1, b->type, flag); break; case BOOLEXP_OWNER: safe_chr(OWNER_TOKEN, boolexp_buf, &buftop); unparse_boolexp1(player, b->sub1, b->type, flag); break; case BOOLEXP_NOT: safe_chr(NOT_TOKEN, boolexp_buf, &buftop); unparse_boolexp1(player, b->sub1, b->type, flag); break; case BOOLEXP_CONST: if (flag) { sprintf(tbuf1, "#%d", b->thing); safe_str(tbuf1, boolexp_buf, &buftop); } else safe_str(unparse_object(player, b->thing), boolexp_buf, &buftop); break; case BOOLEXP_PROP: strcpy(tbuf1, b->prop_name); strcat(tbuf1, ":"); if (b->prop_data) strcat(tbuf1, b->prop_data); safe_str(tbuf1, boolexp_buf, &buftop); break; case BOOLEXP_EVAL: /* sprintf(tbuf1, "%s/%s", b->atr_lock->name, uncompress(b->atr_lock->text)); */ sprintf(tbuf1, "%s/%s", b->prop_name, b->prop_data ? uncompress(b->prop_data) : ""); safe_str(tbuf1, boolexp_buf, &buftop); break; default: safe_str((char *)"Bad boolexp type!", boolexp_buf, &buftop); fprintf(stderr, "ERROR: unparse_boolexp1 bad boolexp type on #%d\n", player); break; } } } char *unparse_boolexp(dbref player, boolexp *b) { buftop = boolexp_buf; unparse_boolexp1(player, b, BOOLEXP_CONST, 0); /* no outer type */ *buftop++ = '\0'; return boolexp_buf; } #endif /* MUSH */