Remove unneeded dependency on glib-2.2.x by g_printf() & <glib/gprintf.h>
[captive.git] / src / client / cmdline / file_info.c
1 /* $Id$
2  * client cmdline interface GnomeVFSFileInfo utils for libcaptive
3  * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 #include <glib/gmessages.h>
23 #include <glib/gerror.h>
24 #include <libgnomevfs/gnome-vfs-file-info.h>
25 #include <glib/gstrfuncs.h>
26 #include <stdio.h>
27
28
29 #include "file_info.h"  /* self */
30
31
32 GQuark cmdline_file_info_error_quark(void)
33 {
34 GQuark r=0;
35
36         if (!r)
37                 r=g_quark_from_static_string("cmdline-file_info");
38
39         return r;
40 }
41
42
43 void file_info_dump_line(const GnomeVFSFileInfo *file_info,GError **errp)
44 {
45 const gchar *file_type,*file_perms;
46 gchar *file_size;
47
48         g_return_if_fail(!errp || !*errp);
49
50         switch (!(file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE) ? GNOME_VFS_FILE_TYPE_UNKNOWN : file_info->type) {
51                 case GNOME_VFS_FILE_TYPE_REGULAR:   file_type="FILE"; break;
52                 case GNOME_VFS_FILE_TYPE_DIRECTORY: file_type="DIR ";  break;
53                 case GNOME_VFS_FILE_TYPE_SOCKET:    file_type="DEV ";  break;
54                 default:                            file_type="??? ";  break;
55                 }
56
57         if (!(file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS))
58                 file_perms="???";
59         else if (file_info->permissions & GNOME_VFS_PERM_USER_WRITE)
60                 file_perms="r/w";
61         else
62                 file_perms="r/o";
63
64         if (file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE)
65                 file_size=g_strdup_printf("%8" GNOME_VFS_SIZE_FORMAT_STR,file_info->size);
66         else
67                 file_size=g_strdup_printf("%8s","???");
68
69         /*      type pm sz nm */
70         printf("[%s] %s %s %s\n",file_type,file_perms,file_size,file_info->name);
71         
72         g_free(file_size);
73 }