/* Copyright (C) 2003 Mohammed Sameer. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #define EXIT(x) fprintf(stderr,"%s\n", x); exit(1); int main (int argc, char *argv[]) { FILE *in; GtkWidget *win, *view, *scrolledwin; GtkTextBuffer *buffer; GtkTextIter iter; gchar *buf = NULL; gulong size = 0; in = fopen ("/home/mohammed/quickbrown.txt", "r"); if (!in) { EXIT ("Can't open file")} while (getc (in) != EOF) { ++size; } if (size == 0) { fclose (in); EXIT ("The file is empty"); } buf = g_malloc (sizeof (gchar) * (size + 1)); if (!buf) { fclose (in); EXIT ("Run out of memory"); } fseek (in, 0, SEEK_SET); fread (buf, size, 1, in); fclose (in); gtk_init (&argc, &argv); win = gtk_window_new (GTK_WINDOW_TOPLEVEL); scrolledwin = gtk_scrolled_window_new (NULL, NULL); view = gtk_text_view_new (); gtk_container_add (GTK_CONTAINER (scrolledwin), view); gtk_container_add (GTK_CONTAINER (win), scrolledwin); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); gtk_text_buffer_get_iter_at_line (buffer, &iter, 0); gtk_text_buffer_insert (buffer, &iter, buf, size); gtk_widget_show_all (win); g_signal_connect (G_OBJECT (win), "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_main (); return 0; }