/* $Id$ * client cmdline interface GnomeVFSFileInfo utils for libcaptive * Copyright (C) 2003 Jan Kratochvil * * 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 #include #include #include #include #include #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 */ printf("[%s] %s %s %s\n",file_type,file_perms,file_size,file_info->name); g_free(file_size); } void file_info_dump_full(const GnomeVFSFileInfo *file_info,GError **errp) { g_return_if_fail(!errp || !*errp); printf("Filename: %s\n",file_info->name); fputs("File type: ",stdout); 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: puts("REGULAR"); break; case GNOME_VFS_FILE_TYPE_DIRECTORY: puts("DIRECTORY"); break; case GNOME_VFS_FILE_TYPE_SOCKET: puts("SOCKET"); break; default: puts("???"); break; } fputs("File size: ",stdout); if (file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) printf("%" GNOME_VFS_SIZE_FORMAT_STR "\n",file_info->size); else puts("???"); fputs("Block count: ",stdout); if (file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT) printf("%" GNOME_VFS_SIZE_FORMAT_STR "\n",file_info->block_count); else puts("???"); fputs("Writable?: ",stdout); if (!(file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS)) puts("???"); else if (file_info->permissions & GNOME_VFS_PERM_USER_WRITE) puts("read/write"); else puts("read/only"); fputs("Access-time (atime): ",stdout); if (!(file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_ATIME)) puts("???"); else fputs(ctime(&file_info->atime),stdout); fputs("Modification-time (mtime): ",stdout); if (!(file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MTIME)) puts("???"); else fputs(ctime(&file_info->mtime),stdout); fputs("Change-time (ctime): ",stdout); if (!(file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_CTIME)) puts("???"); else fputs(ctime(&file_info->ctime),stdout); }