Esempio n. 1
0
void BrowerEditAreaWidget::initContent(const QString &filePath)
{
    QString versionInfo("Version %1 revision %2 (%3)");
    versionInfo = versionInfo.arg(QString::fromLatin1(VERSION_STR))
                             .arg(QString::fromLatin1(REVISION_STR).left(10))
                             .arg(QString::fromLatin1(BUILT_TIME_STR));
    QFile startHereFile(filePath);
    if(!startHereFile.open(QIODevice::ReadOnly|QIODevice::Text))
    {
        return;
    }
    brower->setHtml(QString::fromUtf8(startHereFile.readAll()).arg(versionInfo));
    startHereFile.close();
}
// The result value contains major and minor version in the high resp. the low WORD
DWORD GetFileVersion(WCHAR *path)
{
    DWORD fileVersion = 0;
    DWORD handle;
    DWORD size = GetFileVersionInfoSize(path, &handle);
    ScopedMem<void> versionInfo(malloc(size));

    if (versionInfo && GetFileVersionInfo(path, handle, size, versionInfo)) {
        VS_FIXEDFILEINFO *fileInfo;
        UINT len;
        if (VerQueryValue(versionInfo, L"\\", (LPVOID *)&fileInfo, &len))
            fileVersion = fileInfo->dwFileVersionMS;
    }

    return fileVersion;
}
Esempio n. 3
0
String getProductVersion() {
    String productVersion;
    String binaryPath = getBinaryLocation();

    DWORD dwSize = GetFileVersionInfoSize(binaryPath.c_str(), NULL);
    if (dwSize) {
        std::vector<BYTE> versionInfo(dwSize);
        BOOL status = GetFileVersionInfo(binaryPath.c_str(), NULL, dwSize, &versionInfo[0]);
        if (status) {
            productVersion = getQueryString(&versionInfo[0], "ProductVersion");
        }
    }

    if (productVersion.empty()) {
        return "unknown";
    } else {
        return productVersion;
    }
}
Esempio n. 4
0
//#define DEBUG
bool CFlashUpdate::selectHttpImage(void)
{
    CHTTPTool httpTool;
    std::string url;
    std::string name;
    std::string version;
    std::string md5;
    std::vector<std::string> updates_lists, urls, names, versions, descriptions, md5s;
    char fileTypes[128];
    int selected = -1;

    httpTool.setStatusViewer(this);
    showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_GETINFOFILE)); // UTF-8

    CMenuWidget SelectionWidget(LOCALE_FLASHUPDATE_SELECTIMAGE, "softupdate.raw", 600);
    SelectionWidget.addItem(GenericMenuSeparator);
    SelectionWidget.addItem(GenericMenuBack);

    std::ifstream urlFile(g_settings.softupdate_url_file);
#ifdef DEBUG
    printf("[update] file %s\n", g_settings.softupdate_url_file);
#endif

    unsigned int i = 0;
    while (urlFile >> url)
    {
        std::string::size_type startpos, endpos;
#ifdef DEBUG
        printf("[update] url %s\n", url.c_str());
#endif

        /* extract domain name */
        startpos = url.find("//");
        if (startpos == std::string::npos)
        {
            startpos = 0;
            endpos   = std::string::npos;
            updates_lists.push_back(url.substr(startpos, endpos - startpos));
        }
        else
        {
            //startpos += 2;
            //endpos    = url.find('/', startpos);
            startpos = url.find('/', startpos+2)+1;
            endpos   = std::string::npos;
            updates_lists.push_back(url.substr(startpos, endpos - startpos));
        }
        //updates_lists.push_back(url.substr(startpos, endpos - startpos));

        SelectionWidget.addItem(new CNonLocalizedMenuSeparator(updates_lists.rbegin()->c_str(), LOCALE_FLASHUPDATE_SELECTIMAGE));
        if (httpTool.downloadFile(url, gTmpPath LIST_OF_UPDATES_LOCAL_FILENAME, 20))
        {
            std::ifstream in(gTmpPath LIST_OF_UPDATES_LOCAL_FILENAME);
            bool enabled;
            while (in >> url >> version >> md5 >> std::ws)
            {
                urls.push_back(url);
                versions.push_back(version);
                std::getline(in, name);
                names.push_back(name);
                //std::getline(in, md5);
                md5s.push_back(md5);
                enabled = true;
#ifdef DEBUG
                printf("[update] url %s version %s md5 %s name %s\n", url.c_str(), version.c_str(), md5.c_str(), name.c_str());
#endif

                CFlashVersionInfo versionInfo(versions[i]);

                if(!allow_flash && (versionInfo.snapshot < '3'))
                    enabled = false;
                fileTypes[i] = versionInfo.snapshot;
                std::string description = versionInfo.getType();
                description += ' ';
                description += versionInfo.getDate();
                description += ' ';
                description += versionInfo.getTime();

                descriptions.push_back(description); /* workaround since CMenuForwarder does not store the Option String itself */

                SelectionWidget.addItem(new CMenuForwarderNonLocalized(names[i].c_str(), enabled, descriptions[i].c_str(), new CUpdateMenuTarget(i, &selected)));
                i++;
            }
        }
    }
