This commit is contained in:
twinaphex 2020-01-30 17:48:20 +01:00
parent d2f9a76ce8
commit 5568b4ef93
11 changed files with 286 additions and 116 deletions

View file

@ -20,9 +20,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#if __TEST_FNMATCH__
#include <assert.h>
#endif
#include <stddef.h>
#include <compat/fnmatch.h>
@ -123,37 +120,3 @@ int rl_fnmatch(const char *pattern, const char *string, int flags)
return 0;
return FNM_NOMATCH;
}
#if __TEST_FNMATCH__
int main(void)
{
assert(rl_fnmatch("TEST", "TEST", 0) == 0);
assert(rl_fnmatch("TE?T", "TEST", 0) == 0);
assert(rl_fnmatch("TE[Ssa]T", "TEST", 0) == 0);
assert(rl_fnmatch("TE[Ssda]T", "TEsT", 0) == 0);
assert(rl_fnmatch("TE[Ssda]T", "TEdT", 0) == 0);
assert(rl_fnmatch("TE[Ssda]T", "TEaT", 0) == 0);
assert(rl_fnmatch("TEST*", "TEST", 0) == 0);
assert(rl_fnmatch("TEST**", "TEST", 0) == 0);
assert(rl_fnmatch("TE*ST*", "TEST", 0) == 0);
assert(rl_fnmatch("TE**ST*", "TEST", 0) == 0);
assert(rl_fnmatch("TE**ST*", "TExST", 0) == 0);
assert(rl_fnmatch("TE**ST", "TEST", 0) == 0);
assert(rl_fnmatch("TE**ST", "TExST", 0) == 0);
assert(rl_fnmatch("TE\\**ST", "TE*xST", 0) == 0);
assert(rl_fnmatch("*.*", "test.jpg", 0) == 0);
assert(rl_fnmatch("*.jpg", "test.jpg", 0) == 0);
assert(rl_fnmatch("*.[Jj][Pp][Gg]", "test.jPg", 0) == 0);
assert(rl_fnmatch("*.[Jj]*[Gg]", "test.jPg", 0) == 0);
assert(rl_fnmatch("TEST?", "TEST", 0) == FNM_NOMATCH);
assert(rl_fnmatch("TES[asd", "TEST", 0) == FNM_NOMATCH);
assert(rl_fnmatch("TEST\\", "TEST", 0) == FNM_NOMATCH);
assert(rl_fnmatch("TEST*S", "TEST", 0) == FNM_NOMATCH);
assert(rl_fnmatch("TE**ST", "TExT", 0) == FNM_NOMATCH);
assert(rl_fnmatch("TE\\*T", "TExT", 0) == FNM_NOMATCH);
assert(rl_fnmatch("TES?", "TES", 0) == FNM_NOMATCH);
assert(rl_fnmatch("TE", "TEST", 0) == FNM_NOMATCH);
assert(rl_fnmatch("TEST!", "TEST", 0) == FNM_NOMATCH);
assert(rl_fnmatch("DSAD", "TEST", 0) == FNM_NOMATCH);
}
#endif

View file

@ -84,20 +84,3 @@ int string_parse_html_anchor(const char *line, char *link, char *name,
return 0;
}
#ifndef RARCH_INTERNAL
int main(int argc, char *argv[])
{
char link[1024];
char name[1024];
const char *line = "<a href=\"http://www.test.com/somefile.zip\">Test</a>\n";
link[0] = name[0] = '\0';
string_parse_html_anchor(line, link, name, sizeof(link), sizeof(name));
printf("link: %s\nname: %s\n", link, name);
return 1;
}
#endif

View file

