src/cmd/fsexam/src/fsexam-convcontent.c
author yz157939@agc105
Fri, 25 Apr 2008 17:13:57 +0800
changeset 149 0014c9b031e9
parent 147 8c4ef02c14b8
permissions -rw-r--r--
add fsexam 0.8.1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
147
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
     1
/*
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
     2
 * CDDL HEADER START
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
     3
 *
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
     5
 * Common Development and Distribution License (the "License").
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
     6
 * You may not use this file except in compliance with the License.
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
     7
 *
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    11
 * and limitations under the License.
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    12
 *
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    18
 *
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    19
 * CDDL HEADER END
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    20
 */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    21
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    22
/*
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    23
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    24
 * Use is subject to license terms.
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    25
 */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    26
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    27
#ifdef HAVE_CONFIG_H
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    28
#include <config.h>
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    29
#endif
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    30
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    31
#include <stdio.h>
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    32
#include <stdlib.h>
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    33
#include <string.h>
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    34
#include <sys/stat.h>
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    35
#include <sys/types.h>
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    36
#include <dirent.h>
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    37
#include <libgen.h>
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    38
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    39
#include <glib/gi18n.h>
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    40
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    41
#include "fsexam-header.h"
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    42
#include "encoding.h"
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    43
#include "fsexam-convcontent.h"
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    44
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    45
/* Store processed files, avoid loops */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    46
static GHashTable   *name_hash = NULL;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    47
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    48
static gboolean     convert_file (const gchar *name, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    49
                                  FSEXAM_setting *setting, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    50
                                  gboolean restore);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    51
static gboolean     convert_single_file (const gchar *fullpath, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    52
                                  FSEXAM_setting *setting);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    53
static void         puts_msg (FSEXAM_setting *setting, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    54
                                  const gchar *path, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    55
                                  const gchar *from_en, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    56
                                  const gchar *to_en);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    57
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    58
/*
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    59
 * wrapper for fsexam_log_puts() and display_msg ()
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    60
 */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    61
static void
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    62
puts_msg (FSEXAM_setting *setting, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    63
          const gchar *path, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    64
          const gchar *from_en, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    65
          const gchar *to_en)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    66
{
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    67
    if ((setting == NULL) || (path == NULL))
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    68
        return;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    69
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    70
    if (fsexam_errno == ERR_OK) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    71
        gchar *msg;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    72
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    73
        if ((from_en == NULL) || (to_en == NULL))
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    74
            return;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    75
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    76
        msg = g_strdup_printf (_("[Content] %s -> %s"), from_en, to_en);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    77
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    78
        fsexam_log_puts (setting->log_info, path, msg);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    79
        if (setting->display_msg)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    80
            setting->display_msg (path, msg);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    81
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    82
        g_free (msg);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    83
    }else{
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    84
        fsexam_log_puts (setting->log_info, path, NULL);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    85
        if (setting->display_msg)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    86
            setting->display_msg (path, fsexam_error_get_msg ());
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    87
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    88
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    89
    return;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    90
}
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    91
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    92
/*
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    93
 * Modify file contents, and write history info if needed
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    94
 */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    95
