00001 #include <cstring>
00002 #include "Rtypes.h"
00003 #include "RawData/littleendian_strings.h"
00004
00005
00006
00007 UInt_t nwords_in_string(const Char_t* x) {
00008
00009 UInt_t csize = strlen(x);
00010 return ((csize+1)+(sizeof(Int_t)-1))/sizeof(Int_t);
00011 }
00012
00013
00014 void pack_string_in_lel(Int_t* dest_i ,const Char_t* src_c) {
00015
00016
00017
00018
00019 UInt_t nchar = strlen(src_c);
00020 UInt_t nwd = nwords_in_string(src_c);
00021
00022 Char_t* dest_c = (Char_t*) dest_i;
00023
00024 dest_i[nwd-1] = 0;
00025 memcpy(dest_c,src_c,nchar);
00026
00027
00028 for (UInt_t i=0; i<nwd; ++i)
00029 dest_i[i] = (Int_t)minos_htolel((UInt_t)dest_i[i]);
00030 }
00031
00032
00033 Char_t* unpack_lel_to_string(const Int_t* src_i, UInt_t nwd) {
00034
00035
00036
00037
00038 const UInt_t cperl = sizeof(Int_t)/sizeof(Char_t);
00039
00040 UInt_t nchar = nwd*cperl;
00041
00042 Char_t* dest_c = new Char_t [nchar];
00043 Int_t* dest_i = (Int_t*) dest_c;
00044 const Char_t* src_c = (const Char_t*) src_i;
00045 memcpy(dest_c,src_c,nchar);
00046
00047
00048 for (UInt_t i=0; i<nwd; ++i)
00049 dest_i[i] = (Int_t)minos_letohl((UInt_t)dest_i[i]);
00050
00051 return dest_c;
00052 }