bool GlueFile::WriteTable() { AMJU_CALL_STACK; // Write the number of files. uint32 numFiles = m_table.size(); numFiles = Endian(numFiles); m_gluefile.seekg(0); m_gluefile.write((char*)&numFiles, sizeof(uint32)); // Write the new table position. uint32 tablepos = Endian(m_tablePos); m_gluefile.write((char*)&tablepos, sizeof(uint32)); // Seek to the table position m_gluefile.seekg(m_tablePos); // Iterate over sub-file list, writing to the GlueFile. for (FileList::iterator it = m_filenames.begin(); it != m_filenames.end(); ++it) { // Get the length of the sub-file name. uint32 subfilenamelen = it->length(); uint32 endiansubfilenamelen = Endian(subfilenamelen); #ifdef GLUE_FILE_DEBUG std::cout << "GLUE FILE: Write table: writing size of name \"" << it->c_str() << "\": " << subfilenamelen << "\n"; #endif m_gluefile.write((char*)&endiansubfilenamelen, sizeof(uint32)); #ifdef GLUE_FILE_DEBUG std::cout << "GLUE FILE: Write table: writing name \"" << it->c_str() << "\"\n"; #endif // Write the string m_gluefile.write(it->c_str(), subfilenamelen); // Write the size of this sub-file. uint32 size = m_table[*it].first; #ifdef GLUE_FILE_DEBUG std::cout << "GLUE FILE: Write table: writing size of file \"" << it->c_str() << "\": " << size << "\n"; #endif size = Endian(size); m_gluefile.write((char*)&size, sizeof(uint32)); } return true; }
bpt::string bpt::ParsingTools::BuildCharacter(wchar_t c, bool in_string, int *out) const { if (out) *out = 1; switch (c) { case '\a': return ("\\a"); case '\b': return ("\\b"); case '\v': return ("\\v"); case '\f': return ("\\f"); case '\n': return ("\\n"); case '\t': return ("\\t"); case '\r': return ("\\r"); case '\0': return ("\\0"); case '\'': if (in_string) return ("'"); return ("\\'"); case '"': if (in_string == false) return ("\""); return ("\\\""); default: bpt::stringstream ss; char tab[sizeof(wchar_t) + 1]; wchar_t x; x = Endian(c); memcpy(&tab[0], &x, sizeof(x)); tab[sizeof(x)] = '\0'; if (tab[0] & 0x80) { ss << &tab[0]; if (out) *out = strlen(&tab[0]); } else { char _c = c; if (c < ' ' || (c >= 127 && c <= 255)) ss << "\\0" << std::oct << c; else ss << _c; } return (ss.str()); } return (""); }
mdsip_message_t *mdsip_get_message(void *io_handle, int *status) { mdsip_message_header_t header; globus_result_t result; mdsip_message_t *msg = NULL; int msglen = 0; globus_size_t nbytes; *status = 0; result = globus_xio_read(io_handle, (globus_byte_t *)&header, sizeof(header),sizeof(header),&nbytes, NULL); mdsip_test_status(io_handle,result,"mdsip_get_message, globus_xio_read"); if (result != GLOBUS_SUCCESS) return NULL; if ( Endian(header.client_type) != Endian(mdsip_client_type()) ) mdsip_flip_header(&header); if ( CType(header.client_type) > CRAY_CLIENT || header.ndims > MAX_DIMS || header.msglen < sizeof(header)) { globus_xio_close(io_handle,NULL); fprintf(stderr,"ERROR: mdsip_get_message, bad message header - closing connection\n"); return NULL; } msglen = header.msglen; msg = malloc(header.msglen); msg->h = header; if (msglen > sizeof(header)) { result = globus_xio_read(io_handle,msg->bytes,msglen - sizeof(header),msglen - sizeof(header),&nbytes,NULL); mdsip_test_status(io_handle,result,"mdsip_get_message, globus_xio_read"); } if (result != GLOBUS_SUCCESS) { free(msg); return NULL; } if (Endian(header.client_type) != Endian(mdsip_client_type())) mdsip_flip_data(msg); *status = 1; return msg; }
Message *GetMdsMsg(int id, int *status) { MsgHdr header; Message *msg = 0; int msglen = 0; //MdsSetClientAddr(0); *status = 0; *status = GetBytes(id, (void *)&header, sizeof(MsgHdr)); if (*status &1){ if ( Endian(header.client_type) != Endian(ClientType()) ) FlipHeader(&header); #ifdef DEBUG printf("msglen = %d\nstatus = %d\nlength = %d\nnargs = %d\ndescriptor_idx = %d\nmessage_id = %d\ndtype = %d\n", header.msglen,header.status,header.length,header.nargs,header.descriptor_idx,header.message_id,header.dtype); printf("client_type = %d\nndims = %d\n",header.client_type,header.ndims); #endif if (CType(header.client_type) > CRAY_CLIENT || header.ndims > MAX_DIMS) { DisconnectConnection(id); fprintf(stderr,"\rGetMdsMsg shutdown connection %d: bad msg header, header.ndims=%d, client_type=%d\n",id,header.ndims,CType(header.client_type)); *status = 0; return 0; } msglen = header.msglen; msg = malloc(header.msglen); msg->h = header; *status = GetBytes(id, msg->bytes, msglen - sizeof(MsgHdr)); if (*status & 1 && IsCompressed(header.client_type)) { Message *m; unsigned long dlen; memcpy(&msglen, msg->bytes, 4); if (Endian(header.client_type) != Endian(ClientType())) FlipBytes(4,(char *)&msglen); m = malloc(msglen); m->h = header; dlen = msglen - sizeof(MsgHdr); *status = uncompress(m->bytes, &dlen, msg->bytes + 4, header.msglen - sizeof(MsgHdr) - 4) == 0; if (*status & 1) { m->h.msglen = msglen; free(msg); msg = m; } else free(m); } if (*status & 1 && (Endian(header.client_type) != Endian(ClientType()))) FlipData(msg); } return msg; }
bool GlueFile::ReadTable() { AMJU_CALL_STACK; // Get the number of sub-files. This is the uint32 at file pos zero. uint32 numFiles = 0; //m_gluefile.seekg(0); GetBinary(0, sizeof(uint32), (unsigned char*)&numFiles); numFiles = Endian(numFiles); #ifdef GLUE_FILE_DEBUG std::cout << "GLUE FILE: no of files: " << numFiles << "\n"; #endif // Get the file pos of the table. This is the next uint32. //m_gluefile.read((char*)&m_tablePos, sizeof(uint32)); GetBinary(4, sizeof(uint32), (unsigned char*)&m_tablePos); m_tablePos = Endian(m_tablePos); #ifdef GLUE_FILE_DEBUG std::cout << "GLUE FILE: table start: " << m_tablePos << "\n"; #endif // Seek to the table start. uint32 tablePos = m_tablePos; //m_gluefile.seekg(m_tablePos); uint32 pos = BASE; // For each sub-file, get the name and file pos. for (uint32 i = 0; i < numFiles; i++) { // Get the length of the sub-file name. uint32 subfilenamelen = 0; //m_gluefile.read((char*)&subfilenamelen, sizeof(uint32)); GetBinary(tablePos, sizeof(uint32), (unsigned char*)&subfilenamelen); tablePos += sizeof(uint32); subfilenamelen = Endian(subfilenamelen); unsigned char buf[1000]; //m_gluefile.read(buf, subfilenamelen); GetBinary(tablePos, subfilenamelen, buf); buf[subfilenamelen] = '\0'; #ifdef GLUE_FILE_DEBUG std::cout << "GLUE FILE: file " << i << " size of name: " << subfilenamelen << " name: \"" << buf << "\"\n"; #endif tablePos += subfilenamelen; string lowname = ToLower((char*)buf); // Now get the size of this sub-file. uint32 size = 0; //m_gluefile.read((char*)&size, sizeof(uint32)); GetBinary(tablePos, sizeof(uint32), (unsigned char*)&size); tablePos += sizeof(uint32); size = Endian(size); #ifdef GLUE_FILE_DEBUG std::cout << "GLUE FILE: Found file: " << lowname.c_str() << " size: " << size << " pos: " << pos << "\n"; #endif // Store the sub-file's size and position.. m_table[lowname] = make_pair(size, pos); // .. also append to this list so we keep the order in which the // sub-files were added. m_filenames.push_back(lowname); pos += size; } // Copy the list of all subfiles. As subfiles are 'opened', they are removed // from the unused list. The ones left are printed out in the dtor. m_unusedFiles = m_filenames; return true; }
void main() { Endian(); }