static gboolean
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    96
write_back_contents (FSEXAM_setting *setting, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    97
                     const gchar *fullpath, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    98
                     gchar *converted_contents, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
    99
                     short fid, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   100
                     short tid)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   101
{
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   102
    gboolean    ret = FALSE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   103
    gboolean    need_free = FALSE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   104
    gsize       length;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   105
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   106
    if ((NULL == setting) || (NULL == fullpath))
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   107
        return FALSE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   108
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   109
    if (converted_contents == NULL) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   110
        const gchar  *from_encoding = id2encoding (fid);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   111
        const gchar  *to_encoding = id2encoding (tid);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   112
        gchar        *contents = NULL;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   113
        gboolean     err;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   114
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   115
        if ((NULL == from_encoding) || (NULL == to_encoding))
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   116
            return FALSE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   117
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   118
        err = g_file_get_contents (fullpath, &contents, &length, NULL);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   119
        if (err && !contents) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   120
            fsexam_errno = ERR_CANNOT_READ;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   121
            goto done;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   122
        } else if (length == 0) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   123
            fsexam_errno = ERR_EMPTY_FILE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   124
            goto done;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   125
        }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   126
    
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   127
        converted_contents = g_convert (contents,
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   128
                                        length,
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   129
                                        to_encoding,
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   130
                                        from_encoding,
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   131
                                        NULL,
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   132
                                        NULL,
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   133
                                        NULL);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   134
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   135
        g_free (contents);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   136
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   137
        if (converted_contents == NULL) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   138
            fsexam_errno = ERR_CANNOT_CONVERT;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   139
            goto done;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   140
        }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   141
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   142
        need_free = TRUE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   143
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   144
        
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   145
    length = strlen (converted_contents);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   146
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   147
    if (g_file_set_contents (fullpath, converted_contents, length, NULL)) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   148
        ret = TRUE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   149
        ++setting->succ_num;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   150
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   151
        /* UNDO don't need write history */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   152
        if (! (setting->flags & FSEXAM_SETTING_FLAGS_UNDO)) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   153
            gboolean same_serial = TRUE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   154
            if (setting->flags & FSEXAM_SETTING_FLAGS_DIFF_SERIAL) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   155
                setting->flags &= ~FSEXAM_SETTING_FLAGS_DIFF_SERIAL;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   156
                same_serial = FALSE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   157
            }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   158
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   159
            fsexam_history_put (setting->hist_info, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   160
                            ConvContent, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   161
                            fullpath,
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   162
                            fid,
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   163
                            tid,
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   164
                            same_serial);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   165
        }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   166
    }else{
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   167
        ++setting->fail_num;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   168
        fsexam_errno = ERR_CANNOT_WRITE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   169
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   170
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   171
done:
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   172
    if (need_free)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   173
        g_free (converted_contents);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   174
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   175
    return ret;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   176
}
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   177
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   178
/*
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   179
 * Restore single one file. Won't care about follow or recursive 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   180
 */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   181
static gboolean
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   182
restore_single_file (const gchar *fullpath, FSEXAM_setting *setting)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   183
{
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   184
    gboolean    ret = FALSE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   185
    Hist_item   *item = NULL;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   186
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   187
    if ((NULL == fullpath) || (NULL == setting))
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   188
        return FALSE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   189
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   190
    fsexam_errno = ERR_OK;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   191
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   192
    if (! setting->pref->dry_run  /* special type don't support dryrun */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   193
            && setting->pref->special 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   194
            && fsexam_special_convert_content (fullpath, setting, TRUE)) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   195
        ++setting->succ_num;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   196
        return TRUE;    
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   197
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   198
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   199
    item = fsexam_history_search (setting->hist_info, fullpath, FALSE);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   200
    if (item == NULL) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   201
        fsexam_errno = ERR_HIST_NO_ITEM;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   202
        ++setting->ignore_num;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   203
        goto done;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   204
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   205
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   206
    ret = write_back_contents (setting, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   207
                               fullpath, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   208
                               NULL, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   209
                               item->to_encoding, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   210
                               item->from_encoding);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   211
    
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   212
done:
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   213
    puts_msg (setting, fullpath, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   214
              item ? id2encoding (item->to_encoding) : NULL, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   215
              item ? id2encoding (item->from_encoding) : NULL);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   216
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   217
    return ret;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   218
}
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   219
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   220
/*
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   221
 * Convert single one file, display candidate or dryrun.
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   222
 * Won't care follow or recursive
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   223
 */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   224