@ -0,0 +1,58 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (compat_fnmatch_test.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <assert.h>
#include <stddef.h>
#include <compat/fnmatch.h>
int main(void)
{
assert(rl_fnmatch("TEST", "TEST", 0) == 0);
assert(rl_fnmatch("TE?T", "TEST", 0) == 0);
assert(rl_fnmatch("TE[Ssa]T", "TEST", 0) == 0);
assert(rl_fnmatch("TE[Ssda]T", "TEsT", 0) == 0);
assert(rl_fnmatch("TE[Ssda]T", "TEdT", 0) == 0);
assert(rl_fnmatch("TE[Ssda]T", "TEaT", 0) == 0);
assert(rl_fnmatch("TEST*", "TEST", 0) == 0);
assert(rl_fnmatch("TEST**", "TEST", 0) == 0);
assert(rl_fnmatch("TE*ST*", "TEST", 0) == 0);
assert(rl_fnmatch("TE**ST*", "TEST", 0) == 0);
assert(rl_fnmatch("TE**ST*", "TExST", 0) == 0);
assert(rl_fnmatch("TE**ST", "TEST", 0) == 0);
assert(rl_fnmatch("TE**ST", "TExST", 0) == 0);
assert(rl_fnmatch("TE\\**ST", "TE*xST", 0) == 0);
assert(rl_fnmatch("*.*", "test.jpg", 0) == 0);
assert(rl_fnmatch("*.jpg", "test.jpg", 0) == 0);
assert(rl_fnmatch("*.[Jj][Pp][Gg]", "test.jPg", 0) == 0);
assert(rl_fnmatch("*.[Jj]*[Gg]", "test.jPg", 0) == 0);
assert(rl_fnmatch("TEST?", "TEST", 0) == FNM_NOMATCH);
assert(rl_fnmatch("TES[asd", "TEST", 0) == FNM_NOMATCH);
assert(rl_fnmatch("TEST\\", "TEST", 0) == FNM_NOMATCH);
assert(rl_fnmatch("TEST*S", "TEST", 0) == FNM_NOMATCH);
assert(rl_fnmatch("TE**ST", "TExT", 0) == FNM_NOMATCH);
assert(rl_fnmatch("TE\\*T", "TExT", 0) == FNM_NOMATCH);
assert(rl_fnmatch("TES?", "TES", 0) == FNM_NOMATCH);
assert(rl_fnmatch("TE", "TEST", 0) == FNM_NOMATCH);
assert(rl_fnmatch("TEST!", "TEST", 0) == FNM_NOMATCH);
assert(rl_fnmatch("DSAD", "TEST", 0) == FNM_NOMATCH);
}

View file

@ -0,0 +1,66 @@
/* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (rxml_test.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <formats/rxml.h>
#include <stdio.h>
static void print_siblings(struct rxml_node *node, unsigned level)
{
fprintf(stderr, "\n%*sName: %s\n", level * 4, "", node->name);
if (node->data)
fprintf(stderr, "%*sData: %s\n", level * 4, "", node->data);
for (const struct rxml_attrib_node *attrib =
node->attrib; attrib; attrib = attrib->next)
fprintf(stderr, "%*s Attrib: %s = %s\n", level * 4, "",
attrib->attrib, attrib->value);
if (node->children)
print_siblings(node->children, level + 1);
if (node->next)
print_siblings(node->next, level);
}
static void rxml_log_document(const char *path)
{
rxml_document_t *doc = rxml_load_document(path);
if (!doc)
{
fprintf(stderr, "rxml: Failed to load document: %s\n", path);
return;
}
print_siblings(rxml_root_node(doc), 0);
rxml_free_document(doc);
}
int main(int argc, char *argv[])
{
if (argc != 2)
{
fprintf(stderr, "Usage: %s <path>\n", argv[0]);
return 1;
}
rxml_log_document(argv[1]);
}

View file

@ -1,4 +1,4 @@
TARGETS = http_test net_ifinfo
TARGETS = http_test http_parse_test net_ifinfo
LIBRETRO_COMM_DIR := ../..
@ -37,6 +37,19 @@ HTTP_TEST_C = \
HTTP_TEST_OBJS := $(HTTP_TEST_C:.c=.o)
HTTP_PARSE_TEST_C = \
$(LIBRETRO_COMM_DIR)/net/net_http.c \
$(LIBRETRO_COMM_DIR)/net/net_http_parse.c \
$(LIBRETRO_COMM_DIR)/net/net_compat.c \
$(LIBRETRO_COMM_DIR)/net/net_socket.c \
$(LIBRETRO_COMM_DIR)/compat/compat_strl.c \
$(LIBRETRO_COMM_DIR)/compat/compat_strcasestr.c \
$(LIBRETRO_COMM_DIR)/encodings/encoding_utf.c \
$(LIBRETRO_COMM_DIR)/string/stdstring.c \
net_http_parse_test.c
HTTP_PARSE_TEST_OBJS := $(HTTP_PARSE_TEST_C:.c=.o)
NET_IFINFO_C = \
$(LIBRETRO_COMM_DIR)/net/net_ifinfo.c \
net_ifinfo_test.c
@ -54,6 +67,9 @@ all: $(TARGETS)
%.o: %.c
$(CC) $(INCFLAGS) $< -c $(CFLAGS) -o $@
http_parse_test: $(HTTP_PARSE_TEST_OBJS)
$(CC) $(INCFLAGS) $(HTTP_PARSE_TEST_OBJS) $(CFLAGS) -o $@
http_test: $(HTTP_TEST_OBJS)
$(CC) $(INCFLAGS) $(HTTP_TEST_OBJS) $(CFLAGS) -o $@
@ -61,4 +77,4 @@ net_ifinfo: $(NET_IFINFO_OBJS)
$(CC) $(INCFLAGS) $(NET_IFINFO_OBJS) $(CFLAGS) -o $@
clean:
rm -rf $(TARGETS) $(HTTP_TEST_OBJS) $(NET_IFINFO_OBJS)
rm -rf $(TARGETS) $(HTTP_TEST_OBJS) $(HTTP_PARSE_TEST_OBJS) $(NET_IFINFO_OBJS)

View file

@ -0,0 +1,39 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (net_http_parse_test.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <compat/strcasestr.h>
int main(int argc, char *argv[])
{
char link[1024];
char name[1024];
const char *line = "<a href=\"http://www.test.com/somefile.zip\">Test</a>\n";
link[0] = name[0] = '\0';
string_parse_html_anchor(line, link, name, sizeof(link), sizeof(name));
printf("link: %s\nname: %s\n", link, name);
return 1;
}

View file

@ -52,6 +52,7 @@ else
EXE_EXT = .exe
endif
PWD_DIR := .
LIBRETRO_COMM_DIR := ../..
CORE_DIR := $(LIBRETRO_COMM_DIR)/utils
@ -67,23 +68,33 @@ ASMFLAGS := -INEON/asm
asflags += -mfpu=neon
endif
OBJS += $(CORE_DIR)/djb2.o \
$(CORE_DIR)/md5.o \
$(CORE_DIR)/sha1.o \
$(CORE_DIR)/sha1_main.o \
$(CORE_DIR)/crc32.o
DJB2_OBJS := $(CORE_DIR)/djb2.o
MD5_OBJS := $(CORE_DIR)/md5.o \
$(PWD_DIR)/md5_test.o
SHA1_OBJS := $(CORE_DIR)/sha1.o \
$(PWD_DIR)/sha1_main.o
CRC32_OBJS := $(PWD_DIR)/crc32.o \
$(LIBRETRO_COMM_DIR)/compat/fopen_utf8.o \
$(LIBRETRO_COMM_DIR)/compat/compat_strl.o \
$(LIBRETRO_COMM_DIR)/encodings/encoding_utf.o \
$(LIBRETRO_COMM_DIR)/streams/file_stream.o \
$(LIBRETRO_COMM_DIR)/vfs/vfs_implementation.o \
$(LIBRETRO_COMM_DIR)/encodings/encoding_crc32.o
UTILS := djb2$(EXE_EXT) md5$(EXE_EXT) sha1$(EXE_EXT) crc32$(EXE_EXT)
all: $(UTILS)
djb2$(EXE_EXT): $(CORE_DIR)/djb2.o
djb2$(EXE_EXT): $(DJB2_OBJS)
md5$(EXE_EXT): $(CORE_DIR)/md5.o
md5$(EXE_EXT): $(MD5_OBJS)
sha1$(EXE_EXT): $(CORE_DIR)/sha1.o $(CORE_DIR)/sha1_main.o
sha1$(EXE_EXT): $(SHA1_OBJS)
crc32$(EXE_EXT): $(CORE_DIR)/crc32.o $(CORE_DIR)/../encodings/encoding_crc32.o
crc32$(EXE_EXT): $(CRC32_OBJS)
%.o: %.S
$(CC) -c -o $@ $(asflags) $(LDFLAGS) $(ASMFLAGS) $<

85
samples/utils/md5_test.c Normal file
View file

@ -0,0 +1,85 @@
/*
* This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
* MD5 Message-Digest Algorithm (RFC 1321).
*
* Homepage:
* http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
*
* Author:
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
*
* This software was written by Alexander Peslyak in 2001. No copyright is
* claimed, and the software is hereby placed in the public domain.
* In case this attempt to disclaim copyright and place the software in the
* public domain is deemed null and void, then the software is
* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
* general public under the following terms:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted.
*
* There's ABSOLUTELY NO WARRANTY, express or implied.
*
* (This is a heavily cut-down "BSD license".)
*
* This differs from Colin Plumb's older public domain implementation in that
* no exactly 32-bit integer data type is required (any 32-bit or wider
* unsigned integer data type will do), there's no compile-time endianness
* configuration, and the function prototypes match OpenSSL's. No code from
* Colin Plumb's implementation has been reused; this comment merely compares
* the properties of the two independent implementations.
*
* The primary goals of this implementation are portability and ease of use.
* It is meant to be fast, but not as fast as possible. Some known
* optimizations are not included to reduce source code size and avoid
* compile-time configuration.
*/
#include <stdio.h>
#include <string.h>
#include <rhash.h>
int main (int argc, char *argv[])
{
/* For each command line argument in turn:
** filename -- prints message digest and name of file
*/
int i;
MD5_CTX ctx;
FILE* file;
size_t numread;
char buffer[16384];
unsigned char result[16];
for (i = 1; i < argc; i++)
{
MD5_Init(&ctx);
file = fopen(argv[i], "rb");
if (file)
{
do
{
numread = fread((void*)buffer, 1, sizeof(buffer), file);
if (numread)
{
MD5_Update(&ctx,(void*)buffer, numread);
}
}
while (numread);
fclose(file);
MD5_Final(result, &ctx);
printf("%02x%02x%02x%02x%02x%02x%02x%02x"
"%02x%02x%02x%02x%02x%02x%02x%02x %s\n",
result[ 0 ], result[ 1 ], result[ 2 ], result[ 3 ],
result[ 4 ], result[ 5 ], result[ 6 ], result[ 7 ],
result[ 8 ], result[ 9 ], result[ 10 ], result[ 11 ],
result[ 12 ], result[ 13 ], result[ 14 ], result[ 15 ],
argv[i]);
}
}
return 0;
}

View file

@ -293,54 +293,3 @@ void MD5_Final(unsigned char *result, MD5_CTX *ctx)
memset(ctx, 0, sizeof(*ctx));
}
#ifdef MD5_BUILD_UTILITY
#include <stdio.h>
int main (int argc, char *argv[])
{
/* For each command line argument in turn:
** filename -- prints message digest and name of file
*/
int i;
MD5_CTX ctx;
FILE* file;
size_t numread;
char buffer[16384];
unsigned char result[16];
for (i = 1; i < argc; i++)
{
MD5_Init(&ctx);
file = fopen(argv[i], "rb");
if (file)
{
do
{
numread = fread((void*)buffer, 1, sizeof(buffer), file);
if (numread)
{
MD5_Update(&ctx,(void*)buffer, numread);
}
}
while (numread);
fclose(file);
MD5_Final(result, &ctx);
printf("%02x%02x%02x%02x%02x%02x%02x%02x"
"%02x%02x%02x%02x%02x%02x%02x%02x %s\n",
result[ 0 ], result[ 1 ], result[ 2 ], result[ 3 ],
result[ 4 ], result[ 5 ], result[ 6 ], result[ 7 ],
result[ 8 ], result[ 9 ], result[ 10 ], result[ 11 ],
result[ 12 ], result[ 13 ], result[ 14 ], result[ 15 ],
argv[i]);
}
}
return 0;
}
#endif