home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / tinymud2.zip / UNPARSE.C < prev    next >
C/C++ Source or Header  |  1990-09-02  |  3KB  |  120 lines

  1. #include "db.h"
  2.  
  3. #include "externs.h"
  4. #include "config.h"
  5. #include "interface.h"
  6.  
  7. static const char *unparse_flags(dbref thing)
  8. {
  9.     static char buf[BUFFER_LEN];
  10.     char *p;
  11.     const char *type_codes = TYPE_CODES;
  12.  
  13.     p = buf;
  14.     if(Typeof(thing) != TYPE_THING) *p++ = type_codes[Typeof(thing)];
  15.     if(db[thing].flags & ~TYPE_MASK) {
  16.     /* print flags */
  17.     if(db[thing].flags & WIZARD) *p++ = WIZARD_MARK;
  18. #ifdef ROBOT_MODE
  19.     if(db[thing].flags & ROBOT) *p++ = ROBOT_MARK;
  20. #endif ROBOT_MODE
  21.     if(db[thing].flags & STICKY) *p++ = STICKY_MARK;
  22.     if(db[thing].flags & DARK) *p++ = DARK_MARK;
  23.     if(db[thing].flags & LINK_OK) *p++ = LINK_MARK;
  24.     if(db[thing].flags & ABODE) *p++ = ABODE_MARK;
  25.     if(db[thing].flags & TEMPLE) *p++ = TEMPLE_MARK;
  26. #ifdef RESTRICTED_BUILDING
  27.     if(db[thing].flags & BUILDER) *p++ = BUILDER_MARK;
  28. #endif /* RESTRICTED_BUILDING */
  29.     if(db[thing].flags & HAVEN) *p++ = HAVEN_MARK;
  30.     if(db[thing].flags & UNWANTED) *p++ = UNWANTED_MARK;
  31. #ifdef GENDER
  32.     if(Genderof(thing) == GENDER_MALE) *p++ = MALE_MARK;
  33.     if(Genderof(thing) == GENDER_FEMALE) *p++ = FEMALE_MARK;
  34.     if(Genderof(thing) == GENDER_NEUTER) *p++ = NEUTER_MARK;
  35. #endif /* GENDER */
  36.     }
  37.     *p = '\0';
  38.     return buf;
  39. }
  40.  
  41. const char *unparse_object(dbref player, dbref loc)
  42. {
  43.     static char buf[BUFFER_LEN];
  44.  
  45.     switch(loc) {
  46.       case NOTHING:
  47.     return "*NOTHING*";
  48.       case HOME:
  49.     return "*HOME*";
  50.       default:
  51.     if(controls(player, loc) || can_link_to(player, NOTYPE, loc)
  52.        || (db[loc].flags & UNWANTED)) {
  53.         /* show everything */
  54.         sprintf(buf, "%s(#%d%s)", db[loc].name, loc, unparse_flags(loc));
  55.         return buf;
  56.     } else {
  57.         /* show only the name */
  58.         return db[loc].name;
  59.     }
  60.     }
  61. }
  62.  
  63. static char boolexp_buf[BUFFER_LEN];
  64. static char *buftop;
  65.  
  66. static void unparse_boolexp1(dbref player,
  67.                  struct boolexp *b, boolexp_type outer_type)
  68. {
  69.     if(b == TRUE_BOOLEXP) {
  70.     strcpy(buftop, "*UNLOCKED*");
  71.     buftop += strlen(buftop);
  72.     } else {
  73.     switch(b->type) {
  74.       case BOOLEXP_AND:
  75.         if(outer_type == BOOLEXP_NOT) {
  76.         *buftop++ = '(';
  77.         }
  78.         unparse_boolexp1(player, b->sub1, b->type);
  79.         *buftop++ = AND_TOKEN;
  80.         unparse_boolexp1(player, b->sub2, b->type);
  81.         if(outer_type == BOOLEXP_NOT) {
  82.         *buftop++ = ')';
  83.         }
  84.         break;
  85.       case BOOLEXP_OR:
  86.         if(outer_type == BOOLEXP_NOT || outer_type == BOOLEXP_AND) {
  87.         *buftop++ = '(';
  88.         }
  89.         unparse_boolexp1(player, b->sub1, b->type);
  90.         *buftop++ = OR_TOKEN;
  91.         unparse_boolexp1(player, b->sub2, b->type);
  92.         if(outer_type == BOOLEXP_NOT || outer_type == BOOLEXP_AND) {
  93.         *buftop++ = ')';
  94.         }
  95.         break;
  96.       case BOOLEXP_NOT:
  97.         *buftop++ = '!';
  98.         unparse_boolexp1(player, b->sub1, b->type);
  99.         break;
  100.       case BOOLEXP_CONST:
  101.         strcpy(buftop, unparse_object(player, b->thing));
  102.         buftop += strlen(buftop);
  103.         break;
  104.       default:
  105.         abort();        /* bad type */
  106.         break;
  107.     }
  108.     }
  109. }
  110.         
  111. const char *unparse_boolexp(dbref player, struct boolexp *b)
  112. {
  113.     buftop = boolexp_buf;
  114.     unparse_boolexp1(player, b, BOOLEXP_CONST);    /* no outer type */
  115.     *buftop++ = '\0';
  116.  
  117.     return boolexp_buf;
  118. }
  119.     
  120.