blob: d434642d7169fe4c600c9fdaabdf8fd0c9dace00 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001// MorgenGrauen MUDlib
2//
3// thing/util.c -- Utilities
4//
5// $Id: util.c 6366 2007-07-15 21:06:24Z Zesstra $
6
7#define NEED_PROTOTYPES
8#include "/sys/thing/util.h"
9#include "/sys/thing/properties.h"
10
11#pragma strict_types
12#pragma save_types
13#pragma range_check
14#pragma no_clone
15#pragma pedantic
16
17public 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
31static 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
55static 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
73static 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
99static 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}