mirror of
https://github.com/reactos/reactos.git
synced 2025-02-23 08:55:19 +00:00
reformat and simplify before adding functionality
svn path=/branches/xmlbuildsystem/; revision=14076
This commit is contained in:
parent
defea05242
commit
effadc5c83
1 changed files with 84 additions and 95 deletions
|
@ -10,112 +10,101 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WIN32)
|
#define WIN_SEPARATOR_CHAR '\\'
|
||||||
#define DIR_SEPARATOR_CHAR '\\'
|
#define WIN_SEPARATOR_STRING "\\"
|
||||||
#define DIR_SEPARATOR_STRING "\\"
|
#define NIX_SEPARATOR_CHAR '/'
|
||||||
#define DOS_PATHS
|
#define NIX_SEPARATOR_STRING "/"
|
||||||
#else
|
|
||||||
#define DIR_SEPARATOR_CHAR '/'
|
|
||||||
#define DIR_SEPARATOR_STRING "/"
|
|
||||||
#define UNIX_PATHS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char* convert_path(char* origpath)
|
#ifdef WIN32
|
||||||
{
|
#define DIR_SEPARATOR_CHAR WIN_SEPARATOR_CHAR
|
||||||
char* newpath;
|
#define DIR_SEPARATOR_STRING WIN_SEPARATOR_STRING
|
||||||
int i;
|
#define BAD_SEPARATOR_CHAR NIX_SEPARATOR_CHAR
|
||||||
|
#define MKDIR(s) mkdir(s)
|
||||||
//newpath = strdup(origpath);
|
|
||||||
newpath=malloc(strlen(origpath)+1);
|
|
||||||
strcpy(newpath,origpath);
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (newpath[i] != 0)
|
|
||||||
{
|
|
||||||
#ifdef UNIX_PATHS
|
|
||||||
if (newpath[i] == '\\')
|
|
||||||
{
|
|
||||||
newpath[i] = '/';
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
#ifdef DOS_PATHS
|
#define DIR_SEPARATOR_CHAR NIX_SEPARATOR_CHAR
|
||||||
if (newpath[i] == '/')
|
#define DIR_SEPARATOR_STRING NIX_SEPARATOR_STRING
|
||||||
{
|
#define BAD_SEPARATOR_CHAR WIN_SEPARATOR_CHAR
|
||||||
newpath[i] = '\\';
|
#define MKDIR(s) mkdir(s,0755)
|
||||||
}
|
#endif
|
||||||
#endif
|
|
||||||
#endif
|
char*
|
||||||
i++;
|
convert_path(char* origpath)
|
||||||
}
|
{
|
||||||
return(newpath);
|
char* newpath;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
newpath=malloc(strlen(origpath)+1);
|
||||||
|
strcpy(newpath,origpath);
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (newpath[i] != 0)
|
||||||
|
{
|
||||||
|
if (newpath[i] == BAD_SEPARATOR_CHAR)
|
||||||
|
{
|
||||||
|
newpath[i] = DIR_SEPARATOR_CHAR;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return(newpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TRANSFER_SIZE (65536)
|
#define TRANSFER_SIZE (65536)
|
||||||
|
|
||||||
int mkdir_p(char* path)
|
int mkdir_p(char* path)
|
||||||
{
|
{
|
||||||
if (chdir(path) == 0)
|
if (chdir(path) == 0)
|
||||||
{
|
{
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
if (MKDIR(path) != 0)
|
||||||
|
{
|
||||||
|
perror("Failed to create directory");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (chdir(path) != 0)
|
||||||
|
{
|
||||||
|
perror("Failed to change directory");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
return(0);
|
return(0);
|
||||||
}
|
|
||||||
#ifdef UNIX_PATHS
|
|
||||||
if (mkdir(path, 0755) != 0)
|
|
||||||
{
|
|
||||||
perror("Failed to create directory");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (mkdir(path) != 0)
|
|
||||||
{
|
|
||||||
perror("Failed to create directory");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (chdir(path) != 0)
|
|
||||||
{
|
|
||||||
perror("Failed to change directory");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
char* path1;
|
char* path1;
|
||||||
char* csec;
|
char* csec;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Too many arguments\n");
|
fprintf(stderr, "Too many arguments\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
path1 = convert_path(argv[1]);
|
path1 = convert_path(argv[1]);
|
||||||
|
|
||||||
if (isalpha(path1[0]) && path1[1] == ':' && path1[2] == DIR_SEPARATOR_CHAR)
|
if (isalpha(path1[0]) && path1[1] == ':' && path1[2] == DIR_SEPARATOR_CHAR)
|
||||||
{
|
{
|
||||||
csec = strtok(path1, DIR_SEPARATOR_STRING);
|
csec = strtok(path1, DIR_SEPARATOR_STRING);
|
||||||
sprintf(buf, "%s\\", csec);
|
sprintf(buf, "%s\\", csec);
|
||||||
chdir(buf);
|
chdir(buf);
|
||||||
csec = strtok(NULL, DIR_SEPARATOR_STRING);
|
csec = strtok(NULL, DIR_SEPARATOR_STRING);
|
||||||
}
|
}
|
||||||
else if (path1[0] == DIR_SEPARATOR_CHAR)
|
else if (path1[0] == DIR_SEPARATOR_CHAR)
|
||||||
{
|
{
|
||||||
chdir(DIR_SEPARATOR_STRING);
|
chdir(DIR_SEPARATOR_STRING);
|
||||||
csec = strtok(path1, DIR_SEPARATOR_STRING);
|
csec = strtok(path1, DIR_SEPARATOR_STRING);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
csec = strtok(path1, DIR_SEPARATOR_STRING);
|
csec = strtok(path1, DIR_SEPARATOR_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (csec != NULL)
|
while (csec != NULL)
|
||||||
{
|
{
|
||||||
mkdir_p(csec);
|
mkdir_p(csec);
|
||||||
csec = strtok(NULL, DIR_SEPARATOR_STRING);
|
csec = strtok(NULL, DIR_SEPARATOR_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue