File: test-load.c

package info (click to toggle)
gtksourceview5 5.18.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,780 kB
  • sloc: ansic: 71,161; xml: 1,493; javascript: 866; perl: 216; sh: 144; java: 49; php: 48; yacc: 45; ruby: 38; ml: 36; python: 33; sql: 30; makefile: 23; cobol: 20; objc: 19; lisp: 19; fortran: 14; awk: 9; cpp: 8
file content (54 lines) | stat: -rw-r--r-- 1,336 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <gtksourceview/gtksource.h>
#include <stdlib.h>

static void
finished_cb (GObject      *object,
             GAsyncResult *result,
             gpointer      user_data)
{
  GError *error = NULL;
  GMainLoop *loop = user_data;

  if (!gtk_source_file_loader_load_finish (GTK_SOURCE_FILE_LOADER (object), result, &error))
    g_printerr ("Error loading file: %s\n", error->message);

  g_clear_error (&error);
  g_main_loop_quit (loop);
}

int
main (int argc,
      char *argv[])
{
  GFile *file = NULL;
  GMainLoop *loop = NULL;
  GtkSourceBuffer *buffer = NULL;
  GtkSourceFile *sfile = NULL;
  GtkSourceFileLoader *loader = NULL;

  if (argc != 2)
    {
      g_printerr ("usage: %s FILENAME\n", argv[0]);
      return EXIT_FAILURE;
    }

  gtk_source_init ();

  loop = g_main_loop_new (NULL, FALSE);
  file = g_file_new_for_commandline_arg (argv[1]);
  buffer = gtk_source_buffer_new (NULL);
  sfile = gtk_source_file_new ();
  gtk_source_file_set_location (sfile, file);
  loader = gtk_source_file_loader_new (buffer, sfile);

  gtk_source_file_loader_load_async (loader, G_PRIORITY_DEFAULT, NULL, NULL, NULL, NULL, finished_cb, loop);

  g_main_loop_run (loop);

  g_object_unref (loader);
  g_object_unref (sfile);
  g_object_unref (buffer);
  g_object_unref (file);
  g_main_loop_unref (loop);
  return EXIT_SUCCESS;
}