Re: is this correct way to open file in buffer?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 01/30/2013 07:39 AM, Rudra Banerjee wrote:
Dear friends, I am trying hard to get rid of file reading and editing (as
evident from my previous post) Here is a small code where I tried to open
my file in a buffer and scan. Its small, 50 line code. I will be grateful
if anybody kindly have a look and tell if this is really opening the file
from buffer or still using the file. Please help.

I am coming late into this thread, so please forgive the following question(s).

I would like clarification "opening the file from buffer or still using the file".

In C, there is an api that allows us to open a file, and then associate a
memory location with the file's contents. There after, any modification to the
file, automatically shows in the buffer (i.e. no read() or re-read is
required) and any modification to the file buffer will automatically show on
disk (without the necessity of a write()).

Is this what you are trying to do ?

If yes, then the below will not accomplish this. The C api is to do a standard
open(2) and then a mmap(2) to associate the file's buffer to a fixed memory
location - I am happy to supply more details upon a confirmation.

All the best,

- -Greg

void open_file(GtkWidget *widget, gpointer data){ GScanner *scanner; 
GHashTable *table; char* fd; gsize length; GError* error=NULL; GtkWidget
*dialog; //, *entry; GtkFileFilter *filter; dialog =
gtk_file_chooser_dialog_new("Open File", NULL, 
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, 
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);

filter = gtk_file_filter_new(); gtk_file_filter_set_name(filter, "All files
(*.*)"); gtk_file_filter_add_pattern(filter, "*"); 
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);

filter = gtk_file_filter_new(); gtk_file_filter_set_name(filter, "Bibtex
file (*.bib)"); gtk_file_filter_add_pattern(filter, "*.bib"); 
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); 
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);

if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { filename =
gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); 
gtk_list_store_clear (store); g_file_get_contents(filename, &fd, &length ,
&error); g_assert(!error);

scanner = g_scanner_new (NULL); g_scanner_input_text (scanner, fd,
CHAR_BUFF);

table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); 
do { g_hash_table_remove_all (table); parse_entry (scanner, table); 
output_entry (table);

g_scanner_peek_next_token (scanner); } while (scanner->next_token !=
G_TOKEN_EOF && scanner->next_token != G_TOKEN_ERROR);


/* finsish parsing */ g_scanner_destroy (scanner); g_hash_table_destroy
(table);

gtk_label_set_text(GTK_LABEL(flabel), filename); 
gtk_widget_destroy(dialog); } else gtk_widget_destroy(dialog); }

_______________________________________________ gtk-app-devel-list mailing
list gtk-app-devel-list gnome org 
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



- -- 
+---------------------------------------------------------------------+

Please also check the log file at "/dev/null" for additional information.
                (from /var/log/Xorg.setup.log)

| Greg Hosler                                   ghosler redhat com    |
+---------------------------------------------------------------------+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.13 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlEIYewACgkQ404fl/0CV/TEZwCgrUZ9iXok5ykJLMAg0dn8QfAU
EDsAn2oAgw6aoXMG39yWQSu1RW7o8Gux
=b+22
-----END PGP SIGNATURE-----



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]