mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 22:43:04 +00:00
Clean up tools folder.
svn path=/trunk/; revision=34107
This commit is contained in:
parent
b2f5b33c7f
commit
4865f6c89b
10 changed files with 0 additions and 2323 deletions
|
@ -1,109 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
char buf[512];
|
|
||||||
char buf2[512];
|
|
||||||
char ch;
|
|
||||||
unsigned int i, j;
|
|
||||||
char* dot;
|
|
||||||
char* ext;
|
|
||||||
char* prefix;
|
|
||||||
FILE* out;
|
|
||||||
|
|
||||||
if (argc != 3)
|
|
||||||
{
|
|
||||||
printf("Too few arguments\n");
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
prefix = strdup(argv[1]);
|
|
||||||
|
|
||||||
out = fopen(argv[2], "wb");
|
|
||||||
if (out == NULL)
|
|
||||||
{
|
|
||||||
printf("Unable to open output file\n");
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while ((ch = fgetc(stdin)) == '#')
|
|
||||||
{
|
|
||||||
while ((ch = fgetc(stdin)) != '\n' && ch != EOF)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ch != EOF)
|
|
||||||
{
|
|
||||||
buf[i] = ch;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((ch = fgetc(stdin)) != ':' && ch != EOF)
|
|
||||||
{
|
|
||||||
buf[i] = ch;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
buf[i] = 0;
|
|
||||||
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
i = 0;
|
|
||||||
while ((ch = fgetc(stdin)) == ' ' && ch != EOF)
|
|
||||||
{
|
|
||||||
buf2[i] = ch;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (ch != EOF)
|
|
||||||
{
|
|
||||||
buf2[i] = ch;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
j = i;
|
|
||||||
while ((ch = fgetc(stdin)) != ' ' && ch != EOF)
|
|
||||||
{
|
|
||||||
buf2[j] = ch;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
buf2[j] = 0;
|
|
||||||
if (i == j)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ext = strrchr(buf2, '.');
|
|
||||||
if (ext != NULL)
|
|
||||||
{
|
|
||||||
if (0 == strcmp(ext, ".h"))
|
|
||||||
{
|
|
||||||
ext = "h.gch";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ext = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dot = strrchr(buf, '.');
|
|
||||||
if (dot != NULL)
|
|
||||||
{
|
|
||||||
*dot = 0;
|
|
||||||
}
|
|
||||||
fprintf(out, "%s/.%s.TAG %s/.%s.d %s/%s.%s:%s ", prefix, buf, prefix, buf,
|
|
||||||
prefix,buf,ext ? ext : "o" , buf2);
|
|
||||||
|
|
||||||
while ((ch = fgetc(stdin)) != EOF)
|
|
||||||
{
|
|
||||||
fputc(ch, out);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
|
@ -1,132 +0,0 @@
|
||||||
/* make_ctests.c
|
|
||||||
|
|
||||||
* This program is a port of wine project's make_ctests script
|
|
||||||
|
|
||||||
# Script to generate a C file containing a list of tests
|
|
||||||
#
|
|
||||||
# Copyright 2002 Alexandre Julliard
|
|
||||||
# Copyright 2002 Dimitrie O. Paun
|
|
||||||
#
|
|
||||||
# This library is free software; you can redistribute it and/or
|
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
|
||||||
# License as published by the Free Software Foundation; either
|
|
||||||
# version 2.1 of the License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This library is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
# Lesser General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Lesser General Public
|
|
||||||
# License along with this library; if not, write to the Free Software
|
|
||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
#
|
|
||||||
|
|
||||||
# ***** Keep in sync with tools/winapi/msvcmaker:_generate_testlist_c *****
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
const char* header =
|
|
||||||
"/* Automatically generated file; DO NOT EDIT!! */\n"
|
|
||||||
"\n"
|
|
||||||
"/* stdarg.h is needed for Winelib */\n"
|
|
||||||
"#include <stdarg.h>\n"
|
|
||||||
"#include <stdio.h>\n"
|
|
||||||
"#include <stdlib.h>\n"
|
|
||||||
"#include \"windef.h\"\n"
|
|
||||||
"#include \"winbase.h\"\n"
|
|
||||||
"\n";
|
|
||||||
|
|
||||||
const char* middle =
|
|
||||||
"\n"
|
|
||||||
"struct test\n"
|
|
||||||
"{\n"
|
|
||||||
" const char *name;\n"
|
|
||||||
" void (*func)(void);\n"
|
|
||||||
"};\n"
|
|
||||||
"\n"
|
|
||||||
"static const struct test winetest_testlist[] =\n"
|
|
||||||
"{\n";
|
|
||||||
|
|
||||||
const char* end =
|
|
||||||
" { 0, 0 }\n"
|
|
||||||
"};\n"
|
|
||||||
"\n"
|
|
||||||
"#define WINETEST_WANT_MAIN\n"
|
|
||||||
"#include \"wine/test.h\"\n"
|
|
||||||
"\n";
|
|
||||||
|
|
||||||
char*
|
|
||||||
basename ( const char* filename )
|
|
||||||
{
|
|
||||||
const char *p, *p2;
|
|
||||||
char *out;
|
|
||||||
size_t out_len;
|
|
||||||
|
|
||||||
if ( filename == NULL )
|
|
||||||
{
|
|
||||||
fprintf ( stderr, "basename() called with null filename\n" );
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
p = strrchr ( filename, '/' );
|
|
||||||
if ( !p )
|
|
||||||
p = filename;
|
|
||||||
else
|
|
||||||
++p;
|
|
||||||
|
|
||||||
/* look for backslashes, too... */
|
|
||||||
p2 = strrchr ( filename, '\\' );
|
|
||||||
if ( p2 > p )
|
|
||||||
p = p2 + 1;
|
|
||||||
|
|
||||||
/* find extension... */
|
|
||||||
p2 = strrchr ( filename, '.' );
|
|
||||||
if ( !p2 )
|
|
||||||
p2 = p + strlen(p);
|
|
||||||
|
|
||||||
/* malloc a copy */
|
|
||||||
out_len = p2-p;
|
|
||||||
out = malloc ( out_len+1 );
|
|
||||||
if ( out == NULL )
|
|
||||||
{
|
|
||||||
fprintf ( stderr, "malloc() failed\n" );
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
memmove ( out, p, out_len );
|
|
||||||
out[out_len] = '\0';
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
main ( int argc, const char** argv )
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
printf ( "%s", header );
|
|
||||||
|
|
||||||
for ( i = 1; i < argc; i++ )
|
|
||||||
{
|
|
||||||
char* test = basename(argv[i]);
|
|
||||||
if ( test == NULL )
|
|
||||||
return 255;
|
|
||||||
printf ( "extern void func_%s(void);\n", test );
|
|
||||||
free ( test );
|
|
||||||
}
|
|
||||||
|
|
||||||
printf ( "%s", middle );
|
|
||||||
|
|
||||||
for ( i = 1; i < argc; i++ )
|
|
||||||
{
|
|
||||||
char* test = basename(argv[i]);
|
|
||||||
if ( test == NULL )
|
|
||||||
return 255;
|
|
||||||
printf ( " { \"%s\", func_%s },\n", test, test );
|
|
||||||
free ( test );
|
|
||||||
}
|
|
||||||
|
|
||||||
printf ( "%s", end );
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,347 +0,0 @@
|
||||||
#include <ctype.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#define N_CYLINDERS 80
|
|
||||||
#define ROOT_ENTRY_SIZE 32
|
|
||||||
|
|
||||||
#define SECTOR_SIZE 512
|
|
||||||
#define SECTORS_PER_CLUSTER 1
|
|
||||||
#define N_RESERVED 1
|
|
||||||
#define N_FATS 2
|
|
||||||
#define N_ROOT_ENTRIES 224
|
|
||||||
#define SECTORS_PER_DISK (N_HEADS * N_CYLINDERS * SECTORS_PER_TRACK)
|
|
||||||
#define MEDIA_TYPE 0xf0
|
|
||||||
#define SECTORS_PER_FAT 9
|
|
||||||
#define SECTORS_PER_TRACK 18
|
|
||||||
#define N_HEADS 2
|
|
||||||
#define SIGNATURE 0x29 /* only MS? */
|
|
||||||
#define END_SIGNATURE 0xaa55
|
|
||||||
|
|
||||||
|
|
||||||
#define ATTR_READONLY 0x01
|
|
||||||
#define ATTR_HIDDEN 0x02
|
|
||||||
#define ATTR_SYSTEM 0x04
|
|
||||||
#define ATTR_VOLUME 0x08
|
|
||||||
#define ATTR_SUBDIR 0x10
|
|
||||||
#define ATTR_ARCHIVE 0x20
|
|
||||||
#define ATTR_RES1 0x40
|
|
||||||
#define ATTR_RES2 0x80
|
|
||||||
|
|
||||||
|
|
||||||
typedef unsigned char disk_sector_t[SECTOR_SIZE];
|
|
||||||
|
|
||||||
typedef struct boot_sector
|
|
||||||
{
|
|
||||||
unsigned short jmp;
|
|
||||||
unsigned char nop;
|
|
||||||
char oem[8];
|
|
||||||
unsigned short bytes_per_sector;
|
|
||||||
unsigned char sectors_per_cluster;
|
|
||||||
unsigned short reserved_sectors;
|
|
||||||
unsigned char n_fats;
|
|
||||||
unsigned short n_root_entries;
|
|
||||||
unsigned short n_sectors;
|
|
||||||
unsigned char media_type;
|
|
||||||
unsigned short sectors_per_fat;
|
|
||||||
unsigned short sectors_per_track;
|
|
||||||
unsigned short n_heads;
|
|
||||||
unsigned long hidden_sectors;
|
|
||||||
unsigned long huge_sectors;
|
|
||||||
unsigned char drive;
|
|
||||||
unsigned char reserved;
|
|
||||||
unsigned char signature;
|
|
||||||
unsigned long volume_id;
|
|
||||||
char volume_label[11];
|
|
||||||
char file_system[8];
|
|
||||||
unsigned char boot_code[SECTOR_SIZE - 62 - 2];
|
|
||||||
unsigned short end_signature;
|
|
||||||
} __attribute__ ((packed)) boot_sector_t;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct root_entry
|
|
||||||
{
|
|
||||||
char name[8];
|
|
||||||
char extension[3];
|
|
||||||
unsigned char attribute;
|
|
||||||
unsigned char reserved[10];
|
|
||||||
unsigned short time;
|
|
||||||
unsigned short date;
|
|
||||||
unsigned short cluster;
|
|
||||||
unsigned long size;
|
|
||||||
} __attribute ((packed)) root_entry_t;
|
|
||||||
|
|
||||||
|
|
||||||
disk_sector_t *new_image(char *bsfname)
|
|
||||||
{
|
|
||||||
FILE *bsf;
|
|
||||||
disk_sector_t *img;
|
|
||||||
boot_sector_t boot_sec;
|
|
||||||
root_entry_t *root;
|
|
||||||
|
|
||||||
if ((bsf = fopen(bsfname, "rb")) == NULL)
|
|
||||||
{
|
|
||||||
printf("Boot sector image file %s not found!\n", bsfname);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (fread(&boot_sec, 1, SECTOR_SIZE, bsf) != SECTOR_SIZE)
|
|
||||||
{
|
|
||||||
printf("Unable to read boot sector image file %s!\n", bsfname);
|
|
||||||
fclose(bsf);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
fclose(bsf);
|
|
||||||
|
|
||||||
if ( (boot_sec.bytes_per_sector != SECTOR_SIZE) ||
|
|
||||||
(boot_sec.sectors_per_cluster != SECTORS_PER_CLUSTER) ||
|
|
||||||
(boot_sec.reserved_sectors != N_RESERVED) ||
|
|
||||||
(boot_sec.n_fats != N_FATS) ||
|
|
||||||
(boot_sec.n_root_entries != N_ROOT_ENTRIES) ||
|
|
||||||
(boot_sec.n_sectors != SECTORS_PER_DISK) ||
|
|
||||||
(boot_sec.media_type != MEDIA_TYPE) ||
|
|
||||||
(boot_sec.sectors_per_fat != SECTORS_PER_FAT) ||
|
|
||||||
(boot_sec.sectors_per_track != SECTORS_PER_TRACK) ||
|
|
||||||
(boot_sec.n_heads != N_HEADS) ||
|
|
||||||
// (boot_sec.signature != SIGNATURE) ||
|
|
||||||
(boot_sec.end_signature != END_SIGNATURE) )
|
|
||||||
{
|
|
||||||
printf("Invalid boot sector in file %s\n", bsfname);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((img = (disk_sector_t *)malloc(SECTOR_SIZE * SECTORS_PER_DISK)) == NULL)
|
|
||||||
{
|
|
||||||
printf("Not enough memory!\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(img, 0, SECTOR_SIZE * SECTORS_PER_TRACK);
|
|
||||||
memcpy(img, &boot_sec, SECTOR_SIZE);
|
|
||||||
|
|
||||||
root = (root_entry_t *)img[N_RESERVED + N_FATS * SECTORS_PER_FAT];
|
|
||||||
strncpy(root->name, "REACTOS ", 11);
|
|
||||||
root->attribute = ATTR_VOLUME;
|
|
||||||
|
|
||||||
return img;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void create_root_entry(root_entry_t *root, char *fname,
|
|
||||||
unsigned short cluster, unsigned long size)
|
|
||||||
{
|
|
||||||
int i, j;
|
|
||||||
time_t t;
|
|
||||||
struct tm *localt;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
j = 0;
|
|
||||||
while ((fname[j] != '\0') && (fname[j] != '.') && (i < 8))
|
|
||||||
{
|
|
||||||
root->name[i] = toupper(fname[j]);
|
|
||||||
i++;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
while (i < 8)
|
|
||||||
{
|
|
||||||
root->name[i] = ' ';
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if (fname[j] == '.')
|
|
||||||
{
|
|
||||||
i = 0;
|
|
||||||
j++;
|
|
||||||
while ((fname[j] != '\0') && (i < 3))
|
|
||||||
{
|
|
||||||
root->extension[i] = toupper(fname[j]);
|
|
||||||
i++;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
while (i < 3)
|
|
||||||
{
|
|
||||||
root->extension[i] = ' ';
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i = 0;
|
|
||||||
while (i < 3)
|
|
||||||
{
|
|
||||||
root->extension[i] = ' ';
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
root->attribute = ATTR_ARCHIVE;
|
|
||||||
t = time(0);
|
|
||||||
localt = localtime(&t);
|
|
||||||
root->time = (((localt->tm_hour & 0x001f) << 11) |
|
|
||||||
((localt->tm_min & 0x003f) << 5) |
|
|
||||||
((localt->tm_sec / 2) & 0x001f));
|
|
||||||
root->date = ((((localt->tm_year - 80) & 0x007f) << 9) |
|
|
||||||
(((localt->tm_mon + 1) & 0x000f) << 5) |
|
|
||||||
(localt->tm_mday & 0x001f));
|
|
||||||
root->cluster = cluster;
|
|
||||||
root->size = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void update_fat(unsigned char *fat, int cl_start, int cl_end)
|
|
||||||
{
|
|
||||||
int i, k;
|
|
||||||
unsigned short *cl;
|
|
||||||
|
|
||||||
for (i = cl_start; i < cl_end - 1; i++)
|
|
||||||
{
|
|
||||||
k = (i - 2) * 3 / 2;
|
|
||||||
cl = ((unsigned short *)&fat[k]);
|
|
||||||
if (i & 1)
|
|
||||||
{
|
|
||||||
*cl = (*cl & 0x000f) | (((i + 1) & 0x0fff) << 4);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*cl = (*cl & 0xf000) | ((i + 1) & 0x0fff);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
k = (i - 2) * 3 / 2;
|
|
||||||
cl = ((unsigned short *)&fat[k]);
|
|
||||||
if (i & 1)
|
|
||||||
{
|
|
||||||
*cl = (*cl & 0x000f) | 0xfff0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*cl = (*cl & 0xf000) | 0x0fff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int copy_files(disk_sector_t *img, char *filenames[], int n_files)
|
|
||||||
{
|
|
||||||
int i, k;
|
|
||||||
FILE *f;
|
|
||||||
int cl_start, cl_end;
|
|
||||||
unsigned char *fat1, *fat2;
|
|
||||||
root_entry_t *root;
|
|
||||||
unsigned long n, size;
|
|
||||||
|
|
||||||
fat1 = (unsigned char *)img[N_RESERVED];
|
|
||||||
fat2 = (unsigned char *)img[N_RESERVED + SECTORS_PER_FAT];
|
|
||||||
root = (root_entry_t *)img[N_RESERVED + N_FATS * SECTORS_PER_FAT];
|
|
||||||
|
|
||||||
k = N_RESERVED +
|
|
||||||
N_FATS * SECTORS_PER_FAT +
|
|
||||||
N_ROOT_ENTRIES * ROOT_ENTRY_SIZE / SECTOR_SIZE;
|
|
||||||
|
|
||||||
cl_end = 1;
|
|
||||||
|
|
||||||
if (n_files > N_ROOT_ENTRIES)
|
|
||||||
{
|
|
||||||
n_files = N_ROOT_ENTRIES;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < n_files; i++)
|
|
||||||
{
|
|
||||||
cl_start = cl_end + 1;
|
|
||||||
if ((f = fopen(filenames[i], "rb")) == NULL)
|
|
||||||
{
|
|
||||||
printf("Error opening file %s!", filenames[i]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf(" %s\n", filenames[i]);
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
while ((n = fread(img[k], 1, SECTOR_SIZE, f)) > 0)
|
|
||||||
{
|
|
||||||
size += n;
|
|
||||||
cl_end++;
|
|
||||||
k++;
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
root++;
|
|
||||||
create_root_entry(root, filenames[i], cl_start, size);
|
|
||||||
|
|
||||||
update_fat(fat1, cl_start, cl_end);
|
|
||||||
}
|
|
||||||
memcpy(fat2, fat1, SECTORS_PER_FAT * SECTOR_SIZE);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int write_image(disk_sector_t *img, char *imgname)
|
|
||||||
{
|
|
||||||
FILE *f;
|
|
||||||
|
|
||||||
if ((f = fopen(imgname, "rb")) != NULL)
|
|
||||||
{
|
|
||||||
printf("Image file %s already exists!\n", imgname);
|
|
||||||
fclose(f);
|
|
||||||
free(img);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
f = fopen(imgname, "wb");
|
|
||||||
if (fwrite(img, SECTOR_SIZE, SECTORS_PER_DISK, f) != SECTORS_PER_DISK)
|
|
||||||
{
|
|
||||||
printf("Unable to write image file %s\n!", imgname);
|
|
||||||
fclose(f);
|
|
||||||
free(img);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
free(img);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
disk_sector_t *img;
|
|
||||||
char *imgname;
|
|
||||||
char *bsfname;
|
|
||||||
char **filenames;
|
|
||||||
int n_files;
|
|
||||||
|
|
||||||
if (argc < 4)
|
|
||||||
{
|
|
||||||
printf("Usage: mkflpimg <image> <boot sector> <source files>\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
imgname = argv[1];
|
|
||||||
bsfname = argv[2];
|
|
||||||
filenames = &argv[3];
|
|
||||||
n_files = argc - 3;
|
|
||||||
|
|
||||||
printf("Creating image ...\n");
|
|
||||||
if ((img = new_image(bsfname)) == NULL)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Copying files ...\n");
|
|
||||||
|
|
||||||
if (copy_files(img, filenames, n_files))
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Writing image file ...\n");
|
|
||||||
|
|
||||||
if (write_image(img, imgname))
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Finished.\n");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,337 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <utime.h>
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <io.h>
|
|
||||||
#include <dos.h>
|
|
||||||
#else
|
|
||||||
#include <sys/io.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
|
||||||
#endif
|
|
||||||
#ifndef MAX_PATH
|
|
||||||
#define MAX_PATH 260
|
|
||||||
#endif
|
|
||||||
#ifndef WIN32
|
|
||||||
#define DIR_SEPARATOR_CHAR '/'
|
|
||||||
#define DIR_SEPARATOR_STRING "/"
|
|
||||||
#else
|
|
||||||
#define DIR_SEPARATOR_CHAR '\\'
|
|
||||||
#define DIR_SEPARATOR_STRING "\\"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char *
|
|
||||||
make_absolute(char *absolute, char *path)
|
|
||||||
{
|
|
||||||
#ifndef WIN32
|
|
||||||
if (path[0] == DIR_SEPARATOR_CHAR)
|
|
||||||
{
|
|
||||||
strcpy(absolute, path);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
getcwd(absolute, MAX_PATH);
|
|
||||||
strcat(absolute, DIR_SEPARATOR_STRING);
|
|
||||||
strcat(absolute, path);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
_fullpath(absolute, path, MAX_PATH);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return absolute;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* convert_path(char* origpath)
|
|
||||||
{
|
|
||||||
char* newpath;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
//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
|
|
||||||
#ifdef DOS_PATHS
|
|
||||||
if (newpath[i] == '/')
|
|
||||||
{
|
|
||||||
newpath[i] = '\\';
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return(newpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TRANSFER_SIZE (65536)
|
|
||||||
|
|
||||||
static void
|
|
||||||
copy_file(char* path1, char* path2)
|
|
||||||
{
|
|
||||||
FILE* in;
|
|
||||||
FILE* out;
|
|
||||||
char* buf;
|
|
||||||
int n_in;
|
|
||||||
int n_out;
|
|
||||||
struct stat st_buffer;
|
|
||||||
struct utimbuf ut_buffer;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(buf);
|
|
||||||
fclose(in);
|
|
||||||
fclose(out);
|
|
||||||
|
|
||||||
if (stat(path2, &st_buffer) >= 0)
|
|
||||||
{
|
|
||||||
ut_buffer.actime = st_buffer.st_atime;
|
|
||||||
|
|
||||||
if (stat(path1, &st_buffer) >= 0)
|
|
||||||
{
|
|
||||||
ut_buffer.modtime = st_buffer.st_mtime;
|
|
||||||
utime(path2, &ut_buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
|
|
||||||
static void
|
|
||||||
copy_directory (char *path1, char *path2)
|
|
||||||
{
|
|
||||||
struct _finddata_t f;
|
|
||||||
int findhandle;
|
|
||||||
char buf[MAX_PATH];
|
|
||||||
char tobuf[MAX_PATH];
|
|
||||||
|
|
||||||
strcpy(buf, path1);
|
|
||||||
if (path1[strlen(path1) - 1] != DIR_SEPARATOR_CHAR)
|
|
||||||
strcat(buf, DIR_SEPARATOR_STRING);
|
|
||||||
strcat(buf, "*.*");
|
|
||||||
findhandle =_findfirst(buf, &f);
|
|
||||||
if (findhandle != 0)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if ((f.attrib & _A_SUBDIR) == 0 && f.name[0] != '.')
|
|
||||||
{
|
|
||||||
// Convert to absolute path
|
|
||||||
make_absolute(buf, path1);
|
|
||||||
if (path1[strlen(path1) - 1] != DIR_SEPARATOR_CHAR)
|
|
||||||
strcat(buf, DIR_SEPARATOR_STRING);
|
|
||||||
strcat(buf, f.name);
|
|
||||||
|
|
||||||
//printf("copying file %s\n", buf);
|
|
||||||
if (path2[strlen(path2) - 1] == DIR_SEPARATOR_CHAR)
|
|
||||||
{
|
|
||||||
strcpy(tobuf, path2);
|
|
||||||
strcat(tobuf, f.name);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
strcpy(tobuf, path2);
|
|
||||||
strcat(tobuf, DIR_SEPARATOR_STRING);
|
|
||||||
strcat(tobuf, f.name);
|
|
||||||
}
|
|
||||||
copy_file(buf, tobuf);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//printf("skipping directory '%s'\n", f.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (_findnext(findhandle, &f) == 0);
|
|
||||||
|
|
||||||
_findclose(findhandle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
/* Linux version */
|
|
||||||
|
|
||||||
static int
|
|
||||||
is_reg (char *path, char *fn)
|
|
||||||
{
|
|
||||||
char buf[MAX_PATH];
|
|
||||||
char buf2[MAX_PATH];
|
|
||||||
struct stat sbuf;
|
|
||||||
|
|
||||||
strcpy(buf, path);
|
|
||||||
if (buf[strlen(buf)-1] != '/')
|
|
||||||
strcat(buf, "/");
|
|
||||||
strcat(buf, fn);
|
|
||||||
|
|
||||||
make_absolute(buf2, buf);
|
|
||||||
|
|
||||||
if (stat(buf2, &sbuf) == -1)
|
|
||||||
return 0;
|
|
||||||
else {
|
|
||||||
if (S_ISREG(sbuf.st_mode))
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
copy_directory (char *path1, char *path2)
|
|
||||||
{
|
|
||||||
DIR *dirp;
|
|
||||||
struct dirent *entry;
|
|
||||||
struct stat stbuf;
|
|
||||||
char buf[MAX_PATH];
|
|
||||||
char tobuf[MAX_PATH];
|
|
||||||
char err[400];
|
|
||||||
|
|
||||||
dirp = opendir(path1);
|
|
||||||
|
|
||||||
if (dirp != NULL)
|
|
||||||
{
|
|
||||||
while ((entry = readdir (dirp)) != NULL)
|
|
||||||
{
|
|
||||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
|
||||||
continue; // skip self and parent
|
|
||||||
|
|
||||||
if (entry->d_type == DT_REG || is_reg(path1, entry->d_name)) // normal file
|
|
||||||
{
|
|
||||||
// Convert to absolute path
|
|
||||||
make_absolute(buf, path1);
|
|
||||||
if (path1[strlen(path1) - 1] != DIR_SEPARATOR_CHAR)
|
|
||||||
strcat(buf, DIR_SEPARATOR_STRING);
|
|
||||||
strcat(buf, entry->d_name);
|
|
||||||
if (stat(buf, &stbuf) == -1)
|
|
||||||
{
|
|
||||||
sprintf(err, "Can't access '%s' (%s)\n", buf, strerror(errno));
|
|
||||||
perror(err);
|
|
||||||
exit(1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//printf("copying file '%s'\n", entry->d_name);
|
|
||||||
if (path2[strlen(path2) - 1] == DIR_SEPARATOR_CHAR)
|
|
||||||
{
|
|
||||||
strcpy(tobuf, path2);
|
|
||||||
strcat(tobuf, entry->d_name);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
strcpy(tobuf, path2);
|
|
||||||
strcat(tobuf, DIR_SEPARATOR_STRING);
|
|
||||||
strcat(tobuf, entry->d_name);
|
|
||||||
}
|
|
||||||
copy_file(buf, tobuf);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//printf("skipping directory '%s'\n", entry->d_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir (dirp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sprintf(err, "Can't open %s\n", path1);
|
|
||||||
perror(err);
|
|
||||||
exit(1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int
|
|
||||||
is_directory(char *path)
|
|
||||||
{
|
|
||||||
struct stat stbuf;
|
|
||||||
char buf[MAX_PATH];
|
|
||||||
|
|
||||||
// Convert to absolute path
|
|
||||||
make_absolute(buf, path);
|
|
||||||
if (stat(buf, &stbuf) == -1)
|
|
||||||
{
|
|
||||||
/* Assume a destination file */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (S_ISDIR(stbuf.st_mode))
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
char* path1;
|
|
||||||
char* path2;
|
|
||||||
int dir1;
|
|
||||||
int dir2;
|
|
||||||
|
|
||||||
if (argc != 3)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Wrong argument count\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
path1 = convert_path(argv[1]);
|
|
||||||
path2 = convert_path(argv[2]);
|
|
||||||
|
|
||||||
dir1 = is_directory(path1);
|
|
||||||
dir2 = is_directory(path2);
|
|
||||||
|
|
||||||
if ((dir1 && !dir2) || (!dir1 && dir2))
|
|
||||||
{
|
|
||||||
perror("None or both paramters must be a directory\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dir1)
|
|
||||||
{
|
|
||||||
copy_directory(path1, path2);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
copy_file(path1, path2);
|
|
||||||
}
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
}
|
|
|
@ -1,101 +0,0 @@
|
||||||
/* $Id$
|
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
|
||||||
* PROGRAMMER: Rex Jolliff (rex@lvcablemodem.com)
|
|
||||||
* PURPOSE: Platform independent delete command
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#ifdef __WIN32__
|
|
||||||
# include <io.h>
|
|
||||||
#endif
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
void
|
|
||||||
convertPath (char * pathToConvert)
|
|
||||||
{
|
|
||||||
while (*pathToConvert != 0)
|
|
||||||
{
|
|
||||||
if (*pathToConvert == '\\')
|
|
||||||
{
|
|
||||||
*pathToConvert = '/';
|
|
||||||
}
|
|
||||||
pathToConvert++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
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, ".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
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
|
|
||||||
{
|
|
||||||
#ifdef __WIN32__
|
|
||||||
_chmod (argv [idx], _S_IREAD | _S_IWRITE);
|
|
||||||
#else
|
|
||||||
chmod (argv [idx], 0666);
|
|
||||||
#endif
|
|
||||||
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;
|
|
||||||
}
|
|
|
@ -1,870 +0,0 @@
|
||||||
/*
|
|
||||||
* Generate a file with test registrations from a list
|
|
||||||
* of files in a directory.
|
|
||||||
* Casper S. Hornstrup <chorns@users.sourceforge.net>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <io.h>
|
|
||||||
#include <dos.h>
|
|
||||||
#else
|
|
||||||
#include <sys/io.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#ifndef MAX_PATH
|
|
||||||
#define MAX_PATH 260
|
|
||||||
#endif
|
|
||||||
#ifndef WIN32
|
|
||||||
#define DIR_SEPARATOR_CHAR '/'
|
|
||||||
#define DIR_SEPARATOR_STRING "/"
|
|
||||||
#else
|
|
||||||
#define DIR_SEPARATOR_CHAR '\\'
|
|
||||||
#define DIR_SEPARATOR_STRING "\\"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static FILE *out;
|
|
||||||
static char *path;
|
|
||||||
static char *file;
|
|
||||||
static char *makefile;
|
|
||||||
static char *exestubfile;
|
|
||||||
|
|
||||||
static char*
|
|
||||||
convert_path(char* origpath)
|
|
||||||
{
|
|
||||||
char* newpath;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* for no good reason, i'm having trouble getting gcc to link strdup */
|
|
||||||
//newpath = strdup(origpath);
|
|
||||||
newpath = malloc(strlen(origpath)+1);
|
|
||||||
strcpy(newpath, origpath);
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (newpath[i] != 0)
|
|
||||||
{
|
|
||||||
#ifndef WIN32
|
|
||||||
if (newpath[i] == '\\')
|
|
||||||
{
|
|
||||||
newpath[i] = '/';
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#ifdef WIN32
|
|
||||||
if (newpath[i] == '/')
|
|
||||||
{
|
|
||||||
newpath[i] = '\\';
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return(newpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
write_line(char *line)
|
|
||||||
{
|
|
||||||
int n_out;
|
|
||||||
char buf[200];
|
|
||||||
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
strcpy(buf, line);
|
|
||||||
/* Terminate the line */
|
|
||||||
buf[strlen(buf)] = '\r';
|
|
||||||
buf[strlen(buf)] = '\n';
|
|
||||||
|
|
||||||
n_out = fwrite(&buf[0], 1, strlen(buf), out);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
change_extension(char *filenamebuffer,
|
|
||||||
char *filename,
|
|
||||||
char *newextension)
|
|
||||||
{
|
|
||||||
char *ptr;
|
|
||||||
|
|
||||||
if (newextension == NULL)
|
|
||||||
{
|
|
||||||
strcpy(filenamebuffer, filename);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr = strrchr(filename, '.');
|
|
||||||
if (ptr != NULL)
|
|
||||||
{
|
|
||||||
strncpy(filenamebuffer, filename, ptr - filename);
|
|
||||||
filenamebuffer[ptr - filename] = 0;
|
|
||||||
strcat(filenamebuffer, newextension);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
strcpy(filenamebuffer, filename);
|
|
||||||
strcat(filenamebuffer, newextension);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
get_test_name(char *filename,
|
|
||||||
char *testname)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
strcpy(testname, filename);
|
|
||||||
|
|
||||||
i = strlen(testname);
|
|
||||||
while (i > 0 && testname[i] != '.')
|
|
||||||
{
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
if (i > 0)
|
|
||||||
{
|
|
||||||
testname[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make a capital first letter and make all other letters lower case */
|
|
||||||
testname[0] = toupper(testname[0]);
|
|
||||||
if (!((testname[0] >= 'A' && testname[0] <= 'Z') ||
|
|
||||||
(testname[0] >= '0' && testname[0] <= '9')))
|
|
||||||
{
|
|
||||||
testname[0] = '_';
|
|
||||||
}
|
|
||||||
i = 1;
|
|
||||||
while (i < strlen(testname))
|
|
||||||
{
|
|
||||||
testname[i] = tolower(testname[i]);
|
|
||||||
if (!((testname[i] >= 'a' && testname[i] <= 'z') ||
|
|
||||||
(testname[i] >= '0' && testname[i] <= '9')))
|
|
||||||
{
|
|
||||||
testname[i] = '_';
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* filename - name of file to make registrations for
|
|
||||||
* type - type of registration (0 = prototype, 1 = call, 2 = makefile)
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
register_test(char *filename,
|
|
||||||
int type)
|
|
||||||
{
|
|
||||||
char ext[100];
|
|
||||||
char testname[100];
|
|
||||||
char call[100];
|
|
||||||
char regtest[100];
|
|
||||||
char filenamebuffer[MAX_PATH];
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = strlen(filename);
|
|
||||||
while (i > 0 && filename[i] != '.')
|
|
||||||
{
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
if (i > 0)
|
|
||||||
{
|
|
||||||
memset(ext, 0, sizeof(ext));
|
|
||||||
strncpy(&ext[0], &filename[i], strlen(&filename[i]));
|
|
||||||
|
|
||||||
if (strcasecmp(ext, ".c") != 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(testname, 0, sizeof(testname));
|
|
||||||
get_test_name(filename, testname);
|
|
||||||
|
|
||||||
if (type == 0)
|
|
||||||
{
|
|
||||||
sprintf(regtest, "extern int %sTest(int Command, char *Buffer);", testname);
|
|
||||||
write_line(regtest);
|
|
||||||
}
|
|
||||||
else if (type == 1)
|
|
||||||
{
|
|
||||||
sprintf(call, "%sTest", testname);
|
|
||||||
sprintf(regtest, " AddTest((TestRoutine)%s);", call);
|
|
||||||
write_line(regtest);
|
|
||||||
}
|
|
||||||
else if (type == 2)
|
|
||||||
{
|
|
||||||
change_extension(filenamebuffer, filename, ".o");
|
|
||||||
sprintf(regtest, "%s \\", filenamebuffer);
|
|
||||||
write_line(regtest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
|
|
||||||
/* Win32 version */
|
|
||||||
|
|
||||||
static void
|
|
||||||
make_file_list (int type)
|
|
||||||
{
|
|
||||||
struct _finddata_t f;
|
|
||||||
int findhandle;
|
|
||||||
char searchbuf[MAX_PATH];
|
|
||||||
|
|
||||||
strcpy(searchbuf, path);
|
|
||||||
strcat(searchbuf, "*.*");
|
|
||||||
findhandle =_findfirst(searchbuf, &f);
|
|
||||||
if (findhandle != -1)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (f.attrib & _A_SUBDIR)
|
|
||||||
{
|
|
||||||
/* Skip subdirectories */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
register_test(f.name, type);
|
|
||||||
}
|
|
||||||
while (_findnext(findhandle, &f) == 0);
|
|
||||||
_findclose(findhandle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* Linux version */
|
|
||||||
static void
|
|
||||||
make_file_list (int type)
|
|
||||||
{
|
|
||||||
DIR *dirp;
|
|
||||||
struct dirent *entry;
|
|
||||||
struct stat stbuf;
|
|
||||||
char buf[MAX_PATH];
|
|
||||||
|
|
||||||
#ifdef HAVE_D_TYPE
|
|
||||||
dirp = opendir(path);
|
|
||||||
if (dirp != NULL)
|
|
||||||
{
|
|
||||||
while ((entry = readdir(dirp)) != NULL)
|
|
||||||
{
|
|
||||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
|
||||||
continue; // skip self and parent
|
|
||||||
|
|
||||||
if (entry->d_type == DT_REG) // normal file
|
|
||||||
{
|
|
||||||
// Check for an absolute path
|
|
||||||
if (path[0] == DIR_SEPARATOR_CHAR)
|
|
||||||
{
|
|
||||||
strcpy(buf, path);
|
|
||||||
strcat(buf, DIR_SEPARATOR_STRING);
|
|
||||||
strcat(buf, entry->d_name);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
getcwd(buf, sizeof(buf));
|
|
||||||
strcat(buf, DIR_SEPARATOR_STRING);
|
|
||||||
strcat(buf, path);
|
|
||||||
strcat(buf, entry->d_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stat(buf, &stbuf) == -1)
|
|
||||||
{
|
|
||||||
printf("Can't access '%s' (%s)\n", buf, strerror(errno));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (S_ISDIR(stbuf.st_mode))
|
|
||||||
{
|
|
||||||
/* Skip subdirectories */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
register_test(entry->d_name, type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir(dirp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Can't open %s\n", path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
dirp = opendir(path);
|
|
||||||
if (dirp != NULL)
|
|
||||||
{
|
|
||||||
while ((entry = readdir(dirp)) != NULL)
|
|
||||||
{
|
|
||||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
|
||||||
continue; // skip self and parent
|
|
||||||
|
|
||||||
// Check for an absolute path
|
|
||||||
if (path[0] == DIR_SEPARATOR_CHAR)
|
|
||||||
{
|
|
||||||
strcpy(buf, path);
|
|
||||||
strcat(buf, DIR_SEPARATOR_STRING);
|
|
||||||
strcat(buf, entry->d_name);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
getcwd(buf, sizeof(buf));
|
|
||||||
strcat(buf, DIR_SEPARATOR_STRING);
|
|
||||||
strcat(buf, path);
|
|
||||||
strcat(buf, entry->d_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stat(buf, &stbuf) == -1)
|
|
||||||
{
|
|
||||||
printf("Can't access '%s' (%s)\n", buf, strerror(errno));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (S_ISDIR(stbuf.st_mode))
|
|
||||||
{
|
|
||||||
/* Skip subdirectories */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
register_test(entry->d_name, type);
|
|
||||||
}
|
|
||||||
closedir(dirp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Can't open %s\n", path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int
|
|
||||||
is_file_changed(char *filename,
|
|
||||||
char *content)
|
|
||||||
{
|
|
||||||
FILE *file;
|
|
||||||
int size;
|
|
||||||
int n;
|
|
||||||
char *filecontent;
|
|
||||||
|
|
||||||
file = fopen(filename, "rb");
|
|
||||||
if (file == NULL)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
fseek(file, 0, SEEK_END);
|
|
||||||
size = ftell(file);
|
|
||||||
fseek(file, 0, SEEK_SET);
|
|
||||||
if (size <= 0)
|
|
||||||
{
|
|
||||||
fclose(file);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
filecontent = malloc(size);
|
|
||||||
if (filecontent == NULL)
|
|
||||||
{
|
|
||||||
fclose(file);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
n = fread(filecontent, 1, size, file);
|
|
||||||
|
|
||||||
if (n != strlen(content))
|
|
||||||
{
|
|
||||||
free(filecontent);
|
|
||||||
fclose(file);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(content, filecontent) != 0)
|
|
||||||
{
|
|
||||||
free(filecontent);
|
|
||||||
fclose(file);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(filecontent);
|
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
write_file_if_changed(char *filename,
|
|
||||||
char *content)
|
|
||||||
{
|
|
||||||
FILE *file;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
if (is_file_changed(filename, content) == 0)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
file = fopen(filename, "wb");
|
|
||||||
if (file == NULL)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
n = fwrite(content, 1, strlen(content), file);
|
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char EXESTUB[] =
|
|
||||||
"/* This file is autogenerated. */\n"
|
|
||||||
"\n"
|
|
||||||
"#include <windows.h>\n"
|
|
||||||
"#include \"regtests.h\"\n"
|
|
||||||
"\n"
|
|
||||||
"void\n"
|
|
||||||
"ConsoleWrite(char *Buffer)\n"
|
|
||||||
"{\n"
|
|
||||||
" printf(Buffer);\n"
|
|
||||||
"}\n"
|
|
||||||
"\n"
|
|
||||||
"int\n"
|
|
||||||
"mainCRTStartup(HANDLE hInstance,\n"
|
|
||||||
" HANDLE hPrevInstance,\n"
|
|
||||||
" LPSTR lpszCmdParam,\n"
|
|
||||||
" int nCmdShow)\n"
|
|
||||||
"{\n"
|
|
||||||
" InitializeTests();\n"
|
|
||||||
" RegisterTests();\n"
|
|
||||||
" SetupOnce();\n"
|
|
||||||
" PerformTests(ConsoleWrite, NULL);\n"
|
|
||||||
" _ExitProcess(0);\n"
|
|
||||||
" return 0;\n"
|
|
||||||
"}\n";
|
|
||||||
|
|
||||||
static char STUBS_HEADER[] =
|
|
||||||
"/* This file is autogenerated. */\n"
|
|
||||||
"passthrough:\n"
|
|
||||||
" call _FrameworkGetHook@4\n"
|
|
||||||
" test %eax, %eax\n"
|
|
||||||
" je .return\n"
|
|
||||||
" jmp *%eax\n"
|
|
||||||
".return:\n"
|
|
||||||
" /* This will most likely corrupt the stack */\n"
|
|
||||||
" ret\n"
|
|
||||||
"\n";
|
|
||||||
|
|
||||||
static char HOOKS_HEADER[] =
|
|
||||||
"/* This file is autogenerated. */\n"
|
|
||||||
"#include <windows.h>\n"
|
|
||||||
"#include \"regtests.h\"\n"
|
|
||||||
"\n"
|
|
||||||
"API_DESCRIPTION ExternalDependencies[] =\n"
|
|
||||||
"{\n";
|
|
||||||
|
|
||||||
static char HOOKS_FOOTER[] =
|
|
||||||
"};\n"
|
|
||||||
"\n"
|
|
||||||
"#define ExternalDependencyCount %d\n"
|
|
||||||
"ULONG MaxExternalDependency = ExternalDependencyCount - 1;\n";
|
|
||||||
|
|
||||||
static char HELP[] =
|
|
||||||
"REGTESTS path file makefile [-e exestubfile]\n"
|
|
||||||
"REGTESTS -s stublistfile stubsfile hooksfile\n"
|
|
||||||
"\n"
|
|
||||||
" path Path to files\n"
|
|
||||||
" file Registration file to create\n"
|
|
||||||
" makefile Makefile to create\n"
|
|
||||||
" exestubfile Optional stub for running tests in the build environment\n"
|
|
||||||
" stublistfile File with descriptions of stubs\n"
|
|
||||||
" stubsfile File with stubs to create\n"
|
|
||||||
" hooksfile File with hooks to create\n";
|
|
||||||
|
|
||||||
#define INPUT_BUFFER_SIZE 255
|
|
||||||
|
|
||||||
void
|
|
||||||
write_stubs_header(FILE * out)
|
|
||||||
{
|
|
||||||
fputs(STUBS_HEADER, out);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
write_hooks_header(FILE * out)
|
|
||||||
{
|
|
||||||
fputs(HOOKS_HEADER, out);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
write_hooks_footer(FILE *hooks_out, unsigned long nr_stubs)
|
|
||||||
{
|
|
||||||
fprintf(hooks_out, HOOKS_FOOTER, nr_stubs);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
get_symbolname(char *decoratedname)
|
|
||||||
{
|
|
||||||
char buf[300];
|
|
||||||
|
|
||||||
if (decoratedname[0] == '@')
|
|
||||||
return strdup(decoratedname);
|
|
||||||
strcpy(buf, "_");
|
|
||||||
strcat(buf, decoratedname);
|
|
||||||
return strdup(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
get_undecorated_name(char *buf,
|
|
||||||
char *decoratedname)
|
|
||||||
{
|
|
||||||
int start = 0;
|
|
||||||
int end = 0;
|
|
||||||
|
|
||||||
while (start < strlen(decoratedname) && decoratedname[start] == '@')
|
|
||||||
{
|
|
||||||
start++;
|
|
||||||
}
|
|
||||||
strcpy(buf, &decoratedname[start]);
|
|
||||||
end = strlen(buf) - 1;
|
|
||||||
while (end > 0 && isdigit(buf[end]))
|
|
||||||
{
|
|
||||||
end--;
|
|
||||||
}
|
|
||||||
if (buf[end] == '@')
|
|
||||||
{
|
|
||||||
buf[end] = 0;
|
|
||||||
}
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
get_forwarded_export(char *forwardedexport)
|
|
||||||
{
|
|
||||||
char buf[300];
|
|
||||||
|
|
||||||
if (forwardedexport == NULL)
|
|
||||||
{
|
|
||||||
strcpy(buf, "NULL");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sprintf(buf, "\"%s\"", forwardedexport);
|
|
||||||
}
|
|
||||||
return strdup(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
write_stub(FILE *stubs_out, FILE *hooks_out, char *dllname,
|
|
||||||
char *decoratedname_and_forward, unsigned int stub_index)
|
|
||||||
{
|
|
||||||
char buf[300];
|
|
||||||
char *p;
|
|
||||||
char *decoratedname = NULL;
|
|
||||||
char *forwardedexport = NULL;
|
|
||||||
char *symbolname = NULL;
|
|
||||||
|
|
||||||
p = strtok(decoratedname_and_forward, "=");
|
|
||||||
if (p != NULL)
|
|
||||||
{
|
|
||||||
decoratedname = p;
|
|
||||||
|
|
||||||
p = strtok(NULL, "=");
|
|
||||||
forwardedexport = p;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
decoratedname = decoratedname_and_forward;
|
|
||||||
forwardedexport = decoratedname_and_forward;
|
|
||||||
}
|
|
||||||
|
|
||||||
symbolname = get_symbolname(decoratedname);
|
|
||||||
fprintf(stubs_out, ".globl %s\n", symbolname);
|
|
||||||
fprintf(stubs_out, "%s:\n", symbolname);
|
|
||||||
free(symbolname);
|
|
||||||
fprintf(stubs_out, " pushl $%d\n", stub_index);
|
|
||||||
fprintf(stubs_out, " jmp passthrough\n");
|
|
||||||
fprintf(stubs_out, "\n");
|
|
||||||
forwardedexport = get_forwarded_export(forwardedexport);
|
|
||||||
fprintf(hooks_out, " {\"%s\", \"%s\", %s, NULL, NULL},\n",
|
|
||||||
dllname,
|
|
||||||
get_undecorated_name(buf, decoratedname),
|
|
||||||
forwardedexport);
|
|
||||||
free(forwardedexport);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
create_stubs_and_hooks(
|
|
||||||
FILE *in,
|
|
||||||
FILE *stubs_out,
|
|
||||||
FILE *hooks_out)
|
|
||||||
{
|
|
||||||
char line[INPUT_BUFFER_SIZE];
|
|
||||||
char *s, *start;
|
|
||||||
char *dllname;
|
|
||||||
char *decoratedname_and_forward;
|
|
||||||
int stub_index;
|
|
||||||
|
|
||||||
write_stubs_header(stubs_out);
|
|
||||||
|
|
||||||
write_hooks_header(hooks_out);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Scan the database. The database is a text file; each
|
|
||||||
* line is a record, which contains data for one stub.
|
|
||||||
* Each record has two columns:
|
|
||||||
*
|
|
||||||
* DLLNAME (e.g. ntdll.dll)
|
|
||||||
* DECORATED NAME (e.g. NtCreateProcess@32, @InterlockedIncrement@4 or printf)
|
|
||||||
*/
|
|
||||||
stub_index = 0; /* First stub has index zero */
|
|
||||||
|
|
||||||
for (
|
|
||||||
;
|
|
||||||
/* Go on until EOF or read zero bytes */
|
|
||||||
((!feof(in)) && (fgets(line, sizeof line, in) != NULL));
|
|
||||||
/* Next stub index */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Ignore leading blanks
|
|
||||||
*/
|
|
||||||
for( start = line; *start && isspace(*start); start++ );
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Strip comments, eols
|
|
||||||
*/
|
|
||||||
for( s = start; *s && !strchr("#\n\r", *s); s++ );
|
|
||||||
|
|
||||||
*s = '\0';
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Remove trailing blanks. Backup off the char that ended our
|
|
||||||
* run before.
|
|
||||||
*/
|
|
||||||
for( s--; s > start && isspace(*s); s-- ) *s = '\0';
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Skip empty lines
|
|
||||||
*/
|
|
||||||
if (s > start)
|
|
||||||
{
|
|
||||||
/* Extract the DLL name */
|
|
||||||
dllname = (char *) strtok(start, " \t");
|
|
||||||
if (dllname != NULL && strlen(dllname) > 0)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Extract the decorated function name and possibly forwarded export.
|
|
||||||
* Format:
|
|
||||||
* decoratedname=forwardedexport (no DLL name)
|
|
||||||
*/
|
|
||||||
decoratedname_and_forward = (char *) strtok(NULL, " \t");
|
|
||||||
/* Extract the argument count */
|
|
||||||
|
|
||||||
/* Something went wrong finding the separator ...
|
|
||||||
* print an error and bail. */
|
|
||||||
if( !decoratedname_and_forward ) {
|
|
||||||
fprintf
|
|
||||||
( stderr,
|
|
||||||
"Could not find separator between decorated "
|
|
||||||
"function name and dll name.\n"
|
|
||||||
"Format entries as <dllname> <import>\n"
|
|
||||||
"Legal comments start with #\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
write_stub(stubs_out, hooks_out, dllname, decoratedname_and_forward, stub_index);
|
|
||||||
stub_index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
write_hooks_footer(hooks_out, stub_index);
|
|
||||||
}
|
|
||||||
|
|
||||||
int run_stubs(int argc,
|
|
||||||
char **argv)
|
|
||||||
{
|
|
||||||
FILE *in;
|
|
||||||
FILE *stubs_out;
|
|
||||||
FILE *hooks_out;
|
|
||||||
|
|
||||||
in = fopen(argv[2], "rb");
|
|
||||||
if (in == NULL)
|
|
||||||
{
|
|
||||||
perror("Failed to open stub description input file");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
stubs_out = fopen(argv[3], "wb");
|
|
||||||
if (stubs_out == NULL)
|
|
||||||
{
|
|
||||||
perror("Failed to open stubs output file");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
hooks_out = fopen(argv[4], "wb");
|
|
||||||
if (hooks_out == NULL)
|
|
||||||
{
|
|
||||||
perror("Failed to open hooks output file");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
create_stubs_and_hooks(in, stubs_out, hooks_out);
|
|
||||||
|
|
||||||
fclose(stubs_out);
|
|
||||||
fclose(hooks_out);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int run_registrations(int argc,
|
|
||||||
char **argv)
|
|
||||||
{
|
|
||||||
char buf[MAX_PATH];
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (argc < 4)
|
|
||||||
{
|
|
||||||
puts(HELP);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
strcpy(buf, convert_path(argv[1]));
|
|
||||||
if (buf[strlen(buf)] != DIR_SEPARATOR_CHAR)
|
|
||||||
{
|
|
||||||
int i = strlen(buf);
|
|
||||||
buf[strlen(buf)] = DIR_SEPARATOR_CHAR;
|
|
||||||
buf[i + 1] = 0;
|
|
||||||
}
|
|
||||||
path = buf;
|
|
||||||
if (path[0] == 0)
|
|
||||||
{
|
|
||||||
printf("Missing path\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
file = convert_path(argv[2]);
|
|
||||||
if (file[0] == 0)
|
|
||||||
{
|
|
||||||
printf("Missing file\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
makefile = convert_path(argv[3]);
|
|
||||||
if (makefile[0] == 0)
|
|
||||||
{
|
|
||||||
printf("Missing makefile\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
exestubfile = NULL;
|
|
||||||
for (i = 4; i < argc; i++)
|
|
||||||
{
|
|
||||||
if (argv[i][0] == '-')
|
|
||||||
{
|
|
||||||
if (argv[i][1] == 'e')
|
|
||||||
{
|
|
||||||
exestubfile = convert_path(argv[++i]);
|
|
||||||
if (exestubfile[0] == 0)
|
|
||||||
{
|
|
||||||
printf("Missing exestubfile\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Unknown switch -%c\n", argv[i][1]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Registration file */
|
|
||||||
out = fopen(file, "wb");
|
|
||||||
if (out == NULL)
|
|
||||||
{
|
|
||||||
perror("Cannot create output file");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
write_line("/* This file is autogenerated. */");
|
|
||||||
write_line("");
|
|
||||||
write_line("typedef int (*TestRoutine)(int Command, char *Buffer);");
|
|
||||||
write_line("");
|
|
||||||
|
|
||||||
make_file_list(0);
|
|
||||||
|
|
||||||
write_line("");
|
|
||||||
write_line("extern void AddTest(TestRoutine Routine);");
|
|
||||||
write_line("");
|
|
||||||
write_line("void RegisterTests()");
|
|
||||||
write_line("{");
|
|
||||||
|
|
||||||
make_file_list(1);
|
|
||||||
|
|
||||||
write_line("}");
|
|
||||||
|
|
||||||
fclose(out);
|
|
||||||
|
|
||||||
|
|
||||||
/* Makefile */
|
|
||||||
out = fopen(makefile, "wb");
|
|
||||||
if (out == NULL)
|
|
||||||
{
|
|
||||||
perror("Cannot create output makefile");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
write_line("# This file is autogenerated.");
|
|
||||||
write_line("");
|
|
||||||
write_line("TESTS = \\");
|
|
||||||
|
|
||||||
make_file_list(2);
|
|
||||||
|
|
||||||
write_line("");
|
|
||||||
|
|
||||||
fclose(out);
|
|
||||||
|
|
||||||
/* Executable stubfile */
|
|
||||||
if (exestubfile != NULL)
|
|
||||||
{
|
|
||||||
if (write_file_if_changed(exestubfile, EXESTUB) != 0)
|
|
||||||
{
|
|
||||||
perror("Cannot create output executable stubfile");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc,
|
|
||||||
char **argv)
|
|
||||||
{
|
|
||||||
if (argc < 2)
|
|
||||||
{
|
|
||||||
puts(HELP);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strlen(argv[1]) > 1 && argv[1][0] == '-' && argv[1][1] == 's')
|
|
||||||
{
|
|
||||||
return run_stubs(argc, argv);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return run_registrations(argc, argv);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,136 +0,0 @@
|
||||||
/*
|
|
||||||
* Copy a text file with end-of-line character transformation (EOL)
|
|
||||||
*
|
|
||||||
* Usage: rline input-file output-file
|
|
||||||
*/
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
fsize (FILE * f)
|
|
||||||
{
|
|
||||||
struct stat st;
|
|
||||||
int fh = fileno (f);
|
|
||||||
|
|
||||||
if (fh < 0 || fstat (fh, &st) < 0)
|
|
||||||
return -1;
|
|
||||||
return (int) st.st_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
char* path1;
|
|
||||||
char* path2;
|
|
||||||
FILE* in;
|
|
||||||
FILE* out;
|
|
||||||
char* in_buf;
|
|
||||||
int in_size;
|
|
||||||
int in_ptr;
|
|
||||||
int linelen;
|
|
||||||
int n_in;
|
|
||||||
int n_out;
|
|
||||||
char eol_buf[2];
|
|
||||||
|
|
||||||
/* Terminate the line with windows EOL characters (CRLF) */
|
|
||||||
eol_buf[0] = '\r';
|
|
||||||
eol_buf[1] = '\n';
|
|
||||||
|
|
||||||
if (argc != 3)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Wrong argument count\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);
|
|
||||||
}
|
|
||||||
|
|
||||||
in_size = fsize(in);
|
|
||||||
in_buf = malloc(in_size);
|
|
||||||
if (in_buf == NULL)
|
|
||||||
{
|
|
||||||
perror("Not enough free memory");
|
|
||||||
fclose(in);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
out = fopen(path2, "wb");
|
|
||||||
if (out == NULL)
|
|
||||||
{
|
|
||||||
perror("Cannot open output file");
|
|
||||||
fclose(in);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read it all in */
|
|
||||||
n_in = fread(in_buf, 1, in_size, in);
|
|
||||||
|
|
||||||
in_ptr = 0;
|
|
||||||
while (in_ptr < in_size)
|
|
||||||
{
|
|
||||||
linelen = 0;
|
|
||||||
|
|
||||||
while ((in_ptr + linelen < in_size) && (in_buf[in_ptr + linelen] != '\r') && (in_buf[in_ptr + linelen] != '\n'))
|
|
||||||
{
|
|
||||||
linelen++;
|
|
||||||
}
|
|
||||||
if (linelen > 0)
|
|
||||||
{
|
|
||||||
n_out = fwrite(&in_buf[in_ptr], 1, linelen, out);
|
|
||||||
in_ptr += linelen;
|
|
||||||
}
|
|
||||||
/* Terminate the line */
|
|
||||||
n_out = fwrite(&eol_buf[0], 1, sizeof(eol_buf), out);
|
|
||||||
|
|
||||||
if ((in_ptr < in_size) && (in_buf[in_ptr] == '\r'))
|
|
||||||
{
|
|
||||||
in_ptr++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((in_ptr < in_size) && (in_buf[in_ptr] == '\n'))
|
|
||||||
{
|
|
||||||
in_ptr++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(in_buf);
|
|
||||||
fclose(in);
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
}
|
|
|
@ -1,110 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <direct.h>
|
|
||||||
#else
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define WIN_SEPARATOR_CHAR '\\'
|
|
||||||
#define WIN_SEPARATOR_STRING "\\"
|
|
||||||
#define NIX_SEPARATOR_CHAR '/'
|
|
||||||
#define NIX_SEPARATOR_STRING "/"
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#define DIR_SEPARATOR_CHAR WIN_SEPARATOR_CHAR
|
|
||||||
#define DIR_SEPARATOR_STRING WIN_SEPARATOR_STRING
|
|
||||||
#define BAD_SEPARATOR_CHAR NIX_SEPARATOR_CHAR
|
|
||||||
#define MKDIR(s) mkdir(s)
|
|
||||||
#else
|
|
||||||
#define DIR_SEPARATOR_CHAR NIX_SEPARATOR_CHAR
|
|
||||||
#define DIR_SEPARATOR_STRING NIX_SEPARATOR_STRING
|
|
||||||
#define BAD_SEPARATOR_CHAR WIN_SEPARATOR_CHAR
|
|
||||||
#define MKDIR(s) mkdir(s,0755)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char*
|
|
||||||
convert_path(char* origpath)
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
|
|
||||||
int mkdir_p(char* path)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
char* path1;
|
|
||||||
char* csec;
|
|
||||||
char buf[256];
|
|
||||||
|
|
||||||
if (argc != 2)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Too many arguments\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
path1 = convert_path(argv[1]);
|
|
||||||
|
|
||||||
if (isalpha(path1[0]) && path1[1] == ':' && path1[2] == DIR_SEPARATOR_CHAR)
|
|
||||||
{
|
|
||||||
csec = strtok(path1, DIR_SEPARATOR_STRING);
|
|
||||||
sprintf(buf, "%s\\", csec);
|
|
||||||
chdir(buf);
|
|
||||||
csec = strtok(NULL, DIR_SEPARATOR_STRING);
|
|
||||||
}
|
|
||||||
else if (path1[0] == DIR_SEPARATOR_CHAR)
|
|
||||||
{
|
|
||||||
chdir(DIR_SEPARATOR_STRING);
|
|
||||||
csec = strtok(path1, DIR_SEPARATOR_STRING);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
csec = strtok(path1, DIR_SEPARATOR_STRING);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (csec != NULL)
|
|
||||||
{
|
|
||||||
mkdir_p(csec);
|
|
||||||
csec = strtok(NULL, DIR_SEPARATOR_STRING);
|
|
||||||
}
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
}
|
|
|
@ -1,95 +0,0 @@
|
||||||
/* $Id$
|
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
|
||||||
* PROGRAMMER: Rex Jolliff (rex@lvcablemodem.com)
|
|
||||||
* Casper S. Hornstrup (chorns@users.sourceforge.net)
|
|
||||||
* PURPOSE: Platform independent remove directory command
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#ifndef _MSC_VER
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void
|
|
||||||
convertPath (char * pathToConvert)
|
|
||||||
{
|
|
||||||
while (*pathToConvert != 0)
|
|
||||||
{
|
|
||||||
if (*pathToConvert == '\\')
|
|
||||||
{
|
|
||||||
*pathToConvert = '/';
|
|
||||||
}
|
|
||||||
pathToConvert++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
|
@ -1,86 +0,0 @@
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <sys/utime.h>
|
|
||||||
#include <time.h>
|
|
||||||
#else
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
char* convert_path(char* origpath)
|
|
||||||
{
|
|
||||||
char* newpath;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
//newpath = (char *)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
|
|
||||||
#ifdef DOS_PATHS
|
|
||||||
if (newpath[i] == '/')
|
|
||||||
{
|
|
||||||
newpath[i] = '\\';
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return(newpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
char* path;
|
|
||||||
int id;
|
|
||||||
#ifdef WIN32
|
|
||||||
time_t now;
|
|
||||||
struct utimbuf fnow;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (argc != 2)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Wrong number of arguments.\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
path = convert_path(argv[1]);
|
|
||||||
id = open(path, S_IWRITE, S_IRUSR | S_IWUSR);
|
|
||||||
if (id < 0)
|
|
||||||
{
|
|
||||||
id = open(path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
|
|
||||||
if (id < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Cannot create file.\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
close(id);
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
now = time(NULL);
|
|
||||||
fnow.actime = now;
|
|
||||||
fnow.modtime = now;
|
|
||||||
(int) utime(path, &fnow);
|
|
||||||
#else
|
|
||||||
(int) utimes(path, NULL);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue