Compare commits
2 Commits
d19256621b
...
f5d82983a4
Author | SHA1 | Date | |
---|---|---|---|
f5d82983a4 | |||
bc4be4e295 |
@@ -6,51 +6,28 @@
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
int len;
|
int len;
|
||||||
Var *members;
|
Var *members;
|
||||||
|
bool alive;
|
||||||
} Array;
|
} Array;
|
||||||
|
|
||||||
# define ArrayIndexOutOfBound = (Status){\
|
DEFSTATUS(ArrayIndexOutOfBound, 1, "Given index was accessing illegal address.", STATUS_ERROR, &MemoryViolation);
|
||||||
.identity = nameof(ArrayIndexOutOfBound),\
|
DEFSTATUS(InvalidArrayLength, 1, "Given length is invalid.", STATUS_ERROR, &ErrorStatus);
|
||||||
.value = 1,\
|
|
||||||
.description = "Given index was accessing illegal address.",\
|
|
||||||
.characteristic = STATUS_ERROR,\
|
|
||||||
.prev = &MemoryViolation\
|
|
||||||
}
|
|
||||||
|
|
||||||
# define InvalidArrayLength (Status){\
|
Status Array_Create(Array *inst, int len, size_t size);
|
||||||
.value = 1,\
|
|
||||||
.description = "Given length is invalid.",\
|
|
||||||
.characteristic = STATUS_ERROR,\
|
|
||||||
.prev = &ErrorStatus\
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Elementary. */
|
|
||||||
Status Array_Create(Array *inst, int len, size_t size)
|
|
||||||
throws(InsufficientMemory InvalidArrayLength);
|
|
||||||
Status Array_CopyOf(Array *inst, Array *other);
|
Status Array_CopyOf(Array *inst, Array *other);
|
||||||
Status Array_Delete(Array *inst);
|
void Array_Delete(Array *inst);
|
||||||
Status Array_GetIdx(Array *inst, Var *store, int index);
|
Status Array_GetIdx(Array *inst, Var *store, int index);
|
||||||
throws(ArrayIndexOutOfBound);
|
|
||||||
Status Array_SetIdx(Array *inst, Var *source, int index);
|
Status Array_SetIdx(Array *inst, Var *source, int index);
|
||||||
throws(ArrayIndexOutOfBound);
|
|
||||||
bool Array_Equals(Array *arr1, Array *arr2);
|
bool Array_Equals(Array *arr1, Array *arr2);
|
||||||
|
|
||||||
/* Extensional. */
|
|
||||||
Status ArrayUtils_Insert(Array *inst, Var *item, int index);
|
Status ArrayUtils_Insert(Array *inst, Var *item, int index);
|
||||||
throws(ArrayIndexOutOfBound);
|
|
||||||
Status ArrayUtils_InsertArray(Array *inst, Array *items, int index);
|
Status ArrayUtils_InsertArray(Array *inst, Array *items, int index);
|
||||||
throws(ArrayIndexOutOfBound);
|
|
||||||
Status ArrayUtils_Remove(Array *inst, int index);
|
Status ArrayUtils_Remove(Array *inst, int index);
|
||||||
throws(ArrayIndexOutOfBound);
|
|
||||||
Status ArrayUtils_RemoveArray(Array *inst, int off, int len);
|
Status ArrayUtils_RemoveArray(Array *inst, int off, int len);
|
||||||
throws(ArrayIndexOutOfBound InvalidArrayLength);
|
|
||||||
Status ArrayUtils_Subarray(Array *inst, Array *store, int off, int len);
|
Status ArrayUtils_Subarray(Array *inst, Array *store, int off, int len);
|
||||||
throws(ArrayIndexOutOfBound InvalidArrayLength);
|
|
||||||
Status ArrayUtils_Fill(Array *inst, Var *elem, int off, int len);
|
Status ArrayUtils_Fill(Array *inst, Var *elem, int off, int len);
|
||||||
throws(ArrayIndexOutOfBound InvalidArrayLength);
|
|
||||||
Status ArrayUtils_Search(Array *inst, Var *item, int *store);
|
Status ArrayUtils_Search(Array *inst, Var *item, int *store);
|
||||||
Status ArrayUtils_SearchArray(Array *inst, Array *items, int *store);
|
Status ArrayUtils_SearchArray(Array *inst, Array *items, int *store);
|
||||||
Status ArrayUtils_Split(Array *inst, Array *fore, Array *rear, int index);
|
Status ArrayUtils_Split(Array *inst, Array *fore, Array *rear, int index);
|
||||||
throws(ArrayIndexOutOfBound);
|
|
||||||
Status ArrayUtils_Revert(Array *inst);
|
Status ArrayUtils_Revert(Array *inst);
|
||||||
bool ArrayUtils_IsEmpty(Array *inst);
|
bool ArrayUtils_IsEmpty(Array *inst);
|
||||||
bool ArrayUtils_IsBlank(Array *inst);
|
bool ArrayUtils_IsBlank(Array *inst);
|
||||||
|
@@ -3,155 +3,146 @@
|
|||||||
|
|
||||||
Status Array_Create(Array *inst, int len, size_t size)
|
Status Array_Create(Array *inst, int len, size_t size)
|
||||||
{
|
{
|
||||||
/* Skip unavailable inst and invalid param. */
|
/* Skip the living instances. */
|
||||||
nonull(inst, apply(UnavailableInstance));
|
state(inst && inst->alive, apply(InstanceStillAlive));
|
||||||
state((len < 0), apply(InvalidArrayLength));
|
|
||||||
solve((!len), { inst->len = 0; inst->members = NULL; return apply(NormalStatus); })
|
|
||||||
|
|
||||||
inst->len = len;
|
/* Allocate for members from the inst. */
|
||||||
inst->members = calloc(len, sizeof(Var));
|
state(!(inst->members = calloc(len, sizeof(Var))), apply(InsufficientMemory));
|
||||||
|
|
||||||
|
/* Create for each item from members. */
|
||||||
int erridx = -1;
|
int erridx = -1;
|
||||||
|
Status errstat = EMPTY;
|
||||||
for (register int i = 0; i < len; i++) {
|
for (register int i = 0; i < len; i++) {
|
||||||
// TODO(william): Throw InsufficientMemory at following line.
|
notok(Var_Create(&inst->members[i], size), {
|
||||||
// DONE(william): ensure(Var_Create(&inst->members[i], size), "Failed to create a new var.");
|
|
||||||
|
|
||||||
notok((Var_Create(&inst->members[i], size)), {
|
|
||||||
#ifdef __DEBUG__
|
|
||||||
cat("Var_Create failed!\n")
|
|
||||||
#endif
|
|
||||||
erridx = i;
|
erridx = i;
|
||||||
|
errstat = apply(_);
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
#ifdef __DEBUG__
|
|
||||||
cat("Var_Create success!\n")
|
|
||||||
#endif
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Review on erridx. Release data that allocated. */
|
/* Got problem during allocations. */
|
||||||
if (erridx != -1) {
|
if (erridx >= 0) {
|
||||||
for (register int i = erridx; i >= 0; i--) {
|
/* Release members allocated backwardly. */
|
||||||
|
for (register int i = erridx - 1; i >= 0; i--) {
|
||||||
Var_Delete(&inst->members[i]);
|
Var_Delete(&inst->members[i]);
|
||||||
#ifdef __DEBUG__
|
|
||||||
cat("Deleted var from InsufficientMemory from Array_Create!")
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Release array itself. */
|
/* Release the array inst. */
|
||||||
free(inst->members);
|
free(inst->members);
|
||||||
|
|
||||||
return apply(InsufficientMemory);
|
return errstat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Assign rest of the struct members. */
|
||||||
|
inst->len = len;
|
||||||
|
inst->alive = true;
|
||||||
|
|
||||||
return apply(NormalStatus);
|
return apply(NormalStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
Status Array_CopyOf(Array *inst, Array *other)
|
Status Array_CopyOf(Array *inst, Array *other)
|
||||||
{
|
{
|
||||||
// /* Skip unavailable inst and invalid param. */
|
/* Skip unavailble parameters. */
|
||||||
// nonull(inst, apply(UnavailableInstance));
|
nonull(other,
|
||||||
// nonull(other, error(InvalidParameter, "Given other was unavailable."));
|
apply(annot(UnavailableInstance,
|
||||||
|
"Given object for copying to inst was unavailable.")));
|
||||||
|
|
||||||
// /* Assign value for len. */
|
/* Skip invalid parameters and instances. */
|
||||||
// inst->len = other->len;
|
state(inst && inst->alive,
|
||||||
|
apply(annot(InstanceStillAlive,
|
||||||
|
"Given inst for being copied was still alive.")));
|
||||||
|
|
||||||
// if (inst->members == NULL) return apply(NormalStatus);
|
state(!other->alive,
|
||||||
// match(RuntimeError, Array_Create(inst, other->len), "Failed on recreating "
|
apply(annot(InstanceNotAlive,
|
||||||
// "array.");
|
"Given object for copying to inst was not alive.")));
|
||||||
|
|
||||||
// /* Copy and assign for each member from other to inst. */
|
state(!other->len,
|
||||||
// for (register int i = 0; i < inst->len; i++) {
|
apply(annot(InvalidArrayLength,
|
||||||
// inst[i] = other[i];
|
"Given object for copying to inst has length of ZERO.")));
|
||||||
// }
|
|
||||||
|
|
||||||
// return apply(NormalStatus);
|
/* Allocate for members from the inst. */
|
||||||
|
state(!(inst->members = calloc(other->len, sizeof(Var))),
|
||||||
|
apply(InsufficientMemory));
|
||||||
|
|
||||||
|
/* Create for each item from members. */
|
||||||
|
int erridx = -1;
|
||||||
|
Status errstat = EMPTY;
|
||||||
|
for (register int i = 0; i < other->len; i++) {
|
||||||
|
notok(Var_Create(&inst->members[i], other->members[0].size), {
|
||||||
|
erridx = i;
|
||||||
|
errstat = apply(_);
|
||||||
|
break;
|
||||||
|
})
|
||||||
|
|
||||||
|
notok(Var_CopyOf(&inst->members[i], &other->members[i]), {
|
||||||
|
erridx = i;
|
||||||
|
errstat = apply(_);
|
||||||
|
break;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Got problem during allocations. */
|
||||||
/*
|
if (erridx >= 0) {
|
||||||
if (other == NULL) return 1;
|
/* Release members allocated backwardly. */
|
||||||
|
for (register int i = erridx - 1; i >= 0; i--) {
|
||||||
String_Create(inst, other->len);
|
Var_Delete(&inst->members[i]);
|
||||||
for (register int i = 0; i < other->len; i++) {
|
|
||||||
inst->arr[i] = other->arr[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
/* Release the array inst. */
|
||||||
|
free(inst->members);
|
||||||
|
|
||||||
|
return errstat;
|
||||||
|
}
|
||||||
|
|
||||||
*/
|
/* Assign rest of the struct members. */
|
||||||
|
inst->len = other->len;
|
||||||
|
inst->alive = true;
|
||||||
|
|
||||||
|
return apply(NormalStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
Status Array_Delete(Array *inst)
|
void Array_Delete(Array *inst)
|
||||||
{
|
{
|
||||||
/* Skip unavailable inst and invalid param. */
|
svoid(!inst || !inst->alive);
|
||||||
nonull(inst, apply(UnavailableInstance));
|
|
||||||
solve((inst->members == NULL), return apply(NormalStatus));
|
for (register int i = 0; i < inst->len; i++) {
|
||||||
|
Var_Delete(&inst->members[i]);
|
||||||
|
}
|
||||||
|
|
||||||
inst->len = 0;
|
|
||||||
free(inst->members);
|
free(inst->members);
|
||||||
inst->members = NULL;
|
|
||||||
|
|
||||||
return apply(NormalStatus);
|
inst->alive = false;
|
||||||
|
inst->len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status Array_GetIdx(Array *inst, Var *store, int index)
|
Status Array_GetIdx(Array *inst, Var *store, int index);
|
||||||
{
|
|
||||||
/* Skip unavailable inst and invalid param. */
|
|
||||||
nonull(inst, apply(UnavailableInstance));
|
|
||||||
nonull(store,
|
|
||||||
apply(error(InvalidParameter, "Given reference to store was unavailable.")));
|
|
||||||
state((index < 0 || index >= inst->len), apply(ArrayIndexOutOfBound));
|
|
||||||
|
|
||||||
*store = inst->members[index];
|
Status Array_SetIdx(Array *inst, Var *source, int index);
|
||||||
|
|
||||||
return apply(NormalStatus);
|
bool Array_Equals(Array *arr1, Array *arr2);
|
||||||
}
|
|
||||||
|
|
||||||
Status Array_SetIdx(Array *inst, Var *source, int index)
|
|
||||||
{
|
|
||||||
/* Skip unavailable inst and invalid param. */
|
|
||||||
nonull(inst, apply(UnavailableInstance));
|
|
||||||
nonull(source,
|
|
||||||
apply(
|
|
||||||
error(InvalidParameter, "Given reference to source was unavailable.")));
|
|
||||||
state((index < 0 || index >= inst->len), apply(ArrayIndexOutOfBound));
|
|
||||||
|
|
||||||
inst->members[index] = *source;
|
|
||||||
|
|
||||||
return apply(NormalStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Array_Equals(Array *a, Array *b)
|
|
||||||
{
|
|
||||||
/* Skip unavailable inst and invalid param. */
|
|
||||||
state((a == NULL || b == NULL), false);
|
|
||||||
state((a->len != b->len), false);
|
|
||||||
|
|
||||||
for (register int i = 0; i < a->len; i++) {
|
|
||||||
if (!Var_Equals(&a->members[i], &b->members[i])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
Status ArrayUtils_Insert(Array *inst, Var *item, int index);
|
||||||
|
|
||||||
Status ArrayUtils_Fill(Array *inst, Var *elem, int off, int len)
|
Status ArrayUtils_InsertArray(Array *inst, Array *items, int index);
|
||||||
{
|
|
||||||
nonull(inst, apply(UnavailableInstance));
|
|
||||||
nonull(elem,
|
|
||||||
apply(error(InvalidParameter, "Given reference to elem was unavailable.")));
|
|
||||||
state((off + len > inst->len) || (off < 0) || (len < 0),
|
|
||||||
apply(ArrayIndexOutOfBound));
|
|
||||||
|
|
||||||
/* Copy elem into each specified members from inst with off and len. */
|
Status ArrayUtils_Remove(Array *inst, int index);
|
||||||
for (register int i = off; i < (off + len); i++) {
|
|
||||||
inst->members[i] = *elem;
|
Status ArrayUtils_RemoveArray(Array *inst, int off, int len);
|
||||||
}
|
|
||||||
|
Status ArrayUtils_Subarray(Array *inst, Array *store, int off, int len);
|
||||||
|
|
||||||
|
Status ArrayUtils_Fill(Array *inst, Var *elem, int off, int len);
|
||||||
|
|
||||||
|
Status ArrayUtils_Search(Array *inst, Var *item, int *store);
|
||||||
|
|
||||||
|
Status ArrayUtils_SearchArray(Array *inst, Array *items, int *store);
|
||||||
|
|
||||||
|
Status ArrayUtils_Split(Array *inst, Array *fore, Array *rear, int index);
|
||||||
|
|
||||||
|
Status ArrayUtils_Revert(Array *inst);
|
||||||
|
|
||||||
|
bool ArrayUtils_IsEmpty(Array *inst);
|
||||||
|
|
||||||
|
bool ArrayUtils_IsBlank(Array *inst);
|
||||||
|
|
||||||
return apply(NormalStatus);
|
|
||||||
}
|
|
||||||
|
@@ -2,14 +2,14 @@ cmake_minimum_required (VERSION 3.5)
|
|||||||
|
|
||||||
project (Compound)
|
project (Compound)
|
||||||
|
|
||||||
set(CMAKE_C_COMPILER gcc)
|
set(CMAKE_C_COMPILER clang)
|
||||||
|
|
||||||
add_compile_options(-g -std=c99 -Wall -Wextra -D__DEBUG__)
|
add_compile_options(-g -std=c99 -Wall -Wextra -D__DEBUG__)
|
||||||
|
|
||||||
set(SHARED_SOURCE
|
set(SHARED_SOURCE
|
||||||
MemMan/src/memman.c
|
MemMan/src/memman.c
|
||||||
Status/src/status.c
|
Status/src/status.c
|
||||||
Utils/src/utils.c
|
Array/src/array.c
|
||||||
Var/src/var.c
|
Var/src/var.c
|
||||||
catlog.c)
|
catlog.c)
|
||||||
|
|
||||||
@@ -32,5 +32,6 @@ add_executable(CompoundTest
|
|||||||
test.c
|
test.c
|
||||||
MemMan/src/memman.c
|
MemMan/src/memman.c
|
||||||
Status/src/status.c
|
Status/src/status.c
|
||||||
Utils/src/utils.c
|
Array/src/array.c
|
||||||
|
Var/src/var.c
|
||||||
catlog.c)
|
catlog.c)
|
||||||
|
@@ -5,10 +5,6 @@ Status Location_Literalise(Location *inst, char *buff)
|
|||||||
nonull(inst, apply(UnavailableInstance));
|
nonull(inst, apply(UnavailableInstance));
|
||||||
nonull(buff, apply(UnavailableBuffer));
|
nonull(buff, apply(UnavailableBuffer));
|
||||||
|
|
||||||
/* Literalise line. */
|
|
||||||
char line_buff[LITERALISATION_LENGTH_MAXIMUM] = EMPTY;
|
|
||||||
Utils_LiteraliseInteger(inst->line, line_buff);
|
|
||||||
|
|
||||||
where(
|
where(
|
||||||
snprintf(buff, LITERALISATION_LENGTH_MAXIMUM,
|
snprintf(buff, LITERALISATION_LENGTH_MAXIMUM,
|
||||||
LOCATION_LITERALISE_FORMAT,inst->file,inst->line,inst->func),
|
LOCATION_LITERALISE_FORMAT,inst->file,inst->line,inst->func),
|
||||||
@@ -140,15 +136,6 @@ int StatusUtils_Depth(Status *stat)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return cnt;
|
return cnt;
|
||||||
|
|
||||||
// Status *current = stat; // Include this layer of Status.
|
|
||||||
// register int cnt;
|
|
||||||
// for (cnt = 0; (!StatusUtils_IsRecursive(*current)
|
|
||||||
// && StatusUtils_HasPrev(*current)); cnt++) {
|
|
||||||
// current = current->prev;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return cnt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// bool arguestarter_equal(ArgueStarter *inst1, ArgueStarter *inst2)
|
// bool arguestarter_equal(ArgueStarter *inst1, ArgueStarter *inst2)
|
||||||
|
@@ -1,49 +1,49 @@
|
|||||||
#include <Compound/utils.h>
|
#include <Compound/utils.h>
|
||||||
|
|
||||||
int Utils_CalcDigits(long long int n)
|
// int Utils_CalcDigits(long long int n)
|
||||||
{
|
// {
|
||||||
if (n == 0) {
|
// if (n == 0) {
|
||||||
return 1;
|
// return 1;
|
||||||
}
|
// }
|
||||||
|
|
||||||
n = llabs(n);
|
// n = llabs(n);
|
||||||
|
|
||||||
/* Accumulate. */
|
// /* Accumulate. */
|
||||||
register int i;
|
// register int i;
|
||||||
for (i = 0; n; i++) n /= 10;
|
// for (i = 0; n; i++) n /= 10;
|
||||||
|
|
||||||
return i;
|
// return i;
|
||||||
}
|
// }
|
||||||
|
|
||||||
int Utils_LiteraliseInteger(long long int n, char *buff)
|
// int Utils_LiteraliseInteger(long long int n, char *buff)
|
||||||
{
|
// {
|
||||||
/* Invalid buffer was presented. */
|
// /* Invalid buffer was presented. */
|
||||||
if (strlen(buff) != LITERALISATION_LENGTH_MAXIMUM) {
|
// if (strlen(buff) != LITERALISATION_LENGTH_MAXIMUM) {
|
||||||
buff = NULL;
|
// buff = NULL;
|
||||||
return 0;
|
// return 0;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (!n) {
|
// if (!n) {
|
||||||
buff = "0";
|
// buff = "0";
|
||||||
return 1;
|
// return 1;
|
||||||
}
|
// }
|
||||||
|
|
||||||
const int literalising_len = Utils_CalcDigits(n);
|
// const int literalising_len = Utils_CalcDigits(n);
|
||||||
if (literalising_len >= LITERALISATION_LENGTH_MAXIMUM) {
|
// if (literalising_len >= LITERALISATION_LENGTH_MAXIMUM) {
|
||||||
buff = NULL;
|
// buff = NULL;
|
||||||
return 0;
|
// return 0;
|
||||||
}
|
// }
|
||||||
|
|
||||||
char literalising[literalising_len];
|
// char literalising[literalising_len];
|
||||||
for (register int i = 0; i < literalising_len; i++) {
|
// for (register int i = 0; i < literalising_len; i++) {
|
||||||
literalising[i] = (n / (int)pow(10, i));
|
// literalising[i] = (n / (int)pow(10, i));
|
||||||
}
|
// }
|
||||||
|
|
||||||
return literalising_len;
|
// return literalising_len;
|
||||||
}
|
// }
|
||||||
|
|
||||||
int Utils_DateTimeLiteralise(time_t timer, char *buff,
|
// int Utils_DateTimeLiteralise(time_t timer, char *buff,
|
||||||
const char *__restrict format)
|
// const char *__restrict format)
|
||||||
{
|
// {
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
@@ -47,9 +47,10 @@ Status Var_CopyOf(Var *inst, Var *other)
|
|||||||
|
|
||||||
void Var_Delete(Var *inst)
|
void Var_Delete(Var *inst)
|
||||||
{
|
{
|
||||||
svoid(!inst);
|
svoid(!inst || !inst->alive);
|
||||||
|
|
||||||
free(inst->addr);
|
free(inst->addr);
|
||||||
|
inst->alive = false;
|
||||||
inst->addr = NULL;
|
inst->addr = NULL;
|
||||||
inst->size = 0;
|
inst->size = 0;
|
||||||
}
|
}
|
||||||
|
2
catlog.c
2
catlog.c
@@ -99,7 +99,7 @@ Status CatlogSender_Send(CatlogSender *inst)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Status CatlogUtils_OpenFile(FILE **fileptr, const char *filepath,
|
Status CatlogUtils_OpenFile(FILE **fileptr, const char *filepath,
|
||||||
const char const *restrict mode)
|
const char *restrict mode)
|
||||||
{
|
{
|
||||||
/* Skip unavailable instances and parameters. */
|
/* Skip unavailable instances and parameters. */
|
||||||
nonull(fileptr, apply(UnavailableBuffer));
|
nonull(fileptr, apply(UnavailableBuffer));
|
||||||
|
2
catlog.h
2
catlog.h
@@ -59,7 +59,7 @@ Status CatlogSender_CopyOf(CatlogSender *inst, CatlogSender *other);
|
|||||||
Status CatlogSender_Send(CatlogSender *inst);
|
Status CatlogSender_Send(CatlogSender *inst);
|
||||||
bool CatlogSender_Equals(CatlogSender *inst, CatlogSender *other);
|
bool CatlogSender_Equals(CatlogSender *inst, CatlogSender *other);
|
||||||
Status CatlogUtils_OpenFile(FILE **fileptr, const char *filepath,
|
Status CatlogUtils_OpenFile(FILE **fileptr, const char *filepath,
|
||||||
const char const *restrict mode);
|
const char *restrict mode);
|
||||||
Status CatlogUtils_CloseFile(FILE **fileptr);
|
Status CatlogUtils_CloseFile(FILE **fileptr);
|
||||||
|
|
||||||
#endif /* COMPOUND_CATLOG_H */
|
#endif /* COMPOUND_CATLOG_H */
|
||||||
|
7
common.h
7
common.h
@@ -1,10 +1,6 @@
|
|||||||
#ifndef COMPOUND_COMMON_H
|
#ifndef COMPOUND_COMMON_H
|
||||||
# define COMPOUND_COMMON_H
|
# define COMPOUND_COMMON_H
|
||||||
|
|
||||||
# ifdef __DEBUG__
|
|
||||||
# warning DEBUG IS ON
|
|
||||||
# endif /* __DEBUG__ */
|
|
||||||
|
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <stdbool.h>
|
# include <stdbool.h>
|
||||||
|
|
||||||
@@ -43,6 +39,9 @@
|
|||||||
/* Return e when passing a failing e commented with c. */
|
/* Return e when passing a failing e commented with c. */
|
||||||
# define fails(e, c) { notok(e, return apply(annot(_, c));) }
|
# define fails(e, c) { notok(e, return apply(annot(_, c));) }
|
||||||
|
|
||||||
|
/* Return e when passing a failing e. */
|
||||||
|
# define fail(e) { notok(e, return apply(_);) }
|
||||||
|
|
||||||
/* Return v when passing a failing e. */
|
/* Return v when passing a failing e. */
|
||||||
# define vfail(e, v) { notok(e, return v;) }
|
# define vfail(e, v) { notok(e, return v;) }
|
||||||
|
|
||||||
|
40
test.c
40
test.c
@@ -20,6 +20,38 @@ __attribute__((destructor))
|
|||||||
void __DESTRUCT__() {}
|
void __DESTRUCT__() {}
|
||||||
|
|
||||||
Status Main(void)
|
Status Main(void)
|
||||||
|
{
|
||||||
|
const int len = 8;
|
||||||
|
|
||||||
|
int iarr[] = {
|
||||||
|
1, 2, 4, 8, 16, 32, 64, 128
|
||||||
|
};
|
||||||
|
|
||||||
|
Array arr;
|
||||||
|
fails(Array_Create(&arr, len, sizeof(__typeof__(iarr[0]))),
|
||||||
|
"Failed to create an array instance.");
|
||||||
|
|
||||||
|
/* Array member assignments with iarr. */
|
||||||
|
for (register int i = 0; i < arr.len; i++) {
|
||||||
|
arr.members[i].addr = &iarr[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (register int i = 0; i < arr.len; i++) {
|
||||||
|
(void)printf("%d\n", i);
|
||||||
|
|
||||||
|
for (register int j = 0; j < *(int *)arr.members[i].addr; j++) {
|
||||||
|
(void)printf("#");
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Array_Delete(&arr);
|
||||||
|
|
||||||
|
return apply(NormalStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
Status MainStatus(void)
|
||||||
{
|
{
|
||||||
// Memory mem1;
|
// Memory mem1;
|
||||||
// seek(Memory_Create(&mem1, INT64_MAX), {
|
// seek(Memory_Create(&mem1, INT64_MAX), {
|
||||||
@@ -453,5 +485,11 @@ Status Main(void)
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
return Main().value;
|
int rtn = 0;
|
||||||
|
notok(Main(), {
|
||||||
|
rtn = _.value;
|
||||||
|
PrintStatusDump(_);
|
||||||
|
})
|
||||||
|
|
||||||
|
return rtn;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user