示例#1
0
void CDistinta::SalvaDistinta(bool saveas)
{
	wxFile ff;
	wxString nome_file;
	int uu;
	RigaDist* rd;
	ListaRighe::Node* nrd;


	if (saveas) {
		fd = new wxFileDialog(NULL, "Save As...",dist_path,nome_dist,"*.dat", wxFD_SAVE);

		 if (fd->ShowModal() == wxID_CANCEL) {
		   delete fd;
			return; // the user changed idea...
		}
		
		nome_dist = fd->GetFilename();
	
		nome_file = dist_path+nome_dist;
	}
	else
		nome_file = ".\\DISTINTA.DAT";

	ff.Open(nome_file,wxFile::write);
	
	//se salvataggio distinta attuale
	//come prima cosa salvo il nome della distinta...
	if(saveas==false) {
		uu=wxStrlen(nome_dist);
		ff.Write(&uu,sizeof(int));
		if (uu>0)
			ff.Write(nome_dist,wxMBConvUTF8());
	}
	//... e poi tutte le righe...
	nrd=lista->GetFirst();

	while (nrd) {
		rd = nrd->GetData();

		for(int ii=0; ii<num_var; ii++) {
			ff.Write(&rd->dati.d[ii],sizeof(double));
			ff.Write(&rd->dati.i[ii],sizeof(int));
		}
		for(int ii=0; ii<num_var; ii++) {
			uu=wxStrlen(rd->dati.s[ii]);
			ff.Write(&uu,sizeof(int));
			if (uu>0)
				ff.Write(rd->dati.s[ii],wxMBConvUTF8());
		} //TODO vedere se passare all'ascii 8 bit

		nrd = nrd->GetNext();
	}

	ff.Close();

	statusbar->SetStatusText(nome_dist,0);


}
示例#2
0
void InteractiveInputTestCase::TestRegExInteractive()
{
#ifdef TEST_REGEX 
    wxPuts(wxT("*** Testing RE interactively ***"));

    for ( ;; )
    {
        wxChar pattern[128];
        wxPrintf(wxT("Enter a pattern (press ENTER or type 'quit' to escape): "));
        if ( !wxFgets(pattern, WXSIZEOF(pattern), stdin) )
            break;

        // kill the last '\n'
        pattern[wxStrlen(pattern) - 1] = 0;

        if (pattern[0] == '\0' || wxStrcmp(pattern, "quit") == 0)
            break;
            
        wxRegEx re;
        if ( !re.Compile(pattern) )
        {
            continue;
        }

        wxChar text[128];
        for ( ;; )
        {
            wxPrintf(wxT("Enter text to match: "));
            if ( !wxFgets(text, WXSIZEOF(text), stdin) )
                break;

            // kill the last '\n'
            text[wxStrlen(text) - 1] = 0;

            if ( !re.Matches(text) )
            {
                wxPrintf(wxT("No match.\n"));
            }
            else
            {
                wxPrintf(wxT("Pattern matches at '%s'\n"), re.GetMatch(text).c_str());

                size_t start, len;
                for ( size_t n = 1; ; n++ )
                {
                    if ( !re.GetMatch(&start, &len, n) )
                    {
                        break;
                    }

                    wxPrintf(wxT("Subexpr %u matched '%s'\n"),
                             n, wxString(text + start, len).c_str());
                }
            }
        }
        
        wxPuts("\n");
    }
#endif // TEST_REGEX
}
示例#3
0
void VarArgTestCase::RepeatedPrintf()
{
    wxCharBuffer buffer(2);
    char *p = buffer.data();
    *p = 'h';
    p++;
    *p = 'i';

    wxString s;
    s = wxString::Format("buffer %s, len %d", buffer, (int)wxStrlen(buffer));
    CPPUNIT_ASSERT_EQUAL("buffer hi, len 2", s);

    s = wxString::Format("buffer %s, len %d", buffer, (int)wxStrlen(buffer));
    CPPUNIT_ASSERT_EQUAL("buffer hi, len 2", s);
}
示例#4
0
文件: stream.cpp 项目: hgwells/tive
wxString::size_type wxFilterClassFactoryBase::FindExtension(
        const wxChar *location) const
{
    size_t len = wxStrlen(location);

    for (const wxChar *const *p = GetProtocols(wxSTREAM_FILEEXT); *p; p++)
    {
        size_t l = wxStrlen(*p);

        if (l <= len && wxStrcmp(*p, location + len - l) == 0)
            return len - l;
    }

    return wxString::npos;
}
示例#5
0
bool EffectDtmf::Init()
{
   // dialog will be passed values from effect
   // Effect retrieves values from saved config
   // Dialog will take care of using them to initialize controls
   // If there is a selection, use that duration, otherwise use
   // value from saved config: this is useful is user wants to
   // replace selection with dtmf sequence

   if (mT1 > mT0) {
      // there is a selection: let's fit in there...
      // MJS: note that this is just for the TTC and is independent of the track rate
      // but we do need to make sure we have the right number of samples at the project rate
      AudacityProject *p = GetActiveProject();
      double projRate = p->GetRate();
      double quantMT0 = QUANTIZED_TIME(mT0, projRate);
      double quantMT1 = QUANTIZED_TIME(mT1, projRate);
      mDuration = quantMT1 - quantMT0;
      mIsSelection = true;
   } else {
      // retrieve last used values
      gPrefs->Read(wxT("/Effects/DtmfGen/SequenceDuration"), &mDuration, 1L);
      mIsSelection = false;
   }
   gPrefs->Read(wxT("/Effects/DtmfGen/String"), &dtmfString, wxT("audacity"));
   gPrefs->Read(wxT("/Effects/DtmfGen/DutyCycle"), &dtmfDutyCycle, 550L);
   gPrefs->Read(wxT("/Effects/DtmfGen/Amplitude"), &dtmfAmplitude, 0.8f);

   dtmfNTones = wxStrlen(dtmfString);

   return true;
}
示例#6
0
int AutoCompData::FindString( const wxChar* word, const wxChar* words, const wxArrayInt& indicies )
{
   // Do a simple binary search using the index array
   // to find the strings in the word list.  It's all 
   // sorted, so it should be super quick.
   size_t i,
      lo = 0,
      hi = indicies.GetCount();
   int res;
   const wxChar* other;

   size_t wordLen = wxStrlen( word );

   while ( lo < hi ) {

      i = (lo + hi) / 2;

      other = words + indicies[i];
      res = wxStrnicmp(word, other, wordLen);
      if ( res < 0 )
         hi = i;
      else if ( res > 0 )
         lo = i + 1;
      else
         return i;
   }

   return -1;
}
示例#7
0
bool EffectDtmf::Init()
{
   // dialog will be passed values from effect
   // Effect retrieves values from saved config
   // Dialog will take care of using them to initialize controls
   // If there is a selection, use that duration, otherwise use
   // value from saved config: this is useful is user wants to
   // replace selection with dtmf sequence

   if (mT1 > mT0) {
      // there is a selection: let's fit in there...
      mDuration = mT1 - mT0;
      mIsSelection = true;
   } else {
      // retrieve last used values
      gPrefs->Read(wxT("/CsPresets/DtmfGen_SequenceDuration"), &mDuration, 1L);
      mIsSelection = false;
   }
   /// \todo this code shouldn't be using /CsPresets - need to review its use
   gPrefs->Read(wxT("/CsPresets/DtmfGen_String"), &dtmfString, wxT("audacity"));
   gPrefs->Read(wxT("/CsPresets/DtmfGen_DutyCycle"), &dtmfDutyCycle, 550L);
   gPrefs->Read(wxT("/CsPresets/DtmfGen_Amplitude"), &dtmfAmplitude, 0.8f);

   dtmfNTones = wxStrlen(dtmfString);

   return true;
}
示例#8
0
wxString wxComboBox::DoGetValue() const
{
    GtkEntry *entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
    wxString tmp( wxGTK_CONV_BACK( gtk_entry_get_text( entry ) ) );

#if 0
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
    for (int i = 0; i < wxStrlen(tmp.c_str()) +1; i++)
    {
        wxChar c = tmp[i];
        printf( "%d ", (int) (c) );
    }
    printf( "\n" );
#endif

    return tmp;
}
示例#9
0
void wxMetafileDC::GetTextExtent(const wxString& string, long *x, long *y,
                                 long *descent, long *externalLeading, wxFont *theFont, bool WXUNUSED(use16bit)) const
{
    wxFont *fontToUse = theFont;
    if (!fontToUse)
        fontToUse = (wxFont*) &m_font;

    HDC dc = GetDC(NULL);

    SIZE sizeRect;
    TEXTMETRIC tm;
    ::GetTextExtentPoint32(dc, WXSTRINGCAST string, wxStrlen(WXSTRINGCAST string), &sizeRect);
    GetTextMetrics(dc, &tm);

    ReleaseDC(NULL, dc);

    if ( x )
        *x = sizeRect.cx;
    if ( y )
        *y = sizeRect.cy;
    if ( descent )
        *descent = tm.tmDescent;
    if ( externalLeading )
        *externalLeading = tm.tmExternalLeading;
}
示例#10
0
// return prefixCode+number if the string is of the form "<prefix><number>" and
// 0 if it isn't
//
// first and last parameter specify the valid domain for "number" part
static int
        IsNumberedAccelKey(const wxString& str,
                           const wxChar *prefix,
                           wxKeyCode prefixCode,
                           unsigned first,
                           unsigned last)
{
    const size_t lenPrefix = wxStrlen(prefix);
    if ( !CompareAccelString(str.Left(lenPrefix), prefix) )
        return 0;

    unsigned long num;
    if ( !str.Mid(lenPrefix).ToULong(&num) )
        return 0;

    if ( num < first || num > last )
    {
        // this must be a mistake, chances that this is a valid name of another
        // key are vanishingly small
        wxLogDebug(_T("Invalid key string \"%s\""), str.c_str());
        return 0;
    }

    return prefixCode + num - first;
}
示例#11
0
文件: console.cpp 项目: euler0/Helium
int main(int argc, char **argv)
{
    wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");

    wxInitializer initializer;
    if ( !initializer )
    {
        fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
        return -1;
    }

    wxCmdLineParser parser(cmdLineDesc, argc, argv);
    switch ( parser.Parse() )
    {
        case -1:
            // help was given, terminating
            break;

        case 0:
            // everything is ok; proceed
            if (parser.Found("d"))
            {
                wxPrintf("Dummy switch was given...\n");

                while (1)
                {
                    wxChar input[128];
                    wxPrintf("Try to guess the magic number (type 'quit' to escape): ");
                    if ( !wxFgets(input, WXSIZEOF(input), stdin) )
                        break;

                    // kill the last '\n'
                    input[wxStrlen(input) - 1] = 0;
                    
                    if (wxStrcmp(input, "quit") == 0)
                        break;

                    long val;
                    if (!wxString(input).ToLong(&val))
                    {
                        wxPrintf("Invalid number...\n");
                        continue;
                    }

                    if (val == 42)
                        wxPrintf("You guessed!\n");
                    else
                        wxPrintf("Bad luck!\n");
                }
            }
            break;

        default:
            break;
    }

    // do something useful here

    return 0;
}
示例#12
0
// assigns C string
wxStringImpl& wxStringImpl::operator=(const wxStringCharType *psz)
{
  if ( !AssignCopy(wxStrlen(psz), psz) ) {
    wxFAIL_MSG( wxT("out of memory in wxStringImpl::operator=(const wxStringCharType *)") );
  }
  return *this;
}
示例#13
0
void ChatLog::FillLastLineArray()
{
    int fd ( open(GetCurrentLogfilePath().mb_str(), O_RDONLY) );
    if ( fd < 0 )
    {
        wxLogError(_T("%s: failed to open log file."), __PRETTY_FUNCTION__);
        return;
    }
    size_t num_lines ( sett().GetAutoloadedChatlogLinesCount() );

    m_last_lines.Clear();
    m_last_lines.Alloc(num_lines);

    const wxChar* wc_EOL ( wxTextBuffer::GetEOL() );
    size_t eol_num_chars ( wxStrlen(wc_EOL) );
#ifndef WIN32
    char* eol ( static_cast<char*>( alloca(eol_num_chars) ) );
#else
    char* eol ( new char[eol_num_chars] );
#endif
    wxConvUTF8.WC2MB(eol, wc_EOL, eol_num_chars);

    size_t lines_added ( find_tail_sequences(fd, eol, eol_num_chars, num_lines, m_last_lines) );
    wxLogMessage(_T("ChatLog::FillLastLineArray: Loaded %lu lines from %s."), lines_added, GetCurrentLogfilePath().c_str());
    close(fd);

#ifdef WIN32
    delete[] eol;
#endif
}
示例#14
0
文件: app.cpp 项目: zhchbin/wxWidgets
bool wxApp::Initialize(int& argc, wxChar **argv)
{
    // Mac-specific

#if wxDEBUG_LEVEL && wxOSX_USE_COCOA_OR_CARBON
    InstallDebugAssertOutputHandler( NewDebugAssertOutputHandlerUPP( wxMacAssertOutputHandler ) );
#endif

    /*
     Cocoa supports -Key value options which set the user defaults key "Key"
     to the value "value"  Some of them are very handy for debugging like
     -NSShowAllViews YES.  Cocoa picks these up from the real argv so
     our removal of them from the wx copy of it does not affect Cocoa's
     ability to see them.
     
     We basically just assume that any "-NS" option and its following
     argument needs to be removed from argv.  We hope that user code does
     not expect to see -NS options and indeed it's probably a safe bet
     since most user code accepting options is probably using the
     double-dash GNU-style syntax.
     */
    for(int i=1; i < argc; ++i)
    {
        static const wxChar *ARG_NS = wxT("-NS");
        if( wxStrncmp(argv[i], ARG_NS, wxStrlen(ARG_NS)) == 0 )
        {
            // Only eat this option if it has an argument
            if( (i + 1) < argc )
            {
                memmove(argv + i, argv + i + 2, (argc-i-1)*sizeof(wxChar*));
                argc -= 2;
                // drop back one position so the next run through the loop
                // reprocesses the argument at our current index.
                --i;
            }
        }
    }

    if ( !wxAppBase::Initialize(argc, argv) )
        return false;

#if wxUSE_INTL
    wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
#endif

    // these might be the startup dirs, set them to the 'usual' dir containing the app bundle
    wxString startupCwd = wxGetCwd() ;
    if ( startupCwd == wxT("/") || startupCwd.Right(15) == wxT("/Contents/MacOS") )
    {
        CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle() ) ;
        CFURLRef urlParent = CFURLCreateCopyDeletingLastPathComponent( kCFAllocatorDefault , url ) ;
        CFRelease( url ) ;
        CFStringRef path = CFURLCopyFileSystemPath ( urlParent , kCFURLPOSIXPathStyle ) ;
        CFRelease( urlParent ) ;
        wxString cwd = wxCFStringRef(path).AsString(wxLocale::GetSystemEncoding());
        wxSetWorkingDirectory( cwd ) ;
    }

    return true;
}
示例#15
0
文件: metafile.cpp 项目: beanhome/dev
void wxMetafileDCImpl::DoGetTextExtent(const wxString& string,
                                       wxCoord *x, wxCoord *y,
                                       wxCoord *descent, wxCoord *externalLeading,
                                       const wxFont *theFont) const
{
    const wxFont *fontToUse = theFont;
    if (!fontToUse)
        fontToUse = &m_font;

    ScreenHDC dc;
    SelectInHDC selFont(dc, GetHfontOf(*fontToUse));

    SIZE sizeRect;
    TEXTMETRIC tm;
    ::GetTextExtentPoint32(dc, WXSTRINGCAST string, wxStrlen(WXSTRINGCAST string), &sizeRect);
    ::GetTextMetrics(dc, &tm);

    if ( x )
        *x = sizeRect.cx;
    if ( y )
        *y = sizeRect.cy;
    if ( descent )
        *descent = tm.tmDescent;
    if ( externalLeading )
        *externalLeading = tm.tmExternalLeading;
}
示例#16
0
void QuickFindBar::DoSearch(size_t searchFlags, int posToSearchFrom)
{
    if(!m_sci || m_sci->GetLength() == 0 || m_findWhat->GetValue().IsEmpty())
        return;

    // Clear all search markers if desired
    if (EditorConfigST::Get()->GetOptions()->GetClearHighlitWordsOnFind()) {
        m_sci->SetIndicatorCurrent(MARKER_WORD_HIGHLIGHT);
        m_sci->IndicatorClearRange(0, m_sci->GetLength());
    }

    m_flags = DoGetSearchFlags();

    wxString find = m_findWhat->GetValue();
    wchar_t* pinput = DoGetSearchStringPtr();
    if(!pinput)
        return;
    int start = -1, stop = -1;
    m_sci->GetSelection(&start, &stop);

    bool fwd = searchFlags & kSearchForward;
    bool addSelection = searchFlags & kSearchMultiSelect;
    bool incr = searchFlags & kSearchIncremental;

    int offset;
    if(posToSearchFrom != wxNOT_FOUND) {
        offset = posToSearchFrom;
    } else {
        offset = (!fwd || incr) ? start : stop;
    }
    int flags = m_flags | (fwd ? 0 : wxSD_SEARCH_BACKWARD);
    int pos = 0, len = 0;

    if(!StringFindReplacer::Search(pinput, offset, find.wc_str(), flags, pos, len)) {
        offset = fwd ? 0 : wxStrlen(pinput) - 1;
        if(!StringFindReplacer::Search(pinput, offset, find.wc_str(), flags, pos, len)) {
            m_findWhat->SetBackgroundColour(wxT("PINK"));
            m_findWhat->Refresh();
            return;
        }
    }

    m_findWhat->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
    m_findWhat->Refresh();
    if(addSelection && m_sci->GetSelections()) {
        m_sci->AddSelection(pos, pos + len);
    } else {
        m_sci->ClearSelections();
        m_sci->SetSelection(pos, pos + len);
    }

    // Ensure that the found string is visible (i.e. its line isn't folded away)
    // and that the user can see it without having to scroll
    int line = m_sci->LineFromPosition(pos);
    if(line >= 0) {
        m_sci->EnsureVisible(line);
        m_sci->EnsureCaretVisible();
    }
}
示例#17
0
文件: wxpoem.cpp 项目: beanhome/dev
bool MyApp::OnInit()
{
    poem_buffer = new wxChar[BUFFER_SIZE];

    // Seed the random number generator
#ifdef __WXWINCE__
    srand((unsigned) CeGetRandomSeed());
#else
    time_t current_time;

    (void)time(&current_time);
    srand((unsigned int)current_time);
#endif

//    randomize();
    pages[0] = 0;

    TheMainWindow = new MainWindow(NULL,
                                   wxID_ANY,
                                   wxT("wxPoem"),
                                   wxPoint(XPos, YPos),
                                   wxDefaultSize,
                                   wxCAPTION|wxMINIMIZE_BOX|wxSYSTEM_MENU|wxCLOSE_BOX|wxFULL_REPAINT_ON_RESIZE
                                   );

    TheMainWindow->canvas = new MyCanvas(TheMainWindow);

    if (argc > 1)
    {
        index_filename = wxStrcpy(new wxChar[wxStrlen(argv[1]) + 1], argv[1]);
        data_filename = wxStrcpy(new wxChar[wxStrlen(argv[1]) + 1], argv[1]);
    }
    else
    {
        index_filename = wxT(DEFAULT_POETRY_IND);
        data_filename = wxT(DEFAULT_POETRY_DAT);
    }
    TryLoadIndex();

    TheMainWindow->GetIndexLoadPoem();
    TheMainWindow->Resize();
    TheMainWindow->Show(true);

    return true;
}
示例#18
0
wxChar* SCCConnection::OnRequest(const wxString& WXUNUSED(topic),
			const wxString& item,
			int* size,
			wxIPCFormat WXUNUSED(format)) {
	if (item == scc_ipc_messages::reload_menu_msg) {
		assert(app != NULL);
		app->ReloadMenu();

		*size = wxStrlen(scc_ipc_messages::ok_resp) * sizeof(wxChar)
			+ sizeof(wxChar);
		return (wxChar*) scc_ipc_messages::ok_resp;
	} else {

		*size = wxStrlen(scc_ipc_messages::unknown_command_resp) * sizeof(wxChar)
			+ sizeof(wxChar);
		return (wxChar*) scc_ipc_messages::unknown_command_resp;
	}
}
示例#19
0
int wxGpiStrcmp(
  wxChar*                           s0
, wxChar*                           s1
)
{   int                             l0;
    int                             l1;
    int                             l;
    int                             d;
    int                             d1;
    int                             i;
    int                             rc;

    rc = 0;
    if(s0 == NULL)
    {
        if(s1 == NULL)
            return 0;
        else
            return 32;
    }
    else if(s1 == NULL)
        return 32;

    l0 = wxStrlen(s0);
    l1 = wxStrlen(s1);
    l  = l0;
    if(l0 != l1)
    {
        rc++;
        if(l1 < l0)
            l = l1;
    }
    for(i=0;i<l;i++)
    {
        d = s0[i]-s1[i];
        if(!d)
            continue;
        d1 = wxToupper(s0[i]) - wxToupper(s1[i]);
        if(!d1)
            continue;
        rc += abs(d);
    }
    return rc;
}
示例#20
0
wxString Config::validateConfig()
{
    wxRegEx findIP( wxT("^(([0-9]{1}|[0-9]{2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]{1}|[0-9]{2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])$"));
    wxRegEx b64Validate( wxT("^[A-Za-z0-9+/]+={0,3}$"));
    wxRegEx portStringValidate( wxT("(tcp|udp)/+[0-9]"));

    if (this->NICK_NAME.CmpNoCase(wxEmptyString) == 0 ) {
        return wxT("You must choose a Nickname.");
    } else if (this->SERVER_IP.Find(_(".")) == wxNOT_FOUND) { //check for valid ip or hostname -- Relex this check greatly and throw the error when trying to send.
        return wxT("You must supply a valid server address.");
    } else if((wxAtoi(this->SERVER_PORT) < 1 || wxAtoi(this->SERVER_PORT) > 65535) && this->SERVER_PORT.CmpNoCase(wxT("Random")) != 0){
        return wxT("Invalid Server Port"); //check server port is valid port or random
    } else if (this->LEGACY == true && this->HMAC.CmpNoCase(wxEmptyString) != 0) {//check no hmac with legacy
        return wxT("You cannot use an HMAC in legacy mode.");
    } else if (this->KEY_BASE64 && wxStrlen(this->KEY) % 4 != 0) { //check base64 must have a multiple of 4 length
        return wxT("Invalid Base64 Key Length.");
    } else if (this->KEY_BASE64 && !b64Validate.Matches(this->KEY)) { // looks for disallowed b64 characters
        return wxT("Invalid Base64 Key.");
    } else if (this->HMAC_BASE64 && wxStrlen(this->HMAC) % 4 != 0) { //check base64 must have a multiple of 4 length
        return wxT("Invalid Base64 HMAC Length.");
    } else if (this->HMAC_BASE64 && !b64Validate.Matches(this->HMAC)) { // looks for disallowed b64 characters
        return wxT("Invalid Base64 HMAC.");
    } else if (!(this->MESS_TYPE.CmpNoCase(wxT("Server Command")) == 0 || portStringValidate.Matches(this->PORTS))) { //If not a server command, make sure the port string is valid
        return wxT("Invalid Port string. Must look like tcp/22.");
    } else if (!(this->ACCESS_IP.CmpNoCase(wxT("Resolve IP")) == 0 ||  this->ACCESS_IP.CmpNoCase(wxT("Source IP")) == 0 || this->ACCESS_IP.CmpNoCase(wxT("Prompt IP")) == 0 || findIP.Matches(this->ACCESS_IP) )) { //if specifying ip, make sure is valid
        return wxT("Invalid IP to allow."); // Have to have a valid ip to allow, if using allow ip
    } else if (this->MESS_TYPE.CmpNoCase(wxT("Nat Access")) == 0 && !(0 < wxAtoi(NAT_PORT) && wxAtoi(NAT_PORT) < 65536)) { //NAT_IP must be a valid ip, and NAT_PORT must be a valid port
        return wxT("Invalid NAT port.");
    } else if (!(this->DIGEST_TYPE.CmpNoCase(wxT("MD5")) == 0
                || this->DIGEST_TYPE.CmpNoCase(wxT("SHA1")) == 0
                || this->DIGEST_TYPE.CmpNoCase(wxT("SHA256")) == 0
                || this->DIGEST_TYPE.CmpNoCase(wxT("SHA384")) == 0
                || this->DIGEST_TYPE.CmpNoCase(wxT("SHA512")) == 0)) {
        return wxT("Invalid SPA digest type.");
    } else if (!(this->HMAC_TYPE.CmpNoCase(wxT("MD5")) == 0
                || this->HMAC_TYPE.CmpNoCase(wxT("SHA1")) == 0
                || this->HMAC_TYPE.CmpNoCase(wxT("SHA256")) == 0
                || this->HMAC_TYPE.CmpNoCase(wxT("SHA384")) == 0
                || this->HMAC_TYPE.CmpNoCase(wxT("SHA512")) == 0)) {
        return wxT("Invalid HMAC digest type.");
    } else { //Could check for valid looking gpg keys if enabled
        return wxT("valid");
    }
}
示例#21
0
void ecUtils::UnicodeToCStr(const wxChar* str,char *&psz)
{
    int nLength=1 + wxStrlen(str);
    psz=new char[nLength];
#ifdef _UNICODE
    WideCharToMultiByte(CP_ACP, 0, str, -1, psz, nLength, NULL, NULL);
#else
    strcpy(psz,str);
#endif
}
示例#22
0
文件: PGP.cpp 项目: vadz/mahogany
// checks whether the given string starts with this substring and advances it
// past it if it does
static inline bool AdvanceIfMatches(const wxChar **p, const wxChar *substr)
{
   const size_t len = wxStrlen(substr);
   if ( wxStrncmp(*p, substr, len) != 0 )
      return false;

   *p += len;

   return true;
}
void SpellCheckCmdLineInterface::GetFeedback()
{
  wxChar strReplacement[256];
  wxPrintf(_T("\nReplacement? : \n"));
  if ( !wxFgets(strReplacement, WXSIZEOF(strReplacement), stdin) )
    m_nLastAction = ACTION_IGNORE; /* ignore the current misspelling */
  else
	{
  	strReplacement[wxStrlen(strReplacement) - 1] = '\0';
		if (wxStrlen(strReplacement) == 0)
		{
    	m_nLastAction = ACTION_IGNORE; /* ignore the current misspelling */
		}
		else
		{
	    m_nLastAction = ACTION_REPLACE;
			m_strReplaceWithText = strReplacement;
		}
	}
}
示例#24
0
wxChar *
copystring (const wxChar *s)
{
    if (s == NULL) s = wxEmptyString;
    size_t len = wxStrlen (s) + 1;

    wxChar *news = new wxChar[len];
    memcpy (news, s, len * sizeof(wxChar));    // Should be the fastest

    return news;
}
示例#25
0
wxString::size_type wxFilterClassFactoryBase::FindExtension(
        const wxString& location) const
{
    for (const wxChar *const *p = GetProtocols(wxSTREAM_FILEEXT); *p; p++)
    {
        if ( location.EndsWith(*p) )
            return location.length() - wxStrlen(*p);
    }

    return wxString::npos;
}
示例#26
0
void DtmfDialog::Recalculate(void) {

   // remember that dDutyCycle is in range (0-1000)
   double slot;

   dString = mDtmfStringT->GetValue();
   dDuration = mDtmfDurationT->GetTimeValue();

   dNTones = wxStrlen(dString);
   dDutyCycle = TrapLong(mDtmfDutyS->GetValue(), DUTY_MIN, DUTY_MAX);

   if (dNTones==0) {
      // no tones, all zero: don't do anything
      // this should take care of the case where user got an empty
      // dtmf sequence into the generator: track won't be generated
      dTone = 0;
      dDuration = 0;
      dSilence = dDuration;
   } else
     if (dNTones==1) {
        // single tone, as long as the sequence
          dSilence = 0;
          dTone = dDuration;

     } else {
        // Don't be fooled by the fact that you divide the sequence into dNTones:
        // the last slot will only contain a tone, not ending with silence.
        // Given this, the right thing to do is to divide the sequence duration
        // by dNTones tones and (dNTones-1) silences each sized according to the duty
        // cycle: original division was:
        // slot=dDuration / (dNTones*(dDutyCycle/DUTY_MAX)+(dNTones-1)*(1.0-dDutyCycle/DUTY_MAX))
        // which can be simplified in the one below.
        // Then just take the part that belongs to tone or silence.
        //
        slot=dDuration/((double)dNTones+(dDutyCycle/DUTY_MAX)-1);
        dTone = slot * (dDutyCycle/DUTY_MAX); // seconds
        dSilence = slot * (1.0 - (dDutyCycle/DUTY_MAX)); // seconds

        // Note that in the extremes we have:
        // - dutyCycle=100%, this means no silence, so each tone will measure dDuration/dNTones
        // - dutyCycle=0%, this means no tones, so each silence slot will measure dDuration/(NTones-1)
        // But we always count:
        // - dNTones tones
        // - dNTones-1 silences
     }

   mDtmfDutyT->SetLabel(wxString::Format(wxT("%.1f %%"), (float)dDutyCycle/DUTY_SCALE));
   mDtmfDutyT->SetName(mDtmfDutyT->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
   mDtmfSilenceT->SetLabel(wxString::Format(wxString(wxT("%d ")) + _("ms"),  (int) (dTone * 1000)));
   mDtmfSilenceT->SetName(mDtmfSilenceT->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
   mDtmfToneT->SetLabel(wxString::Format(wxString(wxT("%d ")) + _("ms"),  (int) (dSilence * 1000)));
   mDtmfToneT->SetName(mDtmfToneT->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
}
示例#27
0
/*static*/
void wxMemoryFSHandlerBase::AddFileWithMimeType(const wxString& filename,
                                                const wxString& textdata,
                                                const wxString& mimetype)
{
    AddFileWithMimeType
    (
        filename,
        static_cast<const char *>(textdata.To8BitData()),
        wxStrlen(static_cast<const char *>(textdata.To8BitData())),
        mimetype
    );
}
示例#28
0
bool EffectDtmf::PromptUser()
{
   DtmfDialog dlog(mParent, _("DTMF Tone Generator"));


   // dialog will be passed values from effect
   // Effect retrieves values from saved config
   // Dialog will take care of using them to initialize controls
   // If there is a selection, use that duration, otherwise use
   // value from saved config: this is useful is user wants to
   // replace selection with dtmf sequence

   if (mT1 > mT0) {
      // there is a selection: let's fit in there...
      dtmfDuration = mT1 - mT0;
      dlog.dIsSelection = true;
   } else {
      // retrieve last used values
      gPrefs->Read(wxT("/CsPresets/DtmfGen_SequenceDuration"), &dtmfDuration, 1L);
      dlog.dIsSelection = false;
   }
   /// \todo this code shouldn't be using /CsPresets - need to review its use
   gPrefs->Read(wxT("/CsPresets/DtmfGen_String"), &dtmfString, wxT("audacity"));
   gPrefs->Read(wxT("/CsPresets/DtmfGen_DutyCycle"), &dtmfDutyCycle, 550L);
   gPrefs->Read(wxT("/CsPresets/DtmfGen_Amplitude"), &dtmfAmplitude, 0.8f);

   dtmfNTones = wxStrlen(dtmfString);

   // Initialize dialog locals
   dlog.dString = dtmfString;
   dlog.dDutyCycle = dtmfDutyCycle;
   dlog.dDuration = dtmfDuration;
   dlog.dAmplitude = dtmfAmplitude;

   // start dialog
   dlog.Init();
   dlog.ShowModal();

   if (dlog.GetReturnCode() == wxID_CANCEL)
      return false;

   // if there was an OK, retrieve values
   dtmfString = dlog.dString;
   dtmfDutyCycle = dlog.dDutyCycle;
   dtmfDuration = dlog.dDuration;
   dtmfAmplitude = dlog.dAmplitude;
   
   dtmfNTones = dlog.dNTones;
   dtmfTone = dlog.dTone;
   dtmfSilence = dlog.dSilence;

   return true;
}
示例#29
0
bool wxPropertyValidator::StringToLong (wxChar *s, long *number) {
    bool ok = true;
    wxChar *value_ptr;
    *number = wxStrtol (s, &value_ptr, 10);
    if (value_ptr) {
        int len = wxStrlen (value_ptr);
        for (int i = 0; i < len; i++) {
            ok = (wxIsspace (value_ptr[i]) != 0);
            if (!ok) return false;
        }
    }
    return ok;
}
示例#30
0
// takes nLength elements of psz starting at nPos
void wxStringImpl::InitWith(const wxStringCharType *psz,
                            size_t nPos, size_t nLength)
{
  Init();

  // if the length is not given, assume the string to be NUL terminated
  if ( nLength == npos ) {
    wxASSERT_MSG( nPos <= wxStrlen(psz), wxT("index out of bounds") );

    nLength = wxStrlen(psz + nPos);
  }

  STATISTICS_ADD(InitialLength, nLength);

  if ( nLength > 0 ) {
    // trailing '\0' is written in AllocBuffer()
    if ( !AllocBuffer(nLength) ) {
      wxFAIL_MSG( wxT("out of memory in wxStringImpl::InitWith") );
      return;
    }
    wxStringMemcpy(m_pchData, psz + nPos, nLength);
  }
}