Initial revision

svn path=/trunk/rosdocs/; revision=3069
This commit is contained in:
Casper Hornstrup 2002-06-13 20:37:16 +00:00
parent b5693113b2
commit 85c0278654
5 changed files with 420 additions and 0 deletions

48
tools/Makefile Normal file
View File

@ -0,0 +1,48 @@
PATH_TO_TOP = ..
TOOLS = \
rcopy$(EXE_POSTFIX) \
rdel$(EXE_POSTFIX) \
rmkdir$(EXE_POSTFIX) \
rrmdir$(EXE_POSTFIX)
CLEAN_FILES = $(TOOLS)
all: $(TOOLS)
ifeq ($(HOST),mingw32-linux)
rcopy$(EXE_POSTFIX): rcopy.c
$(HOST_CC) $(CFLAGS) -DUNIX_PATHS rcopy.c -o rcopy$(EXE_POSTFIX)
endif
ifeq ($(HOST),mingw32-windows)
rcopy$(EXE_POSTFIX): rcopy.c
$(HOST_CC) $(CFLAGS) -DDOS_PATHS rcopy.c -o rcopy$(EXE_POSTFIX)
endif
rdel$(EXE_POSTFIX): rdel.c
$(HOST_CC) $(CFLAGS) rdel.c -o rdel$(EXE_POSTFIX)
ifeq ($(HOST),mingw32-linux)
rmkdir$(EXE_POSTFIX): rmkdir.c
$(HOST_CC) $(CFLAGS) -DUNIX_PATHS rmkdir.c -o rmkdir$(EXE_POSTFIX)
endif
ifeq ($(HOST),mingw32-windows)
rmkdir$(EXE_POSTFIX): rmkdir.c
$(HOST_CC) $(CFLAGS) -DDOS_PATHS rmkdir.c -o rmkdir$(EXE_POSTFIX)
endif
ifeq ($(HOST),mingw32-linux)
rrmdir$(EXE_POSTFIX): rrmdir.c
$(HOST_CC) $(CFLAGS) -DUNIX_PATHS rrmdir.c -o rrmdir$(EXE_POSTFIX)
endif
ifeq ($(HOST),mingw32-windows)
rrmdir$(EXE_POSTFIX): rrmdir.c
$(HOST_CC) $(CFLAGS) -DDOS_PATHS rrmdir.c -o rrmdir$(EXE_POSTFIX)
endif
clean:
- $(RM) $(CLEAN_FILES)
.PHONY: all clean
include $(PATH_TO_TOP)/rules.mk

87
tools/rcopy.c Executable file
View File

@ -0,0 +1,87 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char* convert_path(char* origpath)
{
char* newpath;
int i;
newpath = strdup(origpath);
i = 0;
while (newpath[i] != 0)
{
#ifdef UNIX_PATHS
if (newpath[i] == '\\')
{
newpath[i] = '/';
}
#else
#ifdef DOS_PATHS
if (newpath[i] == '/')
{
newpath[i] = '\\';
}
#endif
#endif
i++;
}
return(newpath);
}
#define TRANSFER_SIZE (65536)
int main(int argc, char* argv[])
{
char* path1;
char* path2;
FILE* in;
FILE* out;
char* buf;
int n_in;
int n_out;
if (argc != 3)
{
fprintf(stderr, "Too many arguments\n");
exit(1);
}
path1 = convert_path(argv[1]);
path2 = convert_path(argv[2]);
in = fopen(path1, "rb");
if (in == NULL)
{
perror("Cannot open input file");
exit(1);
}
out = fopen(path2, "wb");
if (out == NULL)
{
perror("Cannot open output file");
fclose(in);
exit(1);
}
buf = malloc(TRANSFER_SIZE);
while (!feof(in))
{
n_in = fread(buf, 1, TRANSFER_SIZE, in);
n_out = fwrite(buf, 1, n_in, out);
if (n_in != n_out)
{
perror("Failed to write to output file\n");
free(buf);
fclose(in);
fclose(out);
exit(1);
}
}
exit(0);
}

91
tools/rdel.c Executable file
View File

