Ejemplo n.º 1
0
Archivo: ch.c Proyecto: PDXostc/navit
void
ch_generate_tiles(char *map_suffix, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info)
{
	struct tile_info info;
	FILE *in,*ref,*ddsg_coords,*ddsg;
	FILE **graphfiles;
        info.write=0;
        info.maxlen=0;
        info.suffix=suffix;
        info.tiles_list=NULL;
        info.tilesdir_out=tilesdir_out;
	graphfiles=g_alloca(sizeof(FILE*)*(ch_levels+1));

	ch_create_tempfiles(suffix, graphfiles, ch_levels, 1);
	in=tempfile(map_suffix,"ways_split",0);
	ref=tempfile(map_suffix,"ways_split_ref",0);
	ddsg_coords=tempfile(suffix,"ddsg_coords",1);
	ddsg=tempfile(suffix,"ddsg",1);
	ch_generate_ddsg(in, ref, ddsg_coords, ddsg);
	fclose(in);
	fclose(ref);
	fclose(ddsg_coords);
	fclose(ddsg);
	ch_generate_sgr(suffix);
	ch_setup(suffix);
	ch_process(graphfiles, ch_levels, 0);
	ch_close_tempfiles(graphfiles, ch_levels);

	tile_hash=g_hash_table_new(g_str_hash, g_str_equal);
	ch_copy_to_tiles(suffix, ch_levels, &info, NULL);
	merge_tiles(&info);

	write_tilesdir(&info, zip_info, tilesdir_out);
}
Ejemplo n.º 2
0
void processFileArgument(char* name) {
    if (!table.lookup(name)) {
        fprintf(stderr, "File %s is not present in baseline.\n", name);
        return;
    }

    File localfile(name);
    if (localfile.exists()) {
        processFile(name);
    } else {
        if (forced_revision()) {
            File tempfile("forced_mergefile.tmp");
            File rcsfile(dirs.baseline, dirs.subdir->path, "RCS",
                         localfile.path);
            char line[LINE_LENGTH];
            char* version = forced_revision_number ? forced_revision_number :
                            rcsfile.getRevisionFromDate(forced_revision_date);
            sprintf(line, "co -q -p%s %s,v > %s",
                    version, rcsfile.path, tempfile.path);
            if (execute(line)) {
                tempfile.un_link();
                exit(-1);
            }
            localfile.become(tempfile, save);
            tempfile.un_link();
        } else {
            File basefile(dirs.baseline, dirs.subdir->path, localfile.path);
            localfile.become(basefile, save);
        }
    }
}
Ejemplo n.º 3
0
TEST(DISABLED_ML_SVM, linear_save_load)
{
    Ptr<cv::ml::SVM> svm1, svm2, svm3;

    svm1 = Algorithm::load<SVM>("SVM45_X_38-1.xml");
    svm2 = Algorithm::load<SVM>("SVM45_X_38-2.xml");
    string tname = tempfile("a.json");
    svm2->save(tname + "?base64");
    svm3 = Algorithm::load<SVM>(tname);

    ASSERT_EQ(svm1->getVarCount(), svm2->getVarCount());
    ASSERT_EQ(svm1->getVarCount(), svm3->getVarCount());

    int m = 10000, n = svm1->getVarCount();
    Mat samples(m, n, CV_32F), r1, r2, r3;
    randu(samples, 0., 1.);

    svm1->predict(samples, r1);
    svm2->predict(samples, r2);
    svm3->predict(samples, r3);

    double eps = 1e-4;
    EXPECT_LE(cvtest::norm(r1, r2, NORM_INF), eps);
    EXPECT_LE(cvtest::norm(r1, r3, NORM_INF), eps);

    remove(tname.c_str());
}
Ejemplo n.º 4
0
void Tree::deleteclass() {

	Gtk::TreeModel::iterator iter = get_selection()->get_selected();
	if( *iter ) {
	
		Glib::ustring str = (*iter)[m_Columns.m_col_crn];
		std::ifstream coursefile( course_file );
		std::ofstream tempfile( course_temp );
		if( coursefile.is_open() && tempfile.is_open() ) {
			while( true ) {
				char buf[10], line[256];
				coursefile >> buf; // Get crn
				coursefile.getline( line, 255 ); // Get rest of line
				if( coursefile.eof() ) break;
				if( str.compare( buf ) == 0 ) // Skip if crns are equal
					continue;
				tempfile << buf << line << std::endl; // Write to temp
			}
			coursefile.close();
			tempfile.close();
			std::remove( course_file ); // Remove and rename file
			std::rename( course_temp, course_file );
		}
		m_refTreeModel->erase( iter ); // Erase from tree
	}
}
Ejemplo n.º 5
0
static int fixup(int fd)
{
  int pid;
  int status;
  int newfd;
  if (fixup_argv != 0) {
    if (lseek(fd, 0, SEEK_SET) != 0)
      respond("ZCould not seek in temporary file");
    if ((newfd = tempfile("tmp/spool")) == -1)
      respond("ZCould not create temporary file");
    if ((pid = fork()) == -1)
      respond("ZCould not fork fixup program");
    if (pid == 0) {
      dup2(fd, 0);
      close(fd);
      dup2(newfd, 1);
      close(newfd);
      execvp(fixup_argv[0], fixup_argv);
      die3sys(111, "Could not exec '", fixup_argv[0], "'");
    }
    if (waitpid(pid, &status, 0) != pid)
      respond("ZWaitpid failed");
    if (status != 0)
      respond("ZFilter failed");
    fd = newfd;
  }
  return fd;
}
void FileList::scan( const char * pattern )
{
    files.clear();
    WIN32_FIND_DATAA FindFileData;
    HANDLE hFind;
    DirPath loc = folder;
    loc << pattern;
    std::string base = folder.c_str();
    std::string filename;
    hFind = FindFirstFileA( loc.c_str(), &FindFileData );

    /*int i = 0;*/
    while( hFind != INVALID_HANDLE_VALUE )
    {
        filename = FindFileData.cFileName;
        FileListEntry tempfile( base, filename );
        files.push_back( tempfile );

        if( FindNextFileA( hFind, &FindFileData ) == 0 )
        {
            break;
        }
    }

    FindClose( hFind );
}
Ejemplo n.º 7
0
void BundleManager::OnRemoteAction(cxRemoteAction& event) {
	if (!event.Succeded()) return;
	if (!event.GetTarget() == m_tempFile) return;

	// Get the description
	wxFFile tempfile(m_tempFile, wxT("rb"));
	TiXmlDocument doc;
	if (!tempfile.IsOpened() || !doc.LoadFile(tempfile.fp())) return;
	TiXmlHandle docHandle( &doc );
	const TiXmlElement* child = docHandle.FirstChildElement("plist").FirstChildElement("dict").FirstChildElement().Element();
	while (child) {
		if (strcmp(child->Value(), "key") != 0) return; // invalid dict
		const TiXmlElement* const value = child->NextSiblingElement();
		if (!value) return; // invalid dict

		if (strcmp(child->GetText(), "description") == 0) {
			const char* desc = value->GetText(); // Get value
			if (desc) {
#ifdef __WXMSW__
				const wxString descStr(desc, wxConvUTF8);
				m_browser->LoadString(descStr);
#endif
			}

			return;
		}
		child = value->NextSiblingElement(); // advance past value
	}
}
Ejemplo n.º 8
0
/*!
 * Copy a temporary file to the real file and delete the temporary file
 * \param path is the path to the files
 * \param fileName is the real file name, which does not include the temporary prefix
 */
