Exemplo n.º 1
0
int hitbuffer_finish(hitbuffer *hb) {
	if (!strcmp(hb->word, "")) {
		return 0;
	}
	if (hb->type == 0) {	
	  //		fprintf(stderr, "%s: %d\n", hb->word, (int)hb->freq);
		write_dir(hb);
	}
	else if (hb->type == 1) {
	  //	fprintf(stderr, "%s: %d [%d blocks]\n", hb->word, (int)hb->freq, (int)hb->dir_length);
		write_dir(hb);
		write_blk(hb);
	}
	return 0;
}
Exemplo n.º 2
0
void dir_unlink(inode* inode, std::string const& name)
{
	if (!inode)
		throw std::invalid_argument("dir_unlink  null arg: inode");

	// If our path resolution code works as expected, the filename
	// of any path will never be 0 bytes in length. So an assert is fine.
	assert(name.size() > 0);

	if (name.size() > MAX_FILENAME_LEN)
		throw fs_error(ERROR_NAMETOOLONG);

	inode_guard lock(inode->lock);

	auto entries = read_dir(inode);

	for (auto it = entries.begin(); it != entries.end(); ++it) {
		if (!compare_dirent_name(*it, name))
			continue;

		entries.erase(it);
		write_dir(inode, entries);
		return;
	}

	throw fs_error(ERROR_NOENTRY);
}
Exemplo n.º 3
0
void dir_link(inode* inode, std::string const& name, uint32_t ino)
{
	assert(inode);
	// If our path resolution code works as expected, the filename
	// of any path will never be 0 bytes in length. So an assert is fine.
	assert(name.size() > 0);

	if (name.size() > MAX_FILENAME_LEN)
		throw fs_error(ERROR_NAMETOOLONG);

	dir_entry ent;
	ent.f_ino = ino;
	if (0 < name.size()) {
		ent.f_namelen = (uint8_t) name.size();
		std::memcpy(ent.f_name, name.c_str(), name.size());
	}

	inode_guard lock(inode->lock);

	auto entries = read_dir(inode);

	for (auto& j : entries) {
		if (!compare_dirent_name(j, name))
			continue;

		throw fs_error(ERROR_EXIST);
	}

	entries.emplace_back(ent);
	write_dir(inode, entries);
}
Exemplo n.º 4
0
int pandalog_close_write(void) {
    // finish current chunk then write directory info and header
    write_current_chunk();
    // Not a mistake!
    // this will add one more dir entry for last instr and file pos
    add_dir_entry(thePandalog->chunk_num);
    write_dir();
    return 0;
}
Exemplo n.º 5
0
void UmlActivityParameter::write(FileOut & out) {
  // write parameter def

  out.indent();
  out << "<ownedParameter name=\"";
  out.quote(name());
  out << '"';
  out.id(this);
  write_dir(out);
  write_effect(out);
  write_flags(out);
  out << ">\n";
  
  out.indent(+1);
  
  write_description_properties(out);
  write_multiplicity(out, multiplicity(), this);
  write_default_value(out, defaultValue(), this);
  UmlItem::write_type(out, type());
  
  out.indent(-1);

  out.indent();
  out << "</ownedParameter>\n";

  //write parameter node
  out.indent();
  out << "<node xmi:type=\"uml:ActivityParameterNode\" name =\"";
  out.quote(name());
  out << '"';
  out.id_prefix(this, "PARAMETER_NODE_");
  if (isControlType())
    out << " isControlType=\"true\"";
  write_ordering(out);
  write_selection(out);
  write_in_state(out);
  out << ">\n";
  out.indent(+1);

  UmlItem::write_type(out, type());

  const Q3PtrVector<UmlItem> ch = children();
  unsigned n = ch.size();
  
  for (unsigned i = 0; i != n; i += 1)
    ch[i]->write(out);

  out.indent(-1);
  out.indent();
  out << "</node>\n";

  unload();
}
Exemplo n.º 6
0
static void write_dir( FILE* of, GMenuTreeDirectory* dir )
{
    GSList* l;
    const char* cstr;
    char* str;

    fprintf( of, "+%s\n", gmenu_tree_directory_get_menu_id( dir ) );
    fprintf( of, "%s\n", gmenu_tree_directory_get_name( dir ) );
    cstr = gmenu_tree_directory_get_comment( dir );
    fprintf( of, "%s\n", cstr ? cstr : "" );
    cstr = gmenu_tree_directory_get_icon( dir );
    fprintf( of, "%s\n", cstr ? cstr : "" );

    if( gmenu_tree_directory_get_desktop_file_path( dir ) )
    {
        /* get basename of its desktop file. */
        str = g_path_get_basename( gmenu_tree_directory_get_desktop_file_path( dir ) );
        fprintf( of, "%s\n", str );
        g_free( str );

        /* get the location of its desktop file. */
        str = g_path_get_dirname( gmenu_tree_directory_get_desktop_file_path( dir ) );
        fprintf( of, "%d\n", dirname_index( str ) );
        g_free( str );
    }
    else
    {
        fprintf( of, "\n-1\n" );
    }

    // fprintf( of, "\n" );    /* end of item info */

    for( l = gmenu_tree_directory_get_contents(dir); l; l = l->next )
    {
        GMenuTreeItem* item = (GMenuTreeItem*)l->data;
        GMenuTreeItemType type = gmenu_tree_item_get_type(item);

        if( type == GMENU_TREE_ITEM_DIRECTORY )
        {
            write_dir( of, (GMenuTreeDirectory*)item );
        }
        else if( type == GMENU_TREE_ITEM_ENTRY )
        {
            write_entry( of, (GMenuTreeEntry*)item );
        }
        else if( type == GMENU_TREE_ITEM_SEPARATOR )
            fputs( "-\n", of );
    }
    fputs( "\n", of );
}
Exemplo n.º 7
0
Arquivo: initrd.c Projeto: borlox/kos
void id_write(const char *file, const char *logfile)
{
	FILE *f = fopen(file, "wb");
	FILE *log = fopen(logfile, "w");
	if (!f || !log) {
		fprintf(stderr, "Could not open file '%s' or '%s': %s\n", file, logfile, strerror(errno));
		return;
	}

	int offs = write_header(f, log);
	int size = write_dir(root, f, offs, log, 0);
	printf("Total size: %d kb\n", size / 1024);
	fclose(f);
	fclose(log);
}
Exemplo n.º 8
0
static int logfs_replace_inode(struct inode *dir, struct dentry *dentry,
		struct logfs_disk_dentry *dd, struct inode *inode)
{
	loff_t pos;
	int err;

