int Nestea_i::load_data (void) { ACE_FILE_IO file; ACE_FILE_Connector connector; if (connector.connect (file, ACE_FILE_Addr (this->data_filename_), 0, ACE_Addr::sap_any) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n to %s", "connect", this->data_filename_), -1); char str[MAX_UINT32_STR_LEN]; int len = file.recv (str, MAX_UINT32_STR_LEN); str[len] = 0; if (len > 0) this->cans_ = ACE_OS::atoi (str); else this->cans_ = 0; return 0; }
void JAWS_Config_File_Impl::parse_file (void) { ACE_FILE_Connector fconnector; ACE_FILE_IO fio; if (fconnector.connect ( fio , this->faddr_ , 0 , ACE_Addr::sap_any , 0 , O_RDONLY ) == -1) return; ACE_Message_Block buffer (8192); ACE_Message_Block line (4096); ssize_t count = 0; const ACE_TCHAR *sym_name; const ACE_TCHAR *sym_value; int last_line_was_read = 0; ACE_TCHAR *end_of_current_line = 0; ACE_TCHAR *p = 0; while (last_line_was_read || (count = fio.recv (buffer.wr_ptr (), buffer.space () - 2)) >= 0) { end_of_current_line = 0; // Make sure input is newline terminated if it is the last line, // and always null terminated. if (! last_line_was_read) { if (count > 0) { buffer.wr_ptr (count); // Scan forward for at least one newline character p = buffer.rd_ptr (); while (p != buffer.wr_ptr ()) { if (*p == '\n') break; p++; } if (p == buffer.wr_ptr ()) continue; end_of_current_line = p; } else { if (buffer.wr_ptr ()[-1] != '\n') { buffer.wr_ptr ()[0] = '\n'; buffer.wr_ptr (1); } last_line_was_read = 1; } buffer.wr_ptr ()[0] = '\0'; } if (end_of_current_line == 0) { end_of_current_line = buffer.rd_ptr (); while (*end_of_current_line != '\n') end_of_current_line++; } // If buffer is not pointing to a continuation line, or there is // no more input, then can commit the scanned configuration // line. if (line.length () != 0 && ((last_line_was_read && buffer.length () == 0) || (buffer.rd_ptr ()[0] != ' ' && buffer.rd_ptr ()[0] != '\t'))) { ACE_TCHAR *name = 0; ACE_TCHAR *value = 0; name = line.rd_ptr (); for (p = name; *p != '\0'; p++) { if (*p == '=') { line.rd_ptr (p+1); while (p != name && (p[-1] == ' ' || p[-1] == '\t')) p--; *p = '\0'; } } if (*name) { value = line.rd_ptr (); while (*value == ' ' || *value == '\t') value++; p = line.wr_ptr (); while (p != value && (p[-1] == ' ' || p[-1] == '\t')) p--; *p = '\0'; sym_name = this->strings_->duplicate (name); sym_value = this->strings_->duplicate (value); this->symbols_->rebind (sym_name, sym_value); } line.reset (); } // If we are done, we are done! if (last_line_was_read && buffer.length () == 0) break; // If the buffer is pointing at a comment line, ignore it. if (buffer.rd_ptr ()[0] == '#' || buffer.rd_ptr ()[0] == '\n' || (buffer.rd_ptr ()[0] == '\r' && buffer.rd_ptr ()[1] == '\n')) { buffer.rd_ptr (end_of_current_line + 1); buffer.crunch (); continue; } // Whatever is left is either the start of a name-value-pair or a // continuation of one. line.copy (buffer.rd_ptr (), end_of_current_line - buffer.rd_ptr ()); p = line.wr_ptr (); while (p != line.rd_ptr () && (p[-1] == ' ' || p[-1] == '\t')) p--; line.wr_ptr (p); line.wr_ptr ()[0] = '\0'; buffer.rd_ptr (end_of_current_line + 1); buffer.crunch (); } fio.close (); }
static int test_ostream (void) { // This message should show up in the log file. ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("first message\n"))); ACE_LOG_MSG->clr_flags (ACE_Log_Msg::OSTREAM); // This message should not show up anywhere. ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("second message\n"))); ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM); #if !defined (ACE_LACKS_IOSTREAM_TOTALLY) // Create a persistent store. const ACE_TCHAR *filename = ACE_TEXT ("output"); ofstream myostream (ACE_TEXT_ALWAYS_CHAR (filename), ios::out | ios::trunc); // Check for errors. if (myostream.bad ()) return -1; // Set the ostream. ACE_LOG_MSG->msg_ostream (&myostream); // This message should show up in the ostream. ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("fourth message\n"))); // Set the ostream back to the test's log file. ACE_LOG_MSG->msg_ostream (ace_file_stream::instance ()->output_file ()); // Now close the ostream file and check its contents. myostream.close (); ACE_FILE_Connector connector; ACE_FILE_IO file; // Open up the file. if (connector.connect (file, ACE_FILE_Addr (filename)) == -1) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("connect failed for %p\n"), filename), 1); } // Unlink this file right away so that it is automatically removed // when the process exits.Ignore error returns in case this operation // is not supported. ACE_OS::unlink(filename); ACE_FILE_Info info; if (file.get_info (info) == -1) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("get_info failed on %p\n"), filename), -1); } // Allocate the input buffer char *buffer; ACE_NEW_RETURN (buffer, char[info.size_ + 1], -1); // Make sure <buffer> is released automagically. ACE_Auto_Basic_Array_Ptr<char> b (buffer); // Read the file into the buffer. ssize_t size = file.recv (buffer, info.size_); if (size != info.size_) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Read %d bytes, rather than expected %d bytes\n"), size, info.size_), -1); } // Make sure to NUL-terminate this turkey! buffer[size] = '\0'; ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s"), buffer)); #endif /* ACE_LACKS_IOSTREAM_TOTALLY */ // This message should show up in stderr and the ostream (without // ACE_LACKS_IOSTREAM_TOTALLY). ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("fifth message\n"))); return 0; }