Exemplo n.º 1
0
//Include the message
RenameProjectDialog::RenameProjectDialog(const QString &projectDirectory, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::RenameProjectDialog)
{
    ui->setupUi(this);

    //Setup the message
    ui->message->setText( tr("A directory with the same name as the current project exists") + "\n"
                          +tr("Do you wish to move this driectroy to another place?"));

    //Strip the last "/" from the directory name (if any)
    QString dir = projectDirectory;
    if (dir.endsWith("/") || dir.endsWith("\\"))
        dir.remove(dir.size()-1,1);

    //Propose a new name
    int cnt = 1;
    QString newDir;
    do {
        newDir = dir + QString("_%1").arg(cnt);
        cnt++;
    }
    while ( ! checkFileName(newDir) );

    ui->filename->setText(newDir);
    //ui->filename->setCursorPosition(newDir.size());
    ui->filename->setFocus();

    //Filename check
    CONNECT( ui->filename, SIGNAL(textChanged(QString)), this, SLOT(checkFileName(QString)));
}
Exemplo n.º 2
0
/* Err... well, the pretty obvious sfscreate entry point
 *
 * return       : 1 on argument missing - 0 on success
 * variables    : A diskimage
 */
int main(int argc, char ** argv) {
    superblock   spb;
    bitmap       bpm;   // bitmap = 1 block
    file_entries fes;   // file entries  = 16 block
    file_entry   fie;   // temporary file entry
    file_content fic;   // file content  = 1000 block

    // You shall not pass alone !
    if (argc == 2 && (strcmp(argv[1], "-h") == 0 ||
                     (strcmp(argv[1], "--help") == 0))) {
        printf(HELP);
        printf(USAGE);
        return 1;
    } else if (argc != 2){
        printf(USAGE);
        return 1;
    }

    /* Checking filename */
    char * filename = checkFileName(argv[1]);

    // Initializing superblock
    createSuperBlock(&spb);

    // Initializing bitmap
    createBMP(&bpm);

    // Initializing file entries
    createFileEntries(&fes, &fie);

    // Initializing file content
    createFileContent(&fic);

    // Creating diskimage and writing down to it previously created elements
    printf(CREATEDISKIMG);
    FILE *fh = fopen (filename, "wb"); // w is write, b is ISO C compliance...
    if (fh != NULL) {
        fwrite (&spb, sizeof (superblock), 1, fh);
        fwrite (&bpm, sizeof (int8_t), BLOCK, fh);
        fwrite (&fes, sizeof (int8_t), 16*BLOCK, fh);
        fwrite (&fic, sizeof (int8_t), Max_block_file*BLOCK, fh);
        fclose (fh);
    }
    free(filename);
    return 0;
}
Exemplo n.º 3
0
SourceFile::SourceFile( const QString &fn, bool temp, Project *p )
    : filename( fn ), ed( 0 ), fileNameTemp( temp ),
      timeStamp( 0, p->makeAbsolute( fn ) ), pro( p ), pkg( FALSE )
      , accepted( TRUE )
{
    iface = 0;
    
    if ( !temp )
	accepted = checkFileName( TRUE );
    
    if (accepted) {
	load();
	pro->addSourceFile( this );
	MetaDataBase::addEntry( this );
    }
    
}
Exemplo n.º 4
0
/**
 * Save the key data in a JSON like format. The filename is specified in
 * constructor YubikoOtpKeyConfig::YubikoOtpKeyConfig(const string& )
 */
