(MOD) Refined Var, Array, CatlogMsg, CatlogSender, Status
This is the very first version that pass the compiler. Though it has lots things were made for testing, such as commenting problematic source code to avoid irrelevant errors. For test.c, everything is working fine. Congrats!
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,3 +13,4 @@ todo_stack
|
||||
getReady.sh
|
||||
base_type.c
|
||||
sample
|
||||
compile
|
||||
|
@@ -21,23 +21,33 @@ static Status InvalidArrayLength = {
|
||||
};
|
||||
|
||||
/* Elementary. */
|
||||
Status Array_Create(Array *inst, int len);
|
||||
Status Array_Create(Array *inst, int len, size_t size)
|
||||
throws(InsufficientMemory InvalidArrayLength);
|
||||
Status Array_CopyOf(Array *inst, Array *other);
|
||||
Status Array_Delete(Array *inst);
|
||||
Status Array_GetIdx(Array *inst, Var *store, int index);
|
||||
throws(ArrayIndexOutOfBound);
|
||||
Status Array_SetIdx(Array *inst, Var *source, int index);
|
||||
bool Array_Equal(Array *arr1, Array *arr2);
|
||||
throws(ArrayIndexOutOfBound);
|
||||
bool Array_Equals(Array *arr1, Array *arr2);
|
||||
|
||||
/* Extensional. */
|
||||
Status ArrayUtils_Insert(Array *inst, Var *item, int index);
|
||||
throws(ArrayIndexOutOfBound);
|
||||
Status ArrayUtils_InsertArray(Array *inst, Array *items, int index);
|
||||
throws(ArrayIndexOutOfBound);
|
||||
Status ArrayUtils_Remove(Array *inst, int index);
|
||||
throws(ArrayIndexOutOfBound);
|
||||
Status ArrayUtils_RemoveArray(Array *inst, int off, int len);
|
||||
throws(ArrayIndexOutOfBound InvalidArrayLength);
|
||||
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);
|
||||
throws(ArrayIndexOutOfBound InvalidArrayLength);
|
||||
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);
|
||||
throws(ArrayIndexOutOfBound);
|
||||
Status ArrayUtils_Revert(Array *inst);
|
||||
bool ArrayUtils_IsEmpty(Array *inst);
|
||||
bool ArrayUtils_IsBlank(Array *inst);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include <Compound/array.h>
|
||||
#include <Compound/status.h>
|
||||
|
||||
Status Array_Create(Array *inst, int len)
|
||||
Status Array_Create(Array *inst, int len, size_t size)
|
||||
{
|
||||
/* Skip unavailable inst and invalid param. */
|
||||
fails(inst, UnavailableInstance);
|
||||
@@ -10,29 +10,75 @@ Status Array_Create(Array *inst, int len)
|
||||
|
||||
inst->len = len;
|
||||
inst->members = calloc(len, sizeof(Var));
|
||||
int erridx = -1;
|
||||
for (register int i = 0; i < len; i++) {
|
||||
// TODO(william): Throw InsufficientMemory at following line.
|
||||
solve(!StatusUtils_IsOkay(Var_Create(&inst->members[i], size)), {
|
||||
#ifdef __DEBUG__
|
||||
cat("Var_Create failed!\n")
|
||||
#endif
|
||||
erridx = i;
|
||||
break;
|
||||
} else {
|
||||
#ifdef __DEBUG__
|
||||
cat("Var_Create success!\n")
|
||||
#endif
|
||||
})
|
||||
}
|
||||
|
||||
/* Review on erridx. Release data that allocated. */
|
||||
if (erridx != -1) {
|
||||
for (register int i = erridx; i >= 0; i--) {
|
||||
Var_Delete(&inst->members[i]);
|
||||
#ifdef __DEBUG__
|
||||
cat("Deleted var from InsufficientMemory from Array_Create!")
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Release array itself. */
|
||||
free(inst->members);
|
||||
|
||||
return InsufficientMemory;
|
||||
}
|
||||
|
||||
return NormalStatus;
|
||||
}
|
||||
|
||||
Status Array_CopyOf(Array *inst, Array *other)
|
||||
{
|
||||
/* Skip unavailable inst and invalid param. */
|
||||
fails(inst, UnavailableInstance);
|
||||
fails(other, error(InvalidParameter, "Given other was unavailable."));
|
||||
// /* Skip unavailable inst and invalid param. */
|
||||
// fails(inst, UnavailableInstance);
|
||||
// fails(other, error(InvalidParameter, "Given other was unavailable."));
|
||||
|
||||
/* Assign value for len. */
|
||||
inst->len = other->len;
|
||||
// /* Assign value for len. */
|
||||
// inst->len = other->len;
|
||||
|
||||
/* Recreate array. */
|
||||
if (inst->members == NULL) return NormalStatus;
|
||||
match(RuntimeError, Array_Delete(inst), "Failed on deleting array.");
|
||||
match(RuntimeError, Array_Create(inst, other->len), "Failed on recreating "
|
||||
"array.");
|
||||
// if (inst->members == NULL) return NormalStatus;
|
||||
// match(RuntimeError, Array_Create(inst, other->len), "Failed on recreating "
|
||||
// "array.");
|
||||
|
||||
/* Copy and assign for each member from other to inst. */
|
||||
for (register int i = 0; i < inst->len; i++) {
|
||||
inst[i] = other[i];
|
||||
}
|
||||
// /* Copy and assign for each member from other to inst. */
|
||||
// for (register int i = 0; i < inst->len; i++) {
|
||||
// inst[i] = other[i];
|
||||
// }
|
||||
|
||||
return NormalStatus;
|
||||
// return NormalStatus;
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
if (other == NULL) return 1;
|
||||
|
||||
String_Create(inst, other->len);
|
||||
for (register int i = 0; i < other->len; i++) {
|
||||
inst->arr[i] = other->arr[i];
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
Status Array_Delete(Array *inst)
|
||||
@@ -74,14 +120,14 @@ Status Array_SetIdx(Array *inst, Var *source, int index)
|
||||
return NormalStatus;
|
||||
}
|
||||
|
||||
bool Array_Equal(Array *a, Array *b)
|
||||
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_Equal(&a->members[i], &b->members[i])) {
|
||||
if (!Var_Equals(&a->members[i], &b->members[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ cmake_minimum_required (VERSION 3.5)
|
||||
project (Compound)
|
||||
|
||||
add_compile_options(-g -std=c99 -Wall -Wextra -Wformat)
|
||||
LINK_LIBRARIES(m)
|
||||
|
||||
# add_executable(CompoundTest test.c
|
||||
# Var/src/var.c
|
||||
@@ -13,7 +14,10 @@ add_compile_options(-g -std=c99 -Wall -Wextra -Wformat)
|
||||
# catlog.c
|
||||
# name.c)
|
||||
|
||||
add_executable(CompoundTest test.c
|
||||
add_executable(CompoundTest
|
||||
test.c
|
||||
Var/src/var.c
|
||||
Array/src/array.c
|
||||
Status/src/status.c)
|
||||
Status/src/status.c
|
||||
Utils/src/utils.c
|
||||
catlog.c)
|
||||
|
@@ -32,7 +32,7 @@ Status MemMan_Memory_Reallocate(Memory *inst, size_t length);
|
||||
void MemMan_Memory_Release(Memory *inst);
|
||||
Status MemMan_Memory_Prioritise(Memory *inst);
|
||||
Status MemMan_Memory_Deprioritise(Memory *inst);
|
||||
bool MemMan_Memory_Equal(Memory *inst, Memory *other);
|
||||
bool MemMan_Memory_Equals(Memory *inst, Memory *other);
|
||||
|
||||
Status MemMan_MemoryPool_Create(MemoryPool *inst, size_t volume);
|
||||
Status MemMan_MemoryPool_Constr(MemoryPool *inst, size_t volume, int priority);
|
||||
|
@@ -2,13 +2,13 @@
|
||||
# define COMPOUND_OBJECT_H
|
||||
|
||||
# include <Compound/array.h>
|
||||
# include <Compound/namespace.h>
|
||||
# include <Compound/name.h>
|
||||
# include <Compound/type.h>
|
||||
|
||||
typedef struct { // interface
|
||||
Var *data;
|
||||
Array buffer;
|
||||
int (*Literalise)(void);
|
||||
Var *(*Literalise)(void);
|
||||
int (*Correspond)(Var *other);
|
||||
} Object;
|
||||
|
||||
@@ -71,7 +71,9 @@ typedef struct {
|
||||
} Destructor;
|
||||
|
||||
typedef struct {
|
||||
OBJECT_IMPLEMENTATION
|
||||
// OBJECT_IMPLEMENTATION
|
||||
|
||||
Object this;
|
||||
|
||||
char *identity;
|
||||
|
||||
|
@@ -42,7 +42,7 @@ DECLARATION:
|
||||
|
||||
*PLEASE NOTE, AN EMPTY DESCRIPTION ALONG WITH A NULL DESCRIPTION IS
|
||||
REGARDED AS "MEANINGLESS ONE" WHICH DOES NOT DOING ANYTHING EFFECTIVE FOR
|
||||
ANYONE. DESCRIPTIONS CAN BE VALIDATED WITH FUNCTION `status_isvalid`.
|
||||
ANYONE. DESCRIPTIONS CAN BE VALIDATED WITH FUNCTION `StatusUtils_IsValid`.
|
||||
|
||||
iii. characteristic: int
|
||||
|
||||
@@ -60,10 +60,11 @@ DECLARATION:
|
||||
IN SOME CASES, THIS MEMBER COULD POINT AT IT SELF, MEANING IT COULD MAKE
|
||||
A RECURSIVE SITUATION WHERE IT REQUIRE EXTRA EXAMINATIONS BEFORE GOING TO
|
||||
THE ADDRESS IT POINTS AT. THESE PROBLEMS CAN BE AVOIDED WITH FUNCTION
|
||||
`status_recursive` CALLED AHEAD.
|
||||
`StatusUtils_IsRecursive` CALLED AHEAD.
|
||||
|
||||
*GO SEE status_dump FOR DETAILS ABOUT DUMPING CALLING STACKS.
|
||||
*GO SEE status_recursive FOR DETERRING RECURSIVE "PREV".
|
||||
*GO SEE StatusUtils_Dump
|
||||
StatusUtils_Dump FOR DETAILS ABOUT DUMPING CALLING STACKS.
|
||||
*GO SEE StatusUtils_IsRecursive FOR DETERRING RECURSIVE "PREV".
|
||||
|
||||
SYNONYM:
|
||||
Status funcname1(void *param);
|
||||
|
@@ -8,6 +8,7 @@
|
||||
# include <threads.h>
|
||||
# include <time.h>
|
||||
# include <stdio.h>
|
||||
# include <math.h>
|
||||
|
||||
# include <Compound/common.h>
|
||||
# include <Compound/utils.h>
|
||||
@@ -20,7 +21,6 @@ typedef enum {
|
||||
STATUS_ERROR = 1
|
||||
} StatusCharacteristics;
|
||||
|
||||
|
||||
typedef enum {
|
||||
/* Settlement. */
|
||||
ARGUE_RESULT_FINALISED = 0b01,
|
||||
@@ -100,17 +100,17 @@ typedef enum {
|
||||
/* "Report" recollects essential informations, included but not limited to
|
||||
Status and others for making an report for debugging and such. */
|
||||
typedef struct {
|
||||
Status stat;
|
||||
char *originator;
|
||||
Status status;
|
||||
char *initiator;
|
||||
time_t time;
|
||||
ReportSendingPriority priority;
|
||||
ReportSendingTaskStatus status;
|
||||
ReportSendingTaskStatus task_status;
|
||||
FILE *dest; // The destination where the report is sending to.
|
||||
} Report;
|
||||
|
||||
/*
|
||||
|
||||
TIME [PRIORITY] STATUSNAME (ORIGINATOR): STATUS.DESCRIPTION
|
||||
DATETIME [PRIORITY] STATUSNAME (ORIGINATOR): STATUS.DESCRIPTION
|
||||
at LOCATION.FILE:LOCATION.LINE, LOCATION.FUNC
|
||||
at LOCATION.FILE:LOCATION.LINE, LOCATION.FUNC
|
||||
at LOCATION.FILE:LOCATION.LINE, LOCATION.FUNC
|
||||
@@ -126,23 +126,23 @@ Fri 10 May 03:02:37 CST 2024 [EXCEPTIONAL] InvalidParameter (Nullity): Given buf
|
||||
|
||||
*/
|
||||
|
||||
# define REPORT_LITERALISE_HEADER_FORMAT "%ld [%s] %s (%s): %s"
|
||||
# define REPORT_LITERALISE_HEADER_FORMAT "%s [%s] %s (%s): %s"
|
||||
# define REPORT_LITERALISE_CHAINS_FORMAT " at %s:%d, %s"
|
||||
# define REPORT_LITERALISE_CHAINS_EXCLAIM_FORMAT "!!!!at %s:%d, %s"
|
||||
|
||||
# define REPORT_LITERALISE_HEADER_FORMAT_LENGTH(buff, PRIORITY, STATUSNAME, \
|
||||
ORIGINATOR, DESCRIPTION) \
|
||||
{ \
|
||||
const time_t now = time(NULL); \
|
||||
(void)strflen(buff, 28, DATETIME_FORMAT, localtime(&now)); \
|
||||
*length = strlen(buff); \
|
||||
}
|
||||
// # define REPORT_LITERALISE_HEADER_FORMAT_LENGTH(buff, PRIORITY, STATUSNAME, \
|
||||
// ORIGINATOR, DESCRIPTION) \
|
||||
// { \
|
||||
// const time_t now = time(NULL); \
|
||||
// (void)strflen(buff, 28, DATETIME_FORMAT, localtime(&now)); \
|
||||
// *length = strlen(buff); \
|
||||
// }
|
||||
|
||||
# define REPORT_LITERALISE_CHAINS_FORMAT_LENGTH(FILEPATH, LINE, FUNCNAME) \
|
||||
(strlen(FILEPATH) + utils_calc_digits(LINE) + \
|
||||
strlen(FUNCNAME) + 10) // Does not count '\0'
|
||||
# define REPORT_LITERALISE_CHAINS_EXCLAIM_FORMAT_LENGTH \
|
||||
REPORT_LITERALISE_CHAINS_FORMAT_LENGTH
|
||||
// # define REPORT_LITERALISE_CHAINS_FORMAT_LENGTH(FILEPATH, LINE, FUNCNAME) \
|
||||
// (strlen(FILEPATH) + utils_calc_digits(LINE) + \
|
||||
// strlen(FUNCNAME) + 10) // Does not count '\0'
|
||||
// # define REPORT_LITERALISE_CHAINS_EXCLAIM_FORMAT_LENGTH \
|
||||
// REPORT_LITERALISE_CHAINS_FORMAT_LENGTH
|
||||
|
||||
typedef enum {
|
||||
REPORT_SENDER_RESULT_FINISHED,
|
||||
@@ -200,21 +200,21 @@ typedef struct {
|
||||
|
||||
# define STATUS_BUFFER_MAXIMUM_LENGTH UINT32_MAX
|
||||
|
||||
bool Location_Equal(Location lc1, Location lc2);
|
||||
bool Status_Equal(Status stat1, Status stat2);
|
||||
bool Location_Equals(Location lc1, Location lc2);
|
||||
Status Status_Literalise(Status *inst, char *buff);
|
||||
void StatusUtils_Dump(Status *stat, Status *statbuff, int idx);
|
||||
bool StatusUtils_HasPrev(Status *stat);
|
||||
bool StatusUtils_IsOkay(Status stat);
|
||||
bool StatusUtils_IsValid(Status stat);
|
||||
bool StatusUtils_IsRecursive(Status stat);
|
||||
int StatusUtils_Depth(Status *stat);
|
||||
bool Status_Equals(Status stat1, Status stat2);
|
||||
void StatusUtils_Dump(Status *inst, Status *store, int idx);
|
||||
bool StatusUtils_HasPrev(Status *inst);
|
||||
bool StatusUtils_IsOkay(Status inst);
|
||||
bool StatusUtils_IsValid(Status inst);
|
||||
bool StatusUtils_IsRecursive(Status inst);
|
||||
int StatusUtils_Depth(Status *inst);
|
||||
|
||||
Status
|
||||
Report_Create(Report *inst, Status *stat, FILE *dest, char *originator,
|
||||
Report_Create(Report *inst, Status *stat, FILE *dest, char *initiator,
|
||||
int priority);
|
||||
bool
|
||||
Report_Equal(Report repo1, Report repo2);
|
||||
Report_Equals(Report repo1, Report repo2);
|
||||
Status
|
||||
Report_Literalise(Report *inst, char *buff);
|
||||
|
||||
@@ -223,8 +223,8 @@ Status
|
||||
ReportSender_Create(ReportSender *inst, Report *report);
|
||||
Status
|
||||
ReportSender_Send(ReportSender *inst, ReportSendingTask task);
|
||||
ReportSendingTaskStatus
|
||||
ReportSender_GetStatus(ReportSender *inst);
|
||||
// ReportSendingTaskStatus
|
||||
// ReportSender_GetStatus(ReportSender *inst);
|
||||
|
||||
ReportSendingTaskID
|
||||
ReportSenderManager_AppendTask(ReportSendingManager *inst,
|
||||
@@ -286,10 +286,22 @@ static Status NullPointerAccounted = {
|
||||
.prev = &MemoryViolation
|
||||
};
|
||||
|
||||
static Status InvalidObject = {
|
||||
.description = "An invalid object was presented.",
|
||||
.characteristic = STATUS_ERROR,
|
||||
.prev = &ErrorStatus
|
||||
};
|
||||
|
||||
static Status UnavailableObject = {
|
||||
.description = "An unavailable object was presented.",
|
||||
.characteristic = STATUS_ERROR,
|
||||
.prev = &ErrorStatus
|
||||
};
|
||||
|
||||
static Status InvalidParameter = {
|
||||
.description = "An invalid parameter was presented.",
|
||||
.characteristic = STATUS_ERROR,
|
||||
.prev = &ErrorStatus
|
||||
.prev = &InvalidObject
|
||||
};
|
||||
|
||||
static Status InsufficientMemory = {
|
||||
@@ -328,7 +340,7 @@ static Status ImprecisionError = {
|
||||
.prev = &RuntimeError
|
||||
};
|
||||
|
||||
// ---------------USER DEFINED | RUNTIME-------------------
|
||||
// ---------------------USER DEFINED-----------------------
|
||||
|
||||
static Status UnavailableInstance = {
|
||||
.description = "An unavailable instance was given for initialisation.",
|
||||
@@ -372,6 +384,12 @@ static Status InvalidFileName = {
|
||||
.prev = &ReadWriteError
|
||||
};
|
||||
|
||||
static Status UnavailableFileName = {
|
||||
.description = "Given file name was unavailable",
|
||||
.characteristic = STATUS_ERROR,
|
||||
.prev = &UnavailableObject
|
||||
};
|
||||
|
||||
static Status ReportThrown = {
|
||||
.description = "This function has thrown a report, "
|
||||
"following instructions aborted.",
|
||||
@@ -379,12 +397,36 @@ static Status ReportThrown = {
|
||||
.prev = &RuntimeError
|
||||
};
|
||||
|
||||
static Status ReportMessageLengthTooLong = {
|
||||
static Status ReportMessageTooLong = {
|
||||
.description = "Given message is too long.",
|
||||
.characteristic = STATUS_ERROR,
|
||||
.prev = &ArrayLengthError
|
||||
};
|
||||
|
||||
static Status MaximumLengthExceeded = {
|
||||
.description = "Buffer was too long.",
|
||||
.characteristic = STATUS_ERROR,
|
||||
.prev = &ArrayLengthError
|
||||
};
|
||||
|
||||
static Status MaximumLiteralisationLengthExceeded = {
|
||||
.description = "Literalisation was too long.",
|
||||
.characteristic = STATUS_ERROR,
|
||||
.prev = &MaximumLengthExceeded
|
||||
};
|
||||
|
||||
static Status UnavailableBuffer = {
|
||||
.description = "Given buffer was unavailable.",
|
||||
.characteristic = STATUS_ERROR,
|
||||
.prev = &UnavailableInstance
|
||||
};
|
||||
|
||||
static Status InvalidLiteralisingBuffer = {
|
||||
.description = "Given buffer does not have a good integrity on its length.",
|
||||
.characteristic = STATUS_ERROR,
|
||||
.prev = &InvalidObject
|
||||
};
|
||||
|
||||
// ========================================================
|
||||
|
||||
/* Throw the report created with $e if $e is abnormal, commented with $c. */
|
||||
@@ -417,25 +459,6 @@ static Status ReportMessageLengthTooLong = {
|
||||
|
||||
ReportSendingTaskID __throw(Report report, Location loc);
|
||||
Report catch(ReportSendingTaskID taskid);
|
||||
static int HANDLER(void *report)
|
||||
{
|
||||
/* Throw UnableToThrowError when param is unavailable. */
|
||||
if (report == NULL) {
|
||||
/* Create report on this. */
|
||||
Report e;
|
||||
Report_Create(
|
||||
&e,
|
||||
&error(UnableToThrowError, "Cannot perform throwing. Aborted."),
|
||||
stderr, nameof(DEFAULT_ARGUE_STARTER),
|
||||
REPORT_SENDING_PRIORITY_FATAL);
|
||||
|
||||
/* Perform throwing. */
|
||||
(void)throw(e); // Throw the report alone.
|
||||
return 1;
|
||||
}
|
||||
|
||||
(void)throw(*(Report *)report); // Lonely _throw, no catch will company.
|
||||
return 0;
|
||||
}
|
||||
int HANDLER(void *report);
|
||||
|
||||
#endif /* COMPOUND_STATUS_H */
|
||||
|
@@ -1,42 +1,15 @@
|
||||
#include <Compound/common.h>
|
||||
#include <Compound/status.h>
|
||||
#include <Compound/var.h>
|
||||
#include <Compound/utils.h>
|
||||
|
||||
bool status_issuelocation_equal(Location lc1, Location lc2) {
|
||||
bool Location_Equal(Location lc1, Location lc2)
|
||||
{
|
||||
return ((!strcmp(lc1.file, lc2.file)) && (lc1.line == lc2.line) &&
|
||||
(!strcmp(lc1.func, lc2.func)));
|
||||
}
|
||||
|
||||
bool status_hasprev(Status stat) {
|
||||
/* Skip when stat is unavailable for accessing. */
|
||||
state(Status_Equal(stat, (Status){}), false);
|
||||
|
||||
return (stat.prev != NULL);
|
||||
}
|
||||
|
||||
bool status_isokay(Status stat) { return (!stat.characteristic); }
|
||||
|
||||
bool status_isvalid(Status stat) {
|
||||
return (!strcmp(stat.description, "") && stat.characteristic >= 0 &&
|
||||
stat.prev != NULL);
|
||||
}
|
||||
|
||||
bool status_recursive(Status stat) {
|
||||
return (stat.prev != NULL && stat.prev == &stat);
|
||||
}
|
||||
|
||||
void status_dump(Status *inst, Status *statbuff, int idx) {
|
||||
|
||||
/* Skip when either stat or stat.prev is unavailable, or, idx is invalid. */
|
||||
solve((statbuff == NULL || !status_hasprev(*inst) || idx < 0), return;);
|
||||
|
||||
statbuff[idx] = *inst;
|
||||
(void)printf("status_dump: Index %d has assigned with %p\n", idx, &inst);
|
||||
|
||||
status_dump(inst->prev, statbuff, ++idx);
|
||||
}
|
||||
|
||||
bool Status_Equal(Status stat1, Status stat2) {
|
||||
bool Status_Equals(Status stat1, Status stat2)
|
||||
{
|
||||
|
||||
/* Skip when both stat1 and stat2 are empty. */
|
||||
state((stat1.value == 0 && stat2.value == 0 && stat1.description == 0x0 &&
|
||||
@@ -48,22 +21,88 @@ bool Status_Equal(Status stat1, Status stat2) {
|
||||
return ((stat1.value == stat2.value) &&
|
||||
(!strcmp(stat1.description, stat2.description)) &&
|
||||
(stat1.characteristic == stat2.characteristic) &&
|
||||
(Status_Equal(*stat1.prev, *stat2.prev)));
|
||||
(Status_Equals(*stat1.prev, *stat2.prev)));
|
||||
}
|
||||
|
||||
Status Status_Literalise(Status *inst, char *buff)
|
||||
{
|
||||
/* Skip unavailable or invalid parameters. */
|
||||
fails(inst, UnavailableInstance);
|
||||
fails(buff, UnavailableBuffer);
|
||||
// state(strlen(buff) != LITERALISATION_LENGTH_MAXIMUM,
|
||||
// InvalidLiteralisingBuffer);
|
||||
|
||||
/* Set up idx for counting final literalisation length to ensure the
|
||||
string copying is index access safe. */
|
||||
int idx = 0;
|
||||
const int status_dump_buffer_len = StatusUtils_Depth(inst);
|
||||
|
||||
Status status_dump_buffer[status_dump_buffer_len];
|
||||
|
||||
/* Literalise every status that flattened on status_dump_buffer. */
|
||||
for (register int i = 0; i < status_dump_buffer_len; i++) {
|
||||
char status_literalising_buffer[LITERALISATION_LENGTH_MAXIMUM];
|
||||
(void)Status_Literalise(&status_dump_buffer[i], status_literalising_buffer);
|
||||
|
||||
/* Append to buff. */
|
||||
/* Prevent buffer-out-of-bound access. */
|
||||
const int status_literalising_buffer_len = strlen(status_literalising_buffer);
|
||||
if (idx + status_literalising_buffer_len >= LITERALISATION_LENGTH_MAXIMUM) {
|
||||
buff = NULL;
|
||||
return MaximumLiteralisationLengthExceeded;
|
||||
}
|
||||
|
||||
idx += status_literalising_buffer_len;
|
||||
(void)strcat(buff, status_literalising_buffer);
|
||||
}
|
||||
|
||||
return NormalStatus;
|
||||
}
|
||||
|
||||
int StatusUtils_Depth(Status *stat) {
|
||||
bool StatusUtils_HasPrev(Status *stat)
|
||||
{
|
||||
/* Skip when stat is unavailable for accessing. */
|
||||
state(Status_Equals(*stat, (Status){}), false);
|
||||
|
||||
return (stat->prev != NULL);
|
||||
}
|
||||
|
||||
bool StatusUtils_IsOkay(Status stat)
|
||||
{
|
||||
return (!stat.characteristic);
|
||||
}
|
||||
|
||||
bool StatusUtils_IsValid(Status stat)
|
||||
{
|
||||
return (!strcmp(stat.description, "") && stat.characteristic >= 0 &&
|
||||
stat.prev != NULL);
|
||||
}
|
||||
|
||||
bool StatusUtils_IsRecursive(Status stat)
|
||||
{
|
||||
return (stat.prev != NULL && stat.prev == &stat);
|
||||
}
|
||||
|
||||
void StatusUtils_Dump(Status *inst, Status *store, int idx)
|
||||
{
|
||||
|
||||
/* Skip when either stat or stat.prev is unavailable, or, idx is invalid. */
|
||||
solve((store == NULL || !StatusUtils_HasPrev(inst) || idx < 0), return;);
|
||||
|
||||
store[idx] = *inst;
|
||||
|
||||
StatusUtils_Dump(inst->prev, store, ++idx);
|
||||
}
|
||||
|
||||
int StatusUtils_Depth(Status *stat)
|
||||
{
|
||||
/* Skip unavailable stat. */
|
||||
state((stat == NULL), -1);
|
||||
|
||||
Status *p = stat; // Include this layer of Status.
|
||||
int cnt = 1;
|
||||
while (p != NULL) {
|
||||
if (status_recursive(*p) || !status_hasprev(*stat)) break;
|
||||
if (StatusUtils_IsRecursive(*p) || !StatusUtils_HasPrev(stat)) break;
|
||||
|
||||
p = p->prev;
|
||||
cnt += 1;
|
||||
@@ -72,20 +111,21 @@ int StatusUtils_Depth(Status *stat) {
|
||||
return cnt;
|
||||
}
|
||||
|
||||
Status report_create(Report *inst, Status *stat, FILE *dest, char *originator,
|
||||
int priority) {
|
||||
Status Report_Create(Report *inst, Status *stat, FILE *dest, char *initiator,
|
||||
int priority)
|
||||
{
|
||||
/* Skip unavailable parameters. */
|
||||
fails(inst, UnavailableInstance);
|
||||
fails(stat, error(InvalidParameter, "Given originator was null."));
|
||||
fails(originator, error(InvalidParameter, "Given originator was null."));
|
||||
fails(stat, error(InvalidParameter, "Given initiator was null."));
|
||||
fails(initiator, error(InvalidParameter, "Given initiator was null."));
|
||||
state(priority < 0, error(InvalidParameter, "Given priority was negative."));
|
||||
|
||||
/* Copy and assign. */
|
||||
inst->stat = *stat;
|
||||
inst->originator = originator;
|
||||
inst->status = *stat;
|
||||
inst->initiator = initiator;
|
||||
inst->time = time(NULL);
|
||||
inst->priority = priority;
|
||||
inst->status = REPORT_SENDING_TASK_STATUS_PENDING;
|
||||
inst->task_status = REPORT_SENDING_TASK_STATUS_PENDING;
|
||||
inst->dest = (dest == NULL ? stderr : dest);
|
||||
|
||||
return NormalStatus;
|
||||
@@ -93,39 +133,64 @@ Status report_create(Report *inst, Status *stat, FILE *dest, char *originator,
|
||||
|
||||
Status Report_Literalise(Report *inst, char *buff)
|
||||
{
|
||||
/* Skip when inst or buff is unavailable. */
|
||||
fails(inst, UnavailableInstance);
|
||||
fails(buff, error(InvalidParameter, "Given buffer was unavailable."));
|
||||
fails(buff, UnavailableBuffer);
|
||||
// state(strlen(buff) != LITERALISATION_LENGTH_MAXIMUM,
|
||||
// InvalidLiteralisingBuffer);
|
||||
|
||||
/* By calculating the depth of status, we can calculate the exact length of
|
||||
literalisation of report. */
|
||||
const int depth = StatusUtils_Depth(&inst->stat);
|
||||
/* Report literalisation. */
|
||||
int idx = 0;
|
||||
char report_literalising[LITERALISATION_LENGTH_MAXIMUM];
|
||||
|
||||
/* Dump all the status. */
|
||||
Status stats[depth];
|
||||
StatusUtils_Dump(&inst->stat, stats, 0);
|
||||
/** Status literalisation. **/
|
||||
char status_literalising[LITERALISATION_LENGTH_MAXIMUM];
|
||||
(void)Status_Literalise(&inst->status, status_literalising);
|
||||
idx += strlen(status_literalising);
|
||||
/** fin **/
|
||||
|
||||
/* Literalise by iterating. */
|
||||
int report_literalised_length = 0;
|
||||
for (register int i = 0; i < depth; i++) {
|
||||
/* Literalise individual status. */
|
||||
char buff[strlen(stats[i].description) + 1 + ];
|
||||
(void)Status_Literalise(&stats[i], buff); // Ignore the returning.
|
||||
// Otherwise, if we throw the report once the returning status is abnormal,
|
||||
// this function would be called again by the throw function.
|
||||
/** Initiator literalisation. **/
|
||||
idx += strlen(inst->initiator);
|
||||
/** fin **/
|
||||
|
||||
/* Accumulate length of report literalisation. */
|
||||
report_literalised_length += strlen(buff);
|
||||
/** Time literalisation. **/
|
||||
char time_literalising[LITERALISATION_LENGTH_MAXIMUM];
|
||||
idx += Utils_LiteraliseInteger(inst->time, time_literalising);
|
||||
/** fin **/
|
||||
|
||||
/** Priority literalisation. **/
|
||||
char priority_literalising[LITERALISATION_LENGTH_MAXIMUM];
|
||||
idx += Utils_LiteraliseInteger(inst->priority, priority_literalising);
|
||||
/** fin **/
|
||||
|
||||
/** Task_status literalisation. **/
|
||||
char task_status_literalising[LITERALISATION_LENGTH_MAXIMUM];
|
||||
idx += Utils_LiteraliseInteger(inst->task_status, task_status_literalising);
|
||||
/** fin **/
|
||||
|
||||
/** Dest literalisation. **/
|
||||
char dest_literalising[LITERALISATION_LENGTH_MAXIMUM];
|
||||
idx += Utils_LiteraliseInteger((long long int)inst->dest, dest_literalising);
|
||||
/** fin **/
|
||||
|
||||
if (idx >= LITERALISATION_LENGTH_MAXIMUM) {
|
||||
buff = NULL;
|
||||
return MaximumLiteralisationLengthExceeded;
|
||||
}
|
||||
|
||||
/* Create report literalisation buffer according to
|
||||
report_literalised_length. */
|
||||
char report_literalised_buffer[report_literalised_length];
|
||||
strcpy(report_literalising, status_literalising);
|
||||
strcpy(report_literalising, time_literalising);
|
||||
strcpy(report_literalising, priority_literalising);
|
||||
strcpy(report_literalising, task_status_literalising);
|
||||
strcpy(report_literalising, dest_literalising);
|
||||
|
||||
/* */
|
||||
strcpy(buff, report_literalising);
|
||||
/* fin */
|
||||
|
||||
return NormalStatus;
|
||||
}
|
||||
|
||||
Status ReportSender_Create(ReportSender *inst, Report *report) {
|
||||
Status ReportSender_Create(ReportSender *inst, Report *report)
|
||||
{
|
||||
fails(inst, UnavailableInstance);
|
||||
fails(report, error(UnavailableParameter, "Given report was unavailable."));
|
||||
|
||||
@@ -138,23 +203,25 @@ Status ReportSender_Create(ReportSender *inst, Report *report) {
|
||||
return NormalStatus;
|
||||
}
|
||||
|
||||
Status ReportSender_Send(ReportSender *inst, ReportSendingTask task) {
|
||||
/* Skip when inst or task is unavailable. */
|
||||
fails(inst,
|
||||
error(UnavailableInstance, "Report sender was given unavailable."));
|
||||
fails(task, InvalidReportTask);
|
||||
Status ReportSender_Send(ReportSender *inst, ReportSendingTask task)
|
||||
{
|
||||
// /* Skip when inst or task is unavailable. */
|
||||
// fails(inst,
|
||||
// error(UnavailableInstance, "Report sender was given unavailable."));
|
||||
// fails(task, InvalidReportTask);
|
||||
|
||||
/* Assign for dest. */
|
||||
const FILE *dest = (inst->report->dest == NULL ? stdout : inst->report->dest);
|
||||
// char buff[];
|
||||
// TODO(william): HERE, Report_Literalise
|
||||
// /* Assign for dest. */
|
||||
// const FILE *dest = (inst->report->dest == NULL ? stdout : inst->report->dest);
|
||||
// // char buff[];
|
||||
// // TODO(william): HERE, Report_Literalise
|
||||
|
||||
/* Write/Send data. */
|
||||
inst->report->status = REPORT_SENDING_TASK_STATUS_PROCEEDING;
|
||||
if (!fprintf(dest, buff)) {
|
||||
}
|
||||
// /* Write/Send data. */
|
||||
// inst->report->task_status = REPORT_SENDING_TASK_STATUS_PROCEEDING;
|
||||
// if (!fprintf(dest, buff)) {
|
||||
// }
|
||||
|
||||
/* Sent successfully! Mark down properties. */
|
||||
// /* Sent successfully! Mark down properties. */
|
||||
return NormalStatus;
|
||||
}
|
||||
|
||||
// bool arguestarter_equal(ArgueStarter *inst1, ArgueStarter *inst2)
|
||||
@@ -166,40 +233,65 @@ Status ReportSender_Send(ReportSender *inst, ReportSendingTask task) {
|
||||
// || (inst1->external_param == inst2->external_param);
|
||||
// }
|
||||
|
||||
ReportSendingTaskID _throw(Report report, Location loc) {
|
||||
// /* Create new a instance of ReportSender. */
|
||||
ReportSendingTaskID _throw(Report report, Location loc)
|
||||
{
|
||||
// // /* Create new a instance of ReportSender. */
|
||||
// // ReportSender sender;
|
||||
// // ReportSender_Create(&sender, stderr);
|
||||
|
||||
// // /* Send message. */
|
||||
// // /* Initialise sender's thread. */
|
||||
// // thrd_t sending;
|
||||
// // /* Skip on failing on creating thread. */
|
||||
// // if (!thrd_create(&sending, starter, NULL)) {
|
||||
|
||||
// // /* Conclude the session of sender. */
|
||||
// // report.status = REPORT_SENDING_TASK_STATUS_FINISHED,
|
||||
// // report.result = (ARGUE_RESULT_FINALISED | ARGUE_RESULT_NEGATIVE);
|
||||
|
||||
// // sender.result = REPORT_SENDER_RESULT_FINISHED;
|
||||
// // sender.successful = false;
|
||||
|
||||
// // return -1;
|
||||
// // }
|
||||
|
||||
// // /* Perform sending. */
|
||||
// // ReportSender_Send(&sender, NULL);
|
||||
|
||||
// /* Initialise sender. */
|
||||
// ReportSender sender;
|
||||
// ReportSender_Create(&sender, stderr);
|
||||
// /* Return with -1 when initialisation failed. */
|
||||
// state(!(StatusUtils_IsOkay(ReportSender_Create(&sender, &report))), -1);
|
||||
|
||||
// /* Send message. */
|
||||
// /* Initialise sender's thread. */
|
||||
// thrd_t sending;
|
||||
// /* Skip on failing on creating thread. */
|
||||
// if (!thrd_create(&sending, starter, NULL)) {
|
||||
// /* Inject location information. Could be more elegant, though. */
|
||||
// sender.report->status.loc = loc;
|
||||
|
||||
// /* Conclude the session of sender. */
|
||||
// report.status = REPORT_SENDING_TASK_STATUS_FINISHED,
|
||||
// report.result = (ARGUE_RESULT_FINALISED | ARGUE_RESULT_NEGATIVE);
|
||||
// /* Send. */ /* Return -1 when failed on sending. */
|
||||
// state(!StatusUtils_IsOkay(ReportSender_Send(&sender, HANDLER)), -1);
|
||||
|
||||
// sender.result = REPORT_SENDER_RESULT_FINISHED;
|
||||
// sender.successful = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// return -1;
|
||||
int HANDLER(void *report)
|
||||
{
|
||||
// /* Throw UnableToThrowError when param is unavailable. */
|
||||
// if (report == NULL) {
|
||||
// /* Create report on this. */
|
||||
// Report e;
|
||||
// Report_Create(
|
||||
// &e,
|
||||
// &error(UnableToThrowError, "Cannot perform throwing. Aborted."),
|
||||
// stderr, nameof(DEFAULT_ARGUE_STARTER),
|
||||
// REPORT_SENDING_PRIORITY_FATAL);
|
||||
|
||||
// /* Perform throwing. */
|
||||
// (void)throw(e); // Throw the report alone.
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
// /* Perform sending. */
|
||||
// ReportSender_Send(&sender, NULL);
|
||||
|
||||
/* Initialise sender. */
|
||||
ReportSender sender;
|
||||
/* Return with -1 when initialisation failed. */
|
||||
state(!(status_isokay(ReportSender_Create(&sender, &report))), -1);
|
||||
|
||||
/* Inject location information. Could be more elegant, though. */
|
||||
sender.report->stat.loc = loc;
|
||||
|
||||
/* Send. */ /* Return -1 when failed on sending. */
|
||||
state(!status_isokay(ReportSender_Send(&sender, HANDLER)), -1);
|
||||
|
||||
// (void)throw(*(Report *)report); // Lonely throw, no catch will company.
|
||||
// return 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ Status String_Delete(String *inst);
|
||||
Status String_GetIdx(String *inst, Char *item, int index);
|
||||
Status String_SetIdx(String *inst, Char *item, int index);
|
||||
Status String_Literalise(String *inst, String *store);
|
||||
bool String_Equal(String *arr1, String *arr2);
|
||||
bool String_Equals(String *arr1, String *arr2);
|
||||
|
||||
/* Extensional. */
|
||||
Status StringUtils_FromInteger(String *inst, int value);
|
||||
|
@@ -38,7 +38,7 @@ Status String_Literalise(String *inst, String *store)
|
||||
fails(inst, UnavailableInstance);
|
||||
}
|
||||
|
||||
bool String_Equal(String *arr1, String *arr2)
|
||||
bool String_Equals(String *arr1, String *arr2)
|
||||
{
|
||||
fails(inst, UnavailableInstance);
|
||||
}
|
||||
|
@@ -4,13 +4,17 @@
|
||||
# include <time.h>
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
# include <math.h>
|
||||
|
||||
# include <Compound/common.h>
|
||||
# include <Compound/const.h>
|
||||
|
||||
# define DATETIME_FORMAT "%a %d %b %X %Z %Y"
|
||||
|
||||
int Utils_CalcDigits(long long n);
|
||||
int Utils_CalcDateTimeLiteralisationLength(char *buff);
|
||||
int Utils_CalcDigits(long long int n);
|
||||
|
||||
int Utils_LiteraliseInteger(long long int n, char *buff);
|
||||
|
||||
int Utils_DateTimeLiteralise(time_t t, char *buff);
|
||||
|
||||
#endif /* COMPOUND_UTILS_H */
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include <Compound/utils.h>
|
||||
|
||||
int Utils_CalcDigits(long long n)
|
||||
int Utils_CalcDigits(long long int n)
|
||||
{
|
||||
if (n == 0) {
|
||||
return 1;
|
||||
@@ -15,11 +15,34 @@ int Utils_CalcDigits(long long n)
|
||||
return i;
|
||||
}
|
||||
|
||||
int Utils_CalcDateTimeLiteralisationLength(char *buff)
|
||||
int Utils_LiteraliseInteger(long long int n, char *buff)
|
||||
{
|
||||
const time_t now = time(NULL);
|
||||
/* Invalid buffer was presented. */
|
||||
if (strlen(buff) != LITERALISATION_LENGTH_MAXIMUM) {
|
||||
buff = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void)strftime(buff, 28, DATETIME_FORMAT, localtime(&now));
|
||||
if (!n) {
|
||||
buff = "0";
|
||||
return 1;
|
||||
}
|
||||
|
||||
return strlen(buff);
|
||||
const int literalising_len = Utils_CalcDigits(n);
|
||||
if (literalising_len >= LITERALISATION_LENGTH_MAXIMUM) {
|
||||
buff = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
char literalising[literalising_len];
|
||||
for (register int i = 0; i < literalising_len; i++) {
|
||||
literalising[i] = (n / (int)pow(10, i));
|
||||
}
|
||||
|
||||
return literalising_len;
|
||||
}
|
||||
|
||||
int Utils_DateTimeLiteralise(time_t t, char *buff)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@@ -5,18 +5,21 @@
|
||||
|
||||
# include <Compound/common.h>
|
||||
# include <Compound/status.h>
|
||||
# include <Compound/catlog.h>
|
||||
|
||||
# define VAR_IDENTITY_LENGTH 64
|
||||
# define VAR_LITERALISE_LENGTH (VAR_IDENTITY_LENGTH + 16 + 9 + 10)
|
||||
# define VAR_LITERALISE_FORMAT ("%s @[%p]: %ld")
|
||||
# define VAR_IDENTITY_ILLEGAL_CHAR "!@#$%^*()-=+;\'\"\\|,./<>?[]{}`~ "
|
||||
// # define VAR_IDENTITY_LENGTH 64
|
||||
// # define VAR_LITERALISE_LENGTH (VAR_IDENTITY_LENGTH + 16 + 9 + 10)
|
||||
# define VAR_LITERALISE_LENGTH (16 + 9 + 10)
|
||||
// # define VAR_LITERALISE_FORMAT ("%s @[%p]: %ld")
|
||||
# define VAR_LITERALISE_FORMAT "@[%p]: %ld"
|
||||
// # define VAR_IDENTITY_ILLEGAL_CHAR "!@#$%^*()-=+;\'\"\\|,./<>?[]{}`~ "
|
||||
|
||||
static Status IllegalVarIdentity = {
|
||||
.description = "Given identity does not fit the standard of Var Naming "
|
||||
"convension.",
|
||||
.characteristic = STATUS_ERROR,
|
||||
.prev = &InvalidParameter
|
||||
};
|
||||
// static Status IllegalVarIdentity = {
|
||||
// .description = "Given identity does not fit the standard of Var Naming "
|
||||
// "convention.",
|
||||
// .characteristic = STATUS_ERROR,
|
||||
// .prev = &InvalidParameter
|
||||
// };
|
||||
|
||||
// static Status VarIdentityTooLong = {
|
||||
// .description = "Given identity has longer length that the maximum length "
|
||||
@@ -31,8 +34,8 @@ typedef struct {
|
||||
void *addr;
|
||||
size_t size;
|
||||
|
||||
/* Identification */
|
||||
char *identity; // Maximum up to VAR_IDENTITY_LENGTH
|
||||
// /* Identification */
|
||||
// char *identity; // Maximum up to VAR_IDENTITY_LENGTH
|
||||
|
||||
} Var;
|
||||
|
||||
@@ -43,13 +46,13 @@ typedef struct {
|
||||
// };
|
||||
// } _Var;
|
||||
|
||||
Status Var_Create(Var *inst, void *addr, size_t size, char *identity);
|
||||
Status Var_Create(Var *inst, size_t size) throws(InsufficientMemory);
|
||||
Status Var_CopyOf(Var *inst, Var *other);
|
||||
Status Var_Literalise(Var *inst, char *buff);
|
||||
bool Var_Equal(Var *a, Var *b);
|
||||
bool Var_Equals(Var *a, Var *b);
|
||||
void Var_Delete(Var *inst);
|
||||
|
||||
void VarUtils_Swap(Var *v1, Var *v2);
|
||||
bool VarUtils_IsIdentityLegal(char *identity);
|
||||
// bool VarUtils_IsIdentityLegal(char *identity);
|
||||
|
||||
#endif /* COMPOUND_VAR */
|
||||
|
111
Var/src/var.c
111
Var/src/var.c
@@ -1,45 +1,67 @@
|
||||
#include <Compound/var.h>
|
||||
|
||||
Status Var_Create(Var *inst, void *addr, size_t size, char *identity)
|
||||
Status Var_Create(Var *inst, size_t size)
|
||||
{
|
||||
/* Skip when inst is unavailable. */
|
||||
fails(inst, UnavailableInstance);
|
||||
/* Skip when identity is unavailable. */
|
||||
fails(identity, NullPointerAccounted);
|
||||
/* Skip when identity does not pass the examine. */
|
||||
state(!VarUtils_IsIdentityLegal(identity), IllegalVarIdentity);
|
||||
*inst = (Var) {
|
||||
.addr = malloc(size),
|
||||
.size = size
|
||||
};
|
||||
|
||||
inst->addr = addr;
|
||||
inst->size = size;
|
||||
*inst->identity = *identity;
|
||||
if (inst->addr == NULL) {
|
||||
return InsufficientMemory;
|
||||
}
|
||||
|
||||
return NormalStatus;
|
||||
}
|
||||
|
||||
// Status Var_Create(Var *inst, void *addr, size_t size, char *identity)
|
||||
// {
|
||||
// /* Skip when inst is unavailable. */
|
||||
// fails(inst, UnavailableInstance);
|
||||
// /* Skip when identity is unavailable. */
|
||||
// fails(identity, NullPointerAccounted);
|
||||
// /* Skip when identity does not pass the examine. */
|
||||
// state(!VarUtils_IsIdentityLegal(identity), IllegalVarIdentity);
|
||||
|
||||
// inst->addr = addr;
|
||||
// inst->size = size;
|
||||
// *inst->identity = *identity;
|
||||
|
||||
// return NormalStatus;
|
||||
// }
|
||||
|
||||
Status Var_CopyOf(Var *inst, Var *other)
|
||||
{
|
||||
/* Skip when inst or other is unavailable. */
|
||||
fails(inst, UnavailableInstance);
|
||||
fails(other, NullPointerAccounted);
|
||||
fails(other, InvalidParameter);
|
||||
|
||||
/* Copy and assign. */
|
||||
inst->addr = other->addr;
|
||||
/* Copy members from other. Only has to apply size, no addr is needed. */
|
||||
inst->addr = malloc(other->size);
|
||||
inst->size = other->size;
|
||||
*inst->identity = *other->identity;
|
||||
|
||||
return NormalStatus;
|
||||
}
|
||||
|
||||
void Var_Delete(Var *inst)
|
||||
{
|
||||
/* Skip when inst or inst->addr is unavailable. */
|
||||
svoid(inst == NULL || inst->addr == NULL);
|
||||
if (inst == NULL) return;
|
||||
|
||||
free(inst->addr);
|
||||
inst->addr = NULL;
|
||||
inst->size = 0;
|
||||
*inst->identity = 0;
|
||||
}
|
||||
|
||||
// void Var_Delete(Var *inst)
|
||||
// {
|
||||
// /* Skip when inst or inst->addr is unavailable. */
|
||||
// svoid(inst == NULL || inst->addr == NULL);
|
||||
|
||||
// inst->addr = NULL;
|
||||
// inst->size = 0;
|
||||
// *inst->identity = 0;
|
||||
// }
|
||||
|
||||
void VarUtils_Swap(Var *v1, Var *v2)
|
||||
{
|
||||
/* Skip when v1 or v2 is unavailable. */
|
||||
@@ -56,49 +78,46 @@ Status Var_Literalise(Var *inst, char *buff)
|
||||
state(inst == NULL, UnavailableInstance);
|
||||
|
||||
/* Write into buffer. */
|
||||
state(!sprintf(buff, VAR_LITERALISE_FORMAT, inst->identity,
|
||||
inst->addr, inst->size),
|
||||
state(!sprintf(buff, VAR_LITERALISE_FORMAT"\n", inst->addr, inst->size),
|
||||
error(RuntimeError, "Sprintf returned 0 where it should never do."));
|
||||
|
||||
return NormalStatus;
|
||||
}
|
||||
|
||||
bool Var_Equal(Var *a, Var *b)
|
||||
bool Var_Equals(Var *a, Var *b)
|
||||
{
|
||||
/* Skip unavailable inst and invalid param. */
|
||||
state((a == NULL || b == NULL), false);
|
||||
|
||||
return (a->addr == b->addr &&
|
||||
a->size == b->size &&
|
||||
(!strcmp(a->identity, b->identity)));
|
||||
return (a->addr == b->addr && a->size == b->size);
|
||||
}
|
||||
|
||||
bool VarUtils_IsIdentityLegal(char *identity)
|
||||
{
|
||||
/* Skip when identity is unavailable. */
|
||||
state(identity == NULL, false);
|
||||
// bool VarUtils_IsIdentityLegal(char *identity)
|
||||
// {
|
||||
// /* Skip when identity is unavailable. */
|
||||
// state(identity == NULL, false);
|
||||
|
||||
const int len = strlen(identity);
|
||||
// const int len = strlen(identity);
|
||||
|
||||
/* Skip when identity is empty. */
|
||||
state(len == 0, false);
|
||||
// /* Skip when identity is empty. */
|
||||
// state(len == 0, false);
|
||||
|
||||
/* Skip when the first char is not within alphabet. */
|
||||
state(ATRANGE('a', 'z', identity[0])
|
||||
|| ATRANGE('A', 'Z', identity[0]), false);
|
||||
// /* Skip when the first char is not within alphabet. */
|
||||
// state(ATRANGE('a', 'z', identity[0])
|
||||
// || ATRANGE('A', 'Z', identity[0]), false);
|
||||
|
||||
/* Skip when the length of identity is greater that VAR_IDENTITY_LENGTH. */
|
||||
state(len > VAR_IDENTITY_LENGTH, false);
|
||||
// /* Skip when the length of identity is greater that VAR_IDENTITY_LENGTH. */
|
||||
// state(len > VAR_IDENTITY_LENGTH, false);
|
||||
|
||||
/* Skip when identity has space and illegal characters in it. */
|
||||
const int illegal_len = strlen(VAR_IDENTITY_ILLEGAL_CHAR);
|
||||
for (register int i = 0; i < len; i++) {
|
||||
for (register int j = 0; j < illegal_len; j++) {
|
||||
if (identity[i] == VAR_IDENTITY_ILLEGAL_CHAR[j]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// /* Skip when identity has space and illegal characters in it. */
|
||||
// const int illegal_len = strlen(VAR_IDENTITY_ILLEGAL_CHAR);
|
||||
// for (register int i = 0; i < len; i++) {
|
||||
// for (register int j = 0; j < illegal_len; j++) {
|
||||
// if (identity[i] == VAR_IDENTITY_ILLEGAL_CHAR[j]) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
// return true;
|
||||
// }
|
||||
|
44
catlog.c
44
catlog.c
@@ -2,16 +2,16 @@
|
||||
#include <Compound/status.h>
|
||||
|
||||
Status CatlogMsg_Create(CatlogMsg *inst, CatlogLevel level,
|
||||
char const *originator, char const *msg)
|
||||
char *initiator, char *msg)
|
||||
{
|
||||
/* Skip unavailable instances and parameters. */
|
||||
fails(inst, UnavailableInstance);
|
||||
state((originator == NULL || msg == NULL), InvalidParameter);
|
||||
state((initiator == NULL || msg == NULL), InvalidParameter);
|
||||
|
||||
inst->time = time(NULL);
|
||||
inst->level = level;
|
||||
*inst->originator = *originator;
|
||||
*inst->content = *msg;
|
||||
inst->initiator = initiator;
|
||||
inst->content = msg;
|
||||
|
||||
return NormalStatus;
|
||||
}
|
||||
@@ -27,7 +27,7 @@ Status CatlogMsg_CopyOf(CatlogMsg *inst, CatlogMsg *other)
|
||||
return NormalStatus;
|
||||
}
|
||||
|
||||
bool CatlogMsg_Equal(CatlogMsg *inst, CatlogMsg *other)
|
||||
bool CatlogMsg_Equals(CatlogMsg *inst, CatlogMsg *other)
|
||||
{
|
||||
/* Skip unavailable instances and parameters. */
|
||||
state((inst == NULL || other == NULL), false);
|
||||
@@ -35,7 +35,7 @@ bool CatlogMsg_Equal(CatlogMsg *inst, CatlogMsg *other)
|
||||
return (
|
||||
inst->time == other->time &&
|
||||
inst->level == other->level &&
|
||||
(!strcmp(inst->originator, other->originator)) &&
|
||||
(!strcmp(inst->initiator, other->initiator)) &&
|
||||
(!strcmp(inst->content, other->content))
|
||||
);
|
||||
}
|
||||
@@ -70,13 +70,13 @@ Status CatlogSender_CopyOf(CatlogSender *inst, CatlogSender *other)
|
||||
return NormalStatus;
|
||||
}
|
||||
|
||||
bool CatlogSender_Equal(CatlogSender *inst, CatlogSender *other)
|
||||
bool CatlogSender_Equals(CatlogSender *inst, CatlogSender *other)
|
||||
{
|
||||
/* Skip unavailable instances and parameters. */
|
||||
state((inst == NULL || other == NULL), false);
|
||||
|
||||
return (
|
||||
CatlogMsg_Equal(&inst->msg, &other->msg) &&
|
||||
CatlogMsg_Equals(&inst->msg, &other->msg) &&
|
||||
inst->dst == other->dst &&
|
||||
inst->successful == other->successful &&
|
||||
((inst->elapsed.tv_sec == other->elapsed.tv_sec) &&
|
||||
@@ -84,23 +84,35 @@ bool CatlogSender_Equal(CatlogSender *inst, CatlogSender *other)
|
||||
);
|
||||
}
|
||||
|
||||
Status CatlogSender_Send(CatlogSender *inst, int *store, bool append)
|
||||
Status CatlogSender_Send(CatlogSender *inst, char *filepath, bool append)
|
||||
throws(ReadWriteError)
|
||||
{
|
||||
/* Skip unavailable instances and parameters. */
|
||||
fails(inst, UnavailableInstance);
|
||||
fails(store, InvalidParameter);
|
||||
fails(filepath, UnavailableFileName);
|
||||
|
||||
/* Open file. */
|
||||
ensure(CatlogUtils_OpenFile(inst->dst, (append ? "a" : "w")),
|
||||
"Unable to open file.");
|
||||
// ensure(CatlogUtils_OpenFile(inst->dst, (append ? "a" : "w")),
|
||||
// "Unable to open file.");
|
||||
(void)CatlogUtils_OpenFile(inst->dst, filepath, (append ? "a" : "w"));
|
||||
|
||||
/* Write msg. */
|
||||
*store = fprintf(inst->dst, "%s", inst->msg.content);
|
||||
|
||||
return NormalStatus;
|
||||
return normal(NormalStatus, "", fprintf(inst->dst, "%s", inst->msg.content));
|
||||
}
|
||||
|
||||
Status CatlogUtils_CalcElapsed(struct timespec t1, struct timespec t2);
|
||||
|
||||
Status CatlogUtils_OpenFile(FILE *store, const char const *__restrict mode);
|
||||
Status CatlogUtils_OpenFile(FILE *store, char *filepath,
|
||||
const char const *__restrict mode)
|
||||
{
|
||||
/* No need to open a system output stream. */
|
||||
if (!strcmp(filepath, "stdin") ||
|
||||
!strcmp(filepath, "stdout") ||
|
||||
!strcmp(filepath, "stderr")) {
|
||||
return NormalStatus;
|
||||
}
|
||||
|
||||
store = fopen(filepath, mode);
|
||||
|
||||
return NormalStatus;
|
||||
}
|
||||
|
15
catlog.h
15
catlog.h
@@ -1,8 +1,8 @@
|
||||
#ifndef COMPOUND_CATLOG_H
|
||||
# define COMPOUND_CATLOG_H
|
||||
|
||||
# include <Compound/status.h>
|
||||
# include <Compound/common.h>
|
||||
# include <Compound/status.h>
|
||||
|
||||
typedef enum {
|
||||
CATLOG_LEVEL_ALL, // Least the value, most the information.
|
||||
@@ -18,14 +18,14 @@ typedef enum {
|
||||
typedef struct {
|
||||
time_t time;
|
||||
CatlogLevel level;
|
||||
char *originator;
|
||||
char *initiator;
|
||||
char *content;
|
||||
} CatlogMsg;
|
||||
|
||||
Status CatlogMsg_Create(CatlogMsg *inst, CatlogLevel level,
|
||||
char const *originator, char const *msg);
|
||||
char *initiator, char *msg);
|
||||
Status CatlogMsg_CopyOf(CatlogMsg *inst, CatlogMsg *other);
|
||||
bool CatlogMsg_Equal(CatlogMsg *inst, CatlogMsg *other);
|
||||
bool CatlogMsg_Equals(CatlogMsg *inst, CatlogMsg *other);
|
||||
|
||||
typedef struct {
|
||||
CatlogMsg msg;
|
||||
@@ -36,10 +36,11 @@ typedef struct {
|
||||
|
||||
Status CatlogSender_Create(CatlogSender *inst, CatlogMsg *msg, FILE *dst);
|
||||
Status CatlogSender_CopyOf(CatlogSender *inst, CatlogSender *other);
|
||||
bool CatlogSender_Equal(CatlogSender *inst, CatlogSender *other);
|
||||
Status CatlogSender_Send(CatlogSender *inst, int *store, bool append)
|
||||
bool CatlogSender_Equals(CatlogSender *inst, CatlogSender *other);
|
||||
Status CatlogSender_Send(CatlogSender *inst, char *filepath, bool append)
|
||||
throws(ReadWriteError);
|
||||
Status CatlogUtils_CalcElapsed(struct timespec t1, struct timespec t2);
|
||||
Status CatlogUtils_OpenFile(FILE *store, const char *__restrict mode);
|
||||
Status CatlogUtils_OpenFile(FILE *store, char *filepath,
|
||||
const char const *__restrict mode);
|
||||
|
||||
#endif /* COMPOUND_CATLOG_H */
|
||||
|
79
common.h
79
common.h
@@ -1,5 +1,6 @@
|
||||
#ifndef COMPOUND_COMMON_h
|
||||
# define COMPOUND_COMMON_h
|
||||
// # define __DEBUG__ 1
|
||||
|
||||
# include <stdlib.h>
|
||||
# include <stdbool.h>
|
||||
@@ -39,37 +40,37 @@
|
||||
*/
|
||||
# define svoid(s) { if ((s)) return; }
|
||||
|
||||
/**
|
||||
* @brief Return an Error Status with given parameter $c as the
|
||||
* comment or description.
|
||||
* @return A instance of Error Status customised.
|
||||
* @note "error" stands for "Error in Status"
|
||||
* @note 'e' stands for "Error"
|
||||
* @note 'c' stands for "Comment"
|
||||
*/
|
||||
# define error(e, c) ((Status) {\
|
||||
|
||||
/* Create a new UnknownStatus on the fly. */
|
||||
# define unknown(e, c, v) ((Status) {\
|
||||
.value = v,\
|
||||
.description = c,\
|
||||
.characteristic = e.characteristic,\
|
||||
.characteristic = STATUS_UNKNOWN,\
|
||||
.prev = e.prev\
|
||||
})
|
||||
|
||||
/**
|
||||
* @brief Return an Error Status with given parameter $p as the
|
||||
* predecessor.
|
||||
* @return A instance of Error Status inherited.
|
||||
* @note "extend" stands for "Extend from Predecessor"
|
||||
* @note 'i' stands for 'Instance'
|
||||
* @note 'p' stands for "Predecessor"
|
||||
*/
|
||||
# define extend(i, p) ((Status)) {\
|
||||
.prev = p\
|
||||
}
|
||||
|
||||
# define modify(e, s, c) ((Status)) {\
|
||||
.description = s,\
|
||||
.characteristic = c,\
|
||||
/* Create a new NormalStatus on the fly. */
|
||||
# define normal(e, c, v) ((Status) {\
|
||||
.value = v,\
|
||||
.description = c,\
|
||||
.characteristic = STATUS_NORMAL,\
|
||||
.prev = e.prev\
|
||||
}
|
||||
})
|
||||
|
||||
/* Create a new ErrorStatus on the fly. */
|
||||
# define error(e, c) ((Status) {\
|
||||
.description = c,\
|
||||
.characteristic = STATUS_ERROR,\
|
||||
.prev = e.prev\
|
||||
})
|
||||
|
||||
/* Extend the Status chain by giving 'p' for "predecessor"
|
||||
and 'c' for "comment/description". */
|
||||
# define extend(p, c) ((Status) {\
|
||||
.description = c,\
|
||||
.characteristic = p.characteristic,\
|
||||
.prev = p\
|
||||
})
|
||||
|
||||
/** @brief Create a report in place.
|
||||
* @return A instance of Status Report customised.
|
||||
@@ -78,8 +79,8 @@
|
||||
* @note 'c' stands for "Char String of Originator"
|
||||
*/
|
||||
# define stamp(e, c) ((Report) {\
|
||||
.stat = e,\
|
||||
.originator = c,\
|
||||
.status = e,\
|
||||
.initiator = c,\
|
||||
.time = time(NULL),\
|
||||
.priority = REPORT_SENDING_PRIORITY_NORMAL,\
|
||||
.status = REPORT_SENDING_TASK_STATUS_PENDING\
|
||||
@@ -103,7 +104,7 @@
|
||||
// */
|
||||
// # define force(s, k, v) solve((s) != (k), v)
|
||||
|
||||
// # define sforce(s, k, v) solve((!status_equal(s, k)), v)
|
||||
// # define sforce(s, k, v) solve((!Status_Equals(s, k)), v)
|
||||
|
||||
/* Get the literal. */
|
||||
# define nameof(obj) #obj
|
||||
@@ -115,6 +116,24 @@
|
||||
|
||||
# define String(T) String
|
||||
|
||||
# define cat(s) {\
|
||||
CatlogMsg msg;\
|
||||
CatlogMsg_Create(&msg, CATLOG_LEVEL_DEBUG, "CAT", s);\
|
||||
CatlogSender sender;\
|
||||
CatlogSender_Create(&sender, &msg, stderr);\
|
||||
CatlogSender_Send(&sender, "stdout", false);\
|
||||
}
|
||||
|
||||
# define ok(s, b) {\
|
||||
const Status _ = s;\
|
||||
if (StatusUtils_IsOkay(_)) b\
|
||||
}
|
||||
|
||||
# define notok(s, b) {\
|
||||
const Status _ = s;\
|
||||
if (!StatusUtils_IsOkay(_)) b\
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
COMMON_ERROR_NULLPTR = 1,
|
||||
COMMON_ERROR_INVALID_ARGUMENT,
|
||||
@@ -148,4 +167,6 @@ typedef bool _Bit;
|
||||
# define ATRANGE(lf, rt, v) \
|
||||
(INRANGE(lf, true, rt, true, v)) ? 0 : ((v < lf) ? (v - lf) : (v - rt))
|
||||
|
||||
# define LITERALISATION_LENGTH_MAXIMUM 0xFFFF
|
||||
|
||||
#endif /* NO COMPOUND_COMMON_h */
|
||||
|
4
install
4
install
@@ -34,6 +34,6 @@ while :; do
|
||||
done
|
||||
|
||||
cp -v "common.h" "const.h" "platform.h"\
|
||||
"name.h" "type.h" "catlog.h"\
|
||||
"attr.h" "$DST"
|
||||
"name.h" "namescope.h" "type.h" "catlog.h"\
|
||||
"attr.h" "registry.h" "$DST"
|
||||
printf "\nDone\n"
|
||||
|
70
name.c
70
name.c
@@ -1,71 +1 @@
|
||||
#include <Compound/name.h>
|
||||
|
||||
Status NameSpace_Create(NameSpace *inst)
|
||||
{
|
||||
fails(inst, UnavailableInstance);
|
||||
|
||||
/* Create instances for members from inst. */
|
||||
state(status_isokay(NameSpace_EmptyName(&inst->latest)),
|
||||
error(RuntimeError, "Failed to initialise latest from NameSpace"));
|
||||
state(status_isokay(NameSpace_EmptyName(&inst->idx)),
|
||||
error(RuntimeError, "Failed to initialise idx from NameSpace"));
|
||||
state(status_isokay(NameSpace_EmptyName(inst->occupied)),
|
||||
error(RuntimeError, "Failed to initialise occupied from NameSpace"));
|
||||
|
||||
return NormalStatus;
|
||||
}
|
||||
|
||||
Status NameSpace_CopyOf(NameSpace *inst, NameSpace *other)
|
||||
{
|
||||
fails(inst, UnavailableInstance);
|
||||
fails(other, UnavailableParameter);
|
||||
|
||||
/* Copy and assign. */
|
||||
other->latest = inst->latest;
|
||||
other->idx = inst->idx;
|
||||
|
||||
const Name len = NameSpace_CalcNameArrayLength(&other->occupied);
|
||||
for (Name i = (Name){0}; (NameSpace_CompareName(i, len) < 0);) {
|
||||
|
||||
// TODO(william): HERE
|
||||
|
||||
/* i++ */
|
||||
state((!status_isokay(NameSpace_CountUp(&i))),
|
||||
error(RuntimeError, "Error occurred during calculations of Name."));
|
||||
}
|
||||
}
|
||||
|
||||
Status NameSpace_CreateName(NameSpace *inst, Name *buff);
|
||||
|
||||
Status NameSpace_RemoveName(NameSpace *inst, Name idx);
|
||||
|
||||
Status NameSpace_EmptyName(Name *inst);
|
||||
|
||||
Status NameSpace_CountUp(Name *inst);
|
||||
|
||||
Status NameSpace_CountDown(Name *inst);
|
||||
|
||||
Status NameSpace_CountUpFor(Name *inst, Name amount);
|
||||
|
||||
Status NameSpace_CountDownFor(Name *inst, Name amount);
|
||||
|
||||
Status NameSpace_UpdateLatest(NameSpace *inst, Name idx);
|
||||
|
||||
Status NameSpace_FormatTrim(Name *inst);
|
||||
|
||||
Status NameSpace_FormatInflate(Name *inst);
|
||||
|
||||
Name NameSpace_CalcNameArrayLength(Name **arr);
|
||||
|
||||
bool NameSpace_IsAvailable(NameSpace *inst, Name idx);
|
||||
|
||||
bool NameSpace_IsValidName(Name *inst);
|
||||
|
||||
int NameSpace_CompareName(Name *a, Name *b)
|
||||
{
|
||||
/* Validation comes the first. --William */
|
||||
if (!NameSpace_IsValidName(a) || !NameSpace_IsValidName(b)) {
|
||||
Report e; ArgueStartParam h;
|
||||
throw(stamp(&InvalidName));
|
||||
}
|
||||
}
|
||||
|
4
name.h
4
name.h
@@ -34,11 +34,11 @@ static const Name NullName = {
|
||||
// Name value;
|
||||
// Name idx;
|
||||
// Name *occupied;
|
||||
// } NameSpace; // Size: 8+8+8 =8*3 =24 Bytes (x64)
|
||||
// } NameScope; // Size: 8+8+8 =8*3 =24 Bytes (x64)
|
||||
|
||||
/*
|
||||
* Example:
|
||||
* Var variable_from_namespace_Utils_in_class_Calculation_in_function_C;
|
||||
* Var variable_from_namescope_Utils_in_class_Calculation_in_function_C;
|
||||
* // Not enough room for representation.
|
||||
* // Must use another more efficient method to store the name.
|
||||
* Become (roughly):
|
||||
|
71
namescope.c
71
namescope.c
@@ -0,0 +1,71 @@
|
||||
#include <Compound/namescope.h>
|
||||
|
||||
Status NameScope_Create(NameScope *inst)
|
||||
{
|
||||
fails(inst, UnavailableInstance);
|
||||
|
||||
/* Create instances for members from inst. */
|
||||
state(StatusUtils_IsOkay(NameScope_EmptyName(&inst->latest)),
|
||||
error(RuntimeError, "Failed to initialise latest from NameScope"));
|
||||
state(StatusUtils_IsOkay(NameScope_EmptyName(&inst->idx)),
|
||||
error(RuntimeError, "Failed to initialise idx from NameScope"));
|
||||
state(StatusUtils_IsOkay(NameScope_EmptyName(inst->occupied)),
|
||||
error(RuntimeError, "Failed to initialise occupied from NameScope"));
|
||||
|
||||
return NormalStatus;
|
||||
}
|
||||
|
||||
Status NameScope_CopyOf(NameScope *inst, NameScope *other)
|
||||
{
|
||||
fails(inst, UnavailableInstance);
|
||||
fails(other, UnavailableParameter);
|
||||
|
||||
/* Copy and assign. */
|
||||
other->latest = inst->latest;
|
||||
other->idx = inst->idx;
|
||||
|
||||
const Name len = NameScope_CalcNameArrayLength(&other->occupied);
|
||||
for (Name i = (Name){0}; (NameScope_CompareName(i, len) < 0);) {
|
||||
|
||||
// TODO(william): HERE
|
||||
|
||||
/* i++ */
|
||||
state((!StatusUtils_IsOkay(NameScope_CountUp(&i))),
|
||||
error(RuntimeError, "Error occurred during calculations of Name."));
|
||||
}
|
||||
}
|
||||
|
||||
Status NameScope_CreateName(NameScope *inst, Name *buff);
|
||||
|
||||
Status NameScope_RemoveName(NameScope *inst, Name idx);
|
||||
|
||||
Status NameScope_EmptyName(Name *inst);
|
||||
|
||||
Status NameScope_CountUp(Name *inst);
|
||||
|
||||
Status NameScope_CountDown(Name *inst);
|
||||
|
||||
Status NameScope_CountUpFor(Name *inst, Name amount);
|
||||
|
||||
Status NameScope_CountDownFor(Name *inst, Name amount);
|
||||
|
||||
Status NameScope_UpdateLatest(NameScope *inst, Name idx);
|
||||
|
||||
Status NameScope_FormatTrim(Name *inst);
|
||||
|
||||
Status NameScope_FormatInflate(Name *inst);
|
||||
|
||||
Name NameScope_CalcNameArrayLength(Name **arr);
|
||||
|
||||
bool NameScope_IsAvailable(NameScope *inst, Name idx);
|
||||
|
||||
bool NameScope_IsValidName(Name *inst);
|
||||
|
||||
int NameScope_CompareName(Name *a, Name *b)
|
||||
{
|
||||
/* Validation comes the first. --William */
|
||||
if (!NameScope_IsValidName(a) || !NameScope_IsValidName(b)) {
|
||||
Report e; ArgueStartParam h;
|
||||
throw(stamp(&InvalidName));
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ Status NameScope_CopyOf(NameScope *inst, NameScope *other);
|
||||
Status NameScope_CreateName(NameScope *inst, Name *buff);
|
||||
Status NameScope_RemoveName(NameScope *inst, Name idx);
|
||||
Status NameScope_UpdateLatest(NameScope *inst, Name idx);
|
||||
bool NameScope_Equal(NameScope *inst, NameScope *other);
|
||||
bool NameScope_Equals(NameScope *inst, NameScope *other);
|
||||
bool NameScope_IsAvailable(NameScope *inst, Name idx);
|
||||
|
||||
/* Universal Attribute NameScope. (U.A.N.) */
|
||||
|
Reference in New Issue
Block a user