static gboolean
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   225
convert_single_file (const gchar *fullpath, FSEXAM_setting *setting)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   226
{
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   227
    Score       score;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   228
    Encoding    *encoding = NULL;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   229
    gboolean    ret = FALSE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   230
    gboolean    err;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   231
    gsize       length;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   232
    gchar       *contents = NULL;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   233
    gchar       *sample_contents = NULL;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   234
    gboolean    need_free_contents = FALSE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   235
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   236
    if ((NULL == fullpath) || (NULL == setting))
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   237
        return FALSE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   238
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   239
    fsexam_errno = ERR_OK;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   240
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   241
    if (! file_validate_for_contentconv (fullpath, setting)) {  
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   242
        goto done;      /* fsexam_errno has been set, goto log */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   243
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   244
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   245
    if (! setting->pref->dry_run
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   246
            && setting->pref->special 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   247
            && fsexam_special_convert_content (fullpath, setting, FALSE)) { 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   248
        ++setting->succ_num;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   249
        return TRUE;    
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   250
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   251
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   252
    /* 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   253
     * handle encoding auto detection.
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   254
     * And fsexam_is_plain_text/file(1) need these encodings 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   255
     */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   256
    if (setting->pref->auto_detect) { 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   257
        GList *detected_encoding;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   258
        
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   259
        detected_encoding = file_encoding_detect (fullpath, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   260
                                                  DEFAULT_DETECTING_FLAG);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   261
        setting->pref->encode_list = fsexam_encoding_add_auto (
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   262
                                                setting->pref->encode_list, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   263
                                                detected_encoding);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   264
        auto_encoding_free (detected_encoding);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   265
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   266
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   267
    if (! fsexam_is_plain_text (fullpath, setting)) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   268
        /* This func need auto detected encoding */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   269
        fsexam_errno = ERR_FILE_TYPE_NOT_SUPPORT;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   270
        goto done;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   271
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   272
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   273
    /* plain text now */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   274
    err = g_file_get_contents (fullpath, &contents, &length, NULL);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   275
    if (err && !contents) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   276
        fsexam_errno = ERR_CANNOT_READ;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   277
        goto done;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   278
    } else if (length == 0) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   279
        fsexam_errno = ERR_EMPTY_FILE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   280
        goto done;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   281
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   282
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   283
    sample_contents = get_sample_text (contents, &length);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   284
    score = fsexam_encoding_decode (setting->pref->encode_list,
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   285
                                    ConvContent,
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   286
                                    sample_contents,
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   287
                                    length,
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   288
                                    setting->pref->force);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   289
    g_free (contents);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   290
    g_free (sample_contents);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   291
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   292
    need_free_contents = TRUE;      /* need free contents in encoding_list */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   293
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   294
    if (setting->pref->dry_run){    /* dry run */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   295
        ret = fsexam_dryrun_puts (setting->dryrun_info, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   296
                                  fullpath, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   297
                                  score, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   298
                                  setting->pref->encode_list, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   299
                                  ConvContent); 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   300
        ret ? ++setting->succ_num : ++setting->fail_num;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   301
    } else {                        /* real convert */  
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   302
        gint  index = 0;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   303
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   304
        if ((score == FAIL) || (score == ORIGINAL)){
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   305
            fsexam_errno = (score == FAIL) ? ERR_NO_PROPER_ENCODING 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   306
                                           : ERR_CONTENT_UTF8_ALREADY;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   307
            goto done;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   308
        }   
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   309
       
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   310
        if (setting->gold_index != -1) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   311
            index = setting->gold_index;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   312
        } else if (setting->pref->auto_conversion) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   313
            index = fsexam_encoding_get_first_index (
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   314
                                            setting->pref->encode_list);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   315
        } else {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   316
            index = setting->get_index (setting->pref->encode_list, FALSE);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   317
        }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   318
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   319
        if (-1 == index)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   320
            goto done;              /* cancel the selection */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   321
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   322
        encoding = (Encoding *)g_list_nth_data (setting->pref->encode_list, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   323
                                                index);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   324
        if (NULL == encoding){
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   325
            fsexam_errno = ERR_ENCODING_INDEX_INVALID;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   326
            goto done;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   327
        }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   328
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   329
        ret = write_back_contents (setting, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   330
                                   fullpath, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   331
                                   NULL,
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   332
                                   encoding->encodingID, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   333
                                   encoding2id ("UTF-8"));
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   334
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   335
 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   336
    goto cleanup;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   337
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   338
done:
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   339
    ++setting->ignore_num;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   340
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   341
cleanup:
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   342
    if (!setting->pref->dry_run) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   343
        puts_msg (setting, fullpath, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   344
                  encoding ? id2encoding (encoding->encodingID) : NULL, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   345
                  "UTF-8");
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   346
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   347
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   348
    if (setting->pref->auto_detect)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   349
        setting->pref->encode_list = fsexam_encoding_remove_auto (
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   350
                                               setting->pref->encode_list);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   351
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   352
    if (need_free_contents)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   353
        fsexam_encoding_cleanup_content (setting->pref->encode_list);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   354
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   355
    return ret;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   356
}
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   357
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   358
/* 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   359
 * Convert given file, handling various flags also
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   360
 */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   361
static gboolean
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   362
convert_file (const gchar *name, FSEXAM_setting *setting, gboolean restore)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   363
{
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   364
    gchar    *abs_path = get_abs_path (name);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   365
    gboolean ret = FALSE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   366
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   367
    if ((abs_path == NULL) || (setting == NULL)) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   368
        goto done;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   369
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   370
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   371
    /* Global hash pointer */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   372
    if (g_hash_table_lookup (name_hash, abs_path)) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   373
        ret = TRUE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   374
        goto done;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   375
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   376
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   377
    g_hash_table_insert (name_hash, g_strdup (abs_path), (gpointer)-1);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   378
    ++setting->total_num;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   379
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   380
    if (restore) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   381
        restore_single_file (abs_path, setting);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   382
    }else{
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   383
        convert_single_file (abs_path, setting);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   384
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   385
    
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   386
    if (setting->pref->follow 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   387
            && g_file_test (abs_path, G_FILE_TEST_IS_SYMLINK)) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   388
        /* Symlink file */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   389
        gchar    *target = get_abs_path_for_symlink_target (abs_path);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   390
        ++setting->ignore_num;      /* ignore symlink file itself */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   391
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   392
        if (target == NULL)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   393
            goto done;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   394
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   395
        convert_file (target, setting, restore);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   396
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   397
        g_free (target);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   398
    }else if (setting->pref->recursive 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   399
            && g_file_test (abs_path, G_FILE_TEST_IS_DIR)) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   400
        const gchar *filename = NULL;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   401
        GDir        *dp = g_dir_open (abs_path, 0, NULL);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   402
        ++setting->ignore_num;      /* ignore directory file itself */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   403
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   404
        if (dp == NULL)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   405
            goto done;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   406
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   407
        while ((filename = g_dir_read_name (dp)) != NULL) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   408
            gchar *childname = g_strdup_printf ("%s/%s", abs_path, filename);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   409
            convert_file (childname, setting, restore);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   410
            g_free (childname);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   411
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   412
            if (setting->flags & FSEXAM_SETTING_FLAGS_STOP)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   413
                break;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   414
        }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   415
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   416
        g_dir_close (dp);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   417
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   418
    
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   419
    ret = TRUE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   420
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   421
done:
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   422
    g_free (abs_path);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   423
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   424
    return ret;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   425
}
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   426
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   427
static void
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   428
dryrun_convert_contents (GSList *slist, FSEXAM_setting *setting)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   429
{
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   430
    if ((NULL == slist) || (NULL == setting))
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   431
        return;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   432
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   433
    while (slist != NULL) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   434
        Dryrun_item *item = slist->data;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   435
        
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   436
        ++setting->passin_num;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   437
        ++setting->total_num;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   438
       
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   439
        write_back_contents (setting, item->path, NULL, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   440
                             encoding2id (item->encoding), 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   441
                             encoding2id ("UTF-8"));
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   442
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   443
        puts_msg (setting, item->path,  item->encoding, "UTF-8");
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   444
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   445
        slist = slist->next;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   446
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   447
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   448
    return;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   449
}
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   450
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   451
static gboolean
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   452
_convert_or_restore_contents (FSEXAM_setting *setting, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   453
                              GList *list, 
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   454
                              gboolean restore)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   455
{
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   456
    if ((list == NULL) || (setting == NULL))
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   457
        return FALSE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   458
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   459
    name_hash = g_hash_table_new_full (
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   460
                    g_str_hash,
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   461
                    g_str_equal,
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   462
                    (GDestroyNotify) g_free,
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   463
                    (GDestroyNotify) NULL);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   464
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   465
    if (name_hash == NULL) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   466
        g_print (_("Can't new hash table.\n"));
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   467
        return FALSE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   468
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   469
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   470
    fsexam_setting_reset_stats (setting);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   471
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   472
    setting->passin_num = g_list_length (list);     /* passin No. of files */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   473
    setting->flags |= FSEXAM_SETTING_FLAGS_DIFF_SERIAL;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   474
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   475
    while (list) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   476
        convert_file ((char *)list->data, setting, restore);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   477
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   478
        if (setting->flags & FSEXAM_SETTING_FLAGS_STOP)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   479
            break;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   480
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   481
        list = g_list_next (list);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   482
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   483
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   484
    setting->flags = 0;     /* clear all flags */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   485
    setting->display_stats (setting);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   486
    fsexam_log_flush (setting->log_info);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   487
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   488
    g_hash_table_destroy (name_hash);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   489
    name_hash = NULL;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   490
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   491
    return TRUE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   492
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   493
}
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   494
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   495
/*----------- Public API ---------------------*/
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   496
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   497
/*
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   498
 * Convert single file
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   499
 */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   500
