+Real implementation of 'captive-cmdline' client
[captive.git] / src / client / cmdline / file_info.c
diff --git a/src/client/cmdline/file_info.c b/src/client/cmdline/file_info.c
new file mode 100644 (file)
index 0000000..d659973
--- /dev/null
@@ -0,0 +1,73 @@
+/* $Id$
+ * client cmdline interface GnomeVFSFileInfo utils for libcaptive
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#include "config.h"
+
+#include <glib/gmessages.h>
+#include <glib/gerror.h>
+#include <libgnomevfs/gnome-vfs-file-info.h>
+#include <glib/gstrfuncs.h>
+#include <glib/gprintf.h>
+
+
+#include "file_info.h" /* self */
+
+
+GQuark cmdline_file_info_error_quark(void)
+{
+GQuark r=0;
+
+       if (!r)
+               r=g_quark_from_static_string("cmdline-file_info");
+
+       return r;
+}
+
+
+void file_info_dump_line(const GnomeVFSFileInfo *file_info,GError **errp)
+{
+const gchar *file_type,*file_perms;
+gchar *file_size;
+
+       g_return_if_fail(!errp || !*errp);
+
+       switch (!(file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE) ? GNOME_VFS_FILE_TYPE_UNKNOWN : file_info->type) {
+               case GNOME_VFS_FILE_TYPE_REGULAR:   file_type="FILE"; break;
+               case GNOME_VFS_FILE_TYPE_DIRECTORY: file_type="DIR ";  break;
+               case GNOME_VFS_FILE_TYPE_SOCKET:    file_type="DEV ";  break;
+               default:                            file_type="??? ";  break;
+               }
+
+       if (!(file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS))
+               file_perms="???";
+       else if (file_info->permissions & GNOME_VFS_PERM_USER_WRITE)
+               file_perms="r/w";
+       else
+               file_perms="r/o";
+
+       if (file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE)
+               file_size=g_strdup_printf("%8" GNOME_VFS_SIZE_FORMAT_STR,file_info->size);
+       else
+               file_size=g_strdup_printf("%8s","???");
+
+       /*      type pm sz nm */
+       g_printf("[%s] %s %s %s\n",file_type,file_perms,file_size,file_info->name);
+       
+       g_free(file_size);
+}