int main() {
	std::vector<std::string> DataArray = ReadFileContents("datafiles/4.txt"); // read in the strings
	std::cout << "Number of inputs: " << DataArray.size() << std::endl;
	std::vector<TestString> possible_outputs = InitialKeyAndStringPurge(DataArray); // vector of possible strings
	std::cout << "Number after initial cull: " << possible_outputs.size() << std::endl;
	
	possible_outputs = AnalyseLetterFrequencies(possible_outputs);
	
	int ash_ketchum = FindHighestScore(possible_outputs);
	
	std::cout << possible_outputs[0].GetCipherText() << std::endl;

	return 0;
}
OSErr TShioTimeValue::ReadTimeValues (char *path, short format, short unitsIfKnownInAdvance)
{
	// code goes here, use unitsIfKnownInAdvance to tell if we're coming from a location file, 
	// if not and it's a heights file ask if progressive or standing wave (add new field or track as 'P')
	//#pragma unused(unitsIfKnownInAdvance)	
	char strLine[kMaxKeyedLineLength];
	long i,numValues;
	double value1, value2, magnitude, degrees;
	CHARH f = 0;
	DateTimeRec time;
	TimeValuePair pair;
	OSErr	err = noErr,scanErr;
	long lineNum = 0;
	char *p;
	long numScanned;
	double value, stationLat, stationLon;
	CONTROLVAR  DatumControls;
	
	if (err = OSSMTimeValue_c::InitTimeFunc()) return err;
	
	timeValues = 0;
	fileName[0] = 0;
	
	if (!path) return -1;
	
	strcpy(strLine, path);
	SplitPathFile(strLine, this->fileName);
	
	err = ReadFileContents(TERMINATED, 0, 0, path, 0, 0, &f);
	if(err)	{ TechError("TShioTimeValue::ReadTimeValues()", "ReadFileContents()", 0); return -1; }
	
	lineNum = 0;
	// first line
	if(!(p = GetKeyedLine(f, "[StationInfo]",lineNum++,strLine)))  goto readError;
	// 2nd line
	if(!(p = GetKeyedLine(f, "Type=",lineNum++,strLine)))  goto readError;
	switch(p[0])
	{
			//case 'c': case 'C': this->fStationType = 'C'; break;
			//case 'h': case 'H': this->fStationType = 'H'; break;
			//case 'p': case 'P': this->fStationType = 'P';	// for now assume progressive waves selected in file, maybe change to user input
		case 'c': case 'C': 
			this->fStationType = 'C'; break;
		case 'h': case 'H': 
			this->fStationType = 'H'; 
		{
			// if not a location file, Ask user if this is a progressive or standing wave
			// also ask for scale factor here
			/*if (unitsIfKnownInAdvance==kFudgeFlag)
			 {
			 short buttonSelected;
			 buttonSelected  = MULTICHOICEALERT(1690,"The file you selected is a shio heights file. Are you sure you want to treat it as a progressive wave?",TRUE);
			 switch(buttonSelected){
			 case 1:// continue, treat as progressive wave
			 this->fStationType = 'P';
			 break;  
			 case 3: // cancel
			 //return 0;// leave as standing wave?
			 return -1;
			 break;
			 }
			 //printNote("The shio heights file will be treated as a progressive wave file");
			 //this->fStationType = 'P';
			 }*/
			if (unitsIfKnownInAdvance!=-2)	// not a location file
			{
				Boolean bStandingWave = true;
				float scaleFactor = fScaleFactor;
				err = ShioHtsDialog(&bStandingWave,&scaleFactor,mapWindow);
				if (!err)
				{
					if (!bStandingWave) this->fStationType = 'P';
					//this->fScaleFactor = scaleFactor;
				}
			}
		}
			break;
		case 'p': case 'P': 
			this->fStationType = 'P';	// for now assume progressive waves selected in file, maybe change to user input
			
			//printError("You have selected a SHIO heights file.  Only SHIO current files can be used in GNOME.");
			//return -1;
			break;	// Allow heights files to be read in 9/18/00
		default:	goto readError; 	
	}
	// 3nd line
	if(!(p = GetKeyedLine(f, "Name=",lineNum++,strLine)))  goto readError;
	strncpy(this->fStationName,p,MAXSTATIONNAMELEN);
	this->fStationName[MAXSTATIONNAMELEN-1] = 0;
	// 
	if(err = this->GetKeyedValue(f,"Latitude=",lineNum++,strLine,&stationLat))  goto readError;
	if(err = this->GetKeyedValue(f,"Longitude=",lineNum++,strLine,&stationLon))  goto readError;

	this->fStationPosition.p.pLat = stationLat * 1000000;
	this->fStationPosition.p.pLong = stationLon * 1000000;
	
	//
	if(!(p = GetKeyedLine(f, "[Constituents]",lineNum++,strLine)))  goto readError;
	// code goes here in version 1.2.7 these lines won't be required for height files, but should still allow old format
	//if(err = this->GetKeyedValue(f,"DatumControls.datum=",lineNum++,strLine,&this->fConstituent.DatumControls.datum))  goto readError;
	if(err = this->GetKeyedValue(f,"DatumControls.datum=",lineNum++,strLine,&this->fConstituent.DatumControls.datum))  
	{
		if(this->fStationType=='h' || this->fStationType=='H')
		{
			lineNum--;	// possibly new Shio output which eliminated the unused datumcontrols for height files
			goto skipDatumControls;
		}
		else
		{
			goto readError;
		}
	}
	if(err = this->GetKeyedValue(f,"DatumControls.FDir=",lineNum++,strLine,&this->fConstituent.DatumControls.FDir))  goto readError;
	if(err = this->GetKeyedValue(f,"DatumControls.EDir=",lineNum++,strLine,&this->fConstituent.DatumControls.EDir))  goto readError;
	if(err = this->GetKeyedValue(f,"DatumControls.L2Flag=",lineNum++,strLine,&this->fConstituent.DatumControls.L2Flag))  goto readError;
	if(err = this->GetKeyedValue(f,"DatumControls.HFlag=",lineNum++,strLine,&this->fConstituent.DatumControls.HFlag))  goto readError;
	if(err = this->GetKeyedValue(f,"DatumControls.RotFlag=",lineNum++,strLine,&this->fConstituent.DatumControls.RotFlag))  goto readError;
	
skipDatumControls:
	if(err = this->GetKeyedValue(f,"H=",lineNum++,strLine,&this->fConstituent.H))  goto readError;
	if(err = this->GetKeyedValue(f,"kPrime=",lineNum++,strLine,&this->fConstituent.kPrime))  goto readError;
	
	if(!(p = GetKeyedLine(f, "[Offset]",lineNum++,strLine)))  goto readError;
	
	switch(this->fStationType)
	{
		case 'c': case 'C': 
			if(err = this->GetKeyedValue(f,"MinBefFloodTime=",lineNum++,strLine,&this->fCurrentOffset.MinBefFloodTime))  goto readError;
			if(err = this->GetKeyedValue(f,"FloodTime=",lineNum++,strLine,&this->fCurrentOffset.FloodTime))  goto readError;
			if(err = this->GetKeyedValue(f,"MinBefEbbTime=",lineNum++,strLine,&this->fCurrentOffset.MinBefEbbTime))  goto readError;
			if(err = this->GetKeyedValue(f,"EbbTime=",lineNum++,strLine,&this->fCurrentOffset.EbbTime))  goto readError;
			if(err = this->GetKeyedValue(f,"FloodSpdRatio=",lineNum++,strLine,&this->fCurrentOffset.FloodSpdRatio))  goto readError;
			if(err = this->GetKeyedValue(f,"EbbSpdRatio=",lineNum++,strLine,&this->fCurrentOffset.EbbSpdRatio))  goto readError;
			if(err = this->GetKeyedValue(f,"MinBFloodSpd=",lineNum++,strLine,&this->fCurrentOffset.MinBFloodSpd))  goto readError;
			if(err = this->GetKeyedValue(f,"MinBFloodDir=",lineNum++,strLine,&this->fCurrentOffset.MinBFloodDir))  goto readError;
			if(err = this->GetKeyedValue(f,"MaxFloodSpd=",lineNum++,strLine,&this->fCurrentOffset.MaxFloodSpd))  goto readError;
			if(err = this->GetKeyedValue(f,"MaxFloodDir=",lineNum++,strLine,&this->fCurrentOffset.MaxFloodDir))  goto readError;
			if(err = this->GetKeyedValue(f,"MinBEbbSpd=",lineNum++,strLine,&this->fCurrentOffset.MinBEbbSpd))  goto readError;
			if(err = this->GetKeyedValue(f,"MinBEbbDir=",lineNum++,strLine,&this->fCurrentOffset.MinBEbbDir))  goto readError;
			if(err = this->GetKeyedValue(f,"MaxEbbSpd=",lineNum++,strLine,&this->fCurrentOffset.MaxEbbSpd))  goto readError;
			if(err = this->GetKeyedValue(f,"MaxEbbDir=",lineNum++,strLine,&this->fCurrentOffset.MaxEbbDir))  goto readError;
			SetFileType(SHIOCURRENTSFILE);
			break;
		case 'h': case 'H': 
			if(err = this->GetKeyedValue(f,"HighTime=",lineNum++,strLine,&this->fHeightOffset.HighTime))  goto readError;
			if(err = this->GetKeyedValue(f,"LowTime=",lineNum++,strLine,&this->fHeightOffset.LowTime))  goto readError;
			if(err = this->GetKeyedValue(f,"HighHeight_Mult=",lineNum++,strLine,&this->fHeightOffset.HighHeight_Mult))  goto readError;
			if(err = this->GetKeyedValue(f,"HighHeight_Add=",lineNum++,strLine,&this->fHeightOffset.HighHeight_Add))  goto readError;
			if(err = this->GetKeyedValue(f,"LowHeight_Mult=",lineNum++,strLine,&this->fHeightOffset.LowHeight_Mult))  goto readError;
			if(err = this->GetKeyedValue(f,"LowHeight_Add=",lineNum++,strLine,&this->fHeightOffset.LowHeight_Add))  goto readError;
			SetFileType(SHIOHEIGHTSFILE);
			break;
		case 'p': case 'P': 
			if(err = this->GetKeyedValue(f,"HighTime=",lineNum++,strLine,&this->fHeightOffset.HighTime))  goto readError;
			if(err = this->GetKeyedValue(f,"LowTime=",lineNum++,strLine,&this->fHeightOffset.LowTime))  goto readError;
			if(err = this->GetKeyedValue(f,"HighHeight_Mult=",lineNum++,strLine,&this->fHeightOffset.HighHeight_Mult))  goto readError;
			if(err = this->GetKeyedValue(f,"HighHeight_Add=",lineNum++,strLine,&this->fHeightOffset.HighHeight_Add))  goto readError;
			if(err = this->GetKeyedValue(f,"LowHeight_Mult=",lineNum++,strLine,&this->fHeightOffset.LowHeight_Mult))  goto readError;
			if(err = this->GetKeyedValue(f,"LowHeight_Add=",lineNum++,strLine,&this->fHeightOffset.LowHeight_Add))  goto readError;
			SetFileType(PROGRESSIVETIDEFILE);
			break;
	}
	
	
	if(f) DisposeHandle((Handle)f); f = nil;
	return 0;
	
readError:
	if(f) DisposeHandle((Handle)f); f = nil;
	sprintf(strLine,"Error reading SHIO time file %s on line %ld",this->fileName,lineNum);
	printError(strLine);
	this->Dispose();
	return -1;
	
Error:
	if(f) DisposeHandle((Handle)f); f = nil;
	return -1;
	
}
Beispiel #3
0
///////////////////////////////////////////////////////////////////////////////
// OnInitDialog
BOOL CCrashReportDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// get our path name - we assume that crashed exe is in same directory
	TCHAR appPath[_MAX_PATH];
	appPath[0]=0;
	::GetModuleFileName(NULL, appPath, _MAX_PATH);
	TCHAR *cp = _tcsrchr(appPath, _T('\\'));
	if (cp != NULL)
	{
		cp++;
		*cp = 0;
	}
	TCHAR crashedAppicationPath[MAX_PATH];
	_sntprintf(crashedAppicationPath, MAX_PATH, _T("%s%s"), appPath, CRASHREPORT_APPEXENAME);
	//=== Initialize the gui with the Crashed Title / icon
	InitializeDisplay(CRASHREPORT_APPTITLE, crashedAppicationPath);
	//=== Create the native report
	m_debugInfo += CollectInformation(crashedAppicationPath);


	//=== Application Monitor Data
