~ubuntu-branches/ubuntu/quantal/icu/quantal

« back to all changes in this revision

Viewing changes to source/tools/toolutil/toolutil.c

  • Committer: Package Import Robot
  • Author(s): Yves Arrouye
  • Date: 2002-03-03 15:31:13 UTC
  • Revision ID: package-import@ubuntu.com-20020303153113-3ssceqlq45xbmbnc
Tags: upstream-2.0-2.1pre20020303
ImportĀ upstreamĀ versionĀ 2.0-2.1pre20020303

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
*******************************************************************************
 
3
*
 
4
*   Copyright (C) 1999-2000, International Business Machines
 
5
*   Corporation and others.  All Rights Reserved.
 
6
*
 
7
*******************************************************************************
 
8
*   file name:  toolutil.c
 
9
*   encoding:   US-ASCII
 
10
*   tab size:   8 (not used)
 
11
*   indentation:4
 
12
*
 
13
*   created on: 1999nov19
 
14
*   created by: Markus W. Scherer
 
15
*
 
16
*   This file contains utility functions for ICU tools like genccode.
 
17
*/
 
18
 
 
19
#ifdef WIN32
 
20
#   define VC_EXTRALEAN
 
21
#   define WIN32_LEAN_AND_MEAN
 
22
#   include <windows.h>
 
23
#endif
 
24
#include "unicode/utypes.h"
 
25
#include "unicode/putil.h"
 
26
#include "cmemory.h"
 
27
#include "cstring.h"
 
28
#include "toolutil.h"
 
29
 
 
30
U_CFUNC const char *
 
31
getLongPathname(const char *pathname) {
 
32
#ifdef WIN32
 
33
    /* anticipate problems with "short" pathnames */
 
34
    static WIN32_FIND_DATA info;
 
35
    HANDLE file=FindFirstFile(pathname, &info);
 
36
    if(file!=INVALID_HANDLE_VALUE) {
 
37
        if(info.cAlternateFileName[0]!=0) {
 
38
            /* this file has a short name, get and use the long one */
 
39
            const char *basename=findBasename(pathname);
 
40
            if(basename!=pathname) {
 
41
                /* prepend the long filename with the original path */
 
42
                uprv_memmove(info.cFileName+(basename-pathname), info.cFileName, uprv_strlen(info.cFileName)+1);
 
43
                uprv_memcpy(info.cFileName, pathname, basename-pathname);
 
44
            }
 
45
            pathname=info.cFileName;
 
46
        }
 
47
        FindClose(file);
 
48
    }
 
49
#endif
 
50
    return pathname;
 
51
}
 
52
 
 
53
U_CFUNC const char *
 
54
findBasename(const char *filename) {
 
55
    const char *basename=uprv_strrchr(filename, U_FILE_SEP_CHAR);
 
56
    if(basename!=NULL) {
 
57
        return basename+1;
 
58
    } else {
 
59
        return filename;
 
60
    }
 
61
}