mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
a test program emulating some of 'ls' build it (currently on win32)
2007-12-09 Hans Breuer <hans@breuer.org> * tests/gio-ls.c : (new file) a test program emulating some of 'ls' * tests/makefile.msc.in : build it (currently on win32) svn path=/trunk/; revision=6079
This commit is contained in:
parent
50112b929e
commit
29ca2e26b0
@ -1,5 +1,8 @@
|
||||
2007-12-09 Hans Breuer <hans@breuer.org>
|
||||
|
||||
* tests/gio-ls.c : (new file) a test program emulating some of 'ls'
|
||||
* tests/makefile.msc.in : build it (currently on win32)
|
||||
|
||||
* **/makefile.msc glib/makefile.msc.in : removed -GD to compile
|
||||
with msvc9 (vs2008) with less complains
|
||||
|
||||
|
122
tests/gio-ls.c
Normal file
122
tests/gio-ls.c
Normal file
@ -0,0 +1,122 @@
|
||||
|
||||
#include <glib/goption.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#define GETTEXT_PACKAGE "gio-ls"
|
||||
#define N_(s) (s)
|
||||
#define _(s) (s)
|
||||
|
||||
enum
|
||||
{
|
||||
SHOW_ALL,
|
||||
SHOW_LONG
|
||||
};
|
||||
|
||||
static void print_path (const gchar* path, guint32 flags);
|
||||
|
||||
static gboolean show_all = FALSE;
|
||||
static gboolean show_long = FALSE;
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
|
||||
GOptionContext *context = NULL;
|
||||
static GOptionEntry options[] =
|
||||
{
|
||||
{"all", 'a', 0, G_OPTION_ARG_NONE, &show_all,
|
||||
N_("do not hide entries"), NULL },
|
||||
{"long", 'l', 0, G_OPTION_ARG_NONE, &show_long,
|
||||
N_("use a long listing format"), NULL },
|
||||
{ NULL }
|
||||
};
|
||||
GError *error = NULL;
|
||||
int i;
|
||||
|
||||
g_type_init ();
|
||||
|
||||
context = g_option_context_new(_("[FILE...]"));
|
||||
g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
|
||||
|
||||
if (!g_option_context_parse (context, &argc, &argv, &error))
|
||||
{
|
||||
g_print ("%s", error->message);
|
||||
g_error_free (error);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
print_path (argv[i], (show_all ? SHOW_ALL : 0) | (show_long ? SHOW_LONG : 0));
|
||||
}
|
||||
}
|
||||
|
||||
g_option_context_free(context);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
print_path (const gchar* path,
|
||||
guint32 flags)
|
||||
{
|
||||
GFile *top;
|
||||
const gchar *short_attrs = G_FILE_ATTRIBUTE_STD_NAME;
|
||||
const gchar *long_attrs = G_FILE_ATTRIBUTE_OWNER_USER "," G_FILE_ATTRIBUTE_OWNER_GROUP "," \
|
||||
"access:*,std:*";
|
||||
const gchar *attrs;
|
||||
|
||||
if (flags & SHOW_LONG)
|
||||
attrs = long_attrs;
|
||||
else
|
||||
attrs = short_attrs;
|
||||
|
||||
top = g_file_new_for_path (path);
|
||||
if (top)
|
||||
{
|
||||
GFileInfo *info;
|
||||
GError *error = NULL;
|
||||
GFileEnumerator *enumerator = g_file_enumerate_children (top, attrs,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error);
|
||||
if (error)
|
||||
{
|
||||
g_print ("%s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
if (!enumerator)
|
||||
return;
|
||||
|
||||
while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL)
|
||||
{
|
||||
const gchar *name = g_file_info_get_name (info);
|
||||
|
||||
if (flags & SHOW_LONG)
|
||||
{
|
||||
GFileAttributeValue *val = g_file_info_get_attribute (info, G_FILE_ATTRIBUTE_OWNER_USER);
|
||||
|
||||
g_print ("%c%c%c%c ",
|
||||
g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY ? 'd' : '-',
|
||||
g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ) ? 'r' : '-',
|
||||
g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE) ? 'w' : '-',
|
||||
g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE) ? 'x' : '-');
|
||||
|
||||
if (!val)
|
||||
g_print ("\t?");
|
||||
else if (val->type == G_FILE_ATTRIBUTE_TYPE_STRING)
|
||||
g_print ("\t%15s", val->u.string);
|
||||
|
||||
val = g_file_info_get_attribute (info, G_FILE_ATTRIBUTE_OWNER_GROUP);
|
||||
if (!val)
|
||||
g_print ("\t?");
|
||||
else if (val->type == G_FILE_ATTRIBUTE_TYPE_STRING)
|
||||
g_print ("\t%15s", val->u.string);
|
||||
}
|
||||
|
||||
g_print ("\t%s\n", name ? name : "<NULL>");
|
||||
|
||||
g_object_unref (info);
|
||||
}
|
||||
|
||||
g_object_unref (top);
|
||||
}
|
||||
}
|
@ -73,6 +73,8 @@ TESTS = \
|
||||
utf8-validate.exe \
|
||||
utf8-pointer.exe \
|
||||
uri-test.exe \
|
||||
\
|
||||
gio-ls.exe
|
||||
|
||||
DLLS = \
|
||||
libmoduletestplugin_a.dll \
|
||||
@ -84,6 +86,12 @@ all : $(TESTS) $(NONAUTOMATIC_TESTS) $(DLLS)
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
$(CC) $(CFLAGS) -Fe$@ $< ..\glib\glib-2.0.lib ..\gmodule\gmodule-2.0.lib ..\gthread\gthread-2.0.lib $(LDFLAGS) user32.lib /subsystem:console
|
||||
|
||||
gio-ls.exe : gio-ls.obj
|
||||
$(CC) $(CFLAGS) -Fe$@ gio-ls.obj \
|
||||
..\glib\glib-2.0.lib ..\gmodule\gmodule-2.0.lib ..\gthread\gthread-2.0.lib \
|
||||
..\gobject\gobject-2.0.lib ..\gio\gio-2.0.lib \
|
||||
$(LDFLAGS) user32.lib /subsystem:console
|
||||
|
||||
slice-test.exe : memchunks.obj slice-test.obj
|
||||
$(CC) $(CFLAGS) -Fe$@ memchunks.obj slice-test.obj \
|
||||
..\glib\glib-2.0.lib ..\gmodule\gmodule-2.0.lib ..\gthread\gthread-2.0.lib $(LDFLAGS) user32.lib /subsystem:console
|
||||
|
Loading…
Reference in New Issue
Block a user