Update German translation
[glib.git] / tests / gio-ls.c
blob9ae74d4760b5633c305ea4288c3dd430269ed68a
2 #include <gio/gio.h>
4 #define GETTEXT_PACKAGE "gio-ls"
5 #define N_(s) (s)
6 #define _(s) (s)
8 enum
10 SHOW_ALL,
11 SHOW_LONG
14 static void print_path (const gchar* path, guint32 flags);
16 static gboolean show_all = FALSE;
17 static gboolean show_long = FALSE;
19 int
20 main (int argc, char *argv[])
23 GOptionContext *context = NULL;
24 static GOptionEntry options[] =
26 {"all", 'a', 0, G_OPTION_ARG_NONE, &show_all,
27 N_("do not hide entries"), NULL },
28 {"long", 'l', 0, G_OPTION_ARG_NONE, &show_long,
29 N_("use a long listing format"), NULL },
30 { NULL }
32 GError *error = NULL;
33 int i;
35 context = g_option_context_new(_("[FILE...]"));
36 g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
38 if (!g_option_context_parse (context, &argc, &argv, &error))
40 g_print ("%s", error->message);
41 g_error_free (error);
44 else
46 for (i = 1; i < argc; i++)
48 print_path (argv[i], (show_all ? SHOW_ALL : 0) | (show_long ? SHOW_LONG : 0));
52 g_option_context_free(context);
53 return 0;
56 static void
57 print_path (const gchar* path,
58 guint32 flags)
60 GFile *top;
61 const gchar *short_attrs = G_FILE_ATTRIBUTE_STANDARD_NAME;
62 const gchar *long_attrs = G_FILE_ATTRIBUTE_OWNER_USER "," G_FILE_ATTRIBUTE_OWNER_GROUP "," \
63 "access:*,std:*";
64 const gchar *attrs;
66 if (flags & SHOW_LONG)
67 attrs = long_attrs;
68 else
69 attrs = short_attrs;
71 top = g_file_new_for_path (path);
72 if (top)
74 GFileInfo *info;
75 GError *error = NULL;
76 GFileEnumerator *enumerator = g_file_enumerate_children (top, attrs,
77 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error);
78 if (error)
80 g_print ("%s", error->message);
81 g_error_free (error);
83 if (!enumerator)
84 return;
86 while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL)
88 const gchar *name = g_file_info_get_name (info);
90 if (flags & SHOW_LONG)
92 const gchar *val;
94 g_print ("%c%c%c%c ",
95 g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY ? 'd' : '-',
96 g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ) ? 'r' : '-',
97 g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE) ? 'w' : '-',
98 g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE) ? 'x' : '-');
100 val = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_USER);
101 g_print ("\t%15s", val ? val : "?user?");
103 val = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_GROUP);
104 g_print ("\t%15s", val ? val : "?group?");
107 g_print ("\t%s\n", name ? name : "?noname?");
109 g_object_unref (info);
112 g_object_unref (top);