void YubikoOtpKeyConfig::save() {
	BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyConfig::save");
	const string myOutFile = checkFileName(true);
	ptree myTree;
	myTree.put(K_NM_DOC_PRIV_ID /*--->*/, getPrivateId());
	myTree.put(K_NM_DOC_PUB_ID /*---->*/, getPublicId());
	myTree.put(K_NM_DOC_SEC_KEY /*--->*/, getSecretKey());
	myTree.put(K_NM_DOC_TIMESTAMP /*->*/, getTimestamp().tstp_int);
	myTree.put(K_NM_DOC_SES_CNTR /*-->*/, getCounter());
	myTree.put(K_NM_DOC_CRC /*------->*/, getCrc());
	myTree.put(K_NM_DOC_RANDOM /*---->*/, getRandom());
	myTree.put(K_NM_DOC_USE_CNTR /*-->*/, getUseCounter());
	myTree.put(K_NM_DOC_DESC /*------>*/, getDescription());
	myTree.put(K_NM_DOC_SYS_USER /*-->*/, getSysUser());
	myTree.put(K_NM_DOC_VERS /*------>*/, K_VL_VERS);
	write_json(myOutFile, myTree);
	itsChangedFlag = false;
}
Exemplo n.º 5
0
void YubikoOtpKeyConfig::load() {
	BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyConfig::load");
	const string myInFile = checkFileName(false);
	ptree myTree;
	read_json(myInFile, myTree);
	const string myVer(myTree.get<string>(K_NM_DOC_VERS));
	BOOST_LOG_TRIVIAL(info)<< K_NM_VERS << ":" << myVer;
	setPrivateId(myTree.get<string>(K_NM_DOC_PRIV_ID));
	setPublicId(myTree.get<string>(K_NM_DOC_PUB_ID));
	setSecretKey(myTree.get<string>(K_NM_DOC_SEC_KEY));
	setTimestamp(UTimestamp(myTree.get<uint64_t>(K_NM_DOC_TIMESTAMP)));
	setCounter(myTree.get<uint8_t>(K_NM_DOC_SES_CNTR));
	setCrc(myTree.get<uint16_t>(K_NM_DOC_CRC));
	setRandom(myTree.get<uint16_t>(K_NM_DOC_RANDOM));
	setUseCounter(myTree.get<uint8_t>(K_NM_DOC_USE_CNTR));
	setDescription(myTree.get<string>(K_NM_DOC_DESC));
	if (myVer != "0.0.1") {
		const string mySysUser { myTree.get<string>(K_NM_DOC_SYS_USER) };
		if (!mySysUser.empty())
			setSysUser(mySysUser);
	}
	itsChangedFlag = false;
}
Exemplo n.º 6
0
bool SourceFile::saveAs( bool ignoreModified )
{
    LanguageInterface *iface = MetaDataBase::languageInterface( pro->language() );
    QString filter;
    if ( iface )
	filter = iface->fileFilterList().join(";;");

    QString old = filename;
    QString initFn = pro->makeAbsolute( filename );
    if ( ignoreModified ) {
	QString dir = QStringList::split( ':', project()->iFace()->customSetting( "QTSCRIPT_PACKAGES" ) ).first();
	initFn = QFileInfo( initFn ).fileName();
	initFn.prepend( dir + "/" );
    }
    QString fn = QFileDialog::getSaveFileName( initFn, filter );
    if ( fn.isEmpty() )
	return FALSE;
    fileNameTemp = FALSE;
    filename = pro->makeRelative( fn );
    if ( !checkFileName( TRUE ) ) {
	filename = old;
	return FALSE;
    }
    pro->setModified( TRUE );
    timeStamp.setFileName( pro->makeAbsolute( filename ) );
    if ( ed )
	ed->setCaption( tr( "Edit %1" ).arg( filename ) );
    setModified( TRUE );
    if ( pro->isDummy() ) {
	QObject *o = ed->parent();
	while ( o && !o->isA( "MainWindow" ) )
	    o = o->parent();
	if ( o )
	    ((MainWindow *)o)->addRecentlyOpenedFile( fn );
    }
    return save( ignoreModified );
}
Exemplo n.º 7
0
int main(int argc, const char* argv[]) 
{ 
    try {
        Timer timer;
        
        const char* symbolFileName = "./symbols.xmap";
        const char* rulesFileName    = "./rules.xml";
        const char* inOsmFileName    = "./in.osm";
        const char* outXmapFileName  = "./out.xmap";

        if (argc > 1) {
            for (int i = 1; i < argc; ++i) {
                if (std::string(argv[i]) == "-i") {
                    inOsmFileName = argv[++i];
                    checkFileName(inOsmFileName,argv[0]);
                }
                else if (std::string(argv[i]) == "-o") {
                    outXmapFileName = argv[++i];
                    checkFileName(outXmapFileName,argv[0]);
                }
                else if (std::string(argv[i]) == "-s") {
                    symbolFileName = argv[++i];
                    checkFileName(symbolFileName,argv[0]);
                }
                else if (std::string(argv[i]) == "-r") {
                    rulesFileName = argv[++i];
                    checkFileName(rulesFileName,argv[0]);
                }
                else if (std::string(argv[i]) == "--help" ||
                         std::string(argv[i]) == "-h" ||
                         std::string(argv[i]) == "help") {
                    printUsage(argv[0]);
                    return 0;
                }
                else {
                    printUsage(argv[0]);
                    throw Error("Unknown option '" + std::string(argv[i]) + "'");
                }
            }
        }

        info("Using files:");
        info("\t* input OSM file       - " + std::string(inOsmFileName));
        info("\t* output XMAP file     - " + std::string(outXmapFileName));
        info("\t* symbol set XMAP file - " + std::string(symbolFileName));
        info("\t* rules file           - " + std::string(rulesFileName));

        XmlTree inXmapDoc(symbolFileName);
        XmlElement inXmapRoot = inXmapDoc.getChild("map");

        XmlTree inOsmDoc(inOsmFileName);
        XmlElement inOsmRoot = inOsmDoc.getChild("osm");

        const double min_supported_version = 0.5;
        const double max_supported_version = 0.6;

        double version = inOsmRoot.getAttribute<double>("version");
        if (version < min_supported_version || version > max_supported_version) {
            throw Error("OSM data version %.1f isn't supported" + std::to_string(version));
        }

        XmlElement bounds = inOsmRoot.getChild("bounds");
        if (bounds.isEmpty()) {
            throw Error("No bounds");
        }
        double x = bounds.getAttribute<double>("minlon") +
                   bounds.getAttribute<double>("maxlon");
        x /= 2;
        double y = bounds.getAttribute<double>("minlat") +
                   bounds.getAttribute<double>("maxlat");
        y /= 2;
        Coords geographic_ref_point(x,y);

        Georeferencing georef(inXmapRoot, geographic_ref_point);

        Main::transform = CoordsTransform(georef);
        SymbolIdByCodeMap symbolIds(inXmapRoot);
        Main::rules = Rules(rulesFileName,symbolIds);

        osmToXmap(inOsmRoot,outXmapFileName,symbolFileName,georef);

        info("\nExecution time: " + std::to_string(timer.getCurTime()) + " sec.");
    }
    /*
    catch (const char * msg) {
        std::cerr << "ERROR: " << msg << std::endl;
    }
    */
    catch (std::exception& error) {
        std::cerr << "ERROR: " << error.what() << std::endl;
        return 1;
    }
}
Exemplo n.º 8
0
int main(int argc,char *argv[])
{
	system("clear");
	printf("\n\t\t\t\t\t\tSERVER\n");
	
	int connfd,sockfd,clen,n,n1,pid,writefd;
	char serverString[50],clientString[50],filename[20];
	
	struct sockaddr_in servaddr,cliaddr;
	bzero(&servaddr,sizeof(servaddr));
	bzero(&cliaddr,sizeof(cliaddr));
	
	sockfd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
	
	if(sockfd < 0)
	{
		printf("\n\tSocket Error\n");
		perror("socket");
		exit(1);
	}
	
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(8889);
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	
	if(bind(sockfd,(struct sockaddr *)&servaddr,sizeof(servaddr)) < 0)
	{
		printf("\n\tSocket Error\n");
		perror("bind");
		exit(1);
	}
	
	if(listen(sockfd,3) < 0)
	{
		printf("\n\tListen Error\n");
		perror("listen");
		exit(1);
	}
	
	while(1)
	{
		clen = sizeof(cliaddr);
		connfd = accept(sockfd,(struct sockaddr *)&cliaddr,&clen);
		if(connfd < 0)
		{
			printf("\n\tAccept Error\n");
			perror("Accept");
			exit(1);
		}
		
		if((pid = fork()) == 0)
		{
		
			close(sockfd);
			
			again : if((n = read(connfd,serverString,sizeof(serverString)) )> 0)
			//serverString[n] = '\0';
			if((n < 0) && (errno == EINTR))
			{
				goto again;
			}
			if(n < 0)
			{
				printf("\n\tRead Error\n");
				perror("read");
				exit(1);
			}
			
			printf("\n\tServerString : %s\n",serverString);
	
			strcpy(filename,serverString);
			checkFileName(filename);
		
			printf("\n\tFilename : %s\n",filename);
			bzero(serverString,sizeof(serverString));
//			printf("\n\tFilename : %s\n",filename);
	
			if(createFile(serverString) != 1)
			{
				printf("\n\tCould not create file\n");
				exit(1);
			}
			else
			{
				while(read(sockfd,serverString,sizeof(serverString)) != 0)
				{
					FILE *fp;
					fp = fopen("read_text.c","rb+");
					if(fp == NULL)
					{
						printf("\n\tError in writting the file\n");
						exit(1);
					}
					
					if((writefd = fwrite(serverString,sizeof(serverString),1,fp)) == 0)
					{
						printf("\n\tWritting error into file\n");
						//error code
						exit(1);
					}
					fclose(fp);
				}
			}
		}
		close(connfd);
	}
}