MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | // MorgenGrauen MUDlib |
| 2 | // |
| 3 | // player/util. -- Utilities |
| 4 | // |
| 5 | // $Id: util.c 6371 2007-07-17 22:46:50Z Zesstra $ |
| 6 | #pragma strict_types |
| 7 | #pragma save_types |
| 8 | #pragma range_check |
| 9 | #pragma no_clone |
| 10 | #pragma pedantic |
| 11 | |
| 12 | #define NEED_PROTOTYPES |
| 13 | |
| 14 | #include "/sys/player/util.h" |
| 15 | #include "/sys/thing/properties.h" |
| 16 | |
| 17 | public void ShowPropList(string *props) |
| 18 | { |
| 19 | int i,j; |
| 20 | |
| 21 | j=sizeof(props); |
| 22 | |
| 23 | for ( i=0; i<j ; i++) |
| 24 | { |
| 25 | write("*"+props[i]+": "); |
| 26 | PrettyDump(QueryProp(props[i])); |
| 27 | write("\n"); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | static void PrettyDump(mixed x) |
| 32 | { |
| 33 | if (pointerp(x)) |
| 34 | { |
| 35 | DumpArray(x); |
| 36 | } |
| 37 | else if (mappingp(x)) |
| 38 | { |
| 39 | DumpMapping(x); |
| 40 | } |
| 41 | else if (objectp(x)) |
| 42 | { |
| 43 | write ("OBJ("+object_name(x)+")"); |
| 44 | } |
| 45 | else if (stringp(x)) |
| 46 | { |
| 47 | write("\""+x+"\""); |
| 48 | } |
| 49 | else |
| 50 | { |
| 51 | write (x); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | static void DumpArray(mixed *x) |
| 56 | { |
| 57 | int i,j; |
| 58 | |
| 59 | write ("({ "); |
| 60 | if ( (j=sizeof(x))>0 ) |
| 61 | { |
| 62 | for ( i=0 ; i<(j-1) ; i++) |
| 63 | { |
| 64 | PrettyDump(x[i]); |
| 65 | write(", "); |
| 66 | } |
| 67 | PrettyDump(x[i]); |
| 68 | write(" "); |
| 69 | } |
| 70 | write ("})"); |
| 71 | } |
| 72 | |
| 73 | static void DumpMapping(mapping x) |
| 74 | { |
| 75 | int i, c, s; |
| 76 | mixed *ind; |
| 77 | |
| 78 | write("([ "); |
| 79 | |
| 80 | if ( (c=sizeof(ind=m_indices(x)))<1 ) |
| 81 | { |
| 82 | write(" ])"); |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | s=get_type_info(x,1); |
| 87 | |
| 88 | DumpKeyValPair(x, ind[0], s); |
| 89 | for ( i=1 ; i<c ; i++ ) |
| 90 | { |
| 91 | write(", "); |
| 92 | DumpKeyValPair(x, ind[i], s); |
| 93 | } |
| 94 | write(" ])"); |
| 95 | } |
| 96 | |
| 97 | // Lacht nicht ueber den Namen!!! -Boing |
| 98 | // Nein, ueber den Namen lache ich nicht ... -Paracelsus |
| 99 | static void DumpKeyValPair(mapping x, mixed key, int size) |
| 100 | { int j, vc; |
| 101 | |
| 102 | PrettyDump(key); |
| 103 | write(" : "); |
| 104 | PrettyDump(x[key,0]); |
| 105 | |
| 106 | for ( j=1; j<size; j++) |
| 107 | { |
| 108 | write("; "); |
| 109 | PrettyDump(x[key, j]); |
| 110 | } |
| 111 | } |