(file) Return to fieldprint.c CVS log (file) (dir) Up to [OMI] / omi / base

  1 krisbash 1.1 /*
  2              **==============================================================================
  3              **
  4              ** Open Management Infrastructure (OMI)
  5              **
  6              ** Copyright (c) Microsoft Corporation
  7              ** 
  8              ** Licensed under the Apache License, Version 2.0 (the "License"); you may not 
  9              ** use this file except in compliance with the License. You may obtain a copy 
 10              ** of the License at 
 11              **
 12              **     http://www.apache.org/licenses/LICENSE-2.0 
 13              **
 14              ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15              ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
 16              ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
 17              ** MERCHANTABLITY OR NON-INFRINGEMENT. 
 18              **
 19              ** See the Apache 2 License for the specific language governing permissions 
 20              ** and limitations under the License.
 21              **
 22 krisbash 1.1 **==============================================================================
 23              */
 24              
 25              #include "field.h"
 26              #include "indent.h"
 27              #include "miextras.h"
 28              #include <pal/format.h>
 29              #include "helpers.h"
 30              
 31              #define _BORROW 0x01
 32              
 33              void Field_Print(
 34                  const Field* self,
 35                  FILE* os, 
 36                  MI_Type type, 
 37                  MI_Uint32 level,
 38                  MI_Boolean showNulls,
 39                  MI_Boolean isClass)
 40              {
 41                  MI_Value v;
 42                  MI_Boolean e;
 43 krisbash 1.1     MI_Uint8 f;
 44                  Field_Extract(self, type, &v, &e, &f);
 45              
 46                  if (!e)
 47                  {
 48                      Ftprintf(os, ZT("NULL"));
 49                      return;
 50                  }
 51                  else 
 52                  {
 53                      switch (type)
 54                      {
 55                          case MI_BOOLEAN:
 56                          {
 57                              const MI_Boolean* p = (const MI_Boolean*)&v;
 58                              Ftprintf(os, ZT("%s"), scs(*p ? "true" : "false"));
 59                              break;
 60                          }
 61                          case MI_SINT8:
 62                          {
 63                              Ftprintf(os, ZT("%d"), *((const MI_Sint8*)&v));
 64 krisbash 1.1                 break;
 65                          }
 66                          case MI_UINT8:
 67                          {
 68                              Ftprintf(os, ZT("%u"), *((const MI_Uint8*)&v));
 69                              break;
 70                          }
 71                          case MI_SINT16:
 72                          {
 73                              Ftprintf(os, ZT("%d"), *((const MI_Sint16*)&v));
 74                              break;
 75                          }
 76                          case MI_UINT16:
 77                          {
 78                              Ftprintf(os, ZT("%u"), *((const MI_Uint16*)&v));
 79                              break;
 80                          }
 81                          case MI_SINT32:
 82                          {
 83                              Ftprintf(os, ZT("%d"), *((const MI_Sint32*)&v));
 84                              break;
 85 krisbash 1.1             }
 86                          case MI_UINT32:
 87                          {
 88                              Ftprintf(os, ZT("%u"), *((const MI_Uint32*)&v));
 89                              break;
 90                          }
 91                          case MI_SINT64:
 92                          {
 93                              Ftprintf(os, SINT64_FMT_T, *((const MI_Sint64*)&v));
 94                              break;
 95                          }
 96                          case MI_UINT64:
 97                          {
 98                              Ftprintf(os, UINT64_FMT_T, *((const MI_Uint64*)&v));
 99                              break;
100                          }
101                          case MI_REAL32:
102                          {
103                              Ftprintf(os, ZT("%g"), *((const MI_Real32*)&v));
104                              break;
105                          }
106 krisbash 1.1             case MI_REAL64:
107                          {
108                              Ftprintf(os, ZT("%g"), *((const MI_Real64*)&v));
109                              break;
110                          }
111                          case MI_CHAR16:
112                          {
113                              Ftprintf(os, ZT("%u"), *((const MI_Char16*)&v));
114                              break;
115                          }
116                          case MI_DATETIME:
117                          {
118                              ZChar buf[26];
119                              DatetimeToStr((const MI_Datetime*)&v, buf);
120                              Ftprintf(os, PAL_T("%T"), tcs(buf));
121                              break;
122                          }
123                          case MI_STRING:
124                          {
125                              Ftprintf(os, PAL_T("%T"), tcs(*((TChar**)&v)));
126                              break;
127 krisbash 1.1             }
128                          case MI_BOOLEANA:
129                          case MI_SINT8A:
130                          case MI_UINT8A:
131                          case MI_SINT16A:
132                          case MI_UINT16A:
133                          case MI_SINT32A:
134                          case MI_UINT32A:
135                          case MI_SINT64A:
136                          case MI_UINT64A:
137                          case MI_REAL32A:
138                          case MI_REAL64A:
139                          case MI_CHAR16A:
140                          case MI_DATETIMEA:
141                          {
142                              MI_BooleanA* arr = (MI_BooleanA*)&v;
143                              char* ptr = (char*)arr->data;
144                              MI_Uint32 i;
145              
146                              Ftprintf(os, ZT("{"));
147              
148 krisbash 1.1                 for (i = 0; i < arr->size; i++)
149                              {
150                                  MI_Type stype = Type_ScalarOf(type);
151                                  MI_Type ssize = Type_SizeOf(stype);
152                                  Field field;
153              
154                                  /* Build dummy field */
155                                  _Analysis_assume_(sizeof(field)==(ssize+sizeof(MI_Boolean)+sizeof(MI_Uint8)));
156                                  memcpy(&field, ptr, ssize);
157                                  *(MI_Boolean*)((char*)&field + ssize) = MI_TRUE;
158                                  *(MI_Uint8*)((char*)&field + ssize + 1) = 0;
159              
160                                  /* Print dummy field */
161                                  Field_Print(&field, os, stype, level, showNulls, isClass);
162                                  ptr += ssize;
163              
164                                  if (i + 1 != arr->size)
165                                      Ftprintf(os, ZT(", "));
166                              }
167              
168                              Ftprintf(os, ZT("}"));
169 krisbash 1.1                 break;
170                          }
171                          case MI_STRINGA:
172                          {
173                              MI_StringA* arr = (MI_StringA*)&v;
174                              MI_Uint32 i;
175              
176                              Ftprintf(os, ZT("{"));
177              
178                              for (i = 0; i < arr->size; i++)
179                              {
180                                  Ftprintf(os, PAL_T("%T"), tcs(arr->data[i]));
181              
182                                  if (i + 1 != arr->size)
183                                      Ftprintf(os, PAL_T(", "));
184                              }
185              
186                              Ftprintf(os, PAL_T("}"));
187                              break;
188                          }
189                          case MI_INSTANCE:
190 krisbash 1.1             case MI_REFERENCE:
191                          {
192                              MI_Instance* inst = *((MI_Instance**)&v);
193              
194                              if ( type == MI_REFERENCE)
195                                  Ftprintf(os, ZT(" REF "));
196              
197                              Instance_Print(inst, os, level, showNulls, isClass);
198                              break;
199                          }
200                          case MI_INSTANCEA:
201                          case MI_REFERENCEA:
202                          {
203                              MI_InstanceA* inst = ((MI_InstanceA*)&v);
204                              MI_Uint32 i;
205              
206                              if ( type == MI_REFERENCEA)
207                                  Ftprintf(os, ZT(" REF "));
208              
209              #if 0
210                              Ftprintf(os, "[%d]\n", (int)inst->size);
211 krisbash 1.1 #endif
212                              Ftprintf(os, ZT("\n"));
213              
214                              Indent(os, level);
215                              Ftprintf(os, ZT("{\n"));
216              
217                              for (i = 0; i < inst->size; i++)
218                              {
219                                  Instance_Print(inst->data[i], os, level + 1, showNulls, isClass);
220                              }
221              
222                              Indent(os, level);
223                              Ftprintf(os, ZT("}"));
224              
225                              break;
226                          }
227                          default:
228                              break;
229                      }
230                  }
231              }

ViewCVS 0.9.2