00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifdef _FEDM_LINUX
00033 #include <sys/time.h>
00034 #endif
00035 #include <time.h>
00036 #include "FEDM_XmlParser_IWriter.h"
00037 #include "FEDM_XmlParser_Base.h"
00038
00039
00040
00041
00042
00043 FEDM_XmlParser_Writer::FEDM_XmlParser_Writer(void)
00044 {
00045 m_pXmlParser = NULL;
00046 }
00047
00048 FEDM_XmlParser_Writer::~FEDM_XmlParser_Writer(void)
00049 {
00050 }
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 int FEDM_XmlParser_Writer::SerializeHeaderOut(FEDM_XML_TREEITEM* root, const char* szVendor)
00069 {
00070 if(root == NULL)
00071 {
00072 m_pXmlParser->SetLastError(FEDM_ERROR_NULL_POINTER);
00073 return FEDM_ERROR_NULL_POINTER;
00074 }
00075
00076 unsigned char ucTmp[2];
00077 wchar_t wcTmp[512];
00078 #ifdef _FEDM_WINDOWS
00079 #if _MSC_VER == 1200
00080 time_t long_time;
00081 struct tm* tmtime;
00082 #else
00083 #ifdef __BORLANDC__
00084 time_t long_time;
00085 struct tm* tmtime;
00086 #else
00087 __time64_t long_time;
00088 struct tm tmtime;
00089 #endif
00090 #endif
00091 #endif
00092 #ifdef _FEDM_LINUX
00093 time_t ltime;
00094 struct tm* tmtime;
00095 struct timeval tv;
00096 #endif
00097 FEDM_XML_TREEITEM* child = NULL;
00098 FEDM_XML_TREEITEM* parent = NULL;
00099
00100
00101 child = BuildTag(FEDM_XML_TAG_FILE_HDR_UC);
00102 if(child == NULL)
00103 {
00104 DeleteXmlTree();
00105 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00106 return m_pXmlParser->GetLastError();
00107 }
00108 AddTagItem(root, child);
00109 parent = child;
00110
00111
00112 child = BuildTag(FEDM_XML_TAG_DOC_TYPE_UC, false);
00113 if(child == NULL)
00114 {
00115 DeleteXmlTree();
00116 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00117 return m_pXmlParser->GetLastError();
00118 }
00119 #if defined(__BORLANDC__) || defined(_MSC_VER)
00120 #if _MSC_VER <= 1200
00121 swprintf(wcTmp, L"%S", m_pXmlParser->m_XmlHeader.szDocType);
00122 #else
00123 #if defined(_WIN32_WCE)
00124 swprintf(wcTmp, L"%S", m_pXmlParser->m_XmlHeader.szDocType);
00125 #else
00126 swprintf(wcTmp, 512, L"%S", m_pXmlParser->m_XmlHeader.szDocType);
00127 #endif
00128 #endif
00129 #else
00130 swprintf(wcTmp, 512, L"%s", m_pXmlParser->m_XmlHeader.szDocType);
00131 #endif
00132 AddTagValue(child, wcTmp);
00133 AddTagItem(parent, child);
00134
00135
00136 child = BuildTag(FEDM_XML_TAG_DOC_VERSION_UC, false);
00137 if(child == NULL)
00138 {
00139 DeleteXmlTree();
00140 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00141 return m_pXmlParser->GetLastError();
00142 }
00143 ucTmp[0] = (unsigned char)m_pXmlParser->m_XmlHeader.uiDocVersion;
00144 ucTmp[1] = (unsigned char)(m_pXmlParser->m_XmlHeader.uiDocVersion >> 8);
00145 #if defined(__BORLANDC__) || defined(_MSC_VER)
00146 #if _MSC_VER <= 1200
00147 swprintf(wcTmp, L"%d.%d", (int)ucTmp[1], (int)ucTmp[0]);
00148 #else
00149 #if defined(_WIN32_WCE)
00150 swprintf(wcTmp, L"%d.%d", (int)ucTmp[1], (int)ucTmp[0]);
00151 #else
00152 swprintf(wcTmp, 512, L"%d.%d", (int)ucTmp[1], (int)ucTmp[0]);
00153 #endif
00154 #endif
00155 #else
00156 swprintf(wcTmp, 512, L"%d.%d", (int)ucTmp[1], (int)ucTmp[0]);
00157 #endif
00158 AddTagValue(child, wcTmp);
00159 AddTagItem(parent, child);
00160
00161
00162 child = BuildTag(FEDM_XML_TAG_VENDOR_UC, false);
00163 if(child == NULL)
00164 {
00165 DeleteXmlTree();
00166 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00167 return m_pXmlParser->GetLastError();
00168 }
00169 if(strlen(szVendor) > 0)
00170 {
00171 #if defined(__BORLANDC__) || defined(_MSC_VER)
00172 #if _MSC_VER <= 1200
00173 swprintf(wcTmp, L"%S", szVendor);
00174 #else
00175 #if defined(_WIN32_WCE)
00176 swprintf(wcTmp, L"%S", szVendor);
00177 #else
00178 swprintf(wcTmp, 512, L"%S", szVendor);
00179 #endif
00180 #endif
00181 #else
00182 swprintf(wcTmp, 512, L"%s", szVendor);
00183 #endif
00184 AddTagValue(child, wcTmp);
00185 }
00186 else
00187 {
00188 AddTagValue(child, L"FEIG ELECTRONIC");
00189 }
00190 AddTagItem(parent, child);
00191
00192
00193 child = BuildTag(FEDM_XML_TAG_FEDM_VERSION_UC, false);
00194 if(child == NULL)
00195 {
00196 DeleteXmlTree();
00197 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00198 return m_pXmlParser->GetLastError();
00199 }
00200 AddTagValue(child, FEDM_VERSION_UC);
00201 AddTagItem(parent, child);
00202
00203
00204 child = BuildTag(FEDM_XML_TAG_DATE_UC, false);
00205 if(child == NULL)
00206 {
00207 DeleteXmlTree();
00208 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00209 return m_pXmlParser->GetLastError();
00210 }
00211
00212 #ifdef _FEDM_WINDOWS
00213 #if _MSC_VER == 1200
00214 time( &long_time );
00215 tmtime = localtime( &long_time );
00216 wcsftime(wcTmp, 128, L"%Y-%m-%d", tmtime);
00217 #else
00218 #ifdef __BORLANDC__
00219 time( &long_time );
00220 tmtime = localtime( &long_time );
00221 wcsftime(wcTmp, 128, L"%Y-%m-%d", tmtime);
00222 #else
00223 _time64( &long_time );
00224
00225 _localtime64_s( &tmtime, &long_time );
00226 wcsftime(wcTmp, 128, L"%Y-%m-%d", &tmtime);
00227 #endif
00228 #endif
00229 #endif
00230
00231 #ifdef _FEDM_LINUX
00232 gettimeofday(&tv, NULL);
00233 ltime = tv.tv_sec;
00234 tmtime = localtime(<ime);
00235 wcsftime(wcTmp, 128, L"%Y-%m-%d", tmtime);
00236 #endif
00237 AddTagValue(child, wcTmp);
00238 AddTagItem(parent, child);
00239
00240
00241 child = BuildTag(FEDM_XML_TAG_TIME_UC, false);
00242 if(child == NULL)
00243 {
00244 DeleteXmlTree();
00245 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00246 return m_pXmlParser->GetLastError();
00247 }
00248
00249 #ifdef _FEDM_WINDOWS
00250 #if _MSC_VER == 1200
00251 wcsftime(wcTmp, 128, L"%X", tmtime);
00252 #else
00253 #ifdef __BORLANDC__
00254 wcsftime(wcTmp, 128, L"%X", tmtime);
00255 #else
00256 wcsftime(wcTmp, 128, L"%X", &tmtime);
00257 #endif
00258 #endif
00259 #endif
00260
00261 #ifdef _FEDM_LINUX
00262 wcsftime(wcTmp, 128, L"%X", tmtime);
00263 #endif
00264
00265 AddTagValue(child, wcTmp);
00266 AddTagItem(parent, child);
00267
00268
00269 child = BuildTag(FEDM_XML_TAG_COMMENT_UC, false);
00270 if(child == NULL)
00271 {
00272 DeleteXmlTree();
00273 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00274 return m_pXmlParser->GetLastError();
00275 }
00276 #if defined(__BORLANDC__) || defined(_MSC_VER)
00277 #if _MSC_VER <= 1200
00278 swprintf(wcTmp, L"%S", m_pXmlParser->m_XmlHeader.szComment);
00279 #else
00280 #if defined(_WIN32_WCE)
00281 swprintf(wcTmp, L"%S", m_pXmlParser->m_XmlHeader.szComment);
00282 #else
00283 swprintf(wcTmp, 512, L"%S", m_pXmlParser->m_XmlHeader.szComment);
00284 #endif
00285 #endif
00286 #else
00287 swprintf(wcTmp, 512, L"%s", m_pXmlParser->m_XmlHeader.szComment);
00288 #endif
00289 AddTagValue(child, wcTmp);
00290 AddTagItem(parent, child);
00291
00292
00293 child = BuildTag(FEDM_XML_TAG_CRC_UC, false);
00294 if(child == NULL)
00295 {
00296 DeleteXmlTree();
00297 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00298 return m_pXmlParser->GetLastError();
00299 }
00300 #if defined(__BORLANDC__) || defined(_MSC_VER)
00301 #if _MSC_VER <= 1200
00302 swprintf(wcTmp, L"%d", m_pXmlParser->m_XmlHeader.uiCrc);
00303 #else
00304 #if defined(_WIN32_WCE)
00305 swprintf(wcTmp, L"%d", m_pXmlParser->m_XmlHeader.uiCrc);
00306 #else
00307 swprintf(wcTmp, 512, L"%d", m_pXmlParser->m_XmlHeader.uiCrc);
00308 #endif
00309 #endif
00310 #else
00311 swprintf(wcTmp, 512, L"%d", m_pXmlParser->m_XmlHeader.uiCrc);
00312 #endif
00313 AddTagValue(child, wcTmp);
00314 AddTagItem(parent, child);
00315
00316 m_pXmlParser->SetLastError(FEDM_OK);
00317 return m_pXmlParser->GetLastError();
00318 }