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