Esempio n. 5
0
void Initialize(void) {
#if defined (BUSPIRATEV2)
	unsigned char i;
#endif

    volatile unsigned long delay = 0xffff;

    //   volatile unsigned long delay = 0xffff;
    // TBLPAG = 0; // we need to be in page 0 (somehow this isn't set)
#if defined (BUSPIRATEV2) || defined (BUSPIRATEV1A)
    CLKDIVbits.RCDIV0 = 0; //clock divider to 0
    AD1PCFG = 0xFFFF; // Default all pins to digital
#elif defined (BUSPIRATEV4)
    INTCON1bits.NSTDIS = 1;
    CLKDIV = 0x0000; // Set PLL prescaler (1:1)
    BP_LEDUSB_DIR = 0; // output
    CORCONbits.PSV = 1; // JTR PIC24 fixup ?? PSV not being initialized. May have been done by c_init though.
    PSVPAG = 0; //
    OSCCONbits.SOSCEN = 0;
    AD1PCFGL = 0x7FD8; //BUSPIRATEV4 has five analog pins b0, b1, b2, b5, b15
    AD1PCFGH = 0x2;
    // usb_register_sof_handler(0);
#endif

    OSCCONbits.SOSCEN = 0;


    while (delay--);
    //set pin configuration using peripheral pin select
#if defined (BUSPIRATEV2) || defined (BUSPIRATEV1A)
    BP_TERM_RX = BP_TERM_RX_RP; //Inputs UART1 RX RPINR18bits.U1RXR=4;
    BP_TERM_TX_RP = BP_TERM_TX; // Outputs UART1 TX RPOR1bits.RP3R=U1TX_IO;
#elif defined (BUSPIRATEV4) && defined (BPV4_DEBUG)
    BP_TERM_RX = BP_TERM_RX_RP; //Inputs UART1 RX RPINR18bits.U1RXR=11;//AUX2
    BP_TERM_TX_RP = BP_TERM_TX; // Outputs UART1 TX RPOR1bits.RP2R=U1TX_IO;//AUX1
#endif

    //put startup values in config (do first)
    bpConfig.termSpeed = 8; //default PC side port speed, startup in 115200, or saved state (later)....
    bpConfig.displayMode = HEX;

    bpInit(); //put startup values in config (do first)clean up, exit in HI-Z

#if defined (BUSPIRATEV2) || defined (BUSPIRATEV1A)
    InitializeUART1(); //init the PC side serial port
#endif

#if defined (BUSPIRATEV4) && !defined (BPV4_DEBUG)
    initCDC();
    usb_init(cdc_device_descriptor, cdc_config_descriptor, cdc_str_descs, USB_NUM_STRINGS);
    usb_start();
#endif

#if defined (BUSPIRATEV4) && defined (BPV4_DEBUG)
    InitializeUART1(); //init the PC side serial port
#endif

#if defined (BUSPIRATEV2)
    //find the Bus Pirate revision
    //pullup on, do it now so it can settle during the next operations
    CNPU1bits.CN6PUE = 1;
    CNPU1bits.CN7PUE = 1;
#endif
    //#ifndef BUSPIRATEV4
    // Get the chip type and revision
    bpConfig.dev_type = bpReadFlash(DEV_ADDR_UPPER, DEV_ADDR_TYPE);
    bpConfig.dev_rev = bpReadFlash(DEV_ADDR_UPPER, DEV_ADDR_REV);
    //#endif

#if defined (BUSPIRATEV2)
    //now check the revision
	//Version | RB3 | RB2
	//2go, 3a | 1   |  1
	//v3b     | 1   |  0
	//v3.5    | 0   |  0
	i=PORTB; //get settings
	i=i>>2; //remove unused
	i&=(~0b11111100); //clear others
    if (i==0b11) {
        bpConfig.HWversion = 'a';
    } else if(i==0b10){
        bpConfig.HWversion = 'b';
    }else if(i==0){
        bpConfig.HWversion = '5';
	}
    //pullup off
    CNPU1bits.CN6PUE = 0;
    CNPU1bits.CN7PUE = 0;
#else
    bpConfig.HWversion = 0;
#endif

    bpConfig.quiet = 0; // turn output on (default)
    modeConfig.numbits = 8;
#ifdef BP_USE_BASIC
    initpgmspace();
#endif

    TBLPAG = 0; // we need to be in page 0 (somehow this isn't set)

#ifndef BUSPIRATEV4
    bpWBR; //send a line feed
    versionInfo(); //prints hardware and firmware version info (base.c)
#endif

}
Esempio n. 6
0
bool CFlashUpdate::checkVersion4Update()
{
	if(g_settings.softupdate_mode==1) //internet-update
	{
		if(!getInfo())
		{
			hide();
			ShowHint("messagebox.error", g_Locale->getText("flashupdate.getinfofileerror") );
			return false;
		}

		showLocalStatus(100);
		showGlobalStatus(20);
		showStatusMessage(g_Locale->getText("flashupdate.versioncheck").c_str());


		string sFileName = gTmpPath+VersionFile;

		CConfigFile configfile('\t');
		if(!configfile.loadConfig(sFileName))
		{
			ShowHint ( "messagebox.error", g_Locale->getText("flashupdate.getinfofileerror") );
			return false;
		}
		else
		{
			newVersion = configfile.getString( "version", "" );
			if(newVersion=="")
			{
				ShowHint ( "messagebox.error", g_Locale->getText("flashupdate.getinfofileerror") );
				return false;
			}
		}
		printf("internet version: %s\n", newVersion.c_str());

		if(newVersion==installedVersion)
		{
			ShowHint ( "messagebox.error", g_Locale->getText("flashupdate.nonewversion") );
			return false;
		}
	}
	else
	{
		//manuelles update -- filecheck + abfrage
		FILE* fd = fopen((string(gTmpPath+ ImageFile)).c_str(), "r");
		if(fd)
		{
			fclose(fd);
		}
		else
		{
			hide();
			printf("flash-file not found: %s\n", (string(gTmpPath+ ImageFile)).c_str() );
			ShowHint ( "messagebox.error", g_Locale->getText("flashupdate.cantopenfile") );
			return false;
		}
		hide();
		
		//bestimmung der CramfsDaten
		char cramfsName[30];
		cramfs_name( (char*) (string(gTmpPath+ImageFile)).c_str(), (char*) &cramfsName);

		CFlashVersionInfo versionInfo(cramfsName);

		char msg[400];
		sprintf( (char*) &msg, g_Locale->getText("flashupdate.msgbox_manual").c_str(), versionInfo.getDate().c_str(), 
				versionInfo.getTime().c_str(), versionInfo.getBaseImageVersion().c_str(), versionInfo.getType().c_str() );
		if ( ShowMsg ( "messagebox.info", msg, CMessageBox::mbrYes, CMessageBox::mbYes | CMessageBox::mbNo, "softupdate.raw" ) != CMessageBox::mbrYes )
		{
			return false;
		}

		return true;
	}
	
	showLocalStatus(100);
	showGlobalStatus(20);
	hide();

	//bestimmung der CramfsDaten
	CFlashVersionInfo versionInfo(newVersion);
	
	char msg[250];
	sprintf( (char*) &msg, g_Locale->getText("flashupdate.msgbox").c_str(), versionInfo.getDate().c_str(), 
				versionInfo.getTime().c_str(), versionInfo.getBaseImageVersion().c_str(), versionInfo.getType().c_str() );
    if ( ShowMsg ( "messagebox.info", msg, CMessageBox::mbrYes, CMessageBox::mbYes | CMessageBox::mbNo, "softupdate.raw" ) != CMessageBox::mbrYes )
    {
		return false;
    }

	return true;
}
Esempio n. 7
0
//#define DEBUG
bool CFlashUpdate::selectHttpImage(void)
{
	CHTTPTool httpTool;
	std::string url;
	std::string name;
	std::string version;
	std::string md5;
	std::vector<std::string> updates_lists, urls, names, versions, descriptions, md5s;
	char fileTypes[128];
	int selected = -1, listWidth = w_max (80, 10);
	int curVer, newVer, newfound = 0;

	std::vector<CUpdateMenuTarget*> update_t_list;

	CConfigFile _configfile('\t');
	const char * versionString = (_configfile.loadConfig("/.version")) ? (_configfile.getString( "version", "????????????????").c_str()) : "????????????????";
	installedVersion = versionString;

	CFlashVersionInfo curInfo(versionString);
	printf("current flash-version: %s (%d)\n", installedVersion.c_str(), curInfo.getVersion());
	curVer = curInfo.getVersion();

	httpTool.setStatusViewer(this);
	showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_GETINFOFILE)); // UTF-8

	char current[200];
	snprintf(current, 200, "%s: %s %s %s %s %s", g_Locale->getText(LOCALE_FLASHUPDATE_CURRENTVERSION_SEP), curInfo.getReleaseCycle(), 
		g_Locale->getText(LOCALE_FLASHUPDATE_CURRENTVERSIONDATE), curInfo.getDate(), 
		g_Locale->getText(LOCALE_FLASHUPDATE_CURRENTVERSIONTIME), curInfo.getTime());

	CMenuWidget SelectionWidget(LOCALE_FLASHUPDATE_SELECTIMAGE, NEUTRINO_ICON_UPDATE, listWidth, MN_WIDGET_ID_IMAGESELECTOR);

	SelectionWidget.addItem(GenericMenuSeparator);
	SelectionWidget.addItem(GenericMenuBack);
	SelectionWidget.addItem(new CMenuSeparator(CMenuSeparator::LINE));

	SelectionWidget.addItem(new CMenuForwarder(current, false));
	std::ifstream urlFile(g_settings.softupdate_url_file.c_str());
