Browse Source

some minor cleanup

David Rose 16 years ago
parent
commit
6b6a90e1b0

+ 29 - 9
direct/src/plugin/binaryXml.cxx

@@ -104,7 +104,7 @@ write_xml_node(ostream &out, TiXmlNode *xnode) {
 //               return value.  Returns NULL on error.
 //               return value.  Returns NULL on error.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 static TiXmlNode *
 static TiXmlNode *
-read_xml_node(istream &in) {
+read_xml_node(istream &in, char *&buffer, size_t &buffer_length) {
   NodeType type = (NodeType)in.get();
   NodeType type = (NodeType)in.get();
   if (type == NT_unknown) {
   if (type == NT_unknown) {
     return NULL;
     return NULL;
@@ -116,10 +116,14 @@ read_xml_node(istream &in) {
     return NULL;
     return NULL;
   }
   }
 
 
-  char *buffer = new char[value_length];
+  if (value_length > buffer_length) {
+    delete[] buffer;
+    buffer_length = value_length;
+    buffer = new char[buffer_length];
+  }
+
   in.read(buffer, value_length);
   in.read(buffer, value_length);
   string value(buffer, value_length);
   string value(buffer, value_length);
-  delete[] buffer;
 
 
   TiXmlNode *xnode = NULL;
   TiXmlNode *xnode = NULL;
   if (type == NT_element) {
   if (type == NT_element) {
@@ -147,10 +151,14 @@ read_xml_node(istream &in) {
         return NULL;
         return NULL;
       }
       }
 
 
-      buffer = new char[name_length];
+      if (name_length > buffer_length) {
+        delete[] buffer;
+        buffer_length = name_length;
+        buffer = new char[buffer_length];
+      }
+
       in.read(buffer, name_length);
       in.read(buffer, name_length);
       string name(buffer, name_length);
       string name(buffer, name_length);
-      delete[] buffer;
 
 
       size_t value_length;
       size_t value_length;
       in.read((char *)&value_length, sizeof(value_length));
       in.read((char *)&value_length, sizeof(value_length));
@@ -159,10 +167,14 @@ read_xml_node(istream &in) {
         return NULL;
         return NULL;
       }
       }
 
 
-      buffer = new char[value_length];
+      if (value_length > buffer_length) {
+        delete[] buffer;
+        buffer_length = value_length;
+        buffer = new char[buffer_length];
+      }
+
       in.read(buffer, value_length);
       in.read(buffer, value_length);
       string value(buffer, value_length);
       string value(buffer, value_length);
-      delete[] buffer;
 
 
       xelement->SetAttribute(name, value);
       xelement->SetAttribute(name, value);
 
 
@@ -175,7 +187,7 @@ read_xml_node(istream &in) {
   
   
   while (got_child && in && !in.eof()) {
   while (got_child && in && !in.eof()) {
     // We have a child.
     // We have a child.
-    TiXmlNode *xchild = read_xml_node(in);
+    TiXmlNode *xchild = read_xml_node(in, buffer, buffer_length);
     if (xchild != NULL) {
     if (xchild != NULL) {
       xnode->LinkEndChild(xchild);
       xnode->LinkEndChild(xchild);
     }
     }
@@ -201,6 +213,11 @@ write_xml(ostream &out, TiXmlDocument *doc, ostream &logfile) {
 
 
 #else
 #else
   // Formatted ASCII write.
   // Formatted ASCII write.
+
+  // We need a declaration to write it safely.
+  TiXmlDeclaration decl("1.0", "utf-8", "");
+  doc->InsertBeforeChild(doc->FirstChild(), decl);
+
   out << *doc;
   out << *doc;
 #endif
 #endif
 
 
@@ -232,7 +249,10 @@ TiXmlDocument *
 read_xml(istream &in, ostream &logfile) {
 read_xml(istream &in, ostream &logfile) {
 #if DO_BINARY_XML
 #if DO_BINARY_XML
   // binary read.
   // binary read.
-  TiXmlNode *xnode = read_xml_node(in);
+  size_t buffer_length = 128;
+  char *buffer = new char[buffer_length];
+  TiXmlNode *xnode = read_xml_node(in, buffer, buffer_length);
+  delete[] buffer;
   if (xnode == NULL) {
   if (xnode == NULL) {
     return NULL;
     return NULL;
   }
   }

+ 3 - 12
direct/src/plugin/p3dInstance.cxx

@@ -94,7 +94,7 @@ P3DInstance::
   P3D_OBJECT_XDECREF(_browser_script_object);
   P3D_OBJECT_XDECREF(_browser_script_object);
 
 
   nout << "panda_script_object ref = "
   nout << "panda_script_object ref = "
-       << _panda_script_object->_ref_count << "\n" << flush;
+       << _panda_script_object->_ref_count << "\n";
   P3D_OBJECT_DECREF(_panda_script_object);
   P3D_OBJECT_DECREF(_panda_script_object);
 
 
   // Tell all of the packages that we're no longer in business for
   // Tell all of the packages that we're no longer in business for
@@ -208,7 +208,6 @@ set_wparams(const P3DWindowParams &wparams) {
   // Update the instance in the sub-process.
   // Update the instance in the sub-process.
   if (_session != NULL) {
   if (_session != NULL) {
     TiXmlDocument *doc = new TiXmlDocument;
     TiXmlDocument *doc = new TiXmlDocument;
-    TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
     TiXmlElement *xcommand = new TiXmlElement("command");
     TiXmlElement *xcommand = new TiXmlElement("command");
     xcommand->SetAttribute("cmd", "setup_window");
     xcommand->SetAttribute("cmd", "setup_window");
     xcommand->SetAttribute("instance_id", get_instance_id());
     xcommand->SetAttribute("instance_id", get_instance_id());
@@ -247,7 +246,6 @@ set_wparams(const P3DWindowParams &wparams) {
     }
     }
 #endif   // __APPLE__
 #endif   // __APPLE__
     
     
-    doc->LinkEndChild(decl);
     doc->LinkEndChild(xcommand);
     doc->LinkEndChild(xcommand);
     xcommand->LinkEndChild(xwparams);
     xcommand->LinkEndChild(xwparams);
 
 
@@ -466,8 +464,7 @@ feed_url_stream(int unique_id,
                 size_t this_data_size) {
                 size_t this_data_size) {
   Downloads::iterator di = _downloads.find(unique_id);
   Downloads::iterator di = _downloads.find(unique_id);
   if (di == _downloads.end()) {
   if (di == _downloads.end()) {
-    nout << "Unexpected feed_url_stream for " << unique_id << "\n"
-         << flush;
+    nout << "Unexpected feed_url_stream for " << unique_id << "\n";
     // Don't know this request.
     // Don't know this request.
     return false;
     return false;
   }
   }
@@ -696,7 +693,6 @@ make_xml() {
 void P3DInstance::
 void P3DInstance::
 send_browser_script_object() {
 send_browser_script_object() {
   TiXmlDocument *doc = new TiXmlDocument;
   TiXmlDocument *doc = new TiXmlDocument;
-  TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
   TiXmlElement *xcommand = new TiXmlElement("command");
   TiXmlElement *xcommand = new TiXmlElement("command");
   xcommand->SetAttribute("cmd", "pyobj");
   xcommand->SetAttribute("cmd", "pyobj");
   xcommand->SetAttribute("op", "set_browser_script_object");
   xcommand->SetAttribute("op", "set_browser_script_object");
@@ -704,7 +700,6 @@ send_browser_script_object() {
     xcommand->LinkEndChild(_session->p3dobj_to_xml(_browser_script_object));
     xcommand->LinkEndChild(_session->p3dobj_to_xml(_browser_script_object));
   }
   }
   
   
-  doc->LinkEndChild(decl);
   doc->LinkEndChild(xcommand);
   doc->LinkEndChild(xcommand);
   
   
   _session->send_command(doc);
   _session->send_command(doc);
@@ -793,17 +788,15 @@ void P3DInstance::
 handle_notify_request(const string &message) {
 handle_notify_request(const string &message) {
   // We look for certain notify events that have particular meaning
   // We look for certain notify events that have particular meaning
   // to this instance.
   // to this instance.
-  nout << "Got notify: " << message << "\n" << flush;
+  nout << "Got notify: " << message << "\n";
   if (message == "onpythonload") {
   if (message == "onpythonload") {
     // Once Python is up and running, we can get the actual toplevel
     // Once Python is up and running, we can get the actual toplevel
     // object from the Python side, and merge it with our own.
     // object from the Python side, and merge it with our own.
 
 
     TiXmlDocument *doc = new TiXmlDocument;
     TiXmlDocument *doc = new TiXmlDocument;
-    TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
     TiXmlElement *xcommand = new TiXmlElement("command");
     TiXmlElement *xcommand = new TiXmlElement("command");
     xcommand->SetAttribute("cmd", "pyobj");
     xcommand->SetAttribute("cmd", "pyobj");
     xcommand->SetAttribute("op", "get_panda_script_object");
     xcommand->SetAttribute("op", "get_panda_script_object");
-    doc->LinkEndChild(decl);
     doc->LinkEndChild(xcommand);
     doc->LinkEndChild(xcommand);
     TiXmlDocument *response = _session->command_and_response(doc);
     TiXmlDocument *response = _session->command_and_response(doc);
     
     
@@ -859,12 +852,10 @@ handle_script_request(const string &operation, P3D_object *object,
                       bool needs_response, int unique_id) {
                       bool needs_response, int unique_id) {
 
 
   TiXmlDocument *doc = new TiXmlDocument;
   TiXmlDocument *doc = new TiXmlDocument;
-  TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
   TiXmlElement *xcommand = new TiXmlElement("command");
   TiXmlElement *xcommand = new TiXmlElement("command");
   xcommand->SetAttribute("cmd", "script_response");
   xcommand->SetAttribute("cmd", "script_response");
   xcommand->SetAttribute("unique_id", unique_id);
   xcommand->SetAttribute("unique_id", unique_id);
   
   
-  doc->LinkEndChild(decl);
   doc->LinkEndChild(xcommand);
   doc->LinkEndChild(xcommand);
 
 
   if (operation == "get_property") {
   if (operation == "get_property") {

+ 4 - 4
direct/src/plugin/p3dInstanceManager.cxx

@@ -85,7 +85,7 @@ P3DInstanceManager::
        << " " << _none_object->_ref_count
        << " " << _none_object->_ref_count
        << " " << _true_object->_ref_count
        << " " << _true_object->_ref_count
        << " " << _false_object->_ref_count
        << " " << _false_object->_ref_count
-       << "\n" << flush;
+       << "\n";
 
 
   /*
   /*
   assert(_undefined_object->_ref_count == 1);
   assert(_undefined_object->_ref_count == 1);
@@ -119,10 +119,10 @@ initialize() {
   _platform = P3D_PLUGIN_PLATFORM;
   _platform = P3D_PLUGIN_PLATFORM;
 
 
   nout << "_root_dir = " << _root_dir << ", download = " 
   nout << "_root_dir = " << _root_dir << ", download = " 
-       << _download_url << "\n" << flush;
+       << _download_url << "\n";
 
 
   if (_root_dir.empty()) {
   if (_root_dir.empty()) {
-    nout << "Could not find root directory.\n" << flush;
+    nout << "Could not find root directory.\n";
     return false;
     return false;
   }
   }
 
 
@@ -158,7 +158,7 @@ bool P3DInstanceManager::
 start_instance(P3DInstance *inst, const string &p3d_filename,
 start_instance(P3DInstance *inst, const string &p3d_filename,
                const P3D_token tokens[], size_t num_tokens) {
                const P3D_token tokens[], size_t num_tokens) {
   if (inst->is_started()) {
   if (inst->is_started()) {
-    nout << "Instance started twice: " << inst << "\n" << flush;
+    nout << "Instance started twice: " << inst << "\n";
     return false;
     return false;
   }
   }
   inst->set_fparams(P3DFileParams(p3d_filename, tokens, num_tokens));
   inst->set_fparams(P3DFileParams(p3d_filename, tokens, num_tokens));

+ 1 - 1
direct/src/plugin/p3dObject.cxx

@@ -112,7 +112,7 @@ static void
 generic_finish(P3D_object *object) {
 generic_finish(P3D_object *object) {
   // You must override finish(), though, otherwise it's a leak.  The
   // You must override finish(), though, otherwise it's a leak.  The
   // core API has no idea how to delete your object.
   // core API has no idea how to delete your object.
-  nout << "Warning!  default object_finish() method does nothing; object will leak.\n" << flush;
+  nout << "Warning!  default object_finish() method does nothing; object will leak.\n";
 }
 }
 
 
 static P3D_object_type 
 static P3D_object_type 

+ 27 - 25
direct/src/plugin/p3dOsxSplashWindow.cxx

@@ -257,31 +257,33 @@ paint_window() {
   PaintRect(&rdone);
   PaintRect(&rdone);
   EraseRect(&rneed);
   EraseRect(&rneed);
 
 
-  RGBColor black = { 0, 0, 0 };
-  RGBForeColor(&black);
-
-  TextFont(0);
-  TextFace(bold);
-  TextMode(srcOr);
-  TextSize(0);
-
-  Point numer = { 1, 1 };
-  Point denom = { 1, 1 };
-  FontInfo font_info;
-  StdTxMeas(_install_label.size(), _install_label.data(), &numer, &denom, &font_info);
-  int ascent = font_info.ascent * numer.v / denom.v;
-  int descent = font_info.descent * numer.v / denom.v;
-
-  int text_width = TextWidth(_install_label.data(), 0, _install_label.size());
-  int text_x = (win_width - text_width) / 2;
-  int text_y = bar_y - descent - 8;
-
-  Rect rtext = { text_y - ascent - 2, text_x - 2, 
-                 text_y + descent + 2, text_x + text_width + 2 }; 
-  EraseRect(&rtext);
-
-  MoveTo(text_x, text_y);
-  DrawText(_install_label.data(), 0, _install_label.size());
+  if (!_install_label.empty()) {
+    RGBColor black = { 0, 0, 0 };
+    RGBForeColor(&black);
+    
+    TextFont(0);
+    TextFace(bold);
+    TextMode(srcOr);
+    TextSize(0);
+    
+    Point numer = { 1, 1 };
+    Point denom = { 1, 1 };
+    FontInfo font_info;
+    StdTxMeas(_install_label.size(), _install_label.data(), &numer, &denom, &font_info);
+    int ascent = font_info.ascent * numer.v / denom.v;
+    int descent = font_info.descent * numer.v / denom.v;
+
+    int text_width = TextWidth(_install_label.data(), 0, _install_label.size());
+    int text_x = (win_width - text_width) / 2;
+    int text_y = bar_y - descent - 8;
+    
+    Rect rtext = { text_y - ascent - 2, text_x - 2, 
+                   text_y + descent + 2, text_x + text_width + 2 }; 
+    EraseRect(&rtext);
+
+    MoveTo(text_x, text_y);
+    DrawText(_install_label.data(), 0, _install_label.size());
+  }
 
 
   if (portChanged) {
   if (portChanged) {
     QDSwapPort(portSave, NULL);
     QDSwapPort(portSave, NULL);

+ 0 - 2
direct/src/plugin/p3dPythonObject.cxx

@@ -235,7 +235,6 @@ P3D_object *P3DPythonObject::
 call(const string &method_name, bool needs_response,
 call(const string &method_name, bool needs_response,
      P3D_object *params[], int num_params) {
      P3D_object *params[], int num_params) {
   TiXmlDocument *doc = new TiXmlDocument;
   TiXmlDocument *doc = new TiXmlDocument;
-  TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
   TiXmlElement *xcommand = new TiXmlElement("command");
   TiXmlElement *xcommand = new TiXmlElement("command");
   xcommand->SetAttribute("cmd", "pyobj");
   xcommand->SetAttribute("cmd", "pyobj");
   xcommand->SetAttribute("op", "call");
   xcommand->SetAttribute("op", "call");
@@ -252,7 +251,6 @@ call(const string &method_name, bool needs_response,
     xcommand->LinkEndChild(xparams);
     xcommand->LinkEndChild(xparams);
   }
   }
 
 
-  doc->LinkEndChild(decl);
   doc->LinkEndChild(xcommand);
   doc->LinkEndChild(xcommand);
 
 
   // If no response is requested, send the command out in a vacuum,
   // If no response is requested, send the command out in a vacuum,

+ 4 - 10
direct/src/plugin/p3dPythonRun.cxx

@@ -335,10 +335,8 @@ handle_command(TiXmlDocument *doc) {
         if (needs_response) {
         if (needs_response) {
           // Better send a response.
           // Better send a response.
           TiXmlDocument doc;
           TiXmlDocument doc;
-          TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
           TiXmlElement *xresponse = new TiXmlElement("response");
           TiXmlElement *xresponse = new TiXmlElement("response");
           xresponse->SetAttribute("response_id", want_response_id);
           xresponse->SetAttribute("response_id", want_response_id);
-          doc.LinkEndChild(decl);
           doc.LinkEndChild(xresponse);
           doc.LinkEndChild(xresponse);
           write_xml(_pipe_write, &doc, nout);
           write_xml(_pipe_write, &doc, nout);
         }
         }
@@ -359,10 +357,8 @@ void P3DPythonRun::
 handle_pyobj_command(TiXmlElement *xcommand, bool needs_response,
 handle_pyobj_command(TiXmlElement *xcommand, bool needs_response,
                      int want_response_id) {
                      int want_response_id) {
   TiXmlDocument doc;
   TiXmlDocument doc;
-  TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
   TiXmlElement *xresponse = new TiXmlElement("response");
   TiXmlElement *xresponse = new TiXmlElement("response");
   xresponse->SetAttribute("response_id", want_response_id);
   xresponse->SetAttribute("response_id", want_response_id);
-  doc.LinkEndChild(decl);
   doc.LinkEndChild(xresponse);
   doc.LinkEndChild(xresponse);
 
 
   const char *op = xcommand->Attribute("op");
   const char *op = xcommand->Attribute("op");
@@ -601,7 +597,7 @@ handle_pyobj_command(TiXmlElement *xcommand, bool needs_response,
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void P3DPythonRun::
 void P3DPythonRun::
 check_comm() {
 check_comm() {
-  //  nout << ":" << flush;
+  //  nout << ":";
   ACQUIRE_LOCK(_commands_lock);
   ACQUIRE_LOCK(_commands_lock);
   while (!_commands.empty()) {
   while (!_commands.empty()) {
     TiXmlDocument *doc = _commands.front();
     TiXmlDocument *doc = _commands.front();
@@ -647,7 +643,7 @@ st_check_comm(PyObject *, PyObject *args) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 TiXmlDocument *P3DPythonRun::
 TiXmlDocument *P3DPythonRun::
 wait_script_response(int response_id) {
 wait_script_response(int response_id) {
-  //  nout << "waiting script_response " << response_id << "\n" << flush;
+  //  nout << "waiting script_response " << response_id << "\n";
   while (true) {
   while (true) {
     Commands::iterator ci;
     Commands::iterator ci;
 
 
@@ -694,7 +690,7 @@ wait_script_response(int response_id) {
           // This is the response we were waiting for.
           // This is the response we were waiting for.
           _responses.erase(ci);
           _responses.erase(ci);
           _responses_lock.release();
           _responses_lock.release();
-          //          nout << "got script_response " << unique_id << "\n" << flush;
+          //          nout << "got script_response " << unique_id << "\n";
           return doc;
           return doc;
         }
         }
       }
       }
@@ -716,7 +712,7 @@ wait_script_response(int response_id) {
     PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE | PM_NOYIELD);
     PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE | PM_NOYIELD);
 #endif  // _WIN32
 #endif  // _WIN32
 
 
-    //    nout << "." << flush;
+    //    nout << ".";
 
 
     // It hasn't shown up yet.  Give the sub-thread a chance to
     // It hasn't shown up yet.  Give the sub-thread a chance to
     // process the input and append it to the queue.
     // process the input and append it to the queue.
@@ -771,11 +767,9 @@ py_request_func(PyObject *args) {
   }
   }
 
 
   TiXmlDocument doc;
   TiXmlDocument doc;
-  TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
   TiXmlElement *xrequest = new TiXmlElement("request");
   TiXmlElement *xrequest = new TiXmlElement("request");
   xrequest->SetAttribute("instance_id", instance_id);
   xrequest->SetAttribute("instance_id", instance_id);
   xrequest->SetAttribute("rtype", request_type);
   xrequest->SetAttribute("rtype", request_type);
-  doc.LinkEndChild(decl);
   doc.LinkEndChild(xrequest);
   doc.LinkEndChild(xrequest);
 
 
   if (strcmp(request_type, "notify") == 0) {
   if (strcmp(request_type, "notify") == 0) {

+ 12 - 22
direct/src/plugin/p3dSession.cxx

@@ -104,10 +104,8 @@ shutdown() {
   if (_p3dpython_running) {
   if (_p3dpython_running) {
     // Tell the process we're going away.
     // Tell the process we're going away.
     TiXmlDocument doc;
     TiXmlDocument doc;
-    TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
     TiXmlElement *xcommand = new TiXmlElement("command");
     TiXmlElement *xcommand = new TiXmlElement("command");
     xcommand->SetAttribute("cmd", "exit");
     xcommand->SetAttribute("cmd", "exit");
-    doc.LinkEndChild(decl);
     doc.LinkEndChild(xcommand);
     doc.LinkEndChild(xcommand);
     write_xml(_pipe_write, &doc, nout);
     write_xml(_pipe_write, &doc, nout);
 
 
@@ -124,7 +122,7 @@ shutdown() {
     // Now give the process a chance to terminate itself cleanly.
     // Now give the process a chance to terminate itself cleanly.
     if (WaitForSingleObject(_p3dpython_handle, max_wait_ms) == WAIT_TIMEOUT) {
     if (WaitForSingleObject(_p3dpython_handle, max_wait_ms) == WAIT_TIMEOUT) {
       // It didn't shut down cleanly, so kill it the hard way.
       // It didn't shut down cleanly, so kill it the hard way.
-      nout << "Force-killing python process.\n" << flush;
+      nout << "Force-killing python process.\n";
       TerminateProcess(_p3dpython_handle, 2);
       TerminateProcess(_p3dpython_handle, 2);
     }
     }
 
 
@@ -153,7 +151,7 @@ shutdown() {
       if (elapsed > max_wait_ms) {
       if (elapsed > max_wait_ms) {
         // Tired of waiting.  Kill the process.
         // Tired of waiting.  Kill the process.
         nout << "Force-killing python process, pid " << _p3dpython_pid 
         nout << "Force-killing python process, pid " << _p3dpython_pid 
-             << "\n" << flush;
+             << "\n";
         kill(_p3dpython_pid, SIGKILL);
         kill(_p3dpython_pid, SIGKILL);
         start_ms = now_ms;
         start_ms = now_ms;
       }
       }
@@ -218,12 +216,10 @@ start_instance(P3DInstance *inst) {
   assert(inserted);
   assert(inserted);
 
 
   TiXmlDocument *doc = new TiXmlDocument;
   TiXmlDocument *doc = new TiXmlDocument;
-  TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
   TiXmlElement *xcommand = new TiXmlElement("command");
   TiXmlElement *xcommand = new TiXmlElement("command");
   xcommand->SetAttribute("cmd", "start_instance");
   xcommand->SetAttribute("cmd", "start_instance");
   TiXmlElement *xinstance = inst->make_xml();
   TiXmlElement *xinstance = inst->make_xml();
   
   
-  doc->LinkEndChild(decl);
   doc->LinkEndChild(xcommand);
   doc->LinkEndChild(xcommand);
   xcommand->LinkEndChild(xinstance);
   xcommand->LinkEndChild(xinstance);
 
 
@@ -252,12 +248,10 @@ start_instance(P3DInstance *inst) {
 void P3DSession::
 void P3DSession::
 terminate_instance(P3DInstance *inst) {
 terminate_instance(P3DInstance *inst) {
   TiXmlDocument *doc = new TiXmlDocument;
   TiXmlDocument *doc = new TiXmlDocument;
-  TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
   TiXmlElement *xcommand = new TiXmlElement("command");
   TiXmlElement *xcommand = new TiXmlElement("command");
   xcommand->SetAttribute("cmd", "terminate_instance");
   xcommand->SetAttribute("cmd", "terminate_instance");
   xcommand->SetAttribute("instance_id", inst->get_instance_id());
   xcommand->SetAttribute("instance_id", inst->get_instance_id());
   
   
-  doc->LinkEndChild(decl);
   doc->LinkEndChild(xcommand);
   doc->LinkEndChild(xcommand);
 
 
   send_command(doc);
   send_command(doc);
@@ -621,11 +615,9 @@ void P3DSession::
 drop_pyobj(int object_id) {
 drop_pyobj(int object_id) {
   if (_p3dpython_running) {
   if (_p3dpython_running) {
     TiXmlDocument doc;
     TiXmlDocument doc;
-    TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
     TiXmlElement *xcommand = new TiXmlElement("command");
     TiXmlElement *xcommand = new TiXmlElement("command");
     xcommand->SetAttribute("cmd", "drop_pyobj");
     xcommand->SetAttribute("cmd", "drop_pyobj");
     xcommand->SetAttribute("object_id", object_id);
     xcommand->SetAttribute("object_id", object_id);
-    doc.LinkEndChild(decl);
     doc.LinkEndChild(xcommand);
     doc.LinkEndChild(xcommand);
     write_xml(_pipe_write, &doc, nout);
     write_xml(_pipe_write, &doc, nout);
   }
   }
@@ -735,27 +727,25 @@ start_p3dpython() {
 #endif
 #endif
 
 
   if (!started_p3dpython) {
   if (!started_p3dpython) {
-    nout << "Failed to create process.\n" << flush;
+    nout << "Failed to create process.\n";
     return;
     return;
   }
   }
   _p3dpython_running = true;
   _p3dpython_running = true;
 
 
   if (!_pipe_read) {
   if (!_pipe_read) {
-    nout << "unable to open read pipe\n" << flush;
+    nout << "unable to open read pipe\n";
   }
   }
   if (!_pipe_write) {
   if (!_pipe_write) {
-    nout << "unable to open write pipe\n" << flush;
+    nout << "unable to open write pipe\n";
   }
   }
   
   
   spawn_read_thread();
   spawn_read_thread();
 
 
   // The very first command we send to the process is its session_id.
   // The very first command we send to the process is its session_id.
   TiXmlDocument doc;
   TiXmlDocument doc;
-  TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
   TiXmlElement *xcommand = new TiXmlElement("command");
   TiXmlElement *xcommand = new TiXmlElement("command");
   xcommand->SetAttribute("cmd", "init");
   xcommand->SetAttribute("cmd", "init");
   xcommand->SetAttribute("session_id", _session_id);
   xcommand->SetAttribute("session_id", _session_id);
-  doc.LinkEndChild(decl);
   doc.LinkEndChild(xcommand);
   doc.LinkEndChild(xcommand);
   write_xml(_pipe_write, &doc, nout);
   write_xml(_pipe_write, &doc, nout);
   
   
@@ -822,7 +812,7 @@ rt_thread_run() {
     rt_handle_request(doc);
     rt_handle_request(doc);
   }
   }
 
 
-  logfile << "Exiting rt_thread_run in " << this << "\n" << flush;
+  logfile << "Exiting rt_thread_run in " << this << "\n";
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -918,7 +908,7 @@ win_create_process(const string &program, const string &start_dir,
 
 
   // Create the pipe to the process.
   // Create the pipe to the process.
   if (!CreatePipe(&r_to, &w_to, NULL, 0)) {
   if (!CreatePipe(&r_to, &w_to, NULL, 0)) {
-    nout << "failed to create pipe\n" << flush;
+    nout << "failed to create pipe\n";
   } else {
   } else {
     // Make sure the right end of the pipe is inheritable.
     // Make sure the right end of the pipe is inheritable.
     SetHandleInformation(r_to, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
     SetHandleInformation(r_to, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
@@ -927,7 +917,7 @@ win_create_process(const string &program, const string &start_dir,
 
 
   // Create the pipe from the process.
   // Create the pipe from the process.
   if (!CreatePipe(&r_from, &w_from, NULL, 0)) {
   if (!CreatePipe(&r_from, &w_from, NULL, 0)) {
-    nout << "failed to create pipe\n" << flush;
+    nout << "failed to create pipe\n";
   } else { 
   } else { 
     // Make sure the right end of the pipe is inheritable.
     // Make sure the right end of the pipe is inheritable.
     SetHandleInformation(w_from, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
     SetHandleInformation(w_from, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
@@ -947,7 +937,7 @@ win_create_process(const string &program, const string &start_dir,
       error_handle = handle;
       error_handle = handle;
       SetHandleInformation(error_handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
       SetHandleInformation(error_handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
     } else {
     } else {
-      nout << "Unable to open " << output_filename << "\n" << flush;
+      nout << "Unable to open " << output_filename << "\n";
     }
     }
   }
   }
 
 
@@ -1046,7 +1036,7 @@ posix_create_process(const string &program, const string &start_dir,
       int logfile_fd = open(output_filename.c_str(), 
       int logfile_fd = open(output_filename.c_str(), 
                             O_WRONLY | O_CREAT | O_TRUNC, 0666);
                             O_WRONLY | O_CREAT | O_TRUNC, 0666);
       if (logfile_fd < 0) {
       if (logfile_fd < 0) {
-        nout << "Unable to open " << output_filename << "\n" << flush;
+        nout << "Unable to open " << output_filename << "\n";
       } else {
       } else {
         dup2(logfile_fd, STDERR_FILENO);
         dup2(logfile_fd, STDERR_FILENO);
         close(logfile_fd);
         close(logfile_fd);
@@ -1061,7 +1051,7 @@ posix_create_process(const string &program, const string &start_dir,
     close(from_fd[0]);
     close(from_fd[0]);
 
 
     if (chdir(start_dir.c_str()) < 0) {
     if (chdir(start_dir.c_str()) < 0) {
-      nout << "Could not chdir to " << start_dir << "\n" << flush;
+      nout << "Could not chdir to " << start_dir << "\n";
       _exit(1);
       _exit(1);
     }
     }
 
 
@@ -1077,7 +1067,7 @@ posix_create_process(const string &program, const string &start_dir,
     ptrs.push_back((char *)NULL);
     ptrs.push_back((char *)NULL);
     
     
     execle(program.c_str(), program.c_str(), (char *)0, &ptrs[0]);
     execle(program.c_str(), program.c_str(), (char *)0, &ptrs[0]);
-    nout << "Failed to exec " << program << "\n" << flush;
+    nout << "Failed to exec " << program << "\n";
     _exit(1);
     _exit(1);
   }
   }
 
 

+ 2 - 4
direct/src/plugin/p3dSplashWindow.cxx

@@ -144,8 +144,7 @@ read_image(const string &image_filename, bool image_filename_temp,
   // ever support.
   // ever support.
   FILE *fp = fopen(image_filename.c_str(), "rb");
   FILE *fp = fopen(image_filename.c_str(), "rb");
   if (fp == NULL) {
   if (fp == NULL) {
-    nout << "Couldn't open splash file image: " << image_filename << "\n"
-         << flush;
+    nout << "Couldn't open splash file image: " << image_filename << "\n";
     if (image_filename_temp) {
     if (image_filename_temp) {
       unlink(image_filename.c_str());
       unlink(image_filename.c_str());
     }
     }
@@ -164,8 +163,7 @@ read_image(const string &image_filename, bool image_filename_temp,
   // Establish the setjmp return context for my_error_exit to use
   // Establish the setjmp return context for my_error_exit to use
   if (setjmp(jerr.setjmp_buffer)) {
   if (setjmp(jerr.setjmp_buffer)) {
     // If we get here, the JPEG code has signaled an error.
     // If we get here, the JPEG code has signaled an error.
-    nout << "JPEG error decoding " << image_filename << "\n"
-         << flush;
+    nout << "JPEG error decoding " << image_filename << "\n";
 
 
     // We need to clean up the JPEG object, close the input file, and return.
     // We need to clean up the JPEG object, close the input file, and return.
     jpeg_destroy_decompress(&cinfo);
     jpeg_destroy_decompress(&cinfo);

+ 1 - 2
direct/src/plugin/p3dWinSplashWindow.cxx

@@ -560,8 +560,7 @@ update_image_filename(const string &image_filename, bool image_filename_temp) {
 
 
   delete[] new_data;
   delete[] new_data;
 
 
-  nout << "Loaded splash file image: " << image_filename << "\n"
-       << flush;
+  nout << "Loaded splash file image: " << image_filename << "\n";
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 1 - 9
direct/src/plugin/p3dX11SplashWindow.cxx

@@ -106,12 +106,10 @@ set_image_filename(const string &image_filename,
   }
   }
 
 
   TiXmlDocument doc;
   TiXmlDocument doc;
-  TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
   TiXmlElement *xcommand = new TiXmlElement("command");
   TiXmlElement *xcommand = new TiXmlElement("command");
   xcommand->SetAttribute("cmd", "set_image_filename");
   xcommand->SetAttribute("cmd", "set_image_filename");
   xcommand->SetAttribute("image_filename", image_filename);
   xcommand->SetAttribute("image_filename", image_filename);
   xcommand->SetAttribute("image_filename_temp", (int)image_filename_temp);
   xcommand->SetAttribute("image_filename_temp", (int)image_filename_temp);
-  doc.LinkEndChild(decl);
   doc.LinkEndChild(xcommand);
   doc.LinkEndChild(xcommand);
   write_xml(_pipe_write, &doc, nout);
   write_xml(_pipe_write, &doc, nout);
 
 
@@ -131,11 +129,9 @@ set_install_label(const string &install_label) {
   }
   }
 
 
   TiXmlDocument doc;
   TiXmlDocument doc;
-  TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
   TiXmlElement *xcommand = new TiXmlElement("command");
   TiXmlElement *xcommand = new TiXmlElement("command");
   xcommand->SetAttribute("cmd", "set_install_label");
   xcommand->SetAttribute("cmd", "set_install_label");
   xcommand->SetAttribute("install_label", install_label);
   xcommand->SetAttribute("install_label", install_label);
-  doc.LinkEndChild(decl);
   doc.LinkEndChild(xcommand);
   doc.LinkEndChild(xcommand);
   write_xml(_pipe_write, &doc, nout);
   write_xml(_pipe_write, &doc, nout);
 
 
@@ -154,11 +150,9 @@ set_install_progress(double install_progress) {
   }
   }
 
 
   TiXmlDocument doc;
   TiXmlDocument doc;
-  TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
   TiXmlElement *xcommand = new TiXmlElement("command");
   TiXmlElement *xcommand = new TiXmlElement("command");
   xcommand->SetAttribute("cmd", "set_install_progress");
   xcommand->SetAttribute("cmd", "set_install_progress");
   xcommand->SetDoubleAttribute("install_progress", install_progress);
   xcommand->SetDoubleAttribute("install_progress", install_progress);
-  doc.LinkEndChild(decl);
   doc.LinkEndChild(xcommand);
   doc.LinkEndChild(xcommand);
   write_xml(_pipe_write, &doc, nout);
   write_xml(_pipe_write, &doc, nout);
 
 
@@ -223,10 +217,8 @@ stop_subprocess() {
 
 
   // Ask the subprocess to stop.
   // Ask the subprocess to stop.
   TiXmlDocument doc;
   TiXmlDocument doc;
-  TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
   TiXmlElement *xcommand = new TiXmlElement("command");
   TiXmlElement *xcommand = new TiXmlElement("command");
   xcommand->SetAttribute("cmd", "exit");
   xcommand->SetAttribute("cmd", "exit");
-  doc.LinkEndChild(decl);
   doc.LinkEndChild(xcommand);
   doc.LinkEndChild(xcommand);
   write_xml(_pipe_write, &doc, nout);
   write_xml(_pipe_write, &doc, nout);
 
 
@@ -257,7 +249,7 @@ stop_subprocess() {
     if (elapsed > max_wait_ms) {
     if (elapsed > max_wait_ms) {
       // Tired of waiting.  Kill the process.
       // Tired of waiting.  Kill the process.
       nout << "Force-killing splash window process, pid " << _subprocess_pid 
       nout << "Force-killing splash window process, pid " << _subprocess_pid 
-           << "\n" << flush;
+           << "\n";
       kill(_subprocess_pid, SIGKILL);
       kill(_subprocess_pid, SIGKILL);
       start_ms = now_ms;
       start_ms = now_ms;
     }
     }

+ 1 - 0
direct/src/plugin/p3d_plugin.cxx

@@ -57,6 +57,7 @@ P3D_initialize(int api_version, const char *output_filename) {
   if (!plugin_output_filename.empty()) {
   if (!plugin_output_filename.empty()) {
     logfile.open(plugin_output_filename.c_str(), ios::out | ios::trunc);
     logfile.open(plugin_output_filename.c_str(), ios::out | ios::trunc);
     if (logfile) {
     if (logfile) {
+      logfile.setf(ios::unitbuf);
       nout_stream = &logfile;
       nout_stream = &logfile;
     }
     }
   }
   }

+ 3 - 2
direct/src/plugin_npapi/nppanda3d_common.h

@@ -28,8 +28,9 @@
 
 
 using namespace std;
 using namespace std;
 
 
-// Appears in nppanda3d_startup.cxx.
-extern ofstream logfile;
+// Appears in startup.cxx.
+extern ostream *nout_stream;
+#define nout (*nout_stream)
 
 
 #ifdef _WIN32
 #ifdef _WIN32
 
 

+ 16 - 16
direct/src/plugin_npapi/ppInstance.cxx

@@ -209,7 +209,7 @@ new_stream(NPMIMEType type, NPStream *stream, bool seekable, uint16 *stype) {
 
 
   default:
   default:
     // Don't know what this is.
     // Don't know what this is.
-    logfile << "Unexpected request " << (int)req->_rtype << "\n";
+    nout << "Unexpected request " << (int)req->_rtype << "\n";
   }
   }
 
 
   return NPERR_GENERIC_ERROR;
   return NPERR_GENERIC_ERROR;
@@ -224,7 +224,7 @@ new_stream(NPMIMEType type, NPStream *stream, bool seekable, uint16 *stype) {
 int PPInstance::
 int PPInstance::
 write_stream(NPStream *stream, int offset, int len, void *buffer) {
 write_stream(NPStream *stream, int offset, int len, void *buffer) {
   if (stream->notifyData == NULL) {
   if (stream->notifyData == NULL) {
-    logfile << "Unexpected write_stream on " << stream->url << "\n";
+    nout << "Unexpected write_stream on " << stream->url << "\n";
     return 0;
     return 0;
   }
   }
 
 
@@ -237,7 +237,7 @@ write_stream(NPStream *stream, int offset, int len, void *buffer) {
     return len;
     return len;
     
     
   default:
   default:
-    logfile << "Unexpected write_stream on " << stream->url << "\n";
+    nout << "Unexpected write_stream on " << stream->url << "\n";
     break;
     break;
   }
   }
 
 
@@ -254,7 +254,7 @@ write_stream(NPStream *stream, int offset, int len, void *buffer) {
 NPError PPInstance::
 NPError PPInstance::
 destroy_stream(NPStream *stream, NPReason reason) {
 destroy_stream(NPStream *stream, NPReason reason) {
   if (stream->notifyData == NULL) {
   if (stream->notifyData == NULL) {
-    logfile << "Unexpected destroy_stream on " << stream->url << "\n";
+    nout << "Unexpected destroy_stream on " << stream->url << "\n";
     return NPERR_GENERIC_ERROR;
     return NPERR_GENERIC_ERROR;
   }
   }
 
 
@@ -301,7 +301,7 @@ url_notify(const char *url, NPReason reason, void *notifyData) {
       // We shouldn't have gotten here without notifying the stream
       // We shouldn't have gotten here without notifying the stream
       // unless the stream never got started (and hence we never
       // unless the stream never got started (and hence we never
       // called destroy_stream().
       // called destroy_stream().
-      logfile << "Failure starting stream\n" << flush;
+      nout << "Failure starting stream\n";
       assert(reason != NPRES_DONE);
       assert(reason != NPRES_DONE);
 
 
       P3D_instance_feed_url_stream(_p3d_inst, req->_user_id,
       P3D_instance_feed_url_stream(_p3d_inst, req->_user_id,
@@ -312,7 +312,7 @@ url_notify(const char *url, NPReason reason, void *notifyData) {
 
 
   case PPDownloadRequest::RT_contents_file:
   case PPDownloadRequest::RT_contents_file:
     if (reason != NPRES_DONE) {
     if (reason != NPRES_DONE) {
-      logfile << "Failure downloading " << url << "\n";
+      nout << "Failure downloading " << url << "\n";
       // TODO: fail
       // TODO: fail
     }
     }
     break;
     break;
@@ -333,7 +333,7 @@ url_notify(const char *url, NPReason reason, void *notifyData) {
 void PPInstance::
 void PPInstance::
 stream_as_file(NPStream *stream, const char *fname) {
 stream_as_file(NPStream *stream, const char *fname) {
   if (stream->notifyData == NULL) {
   if (stream->notifyData == NULL) {
-    logfile << "Unexpected stream_as_file on " << stream->url << "\n";
+    nout << "Unexpected stream_as_file on " << stream->url << "\n";
     return;
     return;
   }
   }
 
 
@@ -454,7 +454,7 @@ handle_request(P3D_request *request) {
 
 
   default:
   default:
     // Some request types are not handled.
     // Some request types are not handled.
-    logfile << "Unhandled request: " << request->_request_type << "\n";
+    nout << "Unhandled request: " << request->_request_type << "\n";
     break;
     break;
   };
   };
 
 
@@ -724,8 +724,8 @@ read_contents_file(const string &filename) {
   }
   }
 
 
   // Couldn't find the coreapi package description.
   // Couldn't find the coreapi package description.
-  logfile << "No coreapi package defined in contents file for "
-          << P3D_PLUGIN_PLATFORM << "\n" << flush;
+  nout << "No coreapi package defined in contents file for "
+       << P3D_PLUGIN_PLATFORM << "\n";
   return false;
   return false;
 }
 }
 
 
@@ -766,7 +766,7 @@ downloaded_file(PPDownloadRequest *req, const string &filename) {
     // Now we have the contents.xml file.  Read this to get the
     // Now we have the contents.xml file.  Read this to get the
     // filename and md5 hash of our core API DLL.
     // filename and md5 hash of our core API DLL.
     if (!read_contents_file(filename)) {
     if (!read_contents_file(filename)) {
-      logfile << "Unable to read contents file\n";
+      nout << "Unable to read contents file\n";
       // TODO: fail
       // TODO: fail
     }
     }
     break;
     break;
@@ -794,7 +794,7 @@ downloaded_file(PPDownloadRequest *req, const string &filename) {
 
 
   default:
   default:
     // Don't know what this is.
     // Don't know what this is.
-    logfile << "Unexpected downloaded file, type " << (int)req->_rtype << "\n";
+    nout << "Unexpected downloaded file, type " << (int)req->_rtype << "\n";
   }
   }
 }
 }
 
 
@@ -879,7 +879,7 @@ downloaded_plugin(const string &filename) {
   }
   }
 
 
   if (!out) {
   if (!out) {
-    logfile << "Could not write " << pathname << "\n";
+    nout << "Could not write " << pathname << "\n";
     // TODO: fail
     // TODO: fail
     return;
     return;
   }
   }
@@ -892,7 +892,7 @@ downloaded_plugin(const string &filename) {
     return;
     return;
   }
   }
 
 
-  logfile << "After download, " << pathname << " is no good.\n";
+  nout << "After download, " << pathname << " is no good.\n";
   // TODO: fail
   // TODO: fail
 }
 }
 
 
@@ -920,7 +920,7 @@ do_load_plugin() {
 #endif  // P3D_PLUGIN_P3D_PLUGIN
 #endif  // P3D_PLUGIN_P3D_PLUGIN
 
 
   if (!load_plugin(pathname)) {
   if (!load_plugin(pathname)) {
-    logfile << "Unable to launch core API in " << pathname << "\n" << flush;
+    nout << "Unable to launch core API in " << pathname << "\n";
     return;
     return;
   }
   }
   create_instance();
   create_instance();
@@ -960,7 +960,7 @@ create_instance() {
       P3D_instance_set_browser_script_object(_p3d_inst, pobj);
       P3D_instance_set_browser_script_object(_p3d_inst, pobj);
       browser->releaseobject(window_object);
       browser->releaseobject(window_object);
     } else {
     } else {
-      logfile << "Couldn't get window_object\n" << flush;
+      nout << "Couldn't get window_object\n";
     }
     }
 
 
     if (_script_object != NULL) {
     if (_script_object != NULL) {

+ 35 - 34
direct/src/plugin_npapi/startup.cxx

@@ -20,7 +20,8 @@
 #include <malloc.h>
 #include <malloc.h>
 #endif
 #endif
 
 
-ofstream logfile;
+static ofstream logfile;
+ostream *nout_stream = &logfile;
 
 
 NPNetscapeFuncs *browser;
 NPNetscapeFuncs *browser;
 
 
@@ -47,6 +48,7 @@ open_logfile() {
 #endif  // _WIN32
 #endif  // _WIN32
     }
     }
     logfile.open(logfilename.c_str());
     logfile.open(logfilename.c_str());
+    logfile.setf(ios::unitbuf);
     logfile_is_open = true;
     logfile_is_open = true;
   }
   }
 }
 }
@@ -85,7 +87,7 @@ NP_GetValue(void*, NPPVariable variable, void* value) {
       *((PRBool *)value) = PR_FALSE;
       *((PRBool *)value) = PR_FALSE;
       break;
       break;
     default:
     default:
-      logfile << "Ignoring GetValue request " << variable << "\n" << flush;
+      nout << "Ignoring GetValue request " << variable << "\n";
       return NPERR_INVALID_PARAM;
       return NPERR_INVALID_PARAM;
   }
   }
   
   
@@ -115,9 +117,9 @@ NP_Initialize(NPNetscapeFuncs *browserFuncs,
   browser = browserFuncs;
   browser = browserFuncs;
 
 
   open_logfile();
   open_logfile();
-  logfile << "initializing\n" << flush;
+  nout << "initializing\n";
 
 
-  logfile << "browserFuncs = " << browserFuncs << "\n" << flush;
+  nout << "browserFuncs = " << browserFuncs << "\n";
 
 
   // On Unix, we have to use the pluginFuncs argument
   // On Unix, we have to use the pluginFuncs argument
   // to pass our entry points.
   // to pass our entry points.
@@ -141,8 +143,7 @@ NP_Initialize(NPNetscapeFuncs *browserFuncs,
 NPError OSCALL
 NPError OSCALL
 NP_GetEntryPoints(NPPluginFuncs *pluginFuncs) {
 NP_GetEntryPoints(NPPluginFuncs *pluginFuncs) {
   open_logfile();
   open_logfile();
-  logfile << "NP_GetEntryPoints, pluginFuncs = " << pluginFuncs << "\n"
-          << flush;
+  nout << "NP_GetEntryPoints, pluginFuncs = " << pluginFuncs << "\n";
   pluginFuncs->version = 11;
   pluginFuncs->version = 11;
   pluginFuncs->size = sizeof(pluginFuncs);
   pluginFuncs->size = sizeof(pluginFuncs);
   pluginFuncs->newp = NPP_New;
   pluginFuncs->newp = NPP_New;
@@ -170,7 +171,7 @@ NP_GetEntryPoints(NPPluginFuncs *pluginFuncs) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 NPError OSCALL
 NPError OSCALL
 NP_Shutdown(void) {
 NP_Shutdown(void) {
-  logfile << "shutdown\n" << flush;
+  nout << "shutdown\n";
   unload_plugin();
   unload_plugin();
 
 
   // Not clear whether there's a return value or not.  Some versions
   // Not clear whether there's a return value or not.  Some versions
@@ -186,7 +187,7 @@ NP_Shutdown(void) {
 NPError 
 NPError 
 NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, 
 NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, 
         int16 argc, char *argn[], char *argv[], NPSavedData *saved) {
         int16 argc, char *argn[], char *argv[], NPSavedData *saved) {
-  logfile << "new instance\n" << flush;
+  nout << "new instance\n";
 
 
   PPInstance *inst = new PPInstance(pluginType, instance, mode,
   PPInstance *inst = new PPInstance(pluginType, instance, mode,
                                     argc, argn, argv, saved);
                                     argc, argn, argv, saved);
@@ -210,8 +211,8 @@ NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode,
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 NPError
 NPError
 NPP_Destroy(NPP instance, NPSavedData **save) {
 NPP_Destroy(NPP instance, NPSavedData **save) {
-  logfile << "destroy instance " << instance << "\n";
-  logfile << "save = " << (void *)save << "\n" << flush;
+  nout << "destroy instance " << instance << "\n";
+  nout << "save = " << (void *)save << "\n";
   //  (*save) = NULL;
   //  (*save) = NULL;
   delete (PPInstance *)(instance->pdata);
   delete (PPInstance *)(instance->pdata);
   instance->pdata = NULL;
   instance->pdata = NULL;
@@ -229,9 +230,9 @@ NPP_Destroy(NPP instance, NPSavedData **save) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 NPError
 NPError
 NPP_SetWindow(NPP instance, NPWindow *window) {
 NPP_SetWindow(NPP instance, NPWindow *window) {
-  logfile << "SetWindow " << window->x << ", " << window->y
+  nout << "SetWindow " << window->x << ", " << window->y
           << ", " << window->width << ", " << window->height
           << ", " << window->width << ", " << window->height
-          << "\n" << flush;
+          << "\n";
 
 
   PPInstance *inst = (PPInstance *)(instance->pdata);
   PPInstance *inst = (PPInstance *)(instance->pdata);
   assert(inst != NULL);
   assert(inst != NULL);
@@ -251,10 +252,10 @@ NPP_SetWindow(NPP instance, NPWindow *window) {
 NPError
 NPError
 NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, 
 NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, 
               NPBool seekable, uint16 *stype) {
               NPBool seekable, uint16 *stype) {
-  logfile << "NewStream " << type << ", " << stream->url 
-          << ", " << stream->end 
-          << ", notifyData = " << stream->notifyData
-          << "\n" << flush;
+  nout << "NewStream " << type << ", " << stream->url 
+       << ", " << stream->end 
+       << ", notifyData = " << stream->notifyData
+       << "\n";
   PPInstance::generic_browser_call();
   PPInstance::generic_browser_call();
   PPInstance *inst = (PPInstance *)(instance->pdata);
   PPInstance *inst = (PPInstance *)(instance->pdata);
   assert(inst != NULL);
   assert(inst != NULL);
@@ -269,11 +270,11 @@ NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream,
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 NPError 
 NPError 
 NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason) {
 NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason) {
-  logfile << "DestroyStream " << stream->url 
-          << ", " << stream->end 
-          << ", notifyData = " << stream->notifyData
-          << ", reason = " << reason
-          << "\n" << flush;
+  nout << "DestroyStream " << stream->url 
+       << ", " << stream->end 
+       << ", notifyData = " << stream->notifyData
+       << ", reason = " << reason
+       << "\n";
 
 
   PPInstance::generic_browser_call();
   PPInstance::generic_browser_call();
   PPInstance *inst = (PPInstance *)(instance->pdata);
   PPInstance *inst = (PPInstance *)(instance->pdata);
@@ -304,7 +305,7 @@ NPP_WriteReady(NPP instance, NPStream *stream) {
 int32
 int32
 NPP_Write(NPP instance, NPStream *stream, int32 offset, 
 NPP_Write(NPP instance, NPStream *stream, int32 offset, 
           int32 len, void *buffer) {
           int32 len, void *buffer) {
-  //  logfile << "Write " << stream->url << ", " << len << "\n" << flush;
+  //  nout << "Write " << stream->url << ", " << len << "\n";
   PPInstance::generic_browser_call();
   PPInstance::generic_browser_call();
   PPInstance *inst = (PPInstance *)(instance->pdata);
   PPInstance *inst = (PPInstance *)(instance->pdata);
   assert(inst != NULL);
   assert(inst != NULL);
@@ -321,10 +322,10 @@ NPP_Write(NPP instance, NPStream *stream, int32 offset,
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void
 void
 NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname) {
 NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname) {
-  logfile << "StreamAsFile " << stream->url 
-          << ", " << stream->end 
-          << ", notifyData = " << stream->notifyData
-          << "\n" << flush;
+  nout << "StreamAsFile " << stream->url 
+       << ", " << stream->end 
+       << ", notifyData = " << stream->notifyData
+       << "\n";
 
 
   PPInstance::generic_browser_call();
   PPInstance::generic_browser_call();
   PPInstance *inst = (PPInstance *)(instance->pdata);
   PPInstance *inst = (PPInstance *)(instance->pdata);
@@ -340,7 +341,7 @@ NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void 
 void 
 NPP_Print(NPP instance, NPPrint *platformPrint) {
 NPP_Print(NPP instance, NPPrint *platformPrint) {
-  logfile << "Print\n";
+  nout << "Print\n";
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -350,7 +351,7 @@ NPP_Print(NPP instance, NPPrint *platformPrint) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 int16
 int16
 NPP_HandleEvent(NPP instance, void *event) {
 NPP_HandleEvent(NPP instance, void *event) {
-  //  logfile << "HandleEvent\n" << flush;
+  //  nout << "HandleEvent\n";
   PPInstance::generic_browser_call();
   PPInstance::generic_browser_call();
 
 
   PPInstance *inst = (PPInstance *)(instance->pdata);
   PPInstance *inst = (PPInstance *)(instance->pdata);
@@ -367,10 +368,10 @@ NPP_HandleEvent(NPP instance, void *event) {
 void
 void
 NPP_URLNotify(NPP instance, const char *url,
 NPP_URLNotify(NPP instance, const char *url,
               NPReason reason, void *notifyData) {
               NPReason reason, void *notifyData) {
-  logfile << "URLNotify: " << url 
-          << ", notifyData = " << notifyData
-          << ", reason = " << reason
-          << "\n" << flush;
+  nout << "URLNotify: " << url 
+       << ", notifyData = " << notifyData
+       << ", reason = " << reason
+       << "\n";
 
 
   PPInstance::generic_browser_call();
   PPInstance::generic_browser_call();
   PPInstance *inst = (PPInstance *)(instance->pdata);
   PPInstance *inst = (PPInstance *)(instance->pdata);
@@ -386,7 +387,7 @@ NPP_URLNotify(NPP instance, const char *url,
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 NPError
 NPError
 NPP_GetValue(NPP instance, NPPVariable variable, void *value) {
 NPP_GetValue(NPP instance, NPPVariable variable, void *value) {
-  logfile << "GetValue " << variable << "\n";
+  nout << "GetValue " << variable << "\n";
   PPInstance::generic_browser_call();
   PPInstance::generic_browser_call();
   PPInstance *inst = (PPInstance *)(instance->pdata);
   PPInstance *inst = (PPInstance *)(instance->pdata);
   assert(inst != NULL);
   assert(inst != NULL);
@@ -410,7 +411,7 @@ NPP_GetValue(NPP instance, NPPVariable variable, void *value) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 NPError 
 NPError 
 NPP_SetValue(NPP instance, NPNVariable variable, void *value) {
 NPP_SetValue(NPP instance, NPNVariable variable, void *value) {
-  logfile << "SetValue " << variable << "\n";
+  nout << "SetValue " << variable << "\n";
   PPInstance::generic_browser_call();
   PPInstance::generic_browser_call();
   return NPERR_GENERIC_ERROR;
   return NPERR_GENERIC_ERROR;
 }
 }