2001-12-11 23:51:01 +01:00
|
|
|
/* cygpath.cc -- convert pathnames between Windows and Unix format
|
2007-03-31 02:03:25 +02:00
|
|
|
Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
2010-01-07 13:08:11 +01:00
|
|
|
2006, 2007, 2008, 2009, 2010 Red Hat, Inc.
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2002-01-17 17:54:01 +01:00
|
|
|
#define NOCOMATTRIBUTE
|
|
|
|
|
|
|
|
#include <shlobj.h>
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2009-03-14 15:56:20 +01:00
|
|
|
#include <wchar.h>
|
|
|
|
#include <locale.h>
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <getopt.h>
|
2000-05-18 20:39:11 +02:00
|
|
|
#include <windows.h>
|
2000-04-11 04:57:25 +02:00
|
|
|
#include <io.h>
|
|
|
|
#include <sys/fcntl.h>
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <sys/cygwin.h>
|
2011-10-10 16:57:48 +02:00
|
|
|
#include <cygwin/version.h>
|
2000-04-13 07:23:30 +02:00
|
|
|
#include <ctype.h>
|
2004-02-21 05:51:15 +01:00
|
|
|
#include <errno.h>
|
2006-08-02 11:48:18 +02:00
|
|
|
#include <ddk/ntddk.h>
|
|
|
|
#include <ddk/winddk.h>
|
|
|
|
#include <ddk/ntifs.h>
|
2009-03-14 15:56:20 +01:00
|
|
|
#include "wide_path.h"
|
2010-08-28 13:22:37 +02:00
|
|
|
#include "loadlib.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
static char *prog_name;
|
2007-01-09 13:17:05 +01:00
|
|
|
static char *file_arg, *output_arg;
|
2000-04-13 07:23:30 +02:00
|
|
|
static int path_flag, unix_flag, windows_flag, absolute_flag;
|
2002-05-22 12:05:41 +02:00
|
|
|
static int shortname_flag, longname_flag;
|
|
|
|
static int ignore_flag, allusers_flag, output_flag;
|
2007-05-23 18:45:03 +02:00
|
|
|
static int mixed_flag, options_from_file_flag, mode_flag;
|
2009-05-17 13:16:12 +02:00
|
|
|
static UINT codepage;
|
2007-05-23 18:45:03 +02:00
|
|
|
|
2002-07-01 22:54:35 +02:00
|
|
|
static const char *format_type_arg;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2002-03-07 04:00:14 +01:00
|
|
|
static struct option long_options[] = {
|
|
|
|
{(char *) "absolute", no_argument, NULL, 'a'},
|
2002-07-01 22:54:35 +02:00
|
|
|
{(char *) "close", required_argument, NULL, 'c'},
|
|
|
|
{(char *) "dos", no_argument, NULL, 'd'},
|
|
|
|
{(char *) "file", required_argument, NULL, 'f'},
|
|
|
|
{(char *) "help", no_argument, NULL, 'h'},
|
|
|
|
{(char *) "ignore", no_argument, NULL, 'i'},
|
|
|
|
{(char *) "long-name", no_argument, NULL, 'l'},
|
|
|
|
{(char *) "mixed", no_argument, NULL, 'm'},
|
2004-02-25 02:23:20 +01:00
|
|
|
{(char *) "mode", no_argument, NULL, 'M'},
|
2002-03-07 04:00:14 +01:00
|
|
|
{(char *) "option", no_argument, NULL, 'o'},
|
|
|
|
{(char *) "path", no_argument, NULL, 'p'},
|
2002-07-01 22:54:35 +02:00
|
|
|
{(char *) "short-name", no_argument, NULL, 's'},
|
|
|
|
{(char *) "type", required_argument, NULL, 't'},
|
2002-03-07 04:00:14 +01:00
|
|
|
{(char *) "unix", no_argument, NULL, 'u'},
|
2011-10-10 16:57:48 +02:00
|
|
|
{(char *) "version", no_argument, NULL, 'V'},
|
2002-03-07 04:00:14 +01:00
|
|
|
{(char *) "windows", no_argument, NULL, 'w'},
|
|
|
|
{(char *) "allusers", no_argument, NULL, 'A'},
|
|
|
|
{(char *) "desktop", no_argument, NULL, 'D'},
|
2002-05-15 13:36:00 +02:00
|
|
|
{(char *) "homeroot", no_argument, NULL, 'H'},
|
2007-01-09 13:17:05 +01:00
|
|
|
{(char *) "mydocs", no_argument, NULL, 'O'},
|
2002-07-01 22:54:35 +02:00
|
|
|
{(char *) "smprograms", no_argument, NULL, 'P'},
|
|
|
|
{(char *) "sysdir", no_argument, NULL, 'S'},
|
|
|
|
{(char *) "windir", no_argument, NULL, 'W'},
|
2007-01-09 13:17:05 +01:00
|
|
|
{(char *) "folder", required_argument, NULL, 'F'},
|
2009-05-17 13:16:12 +02:00
|
|
|
{(char *) "codepage", required_argument, NULL, 'C'},
|
2002-03-07 04:00:14 +01:00
|
|
|
{0, no_argument, 0, 0}
|
2000-02-17 20:38:33 +01:00
|
|
|
};
|
|
|
|
|
2011-10-10 16:57:48 +02:00
|
|
|
static char options[] = "ac:df:hilmMopst:uVwAC:DHOPSWF:";
|
2002-09-15 17:19:49 +02:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
static void
|
2002-03-07 04:00:14 +01:00
|
|
|
usage (FILE * stream, int status)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-09-19 03:26:45 +02:00
|
|
|
if (!ignore_flag || !status)
|
|
|
|
fprintf (stream, "\
|
2011-10-10 16:57:48 +02:00
|
|
|
Usage: %1$s (-d|-m|-u|-w|-t TYPE) [-f FILE] [OPTION]... NAME...\n\
|
|
|
|
%1$s [-c HANDLE] \n\
|
|
|
|
%1$s [-ADHOPSW] \n\
|
|
|
|
%1$s [-F ID] \n\
|
|
|
|
\n\
|
2003-04-26 23:52:03 +02:00
|
|
|
Convert Unix and Windows format paths, or output system path information\n\
|
2003-09-11 04:56:40 +02:00
|
|
|
\n\
|
2002-07-01 22:54:35 +02:00
|
|
|
Output type options:\n\
|
2011-10-10 16:57:48 +02:00
|
|
|
\n\
|
2007-01-09 13:17:05 +01:00
|
|
|
-d, --dos print DOS (short) form of NAMEs (C:\\PROGRA~1\\)\n\
|
2002-07-01 22:54:35 +02:00
|
|
|
-m, --mixed like --windows, but with regular slashes (C:/WINNT)\n\
|
2007-01-09 13:17:05 +01:00
|
|
|
-M, --mode report on mode of file (binmode or textmode)\n\
|
|
|
|
-u, --unix (default) print Unix form of NAMEs (/cygdrive/c/winnt)\n\
|
2005-02-24 05:32:45 +01:00
|
|
|
-w, --windows print Windows form of NAMEs (C:\\WINNT)\n\
|
2002-07-01 22:54:35 +02:00
|
|
|
-t, --type TYPE print TYPE form: 'dos', 'mixed', 'unix', or 'windows'\n\
|
2011-10-10 16:57:48 +02:00
|
|
|
\n\
|
2002-06-19 04:09:41 +02:00
|
|
|
Path conversion options:\n\
|
2011-10-10 16:57:48 +02:00
|
|
|
\n\
|
2002-07-01 22:54:35 +02:00
|
|
|
-a, --absolute output absolute path\n\
|
2007-01-09 13:17:05 +01:00
|
|
|
-l, --long-name print Windows long form of NAMEs (with -w, -m only)\n\
|
|
|
|
-p, --path NAME is a PATH list (i.e., '/bin:/usr/bin')\n\
|
|
|
|
-s, --short-name print DOS (short) form of NAMEs (with -w, -m only)\n\
|
2009-05-17 13:16:12 +02:00
|
|
|
-C, --codepage CP print DOS, Windows, or mixed pathname in Windows\n\
|
|
|
|
codepage CP. CP can be a numeric codepage identifier,\n\
|
|
|
|
or one of the reserved words ANSI, OEM, or UTF8.\n\
|
2011-10-10 16:57:48 +02:00
|
|
|
If this option is missing, %1$s defaults to the\n\
|
2009-05-17 13:16:12 +02:00
|
|
|
character set defined by the current locale.\n\
|
2011-10-10 16:57:48 +02:00
|
|
|
\n\
|
2002-07-01 22:54:35 +02:00
|
|
|
System information:\n\
|
2011-10-10 16:57:48 +02:00
|
|
|
\n\
|
2007-01-09 13:17:05 +01:00
|
|
|
-A, --allusers use `All Users' instead of current user for -D, -O, -P\n\
|
|
|
|
-D, --desktop output `Desktop' directory and exit\n\
|
2002-07-01 22:54:35 +02:00
|
|
|
-H, --homeroot output `Profiles' directory (home root) and exit\n\
|
2007-01-09 13:17:05 +01:00
|
|
|
-O, --mydocs output `My Documents' directory and exit\n\
|
|
|
|
-P, --smprograms output Start Menu `Programs' directory and exit\n\
|
|
|
|
-S, --sysdir output system directory and exit\n\
|
|
|
|
-W, --windir output `Windows' directory and exit\n\
|
|
|
|
-F, --folder ID output special folder with numeric ID and exit\n\
|
2011-10-10 16:57:48 +02:00
|
|
|
", prog_name);
|
2004-03-15 22:34:12 +01:00
|
|
|
if (ignore_flag)
|
|
|
|
/* nothing to do */;
|
|
|
|
else if (stream != stdout)
|
|
|
|
fprintf(stream, "Try `%s --help' for more information.\n", prog_name);
|
|
|
|
else
|
2002-07-01 22:54:35 +02:00
|
|
|
{
|
2004-03-15 22:34:12 +01:00
|
|
|
fprintf (stream, "\
|
2011-10-10 16:57:48 +02:00
|
|
|
\n\
|
2002-06-19 04:09:41 +02:00
|
|
|
Other options:\n\
|
2011-10-10 16:57:48 +02:00
|
|
|
\n\
|
2002-07-01 22:54:35 +02:00
|
|
|
-f, --file FILE read FILE for input; use - to read from STDIN\n\
|
|
|
|
-o, --option read options from FILE as well (for use with --file)\n\
|
|
|
|
-c, --close HANDLE close HANDLE (for use in captured process)\n\
|
2007-01-09 13:17:05 +01:00
|
|
|
-i, --ignore ignore missing argument\n\
|
2002-07-01 22:54:35 +02:00
|
|
|
-h, --help output usage information and exit\n\
|
2011-10-10 16:57:48 +02:00
|
|
|
-V, --version output version information and exit\n\
|
|
|
|
\n");
|
2002-07-01 22:54:35 +02:00
|
|
|
}
|
2000-09-19 03:26:45 +02:00
|
|
|
exit (ignore_flag ? 0 : status);
|
|
|
|
}
|
|
|
|
|
2006-08-02 11:48:18 +02:00
|
|
|
static inline BOOLEAN
|
|
|
|
RtlAllocateUnicodeString (PUNICODE_STRING uni, ULONG size)
|
|
|
|
{
|
|
|
|
uni->Length = 0;
|
2010-09-06 11:48:55 +02:00
|
|
|
uni->MaximumLength = size / sizeof (WCHAR);
|
2006-08-02 11:48:18 +02:00
|
|
|
uni->Buffer = (WCHAR *) malloc (size);
|
|
|
|
return uni->Buffer != NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-06 11:48:55 +02:00
|
|
|
static inline BOOLEAN
|
|
|
|
RtlEqualUnicodePathPrefix (PUNICODE_STRING path, PUNICODE_STRING prefix,
|
|
|
|
BOOLEAN caseinsensitive)
|
|
|
|
{
|
|
|
|
UNICODE_STRING p;
|
|
|
|
|
|
|
|
p.Length = p.MaximumLength = prefix->Length < path->Length
|
|
|
|
? prefix->Length : path->Length;
|
|
|
|
p.Buffer = path->Buffer;
|
|
|
|
return RtlEqualUnicodeString (&p, prefix, caseinsensitive);
|
|
|
|
}
|
|
|
|
|
2009-05-17 13:16:12 +02:00
|
|
|
static size_t
|
|
|
|
my_wcstombs (char *dest, const wchar_t *src, size_t n)
|
|
|
|
{
|
|
|
|
if (codepage)
|
|
|
|
return WideCharToMultiByte (codepage, 0, src, -1, dest, n, NULL, NULL);
|
|
|
|
else
|
|
|
|
return wcstombs (dest, src, n);
|
|
|
|
}
|
|
|
|
|
2010-09-06 11:48:55 +02:00
|
|
|
#define HARDDISK_PREFIX L"\\Device\\Harddisk"
|
|
|
|
#define GLOBALROOT_PREFIX "\\\\.\\GLOBALROOT"
|
|
|
|
|
2006-08-02 11:48:18 +02:00
|
|
|
static char *
|
|
|
|
get_device_name (char *path)
|
|
|
|
{
|
|
|
|
UNICODE_STRING ntdev, tgtdev, ntdevdir;
|
|
|
|
ANSI_STRING ans;
|
|
|
|
OBJECT_ATTRIBUTES ntobj;
|
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE lnk, dir;
|
2010-09-06 11:48:55 +02:00
|
|
|
bool got_one = false;
|
2006-08-02 11:48:18 +02:00
|
|
|
char *ret = strdup (path);
|
|
|
|
PDIRECTORY_BASIC_INFORMATION odi = (PDIRECTORY_BASIC_INFORMATION)
|
|
|
|
alloca (4096);
|
|
|
|
BOOLEAN restart;
|
|
|
|
ULONG cont;
|
|
|
|
|
2010-09-06 11:48:55 +02:00
|
|
|
if (!strncasecmp (path, GLOBALROOT_PREFIX "\\", sizeof (GLOBALROOT_PREFIX)))
|
|
|
|
path += sizeof (GLOBALROOT_PREFIX) - 1;
|
2006-08-02 11:48:18 +02:00
|
|
|
if (strncasecmp (path, "\\Device\\", 8))
|
|
|
|
return ret;
|
|
|
|
|
2010-09-06 11:48:55 +02:00
|
|
|
if (!RtlAllocateUnicodeString (&ntdev, 65534))
|
2006-08-02 11:48:18 +02:00
|
|
|
return ret;
|
2010-09-06 11:48:55 +02:00
|
|
|
if (!RtlAllocateUnicodeString (&tgtdev, 65534))
|
2006-08-02 11:48:18 +02:00
|
|
|
return ret;
|
|
|
|
RtlInitAnsiString (&ans, path);
|
|
|
|
RtlAnsiStringToUnicodeString (&ntdev, &ans, FALSE);
|
|
|
|
|
|
|
|
/* First check if the given device name is a symbolic link itself. If so,
|
|
|
|
query it and use the new name as actual device name to search for in the
|
|
|
|
DOS device name directory. If not, just use the incoming device name. */
|
|
|
|
InitializeObjectAttributes (&ntobj, &ntdev, OBJ_CASE_INSENSITIVE, NULL, NULL);
|
|
|
|
status = ZwOpenSymbolicLinkObject (&lnk, SYMBOLIC_LINK_QUERY, &ntobj);
|
|
|
|
if (NT_SUCCESS (status))
|
|
|
|
{
|
|
|
|
status = ZwQuerySymbolicLinkObject (lnk, &tgtdev, NULL);
|
|
|
|
ZwClose (lnk);
|
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
goto out;
|
|
|
|
RtlCopyUnicodeString (&ntdev, &tgtdev);
|
|
|
|
}
|
2010-09-06 11:48:55 +02:00
|
|
|
else if (status != STATUS_OBJECT_TYPE_MISMATCH
|
|
|
|
&& status != STATUS_OBJECT_PATH_SYNTAX_BAD)
|
2006-08-02 11:48:18 +02:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; ++i)
|
|
|
|
{
|
|
|
|
/* There are two DOS device directories, the local and the global dir.
|
|
|
|
Try both, local first. */
|
|
|
|
RtlInitUnicodeString (&ntdevdir, i ? L"\\GLOBAL??" : L"\\??");
|
|
|
|
|
|
|
|
/* Open the directory... */
|
|
|
|
InitializeObjectAttributes (&ntobj, &ntdevdir, OBJ_CASE_INSENSITIVE,
|
|
|
|
NULL, NULL);
|
|
|
|
status = ZwOpenDirectoryObject (&dir, DIRECTORY_QUERY, &ntobj);
|
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* ...and scan it. */
|
|
|
|
for (restart = TRUE, cont = 0;
|
|
|
|
NT_SUCCESS (ZwQueryDirectoryObject (dir, odi, 4096, TRUE,
|
|
|
|
restart, &cont, NULL));
|
|
|
|
restart = FALSE)
|
|
|
|
{
|
|
|
|
/* For each entry check if it's a symbolic link. */
|
|
|
|
InitializeObjectAttributes (&ntobj, &odi->ObjectName,
|
|
|
|
OBJ_CASE_INSENSITIVE, dir, NULL);
|
|
|
|
status = ZwOpenSymbolicLinkObject (&lnk, SYMBOLIC_LINK_QUERY, &ntobj);
|
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
continue;
|
|
|
|
tgtdev.Length = 0;
|
|
|
|
tgtdev.MaximumLength = 512;
|
|
|
|
/* If so, query it and compare the target of the symlink with the
|
|
|
|
incoming device name. */
|
|
|
|
status = ZwQuerySymbolicLinkObject (lnk, &tgtdev, NULL);
|
|
|
|
ZwClose (lnk);
|
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
continue;
|
2010-09-06 11:48:55 +02:00
|
|
|
if (tgtdev.Length /* There's actually a symlink pointing to an
|
|
|
|
empty string: \??\GLOBALROOT -> "" */
|
|
|
|
&& RtlEqualUnicodePathPrefix (&ntdev, &tgtdev, TRUE))
|
2006-08-02 11:48:18 +02:00
|
|
|
{
|
|
|
|
/* If the comparison succeeds, the name of the directory entry is
|
|
|
|
a valid DOS device name, if prepended with "\\.\". Return that
|
|
|
|
valid DOS path. */
|
2010-09-06 11:48:55 +02:00
|
|
|
wchar_t *trailing = NULL;
|
|
|
|
if (ntdev.Length > tgtdev.Length)
|
|
|
|
trailing = ntdev.Buffer + tgtdev.Length / sizeof (WCHAR);
|
2006-08-02 11:48:18 +02:00
|
|
|
ULONG len = RtlUnicodeStringToAnsiSize (&odi->ObjectName);
|
2010-09-06 11:48:55 +02:00
|
|
|
if (trailing)
|
|
|
|
len += my_wcstombs (NULL, trailing, 0);
|
2010-01-07 18:19:12 +01:00
|
|
|
free (ret);
|
2006-08-02 11:48:18 +02:00
|
|
|
ret = (char *) malloc (len + 4);
|
|
|
|
strcpy (ret, "\\\\.\\");
|
|
|
|
ans.Length = 0;
|
|
|
|
ans.MaximumLength = len;
|
|
|
|
ans.Buffer = ret + 4;
|
|
|
|
RtlUnicodeStringToAnsiString (&ans, &odi->ObjectName, FALSE);
|
2010-09-06 11:48:55 +02:00
|
|
|
if (trailing)
|
|
|
|
my_wcstombs (ans.Buffer + ans.Length, trailing,
|
|
|
|
ans.MaximumLength - ans.Length);
|
|
|
|
ans.Buffer[ans.MaximumLength - 1] = '\0';
|
|
|
|
got_one = true;
|
2010-08-26 14:06:27 +02:00
|
|
|
/* Special case for local disks: It's most feasible if the
|
|
|
|
DOS device name reflects the DOS drive, so we check for this
|
|
|
|
explicitly and only return prematurely if so. */
|
|
|
|
if (ntdev.Length < wcslen (HARDDISK_PREFIX)
|
|
|
|
|| wcsncasecmp (ntdev.Buffer, HARDDISK_PREFIX, 8) != 0
|
|
|
|
|| (odi->ObjectName.Length == 2 * sizeof (WCHAR)
|
|
|
|
&& odi->ObjectName.Buffer[1] == L':'))
|
|
|
|
{
|
2010-09-06 11:48:55 +02:00
|
|
|
if (trailing)
|
|
|
|
{
|
|
|
|
/* If there's a trailing path, it's a perfectly valid
|
|
|
|
DOS pathname without the \\.\ prefix. Unless it's
|
|
|
|
longer than MAX_PATH - 1 in which case it needs
|
|
|
|
the \\?\ prefix. */
|
2010-12-06 14:40:24 +01:00
|
|
|
if ((len = strlen (ret + 4)) >= MAX_PATH)
|
2010-09-06 11:48:55 +02:00
|
|
|
ret[2] = '?';
|
|
|
|
else
|
|
|
|
memmove (ret, ret + 4, strlen (ret + 4) + 1);
|
|
|
|
}
|
2010-08-26 14:06:27 +02:00
|
|
|
ZwClose (dir);
|
|
|
|
goto out;
|
|
|
|
}
|
2006-08-02 11:48:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ZwClose (dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
free (tgtdev.Buffer);
|
|
|
|
free (ntdev.Buffer);
|
2010-09-06 11:48:55 +02:00
|
|
|
if (!got_one)
|
|
|
|
{
|
|
|
|
free (ret);
|
|
|
|
ret = (char *) malloc (sizeof (GLOBALROOT_PREFIX) + strlen (path));
|
|
|
|
if (ret)
|
|
|
|
stpcpy (stpcpy (ret, GLOBALROOT_PREFIX), path);
|
|
|
|
}
|
2006-08-02 11:48:18 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
get_device_paths (char *path)
|
|
|
|
{
|
|
|
|
char *sbuf;
|
|
|
|
char *ptr;
|
|
|
|
int n = 1;
|
|
|
|
|
|
|
|
ptr = path;
|
|
|
|
while ((ptr = strchr (ptr, ';')))
|
|
|
|
{
|
|
|
|
ptr++;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *paths[n];
|
|
|
|
DWORD acc = 0;
|
|
|
|
int i;
|
|
|
|
if (!n)
|
|
|
|
return strdup ("");
|
|
|
|
|
|
|
|
for (i = 0, ptr = path; ptr; i++)
|
|
|
|
{
|
|
|
|
char *next = ptr;
|
|
|
|
ptr = strchr (ptr, ';');
|
|
|
|
if (ptr)
|
|
|
|
*ptr++ = 0;
|
|
|
|
paths[i] = get_device_name (next);
|
|
|
|
acc += strlen (paths[i]) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sbuf = (char *) malloc (acc + 1);
|
|
|
|
if (sbuf == NULL)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s: out of memory\n", prog_name);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sbuf[0] = '\0';
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
strcat (strcat (sbuf, paths[i]), ";");
|
|
|
|
free (paths[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
strchr (sbuf, '\0')[-1] = '\0';
|
|
|
|
return sbuf;
|
|
|
|
}
|
|
|
|
|
2000-09-19 03:26:45 +02:00
|
|
|
static char *
|
|
|
|
get_short_paths (char *path)
|
|
|
|
{
|
2009-03-14 15:56:20 +01:00
|
|
|
wchar_t *sbuf;
|
|
|
|
wchar_t *sptr;
|
2000-09-19 03:26:45 +02:00
|
|
|
char *next;
|
|
|
|
char *ptr = path;
|
|
|
|
char *end = strrchr (path, 0);
|
|
|
|
DWORD acc = 0;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
while (ptr != NULL)
|
|
|
|
{
|
2002-03-07 04:00:14 +01:00
|
|
|
next = ptr;
|
|
|
|
ptr = strchr (ptr, ';');
|
|
|
|
if (ptr)
|
|
|
|
*ptr++ = 0;
|
2009-03-14 15:56:20 +01:00
|
|
|
wide_path wpath (next);
|
|
|
|
len = GetShortPathNameW (wpath, NULL, 0);
|
2003-06-12 22:40:58 +02:00
|
|
|
if (!len)
|
2002-03-07 04:00:14 +01:00
|
|
|
{
|
2011-10-10 16:57:48 +02:00
|
|
|
fprintf (stderr, "%s: cannot create short name of %s\n",
|
|
|
|
prog_name, next);
|
2002-03-07 04:00:14 +01:00
|
|
|
exit (2);
|
|
|
|
}
|
|
|
|
acc += len + 1;
|
2000-09-19 03:26:45 +02:00
|
|
|
}
|
2009-03-14 15:56:20 +01:00
|
|
|
sptr = sbuf = (wchar_t *) malloc ((acc + 1) * sizeof (wchar_t));
|
2000-09-19 03:26:45 +02:00
|
|
|
if (sbuf == NULL)
|
|
|
|
{
|
2002-03-07 04:00:14 +01:00
|
|
|
fprintf (stderr, "%s: out of memory\n", prog_name);
|
|
|
|
exit (1);
|
2000-09-19 03:26:45 +02:00
|
|
|
}
|
2002-03-07 04:00:14 +01:00
|
|
|
ptr = path;
|
|
|
|
for (;;)
|
|
|
|
{
|
2009-03-14 15:56:20 +01:00
|
|
|
wide_path wpath (ptr);
|
|
|
|
len = GetShortPathNameW (wpath, sptr, acc);
|
2003-06-12 22:40:58 +02:00
|
|
|
if (!len)
|
2002-03-07 04:00:14 +01:00
|
|
|
{
|
2011-10-10 16:57:48 +02:00
|
|
|
fprintf (stderr, "%s: cannot create short name of %s\n",
|
|
|
|
prog_name, ptr);
|
2002-03-07 04:00:14 +01:00
|
|
|
exit (2);
|
|
|
|
}
|
2000-09-19 03:26:45 +02:00
|
|
|
|
2002-03-07 04:00:14 +01:00
|
|
|
ptr = strrchr (ptr, 0);
|
2009-03-14 15:56:20 +01:00
|
|
|
sptr = wcsrchr (sptr, 0);
|
2002-03-07 04:00:14 +01:00
|
|
|
if (ptr == end)
|
|
|
|
break;
|
2009-03-14 15:56:20 +01:00
|
|
|
*sptr = L';';
|
2002-03-07 04:00:14 +01:00
|
|
|
++ptr, ++sptr;
|
2002-05-22 12:05:41 +02:00
|
|
|
acc -= len + 1;
|
2002-03-07 04:00:14 +01:00
|
|
|
}
|
2009-05-17 13:16:12 +02:00
|
|
|
len = my_wcstombs (NULL, sbuf, 0) + 1;
|
2009-03-14 15:56:20 +01:00
|
|
|
ptr = (char *) malloc (len);
|
|
|
|
if (ptr == NULL)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s: out of memory\n", prog_name);
|
|
|
|
exit (1);
|
|
|
|
}
|
2009-05-17 13:16:12 +02:00
|
|
|
my_wcstombs (ptr, sbuf, len);
|
2009-03-14 15:56:20 +01:00
|
|
|
return ptr;
|
2000-09-19 03:26:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
get_short_name (const char *filename)
|
|
|
|
{
|
2009-03-14 15:56:20 +01:00
|
|
|
wchar_t buf[32768];
|
|
|
|
char *sbuf;
|
|
|
|
wide_path wpath (filename);
|
|
|
|
DWORD len = GetShortPathNameW (wpath, buf, 32768);
|
2003-06-12 22:40:58 +02:00
|
|
|
if (!len)
|
2002-03-07 04:00:14 +01:00
|
|
|
{
|
2011-10-10 16:57:48 +02:00
|
|
|
fprintf (stderr, "%s: cannot create short name of %s\n",
|
|
|
|
prog_name, filename);
|
2002-03-07 04:00:14 +01:00
|
|
|
exit (2);
|
|
|
|
}
|
2009-05-17 13:16:12 +02:00
|
|
|
len = my_wcstombs (NULL, buf, 0) + 1;
|
2009-03-14 15:56:20 +01:00
|
|
|
sbuf = (char *) malloc (len);
|
2000-09-19 03:26:45 +02:00
|
|
|
if (sbuf == NULL)
|
2002-03-07 04:00:14 +01:00
|
|
|
{
|
|
|
|
fprintf (stderr, "%s: out of memory\n", prog_name);
|
|
|
|
exit (1);
|
|
|
|
}
|
2009-05-17 13:16:12 +02:00
|
|
|
my_wcstombs (sbuf, buf, len);
|
2009-03-14 15:56:20 +01:00
|
|
|
return sbuf;
|
2002-05-22 12:05:41 +02:00
|
|
|
}
|
|
|
|
|
2002-10-31 03:40:26 +01:00
|
|
|
static DWORD WINAPI
|
2009-03-14 15:56:20 +01:00
|
|
|
get_long_path_name_w32impl (LPCWSTR src, LPWSTR sbuf, DWORD)
|
2002-05-22 12:05:41 +02:00
|
|
|
{
|
2009-03-14 15:56:20 +01:00
|
|
|
wchar_t *buf1 = (wchar_t *) malloc (32768);
|
|
|
|
wchar_t *buf2 = (wchar_t *) malloc (32768);
|
|
|
|
wchar_t *ptr;
|
|
|
|
const wchar_t *pelem, *next;
|
|
|
|
WIN32_FIND_DATAW w32_fd;
|
|
|
|
DWORD len;
|
2002-10-31 03:40:26 +01:00
|
|
|
|
2009-03-14 15:56:20 +01:00
|
|
|
wcscpy (buf1, src);
|
|
|
|
*buf2 = L'\0';
|
2002-05-22 12:05:41 +02:00
|
|
|
pelem = src;
|
|
|
|
ptr = buf2;
|
|
|
|
while (pelem)
|
|
|
|
{
|
|
|
|
next = pelem;
|
2009-03-14 15:56:20 +01:00
|
|
|
if (*next == L'\\')
|
2002-05-22 12:05:41 +02:00
|
|
|
{
|
2009-03-14 15:56:20 +01:00
|
|
|
wcscat (ptr++, L"\\");
|
2002-05-22 12:05:41 +02:00
|
|
|
pelem++;
|
|
|
|
if (!*pelem)
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
2009-03-14 15:56:20 +01:00
|
|
|
pelem = wcschr (next, L'\\');
|
|
|
|
len = pelem ? (pelem++ - next) : wcslen (next);
|
|
|
|
wcsncpy (ptr, next, len);
|
|
|
|
ptr[len] = L'\0';
|
|
|
|
if (next[1] != L':' && wcscmp(next, L".") && wcscmp(next, L".."))
|
2002-05-22 12:05:41 +02:00
|
|
|
{
|
2007-03-31 02:03:25 +02:00
|
|
|
HANDLE h;
|
2009-03-14 15:56:20 +01:00
|
|
|
h = FindFirstFileW (buf2, &w32_fd);
|
2007-03-31 02:03:25 +02:00
|
|
|
if (h != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2009-03-14 15:56:20 +01:00
|
|
|
wcscpy (ptr, w32_fd.cFileName);
|
2007-03-31 02:03:25 +02:00
|
|
|
FindClose (h);
|
|
|
|
}
|
2002-05-22 12:05:41 +02:00
|
|
|
}
|
2009-03-14 15:56:20 +01:00
|
|
|
ptr += wcslen (ptr);
|
2002-05-22 12:05:41 +02:00
|
|
|
if (pelem)
|
|
|
|
{
|
|
|
|
*ptr++ = '\\';
|
|
|
|
*ptr = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sbuf)
|
2009-03-14 15:56:20 +01:00
|
|
|
wcscpy (sbuf, buf2);
|
2002-05-22 12:05:41 +02:00
|
|
|
SetLastError (0);
|
2009-03-14 15:56:20 +01:00
|
|
|
len = wcslen (buf2) + (sbuf ? 0 : 1);
|
|
|
|
free (buf1);
|
|
|
|
free (buf2);
|
|
|
|
return len;
|
2002-05-22 12:05:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2002-10-31 03:40:26 +01:00
|
|
|
get_long_name (const char *filename, DWORD& len)
|
2002-05-22 12:05:41 +02:00
|
|
|
{
|
2009-03-14 15:56:20 +01:00
|
|
|
char *sbuf;
|
|
|
|
wchar_t buf[32768];
|
2010-08-28 13:22:37 +02:00
|
|
|
static HINSTANCE k32 = GetModuleHandleW (L"kernel32.dll");
|
2009-03-14 15:56:20 +01:00
|
|
|
static DWORD (WINAPI *GetLongPathName) (LPCWSTR, LPWSTR, DWORD) =
|
|
|
|
(DWORD (WINAPI *) (LPCWSTR, LPWSTR, DWORD)) GetProcAddress (k32, "GetLongPathNameW");
|
2002-10-31 03:40:26 +01:00
|
|
|
if (!GetLongPathName)
|
|
|
|
GetLongPathName = get_long_path_name_w32impl;
|
2002-05-22 12:05:41 +02:00
|
|
|
|
2009-03-14 15:56:20 +01:00
|
|
|
wide_path wpath (filename);
|
|
|
|
len = GetLongPathName (wpath, buf, 32768);
|
2006-07-27 23:07:33 +02:00
|
|
|
if (len == 0)
|
2002-05-22 12:05:41 +02:00
|
|
|
{
|
2006-07-31 09:31:56 +02:00
|
|
|
DWORD err = GetLastError ();
|
|
|
|
|
|
|
|
if (err == ERROR_INVALID_PARAMETER)
|
2006-07-27 23:07:33 +02:00
|
|
|
{
|
2011-10-10 16:57:48 +02:00
|
|
|
fprintf (stderr, "%s: cannot create long name of %s\n",
|
|
|
|
prog_name, filename);
|
2006-07-27 23:07:33 +02:00
|
|
|
exit (2);
|
|
|
|
}
|
2006-07-31 09:31:56 +02:00
|
|
|
else if (err == ERROR_FILE_NOT_FOUND)
|
2009-03-14 15:56:20 +01:00
|
|
|
get_long_path_name_w32impl (wpath, buf, 32768);
|
2006-07-31 09:31:56 +02:00
|
|
|
else
|
2007-03-31 02:03:25 +02:00
|
|
|
{
|
2009-03-14 15:56:20 +01:00
|
|
|
buf[0] = L'\0';
|
|
|
|
wcsncat (buf, wpath, 32767);
|
2006-07-31 09:31:56 +02:00
|
|
|
}
|
2002-05-22 12:05:41 +02:00
|
|
|
}
|
2009-05-17 13:16:12 +02:00
|
|
|
len = my_wcstombs (NULL, buf, 0);
|
2002-10-31 03:40:26 +01:00
|
|
|
sbuf = (char *) malloc (len + 1);
|
|
|
|
if (!sbuf)
|
2002-05-22 12:05:41 +02:00
|
|
|
{
|
|
|
|
fprintf (stderr, "%s: out of memory\n", prog_name);
|
|
|
|
exit (1);
|
|
|
|
}
|
2009-05-17 13:16:12 +02:00
|
|
|
my_wcstombs (sbuf, buf, len + 1);
|
2009-03-14 15:56:20 +01:00
|
|
|
return sbuf;
|
2002-05-22 12:05:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2002-10-31 03:40:26 +01:00
|
|
|
get_long_paths (char *path)
|
2002-05-22 12:05:41 +02:00
|
|
|
{
|
2002-10-31 03:40:26 +01:00
|
|
|
char *sbuf;
|
|
|
|
char *ptr;
|
|
|
|
int n = 1;
|
|
|
|
|
|
|
|
ptr = path;
|
|
|
|
while ((ptr = strchr (ptr, ';')))
|
2002-03-07 04:00:14 +01:00
|
|
|
{
|
2002-10-31 03:40:26 +01:00
|
|
|
ptr++;
|
|
|
|
n++;
|
2002-03-07 04:00:14 +01:00
|
|
|
}
|
2002-10-31 03:40:26 +01:00
|
|
|
|
|
|
|
char *paths[n];
|
|
|
|
DWORD acc = 0;
|
|
|
|
int i;
|
|
|
|
if (!n)
|
|
|
|
return strdup ("");
|
|
|
|
|
|
|
|
for (i = 0, ptr = path; ptr; i++)
|
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
char *next = ptr;
|
|
|
|
ptr = strchr (ptr, ';');
|
|
|
|
if (ptr)
|
|
|
|
*ptr++ = 0;
|
|
|
|
paths[i] = get_long_name (next, len);
|
|
|
|
acc += len + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sbuf = (char *) malloc (acc + 1);
|
2002-05-22 12:05:41 +02:00
|
|
|
if (sbuf == NULL)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s: out of memory\n", prog_name);
|
|
|
|
exit (1);
|
|
|
|
}
|
2002-10-31 03:40:26 +01:00
|
|
|
|
|
|
|
sbuf[0] = '\0';
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
strcat (strcat (sbuf, paths[i]), ";");
|
|
|
|
free (paths[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
strchr (sbuf, '\0')[-1] = '\0';
|
|
|
|
return sbuf;
|
2002-05-22 12:05:41 +02:00
|
|
|
}
|
|
|
|
|
2002-06-19 04:09:41 +02:00
|
|
|
static void
|
|
|
|
convert_slashes (char* name)
|
|
|
|
{
|
|
|
|
while ((name = strchr (name, '\\')) != NULL)
|
|
|
|
{
|
|
|
|
if (*name == '\\')
|
|
|
|
*name = '/';
|
|
|
|
name++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-09 13:17:05 +01:00
|
|
|
static bool
|
|
|
|
get_special_folder (char* path, int id)
|
|
|
|
{
|
2009-10-15 13:40:02 +02:00
|
|
|
WCHAR wpath[MAX_PATH];
|
|
|
|
|
|
|
|
path[0] = '\0';
|
|
|
|
wpath[0] = L'\0';
|
2007-01-09 13:17:05 +01:00
|
|
|
LPITEMIDLIST pidl = 0;
|
|
|
|
if (SHGetSpecialFolderLocation (NULL, id, &pidl) != S_OK)
|
|
|
|
return false;
|
2009-10-15 13:40:02 +02:00
|
|
|
if (!SHGetPathFromIDListW (pidl, wpath) || !wpath[0])
|
2007-01-09 13:17:05 +01:00
|
|
|
return false;
|
2009-10-15 13:40:02 +02:00
|
|
|
my_wcstombs (path, wpath, PATH_MAX);
|
2007-01-09 13:17:05 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-05-22 12:05:41 +02:00
|
|
|
static void
|
2007-05-23 18:45:03 +02:00
|
|
|
do_sysfolders (char option)
|
2002-05-22 12:05:41 +02:00
|
|
|
{
|
2009-10-15 13:40:02 +02:00
|
|
|
char *buf, buf1[PATH_MAX], buf2[PATH_MAX];
|
2010-01-16 11:25:58 +01:00
|
|
|
char *tmp = NULL;
|
2009-10-15 13:40:02 +02:00
|
|
|
WCHAR wbuf[MAX_PATH];
|
2002-05-22 12:05:41 +02:00
|
|
|
DWORD len = MAX_PATH;
|
2009-10-15 13:40:02 +02:00
|
|
|
WIN32_FIND_DATAW w32_fd;
|
2002-10-31 03:40:26 +01:00
|
|
|
HINSTANCE k32;
|
2009-10-15 13:40:02 +02:00
|
|
|
BOOL (*GetProfilesDirectoryAPtrW) (LPWSTR, LPDWORD) = 0;
|
2002-10-31 03:40:26 +01:00
|
|
|
|
2002-05-22 12:05:41 +02:00
|
|
|
buf = buf1;
|
2007-01-09 13:17:05 +01:00
|
|
|
buf[0] = 0;
|
2002-05-22 12:05:41 +02:00
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case 'D':
|
2009-10-15 13:40:02 +02:00
|
|
|
get_special_folder (buf, allusers_flag ? CSIDL_COMMON_DESKTOPDIRECTORY
|
|
|
|
: CSIDL_DESKTOPDIRECTORY);
|
2002-05-22 12:05:41 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'P':
|
2009-10-15 13:40:02 +02:00
|
|
|
get_special_folder (buf, allusers_flag ? CSIDL_COMMON_PROGRAMS
|
|
|
|
: CSIDL_PROGRAMS);
|
2007-01-09 13:17:05 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'O':
|
2009-10-15 13:40:02 +02:00
|
|
|
get_special_folder (buf, allusers_flag ? CSIDL_COMMON_DOCUMENTS
|
|
|
|
: CSIDL_PERSONAL);
|
2007-01-09 13:17:05 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'F':
|
|
|
|
{
|
|
|
|
int val = -1, len = -1;
|
|
|
|
if (!(sscanf (output_arg, "%i%n", &val, &len) == 1
|
|
|
|
&& len == (int) strlen (output_arg) && val >= 0))
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s: syntax error in special folder ID %s\n",
|
|
|
|
prog_name, output_arg);
|
|
|
|
exit (1);
|
|
|
|
}
|
2007-03-31 02:03:25 +02:00
|
|
|
get_special_folder (buf, val);
|
2007-01-09 13:17:05 +01:00
|
|
|
}
|
2002-05-22 12:05:41 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'H':
|
2010-08-28 13:22:37 +02:00
|
|
|
k32 = LoadLibrary ("userenv.dll");
|
2002-10-31 03:40:26 +01:00
|
|
|
if (k32)
|
2009-10-15 13:40:02 +02:00
|
|
|
GetProfilesDirectoryAPtrW = (BOOL (*) (LPWSTR, LPDWORD))
|
|
|
|
GetProcAddress (k32, "GetProfilesDirectoryW");
|
|
|
|
if (GetProfilesDirectoryAPtrW)
|
|
|
|
(*GetProfilesDirectoryAPtrW) (wbuf, &len);
|
2002-05-22 12:05:41 +02:00
|
|
|
else
|
|
|
|
{
|
2009-10-15 13:40:02 +02:00
|
|
|
GetWindowsDirectoryW (wbuf, MAX_PATH);
|
|
|
|
wcscat (wbuf, L"\\Profiles");
|
2002-05-22 12:05:41 +02:00
|
|
|
}
|
2009-10-15 13:40:02 +02:00
|
|
|
my_wcstombs (buf, wbuf, PATH_MAX);
|
2002-05-22 12:05:41 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'S':
|
2009-10-15 13:40:02 +02:00
|
|
|
{
|
|
|
|
HANDLE fh;
|
|
|
|
|
|
|
|
GetSystemDirectoryW (wbuf, MAX_PATH);
|
|
|
|
if ((fh = FindFirstFileW (wbuf, &w32_fd)) != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
FindClose (fh);
|
|
|
|
wcscpy (wcsrchr (wbuf, L'\\') + 1, w32_fd.cFileName);
|
|
|
|
}
|
|
|
|
my_wcstombs (buf, wbuf, PATH_MAX);
|
|
|
|
}
|
2002-05-22 12:05:41 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'W':
|
2009-10-15 13:40:02 +02:00
|
|
|
GetWindowsDirectoryW (wbuf, MAX_PATH);
|
|
|
|
my_wcstombs (buf, wbuf, PATH_MAX);
|
2002-05-22 12:05:41 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
usage (stderr, 1);
|
|
|
|
}
|
|
|
|
|
2007-01-09 13:17:05 +01:00
|
|
|
if (!buf[0])
|
|
|
|
{
|
2011-10-10 16:57:48 +02:00
|
|
|
fprintf (stderr, "%s: failed to retrieve special folder path\n",
|
|
|
|
prog_name);
|
2007-01-09 13:17:05 +01:00
|
|
|
}
|
|
|
|
else if (!windows_flag)
|
2002-05-22 12:05:41 +02:00
|
|
|
{
|
2008-03-12 13:47:09 +01:00
|
|
|
if (cygwin_conv_path (CCP_WIN_A_TO_POSIX | CCP_RELATIVE, buf, buf2,
|
2009-03-14 15:56:20 +01:00
|
|
|
PATH_MAX))
|
2004-02-21 05:51:15 +01:00
|
|
|
fprintf (stderr, "%s: error converting \"%s\" - %s\n",
|
|
|
|
prog_name, buf, strerror (errno));
|
|
|
|
else
|
|
|
|
buf = buf2;
|
2002-05-22 12:05:41 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (shortname_flag)
|
2010-01-16 11:25:58 +01:00
|
|
|
tmp = buf = get_short_name (buf);
|
2002-06-19 04:09:41 +02:00
|
|
|
if (mixed_flag)
|
2010-01-16 11:25:58 +01:00
|
|
|
convert_slashes (buf);
|
2002-05-22 12:05:41 +02:00
|
|
|
}
|
|
|
|
printf ("%s\n", buf);
|
2010-01-16 11:25:58 +01:00
|
|
|
if (tmp)
|
|
|
|
free (tmp);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2004-02-25 02:23:20 +01:00
|
|
|
static void
|
|
|
|
report_mode (char *filename)
|
|
|
|
{
|
|
|
|
switch (cygwin_internal (CW_GET_BINMODE, filename))
|
|
|
|
{
|
|
|
|
case O_BINARY:
|
|
|
|
printf ("%s: binary\n", filename);
|
|
|
|
break;
|
|
|
|
case O_TEXT:
|
|
|
|
printf ("%s: text\n", filename);
|
|
|
|
break;
|
|
|
|
default:
|
2011-10-10 16:57:48 +02:00
|
|
|
fprintf (stderr, "%s: file '%s' - %s\n", prog_name,
|
|
|
|
filename, strerror (errno));
|
2004-02-25 02:23:20 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-11 04:57:25 +02:00
|
|
|
static void
|
2007-05-23 18:45:03 +02:00
|
|
|
do_pathconv (char *filename)
|
2000-04-11 04:57:25 +02:00
|
|
|
{
|
2010-01-07 18:19:12 +01:00
|
|
|
char *buf = NULL, *tmp;
|
|
|
|
wchar_t *buf2 = NULL;
|
2002-10-31 03:40:26 +01:00
|
|
|
DWORD len;
|
2008-03-12 13:47:09 +01:00
|
|
|
ssize_t err;
|
2010-02-22 18:40:46 +01:00
|
|
|
bool print_tmp = false;
|
2008-03-12 13:47:09 +01:00
|
|
|
cygwin_conv_path_t conv_func =
|
2009-03-14 15:56:20 +01:00
|
|
|
(unix_flag ? CCP_WIN_A_TO_POSIX
|
|
|
|
: (path_flag ? CCP_POSIX_TO_WIN_A
|
|
|
|
: CCP_POSIX_TO_WIN_W))
|
2008-03-12 13:47:09 +01:00
|
|
|
| (absolute_flag ? CCP_ABSOLUTE : CCP_RELATIVE);
|
2000-04-11 04:57:25 +02:00
|
|
|
|
2002-03-07 04:00:14 +01:00
|
|
|
if (!path_flag)
|
2001-12-26 18:46:12 +01:00
|
|
|
{
|
2002-10-31 03:40:26 +01:00
|
|
|
len = strlen (filename);
|
|
|
|
if (len)
|
2009-03-14 15:56:20 +01:00
|
|
|
len = 32768;
|
2002-10-31 03:40:26 +01:00
|
|
|
else if (ignore_flag)
|
|
|
|
exit (0);
|
|
|
|
else
|
2002-03-07 04:00:14 +01:00
|
|
|
{
|
2011-10-10 16:57:48 +02:00
|
|
|
fprintf (stderr, "%s: can't convert empty path\n",
|
|
|
|
prog_name);
|
2002-10-31 03:40:26 +01:00
|
|
|
exit (1);
|
2002-03-07 04:00:14 +01:00
|
|
|
}
|
2001-12-26 18:46:12 +01:00
|
|
|
}
|
2000-04-11 04:57:25 +02:00
|
|
|
else
|
2008-03-12 13:47:09 +01:00
|
|
|
len = cygwin_conv_path_list (conv_func, filename, NULL, 0);
|
2000-04-11 04:57:25 +02:00
|
|
|
|
|
|
|
buf = (char *) malloc (len);
|
2009-03-14 15:56:20 +01:00
|
|
|
if (!unix_flag && !path_flag)
|
|
|
|
buf2 = (wchar_t *) malloc (len * sizeof (wchar_t));
|
2000-04-11 04:57:25 +02:00
|
|
|
if (buf == NULL)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s: out of memory\n", prog_name);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path_flag)
|
|
|
|
{
|
2008-03-12 13:47:09 +01:00
|
|
|
err = cygwin_conv_path_list (conv_func, filename, buf, len);
|
|
|
|
if (!unix_flag)
|
2002-03-07 04:00:14 +01:00
|
|
|
{
|
2004-02-21 05:51:15 +01:00
|
|
|
if (err)
|
|
|
|
/* oops */;
|
2010-01-07 18:19:12 +01:00
|
|
|
buf = get_device_paths (tmp = buf);
|
|
|
|
free (tmp);
|
2002-03-07 04:00:14 +01:00
|
|
|
if (shortname_flag)
|
2010-01-07 18:19:12 +01:00
|
|
|
{
|
|
|
|
buf = get_short_paths (tmp = buf);
|
|
|
|
free (tmp);
|
|
|
|
}
|
2002-05-22 12:05:41 +02:00
|
|
|
if (longname_flag)
|
2010-01-07 18:19:12 +01:00
|
|
|
{
|
|
|
|
buf = get_long_paths (tmp = buf);
|
|
|
|
free (tmp);
|
|
|
|
}
|
2002-06-07 21:25:26 +02:00
|
|
|
if (mixed_flag)
|
2010-01-16 11:25:58 +01:00
|
|
|
convert_slashes (buf);
|
2002-03-07 04:00:14 +01:00
|
|
|
}
|
2004-02-21 05:51:15 +01:00
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s: error converting \"%s\" - %s\n",
|
|
|
|
prog_name, filename, strerror (errno));
|
|
|
|
exit (1);
|
|
|
|
}
|
2000-04-11 04:57:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-14 15:56:20 +01:00
|
|
|
err = cygwin_conv_path (conv_func, filename,
|
|
|
|
unix_flag ? (void *) buf : (void *) buf2, len);
|
2004-02-21 05:51:15 +01:00
|
|
|
if (err)
|
2002-03-07 04:00:14 +01:00
|
|
|
{
|
2004-02-21 05:51:15 +01:00
|
|
|
fprintf (stderr, "%s: error converting \"%s\" - %s\n",
|
|
|
|
prog_name, filename, strerror (errno));
|
2002-03-07 04:00:14 +01:00
|
|
|
exit (1);
|
|
|
|
}
|
2002-05-22 12:05:41 +02:00
|
|
|
if (!unix_flag)
|
|
|
|
{
|
2009-05-17 13:16:12 +02:00
|
|
|
my_wcstombs (buf, buf2, 32768);
|
2010-01-07 18:19:12 +01:00
|
|
|
buf = get_device_name (tmp = buf);
|
|
|
|
free (tmp);
|
2003-02-12 23:48:13 +01:00
|
|
|
if (shortname_flag)
|
2010-01-07 18:19:12 +01:00
|
|
|
{
|
|
|
|
buf = get_short_name (tmp = buf);
|
|
|
|
free (tmp);
|
|
|
|
}
|
2003-02-12 23:48:13 +01:00
|
|
|
if (longname_flag)
|
2010-01-07 18:19:12 +01:00
|
|
|
{
|
|
|
|
buf = get_long_name (tmp = buf, len);
|
|
|
|
free (tmp);
|
|
|
|
}
|
|
|
|
tmp = buf;
|
2009-04-15 12:00:40 +02:00
|
|
|
if (strncmp (buf, "\\\\?\\", 4) == 0)
|
2009-03-14 15:56:20 +01:00
|
|
|
{
|
2010-09-06 11:48:55 +02:00
|
|
|
len = 0;
|
|
|
|
if (buf[5] == ':')
|
|
|
|
len = 4;
|
|
|
|
else if (!strncmp (buf + 4, "UNC\\", 4))
|
2009-04-15 12:00:40 +02:00
|
|
|
len = 6;
|
2010-09-06 11:48:55 +02:00
|
|
|
if (len && strlen (buf) < MAX_PATH + len)
|
2009-04-15 12:00:40 +02:00
|
|
|
{
|
2010-02-13 12:41:53 +01:00
|
|
|
tmp += len;
|
2009-04-15 12:00:40 +02:00
|
|
|
if (len == 6)
|
2010-02-13 12:41:53 +01:00
|
|
|
*tmp = '\\';
|
2010-02-22 18:40:46 +01:00
|
|
|
print_tmp = true;
|
2009-04-15 12:00:40 +02:00
|
|
|
}
|
2009-03-14 15:56:20 +01:00
|
|
|
}
|
2009-04-15 12:00:40 +02:00
|
|
|
if (mixed_flag)
|
2010-02-13 12:41:53 +01:00
|
|
|
convert_slashes (tmp);
|
2002-05-22 12:05:41 +02:00
|
|
|
}
|
2000-04-11 04:57:25 +02:00
|
|
|
}
|
|
|
|
|
2010-02-22 18:40:46 +01:00
|
|
|
puts (print_tmp ? tmp : buf);
|
2010-01-07 18:19:12 +01:00
|
|
|
if (buf2)
|
|
|
|
free (buf2);
|
|
|
|
if (buf)
|
2010-02-13 12:41:53 +01:00
|
|
|
free (buf);
|
2000-04-11 04:57:25 +02:00
|
|
|
}
|
|
|
|
|
2002-03-07 04:00:14 +01:00
|
|
|
static void
|
|
|
|
print_version ()
|
|
|
|
{
|
2011-10-10 16:57:48 +02:00
|
|
|
printf ("cygpath (cygwin) %d.%d.%d\n"
|
|
|
|
"Path Conversion Utility\n"
|
|
|
|
"Copyright (C) 1998 - %s Red Hat, Inc.\n"
|
|
|
|
"This is free software; see the source for copying conditions. There is NO\n"
|
|
|
|
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
|
|
|
|
CYGWIN_VERSION_DLL_MAJOR / 1000,
|
|
|
|
CYGWIN_VERSION_DLL_MAJOR % 1000,
|
|
|
|
CYGWIN_VERSION_DLL_MINOR,
|
|
|
|
strrchr (__DATE__, ' ') + 1);
|
2002-03-07 04:00:14 +01:00
|
|
|
}
|
|
|
|
|
2007-05-23 18:45:03 +02:00
|
|
|
static int
|
|
|
|
do_options (int argc, char **argv, int from_file)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-03-07 04:00:14 +01:00
|
|
|
int c, o = 0;
|
2000-02-17 20:38:33 +01:00
|
|
|
path_flag = 0;
|
2007-05-23 18:45:03 +02:00
|
|
|
unix_flag = 0;
|
2000-02-17 20:38:33 +01:00
|
|
|
windows_flag = 0;
|
2000-09-19 03:26:45 +02:00
|
|
|
shortname_flag = 0;
|
2002-05-22 12:05:41 +02:00
|
|
|
longname_flag = 0;
|
2002-06-07 21:25:26 +02:00
|
|
|
mixed_flag = 0;
|
2000-09-19 03:26:45 +02:00
|
|
|
ignore_flag = 0;
|
2002-01-17 17:54:01 +01:00
|
|
|
allusers_flag = 0;
|
|
|
|
output_flag = 0;
|
2004-02-25 02:23:20 +01:00
|
|
|
mode_flag = 0;
|
2009-05-17 13:16:12 +02:00
|
|
|
codepage = 0;
|
2007-05-23 18:45:03 +02:00
|
|
|
if (!from_file)
|
|
|
|
options_from_file_flag = 0;
|
|
|
|
optind = 0;
|
2002-09-15 17:19:49 +02:00
|
|
|
while ((c = getopt_long (argc, argv, options,
|
2002-06-07 21:25:26 +02:00
|
|
|
long_options, (int *) NULL)) != EOF)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
switch (c)
|
|
|
|
{
|
2000-04-13 07:23:30 +02:00
|
|
|
case 'a':
|
|
|
|
absolute_flag = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
2007-05-23 18:45:03 +02:00
|
|
|
if (!optarg)
|
|
|
|
usage (stderr, 1);
|
2000-04-13 07:23:30 +02:00
|
|
|
CloseHandle ((HANDLE) strtoul (optarg, NULL, 16));
|
|
|
|
break;
|
|
|
|
|
2002-07-01 22:54:35 +02:00
|
|
|
case 'd':
|
|
|
|
windows_flag = 1;
|
|
|
|
shortname_flag = 1;
|
|
|
|
break;
|
|
|
|
|
2000-04-11 04:57:25 +02:00
|
|
|
case 'f':
|
2007-05-23 18:45:03 +02:00
|
|
|
if (from_file || !optarg)
|
|
|
|
usage (stderr, 1);
|
2000-04-11 04:57:25 +02:00
|
|
|
file_arg = optarg;
|
|
|
|
break;
|
|
|
|
|
2004-02-25 02:23:20 +01:00
|
|
|
case 'M':
|
|
|
|
mode_flag = 1;
|
|
|
|
break;
|
|
|
|
|
2000-04-13 07:23:30 +02:00
|
|
|
case 'o':
|
2007-05-23 18:45:03 +02:00
|
|
|
if (from_file)
|
|
|
|
usage (stderr, 1);
|
2000-04-13 07:23:30 +02:00
|
|
|
options_from_file_flag = 1;
|
|
|
|
break;
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
case 'p':
|
|
|
|
path_flag = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'u':
|
|
|
|
unix_flag = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'w':
|
|
|
|
windows_flag = 1;
|
|
|
|
break;
|
|
|
|
|
2002-07-01 22:54:35 +02:00
|
|
|
case 'm':
|
|
|
|
windows_flag = 1;
|
|
|
|
mixed_flag = 1;
|
|
|
|
break;
|
|
|
|
|
2002-05-22 12:05:41 +02:00
|
|
|
case 'l':
|
|
|
|
longname_flag = 1;
|
|
|
|
break;
|
|
|
|
|
2000-09-19 03:26:45 +02:00
|
|
|
case 's':
|
|
|
|
shortname_flag = 1;
|
|
|
|
break;
|
|
|
|
|
2007-05-23 18:45:03 +02:00
|
|
|
case 't':
|
|
|
|
if (!optarg)
|
2002-06-07 21:25:26 +02:00
|
|
|
usage (stderr, 1);
|
|
|
|
|
2002-07-01 22:54:35 +02:00
|
|
|
format_type_arg = (*optarg == '=') ? (optarg + 1) : (optarg);
|
|
|
|
if (strcasecmp (format_type_arg, "dos") == 0)
|
2002-10-31 03:40:26 +01:00
|
|
|
{
|
2007-05-23 18:45:03 +02:00
|
|
|
windows_flag = 1;
|
|
|
|
shortname_flag = 1;
|
2002-10-31 03:40:26 +01:00
|
|
|
}
|
2007-05-23 18:45:03 +02:00
|
|
|
else if (!strcasecmp (format_type_arg, "mixed"))
|
2002-10-31 03:40:26 +01:00
|
|
|
{
|
2007-05-23 18:45:03 +02:00
|
|
|
windows_flag = 1;
|
|
|
|
mixed_flag = 1;
|
2002-10-31 03:40:26 +01:00
|
|
|
}
|
2007-05-23 18:45:03 +02:00
|
|
|
else if (!strcasecmp (format_type_arg, "unix"))
|
2002-07-01 22:54:35 +02:00
|
|
|
unix_flag = 1;
|
2007-05-23 18:45:03 +02:00
|
|
|
else if (!strcasecmp (format_type_arg, "windows"))
|
2002-10-31 03:40:26 +01:00
|
|
|
windows_flag = 1;
|
2002-06-07 21:25:26 +02:00
|
|
|
else
|
|
|
|
usage (stderr, 1);
|
|
|
|
break;
|
|
|
|
|
2002-01-17 17:54:01 +01:00
|
|
|
case 'A':
|
|
|
|
allusers_flag = 1;
|
|
|
|
break;
|
|
|
|
|
2009-05-17 13:16:12 +02:00
|
|
|
case 'C':
|
|
|
|
if (!optarg)
|
|
|
|
usage (stderr, 1);
|
|
|
|
if (!strcasecmp (optarg, "ANSI"))
|
|
|
|
codepage = GetACP ();
|
|
|
|
else if (!strcasecmp (optarg, "OEM"))
|
|
|
|
codepage = GetOEMCP ();
|
|
|
|
else if (!strcasecmp (optarg, "UTF8")
|
|
|
|
|| !strcasecmp (optarg, "UTF-8"))
|
|
|
|
codepage = CP_UTF8;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *c;
|
|
|
|
codepage = (UINT) strtoul (optarg, &c, 10);
|
|
|
|
if (*c)
|
|
|
|
usage (stderr, 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-01-17 17:54:01 +01:00
|
|
|
case 'D':
|
2002-05-15 13:36:00 +02:00
|
|
|
case 'H':
|
2007-01-09 13:17:05 +01:00
|
|
|
case 'O':
|
2002-01-17 17:54:01 +01:00
|
|
|
case 'P':
|
2000-05-19 19:06:28 +02:00
|
|
|
case 'S':
|
2002-01-17 17:54:01 +01:00
|
|
|
case 'W':
|
2007-05-23 18:45:03 +02:00
|
|
|
++output_flag;
|
2002-05-15 13:36:00 +02:00
|
|
|
o = c;
|
2002-01-17 17:54:01 +01:00
|
|
|
break;
|
2000-05-19 19:06:28 +02:00
|
|
|
|
2007-01-09 13:17:05 +01:00
|
|
|
case 'F':
|
2007-05-23 18:45:03 +02:00
|
|
|
if (!optarg)
|
2007-01-09 13:17:05 +01:00
|
|
|
usage (stderr, 1);
|
2007-05-23 18:45:03 +02:00
|
|
|
++output_flag;
|
2007-01-09 13:17:05 +01:00
|
|
|
output_arg = optarg;
|
|
|
|
o = c;
|
|
|
|
break;
|
|
|
|
|
2000-09-19 03:26:45 +02:00
|
|
|
case 'i':
|
|
|
|
ignore_flag = 1;
|
|
|
|
break;
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
case 'h':
|
|
|
|
usage (stdout, 0);
|
|
|
|
break;
|
|
|
|
|
2011-10-10 16:57:48 +02:00
|
|
|
case 'V':
|
2002-03-07 04:00:14 +01:00
|
|
|
print_version ();
|
2000-02-17 20:38:33 +01:00
|
|
|
exit (0);
|
|
|
|
|
|
|
|
default:
|
2011-10-10 16:57:48 +02:00
|
|
|
fprintf (stderr, "Try `%s --help' for more information.\n",
|
|
|
|
prog_name);
|
|
|
|
exit (1);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-23 18:45:03 +02:00
|
|
|
/* If none of the "important" flags are set, -u is default. */
|
2007-05-29 09:54:45 +02:00
|
|
|
if (!unix_flag && !windows_flag && !mode_flag
|
|
|
|
&& (!from_file ? !options_from_file_flag : 1))
|
2007-05-23 18:45:03 +02:00
|
|
|
unix_flag = 1;
|
|
|
|
|
|
|
|
/* Only one of ... */
|
2007-05-29 09:54:45 +02:00
|
|
|
if (unix_flag + windows_flag + mode_flag > 1
|
2007-05-23 18:45:03 +02:00
|
|
|
+ (!from_file ? options_from_file_flag : 0))
|
2000-04-13 07:23:30 +02:00
|
|
|
usage (stderr, 1);
|
|
|
|
|
2007-05-23 18:45:03 +02:00
|
|
|
/* options_from_file_flag requires a file. */
|
|
|
|
if (!from_file && options_from_file_flag && !file_arg)
|
2002-07-01 22:54:35 +02:00
|
|
|
usage (stderr, 1);
|
|
|
|
|
2007-05-23 18:45:03 +02:00
|
|
|
/* longname and shortname don't play well together. */
|
|
|
|
if (longname_flag && shortname_flag)
|
2002-07-01 22:54:35 +02:00
|
|
|
usage (stderr, 1);
|
|
|
|
|
2007-05-23 18:45:03 +02:00
|
|
|
/* longname and shortname only make sense with Windows paths. */
|
|
|
|
if ((longname_flag || shortname_flag) && !windows_flag)
|
2000-02-17 20:38:33 +01:00
|
|
|
usage (stderr, 1);
|
|
|
|
|
2007-05-23 18:45:03 +02:00
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
action (int argc, char **argv, int opt)
|
|
|
|
{
|
|
|
|
if (output_flag)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2007-05-23 18:45:03 +02:00
|
|
|
if (argv[optind])
|
|
|
|
usage (stderr, 1);
|
2002-05-22 12:05:41 +02:00
|
|
|
|
2007-05-23 18:45:03 +02:00
|
|
|
do_sysfolders (opt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-07 19:30:35 +01:00
|
|
|
if (optind > argc - 1)
|
2000-04-11 04:57:25 +02:00
|
|
|
usage (stderr, 1);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2004-02-25 02:23:20 +01:00
|
|
|
for (int i = optind; argv[i]; i++)
|
|
|
|
if (mode_flag)
|
|
|
|
report_mode (argv[i]);
|
|
|
|
else
|
2007-05-23 18:45:03 +02:00
|
|
|
do_pathconv (argv[i]);
|
2000-04-11 04:57:25 +02:00
|
|
|
}
|
2007-05-23 18:45:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
int o;
|
|
|
|
|
2009-05-15 13:30:18 +02:00
|
|
|
setlocale (LC_CTYPE, "");
|
2011-10-10 16:57:48 +02:00
|
|
|
prog_name = program_invocation_short_name;
|
2007-05-23 18:45:03 +02:00
|
|
|
|
|
|
|
o = do_options (argc, argv, 0);
|
|
|
|
|
|
|
|
if (!file_arg)
|
|
|
|
action (argc, argv, o);
|
2000-02-17 20:38:33 +01:00
|
|
|
else
|
|
|
|
{
|
2000-04-11 04:57:25 +02:00
|
|
|
FILE *fp;
|
|
|
|
char buf[PATH_MAX * 2 + 1];
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-04-11 04:57:25 +02:00
|
|
|
if (argv[optind])
|
|
|
|
usage (stderr, 1);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2007-05-23 18:45:03 +02:00
|
|
|
if (strcmp (file_arg, "-"))
|
|
|
|
{
|
|
|
|
if (!(fp = fopen (file_arg, "rt")))
|
|
|
|
{
|
|
|
|
perror ("cygpath");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
else
|
2000-04-11 04:57:25 +02:00
|
|
|
{
|
|
|
|
fp = stdin;
|
|
|
|
setmode (0, O_TEXT);
|
|
|
|
}
|
2000-04-13 07:23:30 +02:00
|
|
|
setbuf (stdout, NULL);
|
2007-05-23 18:45:03 +02:00
|
|
|
|
|
|
|
while (fgets (buf, sizeof (buf), fp))
|
2000-04-11 04:57:25 +02:00
|
|
|
{
|
2010-01-07 13:08:11 +01:00
|
|
|
int ac = 0;
|
|
|
|
char *av[4] = { NULL, NULL, NULL, NULL };
|
2007-05-23 18:45:03 +02:00
|
|
|
char *p = strchr (buf, '\n');
|
2000-04-11 04:57:25 +02:00
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
2010-01-07 13:08:11 +01:00
|
|
|
p = buf;
|
|
|
|
av[ac++] = prog_name;
|
|
|
|
av[ac++] = p;
|
|
|
|
if (options_from_file_flag && *p == '-')
|
2007-05-23 18:45:03 +02:00
|
|
|
{
|
2010-01-07 13:08:11 +01:00
|
|
|
while (*p && !isspace (*p))
|
|
|
|
++p;
|
|
|
|
if (*p)
|
|
|
|
{
|
|
|
|
*p++ = '\0';
|
|
|
|
while (*p && isspace (*p))
|
|
|
|
++p;
|
|
|
|
av[ac++] = p;
|
|
|
|
}
|
|
|
|
o = do_options (ac, av, 1);
|
2007-05-23 18:45:03 +02:00
|
|
|
}
|
2010-01-07 13:08:11 +01:00
|
|
|
else
|
2000-04-13 07:23:30 +02:00
|
|
|
{
|
2010-01-07 13:08:11 +01:00
|
|
|
output_flag = 0;
|
|
|
|
optind = 1;
|
2000-04-13 07:23:30 +02:00
|
|
|
}
|
2007-05-23 18:45:03 +02:00
|
|
|
action (ac, av, o);
|
2000-04-11 04:57:25 +02:00
|
|
|
}
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
exit (0);
|
|
|
|
}
|