#ifdef DEBUG
	printf("[update] file %s\n", g_settings.softupdate_url_file.c_str());
#endif

	unsigned int i = 0;
	while (urlFile >> url)
	{
		std::string::size_type startpos, endpos;
#ifdef DEBUG
		printf("[update] url %s\n", url.c_str());
#endif

		/* extract domain name */
		startpos = url.find("//");
		if (startpos == std::string::npos)
		{
			startpos = 0;
			endpos   = std::string::npos;
			updates_lists.push_back(url.substr(startpos, endpos - startpos));
		}
		else
		{
			//startpos += 2;
			//endpos    = url.find('/', startpos);
			startpos = url.find('/', startpos+2)+1;
			endpos   = std::string::npos;
			updates_lists.push_back(url.substr(startpos, endpos - startpos));
		}
		//updates_lists.push_back(url.substr(startpos, endpos - startpos));

		SelectionWidget.addItem(new CMenuSeparator(CMenuSeparator::STRING | CMenuSeparator::LINE, updates_lists.rbegin()->c_str()));
		if (httpTool.downloadFile(url, gTmpPath LIST_OF_UPDATES_LOCAL_FILENAME, 20))
		{
			std::ifstream in(gTmpPath LIST_OF_UPDATES_LOCAL_FILENAME);
			bool enabled;
			while (in >> url >> version >> md5 >> std::ws)
			{
				urls.push_back(url);
				versions.push_back(version);
				std::getline(in, name);
				names.push_back(name);
				//std::getline(in, md5);
				md5s.push_back(md5);
				enabled = true;

				CFlashVersionInfo versionInfo(versions[i]);
				newVer = versionInfo.getVersion();
#ifdef DEBUG
				printf("[update] url %s version %s (%d) md5 %s name %s\n", url.c_str(), version.c_str(), newVer, md5.c_str(), name.c_str());
#endif
				if(newVer > curVer)
					newfound = 1;
				if(!allow_flash && (versionInfo.snapshot < '3'))
					enabled = false;
				fileTypes[i] = versionInfo.snapshot;
				//std::string description = versionInfo.getType();
				std::string description = versionInfo.getReleaseCycle();
				description += ' ';
				description += versionInfo.getType();
				description += ' ';
				description += versionInfo.getDate();
				description += ' ';
				description += versionInfo.getTime();

				descriptions.push_back(description); /* workaround since CMenuForwarder does not store the Option String itself */

				//SelectionWidget.addItem(new CMenuForwarder(names[i].c_str(), enabled, descriptions[i].c_str(), new CUpdateMenuTarget(i, &selected)));
				CUpdateMenuTarget * up = new CUpdateMenuTarget(i, &selected);
				update_t_list.push_back(up);
				SelectionWidget.addItem(new CMenuForwarder(descriptions[i].c_str(), enabled, names[i].c_str(), up));
				i++;
			}
		}
	}