@ -0,0 +1,91 @@
/* $Id: rdel.c,v 1.1 2002/06/13 20:37:17 chorns Exp $
* COPYRIGHT: See COPYING in the top level directory
* PROGRAMMER: Rex Jolliff (rex@lvcablemodem.com)
* PURPOSE: Platform independant delete command
*/
#include <dirent.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void
convertPath (char * pathToConvert)
{
while (*pathToConvert != 0)
{
if (*pathToConvert == '\\')
{
*pathToConvert = '/';
}
pathToConvert++;
}
}
void
getDirectory (const char *filename, char * directorySpec)
{
int lengthOfDirectory;
if (strrchr (filename, '/') != 0)
{
lengthOfDirectory = strrchr (filename, '/') - filename;
strncpy (directorySpec, filename, lengthOfDirectory);
directorySpec [lengthOfDirectory] = '\0';
}
else
{
strcpy (directorySpec, ".");
}
}
void
getFilename (const char *filename, char * fileSpec)
{
if (strrchr (filename, '/') != 0)
{
strcpy (fileSpec, strrchr (filename, '/') + 1);
}
else
{
strcpy (fileSpec, filename);
}
}
int
main (int argc, char* argv[])
{
int justPrint = 0;
int idx;
int returnCode;
for (idx = 1; idx < argc; idx++)
{
convertPath (argv [idx]);
if (justPrint)
{
printf ("delete %s\n", argv [idx]);
}
else
{
returnCode = remove (argv [idx]);
if (returnCode != 0 && errno != ENOENT)
{
/* Continue even if there is errors */
#if 0
printf ("Unlink of %s failed. Unlink returned %d.\n",
argv [idx],
returnCode);
return returnCode;
#endif
}
}
}
return 0;
}

102
tools/rmkdir.c Executable file
View File

@ -0,0 +1,102 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char* convert_path(char* origpath)
{
char* newpath;
int i;
newpath = strdup(origpath);
i = 0;
while (newpath[i] != 0)
{
#ifdef UNIX_PATHS
if (newpath[i] == '\\')
{
newpath[i] = '/';
}
#else
#ifdef DOS_PATHS
if (newpath[i] == '/')
{
newpath[i] = '\\';
}
#endif
#endif
i++;
}
return(newpath);
}
#define TRANSFER_SIZE (65536)
int mkdir_p(char* path)
{
if (chdir(path) == 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[])
{
char* path1;
FILE* in;
FILE* out;
char* csec;
int is_abs_path;
if (argc != 2)
{
fprintf(stderr, "Too many arguments\n");
exit(1);
}
path1 = convert_path(argv[1]);
if (isalpha(path1[0]) && path1[1] == ':' && path1[2] == '/')
{
csec = strtok(path1, "/");
chdir(csec);
csec = strtok(NULL, "/");
}
else if (path1[0] == '/')
{
chdir("/");
csec = strtok(path1, "/");
}
else
{
csec = strtok(path1, "/");
}
while (csec != NULL)
{
mkdir_p(csec);
csec = strtok(NULL, "/");
}
exit(0);
}

92
tools/rrmdir.c Executable file
View File

@ -0,0 +1,92 @@
/* $Id: rrmdir.c,v 1.1 2002/06/13 20:37:17 chorns Exp $
* COPYRIGHT: See COPYING in the top level directory
* PROGRAMMER: Rex Jolliff (rex@lvcablemodem.com)
* Casper S. Hornstrup (chorns@users.sourceforge.net)
* PURPOSE: Platform independant remove directory command
*/
#include <dirent.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void
convertPath (char * pathToConvert)
{
while (*pathToConvert != 0)
{
if (*pathToConvert == '\\')
{
*pathToConvert = '/';
}
pathToConvert++;
}
}
void
getDirectory (const char *filename, char * directorySpec)
{
int lengthOfDirectory;
if (strrchr (filename, '/') != 0)
{
lengthOfDirectory = strrchr (filename, '/') - filename;
strncpy (directorySpec, filename, lengthOfDirectory);
directorySpec [lengthOfDirectory] = '\0';
}
else
{
strcpy (directorySpec, ".");
}
}
void
getFilename (const char *filename, char * fileSpec)
{
if (strrchr (filename, '/') != 0)
{
strcpy (fileSpec, strrchr (filename, '/') + 1);
}
else
{
strcpy (fileSpec, filename);
}
}
int
main (int argc, char* argv[])
{
int justPrint = 0;
int idx;
int returnCode;
for (idx = 1; idx < argc; idx++)
{
convertPath (argv [idx]);
if (justPrint)
{
printf ("remove %s\n", argv [idx]);
}
else
{
returnCode = rmdir (argv [idx]);
if (returnCode != 0 && errno != ENOENT)
{
/* Continue even if there is errors */
#if 0
printf ("Rmdir of %s failed. Rmdir returned %d.\n",
argv [idx],
returnCode);
return returnCode;
#endif
}
}
}
return 0;
}