gboolean
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   501
fsexam_convert_content (FSEXAM_setting *setting, const gchar *filename)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   502
{   
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   503
    GList    *list = NULL;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   504
    gboolean ret;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   505
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   506
    if ((filename == NULL) || (setting == NULL))
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   507
        return FALSE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   508
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   509
    list = g_list_prepend (list, g_strdup (filename));
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   510
    ret = fsexam_convert_content_batch (setting, list);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   511
    fsexam_list_free (list);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   512
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   513
    return ret;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   514
}
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   515
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   516
/*
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   517
 * Convert multiple files
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   518
 */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   519
gboolean
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   520
fsexam_convert_content_batch (FSEXAM_setting *setting, GList *list)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   521
{
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   522
    return _convert_or_restore_contents (setting, list, FALSE);    
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   523
}
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   524
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   525
/*
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   526
 * Restore file content
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   527
 */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   528
gboolean
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   529
fsexam_restore_content (FSEXAM_setting *setting, GList *list)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   530
{
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   531
    return _convert_or_restore_contents (setting, list, TRUE);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   532
}
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   533
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   534
/*
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   535
 * Scenario based conversion: convert file content according to
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   536
 * previous dryrun result.
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   537
 */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   538
gboolean
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   539
fsexam_convert_scenario_for_content (FSEXAM_setting *setting)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   540
{
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   541
    g_return_val_if_fail (setting != NULL, FALSE);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   542
    GSList   *slist = NULL;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   543
    gboolean ret;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   544
   
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   545
    fsexam_setting_reset_stats (setting);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   546
    setting->flags |= FSEXAM_SETTING_FLAGS_DIFF_SERIAL;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   547
    
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   548
    /* construct file list from dryrun result */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   549
    ret = fsexam_dryrun_process (setting->dryrun_info, &slist);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   550
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   551
    if ((! ret) || (NULL == slist)) {
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   552
        fsexam_log_puts (setting->log_info, NULL, NULL);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   553
        if (setting->display_msg)
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   554
            setting->display_msg (NULL, fsexam_error_get_msg ());
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   555
        setting->display_stats (setting);       /* display stats infor */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   556
        fsexam_log_flush (setting->log_info);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   557
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   558
        return FALSE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   559
    }
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   560
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   561
    dryrun_convert_contents (slist, setting);   /* real convert */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   562
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   563
    fsexam_dryrun_item_slist_free (slist);  /* free file list just create */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   564
    setting->flags = 0;                     /* clear all flags */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   565
    setting->display_stats (setting);       /* display stats infor */
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   566
    fsexam_log_flush (setting->log_info);
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   567
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   568
    return TRUE;
8c4ef02c14b8 replace new version of fsexam, old version 0.3.1 is not used any more
yz157939@agc105
parents:
diff changeset
   569
}