QList<ProjectExplorer::Abi> EmbeddedLinuxQtVersion::detectQtAbis() const
{
    return qtAbisFromLibrary(qtCorePaths(versionInfo(), qtVersionString()));
}
Esempio n. 9
0
void MSBuildQbsProductProject::addConfiguration(const GeneratableProject &project,
                                            const Project &buildTask,
                                            const ProductData &productData,
                                            const QStringList &buildConfigurationCommandLine)
{
    const auto targetDir = Internal::PathUtils::toNativeSeparators(
                productTargetPath(productData), Internal::HostOsInfo::HostOsWindows);

    auto configurationDir = Internal::PathUtils::toNativeSeparators(
                project.baseBuildDirectory().absolutePath()
                    + QLatin1Char('\\')
                    + MSBuildUtils::configurationName(buildTask),
                Internal::HostOsInfo::HostOsWindows);
    auto relativeTargetDir = targetDir;
    if (targetDir.startsWith(configurationDir))
        relativeTargetDir = QStringLiteral("$(SolutionDir)$(Configuration)")
                + relativeTargetDir.mid(configurationDir.size());

    const auto properties = productData.moduleProperties();

    const bool debugBuild = properties.getModuleProperty(QStringLiteral("qbs"),
                                                         QStringLiteral("debugInformation"))
            .toBool();

    const auto includePaths = QStringList()
            << properties.getModulePropertiesAsStringList(QStringLiteral("cpp"),
                                                          QStringLiteral("includePaths"))
            << properties.getModulePropertiesAsStringList(QStringLiteral("cpp"),
                                                          QStringLiteral("systemIncludePaths"));
    const auto cppDefines = properties
            .getModulePropertiesAsStringList(QStringLiteral("cpp"), QStringLiteral("defines"));

    const auto sep = Internal::HostOsInfo::pathListSeparator(Internal::HostOsInfo::HostOsWindows);

    auto propertyGroup1 = new MSBuildPropertyGroup(this);
    propertyGroup1->setCondition(MSBuildUtils::buildTaskCondition(buildTask));
    propertyGroup1->setLabel(QStringLiteral("Configuration"));
    propertyGroup1->appendProperty(QStringLiteral("UseDebugLibraries"),
                                   debugBuild ? QStringLiteral("true") : QStringLiteral("false"));

    // General - General
    // We need a trailing backslash for $(OutDir); See also the VS documentation:
    // https://docs.microsoft.com/en-us/cpp/ide/common-macros-for-build-commands-and-properties
    propertyGroup1->appendProperty(QStringLiteral("OutDir"), relativeTargetDir + QLatin1Char('\\'));
    propertyGroup1->appendProperty(QStringLiteral("TargetName"), productData.targetName());
    propertyGroup1->appendProperty(QStringLiteral("PlatformToolset"),
                                   versionInfo().platformToolsetVersion());
    propertyGroup1->appendProperty(QStringLiteral("ConfigurationType"), QStringLiteral("Makefile"));

    // VS possible values: Unicode|MultiByte|NotSet
    propertyGroup1->appendProperty(QStringLiteral("CharacterSet"),
        properties.getModuleProperty(QStringLiteral("cpp"),
            QStringLiteral("windowsApiCharacterSet")) == QStringLiteral("unicode")
                ? QStringLiteral("MultiByte") : QStringLiteral("NotSet"));

    // Debugging
    propertyGroup1->appendProperty(QStringLiteral("DebuggerFlavor"),
                                   QStringLiteral("WindowsLocalDebugger"));
    propertyGroup1->appendProperty(QStringLiteral("LocalDebuggerCommand"),
                                   QStringLiteral("$(OutDir)$(TargetName)$(TargetExt)"));
    propertyGroup1->appendProperty(QStringLiteral("LocalDebuggerWorkingDirectory"),
                                   QStringLiteral("$(OutDir)"));

    // NMake - General
    // Skip configuration name, that's handled in qbs-shared.props
    const auto params = Internal::shellQuote(buildConfigurationCommandLine.mid(1),
                                                Internal::HostOsInfo::HostOsWindows);
    propertyGroup1->appendProperty(QStringLiteral("NMakeBuildCommandLine"),
                                   QStringLiteral("$(QbsBuildCommandLine) ") + params);
    propertyGroup1->appendProperty(QStringLiteral("NMakeReBuildCommandLine"),
                                   QStringLiteral("$(QbsReBuildCommandLine) ") + params);
    propertyGroup1->appendProperty(QStringLiteral("NMakeCleanCommandLine"),
                                   QStringLiteral("$(QbsCleanCommandLine) ") + params);
    propertyGroup1->appendProperty(QStringLiteral("NMakeOutput"),
                                   QStringLiteral("$(OutDir)$(TargetName)$(TargetExt)"));

    // NMake - IntelliSense
    propertyGroup1->appendProperty(QStringLiteral("NMakePreprocessorDefinitions"),
                                   cppDefines.join(sep));
    propertyGroup1->appendProperty(QStringLiteral("NMakeIncludeSearchPath"),
                                   includePaths.join(sep));
}
Esempio n. 10
0
int main(int argc, char *argv[])
{
    printf("AnsiLove/C %s - ANSi / ASCII art to PNG converter\n"\
           "Copyright (C) 2011-2012 Stefan Vogt, Brian Cassidy, Frederic Cambus.\n", VERSION);
    
    // SAUCE record related bool types
    bool justDisplaySAUCE = false;
    bool fileHasSAUCE = false;
    
    // retina output bool type
    bool createRetinaRep = false;
    
    // analyze options and do what has to be done
    bool outputIdentical = false;
    bool fileIsBinary = false;
    bool fileIsANSi = false;
    bool fileIsPCBoard = false;
    bool fileIsTundra = false;
    
    if (argc == 1 || argc >= 9) {
        synopsis();
        return EXIT_SUCCESS;
    }
    if ((strcmp(argv[1], "-v") == 0) || (strcmp(argv[1], "--version") == 0)) {
        versionInfo();
        return EXIT_SUCCESS;
    }
    if ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0)) {
        showHelp();
        return EXIT_SUCCESS;
    }
    if (strcmp(argv[1], "-e") == 0) {
        listExamples();
        return EXIT_SUCCESS;
    }
    if ((argv[2] && (strcmp(argv[2], "-s") == 0))  ||
        (argv[2] && (strcmp(argv[2], "-i") == 0))  ||
        (argv[2] && (strcmp(argv[2], "-ir") == 0)) ||
        (argv[2] && (strcmp(argv[2], "-o") == 0))  ||
        (argv[2] && (strcmp(argv[2], "-or") == 0)))
    {
        if (strcmp(argv[2], "-s") == 0) {
            justDisplaySAUCE = true;
        }
        
        if (strcmp(argv[2], "-ir") == 0 || strcmp(argv[2], "-or") == 0) {
            createRetinaRep = true;
        }
                
        // let's check the file for a valid SAUCE record
        sauce *record = sauceReadFileName(argv[1]);
        
        // record == NULL also means there is no file, we can stop here
        if (record == NULL) {
            printf("\nFile %s not found.\n\n", argv[1]);
            return EXIT_FAILURE;
        }
        else {
            // if we find a SAUCE record, update bool flag
            if (strcmp(record->ID, SAUCE_ID) == 0) {
                fileHasSAUCE = true;
            }
        }
        
        // this should be self-explanatory
        if (justDisplaySAUCE == false) 
        {
            // declaration of types we pass to ansilove.c
            char *input = argv[1];
            char output[1000] = { 0 };
            char retinaout[1000] = { 0 };
            char columns[1000] = { 0 };
            char font[1000] = { 0 };
            char bits[1000] = { 0 };
            char icecolors[1000] = { 0 };
            char *fext;
            
            // find last position of char '.' so we can determine the file extension
            size_t index = strrchr(input, '.') - input;
            
            // calculate size of the input string
            size_t inpSize = strlen(input);
            
            // generate size_t result we can pass to our substr() implementation
            size_t result = inpSize - index;
            
            // finally create the file extension string
            fext = substr(input, inpSize - result, result);
            fext = strtolower(fext);
            if (fext == NULL) {
                fext = "none";
            }
            
            // in case we got arguments for input and the '-i' or '-ir' flag is set
            if (strcmp(argv[2], "-i") == 0) {
                // append .png suffix to file name
                sprintf(output, "%s.png", input);
                sprintf(retinaout, "placeholder_%s.png", input);
                outputIdentical = true;
            }
            
            if (strcmp(argv[2], "-ir") == 0) {
                // again, append .png and also add @2x for retina output
                sprintf(output, "%s.png", input);
                sprintf(retinaout, "*****@*****.**", input);
                outputIdentical = true;
            }
            
            if ((strcmp(argv[2], "-o") == 0) && argv[3]) {
                // so the user provided an alternate path / file name
                sprintf(output, "%s.png", argv[3]);
                sprintf(retinaout, "placeholder_%s.png", input);
            }
            
            if ((strcmp(argv[2], "-or") == 0) && argv[3]) {
                // alternate path and retina? damn you! even more work.
                sprintf(output, "%s.png", argv[3]);
                sprintf(retinaout, "*****@*****.**", argv[3]);
            }
        
            if ((strcmp(argv[2], "-o") == 0) && !argv[3]) {
                // arrr... matey! setting the option -o without output file argument, eh?
                printf("\nOption -o is invalid without output file argument.\n\n");
                return EXIT_FAILURE;
            }
            
            if ((strcmp(argv[2], "-or") == 0) && !argv[3]) {
                // y u no enter output file argument?
                printf("\nOption -or is invalid without output file argument.\n\n");
                return EXIT_FAILURE;
            }
            
            // check for operands and apply them based on the file extension
            if ((strcmp(fext, ".bin") == 0) && outputIdentical == true)
            {
                // set binary bool value
                fileIsBinary = true;
                
                // font
                if (argc >= 4) {
                    sprintf(font, "%s", argv[3]);
                }
                else {
                    sprintf(font, "%s", "80x25");
                }
                // bits
                if (argc >= 5) {
                    sprintf(bits, "%s", argv[4]);
                }
                else {
                    sprintf(bits, "%s", "8");
                    
                }
                // iCE colors
                if (argc >= 6) {
                    sprintf(icecolors, "%s", argv[5]);
                }
                else {
                    sprintf(icecolors, "%s", "0");
                }
                // columns
                if (argc >= 7) {
                    sprintf(columns, "%s", argv[6]);
                }
                else {
                    sprintf(columns, "%s", "160");
                }
            }
            else if ((strcmp(fext, ".bin") == 0) && outputIdentical == false)
            {
                // font
                if (argc >= 5) {
                    sprintf(font, "%s", argv[4]);
                }
                else {
                    sprintf(font, "%s", "80x25");
                }
                // bits
                if (argc >= 6) {
                    sprintf(bits, "%s", argv[5]);
                }
                else {
                    sprintf(bits, "%s", "8");
                    
                }
                // iCE colors
                if (argc >= 7) {
                    sprintf(icecolors, "%s", argv[6]);
                }
                else {
                    sprintf(icecolors, "%s", "0");
                }
                // columns
                if (argc >= 8) {
                    sprintf(columns, "%s", argv[7]);
                }
                else {
                    sprintf(columns, "%s", "160");
                }
            }
            else {
                if (outputIdentical == true) {
                    // font
                    if (argc >= 4) {
                        sprintf(font, "%s", argv[3]);
                    }
                    else {
                        sprintf(font, "%s", "80x25");
                    }
                    // bits
                    if (argc >= 5) {
                        sprintf(bits, "%s", argv[4]);
                    }
                    else {
                        sprintf(bits, "%s", "8");
                    }
                    // iCE colors
                    if (argc >= 6) {
                        sprintf(icecolors, "%s", argv[5]);
                    }
                    else {
                        sprintf(icecolors, "%s", "0");
                    }
                }
                else {
                    // font
                    if (argc >= 5) {
                        sprintf(font, "%s", argv[4]);
                    }
                    else {
                        sprintf(font, "%s", "80x25");
                    }
                    // bits
                    if (argc >= 6) {
                        sprintf(bits, "%s", argv[5]);
                    }
                    else {
                        sprintf(bits, "%s", "8");
                    }
                    // iCE colors
                    if (argc >= 7) {
                        sprintf(icecolors, "%s", argv[6]);
                    }
                    else {
                        sprintf(icecolors, "%s", "0");
                    }
                }
            }
            
            // create the output file by invoking the appropiate function
            if (strcmp(fext, ".pcb") == 0) {
                // params: input, output, font, bits, icecolors
                alPcBoardLoader(input, output, retinaout, font, bits, createRetinaRep);
                fileIsPCBoard = true;
            }
            else if (strcmp(fext, ".bin") == 0) {
                // params: input, output, columns, font, bits, icecolors
                alBinaryLoader(input, output, retinaout, columns, font, bits, icecolors, createRetinaRep);
                fileIsBinary = true;
            }
            else if (strcmp(fext, ".adf") == 0) {
                // params: input, output, bits
                alArtworxLoader(input, output, retinaout, bits, createRetinaRep);
            }
            else if (strcmp(fext, ".idf") == 0) {
                // params: input, output, bits
                alIcedrawLoader(input, output, retinaout, bits, fileHasSAUCE, createRetinaRep);
            }
            else if (strcmp(fext, ".tnd") == 0) {
                alTundraLoader(input, output, retinaout, font, bits, createRetinaRep);
                fileIsTundra = true;
            }
            else if (strcmp(fext, ".xb") == 0) {
                // params: input, output, bits
                alXbinLoader(input, output, retinaout, bits, createRetinaRep);
            }
            else {
                // params: input, output, font, bits, icecolors, fext
                alAnsiLoader(input, output, retinaout, font, bits, icecolors, fext, createRetinaRep);
                fileIsANSi = true;
            }
            
            // gather information and report to the command line
            printf("\nInput File: %s\n", input);
            printf("Output File: %s\n", output);
            if (createRetinaRep == true) {
                printf("Retina Output File: %s\n", retinaout);
            }
            if (fileIsANSi == true || fileIsBinary == true || 
                fileIsPCBoard == true || fileIsTundra == true) {
                printf("Font: %s\n", font);
            }
            if (fileIsANSi == true || fileIsBinary == true || 
                fileIsPCBoard == true || fileIsTundra == true) {
                printf("Bits: %s\n", bits);
            }
            if (fileIsANSi == true || fileIsBinary == true || fileIsPCBoard == true) {
                printf("iCE Colors: %s\n", icecolors);
            }
            if (fileIsBinary == true) {
                printf("Columns: %s\n", columns);
            }
        }
        
        // either display SAUCE or tell us if there is no record
        if (fileHasSAUCE == false) {
            printf("\nFile %s does not have a SAUCE record.\n", argv[1]);
        }
        else {
            printf( "\n%s: %s v%s\n", "Id", record->ID, record->version);
            printf( "%s: %s\n", "Title", record->title );
            printf( "%s: %s\n", "Author", record->author);
            printf( "%s: %s\n", "Group", record->group);
            printf( "%s: %s\n", "Date", record->date);
            printf( "%s: %d\n", "Datatype", record->dataType);
            printf( "%s: %d\n", "Filetype", record->fileType);
            if (record->flags != 0) {
                printf( "%s: %d\n", "Flags", record->flags);
            }
            if (record->tinfo1 != 0) {
                printf( "%s: %d\n", "Tinfo1", record->tinfo1);
            }
            if (record->tinfo2 != 0) {
                printf( "%s: %d\n", "Tinfo2", record->tinfo2);
            }
            if (record->tinfo3 != 0) {
                printf( "%s: %d\n", "Tinfo3", record->tinfo3);
            }
            if (record->tinfo4 != 0) {
                printf( "%s: %d\n", "Tinfo4", record->tinfo4);
            }
            if (record->comments > 0) {
                int32_t i;
                printf( "Comments: ");
                for(i = 0; i < record->comments; i++) {
                    printf( "%s\n", record->comment_lines[i] );
                }
            }
        }
        
        // post a message when the output file is created (in case we created output)
        if (justDisplaySAUCE == false) {
            printf("\nSuccessfully created output file.\n\n");
        }
        else {
            printf("\n");
        }
    }
    else {
        // in any other case the synopsis will be just fine
        synopsis();
        return EXIT_SUCCESS;
    }
    return EXIT_SUCCESS;
}
Esempio n. 11
0
int processOptions(int argc, char *argv[], options *opts) 
{
    int c;
    int index;
    bool scalling = false;
    while( (c = getopt_long(argc, argv, "a:b:c:d:D:ef:gGhHk:K:l:Ln:o:rs:S:Vw:x:y:z", long_options, &index)) != -1 ) 
    {
        switch(c) 
        {
            case 'a':
#if RENDERING                
                if (strcmp(optarg, "dot") && strcmp(optarg, "neato") && strcmp(optarg, "fdp") && strcmp(optarg, "sfdp") && strcmp(optarg, "twopi") && strcmp(optarg, "circo")) {
                    std::cerr<<PACKAGE_NAME<<" [WARNING]: '"<<optarg<<"' is not a recognised layout algorithm. Please choose from the following:"<<std::endl;
#ifdef HAVE_NEATO
                    std::cerr<<"\tneato"<<std::endl;
#endif
#ifdef HAVE_DOT
                    std::cerr<<"\tdot"<<std::endl;
#endif
#ifdef HAVE_FDP
                    std::cerr<<"\tfdp"<<std::endl;
#endif
#ifdef HAVE_SFDP
                    std::cerr<<"\tsfdp"<<std::endl;
#endif
#ifdef HAVE_CIRCO
                    std::cerr<<"\tcirco"<<std::endl;
#endif
#ifdef HAVE_TWOPI
                    std::cerr<<"\ttwopi"<<std::endl;
#endif
                    
                } else {
                    opts->layoutAlgorithm = optarg;
                }
#else 
                std::cerr<<PACKAGE_NAME<<" [WARNING]: Not compiled with the correct options to allow rendering of graphs.\nEither use the --enable-rendering option during ./configure and make sure that the graphviz layout programs are in your PATH"<<std::endl;
#endif
                break;
            case 'b': 
                from_string<int>(opts->coverageBins, optarg, std::dec);
                if (opts->coverageBins < 1) 
                {
                    std::cerr<<PACKAGE_NAME<<" [ERROR]: The number of bins for coverage cannot be less than 1"<<std::endl;
                    usage();
                    exit(1);
                }
                break;
            case 'c': 
                if (strcmp(optarg, "red-blue") == 0) 
                {
                    opts->graphColourType = RED_BLUE;
                } 
                else if(strcmp(optarg, "read-blue-green") == 0)
                {
                    opts->graphColourType = RED_BLUE_GREEN;
                }
                else if(strcmp(optarg, "blue-red") == 0)
                {
                    opts->graphColourType = BLUE_RED; 
                }
                else if(strcmp(optarg, "green-blue-red") == 0)
                {
                    opts->graphColourType = GREEN_BLUE_RED;
                }
                else
                {
                    std::cerr<<PACKAGE_NAME<<" [WARNING]: Unknown graph colour type "<<optarg<<" changing to default colour type (red-blue)"<<std::endl;
                    opts->graphColourType = RED_BLUE;
                }
                break;
            case 'd': 
                from_string<unsigned int>(opts->lowDRsize, optarg, std::dec);
                if (opts->lowDRsize < 8) 
                {
                    std::cerr<<PACKAGE_NAME<<" [WARNING]: The lower bound for direct repeat sizes cannot be "<<opts->lowDRsize<<" changing to "<<CRASS_DEF_MIN_DR_SIZE<<std::endl;
                    opts->lowDRsize = CRASS_DEF_MIN_DR_SIZE;
                }
                break;
            case 'D': 
                from_string<unsigned int>(opts->highDRsize, optarg, std::dec);
                break;
            case 'e':
#ifdef DEBUG
                opts->noDebugGraph = true;
#endif
                break;
            case 'f':
                from_string<int>(opts->covCutoff, optarg, std::dec);
                break;
            case 'g':
                 opts->logToScreen = true;
                break;
            case 'G':
            	opts->showSingles= true;
                break;
            case 'h': 
                versionInfo(); 
                usage();
                exit(1); 
                break;
            case 'H':
                opts->removeHomopolymers = true;
                break;
            case 'k': 
                from_string<int>(opts->kmer_clust_size, optarg, std::dec);
                if (opts->kmer_clust_size < 4) 
                {
                    std::cerr<<PACKAGE_NAME<<" [WARNING]: Minimum value for kmer clustering size is: "<<4<<" changing to "<<CRASS_DEF_K_CLUST_MIN<<std::endl;
                    opts->kmer_clust_size = CRASS_DEF_K_CLUST_MIN;
                }
                break;
            case 'K': 
                from_string<int>(opts->cNodeKmerLength, optarg, std::dec);
                break;
            case 'l': 
                from_string<int>(opts->logLevel, optarg, std::dec);
                if(opts->logLevel > CRASS_DEF_MAX_LOGGING)
                {
                    std::cerr<<PACKAGE_NAME<<" [WARNING]: Specified log level higher than max. Changing log level to "<<CRASS_DEF_MAX_LOGGING<<" instead of "<<opts->logLevel<<std::endl;
                    opts->logLevel = CRASS_DEF_MAX_LOGGING;
                }
                break;
            case 'L':
                opts->longDescription = true;
                break;
            case 'n':
                from_string<unsigned int>(opts->minNumRepeats, optarg, std::dec);
                if (opts->minNumRepeats < 2) 
                {
                    std::cerr<<PACKAGE_NAME<<" [ERROR]: The mininum number of repeats cannot be less than 2"<<std::endl;
                    usage();
                    exit(1);
                }
                break;
            case 'o': 
                opts->output_fastq = optarg; 
                // just in case the user put '.' or '..' or '~' as the output directory
                if (opts->output_fastq[opts->output_fastq.length() - 1] != '/')
                {
                    opts->output_fastq += '/';
                }
                
                // check if our output folder exists
                struct stat file_stats;
                if (0 != stat(opts->output_fastq.c_str(),&file_stats)) 
                {
                    RecursiveMkdir(opts->output_fastq);
                }
                // check that the directory is writable
                else if(access(optarg, W_OK))
                {
                    std::cerr<<PACKAGE_NAME<<" [ERROR]: You do not have permission to write to "<<optarg<<std::endl;
                    exit(1);
                }
                break;
            case 'r': 
#ifdef RENDERING 
                opts->noRendering = true; 
#endif
                break;
            case 's': 
                from_string<unsigned int>(opts->lowSpacerSize, optarg, std::dec);
                if (opts->lowSpacerSize < 8) 
                {
                    std::cerr<<PACKAGE_NAME<<" [WARNING]: The lower bound for spacer sizes cannot be "<<opts->lowSpacerSize<<" changing to "<<CRASS_DEF_MIN_SPACER_SIZE<<std::endl;
                    opts->lowSpacerSize = CRASS_DEF_MIN_SPACER_SIZE;
                }
                break;
            case 'S': 
                from_string<unsigned int>(opts->highSpacerSize, optarg, std::dec);
                break;
            case 'V': 
                versionInfo(); 
                exit(1); 
                break;
            case 'w': 
                from_string<unsigned int>(opts->searchWindowLength, optarg, std::dec);
                if ((opts->searchWindowLength < CRASS_DEF_MIN_SEARCH_WINDOW_LENGTH) || (opts->searchWindowLength > CRASS_DEF_MAX_SEARCH_WINDOW_LENGTH))
                {
                    std::cerr<<PACKAGE_NAME<<" [WARNING]: Specified window length higher than max. Changing window length to " << CRASS_DEF_OPTIMAL_SEARCH_WINDOW_LENGTH << " instead of " << opts->searchWindowLength<<std::endl;
                    // Change window length
                    opts->searchWindowLength = CRASS_DEF_OPTIMAL_SEARCH_WINDOW_LENGTH;
                }
                break;        
            case 'x':
                from_string<double>(opts->averageSpacerScalling, optarg, std::dec);
                if (isNotDecimal(opts->averageSpacerScalling)) 
                {
                    std::cerr<<PACKAGE_NAME<<" [WARNING]: The average spacer scalling must be a decimal number. Changing to "<<CRASS_DEF_HOMOPOLYMER_SCALLING<<" instead of "<<opts->averageSpacerScalling<<std::endl;
                    opts->averageSpacerScalling = CRASS_DEF_HOMOPOLYMER_SCALLING;
                }
                scalling = true;
                break;
            case 'y':
                from_string<double>(opts->averageDrScalling, optarg, std::dec);
                if (isNotDecimal(opts->averageDrScalling)) 
                {
                    std::cerr<<PACKAGE_NAME<<" [WARNING]: The average spacer scalling must be a decimal number. Changing to "<<CRASS_DEF_HOMOPOLYMER_SCALLING<<" instead of "<<opts->averageDrScalling<<std::endl;
                    opts->averageDrScalling = CRASS_DEF_HOMOPOLYMER_SCALLING;
                }
                scalling = true;
                break;
            case 'z':
                opts->dontPerformScalling = true;
                break;
            case 0:
#ifdef SEARCH_SINGLETON
                if (strcmp("searchChecker", long_options[index].name) == 0) opts->searchChecker = optarg;
#endif
                break;
            default: 
                versionInfo(); 
                usage(); 
                exit(1); 
                break;
        }
    }
    // Sanity checks for the high and low dr size
    if (opts->lowDRsize >= opts->highDRsize) 
    {
        std::cerr<<PACKAGE_NAME<<" [ERROR]: The lower direct repeat bound is bigger than the higher bound ("<<opts->lowDRsize<<" >= "<<opts->highDRsize<<")"<<std::endl;
        usage();
        exit(1);
    }
    // Sanity checks for the high and low spacer size
    if (opts->lowSpacerSize >= opts->highSpacerSize) 
    {
        std::cerr<<PACKAGE_NAME<<" [ERROR]: The lower spacer bound is bigger than the higher bound ("<<opts->lowSpacerSize<<" >= "<<opts->highSpacerSize<<")"<<std::endl;
        usage();
        exit(1);
    }
    
    // sanity check so that the user doesn't specify scalling and no scalling simultaneously
    if (scalling & opts->dontPerformScalling) {
        std::cerr<<PACKAGE_NAME<<" [ERROR]: Cannot use scalling (-x -y) in conjunction with --noScalling"<<std::endl;
        usage();
        exit(1);
    }
    
    // warn them if they try to scale without specifying to remove homopolymers
    if (scalling && !opts->removeHomopolymers) 
    {
        std::cerr<<PACKAGE_NAME<<" [ERROR]: scalling (-x -y) can only be used in conjunction with --removeHomopolymers"<<std::endl;
        usage();
        exit(1);
    }
    
    // scale the direct repeat and spacer lengths if we should
    if (opts->removeHomopolymers && !opts->dontPerformScalling) 
    {
        opts->lowDRsize *= opts->averageDrScalling;
        opts->highDRsize *= opts->averageDrScalling;
        opts->lowSpacerSize *= opts->averageSpacerScalling;
        opts->highSpacerSize *= opts->averageSpacerScalling;
    }
    
    return optind;
}