/***************************************************** ** ** AtlasLogicCountWorker --- Entry ** ******************************************************/ ExitCode Entry() { while ( sharedSection->doExit == false ) { Sleep( COUNT_THREAD_SLEEP_MILLISEC ); if ( sharedSection->countHasOrder ) { #ifdef DEB_ATLAS_LOGIC printf( "AtlasLogicCountWorker: location count started, filter \"%s\", country \"%s\", mode %d\n", str2char( logic->filter ), str2char( logic->country ), logic->mode ); wxLongLong starttime = wxGetLocalTimeMillis(); #endif sharedSection->countHasOrder = false; int c = dao->getMatchCount( logic->filter, logic->country, logic->mode ); if ( sharedSection->countHasOrder ) { // new order arrived, filter conditions have changed meanwhile: do not write results printf( "WARN: AtlasLogicCountWorker has new order before finishing request\n" ); } else { mutex.Lock(); sharedSection->countHasNews = true; sharedSection->count = c; mutex.Unlock(); #ifdef DEB_ATLAS_LOGIC wxLongLong duration = wxGetLocalTimeMillis() - starttime; printf( "AtlasLogicCountWorker: Location count finished, %d results in %ld millisec\n", c, duration.ToLong() ); #endif } } } return 0; }
/***************************************************** ** ** AtlasLogicFetchWorker --- Entry ** ******************************************************/ ExitCode Entry() { while ( sharedSection->doExit == false ) { Sleep( FETCH_THREAD_SLEEP_MILLISEC ); if ( sharedSection->fetchHasOrder ) { sharedSection->fetchIsWorking = true; #ifdef DEB_ATLAS_LOGIC printf( "AtlasLogicFetchWorker: location fetch started, filter \"%s\", country \"%s\", mode %d offset %d\n", str2char( logic->filter ), str2char( logic->country ), logic->mode, sharedSection->fetchOffset ); wxLongLong starttime = wxGetLocalTimeMillis(); #endif sharedSection->fetchHasOrder = false; logic->resetEntries(); vector<AtlasEntry> l = dao->getEntries( logic->filter, logic->country, logic->mode, ATLAS_MAX_GRID_ELEMENTS, sharedSection->fetchOffset ); if ( l.size() > 0 ) { mutex.Lock(); for ( unsigned int i = 0; i < l.size(); i++ ) { l[i].country = logic->getCountryName( l[i].country_code ); l[i].admin = logic->getAdminName( l[i].country_code, l[i].admin1_code ); logic->entries[i] = new AtlasEntry( l[i] ); } #ifdef DEB_ATLAS_LOGIC wxLongLong duration = wxGetLocalTimeMillis() - starttime; printf( "AtlasLogicFetchWorker: location fetch finished, %d results in %ld millisec\n", (int)l.size(), duration.ToLong() ); #endif if ( sharedSection->fetchHasOrder ) { // filter conditions have changed meanwhile: do not write results printf( "WARN: AtlasLogicFetchWorker has new order before finishing request\n" ); } else { sharedSection->fetchHasNews = true; sharedSection->fetchIsWorking = false; } mutex.Unlock(); } } } return 0; }
/***************************************************** ** ** Formatter --- parseDegMinSecAndFormat ** ******************************************************/ wxString Formatter::parseDegMinSecAndFormat( wxString s, const int format ) { int deg, min, sec; bool b = getDegreeIntsFromString( (const wxChar*)s, deg, min, sec ); if ( ! b ) { printf( "Formatter::parseDegreesAndFormat WARN: invalid string %s\n", str2char( s )); return s; } double value = sec + min * 60 + deg * 3600; value /= 3600.0; wxString ret = getDegreesFormatted( value, format ); #ifdef PARSE_FORMAT_STRICT int deg2, min2, sec2; bool b2 = getDegreeIntsFromString( (const wxChar*)ret, deg2, min2, sec2 ); if ( ! b2 ) { printf( "ERROR Formatter::parseDegMinSecAndFormat: output parsing failed for string %s\n", str2char( ret )); } if ( deg != deg2 || min != min2 || sec != sec2 ) { printf( "ERROR Formatter::parseDegMinSecAndFormat: wrong values (rounding errors?): old %d %d %d, new %d %d %d,\n", deg, min, sec, deg2, min2, sec2 ); } #endif return ret; }
/***************************************************** ** ** AtlasImportWorker --- readSqlFile ** ******************************************************/ int readSqlFile() { wxString buf; wxTextFile textfile; if ( ! textfile.Open( sharedSection->sqlfile, wxConvUTF8 )) { printf( "ERROR: cannot open file filename %s\n", str2char( sharedSection->sqlfile )); sharedSection->errorCount++; return 1; } sharedSection->totalSize = (long)wxFileName::GetSize( sharedSection->sqlfile ).ToULong(); for ( buf = textfile.GetFirstLine(); ! textfile.Eof(); buf = textfile.GetNextLine()) { sharedSection->currentLine++; if ( checkCancelOrExit() ) break; addQueryPart( buf ); if ( checkCancelOrExit() ) break; } textfile.Close(); if ( qb.size() > 0 ) execQueryBundle(); return 0; }
/***************************************************** ** ** AtlasImportWorker --- readZipFile ** ******************************************************/ int readZipFile() { wxString buf; wxFFileInputStream instream( sharedSection->sqlfile ); wxZipInputStream zipstream( instream ); wxTextInputStream textstream( zipstream ); wxZipEntry *zipentry = zipstream.GetNextEntry(); sharedSection->totalSize = (long)zipstream.GetSize(); if ( zipentry ) { printf( "Entry: %s\n", str2char( zipentry->GetName())); bool b = zipstream.OpenEntry( *zipentry ); printf( "Open flag_ %d\n", b ); while( zipstream.GetLastError() == wxSTREAM_NO_ERROR ) { sharedSection->currentLine++; buf = textstream.ReadLine(); if ( checkCancelOrExit() ) break; addQueryPart( buf ); if ( checkCancelOrExit() ) break; } zipstream.CloseEntry(); } else { printf( "Entry NULL\n" ); } if ( qb.size() > 0 ) execQueryBundle(); return 0; }
fint printusing_c( fchar Formatstr, double *dnumber, fchar Resultstr ) /*--------------------------------------------------------------------------*/ /* Decode 'Formatstr' to a C-type format and return formatted */ /* 'number' in 'Resultstr'. Examples of possible format strings can */ /* be found in the description. Return the field width. */ /*--------------------------------------------------------------------------*/ { int len; int before, after; char format[80]; int clen; char *instr; char mode; int i; char result[120]; double number = *dnumber; fint scr = 3; len = (int) nelc_c( Formatstr ); before = strcspn( Formatstr.a, "." ); if (before > len) before = len; if (before!=len) after = len - before - 1; else after = 0; strcpy( format, "%" ); for (i=0; i<2; i++) { mode = Formatstr.a[i]; if (mode == '+') strcat( format, "+" ); if (mode == '-') strcat( format, "-" ); } instr = strpbrk( Formatstr.a, "eEgG" ); if (instr == NULL) { mode = 'f'; } else { /*--------------------------------------------------------------------*/ /* For e, E, f, g and G conversions, the result shall always contain */ /* a radix character, even if no digits follow the radix character. */ /* For g and G conversions, trailing zeroes shall not be removed from */ /* the result as they usually are. */ /*--------------------------------------------------------------------*/ mode = *instr; strcat( format, "#" ); } sprintf( format, "%.*s%d.%d%c", strlen(format), format, len, after, mode ); if (dblank_c(&number)) { sprintf( result, "%*s", len, "b" ); } else { clen = sprintf( result, format, number ); if (clen > len) { sprintf( result, "%*s", len, "*" ); } } /* Copy a zero-terminated character string to a fchar. */ (void) str2char( result, Resultstr ); return(len); }
/***************************************************** ** ** IconProvider --- getBitmap ** ******************************************************/ wxBitmap *IconProvider::getBitmap( const wxString &s ) { static ImageHashMap map; if ( map[s] != 0 ) { return map[s]; } else { wxString filename = FileConfig::get()->getPicDir() + s; if ( ! wxFileName::IsFileReadable( filename )) { printf( "ERROR: bitmap %s not found in directory %s\n", str2char( s ), str2char( FileConfig::get()->getPicDir())); return &wxNullBitmap; } wxBitmap *bmp = new wxBitmap( FileConfig::get()->getPicDir() + s, wxBITMAP_TYPE_ANY ); //bmp->SetName( s ); map[s] = bmp; return bmp; } }
/***************************************************** ** ** DegMinSecInputField --- getDoubleValue ** ******************************************************/ double DegMinSecInputField::getDoubleValue() { Formatter *formatter = Formatter::get(); int deg, min, sec; if ( GetValue().IsEmpty()) return 0.0; const bool b = formatter->getDegreeIntsFromString( (const wxChar*)GetValue(), deg, min, sec ); if ( ! b ) { printf( "DegMinSecInputField::getDoubleValue WARN: invalid string %s\n", str2char( GetValue())); return value; } double v = sec + min * 60 + deg * 3600; return v / 3600.0; }
/***************************************************** ** ** AtlasImporter --- writeErrorStatus ** ******************************************************/ wxString AtlasImporter::writeErrorStatus() { wxString s; if ( sharedSection->errorCount > 0 ) { s << wxT( "Database filename: " ) << sharedSection->dbfile << Endl << wxT( "SQL filename: " ) << sharedSection->sqlfile << Endl //<< wxT( "Current line number: " ) << sharedSection->currentLine << Endl << wxT( "Error message: " ) << sharedSection->errorMessage << Endl; } else { s = _( "No error" ); } printf( "AtlasImporter::writeErrorStatus: %s\n", str2char( s )); return s; }
int POCO_CVT::str2uchar(const char* str, unsigned char& c) { return str2char(str, (char&)c); }
/***************************************************** ** ** HoraExpert --- update ** ******************************************************/ void HoraExpert::update( const double &jd ) { const ObjectId lordseq[7] = { OSATURN, OJUPITER, OMARS, OSUN, OVENUS, OMERCURY, OMOON }; const ObjectId rev_lordseq[7] = { OVENUS, OSATURN, OMERCURY, OJUPITER, OMOON, OMARS, OSUN }; Calculator *calculator = CalculatorFactory().getCalculator(); DateTimeFormatter *formatter = DateTimeFormatter::get(); int i, weekday, day, month, year; double sunrise = calculator->calcNextSolarEvent( SOLAR_EVENT_SUNRISE, jd, location->getLatitude(), location->getLongitude()); double sunset = calculator->calcNextSolarEvent( SOLAR_EVENT_SUNSET, sunrise, location->getLatitude(), location->getLongitude()); double sunrise_next = calculator->calcNextSolarEvent( SOLAR_EVENT_SUNRISE, sunset, location->getLatitude(), location->getLongitude()); weekday = getWeekDay( sunrise ); dinaLord = lordseq[ ( rev_lordseq[weekday] ) % 7 ]; #ifdef HORA_DEB wxString s; printf( "################## DEBUG ######################\n" ); location->dump( s ); s = formatter->getFullDateStringFromJD( jd ); printf( "full date: %s\n", str2char( s )); printf( "jd: %s\n", str2char( formatter->getFullDateStringFromJD( jd ))); printf( "sunrise: %s\n", str2char( formatter->getFullDateStringFromJD( sunrise ))); printf( "sunset: %s\n", str2char( formatter->getFullDateStringFromJD( sunset ))); printf( "sunrise NEXT: %s\n", str2char( formatter->getFullDateStringFromJD( sunrise_next ))); printf( "WEEKDAY %d\n", weekday ); printf( "dinalord %d\n", dinaLord ); printf( "################## END DEBUG ######################\n" ); #endif for ( i = 0; i < 24; i++ ) { horaLord[i] = lordseq[ ( rev_lordseq[weekday] + i ) % 7 ]; } double daydur = sunset - sunrise; double daystep = daydur / 12; double nightdur = sunrise_next - sunset; double nightstep = nightdur / 12; currentHoraLord = horaLord[0]; horaStart[24] = sunrise_next; for ( i = 0; i < 12; i++ ) { horaStart[i] = sunrise + i * daystep; if ( horaStart[i] < jd ) currentHoraLord = horaLord[i]; } for ( i = 0; i < 12; i++ ) { horaStart[i+12] = sunset + i * nightstep; if ( horaStart[i+12] < jd ) currentHoraLord = horaLord[i+12]; } // calculate lords of month and year formatter->calculateDateIntegers( sunrise, day, month, year ); // lord of 1st day of year weekday = getWeekDay( calculator->calc_jd( year, 1, 1, 12 )); varshaLord = lordseq[ ( rev_lordseq[weekday] ) % 7 ]; // lord of 1st day ov month weekday = getWeekDay( calculator->calc_jd( year, month, 1, 12 )); masaLord = lordseq[ ( rev_lordseq[weekday] ) % 7 ]; }
/***************************************************** ** ** Painter --- drawMString ** ******************************************************/ void Painter::drawMString( const MRect &r, MString &f, const int& align ) { #ifdef SHOW_STOP_WATCH static wxLongLong totaltime = 0; const wxLongLong starttime = wxGetLocalTimeMillis(); #endif static int count = 0; SheetFormatter sfmt; wxString s; if ( f.formattedLines.size() == 0 ) { if ( ! f.isEmpty() && f.size.real() == 0 ) { s = sfmt.fragment2PlainText( f ); //printf( "Painter::drawMString - old size %f %f\n", f.size.real(), f.size.imag()); f.size = getTextExtent( f ); printf( "Painter::drawMString - size not set #%d contents was %s, size now %f %f\n", count++, str2char( s ), f.size.real(), f.size.imag()); } drawSingleMStringLine( r, f, align ); //return; } else { double y0 = r.y; if ( align & Align::Top ) { // nothing } else if ( align & Align::Bottom ) { y0 = y0 + r.height - f.size.imag(); } else // default: align & align::VCenter { y0 += .5 * ( r.height - f.size.imag()); } MRect rect( r.x, y0, r.width, r.height ); int line = 0; for( list<MString>::iterator iter = f.formattedLines.begin(); iter != f.formattedLines.end(); iter++ ) { line++; rect.height = iter->size.imag(); //printf( " --->>> Line %d width %f h %f\n", line, iter->size.real(), iter->size.imag() ); drawSingleMStringLine( rect, *iter, align ); rect.y += rect.height; } } #ifdef SHOW_STOP_WATCH const wxLongLong duration = wxGetLocalTimeMillis() - starttime; totaltime += duration; wxLogMessage( wxString::Format( wxT( "Painter::drawTextFormatted in %ld msec, total %ld" ), duration.ToLong(), totaltime.ToLong() )); #endif }
/***************************************************** ** ** LanguageConfig --- init ** ******************************************************/ void LanguageConfig::init() { wxString s; wxStringTokenizer t( config->langList); list<LanguageEntry>::iterator iter; int theLang = -1; #ifdef __WXMSW__ bool found; // init langentries vector langentries.clear(); langentries.push_back( LanguageEntry( wxLANGUAGE_ENGLISH_US, wxT( "en" ), _( "English" ))); langentries.push_back( LanguageEntry( wxLANGUAGE_GERMAN, wxT( "de" ), _( "German" ))); langentries.push_back( LanguageEntry( wxLANGUAGE_ITALIAN, wxT( "it" ), _( "Italian" ))); langentries.push_back( LanguageEntry( wxLANGUAGE_POLISH, wxT( "pl" ), _( "Polish" ))); langentries.push_back( LanguageEntry( wxLANGUAGE_RUSSIAN, wxT( "ru" ), _( "Russian" ))); langentries.push_back( LanguageEntry( wxLANGUAGE_TELUGU, wxT( "te" ), _( "Telugu" ))); langentries.push_back( LanguageEntry( wxLANGUAGE_HUNGARIAN, wxT( "hu" ), _( "Hungarian" ))); langentries.push_back( LanguageEntry( wxLANGUAGE_ROMANIAN, wxT( "ro" ), _( "Romanian" ))); langentries.push_back( LanguageEntry( wxLANGUAGE_SPANISH, wxT( "es" ), _( "Spanish" ))); langentries.push_back( LanguageEntry( wxLANGUAGE_FRENCH, wxT( "fr" ), _( "French" ))); langentries.push_back( LanguageEntry( wxLANGUAGE_TAMIL, wxT( "ta" ), _( "Tamil" ))); while ( t.HasMoreTokens() ) { s = t.GetNextToken(); found = false; for ( iter = langentries.begin(); iter != langentries.end(); iter++ ) { if ((*iter).code == s ) { found = true; break; } } if ( found == false ) { const wxLanguageInfo *info = wxLocale::FindLanguageInfo( s ); if ( info == 0 ) { printf( "Warning: unknown language %s", str2char ( s )); } else { langentries.push_back( LanguageEntry( info->Language, s, info->Description )); } } } langentries.sort( LangSorter() ); const wxLanguageInfo *mylang = wxLocale::FindLanguageInfo( config->lang ); if ( mylang != 0 ) { for ( iter = langentries.begin(); iter != langentries.end(); iter++ ) { if ( (*iter).code == config->lang ) { theLang = (*iter).wxId; break; } } } if ( theLang == -1 ) theLang = wxLANGUAGE_ENGLISH_US; #else theLang = wxLANGUAGE_DEFAULT; #endif setLanguage( theLang ); // Re-translate names of langlist because list was set before locale init // New languages must be set manually for ( iter = langentries.begin(); iter != langentries.end(); iter++ ) { theLang = (*iter).wxId; switch ( theLang ) { case wxLANGUAGE_ENGLISH_US: (*iter).name = _( "English" ); break; case wxLANGUAGE_GERMAN: (*iter).name = _( "German" ); break; case wxLANGUAGE_RUSSIAN: (*iter).name = _( "Russian" ); break; case wxLANGUAGE_TELUGU: (*iter).name = _( "Telugu" ); break; case wxLANGUAGE_POLISH: (*iter).name = _( "Polish" ); break; case wxLANGUAGE_ITALIAN: (*iter).name = _( "Italian" ); break; case wxLANGUAGE_HUNGARIAN: (*iter).name = _( "Hungarian" ); break; case wxLANGUAGE_ROMANIAN: (*iter).name = _( "Romanian" ); break; case wxLANGUAGE_SPANISH: (*iter).name = _( "Spanish" ); break; case wxLANGUAGE_FRENCH: (*iter).name = _( "French" ); break; case wxLANGUAGE_TAMIL: (*iter).name = _( "Tamil" ); break; } } }
int main() { float f; char *pf; float dpf; int a; int pa; #if 0 f = 100.e-1; print_float(f); pf = "100.e-1"; printf("str: %s\n", pf); dpf = str2float(pf); print_float(dpf); f = 3.14159; print_float(f); pf = "3.14159"; printf("str: %s\n", pf); dpf = str2float(pf); print_float(dpf); f = 1.0; print_float(f); pf = "1.0"; printf("str: %s\n", pf); dpf = str2float(pf); print_float(dpf); f = 0xa4.44P0; print_float(f); pf = "0xa4.44P0"; printf("str: %s\n", pf); dpf = str2float(pf); print_float(dpf); f = 0x.4AP-1; print_float(f); pf = "0x.4AP-1"; printf("str: %s\n", pf); dpf = str2float(pf); print_float(dpf); f = 565.45454; print_float(f); pf = "565.45454"; printf("str: %s\n", pf); dpf = str2float(pf); print_float(dpf); f = 6666666666666666666666666693565.4545453; print_float(f); pf = "6666666666666666666666666693565.4545453"; printf("str: %s\n", pf); dpf = str2float(pf); print_float(dpf); f = 123426456562536156315652635162563546532645365463546354632565462354.4545453; print_float(f); pf = "123426456562536156315652635162563546532645365463546354632565462354.4545453"; printf("str: %s\n", pf); dpf = str2float(pf); print_float(dpf); f = 123426456562536156315652635162563.4454545e-34535465757676; print_float(f); pf = "123426456562536156315652635162563.4454545e-34535465757676"; printf("str: %s\n", pf); dpf = str2float(pf); print_float(dpf); f = 100e-1; print_float(f); pf = "100e-1"; printf("str: %s\n", pf); dpf = str2float(pf); print_float(dpf); f = .100e-1; print_float(f); pf = ".100e-1"; printf("str: %s\n", pf); dpf = str2float(pf); print_float(dpf); f = 100.; print_float(f); pf = "100"; printf("str: %s\n", pf); dpf = str2float(pf); print_float(dpf); f = 0xa4P2; print_float(f); pf = "0xa4P2"; printf("str: %s\n", pf); dpf = str2float(pf); print_float(dpf); f = 0X56AP-1; print_float(f); pf = "0X56AP-1"; printf("str: %s\n", pf); dpf = str2float(pf); print_float(dpf); // now start to test dec a = 0x3858454578476885685; printf("%lld\n", a); pf = "0x3858454578476885685"; printf("str: %s\n", pf); pa = str2int(pf); printf("%lld\n", pa); a = 0; printf("%d\n", a); pf = "0"; printf("str: %s\n", pf); pa = str2int(pf); printf("%d\n", pa); a = 46457563545657; printf("%lld\n", a); pf = "46457563545657"; printf("str: %s\n", pf); pa = str2int(pf); printf("%lld\n", pa); a = 046457563745657; printf("%d\n", a); pf = "046457563745657"; printf("str: %s\n", pf); pa = str2int(pf); printf("%d\n", pa); a = 0657; printf("%d\n", a); pf = "0657"; printf("str: %s\n", pf); pa = str2int(pf); printf("%d\n", pa); #endif // now test char char c; char str[100]; char *str2; c = '\\'; printf("%c = %d\n", c, c); str[0] = '\''; str[1] = '\\'; str[2] = '\\'; str[3] = '\''; str[4] = '\0'; a = str2char(str); printf("%c = %d\n", a, a); c = '\"'; printf("%c = %d\n", c, c); str[0] = '\''; str[1] = '\\'; str[2] = '"'; str[3] = '\''; str[4] = '\0'; a = str2char(str); printf("%c = %d\n", a, a); c = '\?'; printf("%c = %d\n", c, c); str[0] = '\''; str[1] = '\\'; str[2] = '?'; str[3] = '\''; str[4] = '\0'; a = str2char(str); printf("%c = %d\n", a, a); c = '\''; printf("%c = %d\n", c, c); str[0] = '\''; str[1] = '\\'; str[2] = '\''; str[3] = '\''; str[4] = '\0'; a = str2char(str); printf("%c = %d\n", a, a); c = '\x45'; printf("%c = %d\n", c, c); str2 = "\'\\x45\'"; a = str2char(str2); printf("%c = %d\n", a, a); c = '\456546576'; printf("%c = %d\n", c, c); str2 = "\'\\456546576\'"; a = str2char(str2); printf("%c = %d\n", a, a); c = '\x3543657654645764576575687584564356457654634'; printf("%c = %d\n", c, c); str2 = "\'\\x3543657654645764576575687584564356457654634\'"; a = str2char(str2); c = (char)a; printf("%c = %d\n", c, c); c = '\333'; printf("%c = %d\n", c, c); str2 = "\'\\333\'"; c = str2char(str2); printf("%c = %d\n", c, c); c = '\35'; printf("%c = %d\n", c, c); str2 = "\'\\35\'"; c = str2char(str2); printf("%c = %d\n", c, c); c = '\6'; printf("%c = %d\n", c, c); str2 = "\'\\6\'"; c = str2char(str2); printf("%c = %d\n", c, c); }