#ifdef USE_APPLICATIONMONITOR
	TCHAR bf[MAX_PATH];
	GetModuleFileName(NULL, bf, MAX_PATH);
	LPTSTR pos = _tcsrchr(bf, '\\');
	pos[1] = 0;
	_tcscat(bf, CRASHREPORT_APPEXENAME);
	pos = _tcsrchr(bf, '.');
	pos[1] = 0;
	_tcscat(bf, _T("ini"));

	IniAppSettings settings;
	settings.Load(bf);
	std::basic_string<TCHAR> stateString;
	if (settings.Read(CRASHREPORT_INIMONITORSECTION, CRASHREPORT_INIMONITORVALUE, stateString, _T("")))
	{
		AppMonitor appMon;
		if (appMon.Load(stateString.c_str()))
		{
			const AppMonitor::State& state = appMon.GetState();
			m_appID = state.AppUniqueID;
			CString line;
			line.Format(_T("AppUniqueID: %u\r\n"), state.AppUniqueID);
			m_debugInfo += line;
			line.Format(_T("IsAfterCrashStatus: %d\r\n"), appMon.IsAfterCrash());
			m_debugInfo += line;
			line.Format(_T("Statistics: %d/%d - %d/%d\r\n"), 
				state.Crashes, 
				state.Runs, 
				state.TotalCrashes, 
				state.TotalRuns
				);
			m_debugInfo += line;
		}

	}

