mirror of
https://github.com/weiju/amiga-stuff
synced 2026-03-21 03:51:24 +00:00
added missing dos compat files to requester project
This commit is contained in:
2
requesters/.gitignore
vendored
2
requesters/.gitignore
vendored
@ -1 +1,3 @@
|
||||
main
|
||||
dos_compat_test
|
||||
file_list_test
|
||||
|
||||
40
requesters/dos_compat.c
Normal file
40
requesters/dos_compat.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "dos_compat.h"
|
||||
|
||||
const char *dc_PathPart(const char *path)
|
||||
{
|
||||
if (path) {
|
||||
int slen = strlen(path);
|
||||
if (slen == 0) return path;
|
||||
int i = slen - 1;
|
||||
for (i = slen - 1; i > 0; i--) {
|
||||
if (path[i] == '/') break;
|
||||
if (path[i] == ':' && i < (slen - 1)) return &(path[i + 1]);
|
||||
}
|
||||
return &(path[i]);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *dc_FilePart(const char *path)
|
||||
{
|
||||
if (path) {
|
||||
int slen = strlen(path);
|
||||
if (slen == 0) return path;
|
||||
int i = slen - 1;
|
||||
for (i = slen - 1; i > 0; i--) {
|
||||
if (path[i] == '/') return &(path[i + 1]);
|
||||
if (path[i] == ':' && i < (slen - 1)) return &(path[i + 1]);
|
||||
}
|
||||
return &(path[i]);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int dc_AddPart(char *dest_path, const char *part_to_add, int dest_size)
|
||||
{
|
||||
if (dest_size == 0) return 0;
|
||||
return 0;
|
||||
}
|
||||
13
requesters/dos_compat.h
Normal file
13
requesters/dos_compat.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#ifndef __DOS_COMPAT_H__
|
||||
#define __DOS_COMPAT_H__
|
||||
|
||||
// Compatibility functions to implement 2.x functionality on 1.x systems
|
||||
|
||||
extern const char *dc_PathPart(const char *path);
|
||||
extern const char *dc_FilePart(const char *path);
|
||||
|
||||
extern int dc_AddPart(char *dest_path, const char *part_to_add, int dest_size);
|
||||
|
||||
#endif /* __DOS_COMPAT_H__ */
|
||||
|
||||
92
requesters/dos_compat_test.c
Normal file
92
requesters/dos_compat_test.c
Normal file
@ -0,0 +1,92 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "chibi.h"
|
||||
#include "dos_compat.h"
|
||||
|
||||
CHIBI_TEST(TestPathPartNull)
|
||||
{
|
||||
chibi_assert(dc_PathPart(NULL) == NULL);
|
||||
}
|
||||
|
||||
CHIBI_TEST(TestPathPartEmpty)
|
||||
{
|
||||
static char path[] = "";
|
||||
chibi_assert(dc_PathPart(path) == path);
|
||||
}
|
||||
|
||||
CHIBI_TEST(TestPathPartVolumeOnly)
|
||||
{
|
||||
static char path[] = "Workbench:";
|
||||
chibi_assert(dc_PathPart(path) == path);
|
||||
}
|
||||
|
||||
CHIBI_TEST(TestPathPartVolumeAndFile)
|
||||
{
|
||||
static char path[] = "Workbench:file1";
|
||||
chibi_assert(dc_PathPart(path) == &(path[10]));
|
||||
}
|
||||
|
||||
CHIBI_TEST(TestPathPartVolumeDirAndFile)
|
||||
{
|
||||
static char path[] = "Workbench:dir/file1";
|
||||
chibi_assert(dc_PathPart(path) == &(path[13]));
|
||||
}
|
||||
|
||||
CHIBI_TEST(TestFilePartNull)
|
||||
{
|
||||
chibi_assert(dc_FilePart(NULL) == NULL);
|
||||
}
|
||||
|
||||
CHIBI_TEST(TestFilePartEmpty)
|
||||
{
|
||||
static char path[] = "";
|
||||
chibi_assert(dc_FilePart(path) == path);
|
||||
}
|
||||
|
||||
CHIBI_TEST(TestFilePartVolumeOnly)
|
||||
{
|
||||
static char path[] = "Workbench:";
|
||||
chibi_assert(dc_FilePart(path) == path);
|
||||
}
|
||||
|
||||
CHIBI_TEST(TestFilePartVolumeAndFile)
|
||||
{
|
||||
static char path[] = "Workbench:file1";
|
||||
chibi_assert(dc_FilePart(path) == &(path[10]));
|
||||
}
|
||||
|
||||
CHIBI_TEST(TestFilePartVolumeDirAndFile)
|
||||
{
|
||||
static char path[] = "Workbench:dir/file1";
|
||||
chibi_assert(dc_FilePart(path) == &(path[14]));
|
||||
}
|
||||
|
||||
CHIBI_TEST(TestAddPartAllNull)
|
||||
{
|
||||
chibi_assert(dc_AddPart(NULL, NULL, 0) == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
chibi_summary_data summary;
|
||||
chibi_suite *suite = chibi_suite_new();
|
||||
|
||||
chibi_suite_add_test(suite, TestPathPartNull);
|
||||
chibi_suite_add_test(suite, TestPathPartEmpty);
|
||||
chibi_suite_add_test(suite, TestPathPartVolumeOnly);
|
||||
chibi_suite_add_test(suite, TestPathPartVolumeAndFile);
|
||||
chibi_suite_add_test(suite, TestPathPartVolumeDirAndFile);
|
||||
|
||||
chibi_suite_add_test(suite, TestFilePartNull);
|
||||
chibi_suite_add_test(suite, TestFilePartEmpty);
|
||||
chibi_suite_add_test(suite, TestFilePartVolumeOnly);
|
||||
chibi_suite_add_test(suite, TestFilePartVolumeAndFile);
|
||||
chibi_suite_add_test(suite, TestFilePartVolumeDirAndFile);
|
||||
|
||||
chibi_suite_add_test(suite, TestAddPartAllNull);
|
||||
|
||||
chibi_suite_run(suite, &summary);
|
||||
chibi_suite_delete(suite);
|
||||
return summary.num_failures;
|
||||
}
|
||||
Reference in New Issue
Block a user