~ubuntu-branches/ubuntu/maverick/librapi2/maverick

« back to all changes in this revision

Viewing changes to tools/pmv.c

  • Committer: Bazaar Package Importer
  • Author(s): Volker Christian
  • Date: 2004-03-25 15:38:55 UTC
  • Revision ID: james.westby@ubuntu.com-20040325153855-bcjmhydo8rufdgsv
Tags: upstream-0.8.9
ImportĀ upstreamĀ versionĀ 0.8.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: pmv.c,v 1.5 2003/05/28 06:37:48 twogood Exp $ */
 
2
#include "pcommon.h"
 
3
#include <rapi.h>
 
4
#include <synce_log.h>
 
5
#include <stdio.h>
 
6
#include <stdlib.h>
 
7
#include <string.h>
 
8
#include <unistd.h>
 
9
 
 
10
static void show_usage(const char* name)
 
11
{
 
12
        fprintf(stderr,
 
13
                        "Syntax:\n"
 
14
                        "\n"
 
15
                        "\t%s [-d LEVEL] [-h] SOURCE DESTINATION\n"
 
16
                        "\n"
 
17
                        "\t-d LEVEL     Set debug log level\n"
 
18
                        "\t                 0 - No logging (default)\n"
 
19
                        "\t                 1 - Errors only\n"
 
20
                        "\t                 2 - Errors and warnings\n"
 
21
                        "\t                 3 - Everything\n"
 
22
                        "\t-h           Show this help message\n"
 
23
                        "\tSOURCE       The current filename\n"
 
24
                        "\tDESTINATION  The new filename\n",
 
25
                        name);
 
26
}
 
27
 
 
28
static bool handle_parameters(int argc, char** argv, char** source, char** dest)
 
29
{
 
30
        int c;
 
31
        int log_level = SYNCE_LOG_LEVEL_LOWEST;
 
32
 
 
33
        while ((c = getopt(argc, argv, "d:h")) != -1)
 
34
        {
 
35
                switch (c)
 
36
                {
 
37
                        case 'd':
 
38
                                log_level = atoi(optarg);
 
39
                                break;
 
40
                        
 
41
                        case 'h':
 
42
                        default:
 
43
                                show_usage(argv[0]);
 
44
                                return false;
 
45
                }
 
46
        }
 
47
 
 
48
        synce_log_set_level(log_level);
 
49
 
 
50
        if ((argc - optind) != 2)
 
51
        {
 
52
                fprintf(stderr, "%s: You need to specify source and destination file names on command line\n\n", argv[0]);
 
53
                show_usage(argv[0]);
 
54
                return false;
 
55
        }
 
56
                
 
57
        *source = strdup(argv[optind++]);
 
58
        *dest   = strdup(argv[optind++]);
 
59
 
 
60
        return true;
 
61
}
 
62
 
 
63
int main(int argc, char** argv)
 
64
{
 
65
        int result = 1;
 
66
        char* source = NULL;
 
67
        char* dest = NULL;
 
68
        HRESULT hr;
 
69
        WCHAR* wide_source = NULL;
 
70
        WCHAR* wide_dest = NULL;
 
71
        
 
72
        if (!handle_parameters(argc, argv, &source, &dest))
 
73
                goto exit;
 
74
 
 
75
        hr = CeRapiInit();
 
76
 
 
77
        if (FAILED(hr))
 
78
        {
 
79
                fprintf(stderr, "%s: Unable to initialize RAPI: %s\n", 
 
80
                                argv[0],
 
81
                                synce_strerror(hr));
 
82
                goto exit;
 
83
        }
 
84
 
 
85
        convert_to_backward_slashes(source);
 
86
        wide_source = wstr_from_ascii(source);
 
87
        wide_source = adjust_remote_path(wide_source, true);
 
88
 
 
89
        convert_to_backward_slashes(dest);
 
90
        wide_dest   = wstr_from_ascii(dest);
 
91
        wide_dest   = adjust_remote_path(wide_dest, true);
 
92
 
 
93
        if (!CeMoveFile(wide_source, wide_dest))
 
94
        {
 
95
                fprintf(stderr, "%s: Cannot move '%s' to '%s': %s\n", 
 
96
                                argv[0],
 
97
                                source,
 
98
                                dest,
 
99
                                synce_strerror(CeGetLastError()));
 
100
                goto exit;
 
101
        }
 
102
 
 
103
        result = 0;
 
104
 
 
105
exit:
 
106
        wstr_free_string(wide_source);
 
107
        wstr_free_string(wide_dest);
 
108
 
 
109
        if (source)
 
110
                free(source);
 
111
 
 
112
        if (dest)
 
113
                free(dest);
 
114
 
 
115
        CeRapiUninit();
 
116
        return result;
 
117
}