00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "stdgeorges.h"
00027
00028 #include "header.h"
00029 #include "nel/misc/thread.h"
00030 #include "nel/misc/i_xml.h"
00031 #include "nel/misc/common.h"
00032
00033 using namespace NLMISC;
00034
00035 namespace NLGEORGES
00036 {
00037
00038
00039
00040 void warning (bool exception, const char *format, ... );
00041
00042
00043
00044 CFileHeader::CFileHeader ()
00045 {
00046 MajorVersion = 0;
00047 MinorVersion = 0;
00048 State = Modified;
00049 Revision = "$R";
00050 Revision += "evision$";
00051 }
00052
00053
00054
00055 void CFileHeader::write (xmlNodePtr node, bool georges4CVS) const
00056 {
00057
00058 if (georges4CVS)
00059 {
00060
00061 xmlSetProp (node, (const xmlChar*)"Revision", (const xmlChar*)Revision.c_str ());
00062 }
00063 else
00064 {
00065
00066 char tmp[512];
00067 smprintf (tmp, 512, "%d.%d", MajorVersion, MinorVersion);
00068 xmlSetProp (node, (const xmlChar*)"Version", (const xmlChar*)tmp);
00069 }
00070
00071
00072 if (State == Modified)
00073 xmlSetProp (node, (const xmlChar*)"State", (const xmlChar*)"modified");
00074 else
00075 xmlSetProp (node, (const xmlChar*)"State", (const xmlChar*)"checked");
00076
00077
00078 if (!Comments.empty ())
00079 {
00080
00081 xmlNodePtr child = xmlNewChild ( node, NULL, (const xmlChar*)"COMMENTS", NULL);
00082 xmlNodePtr textNode = xmlNewText ((const xmlChar *)Comments.c_str());
00083 xmlAddChild (child, textNode);
00084 }
00085
00086
00087 if (!Log.empty ())
00088 {
00089
00090 xmlNodePtr child = xmlNewChild ( node, NULL, (const xmlChar*)"LOG", NULL);
00091 xmlNodePtr textNode = xmlNewText ((const xmlChar *)Log.c_str());
00092 xmlAddChild (child, textNode);
00093 }
00094 }
00095
00096
00097
00098 void CFileHeader::addLog (const char *log)
00099 {
00100 time_t t;
00101 time (&t);
00102 if (!Log.empty())
00103 Log += "\n";
00104 Log += ctime(&t);
00105 Log.resize (Log.size()-1);
00106 Log += " (";
00107 Log += IThread::getCurrentThread ()->getUserName ();
00108 Log += ") ";
00109 Log += log;
00110 }
00111
00112
00113
00114 void CFileHeader::setComments (const char *comments)
00115 {
00116 Comments = comments;
00117 }
00118
00119
00120
00121 void CFileHeader::read (xmlNodePtr root)
00122 {
00123
00124 const char *value = (const char*)xmlGetProp (root, (xmlChar*)"Version");
00125 if (value)
00126 {
00127
00128 if (sscanf (value, "%d.%d", &MajorVersion, &MinorVersion) != 2)
00129 {
00130
00131 xmlFree ((void*)value);
00132
00133
00134 warning (true, "read", "XML Syntax error in TYPE block line %d, the Version argument is invalid.",
00135 (int)root->content);
00136 }
00137
00138
00139 xmlFree ((void*)value);
00140 }
00141 else
00142 {
00143
00144 MajorVersion = 0;
00145 MinorVersion = 0;
00146 }
00147
00148
00149 value = (const char*)xmlGetProp (root, (xmlChar*)"Revision");
00150 if (value)
00151 {
00152
00153 Revision = value;
00154
00155
00156 xmlFree ((void*)value);
00157 }
00158 else
00159 {
00160
00161 Revision = "$R";
00162 Revision += "evision$";
00163 }
00164
00165
00166 value = (const char*)xmlGetProp (root, (xmlChar*)"State");
00167 if (value)
00168 {
00169
00170 if (strcmp (value, "modified") == 0)
00171 {
00172 State = Modified;
00173 }
00174 else if (strcmp (value, "checked") == 0)
00175 {
00176 State = Checked;
00177 }
00178 else
00179 {
00180
00181 xmlFree ((void*)value);
00182
00183
00184 warning (true, "read", "XML Syntax error in TYPE block line %d, the State argument is invalid.",
00185 (int)root->content);
00186 }
00187
00188
00189 xmlFree ((void*)value);
00190 }
00191 else
00192 {
00193
00194 State = Modified;
00195 }
00196
00197
00198 Comments = "";
00199 xmlNodePtr node = CIXml::getFirstChildNode (root, "COMMENTS");
00200 if (node)
00201 {
00202
00203 if (node = CIXml::getFirstChildNode (node, XML_TEXT_NODE))
00204 {
00205
00206 const char *comments = (const char*)xmlNodeGetContent (node);
00207 if (comments)
00208 {
00209 Comments = comments;
00210
00211
00212 xmlFree ((void*)comments);
00213 }
00214 }
00215 }
00216
00217
00218 Log = "";
00219 node = CIXml::getFirstChildNode (root, "LOG");
00220 if (node)
00221 {
00222
00223 if (node = CIXml::getFirstChildNode (node, XML_TEXT_NODE))
00224 {
00225
00226 const char *log = (const char*)xmlNodeGetContent (node);
00227 if (log)
00228 {
00229 Log = log;
00230
00231
00232 xmlFree ((void*)log);
00233 }
00234 }
00235 }
00236 }
00237
00238
00239
00240 const char *CFileHeader::getStateString (TState state)
00241 {
00242 if (state == Modified)
00243 return "Modified";
00244 else
00245 return "Checked";
00246 }
00247
00248
00249
00250 void CFileHeader::warning (bool exception, const char *function, const char *format, ... ) const
00251 {
00252
00253 va_list args;
00254 va_start( args, format );
00255 char buffer[1024];
00256 sint ret = vsnprintf( buffer, 1024, format, args );
00257 va_end( args );
00258
00259
00260 NLGEORGES::warning (exception, "(CFileHeader::%s) : %s", function, buffer);
00261 }
00262
00263
00264
00265 }