#endif


	//=== Add the rest of the files to the report
	INT fileNum = 0;
	LPCTSTR files[] = CRASHREPORT_FILES;
	while (files[fileNum] != 0)
	{
		TCHAR bf[MAX_PATH];
		_sntprintf(bf, MAX_PATH, _T("%s%s"), appPath, files[fileNum]);
		CStringA fileContents;
		if (ReadFileContents(bf, fileContents))
		{
			m_debugInfo += _T("\r\n@===");
			m_debugInfo += files[fileNum];
			m_debugInfo += _T("\r\n");
			m_debugInfo += CA2CT(fileContents);
		}
		fileNum++;
	}
	LoadHandCursor();
	SetTimer(1, 80, NULL);
	return TRUE;  // return TRUE  unless you set the focus to a control
}
Beispiel #4
0
bool ServerSideScripting::ProcessLine( QTextStream &sCode, 
                                       QString     &sLine, 
                                       bool         bInCode,
                                       QString     &sTransBuffer ) const
{
    QString sLowerLine = sLine.toLower();

    if (!sTransBuffer.isEmpty())
    {
        int nEndTransPos = sLowerLine.indexOf("</i18n>");

        if (nEndTransPos == -1)
        {
            sTransBuffer.append(" ");
            sTransBuffer.append(sLine);
            return bInCode;
        }

        if (nEndTransPos > 0)
            sTransBuffer.append(" ");

        sTransBuffer.append(sLine.left(nEndTransPos).trimmed());
        QString trStr =
            QCoreApplication::translate("HtmlUI", sTransBuffer.trimmed().toLocal8Bit().data());
        trStr.replace( '"', "\\\"" );
        sCode << "os.write( \"" << trStr << "\" );\n";
        sTransBuffer = "";

        if (nEndTransPos == (sLine.length() - 7))
            return bInCode;

        sLine = sLine.right(sLine.length() - (nEndTransPos + 7));
    }

    int nStartTransPos = sLowerLine.indexOf("<i18n>");
    if (nStartTransPos != -1)
    {
        int nEndTransPos = sLowerLine.indexOf("</i18n>");
        if (nEndTransPos != -1)
        {
            QString patStr = sLine.mid(nStartTransPos,
                                       (nEndTransPos + 7 - nStartTransPos));
            QString repStr = patStr.mid(6, patStr.length() - 13).trimmed();
            sLine.replace(patStr, QCoreApplication::translate("HtmlUI", repStr.toLocal8Bit().data()));
            return ProcessLine(sCode, sLine, bInCode, sTransBuffer);
        }
        else
        {
            sTransBuffer = " ";
            sTransBuffer.append(sLine.mid(nStartTransPos + 6).trimmed());
            sLine = sLine.left(nStartTransPos);
        }
    }

    int  nStartPos       = 0;
    int  nEndPos         = 0;
    int  nMatchPos       = 0;
    bool bMatchFound     = false;

    QString sExpecting = bInCode ? "%>" : "<%";
    bool    bNewLine   = !(sLine.startsWith( sExpecting ));
        
    while (nStartPos < sLine.length())
    {
        nEndPos = sLine.length() - 1;
        
        sExpecting = bInCode ? "%>" : "<%";
        nMatchPos  = sLine.indexOf( sExpecting, nStartPos );
    
        // ------------------------------------------------------------------
        // If not found, Adjust to Save entire line
        // ------------------------------------------------------------------
        
        if (nMatchPos < 0)
        {
            nMatchPos = nEndPos + 1;
            bMatchFound = false;
        }
        else
            bMatchFound = true;
        
        // ------------------------------------------------------------------
        // Add Code or Text to Line
        // ------------------------------------------------------------------
        
        QString sSegment = sLine.mid( nStartPos, nMatchPos - nStartPos );
                
        if ( !sSegment.isEmpty())
        {
            if (bInCode)
            {
                // Add Code
    
                if (sSegment.startsWith( "=" ))
                {
                    // Evaluate statement and render results.

                    sCode << "os.write( " << sSegment.mid( 1 ) << " ); "
                          << "\n";
                }
                else if (sSegment.startsWith( "import" ))
                {
                    // Loads supplied path as script file. 
                    //
                    // Syntax: import "/relative/path/to/script.js"
                    //   - must be at start of line (no leading spaces)
                    //

                    // Extract filename (remove quotes)

                    QStringList sParts = sSegment.split( ' ', QString::SkipEmptyParts );

                    if (sParts.length() > 1 )
                    {
                        QString sFileName = sParts[1].mid( 1, sParts[1].length() - 2 );

                        QFileInfo oInfo( m_sResRootPath + sFileName );

                        if (oInfo.exists())
                        {
                            sCode << ReadFileContents( oInfo.canonicalFilePath() )
                                  << "\n";
                        }
                        else
                            LOG(VB_GENERAL, LOG_ERR,
                                QString("ServerSideScripting::ProcessLine 'import' - File not found: %1%2")
                                   .arg(m_sResRootPath)
                                   .arg(sFileName));
                    }
                    else
                    {
                        LOG(VB_GENERAL, LOG_ERR,
                            QString("ServerSideScripting::ProcessLine 'import' - Malformed [%1]")
                                .arg( sSegment ));
                    }

                }
                else
                    sCode << sSegment << "\n";

                if (bMatchFound)
                    bInCode = false;
            }
            else
            {
                // Add Text
                
                sSegment.replace( '"', "\\\"" );
    
                sCode << "os.write( \"" << sSegment << "\" );\n";

                if (bMatchFound) 
                    bInCode = true;
            }
        }
        else
        {
            if (bMatchFound)
                bInCode = !bInCode;
        }
        
        nStartPos = nMatchPos + 2;
    }        

    if ((bNewLine) && !bInCode )
        sCode << "os.writeln( \"\" );\n";
    
    return bInCode;
}