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