KLF_EXPORT KLFSysInfo::BatteryInfo _klf_linux_battery_info(bool want_info_onbatterypower) { KLFSysInfo::BatteryInfo info; if (!QFile::exists(SYSINFO_FILE)) { info.islaptop = false; info.onbatterypower = false; return info; } if (want_info_onbatterypower) { QFile file(SYSINFO_FILE); if (!file.open(QIODevice::ReadOnly)) { klfWarning("Can't open file "<<SYSINFO_FILE); return info; } QTextStream tstr(&file); int val; tstr >> val; // val == 1 -> power online // val == 0 -> on battery power info.onbatterypower = ! (bool)val; } info.islaptop = true; return info; }
// !!UNC static LPTSTR translate( LPCTSTR path, TCHAR *buffer ) { TCHAR *l = host_drive_list; const TCHAR *p = path; while(*l) { if(_totupper(p[1]) == _totupper(*l)) break; l += _tcslen(l) + 1; } if(p[0] == TEXT('\\') && *l && (p[2] == 0 || p[2] == TEXT(':') || p[2] == TEXT('\\'))) { p += 2; if(*p == TEXT(':')) p++; if(*p == TEXT('\\')) p++; _sntprintf( buffer, MAX_PATH_LENGTH, TEXT("%c:\\%s"), *l, p ); } else { if(*path == TEXT('\\')) { _sntprintf( buffer, MAX_PATH_LENGTH, TEXT("%s%s"), virtual_root, path ); } else { int len = _tcslen(path); if(len == 0 || path[len-1] == TEXT('\\')) { make_mask( buffer, virtual_root, path, tstr(my_computer).get() ); } else { make_mask( buffer, virtual_root, path, 0 ); } } } charset_mac2host( buffer ); return buffer; }
int my_remove( const char *path ) { DISABLE_ERRORS; auto tpath = tstr(path); LPTSTR p = MRP(tpath.get()); strip_trailing_bs(p); int result; if(is_dir(p)) { result = myRemoveDirectory( p ); } else { D(bug(TEXT("DeleteFile %s\n"), p)); result = DeleteFile( p ); } if(result) { result = 0; my_errno = 0; } else { result = -1; if(exists(p)) { my_errno = EACCES; } else { my_errno = ENOENT; } } D(bug(TEXT("remove(%s,%s) = %d\n"), tpath.get(), p, result)); RESTORE_ERRORS; return result; }
// Exported hook functions int my_stat( const char *path, struct my_stat *st ) { DISABLE_ERRORS; auto tpath = tstr(path); int result; if(*tpath.get() == 0) { /// virtual root memset( st, 0, sizeof(struct my_stat) ); st->st_mode = _S_IFDIR; result = 0; my_errno = 0; } else { result = _tstat( MRP(tpath.get()), (struct _stat *)st ); if(result < 0) { my_errno = errno; } else { my_errno = 0; } } D(bug(TEXT("stat(%s,%s) = %d\n"), tpath.get(), MRP(tpath.get()), result)); if(result >= 0) dump_stat( st ); RESTORE_ERRORS; return result; }
int my_open( const char *path, int mode, ... ) { DISABLE_ERRORS; int result; auto tpath = tstr(path); LPCTSTR p = MRP(tpath.get()); // Windows "open" does not handle _O_CREAT and _O_BINARY as it should if(mode & _O_CREAT) { if(exists(p)) { result = _topen( p, mode & ~_O_CREAT ); D(bug(TEXT("open-nocreat(%s,%s,%d) = %d\n"), tpath.get(), p, mode, result)); } else { result = _tcreat( p, _S_IWRITE|_S_IREAD ); if(result < 0) { make_folders(p); result = _tcreat( p, _S_IWRITE|_S_IREAD ); } D(bug(TEXT("open-creat(%s,%s,%d) = %d\n"), tpath.get(), p, mode, result)); } } else { result = _topen( p, mode ); D(bug(TEXT("open(%s,%s,%d) = %d\n"), tpath.get(), p, mode, result)); } if(result < 0) { my_errno = errno; } else { setmode(result, _O_BINARY); my_errno = 0; } RESTORE_ERRORS; return result; }
//how states change between various states void create_states(i64 n, vector<vector<int> >& vtransit ) { //states gives us all effective numbers, the last one is n vector<string> states;//for each state, empty, a, ab, abc....; states.push_back(string()); string tstr(to_string(n)); for(unsigned int i = 0; i < tstr.size(); ++i){ states.push_back(tstr.substr(0,i+1)); } vtransit.clear(); //vtransit tells us how the state changes when we have //some new input vtransit.resize(states.size()); for(unsigned int i = 0; i < vtransit.size(); ++i){ vtransit[i].resize(states.size(), 0); } //the last state is not necessary to consider for(unsigned int j = 0; j < states.size()-1; ++j){ i64 n0 = 0; if(!states[j].empty()) n0 = stoll(states[j]); n0 *= 10; for(unsigned int i = 0; i < 10; ++i){ i64 num = n0 + i; string si(to_string(num)); int matched = check_states(si, j+1, states); ++vtransit[j][matched]; } } }
TPtrC DeprecatedString::des() const { if (!dataHandle[0]->_isUnicodeValid) dataHandle[0]->makeUnicode(); TPtrC tstr((const TUint16*)unicode(), length() ); return tstr; }
int MessageOut(HWND hWnd,long strMsg, long strTitle, UINT mbstatus) { CString tstr(""); CString mstr(""); VERIFY(tstr.LoadString(strTitle)); VERIFY(mstr.LoadString(strMsg)); return ::MessageBox(hWnd,mstr,tstr,mbstatus); }
int my_rename( const char *old_path, const char *new_path ) { DISABLE_ERRORS; int result = -1; auto told_path = tstr(old_path); auto tnew_path = tstr(new_path); LPCTSTR p_old = MRP(told_path.get()); LPCTSTR p_new = MRP2(tnew_path.get()); result = my_access(old_path,0); if(result < 0) { // my_errno already set } else { if(is_same_drive(p_old,p_new)) { result = _trename( p_old, p_new ); if(result != 0) { // by definition, rename may also return a positive value to indicate an error my_errno = errno; } else { my_errno = 0; } } else { if(is_dir(p_old)) { result = folder_copy( p_old, p_new ); // my_errno already set if(result >= 0) { if(myRemoveDirectory( p_old )) { my_errno = 0; result = 0; } else { // there is no proper error code for this failure. my_errno = EACCES; result = -1; } } } else { result = file_move( p_old, p_new ); // my_errno already set } } } D(bug(TEXT("rename(%s,%s,%s,%s) = %d\n"), told_path.get(), p_old, tnew_path.get(), p_new, result)); RESTORE_ERRORS; return result; }
int main(int argc, const char * argv[]) { CHString *str = tstr("r346457"); id obj = dynamic_cast<id>(str); str = obj->description(); CHLog("%p@", str); arc_ptr<CHMutableString> arc((CHMutableString *)str); arc_ptr<CHString> arc2; arc2 = arc; return 0; }
int MessageOut(HWND hWnd, long strMsg, long strTitle, UINT mbstatus, long val1, long val2) { CString tstr(""); CString mstr(""); CString fstr(""); VERIFY(tstr.LoadString(strTitle)); VERIFY(mstr.LoadString(strMsg)); fstr.Format(mstr,val1,val2); return ::MessageBox(hWnd,fstr,tstr,mbstatus); }
static int lua_peekstr(lua_State *L) { lua::state st(L); char *buf; buf=new char[256]; peekstr(st.as<size_t>(1),buf,256); std::string tstr(buf); st.push(tstr); delete [] buf; return 1; }
void Java_org_cocos2dx_cpp_FacebookConnectPlugin_nativeCallback(JNIEnv* env, jobject thiz, jint cbIndex,jstring params) { if (params != NULL) { const char* str; str = env->GetStringUTFChars(params, 0); std::string tstr(str); HelloWorld::CallFunctionName(cbIndex,tstr); } else { std::string tstr = ""; HelloWorld::CallFunctionName(cbIndex,tstr); } }
std::string FileInfo::linksTo() { #if EFSW_PLATFORM != EFSW_PLATFORM_WIN32 if ( isLink() ) { char * ch = realpath( Filepath.c_str(), NULL); std::string tstr( ch ); free( ch ); return tstr; } #endif return std::string(""); }
int constant(LVALUE *lval) { constype=CINT; conssign=dosigned; lval->is_const = 1 ; /* assume constant will be found */ if ( fnumber(&lval->const_val) ) { lval->val_type=DOUBLE; if ( doublestrings ) { immedlit(litlab); outdec(lval->const_val); nl(); callrts("__atof2"); WriteDefined("math_atof",1); } else { immedlit(dublab); outdec(lval->const_val); nl(); callrts("dload"); } lval->is_const = 0 ; /* floating point not constant */ lval->flags=0; return(1); } else if ( number(&lval->const_val) || pstr(&lval->const_val) ) { /* Insert long stuff/long pointer here? */ if ( (unsigned long )lval->const_val >= 65536LU ) constype = LONG; lval->val_type = constype ; lval->flags = (lval->flags&MKSIGN)|conssign; if (constype == LONG) vlongconst(lval->const_val); else vconst(lval->const_val); return(1); } else if ( tstr(&lval->const_val) ) { lval->is_const = 0 ; /* string address not constant */ lval->ptr_type=CCHAR; /* djm 9/3/99 */ lval->val_type=CINT; lval->flags=0; immedlit(litlab); } else { lval->is_const = 0 ; return(0); } outdec(lval->const_val); nl(); return(1); }
int my_access( const char *path, int mode ) { DISABLE_ERRORS; auto tpath = tstr(path); LPCTSTR p = MRP(tpath.get()); WIN32_FIND_DATA fdata; int result; if(is_dir(p)) { // access does not work for folders. HANDLE h = FindFirstFile( p, &fdata ); if(h != INVALID_HANDLE_VALUE) { FindClose( h ); if(mode == W_OK) { if( (fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0 ) { result = 0; my_errno = 0; } else { result = -1; my_errno = EACCES; } } else { result = 0; my_errno = 0; } } else { result = -1; my_errno = ENOENT; } } else { // W_OK, F_OK are ok. result = _taccess(p,mode); if(result < 0) { my_errno = errno; } else { my_errno = 0; } } D(bug(TEXT("access(%s,%s,%d) = %d\n"), tpath.get(), p, mode, result)); RESTORE_ERRORS; return result; }
int my_mkdir( const char *path, int mode ) { DISABLE_ERRORS; auto tpath = tstr(path); LPTSTR p = MRP(tpath.get()); strip_trailing_bs(p); int result = _tmkdir( p ); if(result < 0) { make_folders(p); result = _tmkdir( p ); } if(result < 0) { my_errno = errno; } else { my_errno = 0; } D(bug(TEXT("mkdir(%s,%s,%d) = %d\n"), tpath.get(), p, mode, result)); RESTORE_ERRORS; return result; }
int my_creat( const char *path, int mode ) { DISABLE_ERRORS; auto tpath = tstr(path); LPCTSTR p = MRP(tpath.get()); int result = _tcreat( p, _S_IWRITE|_S_IREAD ); // note mode if(result < 0) { make_folders(p); result = _tcreat( p, _S_IWRITE|_S_IREAD ); // note mode } if(result < 0) { my_errno = errno; } else { setmode(result, _O_BINARY); my_errno = 0; } D(bug(TEXT("creat(%s,%s,%d) = %d\n"), tpath.get(), p, mode,result)); RESTORE_ERRORS; return result; }
int main() { QString folder("C:\\Users\\Gigotdarnaud\\Desktop\\CircleTexturesHD"); QString outFolder("C:\\Users\\Gigotdarnaud\\Desktop\\CircleTexturesHD\\OUT"); QDir dir (folder); QStringList filters; filters << "*.bmp" << "*.png" << "*.jpg" << "*.tiff"; QStringList ls=dir.entryList(filters, QDir::Files|QDir::NoDotAndDotDot); QFile file(outFolder+'/'+"filelist.list"); file.open(QIODevice::WriteOnly|QIODevice::Text); QTextStream tstr(&file); int c=0; for(int i=0, m=ls.size();i<m;++i) { c+=splitImage(folder+'/'+ls[i], outFolder, tstr,c); } return 0; }
QoreStringNode *RegexTransNode::exec(const QoreString *str, ExceptionSink *xsink) const { //printd(5, "source='%s' target='%s' ('%s')\n", source->getBuffer(), target->getBuffer(), str->getBuffer()); TempEncodingHelper tstr(str, QCS_DEFAULT, xsink); if (*xsink) return 0; QoreStringNode *ns = new QoreStringNode; for (qore_size_t i = 0; i < tstr->strlen(); i++) { char c = tstr->getBuffer()[i]; const char *p = strchr(source->getBuffer(), c); if (p) { qore_size_t pos = p - source->getBuffer(); if (target->strlen() <= pos) pos = target->strlen() - 1; ns->concat(target->getBuffer()[pos]); } else ns->concat(c); } return ns; }
bool check_scrabble_missed(ScrabbleTst& tst, ScrabbleTst& found, int jokers) { typedef std::pair<std::string::iterator, std::string::iterator> MissPair; for (ScrabbleTst::iterator A = tst.begin(); A != tst.end(); ++A) { std::string tstr(A.key()); std::sort(tstr.begin(), tstr.end()); if (found.find(tstr) != found.end()) continue; for (ScrabbleTst::iterator B = found.begin(); B != found.end(); ++B) { if (tstr.size() > B.key().size()) continue; ++scrabble_testcount; std::string fs(B.key()); MissPair miss = std::mismatch(fs.begin(), fs.end(), tstr.begin()); if (miss.first == fs.end() && miss.second == tstr.end()) { std::cout << "SCRABBLE(" << jokers << "): " << tstr << " not found by " << fs << "\n"; return false; } } } return true; }
struct DIR *opendir( const char *path ) { DISABLE_ERRORS; auto tpath = tstr(path); DIR *d = new DIR; if(d) { memset( d, 0, sizeof(DIR) ); if(*tpath.get() == 0) { d->vname_list = host_drive_list; if(d->vname_list) { d->h = VIRTUAL_ROOT_ID; _tcscpy( d->FindFileData.cFileName, d->vname_list ); d->FindFileData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY; } else { d->h = INVALID_HANDLE_VALUE; } } else { TCHAR mask[MAX_PATH_LENGTH]; make_mask( mask, MRP(tpath.get()), TEXT("*.*"), 0 ); D(bug(TEXT("opendir path=%s, mask=%s\n"), tpath.get(), mask)); d->h = FindFirstFile( mask, &d->FindFileData ); if(d->h == INVALID_HANDLE_VALUE) { delete d; d = 0; } } } D(bug(TEXT("opendir(%s,%s) = %08x\n"), tpath.get(), MRP(tpath.get()), d)); RESTORE_ERRORS; return d; }
bool ether_init(void) { TCHAR buf[256]; // Do nothing if no Ethernet device specified const char *name = PrefsFindString("ether"); if (name == NULL) return false; ether_multi_mode = PrefsFindInt32("ethermulticastmode"); ether_use_permanent = PrefsFindBool("etherpermanentaddress"); // Determine Ethernet device type net_if_type = -1; if (PrefsFindBool("routerenabled") || strcmp(name, "router") == 0) net_if_type = NET_IF_ROUTER; else if (strcmp(name, "slirp") == 0) net_if_type = NET_IF_SLIRP; else if (strcmp(name, "tap") == 0) net_if_type = NET_IF_TAP; else net_if_type = NET_IF_B2ETHER; // Initialize NAT-Router if (net_if_type == NET_IF_ROUTER) { if (!router_init()) net_if_type = NET_IF_FAKE; } // Initialize slirp library if (net_if_type == NET_IF_SLIRP) { if (slirp_init() < 0) { WarningAlert(GetString(STR_SLIRP_NO_DNS_FOUND_WARN)); return false; } } // Open ethernet device decltype(tstr(std::declval<const char*>())) dev_name; switch (net_if_type) { case NET_IF_B2ETHER: dev_name = tstr(PrefsFindString("etherguid")); if (dev_name == NULL || strcmp(name, "b2ether") != 0) dev_name = tstr(name); break; case NET_IF_TAP: dev_name = tstr(PrefsFindString("etherguid")); break; } if (net_if_type == NET_IF_B2ETHER) { if (dev_name == NULL) { WarningAlert("No ethernet device GUID specified. Ethernet is not available."); goto open_error; } fd = PacketOpenAdapter( dev_name.get(), ether_multi_mode ); if (!fd) { _sntprintf(buf, lengthof(buf), TEXT("Could not open ethernet adapter %s."), dev_name.get()); WarningAlert(buf); goto open_error; } // Get Ethernet address if(!PacketGetMAC(fd,ether_addr,ether_use_permanent)) { _sntprintf(buf, lengthof(buf), TEXT("Could not get hardware address of device %s. Ethernet is not available."), dev_name.get()); WarningAlert(buf); goto open_error; } D(bug("Real ethernet address %02x %02x %02x %02x %02x %02x\n", ether_addr[0], ether_addr[1], ether_addr[2], ether_addr[3], ether_addr[4], ether_addr[5])); const char *ether_fake_address; ether_fake_address = PrefsFindString("etherfakeaddress"); if(ether_fake_address && strlen(ether_fake_address) == 12) { char sm[10]; strcpy( sm, "0x00" ); for( int i=0; i<6; i++ ) { sm[2] = ether_fake_address[i*2]; sm[3] = ether_fake_address[i*2+1]; ether_addr[i] = (uint8)strtoul(sm,0,0); } D(bug("Fake ethernet address %02x %02x %02x %02x %02x %02x\n", ether_addr[0], ether_addr[1], ether_addr[2], ether_addr[3], ether_addr[4], ether_addr[5])); } } else if (net_if_type == NET_IF_TAP) { if (dev_name == NULL) { WarningAlert("No ethernet device GUID specified. Ethernet is not available."); goto open_error; } fd = tap_open_adapter(dev_name.get()); if (!fd) { _sntprintf(buf, lengthof(buf), TEXT("Could not open ethernet adapter %s."), dev_name.get()); WarningAlert(buf); goto open_error; } if (!tap_check_version(fd)) { _sntprintf(buf, lengthof(buf), TEXT("Minimal TAP-Win32 version supported is %d.%d."), TAP_VERSION_MIN_MAJOR, TAP_VERSION_MIN_MINOR); WarningAlert(buf); goto open_error; } if (!tap_set_status(fd, true)) { WarningAlert("Could not set media status to connected."); goto open_error; } if (!tap_get_mac(fd, ether_addr)) { _sntprintf(buf, lengthof(buf), TEXT("Could not get hardware address of device %s. Ethernet is not available."), dev_name.get()); WarningAlert(buf); goto open_error; } D(bug("Real ethernet address %02x %02x %02x %02x %02x %02x\n", ether_addr[0], ether_addr[1], ether_addr[2], ether_addr[3], ether_addr[4], ether_addr[5])); const char *ether_fake_address; ether_fake_address = PrefsFindString("etherfakeaddress"); if (ether_fake_address && strlen(ether_fake_address) == 12) { char sm[10]; strcpy( sm, "0x00" ); for( int i=0; i<6; i++ ) { sm[2] = ether_fake_address[i*2]; sm[3] = ether_fake_address[i*2+1]; ether_addr[i] = (uint8)strtoul(sm,0,0); } } #if 1 /* If we bridge the underlying ethernet connection and the TAP device altogether, we have to use a fake address. */ else { ether_addr[0] = 0x52; ether_addr[1] = 0x54; ether_addr[2] = 0x00; } #endif D(bug("Fake ethernet address %02x %02x %02x %02x %02x %02x\n", ether_addr[0], ether_addr[1], ether_addr[2], ether_addr[3], ether_addr[4], ether_addr[5])); } else if (net_if_type == NET_IF_SLIRP) { ether_addr[0] = 0x52; ether_addr[1] = 0x54; ether_addr[2] = 0x00; ether_addr[3] = 0x12; ether_addr[4] = 0x34; ether_addr[5] = 0x56; D(bug("Ethernet address %02x %02x %02x %02x %02x %02x\n", ether_addr[0], ether_addr[1], ether_addr[2], ether_addr[3], ether_addr[4], ether_addr[5])); } else { memcpy( ether_addr, router_mac_addr, 6 ); D(bug("Fake ethernet address (same as router) %02x %02x %02x %02x %02x %02x\n", ether_addr[0], ether_addr[1], ether_addr[2], ether_addr[3], ether_addr[4], ether_addr[5])); } // Start packet reception thread int_ack = CreateSemaphore( 0, 0, 1, NULL); if(!int_ack) { WarningAlert("WARNING: Cannot create int_ack semaphore"); goto open_error; } // nonsignaled int_sig = CreateSemaphore( 0, 0, 1, NULL); if(!int_sig) { WarningAlert("WARNING: Cannot create int_sig semaphore"); goto open_error; } int_sig2 = CreateSemaphore( 0, 0, 1, NULL); if(!int_sig2) { WarningAlert("WARNING: Cannot create int_sig2 semaphore"); goto open_error; } int_send_now = CreateSemaphore( 0, 0, 1, NULL); if(!int_send_now) { WarningAlert("WARNING: Cannot create int_send_now semaphore"); goto open_error; } init_queue(); if(!allocate_read_packets()) goto open_error; // No need to enter wait state if we can avoid it. // These all terminate fast. InitializeCriticalSectionAndSpinCount( &fetch_csection, 5000 ); InitializeCriticalSectionAndSpinCount( &queue_csection, 5000 ); InitializeCriticalSectionAndSpinCount( &send_csection, 5000 ); InitializeCriticalSectionAndSpinCount( &wpool_csection, 5000 ); ether_th = (HANDLE)_beginthreadex( 0, 0, ether_thread_feed_int, 0, 0, ðer_tid ); if (!ether_th) { D(bug("Failed to create ethernet thread\n")); goto open_error; } thread_active = true; unsigned int dummy; unsigned int (WINAPI *receive_func)(void *); switch (net_if_type) { case NET_IF_SLIRP: receive_func = slirp_receive_func; break; default: receive_func = ether_thread_get_packets_nt; break; } ether_th2 = (HANDLE)_beginthreadex( 0, 0, receive_func, 0, 0, &dummy ); ether_th1 = (HANDLE)_beginthreadex( 0, 0, ether_thread_write_packets, 0, 0, &dummy ); // Everything OK return true; open_error: if (thread_active) { TerminateThread(ether_th,0); ether_th = 0; if (int_ack) CloseHandle(int_ack); int_ack = 0; if(int_sig) CloseHandle(int_sig); int_sig = 0; if(int_sig2) CloseHandle(int_sig2); int_sig2 = 0; if(int_send_now) CloseHandle(int_send_now); int_send_now = 0; thread_active = false; } if (fd) { switch (net_if_type) { case NET_IF_B2ETHER: PacketCloseAdapter(fd); break; case NET_IF_TAP: tap_close_adapter(fd); break; } fd = 0; } return false; }
void Win::LoadInterfaceGraphics() { //cout << "Win::LoadInterfaceGraphics()" << endl; bool dir_exists = true; BString dirstr( "/boot/home/config/settings/Themis/interface/" ); BDirectory dir( dirstr.String() ); if( dir.InitCheck() != B_OK ) { dir_exists = false; //cout << "/boot/home/config/settings/Themis/interface/ does not exist" << endl; } // load the icons either from bitmap-file or if not present, from internal // icon hexdumps located in "ThemisIcons.h" // initialize all bitmaps with NULL for( int i=0; i < 10; i++ ) bitmaps[i] = NULL; // the array with file-names const char* names[9]; // 4-pic bitmap names[0] = "button_back.png"; names[1] = "button_forward.png"; names[2] = "button_stop.png"; names[3] = "button_home.png"; names[4] = "button_newtab.png"; // 3-pic bitmap names[5] = "button_reload.png"; names[6] = "button_go.png"; names[7] = "button_closetabview.png"; // 1-pic bitmap names[8] = "icon_document.png"; names[9] = "icon_document_empty.png"; // the array with pointers to the hexdumps const unsigned char* hexp[10]; // 4-pic bitmap hexp[0] = button_back_hex; hexp[1] = button_forward_hex; hexp[2] = button_stop_hex; hexp[3] = button_home_hex; hexp[4] = button_newtab_hex; // 3-pic bitmap hexp[5] = button_reload_hex; hexp[6] = button_go_hex; hexp[7] = button_closetabview_hex; // 1-pic bitmap hexp[8] = icon_document_hex; hexp[9] = icon_document_empty_hex; // a tempstring :D // ( i had to move this below the 2 char arrays .. otherwise i got a // seqm viol. and tstr was initialized with hexp[9] .. // dunno if i did some very lousy coding mistakes or if sth is playing me a trick ) BString tstr( dirstr.String() ); for( int i = 0; i < 10; i++ ) { //cout << "bitmap " << i << ": "; if( dir_exists == true ) { //cout << "loading from file" << endl; // load from file tstr.SetTo( dirstr.String() ); if( ( bitmaps[i] = BTranslationUtils::GetBitmapFile( ( tstr += names[i] ).String() ) ) == 0 ) cout << "loading from bitmap-file failed" << endl; } if( bitmaps[i] == NULL ) { // load from hexdump //cout << "loading from hexdump" << endl; if( i <= 4 ) { bitmaps[i] = new BBitmap( BRect( 0,0,63,15 ), B_RGB32 ); memcpy( bitmaps[i]->Bits(), hexp[i], 4096 ); } if( i >= 5 && i <= 7 ) { bitmaps[i] = new BBitmap( BRect( 0,0,47,15 ), B_RGB32 ); memcpy( bitmaps[i]->Bits(), hexp[i], 3072 ); } if( i == 8 || i == 9 ) { bitmaps[i] = new BBitmap( BRect( 0,0,15,15 ), B_RGB32 ); memcpy( bitmaps[i]->Bits(), hexp[i], 1024 ); } } } }
//================================================================================================= // Pocz¹tek programu //================================================================================================= int main(int argc, char **argv) { setlocale(LC_ALL, ""); setlocale(LC_NUMERIC, "C"); if(argc == 1) { printf("QMSH converter, version %s (output %d).\nUsage: \"converter FILE.qmsh.tmp\". Use \"converter -h\" for list of commands.\n", CONVERTER_VERSION, QMSH::VERSION); return 0; } export_phy = false; int result = 0; bool check_subdir = true, force_update = false; for(int i = 1; i < argc; ++i) { char* cstr = argv[i]; if(cstr[0] == '-') { string str(cstr); if(str == "-h" || str == "-help" || str == "-?") { printf("Converter switches:\n" "-h/help/? - list of commands\n" "-v - show converter version and input file versions\n" "-o FILE - output file name\n" "-g1 - use single group (default)\n" "-gf FILE - use animation groups from file\n" "-gcreate - create animation groups and save as file\n" "-gcreaten FILE - create animation groups and save as named file\n" "-phy - export only physic mesh (default extension .phy)\n" "-normal - export normal mesh\n" "-info FILE - show information about mesh (version etc)\n" "-details OPTIONS FILE - like info but more details\n" "-compare FILE FILE2 - compare two meshes and show differences\n" "-upgrade FILE - upgrade mesh to newest version\n" "-upgradedir DIR - upgrade all meshes in directory and subdirectories\n" "-subdir - check subdirectories in upgradedir (default)\n" "-nosubdir - don't check subdirectories in upgradedir\n" "-force - force upgrade operation\n" "-noforce - don't force upgrade operation (default)\n" "Parameters without '-' are treated as input file.\n"); } else if(str == "-v") { printf("Converter version %s\nHandled input file version: %d..%d\nOutput file version: %d\n", CONVERTER_VERSION, QmshTmpLoader::QMSH_TMP_HANDLED_VERSION.x, QmshTmpLoader::QMSH_TMP_HANDLED_VERSION.y, QMSH::VERSION); } else if(str == "-g1") gopt = GO_ONE; else if(str == "-gf") { if(i + 1 < argc) { ++i; group_file = argv[i]; gopt = GO_FILE; } else printf("Missing FILE name for '-gf'!\n"); } else if(str == "-gcreate") { gopt = GO_CREATE; group_file.clear(); } else if(str == "-gcreaten") { if(i + 1 < argc) { ++i; group_file = argv[i]; gopt = GO_CREATE; } else printf("Missing FILE name for '-gcreaten'!\n"); } else if(str == "-o") { if(i + 1 < argc) { ++i; output_file = argv[i]; force_output = true; } else printf("Missing OUTPUT PATH for '-o'!\n"); } else if(str == "-phy") export_phy = true; else if(str == "-normal") export_phy = false; else if(str == "-info") { if(i + 1 < argc) { ++i; Info(argv[i]); } else printf("Missing FILE for '-info'!\n"); } else if(str == "-details") { if(i + 2 < argc) { Info(argv[i + 2], argv[i + 1]); i += 2; } else { printf("Missing OPTIONS or FILE for '-details'!\n"); ++i; } } else if(str == "-compare") { if(i + 2 < argc) { Compare(argv[i + 1], argv[i + 2]); i += 2; } else { printf("Missing FILEs for '-compare'!\n"); ++i; } } else if(str == "-upgrade") { if(i + 1 < argc) { ++i; Upgrade(argv[i], force_update); } else printf("Missing FILE for '-upgrade'!\n"); } else if(str == "-upgradedir") { if(i + 1 < argc) { ++i; UpgradeDir(argv[i], force_update, check_subdir); } else printf("Missing FILE for '-upgradedir'!\n"); } else if(str == "-subdir") check_subdir = true; else if(str == "-nosubdir") check_subdir = false; else if(str == "-force") force_update = true; else if(str == "-noforce") force_update = false; else printf("Unknown switch \"%s\"!\n", cstr); } else { string tstr(cstr); if(!ConvertToQmsh(tstr)) result = 1; group_file.clear(); output_file.clear(); gopt = GO_ONE; } } if(IsDebuggerPresent()) { printf("Press any key to exit..."); _getch(); } return result; }
TPtrC8 DeprecatedString::des8() const { TPtrC8 tstr((const TUint8*)latin1(), length()); return tstr; }
bool IODicom<T>::GetAttributes(PGCore::MetaData<T>& oMetaDataObject, const std::string &iFilePath) { #ifdef _DEBUG LOG0("{ IODicom::GetAttributes"); #endif if (iFilePath.empty()) { LOG0("IO/IODicom::GetAttributes Empty filename"); return false; } #ifdef _PG_GDDCM_ #else OFCondition status = m_fileformat.loadFile(iFilePath.c_str()); if (!status.good()) { LOG2("IO/IODicom::GetAttributes: Cannot read dicom file %s: (%s).", iFilePath.c_str(), status.text()); return false; } #ifdef _DEBUG LOG2("\tIODicom::GetAttributes: Successfully read dicom file %s: (%s).", iFilePath.c_str(), status.text()); #endif // read the meta file here //LOG1("IO/IOBase::ReadMetaData: File: %s", iMetaFileName.c_str()); DcmDataset *dataset = m_fileformat.getDataset(); if (dataset==NULL) { return false; } // patient name OFString patientsName; bool res = dataset->findAndGetOFString(DCM_PatientsName, patientsName).good(); if (!res) { LOG0("IO/IODicom::Read: Cannot fetch patient name"); return false; } oMetaDataObject.SetPatientName(std::string(patientsName.c_str())); #ifdef _DEBUG LOG1("\tIODicom::Read: Successfully read PatientName: (%s).", patientsName.c_str()); #endif // modality OFString modalityStr; res = dataset->findAndGetOFString(DCM_Modality, modalityStr).good(); if (!res) { LOG0("IO/IODicom::Read: Cannot fetch modality"); return false; } PGCore::ePGModality modality = PGCore::MetaData<T>::StrToModality(modalityStr.c_str()); oMetaDataObject.SetModality(modality); #ifdef _DEBUG LOG1("\tIODicom::Read: Successfully read Modality: (%s).", modalityStr.c_str()); #endif // SOP Class UID OFString sopClassUIDStr; DcmMetaInfo *metaInfo = m_fileformat.getMetaInfo(); if (metaInfo) { metaInfo->findAndGetOFString(DCM_MediaStorageSOPClassUID, sopClassUIDStr); PGCore::ePGSOPClass sopClass = PGCore::MetaData<T>::StrToSOPClass(sopClassUIDStr.c_str()); oMetaDataObject.SetSOPClass(sopClass); // DCM_TransferSyntaxUID OFString transferSyntaxStr; res = metaInfo->findAndGetOFString(DCM_TransferSyntaxUID, transferSyntaxStr).good(); if (!res) { LOG0("IO/IODicom::Read:Warning: Cannot fetch TransferSyntaxUID"); } else { if (!strcmp(kPgTransferSyntaxUIDRawImplicitVRLittleEndian, transferSyntaxStr.c_str())) { oMetaDataObject.SetMSBFirst(0); } else if (!strcmp(kPgTransferSyntaxUIDRawExplicitVRLittle, transferSyntaxStr.c_str())) { oMetaDataObject.SetMSBFirst(0); } else if (!strcmp(kPgTransferSyntaxUIDRawExplicitVRLittle, transferSyntaxStr.c_str())) { oMetaDataObject.SetMSBFirst(1); } else if (!strcmp(kPgTransferSyntaxUIDLossLessRLE, transferSyntaxStr.c_str())) { LOG0("IO/IODicom::Read: Cannot read RLE compressed images yet"); return false; } else { std::string tstr(transferSyntaxStr.c_str()); std::string filterStr(kPgTransferSyntaxUIDJPEG); PGCore::ToUpper(tstr); PGCore::ToUpper(filterStr); size_t found=tstr.find(filterStr); bool isJPEG = (found!=string::npos); if (isJPEG) { LOG0("IO/IODicom::Read: Cannot read JPEG images yet"); return false; } } } } DcmItem *ditem = OFstatic_cast(DcmItem *, dataset); if (!ditem) { LOG0("IO/IODicom::Read: Cannot fetch ditem"); return false; } // Samples Per Pixel Uint16 samplesPerPixel = 0; res = ditem->findAndGetUint16(DCM_SamplesPerPixel, samplesPerPixel).good(); if (!res) { LOG0("IO/IODicom::Read: Warning: Cannot fetch SamplesPerPixel"); } else if (samplesPerPixel > sizeof(T)) { LOG2("IO/IODicom::Read: Cannot read SamplesPerPixel: %d, target resolution smaller: %d yet", samplesPerPixel, sizeof(T)); return false; } oMetaDataObject.SetSamplesPerPixel(samplesPerPixel); // DCM_PhotometricInterpretation OFString photoInterpretationStr; res = metaInfo->findAndGetOFString(DCM_PhotometricInterpretation, photoInterpretationStr).good(); if (!res) { #ifdef _DEBUG LOG0("IO/IODicom::Read:Warning Cannot fetch PhotometricInterpretation"); #endif } else if (strcmp(kPgPhotometricRepresentationMChrome2, photoInterpretationStr.c_str())) { #ifdef _DEBUG LOG1("IO/IODicom::Read: Cannot read PhotometricInterpretation %s", photoInterpretationStr.c_str()); #endif return false; } // DCM_NumberOfFrames long numFrames = 1; res = dataset->findAndGetLongInt(DCM_NumberOfFrames, numFrames).good(); if (!res) { #ifdef _DEBUG LOG0("IO/IODicom::Read: Warning: Cannot fetch NumberOfFrames"); #endif oMetaDataObject.SetFrameCount(1); } else { oMetaDataObject.SetFrameCount(numFrames); } // size Uint16 imageRows = 0; Uint16 imageColumns = 0; res = ditem->findAndGetUint16(DCM_Rows, imageRows).good(); if (!res) { LOG0("IO/IODicom::Read: Cannot fetch rows"); return false; } res = ditem->findAndGetUint16(DCM_Columns, imageColumns).good(); if (!res) { LOG0("IO/IODicom::Read: Cannot fetch columns"); return false; } oMetaDataObject.SetSize(PGMath::Vector3D<int>(imageColumns, imageRows, 1)); #ifdef _DEBUG LOG2("\tIODicom::Read: Size: Rows: %d, Columns: %d", imageRows, imageColumns); #endif // number of bits Uint16 imageBitsAllocated = 0; res = ditem->findAndGetUint16(DCM_BitsAllocated, imageBitsAllocated).good(); if (!res) { LOG0("IO/IODicom::Read: Cannot fetch bits allocated"); return false; } oMetaDataObject.SetNumberOfBits(imageBitsAllocated); #ifdef _DEBUG LOG1("\tIODicom::Read: bits allocated: %d", imageBitsAllocated); #endif // spacing Float64 sx=1, sy=1; DcmElement *elem = 0; OFCondition cond = dataset->findAndGetElement(DCM_PixelSpacing, elem); if(!cond.good()) { LOG1("IO/IODicom::Read:Warning Cannot fetch pixel spacing (%s)", cond.text()); } else { cond = elem->getFloat64(sx, 0); if(!cond.good()) { LOG1("IO/IODicom::Read:Warning Cannot fetch pixel X spacing (%s)", cond.text()); } cond = elem->getFloat64(sy, 1); if(!cond.good()) { LOG1("IO/IODicom::Read:Warning Cannot fetch pixel Y spacing (%s)", cond.text()); } } if (sx!=sy) { LOG2("IO/IODicom::Read:Warning: X/Y spacings (%3.2f, %3.2f) mismatch. Ignoring anisotrpy", sx, sy); sy = sx; } #ifdef _DEBUG LOG2("\tIODicom::Read: pixel X and Y spacings (%3.5f %3.5f)",sx, sy); #endif oMetaDataObject.SetSpacing(PGMath::Vector3D<float>(sx, sy, 1)); // STUDY UID OFString studyUIDStr; res = dataset->findAndGetOFString(DCM_StudyInstanceUID, studyUIDStr).good(); if (!res) { LOG0("IO/IODicom::Read:Warning Cannot fetch StudyUID"); } else { oMetaDataObject.SetStudyUID(std::string(studyUIDStr.c_str())); } // series UID OFString seriesUIDStr; res = dataset->findAndGetOFString(DCM_SeriesInstanceUID, seriesUIDStr).good(); if (!res) { LOG0("IO/IODicom::Read:Warning Cannot fetch seriesUID"); } else { oMetaDataObject.SetSeriesUID(std::string(seriesUIDStr.c_str())); //LOG1("IO/IODicom::Read:seriesUID : %s", oMetaDataObject.GetSeriesUID().c_str()); } // orientation Float64 rowOr[3] = { 1.0f, 0.0f, 0.0f }, colOr[3] = { 0.0f, 1.0f, 0.0f }; std::vector<PGMath::Vector3D<float> > orXs; std::vector<PGMath::Vector3D<float> > orYs; cond = dataset->findAndGetElement(DCM_ImageOrientationPatient, elem); if(!cond.good()) { LOG1("IO/IODicom::Read:Warning Cannot fetch DCM_ImageOrientationPatient (%s)", cond.text()); } else { elem->getFloat64(rowOr[0], 0); elem->getFloat64(rowOr[1], 1); elem->getFloat64(rowOr[2], 2); elem->getFloat64(colOr[0], 3); elem->getFloat64(colOr[1], 4); elem->getFloat64(colOr[2], 5); } orXs.push_back(PGMath::Vector3D<float>(rowOr[0], rowOr[1], rowOr[2])); oMetaDataObject.SetImageOrientationsPatientX(orXs); #ifdef _DEBUG LOG3("\tIODicom::Read: Image Row vector orientation (%3.5f %3.5f %3.5f)", rowOr[0], rowOr[1], rowOr[2]); #endif orYs.push_back(PGMath::Vector3D<float>(colOr[0], colOr[1], colOr[2])); oMetaDataObject.SetImageOrientationsPatientY(orYs); #ifdef _DEBUG LOG3("\tIODicom::Read: Image Col vector orientation (%3.5f %3.5f %3.5f)", colOr[0], colOr[1], colOr[2]); #endif // position Float64 imgPos[3] = { 0.0f, 0.0f, 0.0f }; std::vector<PGMath::Vector3D<float> > positions; cond = dataset->findAndGetElement(DCM_ImagePositionPatient, elem); if(!cond.good()) { LOG1("IO/IODicom::Read:Warning Cannot fetch DCM_ImagePositionPatient (%s)", cond.text()); } else { elem->getFloat64(imgPos[0], 0); elem->getFloat64(imgPos[1], 1); elem->getFloat64(imgPos[2], 2); } positions.push_back(PGMath::Vector3D<float>(imgPos[0], imgPos[1], imgPos[2])); oMetaDataObject.SetImagePositionsPatient(positions); #ifdef _DEBUG LOG3("\tIODicom::Read: Image Position (%3.5f %3.5f %3.5f)", imgPos[0], imgPos[1], imgPos[2]); #endif // slope / intercept if (modality==PGCore::kPGModalityCT || modality==PGCore::kPGModalityPT) { Float64 slope = -999.0f; cond = dataset->findAndGetElement(DCM_RescaleSlope, elem); if(!cond.good()) { LOG1("IO/IODicom::Read:Warning Cannot fetch DCM_RescaleSlope (%s)", cond.text()); } else { cond = elem->getFloat64(slope, 0); if(cond.good()) //if (dataset->findAndGetFloat64(DCM_RescaleIntercept, slope) == EC_Normal) { oMetaDataObject.SetSlope(slope); //LOG1("IO/IODicom::Read: Cannot fetch pixel Y spacing (%s)", cond.text()); } } Float64 intercept = -999.0f; //dataset->findAndGetFloat64(DCM_RescaleIntercept, intercept); cond = dataset->findAndGetElement(DCM_RescaleIntercept, elem); if(!cond.good()) { LOG1("IO/IODicom::Read:Warning Cannot fetch DCM_RescaleIntercept (%s)", cond.text()); } else { cond = elem->getFloat64(intercept, 0); if(cond.good()) //if (dataset->findAndGetFloat64(DCM_RescaleIntercept, intercept) == EC_Normal) { oMetaDataObject.SetIntercept(intercept); } } } /* Uint16 imageBytesAllocated = 0; Uint16 imagePlanarConfiguration = 0; Uint16 imageSamplesPerPixel = 0; Sint32 imageFrames = 1; Uint16 imageBitsAllocated = 0; if (result.good()) result = ditem->findAndGetUint16(DCM_BitsAllocated, imageBitsAllocated); res = ditem->findAndGetUint16(DCM_SamplesPerPixel, imageSamplesPerPixel); // slope / intercept // high bit // planar configuration // endianness oMetaData->SetMSBFirst(getValueI(iStr,std::string(kPGTagMSBFirst))); */ #endif #ifdef _DEBUG LOG0("} IODicom::GetAttributes"); #endif return true; }
void forOlya() { TString ntuple = "flatout"; // or "mvaout" TFile* f = (ntuple=="flatout") ? new TFile("flatout.periodall+MC.muons.mva.analysis.n0.j0.loose.root","READ") : new TFile("mvaout.muons.root","READ");; TTree* tS0 = (TTree*)f->Get((ntuple=="flatout") ? "flatout_Wtaunu_3mu" : "fltmva_Wtaunu_3mu"); TTree* tS = (TTree*)f->Get((ntuple=="flatout") ? "flatout_Wtaunu_200k_3mu" : "fltmva_Wtaunu_200k_3mu"); TTree* tD = (TTree*)f->Get((ntuple=="flatout") ? "flatout_Data" : "fltmva_Data"); TString smMinTraining = tstr(mTrainingMinGlob,0); TString smMaxTraining = tstr(mTrainingMaxGlob,0); TString smMinSBleft = tstr(mSideBandLeftLowerMeVGlob,0); TString smMaxSBleft = tstr(mBlindMinGlob,0); TString smMinSBright = tstr(mBlindMaxGlob,0); TString smMaxSBright = tstr(mSideBandRightUpperMeVGlob,0); TString sxSRmin = tstr(mSRminMeVGlob,0); TString sxSRmax = tstr(mSRmaxMeVGlob,0); TString soptBDTcut = tstr(optBDTcut,4); TString sminBDTcut = tstr(minBDTcut,4); TString cuts_sig = ""; TString cuts_bkg = ""; Float_t ninitS = -1; Float_t npassedS = -1; Float_t npassedD = -1; bool blinded = true; bool unblinded = false; bool doBDT = true; bool noBDT = false; //// loose training selection cuts_sig = postBDTcut(smMinTraining,smMinSBleft,smMaxSBright,smMaxTraining,"-1","-1","sig", "","", unblinded,noBDT,"preTraining",ntuple); cuts_bkg = postBDTcut(smMinTraining,smMinSBleft,smMaxSBright,smMaxTraining,"-1","-1","bkg", "","", blinded,noBDT,"preTraining",ntuple); npassedS = tS->GetEntries(cuts_sig); cout << "Loose+training only (signal) : " << npassedS << endl; npassedD = tD->GetEntries(cuts_bkg); cout << "Loose+training only (SB data): " << npassedD << endl; //// loose selection cuts_sig = postBDTcut(smMinSBleft,smMaxSBleft,smMinSBright,smMaxSBright,"-1","-1","sig", sxSRmin,sxSRmax, unblinded,noBDT,"preTraining",ntuple); cuts_bkg = postBDTcut(smMinSBleft,smMaxSBleft,smMinSBright,smMaxSBright,"-1","-1","bkg", sxSRmin,sxSRmax, blinded,noBDT,"preTraining",ntuple); npassedS = tS->GetEntries(cuts_sig); cout << "Loose only (signal) : " << npassedS << endl; npassedD = tD->GetEntries(cuts_bkg); cout << "Loose only (SB data): " << npassedD << endl; //// loose+x>x0 selection cuts_sig = postBDTcut(smMinSBleft,smMaxSBleft,smMinSBright,smMaxSBright,sminBDTcut,sminBDTcut,"sig", sxSRmin,sxSRmax, unblinded,doBDT,"preTraining",ntuple); cuts_bkg = postBDTcut(smMinSBleft,smMaxSBleft,smMinSBright,smMaxSBright,sminBDTcut,sminBDTcut,"bkg", sxSRmin,sxSRmax, blinded,doBDT,"preTraining",ntuple); npassedS = tS->GetEntries(cuts_sig); cout << "Loose+x>x0 only (signal) : " << npassedS << endl; npassedD = tD->GetEntries(cuts_bkg); cout << "Loose+x>x0 only (SB data): " << npassedD << endl; //// tight selection cuts_sig = postBDTcut(smMinSBleft,smMaxSBleft,smMinSBright,smMaxSBright,"-1","-1","sig", sxSRmin,sxSRmax, unblinded,noBDT,"postTraining",ntuple); cuts_bkg = postBDTcut(smMinSBleft,smMaxSBleft,smMinSBright,smMaxSBright,"-1","-1","bkg", sxSRmin,sxSRmax, blinded,noBDT,"postTraining",ntuple); npassedS = tS->GetEntries(cuts_sig); cout << "Tight only (signal) : " << npassedS << endl; npassedD = tD->GetEntries(cuts_bkg); cout << "Tight only (SB data): " << npassedD << endl; //// tight+x>x0 selection cuts_sig = postBDTcut(smMinSBleft,smMaxSBleft,smMinSBright,smMaxSBright,sminBDTcut,sminBDTcut,"sig", sxSRmin,sxSRmax, unblinded,doBDT,"postTraining",ntuple); cuts_bkg = postBDTcut(smMinSBleft,smMaxSBleft,smMinSBright,smMaxSBright,sminBDTcut,sminBDTcut,"bkg", sxSRmin,sxSRmax, blinded,doBDT,"postTraining",ntuple); npassedS = tS->GetEntries(cuts_sig); cout << "Tight+x>x0 only (signal) : " << npassedS << endl; npassedD = tD->GetEntries(cuts_bkg); cout << "Tight+x>x0 only (SB data): " << npassedD << endl; //// tight+x>x1 selection cuts_sig = postBDTcut(smMinSBleft,smMaxSBleft,smMinSBright,smMaxSBright,sminBDTcut,soptBDTcut,"sig", sxSRmin,sxSRmax, unblinded,doBDT,"postTraining",ntuple); cuts_bkg = postBDTcut(smMinSBleft,smMaxSBleft,smMinSBright,smMaxSBright,sminBDTcut,soptBDTcut,"bkg", sxSRmin,sxSRmax, blinded,doBDT,"postTraining",ntuple); npassedS = tS->GetEntries(cuts_sig); cout << "Tight+x>x1 only (signal) : " << npassedS << endl; npassedD = tD->GetEntries(cuts_bkg); cout << "Tight+x>x1 only (SB data): " << npassedD << endl; }