Пример #1
0
static Eina_Bool storage_item_write(AppData *ad, CNP_ITEM *item)
{
	CALLED();
	StorageData *sd = ad->storage;
	int index = getMinIndex(sd->indexTable, STORAGE_ITEM_CNT);
	sd->indexTable[index] = ecore_time_unix_get();
	sd->itemTable[index] = item;

	item_write(sd->ef, index, item);
	storage_index_write(sd);
	dump_items(sd);
	return EINA_TRUE;
}
Пример #2
0
static void storage_rewrite_all_items(StorageData *sd)
{
	CALLED();
	if (sd->ef)
		eet_close(sd->ef);
	ecore_file_remove(STORAGE_FILEPATH);
	sd->ef = eet_open(STORAGE_FILEPATH, EET_FILE_MODE_READ_WRITE);

	int i;
	for (i = 0; i < STORAGE_ITEM_CNT; i++)
	{
		if ((sd->indexTable[i] != STORAGE_INDEX_ITEM_NONE) && (sd->itemTable[i]))
			item_write(sd->ef, i, sd->itemTable[i]);
	}
	storage_index_write(sd);
}
Пример #3
0
/**
   Save the specified mode to file
*/
static void history_save_mode( void *n, history_mode_t *m )
{
    FILE *out;
    history_mode_t *on_disk;
    int i;
    int has_new=0;
    wchar_t *tmp_name;

    int ok = 1;

    /*
      First check if there are any new entries to save. If not, then
      we can just return
    */
    for( i=0; i<al_get_count(&m->item); i++ )
    {
        void *ptr = al_get( &m->item, i );
        has_new = item_is_new( m, ptr );
        if( has_new )
        {
            break;
        }
    }

    if( !has_new )
    {
        return;
    }

    signal_block();

    /*
      Set up on_disk variable to describe the current contents of the
      history file
    */
    on_disk = history_create_mode( m->name );
    history_load( on_disk );

    tmp_name = history_filename( on_disk, m->name, L".tmp" );

    if( tmp_name )
    {
        tmp_name = wcsdup(tmp_name );

        if( (out=wfopen( tmp_name, "w" ) ) )
        {
            hash_table_t mine;

            hash_init( &mine, &hash_item_func, &hash_item_cmp );

            for( i=0; i<al_get_count(&m->item); i++ )
            {
                void *ptr = al_get( &m->item, i );
                int is_new = item_is_new( m, ptr );
                if( is_new )
                {
                    hash_put( &mine, item_get( m, ptr ), L"" );
                }
            }

            /*
              Re-save the old history
            */
            for( i=0; ok && (i<al_get_count(&on_disk->item)); i++ )
            {
                void *ptr = al_get( &on_disk->item, i );
                item_t *i = item_get( on_disk, ptr );
                if( !hash_get( &mine, i ) )
                {
                    if( item_write( out, on_disk, ptr ) == -1 )
                    {
                        ok = 0;
                        break;
                    }
                }

            }

            hash_destroy( &mine );

            /*
              Add our own items last
            */
            for( i=0; ok && (i<al_get_count(&m->item)); i++ )
            {
                void *ptr = al_get( &m->item, i );
                int is_new = item_is_new( m, ptr );
                if( is_new )
                {
                    if( item_write( out, m, ptr ) == -1 )
                    {
                        ok = 0;
                    }
                }
            }

            if( fclose( out ) || !ok )
            {
                /*
                  This message does not have high enough priority to
                  be shown by default.
                */
                debug( 2, L"Error when writing history file" );
            }
            else
            {
                wrename( tmp_name, history_filename( on_disk, m->name, 0 ) );
            }
        }
        free( tmp_name );
    }

    halloc_free( on_disk);

    if( ok )
    {

        /*
          Reset the history. The item_t entries created in this session
          are not lost or dropped, they are stored in the session_item
          hash table. On reload, they will be automatically inserted at
          the end of the history list.
        */

        if( m->mmap_start && (m->mmap_start != MAP_FAILED ) )
        {
            munmap( m->mmap_start, m->mmap_length );
        }

        al_truncate( &m->item, 0 );
        al_truncate( &m->used, 0 );
        m->pos = 0;
        m->has_loaded = 0;
        m->mmap_start=0;
        m->mmap_length=0;

        m->save_timestamp=time(0);
        m->new_count = 0;
    }

    signal_unblock();
}
Пример #4
0
int main(int argc, char **argv)
{
  const char *filename = NULL;
  const char *outfile = NULL;
  if ( argc <= 1 )
  {
    printf("%s [options] mapfile\n", argv[0]);
    printf("  -o c-file-name\n");
    exit(1);
  }
  argv++;
  argc--;
  
  while( argc > 0 )
  {
    if ( strcmp(*argv, "-o" ) == 0 )
    {
      argv++;
      argc--;
      if ( argc <= 0 )
      {
	printf("output file missing\n");
	exit(1);
      }
      outfile = argv[0];
    }
    else
    {
      filename = argv[0];
    }
    argv++;
    argc--;
  }
  
  clear_map();
  
  if ( filename != NULL  )
  {
    out_fp= NULL;
    if ( outfile != NULL )
    {
      out_fp = fopen(outfile, "w");
      printf("output file %s\n", outfile);
      fprintf(out_fp, "/* %s generated by mapgen, [email protected] */\n", outfile);
      fprintf(out_fp, "\n");
      fprintf(out_fp, "#include \"map.h\"\n");
      fprintf(out_fp, "\n");
    }
    map_read_filename(filename, PHASE_MAPDATA);

    ugl_WriteBytecodeCArray(out_fp, "map_code");
    
    //write_item_onmap();
    
    item_write(out_fp);
    
    if ( out_fp != NULL )
    {
      fprintf(out_fp, "map_t map_list[] = {\n");
      map_read_filename(filename, PHASE_MAPSTRUCT);
      fprintf(out_fp, "};\n");
      fprintf(out_fp, "\n");
      
    }
    if ( out_fp != NULL )
      fclose(out_fp);
  }
}