	err = logfs_get_dd(dir, dentry, dd, &pos);
	if (err)
		return err;
	dd->ino = cpu_to_be64(inode->i_ino);
	dd->type = logfs_type(inode);

	err = write_dir(dir, dd, pos);
	if (err)
		return err;
	log_dir("Replace dentry (%lx, %llx) %s -> %llx\n", dir->i_ino, pos,
			dd->name, be64_to_cpu(dd->ino));
	return write_inode(dir);
}
Exemplo n.º 9
0
void pre_lzw_mp::do_lzw(QString n){
    QString job = n;
    QString images_src = src + "\\" +n;
    QString write_dst = dst + "\\" + n;
    QString image_name, saved_name;
    int dot_pos;
    QString image_path;
    QDir images_dir(images_src);
    QDir write_dir(dst);
    write_dir.mkdir(job);
    qDebug()<<images_src;
    qDebug()<<write_dst;
    QFileInfoList images_info_list = images_dir.entryInfoList();
    QList<QFileInfo>::iterator image_iter = images_info_list.begin();
    FreeImage_Initialise(true);
    for(; image_iter < images_info_list.end(); ++image_iter){
        if((*image_iter).isDir()){
//            qDebug()<<(*image_iter).fileName();
            continue;
        }
        image_name = (*image_iter).fileName();
        dot_pos = image_name.indexOf(".");
        saved_name = write_dst + "\\" + image_name.left(dot_pos) + "_c.tif";
        image_path = (*image_iter).absoluteFilePath();
        FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(image_path.toStdString().c_str(), 0);
        if(fif == FIF_UNKNOWN){
            fif = FreeImage_GetFIFFromFilename(image_path.toStdString().c_str());
        }
        if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)){
            FIBITMAP *image = FreeImage_Load(fif, image_path.toStdString().c_str());
            FreeImage_Save(FIF_TIFF, image, saved_name.toStdString().c_str(), TIFF_LZW);
            FreeImage_Unload(image);
        }        
    }
    FreeImage_DeInitialise();
}
Exemplo n.º 10
0
void split_bucket( obj table, obj bucket, obj h, obj k, obj v )
{
int i, di, j, dir_bits, bucket_bits;
obj b, vec;
struct bucket_chain hi, lo;
UINT_32 mask;

    dir_bits = fx2int(gvec_read(table,HASHTABLE_DIR_BITS));
    vec = gvec_read( table, HASHTABLE_DIRECTORY );

    if (EQ(bucket,FALSE_OBJ))
    {
	bucket = make_bucket( gvec_read( table, HASHTABLE_BUCKET_CLASS ),
			      dir_bits );
	write_dir( vec, h, bucket ); 

	write_bucket_hash( bucket, SLOT(2), h );
	write_bucket_key( bucket, SLOT(2), k );
	write_bucket_value( bucket, SLOT(2), v );
	return;
    }
    
    bucket_bits = fx2int(gvec_read(bucket,BUCKET_BITS));
    
    /* grow the hash table's directory if necessary */
    
    if (dir_bits == bucket_bits)
    {
    UINT_32 i, old_size;
    obj old_vec = vec;
    
	old_size = 1<<dir_bits;
	dir_bits++;

#ifdef DEBUG_0
	printf( "growing directory from %u entries\n", old_size );
#endif /* DEBUG_0 */
	
	vec = alloc( SLOT(2*old_size), vector_class );

	for (i=0; i<old_size; i++)
	    gvec_write_init( vec, SLOT(i), 
			      gvec_read( old_vec, SLOT(i) ) );
	for (i=0; i<old_size; i++)
	    gvec_write_init( vec, SLOT(i + old_size), 
	    		      gvec_read( old_vec, SLOT(i) ) );

	gvec_write_ptr( table, HASHTABLE_DIRECTORY, vec );
	gvec_write_non_ptr( table, HASHTABLE_DIR_BITS, int2fx(dir_bits) );
    }

    /* initialize the structures for the new chains */
    
#ifdef DEBUG_0
    printf( "initializing hi/lo\n" );
#endif /* DEBUG_0 */

    init_chain( table, &hi, bucket_bits+1 );
    init_chain( table, &lo, bucket_bits+1 );
    
    /* traverse the bucket */
    
    /* this mask selects the bit that distinguishes the "hi"
       bucket from the "lo" bucket
    */
    
    mask = VAL(int2fx(1)) << bucket_bits;
    
#ifdef DEBUG_0
    printf( "mask = %#x\n", mask );
#endif /* DEBUG_0 */

    chain_insert( (VAL(h) & mask) ? &hi : &lo, h, k, v );

    for (b=bucket; !EQ(b,FALSE_OBJ); b=gvec_read(b,BUCKET_OVERFLOW))
    {
	for (i=SLOT(2); i<SLOT(2+BUCKET_CAPACITY); i+=SLOT(1))
	{
	  obj h = gvec_read( b, i );
	  struct bucket_chain *use;
	
	  use = (VAL(h) & mask) ? &hi : &lo;
	  chain_insert( use, 
			h, 
			gvec_read( b, i+SLOT(BUCKET_CAPACITY) ),
			gvec_read( b, i+2*SLOT(BUCKET_CAPACITY) ) );
	}
    }
    
    /* install the new bucket chains in the directory */
    
    i = SLOT( fx2int( h ) & ((1 << bucket_bits) - 1) );
    di = SLOT( 1 << bucket_bits );

    for (j=0; j<(1<<(dir_bits - (bucket_bits+1))); j++)
    {
#ifdef DEBUG_0
	printf( "installing lo at %u\n", i/W );
#endif /* DEBUG_0 */
        gvec_write( vec, i, lo.first );
	i += di;
#ifdef DEBUG_0
	printf( "installing hi at %u\n", i/W );
#endif /* DEBUG_0 */
        gvec_write( vec, i, hi.first );
	i += di;
    }
}
Exemplo n.º 11
0
Arquivo: initrd.c Projeto: borlox/kos
static int write_dir(struct entry *dir, FILE *out, int offset, FILE *log, int idt)
{
	space(stdout, idt * 2);
	printf("/%s\n", dir->name);

	LOG("~ Offset is  %d\n", offset);
	LOG("~ Filepos is %d\n", ftell(out));

	int namelen = strlen(dir->name) + 1; /* including '\0' */
	int namepos = offset + sizeof(struct id_entry);
	int datapos = namepos + namelen;

	struct id_entry entry;
	entry.type    = 1;
	entry.name    = namepos;
	entry.count   = dir->count;
	entry.content = datapos;
	entry.next    = 0; /* still not known */

	LOG("* Writing directory at offset %d:\n", offset);
	LOG("|- Type:        %d\n", entry.type);
	LOG("|- NameOffs:    %d\n", entry.name);
	LOG("|- Count:       %d\n", entry.count);
	LOG("|- ContentOffs: %d\n", entry.content);
	LOG("|- NextOffs:    <still unknown>\n");

	fwrite(&entry, sizeof(entry), 1, out);

	long next_posinfile = ftell(out) - 4;
	LOG("|- Pos of next is %d\n", next_posinfile);

	LOG("|- Writing name: '%s' with length %d\n", dir->name, namelen);
	fwrite(dir->name, 1, namelen, out);

	struct entry *cur = dir->files;

	int offs = datapos;
	while (cur) {
		if (cur->path) {
			offs = write_file(cur, out, offs, log, idt + 1);
		}
		else {
			offs = write_dir(cur, out, offs, log, idt + 1);
		}
		cur = cur->next;
	}

	if (dir->next) {
		long cur_pos = ftell(out);
		fseek(out, next_posinfile, SEEK_SET);
		fwrite(&offs, 4, 1, out);
		fseek(out, cur_pos, SEEK_SET);
		LOG("|- Next offset changed to %d\n", offs);
		LOG("|- File pos is %d, was %d\n", ftell(out), cur_pos);
	}
	else {
		LOG("|- No next offset needed.\n");
	}

	LOG("`- New offset is %d\n", offs);
	return offs;
}
Exemplo n.º 12
0
int main(int argc, char** argv)
{
    GOptionContext* opt_ctx;
    GError* err = NULL;
    GMenuTree* menu_tree = NULL;
    GMenuTreeDirectory* root_dir;
    GSList* l;
    FILE *of;
    int ofd;
    char *tmp;
    char *dir;
    const gchar* const * xdg_cfg_dirs;
    const gchar* const * pdir;
    const char* menu_prefix;
    char* menu_file;
    char* plus_ptr = NULL;

    setlocale (LC_ALL, "");

    opt_ctx = g_option_context_new("Generate cache for freedesktop.org compliant menus.");
    g_option_context_add_main_entries( opt_ctx, opt_entries, NULL );
    if( ! g_option_context_parse( opt_ctx, &argc, &argv, &err ) )
    {
        g_print( "%s", err->message );
        g_error_free( err );
        return 1;
    }

    if( lang )
        g_setenv( "LANGUAGE", lang, TRUE );
#if 0
    /* if the cache is already up-to-date, just leave it. */
    if( !force && is_menu_uptodate() )
    {
        g_print("upda-to-date, re-generation is not needed.");
        return 0;
    }
#endif

    /* some memory leaks happen here if g_free is not used to free the keys. */
    de_hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
    g_hash_table_insert( de_hash, (gpointer)"LXDE", (gpointer)SHOW_IN_LXDE );
    g_hash_table_insert( de_hash, (gpointer)"GNOME", (gpointer)SHOW_IN_GNOME );
    g_hash_table_insert( de_hash, (gpointer)"KDE", (gpointer)SHOW_IN_KDE );
    g_hash_table_insert( de_hash, (gpointer)"XFCE", (gpointer)SHOW_IN_XFCE );
    g_hash_table_insert( de_hash, (gpointer)"ROX", (gpointer)SHOW_IN_ROX );

    if(ifile)
        plus_ptr = strrchr(ifile, '+');

    if(plus_ptr != NULL && strcmp(plus_ptr, "+hidden") != 0)
        plus_ptr = NULL;

    if(plus_ptr)
    {
        *plus_ptr = '\0';
        menu_tree = gmenu_tree_lookup( ifile, GMENU_TREE_FLAGS_INCLUDE_NODISPLAY | GMENU_TREE_FLAGS_INCLUDE_EXCLUDED | GMENU_TREE_FLAGS_SHOW_EMPTY );
        *plus_ptr = '+';
    }
    else
        menu_tree = gmenu_tree_lookup( ifile, GMENU_TREE_FLAGS_INCLUDE_EXCLUDED );
    if( ! menu_tree )
    {
        g_print("Error loading source menu file: %s\n", ifile);
        return 1;
    }

    dir = g_path_get_dirname( ofile );
    if( !g_file_test( dir, G_FILE_TEST_EXISTS ) )
        g_mkdir_with_parents( dir, 0700 );
    g_free( dir );

    /* write the tree to cache. */
    tmp = g_malloc( strlen( ofile ) + 7 );
    strcpy( tmp, ofile );
    strcat( tmp, "XXXXXX" );
    ofd = g_mkstemp( tmp );
    if( ofd == -1 )
    {
        g_print( "Error writing output file: %s\n", g_strerror(errno) );
        return 1;
    }

    of = fdopen( ofd, "w" );
    if( ! of )
    {
        g_print( "Error writing output file: %s\n", ofile );
        return 1;
    }

    /* Version number should be added to the head of this cache file. */
    fprintf( of, "%d.%d\n", VER_MAJOR, VER_MINOR );

    /* the first line is menu name */
    fprintf( of, "%s\n", ifile );

    root_dir = gmenu_tree_get_root_directory( menu_tree );

    /* add the source menu file itself to the list of files requiring monitor */
    if(plus_ptr)
        *plus_ptr = '\0';
    if( g_path_is_absolute(ifile) )
    {
        if( ! g_slist_find_custom(all_used_files, ifile, (GCompareFunc)strcmp ) )
            all_used_files = g_slist_prepend(all_used_files, g_strdup(ifile));
    }
    else
    {
        char* file_name;
        xdg_cfg_dirs = g_get_system_config_dirs();
        menu_prefix = g_getenv("XDG_MENU_PREFIX");
        file_name = menu_prefix ? g_strconcat(menu_prefix, ifile, NULL) : ifile;
        for( pdir = xdg_cfg_dirs; *pdir; ++pdir )
        {
            menu_file = g_build_filename( *pdir, "menus", file_name, NULL );
            if( ! g_slist_find_custom(all_used_dirs, menu_file, (GCompareFunc)strcmp ) )
                all_used_files = g_slist_prepend(all_used_files, menu_file);
            else
                g_free( menu_file );
        }
        menu_file = g_build_filename( g_get_user_config_dir(), "menus", file_name, NULL );
        if( file_name != ifile )
            g_free(file_name);

        if( ! g_slist_find_custom(all_used_dirs, menu_file, (GCompareFunc)strcmp ) )
            all_used_files = g_slist_prepend(all_used_files, menu_file);
        else
            g_free(menu_file);
    }

    /* write a list of all files which need to be monitored for changes. */
    /* write number of files first */
    fprintf( of, "%d\n", g_slist_length(all_used_dirs) + g_slist_length(all_used_files) );

    /* list all files.
     * add D or F at the begin of each line to indicate whether it's a
     * file or directory. */
    for( l = all_used_dirs; l; l = l->next )
    {
        fprintf( of, "D%s\n", (char*)l->data );
    }
    for( l = all_used_files; l; l = l->next )
    {
        fprintf( of, "F%s\n", (char*)l->data );
    }

    /* write all DE names in this menu. Known DEs such as LXDE, GNOME, and KDE don't need to be listed here */
    if( g_hash_table_size(de_hash) > N_KNOWN_DESKTOPS ) /* if there are some unknown DEs added to the hash */
        g_hash_table_foreach(de_hash, (GHFunc)write_de_name, of );
    fputc('\n', of);

    /* write the whole menu tree */
    write_dir( of, root_dir );

    fclose( of );

    gmenu_tree_unref( menu_tree );

    g_hash_table_destroy(de_hash);

    if( g_rename( tmp, ofile ) == -1 )
    {
        g_print( "Error writing output file: %s\n", g_strerror( errno ) );
    }
    g_free( tmp );
    /* g_print("success!\n"); */
    return 0;
}