void ProtocolFile::copyTemporaryFile(const QString& path, const QString& fileName)
{
    bool equal = false;
    QString tempFileName = path + tempprefix + fileName;
    QString permFileName = path + fileName;

    QFile tempfile(tempFileName);
    QFile permfile(permFileName);

    // Its possible we already copied and deleted the file, so this isn't an error
    if(!tempfile.open(QIODevice::ReadOnly | QIODevice::Text))
        return;

    // Check if the files are the same
    if(permfile.open(QIODevice::ReadOnly | QIODevice::Text))
        equal = tempfile.readAll() == permfile.readAll();

    // Done with the file contents
    tempfile.close();
    permfile.close();

    if(equal)
    {
        // If the two file contents are the same, delete the temporary
        // file, leave the original file unchanged
        deleteFile(tempFileName);
    }
    else
    {
        // else if the file contents are different, delete the original
        // file and rename the temp file to be the original file
        renameFile(tempFileName, permFileName);
    }

}// ProtocolFile::copyTemporaryFile
Ejemplo n.º 9
0
// Start a new plot
void PlotAgent::start_plot(const string& title, int n)
{
    if (need_reset)
	reset();

    titles += title;
    values += "";
    dims   += 0;

    ndim = n;

    while (files.size() < titles.size())
    {
	// Open a new temporary file
	files += tempfile();
    }

    // Open plot stream
    plot_os.open(files[titles.size() - 1].chars());

    // Issue initial line
    plot_os << "# " DDD_NAME ": " << title << "\n"
	    << "# Use `set parametric' and `"
	    << (ndim <= 2 ? "plot" : "splot")
	    << "' to plot this data.\n"
	    << "# " 
	    << (ndim <= 2 ? "X\tVALUE" : "X\tY\tVALUE")
	    << "\n";
}
Ejemplo n.º 10
0
void avi_write::begin_avi_recording(const char *name)
{
	// stop any existing recording
	end_avi_recording();

	// reset the state
	m_frame = 0;
	m_next_frame_time = m_machine.time();

	const screen_device *primary_screen = screen_device_iterator(m_machine.root_device()).first();
	// build up information about this new movie
	avi_file::movie_info info;
	info.video_format = 0;
	info.video_timescale = 1000 * (primary_screen ? ATTOSECONDS_TO_HZ(primary_screen->frame_period().m_attoseconds) : screen_device::DEFAULT_FRAME_RATE);
	info.video_sampletime = 1000;
	info.video_numsamples = 0;
	info.video_width = m_width;
	info.video_height = m_height;
	info.video_depth = 24;

	info.audio_format = 0;
	info.audio_timescale = m_machine.sample_rate();
	info.audio_sampletime = 1;
	info.audio_numsamples = 0;
	info.audio_channels = 2;
	info.audio_samplebits = 16;
	info.audio_samplerate = m_machine.sample_rate();

	// compute the frame time
	m_frame_period = attotime::from_seconds(1000) / info.video_timescale;

	// create a new temporary movie file
	emu_file tempfile(m_machine.options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
	const osd_file::error filerr = (!name || !name[0] || !std::strcmp(name, OSDOPTVAL_AUTO))
			? m_machine.video().open_next(tempfile, "avi")
			: tempfile.open(name);

	// if we succeeded, make a copy of the name and create the real file over top
	if (filerr == osd_file::error::NONE)
	{
		const std::string fullpath = tempfile.fullpath();
		tempfile.close();

		// create the file and free the string
		avi_file::error avierr = avi_file::create(fullpath, info, m_output_file);
		if (avierr != avi_file::error::NONE)
		{
			osd_printf_error("Error creating AVI: %s\n", avi_file::error_string(avierr));
		}
		else
		{
			m_recording = true;
		}
	}
}
Ejemplo n.º 11
0
Archivo: ch.c Proyecto: PDXostc/navit
static void
ch_create_tempfiles(char *suffix, FILE **files, int count, int mode)
{	
	char name[256];
	int i;

	for (i = 0 ; i <= count ; i++) {
		sprintf(name,"graph_%d",i);
		files[i]=tempfile(suffix, name, mode);
	}
}
Ejemplo n.º 12
0
Disk*
diskinit()
{
	Disk *d;

	d = emalloc(sizeof(Disk));
	d->fd = tempfile();
	if(d->fd < 0){
		fprint(2, "acme: can't create temp file: %r\n");
		threadexitsall("diskinit");
	}
	return d;
}
Ejemplo n.º 13
0
bool imencode( const String& ext, InputArray _image,
               std::vector<uchar>& buf, const std::vector<int>& params )
{
    CV_TRACE_FUNCTION();

    Mat image = _image.getMat();

    int channels = image.channels();
    CV_Assert( channels == 1 || channels == 3 || channels == 4 );

    ImageEncoder encoder = findEncoder( ext );
    if( !encoder )
        CV_Error( CV_StsError, "could not find encoder for the specified extension" );

    if( !encoder->isFormatSupported(image.depth()) )
    {
        CV_Assert( encoder->isFormatSupported(CV_8U) );
        Mat temp;
        image.convertTo(temp, CV_8U);
        image = temp;
    }

    bool code;
    if( encoder->setDestination(buf) )
    {
        code = encoder->write(image, params);
        encoder->throwOnEror();
        CV_Assert( code );
    }
    else
    {
        String filename = tempfile();
        code = encoder->setDestination(filename);
        CV_Assert( code );

        code = encoder->write(image, params);
        encoder->throwOnEror();
        CV_Assert( code );

        FILE* f = fopen( filename.c_str(), "rb" );
        CV_Assert(f != 0);
        fseek( f, 0, SEEK_END );
        long pos = ftell(f);
        buf.resize((size_t)pos);
        fseek( f, 0, SEEK_SET );
        buf.resize(fread( &buf[0], 1, buf.size(), f ));
        fclose(f);
        remove(filename.c_str());
    }
    return code;
}
Ejemplo n.º 14
0
string const LyXVC::getLogFile() const
{
	if (!vcs)
		return string();

	TempFile tempfile("lyxvclog");
	tempfile.setAutoRemove(false);
	FileName const tmpf = tempfile.name();
	if (tmpf.empty()) {
		LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
		return string();
	}
	LYXERR(Debug::LYXVC, "Generating logfile " << tmpf);
	vcs->getLog(tmpf);
	return tmpf.absFileName();
}
Ejemplo n.º 15
0
Archivo: ch.c Proyecto: PDXostc/navit
static void
ch_copy_to_tiles(char *suffix, int count, struct tile_info *info, FILE *ref)
{
	char name[256];
	int i;
	FILE *f;
	struct item_bin *item_bin;

	for (i = count ; i >= 0 ; i--) {
		sprintf(name,"graph_%d",i);
		f=tempfile(suffix, name, 0);
		while ((item_bin = read_item(f))) {
			tile_write_item_minmax(info, item_bin, ref, i, i);
		}
		fclose(f);
	}
}
Ejemplo n.º 16
0
QgsAuthOAuth2Method::~QgsAuthOAuth2Method()
{
  QDir tempdir( QgsAuthOAuth2Config::tokenCacheDirectory( true ) );
  const QStringList dirlist = tempdir.entryList( QDir::Files | QDir::NoDotAndDotDot );
  for ( const QString &f : dirlist )
  {
    QString tempfile( tempdir.path() + '/' + f );
    if ( !QFile::remove( tempfile ) )
    {
      QgsDebugMsg( QStringLiteral( "FAILED to delete temp token cache file: %1" ).arg( tempfile ) );
    }
  }
  if ( !tempdir.rmdir( tempdir.path() ) )
  {
    QgsDebugMsg( QStringLiteral( "FAILED to delete temp token cache directory: %1" ).arg( tempdir.path() ) );
  }
}
Ejemplo n.º 17
0
static void cmd_store(str* data)
{
  int i;
  int fd;
  if ((i = str_findfirst(data, 0)) <= 0)
    respond("DStore command is missing data");
  ++i;
  if ((fd = tempfile("tmp/spool")) == -1)
    respond("ZCould not create temporary file");
  if (write(fd, data->s + i, data->len - i) != (long)(data->len - i)
      || (fd = fixup(fd)) == -1
      || fchmod(fd, 0400) == -1
      || close(fd) != 0)
    respond("ZCould not write temporary file");
  if (rename(tempname.s, filename.s) != 0)
    respond("ZCould not rename temporary file");
  trigger_pull(TRIGGER);
  respond("KCrontab successfully written");
}
Ejemplo n.º 18
0
bool QFontDatabase::removeApplicationFont(int handle)
{
    QMutexLocker locker(fontDatabaseMutex());

    QFontDatabasePrivate *db = privateDb();
    if (handle < 0 || handle >= db->applicationFonts.count())
        return false;

    const QFontDatabasePrivate::ApplicationFont font = db->applicationFonts.at(handle);
    db->applicationFonts[handle] = QFontDatabasePrivate::ApplicationFont();
    if (font.memoryFont) {
#ifdef Q_OS_WINCE
        bool removeSucceeded = RemoveFontResource((LPCWSTR)font.fileName.utf16());
        QFile tempfile(font.fileName);
        tempfile.remove();
        if (!removeSucceeded)
            return false;
#else
        PtrRemoveFontMemResourceEx ptrRemoveFontMemResourceEx = (PtrRemoveFontMemResourceEx)QSystemLibrary::resolve(QLatin1String("gdi32"),
                                                                                                              "RemoveFontMemResourceEx");
        if (!ptrRemoveFontMemResourceEx
            || !ptrRemoveFontMemResourceEx(font.handle))
            return false;
#endif // Q_OS_WINCE
    } else {
#ifdef Q_OS_WINCE
        if (!RemoveFontResource((LPCWSTR)font.fileName.utf16()))
            return false;
#else
        PtrRemoveFontResourceExW ptrRemoveFontResourceExW = (PtrRemoveFontResourceExW)QSystemLibrary::resolve(QLatin1String("gdi32"),
                                                                                                        "RemoveFontResourceExW");
        if (!ptrRemoveFontResourceExW
            || !ptrRemoveFontResourceExW((LPCWSTR)font.fileName.utf16(), FR_PRIVATE, 0))
            return false;
#endif // Q_OS_WINCE
    }

    db->invalidate();
    return true;
}
Ejemplo n.º 19
0
void RetroArchTools::on_m3ugenbutton_clicked()
{
    m3udata_current.outpath = ui->m3u_outbox->text();
    m3udata_current.name = ui->dir2m3u_name->text();
    if (!inputExists(m3udata_current.name))
    {
        QMessageBox::warning(this,tr("Error!"),tr("Please input the name of the multi-disk game."));
        return;
    }
    if (!inputExists(m3udata_current.outpath))
    {
        QMessageBox::warning(this,tr("Error!"),tr("Please input the output path for the m3u."));
        return;
    }
    if (!fileExists(m3udata_current.outpath) || isFile(m3udata_current.outpath))
    {
        QMessageBox::warning(this,tr("Error!"),tr("Cannot find output directory!"));
        return;
    }
    QString m3ufile = QDir(m3udata_current.outpath).filePath(m3udata_current.name + ".m3u");
    QFile m3u2(m3ufile);
    if (m3u2.open(QFile::WriteOnly | QFile::Truncate))
    {
        QTextStream m3u2_out(&m3u2);
        for(int row = 0; row < ui->m3u_listbox->count(); row++)
        {
            QFileInfo tempfile(ui->m3u_listbox->item(row)->text());
            m3u2_out << tempfile.fileName() + "\n";
        }
        m3u2.close();
    }
    else
    {
        QMessageBox::warning(this,tr("Error!"),tr("Error writing to m3u (check the file isn't being used somewhere)"));
        return;
    }
    QMessageBox::information(this,tr("Finished!"),"m3u file created at " + m3ufile);
}
Ejemplo n.º 20
0
void video_manager::begin_recording(const char *name, movie_format format)
{
	// stop any existign recording
	end_recording();

	// create a snapshot bitmap so we know what the target size is
	create_snapshot_bitmap(NULL);

	// reset the state
	m_movie_frame = 0;
	m_movie_next_frame_time = machine().time();

	// start up an AVI recording
	if (format == MF_AVI)
	{
		// build up information about this new movie
		avi_movie_info info;
		info.video_format = 0;
		info.video_timescale = 1000 * ((machine().primary_screen != NULL) ? ATTOSECONDS_TO_HZ(machine().primary_screen->frame_period().attoseconds) : screen_device::DEFAULT_FRAME_RATE);
		info.video_sampletime = 1000;
		info.video_numsamples = 0;
		info.video_width = m_snap_bitmap.width();
		info.video_height = m_snap_bitmap.height();
		info.video_depth = 24;

		info.audio_format = 0;
		info.audio_timescale = machine().sample_rate();
		info.audio_sampletime = 1;
		info.audio_numsamples = 0;
		info.audio_channels = 2;
		info.audio_samplebits = 16;
		info.audio_samplerate = machine().sample_rate();

		// create a new temporary movie file
		file_error filerr;
		astring fullpath;
		{
			emu_file tempfile(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
			if (name != NULL)
				filerr = tempfile.open(name);
			else
				filerr = open_next(tempfile, "avi");

			// compute the frame time
			m_movie_frame_period = attotime::from_seconds(1000) / info.video_timescale;

			// if we succeeded, make a copy of the name and create the real file over top
			if (filerr == FILERR_NONE)
				fullpath = tempfile.fullpath();
		}

		if (filerr == FILERR_NONE)
		{
			// create the file and free the string
			avi_error avierr = avi_create(fullpath, &info, &m_avifile);
			if (avierr != AVIERR_NONE)
				mame_printf_error("Error creating AVI: %s\n", avi_error_string(avierr));
		}
	}

	// start up a MNG recording
	else if (format == MF_MNG)
	{
		// create a new movie file and start recording
		m_mngfile = auto_alloc(machine(), emu_file(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS));
		file_error filerr;
		if (name != NULL)
			filerr = m_mngfile->open(name);
		else
			filerr = open_next(*m_mngfile, "mng");

		if (filerr == FILERR_NONE)
		{
			// start the capture
			int rate = (machine().primary_screen != NULL) ? ATTOSECONDS_TO_HZ(machine().primary_screen->frame_period().attoseconds) : screen_device::DEFAULT_FRAME_RATE;
			png_error pngerr = mng_capture_start(*m_mngfile, m_snap_bitmap, rate);
			if (pngerr != PNGERR_NONE)
				return end_recording();

			// compute the frame time
			m_movie_frame_period = attotime::from_hz(rate);
		}
		else
		{
			mame_printf_error("Error creating MNG\n");
			global_free(m_mngfile);
			m_mngfile = NULL;
		}
	}
}
Ejemplo n.º 21
0
Archivo: ch.c Proyecto: PDXostc/navit
void
ch_assemble_map(char *map_suffix, char *suffix, struct zip_info *zip_info)
{
	struct tile_info info;
	struct tile_head *th;
	FILE **graphfiles=g_alloca(sizeof(FILE*)*(ch_levels+1));
	FILE *ref;
	struct item_id id;
	int nodeid=0;

        info.write=1;
        info.maxlen=zip_get_maxnamelen(zip_info);
        info.suffix=suffix;
        info.tiles_list=NULL;
        info.tilesdir_out=NULL;
	ref=tempfile(suffix,"sgr_ref",1);

	create_tile_hash();

	th=tile_head_root;
        while (th) {
		th->zip_data=NULL;
		th->process=1;
                th=th->next;
        }

	ch_setup(suffix);
	ch_copy_to_tiles(suffix, ch_levels, &info, ref);
	fclose(ref);
	ref=tempfile(suffix,"sgr_ref",0);
	sgr_nodes_hash=g_hash_table_new_full(NULL, NULL, NULL, item_id_slice_free);
	while (fread(&id, sizeof(id), 1, ref)) {
		struct item_id *id2=g_slice_new(struct item_id);
		*id2=id;
#if 0
		dbg(lvl_debug,"%d is "ITEM_ID_FMT"\n",nodeid,ITEM_ID_ARGS(*id2));
#endif
		g_hash_table_insert(sgr_nodes_hash, GINT_TO_POINTER(nodeid), id2);
		nodeid++;
	}
	th=tile_head_root;
        while (th) {
		th->zip_data=malloc(th->total_size);
		th->total_size_used=0;
                th=th->next;
        }
	ch_create_tempfiles(suffix, graphfiles, ch_levels, 1);
	ch_process(graphfiles, ch_levels, 1);
	ch_close_tempfiles(graphfiles, ch_levels);

	g_hash_table_destroy(newnode_hash);
	g_hash_table_destroy(edge_hash);
	g_hash_table_destroy(sgr_nodes_hash);

	ch_copy_to_tiles(suffix, ch_levels, &info, NULL);
	write_tilesdir(&info, zip_info, NULL);

	th=tile_head_root;
        while (th) {
		if (th->name[0]) {
			if (th->total_size != th->total_size_used) {
				fprintf(stderr,"Size error '%s': %d vs %d\n", th->name, th->total_size, th->total_size_used);
				exit(1);
			}
			write_zipmember(zip_info, th->name, zip_get_maxnamelen(zip_info), th->zip_data, th->total_size);
		} else {
			fwrite(th->zip_data, th->total_size, 1, zip_get_index(zip_info));
		}
		g_free(th->zip_data);
                th=th->next;
        }
}
Ejemplo n.º 22
0
void video_manager::begin_recording(const char *name, movie_format format)
{
	// create a snapshot bitmap so we know what the target size is
	create_snapshot_bitmap(nullptr);

	// start up an AVI recording
	if (format == MF_AVI)
	{
		// stop any existing recording
		end_recording(format);

		// reset the state
		m_avi_frame = 0;
		m_avi_next_frame_time = machine().time();

		// build up information about this new movie
		screen_device *screen = machine().first_screen();
		avi_file::movie_info info;
		info.video_format = 0;
		info.video_timescale = 1000 * ((screen != nullptr) ? ATTOSECONDS_TO_HZ(screen->frame_period().attoseconds()) : screen_device::DEFAULT_FRAME_RATE);
		info.video_sampletime = 1000;
		info.video_numsamples = 0;
		info.video_width = m_snap_bitmap.width();
		info.video_height = m_snap_bitmap.height();
		info.video_depth = 24;

		info.audio_format = 0;
		info.audio_timescale = machine().sample_rate();
		info.audio_sampletime = 1;
		info.audio_numsamples = 0;
		info.audio_channels = 2;
		info.audio_samplebits = 16;
		info.audio_samplerate = machine().sample_rate();

		// create a new temporary movie file
		osd_file::error filerr;
		std::string fullpath;
		{
			emu_file tempfile(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
			if (name != nullptr)
				filerr = tempfile.open(name);
			else
				filerr = open_next(tempfile, "avi");

			// if we succeeded, make a copy of the name and create the real file over top
			if (filerr == osd_file::error::NONE)
				fullpath = tempfile.fullpath();
		}

		if (filerr == osd_file::error::NONE)
		{
			// compute the frame time
			m_avi_frame_period = attotime::from_seconds(1000) / info.video_timescale;

			// create the file and free the string
			avi_file::error avierr = avi_file::create(fullpath, info, m_avi_file);
			if (avierr != avi_file::error::NONE)
			{
				osd_printf_error("Error creating AVI: %s\n", avi_file::error_string(avierr));
				return end_recording(format);
			}
		}
	}

	// start up a MNG recording
	else if (format == MF_MNG)
	{
		// stop any existing recording
		end_recording(format);

		// reset the state
		m_mng_frame = 0;
		m_mng_next_frame_time = machine().time();

		// create a new movie file and start recording
		m_mng_file = std::make_unique<emu_file>(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
		osd_file::error filerr;
		if (name != nullptr)
			filerr = m_mng_file->open(name);
		else
			filerr = open_next(*m_mng_file, "mng");

		if (filerr == osd_file::error::NONE)
		{
			// start the capture
			screen_device *screen = machine().first_screen();
			int rate = (screen != nullptr) ? ATTOSECONDS_TO_HZ(screen->frame_period().attoseconds()) : screen_device::DEFAULT_FRAME_RATE;
			png_error pngerr = mng_capture_start(*m_mng_file, m_snap_bitmap, rate);
			if (pngerr != PNGERR_NONE)
			{
				osd_printf_error("Error capturing MNG, png_error=%d\n", pngerr);
				return end_recording(format);
			}

			// compute the frame time
			m_mng_frame_period = attotime::from_hz(rate);
		}
		else
		{
			osd_printf_error("Error creating MNG, osd_file::error=%d\n", int(filerr));
			m_mng_file.reset();
		}
	}
}
Ejemplo n.º 23
0
static bool find_include_file(std::string &srcincpath, int srcrootlen, int dstrootlen, std::string &srcfile, std::string &dstfile, std::string &filename)
{
	// iterate over include paths and find the file
	for (include_path *curpath = incpaths; curpath != nullptr; curpath = curpath->next)
	{
		// a '.' include path is specially treated
		if (curpath->path.compare(".") == 0)
			srcincpath.assign(srcfile.substr(0, srcfile.find_last_of(PATH_SEPARATOR[0])));
		else
			srcincpath.assign(srcfile.substr(0, srcrootlen + 1)).append(curpath->path);

		// append the filename piecemeal to account for directories
		int lastsepindex = 0;
		int sepindex;
		while ((sepindex = filename.find_first_of('/', lastsepindex)) != -1)
		{
			// handle .. by removing a chunk from the incpath
			std::string pathpart(filename, lastsepindex, sepindex - lastsepindex);
			if (pathpart.compare("..")==0)
			{
				sepindex = srcincpath.find_last_of(PATH_SEPARATOR[0]);
				if (sepindex != -1)
					srcincpath.substr(0, sepindex);
			}

			// otherwise, append a path separator and the pathpart
			else
				srcincpath.append(PATH_SEPARATOR).append(pathpart);

			// advance past the previous index
			lastsepindex = sepindex + 1;
		}

		// now append the filename
		srcincpath.append(PATH_SEPARATOR).append(filename.substr(lastsepindex, -1));

		// see if we can open it
		util::core_file::ptr testfile;
		if (util::core_file::open(srcincpath, OPEN_FLAG_READ, testfile) == osd_file::error::NONE)
		{
			// close the file
			testfile.reset();

			// find the longest matching directory substring between the include and source file
			lastsepindex = 0;
			while ((sepindex = srcincpath.find_first_of(PATH_SEPARATOR[0], lastsepindex)) != -1)
			{
				// get substrings up to the current directory
				std::string tempfile(srcfile, 0, sepindex);
				std::string tempinc(srcincpath, 0, sepindex);

				// if we don't match, stop
				if (tempfile.compare(tempinc)!=0)
					break;
				lastsepindex = sepindex + 1;
			}

			// chop off the common parts of the paths
			std::string tempfile(srcfile, lastsepindex, -1);
			srcincpath = srcincpath.substr(lastsepindex, -1);
			strreplacechr(srcincpath, PATH_SEPARATOR[0], '/');

			// for each directory left in the filename, we need to prepend a "../"
			while ((sepindex = tempfile.find_first_of(PATH_SEPARATOR[0])) != -1)
			{
				tempfile.substr(sepindex + 1, -1);
				srcincpath.insert(0, "../");
			}
			srcincpath.append(".html");

			// free the strings and return the include path
			return true;
		}
	}
	return false;
}
Ejemplo n.º 24
0
int main(int argc, char *argv[]) {

  int numPoints = 1;

  double qMax = 0.;
  
  // Sets format of output: 4 decimal places
  outputCharacteristics(6);

  void (*boundaryCondition)(MssmSoftsusy &, const DoubleVector &);
  

  
  if (argc !=1 ) {
    cerr << "GAUGE/GRAVITY" << endl; 
    cerr << "SOFTSUSY" << VERSION << endl;
    cerr << "B.C. Allanach, Comput. Phys. Commun. 143 (2002) 305-331,";
    cerr << " hep-ph/0104145\n";
    cerr << "Low energy data in SOFTSUSY: MIXING=" << MIXING << " TOLERANCE=" 
	 << TOLERANCE << endl;
    cerr << "G_F=" << GMU << " GeV^2" << endl;
  }

  // RANDOM SEED /////////////////////
    time_t seconds;
    time( &seconds); 
    srand( (unsigned int) seconds ); 
  ////////////////////////////////////
  


  double mgutGuess = 2.0e16, mbmb = MBOTTOM, mtau = MTAU;
  int sgnMu = 1;
  bool gaugeUnification = false, ewsbBCscale = false, altEwsb = false;
  bool flag = false; 



  double M_moduli_start, M_moduli_end ;
  double M_gauge_start, M_gauge_end ; 
  double M_mess_start, M_mess_end ; 
  
  double M_moduli, M_gauge, M_mess ;
  
  double tanb_start, tanb_end ; 
  double tanb = 10; 
  DoubleVector pars(3); 
  // My modification 
 
 
  cout << "argc = " << argc << endl; 
  cout << flush ; 


  if(argc != 3 ) {
    errorCall() ;
    exit(-1) ;
  }
  /*   if (!strcmp(argv[1], "g-gmsb")) {
    cout << "SOFTSUSY Gauge/Gravity calculation" << endl;
    cout << flush;  */

  if( argc == 3 ) { 

    ifstream inputfile(argv[1]); 
    ofstream outputfile(argv[2]); 

    string varname; 
    
    inputfile >> varname >> l1 ; 

    cout << varname << endl; 

    inputfile >> varname >> l2 ; 
    inputfile >> varname >> l3 ; 

    inputfile >> varname >> nQ ; 
    inputfile >> varname >> nU ; 
    inputfile >> varname >> nD ; 
    inputfile >> varname >> nL ; 
    inputfile >> varname >> nE ;
 
    inputfile >> varname >> nHu ; 
    inputfile >> varname >> nHd ; 

    inputfile >> varname >> N ;
 
    inputfile >> varname >> numscan;
    inputfile >> varname >> M_moduli_start ; 
    inputfile >> varname >> M_moduli_end ; 
    inputfile >> varname >> M_gauge_start ; 
    inputfile >> varname >> M_gauge_end ; 
    inputfile >> varname >> M_mess_start   ; 
    inputfile >> varname >> M_mess_end   ; 
    inputfile >> varname >> tanb_start     ;
    inputfile >> varname >> tanb_end    ;

    inputfile >> varname >> sgnMu    ;
     
    inputfile.close(); 

    cout << "l1 = " << l1 << endl 
	 << "l2 = " << l2 << endl
	 << "l3 = " << l3 << endl 
	 << "nQ = " << nQ << endl 
       	 << "nU = " << nU << endl 
	 << "nD = " << nD << endl
	 << "nL = " << nL << endl 
	 << "nE = " << nE << endl 
	 << "nHu = " << nHu << endl 
	 << "nHd = " << nHd << endl 
	 << "N = " << N << endl 
	 << "numscan = " << numscan << endl
	 << "M_moduli_start = " << M_moduli_start << endl
	 << "M_moduli_end = " << M_moduli_end << endl
	 << "M_gauge_start = " << M_gauge_start << endl 
	 << "M_gauge_end = " << M_gauge_end << endl 
	 << "M_mess_start = " << M_mess_start << endl 
	 << "M_mess_end = " << M_mess_end << endl 
	 << "tanb_start =  " << tanb_start << endl 
	 << "tanb_end = " << tanb_end << endl
	 << "sgnMu = " << sgnMu << endl; 


    for( int i = 0 ; i < numscan ; i++ ) { 
      QedQcd oneset0, oneset1, oneset2;

      M_moduli = randomgenerator( M_moduli_start, M_moduli_end ) ; 
      M_gauge  = randomgenerator( M_gauge_start,  M_gauge_end ) ; 
      M_mess   = lograndomgenerator( M_mess_start,   M_mess_end ) ;
      tanb     = randomgenerator( tanb_start,     tanb_end ) ; 
      
      cout << i << "th run : " << endl ;  
      cout << "M_moduli = " << M_moduli << endl 
	   << "M_gauge  = " << M_gauge  << endl 
	   << "M_mess   = " << M_mess   << endl 
	   << "tanb     = " << tanb     << endl ; 
      
      mgutGuess = 2e16;
      gaugeUnification = false;
      pars.setEnd(3);
      pars(1) = M_moduli; pars(2) = M_gauge; pars(3) = M_mess;
      //      r = &m;
      
      //      if (flag) oneset0.calcPoleMb();
      oneset0.toMz();
      oneset1.toMz(); 
      oneset2.toMz(); 
      
      //      ofstream  rgefile; 
      //    rgefile.open("rge.dat"); 
      
      //   ofstream  spectrumfile; 
      //   spectrumfile.open("spectrum.dat") ;
      
      //      cout << "Here comes r1 " << endl; 
      
      MssmSoftsusy r0 ; 
      cout << "Starting" << endl; 
      r0.N= 0 ; 
      r0.Nflag = true; 
      r0.beta2() ;
      r0.Nflag = false; 
      
      double mgut =  r0.lowOrg(gaugegravityBcs0, mgutGuess, pars, sgnMu,
			       tanb, oneset0, gaugeUnification, ewsbBCscale);
      
      r0.runto( M_mess );
      
      cout << "starting phase 2 " << endl; 
      r0.N = N ;
      r0.Nflag = true; 
      r0.beta2() ; 
      r0.Nflag = false; 
      
      r0.runto( mgutGuess ) ; 
      
      global_g1 = r0.displayGaugeCoupling(1); 
      global_g2 = r0.displayGaugeCoupling(2); 
      global_g3 = r0.displayGaugeCoupling(3); 

      MssmSoftsusy r1 ; //, r2;// MssmSoftsusy2 l;
     
      r1.N = N ; 
      r1.Nflag = true; 
      r1.beta2(); 
      r1.Nflag = false ; 
      
      mgut =  r1.lowOrg(gaugegravityBcs1, mgutGuess, pars, sgnMu,
			tanb, oneset1, gaugeUnification, ewsbBCscale);
      
      
        cout << "Here comes r1" << endl; 
        cout << r1 ; 
      
    //  RGRUN( rgefile, r1 , log(mgutGuess) / log(10) , log( M_mess) / log( 10 ) , 20 ) ; 
      
      r1.runto( M_mess );
      
      global_g1 = r1.displayGaugeCoupling(1); 
      global_g2 = r1.displayGaugeCoupling(2); 
      global_g3 = r1.displayGaugeCoupling(3); 
      
      
      inter_gaugino1 = r1.displayGaugino(1); 
      inter_gaugino2 = r1.displayGaugino(2); 
      inter_gaugino3 = r1.displayGaugino(3); 
      
      inter_massmQl = r1.displaySoftMassSquared(mQl) ;
      inter_massmUr = r1.displaySoftMassSquared(mUr) ;
      inter_massmDr = r1.displaySoftMassSquared(mDr) ;
      inter_massmLl = r1.displaySoftMassSquared(mLl) ;
      inter_massmEr = r1.displaySoftMassSquared(mEr) ;
      inter_massmHu = r1.displayMh2Squared(); 
      inter_massmHd = r1.displayMh1Squared(); 
      
      inter_A_HuQU(1,1) = r1.displaySoftA( UA, 1, 1); 
      inter_A_HuQU(2,2) = r1.displaySoftA( UA, 2, 2); 
      inter_A_HuQU(3,3) = r1.displaySoftA( UA, 3, 3); 
      inter_A_HdQD(1,1) = r1.displaySoftA( DA, 1, 1); 
      inter_A_HdQD(2,2) = r1.displaySoftA( DA, 2, 2); 
      inter_A_HdQD(3,3) = r1.displaySoftA( DA, 3, 3); 
      inter_A_HdLE(1,1) = r1.displaySoftA( EA, 1, 1); 
      inter_A_HdLE(2,2) = r1.displaySoftA( EA, 2, 2); 
      inter_A_HdLE(3,3) = r1.displaySoftA( EA, 3, 3); 
      
      mgutGuess = M_mess ;
      
      
      cout << "Here comes r2" << endl; 
      MssmSoftsusy r2 ;
      r2.N = 0; 
      r2.Nflag = true; 
      r2.beta2(); 
      r2.Nflag = false ;
      
      mgut =  r2.lowOrg(gaugegravityBcs2, mgutGuess, pars, sgnMu, 
			tanb, oneset2, gaugeUnification, ewsbBCscale); 
      //    cout << r2 ; 
      
      //      RGRUN( rgefile, r2 , log(M_mess) / log(10),  log(100) / log(10), 20 ) ; 
      
      //rgefile.close(); 
      
      //spectrumrecord( spectrumfile, r2 ) ;
      
      // spectrumfile.close(); 
      
      cout << r2 ; 
      //  sPhysical p = r2.displayPhys() ;
      
      //  cout << p ; 
      
      ofstream tempfile("LesHouches.dat"); 
      streambuf* strm_buffer = cout.rdbuf(); 
      
      cout.rdbuf( tempfile.rdbuf() ) ; 
      
      r2.lesHouchesAccordOutput("nonUniversal", pars, 
				sgnMu, tanb, 0, 1, mbmb, 
				mtau, MGUTSCALE , 0 ) ; 
      cout << flush; 
      cout.rdbuf(strm_buffer); 
      tempfile.close(); 

      if (r2.displayProblem().test()) {
	cout << "# SOFTSUSY problem with point: " << r2.displayProblem();
      }      

      if( checktheresult( r2 ) ) { 
	
	//////////////////////////////////////////////////
	//                micrOmegas                    //
	//////////////////////////////////////////////////
	
	double Xf, Omega, Omega2, bsg_value, bsmumu_value, gmuon_value; 
	string mess; 
	double mtop ;
	
	int err ; 
	int fast = 1; 
	double Beps = 1E-6 ; 
	
	double cut = 0.01; 
	
	
	
	err = readLesH("LesHouches.dat",1); 
	
	//
	//  printVar(stdout); 
	//
	char messtemp[20]; 
	
	err=sortOddParticles(messtemp);
	mess = messtemp; 
	
	//	HiggsMasses(stdout);     
	//	printMasses(stdout,1);
	
	
	Omega=darkOmega(&Xf,fast,Beps);
	
	o1Contents(stdout);
	printChannels(Xf,cut,Beps,1,stdout); 
	bsg_value= bsgnlo_(); 
	bsmumu_value = bsmumu_(); 
	gmuon_value = gmuon_(); 
      
	recordphysics( outputfile, r2, M_moduli, M_gauge, M_mess, tanb, 
		       bsg_value, gmuon_value, bsmumu_value, Omega ) ; 
      }
      else {
	recordphysics( outputfile, r2, M_moduli, M_gauge, M_mess, tanb,
		       0, 0 , 0, 0 ) ; 
      }

    }

  }
Ejemplo n.º 25
0
void
main(int argc, char *argv[])
{
	char *devdir;
	int i, rv, netfd, bsize;
	int datafd;

#ifndef plan9

	void (*oldhandler)();

#endif

	devdir = nil;
	/* make connection */
	if (argc != 2) {
		fprint(stderr, "usage: %s network!destination!service\n", argv[0]);
		exits("incorrect number of arguments");
	}

	/* read options line from stdin into lnbuf */
	i = readline(0);

	/* read stdin into tempfile to get size */
	datafd = tempfile();
	bsize = prereadfile(datafd);

	/* network connection is opened after data is in to avoid timeout */
	if ((netfd=dial(argv[1], 0, 0, 0)) < 0) {
		fprint(stderr, "dialing %s\n", devdir);
		perror("dial");
		exits("can't dial");
	}

	/* write out the options we read above */
	if (write(netfd, lnbuf, i) != i) {
		error(0, "write error while sending options\n");
		exits("write error while sending options");
	}

	/* send the size of the file to be sent */
	sprint(lnbuf, "%d\n", bsize);
	i = strlen(lnbuf);
	if ((rv=write(netfd, lnbuf, i)) != i) {
		perror("write error while sending size");
		error(0, "write returned %d\n", rv);
		exits("write error while sending size");
	}

	if (seek(datafd, 0L, 0) < 0) {
		error(0, "error seeking temp file\n");
		exits("seek error");
	}
	/* mirror performance in readfile() in lpdaemon */

#ifdef plan9

	atnotify(alarmhandler, 1);

#else

	oldhandler = signal(SIGALRM, alarmhandler);

#endif

	dbgstate = 1;
	if(!recvACK(netfd)) {
		error(0, "failed to receive ACK before sending data\n");
		exits("recv ack1 failed");
	}
	dbgstate = 2;
	if ((i=pass(datafd, netfd, bsize)) != 0) {
		NAK(netfd);
		error(0, "failed to send %d bytes\n", i);
		exits("send data failed");
	}
	ACK(netfd);
	dbgstate = 3;
	if(!recvACK(netfd)) {
		error(0, "failed to receive ACK after sending data\n");
		exits("recv ack2 failed");
	}

	/* get response, as from lp -q */
	dbgstate = 4;
	while((rv=read(netfd, jobbuf, RDSIZE)) > 0) {
		if((write(1, jobbuf, rv)) != rv) {
			error(0, "write error while sending to stdout\n");
			exits("write error while sending to stdout");
		}
	}
	dbgstate = 5;

#ifdef plan9

	atnotify(alarmhandler, 0);
	/* close down network connections and go away */
	exits("");

#else

	signal(SIGALRM, oldhandler);
	exit(0);

#endif

}
Ejemplo n.º 26
0
static void*
imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
{
    CV_Assert(buf.data && buf.isContinuous());
    IplImage* image = 0;
    CvMat *matrix = 0;
    Mat temp, *data = &temp;
    string filename;

    ImageDecoder decoder = findDecoder(buf);
    if( decoder.empty() )
        return 0;

    if( !decoder->setSource(buf) )
    {
        filename = tempfile();
        FILE* f = fopen( filename.c_str(), "wb" );
        if( !f )
            return 0;
        size_t bufSize = buf.cols*buf.rows*buf.elemSize();
        fwrite( &buf.data[0], 1, bufSize, f );
        fclose(f);
        decoder->setSource(filename);
    }

    if( !decoder->readHeader() )
    {
        if( !filename.empty() )
            remove(filename.c_str());
        return 0;
    }

    CvSize size;
    size.width = decoder->width();
    size.height = decoder->height();

    int type = decoder->type();
    if( flags != -1 )
    {
        if( (flags & CV_LOAD_IMAGE_ANYDEPTH) == 0 )
            type = CV_MAKETYPE(CV_8U, CV_MAT_CN(type));

        if( (flags & CV_LOAD_IMAGE_COLOR) != 0 ||
                ((flags & CV_LOAD_IMAGE_ANYCOLOR) != 0 && CV_MAT_CN(type) > 1) )
            type = CV_MAKETYPE(CV_MAT_DEPTH(type), 3);
        else
            type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
    }

    if( hdrtype == LOAD_CVMAT || hdrtype == LOAD_MAT )
    {
        if( hdrtype == LOAD_CVMAT )
        {
            matrix = cvCreateMat( size.height, size.width, type );
            temp = cvarrToMat(matrix);
        }
        else
        {
            mat->create( size.height, size.width, type );
            data = mat;
        }
    }
    else
    {
        image = cvCreateImage( size, cvIplDepth(type), CV_MAT_CN(type) );
        temp = cvarrToMat(image);
    }

    bool code = decoder->readData( *data );
    if( !filename.empty() )
        remove(filename.c_str());

    if( !code )
    {
        cvReleaseImage( &image );
        cvReleaseMat( &matrix );
        if( mat )
            mat->release();
        return 0;
    }

    return hdrtype == LOAD_CVMAT ? (void*)matrix :
           hdrtype == LOAD_IMAGE ? (void*)image : (void*)mat;
}
Ejemplo n.º 27
0
static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt)
{
    if(!fnt->data.isEmpty()) {
#ifndef Q_OS_WINCE
        PtrAddFontMemResourceEx ptrAddFontMemResourceEx = (PtrAddFontMemResourceEx)QSystemLibrary::resolve(QLatin1String("gdi32"),
                                                                                                     "AddFontMemResourceEx");
        if (!ptrAddFontMemResourceEx)
            return;
#endif
        getFamiliesAndSignatures(fnt->data, fnt);
        if (fnt->families.isEmpty())
            return;

#ifdef Q_OS_WINCE
        HANDLE handle = 0;

        {
#ifdef QT_NO_TEMPORARYFILE
           wchar_t lpBuffer[MAX_PATH];
           GetTempPath(MAX_PATH, lpBuffer);
           QString s = QString::fromWCharArray(lpBuffer);
           QFile tempfile(s + QLatin1String("/font") + QString::number(GetTickCount()) + QLatin1String(".ttf"));
           if (!tempfile.open(QIODevice::ReadWrite))
#else
            QTemporaryFile tempfile(QLatin1String("XXXXXXXX.ttf"));
            if (!tempfile.open())
#endif // QT_NO_TEMPORARYFILE
                return;
            if (tempfile.write(fnt->data) == -1)
                return;

#ifndef QT_NO_TEMPORARYFILE
            tempfile.setAutoRemove(false);
#endif
            fnt->fileName = QFileInfo(tempfile.fileName()).absoluteFilePath();
        }

        if (AddFontResource((LPCWSTR)fnt->fileName.utf16()) == 0) {
            QFile(fnt->fileName).remove();
            return;
        }
#else
        DWORD dummy = 0;
        HANDLE handle = ptrAddFontMemResourceEx((void *)fnt->data.constData(), fnt->data.size(), 0,
                                                &dummy);
        if (handle == 0)
            return;
#endif // Q_OS_WINCE

        fnt->handle = handle;
        fnt->data = QByteArray();
        fnt->memoryFont = true;
    } else {
        QFile f(fnt->fileName);
        if (!f.open(QIODevice::ReadOnly))
            return;
        QByteArray data = f.readAll();
        f.close();
        getFamiliesAndSignatures(data, fnt);

#ifdef Q_OS_WINCE
        QFileInfo fileinfo(fnt->fileName);
        fnt->fileName = fileinfo.absoluteFilePath();
        if (AddFontResource((LPCWSTR)fnt->fileName.utf16()) == 0)
            return;
#else
        PtrAddFontResourceExW ptrAddFontResourceExW = (PtrAddFontResourceExW)QSystemLibrary::resolve(QLatin1String("gdi32"),
                                                                                               "AddFontResourceExW");
        if (!ptrAddFontResourceExW
            || ptrAddFontResourceExW((wchar_t*)fnt->fileName.utf16(), FR_PRIVATE, 0) == 0)
            return;
#endif // Q_OS_WINCE

        fnt->memoryFont = false;
    }
}
Ejemplo n.º 28
0
int
main(int argc, char *argv[])
{
	struct stat putfd_1_stat, putfd_2_stat, getfd_1_stat, getfd_2_stat;
	int fd[2], putfd_1, putfd_2, getfd_1, getfd_2;
	const char *test;

	/*
	 * First test: put a temporary file into a UNIX domain socket, then
	 * take it out and make sure it's the same file.  First time around,
	 * don't close the reference after sending.
	 */
	test = "test1-simplesendfd";
	printf("beginning %s\n", test);

	domainsocketpair(test, fd);
	tempfile(test, &putfd_1);
	dofstat(test, putfd_1, &putfd_1_stat);
	sendfd(test, fd[0], putfd_1);
	recvfd(test, fd[1], &getfd_1);
	dofstat(test, getfd_1, &getfd_1_stat);
	samefile(test, &putfd_1_stat, &getfd_1_stat);
	close(putfd_1);
	close(getfd_1);
	closesocketpair(fd);

	printf("%s passed\n", test);

	/*
	 * Second test: same as first, only close the file reference after
	 * sending, so that the only reference is the descriptor in the UNIX
	 * domain socket buffer.
	 */
	test = "test2-sendandclose";
	printf("beginning %s\n", test);

	domainsocketpair(test, fd);
	tempfile(test, &putfd_1);
	dofstat(test, putfd_1, &putfd_1_stat);
	sendfd(test, fd[0], putfd_1);
	close(putfd_1);
	recvfd(test, fd[1], &getfd_1);
	dofstat(test, getfd_1, &getfd_1_stat);
	samefile(test, &putfd_1_stat, &getfd_1_stat);
	close(getfd_1);
	closesocketpair(fd);

	printf("%s passed\n", test);

	/*
	 * Third test: put a temporary file into a UNIX domain socket, then
	 * close both endpoints causing garbage collection to kick off.
	 */
	test = "test3-sendandcancel";
	printf("beginning %s\n", test);

	domainsocketpair(test, fd);
	tempfile(test, &putfd_1);
	sendfd(test, fd[0], putfd_1);
	close(putfd_1);
	closesocketpair(fd);

	printf("%s passed\n", test);

	/*
	 * Send two files.  Then receive them.  Make sure they are returned
	 * in the right order, and both get there.
	 */

	test = "test4-twofile";
	printf("beginning %s\n", test);

	domainsocketpair(test, fd);
	tempfile(test, &putfd_1);
	tempfile(test, &putfd_2);
	dofstat(test, putfd_1, &putfd_1_stat);
	dofstat(test, putfd_2, &putfd_2_stat);
	sendfd(test, fd[0], putfd_1);
	sendfd(test, fd[0], putfd_2);
	close(putfd_1);
	close(putfd_2);
	recvfd(test, fd[1], &getfd_1);
	recvfd(test, fd[1], &getfd_2);
	dofstat(test, getfd_1, &getfd_1_stat);
	dofstat(test, getfd_2, &getfd_2_stat);
	samefile(test, &putfd_1_stat, &getfd_1_stat);
	samefile(test, &putfd_2_stat, &getfd_2_stat);
	close(getfd_1);
	close(getfd_2);
	closesocketpair(fd);

	printf("%s passed\n", test);

	/*
	 * Big bundling test.  Send an endpoint of the UNIX domain socket
	 * over itself, closing the door behind it.
	 */

	test = "test5-bundle";
	printf("beginning %s\n", test);

	domainsocketpair(test, fd);

	sendfd(test, fd[0], fd[0]);
	close(fd[0]);
	recvfd(test, fd[1], &getfd_1);
	close(getfd_1);
	close(fd[1]);

	printf("%s passed\n", test);

	/*
	 * Big bundling test part two: Send an endpoint of the UNIX domain
	 * socket over itself, close the door behind it, and never remove it
	 * from the other end.
	 */

	test = "test6-bundlecancel";
	printf("beginning %s\n", test);

	domainsocketpair(test, fd);
	sendfd(test, fd[0], fd[0]);
	sendfd(test, fd[1], fd[0]);
	closesocketpair(fd);

	printf("%s passed\n", test);

	/*
	 * Test for PR 151758: Send an character device over the UNIX
	 * domain socket and then close both sockets to orphan the
	 * device.
	 */

	test = "test7-devfsorphan";
	printf("beginning %s\n", test);

	domainsocketpair(test, fd);
	devnull(test, &putfd_1);
	sendfd(test, fd[0], putfd_1);
	close(putfd_1);
	closesocketpair(fd);

	printf("%s passed\n", test);
	
	return (0);
}
Ejemplo n.º 29
0
static GList *
process_boundaries_finish(GList *boundaries_list)
{
	//fprintf(stderr,"process_boundaries_finish:001\n");

	GList *l, *sl, *l2, *ln;
	GList *ret = NULL;
	l = boundaries_list;
	char *f1_name = NULL;
	char *f2_name = NULL;
	long long b_counter_1 = 0;
	long long nodes_counter_ = 0;
	long long ways_counter_ = 0;

	while (l)
	{
		struct boundary *boundary = l->data;
		int first = 1;
		FILE *f = NULL, *fu = NULL;

		b_counter_1++;
		if ((b_counter_1 % 500) == 0)
		{
			fprintf(stderr,"boundaries_f1:B:%lld\n", b_counter_1);
		}

		//fprintf(stderr,"process_boundaries_finish:002\n");

		// only lowercase country code
		if (boundary->iso2)
		{
			int i99;
			for (i99 = 0; boundary->iso2[i99]; i99++)
			{
				boundary->iso2[i99] = tolower(boundary->iso2[i99]);
			}
		}
		// only lowercase country code

		if (boundary->country)
		{
			//fprintf(stderr,"process_boundaries_finish:003\n");

			char *name = g_strdup_printf("country_%s_poly", boundary->iso2);
			f1_name = g_strdup_printf("country_%s_poly", boundary->iso2);
			f = tempfile("", name, 1);
			g_free(name);
		}



		// calc bounding box
		first = 1;
		nodes_counter_ = 0;
		ways_counter_ = 0;
		sl = boundary->segments;
		while (sl)
		{
			struct geom_poly_segment *gs = sl->data;
			struct coord *c = gs->first;
			while (c <= gs->last)
			{
				if (first)
				{
					boundary->r.l = *c;
					boundary->r.h = *c;
					first = 0;
				}
				else
				{
					bbox_extend(c, &boundary->r);
				}
				c++;
				nodes_counter_++;
			}
			sl = g_list_next(sl);
			ways_counter_++;
		}

		//fprintf(stderr, "relid:%lld\n", item_bin_get_relationid(boundary->ib));
		//fprintf(stderr, "ways:%lld nodes:%lld\n", ways_counter_, nodes_counter_);

		boundary->sorted_segments = geom_poly_segments_sort(boundary->segments, geom_poly_segment_type_way_right_side);
		sl = boundary->sorted_segments;

		first = 1;
		while (sl)
		{
			//fprintf(stderr,"process_boundaries_finish:004.1\n");

			struct geom_poly_segment *gs = sl->data;
			struct coord *c = gs->first;

			/*
			while (c <= gs->last)
			{
				if (first)
				{
					boundary->r.l = *c;
					boundary->r.h = *c;
					first = 0;
				}
				else
				{
					bbox_extend(c, &boundary->r);
				}
				c++;

				//fprintf(stderr,"process_boundaries_finish:004.2 lx=%d ly=%d hx=%d hy=%d\n",boundary->r.l.x,boundary->r.l.y,boundary->r.h.x,boundary->r.h.y);

			}
			*/

			if (f)
			{
				struct item_bin *ib = item_bin_2;
				item_bin_init(ib, type_selected_line);
				item_bin_add_coord(ib, gs->first, gs->last - gs->first + 1);
				item_bin_write(ib, f);
			}

			if (boundary->country)
			{
				if (!coord_is_equal(*gs->first, *gs->last))
				{
					if (!fu)
					{
						char *name = g_strdup_printf("country_%s_broken", boundary->iso2);
						f2_name = g_strdup_printf("country_%s_broken", boundary->iso2);
						fprintf(stderr, "*BROKEN* country_%s_broken\n", boundary->iso2);
						fu = tempfile("", name, 1);
						g_free(name);
					}
					struct item_bin *ib = item_bin_2;
					item_bin_init(ib, type_selected_point);
					item_bin_add_coord(ib, gs->first, 1);
					item_bin_write(ib, fu);

					item_bin_init(ib, type_selected_point);
					item_bin_add_coord(ib, gs->last, 1);
					item_bin_write(ib, fu);
				}
			}
			sl = g_list_next(sl);

			if (f2_name)
			{
				tempfile_unlink("", f2_name);
				g_free(f2_name);
				f2_name = NULL;
			}
		}

		ret = process_boundaries_insert(ret, boundary);
		l = g_list_next(l);

		if (f)
		{
			fclose(f);
		}

		if (fu)
		{
			if (boundary->country)
			{
				//osm_warning("relation", item_bin_get_relationid(boundary->ib), 0, "Broken country polygon '%s'\n", boundary->iso2);
				fprintf(stderr, "*BROKEN* country polygon '%s' relid=%lld\n", boundary->iso2, item_bin_get_relationid(boundary->ib));
			}
			fclose(fu);
		}

		if (f1_name)
		{
			tempfile_unlink("", f1_name);
			g_free(f1_name);
			f1_name = NULL;
		}
	}
#if 0
	printf("hierarchy\n");
#endif

	// boundaries_list = g_list_sort(boundaries_list, boundary_bbox_compare); // disable sorting, does not seem to do any good

// children stuff totally broken!!!
#if 0
	b_counter_1 = 0;
	l = boundaries_list;
	while (l)
	{
		b_counter_1++;
		if ((b_counter_1 % 500) == 0)
		{
			fprintf(stderr,"boundaries_f2:B:%lld\n", b_counter_1);
		}

		struct boundary *boundary = l->data;
		ln = l2 = g_list_next(l);
		while (l2)
		{
			struct boundary *boundary2 = l2->data;
			if (bbox_contains_bbox(&boundary2->r, &boundary->r))
			{
				boundaries_list = g_list_remove(boundaries_list, boundary);
				boundary2->children = g_list_append(boundary2->children, boundary);
				break;
			}
			l2 = g_list_next(l2);
		}
		l = ln;
	}
#endif
// children stuff totally broken!!!

	// -- DEBUG --
	// -- DEBUG --
	// -- DEBUG --
	// dump_hierarchy(boundaries_list,""); // --> prints huge amounts of data!! be careful
	// -- DEBUG --
	// -- DEBUG --
	// -- DEBUG --

	return boundaries_list;
}
Ejemplo n.º 30
0
static bool find_include_file(astring &srcincpath, int srcrootlen, int dstrootlen, astring &srcfile, astring &dstfile, astring &filename)
{
	// iterate over include paths and find the file
	for (include_path *curpath = incpaths; curpath != NULL; curpath = curpath->next)
	{
		// a '.' include path is specially treated
		if (curpath->path == ".")
			srcincpath.cpysubstr(srcfile, 0, srcfile.rchr(0, PATH_SEPARATOR[0]));
		else
			srcincpath.cpysubstr(srcfile, 0, srcrootlen + 1).cat(curpath->path);

		// append the filename piecemeal to account for directories
		int lastsepindex = 0;
		int sepindex;
		while ((sepindex = filename.chr(lastsepindex, '/')) != -1)
		{
			// handle .. by removing a chunk from the incpath
			astring pathpart(filename, lastsepindex, sepindex - lastsepindex);
			if (pathpart == "..")
			{
				sepindex = srcincpath.rchr(0, PATH_SEPARATOR[0]);
				if (sepindex != -1)
					srcincpath.substr(0, sepindex);
			}

			// otherwise, append a path separator and the pathpart
			else
				srcincpath.cat(PATH_SEPARATOR).cat(pathpart);

			// advance past the previous index
			lastsepindex = sepindex + 1;
		}

		// now append the filename
		srcincpath.cat(PATH_SEPARATOR).catsubstr(filename, lastsepindex, -1);

		// see if we can open it
		core_file *testfile;
		if (core_fopen(srcincpath, OPEN_FLAG_READ, &testfile) == FILERR_NONE)
		{
			// close the file
			core_fclose(testfile);

			// find the longest matching directory substring between the include and source file
			lastsepindex = 0;
			while ((sepindex = srcincpath.chr(lastsepindex, PATH_SEPARATOR[0])) != -1)
			{
				// get substrings up to the current directory
				astring tempfile(srcfile, 0, sepindex);
				astring tempinc(srcincpath, 0, sepindex);

				// if we don't match, stop
				if (tempfile != tempinc)
					break;
				lastsepindex = sepindex + 1;
			}

			// chop off the common parts of the paths
			astring tempfile(srcfile, lastsepindex, -1);
			srcincpath.substr(lastsepindex, -1).replacechr(PATH_SEPARATOR[0], '/');

			// for each directory left in the filename, we need to prepend a "../"
			while ((sepindex = tempfile.chr(0, PATH_SEPARATOR[0])) != -1)
			{
				tempfile.substr(sepindex + 1, -1);
				srcincpath.ins(0, "../");
			}
			srcincpath.cat(".html");

			// free the strings and return the include path
			return true;
		}
	}
	return false;
}