source: trunk/third/gnome-vfs2/programs/gnomevfs-ls.c @ 20794

Revision 20794, 3.2 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r20793, which included commits to RCS files with non-trunk default branches.
RevLine 
[20793]1/* gnomevfs-ls.c - Test for open_dir(), read_dir() and close_dir() for gnome-vfs
2
3   Copyright (C) 2003, Red Hat
4
5   The Gnome Library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Library General Public License as
7   published by the Free Software Foundation; either version 2 of the
8   License, or (at your option) any later version.
9
10   The Gnome Library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Library General Public License for more details.
14
15   You should have received a copy of the GNU Library General Public
16   License along with the Gnome Library; see the file COPYING.LIB.  If not,
17   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18   Boston, MA 02111-1307, USA.
19
20   Author: Bastien Nocera <hadess@hadess.net>
21*/
22
23#include <locale.h>
24#include <libgnomevfs/gnome-vfs.h>
25
26char *directory;
27
28static void show_data (gpointer item, gpointer no_item);
29static void list (void);
30
31static const gchar *
32type_to_string (GnomeVFSFileType type)
33{
34        switch (type) {
35        case GNOME_VFS_FILE_TYPE_UNKNOWN:
36                return "Unknown";
37        case GNOME_VFS_FILE_TYPE_REGULAR:
38                return "Regular";
39        case GNOME_VFS_FILE_TYPE_DIRECTORY:
40                return "Directory";
41        case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK:
42                return "Symbolic Link";
43        case GNOME_VFS_FILE_TYPE_FIFO:
44                return "FIFO";
45        case GNOME_VFS_FILE_TYPE_SOCKET:
46                return "Socket";
47        case GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE:
48                return "Character device";
49        case GNOME_VFS_FILE_TYPE_BLOCK_DEVICE:
50                return "Block device";
51        default:
52                return "???";
53        }
54}
55
56static void
57show_data (gpointer item, gpointer no_item)
58{
59        GnomeVFSFileInfo *info;
60        char *path;
61
62        info = (GnomeVFSFileInfo *) item;
63
64        path = g_strconcat (directory, "/", info->name, NULL);
65
66        g_print ("%s\t%s%s%s\t(%s, %s)\tsize %ld\tmode %04o\n",
67                        info->name,
68                        GNOME_VFS_FILE_INFO_SYMLINK (info) ? " [link: " : "",
69                        GNOME_VFS_FILE_INFO_SYMLINK (info) ? info->symlink_name
70                        : "",
71                        GNOME_VFS_FILE_INFO_SYMLINK (info) ? " ]" : "",
72                        type_to_string (info->type),
73                        info->mime_type,
74                        (glong) info->size,
75                        info->permissions);
76
77        g_free (path);
78}
79
80void
81list (void)
82{
83        GnomeVFSResult result;
84        GnomeVFSFileInfo *info;
85        GnomeVFSDirectoryHandle *handle;
86
87        result = gnome_vfs_directory_open (&handle, directory,
88                        GNOME_VFS_FILE_INFO_GET_MIME_TYPE
89                        | GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
90
91        if (result != GNOME_VFS_OK)
92        {
93                g_print("Error opening: %s\n", gnome_vfs_result_to_string
94                                (result));
95                return;
96        }
97
98        info = gnome_vfs_file_info_new ();
99        while ((result = gnome_vfs_directory_read_next (handle, info)) == GNOME_VFS_OK) {
100                show_data ((gpointer) info, NULL);
101        }
102
103        gnome_vfs_file_info_unref (info);
104
105        if ((result != GNOME_VFS_OK) && (result != GNOME_VFS_ERROR_EOF)) {
106                g_print ("Error: %s\n", gnome_vfs_result_to_string (result));
107                return;
108        }
109}
110
111int
112main (int argc, char *argv[])
113{
114 
115        setlocale (LC_ALL, "");
116
117        gnome_vfs_init ();
118
119        if (argc > 1) {
120                directory = argv[1];
121        } else {
122                char *tmp;
123
124                tmp = g_get_current_dir ();
125                directory = gnome_vfs_escape_path_string (tmp);
126                g_free (tmp);
127        }
128
129        list ();
130
131        gnome_vfs_shutdown ();
132        return 0;
133}
Note: See TracBrowser for help on using the repository browser.